ATLAS Offline Software
DivideBin.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
9 #include <dqm_core/AlgorithmConfig.h>
12 #include <dqm_core/AlgorithmManager.h>
13 #include <TH1.h>
14 #include <TH2.h>
15 #include <TF1.h>
16 #include <TClass.h>
17 #include <ers/ers.h>
18 
19 static dqm_algorithms::DivideBin myInstance;
20 
22 
23 {
24  dqm_core::AlgorithmManager::instance().registerAlgorithm("DivideBin", this);
25 }
26 
29 {
30 
31  return new DivideBin();
32 }
33 
34 
37  const TObject & object,
38  const dqm_core::AlgorithmConfig & config)
39 {
40  const TH1 * histogram;
41 
42  if( object.IsA()->InheritsFrom( "TH1" ) ) {
43  histogram = static_cast<const TH1*>(&object);
44  if (histogram->GetDimension() > 2 ){
45  throw dqm_core::BadConfig( ERS_HERE, name, "dimension > 2 " );
46  }
47  } else {
48  throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" );
49  }
50 
51 
52  double gthresho;
53  double rthresho;
54  int xbin_num;
55  int xbin_denom;
56  try {
57  xbin_num = (int)dqm_algorithms::tools::GetFirstFromMap( "TestBin", config.getParameters());
58  xbin_denom = (int)dqm_algorithms::tools::GetFirstFromMap( "RefBin", config.getParameters());
59  }
60  catch ( dqm_core::Exception & ex ) {
61  throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
62  }
63 
64  try {
65  gthresho = dqm_algorithms::tools::GetFromMap( "Threshold", config.getGreenThresholds() );
66  rthresho = dqm_algorithms::tools::GetFromMap( "Threshold", config.getRedThresholds() );
67  }
68  catch ( dqm_core::Exception & ex ) {
69  throw dqm_core::BadConfig(ERS_HERE,name,"Parameter: 'Threshold' is mandatory, cannot continue");
70 
71  }
72 
73  const double minstat = dqm_algorithms::tools::GetFirstFromMap( "MinStat", config.getParameters(), -1);
74 
75  const double minrefentries = dqm_algorithms::tools::GetFirstFromMap( "MinRefEntries", config.getParameters(), 1 );
76 
77  if (histogram->GetEntries() < minstat ) {
79  result->tags_["InsufficientEntries"] = histogram->GetEntries();
80  return result;
81  }
82 
83  // Get the denominator
84  double hdenom = histogram->GetBinContent(xbin_denom);
85 
86  if ( minrefentries > 0 && hdenom < minrefentries) {
88  result->tags_["InsufficientRefEntries"] = hdenom;
89  return result;
90  }
91 
92  // Get the numerator
93  double hnum = histogram -> GetBinContent(xbin_num);
94 
95  double value = hnum/hdenom;
96 
98  result->tags_["BinRatio"] = value;
99 
100 if (rthresho < gthresho){
101  if ( value >= gthresho ) {
102  result->status_ = dqm_core::Result::Green;
103  } else if ( value < rthresho ) {
104  result->status_ = dqm_core::Result::Red;
105  } else {
106  result->status_ = dqm_core::Result::Yellow;
107  }
108 } else {
109  if ( value <= gthresho ) {
110  result->status_ = dqm_core::Result::Green;
111  } else if ( value > rthresho ) {
112  result->status_ = dqm_core::Result::Red;
113  } else {
114  result->status_ = dqm_core::Result::Yellow;
115  }
116 }
117 
118  return result;
119 }
120 
121 
123  out<<"DivideBin : Performs the division of a particular bin by the total entries in that histogram "<< std::endl;
124  out<<"Optional Parameter : MinStat : Minimum histogram statistics needed to perform Algorithm"<< std::endl;
125  out<<"Optional Parameter : MinRefEntries : Minimum number of entries in reference bin needed to perform Algorithm"<< std::endl;
126  out<<"Mandatory parameter: TestBin: Index of the bin in x that should be tested\n"<< std::endl;
127  out<<"Mandatory parameter: RefBin: Index of the bin in x that should be used as a reference\n"<< std::endl;
128 
129 }
130 
dqm_algorithms::DivideBin::execute
dqm_core::Result * execute(const std::string &, const TObject &, const dqm_core::AlgorithmConfig &)
Definition: DivideBin.cxx:36
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::DivideBin
Definition: DivideBin.h:19
dqm_algorithms::DivideBin::printDescription
void printDescription(std::ostream &out)
Definition: DivideBin.cxx:122
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
athena.value
value
Definition: athena.py:122
DivideBin.h
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
dqm_algorithms::DivideBin::DivideBin
DivideBin()
Definition: DivideBin.cxx:21
Result
ICscStripFitter::Result Result
Definition: CalibCscStripFitter.cxx:13
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:195
TH1
Definition: rootspy.cxx:268
dqm_algorithms::DivideBin::clone
DivideBin * clone()
Definition: DivideBin.cxx:28
AlgorithmHelper.h
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
dqm_algorithms::tools::GetFirstFromMap
double GetFirstFromMap(const std::string &paramName, const std::map< std::string, double > &params)
Definition: AlgorithmHelper.cxx:339
histogram
std::string histogram
Definition: chains.cxx:52