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