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