ATLAS Offline Software
MDTTubeCheckError.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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 
28 static dqm_algorithms::MDTTubeCheckError staticInstance;
29 
30 
31 namespace 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 
45 {
46 }
47 
48 
49 dqm_core::Algorithm*
51 {
52  return new MDTTubeCheckError(*this);
53 }
54 
55 
57 MDTTubeCheckError::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());
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){
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());
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 
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]) || ((LowStatTubes/range[1]) > LowStatThre)) {
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 
190 void
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
dqm_algorithms::tools::GetBinRange
std::vector< int > GetBinRange(const TH1 *histogram, const std::map< std::string, double > &params)
Definition: AlgorithmHelper.cxx:380
Undefined
@ Undefined
Definition: MaterialTypes.h:8
get_generator_info.result
result
Definition: get_generator_info.py:21
IsA
#define IsA
Declare the TObject style functions.
Definition: xAODTEventBranch.h:59
dqm_algorithms::MDTTubeCheckError::~MDTTubeCheckError
virtual ~MDTTubeCheckError()
Definition: MDTTubeCheckError.cxx:44
dqm_algorithms::MDTTubeCheckError::printDescription
virtual void printDescription(std::ostream &out)
Definition: MDTTubeCheckError.cxx:191
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
dqm_algorithms::MDTTubeCheckError::m_name
std::string m_name
Definition: MDTTubeCheckError.h:33
ReweightUtils.message
message
Definition: ReweightUtils.py:15
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
lumiFormat.i
int i
Definition: lumiFormat.py:85
Result
ICscStripFitter::Result Result
Definition: CalibCscStripFitter.cxx:13
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
python.handimod.Green
int Green
Definition: handimod.py:524
dqm_algorithms::MDTTubeCheckError
Definition: MDTTubeCheckError.h:20
MDTTubeCheckError.h
python.handimod.Red
Red
Definition: handimod.py:551
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
dqm_algorithms::MDTTubeCheckError::execute
virtual dqm_core::Result * execute(const std::string &name, const TObject &object, const dqm_core::AlgorithmConfig &config)
Definition: MDTTubeCheckError.cxx:57
dqm_algorithms::MDTTubeCheckError::clone
virtual dqm_core::Algorithm * clone()
Definition: MDTTubeCheckError.cxx:50
dqm_algorithms
Definition: AddReference.h:17
AlgorithmHelper.h
dqm_algorithms::tools::GetFromMap
const T & GetFromMap(const std::string &pname, const std::map< std::string, T > &params)
Definition: AlgorithmHelper.h:114
pickleTool.object
object
Definition: pickleTool.py:30
dqm_algorithms::tools::GetFirstFromMap
double GetFirstFromMap(const std::string &paramName, const std::map< std::string, double > &params)
Definition: AlgorithmHelper.cxx:339
dqm_algorithms::MDTTubeCheckError::MDTTubeCheckError
MDTTubeCheckError()
Definition: MDTTubeCheckError.cxx:37
histogram
std::string histogram
Definition: chains.cxx:52
fitman.k
k
Definition: fitman.py:528