ATLAS Offline Software
Loading...
Searching...
No Matches
MDTTubeCheckError.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5// **********************************************************************
6// $Id: MDTTubeCheckError.cxx,v 1.0 2008/31/07 Elena Solfaroli Camillocci
7// **********************************************************************
8
10
11
12
13#include <TClass.h>
14#include <TH1.h>
15#include <TAxis.h>
16
17
18#include "dqm_core/exceptions.h"
19#include "dqm_core/AlgorithmConfig.h"
20#include "dqm_core/AlgorithmManager.h"
21#include "dqm_core/Result.h"
23#include "ers/ers.h"
24#include <cmath>
25#include <iostream>
26#include <map>
27
29
30
31namespace dqm_algorithms {
32
33// *********************************************************************
34// Public Methods
35// *********************************************************************
36
38 : m_name("MDTTubeCheckError")
39{
40 dqm_core::AlgorithmManager::instance().registerAlgorithm( m_name, this );
41}
42
43
47
48
49dqm_core::Algorithm*
51{
52 return new MDTTubeCheckError(*this);
53}
54
55
56dqm_core::Result*
57MDTTubeCheckError::execute( const std::string& name, const TObject& object, const dqm_core::AlgorithmConfig& config)
58{
59 const TH1* histogram;
60 const TH1* refhist=0;
61
62 if( object.IsA()->InheritsFrom( "TH1" ) ) {
63 histogram = static_cast<const TH1*>(&object);
64 if (histogram->GetDimension() >= 2 ){
65 throw dqm_core::BadConfig( ERS_HERE, name, "dimension >= 2 " );
66 }
67 } else {
68 throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" );
69 }
70
71 //Get Parameters and Thresholds
72 double minstat;
73 double bin_threshold;
74 double nErr;
75 double LowStatErr;
76 double LowStatThre;
77 double refcheck;
78 double greenTh;
79 double redTh;
80 try {
81 bin_threshold = dqm_algorithms::tools::GetFirstFromMap( "BinThreshold", config.getParameters());
82 nErr = dqm_algorithms::tools::GetFirstFromMap( "nErrBin", config.getParameters());
83 LowStatErr = dqm_algorithms::tools::GetFirstFromMap( "LowStatErr", config.getParameters(), 99999.);
84 LowStatThre = dqm_algorithms::tools::GetFirstFromMap( "LowStatThre", config.getParameters(), 0.);
85 refcheck = dqm_algorithms::tools::GetFirstFromMap( "ReferenceCheck", config.getParameters());
86 minstat = dqm_algorithms::tools::GetFirstFromMap("MinStat", config.getParameters(), -1);
87 redTh = dqm_algorithms::tools::GetFromMap( "NBins", config.getRedThresholds());
88 greenTh = dqm_algorithms::tools::GetFromMap( "NBins", config.getGreenThresholds() );
89 }
90 catch ( dqm_core::Exception & ex ) {
91 throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
92 }
93
94 //Get Reference Histo
95 if (refcheck>0) {
96 try {
97 refhist = static_cast<const TH1*>( config.getReference() );
98 }
99 catch ( dqm_core::Exception & ex ) {
100 throw dqm_core::BadRefHist(ERS_HERE,name," Could not retreive reference");
101 }
102 if (histogram->GetDimension() != refhist->GetDimension() ) {
103 throw dqm_core::BadRefHist( ERS_HERE, name, "Reference VS histo: Different dimension!" );
104 }
105 if (histogram->GetNbinsX() != refhist->GetNbinsX() ) {
106 throw dqm_core::BadRefHist( ERS_HERE, name, "Reference VS histo: Different number of bins!" );
107 }
108 }
109
110 //Check of statistics
111 if (histogram->GetEntries() < minstat ) {
112 ERS_INFO("Histogram does not satisfy MinStat requirement " <<histogram->GetName());
113 dqm_core::Result *result = new dqm_core::Result(dqm_core::Result::Undefined);
114 result->tags_["InsufficientEntries"] = histogram->GetEntries();
115 return result;
116 }
117 ERS_DEBUG(1,"Statistics: "<< histogram->GetEntries()<< " entries ");
118
119 int count = 0;
120 std::vector<int> range;
121 if (histogram->GetDimension() == 1){
122 range = dqm_algorithms::tools::GetBinRange(histogram, config.getParameters());
123 } else {
124 ERS_INFO("Histogram has not dimension 1 : " <<histogram->GetName());
125 throw dqm_core::Exception( ERS_HERE, histogram->GetName() );
126 }
127 if (range[1] == 0) {
128 ERS_INFO("Empty histogram: " <<histogram->GetName());
129 dqm_core::Result* result = new dqm_core::Result();
130 result->status_ = dqm_core::Result::Undefined;
131 ERS_DEBUG(1,"Undefined");
132 return result;
133 }
134
135 std::vector<int> Tubes;
136 int EmptyTubes =0;
137 int LowStatTubes =0;
138 for ( int i = range[0]; i <= range[1]; ++i ) {
139 double Content = histogram->GetBinContent(i);
140 double ErrCont = histogram->GetBinError(i);
141 if (ErrCont > LowStatErr) LowStatTubes++;
142 if (Content+std::abs(ErrCont) != 0.) {
143 if ((Content + nErr*ErrCont) < bin_threshold ) {
144 if (refcheck>0) {
145 double RefCont = refhist->GetBinContent(i);
146 double RefErrCont = refhist->GetBinError(i);
147 double Diff = std::abs(Content - RefCont);
148 double ErrDiff = sqrt(ErrCont*ErrCont + RefErrCont*RefErrCont);
149 if (Diff > nErr*ErrDiff) {
150 ++count;
151 Tubes.push_back(i);
152 }
153 } else {
154 ++count;
155 Tubes.push_back(i);
156 }
157 }
158 } else { ++EmptyTubes; }
159 }
160 ERS_DEBUG(1,"Number of bins " << name << " different from a treshold of " << bin_threshold << " is " << count );
161
162 dqm_core::Result* result = new dqm_core::Result();
163 result->tags_["NChangedStatusTubes"] = count;
164 if (Tubes.size()>0) {
165 for (int k=0; k<(int)Tubes.size(); k++) {
166 std::string ToDB="ChangedStatusTube_";
167 ToDB += std::to_string(k+1);
168 result->tags_[ToDB] = Tubes[k];
169 ERS_DEBUG(1,"MDT Tube which changed status: "<<ToDB<<" = "<<Tubes[k] );
170 }
171 }
172
173 if ((EmptyTubes == range[1]) || ((static_cast<double>(LowStatTubes)/range[1]) > LowStatThre)) {
174 result->status_ = dqm_core::Result::Undefined;
175 ERS_DEBUG(1,"Undefined");
176 } else if (count >= redTh) {
177 result->status_ = dqm_core::Result::Red;
178 ERS_DEBUG(1,"Red");
179 } else if ( count > greenTh) {
180 result->status_ = dqm_core::Result::Yellow;
181 ERS_DEBUG(1,"Yellow");
182 } else {
183 result->status_ = dqm_core::Result::Green;
184 ERS_DEBUG(1,"Green");
185 }
186 return result;
187}
188
189
190void
192{
193 std::string message;
194 message += "\n";
195 message += "Algorithm: \"" + m_name + "\"\n";
196 message += "Description: Check if the number of entries in bins is less than BinThreshold and compare with Reference Histo \n";
197 message += "Mandatory Parameter: BinThreshold: Look for bins less than BinTreshold; Count number of bins satifying requirement \n";
198 message += "Mandatory Parameter: nErrBin: n-sigma of acceptance for check with the BinTreshold \n";
199 message += "Mandatory Parameter: ReferenceCheck: 0 if no check on reference is requested \n";
200 message += "Mandatory Green/Red Threshold: NBins: number of bins satifying requirement\n";
201 message += "Optional Parameters: MinStat = Minimum histogram statistics needed to perform Algorithm\n";
202 message += " LowStatErr = error threshold for bin with too low statistics \n";
203 message += " LowStatThre = threshold for fraction of bins with too low statistics \n";
204 message += " xmin: minimum x range\n";
205 message += " xmax: maximum x range\n";
206 message += "\n";
207
208 out << message;
209}
210
211} // namespace dqm_algorithms
static dqm_algorithms::AveragePrint staticInstance
std::string histogram
Definition chains.cxx:52
virtual void printDescription(std::ostream &out)
virtual dqm_core::Algorithm * clone()
virtual dqm_core::Result * execute(const std::string &name, const TObject &object, const dqm_core::AlgorithmConfig &config)
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146
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)
#define IsA
Declare the TObject style functions.