Skip to content

Commit 133fd36

Browse files
committed
[Common] allow access to the reference comparator plots in derived classes
The changes allow to use the ReferenceComparatorTask as a base class, providing access to the reference comparison plots for the derived classes. A typical use case would be a post-processing task that produces some derived plots, which also need to compared with some reference. With the current production code, this involves adding a dedicated ReferenceComparatorTask in the workflow, that fetches the plots from the post-processing task from the QCDB. This commit allows to solve the above problem by deriving the post-processing task from the ReferenceComparatorTask, such that the reference comparison plots can be filled directly by the derived task, without going through the QCDB. This is achieved with the following two changes: * addition of a function that exposes the reference comparison plots in the ReferenceComparatorTask interface * storage of the pointer to the reference histogram in the ReferenceComparatorPlot object, such that it does not need to be passed to the `update()` method
1 parent 622afde commit 133fd36

File tree

4 files changed

+32
-17
lines changed

4 files changed

+32
-17
lines changed

Modules/Common/include/Common/ReferenceComparatorPlot.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ReferenceComparatorPlot
4141
virtual ~ReferenceComparatorPlot() = default;
4242

4343
TObject* getMainCanvas();
44-
void update(TH1* histogram, TH1* referenceHistogram);
44+
void update(TH1* histogram);
4545

4646
private:
4747
std::shared_ptr<ReferenceComparatorPlotImpl> mImplementation;

Modules/Common/include/Common/ReferenceComparatorTask.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class ReferenceComparatorTask : public quality_control::postprocessing::PostProc
5050
void update(quality_control::postprocessing::Trigger, framework::ServiceRegistryRef) override;
5151
void finalize(quality_control::postprocessing::Trigger, framework::ServiceRegistryRef) override;
5252

53+
std::map<std::string, std::shared_ptr<ReferenceComparatorPlot>>& getComparatorPlots() { return mHistograms; }
54+
std::shared_ptr<ReferenceComparatorPlot> getComparatorPlot(std::string plotName);
55+
5356
struct HistoWithRef {
5457
std::shared_ptr<TH1> mPlot;
5558
std::shared_ptr<TH1> mRefPlot;

Modules/Common/src/ReferenceComparatorPlot.cxx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,21 +158,21 @@ static std::shared_ptr<HIST> createHisto2D(const char* name, const char* title,
158158
class ReferenceComparatorPlotImpl
159159
{
160160
public:
161-
ReferenceComparatorPlotImpl(bool scaleReference)
162-
: mScaleReference(scaleReference)
161+
ReferenceComparatorPlotImpl(TH1* referenceHistogram, bool scaleReference)
162+
: mReferenceHistogram(referenceHistogram), mScaleReference(scaleReference)
163163
{
164164
}
165165

166166
virtual ~ReferenceComparatorPlotImpl() = default;
167167

168-
virtual TObject* init(TH1* referenceHistogram, std::string outputPath, bool scaleReference, bool drawRatioOnly, std::string drawOption)
168+
virtual TObject* getMainCanvas()
169169
{
170170
return nullptr;
171171
}
172172

173-
virtual TObject* getMainCanvas()
173+
TH1* getReferenceHistogram()
174174
{
175-
return nullptr;
175+
return mReferenceHistogram;
176176
}
177177

178178
void setScaleRef(bool scaleReference)
@@ -182,9 +182,10 @@ class ReferenceComparatorPlotImpl
182182

183183
bool getScaleReference() { return mScaleReference; }
184184

185-
virtual void update(TH1* histogram, TH1* referenceHistogram) = 0;
185+
virtual void update(TH1* histogram) = 0;
186186

187187
private:
188+
TH1* mReferenceHistogram{ nullptr };
188189
bool mScaleReference{ true };
189190
};
190191

@@ -193,7 +194,7 @@ class ReferenceComparatorPlotImpl1D : public ReferenceComparatorPlotImpl
193194
{
194195
public:
195196
ReferenceComparatorPlotImpl1D(TH1* referenceHistogram, const std::string& outputPath, bool scaleReference, bool drawRatioOnly, const std::string& drawOption)
196-
: ReferenceComparatorPlotImpl(scaleReference)
197+
: ReferenceComparatorPlotImpl(referenceHistogram, scaleReference)
197198
{
198199
float labelSize = 0.04;
199200

@@ -326,8 +327,9 @@ class ReferenceComparatorPlotImpl1D : public ReferenceComparatorPlotImpl
326327
return mCanvas.get();
327328
}
328329

329-
void update(TH1* hist, TH1* referenceHistogram)
330+
void update(TH1* hist)
330331
{
332+
TH1* referenceHistogram = getReferenceHistogram();
331333
if (!hist || !referenceHistogram) {
332334
return;
333335
}
@@ -360,7 +362,7 @@ class ReferenceComparatorPlotImpl2D : public ReferenceComparatorPlotImpl
360362
{
361363
public:
362364
ReferenceComparatorPlotImpl2D(TH1* referenceHistogram, const std::string& outputPath, bool scaleReference, bool drawRatioOnly, const std::string& drawOption)
363-
: ReferenceComparatorPlotImpl(scaleReference)
365+
: ReferenceComparatorPlotImpl(referenceHistogram, scaleReference)
364366
{
365367
if (!referenceHistogram) {
366368
return;
@@ -469,8 +471,9 @@ class ReferenceComparatorPlotImpl2D : public ReferenceComparatorPlotImpl
469471
return mCanvas.get();
470472
}
471473

472-
void update(TH1* histogram, TH1* referenceHistogram)
474+
void update(TH1* histogram)
473475
{
476+
TH1* referenceHistogram = getReferenceHistogram();
474477
if (!histogram || !referenceHistogram) {
475478
return;
476479
}
@@ -523,10 +526,10 @@ TObject* ReferenceComparatorPlot::getMainCanvas()
523526
return (mImplementation.get() ? mImplementation->getMainCanvas() : nullptr);
524527
}
525528

526-
void ReferenceComparatorPlot::update(TH1* histogram, TH1* referenceHistogram)
529+
void ReferenceComparatorPlot::update(TH1* histogram)
527530
{
528531
if (mImplementation) {
529-
mImplementation->update(histogram, referenceHistogram);
532+
mImplementation->update(histogram);
530533
}
531534
}
532535

Modules/Common/src/ReferenceComparatorTask.cxx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,18 @@ void ReferenceComparatorTask::initialize(quality_control::postprocessing::Trigge
165165

166166
//_________________________________________________________________________________________
167167

168+
std::shared_ptr<ReferenceComparatorPlot> ReferenceComparatorTask::getComparatorPlot(std::string plotName)
169+
{
170+
// check if a corresponding output plot was initialized
171+
auto iter = mHistograms.find(plotName);
172+
if (iter == mHistograms.end()) {
173+
return {};
174+
}
175+
return iter->second;
176+
}
177+
178+
//_________________________________________________________________________________________
179+
168180
void ReferenceComparatorTask::update(quality_control::postprocessing::Trigger trigger, framework::ServiceRegistryRef services)
169181
{
170182
auto& qcdb = services.get<repository::DatabaseInterface>();
@@ -192,10 +204,7 @@ void ReferenceComparatorTask::update(quality_control::postprocessing::Trigger tr
192204
}
193205

194206
// update the plot ratios and the histograms with superimposed reference
195-
auto referenceMO = mReferencePlots[plotName];
196-
TH1* referenceHistogram = dynamic_cast<TH1*>(referenceMO->getObject());
197-
198-
iter->second->update(histogram, referenceHistogram);
207+
iter->second->update(histogram);
199208
}
200209
}
201210
}

0 commit comments

Comments
 (0)