Skip to content

Commit 5c9975f

Browse files
committed
[Common] add functions for accessing the reference comparator plots from the canvas
Add to the ReferenceUtils.h header file the functions that allow to access the current, reference and ratio plots from the TCanvas created by the ReferenceComparartorPlot class. This will allow for example custom checkers to access the plots.
1 parent 526f67e commit 5c9975f

File tree

2 files changed

+70
-61
lines changed

2 files changed

+70
-61
lines changed

Framework/include/QualityControl/ReferenceUtils.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
#include "QualityControl/QcInfoLogger.h"
2626
#include "QualityControl/RepoPathUtils.h"
2727

28+
#include <TH1.h>
29+
#include <TCanvas.h>
30+
2831
namespace o2::quality_control::checker
2932
{
3033

@@ -42,6 +45,70 @@ static std::shared_ptr<quality_control::core::MonitorObject> getReferencePlot(qu
4245
return qcdb->retrieveMO(path, name, repository::DatabaseInterface::Timestamp::Latest, referenceActivity);
4346
}
4447

48+
//_________________________________________________________________________________________
49+
//
50+
// Get the current and reference histograms from the container canvas.
51+
// The two histograms are returned as a std::pair
52+
53+
static std::pair<TH1*, TH1*> getPlotsFromCanvas(TCanvas* canvas, std::string& message)
54+
{
55+
// Get the pad containing the current histogram, as well as the reference one in the case of 1-D plots
56+
TPad* padHist = (TPad*)canvas->GetPrimitive(TString::Format("%s_PadHist", canvas->GetName()));
57+
if (!padHist) {
58+
message = "missing PadHist";
59+
return { nullptr, nullptr };
60+
}
61+
// Get the pad containing the reference histogram.
62+
// This pad is only present for 2-D histograms.
63+
// 1-D histograms are drawn superimposed in the same pad
64+
TPad* padHistRef = (TPad*)canvas->GetPrimitive(TString::Format("%s_PadHistRef", canvas->GetName()));
65+
66+
// Get the current histogram
67+
TH1* hist = dynamic_cast<TH1*>(padHist->GetPrimitive(TString::Format("%s_hist", canvas->GetName())));
68+
if (!hist) {
69+
message = "missing histogram";
70+
return { nullptr, nullptr };
71+
}
72+
73+
// Get the reference histogram, trying both pads
74+
TH1* histRef = nullptr;
75+
if (padHistRef) {
76+
histRef = dynamic_cast<TH1*>(padHistRef->GetPrimitive(TString::Format("%s_hist_ref", canvas->GetName())));
77+
} else {
78+
histRef = dynamic_cast<TH1*>(padHist->GetPrimitive(TString::Format("%s_hist_ref", canvas->GetName())));
79+
}
80+
81+
if (!histRef) {
82+
message = "missing reference histogram";
83+
return { nullptr, nullptr };
84+
}
85+
86+
// return a pair with the two histograms
87+
return { hist, histRef };
88+
}
89+
90+
//_________________________________________________________________________________________
91+
//
92+
// Get the ratio histogram from the container canvas
93+
94+
static TH1* getRatioPlotFromCanvas(TCanvas* canvas)
95+
{
96+
// Get the pad containing the current histogram, as well as the reference one in the case of 1-D plots
97+
TPad* padHistRatio = (TPad*)canvas->GetPrimitive(TString::Format("%s_PadHistRatio", canvas->GetName()));
98+
if (!padHistRatio) {
99+
return nullptr;
100+
}
101+
102+
// Get the current histogram
103+
TH1* histRatio = dynamic_cast<TH1*>(padHistRatio->GetPrimitive(TString::Format("%s_hist_ratio", canvas->GetName())));
104+
if (!histRatio) {
105+
return nullptr;
106+
}
107+
108+
// return a pair with the two histograms
109+
return histRatio;
110+
}
111+
45112
} // namespace o2::quality_control::checker
46113

47114
#endif // QUALITYCONTROL_ReferenceUtils_H

Modules/Common/src/ReferenceComparatorCheck.cxx

Lines changed: 3 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -77,71 +77,13 @@ void ReferenceComparatorCheck::endOfActivity(const Activity& activity)
7777

7878
//_________________________________________________________________________________________
7979
//
80-
// Get the current and reference histograms from the canvas.
81-
// The two histograms are returned as a std::pair
82-
static std::pair<TH1*, TH1*> getPlotsFromCanvas(TCanvas* canvas, std::string& message)
83-
{
84-
// Get the pad containing the current histogram, as well as the reference one in the case of 1-D plots
85-
TPad* padHist = (TPad*)canvas->GetPrimitive(TString::Format("%s_PadHist", canvas->GetName()));
86-
if (!padHist) {
87-
message = "missing PadHist";
88-
return { nullptr, nullptr };
89-
}
90-
// Get the pad containing the reference histogram.
91-
// This pad is only present for 2-D histograms.
92-
// 1-D histograms are drawn superimposed in the same pad
93-
TPad* padHistRef = (TPad*)canvas->GetPrimitive(TString::Format("%s_PadHistRef", canvas->GetName()));
94-
95-
// Get the current histogram
96-
TH1* hist = dynamic_cast<TH1*>(padHist->GetPrimitive(TString::Format("%s_hist", canvas->GetName())));
97-
if (!hist) {
98-
message = "missing histogram";
99-
return { nullptr, nullptr };
100-
}
101-
102-
// Get the reference histogram, trying both pads
103-
TH1* histRef = nullptr;
104-
if (padHistRef) {
105-
histRef = dynamic_cast<TH1*>(padHistRef->GetPrimitive(TString::Format("%s_hist_ref", canvas->GetName())));
106-
} else {
107-
histRef = dynamic_cast<TH1*>(padHist->GetPrimitive(TString::Format("%s_hist_ref", canvas->GetName())));
108-
}
109-
110-
if (!histRef) {
111-
message = "missing reference histogram";
112-
return { nullptr, nullptr };
113-
}
114-
115-
// return a pair with the two histograms
116-
return { hist, histRef };
117-
}
11880

11981
static std::pair<TH1*, TH1*> getPlotsFromCanvas(TCanvas* canvas)
12082
{
12183
std::string dummyMessage;
122-
return getPlotsFromCanvas(canvas, dummyMessage);
84+
return o2::quality_control::checker::getPlotsFromCanvas(canvas, dummyMessage);
12385
}
12486

125-
//_________________________________________________________________________________________
126-
//
127-
// Get the ratio histograms from the canvas
128-
static TH1* getRatioPlotFromCanvas(TCanvas* canvas)
129-
{
130-
// Get the pad containing the current histogram, as well as the reference one in the case of 1-D plots
131-
TPad* padHistRatio = (TPad*)canvas->GetPrimitive(TString::Format("%s_PadHistRatio", canvas->GetName()));
132-
if (!padHistRatio) {
133-
return nullptr;
134-
}
135-
136-
// Get the current histogram
137-
TH1* histRatio = dynamic_cast<TH1*>(padHistRatio->GetPrimitive(TString::Format("%s_hist_ratio", canvas->GetName())));
138-
if (!histRatio) {
139-
return nullptr;
140-
}
141-
142-
// return a pair with the two histograms
143-
return histRatio;
144-
}
14587

14688
// Get the current and reference histograms from the canvas, and compare them using the comparator object passed as parameter
14789
static Quality compare(TCanvas* canvas, ObjectComparatorInterface* comparator, std::string& message)
@@ -156,7 +98,7 @@ static Quality compare(TCanvas* canvas, ObjectComparatorInterface* comparator, s
15698
}
15799

158100
// extract the histograms from the canvas
159-
auto plots = getPlotsFromCanvas(canvas, message);
101+
auto plots = o2::quality_control::checker::getPlotsFromCanvas(canvas, message);
160102
if (!plots.first || !plots.second) {
161103
return Quality::Null;
162104
}
@@ -389,7 +331,7 @@ void ReferenceComparatorCheck::beautify(std::shared_ptr<MonitorObject> mo, Quali
389331
setQualityLabel(canvas, quality);
390332

391333
// draw a double-arrow indicating the horizontal range for the check, if it is set
392-
beautifyRatioPlot(moName, getRatioPlotFromCanvas(canvas), quality);
334+
beautifyRatioPlot(moName, o2::quality_control::checker::getRatioPlotFromCanvas(canvas), quality);
393335
} else {
394336
// draw the quality label directly on the plot if the MO is an histogram
395337
auto* th1 = dynamic_cast<TH1*>(mo->getObject());

0 commit comments

Comments
 (0)