ATLAS Offline Software
Loading...
Searching...
No Matches
MDTPercentUnderThresh.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5// **********************************************************************
6// $Id: MDTPercentUnderThresh.cxx,v 1.0 2009/06/10 Valerio Consorti
7// **********************************************************************
8
9
11
12#include <cmath>
13#include <iostream>
14#include <map>
15
16#include <TClass.h>
17#include <TH1.h>
18#include <TF1.h>
19
20#include "dqm_core/exceptions.h"
21#include "dqm_core/AlgorithmConfig.h"
22#include "dqm_core/AlgorithmManager.h"
23#include "dqm_core/Result.h"
25#include "ers/ers.h"
26
27
29
30
31namespace dqm_algorithms {
32
33// *********************************************************************
34// Public Methods
35// *********************************************************************
36
38 : m_name("MDTpercent_under_thresh")
39{
40 dqm_core::AlgorithmManager::instance().registerAlgorithm( m_name, this );
41}
42
43
47
48
49dqm_core::Algorithm*
54
55
56dqm_core::Result*
57MDTPercentUnderThresh::execute( const std::string& name, const TObject& object, const dqm_core::AlgorithmConfig& config)
58{
59 const TH1 * hist;
60
61 if( object.IsA()->InheritsFrom( "TH1" ) ) {
62 hist = static_cast<const TH1*>(&object);
63 if (hist->GetDimension() >= 2 ){
64 throw dqm_core::BadConfig( ERS_HERE, name, "dimension >= 2 " );
65 }
66 } else {
67 throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" );
68 }
69
70 //Get Parameters and Thresholds
71 double minstat;
72 double thresh;
73 double greenTh;
74 double redTh;
75 try {
76 thresh = dqm_algorithms::tools::GetFirstFromMap( "Thresh", config.getParameters());
77 minstat = dqm_algorithms::tools::GetFirstFromMap("MinStat", config.getParameters(), 0);
78 redTh = dqm_algorithms::tools::GetFromMap( "Percent", config.getRedThresholds());
79 greenTh = dqm_algorithms::tools::GetFromMap( "Percent", config.getGreenThresholds() );
80 }
81 catch ( dqm_core::Exception & ex ) {
82 throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
83 }
84
85 //Check of statistics
86 if (hist->GetEntries() < minstat ) {
87 ERS_INFO("Histogram does not satisfy MinStat requirement " <<hist->GetName());
88 dqm_core::Result *result = new dqm_core::Result(dqm_core::Result::Undefined);
89 result->tags_["InsufficientEntries"] = hist->GetEntries();
90 return result;
91 }
92 ERS_DEBUG(1,"Statistics: "<< hist->GetEntries()<< " entries ");
93
94 //Algo
95
96 Double_t hit_under_th=0;
97
98 Double_t N = hist->GetEntries();
99
100 if(N == 0) {
101 dqm_core::Result* result = new dqm_core::Result();
102 result->tags_["Empty_Histogram_found_N_Entries"] = N;
103 result->status_ = dqm_core::Result::Undefined;
104 return result;
105 };
106
107 int i=0;
108
109 do{
110 i++;
111 if(i>hist->GetNbinsX()){
112 dqm_core::Result* result = new dqm_core::Result();
113 result->tags_["Config_error_maximum_bin_exceed_looking_for_bin_number"] = i;
114 result->status_ = dqm_core::Result::Undefined;
115 return result;
116 };
117 hit_under_th += hist->GetBinContent(i);
118 }while(hist->GetBinCenter(i)<thresh);
119
120 double percent = 100 - 100*((double) hit_under_th)/((double) N);
121
122 //Result
123
124 dqm_core::Result* result = new dqm_core::Result();
125 result->tags_["Entries_above_thresh(%)"] = percent;
126
127 if( percent >= greenTh ) {
128 result->status_ = dqm_core::Result::Green;
129 }
130 else if( percent <greenTh && percent>redTh ) {
131 result->status_ = dqm_core::Result::Yellow;
132 }
133 else {
134 result->status_ = dqm_core::Result::Red;
135 }
136
137 // Return the result
138 return result;
139}
140
141
142void
144 std::string message;
145 message += "\n";
146 message += "Algorithm: \"" + m_name + "\"\n";
147 message += "Description: Compute the percent of entries above a threshold and and compare it with user defined green and red Threshold\n";
148 message += "Mandatory Parameters: Green/Red Threshold: Percent: Percent of the entries above threshold requested";
149 message += "Optional Parameters: MinStat = Minimum histogram statistics needed to perform Algorithm\n";
150 message += " thresh = threshold\n";
151 message += "\n";
152
153 out << message;
154}
155
156} // namespace dqm_algorithms
static dqm_algorithms::AveragePrint staticInstance
virtual void printDescription(std::ostream &out)
virtual dqm_core::Result * execute(const std::string &name, const TObject &data, const dqm_core::AlgorithmConfig &config)
virtual dqm_core::Algorithm * clone()
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.