Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions Framework/include/QualityControl/ReferenceUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#include "QualityControl/QcInfoLogger.h"
#include "QualityControl/RepoPathUtils.h"

#include <TH1.h>
#include <TCanvas.h>

namespace o2::quality_control::checker
{

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

//_________________________________________________________________________________________
//
// Get the current and reference histograms from the container canvas.
// The two histograms are returned as a std::pair

static std::pair<TH1*, TH1*> getPlotsFromCanvas(TCanvas* canvas, std::string& message)
{
// Get the pad containing the current histogram, as well as the reference one in the case of 1-D plots
TPad* padHist = dynamic_cast<TPad*>(canvas->GetPrimitive(TString::Format("%s_PadHist", canvas->GetName())));
if (!padHist) {
message = "missing PadHist";
return { nullptr, nullptr };
}
// Get the pad containing the reference histogram.
// This pad is only present for 2-D histograms.
// 1-D histograms are drawn superimposed in the same pad
TPad* padHistRef = (TPad*)canvas->GetPrimitive(TString::Format("%s_PadHistRef", canvas->GetName()));

// Get the current histogram
TH1* hist = dynamic_cast<TH1*>(padHist->GetPrimitive(TString::Format("%s_hist", canvas->GetName())));
if (!hist) {
message = "missing histogram";
return { nullptr, nullptr };
}

// Get the reference histogram, trying both pads
TH1* histRef = nullptr;
if (padHistRef) {
histRef = dynamic_cast<TH1*>(padHistRef->GetPrimitive(TString::Format("%s_hist_ref", canvas->GetName())));
} else {
histRef = dynamic_cast<TH1*>(padHist->GetPrimitive(TString::Format("%s_hist_ref", canvas->GetName())));
}

if (!histRef) {
message = "missing reference histogram";
return { nullptr, nullptr };
}

// return a pair with the two histograms
return { hist, histRef };
}

//_________________________________________________________________________________________
//
// Get the ratio histogram from the container canvas

static TH1* getRatioPlotFromCanvas(TCanvas* canvas)
{
// Get the pad containing the current histogram, as well as the reference one in the case of 1-D plots
TPad* padHistRatio = dynamic_cast<TPad*>(canvas->GetPrimitive(TString::Format("%s_PadHistRatio", canvas->GetName())));
if (!padHistRatio) {
return nullptr;
}

// Get the current histogram
TH1* histRatio = dynamic_cast<TH1*>(padHistRatio->GetPrimitive(TString::Format("%s_hist_ratio", canvas->GetName())));
if (!histRatio) {
return nullptr;
}

// return a pair with the two histograms
return histRatio;
}

} // namespace o2::quality_control::checker

#endif // QUALITYCONTROL_ReferenceUtils_H
2 changes: 1 addition & 1 deletion Modules/Common/include/Common/ReferenceComparatorPlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ReferenceComparatorPlot
virtual ~ReferenceComparatorPlot() = default;

TObject* getMainCanvas();
void update(TH1* histogram, TH1* referenceHistogram);
void update(TH1* histogram);

private:
std::shared_ptr<ReferenceComparatorPlotImpl> mImplementation;
Expand Down
3 changes: 3 additions & 0 deletions Modules/Common/include/Common/ReferenceComparatorTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class ReferenceComparatorTask : public quality_control::postprocessing::PostProc
void update(quality_control::postprocessing::Trigger, framework::ServiceRegistryRef) override;
void finalize(quality_control::postprocessing::Trigger, framework::ServiceRegistryRef) override;

std::map<std::string, std::shared_ptr<ReferenceComparatorPlot>>& getComparatorPlots() { return mHistograms; }
std::shared_ptr<ReferenceComparatorPlot> getComparatorPlot(std::string plotName);

struct HistoWithRef {
std::shared_ptr<TH1> mPlot;
std::shared_ptr<TH1> mRefPlot;
Expand Down
68 changes: 3 additions & 65 deletions Modules/Common/src/ReferenceComparatorCheck.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -75,72 +75,10 @@ void ReferenceComparatorCheck::endOfActivity(const Activity& activity)
{
}

//_________________________________________________________________________________________
//
// Get the current and reference histograms from the canvas.
// The two histograms are returned as a std::pair
static std::pair<TH1*, TH1*> getPlotsFromCanvas(TCanvas* canvas, std::string& message)
{
// Get the pad containing the current histogram, as well as the reference one in the case of 1-D plots
TPad* padHist = (TPad*)canvas->GetPrimitive(TString::Format("%s_PadHist", canvas->GetName()));
if (!padHist) {
message = "missing PadHist";
return { nullptr, nullptr };
}
// Get the pad containing the reference histogram.
// This pad is only present for 2-D histograms.
// 1-D histograms are drawn superimposed in the same pad
TPad* padHistRef = (TPad*)canvas->GetPrimitive(TString::Format("%s_PadHistRef", canvas->GetName()));

// Get the current histogram
TH1* hist = dynamic_cast<TH1*>(padHist->GetPrimitive(TString::Format("%s_hist", canvas->GetName())));
if (!hist) {
message = "missing histogram";
return { nullptr, nullptr };
}

// Get the reference histogram, trying both pads
TH1* histRef = nullptr;
if (padHistRef) {
histRef = dynamic_cast<TH1*>(padHistRef->GetPrimitive(TString::Format("%s_hist_ref", canvas->GetName())));
} else {
histRef = dynamic_cast<TH1*>(padHist->GetPrimitive(TString::Format("%s_hist_ref", canvas->GetName())));
}

if (!histRef) {
message = "missing reference histogram";
return { nullptr, nullptr };
}

// return a pair with the two histograms
return { hist, histRef };
}

static std::pair<TH1*, TH1*> getPlotsFromCanvas(TCanvas* canvas)
{
std::string dummyMessage;
return getPlotsFromCanvas(canvas, dummyMessage);
}

//_________________________________________________________________________________________
//
// Get the ratio histograms from the canvas
static TH1* getRatioPlotFromCanvas(TCanvas* canvas)
{
// Get the pad containing the current histogram, as well as the reference one in the case of 1-D plots
TPad* padHistRatio = (TPad*)canvas->GetPrimitive(TString::Format("%s_PadHistRatio", canvas->GetName()));
if (!padHistRatio) {
return nullptr;
}

// Get the current histogram
TH1* histRatio = dynamic_cast<TH1*>(padHistRatio->GetPrimitive(TString::Format("%s_hist_ratio", canvas->GetName())));
if (!histRatio) {
return nullptr;
}

// return a pair with the two histograms
return histRatio;
return o2::quality_control::checker::getPlotsFromCanvas(canvas, dummyMessage);
}

// Get the current and reference histograms from the canvas, and compare them using the comparator object passed as parameter
Expand All @@ -156,7 +94,7 @@ static Quality compare(TCanvas* canvas, ObjectComparatorInterface* comparator, s
}

// extract the histograms from the canvas
auto plots = getPlotsFromCanvas(canvas, message);
auto plots = o2::quality_control::checker::getPlotsFromCanvas(canvas, message);
if (!plots.first || !plots.second) {
return Quality::Null;
}
Expand Down Expand Up @@ -389,7 +327,7 @@ void ReferenceComparatorCheck::beautify(std::shared_ptr<MonitorObject> mo, Quali
setQualityLabel(canvas, quality);

// draw a double-arrow indicating the horizontal range for the check, if it is set
beautifyRatioPlot(moName, getRatioPlotFromCanvas(canvas), quality);
beautifyRatioPlot(moName, o2::quality_control::checker::getRatioPlotFromCanvas(canvas), quality);
} else {
// draw the quality label directly on the plot if the MO is an histogram
auto* th1 = dynamic_cast<TH1*>(mo->getObject());
Expand Down
27 changes: 15 additions & 12 deletions Modules/Common/src/ReferenceComparatorPlot.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -159,21 +159,21 @@ static std::shared_ptr<HIST> createHisto2D(const char* name, const char* title,
class ReferenceComparatorPlotImpl
{
public:
ReferenceComparatorPlotImpl(bool scaleReference)
: mScaleReference(scaleReference)
ReferenceComparatorPlotImpl(TH1* referenceHistogram, bool scaleReference)
: mReferenceHistogram(referenceHistogram), mScaleReference(scaleReference)
{
}

virtual ~ReferenceComparatorPlotImpl() = default;

virtual TObject* init(TH1* referenceHistogram, std::string outputPath, bool scaleReference, bool drawRatioOnly, std::string drawOption)
virtual TObject* getMainCanvas()
{
return nullptr;
}

virtual TObject* getMainCanvas()
TH1* getReferenceHistogram()
{
return nullptr;
return mReferenceHistogram;
}

void setScaleRef(bool scaleReference)
Expand All @@ -183,9 +183,10 @@ class ReferenceComparatorPlotImpl

bool getScaleReference() { return mScaleReference; }

virtual void update(TH1* histogram, TH1* referenceHistogram) = 0;
virtual void update(TH1* histogram) = 0;

private:
TH1* mReferenceHistogram{ nullptr };
bool mScaleReference{ true };
};

Expand All @@ -200,7 +201,7 @@ class ReferenceComparatorPlotImpl1D : public ReferenceComparatorPlotImpl
bool drawRatioOnly,
double legendHeight,
const std::string& drawOption)
: ReferenceComparatorPlotImpl(scaleReference), mLegendHeight(legendHeight)
: ReferenceComparatorPlotImpl(referenceHistogram, scaleReference), mLegendHeight(legendHeight)
{
float labelSize = 0.04;

Expand Down Expand Up @@ -343,8 +344,9 @@ class ReferenceComparatorPlotImpl1D : public ReferenceComparatorPlotImpl
return mCanvas.get();
}

void update(TH1* hist, TH1* referenceHistogram)
void update(TH1* hist)
{
TH1* referenceHistogram = getReferenceHistogram();
if (!hist || !referenceHistogram) {
return;
}
Expand Down Expand Up @@ -389,7 +391,7 @@ class ReferenceComparatorPlotImpl2D : public ReferenceComparatorPlotImpl
bool scaleReference,
bool drawRatioOnly,
const std::string& drawOption)
: ReferenceComparatorPlotImpl(scaleReference)
: ReferenceComparatorPlotImpl(referenceHistogram, scaleReference)
{
if (!referenceHistogram) {
return;
Expand Down Expand Up @@ -498,8 +500,9 @@ class ReferenceComparatorPlotImpl2D : public ReferenceComparatorPlotImpl
return mCanvas.get();
}

void update(TH1* histogram, TH1* referenceHistogram)
void update(TH1* histogram)
{
TH1* referenceHistogram = getReferenceHistogram();
if (!histogram || !referenceHistogram) {
return;
}
Expand Down Expand Up @@ -559,10 +562,10 @@ TObject* ReferenceComparatorPlot::getMainCanvas()
return (mImplementation.get() ? mImplementation->getMainCanvas() : nullptr);
}

void ReferenceComparatorPlot::update(TH1* histogram, TH1* referenceHistogram)
void ReferenceComparatorPlot::update(TH1* histogram)
{
if (mImplementation) {
mImplementation->update(histogram, referenceHistogram);
mImplementation->update(histogram);
}
}

Expand Down
17 changes: 13 additions & 4 deletions Modules/Common/src/ReferenceComparatorTask.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,18 @@ void ReferenceComparatorTask::initialize(quality_control::postprocessing::Trigge

//_________________________________________________________________________________________

std::shared_ptr<ReferenceComparatorPlot> ReferenceComparatorTask::getComparatorPlot(std::string plotName)
{
// check if a corresponding output plot was initialized
auto iter = mHistograms.find(plotName);
if (iter == mHistograms.end()) {
return {};
}
return iter->second;
}

//_________________________________________________________________________________________

void ReferenceComparatorTask::update(quality_control::postprocessing::Trigger trigger, framework::ServiceRegistryRef services)
{
auto& qcdb = services.get<repository::DatabaseInterface>();
Expand Down Expand Up @@ -194,10 +206,7 @@ void ReferenceComparatorTask::update(quality_control::postprocessing::Trigger tr
}

// update the plot ratios and the histograms with superimposed reference
auto referenceMO = mReferencePlots[plotName];
TH1* referenceHistogram = dynamic_cast<TH1*>(referenceMO->getObject());

iter->second->update(histogram, referenceHistogram);
iter->second->update(histogram);
}
}
}
Expand Down