ATLAS Offline Software
LastBinThresholdAction.cxx
Go to the documentation of this file.
1 /*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <dqm_core/AlgorithmConfig.h>
8 #include <TH1.h>
9 #include <TF1.h>
10 #include <TProfile.h>
11 #include <TClass.h>
12 #include <ers/ers.h>
13 
14 #include <iostream>
15 #include <cstdlib>
16 #include <regex>
17 
18 #include <dqm_core/AlgorithmManager.h>
19 
20 namespace {
21 
22 
24  LastBinGreaterThanThreshold("LastBinGreaterThanThreshold");
25 
27  LastBinLessThanThreshold("LastBinLessThanThreshold");
28 
30  LastBinDifferentThanThreshold("LastBinDifferentThanThreshold");
31 
33  TileDataCorruptionFractionGreaterThanThreshold("TileDataCorruptionGreaterThanThreshold");
34 }
35 
36 void dqm_algorithms::TileDQAction::operator() (const std::string& histogramName, std::string action,
37  double averageBinContent, double lastBinContent) const {
38 
39  const char* actionPath = std::getenv("TILE_DQ_ACTION_PATH");
40  if (actionPath != nullptr) action = std::string(actionPath) + "/" + action;
41 
42  std::smatch match;
43  std::regex expression (".*([LE]B[AC]\\d\\d).*");
44 
45  std::string module("UNKNOWN");
46  if (std::regex_search(histogramName, match, expression) && match.size() > 1) {
47  module = match.str(1);
48  }
49 
50  action += " ";
51  action += histogramName;
52  action += " ";
53  action += module;
54  action += " ";
55  action += std::to_string(lastBinContent);
56  action += " ";
57  action += std::to_string(averageBinContent);
58  action += " &";
59  std::system(action.c_str());
60 }
61 
62 
63 template<class Exceed, class Action>
65  : m_name( name )
66 {
67  dqm_core::AlgorithmManager::instance().registerAlgorithm(name, this);
68 }
69 
70 template<class Exceed, class Action>
73  return new LastBinThresholdAction(m_name);
74 }
75 
76 
77 template<class Exceed, class Action> dqm_core::Result*
79  const TObject& object,
80  const dqm_core::AlgorithmConfig& config )
81 {
82  const TProfile* histogram;
83 
84  if( object.IsA()->InheritsFrom( "TProfile" ) ) {
85  histogram = dynamic_cast<const TProfile*>(&object);
86  if (histogram->GetDimension() > 1){
87  throw dqm_core::BadConfig( ERS_HERE, name, "dimension > 2 " );
88  }
89  } else {
90  throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TProfile" );
91  }
92 
93  const double minStat = dqm_algorithms::tools::GetFirstFromMap( "MinStat", config.getParameters(), -1);
94  const double fixedError = dqm_algorithms::tools::GetFirstFromMap( "FixedError", config.getParameters(), -1);
95  const bool ignoreEmpty = static_cast<bool>( dqm_algorithms::tools::GetFirstFromMap( "IgnoreEmpty", config.getParameters(), 1) );
96  const bool publish = static_cast<bool>( dqm_algorithms::tools::GetFirstFromMap( "PublishBins", config.getParameters(), 0) );
97  const int maxPublish = static_cast<int>( dqm_algorithms::tools::GetFirstFromMap( "MaxPublish", config.getParameters(), 20) );
98  const int nBinsToWatch = static_cast<int>( dqm_algorithms::tools::GetFirstFromMap( "NBinsToWatch", config.getParameters(), -1) );
99  const int nBinsForAction = static_cast<int>( dqm_algorithms::tools::GetFirstFromMap( "NBinsForAction", config.getParameters(), 99999) );
100 
101  std::string action("");
102  std::map<std::string, std::string>::const_iterator itAction = config.getGenericParameters().find("Action");
103  if (itAction != config.getGenericParameters().end()) {
104  action = itAction->second;
105  }
106 
107  if (histogram->GetEntries() < minStat ) {
109  result->tags_["InsufficientEntries"] = histogram->GetEntries();
110  return result;
111  }
112 
113  double binThreshold;
114  double greenThreshold;
115  double redThreshold;
116  try {
117  binThreshold = dqm_algorithms::tools::GetFirstFromMap( "BinThreshold", config.getParameters() );
118  redThreshold = dqm_algorithms::tools::GetFromMap( "NBins", config.getRedThresholds() );
119  greenThreshold = dqm_algorithms::tools::GetFromMap( "NBins", config.getGreenThresholds() );
120  } catch ( dqm_core::Exception & ex ) {
121  throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
122  }
123 
125 
126  int nBinsOverThreshold = 0;
127 
128  int firstBin = 1;
129  int lastBin = histogram->GetNbinsX();
130 
131  if (nBinsToWatch > 0) {
132  while ((histogram->GetBinEntries(lastBin) == 0) && (lastBin > 1)) --lastBin;
133  firstBin = (lastBin > nBinsToWatch) ? (lastBin - nBinsToWatch + 1) : 1;
134 
135  result->tags_["LastBinNumber"] = lastBin; // report where we began the checks (mostly for debugging)
136  result->tags_["LastBinCenter"] = histogram->GetBinCenter(lastBin); // report where that is on the x-axis
137  }
138 
139  double lastBinOverThresholdContent(0.0);
140  double binsOverThresholdContent(0.0);
141 
142  for (int bin = firstBin; bin <= lastBin; ++bin) {
143  if (ignoreEmpty && (histogram->GetBinEntries(bin) == 0)) {
144  continue;
145  }
146  double content = histogram->GetBinContent(bin);
147  if (m_exceeds(content, binThreshold, fixedError)) {
148  ++nBinsOverThreshold;
149  lastBinOverThresholdContent = content;
150  binsOverThresholdContent += content;
151  if (publish && nBinsOverThreshold < maxPublish){
153  }
154  }
155  }
156 
157  ERS_DEBUG(1,"Number of bins exceeded threshold of " << binThreshold << " is " << nBinsOverThreshold );
158  ERS_DEBUG(1,"Green threshold: "<< greenThreshold << " bin(s); Red threshold : " << redThreshold << " bin(s) ");
159 
160  result->tags_["NBins"] = nBinsOverThreshold;
161  if (greenThreshold > redThreshold) {
162  if (nBinsOverThreshold >= greenThreshold) {
163  result->status_ = dqm_core::Result::Green;
164  } else if (nBinsOverThreshold > redThreshold) {
165  result->status_ = dqm_core::Result::Yellow;
166  } else {
167  result->status_ = dqm_core::Result::Red;
168  }
169  } else {
170  if (nBinsOverThreshold <= greenThreshold) {
171  result->status_ = dqm_core::Result::Green;
172  } else if (nBinsOverThreshold < redThreshold) {
173  result->status_ = dqm_core::Result::Yellow;
174  } else {
175  result->status_ = dqm_core::Result::Red;
176  }
177  }
178 
179  if (!action.empty() && nBinsOverThreshold >= nBinsForAction) {
180  double averageBinContent = binsOverThresholdContent / nBinsOverThreshold;
181  std::string histogramName(histogram->GetName());
182  m_doAction(histogramName, action, lastBinOverThresholdContent, averageBinContent);
183  }
184 
185  return result;
186 
187 }
188 
189 template<class Exceed, class Action>
191 
192  out << m_name + ": Checks for number of bins exceded threshold value" << std::endl;
193  out << "Mandatory Parameter: BinThreshold: Look for bins exceeded BinTreshold; Count number of bins satifying requirement" << std::endl;
194  out << "Mandatory Green/Red Threshold: NBins: Number of bins satifying BinThreshold constraint to give Green/Red result" << std::endl;
195 
196  out << "Optional Parameter: FixedError: override the histogram errors with this value" << std::endl;
197  out << "Optional Parameter: IgnoreEmpty: Ignore bins which have zero entries in histogram" << std::endl;
198  out << "Optional Parameter: PublishBins: Save bins which are different from average in Result (set to 1)" << std::endl;
199  out << "Optional Parameter: MaxPublish: Max number of bins to save (default 20)" << std::endl;
200  out << "Optional Parameter: MinStat: Minimum histogram statistics needed to perform Algorithm" << std::endl;
201  out << "Optional parameter: NBinsToWatch - number of final bins that will be checked. (NBinsToWatch >= 1, default = -1)" << std::endl;
202 }
203 
204 
205 // Make sure these are completely instantiated here, as the definitions
206 // are only in this file.
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::LastBinThresholdAction::clone
virtual LastBinThresholdAction * clone() override
Definition: LastBinThresholdAction.cxx:72
dqm_algorithms::LastBinThresholdAction::printDescription
virtual void printDescription(std::ostream &out) const
Definition: LastBinThresholdAction.cxx:190
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
python.HION12.expression
string expression
Definition: HION12.py:55
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
PrepareReferenceFile.regex
regex
Definition: PrepareReferenceFile.py:43
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
grepfile.content
string content
Definition: grepfile.py:56
python.PyAthena.module
module
Definition: PyAthena.py:131
python.TrigEgammaMonitorHelper.TProfile
def TProfile(*args, **kwargs)
Definition: TrigEgammaMonitorHelper.py:81
Result
ICscStripFitter::Result Result
Definition: CalibCscStripFitter.cxx:13
dqm_algorithms::LastBinThresholdAction::execute
virtual dqm_core::Result * execute(const std::string &, const TObject &, const dqm_core::AlgorithmConfig &) override
Definition: LastBinThresholdAction.cxx:78
LastBinThresholdAction.h
python.handimod.Green
int Green
Definition: handimod.py:524
dqm_algorithms::LastBinThresholdAction
Definition: LastBinThresholdAction.h:47
python.handimod.Red
Red
Definition: handimod.py:551
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
plotBeamSpotVxVal.bin
int bin
Definition: plotBeamSpotVxVal.py:83
dqm_algorithms::TileDQAction::operator()
void operator()(const std::string &histogramName, std::string action, double averageBinContent, double lastBinContent) const
Definition: LastBinThresholdAction.cxx:36
SCT_ConditionsAlgorithms::CoveritySafe::getenv
std::string getenv(const std::string &variableName)
get an environment variable
Definition: SCT_ConditionsUtilities.cxx:17
python.CaloScaleNoiseConfig.action
action
Definition: CaloScaleNoiseConfig.py:77
AlgorithmHelper.h
dqm_algorithms::tools::GetFromMap
const T & GetFromMap(const std::string &pname, const std::map< std::string, T > &params)
Definition: AlgorithmHelper.h:114
dqm_algorithms::LastBinThresholdAction::LastBinThresholdAction
LastBinThresholdAction(const std::string &name)
Definition: LastBinThresholdAction.cxx:64
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
match
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition: hcg.cxx:356
histogram
std::string histogram
Definition: chains.cxx:52