ATLAS Offline Software
HLTMETStatus.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 /* Algorithm: AlgHLTMETStatus does the following
6  * Checks the [EF/L2]_MET_status histograms (produced for 10 min block / entire run)
7  * There are 32 status bits and each bin of the above histograms represent a status.
8  * If the status bits 17 -> 29 (in general binLo -> binHi) are filled, flag = YELLOW
9  * If the status bits 32 -> 32 (in general binLo -> binHi) are filled, flag = RED
10  * Expects the following from configuration [<value> corresponds to a bin number]
11  * METYellowMin = <value> specify the bins you want to compute flags for [1-32]
12  * METYellowMax = <value> ditto
13  * METRedMin = <value> ditto
14  * METRedMax = <value> ditto
15  * DoYellowFlag = <1 or 0> 0 means don't compute yellow flags
16  * DoRedFlag = <1 or 0> 0 means don't compute red flags
17  *
18  * Author : Venkatesh Kaushik <venkat.kaushik@cern.ch>
19  * Date : March 2010
20  */
21 
22 #include <dqm_core/AlgorithmConfig.h>
25 #include <TH1.h>
26 #include <TH2.h>
27 #include <TF1.h>
28 #include <TClass.h>
29 #include <ers/ers.h>
30 
31 #include <dqm_core/AlgorithmManager.h>
32 
33 static dqm_algorithms::HLTMETStatus myInstance;
34 
36 
37 {
38  dqm_core::AlgorithmManager::instance().registerAlgorithm("AlgHLTMETStatus", this);
39 }
40 
43 {
44 
45  return new HLTMETStatus();
46 }
47 
48 
51  const TObject & object,
52  const dqm_core::AlgorithmConfig & config)
53 {
54  const TH1 * histogram;
55 
56  if( object.IsA()->InheritsFrom( "TH1" ) ) {
57  histogram = static_cast<const TH1*>(&object);
58  if (histogram->GetDimension() > 2 ){
59  throw dqm_core::BadConfig( ERS_HERE, name, "dimension > 2 " );
60  }
61  } else {
62  throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" );
63  }
65  // Get Green and Red Thresholds
66  double grThr = 0.05, reThr = 0.1; // Green and Red thresholds
67  try {
68  grThr = dqm_algorithms::tools::GetFromMap("Threshold",config.getGreenThresholds() );
69  reThr = dqm_algorithms::tools::GetFromMap("Threshold",config.getRedThresholds() );
70  } catch ( dqm_core::Exception & ex ) {
71  throw dqm_core::BadConfig(ERS_HERE,name,"Paramter: 'Threshold' is mandatory, cannot continue");
72  }
73 
74  //non sense case: compare fraction and threshold >100%
75  if ((grThr>1.0 || reThr>1.0) ) {
76  throw dqm_core::BadConfig(ERS_HERE,m_name,"Configuration Error: Threshold should be between [0.0, 1.0] 10% => 0.1");
77  }
78 
79 
81  // Get Parameters
82  size_t ntotBins = (size_t) histogram -> GetNbinsX();
83 
84  // read thresholds
85  size_t colflags[4];
86  colflags[0] = static_cast<size_t>(dqm_algorithms::tools::GetFirstFromMap("METYellowMin", config.getParameters(), 1));
87  colflags[1] = static_cast<size_t>(dqm_algorithms::tools::GetFirstFromMap("METYellowMax", config.getParameters(), ntotBins));
88  colflags[2] = static_cast<size_t>(dqm_algorithms::tools::GetFirstFromMap("METRedMin", config.getParameters(), 1));
89  colflags[3] = static_cast<size_t>(dqm_algorithms::tools::GetFirstFromMap("METRedMax", config.getParameters(), ntotBins));
90  // read options
91  bool doflags[2];
92  doflags[0] = static_cast<bool>(dqm_algorithms::tools::GetFirstFromMap("DoYellowFlag", config.getParameters(), 1));
93  doflags[1] = static_cast<bool>(dqm_algorithms::tools::GetFirstFromMap("DoRedFlag", config.getParameters(), 1));
94 
96  colflags[0] = ((colflags[0] > 0) && (colflags[0] <= ntotBins)) ? colflags[0] : 1;
97  colflags[1] = ((colflags[1] >= colflags[0]) && (colflags[1] <= ntotBins)) ? colflags[1] : ntotBins;
98  colflags[2] = ((colflags[2] > 0) && (colflags[2] <= ntotBins)) ? colflags[2] : 1;
99  colflags[3] = ((colflags[3] >= colflags[2]) && (colflags[3] <= ntotBins)) ? colflags[3] : ntotBins;
100  bool yellowLo2HiEmpty = true, redLo2HiEmpty = true;
101  int ycnt = 0, rcnt = 0;
102 
103  // we fill 1(error) or 0(no-error) for each bin for every event
104  // therefore we have to divide #of entries by #of bins
105  // to get the #of events
106  double nentries = histogram -> GetEntries();
107  double nevtstot = 1.; // no. of events
108  if(!std::isnan(nentries/ntotBins) || !std::isinf(nentries / ntotBins)) nevtstot = nentries/ntotBins;
109 
110  // yellow flag
111  double theYFracMax = -9., theRFracMax = -9.;
112  if(doflags[0]) {
113  for( size_t j = colflags[0]; j <= colflags[1]; j++ ) {
114  // if at least one of the bins > 0 : flag = YELLOW
115  double thebinc = histogram -> GetBinContent(j);
116  // fraction of events having this error-bit set
117  double thefrac = thebinc / nevtstot;
118 
119  // "Worst-case flag not to exceed YELLOW" flag:
120  // if threshold exceeds green threshold, set yellow
121  // if threshold exceeds red threshold, still set yellow
122  // reThr > grThr
123  if(thefrac > grThr) {
124  if(theYFracMax < thefrac) theYFracMax = thefrac;
125  yellowLo2HiEmpty = false;
126  ycnt ++;
127  }
128  }
129  }
130 
131  // red flag
132  if(doflags[1]) {
133  for( size_t j = colflags[2]; j <= colflags[3]; j++ ) {
134  // if at least one of the bins > 0 : flag = RED
135  double thebinc = histogram -> GetBinContent(j);
136  // fraction of events having this error-bit set
137  double thefrac = thebinc / nevtstot;
138  if(thefrac > reThr) {
139  if(theRFracMax < thefrac) theRFracMax = thefrac;
140  redLo2HiEmpty = false;
141  rcnt++;
142  }
143  }
144  }
145 
146  // set results
147  result->status_ = dqm_core::Result::Green;
148 
149  if(doflags[0] && !yellowLo2HiEmpty) {
150  result->status_ = dqm_core::Result::Yellow;
151  }
152 
153  if(doflags[1] && !redLo2HiEmpty) {
154  result->status_ = dqm_core::Result::Red;
155  }
156 
157  result->tags_["NumOfStatusBitsYellow"] = ycnt;
158  result->tags_["EventFractionYellow"] = theYFracMax;
159  result->tags_["NumOfStatusBitsRed"] = rcnt;
160  result->tags_["EventFractionRed"] = theRFracMax;
161 
163 
164  return result;
165 }
166 
167 void
169 {
170 
171  out<<"HLT MET Status: Of the 32 status bits, check if any subset of bits are set. If so, flag YELLOW" << std::endl;
172  out<<"Bit #32 is global error bit, if set flag RED." << std::endl;
173 
174  out<<"Mandatory parameter: XBin: The label of the X bin that you would like to check\n"<<std::endl;
175 
176 }
177 
dqm_algorithms::HLTMETStatus::HLTMETStatus
HLTMETStatus()
Definition: HLTMETStatus.cxx:35
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::HLTMETStatus::clone
HLTMETStatus * clone()
Definition: HLTMETStatus.cxx:42
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
PlotCalibFromCool.nentries
nentries
Definition: PlotCalibFromCool.py:798
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
HLTMETStatus.h
dqm_algorithms::HLTMETStatus::printDescription
void printDescription(std::ostream &out)
Definition: HLTMETStatus.cxx:168
TH1
Definition: rootspy.cxx:268
generate::GetEntries
double GetEntries(TH1D *h, int ilow, int ihi)
Definition: rmsFrac.cxx:20
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
dqm_algorithms::HLTMETStatus
Definition: HLTMETStatus.h:21
dqm_algorithms::HLTMETStatus::execute
dqm_core::Result * execute(const std::string &, const TObject &, const dqm_core::AlgorithmConfig &)
Definition: HLTMETStatus.cxx:50