ATLAS Offline Software
CheckMean.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // **********************************************************************
6 // $Id: CheckMean.cxx,v 1.1 2007-04-06 11:02:53 mgwilson Exp $
7 // **********************************************************************
8 
10 
11 #include <cmath>
12 #include <iostream>
13 
14 #include <TH1.h>
15 
16 #include "dqm_core/exceptions.h"
17 #include "dqm_core/AlgorithmManager.h"
18 #include "dqm_core/Result.h"
19 
20 
21 static dqm_algorithms::CheckMean staticInstance;
22 
23 
24 namespace dqm_algorithms {
25 
26 // *********************************************************************
27 // Public Methods
28 // *********************************************************************
29 
31 CheckMean()
32  : m_name("AlgCheckMean")
33  , m_limitName("chi2")
34 {
35  dqm_core::AlgorithmManager::instance().registerAlgorithm( m_name, this );
36 }
37 
38 
40 ~CheckMean()
41 {
42 }
43 
44 
45 dqm_core::Algorithm*
47 clone()
48 {
49  return new CheckMean(*this);
50 }
51 
52 
55 execute( const std::string& name, const TObject& data, const dqm_core::AlgorithmConfig& config )
56 {
58 
59  // Cast to the type of TObject to assess
60  const TH1* h = dynamic_cast<const TH1*>( &data );
61  if( h == 0 ) {
62  throw dqm_core::BadConfig( ERS_HERE, name, "Cannot cast data to type TH1" );
63  }
64 
65  const TH1* ref = dynamic_cast<const TH1*>( config.getReference() );
66  if( ref == 0 ) {
67  throw dqm_core::BadConfig( ERS_HERE, name, "Cannot obtain reference of type TH1" );
68  }
69 
70  // Perform the check
71  const double mean_data = h->GetMean();
72  const double mean_ref = ref->GetMean();
73 
74  const double mean_data_err = h->GetMeanError();
75  const double mean_ref_err = ref->GetMeanError();
76 
77  const double chi2_warn = getWarningLimit( config, m_limitName );
78  const double chi2_err = getErrorLimit( config, m_limitName );
79 
80  const double s = ( mean_data - mean_ref );
81  const double s2 = s*s;
82  const double e2 = mean_data_err*mean_data_err + mean_ref_err*mean_ref_err;
83 
84  const double chi2 = s2/e2;
85 
86  //out << "mean_data = " << mean_data << "\n";
87  //out << "mean_ref = " << mean_ref << "\n";
88  //out << "mean_data_err = " << mean_data_err << "\n";
89  //out << "mean_ref_err = " << mean_ref_err << "\n";
90  //out << "chi2 = " << chi2 << "\n";
91 
92  if( chi2 < chi2_warn ) {
94  }
95  else if( chi2 < chi2_err ) {
96  status = dqm_core::Result::Yellow;
97  }
98  else {
100  }
101 
102  // Return the result
103  return new dqm_core::Result( status );
104 }
105 
106 
107 void
109 printDescription(std::ostream& out)
110 {
111  std::string message;
112  message += "\n";
113  message += "Algorithm: \"" + m_name + "\"\n";
114  message += "Description: Checks the mean of a TH1 against the mean of a reference TH1\n";
115  message += " by assessing a chi2 defined by the two means and their errors\n";
116  message += "Parameters: none\n";
117  message += "Limits:\n";
118  message += " \"" + m_limitName + "\" : generate warnings on the chi2 value\n";
119  message += "\n";
120 
121  out << message;
122 }
123 
124 
125 // *********************************************************************
126 // Protected Methods
127 // *********************************************************************
128 
129 
130 double
132 getWarningLimit( const dqm_core::AlgorithmConfig& config, std::string limitName )
133 {
134  std::map<std::string,double> grmap = config.getGreenThresholds();
135  std::map<std::string,double>::const_iterator i = grmap.find( limitName );
136  if( i == grmap.end() ) {
137  throw dqm_core::BadConfig( ERS_HERE, limitName, "Cannot find green threshold" );
138  }
139 
140  return i->second;
141 }
142 
143 
144 double
146 getErrorLimit( const dqm_core::AlgorithmConfig& config, std::string limitName )
147 {
148  std::map<std::string,double> rdmap = config.getRedThresholds();
149  std::map<std::string,double>::const_iterator i = rdmap.find( limitName );
150  if( i == rdmap.end() ) {
151  throw dqm_core::BadConfig( ERS_HERE, limitName, "Cannot find red threshold" );
152  }
153 
154  return i->second;
155 }
156 
157 
158 } // namespace dqm_algorithms
159 
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
Undefined
@ Undefined
Definition: MaterialTypes.h:8
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
dqm_algorithms::CheckMean::getErrorLimit
virtual double getErrorLimit(const dqm_core::AlgorithmConfig &config, std::string limitName)
Definition: CheckMean.cxx:146
dqm_algorithms::CheckMean::m_name
std::string m_name
Definition: CheckMean.h:33
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
dqm_algorithms::CheckMean::printDescription
virtual void printDescription(std::ostream &out)
Definition: CheckMean.cxx:109
ReweightUtils.message
message
Definition: ReweightUtils.py:15
dqm_algorithms::CheckMean
Definition: CheckMean.h:16
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
dqm_algorithms::CheckMean::getWarningLimit
virtual double getWarningLimit(const dqm_core::AlgorithmConfig &config, std::string limitName)
Definition: CheckMean.cxx:132
dqm_algorithms::CheckMean::m_limitName
std::string m_limitName
Definition: CheckMean.h:34
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
dqm_algorithms::CheckMean::CheckMean
CheckMean()
Definition: CheckMean.cxx:31
lumiFormat.i
int i
Definition: lumiFormat.py:85
Result
ICscStripFitter::Result Result
Definition: CalibCscStripFitter.cxx:13
chi2
double chi2(TH1 *h0, TH1 *h1)
Definition: comparitor.cxx:523
python.handimod.Green
int Green
Definition: handimod.py:524
CheckMean.h
dqm_algorithms::CheckMean::execute
virtual dqm_core::Result * execute(const std::string &name, const TObject &data, const dqm_core::AlgorithmConfig &config)
Definition: CheckMean.cxx:55
python.handimod.Red
Red
Definition: handimod.py:551
dqm_algorithms::CheckMean::clone
virtual dqm_core::Algorithm * clone()
Definition: CheckMean.cxx:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
python.handimod.limitName
limitName
Definition: handimod.py:533
dqm_algorithms::CheckMean::~CheckMean
virtual ~CheckMean()
Definition: CheckMean.cxx:40
dqm_algorithms
Definition: AddReference.h:17
h
Athena::Status
Status
Athena specific StatusCode values.
Definition: AthStatusCode.h:22
egammaEnergyPositionAllSamples::e2
double e2(const xAOD::CaloCluster &cluster)
return the uncorrected cluster energy in 2nd sampling
ref
const boost::regex ref(r_ef)
ReadCellNoiseFromCoolCompare.s2
s2
Definition: ReadCellNoiseFromCoolCompare.py:379
merge.status
status
Definition: merge.py:17