ATLAS Offline Software
Loading...
Searching...
No Matches
JarqueBeraTest.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
8
9#include <dqm_core/AlgorithmManager.h>
10#include <dqm_core/AlgorithmConfig.h>
13#include <TH1.h>
14#include <TClass.h>
15#include <TMath.h>
16
19
20dqm_algorithms::JarqueBeraTest::JarqueBeraTest( const std::string & name ) : m_name(name)
21{
22 dqm_core::AlgorithmManager::instance().registerAlgorithm("JarqueBeraTest_"+ name, this );
23}
24
25
31
32dqm_core::Result *
33dqm_algorithms::JarqueBeraTest::execute( const std::string & name ,
34 const TObject & object,
35 const dqm_core::AlgorithmConfig & config )
36{
37 const TH1 * histogram;
38 if(object.IsA()->InheritsFrom( "TH1" )) {
39 histogram = static_cast<const TH1*>( &object );
40 if (histogram->GetDimension() > 2 ){
41 throw dqm_core::BadConfig( ERS_HERE, name, "dimension > 2 " );
42 }
43 } else {
44 throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" );
45 }
46
47 const double minstat = dqm_algorithms::tools::GetFirstFromMap( "MinStat", config.getParameters(), -1);
48 ERS_DEBUG(2,"Minimum statistics required:"<<minstat);
49 if (histogram->GetEffectiveEntries() < minstat ) {
50 dqm_core::Result *result = new dqm_core::Result(dqm_core::Result::Undefined);
51 result->tags_["InsufficientEffectiveEntries"] = histogram->GetEffectiveEntries();
52 return result;
53 }
54 double gthresho,rthresho;
55 std::string thresholdname="JB";
56 if ( m_name == "Prob") thresholdname = "P";
57 try {
58 gthresho = dqm_algorithms::tools::GetFromMap( thresholdname, config.getGreenThresholds() );
59 rthresho = dqm_algorithms::tools::GetFromMap( thresholdname, config.getRedThresholds() );
60 }
61 catch ( dqm_core::Exception & ex ) {
62 throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
63 }
64 ERS_DEBUG(2,"Green Threshold: "<<gthresho<<" Red: "<<rthresho);
65
66 // N.B. Root's return the excess kurtosis, i.e. gamma_2-3
67 // The excess kurtosis is defined scuh as K(N(0,1))=0
68 double k = histogram->GetKurtosis();
69 double s = histogram->GetSkewness();
70 double n = histogram->GetEffectiveEntries();
71 double jb = n/6*( s*s + (k*k)/4 ); //Calculate Jarque Bera
72 //The statistic JB has an asymptotic chi-square distribution with two degrees of freedom
73 // and can be used to test the null hypothesis that the data are from a normal distribution.
74 double prob = TMath::Prob( jb , 2 );
75 ERS_DEBUG(2," K="<<k<<" S="<<s<<" n="<<n<<" jb="<<jb<<" prob="<<prob);
76
77 //Check against thresholds
78 double testValue;
79 if ( m_name == "Prob" ) testValue = prob; //Use probability
80 else testValue = jb; // Use the JB value for comparison
81
82 dqm_core::Result* result = new dqm_core::Result();
83 result->tags_["JB"] = jb;
84 result->tags_["Prob"]=prob;
85 if ( TMath::IsNaN( testValue ) ) //This may happen if RMS==0 Kurtosis and Skewness are inf
86 {
87 result->status_=dqm_core::Result::Undefined;
88 return result;
89 }
90 if ( m_name=="Prob" )
91 {
92 if ( testValue >= gthresho ) {
93 result->status_ = dqm_core::Result::Green;
94 } else if ( testValue > rthresho ) {
95 result->status_ = dqm_core::Result::Yellow;
96 } else {
97 result->status_ = dqm_core::Result::Red;
98 }
99 }
100 else
101 {
102 if ( testValue <= gthresho ) {
103 result->status_ = dqm_core::Result::Green;
104 } else if ( testValue < rthresho ) {
105 result->status_ = dqm_core::Result::Yellow;
106 } else {
107 result->status_ = dqm_core::Result::Red;
108 }
109 }
110 return result;
111}
112
113void
115{
116 out<<"JarqueBeraTest"+m_name+" gives back the ";
117 if ( m_name == "Prob") out<<" probability that the input histogram follows the normal distribution\n"<<std::endl;
118 else out<<" Jarque-Bera value of the input histogram\n"<<std::endl;
119 out<<"Mandatory Green/Red Threshold: ";
120 if ( m_name == "Prob") out<<" P : Probability";
121 else out<<" JB : Jarque-Bera value";
122 out<<" to give Green/Red result.\n"<<std::endl;
123 out<<"Optional Parameter: MinStat: Minimum histogram statistics needed to perform Algorithm\n"<<std::endl;
124}
static dqm_algorithms::JarqueBeraTest jb("JB")
static dqm_algorithms::JarqueBeraTest jb_prob("Prob")
file declares the dqm_algorithms::JarqueBeraTest class, implementing the Jarque-Bera statistical test...
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)
JarqueBeraTest(const std::string &name)
dqm_core::Result * execute(const std::string &, const TObject &, const dqm_core::AlgorithmConfig &)
void printDescription(std::ostream &out)
#define IsA
Declare the TObject style functions.