ATLAS Offline Software
Loading...
Searching...
No Matches
KolmogorovTest.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 <TClass.h>
15#include <ers/ers.h>
16
17#include <dqm_core/AlgorithmManager.h>
18
19
24
25
27 : m_name ( name )
28{
29 dqm_core::AlgorithmManager::instance().registerAlgorithm( "KolmogorovTest_"+ name, this );
30}
31
37
38
39dqm_core::Result *
40dqm_algorithms::KolmogorovTest::execute( const std::string & name,
41 const TObject & object,
42 const dqm_core::AlgorithmConfig & config )
43{
44 const TH1 * histogram;
45 const TH1 * refhist;
46 double gthresho;
47 double rthresho;
48
49 if(object.IsA()->InheritsFrom( "TH1" )) {
50 histogram = static_cast<const TH1*>( &object );
51 if (histogram->GetDimension() > 2 ){
52 throw dqm_core::BadConfig( ERS_HERE, name, "dimension > 2 " );
53 }
54 } else {
55 throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" );
56 }
57
58 const double minstat = dqm_algorithms::tools::GetFirstFromMap( "MinStat", config.getParameters(), -1);
59
60 if (histogram->GetEntries() < minstat ) {
61 dqm_core::Result *result = new dqm_core::Result(dqm_core::Result::Undefined);
62 result->tags_["InsufficientEntries"] = histogram->GetEntries();
63 return result;
64 }
65
66 try {
67 refhist = dynamic_cast<const TH1*>( config.getReference() );
68 }
69 catch ( dqm_core::Exception & ex ) {
70 throw dqm_core::BadRefHist(ERS_HERE,name," Could not retreive reference");
71 }
72
73 if (!refhist) {
74 throw dqm_core::BadRefHist(ERS_HERE, name, "Reference is not a histogram");
75 }
76
77 if (histogram->GetDimension() != refhist->GetDimension() ) {
78 throw dqm_core::BadRefHist( ERS_HERE, name, "Dimension" );
79 }
80
81 if ((histogram->GetNbinsX() != refhist->GetNbinsX()) || (histogram->GetNbinsY() != refhist->GetNbinsY())) {
82 throw dqm_core::BadRefHist( ERS_HERE, name, "number of bins" );
83 }
84
85 if (histogram->GetDimension()==2 && (m_name=="MaxDist" || m_name=="MaxDistPlustNorm")){
86 throw dqm_core::BadConfig( ERS_HERE, name, "MaxDist option cannot be used on 2D histograms" );
87 }
88
89
90 std::string option;
91 std::string thresh;
92 if (m_name == "Prob") {
93 option="";
94 thresh="P";
95 }else if (m_name == "MaxDist") {
96 option="M";
97 thresh="MaxDist";
98 }else if (m_name == "Norm") {
99 option="N";
100 thresh="P";
101 }else if (m_name == "MaxDistPlusNorm") {
102 option="NM";
103 thresh="MaxDist";
104 }else {
105 throw dqm_core::BadConfig( ERS_HERE, "None", m_name );
106 }
107
108 try {
109 gthresho = dqm_algorithms::tools::GetFromMap( thresh, config.getGreenThresholds() );
110 rthresho = dqm_algorithms::tools::GetFromMap( thresh, config.getRedThresholds() );
111 }
112 catch ( dqm_core::Exception & ex ) {
113 throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
114 }
115
116
117 double value = histogram->KolmogorovTest( refhist, option.c_str());
118
119 ERS_DEBUG(1, "Kolmogorov Test with Option " << m_name << " is " << value );
120 ERS_DEBUG(1, "Green threshold: "<< gthresho << "; Red threshold: " << rthresho );
121
122 dqm_core::Result* result = new dqm_core::Result();
123 result->tags_[m_name] = value;
124 if (thresh =="P"){
125 if ( value >= gthresho ) {
126 result->status_ = dqm_core::Result::Green;
127 } else if ( value > rthresho ) {
128 result->status_ = dqm_core::Result::Yellow;
129 } else {
130 result->status_ = dqm_core::Result::Red;
131 }
132 }else {
133 if ( value <= gthresho ) {
134 result->status_ = dqm_core::Result::Green;
135 } else if ( value < rthresho ) {
136 result->status_ = dqm_core::Result::Yellow;
137 } else {
138 result->status_ = dqm_core::Result::Red;
139 }
140 }
141
142 return result;
143}
144void
146{
147 std::string thresh;
148 if (m_name == "Prob") {
149 m_option="";
150 thresh="P";
151 }else if (m_name == "MaxDist") {
152 m_option="M";
153 thresh="MaxDist";
154 }else if (m_name == "Norm") {
155 m_option="N";
156 thresh="P";
157 }else if (m_name == "MaxDistPlusNorm") {
158 m_option="NM";
159 thresh="MaxDist";
160 }
161
162 if (m_name == "Norm" || m_name == "Prob") {
163 out<<"KolmogorovTest_"+ m_name+": Give back probability after performing KolmogorovTest on histogram against referece histogram with "+m_option+" option\n"<<std::endl;
164 } else {
165 out<<"KolmogorovTest_"+ m_name+": Give back MaxDist(for 1D histograms only) after performing KolmogorovTest on histogram against referece histogram with "+m_option+" option\n"<<std::endl;
166 }
167 out<<"Mandatory Green/Red Threshold: "+thresh+" : Probability to give Green/Red result\n"<<std::endl;
168
169 out<<"Optional Parameter: MinStat: Minimum histogram statistics needed to perform Algorithm\n"<<std::endl;
170
171}
172
static dqm_algorithms::KolmogorovTest kolmo_MaxDist("MaxDist")
static dqm_algorithms::KolmogorovTest kolmo_Prob("Prob")
static dqm_algorithms::KolmogorovTest kolmo_NormMaxDist("MaxDistPlusNorm")
static dqm_algorithms::KolmogorovTest kolmo_Norm("Norm")
file declares the dqm_algorithms::KolmogorovTest class.
std::string histogram
Definition chains.cxx:52
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 &)
void printDescription(std::ostream &out)
KolmogorovTest(const std::string &name)
#define IsA
Declare the TObject style functions.