ATLAS Offline Software
DataQuality/dqm_algorithms/src/CorrelationYX.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 
8 
9 #include <TClass.h>
10 #include <TH1.h>
11 #include <TAxis.h>
12 
13 #include "dqm_core/exceptions.h"
14 #include "dqm_core/AlgorithmConfig.h"
16 #include "dqm_core/AlgorithmManager.h"
17 #include "dqm_core/Result.h"
18 #include "ers/ers.h"
19 #include <cmath>
20 #include <iostream>
21 #include <map>
22 
23 static dqm_algorithms::CorrelationYX staticInstance;
24 
25 
26 namespace dqm_algorithms {
27 
28  // *********************************************************************
29  // Public Methods
30  // *********************************************************************
31 
34  : m_name("AlgCorrelationYX")
35  {
36  dqm_core::AlgorithmManager::instance().registerAlgorithm( m_name, this );
37  }
38 
39 
42  {
43  }
44 
45 
48  clone()
49  {
50  return new CorrelationYX(*this);
51  }
52 
53 
56  execute( const std::string& name, const TObject& object, const dqm_core::AlgorithmConfig& config)
57  {
58  const TH1 * histogram;
59 
60  if( object.IsA()->InheritsFrom( "TH1" ) ) {
61  histogram = static_cast<const TH1*>(&object);
62  if (histogram->GetDimension() > 2 ){
63  throw dqm_core::BadConfig( ERS_HERE, name, "dimension > 2 " );
64  }
65  } else {
66  throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" );
67  }
68 
69  int binStart, binEnd;
70  double gmin;
71  double rmin;
72  try {
73  binStart = (int) dqm_algorithms::tools::GetFirstFromMap("BinStart", config.getParameters() );
74  binEnd = (int) dqm_algorithms::tools::GetFirstFromMap("BinEnd" , config.getParameters() );
75  rmin = dqm_algorithms::tools::GetFromMap( "CorrMin", config.getRedThresholds());
76  gmin = dqm_algorithms::tools::GetFromMap( "CorrMin", config.getGreenThresholds() );
77  }
78  catch ( dqm_core::Exception & ex ) {
79  throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
80  }
81 
82 
83  double count = 0;
84  double avX = 0;
85  double avY = 0;
86  double avX2 = 0;
87  double avY2 = 0;
88  double avXY = 0;
89  double sdX = 0;
90  double sdY = 0;
91  double correlation=0;
92 
93  int nbiny = histogram -> GetNbinsY();
94  if(binStart>binEnd) {
95  binStart= 1;
96  binEnd = histogram -> GetNbinsX();
97  }
98  int binSize = binEnd-binStart+1;
99 
100  std::vector<double> contents;
101  contents.resize(binSize);
102  for(int i=0;i<binSize;i++) {
103  int binx = binStart+i;
104  contents[i]=0;
105  for ( int j = 1; j <= nbiny; ++j ) {
106  double content= histogram -> GetBinContent(binx,j);
107  contents[i]+=content;
108  for(int k=0; k!=content;k++) {
109  count ++ ;
110  avX += binx ;
111  avY += j ;
112  avX2 += binx*binx ;
113  avY2 += j*j ;
114  avXY += binx*j ;
115  }
116  }
117  }
118 
119  if(count>0) {
120  avX = avX / count;
121  avY = avY / count;
122  avX2 = avX2 / count;
123  avY2 = avY2 / count;
124  avXY = avXY / count;
125  }
126 
127  sdX = std::sqrt(avX2-avX*avX) ;
128  sdY = std::sqrt(avY2-avY*avY) ;
129  if(sdX>0&&sdY>0)correlation=(avXY-avX*avY)/(sdX*sdY);
130 
131 
132  ERS_DEBUG(1,"Number of entries for bins is "<< count );
133  ERS_DEBUG(1,"Correlation biny and binx is "<< correlation );
134  ERS_DEBUG(1,"Green: "<< gmin << " entries; Red: " << rmin << " entries ");
135 
137 
138 
139 
140  if ( correlation >= gmin ) {
141  result->status_ = dqm_core::Result::Green;
142  } else if ( correlation > rmin ) {
143  result->status_ = dqm_core::Result::Yellow;
144  } else {
145  result->status_ = dqm_core::Result::Red;
146  }
147  result->tags_["Correlation"] = correlation;
148 
149 
150  return result;
151  }
152 
153 
154  void
156  printDescription(std::ostream& out)
157  {
158  std::string message;
159  message += "\n";
160  message += "Algorithm: \"" + m_name + "\"\n";
161  message += "Description: Counts the number of listed bins with entries above CountsTh\n";
162  message += "Parameters: BinStart first bin to be checked (1=first bin)\n";
163  message += " BinEnd last bin to be checked (nbin=last bin)\n";
164  message += " CorrMin minimum correlation Red/Green\n";
165  message += "\n";
166 
167  out << message;
168  }
169 
170 } // namespace dqm_algorithms
get_generator_info.result
result
Definition: get_generator_info.py:21
IsA
#define IsA
Declare the TObject style functions.
Definition: xAODTEventBranch.h:59
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
dqm_algorithms::CorrelationYX::CorrelationYX
CorrelationYX()
Definition: DataQuality/dqm_algorithms/src/CorrelationYX.cxx:33
python.FakeAthena.Algorithm
def Algorithm(name)
Definition: FakeAthena.py:41
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
dqm_algorithms::CorrelationYX::clone
virtual dqm_core::Algorithm * clone()
Definition: DataQuality/dqm_algorithms/src/CorrelationYX.cxx:48
ReweightUtils.message
message
Definition: ReweightUtils.py:15
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
grepfile.content
string content
Definition: grepfile.py:56
dqm_algorithms::CorrelationYX::~CorrelationYX
virtual ~CorrelationYX()
Definition: DataQuality/dqm_algorithms/src/CorrelationYX.cxx:41
lumiFormat.i
int i
Definition: lumiFormat.py:92
Result
ICscStripFitter::Result Result
Definition: CalibCscStripFitter.cxx:13
dqm_algorithms::CorrelationYX
Definition: DataQuality/dqm_algorithms/dqm_algorithms/CorrelationYX.h:16
python.handimod.Green
int Green
Definition: handimod.py:524
contents
void contents(std::vector< std::string > &keys, TDirectory *td, const std::string &directory, const std::string &pattern, const std::string &path)
Definition: computils.cxx:319
python.handimod.Red
Red
Definition: handimod.py:551
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
dqm_algorithms::CorrelationYX::printDescription
virtual void printDescription(std::ostream &out)
Definition: DataQuality/dqm_algorithms/src/CorrelationYX.cxx:156
dqm_algorithms
Definition: AddReference.h:17
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::CorrelationYX::execute
virtual dqm_core::Result * execute(const std::string &name, const TObject &object, const dqm_core::AlgorithmConfig &config)
Definition: DataQuality/dqm_algorithms/src/CorrelationYX.cxx:56
dqm_algorithms::CorrelationYX::m_name
std::string m_name
Definition: DataQuality/dqm_algorithms/dqm_algorithms/CorrelationYX.h:29
CorrelationYX.h
histogram
std::string histogram
Definition: chains.cxx:52
fitman.k
k
Definition: fitman.py:528