Skip to content

Commit

Permalink
Add a generic reference data comparator
Browse files Browse the repository at this point in the history
The code introduces some tools that allow to compare the plots produced by given task(s) with that of a reference run:
- `ReferenceComparatorTask` draws histograms with their reference superimposed, as well as the ratio between histograms and reference
- `ReferenceComparatorCheck` compares the histograms with their corresponding reference, and assesses their compatibility. The comparison is performed by a dynamically loadable module that provides the actual comparison algorithm
- `ReferenceComparatorPlot` is an utility class to draw the current and reference histograms, and their ratio
- `ObjectComparator*` are dynamically loadable modules than implement different histogram comparison methods
  Two examples are provided:
    - `ObjectComparatorDeviation` evaluates the average relative difference between the histogram bins
    - `ObjectComparatorChi2` compares the histograms using a chi2-based test
  • Loading branch information
aferrero2707 committed May 31, 2024
1 parent 88e47b7 commit c18cd63
Show file tree
Hide file tree
Showing 15 changed files with 1,641 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Modules/Common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ target_sources(O2QcCommon
src/CcdbInspectorTask.cxx
src/CcdbInspectorTaskConfig.cxx
src/CcdbInspectorCheck.cxx
src/ObjectComparatorDeviation.cxx
src/ObjectComparatorChi2.cxx
src/ReferenceComparatorPlot.cxx
src/ReferenceComparatorTask.cxx
src/ReferenceComparatorTaskConfig.cxx
src/ReferenceComparatorCheck.cxx
src/NonEmpty.cxx
src/MeanIsAbove.cxx
src/TH1Reductor.cxx
Expand Down Expand Up @@ -54,6 +60,11 @@ add_root_dictionary(O2QcCommon
include/Common/BigScreen.h
include/Common/CcdbInspectorTask.h
include/Common/CcdbInspectorCheck.h
include/Common/ObjectComparatorInterface.h
include/Common/ObjectComparatorDeviation.h
include/Common/ObjectComparatorChi2.h
include/Common/ReferenceComparatorTask.h
include/Common/ReferenceComparatorCheck.h
include/Common/MeanIsAbove.h
include/Common/TH1Ratio.h
include/Common/TH2Ratio.h
Expand Down
4 changes: 4 additions & 0 deletions Modules/Common/include/Common/LinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
#pragma link C++ class o2::quality_control_modules::common::BigScreen + ;
#pragma link C++ class o2::quality_control_modules::common::CcdbInspectorTask + ;
#pragma link C++ class o2::quality_control_modules::common::CcdbInspectorCheck + ;
#pragma link C++ class o2::quality_control_modules::common::ObjectComparatorDeviation + ;
#pragma link C++ class o2::quality_control_modules::common::ObjectComparatorChi2 + ;
#pragma link C++ class o2::quality_control_modules::common::ReferenceComparatorTask + ;
#pragma link C++ class o2::quality_control_modules::common::ReferenceComparatorCheck + ;
#pragma link C++ class o2::quality_control_modules::common::WorstOfAllAggregator + ;
#pragma link C++ class o2::quality_control_modules::common::IncreasingEntries + ;
#pragma link C++ class o2::quality_control_modules::common::TH1SliceReductor + ;
Expand Down
42 changes: 42 additions & 0 deletions Modules/Common/include/Common/ObjectComparatorChi2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

///
/// \file ObjectComparatorChi2.h
/// \author Andrea Ferrero
/// \brief A class for comparing two histogram objects based on a chi2 test
///

#ifndef QUALITYCONTROL_ObjectComparatorChi2_H
#define QUALITYCONTROL_ObjectComparatorChi2_H

#include "Common/ObjectComparatorInterface.h"

namespace o2::quality_control_modules::common
{

/// \brief A class for comparing two histogram objects based on a chi2 test
class ObjectComparatorChi2 : public ObjectComparatorInterface
{
public:
/// \brief Constructor
ObjectComparatorChi2() = default;
/// \brief Destructor
virtual ~ObjectComparatorChi2() = default;

/// \brief objects comparison function
/// \return the quality resulting from the object comparison
o2::quality_control::core::Quality compare(TObject* obj, TObject* objRef, std::string& message) override;
};

} // namespace o2::quality_control_modules::common

#endif // QUALITYCONTROL_ObjectComparatorChi2_H
42 changes: 42 additions & 0 deletions Modules/Common/include/Common/ObjectComparatorDeviation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

///
/// \file ObjectComparatorDeviation.h
/// \author Andrea Ferrero
/// \brief A class for comparing two histogram objects based on the average of the relative deviation between the bins
///

#ifndef QUALITYCONTROL_ObjectComparatorDeviation_H
#define QUALITYCONTROL_ObjectComparatorDeviation_H

#include "Common/ObjectComparatorInterface.h"

namespace o2::quality_control_modules::common
{

/// \brief A class for comparing two histogram objects based on the average of the relative deviation between the bins
class ObjectComparatorDeviation : public ObjectComparatorInterface
{
public:
/// \brief Constructor
ObjectComparatorDeviation() = default;
/// \brief Destructor
virtual ~ObjectComparatorDeviation() = default;

/// \brief objects comparison function
/// \return the quality resulting from the object comparison
o2::quality_control::core::Quality compare(TObject* obj, TObject* objRef, std::string& message) override;
};

} // namespace o2::quality_control_modules::common

#endif // QUALITYCONTROL_ObjectComparatorDeviation_H
62 changes: 62 additions & 0 deletions Modules/Common/include/Common/ObjectComparatorInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

///
/// \file ObjectComparatorInterface.h
/// \author Andrea Ferrero
/// \brief An interface for comparing two TObject
///

#ifndef QUALITYCONTROL_ObjectComparatorInterface_H
#define QUALITYCONTROL_ObjectComparatorInterface_H

#include "QualityControl/Quality.h"
#include "QualityControl/CustomParameters.h"
#include "QualityControl/Activity.h"
class TObject;

namespace o2::quality_control_modules::common
{

/// \brief An interface for comparing two TObject
class ObjectComparatorInterface
{
public:
/// \brief Constructor
ObjectComparatorInterface() = default;
/// \brief Destructor
virtual ~ObjectComparatorInterface() = default;

/// \brief comparator configuration via CustomParameters
// virtual void configure(const o2::quality_control::core::CustomParameters& customParameters, const o2::quality_control::core::Activity activity = {}){};

/// setter/getter methods for the threshold to define the goodness of the comparison
void setThreshold(double threshold) { mThreshold = threshold; }
double getThreshold() { return mThreshold; }

/// setter/getter methods for the flag indicating wether the reference histogram shoould be normalized before performing the comparison
void setNormalizeReference(bool normalize) { mNormalizeReference = normalize; }
bool doNormalizeReference() { return mNormalizeReference; }

/// \brief objects comparison function
/// \return the quality resulting from the object comparison
virtual o2::quality_control::core::Quality compare(TObject* obj, TObject* objRef, std::string& message) = 0;

private:
/// the threshold to define the goodness of the comparison
double mThreshold{ 0 };
/// wether to normalize the reference histogram to the current one before performing the comparison
bool mNormalizeReference{ false };
};

} // namespace o2::quality_control_modules::common

#endif // QUALITYCONTROL_ObjectComparatorInterface_H
59 changes: 59 additions & 0 deletions Modules/Common/include/Common/ReferenceComparatorCheck.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

///
/// \file ReferenceComparatorCheck.h
/// \author Andrea Ferrero
/// \brief A generic QC check that compares a given set of histograms with their corresponding references
///

#ifndef QUALITYCONTROL_ReferenceComparatorCheck_H
#define QUALITYCONTROL_ReferenceComparatorCheck_H

#include "QualityControl/CheckInterface.h"
#include "Common/ObjectComparatorInterface.h"

#include <sstream>

class TPaveText;

namespace o2::quality_control_modules::common
{

/// \brief A generic QC check that compares a given set of histograms with their corresponding references
/// \author Andrea Ferrero
class ReferenceComparatorCheck : public o2::quality_control::checker::CheckInterface
{
public:
/// Default constructor
ReferenceComparatorCheck() = default;
/// Destructor
~ReferenceComparatorCheck() override = default;

// Override interface
void configure() override;
Quality check(std::map<std::string, std::shared_ptr<MonitorObject>>* moMap) override;
void reset() override;
void beautify(std::shared_ptr<MonitorObject> mo, Quality checkResult = Quality::Null) override;
std::string getAcceptedType() override;

void startOfActivity(const Activity& activity) override;
void endOfActivity(const Activity& activity) override;

private:
std::unique_ptr<ObjectComparatorInterface> mComparator;
std::map<std::string, Quality> mQualityFlags;
std::map<std::string, std::shared_ptr<TPaveText>> mQualityLabels;
};

} // namespace o2::quality_control_modules::common

#endif // QC_MODULE_SKELETON_ReferenceComparatorCheck_H
45 changes: 45 additions & 0 deletions Modules/Common/include/Common/ReferenceComparatorPlot.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

///
/// \file ReferenceComparatorPlot.h
/// \author Andrea Ferrero
/// \brief Utility class for the combined drawing of the current and reference plots, and their ratio
///

#ifndef QUALITYCONTROL_REFERENCECOMPARATORPLOT_H
#define QUALITYCONTROL_REFERENCECOMPARATORPLOT_H

#include <TH1.h>
#include <string>
#include <memory>

namespace o2::quality_control_modules::common
{

class ReferenceComparatorPlotImpl;

class ReferenceComparatorPlot
{
public:
ReferenceComparatorPlot(TH1* refHist, std::string outputPath, bool scaleRef, bool drawRatioOnly, std::string drawOption1D, std::string drawOption2D);
virtual ~ReferenceComparatorPlot() = default;

TObject* getObject();
void update(TH1* hist, TH1* histRef);

private:
std::shared_ptr<ReferenceComparatorPlotImpl> mImplementation;
};

} // namespace o2::quality_control_modules::common

#endif // QUALITYCONTROL_REFERENCECOMPARATORTASK_H
84 changes: 84 additions & 0 deletions Modules/Common/include/Common/ReferenceComparatorTask.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

///
/// \file ReferenceComparatorTask.h
/// \author Andrea Ferrero
/// \brief Post-processing task that compares a given set of plots with reference ones
///

#ifndef QUALITYCONTROL_REFERENCECOMPARATORTASK_H
#define QUALITYCONTROL_REFERENCECOMPARATORTASK_H

#include "Common/ReferenceComparatorTaskConfig.h"
#include "Common/BigScreenCanvas.h"
#include "QualityControl/PostProcessingInterface.h"
#include "QualityControl/DatabaseInterface.h"
#include "QualityControl/Quality.h"
#include <TH1.h>
#include <TPad.h>
#include <TCanvas.h>
#include <TPaveText.h>
#include <TText.h>
#include <string>
#include <map>

namespace o2::quality_control_modules::common
{

class ReferenceComparatorPlot;

/// \brief Post-processing task that compares a given set of plots with reference ones
///
/// For each input plot, the task publishes the ratio between the plot and the corresponding reference.
/// Moreover, for 1-D histograms it also publishes the plot itself with the reference superimposed, for visual comparison.
///
/// \author Andrea Ferrero
class ReferenceComparatorTask : public quality_control::postprocessing::PostProcessingInterface
{
public:
ReferenceComparatorTask() = default;
~ReferenceComparatorTask() override = default;

void configure(const boost::property_tree::ptree& config) override;
void initialize(quality_control::postprocessing::Trigger, framework::ServiceRegistryRef) override;
void update(quality_control::postprocessing::Trigger, framework::ServiceRegistryRef) override;
void finalize(quality_control::postprocessing::Trigger, framework::ServiceRegistryRef) override;

struct HistoWithRef {
std::shared_ptr<TH1> mPlot;
std::shared_ptr<TH1> mRefPlot;
std::shared_ptr<TH1> mRatioPlot;
std::shared_ptr<TPad> mPadHist;
std::shared_ptr<TPad> mPadHistRatio;
std::shared_ptr<TCanvas> mCanvas;
};

private:
std::shared_ptr<o2::quality_control::core::MonitorObject> getRefPlot(o2::quality_control::repository::DatabaseInterface& qcdb, std::string fullPath, o2::quality_control::core::Activity activity);
void updatePlot(std::string plotName, TObject* object);

int mRefRun{ 0 };
int mNotOlderThan{ 120 };

/// \brief configuration parameters
ReferenceComparatorTaskConfig mConfig;
/// \brief list of plot names, separately for each group
std::map<std::string, std::vector<std::string>> mPlotNames;
/// \brief reference MOs
std::map<std::string, std::shared_ptr<o2::quality_control::core::MonitorObject>> mRefPlots;
/// \brief histograms with comparison to reference
std::map<std::string, std::shared_ptr<ReferenceComparatorPlot>> mHistograms;
};

} // namespace o2::quality_control_modules::common

#endif // QUALITYCONTROL_REFERENCECOMPARATORTASK_H
Loading

0 comments on commit c18cd63

Please sign in to comment.