ATLAS Offline Software
Loading...
Searching...
No Matches
dqm_algorithms::LastBinThreshold Class Reference

#include <LastBinThreshold.h>

Inheritance diagram for dqm_algorithms::LastBinThreshold:
Collaboration diagram for dqm_algorithms::LastBinThreshold:

Public Member Functions

 LastBinThreshold (const std::string &name)
virtual ~LastBinThreshold ()
virtual LastBinThresholdclone ()
virtual dqm_core::Result * execute (const std::string &name, const TObject &object, const dqm_core::AlgorithmConfig &config)
virtual void printDescription (std::ostream &out)

Private Member Functions

void getParameters (const std::string &name, const dqm_core::AlgorithmConfig &config)
void getThresholds (const std::string &name, const dqm_core::AlgorithmConfig &config)
bool exceeds (double value, double threshold) const

Private Attributes

int m_nBinsToWatch {}
int m_nBinsToExceed {}
int m_binMinEntries {}
bool m_greaterThan {}
bool m_valueThresholds {}
int m_getEntries {}
double m_grn {}
double m_red {}
const std::string m_name

Detailed Description

Definition at line 18 of file LastBinThreshold.h.

Constructor & Destructor Documentation

◆ LastBinThreshold()

dqm_algorithms::LastBinThreshold::LastBinThreshold ( const std::string & name)
explicit

◆ ~LastBinThreshold()

dqm_algorithms::LastBinThreshold::~LastBinThreshold ( )
virtual

Definition at line 41 of file LastBinThreshold.cxx.

42{
43 /* noop */
44}

Member Function Documentation

◆ clone()

dqm_algorithms::LastBinThreshold * dqm_algorithms::LastBinThreshold::clone ( )
virtual

Definition at line 46 of file LastBinThreshold.cxx.

47{
48 return new LastBinThreshold(m_name); // somebody else must delete this
49}
LastBinThreshold(const std::string &name)

◆ exceeds()

bool dqm_algorithms::LastBinThreshold::exceeds ( double value,
double threshold ) const
inlineprivate

Definition at line 185 of file LastBinThreshold.cxx.

186{
187 if (m_greaterThan)
188 return value > threshold;
189 else
190 return value < threshold;
191 // We could derive that behaviour from testing whether (m_grn < m_red) or (m_grn > m_red), but then we
192 // weren't able to find a reasonable behaviour if (m_grn == m_red), i. e. for people who never want yellow.
193}

◆ execute()

dqm_core::Result * dqm_algorithms::LastBinThreshold::execute ( const std::string & name,
const TObject & object,
const dqm_core::AlgorithmConfig & config )
virtual

Definition at line 51 of file LastBinThreshold.cxx.

52{
53 if (!object.IsA()->InheritsFrom("TH1")) { // this could also be TH2 or TH3
54 throw dqm_core::BadConfig(ERS_HERE, name, "does not inherit from TH1");
55 }
56 const TH1 &histogram = dynamic_cast<const TH1 &>(object); // should be possible after the previous check (otherwise we'd get a std::bad_cast)
57 if (histogram.GetDimension() > 1) { // only one-dimensional histograms have a last bin, but feel free to generalise this for D > 1 if you like
58 throw dqm_core::BadConfig(ERS_HERE, name, "has more than one dimension");
59 }
60 bool is_tProfile = false;
61 if (object.IsA()->InheritsFrom("TProfile")) { // BinMinEntries is used only when the histogram is TProfile
62 is_tProfile = true;
63 }
64
65 getParameters(name, config);
66 getThresholds(name, config);
67
68 dqm_core::Result *result = new dqm_core::Result(); // somebody else must delete this
69 int grnExceeded = 0; // how many of the checked bins exceeded the green threshold
70 int redExceeded = 0; // how many of the checked bins exceeded the red threshold
71
72 int currentBin = histogram.GetNbinsX(); // this is the last proper bin (we don't want the overflow bin)
73 if (m_getEntries == 0) { // skip trailing bins with zero content
74 while ((histogram.GetBinContent(currentBin) == 0) && (currentBin > 0)) --currentBin;
75 } else if (m_getEntries == 1) { // assume that this value corresponds to the bin number of the last bin
76 currentBin = histogram.GetEntries();
77 } else if (m_getEntries == 2) { /* noop */ } // just start checking from the rightmost bin
78
79 result->tags_["LastBinNumber"] = currentBin; // report where we began the checks (mostly for debugging)
80 result->tags_["LastBinCenter"] = histogram.GetBinCenter(currentBin); // report where that is on the x-axis
81 // if the histogram is completely empty then currentBin is now zero, and we shouldn't check anything,
82 // therefore the break statement is at the front (!) of the following loop
83
84 for (int i = 0; i < m_nBinsToWatch; ++i) { // step through the final NBinsToWatch bins
85 if (currentBin == 0) break; // we hit the left end (and we don't want the underflow bin)
86 double content = histogram.GetBinContent(currentBin);
88 if (m_greaterThan) content = histogram.GetXaxis()->GetBinUpEdge(currentBin);
89 else content = histogram.GetXaxis()->GetBinLowEdge(currentBin);
90 }
91 if (is_tProfile) { // if the histogram is TProfile, the bin entries are checked
92 const TProfile &profile = dynamic_cast<const TProfile &>(object);
93 if (profile.GetBinEntries(currentBin) < m_binMinEntries) { // if the bin entries is less than MinBinEntries, the count is skipped
94 --currentBin;
95 continue;
96 }
97 }
98 if (exceeds(content, m_grn)) ++grnExceeded; // can be less-than or greater-than relation
99 if (exceeds(content, m_red)) ++redExceeded; // can be less-than or greater-than relation
100 --currentBin;
101 }
102
103 result->tags_["GreenExceeded"] = grnExceeded;
104 result->tags_["RedExceeded"] = redExceeded;
105 if (grnExceeded < redExceeded) // sanity check, this should never happen because getThresholds() makes sure the thresholds have the right order
106 throw dqm_core::BadConfig(ERS_HERE, name, "more bins exceeded the red threshold than the green threshold, this shouldn't happen");
107
108 if (grnExceeded < m_nBinsToExceed) result->status_ = dqm_core::Result::Green;
109 else if (redExceeded < m_nBinsToExceed) result->status_ = dqm_core::Result::Yellow;
110 else result->status_ = dqm_core::Result::Red;
111 return result;
112}
std::string histogram
Definition chains.cxx:52
void getThresholds(const std::string &name, const dqm_core::AlgorithmConfig &config)
bool exceeds(double value, double threshold) const
void getParameters(const std::string &name, const dqm_core::AlgorithmConfig &config)
str content
Definition grepfile.py:56
#define IsA
Declare the TObject style functions.

◆ getParameters()

void dqm_algorithms::LastBinThreshold::getParameters ( const std::string & name,
const dqm_core::AlgorithmConfig & config )
private

Definition at line 140 of file LastBinThreshold.cxx.

141{
142 // The following intermediate variables do not yet have the correct type,
143 // since dqm_core::AlgorithmConfig::getParameters can only return values of type double.
144 // We cannot cast them immediately because we still need to perform some manual range checks.
145 //
146 const double par0 = dqm_algorithms::tools::GetFirstFromMap("NBinsToWatch", config.getParameters(), 1); // default = 1
147 const double par1 = dqm_algorithms::tools::GetFirstFromMap("NBinsToExceed", config.getParameters(), 1); // default = 1
148 const double par2 = dqm_algorithms::tools::GetFirstFromMap("GreaterThan", config.getParameters(), 1); // default = true
149 const double par3 = dqm_algorithms::tools::GetFirstFromMap("ValueThresholds", config.getParameters(), 0); // default = false
150 const double par4 = dqm_algorithms::tools::GetFirstFromMap("GetEntries", config.getParameters(), 0); // default = 0
151 const double par5 = dqm_algorithms::tools::GetFirstFromMap("BinMinEntries", config.getParameters(), 0); // default = 0
152
153 if (par0 < 1)
154 throw dqm_core::BadConfig(ERS_HERE, name, "NBinsToWatch must be 1 or greater");
155 if (par1 < 1)
156 throw dqm_core::BadConfig(ERS_HERE, name, "NBinsToExceed must be 1 or greater");
157 if (par1 > par0)
158 throw dqm_core::BadConfig(ERS_HERE, name, "NBinsToExceed must not be greater than NBinsToWatch");
159 if ((par2 != 0) && (par2 != 1))
160 throw dqm_core::BadConfig(ERS_HERE, name, "GreaterThan must be 0 or 1");
161 if ((par3 != 0) && (par3 != 1))
162 throw dqm_core::BadConfig(ERS_HERE, name, "ValueThresholds must be 0 or 1");
163 if ((par4 != 0) && (par4 != 1) && (par4 != 2))
164 throw dqm_core::BadConfig(ERS_HERE, name, "GetEntries must be 0, 1 or 2");
165
166 m_nBinsToWatch = static_cast<int>(par0);
167 m_nBinsToExceed = static_cast<int>(par1);
168 m_greaterThan = static_cast<bool>(par2);
169 m_valueThresholds = static_cast<bool>(par3);
170 m_getEntries = static_cast<int>(par4);
171 m_binMinEntries = static_cast<int>(par5);
172}
double GetFirstFromMap(const std::string &paramName, const std::map< std::string, double > &params)

◆ getThresholds()

void dqm_algorithms::LastBinThreshold::getThresholds ( const std::string & name,
const dqm_core::AlgorithmConfig & config )
private

Definition at line 174 of file LastBinThreshold.cxx.

175{
176 m_grn = dqm_algorithms::tools::GetFromMap("Threshold", config.getGreenThresholds());
177 m_red = dqm_algorithms::tools::GetFromMap("Threshold", config.getRedThresholds());
178
179 if (m_greaterThan && (m_red < m_grn))
180 throw dqm_core::BadConfig(ERS_HERE, name, "using greater-than comparison, but red threshold is less than green threshold");
181 else if (!m_greaterThan && (m_red > m_grn))
182 throw dqm_core::BadConfig(ERS_HERE, name, "using less-than comparison, but red threshold is greater than green threshold");
183}
const T & GetFromMap(const std::string &pname, const std::map< std::string, T > &params)

◆ printDescription()

void dqm_algorithms::LastBinThreshold::printDescription ( std::ostream & out)
virtual

Definition at line 114 of file LastBinThreshold.cxx.

115{
116 out << m_name << ": Checks whether the last bin(s) of a histogram exceed the given thresholds.\n"
117 "Mandatory green/red thresholds: Threshold - the thresholds against which the bin contents are compared.\n"
118 "Optional parameter: NBinsToWatch - number of final bins that will be checked. (NBinsToWatch >= 1, default = 1)\n"
119 " The result of the algorithm is the worst-case result of all checked bins.\n"
120 "Optional parameter: NBinsToExceed - minimal number of checked bins that have to exceed the given thresholds\n"
121 " before the corresponding result is returned. (1 <= NBinsToExceed <= NBinsToWatch, default = 1)\n"
122 "Optional parameter: BinMinEntries: Minimum number of entries in a TProfile (1D only) for a bin to be checked against thresolds\n"
123 " If a bin does not have a sufficient number of entries it also will not be printed (default = 0)\n"
124 "Optional parameter: GreaterThan - how the values will be compared. (GreaterThan = {0, 1}, default = 1)\n"
125 " GreaterThan == 0: the given thresholds are lower thresholds. (requires green >= red)\n"
126 " GreaterThan == 1: the given thresholds are upper thresholds. (requires green <= red)\n"
127 "Optional parameter: ValueThresholds - which values will be compared. (ValueThresholds = {0, 1}, default = 0)\n"
128 " ValueThresholds == 0: the thresholds correspond to the bin content.\n"
129 " ValueThresholds == 1: the thresholds correspond to the bin x-axis value.\n"
130 "Optional parameter: GetEntries - how to determine which bin is the last. (GetEntries = {0, 1, 2}, default = 0)\n"
131 " GetEntries == 0: find the rightmost non-zero bin, ignore trailing zero bins.\n"
132 " GetEntries == 1: take the return value of TH1::GetEntries() as the number of the last bin.\n"
133 " GetEntries == 2: take the rightmost bin as the last bin, regardless of the bin content.\n"
134 "Returned value: LastBinNumber - the bin number of the last checked (i. e. non-zero) bin.\n"
135 "Returned value: LastBinCenter - the centre of that bin on the horizontal axis.\n"
136 "Returned value: GreenExceeded - how many bins exceeded the green threshold.\n"
137 "Returned value: RedExceeded - how many bins exceeded the red threshold." << std::endl;
138}

Member Data Documentation

◆ m_binMinEntries

int dqm_algorithms::LastBinThreshold::m_binMinEntries {}
private

Definition at line 39 of file LastBinThreshold.h.

39{}; // Minimum number of entries in a TProfile (1D only) for a bin to be checked against thresolds

◆ m_getEntries

int dqm_algorithms::LastBinThreshold::m_getEntries {}
private

Definition at line 42 of file LastBinThreshold.h.

42{}; // search the rightmost non-zero bin (default)

◆ m_greaterThan

bool dqm_algorithms::LastBinThreshold::m_greaterThan {}
private

Definition at line 40 of file LastBinThreshold.h.

40{}; // greater-than or less-than comparison against thresholds? (default = true)

◆ m_grn

double dqm_algorithms::LastBinThreshold::m_grn {}
private

Definition at line 48 of file LastBinThreshold.h.

48{};

◆ m_name

const std::string dqm_algorithms::LastBinThreshold::m_name
private

Definition at line 52 of file LastBinThreshold.h.

◆ m_nBinsToExceed

int dqm_algorithms::LastBinThreshold::m_nBinsToExceed {}
private

Definition at line 38 of file LastBinThreshold.h.

38{}; // how many bins have to exceed the threshold (default = 1), less will be ignored

◆ m_nBinsToWatch

int dqm_algorithms::LastBinThreshold::m_nBinsToWatch {}
private

Definition at line 37 of file LastBinThreshold.h.

37{}; // how many bins to watch (default = 1), returning worst-case result of those bins

◆ m_red

double dqm_algorithms::LastBinThreshold::m_red {}
private

Definition at line 49 of file LastBinThreshold.h.

49{};

◆ m_valueThresholds

bool dqm_algorithms::LastBinThreshold::m_valueThresholds {}
private

Definition at line 41 of file LastBinThreshold.h.

41{}; // thresholds set w.r.t num entries per bin (false) or w.r.t to X-axis value? (default = false)

The documentation for this class was generated from the following files: