ATLAS Offline Software
Chi2Test_Scatterplot.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
9 #include <dqm_core/AlgorithmConfig.h>
12 #include <TH1.h>
13 #include <TF1.h>
14 #include <TH1F.h>
15 #include <TH2F.h>
16 #include <TObjArray.h>
17 #include <string>
18 
19 #include <TClass.h>
20 #include <TGraph.h>
21 #include <TGraphErrors.h>
22 #include <ers/ers.h>
23 
24 #include <dqm_core/AlgorithmManager.h>
25 static dqm_algorithms::Chi2Test_Scatterplot myInstance;
26 
27 
29  {
30  dqm_core::AlgorithmManager::instance().registerAlgorithm("Chi2Test_Scatterplot", this );
31 }
32 
33 
36 {
37  return new Chi2Test_Scatterplot();
38 }
39 
40 
43  const TObject & object,
44  const dqm_core::AlgorithmConfig & config )
45 {
46  const TH1 * inputgraph;
47 
48  if(object.IsA()->InheritsFrom( "TH1" )) {
49  inputgraph = static_cast<const TH1*>( &object );
50 
51  } else {
52  throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" );
53  }
54 
55  double minstat = dqm_algorithms::tools::GetFirstFromMap( "MinStat", config.getParameters(), 1 );
56 
57  if (inputgraph->GetEntries() < minstat ) {
59  result->tags_["InsufficientEntries"] = inputgraph->GetEntries();
60  return result;
61  }
62 
63 
64 
65 
66  TH1 * refhist;
67  double gthresho;
68  double rthresho;
69  std::string option;
70 
71  std::string thresholdname="Chi2_per_NDF";
72 
73  try {
74  gthresho = dqm_algorithms::tools::GetFromMap( thresholdname, config.getGreenThresholds() );
75  rthresho = dqm_algorithms::tools::GetFromMap( thresholdname, config.getRedThresholds() );
76  }
77  catch ( dqm_core::Exception & ex ) {
78  throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
79 
80  }
81 
82  try {
83  refhist = static_cast<TH1 *>( config.getReference() );
84  }
85  catch ( dqm_core::Exception & ex ) {
86  throw dqm_core::BadRefHist(ERS_HERE,name," Could not retreive reference");
87  }
88 
89  if (inputgraph->GetDimension() != refhist->GetDimension() ) {
90  throw dqm_core::BadRefHist( ERS_HERE, "Dimension", name );
91  }
92 
93 
94 
95  if ((inputgraph->GetNbinsX() != refhist->GetNbinsX()) || (inputgraph->GetNbinsY() != refhist->GetNbinsY())) {
96  throw dqm_core::BadRefHist( ERS_HERE, "number of bins", name );
97  }
98 
99  int n=0;
100  double chisq=0;
101  double errsquared{};
102  double inputerr{};
103  double referr{};
104  double val{};
105  double refval{};
106 
107 
108  //read in the range of bin values to use
109  std::vector<int> range;
110  try{
111  range=dqm_algorithms::tools::GetBinRange(inputgraph,config.getParameters());
112  }
113  catch( dqm_core::Exception & ex ) {
114  throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
115  }
116 
117 //now compute the chisq/ndf
118 
119  int count_ndf=0;
120 
121  for(n=range[0];n<(range[1]+1);n++)
122  { inputerr=inputgraph->GetBinError(n);
123  referr=refhist->GetBinError(n);
124  errsquared= referr*referr+inputerr*inputerr;
125  val=inputgraph->GetBinContent(n);
126  refval=refhist->GetBinContent(n);
127  if (referr >0.00001 && inputerr >0.00001)
128  {chisq=chisq+((val-refval)*(val-refval))/errsquared;
129  count_ndf++;
130  }
131  else
132  {//out<<"One of the errors is too small???? "<<n<<std::endl;
133  }
134 
135  }
136 
137 
138  const double value = (count_ndf > 1) ? (chisq / (count_ndf - 1)) : 0; // avoid to divide by zero (should never happen)
139 
141  result->tags_[thresholdname] = value;
142 
143 
144 //check the thresholds
145 
146  if ( value <= gthresho ) {
147  result->status_ = dqm_core::Result::Green;
148  } else if ( value < rthresho ) {
149  result->status_ = dqm_core::Result::Yellow;
150  } else {
151  result->status_ = dqm_core::Result::Red;
152  }
153 
154  ERS_DEBUG(2,"Result: "<<*result);
155 
156  return result;
157 
158 }
159 void
161 {
162 
163  out<<"Chi2Test_Scatterplot performs chisq/ndf test on a scatterplot and returns a dqm_result"<<std::endl;
164 
165 
166  out<<"Mandatory Green/Red Threshold: Chi2_per_NDF to give Green/Red result\n"<<std::endl;
167 
168  out<<"Optional Parameter: MinStat: Minimum histogram statistics needed to perform Algorithm\n"<<std::endl;
169 
170 }
171 
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
Chi2Test_Scatterplot.h
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
athena.value
value
Definition: athena.py:124
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
beamspotman.n
n
Definition: beamspotman.py:731
Result
ICscStripFitter::Result Result
Definition: CalibCscStripFitter.cxx:13
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
dqm_algorithms::Chi2Test_Scatterplot::printDescription
void printDescription(std::ostream &out)
Definition: Chi2Test_Scatterplot.cxx:160
python.handimod.Green
int Green
Definition: handimod.py:524
dqm_algorithms::Chi2Test_Scatterplot
Definition: Chi2Test_Scatterplot.h:19
python.handimod.Red
Red
Definition: handimod.py:551
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
dqm_algorithms::Chi2Test_Scatterplot::Chi2Test_Scatterplot
Chi2Test_Scatterplot()
Definition: Chi2Test_Scatterplot.cxx:28
dqm_algorithms::Chi2Test_Scatterplot::execute
dqm_core::Result * execute(const std::string &, const TObject &, const dqm_core::AlgorithmConfig &)
Definition: Chi2Test_Scatterplot.cxx:42
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
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
dqm_algorithms::Chi2Test_Scatterplot::clone
Chi2Test_Scatterplot * clone()
Definition: Chi2Test_Scatterplot.cxx:35