ATLAS Offline Software
BasicHistoCheck.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 <TH1.h>
13 #include <TF1.h>
14 #include <TClass.h>
15 #include <ers/ers.h>
16 
17 #include <dqm_core/AlgorithmManager.h>
18 
19 namespace
20 {
21  dqm_algorithms::BasicHistoCheck Filling( "Histogram_Not_Empty" );
22  dqm_algorithms::BasicHistoCheck OverFlow( "No_OverFlows" );
23  dqm_algorithms::BasicHistoCheck UnderFlow( "No_UnderFlows" );
24  dqm_algorithms::BasicHistoCheck BinsFilled( "All_Bins_Filled" );
25 
26  dqm_algorithms::BasicHistoCheck Empty( "Histogram_Empty" );
27  dqm_algorithms::BasicHistoCheck EffectiveEmpty( "Histogram_Effective_Empty" );
28 }
29 
30 
32  : m_name( name )
33 {
34  dqm_core::AlgorithmManager::instance().registerAlgorithm(name, this);
35 }
36 
39 {
40 
41  return new BasicHistoCheck( m_name );
42 }
43 
44 
47  const TObject & object,
48  const dqm_core::AlgorithmConfig & config)
49 {
50  const TH1 * histogram;
51 
52  if( object.IsA()->InheritsFrom( "TH1" ) ) {
53  histogram = static_cast<const TH1*>(&object);
54  if (histogram->GetDimension() > 3 ){
55  throw dqm_core::BadConfig( ERS_HERE, name, "dimension > 3 " );
56  }
57  } else {
58  throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" );
59  }
60 
61  const double minstat = dqm_algorithms::tools::GetFirstFromMap( "MinStat", config.getParameters(), -1);
62 
63  if (histogram->GetEntries() < minstat ) {
65  result->tags_["InsufficientEntries"] = histogram->GetEntries();
66  return result;
67  }
68 
69  if (m_name == "Histogram_Not_Empty") {
70  if (histogram->GetEntries() != 0) {
71  ERS_DEBUG(1, "Histogram " <<histogram->GetName()<<" is Not Empty");
73  }else {
74  ERS_DEBUG(1, "Histogram " <<histogram->GetName()<<" is Empty");
76  }
77  } else if (m_name == "No_OverFlows" ) {
78  const unsigned int binsx = histogram->GetNbinsX()+1;
79  const unsigned int binsy = histogram->GetNbinsY()+1;
80  const unsigned int binsz = histogram->GetNbinsZ()+1;
81  switch (histogram->GetDimension()){
82  case 1:
83  if (histogram->GetBinContent(binsx) != 0) {
84  ERS_DEBUG(1, "Histogram " <<histogram->GetName()<<" has OverFlows X");
86  }
87  break;
88  case 2:
89  for (unsigned int i(0); i <= binsx; ++i)
90  if (histogram->GetBinContent(i,binsy) != 0) {
91  ERS_DEBUG(1, "Histogram " <<histogram->GetName()<<" has OverFlows Y");
93  }
94  for (unsigned int i(0); i <= binsy; ++i)
95  if (histogram->GetBinContent(binsx,i) != 0) {
96  ERS_DEBUG(1, "Histogram " <<histogram->GetName()<<" has OverFlows X");
98  }
99  break;
100  case 3:
101  for (unsigned int i(0); i <= binsx; ++i)
102  for (unsigned int j(0); j <= binsy; ++j)
103  if (histogram->GetBinContent(i,j,binsz) != 0) {
104  ERS_DEBUG(1, "Histogram " <<histogram->GetName()<<" has OverFlows Z");
106  }
107  for (unsigned int i(0); i <= binsx; ++i)
108  for (unsigned int j(0); j <= binsz; ++j)
109  if (histogram->GetBinContent(i,binsy,j) != 0) {
110  ERS_DEBUG(1, "Histogram " <<histogram->GetName()<<" has OverFlows Y");
112  }
113  for (unsigned int i(0); i <= binsz; ++i)
114  for (unsigned int j(0); j <= binsy; ++j)
115  if (histogram->GetBinContent(binsx,j,i) != 0) {
116  ERS_DEBUG(1, "Histogram " <<histogram->GetName()<<" has OverFlows X");
118  }
119  break;
120  default:
121  throw dqm_core::BadConfig( ERS_HERE, name, "Something is wrong with the Dimension of the Histogram");
122  }
123  ERS_DEBUG(1, "Histogram " <<histogram->GetName()<<" does NOT have OverFlows");
125  }else if (m_name == "No_UnderFlows") {
126  const unsigned int binsx = histogram->GetNbinsX()+1;
127  const unsigned int binsy = histogram->GetNbinsY()+1;
128  const unsigned int binsz = histogram->GetNbinsZ()+1;
129  switch (histogram->GetDimension()){
130  case 1:
131  if (histogram->GetBinContent(0) != 0) {
132  ERS_DEBUG(1, "Histogram " <<histogram->GetName()<<" has UnderFlows X");
134  }
135  break;
136  case 2:
137  for (unsigned int i(0); i <= binsx; ++i)
138  if (histogram->GetBinContent(i,0) != 0) {
139  ERS_DEBUG(1, "Histogram " <<histogram->GetName()<<" has UnderFlows Y");
141  }
142  for (unsigned int i(0); i <= binsy; ++i)
143  if (histogram->GetBinContent(0,i) != 0) {
144  ERS_DEBUG(1, "Histogram " <<histogram->GetName()<<" has UnderFlows X");
146  }
147  break;
148  case 3:
149  for (unsigned int i(0); i <= binsx; ++i)
150  for (unsigned int j(0); j <= binsy; ++j)
151  if (histogram->GetBinContent(i,j,0) != 0) {
152  ERS_DEBUG(1, "Histogram " <<histogram->GetName()<<" has UnderFlows Z");
154  }
155  for (unsigned int i(0); i <= binsx; ++i)
156  for (unsigned int j(0); j <= binsz; ++j)
157  if (histogram->GetBinContent(i,0,j) != 0) {
158  ERS_DEBUG(1, "Histogram " <<histogram->GetName()<<" has UnderFlows Y");
160  }
161  for (unsigned int i(0); i <= binsz; ++i)
162  for (unsigned int j(0); j <= binsy; ++j)
163  if (histogram->GetBinContent(0,j,i) != 0) {
164  ERS_DEBUG(1, "Histogram " <<histogram->GetName()<<" has UnderFlows X");
166  }
167  break;
168  default:
169  throw dqm_core::BadConfig( ERS_HERE, name, "Something is wrong with the Dimension of the Histogram");
170  }
171  ERS_DEBUG(1, "Histogram " <<histogram->GetName()<<" does NOT have UnderFlows");
173  } else if ( m_name == "All_Bins_Filled" ) {
174  const unsigned int binsx = histogram->GetNbinsX();
175  const unsigned int binsy = histogram->GetNbinsY();
176  const unsigned int binsz = histogram->GetNbinsZ();
177  for ( unsigned int i(1); i <= binsx; ++i ) {
178  for ( unsigned int j(1); j <= binsy; ++j ) {
179  for ( unsigned int k(1); k<= binsz; ++k ) {
180  double content= histogram -> GetBinContent(i,j);
181  if ( content == 0) {
182  ERS_DEBUG(1, "Histogram " <<histogram->GetName()<<" has empty bins");
184  }
185  }
186  }
187  }
188 
189  ERS_DEBUG(1, "Histogram " <<histogram->GetName()<<" has all filled bins");
191 
192 
193  } else if (m_name == "Histogram_Empty") {
194  if (histogram->GetEntries() == 0) {
195  ERS_DEBUG(1, "Histogram " <<histogram->GetName()<<" is Empty");
197  }else {
198  ERS_DEBUG(1, "Histogram " <<histogram->GetName()<<" is Not Empty");
200  }
201  } else if (m_name == "Histogram_Effective_Empty") {
202  if (histogram->GetEffectiveEntries() == 0) {
203  ERS_DEBUG(1, "Histogram " <<histogram->GetName()<<" is Empty");
205  }else {
206  ERS_DEBUG(1, "Histogram " <<histogram->GetName()<<" is Not Empty");
208  }
209 
210 
211  } else {
212  return new dqm_core::Result();
213  }
214 
215 
216 }
217 
218 void
220 {
221  if ( m_name == "All_Bins_Filled"){
222  out<<"All_Bins_Filled: Checks that all bins of histogram are filled\n"<<std::endl;
223  } else if ( m_name == "Histogram_Not_Empty"){
224  out<<"Histogram_Not_Empty: Checks that histogram is not empty\n"<<std::endl;
225  }else if ( m_name == "No_UnderFlows"){
226  out<<"No_UnderFlows: Checks that histogram has no Underflows"<<std::endl;
227  }else if ( m_name == "No_OverFlows"){
228  out<<"No_OverFlows: Checks that histogram has no Overflows"<<std::endl;
229 
230 
231  } else if ( m_name == "Histogram_Empty"){
232  out<<"Histogram_Empty: Checks that histogram is empty\n"<<std::endl;
233  } else if ( m_name == "Histogram_Effective_Empty"){
234  out<<"Histogram_Not_Empty:\tChecks that histogram has no effective entries\n\t\t\t(see ROOT doc -> TH1 -> GetEffectiveEntries())\n"<<std::endl;
235  }
236 
237  out<<"Optional Parameter: MinStat: Minimum histogram statistics needed to perform Algorithm\n"<<std::endl;
238 }
239 
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
dqm_algorithms::BasicHistoCheck::BasicHistoCheck
BasicHistoCheck(const std::string &name)
Definition: BasicHistoCheck.cxx:31
dqm_algorithms::BasicHistoCheck
Definition: BasicHistoCheck.h:19
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
grepfile.content
string content
Definition: grepfile.py:56
lumiFormat.i
int i
Definition: lumiFormat.py:85
Result
ICscStripFitter::Result Result
Definition: CalibCscStripFitter.cxx:13
python.handimod.Green
int Green
Definition: handimod.py:524
dqm_algorithms::BasicHistoCheck::clone
BasicHistoCheck * clone()
Definition: BasicHistoCheck.cxx:38
python.handimod.Red
Red
Definition: handimod.py:551
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
dqm_algorithms::BasicHistoCheck::printDescription
void printDescription(std::ostream &out)
Definition: BasicHistoCheck.cxx:219
BasicHistoCheck.h
AlgorithmHelper.h
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
dqm_algorithms::BasicHistoCheck::execute
dqm_core::Result * execute(const std::string &, const TObject &, const dqm_core::AlgorithmConfig &)
Definition: BasicHistoCheck.cxx:46
histogram
std::string histogram
Definition: chains.cxx:52
fitman.k
k
Definition: fitman.py:528