ATLAS Offline Software
STG_XMeansperSector.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN
3  for the benefit of the ATLAS collaboration
4 */
5 
7 
9 #include <TH2.h>
10 #include <TProfile.h>
11 #include <string>
12 #include <cmath>
13 #include <iostream>
14 
15 #include "dqm_core/exceptions.h"
16 #include "dqm_core/AlgorithmManager.h"
17 #include "dqm_core/AlgorithmConfig.h"
18 #include "dqm_core/Result.h"
19 
20 static dqm_algorithms::STG_XMeansperSector staticInstance;
21 
22 namespace dqm_algorithms {
23 
24  // *********************************************************************
25  // Constructor
26  // *********************************************************************
28  dqm_core::AlgorithmManager::instance().registerAlgorithm(m_name, this);
29  }
30 
31  // *********************************************************************
32  // Clone
33  // *********************************************************************
34  dqm_core::Algorithm*
36  return new STG_XMeansperSector(*this);
37  }
38 
39  // *********************************************************************
40  // Print Description
41  // *********************************************************************
42  void
44  out << "\n";
45  out << "Algorithm: \"" << m_name << "\"\n";
46  out << "Description: Evaluates <X> means per Y-bin in STGC timing histograms.\n";
47  out << "Flags sectors as RED if <X> deviates beyond redMean.\n";
48  out << "Overflow and underflow bins are excluded.\n";
49  out << "\n";
50  }
51 
52  // *********************************************************************
53  // Execute
54  // *********************************************************************
57  execute( const std::string& name, const TObject& object, const dqm_core::AlgorithmConfig& config)
58  {
59  //No status flags are set
62  const TH2 * histogram;
63 
64  if( object.IsA()->InheritsFrom( "TH2" ) ) {
65  histogram = static_cast<const TH2*>(&object);
66  if (histogram->GetDimension() > 2 ){
67  throw dqm_core::BadConfig( ERS_HERE, name, "dimension > 2 " );
68  }
69  } else {
70  throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH2" );
71  }
72 
73  TProfile *h2 = histogram->ProfileY();
74  int Xbins = histogram->GetXaxis()->GetNbins();
75  int Ybins = histogram->GetYaxis()->GetNbins();
76 
77  double mean_global = histogram->GetMean(1);
78 
79  float Meanlow;
80  float Meanhigh;
81  float redMean;
82  if (Xbins > 100) {
83  Meanlow = dqm_algorithms::tools::GetFirstFromMap( "MeanL", config.getParameters(), mean_global-12.5);
84  Meanhigh = dqm_algorithms::tools::GetFirstFromMap( "MeanH", config.getParameters(), mean_global+12.5);
85  redMean = dqm_algorithms::tools::GetFirstFromMap( "MeanRed", config.getParameters(), mean_global+30.0);
86  } else if (Xbins < 15) {
87  Meanlow = dqm_algorithms::tools::GetFirstFromMap( "MeanL", config.getParameters(), mean_global-50.0);
88  Meanhigh = dqm_algorithms::tools::GetFirstFromMap( "MeanH", config.getParameters(), mean_global+50.0);
89  redMean = dqm_algorithms::tools::GetFirstFromMap( "MeanRed", config.getParameters(), mean_global+75.0);
90  } else {
91  Meanlow = dqm_algorithms::tools::GetFirstFromMap( "MeanL", config.getParameters(), mean_global-25.0);
92  Meanhigh = dqm_algorithms::tools::GetFirstFromMap( "MeanH", config.getParameters(), mean_global+25.0);
93  redMean = dqm_algorithms::tools::GetFirstFromMap( "MeanRed", config.getParameters(), mean_global+50.0);
94  }
95 
96  std::vector<float> MeanX(Ybins, 0.0);
97  //float MeanX[Ybins];
98  bool redflag = false;
99  bool yellowflag = false;
100  bool greenflag = false;
101  int Passed=0;
102  for (int i = 1; i <= Ybins; i++) {
103  MeanX[i]=h2->GetBinContent(i);
104  if (MeanX[i]==0) {
105  Passed = Passed +1;
106  continue;
107  }
108  if (MeanX[i] > Meanlow && MeanX[i] < Meanhigh) Passed = Passed +1;
109  if (abs(MeanX[i]-mean_global) > abs(redMean-mean_global)) redflag=true;
110  }
111  double gthreshold;
112  double rthreshold;
113  try {
114  rthreshold = dqm_algorithms::tools::GetFromMap("OOBSectors", config.getRedThresholds());
115  gthreshold = dqm_algorithms::tools::GetFromMap("OOBSectors", config.getGreenThresholds());
116  }
117  catch ( dqm_core::Exception & ex ) {
118  throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
119  }
120  if (Passed >= (Ybins-gthreshold) && not redflag) greenflag=true;
121  else if (Passed >= (Ybins-rthreshold) && not redflag) yellowflag=true;
122  else redflag=true;
123  if ( greenflag ) {
124  result->status_ = dqm_core::Result::Green;
125  } else if ( yellowflag ) {
126  result->status_ = dqm_core::Result::Yellow;
127  } else {
128  result->status_ = dqm_core::Result::Red;
129  }
130  result->tags_["Xbins"] = Xbins;
131  result->tags_["Passed"] = Passed;
132  result->tags_["MeanGlobal"] = mean_global;
133  return result;
134  }
135 
136 } // namespace dqm_algorithms
137 
Undefined
@ Undefined
Definition: MaterialTypes.h:8
get_generator_info.result
result
Definition: get_generator_info.py:21
dqm_algorithms::STG_XMeansperSector::clone
virtual dqm_core::Algorithm * clone() override final
Definition: STG_XMeansperSector.cxx:35
IsA
#define IsA
Declare the TObject style functions.
Definition: xAODTEventBranch.h:59
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:70
dqm_algorithms::STG_XMeansperSector::execute
virtual dqm_core::Result * execute(const std::string &name, const TObject &data, const dqm_core::AlgorithmConfig &config) override final
Definition: STG_XMeansperSector.cxx:57
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
dqm_algorithms::STG_XMeansperSector::printDescription
virtual void printDescription(std::ostream &out)
Definition: STG_XMeansperSector.cxx:43
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
dqm_algorithms::STG_XMeansperSector::STG_XMeansperSector
STG_XMeansperSector()
Definition: STG_XMeansperSector.cxx:27
lumiFormat.i
int i
Definition: lumiFormat.py:85
python.TrigEgammaMonitorHelper.TProfile
def TProfile(*args, **kwargs)
Definition: TrigEgammaMonitorHelper.py:81
Result
ICscStripFitter::Result Result
Definition: CalibCscStripFitter.cxx:13
python.handimod.Green
int Green
Definition: handimod.py:523
STG_XMeansperSector.h
python.handimod.Red
Red
Definition: handimod.py:550
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
dqm_algorithms::STG_XMeansperSector::m_name
std::string m_name
Definition: STG_XMeansperSector.h:28
dqm_algorithms
Definition: AddReference.h:17
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:29
dqm_algorithms::tools::GetFirstFromMap
double GetFirstFromMap(const std::string &paramName, const std::map< std::string, double > &params)
Definition: AlgorithmHelper.cxx:339
dqm_algorithms::STG_XMeansperSector
Definition: STG_XMeansperSector.h:14
histogram
std::string histogram
Definition: chains.cxx:52