ATLAS Offline Software
MDTChi2.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: MDTChi2.cxx,v 1.0 2008/10/08 Valerio Consorti
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 #include "TMath.h"
21 
22 #include "dqm_core/exceptions.h"
23 #include "dqm_core/AlgorithmConfig.h"
24 #include "dqm_core/AlgorithmManager.h"
25 #include "dqm_core/Result.h"
27 #include "ers/ers.h"
28 
29 static dqm_algorithms::MDTChi2 staticInstance;
30 
31 
32 namespace dqm_algorithms {
33 
34 // *********************************************************************
35 // Public Methods
36 // *********************************************************************
37 
39  : m_name("MDTchi2")
40 {
41  dqm_core::AlgorithmManager::instance().registerAlgorithm( m_name, this );
42 }
43 
44 
46 {
47 }
48 
49 
52 {
53  return new MDTChi2(*this);
54 }
55 
56 
58 MDTChi2::execute( const std::string& name, const TObject& object, const dqm_core::AlgorithmConfig& config)
59 {
60  const TH1 * hist;
61  const TH1 * ref;
62 
63  if( object.IsA()->InheritsFrom( "TH1" ) ) {
64  hist = static_cast<const TH1*>(&object);
65  if (hist->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 greenTh;
75  double redTh;
76  try {
77  minstat = dqm_algorithms::tools::GetFirstFromMap("MinStat", config.getParameters(), 50);
78  redTh = dqm_algorithms::tools::GetFromMap( "Limits", config.getRedThresholds());
79  greenTh = dqm_algorithms::tools::GetFromMap( "Limits", config.getGreenThresholds() );
80  }
81  catch ( dqm_core::Exception & ex ) {
82  throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
83  }
84 
85  //Get Reference Histo
86 
87  try {
88  ref = static_cast<const TH1*>( config.getReference() );
89  }
90  catch ( dqm_core::Exception & ex ) {
91  throw dqm_core::BadRefHist(ERS_HERE,name," Could not retreive reference");
92  }
93  if (hist->GetDimension() != ref->GetDimension() ) {
94  throw dqm_core::BadRefHist( ERS_HERE, name, "Reference VS histo: Different dimension!" );
95  }
96  if (hist->GetNbinsX() != ref->GetNbinsX() ) {
97  throw dqm_core::BadRefHist( ERS_HERE, name, "Reference VS histo: Different bin numbre in X axis!" );
98  }
99 
100  //Check of statistics
101  if (hist->GetEntries() < minstat ) {
102  ERS_INFO("Histogram does not satisfy MinStat requirement " <<hist->GetName());
104  result->tags_["InsufficientEntries"] = hist->GetEntries();
105  return result;
106  }
107  ERS_DEBUG(1,"Statistics: "<< hist->GetEntries()<< " entries ");
108 
109 
110  //Algo
111 
112  int i = 0;
113  int count = 1;
114  Double_t n = 0;
115  Double_t n_ref = 0;
116  Double_t chi2 = 0;
117  int max_bin = hist -> GetNbinsX();
118  Double_t N = hist -> GetEntries();
119  Double_t N_ref = ref -> GetEntries();
120 
121  if(N == 0){
122  ERS_INFO("Histogram has no entries" <<hist->GetName());
124  result->tags_["InsufficientEntries"] = hist->GetEntries();
125  return result;
126  };
127 
128  if(N_ref == 0){
129  ERS_INFO("Reference histogram has no entries" <<hist->GetName());
131  result->tags_["InsufficientRefEntries"] = ref->GetEntries();
132  return result;
133  };
134 
135  double norm=1;
136  double norm_ref=1;
137 
138  if(N != 0) norm=1/N;
139  if(N_ref != 0) norm_ref=1/N_ref;
140 
141  for(i=1;i<=max_bin;i++){
142  n = hist->GetBinContent(i);
143  n_ref = ref->GetBinContent(i);
144  if( n != 0 || n_ref != 0) chi2+=(n*norm-n_ref*norm_ref)*(n*norm-n_ref*norm_ref)/(n*norm*norm+n_ref*norm_ref*norm_ref);
145  if( n == 0 && n_ref == 0) count++;
146  };
147 
148  Double_t prob=0;
149  prob=TMath::Prob(chi2,(max_bin-count));
150 
151 
152  //Result
153 
155  result->tags_["chi2_prob"] = prob;
156 
157  if (prob>greenTh) {
158  result->status_ = dqm_core::Result::Green;
159  ERS_DEBUG(1,"Green");
160  } else if ( prob<=greenTh && prob>redTh ) {
161  result->status_ = dqm_core::Result::Yellow;
162  ERS_DEBUG(1,"Yellow");
163  } else if (prob<=redTh) {
164  result->status_ = dqm_core::Result::Red;
165  ERS_DEBUG(1,"Red");
166  }
167  return result;
168 }
169 
170 
171 void
173 {
174  std::string message;
175  message += "\n";
176  message += "Algorithm: \"" + m_name + "\"\n";
177  message += "Description: Perform a chi square check between input istogram and reference\n";
178  message += "Mandatory Green/Red Threshold: Limits: chi square probability limits\n";
179  message += "Optional Parameters: MinStat = Minimum histogram statistics needed to perform Algorithm\n";
180  message += "\n";
181 
182  out << message;
183 }
184 
185 } // namespace dqm_algorithms
PlotCalibFromCool.norm
norm
Definition: PlotCalibFromCool.py:100
Undefined
@ Undefined
Definition: MaterialTypes.h:8
get_generator_info.result
result
Definition: get_generator_info.py:21
dqm_algorithms::MDTChi2::~MDTChi2
virtual ~MDTChi2()
Definition: MDTChi2.cxx:45
IsA
#define IsA
Declare the TObject style functions.
Definition: xAODTEventBranch.h:59
plotmaker.hist
hist
Definition: plotmaker.py:148
python.FakeAthena.Algorithm
def Algorithm(name)
Definition: FakeAthena.py:41
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
dqm_algorithms::MDTChi2::clone
virtual dqm_core::Algorithm * clone()
Definition: MDTChi2.cxx:51
JetTiledMap::N
@ N
Definition: TiledEtaPhiMap.h:44
covarianceTool.prob
prob
Definition: covarianceTool.py:678
dqm_algorithms::MDTChi2
Definition: MDTChi2.h:17
ReweightUtils.message
message
Definition: ReweightUtils.py:15
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
dqm_algorithms::MDTChi2::printDescription
virtual void printDescription(std::ostream &out)
Definition: MDTChi2.cxx:172
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
lumiFormat.i
int i
Definition: lumiFormat.py:92
beamspotman.n
n
Definition: beamspotman.py:731
Result
ICscStripFitter::Result Result
Definition: CalibCscStripFitter.cxx:13
chi2
double chi2(TH1 *h0, TH1 *h1)
Definition: comparitor.cxx:522
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
Definition: AddReference.h:17
MDTChi2.h
ref
const boost::regex ref(r_ef)
TH1
Definition: rootspy.cxx:268
generate::GetEntries
double GetEntries(TH1D *h, int ilow, int ihi)
Definition: rmsFrac.cxx:20
AlgorithmHelper.h
dqm_algorithms::tools::GetFromMap
const T & GetFromMap(const std::string &pname, const std::map< std::string, T > &params)
Definition: AlgorithmHelper.h:114
dqm_algorithms::MDTChi2::execute
virtual dqm_core::Result * execute(const std::string &name, const TObject &object, const dqm_core::AlgorithmConfig &config)
Definition: MDTChi2.cxx:58
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::MDTChi2::MDTChi2
MDTChi2()
Definition: MDTChi2.cxx:38
dqm_algorithms::MDTChi2::m_name
std::string m_name
Definition: MDTChi2.h:30