ATLAS Offline Software
STG_YMeansperSector.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 
9 #include <TH2.h>
10 #include <TProfile.h>
11 #include <string>
12 #include "dqm_core/exceptions.h"
13 #include "dqm_core/AlgorithmManager.h"
14 #include "dqm_core/AlgorithmConfig.h"
15 #include "dqm_core/Result.h"
16 #include <ostream>
17 
18 static dqm_algorithms::STG_YMeansperSector staticInstance;
19 
20 namespace dqm_algorithms {
21 
22  // *********************************************************************
23  // Public Methods
24  // *********************************************************************
25 
26  void
28  printDescription(std::ostream& out)
29  {
30  std::string message;
31  message += "\n";
32  message += "Algorithm: \"" + m_name + "\"\n";
33  message += "Description: Checks the Ymeans per sector of every histogram\n";
34  message += "If the Ymeans are outside the range the sector is flagged red. If one of the sectors is very far from the Ymean the whole histogram is flagged red\n";
35  message += " Overflow (and Underflow) bins are not included\n";
36  message += "\n";
37 
38  out << message;
39  }
40 
43  : m_name("STG_YMeansperSector")
44  {
45  dqm_core::AlgorithmManager::instance().registerAlgorithm( m_name, this );
46  }
47 
48 
51  {
52  }
53 
54 
55  dqm_core::Algorithm*
57  clone()
58  {
59  return new STG_YMeansperSector(*this);
60  }
61 
62 
65  execute( const std::string& name, const TObject& object, const dqm_core::AlgorithmConfig& config)
66  {
67  //No status flags are set
70  const TH2 * histogram;
71 
72  if( object.IsA()->InheritsFrom( "TH2" ) ) {
73  histogram = static_cast<const TH2*>(&object);
74  if (histogram->GetDimension() > 2 ){
75  throw dqm_core::BadConfig( ERS_HERE, name, "dimension > 2 " );
76  }
77  } else {
78  throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH2" );
79  }
80  TProfile *h2 = histogram->ProfileX();
81  int Xbins = histogram->GetXaxis()->GetNbins();
82  int Ybins = histogram->GetYaxis()->GetNbins();
83 
84  float Meanlow = 0;
85  float Meanhigh = 0.0;
86  float redMean = 0.0;
87  if (Ybins < 15) {
88  Meanlow = dqm_algorithms::tools::GetFirstFromMap( "MeanL", config.getParameters(), 3.5);
89  Meanhigh = dqm_algorithms::tools::GetFirstFromMap( "MeanH", config.getParameters(), 5.5);
90  redMean = dqm_algorithms::tools::GetFirstFromMap( "MeanRed", config.getParameters(), 9.0);
91 
92 
93  } else if (Ybins > 100) {
94  Meanlow = dqm_algorithms::tools::GetFirstFromMap( "MeanL", config.getParameters(), -7.5);
95  Meanhigh = dqm_algorithms::tools::GetFirstFromMap( "MeanH", config.getParameters(), 17.5);
96  redMean = dqm_algorithms::tools::GetFirstFromMap( "MeanRed", config.getParameters(), 50.0);
97  }
98 
99  float MeanY[36];
100  bool redflag = false;
101  bool yellowflag = false;
102  bool greenflag = false;
103  int Passed=0;
104  for (int i = 1; i <= Xbins; i++) {
105  MeanY[i]=h2->GetBinContent(i);
106  if (MeanY[i]==0) {
107  Passed = Passed +1;
108  continue;
109  }
110  if (MeanY[i] > Meanlow && MeanY[i] < Meanhigh) Passed = Passed +1;
111  if (abs(MeanY[i]) > abs(redMean)) redflag=true;
112  }
113  double gthreshold;
114  double rthreshold;
115  try {
116  rthreshold = dqm_algorithms::tools::GetFromMap( "NSectors", config.getRedThresholds() );
117  gthreshold = dqm_algorithms::tools::GetFromMap( "NSectors", config.getGreenThresholds() );
118  }
119  catch ( dqm_core::Exception & ex ) {
120  throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
121  }
122  if (Passed -2 > gthreshold && not redflag) greenflag=true;
123  else if (Passed -2 > rthreshold && not redflag) yellowflag=true;
124  else redflag=true;
125  if ( greenflag ) {
126  result->status_ = dqm_core::Result::Green;
127  } else if ( yellowflag ) {
128  result->status_ = dqm_core::Result::Yellow;
129  } else {
130  result->status_ = dqm_core::Result::Red;
131  }
132 
133  return result;
134  }
135 
136 }
Undefined
@ Undefined
Definition: MaterialTypes.h:8
get_generator_info.result
result
Definition: get_generator_info.py:21
IsA
#define IsA
Declare the TObject style functions.
Definition: xAODTEventBranch.h:59
dqm_algorithms::STG_YMeansperSector::STG_YMeansperSector
STG_YMeansperSector()
Definition: STG_YMeansperSector.cxx:42
dqm_algorithms::STG_YMeansperSector::m_name
std::string m_name
Definition: STG_YMeansperSector.h:30
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
ReweightUtils.message
message
Definition: ReweightUtils.py:15
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
lumiFormat.i
int i
Definition: lumiFormat.py:85
Result
ICscStripFitter::Result Result
Definition: CalibCscStripFitter.cxx:13
dqm_algorithms::STG_YMeansperSector::execute
virtual dqm_core::Result * execute(const std::string &name, const TObject &data, const dqm_core::AlgorithmConfig &config)
Definition: STG_YMeansperSector.cxx:65
dqm_algorithms::STG_YMeansperSector::clone
virtual dqm_core::Algorithm * clone()
Definition: STG_YMeansperSector.cxx:57
python.handimod.Green
int Green
Definition: handimod.py:524
TH2
Definition: rootspy.cxx:373
STG_YMeansperSector.h
python.handimod.Red
Red
Definition: handimod.py:551
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
TProfile
Definition: rootspy.cxx:515
dqm_algorithms
Definition: AddReference.h:17
dqm_algorithms::STG_YMeansperSector::~STG_YMeansperSector
virtual ~STG_YMeansperSector()
Definition: STG_YMeansperSector.cxx:50
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::STG_YMeansperSector::printDescription
virtual void printDescription(std::ostream &out)
Definition: STG_YMeansperSector.cxx:28
dqm_algorithms::tools::GetFirstFromMap
double GetFirstFromMap(const std::string &paramName, const std::map< std::string, double > &params)
Definition: AlgorithmHelper.cxx:339
dqm_algorithms::STG_YMeansperSector
Definition: STG_YMeansperSector.h:16
histogram
std::string histogram
Definition: chains.cxx:52
TProfile::GetBinContent
double GetBinContent(int) const
Definition: rootspy.cxx:527