Skip to content

Commit 779dda4

Browse files
authored
[Common] support varibale bins in reference comparator output (#2440)
The changes allow to properly display histograms with variable bin sizes in the output of the reference comparator task.
1 parent 37c66a9 commit 779dda4

1 file changed

Lines changed: 67 additions & 36 deletions

File tree

Modules/Common/src/ReferenceComparatorPlot.cxx

Lines changed: 67 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,61 @@ static void copyAndScaleHistograms(TH1* histogram, TH1* referenceHistogram, TH1*
9898
}
9999
}
100100

101+
template <class HIST>
102+
static std::shared_ptr<HIST> createHisto1D(const char* name, const char* title, TH1* source)
103+
{
104+
std::shared_ptr<HIST> result;
105+
if (source->GetXaxis()->IsVariableBinSize()) {
106+
result = std::make_shared<HIST>(name, title,
107+
source->GetXaxis()->GetNbins(),
108+
source->GetXaxis()->GetXbins()->GetArray());
109+
} else {
110+
result = std::make_shared<HIST>(name, title,
111+
source->GetXaxis()->GetNbins(),
112+
source->GetXaxis()->GetXmin(),
113+
source->GetXaxis()->GetXmax());
114+
}
115+
116+
return result;
117+
}
118+
119+
template <class HIST>
120+
static std::shared_ptr<HIST> createHisto2D(const char* name, const char* title, TH1* source)
121+
{
122+
std::shared_ptr<HIST> result;
123+
if (source->GetXaxis()->IsVariableBinSize() && source->GetYaxis()->IsVariableBinSize()) {
124+
result = std::make_shared<HIST>(name, title,
125+
source->GetXaxis()->GetNbins(),
126+
source->GetXaxis()->GetXbins()->GetArray(),
127+
source->GetYaxis()->GetNbins(),
128+
source->GetYaxis()->GetXbins()->GetArray());
129+
} else if (source->GetXaxis()->IsVariableBinSize() && !source->GetYaxis()->IsVariableBinSize()) {
130+
result = std::make_shared<HIST>(name, title,
131+
source->GetXaxis()->GetNbins(),
132+
source->GetXaxis()->GetXbins()->GetArray(),
133+
source->GetYaxis()->GetNbins(),
134+
source->GetYaxis()->GetXmin(),
135+
source->GetYaxis()->GetXmax());
136+
} else if (!source->GetXaxis()->IsVariableBinSize() && source->GetYaxis()->IsVariableBinSize()) {
137+
result = std::make_shared<HIST>(name, title,
138+
source->GetXaxis()->GetNbins(),
139+
source->GetXaxis()->GetXmin(),
140+
source->GetXaxis()->GetXmax(),
141+
source->GetYaxis()->GetNbins(),
142+
source->GetYaxis()->GetXbins()->GetArray());
143+
} else {
144+
result = std::make_shared<HIST>(name, title,
145+
source->GetXaxis()->GetNbins(),
146+
source->GetXaxis()->GetXmin(),
147+
source->GetXaxis()->GetXmax(),
148+
source->GetYaxis()->GetNbins(),
149+
source->GetYaxis()->GetXmin(),
150+
source->GetYaxis()->GetXmax());
151+
}
152+
153+
return result;
154+
}
155+
101156
//_________________________________________________________________________________________
102157

103158
class ReferenceComparatorPlotImpl
@@ -193,10 +248,7 @@ class ReferenceComparatorPlotImpl1D : public ReferenceComparatorPlotImpl
193248

194249
// histogram from the current run
195250
mPadHist->cd();
196-
mPlot = std::make_shared<HIST>((canvasName + "_hist").c_str(), "",
197-
referenceHistogram->GetXaxis()->GetNbins(),
198-
referenceHistogram->GetXaxis()->GetXmin(),
199-
referenceHistogram->GetXaxis()->GetXmax());
251+
mPlot = createHisto1D<HIST>((canvasName + "_hist").c_str(), "", referenceHistogram);
200252
mPlot->GetXaxis()->SetTitle(referenceHistogram->GetXaxis()->GetTitle());
201253
mPlot->GetXaxis()->SetLabelSize(labelSize);
202254
mPlot->GetXaxis()->SetTitleSize(labelSize);
@@ -211,20 +263,14 @@ class ReferenceComparatorPlotImpl1D : public ReferenceComparatorPlotImpl
211263
mPlot->Draw(drawOption.c_str());
212264

213265
// histogram from the reference run
214-
mReferencePlot = std::make_shared<HIST>((canvasName + "_hist_ref").c_str(), "",
215-
referenceHistogram->GetXaxis()->GetNbins(),
216-
referenceHistogram->GetXaxis()->GetXmin(),
217-
referenceHistogram->GetXaxis()->GetXmax());
266+
mReferencePlot = createHisto1D<HIST>((canvasName + "_hist_ref").c_str(), "", referenceHistogram);
218267
mReferencePlot->SetLineColor(kBlue);
219268
mReferencePlot->SetOption((drawOption + "SAME").c_str());
220269
mReferencePlot->Draw((drawOption + "SAME").c_str());
221270

222271
// histogram with current/reference ratio
223272
mPadHistRatio->cd();
224-
mRatioPlot = std::make_shared<HIST>((canvasName + "_hist_ratio").c_str(), "",
225-
referenceHistogram->GetXaxis()->GetNbins(),
226-
referenceHistogram->GetXaxis()->GetXmin(),
227-
referenceHistogram->GetXaxis()->GetXmax());
273+
mRatioPlot = createHisto1D<HIST>((canvasName + "_hist_ratio").c_str(), "", referenceHistogram);
228274
if (drawRatioOnly) {
229275
mRatioPlot->SetTitle(referenceHistogram->GetTitle());
230276
mRatioPlot->GetXaxis()->SetTitle(referenceHistogram->GetXaxis()->GetTitle());
@@ -369,14 +415,9 @@ class ReferenceComparatorPlotImpl2D : public ReferenceComparatorPlotImpl
369415

370416
// histogram from the current run
371417
mPadHist->cd();
372-
mPlot = std::make_shared<HIST>((canvasName + "_hist").c_str(),
373-
referenceHistogram->GetTitle(),
374-
referenceHistogram->GetXaxis()->GetNbins(),
375-
referenceHistogram->GetXaxis()->GetXmin(),
376-
referenceHistogram->GetXaxis()->GetXmax(),
377-
referenceHistogram->GetYaxis()->GetNbins(),
378-
referenceHistogram->GetYaxis()->GetXmin(),
379-
referenceHistogram->GetYaxis()->GetXmax());
418+
mPlot = createHisto2D<HIST>((canvasName + "_hist").c_str(),
419+
referenceHistogram->GetTitle(),
420+
referenceHistogram);
380421
mPlot->GetXaxis()->SetTitle(referenceHistogram->GetXaxis()->GetTitle());
381422
mPlot->GetYaxis()->SetTitle(referenceHistogram->GetYaxis()->GetTitle());
382423
mPlot->SetStats(0);
@@ -385,14 +426,9 @@ class ReferenceComparatorPlotImpl2D : public ReferenceComparatorPlotImpl
385426

386427
// histogram from the reference run
387428
mPadHistRef->cd();
388-
mReferencePlot = std::make_shared<HIST>((canvasName + "_hist_ref").c_str(),
389-
TString::Format("%s (reference)", referenceHistogram->GetTitle()),
390-
referenceHistogram->GetXaxis()->GetNbins(),
391-
referenceHistogram->GetXaxis()->GetXmin(),
392-
referenceHistogram->GetXaxis()->GetXmax(),
393-
referenceHistogram->GetYaxis()->GetNbins(),
394-
referenceHistogram->GetYaxis()->GetXmin(),
395-
referenceHistogram->GetYaxis()->GetXmax());
429+
mReferencePlot = createHisto2D<HIST>((canvasName + "_hist_ref").c_str(),
430+
TString::Format("%s (reference)", referenceHistogram->GetTitle()),
431+
referenceHistogram);
396432
mReferencePlot->GetXaxis()->SetTitle(referenceHistogram->GetXaxis()->GetTitle());
397433
mReferencePlot->GetYaxis()->SetTitle(referenceHistogram->GetYaxis()->GetTitle());
398434
mReferencePlot->SetStats(0);
@@ -401,14 +437,9 @@ class ReferenceComparatorPlotImpl2D : public ReferenceComparatorPlotImpl
401437

402438
// histogram with current/reference ratio
403439
mPadHistRatio->cd();
404-
mRatioPlot = std::make_shared<HIST>((canvasName + "_hist_ratio").c_str(),
405-
TString::Format("%s (ratio)", referenceHistogram->GetTitle()),
406-
referenceHistogram->GetXaxis()->GetNbins(),
407-
referenceHistogram->GetXaxis()->GetXmin(),
408-
referenceHistogram->GetXaxis()->GetXmax(),
409-
referenceHistogram->GetYaxis()->GetNbins(),
410-
referenceHistogram->GetYaxis()->GetXmin(),
411-
referenceHistogram->GetYaxis()->GetXmax());
440+
mRatioPlot = createHisto2D<HIST>((canvasName + "_hist_ratio").c_str(),
441+
TString::Format("%s (ratio)", referenceHistogram->GetTitle()),
442+
referenceHistogram);
412443
mRatioPlot->GetXaxis()->SetTitle(referenceHistogram->GetXaxis()->GetTitle());
413444
mRatioPlot->GetYaxis()->SetTitle(referenceHistogram->GetYaxis()->GetTitle());
414445
if (!drawRatioOnly) {

0 commit comments

Comments
 (0)