ATLAS Offline Software
MDTTubeCheck.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: 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 //#include <TF1.h>
19 //#include <TProfile.h>
20 
21 #include "dqm_core/exceptions.h"
22 #include "dqm_core/AlgorithmConfig.h"
23 #include "dqm_core/AlgorithmManager.h"
24 #include "dqm_core/Result.h"
26 #include "ers/ers.h"
27 
28 
29 static dqm_algorithms::MDTTubeCheck staticInstance;
30 
31 
32 namespace dqm_algorithms {
33 
34 // *********************************************************************
35 // Public Methods
36 // *********************************************************************
37 
39  : m_name("MDTTubeCheck")
40 {
41  dqm_core::AlgorithmManager::instance().registerAlgorithm( m_name, this );
42 }
43 
44 
46 {
47 }
48 
49 
52 {
53  return new MDTTubeCheck(*this);
54 }
55 
56 
58 MDTTubeCheck::execute( const std::string& name, const TObject& object, const dqm_core::AlgorithmConfig& config)
59 {
60  const TH1 * histogram(0);
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 refcheck;
76  double greenTh;
77  double redTh;
78  double LowStatLevel;
79  try {
80  bin_threshold = dqm_algorithms::tools::GetFirstFromMap( "BinThreshold", config.getParameters());
81  refcheck = dqm_algorithms::tools::GetFirstFromMap( "ReferenceCheck", config.getParameters());
82  LowStatLevel = dqm_algorithms::tools::GetFirstFromMap( "LowStatLevel", config.getParameters(), 10);
83  minstat = dqm_algorithms::tools::GetFirstFromMap( "MinStat", config.getParameters(), -1);
84  redTh = dqm_algorithms::tools::GetFromMap( "NBins", config.getRedThresholds());
85  greenTh = dqm_algorithms::tools::GetFromMap( "NBins", config.getGreenThresholds() );
86  }
87  catch ( dqm_core::Exception & ex ) {
88  throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
89  }
90 
91  //Get Reference Histo
92  if (refcheck>0) {
93  try {
94  refhist = static_cast<const TH1*>( config.getReference() );
95  }
96  catch ( dqm_core::Exception & ex ) {
97  throw dqm_core::BadRefHist(ERS_HERE,name," Could not retreive reference");
98  }
99  if (histogram->GetDimension() != refhist->GetDimension() ) {
100  throw dqm_core::BadRefHist( ERS_HERE, name, "Reference VS histo: Different dimension!" );
101  }
102  if (histogram->GetNbinsX() != refhist->GetNbinsX() ) {
103  throw dqm_core::BadRefHist( ERS_HERE, name, "Reference VS histo: Different number of bins!" );
104  }
105  }
106 
107  //Check of statistics
108  if (histogram->GetEntries() < minstat ) {
109  ERS_INFO("Histogram does not satisfy MinStat requirement " <<histogram->GetName());
111  result->tags_["InsufficientEntries"] = histogram->GetEntries();
112  return result;
113  }
114  ERS_DEBUG(1,"Statistics: "<< histogram->GetEntries()<< " entries ");
115 
116  int NewDead_count = 0;
117  int StillDead_count = 0;
118  int Revived_count = 0;
119  int LowStat_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 
128  std::vector<int> Tubes;
129  for ( int i = range[0]; i <= range[1]; ++i ) {
130  double content = histogram->GetBinContent(i);
131  if (content == LowStatLevel) {
132  ++LowStat_count;
133  } else if (content != 0.) {
134  if (refcheck>0) {
135  double RefCont = refhist->GetBinContent(i);
136  if ((content < bin_threshold) && ((RefCont >= bin_threshold) || (RefCont == LowStatLevel))) {
137  ++NewDead_count;
138  Tubes.push_back(i);
139  } else if ((content < bin_threshold) && ((RefCont < bin_threshold) || (RefCont == LowStatLevel))) {
140  ++StillDead_count;
141  } else if ((content >= bin_threshold) && (RefCont < bin_threshold)) {
142  ++Revived_count;
143  }
144  } else {
145  if (((content < bin_threshold) ) ) {
146  ++NewDead_count;
147  Tubes.push_back(i);
148  }
149  }
150  }
151  }
152  ERS_DEBUG(1,"Number of bins " << name << " different from a treshold of " << bin_threshold << " is " << NewDead_count );
153 
155  if (LowStat_count > 0) result->tags_["NTubes_withLowStat"] = LowStat_count;
156  if (Revived_count > 0) result->tags_["NTubes_Revived"] = Revived_count;
157  result->tags_["NewDead_Tubes"] = NewDead_count;
158  if (Tubes.size()>0) {
159  for (int k=0; k<(int)Tubes.size(); k++) {
160  std::string ToDB="ChangedStatusTube_";
161  char* nn;
162  asprintf(&nn, "%i", k+1);
163  ToDB += nn;
164  result->tags_[ToDB] = Tubes[k];
165  ERS_DEBUG(1,"MDT Tube which changed status: "<<ToDB<<" = "<<Tubes[k] );
166  }
167  }
168  if (NewDead_count >= redTh) {
169  result->status_ = dqm_core::Result::Red;
170  ERS_DEBUG(1,"Red");
171  } else if ( (NewDead_count > greenTh) || (Revived_count > 0)) {
172  result->status_ = dqm_core::Result::Yellow;
173  ERS_DEBUG(1,"Yellow");
174  } else if (LowStat_count > 0) {
176  ERS_DEBUG(1,"Undefined");
177  } else if (StillDead_count == range[1]) {
178  //All tubes are still dead
180  } else {
181  result->status_ = dqm_core::Result::Green;
182  ERS_DEBUG(1,"Green");
183  }
184  return result;
185 }
186 
187 
188 void
190 {
191  std::string message;
192  message += "\n";
193  message += "Algorithm: \"" + m_name + "\"\n";
194  message += "Description: Check if the number of entries in bins is less than BinThreshold and compare with Reference Histo \n";
195  message += "Mandatory Parameter: BinThreshold = Look for bins less than BinTreshold; Count number of bins satifying requirement \n";
196  message += "Mandatory Parameter: ReferenceCheck = 0 if no check on reference is requested \n";
197  message += "Mandatory Green/Red Threshold: NBins = number of bins satifying requirement\n";
198  message += "Optional Parameters: LowStatLevel = Level (in y) that means too few statistics for analysis\n";
199  message += "Optional Parameters: MinStat = Minimum histogram statistics needed to perform Algorithm\n";
200  message += " xmin: minimum x range\n";
201  message += " xmax: maximum x range\n";
202  message += "\n";
203 
204  out << message;
205 }
206 
207 } // 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.FakeAthena.Algorithm
def Algorithm(name)
Definition: FakeAthena.py:41
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:189
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:58
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
python.handimod.Red
Red
Definition: handimod.py:551
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
dqm_algorithms::MDTTubeCheck::MDTTubeCheck
MDTTubeCheck()
Definition: MDTTubeCheck.cxx:38
TH1::GetBinContent
double GetBinContent(int) const
Definition: rootspy.cxx:298
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::MDTTubeCheck::~MDTTubeCheck
virtual ~MDTTubeCheck()
Definition: MDTTubeCheck.cxx:45
dqm_algorithms::MDTTubeCheck::clone
virtual dqm_core::Algorithm * clone()
Definition: MDTTubeCheck.cxx:51
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