ATLAS Offline Software
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 
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 
17 static dqm_algorithms::JarqueBeraTest jb("JB");
18 static dqm_algorithms::JarqueBeraTest jb_prob("Prob");
19 
21 {
22  dqm_core::AlgorithmManager::instance().registerAlgorithm("JarqueBeraTest_"+ name, this );
23 }
24 
25 
28 {
29  return new JarqueBeraTest(m_name);
30 }
31 
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 ) {
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 
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  {
88  return result;
89  }
90  if ( m_name=="Prob" )
91  {
92  if ( testValue >= gthresho ) {
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 
113 void
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 }
Undefined
@ Undefined
Definition: MaterialTypes.h:8
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
dqm_algorithms::JarqueBeraTest::execute
dqm_core::Result * execute(const std::string &, const TObject &, const dqm_core::AlgorithmConfig &)
Definition: JarqueBeraTest.cxx:33
get_generator_info.result
result
Definition: get_generator_info.py:21
IsA
#define IsA
Declare the TObject style functions.
Definition: xAODTEventBranch.h:59
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
covarianceTool.prob
prob
Definition: covarianceTool.py:678
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
JarqueBeraTest.h
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
beamspotman.n
n
Definition: beamspotman.py:731
Result
ICscStripFitter::Result Result
Definition: CalibCscStripFitter.cxx:13
python.handimod.Green
int Green
Definition: handimod.py:524
python.handimod.Red
Red
Definition: handimod.py:551
dqm_algorithms::JarqueBeraTest
Definition: JarqueBeraTest.h:19
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
dqm_algorithms::JarqueBeraTest::clone
JarqueBeraTest * clone()
Definition: JarqueBeraTest.cxx:27
dqm_algorithms::JarqueBeraTest::printDescription
void printDescription(std::ostream &out)
Definition: JarqueBeraTest.cxx:114
dqm_algorithms::JarqueBeraTest::JarqueBeraTest
JarqueBeraTest(const std::string &name)
Definition: JarqueBeraTest.cxx:20
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
histogram
std::string histogram
Definition: chains.cxx:52
fitman.k
k
Definition: fitman.py:528