ATLAS Offline Software
EfficiencyRefComp.cxx
Go to the documentation of this file.
1 /*
2 Copyright (C) 2002-2024 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 
15 namespace{
16 static dqm_algorithms::EfficiencyRefComp erc_instance;
17 }
18 
19 
21  dqm_core::AlgorithmManager::instance().registerAlgorithm("EfficiencyRefComp",this);
22 }
23 
25  return new EfficiencyRefComp();
26 }
27 
28 dqm_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 ) {
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 
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>)(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 }
dqm_algorithms::tools::GetBinRange
std::vector< int > GetBinRange(const TH1 *histogram, const std::map< std::string, double > &params)
Definition: AlgorithmHelper.cxx:380
Undefined
@ Undefined
Definition: MaterialTypes.h:8
get_generator_info.result
result
Definition: get_generator_info.py:21
IsA
#define IsA
Declare the TObject style functions.
Definition: xAODTEventBranch.h:59
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
dqm_algorithms::EfficiencyRefComp::printDescription
void printDescription(std::ostream &out)
Definition: EfficiencyRefComp.cxx:132
EfficiencyRefComp.h
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
mc.diff
diff
Definition: mc.SFGenPy8_MuMu_DD.py:14
dqm_algorithms::tools::PublishBin
void PublishBin(const TH1 *histogram, int xbin, int ybin, double content, dqm_core::Result *result)
Definition: AlgorithmHelper.cxx:426
dqm_algorithms::EfficiencyRefComp::EfficiencyRefComp
EfficiencyRefComp()
Definition: EfficiencyRefComp.cxx:20
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
dqm_algorithms::EfficiencyRefComp::execute
dqm_core::Result * execute(const std::string &, const TObject &, const dqm_core::AlgorithmConfig &)
Definition: EfficiencyRefComp.cxx:28
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
dqm_algorithms::EfficiencyRefComp::clone
EfficiencyRefComp * clone()
Definition: EfficiencyRefComp.cxx:24
dqm_algorithms::EfficiencyRefComp
Definition: EfficiencyRefComp.h:15
lumiFormat.i
int i
Definition: lumiFormat.py:85
Result
ICscStripFitter::Result Result
Definition: CalibCscStripFitter.cxx:13
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
python.handimod.Green
int Green
Definition: handimod.py:524
python.handimod.Red
Red
Definition: handimod.py:551
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
threshold
Definition: chainparser.cxx:74
AlgorithmHelper.h
dqm_algorithms::tools::handleReference
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...
Definition: AlgorithmHelper.cxx:828
dqm_algorithms::tools::GetFromMap
const T & GetFromMap(const std::string &pname, const std::map< std::string, T > &params)
Definition: AlgorithmHelper.h:114
pickleTool.object
object
Definition: pickleTool.py:30
SimpleAlgorithmConfig.h
dqm_algorithms::tools::GetFirstFromMap
double GetFirstFromMap(const std::string &paramName, const std::map< std::string, double > &params)
Definition: AlgorithmHelper.cxx:339
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
histogram
std::string histogram
Definition: chains.cxx:52