ATLAS Offline Software
MDTTubeCheck.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: MDTTubeCheck.cxx,v 1.0 2008/31/07 Elena Solfaroli Camillocci
7 // **********************************************************************
8 
10 
11 #include <cmath>
12 #include <iostream>
13 #include <map>
14 
15 #include <TClass.h>
16 #include <TH1.h>
17 #include <TAxis.h>
18 
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 
28 static dqm_algorithms::MDTTubeCheck staticInstance;
29 
30 
31 namespace dqm_algorithms {
32 
33 // *********************************************************************
34 // Public Methods
35 // *********************************************************************
36 
38  : m_name("MDTTubeCheck")
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 MDTTubeCheck(*this);
53 }
54 
55 
57 MDTTubeCheck::execute( const std::string& name, const TObject& object, const dqm_core::AlgorithmConfig& config)
58 {
59  const TH1 * histogram(0);
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 refcheck;
75  double greenTh;
76  double redTh;
77  double LowStatLevel;
78  try {
79  bin_threshold = dqm_algorithms::tools::GetFirstFromMap( "BinThreshold", config.getParameters());
80  refcheck = dqm_algorithms::tools::GetFirstFromMap( "ReferenceCheck", config.getParameters());
81  LowStatLevel = dqm_algorithms::tools::GetFirstFromMap( "LowStatLevel", config.getParameters(), 10);
82  minstat = dqm_algorithms::tools::GetFirstFromMap( "MinStat", config.getParameters(), -1);
83  redTh = dqm_algorithms::tools::GetFromMap( "NBins", config.getRedThresholds());
84  greenTh = dqm_algorithms::tools::GetFromMap( "NBins", config.getGreenThresholds() );
85  }
86  catch ( dqm_core::Exception & ex ) {
87  throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
88  }
89 
90  //Get Reference Histo
91  if (refcheck>0) {
92  try {
93  refhist = static_cast<const TH1*>( config.getReference() );
94  }
95  catch ( dqm_core::Exception & ex ) {
96  throw dqm_core::BadRefHist(ERS_HERE,name," Could not retreive reference");
97  }
98  if (histogram->GetDimension() != refhist->GetDimension() ) {
99  throw dqm_core::BadRefHist( ERS_HERE, name, "Reference VS histo: Different dimension!" );
100  }
101  if (histogram->GetNbinsX() != refhist->GetNbinsX() ) {
102  throw dqm_core::BadRefHist( ERS_HERE, name, "Reference VS histo: Different number of bins!" );
103  }
104  }
105 
106  //Check of statistics
107  if (histogram->GetEntries() < minstat ) {
108  ERS_INFO("Histogram does not satisfy MinStat requirement " <<histogram->GetName());
110  result->tags_["InsufficientEntries"] = histogram->GetEntries();
111  return result;
112  }
113  ERS_DEBUG(1,"Statistics: "<< histogram->GetEntries()<< " entries ");
114 
115  int NewDead_count = 0;
116  int StillDead_count = 0;
117  int Revived_count = 0;
118  int LowStat_count = 0;
119  std::vector<int> range;
120  if (histogram->GetDimension() == 1){
122  } else {
123  ERS_INFO("Histogram has not dimension 1 : " <<histogram->GetName());
124  throw dqm_core::Exception( ERS_HERE, histogram->GetName() );
125  }
126 
127  std::vector<int> Tubes;
128  for ( int i = range[0]; i <= range[1]; ++i ) {
129  double content = histogram->GetBinContent(i);
130  if (content == LowStatLevel) {
131  ++LowStat_count;
132  } else if (content != 0.) {
133  if (refcheck>0) {
134  double RefCont = refhist->GetBinContent(i);
135  if ((content < bin_threshold) && ((RefCont >= bin_threshold) || (RefCont == LowStatLevel))) {
136  ++NewDead_count;
137  Tubes.push_back(i);
138  } else if ((content < bin_threshold) && ((RefCont < bin_threshold) || (RefCont == LowStatLevel))) {
139  ++StillDead_count;
140  } else if ((content >= bin_threshold) && (RefCont < bin_threshold)) {
141  ++Revived_count;
142  }
143  } else {
144  if (((content < bin_threshold) ) ) {
145  ++NewDead_count;
146  Tubes.push_back(i);
147  }
148  }
149  }
150  }
151  ERS_DEBUG(1,"Number of bins " << name << " different from a treshold of " << bin_threshold << " is " << NewDead_count );
152 
154  if (LowStat_count > 0) result->tags_["NTubes_withLowStat"] = LowStat_count;
155  if (Revived_count > 0) result->tags_["NTubes_Revived"] = Revived_count;
156  result->tags_["NewDead_Tubes"] = NewDead_count;
157  if (Tubes.size()>0) {
158  for (int k=0; k<(int)Tubes.size(); k++) {
159  std::string ToDB="ChangedStatusTube_";
160  ToDB += std::to_string(k+1);
161  result->tags_[ToDB] = Tubes[k];
162  ERS_DEBUG(1,"MDT Tube which changed status: "<<ToDB<<" = "<<Tubes[k] );
163  }
164  }
165  if (NewDead_count >= redTh) {
166  result->status_ = dqm_core::Result::Red;
167  ERS_DEBUG(1,"Red");
168  } else if ( (NewDead_count > greenTh) || (Revived_count > 0)) {
169  result->status_ = dqm_core::Result::Yellow;
170  ERS_DEBUG(1,"Yellow");
171  } else if (LowStat_count > 0) {
173  ERS_DEBUG(1,"Undefined");
174  } else if (StillDead_count == range[1]) {
175  //All tubes are still dead
177  } else {
178  result->status_ = dqm_core::Result::Green;
179  ERS_DEBUG(1,"Green");
180  }
181  return result;
182 }
183 
184 
185 void
187 {
188  std::string message;
189  message += "\n";
190  message += "Algorithm: \"" + m_name + "\"\n";
191  message += "Description: Check if the number of entries in bins is less than BinThreshold and compare with Reference Histo \n";
192  message += "Mandatory Parameter: BinThreshold = Look for bins less than BinTreshold; Count number of bins satifying requirement \n";
193  message += "Mandatory Parameter: ReferenceCheck = 0 if no check on reference is requested \n";
194  message += "Mandatory Green/Red Threshold: NBins = number of bins satifying requirement\n";
195  message += "Optional Parameters: LowStatLevel = Level (in y) that means too few statistics for analysis\n";
196  message += "Optional Parameters: MinStat = Minimum histogram statistics needed to perform Algorithm\n";
197  message += " xmin: minimum x range\n";
198  message += " xmax: maximum x range\n";
199  message += "\n";
200 
201  out << message;
202 }
203 
204 } // 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
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
dqm_algorithms::MDTTubeCheck
Definition: MDTTubeCheck.h:20
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
dqm_algorithms::MDTTubeCheck::m_name
std::string m_name
Definition: MDTTubeCheck.h:33
dqm_algorithms::MDTTubeCheck::printDescription
virtual void printDescription(std::ostream &out)
Definition: MDTTubeCheck.cxx:186
MDTTubeCheck.h
ReweightUtils.message
message
Definition: ReweightUtils.py:15
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
grepfile.content
string content
Definition: grepfile.py:56
dqm_algorithms::MDTTubeCheck::execute
virtual dqm_core::Result * execute(const std::string &name, const TObject &object, const dqm_core::AlgorithmConfig &config)
Definition: MDTTubeCheck.cxx:57
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
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::MDTTubeCheck::MDTTubeCheck
MDTTubeCheck()
Definition: MDTTubeCheck.cxx:37
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::MDTTubeCheck::~MDTTubeCheck
virtual ~MDTTubeCheck()
Definition: MDTTubeCheck.cxx:44
dqm_algorithms::MDTTubeCheck::clone
virtual dqm_core::Algorithm * clone()
Definition: MDTTubeCheck.cxx:50
dqm_algorithms::tools::GetFirstFromMap
double GetFirstFromMap(const std::string &paramName, const std::map< std::string, double > &params)
Definition: AlgorithmHelper.cxx:339
histogram
std::string histogram
Definition: chains.cxx:52
fitman.k
k
Definition: fitman.py:528