ATLAS Offline Software
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 
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 
20 static dqm_algorithms::KolmogorovTest kolmo_Prob( "Prob" );
21 static dqm_algorithms::KolmogorovTest kolmo_MaxDist( "MaxDist" );
22 static dqm_algorithms::KolmogorovTest kolmo_Norm( "Norm" );
23 static dqm_algorithms::KolmogorovTest kolmo_NormMaxDist( "MaxDistPlusNorm" );
24 
25 
27  : m_name ( name )
28 {
29  dqm_core::AlgorithmManager::instance().registerAlgorithm( "KolmogorovTest_"+ name, this );
30 }
31 
34 {
35  return new KolmogorovTest( m_name );
36 }
37 
38 
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 ) {
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 
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 }
144 void
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 
dqm_algorithms::KolmogorovTest::execute
dqm_core::Result * execute(const std::string &, const TObject &, const dqm_core::AlgorithmConfig &)
Definition: KolmogorovTest.cxx:40
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
physval_make_web_display.thresh
thresh
Definition: physval_make_web_display.py:35
dqm_algorithms::KolmogorovTest
Definition: KolmogorovTest.h:19
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
athena.value
value
Definition: athena.py:122
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
python.handimod.Green
int Green
Definition: handimod.py:524
dqm_algorithms::KolmogorovTest::clone
KolmogorovTest * clone()
Definition: KolmogorovTest.cxx:33
python.handimod.Red
Red
Definition: handimod.py:551
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
dqm_algorithms::KolmogorovTest::KolmogorovTest
KolmogorovTest(const std::string &name)
Definition: KolmogorovTest.cxx:26
TH1
Definition: rootspy.cxx:268
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::KolmogorovTest::printDescription
void printDescription(std::ostream &out)
Definition: KolmogorovTest.cxx:145
histogram
std::string histogram
Definition: chains.cxx:52
KolmogorovTest.h