ATLAS Offline Software
MDTTDCSpectrum.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: MDTTDCSpectrum.cxx,v 1.0 2008/10/08 Valerio Consorti
7 // **********************************************************************
8 
10 
11 
12 #include <TClass.h>
13 #include <TH1.h>
14 #include <TAxis.h>
15 #include <TF1.h>
16 //#include <TProfile.h>
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 
29 static dqm_algorithms::MDTTDCSpectrum staticInstance;
30 
31 
32 namespace dqm_algorithms {
33 
34 // *********************************************************************
35 // Public Methods
36 // *********************************************************************
37 
39  : m_name("MDTTDCspectrum")
40 {
41  dqm_core::AlgorithmManager::instance().registerAlgorithm( m_name, this );
42 }
43 
44 
46 {
47 }
48 
49 
52 {
53  return new MDTTDCSpectrum(*this);
54 }
55 
56 
58 MDTTDCSpectrum::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 chi2;
75  double greenTh;
76  double redTh;
77  double max_shift;
78  try {
79  minstat = dqm_algorithms::tools::GetFirstFromMap("MinStat", config.getParameters(), -1);
80  chi2 = dqm_algorithms::tools::GetFirstFromMap("chi2", config.getParameters(), -1);
81  max_shift = dqm_algorithms::tools::GetFirstFromMap("max_shift", config.getParameters(), 999999);
82  redTh = dqm_algorithms::tools::GetFromMap( "Limits", config.getRedThresholds());
83  greenTh = dqm_algorithms::tools::GetFromMap( "Limits", config.getGreenThresholds() );
84  }
85  catch ( dqm_core::Exception & ex ) {
86  throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
87  }
88 
89  //Get Reference Histo
90 
91  try {
92  ref = static_cast<const TH1*>( config.getReference() );
93  }
94  catch ( dqm_core::Exception & ex ) {
95  throw dqm_core::BadRefHist(ERS_HERE,name," Could not retreive reference");
96  }
97  if (hist->GetDimension() != ref->GetDimension() ) {
98  throw dqm_core::BadRefHist( ERS_HERE, name, "Reference VS histo: Different dimension!" );
99  }
100 
101  //Check of statistics
102  if (hist->GetEntries() < minstat ) {
103  ERS_INFO("Histogram does not satisfy MinStat requirement " <<hist->GetName());
105  result->tags_["InsufficientEntries"] = hist->GetEntries();
106  return result;
107  }
108  ERS_DEBUG(1,"Statistics: "<< hist->GetEntries()<< " entries ");
109 
110 
111  //Algo
112  Double_t chi2_per_NDF=999999999;
113 
114  TF1* fit_ref = (TF1*) ref->GetFunction("TimeSpectrum");
115  TF1* fit_hist= (TF1*) hist->GetFunction("TimeSpectrum");
116 
117  if(fit_ref == 0){
118  ERS_INFO("Missing reference fit for "<<hist->GetName());
120  result->tags_["Fit_parameter_NOT_found"] = -999.;
122  return result;
123  };
124  if(fit_hist == 0){
125  ERS_INFO("Missing fit for "<<hist->GetName());
127  result->tags_["Fit_parameter_NOT_found"] = -999.;
129  return result;
130  };
131 
132  if(fit_hist->GetNDF() !=0) chi2_per_NDF = (fit_hist->GetChisquare())/(fit_hist->GetNDF());
133 
134  //Check of chi2
135  if (chi2_per_NDF > chi2 && chi2>0) {
136  ERS_INFO("Histogram does not satisfy chi_square/NDF requirement: " <<hist->GetName());
138  result->tags_["Chi2_over_threshold"] = chi2_per_NDF;
140  return result;
141  }
142 
143  if(fit_hist->GetNDF() == 0){
144  ERS_INFO("NDF not available for histogram " <<hist->GetName());
146  result->tags_["Fit_parameter_NDF"] = 0;
148  return result;
149  };
150 
151  Double_t t0_ref=0;
152  Double_t t0_err_ref=0;
153  Double_t tmax_ref=0;
154  Double_t tmax_err_ref=0;
155 
156  if(fit_ref !=0) t0_ref = ((fit_ref->GetParameter(4))*0.78125);
157  if(fit_ref !=0) t0_err_ref = ((fit_ref->GetParError(4))*0.78125);
158  if(fit_ref !=0) tmax_ref = ((fit_ref->GetParameter(5))*0.78125);
159  if(fit_ref !=0) tmax_err_ref = ((fit_ref->GetParError(5))*0.78125);
160  //Lower limit for t0_err_ref and tmax_err_ref
161  if (t0_err_ref<1.) {
162  t0_err_ref =1.;
163  }
164  if (tmax_err_ref<2.) {
165  tmax_err_ref =2.;
166  }
167 
168  Double_t t0=-99999.;
169  Double_t t0_err=0;
170  Double_t tmax=0;
171  Double_t tmax_err=0;
172 
173  if(fit_hist !=0) t0 = ((fit_hist->GetParameter(4))*0.78125);
174  if(fit_hist !=0) t0_err = ((fit_hist->GetParError(4))*0.78125);
175  if(fit_hist !=0) tmax = ((fit_hist->GetParameter(5))*0.78125);
176  if(fit_hist !=0) tmax_err = ((fit_hist->GetParError(5))*0.78125);
177  //Lower limit for t0_err and tmax_err
178  if (t0_err<1.) {
179  t0_err =1.;
180  }
181  if (tmax_err<2.) {
182  tmax_err =2.;
183  }
184 
185  Double_t Dt0=std::abs(t0-t0_ref);
186  Double_t Dtd=std::abs(tmax-t0-tmax_ref+t0_ref);
187 
188  Double_t sigma_Dt0=sqrt(t0_err*t0_err+t0_err_ref*t0_err_ref);
189  Double_t sigma_Dtmax=sqrt(tmax_err*tmax_err+tmax_err_ref*tmax_err_ref);
190  Double_t sigma_Dtd= sqrt(tmax_err*tmax_err+t0_err*t0_err+tmax_err_ref*tmax_err_ref+t0_err_ref*t0_err_ref);
191 
192  if( sigma_Dt0 ==0 || sigma_Dtmax==0 ){
193  ERS_DEBUG(1,"ERROR: fit parameter errors not found!");
195  result->tags_["Fit_parameter_NOT_found"] = -999.;
197  return result;
198  };
199 
200 
201  //Result
202 
204  result->tags_["01-t0(ns)"] = t0;
205 
206  result->tags_["02-sigma_t0(ns)"] = t0_err;
207  result->tags_["03-t_drift(ns)"] = (tmax-t0);
208  result->tags_["04-sigma_t_drift(ns)"] = sqrt(tmax_err*tmax_err+t0_err*t0_err);
209 
210  int flag_count=0;
211 
212  if( Dtd*0.78125>max_shift ){
213  flag_count+=1000;
214  result->tags_["05-ERROR_(td-td_Ref)"] = Dtd;
215  };
216 
217  if(Dt0>redTh*sigma_Dt0){
218  flag_count+=3;
219  result->tags_["07-ERROR_(t0-t0_Ref)"] = Dt0;
220  result->tags_["08-ERROR_sigma(t0-t0_Ref)"] = sigma_Dt0;
221  }else if(Dt0>greenTh*sigma_Dt0){
222  flag_count+=1;
223  result->tags_["07-ERROR_(t0-t0_Ref)"] = Dt0;
224  result->tags_["08-ERROR_sigma(t0-t0_Ref)"] = sigma_Dt0;
225  };
226 
227 
228  if(Dtd>redTh*sigma_Dtd){
229  flag_count+=3;
230  result->tags_["05-ERROR_(td-td_Ref)"] = Dtd;
231  result->tags_["06-ERROR_sigma(td-td_Ref)"] = sigma_Dtd;
232  } else if(Dtd>greenTh*sigma_Dtd){
233  flag_count+=1;
234  result->tags_["05-ERROR_(td-td_Ref)"] = Dtd;
235  result->tags_["06-ERROR_sigma(td-td_Ref)"] = sigma_Dtd;
236  };
237 
238 
239  if (flag_count>2) {
240  result->status_ = dqm_core::Result::Red;
241  ERS_DEBUG(1,"Red");
242  } else if (flag_count>=1 && flag_count<=2) {
243  result->status_ = dqm_core::Result::Yellow;
244  ERS_DEBUG(1,"Yellow");
245  } else if (flag_count<1) {
246  result->status_ = dqm_core::Result::Green;
247  ERS_DEBUG(1,"Green");
248  }
249  return result;
250 }
251 
252 
253 void
255 {
256  std::string message;
257  message += "\n";
258  message += "Algorithm: \"" + m_name + "\"\n";
259  message += "Description: Check if the histogram t0 tmax and t_drift are compatible with the reference\n";
260  message += "Mandatory Parameters: Green/Red Threshold: Limits: warning: number of standard deviation from mean\n";
261  message += " error\n";
262  message += "Optional Parameters: MinStat = Minimum histogram statistics needed to perform Algorithm\n";
263  message += " chi2 = chi square limit for histogram fit\n";
264  message += " max_shift = maximum difference between t_drif of the histograns and reference\n";
265  message += "\n";
266 
267  out << message;
268 }
269 
270 } // namespace dqm_algorithms
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
plotmaker.hist
hist
Definition: plotmaker.py:148
ALFA_EventTPCnv_Dict::t0
std::vector< ALFA_RawData_p1 > t0
Definition: ALFA_EventTPCnvDict.h:42
python.FakeAthena.Algorithm
def Algorithm(name)
Definition: FakeAthena.py:41
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
dqm_algorithms::MDTTDCSpectrum::MDTTDCSpectrum
MDTTDCSpectrum()
Definition: MDTTDCSpectrum.cxx:38
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
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
dqm_algorithms::MDTTDCSpectrum::clone
virtual dqm_core::Algorithm * clone()
Definition: MDTTDCSpectrum.cxx:51
dqm_algorithms::MDTTDCSpectrum::m_name
std::string m_name
Definition: MDTTDCSpectrum.h:32
dqm_algorithms::MDTTDCSpectrum::~MDTTDCSpectrum
virtual ~MDTTDCSpectrum()
Definition: MDTTDCSpectrum.cxx:45
MDTTDCSpectrum.h
python.handimod.Red
Red
Definition: handimod.py:551
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
dqm_algorithms::MDTTDCSpectrum::execute
virtual dqm_core::Result * execute(const std::string &name, const TObject &object, const dqm_core::AlgorithmConfig &config)
Definition: MDTTDCSpectrum.cxx:58
dqm_algorithms::MDTTDCSpectrum::printDescription
virtual void printDescription(std::ostream &out)
Definition: MDTTDCSpectrum.cxx:254
dqm_algorithms
Definition: AddReference.h:17
ref
const boost::regex ref(r_ef)
TH1
Definition: rootspy.cxx:268
dqm_algorithms::MDTTDCSpectrum
Definition: MDTTDCSpectrum.h:19
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