ATLAS Offline Software
Loading...
Searching...
No Matches
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
8
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>
26
27
29 {
30 dqm_core::AlgorithmManager::instance().registerAlgorithm("Chi2Test_Scatterplot", this );
31}
32
33
39
40
41dqm_core::Result *
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 ) {
58 dqm_core::Result *result = new dqm_core::Result(dqm_core::Result::Undefined);
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
140 dqm_core::Result* result = new dqm_core::Result();
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}
159void
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
static dqm_algorithms::BinContentComp myInstance
file declares the dqm_algorithms::Chi2Test_Scatterplot class.
std::vector< int > GetBinRange(const TH1 *histogram, const std::map< std::string, double > &params)
double GetFirstFromMap(const std::string &paramName, const std::map< std::string, double > &params)
const T & GetFromMap(const std::string &pname, const std::map< std::string, T > &params)
dqm_core::Result * execute(const std::string &, const TObject &, const dqm_core::AlgorithmConfig &)
#define IsA
Declare the TObject style functions.