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

#include <Bins_LessThanNonZeroMedian_Threshold.h>

Inheritance diagram for dqm_algorithms::Bins_LessThanNonZeroMedian_Threshold:
Collaboration diagram for dqm_algorithms::Bins_LessThanNonZeroMedian_Threshold:

Public Member Functions

 Bins_LessThanNonZeroMedian_Threshold ()
BinThresholdclone ()
dqm_core::Result * execute (const std::string &, const TObject &, const dqm_core::AlgorithmConfig &)
bool CompareBinThreshold (const std::string &objname, double bincontent, double threshold)
void printDescription (std::ostream &out)
void parseIgnoreList (const std::string &bins, std::vector< std::string > &ignoredRows, std::vector< std::string > &ignoredCols, std::vector< std::pair< std::string, std::string > > &ignoredBins)

Private Attributes

std::string m_name

Detailed Description

Definition at line 17 of file Bins_LessThanNonZeroMedian_Threshold.h.

Constructor & Destructor Documentation

◆ Bins_LessThanNonZeroMedian_Threshold()

dqm_algorithms::Bins_LessThanNonZeroMedian_Threshold::Bins_LessThanNonZeroMedian_Threshold ( )
inline

Definition at line 19 of file Bins_LessThanNonZeroMedian_Threshold.h.

19: BinThreshold("LessThanNonZeroMedian") {};
BinThreshold(const std::string &name)

Member Function Documentation

◆ clone()

dqm_algorithms::BinThreshold * dqm_algorithms::BinThreshold::clone ( )
inherited

Definition at line 44 of file BinThreshold.cxx.

45{
46
47 return new BinThreshold( m_name );
48}

◆ CompareBinThreshold()

bool dqm_algorithms::BinThreshold::CompareBinThreshold ( const std::string & objname,
double bincontent,
double threshold )
inherited

Definition at line 254 of file BinThreshold.cxx.

254 {
255
256 if (type == "GreaterThan") return (bincontent > threshold);
257 if (type == "GreaterThanAbs") return (std::abs(bincontent) > threshold);
258 if (type == "GreaterThanNonZeroMedian") return (bincontent > threshold);
259 if (type == "LessThan") return (bincontent < threshold);
260 if (type == "LessThanAbs") return (std::abs(bincontent) < threshold);
261 if (type == "LessThanNonZeroMedian") return (bincontent < threshold);
262 if (type == "LessThanEqual") return (bincontent <= threshold);
263 if (type == "GreaterThanEqual") return (bincontent >= threshold);
264 if (type == "Equal") return (bincontent == threshold);
265 if (type == "NotEqual") return (bincontent != threshold);
266
267 return 0;
268}

◆ execute()

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

Definition at line 52 of file BinThreshold.cxx.

55{
56 const TH1 * histogram;
57
58 if( object.IsA()->InheritsFrom( "TH1" ) ) {
59 histogram = static_cast<const TH1*>(&object);
60 if (histogram->GetDimension() > 2 ){
61 throw dqm_core::BadConfig( ERS_HERE, name, "dimension > 2 " );
62 }
63 } else {
64 throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" );
65 }
66
67 const double minstat = dqm_algorithms::tools::GetFirstFromMap( "MinStat", config.getParameters(), -1);
68 const bool publish = (bool) dqm_algorithms::tools::GetFirstFromMap( "PublishBins", config.getParameters(), 0);
69 const int maxpublish = (int) dqm_algorithms::tools::GetFirstFromMap( "MaxPublish", config.getParameters(), 20);
70 const int xmax = (int) dqm_algorithms::tools::GetFirstFromMap( "xMax", config.getParameters(), -1);
71 const int xmin = (int) dqm_algorithms::tools::GetFirstFromMap( "xMin", config.getParameters(), -1);
72 const int ymax = (int) dqm_algorithms::tools::GetFirstFromMap( "yMax", config.getParameters(), -1);
73 const int ymin = (int) dqm_algorithms::tools::GetFirstFromMap( "yMin", config.getParameters(), -1);
74
75 std::string ignoreBins = dqm_algorithms::tools::GetFirstFromMap("IgnoreBins", config.getGenericParameters(), "-1");
76
77 std::vector<std::string> hotRows;
78 std::vector<std::string> hotCols;
79 std::vector<std::pair<std::string,std::string>> hotBins;
80
81 parseIgnoreList(ignoreBins, hotRows, hotCols, hotBins);
82
83 if (histogram->GetEntries() < minstat ) {
84 dqm_core::Result *result = new dqm_core::Result(dqm_core::Result::Undefined);
85 result->tags_["InsufficientEntries"] = histogram->GetEntries();
86 return result;
87 }
88
89 double bin_threshold;
90 double gthreshold;
91 double rthreshold;
92 try {
93 bin_threshold = dqm_algorithms::tools::GetFirstFromMap( "BinThreshold", config.getParameters() );
94 rthreshold = dqm_algorithms::tools::GetFromMap( "NBins", config.getRedThresholds() );
95 gthreshold = dqm_algorithms::tools::GetFromMap( "NBins", config.getGreenThresholds() );
96 }
97 catch ( dqm_core::Exception & ex ) {
98 throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
99 }
100
101
102 int count = 0;
103 std::vector<int> range=dqm_algorithms::tools::GetBinRange(histogram, config.getParameters());
104 dqm_core::Result* result = new dqm_core::Result();
105 TH1* resulthisto;
106 if (histogram->InheritsFrom("TH2")) {
107 resulthisto=(TH1*)(histogram->Clone());
108 } else if (histogram->InheritsFrom("TH1")) {
109 resulthisto=(TH1*)(histogram->Clone());
110 } else {
111 throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" );
112 }
113
114 resulthisto->Reset();
115 if(m_name.find("Median")!=std::string::npos){
116 std::vector<double> bin_vals;
117 for ( int i = range[0]; i <= range[1]; ++i ) {
118 for ( int j = range[2]; j <= range[3]; ++j ) {
119 if(histogram -> GetBinContent(i,j) > 0) bin_vals . push_back( histogram -> GetBinContent(i,j) );
120 }
121 }
122 std::sort(bin_vals.begin(), bin_vals.end());
123 unsigned bin_vals_size = bin_vals.size();
124 double median = 0;
125 if(bin_vals_size%2==0 && bin_vals_size>1) median = (bin_vals.at(bin_vals_size/2-1)+bin_vals.at(bin_vals_size/2))/2;
126 else if(bin_vals_size%2==1 && bin_vals_size>1) median = bin_vals.at(bin_vals_size/2-1);
127 else if(bin_vals_size==1) median = bin_vals.at(0);
128
129 double min_bin_threshold = dqm_algorithms::tools::GetFirstFromMap( "MinBinThreshold", config.getParameters() , -99999);
130 double max_bin_threshold = dqm_algorithms::tools::GetFirstFromMap( "MaxBinTrheshold", config.getParameters() , -99999);
131 bin_threshold=median*bin_threshold;
132
133 bin_threshold = std::max(bin_threshold, min_bin_threshold);
134 if(max_bin_threshold > -1 ) bin_threshold = std::min(bin_threshold, max_bin_threshold);
135
136 result->tags_["Effective_BinThreshold"] = bin_threshold;
137 }
138
139 //bools for skiping threshold comparison of ignored rows, columns and bins
140 bool skipCol;
141 bool skipRow;
142 std::pair<bool,bool> skipBin;
143 std::pair<const char*, const char*> binLabel;
144
145 for ( int i = range[0]; i <= range[1]; ++i ) {
146 skipCol = false;
147 binLabel.first = nullptr;
148 binLabel.second = nullptr;
149
150 if ( !hotCols.empty() ) {
151 for (const auto& col : hotCols){
152
153 // Check if the given string matches the bin index or the bin label
154 binLabel.first = histogram->GetXaxis()->GetBinLabel(i);
155 if ( std::to_string(i)==col || TString(binLabel.first).Contains(TRegexp((col).c_str(),true)) ) skipCol = true;
156 }
157 }
158 //Skip column if ignored
159 if (skipCol) continue;
160
161 //Skip bin threshold comparison if xmax!=-1 and i>xmax
162 if (xmax!=-1 && i>xmax) continue;
163 //Skip bin threshold comparison if xmin!=-1 and i<xmin
164 if (xmin!=-1 && i<xmin) continue;
165
166 for ( int j = range[2]; j <= range[3]; ++j ) {
167 skipRow = false;
168 binLabel.first = nullptr;
169 binLabel.second = nullptr;
170
171 if ( !hotRows.empty() ) {
172 for (const auto& row : hotRows){
173
174 // Check if the given string matches the bin index or the bin label
175 binLabel.second = histogram->GetYaxis()->GetBinLabel(j);
176 if ( std::to_string(j)==row || TString(binLabel.second).Contains(TRegexp((row).c_str(),true)) ) skipRow = true;
177 }
178 }
179 //Skip row if ignored
180 if (skipRow) continue;
181
182 skipBin.first = false;
183 skipBin.second = false;
184 binLabel.first = nullptr;
185 binLabel.second = nullptr;
186
187 if ( !hotBins.empty() ) {
188 for (const auto& bin : hotBins){
189
190 // Check col (bin.first)
191 binLabel.first = histogram->GetXaxis()->GetBinLabel(i);
192 if ( std::to_string(i)==bin.first || TString(binLabel.first).Contains(TRegexp((bin.first).c_str(),true)) ) skipBin.first = true;
193
194 // Check row (bin.second)
195 binLabel.second = histogram->GetYaxis()->GetBinLabel(j);
196 if ( std::to_string(j)==bin.second || TString(binLabel.second).Contains(TRegexp((bin.second).c_str(),true)) ) skipBin.second = true;
197 }
198 }
199 //Skip bin if ignored
200 if (skipBin.first && skipBin.second) continue;
201
202 //Skip bin threshold comparison if ymax!=-1 and j>ymax
203 if (ymax!=-1 && j>ymax) continue;
204 //Skip bin threshold comparison if ymin!=-1 and j<ymin
205 if (ymin!=-1 && j<ymin) continue;
206
207 double content= histogram -> GetBinContent(i,j);
208 if ( CompareBinThreshold(m_name, content, bin_threshold )) {
209 ++count;
210 resulthisto->SetBinContent(i,j,content);
211 if (publish && count< maxpublish){
213 }
214 }
215 }
216 }
217
218 ERS_DEBUG(1,"Number of bins " << m_name << " treshold of " << bin_threshold << " is " << count );
219 ERS_DEBUG(1,"Green threshold: "<< gthreshold << " bin(s); Red threshold : " << rthreshold << " bin(s) ");
220
221 int TotalBins = (int) dqm_algorithms::tools::GetFirstFromMap( "TotalBins", config.getParameters() , -99999);
222 if(TotalBins > -10){
223 if(TotalBins < 0) TotalBins = histogram->GetNbinsX()*histogram->GetNbinsY()*histogram->GetNbinsZ();
224 int effectiveCount = count - (histogram->GetNbinsX()*histogram->GetNbinsY()*histogram->GetNbinsZ() - TotalBins);
225 if(m_name.find("LessThan")!=std::string::npos) result->tags_["NBins_%"] = 100.*effectiveCount/TotalBins;
226 else result->tags_["NBins_%"] = 100.*count/TotalBins;
227 }
228
229 result->tags_["NBins"] = count;
230 result->object_ = boost::shared_ptr<TObject>(resulthisto);
231 if (gthreshold > rthreshold) {
232 if ( count >= gthreshold ) {
233 result->status_ = dqm_core::Result::Green;
234 } else if ( count > rthreshold ) {
235 result->status_ = dqm_core::Result::Yellow;
236 } else {
237 result->status_ = dqm_core::Result::Red;
238 }
239 } else {
240 if ( count <= gthreshold ) {
241 result->status_ = dqm_core::Result::Green;
242 } else if ( count < rthreshold ) {
243 result->status_ = dqm_core::Result::Yellow;
244 } else {
245 result->status_ = dqm_core::Result::Red;
246 }
247 }
248
249 return result;
250
251}
static const uint32_t skipRow
static const uint32_t skipCol
std::string histogram
Definition chains.cxx:52
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146
double xmax
Definition listroot.cxx:61
double ymin
Definition listroot.cxx:63
double xmin
Definition listroot.cxx:60
double ymax
Definition listroot.cxx:64
float median(std::vector< float > &Vec)
float j(const xAOD::IParticle &, const xAOD::TrackMeasurementValidation &hit, const Eigen::Matrix3d &jab_inv)
std::vector< int > GetBinRange(const TH1 *histogram, const std::map< std::string, double > &params)
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)
str content
Definition grepfile.py:56
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
setBGCode setTAP setLVL2ErrorBits bool
void parseIgnoreList(const std::string &bins, std::vector< std::string > &ignoredRows, std::vector< std::string > &ignoredCols, std::vector< std::pair< std::string, std::string > > &ignoredBins)
bool CompareBinThreshold(const std::string &objname, double bincontent, double threshold)
#define IsA
Declare the TObject style functions.

◆ parseIgnoreList()

void dqm_algorithms::BinThreshold::parseIgnoreList ( const std::string & bins,
std::vector< std::string > & ignoredRows,
std::vector< std::string > & ignoredCols,
std::vector< std::pair< std::string, std::string > > & ignoredBins )
inherited

Definition at line 270 of file BinThreshold.cxx.

273 {
274 // Remove "" from input string
275 std::string inputBins_new = "";
276 for (char c : inputBins) if (c != '"') inputBins_new+=c;
277
278 if (!inputBins_new.empty()) {
279 std::stringstream ss(inputBins_new);
280 std::string token;
281
282 while (std::getline(ss, token, ',')) {
283 std::stringstream pairStream(token);
284 std::string first, second;
285
286 if (std::getline(pairStream, first, ':') && std::getline(pairStream, second, ':')) {
287 if (first == "*") {
288 ignoredRows.push_back(std::move(second));
289 } else if (second == "*") {
290 ignoredCols.push_back(std::move(first));
291 } else {
292 ignoredBins.push_back(std::make_pair(first,second));
293 }
294 }
295 }
296 }
297}
static Double_t ss
bool first
Definition DeMoScan.py:534

◆ printDescription()

void dqm_algorithms::BinThreshold::printDescription ( std::ostream & out)
inherited

Definition at line 300 of file BinThreshold.cxx.

301{
302
303 out<<"Bins_"+m_name+"_Threshold: Checks for number of bins "+m_name+" threshold value\n"<<std::endl;
304
305 out<<"Mandatory Parameter: BinThreshold: Look for bins "+m_name+" BinTreshold; Count number of bins satifying requirement \n"<<std::endl;
306
307 out<<"Mandatory Green/Red Threshold: NBins: Number of bins satifying "+m_name+" BinThreshold constraint to give Green/Red result\n"<<std::endl;
308
309 out<<"Optional Parameter: PublishBins: Save bins which are different from average in Result (set to 1)\n"<<std::endl;
310 out<<"Optional Parameter: MaxPublish: Max number of bins to save (default 20)"<<std::endl;
311 out<<"Optional Parameter: MinStat: Minimum histogram statistics needed to perform Algorithm"<<std::endl;
312 out<<"Optional Parameter: xmin: minimum x range"<<std::endl;
313 out<<"Optional Parameter: xmax: maximum x range"<<std::endl;
314 out<<"Optional Parameter: ymin: minimum y range"<<std::endl;
315 out<<"Optional Parameter: ymax: maximum y range\n"<<std::endl;
316 out<<"Optional Parameter: IgnoreBins: List of bins to be plotted in the DQ histograms but ignored in the DQ mismatch check>\n"<<std::endl;
317
318}

Member Data Documentation

◆ m_name

std::string dqm_algorithms::BinThreshold::m_name
privateinherited

Definition at line 37 of file BinThreshold.h.


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