ATLAS Offline Software
Loading...
Searching...
No Matches
EfficiencyRefComp.cxx
Go to the documentation of this file.
1/*
2Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
8#include <TH1.h>
9#include <TClass.h>
10#include <TObjArray.h>
11#include <dqm_core/AlgorithmManager.h>
12
13#include <iostream>
14
15namespace{
16static dqm_algorithms::EfficiencyRefComp erc_instance;
17}
18
19
21 dqm_core::AlgorithmManager::instance().registerAlgorithm("EfficiencyRefComp",this);
22}
23
27
28dqm_core::Result* dqm_algorithms::EfficiencyRefComp::execute(const std::string& name, const TObject& object, const dqm_core::AlgorithmConfig& config){
29 const TH1 * histogram;
30
31 if( object.IsA()->InheritsFrom( "TH1" ) ) {
32 histogram = static_cast<const TH1*>(&object);
33 } else {
34 throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" );
35 }
36
37 const double minstat = dqm_algorithms::tools::GetFirstFromMap( "MinStat", config.getParameters(), -1);
38 const bool publish = (bool) dqm_algorithms::tools::GetFirstFromMap( "PublishBins", config.getParameters(), 0);
39 const int maxpublish = (int) dqm_algorithms::tools::GetFirstFromMap( "MaxPublish", config.getParameters(), 20);
40
41
42 if (histogram->GetEntries() < minstat ) {
43 dqm_core::Result *result = new dqm_core::Result(dqm_core::Result::Undefined);
44 result->tags_["InsufficientEffectiveEntries"] = histogram->GetEffectiveEntries();
45 return result;
46 }
47
48 TObject* ro = config.getReference();
49 const TObject* firstReference=0;
50 TObject* secondReference=0;
51 try {
52 dqm_algorithms::tools::handleReference( *ro , firstReference , secondReference );
53 }catch ( dqm_core::Exception & ex ) {
54 throw dqm_core::BadRefHist(ERS_HERE,name," Could not retreive reference");
55 }
56
57 //Check the reference
58 const TH1* refhist = dynamic_cast<const TH1*>(firstReference);
59 if ( refhist==0 ){
60 throw dqm_core::BadRefHist( ERS_HERE, "Dimension", name );
61 }
62
63 if ((histogram->GetDimension() != refhist->GetDimension()) || (histogram->GetNbinsX() != refhist->GetNbinsX()) || (histogram->GetNbinsY() != refhist->GetNbinsY()) || refhist->GetNbinsZ() != histogram->GetNbinsZ() ) {
64 throw dqm_core::BadRefHist( ERS_HERE, "number of bins", name );
65 }
66
67 //get range of input histograms
68 std::vector<int> range=dqm_algorithms::tools::GetBinRange(histogram, config.getParameters());
69
70 //get config
71 bool check_bin_err = (dqm_algorithms::tools::GetFirstFromMap("CheckBinErr", config.getParameters(), -1) > 0); //if the bin diff < err on bin ignore it
72 double posMaxDiff = dqm_algorithms::tools::GetFirstFromMap("PosMaxDiff", config.getParameters(), 1.0);
73 double negMaxDiff = dqm_algorithms::tools::GetFirstFromMap("NegMaxDiff", config.getParameters(), 1.0);
74
75 int count = 0;
76
77 dqm_core::Result* result = new dqm_core::Result();
78 TH1* resulthisto;
79 resulthisto=(TH1*)(histogram->Clone());
80 resulthisto->Reset();
81
82 //loop over each bin and calulcate the difference from the reference
83 for(int i=range[0]; i< range[1]; i++){
84 double binContent = histogram->GetBinContent(i);
85 double refContent = refhist->GetBinContent(i);
86 double binErr = histogram->GetBinError(i);
87
88 if(std::abs(binContent - refContent) < binErr && check_bin_err){
89 //difference between ref and bin content is less than 1 sigma
90 continue;
91 }
92
93 double diff = binContent - refContent;
94 double adiff = std::abs(diff);
95 double threshold = 1000;
96
97 if(diff < 0){
98 threshold = negMaxDiff;
99 }else{
100 threshold = posMaxDiff;
101 }
102
103 if(adiff > threshold){
104 //bin differs from reference by more than threshold
105 count++;
106 resulthisto->SetBinContent(i, binContent);
107 if (publish && count< maxpublish){
109 }
110 }
111 }
112
113 result->tags_["NBins"] = count;
114 result->object_ = boost::shared_ptr<TObject>(resulthisto);
115
116 double rthreshold = dqm_algorithms::tools::GetFromMap( "NBins", config.getRedThresholds() );
117 double gthreshold = dqm_algorithms::tools::GetFromMap( "NBins", config.getGreenThresholds() );
118
119 if(count >= rthreshold){
120 result->status_ = dqm_core::Result::Red;
121 }else if(count <= gthreshold){
122 result->status_ = dqm_core::Result::Green;
123 }else{
124 result->status_ = dqm_core::Result::Yellow;
125 }
126
127 return result;
128}
129
130
131
133 out<<"EfficiencyRefComp_: Compares each bin to the reference bin and calculates the difference. The difference for each bin is then compared to a threshold value. Different thresholds are supported for bins > ref and < ref."<<std::endl;
134}
void diff(const Jet &rJet1, const Jet &rJet2, std::map< std::string, double > varDiff)
Difference between jets - Non-Class function required by trigger.
Definition Jet.cxx:631
std::string histogram
Definition chains.cxx:52
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146
std::vector< int > GetBinRange(const TH1 *histogram, const std::map< std::string, double > &params)
double GetFirstFromMap(const std::string &paramName, const std::map< std::string, double > &params)
const T & GetFromMap(const std::string &pname, const std::map< std::string, T > &params)
void handleReference(const TObject &inputReference, const TObject *&firstReference, TObject *&secondReference)
Helper function used to handle complex reference histograms This function gets as input a reference o...
void PublishBin(const TH1 *histogram, int xbin, int ybin, double content, dqm_core::Result *result)
void printDescription(std::ostream &out)
dqm_core::Result * execute(const std::string &, const TObject &, const dqm_core::AlgorithmConfig &)
#define IsA
Declare the TObject style functions.