ATLAS Offline Software
MaskedBinRow.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
9 #include <set>
10 #include <dqm_core/AlgorithmConfig.h>
13 #include <TH2.h>
14 #include <TF1.h>
15 #include <TClass.h>
16 #include <ers/ers.h>
17 
18 
19 #include <dqm_core/AlgorithmManager.h>
20 static dqm_algorithms::MaskedBinRow myInstance;
21 
22 
24 {
25  dqm_core::AlgorithmManager::instance().registerAlgorithm( "MaskedBinRow", this );
26 }
27 
29 {
30 }
31 
34 {
35  return new MaskedBinRow();
36 }
37 
38 
41  const TObject & object,
42  const dqm_core::AlgorithmConfig & config )
43 {
44  const TH2 * histogram;
45 
46  if(object.IsA()->InheritsFrom( "TH2" )) {
47  histogram = static_cast<const TH2*>(&object);
48  if (histogram->GetDimension() != 2 ){
49  throw dqm_core::BadConfig( ERS_HERE, name, "dimension != 2 " );
50  }
51  } else {
52  throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH2");
53  }
54 
55 
56  int maskedbin = dqm_algorithms::tools::GetFirstFromMap( "MaskedBin", config.getParameters());
57  int testrows = dqm_algorithms::tools::GetFirstFromMap( "TestRows", config.getParameters(), 0);
58  int okbin = dqm_algorithms::tools::GetFirstFromMap( "OkBin", config.getParameters(), -1);
59  int dorate = dqm_algorithms::tools::GetFirstFromMap( "DoRate", config.getParameters(), 0);
60  int checkstrip = dqm_algorithms::tools::GetFirstFromMap( "CheckStrip", config.getParameters(), 0);
61  int useReference = dqm_algorithms::tools::GetFirstFromMap( "UseReference", config.getParameters(), 0);
62  int useTotalEntries = dqm_algorithms::tools::GetFirstFromMap( "UseTotalEntries", config.getParameters(), 0);
63  int entriesBin = dqm_algorithms::tools::GetFirstFromMap( "EntriesBin", config.getParameters(), -1);
64 
65  std::set<int> ignoredBins;
66  for (const std::pair<std::string,double> keyValuePair : config.getParameters()) {
67  if (keyValuePair.first.compare(0, 9, "IgnoreBin") == 0) {
68  ignoredBins.insert(keyValuePair.second);
69  }
70  }
71 
72  TH2* refhist=0;
73  if (useReference) {
74  refhist = static_cast<TH2 *>( config.getReference() );
75  }
76 
77  if(refhist !=0){
78  if(refhist->InheritsFrom( "TH2" )) {
79  if (refhist->GetDimension() != 2 ){
80  throw dqm_core::BadConfig( ERS_HERE, name, "reference histogram dimension != 2 " );
81  }
82  } else {
83  throw dqm_core::BadConfig( ERS_HERE, name, "reference does not inherit from TH2");
84  }
85  if ((histogram->GetNbinsX() != refhist->GetNbinsX()) || (histogram->GetNbinsY() != refhist->GetNbinsY())) {
86  throw dqm_core::BadRefHist( ERS_HERE, "number of bins", name );
87  }
88  }
89  // if( refhist !=0 and okbin != -1 ){
90  // throw dqm_core::BadConfig( ERS_HERE, name, " MaskedBin is outside range" );
91  // }
92 
93  if ( !testrows && okbin > histogram->GetNbinsX() ) {
94  throw dqm_core::BadConfig( ERS_HERE, name, " MaskedBin is outside range" );
95  }
96  if ( testrows && okbin > histogram->GetNbinsY() ) {
97  throw dqm_core::BadConfig( ERS_HERE, name, " MaskedBin is outside range" );
98  }
99 
100  double gthreshold;
101  double rthreshold;
102  try {
103  rthreshold = dqm_algorithms::tools::GetFromMap( "BinThreshold", config.getRedThresholds() );
104  gthreshold = dqm_algorithms::tools::GetFromMap( "BinThreshold", config.getGreenThresholds() );
105  }
106  catch( dqm_core::Exception & ex ) {
107  throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
108  }
109 
110 
111  int redcount = 0;
112  int yellowcount = 0;
113  int redrows= 0;
114  int yellowrows = 0;
115  int totalEntries = 0;
116 
117  if (useTotalEntries) {
118  totalEntries = histogram->GetEntries();
119  if (totalEntries == 0) {
120  useTotalEntries = 0;
121  dorate = 0;
122  }
123  }
124 
125  if (entriesBin > -1) {
126  totalEntries = histogram->GetBinContent(entriesBin);
127  useTotalEntries = (totalEntries == 0) ? 0 : 1;
128  }
129 
131  int max = 1;
132  if(testrows){ max += histogram->GetNbinsY(); } else { max += histogram->GetNbinsX(); }
133  std::vector<float> rowtotal;
134  rowtotal.clear();
135 
136  if (dorate && !useTotalEntries) {
137  for(int i =0; i<max; ++i){ rowtotal.push_back(0.0); }
138 
139  for(int i =1; i< histogram->GetNbinsX()+1; ++i){
140  for(int j =1; j< histogram->GetNbinsY()+1; ++j){
141  if(testrows==0 && j == maskedbin ) continue;
142  if(testrows==1 && i == maskedbin ) continue;
143  if( testrows ) {
144  rowtotal[j-1] += histogram->GetBinContent(i,j);
145  } else {
146  rowtotal[i-1] += histogram->GetBinContent(i,j);
147  }
148  }
149  }
150  }
151 
152  // for(int i =0; i< rowtotal.size();++i){ out << rowtotal[i] << " " ; } std::cout<<std::endl;
153 
154  // ERS_DEBUG(1,"rowtotal =" << rowtotal) ;
155 
156  for(int i =1; i< histogram->GetNbinsX()+1; ++i){
157  for(int j =1; j< histogram->GetNbinsY()+1; ++j){
158  float bincontent= histogram->GetBinContent(i,j);
159  if (dorate) {
160  if (useTotalEntries) {
161  bincontent /= totalEntries;
162  } else if (testrows) {
163  bincontent /= rowtotal[j - 1];
164  } else {
165  bincontent /= rowtotal[i - 1];
166  }
167  }
168 
169  if(bincontent>gthreshold){
170  if( testrows==1 && histogram->GetBinContent(maskedbin,j) != 0) continue;
171  if( testrows==0 && histogram->GetBinContent(i,maskedbin) != 0) continue;
172 
173  int bin = histogram->GetBin(i, j);
174  if (ignoredBins.count(bin)) continue;
175 
176  if(refhist != 0){
177  if( refhist->GetBinContent(i,j) != 0){
178  if(bincontent < 1.0-gthreshold && bincontent > 1.0-rthreshold ) ++yellowrows;
179  if(bincontent < 1.0-rthreshold ) ++redrows;
180  continue;
181  }
182  }
183  if( testrows==0 && j == okbin){
184  if(bincontent < 1.0-gthreshold && bincontent > 1.0-rthreshold ) ++yellowrows;
185  if(bincontent < 1.0-rthreshold ) redrows++;
186  continue; }
187  if( testrows==1 && i == okbin){
188  if(bincontent < 1.0-gthreshold && bincontent > 1.0-rthreshold ) ++yellowrows;
189  if(bincontent < 1.0-rthreshold ) ++redrows;
190  continue; }
191 
192  ERS_DEBUG(1,"Found bin : ("<< i<< ","<<j<<" ) = " << bincontent ) ;
193 
195  if(bincontent>rthreshold){
196  ++redcount;
197  }else{
198  ++yellowcount;
199  }
200  }
201 
202  }
203  }
204 
205 
206  if (checkstrip) {
207  if (dorate) {
208  if(redrows > 0 ){
209  result->tags_["RedRows"] = redrows;
210  result->status_ = dqm_core::Result::Red;
211  return result;
212  } else if (yellowrows > 0 ){
213  result->tags_["YellowRows"] = yellowrows;
214  result->status_ = dqm_core::Result::Yellow;
215  return result;
216  }
217  }
218 
219  } else {
220  if( redcount > 0 ) {
221  result->tags_["RedBins"] = redcount;
222  result->status_ = dqm_core::Result::Red;
223  return result;
224  } else if(yellowcount > 0 ) {
225  result->tags_["YellowBins"] = yellowcount;
226  result->status_ = dqm_core::Result::Yellow;
227  return result;
228  }
229  }
230 
231 
232  result->status_ = dqm_core::Result::Green;
233  return result;
234 
235 }
236 
237 void
239 {
240 
241  out<<"MaskedBinRow: Does a bins over threshold test in columns/rows but ignores columns/rows if a 'masked' bin has entries\n"<<std::endl;
242 
243  out<<"Mandatory Parameter: MaskedBin : This is the row or column that has the 'masked' bins. \n"<<std::endl;
244 
245  out<<"Optional Parameter: TestRows : If masked bin has entries, ignore entries in row rather than columns when parameter is set to 1. default = 0 "<<std::endl;
246  out<<"Optional Parameter: OkBin : This is the row or column that has the 'ok' bin and will be ignored when preforming the algorithm "<<std::endl;
247  out<<"Optional Parameter: DoRate : This tells the algorithm to check the rate of digital errors rather than an absolute number"<<std::endl;
248  out<<"Optional Parameter: CheckStrip : To be used with DoRate. Rather than check individual bins, it checks that the fraction of events outside the ok bin is below the threshold."<<std::endl;
249  out<<"Optional Parameter: UseReference : Reference histogram with entries in the 'ok' bins will be used to indicate that these bins should be ignored when parameter is set to 1. default = 0 "<<std::endl;
250  out<<"Optional Parameter: UseTotalEntries : The rate of digital errors will be checked against total number of entries in histogram : default = 0 "<<std::endl;
251  out<<"Optional Parameter: EntriesBin : The rate of digital errors will be checked against content of global bin, if it is not negative : default = -1 "<<std::endl;
252  out<<"Optional Parameter: IgnoreBin* : Ignore during this test specified global bin, where * unique characters (can be used many times to ignore many bins)"<<std::endl;
253 }
get_generator_info.result
result
Definition: get_generator_info.py:21
max
#define max(a, b)
Definition: cfImp.cxx:41
IsA
#define IsA
Declare the TObject style functions.
Definition: xAODTEventBranch.h:59
dqm_algorithms::MaskedBinRow::printDescription
void printDescription(std::ostream &out)
Definition: MaskedBinRow.cxx:238
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
bin
Definition: BinsDiffFromStripMedian.h:43
dqm_algorithms::tools::PublishBin
void PublishBin(const TH1 *histogram, int xbin, int ybin, double content, dqm_core::Result *result)
Definition: AlgorithmHelper.cxx:426
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
MaskedBinRow.h
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
beamspotnt.totalEntries
int totalEntries
Definition: bin/beamspotnt.py:1182
lumiFormat.i
int i
Definition: lumiFormat.py:92
dqm_algorithms::MaskedBinRow::MaskedBinRow
MaskedBinRow()
Definition: MaskedBinRow.cxx:23
Result
ICscStripFitter::Result Result
Definition: CalibCscStripFitter.cxx:13
python.handimod.Green
int Green
Definition: handimod.py:524
TH2
Definition: rootspy.cxx:373
python.handimod.Red
Red
Definition: handimod.py:551
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
dqm_algorithms::MaskedBinRow
Definition: MaskedBinRow.h:19
dqm_algorithms::MaskedBinRow::execute
dqm_core::Result * execute(const std::string &, const TObject &, const dqm_core::AlgorithmConfig &)
Definition: MaskedBinRow.cxx:40
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
dqm_algorithms::MaskedBinRow::~MaskedBinRow
~MaskedBinRow()
Definition: MaskedBinRow.cxx:28
dqm_algorithms::MaskedBinRow::clone
MaskedBinRow * clone()
Definition: MaskedBinRow.cxx:33
histogram
std::string histogram
Definition: chains.cxx:52