ATLAS Offline Software
BinThresh.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include <cmath>
8 #include <iostream>
9 #include <map>
10 
11 #include <TH1.h>
12 #include <TProfile.h>
13 #include <TClass.h>
14 
15 #include "dqm_core/exceptions.h"
16 #include "dqm_core/AlgorithmManager.h"
17 #include "dqm_core/AlgorithmConfig.h"
18 #include "dqm_core/Result.h"
19 
20 static dqm_algorithms::BinThresh staticInstance;
21 
22 namespace dqm_algorithms {
23 
24  // *********************************************************************
25  // Public Methods
26  // *********************************************************************
27 
28  void
30  printDescription(std::ostream& out)
31  {
32  std::string message;
33  message += "\n";
34  message += "Algorithm: \"" + m_name + "\"\n";
35  message += "Description: Defines a warning and an error threshold for individual bins.\n";
36  message += " The status is the worst case summary of individual bin comparisons.\n";
37  message += " Some of the parameter names depend on whether the histogram is 1D or 2D.\n";
38  message += "Mandatory Parameter: UseValue:\n";
39  message += " 1: Flag bin contents >= Value\n";
40  message += " >1: Flag bin contents > Value\n";
41  message += " -1: Flag bin contents <= Value\n";
42  message += " <-1: Flag bin contents < Value\n";
43  message += "Mandatory Parameter: TypeValue:\n";
44  message += " 0: Value is compared to total entries in bin\n";
45  message += " 1: Value is compared to fraction of entries in histogram appearing in bin\n";
46  message += " This also determines how the bin contents will be listed if published.\n";
47  message += "Optional Parameter: Publish: Default = -1\n";
48  message += " -1: Print no values\n";
49  message += " 0: Print the number of bins exceeding their threshold\n";
50  message += " # > 0: Print bins exceeding their thresholds individually\n";
51  message += " At most # bins are printed, and the excess is also listed\n";
52  message += "Optional Parameter: TypePublish: Default = 0\n";
53  message += " 0: Print only bins exceeding their error threshold Values\n";
54  message += " 1: Print only bins exceeding their error or warning threshold Values\n";
55  message += " 2: Print all unmasked bins\n";
56  message += "Profile Configuration:\n";
57  message += "Optional Parameter: BinMinEntries: Default = 0\n";
58  message += " Minimum number of entries in a TProfile (1D only) for a bin to be checked against thresolds\n";
59  message += " If a bin does not have a sufficient number of entries it also will not be printed\n";
60  message += "1D Histogram Configuration:\n";
61  message += "Limits: Value_#\n";
62  message += " Arguments are given for individual bins.\n";
63  message += " To make a single threshold check, set Warning:Value == Error:Value\n";
64  message += " Example of asserting the thresholds for a 3 bin histogram with the 2nd bin masked\n";
65  message += " ***In thresholds declaration:\n";
66  message += " limits Value_1 {\n";
67  message += " warning = 0.0\n";
68  message += " error = 0.5\n";
69  message += " }\n";
70  message += " limits Value_3 {\n";
71  message += " warning = 2.0\n";
72  message += " error = 2.5\n";
73  message += " }\n";
74  message += "Limits: Value_All\n";
75  message += " Unmasks and sets thresholds uniformly for all bins.\n";
76  message += " Example of alternative declaration of the 3 bins histogram thresholds and masking above:\n";
77  message += " ***In algorithm declaration\n";
78  message += " Mask_2 = 1\n";
79  message += " ***In thresholds declaration:\n";
80  message += " limits Value_All {\n";
81  message += " warning = 0.0\n";
82  message += " error = 0.5\n";
83  message += " }\n";
84  message += " limits Value_3 {\n";
85  message += " warning = 2.0\n";
86  message += " error = 2.5\n";
87  message += " }\n";
88  message += "Optional Parameters: Mask_# Default = See Note below.\n";
89  message += " 1: Mask bin\n";
90  message += "2D Histogram Configuration:\n";
91  message += "Limits: Value_#_#\n";
92  message += " Arguments are given for individual bins.\n";
93  message += " Example of setting the X = 1, Y = 2 bin thresholds:\n";
94  message += " ***In thresholds declaration:\n";
95  message += " limits Value_1_2 {\n";
96  message += " warning = 2.0\n";
97  message += " error = 2.5\n";
98  message += " }\n";
99  message += "Optional Parameters: Mask_#_# Default = See Note below.\n";
100  message += " 1: Mask bin\n";
101  message += " Example of masking the X = 1, Y = 2 bin:\n";
102  message += " ***In algorithm declaration\n";
103  message += " Mask_1_2 = 1\n";
104  message += "Note Mask_## = 1 has precedence over the unmasking from a Value_## declaration\n";
105  message += "and that Value_## settings take precedence over the Value_All settings.\n";
106  message += "The un-masking option Mask_## = 0 is ignored in order to avoid unmasking an unconfigured bin.";
107 
108  out << message << std::endl;
109  }
110 
112  BinThresh()
113  : m_name("BinThresh")
114  , m_NbinsX(-1)
115  , m_NbinsY(-1)
116  {
117  dqm_core::AlgorithmManager::instance().registerAlgorithm( m_name, this );
118 
119  //NOTE: name will yield the entire directory structure
120  //leading up to the algorithm instance.
121  //This directory structure is used by other features such as result->tag.
122  }
123 
124 
126  ~BinThresh()
127  {
128  }
129 
130 
133  clone()
134  {
135  return new BinThresh(*this);
136  }
137 
138 
141  execute( const std::string& name, const TObject& data, const dqm_core::AlgorithmConfig& config)
142  {
144 
145  //Worst Case Summary default = Good
146  int NWarnings = 0;
147  int NErrors = 0;
148  int NGoodPrint = 0;
149  //Histogram dimension default = no dimensions
150  m_NbinsX = -1;
151  m_NbinsY = -1;
152 
153  //Get data
154  if (!data.IsA()->InheritsFrom("TH1")) {
155  throw dqm_core::BadConfig(ERS_HERE, name, "does not inherit from TH1");
156  }
157  const TH1* h = static_cast<const TH1*>(&data); // h cannot be null
158  if (h->GetDimension() > 2) {
159  throw dqm_core::BadConfig(ERS_HERE, name, "dimension > 2 ");
160  }
161 
162  //Get optional parameters
163  int Publish = Publish_GetFromMap(config.getParameters());
164  int TypePublish = TypePublish_GetFromMap(config.getParameters());
165  int BinMinEntries = BinMinEntries_GetFromMap(config.getParameters());
166 
167  //Get mandatory parameters
168  int UseValue;
169  int TypeValue;
170  try {
171  UseValue = UseValue_GetFromMap(config.getParameters());
172  TypeValue = TypeValue_GetFromMap(config.getParameters());
173  }
174  catch (dqm_core::Exception & ex) {
175  throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
176  }
177  if ( UseValue == 0 ) ERS_INFO("UseValue == 0 is meaningless");
178 
179  //**********
180  // Profile case
181  //**********
182  if ( data.IsA()->InheritsFrom("TProfile") ) {
183  const TProfile* hp = static_cast<const TProfile*>(&data);
184  //ASSUME: dimension = 1
185  m_NbinsX = hp->GetNbinsX();
186 
187  //Get threshold limits & masks
188  std::vector<BinThresh::mask_limits> Limits;
189  try {
190  Limits = Limits1D_GetFromMap(config.getParameters(), config.getGreenThresholds(), config.getRedThresholds());
191  }
192  catch (dqm_core::Exception & ex) {
193  throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
194  }
195  //CHECK
196  //Verify threshold limit consistencies
197  for(int bin = 0; bin < m_NbinsX; bin++) {
198  if ((UseValue > 0 && Limits[bin].WarningValue > Limits[bin].ErrorValue) ||
199  (UseValue < 0 && Limits[bin].WarningValue < Limits[bin].ErrorValue)) {
200  //Masked thresholds might be used for a different algorithm configuration
201  if ( !Limits[bin].Mask ) {
202  std::string problem_message = Form("Incompatible Warning and Error Values in bin_%d : Warning = %e -> Error = %e", bin + 1, Limits[bin].WarningValue, Limits[bin].ErrorValue);
203  ERS_INFO(problem_message.c_str());
204  }
205  }
206  }
207 
208  //Rescale Thresholds to test fractional distribution
209  double h_entries = hp->GetEntries();
210  if ( TypeValue ) {
211  for (int bin = 0; bin < m_NbinsX; bin++) {
212  Limits[bin].WarningValue = Limits[bin].WarningValue * h_entries;
213  Limits[bin].ErrorValue = Limits[bin].ErrorValue * h_entries;
214  }
215  }
216 
217  //Check all bins
218  for (int bin = 0; bin < m_NbinsX; bin++) {
219  double bincon = hp->GetBinContent(bin + 1);
220  if ( !Limits[bin].Mask && hp->GetBinEntries(bin + 1) >= BinMinEntries ) {
221  //Check for and Print errors
222  if ((UseValue == 1 && bincon >= Limits[bin].ErrorValue) ||
223  (UseValue > 1 && bincon > Limits[bin].ErrorValue) ||
224  (UseValue == -1 && bincon <= Limits[bin].ErrorValue) ||
225  (UseValue < -1 && bincon < Limits[bin].ErrorValue) ) {
226  NErrors++;
227  if ( NErrors + NWarnings + NGoodPrint <= Publish ) { //Publish Errors
228  double binval = hp->GetXaxis()->GetBinCenter(bin + 1);
229  //Give bin number as well as bin center
230  //Use scientific notation (e) to be compatible with all axis scales
231  //Include 2 digits after decimal (.*, with *=2) so that partitions up to 1000 are covered.
232  //If using fractional thresholds, then print fractional values.
233  std::string binname = Form("%s_ErrorBin(%u | %.*e)", name.c_str(), bin, 2, binval);
234  //From() ~ printf() (s ~ string, u ~ unsigned int, .*e ~ scientific)
235  if ( TypeValue > 0.5 ) {
236  result->tags_[binname.c_str()] = (bincon / h_entries);
237  } else {
238  result->tags_[binname.c_str()] = bincon;
239  }
240  }
241  }
242  //Check for and Print warnings, if no Errors found
243  else if ((UseValue == 1 && bincon >= Limits[bin].WarningValue) ||
244  (UseValue > 1 && bincon > Limits[bin].WarningValue) ||
245  (UseValue == -1 && bincon <= Limits[bin].WarningValue) ||
246  (UseValue < -1 && bincon < Limits[bin].WarningValue) ) {
247  NWarnings++;
248  if ( TypePublish >= 1 && NErrors + NWarnings + NGoodPrint <= Publish ) { //Publish Warnings
249  float binval = hp->GetXaxis()->GetBinCenter(bin + 1);
250  //Use scientific notation (e) to be compatible with all axis scales
251  //Include 2 digits after decimal (.*, with *=2) so that partitions up to 1000 are covered.
252  //If using fractional thresholds, then print fractional values.
253  std::string binname = Form("%s_WarningBin(%u | %.*e)", name.c_str(), bin, 2, binval);
254  if ( TypeValue > 0.5 ) {
255  result->tags_[binname.c_str()] = (bincon / h_entries);
256  } else {
257  result->tags_[binname.c_str()] = bincon;
258  }
259  }
260  }
261  //Print remaining bins
262  else {
263  NGoodPrint++;
264  if ( TypePublish >= 2 && NErrors + NWarnings + NGoodPrint <= Publish ) { //Publish Good Bins
265  float binval = hp->GetXaxis()->GetBinCenter(bin + 1);
266  //Use scientific notation (e) to be compatible with all axis scales
267  //Include 2 digits after decimal (.*, with *=2) so that partitions up to 1000 are covered.
268  //If using fractional thresholds, then print fractional values.
269  std::string binname = Form("%s_GoodBin(%u | %.*e)", name.c_str(), bin, 2, binval);
270  if ( TypeValue > 0.5 ) {
271  result->tags_[binname.c_str()] = (bincon / h_entries);
272  } else {
273  result->tags_[binname.c_str()] = bincon;
274  }
275  }
276  }
277  }
278  }
279  }
280 
281  //**********
282  // 1D Histogram case
283  //**********
284  if ( (! data.IsA()->InheritsFrom("TProfile")) && h->GetDimension() == 1 ) {
285  m_NbinsX = h->GetNbinsX();
286 
287  //Get threshold limits & masks
288  std::vector<BinThresh::mask_limits> Limits;
289  try {
290  Limits = Limits1D_GetFromMap(config.getParameters(), config.getGreenThresholds(), config.getRedThresholds());
291  }
292  catch (dqm_core::Exception & ex) {
293  throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
294  }
295  //CHECK
296  //Verify threshold limit consistencies
297  for(int bin = 0; bin < m_NbinsX; bin++) {
298  if ((UseValue > 0 && Limits[bin].WarningValue > Limits[bin].ErrorValue) ||
299  (UseValue < 0 && Limits[bin].WarningValue < Limits[bin].ErrorValue)) {
300  //Masked thresholds might be used for a different algorithm configuration
301  if ( !Limits[bin].Mask ) {
302  std::string problem_message = Form("Incompatible Warning and Error Values in bin_%d : Warning = %e -> Error = %e", bin + 1, Limits[bin].WarningValue, Limits[bin].ErrorValue);
303  ERS_INFO(problem_message.c_str());
304  }
305  }
306  }
307 
308  //Rescale Thresholds to test fractional distribution
309  double h_entries = h->GetEntries();
310  if ( TypeValue ) {
311  for (int bin = 0; bin < m_NbinsX; bin++) {
312  Limits[bin].WarningValue = Limits[bin].WarningValue * h_entries;
313  Limits[bin].ErrorValue = Limits[bin].ErrorValue * h_entries;
314  }
315  }
316 
317  //Check all bins
318  for (int bin = 0; bin < m_NbinsX; bin++) {
319  double bincon = h->GetBinContent(bin + 1);
320  if ( !Limits[bin].Mask ) {
321  //Check for and Print errors
322  if ((UseValue == 1 && bincon >= Limits[bin].ErrorValue) ||
323  (UseValue > 1 && bincon > Limits[bin].ErrorValue) ||
324  (UseValue == -1 && bincon <= Limits[bin].ErrorValue) ||
325  (UseValue < -1 && bincon < Limits[bin].ErrorValue) ) {
326  NErrors++;
327  if ( NErrors + NWarnings + NGoodPrint <= Publish ) { //Publish Errors
328  double binval = h->GetXaxis()->GetBinCenter(bin + 1);
329  //Give bin number as well as bin center
330  //Use scientific notation (e) to be compatible with all axis scales
331  //Include 2 digits after decimal (.*, with *=2) so that partitions up to 1000 are covered.
332  //If using fractional thresholds, then print fractional values.
333  std::string binname = Form("%s_ErrorBin(%u | %.*e)", name.c_str(), bin, 2, binval);
334  //From() ~ printf() (s ~ string, u ~ unsigned int, .*e ~ scientific)
335  if ( TypeValue > 0.5 ) {
336  result->tags_[binname.c_str()] = (bincon / h_entries);
337  } else {
338  result->tags_[binname.c_str()] = bincon;
339  }
340  }
341  }
342  //Check for and Print warnings, if no Errors found
343  else if ((UseValue == 1 && bincon >= Limits[bin].WarningValue) ||
344  (UseValue > 1 && bincon > Limits[bin].WarningValue) ||
345  (UseValue == -1 && bincon <= Limits[bin].WarningValue) ||
346  (UseValue < -1 && bincon < Limits[bin].WarningValue) ) {
347  NWarnings++;
348  if ( TypePublish >= 1 && NErrors + NWarnings + NGoodPrint <= Publish ) { //Publish Warnings
349  float binval = h->GetXaxis()->GetBinCenter(bin + 1);
350  //Use scientific notation (e) to be compatible with all axis scales
351  //Include 2 digits after decimal (.*, with *=2) so that partitions up to 1000 are covered.
352  //If using fractional thresholds, then print fractional values.
353  std::string binname = Form("%s_WarningBin(%u | %.*e)", name.c_str(), bin, 2, binval);
354  if ( TypeValue > 0.5 ) {
355  result->tags_[binname.c_str()] = (bincon / h_entries);
356  } else {
357  result->tags_[binname.c_str()] = bincon;
358  }
359  }
360  }
361  //Print remaining bins
362  else {
363  NGoodPrint++;
364  if ( TypePublish >= 2 && NErrors + NWarnings + NGoodPrint <= Publish ) { //Publish Good Bins
365  float binval = h->GetXaxis()->GetBinCenter(bin + 1);
366  //Use scientific notation (e) to be compatible with all axis scales
367  //Include 2 digits after decimal (.*, with *=2) so that partitions up to 1000 are covered.
368  //If using fractional thresholds, then print fractional values.
369  std::string binname = Form("%s_GoodBin(%u | %.*e)", name.c_str(), bin, 2, binval);
370  if ( TypeValue > 0.5 ) {
371  result->tags_[binname.c_str()] = (bincon / h_entries);
372  } else {
373  result->tags_[binname.c_str()] = bincon;
374  }
375  }
376  }
377  }
378  }
379  }
380 
381  //**********
382  // 2D Histogram case
383  //**********
384  if ( (! data.IsA()->InheritsFrom("TProfile")) && h->GetDimension() == 2 ) {
385  m_NbinsX = h->GetNbinsX();
386  m_NbinsY = h->GetNbinsY();
387 
388  //Get threshold limits & masks
389  std::vector< std::vector<BinThresh::mask_limits> > Limits;
390  try {
391  Limits = Limits2D_GetFromMap(config.getParameters(), config.getGreenThresholds(), config.getRedThresholds());
392  }
393  catch (dqm_core::Exception & ex) {
394  throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
395  }
396  //CHECK
397  //Verify threshold limit consistencies
398  for(int binX = 0; binX < m_NbinsX; binX++) {
399  for(int binY = 0; binY < m_NbinsY; binY++) {
400  if ( (UseValue > 0 && Limits[binX][binY].WarningValue > Limits[binX][binY].ErrorValue) ||
401  (UseValue < 0 && Limits[binX][binY].WarningValue < Limits[binX][binY].ErrorValue)) {
402  //Masked thresholds might be used for a different algorithm configuration
403  if ( !Limits[binX][binY].Mask ) {
404  std::string problem_message = Form("Incompatible Warning and Error Values in bin_%d_%d : Warning = %e -> Error = %e", binX + 1, binY + 1, Limits[binX][binY].WarningValue, Limits[binX][binY].ErrorValue);
405  ERS_INFO(problem_message.c_str());
406  }
407  }
408  }}
409 
410  //Rescale Thresholds to test fractional distribution
411  double h_entries = h->GetEntries();
412  if ( TypeValue ) {
413  for (int binX = 0; binX < m_NbinsX; binX++) {
414  for (int binY = 0; binY < m_NbinsY; binY++) {
415  Limits[binX][binY].WarningValue = Limits[binX][binY].WarningValue * h_entries;
416  Limits[binX][binY].ErrorValue = Limits[binX][binY].ErrorValue * h_entries;
417  }}
418  }
419 
420  //Check all bins
421  for (int binX = 0; binX < m_NbinsX; binX++) {
422  for (int binY = 0; binY < m_NbinsY; binY++) {
423  double bincon = h->GetBinContent(binX + 1, binY + 1);
424  if ( !Limits[binX][binY].Mask ) {
425  //Check for and Print errors
426  if ( (UseValue == 1 && bincon >= Limits[binX][binY].ErrorValue) ||
427  (UseValue > 1 && bincon > Limits[binX][binY].ErrorValue) ||
428  (UseValue == -1 && bincon <= Limits[binX][binY].ErrorValue) ||
429  (UseValue < -1 && bincon < Limits[binX][binY].ErrorValue) ) {
430  NErrors++;
431  if ( NErrors + NWarnings + NGoodPrint <= Publish ) { //Publish Errors
432  float binvalX = h->GetXaxis()->GetBinCenter(binX + 1);
433  float binvalY = h->GetYaxis()->GetBinCenter(binY + 1);
434  std::string binname = Form("%s_ErrorBin((%u,%u) | %.*e,%.*e)", name.c_str(), binX, binY, 2, binvalX, 2, binvalY);
435  //From() ~ printf() (s ~ string, u ~ unsigned int, .*e ~ scientific)
436  if ( TypeValue > 0.5 ) {
437  result->tags_[binname.c_str()] = (bincon / h_entries);
438  } else {
439  result->tags_[binname.c_str()] = bincon;
440  }
441  }
442  }
443  //Check for and Print warnings
444  else if ( (UseValue == 1 && bincon >= Limits[binX][binY].WarningValue) ||
445  (UseValue > 1 && bincon > Limits[binX][binY].WarningValue) ||
446  (UseValue == -1 && bincon <= Limits[binX][binY].WarningValue) ||
447  (UseValue < -1 && bincon < Limits[binX][binY].WarningValue) ) {
448  NWarnings++;
449  if ( TypePublish >= 1 && NErrors + NWarnings + NGoodPrint <= Publish ) { //Publish Warnings
450  float binvalX = h->GetXaxis()->GetBinCenter(binX + 1);
451  float binvalY = h->GetYaxis()->GetBinCenter(binY + 1);
452  std::string binname = Form("%s_WarningBin((%u,%u) | %.*e,%.*e)", name.c_str(), binX, binY, 2, binvalX, 2, binvalY);
453  if ( TypeValue > 0.5 ) {
454  result->tags_[binname.c_str()] = (bincon / h_entries);
455  } else {
456  result->tags_[binname.c_str()] = bincon;
457  }
458  }
459  }
460  //Print remaining bins
461  else {
462  NGoodPrint++;
463  if ( TypePublish >= 2 && NErrors + NWarnings + NGoodPrint <= Publish ) { //Publish Good Bins
464  float binvalX = h->GetXaxis()->GetBinCenter(binX + 1);
465  float binvalY = h->GetYaxis()->GetBinCenter(binY + 1);
466  std::string binname = Form("%s_GoodBin((%u,%u) | %.*e,%.*e)", name.c_str(), binX, binY, 2, binvalX, 2, binvalY);
467  if ( TypeValue > 0.5 ) {
468  result->tags_[binname.c_str()] = (bincon / h_entries);
469  } else {
470  result->tags_[binname.c_str()] = bincon;
471  }
472  }
473  }
474  }
475  }}
476  }
477 
478  //Print Number of Errors & Warnings
479  if ( Publish >= 0 ) {
480  std::string pub_error = Form("%s_Bin_Errors", name.c_str());
481  result->tags_[pub_error.c_str()] = NErrors;
482  if ( TypePublish >= 1 ) {
483  std::string pub_warning = Form("%s_Bin_Warnings", name.c_str());
484  result->tags_[pub_warning.c_str()] = NWarnings;
485  }
486  }
487 
488  //Set Flag as worst case summary of all bins
489  if ( (NErrors == 0) && (NWarnings == 0) ) result->status_ = dqm_core::Result::Green;
490  if ( (NErrors == 0) && (NWarnings > 0) ) result->status_ = dqm_core::Result::Yellow;
491  if ( (NErrors > 0) ) result->status_ = dqm_core::Result::Red;
492 
493  return(result);
494  }
495 
496  // *********************************************************************
497  // Protected Methods
498  // *********************************************************************
499 
500  int BinThresh::Publish_GetFromMap(const std::map<std::string, double> & params)
501  {
502  std::map<std::string, double>::const_iterator it = params.find("Publish");
503  if ( it != params.end() ) {
504  return((int) it->second);
505  }else {
506  return(0);
507  }
508  }
509 
510  int BinThresh::TypePublish_GetFromMap(const std::map<std::string, double> & params)
511  {
512  std::map<std::string, double>::const_iterator it = params.find("TypePublish");
513  if ( it != params.end() ) {
514  if ( it->second > 1.5 ) return(2);
515  else if ( it->second > 0.5 ) return(1);
516  else return(0);
517  }else {
518  return(0);
519  }
520  }
521 
522  int BinThresh::UseValue_GetFromMap(const std::map<std::string, double> & params)
523  {
524  std::map<std::string, double>::const_iterator it = params.find("UseValue");
525  if ( it != params.end() ) {
526  return((int) it->second);
527  }else {
528  return(0);
529  }
530  }
531 
532  int BinThresh::TypeValue_GetFromMap(const std::map<std::string, double> & params)
533  {
534  std::map<std::string, double>::const_iterator it = params.find("TypeValue");
535  if ( it != params.end() ) {
536  if ( it->second > 0.5 ) return(1);
537  else return(0);
538  }else {
539  return(0);
540  }
541  }
542 
543  int BinThresh::BinMinEntries_GetFromMap(const std::map<std::string, double> & params)
544  {
545  std::map<std::string, double>::const_iterator it = params.find("BinMinEntries");
546  if ( it != params.end() ) {
547  return((int) it->second);
548  }else {
549  return(0);
550  }
551  }
552 
553  std::vector<BinThresh::mask_limits> BinThresh::Limits1D_GetFromMap( const std::map<std::string, double> & params,
554  const std::map<std::string, double> & warning_params,
555  const std::map<std::string, double> & error_params )
556  {
557  std::map<std::string, double>::const_iterator warning_map_bin;
558  std::map<std::string, double>::const_iterator error_map_bin;
559  std::map<std::string, double>::const_iterator mask_map_bin;
560 
561  //Make Default Limit Values & Masking
562  BinThresh::mask_limits default_Limits;
563  default_Limits.WarningValue = 0.0;
564  default_Limits.ErrorValue = 0.0;
565  default_Limits.Mask = true;
566 
567  //Check for Value_All thresholds to use for all bins
568  warning_map_bin = warning_params.find("Value_All");
569  error_map_bin = error_params.find("Value_All");
570  if ( warning_map_bin != warning_params.end() &&
571  error_map_bin != error_params.end() ) {
572  default_Limits.WarningValue = warning_map_bin->second;
573  default_Limits.ErrorValue = error_map_bin->second;
574  default_Limits.Mask = false;
575  }
576 
577  //Make default threshold & mask
578  std::vector<BinThresh::mask_limits> Limits(m_NbinsX, default_Limits);
579 
580  //Get specific bin limits and unmasked bins
581  for ( int bin = 0; bin < m_NbinsX; bin++ ) {
582  std::string value_bin = Form("Value_%d", bin + 1);
583  //Get thresholds for bin
584  warning_map_bin = warning_params.find(value_bin.c_str());
585  error_map_bin = error_params.find(value_bin.c_str());
586  if ( warning_map_bin != warning_params.end() &&
587  error_map_bin != error_params.end() ) {
588  Limits[bin].WarningValue = warning_map_bin->second;
589  Limits[bin].ErrorValue = error_map_bin->second;
590  Limits[bin].Mask = false;
591  }
592 
593  //Mask out specified bins
594  //The masking that is explicitly defined takes precedence over the implied masking from the thresholds
595  std::string mask_bin = Form("Mask_%d", bin + 1);
596  mask_map_bin = params.find(mask_bin.c_str());
597  if ( mask_map_bin != params.end() ) {
598  if(mask_map_bin->second > 0.5) Limits[bin].Mask = true;
599  //UnMasking should never be necessary
600  }
601  }
602 
603  return(Limits);
604  }
605 
606  std::vector< std::vector<BinThresh::mask_limits> > BinThresh::Limits2D_GetFromMap( const std::map<std::string, double> & params,
607  const std::map<std::string, double> & warning_params,
608  const std::map<std::string, double> & error_params )
609  {
610  std::map<std::string, double>::const_iterator warning_map_bin;
611  std::map<std::string, double>::const_iterator error_map_bin;
612  std::map<std::string, double>::const_iterator mask_map_bin;
613 
614  //Make Default Limit Values & Masking
615  BinThresh::mask_limits default_Limits;
616  default_Limits.WarningValue = 0.0;
617  default_Limits.ErrorValue = 0.0;
618  default_Limits.Mask = true;
619 
620  //Check for Value_All thresholds to use for all bins
621  warning_map_bin = warning_params.find("Value_All");
622  error_map_bin = error_params.find("Value_All");
623  if ( warning_map_bin != warning_params.end() &&
624  error_map_bin != error_params.end() ) {
625  default_Limits.WarningValue = warning_map_bin->second;
626  default_Limits.ErrorValue = error_map_bin->second;
627  default_Limits.Mask = false;
628  }
629 
630  //Make default threshold & mask
631  std::vector< std::vector<BinThresh::mask_limits> > Limits(m_NbinsX, std::vector<BinThresh::mask_limits>(m_NbinsY, default_Limits));
632 
633  //Get specific bin limits and unmasked bins
634  for ( int binX = 0; binX < m_NbinsX; binX++ ) {
635  for ( int binY = 0; binY < m_NbinsY; binY++ ) {
636  std::string value_bin = Form("Value_%d_%d", binX + 1, binY + 1);
637  //Get thresholds for bin
638  warning_map_bin = warning_params.find(value_bin.c_str());
639  error_map_bin = error_params.find(value_bin.c_str());
640  if ( warning_map_bin != warning_params.end() &&
641  error_map_bin != error_params.end() ) {
642  Limits[binX][binY].WarningValue = warning_map_bin->second;
643  Limits[binX][binY].ErrorValue = error_map_bin->second;
644  Limits[binX][binY].Mask = false;
645  }
646 
647  //Mask out specified bins
648  //The masking that is explicitly defined takes precedence over the implied masking from the thresholds
649  std::string mask_bin = Form("Mask_%d_%d", binX + 1, binY + 1);
650  mask_map_bin = params.find(mask_bin.c_str());
651  if ( mask_map_bin != params.end() ) {
652  if(mask_map_bin->second > 0.5) Limits[binX][binY].Mask = true;
653  //UnMasking should never be necessary
654  }
655  }}
656 
657  return(Limits);
658  }
659 
660 } // namespace dqm_algorithms
dqm_algorithms::BinThresh::BinMinEntries_GetFromMap
int BinMinEntries_GetFromMap(const std::map< std::string, double > &params)
Definition: BinThresh.cxx:543
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
get_generator_info.result
result
Definition: get_generator_info.py:21
dqm_algorithms::BinThresh::UseValue_GetFromMap
int UseValue_GetFromMap(const std::map< std::string, double > &params)
Definition: BinThresh.cxx:522
dqm_algorithms::BinThresh::mask_limits::WarningValue
double WarningValue
Definition: BinThresh.h:34
dqm_algorithms::BinThresh::TypePublish_GetFromMap
int TypePublish_GetFromMap(const std::map< std::string, double > &params)
Definition: BinThresh.cxx:510
python.FakeAthena.Algorithm
def Algorithm(name)
Definition: FakeAthena.py:41
skel.it
it
Definition: skel.GENtoEVGEN.py:423
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
bin
Definition: BinsDiffFromStripMedian.h:43
dqm_algorithms::BinThresh::clone
virtual dqm_core::Algorithm * clone()
Definition: BinThresh.cxx:133
dqm_algorithms::BinThresh::~BinThresh
virtual ~BinThresh()
Definition: BinThresh.cxx:126
dqm_algorithms::BinThresh::m_NbinsX
int m_NbinsX
Definition: BinThresh.h:43
BinThresh.h
ReweightUtils.message
message
Definition: ReweightUtils.py:15
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
Trk::binY
@ binY
Definition: BinningType.h:48
dqm_algorithms::BinThresh::mask_limits
Definition: BinThresh.h:32
Result
ICscStripFitter::Result Result
Definition: CalibCscStripFitter.cxx:13
dqm_algorithms::BinThresh::Publish_GetFromMap
int Publish_GetFromMap(const std::map< std::string, double > &params)
Definition: BinThresh.cxx:500
python.handimod.Green
int Green
Definition: handimod.py:524
dqm_algorithms::BinThresh::TypeValue_GetFromMap
int TypeValue_GetFromMap(const std::map< std::string, double > &params)
Definition: BinThresh.cxx:532
Trk::binX
@ binX
Definition: BinningType.h:47
dqm_algorithms::BinThresh::printDescription
virtual void printDescription(std::ostream &out)
Definition: BinThresh.cxx:30
python.handimod.Red
Red
Definition: handimod.py:551
dqm_algorithms::BinThresh::mask_limits::ErrorValue
double ErrorValue
Definition: BinThresh.h:35
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
plotBeamSpotVxVal.bin
int bin
Definition: plotBeamSpotVxVal.py:83
TProfile
Definition: rootspy.cxx:515
dqm_algorithms::BinThresh::Limits2D_GetFromMap
std::vector< std::vector< BinThresh::mask_limits > > Limits2D_GetFromMap(const std::map< std::string, double > &params, const std::map< std::string, double > &warning_params, const std::map< std::string, double > &error_params)
Definition: BinThresh.cxx:606
dqm_algorithms::BinThresh::mask_limits::Mask
bool Mask
Definition: BinThresh.h:33
dqm_algorithms
Definition: AddReference.h:17
h
dqm_algorithms::BinThresh::BinThresh
BinThresh()
Definition: BinThresh.cxx:112
dqm_algorithms::BinThresh::Limits1D_GetFromMap
std::vector< BinThresh::mask_limits > Limits1D_GetFromMap(const std::map< std::string, double > &params, const std::map< std::string, double > &warning_params, const std::map< std::string, double > &error_params)
Definition: BinThresh.cxx:553
TH1
Definition: rootspy.cxx:268
dqm_algorithms::BinThresh::m_name
std::string m_name
Definition: BinThresh.h:40
dqm_algorithms::BinThresh::m_NbinsY
int m_NbinsY
Definition: BinThresh.h:44
PowhegControl_ttFCNC_NLO.params
params
Definition: PowhegControl_ttFCNC_NLO.py:226
dqm_algorithms::BinThresh
Definition: BinThresh.h:18
dqm_algorithms::BinThresh::execute
virtual dqm_core::Result * execute(const std::string &name, const TObject &data, const dqm_core::AlgorithmConfig &config)
Definition: BinThresh.cxx:141
TProfile::GetBinContent
double GetBinContent(int) const
Definition: rootspy.cxx:527