ATLAS Offline Software
Loading...
Searching...
No Matches
dqm_algorithms::ZDCPercentEvents_AboveThreshold Struct Reference

#include <ZDCPercentEvents_AboveThreshold.h>

Inheritance diagram for dqm_algorithms::ZDCPercentEvents_AboveThreshold:
Collaboration diagram for dqm_algorithms::ZDCPercentEvents_AboveThreshold:

Public Member Functions

 ZDCPercentEvents_AboveThreshold ()
virtual dqm_core::Algorithm * clone ()
virtual dqm_core::Result * execute (const std::string &name, const TObject &data, const dqm_core::AlgorithmConfig &config)
double calculatePercentage (const TH1 *hist, dqm_core::Result *result)
virtual void printDescription (std::ostream &out)

Private Attributes

std::string m_name
double m_minstat {}
double m_thresh {}
double m_greenTh {}
double m_redTh {}
int m_binNum {}

Detailed Description

Definition at line 15 of file ZDCPercentEvents_AboveThreshold.h.

Constructor & Destructor Documentation

◆ ZDCPercentEvents_AboveThreshold()

dqm_algorithms::ZDCPercentEvents_AboveThreshold::ZDCPercentEvents_AboveThreshold ( )
inline

Definition at line 16 of file ZDCPercentEvents_AboveThreshold.h.

16: ZDCPercentageThreshTests("AboveThreshold") {};

Member Function Documentation

◆ calculatePercentage()

double dqm_algorithms::ZDCPercentageThreshTests::calculatePercentage ( const TH1 * hist,
dqm_core::Result * result )
inherited

Definition at line 140 of file ZDCPercentageThreshTests.cxx.

140 {
141 // function that calculates percentage of "bad" events
142 // Parameters: hist - pointer to 1D histogram
143 // result - pointer to a dqm_core::Result instance: in case of failure, for recording status and reason of failure
144 // if percentage calculation is invalid, update result with tag for reason of failure
145 // and set result status
146 // return value in [0,1]
147
148 // fetch the denominator: total number of entries (or content of first bin if normalization-to-1st-bin is requested)
149 Double_t N = (m_name == "XthBin_NormalizeToFirstBin")? hist->GetBinContent(1) : hist->GetEntries();
150
151 if(N == 0) {
152 ERS_INFO("Histogram " << hist->GetName() << " has zero entries. Percentage calculation fails.");
153 result->tags_["Empty_Histogram_found_N_Entries"] = N;
154 result->status_ = dqm_core::Result::Undefined;
155 return -1.;
156 };
157
158 // fetch number of "bad" events
159 Double_t hit_under_selection = 0;
160
161 if (m_name == "XthBin" || m_name == "XthBin_NormalizeToFirstBin"){ // if "bad" events are in a user-specified bin
162 hit_under_selection = hist->GetBinContent(m_binNum);
163 }
164 else if (m_name == "UnderThreshold"){ // if "bad" events are those with value under a user-specified threshold
165 hit_under_selection += hist->GetBinContent(1); // add at least bin content of the first bin to avoid meaningless check (always green)
166 int i=2;
167
168 while(hist->GetBinLowEdge(i+1) <= m_thresh){
169 if(i>hist->GetNbinsX()){
170 ERS_INFO("For histogram " << hist->GetName() << ", the user input threshold " << m_thresh << " is out of range (larger than max value). Percentage calculation fails.");
171 result->tags_["Config_error_maximum_bin_exceed_looking_for_bin_number"] = i;
172 result->status_ = dqm_core::Result::Undefined;
173 return -1.;
174 };
175 hit_under_selection += hist->GetBinContent(i);
176 i++;
177 };
178 }
179 else if (m_name == "AboveThreshold"){ // if "bad" events are those with value above a user-specified threshold
180 hit_under_selection += hist->GetBinContent(hist->GetNbinsX()+1); // include number of overflow events in the sum
181 int i = hist->GetNbinsX()+1;
182 do{
183 i--;
184 if(i <= 0){
185 ERS_INFO("For histogram " << hist->GetName() << ", the user input threshold " << m_thresh << " is out of range (smaller than min value). Percentage calculation fails.");
186 result->tags_["Config_error_minimum_bin_below_one"] = i;
187 result->status_ = dqm_core::Result::Undefined;
188 return -1.;
189 };
190 hit_under_selection += hist->GetBinContent(i);
191 } while(hist->GetBinLowEdge(i) > m_thresh);
192 }
193
194 // calculate and return percentage
195 double percent = ((double) hit_under_selection)/((double) N);
196 return percent;
197}

◆ clone()

dqm_core::Algorithm * dqm_algorithms::ZDCPercentageThreshTests::clone ( )
virtualinherited

Definition at line 57 of file ZDCPercentageThreshTests.cxx.

58{
59 return new ZDCPercentageThreshTests(*this);
60}

◆ execute()

dqm_core::Result * dqm_algorithms::ZDCPercentageThreshTests::execute ( const std::string & name,
const TObject & data,
const dqm_core::AlgorithmConfig & config )
virtualinherited

Definition at line 63 of file ZDCPercentageThreshTests.cxx.

64{
65 const TH1 * hist;
66
67 // check histogram is 1D
68 if( object.IsA()->InheritsFrom( "TH1" ) ) {
69 hist = static_cast<const TH1*>(&object);
70 if (hist->GetDimension() >= 2 ){
71 throw dqm_core::BadConfig( ERS_HERE, name, "dimension >= 2 " );
72 }
73 } else {
74 throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" );
75 }
76
77 //Get Parameters and Thresholds
78 try {
79 m_thresh = dqm_algorithms::tools::GetFirstFromMap( "Thresh", config.getParameters(),-1000.);
80 m_binNum = dqm_algorithms::tools::GetFirstFromMap( "BinNum", config.getParameters(),-1000);
81 m_minstat = dqm_algorithms::tools::GetFirstFromMap("MinStat", config.getParameters(), 0);
82 m_redTh = dqm_algorithms::tools::GetFromMap( "PercentBar", config.getRedThresholds());
83 m_greenTh = dqm_algorithms::tools::GetFromMap( "PercentBar", config.getGreenThresholds() );
84 }
85 catch ( dqm_core::Exception & ex ) {
86 throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
87 }
88
89 // case-by-case check for mandatory parameters
90 if ((m_name == "XthBin" || m_name == "XthBin_NormalizeToFirstBin") && m_binNum == -1000){
91 throw dqm_core::BadConfig( ERS_HERE, name, "required parameter BinNum is not provided!" );
92 }else if ((m_name == "UnderThreshold" || m_name == "AboveThreshold") && m_thresh == -1000.){
93 throw dqm_core::BadConfig( ERS_HERE, name, "required parameter Thresh is not provided!" );
94 }
95
96 // check that red and green thresholds are in range
97 if (m_redTh > 1 || m_redTh < 0 || m_greenTh > 1 || m_greenTh < 0){
98 throw dqm_core::BadConfig( ERS_HERE, name, "thresholds m_redTh and m_greenTh must be in the range [0,1]! Threshold(s) out of range." );
99 }
100
101 // check that red threshold is greater than or equal to green
102 if (m_redTh < m_greenTh){
103 throw dqm_core::BadConfig( ERS_HERE, name, "m_redTh must be above or equal to m_greenTh!" );
104 }
105
106 //Check of statistics - only call algorithm if we meet minimum statistics requirement
107 if (hist->GetEntries() < m_minstat ) {
108 ERS_INFO("Histogram does not satisfy MinStat requirement " <<hist->GetName());
109 dqm_core::Result *result = new dqm_core::Result(dqm_core::Result::Undefined);
110 result->tags_["InsufficientEntries"] = hist->GetEntries();
111 return result;
112 }
113 ERS_DEBUG(1,"Statistics: "<< hist->GetEntries()<< " entries ");
114
115 // Calling algorithm - return value in range [0,1]
116 dqm_core::Result* result = new dqm_core::Result();
117 double percent = calculatePercentage(hist, result);
118 if (percent == -1.){ // percentage invalid; result with tag for reason of failing is updated by helper function
119 return result;
120 }
121
122 // Result
123 result->tags_["Entries_under_selection(%)"] = percent;
124
125 if( percent <= m_greenTh ) { // percentage of "bad" events below green threshold
126 result->status_ = dqm_core::Result::Green;
127 }
128 else if( percent > m_greenTh && percent <= m_redTh ) { // percentage of "bad" events between green and red threshold
129 result->status_ = dqm_core::Result::Yellow;
130 }
131 else { // percentage of "bad" events above red threshold
132 result->status_ = dqm_core::Result::Red;
133 }
134
135 // Return the result
136 return result;
137}
double calculatePercentage(const TH1 *hist, dqm_core::Result *result)
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)
#define IsA
Declare the TObject style functions.

◆ printDescription()

void dqm_algorithms::ZDCPercentageThreshTests::printDescription ( std::ostream & out)
virtualinherited

Definition at line 199 of file ZDCPercentageThreshTests.cxx.

199 {
200 std::string message;
201 message += "\n";
202 message += "Algorithm: ZDCPercentEvents_" + m_name + "\n";
203 if (m_name == "XthBin"){
204 message += "Description: Retrieve the percent of entries in the x-th bin and compare it with user defined green and red Threshold\n";
205 }else if (m_name == "XthBin_NormalizeToFirstBin"){
206 message += "Description: Retrieve the percent of entries in the x-th bin, normalized to #entries in the first bin, and compare it with user defined green and red Threshold\n";
207 }else if (m_name == "AboveThreshold"){
208 message += "Description: Compute the percent of entries above a threshold and compare it with user defined green and red Threshold\n";
209 }else if (m_name == "UnderThreshold"){
210 message += "Description: Compute the percent of entries under a threshold and compare it with user defined green and red Threshold\n";
211 }
212 message += " Green if below green Threshold; red if above red Threshold\n";
213
214 message += "Mandatory Green/Red Threshold: PercentBar: Percent bar imposed upon #entries passing selection";
215 if (m_name == "XthBin" || m_name == "XthBin_NormalizeToFirstBin"){
216 message += "Mandatory Parameter: BinNum = number of the bin we impose check on\n";
217 }else if (m_name == "AboveThreshold" || m_name == "UnderThreshold"){
218 message += "Mandatory Parameter: Thresh = threshold\n";
219 }
220 message += "Optional Parameters: MinStat = Minimum histogram statistics needed to perform Algorithm\n";
221 message += "\n";
222
223 out << message;
224}

Member Data Documentation

◆ m_binNum

int dqm_algorithms::ZDCPercentageThreshTests::m_binNum {}
privateinherited

Definition at line 42 of file ZDCPercentageThreshTests.h.

42{};

◆ m_greenTh

double dqm_algorithms::ZDCPercentageThreshTests::m_greenTh {}
privateinherited

Definition at line 40 of file ZDCPercentageThreshTests.h.

40{};

◆ m_minstat

double dqm_algorithms::ZDCPercentageThreshTests::m_minstat {}
privateinherited

Definition at line 38 of file ZDCPercentageThreshTests.h.

38{};

◆ m_name

std::string dqm_algorithms::ZDCPercentageThreshTests::m_name
privateinherited

Definition at line 37 of file ZDCPercentageThreshTests.h.

◆ m_redTh

double dqm_algorithms::ZDCPercentageThreshTests::m_redTh {}
privateinherited

Definition at line 41 of file ZDCPercentageThreshTests.h.

41{};

◆ m_thresh

double dqm_algorithms::ZDCPercentageThreshTests::m_thresh {}
privateinherited

Definition at line 39 of file ZDCPercentageThreshTests.h.

39{};

The documentation for this struct was generated from the following file: