ATLAS Offline Software
BinDump.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // **********************************************************************
6 // $Id: BinDump.cxx,v 1.2 2009/02/07 09:37:17 Remi Lafaye
7 // **********************************************************************
8 
10 
11 #include <cmath>
12 #include <iostream>
13 #include <map>
14 #include <algorithm>
15 
16 #include <TClass.h>
17 #include <TH1.h>
18 #include <TAxis.h>
19 
20 #include "dqm_core/exceptions.h"
21 #include "dqm_core/AlgorithmConfig.h"
23 #include "dqm_core/AlgorithmManager.h"
24 #include "dqm_core/Result.h"
25 #include "ers/ers.h"
26 
27 
28 static dqm_algorithms::BinDump staticInstance;
29 
30 
31 namespace dqm_algorithms {
32 
33 // *********************************************************************
34 // Public Methods
35 // *********************************************************************
36 
38 BinDump()
39  : m_name("BinDump")
40 {
41  dqm_core::AlgorithmManager::instance().registerAlgorithm( m_name, this );
42 }
43 
44 
46 ~BinDump()
47 {
48 }
49 
50 
51 dqm_core::Algorithm*
53 clone()
54 {
55  return new BinDump(*this);
56 }
57 
58 
61 execute( const std::string& name, const TObject& object, const dqm_core::AlgorithmConfig& config)
62 {
63  const TH1 * histogram;
64 
65  if( object.IsA()->InheritsFrom( "TH1" ) ) {
66  histogram = static_cast<const TH1*>(&object);
67  if (histogram->GetDimension() > 2 ){
68  throw dqm_core::BadConfig( ERS_HERE, name, "dimension > 2 " );
69  }
70  } else {
71  throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" );
72  }
73 
74  int binStart, binEnd;
75  int method;
76  double gmin;
77  double rmin;
78  try {
79  binStart = (int) dqm_algorithms::tools::GetFirstFromMap("BinStart", config.getParameters() );
80  binEnd = (int) dqm_algorithms::tools::GetFirstFromMap("BinEnd", config.getParameters() );
81  method = (int) dqm_algorithms::tools::GetFirstFromMap("Method", config.getParameters() );
82  rmin = dqm_algorithms::tools::GetFromMap( "NEntries", config.getRedThresholds());
83  gmin = dqm_algorithms::tools::GetFromMap( "NEntries", config.getGreenThresholds() );
84  }
85  catch ( dqm_core::Exception & ex ) {
86  throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
87  }
88 
89  if (rmin < gmin) {
90  std::swap(rmin, gmin);
91  }
92 
93  double count = 0;
94  int nbinx = histogram -> GetNbinsX();
95  int nbiny = histogram -> GetNbinsY();
96  if(binStart>binEnd) {
97  binStart= 1;
98  binEnd = histogram -> GetNbinsX();
99  }
100  int binSize = binEnd-binStart+1;
101 
102  std::vector<double> contents(binSize);
103  //contents.resize(binSize);
104  for(int i=0;i<binSize;i++) {
105  int binx = binStart+i;
106  contents[i]=0;
107  for ( int j = 1; j <= nbiny; ++j ) {
108  double content= histogram -> GetBinContent(binx,j);
109  contents[i]+=content;
110  count+=content;
111  }
112  }
113 
114  ERS_DEBUG(1,"Number of entries for bins is "
115 << count );
116  ERS_DEBUG(1,"Green: "<< gmin << " entries; Red: " << rmin << " entries ");
117 
118 
119  const TAxis *axis = histogram->GetXaxis();
121  if(axis) {
122  for(int i=0;i<binSize;i++) {
123  char tag[256];
124  const char *label;
125  if(binStart+i==0) sprintf(tag,"Underflows");
126  else if(binStart+i==nbinx+1) sprintf(tag,"Overflows");
127  else {
128  label=axis->GetBinLabel(binStart+i);
129  // remove space in names to help handy.py
130  if(label) {
131  int l=strlen(label);
132  int j=0;
133 
134  char *mylabel=new char[l+1];
135  if(mylabel) {
136  for(int k=0;k<l;k++)
137  if(label[k]!=' ') mylabel[j++]=label[k];
138  mylabel[j]='\0';
139  if (mylabel[0]!=0) sprintf(tag,"%s",mylabel);
140  else sprintf(tag,"Bin%d",binStart+i);
141  delete[] mylabel;
142  }
143  else sprintf(tag,"Bin%d",binStart+i);
144  }
145  else sprintf(tag,"Bin%d",binStart+i);
146  }
147  result->tags_[tag] = contents[i];
148  }
149  } else {
150  for(int i=0;i<binSize;i++) {
151  char tag[256];
152  if(binStart+i==0) sprintf(tag,"Underflows");
153  else if(binStart+i==nbinx+1) sprintf(tag,"Overflows");
154  else sprintf(tag,"Bin%d",binStart+i);
155  result->tags_[tag] = contents[i];
156  }
157  }
158 
159  if(method==0) { // Check on bin sums
160  if ( count <= gmin ) {
161  result->status_ = dqm_core::Result::Green;
162  } else if ( count > rmin ) {
163  result->status_ = dqm_core::Result::Red;
164  } else {
165  result->status_ = dqm_core::Result::Yellow;
166  }
167  result->tags_["Total"] = count;
168  }
169  else if(method>0) { // Check on maximum bin
170  count = 0;
171  for(int i=0;i<binSize;i++) {
172  if(contents[i]>count) count = contents[i];
173  }
174  if ( count <= gmin ) {
175  result->status_ = dqm_core::Result::Green;
176  } else if ( count > rmin ) {
177  result->status_ = dqm_core::Result::Red;
178  } else {
179  result->status_ = dqm_core::Result::Yellow;
180  }
181  result->tags_["Highest"] = count;
182  }
183  else if(method<0) { // Check on minimum bin
184  count = 1e30;
185  for(int i=0;i<binSize;i++) {
186  if(contents[i]<count) count = contents[i];
187  }
188  if ( count <= gmin ) {
189  result->status_ = dqm_core::Result::Green;
190  } else if ( count > rmin ) {
191  result->status_ = dqm_core::Result::Red;
192  } else {
193  result->status_ = dqm_core::Result::Yellow;
194  }
195  result->tags_["Lowest"] = count;
196  }
197 
198  return result;
199 }
200 
201 
202 void
204 printDescription(std::ostream& out)
205 {
206  std::string message;
207  message += "\n";
208  message += "Algorithm: \"" + m_name + "\"\n";
209  message += "Description: Check the number of entries in listed bins\n";
210  message += "Parameters: BinStart first bin to be checked (0=underflows)\n";
211  message += " BinEnd last bin to be checked (nbin+1=overflows)\n";
212  message += " Method=0 check is performed on bin sum\n";
213  message += " Method<0 check is performed on lowest bin\n";
214  message += " Method>0 check is performed on highest bin\n";
215  message += " Nentries Green/Red minimums";
216  message += "\n";
217 
218  out << message;
219 }
220 
221 } // namespace dqm_algorithms
RunTileTBRec.method
method
Definition: RunTileTBRec.py:73
BinDump.h
get_generator_info.result
result
Definition: get_generator_info.py:21
dqm_algorithms::BinDump::m_name
std::string m_name
Definition: BinDump.h:29
IsA
#define IsA
Declare the TObject style functions.
Definition: xAODTEventBranch.h:59
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
yodamerge_tmp.axis
list axis
Definition: yodamerge_tmp.py:241
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
dqm_algorithms::BinDump::~BinDump
virtual ~BinDump()
Definition: BinDump.cxx:46
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
dqm_algorithms::BinDump
Definition: BinDump.h:16
ReweightUtils.message
message
Definition: ReweightUtils.py:15
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
dqm_algorithms::BinDump::printDescription
virtual void printDescription(std::ostream &out)
Definition: BinDump.cxx:204
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
grepfile.content
string content
Definition: grepfile.py:56
dqm_algorithms::BinDump::BinDump
BinDump()
Definition: BinDump.cxx:38
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
WriteCalibToCool.swap
swap
Definition: WriteCalibToCool.py:94
contents
void contents(std::vector< std::string > &keys, TDirectory *td, const std::string &directory, const std::string &pattern, const std::string &path)
Definition: computils.cxx:320
python.handimod.Red
Red
Definition: handimod.py:551
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
dqm_algorithms
Definition: AddReference.h:17
dqm_algorithms::BinDump::clone
virtual dqm_core::Algorithm * clone()
Definition: BinDump.cxx:53
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::BinDump::execute
virtual dqm_core::Result * execute(const std::string &name, const TObject &object, const dqm_core::AlgorithmConfig &config)
Definition: BinDump.cxx:61
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
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
fitman.k
k
Definition: fitman.py:528