Skip to content

Commit 8ad723f

Browse files
authored
QC-1202 Improve naming of canvas elements created by TrendingTask (#2364)
As it turned out, some TPC Checks were relying on the default naming used by TTree::Draw when drawing the trends, i.e. "Graph" and "htemp". When implementing QC-1155, we could not keep them default to allow for drawing a legend in case we had multiple trends on one canvas. This commit changes the following: - It adds an optional "name" field to graphs. If it's absent, "title" is used. If that is absent as well, the main "name" of the plot is used. - In case that "htemp" is used by TTree::Draw only to draw the axes, title, etc, it is renamed to "background". In case that the plot is 1D, "htemp" is renamed to the plot "name" - In case that errors are drawn, the object is renamed to "name" suffixed with "_errors"
1 parent 554af52 commit 8ad723f

4 files changed

Lines changed: 16 additions & 5 deletions

File tree

Framework/include/QualityControl/TrendingTaskConfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ struct TrendingTaskConfig : PostProcessingConfig {
3333

3434
// this corresponds to one TTree::Draw() call, i.e. one graph or histogram drawing
3535
struct Graph {
36+
std::string name;
3637
std::string title;
3738
std::string varexp;
3839
std::string selection;

Framework/postprocessing.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,13 @@
8585
"graphYRange": "0:10000",
8686
"graphs" : [
8787
{
88+
"name": "mean_trend",
8889
"title": "mean trend",
8990
"varexp": "example.mean:time",
9091
"selection": "",
9192
"option": "*L PLC PMC"
9293
}, {
94+
"name": "mean_trend_1000",
9395
"title": "mean trend + 1000",
9496
"varexp": "example.mean + 1000:time",
9597
"selection": "",

Framework/src/TrendingTask.cxx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,22 +337,26 @@ TCanvas* TrendingTask::drawPlot(const TrendingTaskConfig::Plot& plotConfig)
337337
mTrend->Draw(varexpWithErrors.c_str(), graphConfig.selection.c_str(), "goff");
338338
graphErrors = new TGraphErrors(mTrend->GetSelectedRows(), mTrend->GetVal(1), mTrend->GetVal(0),
339339
mTrend->GetVal(2), mTrend->GetVal(3));
340+
graphErrors->SetName((graphConfig.name + "_errors").c_str());
341+
graphErrors->SetTitle((graphConfig.title + " errors").c_str());
340342
// We draw on the same plotConfig as the main graphConfig, but only error bars
341343
graphErrors->Draw("SAME E");
342344
}
343345
}
344346

345347
if (auto graph = dynamic_cast<TGraph*>(c->FindObject("Graph"))) {
348+
graph->SetName(graphConfig.name.c_str());
346349
graph->SetTitle(graphConfig.title.c_str());
347-
graph->SetName(graphConfig.title.c_str());
348350
legend->AddEntry(graph, graphConfig.title.c_str(), deduceGraphLegendOptions(graphConfig).c_str());
349351
}
350352
if (auto htemp = dynamic_cast<TH1*>(c->FindObject("htemp"))) {
351-
htemp->SetTitle(graphConfig.title.c_str());
352-
htemp->SetName(graphConfig.title.c_str());
353353
if (plotOrder == 1) {
354+
htemp->SetName(graphConfig.name.c_str());
355+
htemp->SetTitle(graphConfig.title.c_str());
354356
legend->AddEntry(htemp, graphConfig.title.c_str(), "lpf");
355357
} else {
358+
htemp->SetName("background");
359+
htemp->SetTitle("background");
356360
// htemp was used by TTree::Draw only to draw axes and title, not to plot data, no need to add it to legend
357361
}
358362
// QCG doesn't empty the buffers before visualizing the plotConfig, nor does ROOT when saving the file,

Framework/src/TrendingTaskConfig.cxx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,18 @@ TrendingTaskConfig::TrendingTaskConfig(std::string id, const boost::property_tre
3131
std::vector<Graph> graphs;
3232
if (const auto& graphsConfig = plotConfig.get_child_optional("graphs"); graphsConfig.has_value()) {
3333
for (const auto& [_, graphConfig] : graphsConfig.value()) {
34-
graphs.push_back({ graphConfig.get<std::string>("title", ""),
34+
// first we use name of the graph, if absent, we use graph title, if absent, we use plot (object) name.
35+
const auto& name = graphConfig.get<std::string>("name", graphConfig.get<std::string>("title", plotConfig.get<std::string>("name")));
36+
graphs.push_back({ name,
37+
graphConfig.get<std::string>("title", ""),
3538
graphConfig.get<std::string>("varexp"),
3639
graphConfig.get<std::string>("selection", ""),
3740
graphConfig.get<std::string>("option", ""),
3841
graphConfig.get<std::string>("graphErrors", "") });
3942
}
4043
} else {
41-
graphs.push_back({ plotConfig.get<std::string>("title", ""),
44+
graphs.push_back({ plotConfig.get<std::string>("name", ""),
45+
plotConfig.get<std::string>("title", ""),
4246
plotConfig.get<std::string>("varexp"),
4347
plotConfig.get<std::string>("selection", ""),
4448
plotConfig.get<std::string>("option", ""),

0 commit comments

Comments
 (0)