ATLAS Offline Software
Loading...
Searching...
No Matches
KurtosisTest.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#include <cmath>
17
18#include <dqm_core/AlgorithmManager.h>
19
20namespace
21{
22 dqm_algorithms::KurtosisTest kurtosis_GreaterThan( "GreaterThan" );
23 dqm_algorithms::KurtosisTest kurtosis_LessThan( "LessThan" );
24 dqm_algorithms::KurtosisTest kurtosis_GreaterThanAbs( "GreaterThanAbs" );// Ok, for Kurtosis this is not so much sense (K<0 and K>0 indicate really different things), but just for completeness
25 dqm_algorithms::KurtosisTest kurtosis_LessThanAbs( "LessThanAbs" ); // Kurtosis( normal(0,1) ) =0
26}
27
28//NB. Following ROOT definition This is the excess kurtosis, i.e. fourth standarized momentum -3. K(N(0,1))=0
30 : m_name( name )
31{
32 dqm_core::AlgorithmManager::instance().registerAlgorithm("KurtosisTest_"+name,this);
33}
34
40
41
42dqm_core::Result *
43dqm_algorithms::KurtosisTest::execute( const std::string & name,
44 const TObject & object,
45 const dqm_core::AlgorithmConfig & config )
46{
47 const TH1 * histogram;
48
49 if( object.IsA()->InheritsFrom( "TH1" ) ) {
50 histogram = static_cast<const TH1*>(&object);
51 } else {
52 throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" );
53 }
54
55 const double minstat = dqm_algorithms::tools::GetFirstFromMap( "MinStat", config.getParameters(), -1);
56
57 if (histogram->GetEffectiveEntries() < minstat ) {
58 dqm_core::Result *result = new dqm_core::Result(dqm_core::Result::Undefined);
59 result->tags_["InsufficientEffectiveEntries"] = histogram->GetEffectiveEntries();
60 return result;
61 }
62
63 double gthreshold;
64 double rthreshold;
65
66 int axis = (int) dqm_algorithms::tools::GetFirstFromMap( "Axis", config.getParameters(), 1);
67
68 try {
69 rthreshold = dqm_algorithms::tools::GetFromMap( "K", config.getRedThresholds() );
70 gthreshold = dqm_algorithms::tools::GetFromMap( "K", config.getGreenThresholds() );
71 }
72 catch ( dqm_core::Exception & ex ) {
73 throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
74 }
75 ERS_DEBUG(1,"Axis for kurtosis calculation:"<<axis);
76
77 Double_t kurtosis = histogram->GetKurtosis( axis );
78 Double_t kurtosis_e = histogram->GetKurtosis( axis + 10 );
79
80 dqm_core::Result* result = new dqm_core::Result();
81 ERS_DEBUG(1,"Kurtosis = "<<kurtosis<<" +- "<<kurtosis_e);
82 result->tags_["Kurtosis"] = kurtosis;
83 result->tags_["ApproxStandardError"]=kurtosis_e;
84
85 if ( CompareKurtosisTest( m_name , kurtosis ,gthreshold) ) {
86 result->status_ = dqm_core::Result::Green;
87 } else if ( CompareKurtosisTest( m_name, kurtosis, rthreshold) ) {
88 result->status_ = dqm_core::Result::Yellow;
89 } else {
90 result->status_ = dqm_core::Result::Red;
91 }
92
93 return result;
94
95}
96
97bool
98dqm_algorithms::KurtosisTest::CompareKurtosisTest(const std::string & type, double value, double threshold) {
99
100 if (type == "GreaterThan") return (value > threshold);
101 if (type == "LessThan") return (value < threshold);
102 if (type == "GreaterThanAbs") return ( std::abs(value) > threshold );
103 if (type == "LessThanAbs") return ( std::abs(value) < threshold);
104 return 0;
105}
106
107
108void
110{
111 out<<"KurtosisTest_"+m_name+" : Checks if the Excess Kurtosis of the distribution is "+m_name+" threshold value\n"<<std::endl;
112
113 out<<"Mandatory Green/Red Threshold: K: Value of Kurtosis"<<std::endl;
114
115 out<<"Optional Parameter: MinStat: Minimum histogram statistics needed to perform Algorithm"<<std::endl;
116 out<<"Optional Parameter: Axis: Axis along which compute Kurtosis: 1=X, 2=Y, 3=Z"<<std::endl;
117
118}
119
file declares the dqm_algorithms::KurtosisTest 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 &)
bool CompareKurtosisTest(const std::string &type, double value, double threshold)
KurtosisTest(const std::string &name)
void printDescription(std::ostream &out)
#define IsA
Declare the TObject style functions.