ATLAS Offline Software
MDTADCSpectrum.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: MDTADCSpectrum.cxx,v 1.0 2008/10/08 Valerio Consorti
7 // **********************************************************************
8 
9 
11 
12 
13 #include <TClass.h>
14 #include <TH1.h>
15 #include <TF1.h>
16 
17 #include "dqm_core/exceptions.h"
18 #include "dqm_core/AlgorithmConfig.h"
19 #include "dqm_core/AlgorithmManager.h"
20 #include "dqm_core/Result.h"
22 #include "ers/ers.h"
23 #include <cmath>
24 #include <iostream>
25 #include <map>
26 
27 
28 static dqm_algorithms::MDTADCSpectrum staticInstance;
29 
30 
31 namespace dqm_algorithms {
32 
33 // *********************************************************************
34 // Public Methods
35 // *********************************************************************
36 
38  : m_name("MDTADCspectrum")
39 {
40  dqm_core::AlgorithmManager::instance().registerAlgorithm( m_name, this );
41 }
42 
43 
45 {
46 }
47 
48 
51 {
52  return new MDTADCSpectrum(*this);
53 }
54 
55 
57 MDTADCSpectrum::execute( const std::string& name, const TObject& object, const dqm_core::AlgorithmConfig& config)
58 {
59  const TH1 * hist;
60  const TH1 * ref;
61 
62  if( object.IsA()->InheritsFrom( "TH1" ) ) {
63  hist = static_cast<const TH1*>(&object);
64  if (hist->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 thresh;
74  double greenTh;
75  double redTh;
76  try {
77  thresh = dqm_algorithms::tools::GetFirstFromMap( "thresh", config.getParameters(), 50);
78  minstat = dqm_algorithms::tools::GetFirstFromMap("MinStat", config.getParameters(), 0);
79  redTh = dqm_algorithms::tools::GetFromMap( "Limits", config.getRedThresholds());
80  greenTh = dqm_algorithms::tools::GetFromMap( "Limits", config.getGreenThresholds() );
81  }
82  catch ( dqm_core::Exception & ex ) {
83  throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
84  }
85 
86  //Get Reference Histo
87 
88  try {
89  ref = static_cast<const TH1*>( config.getReference() );
90  }
91  catch ( dqm_core::Exception & ex ) {
92  throw dqm_core::BadRefHist(ERS_HERE,name," Could not retreive reference");
93  }
94  if (hist->GetDimension() != ref->GetDimension() ) {
95  throw dqm_core::BadRefHist( ERS_HERE, name, "Reference VS histo: Different dimension!" );
96  }
97 
98  //Check of statistics
99  if (hist->GetEntries() < minstat ) {
100  ERS_INFO("Histogram does not satisfy MinStat requirement " <<hist->GetName());
102  result->tags_["InsufficientEntries"] = hist->GetEntries();
103  return result;
104  }
105  ERS_DEBUG(1,"Statistics: "<< hist->GetEntries()<< " entries ");
106 
107  //Algo
108 
109  Double_t n_min_50=0;
110  Double_t n_min_50_ref=0;
111 
112  Double_t N = hist->GetEntries();
113  Double_t N_ref = ref ->GetEntries();
114 
115  int i=0;
116 
117  do{
118  i++;
119  n_min_50 += hist->GetBinContent(i);
120  if(i>hist->GetNbinsX()){
121  ERS_INFO("bin limit!"<<i);
124  return result;
125  };
126  }while(hist->GetBinCenter(i)<thresh);
127 
128  i=0;
129 
130  do{
131  i++;
132  n_min_50_ref += ref->GetBinContent(i);
133  if(i>ref->GetNbinsX()){
134  ERS_INFO("bin limit!"<<i);
137  return result;
138  };
139  }while(ref->GetBinCenter(i)<thresh);
140 
141  Double_t f = -1;
142  Double_t f_r= 1;
143  Double_t sigma_hist = -1;
144  Double_t sigma_ref = -1;
145  Double_t sigma = -1;
146  Double_t F = -1;
147 
148 
149  if(N == 0 && N_ref == 0) {
150  ERS_INFO("null N entries found");
152  result->tags_["ERROR_null_entries_found"] = -999.;
154  return result;
155  };
156 
157  if(N !=0 && N_ref !=0){
158  f = n_min_50/N;
159  f_r = n_min_50_ref/N_ref;
160 
161  if(f*f_r == 0 || (1-f)<0 || (1-f_r)<0 ){
162  ERS_DEBUG(1,"*) f = "<<f<<" f_r = "<<f_r);
164  result->tags_["ERROR_problem_in_fraction_computation"] = -999.;
165  result->tags_["n_min_50/N"] = f;
166  result->tags_["n_min_50_ref/N_ref"] = f_r;
168  return result;
169  };
170 
171  //Bernulli distribution
172 
173  sigma_hist= std::sqrt(f*(1-f)/N);
174  sigma_ref= std::sqrt(f_r*(1-f_r)/N_ref);
175 
176  F=f/f_r;
177 
178  sigma = F*std::sqrt((sigma_hist/f)*(sigma_hist/f)+(sigma_ref/f_r)*(sigma_ref/f_r));
179 
180 
181  };
182 
183 
184  //Result
185 
187  result->tags_["00-Pedestal_fraction"] = f;
188  result->tags_["1-Pedestal_over_Ped_ref"] = (1-F);
189  result->tags_["sigma_1-Ped_over_Ped_ref"] = sigma;
190 
191  if(f<= greenTh || (f>greenTh && f_r>greenTh)) {
192  result->status_ = dqm_core::Result::Green;
193  }
194  else if( f>redTh && f_r<greenTh ) {
195  result->tags_["Difference_against_Ref-Pedestal_fraction_Ref"] = f_r;
196  result->status_ = dqm_core::Result::Red;
197  }
198  else {
199  result->status_ = dqm_core::Result::Yellow;
200  }
201 
202  // Return the result
203  return result;
204 }
205 
206 
207 void
209  std::string message;
210  message += "\n";
211  message += "Algorithm: \"" + m_name + "\"\n";
212  message += "Description: Checks if the ratio of hits under treshold is below the limits\n";
213  message += " Comparison with reference is performed \n";
214  message += "Mandatory Parameters: Green/Red Threshold: Limits: warning: ratio limits \n";
215  message += " error\n";
216  message += "Optional Parameters: MinStat = Minimum histogram statistics needed to perform Algorithm\n";
217  message += " thresh = ADC cut on pedestal N counts (def 50)\n";
218  message += "\n";
219 
220  out << message;
221 }
222 
223 } // namespace dqm_algorithms
dqm_algorithms::MDTADCSpectrum::m_name
std::string m_name
Definition: MDTADCSpectrum.h:29
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
Undefined
@ Undefined
Definition: MaterialTypes.h:8
pdg_comparison.sigma
sigma
Definition: pdg_comparison.py:324
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::MDTADCSpectrum::~MDTADCSpectrum
virtual ~MDTADCSpectrum()
Definition: MDTADCSpectrum.cxx:44
physval_make_web_display.thresh
thresh
Definition: physval_make_web_display.py:35
plotmaker.hist
hist
Definition: plotmaker.py:148
python.FakeAthena.Algorithm
def Algorithm(name)
Definition: FakeAthena.py:41
dqm_algorithms::MDTADCSpectrum::execute
virtual dqm_core::Result * execute(const std::string &name, const TObject &data, const dqm_core::AlgorithmConfig &config)
Definition: MDTADCSpectrum.cxx:57
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
JetTiledMap::N
@ N
Definition: TiledEtaPhiMap.h:44
ReweightUtils.message
message
Definition: ReweightUtils.py:15
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
dqm_algorithms::MDTADCSpectrum::clone
virtual dqm_core::Algorithm * clone()
Definition: MDTADCSpectrum.cxx:50
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
dqm_algorithms::MDTADCSpectrum
Definition: MDTADCSpectrum.h:17
python.handimod.Green
int Green
Definition: handimod.py:524
MDTADCSpectrum.h
python.handimod.Red
Red
Definition: handimod.py:551
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
dqm_algorithms::MDTADCSpectrum::MDTADCSpectrum
MDTADCSpectrum()
Definition: MDTADCSpectrum.cxx:37
dqm_algorithms::MDTADCSpectrum::printDescription
virtual void printDescription(std::ostream &out)
Definition: MDTADCSpectrum.cxx:208
dqm_algorithms
Definition: AddReference.h:17
ref
const boost::regex ref(r_ef)
TH1
Definition: rootspy.cxx:268
F
#define F(x, y, z)
Definition: MD5.cxx:112
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