ATLAS Offline Software
Loading...
Searching...
No Matches
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
21
22namespace 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 // *********************************************************************
55 dqm_core::Result*
57 execute( const std::string& name, const TObject& object, const dqm_core::AlgorithmConfig& config)
58 {
59 //No status flags are set
60 dqm_core::Result* result = new dqm_core::Result();
61 result->status_ = dqm_core::Result::Undefined;
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
static dqm_algorithms::AveragePrint staticInstance
std::string histogram
Definition chains.cxx:52
virtual dqm_core::Result * execute(const std::string &name, const TObject &data, const dqm_core::AlgorithmConfig &config) override final
virtual void printDescription(std::ostream &out)
virtual dqm_core::Algorithm * clone() override final
double GetFirstFromMap(const std::string &paramName, const std::map< std::string, double > &params)
const T & GetFromMap(const std::string &pname, const std::map< std::string, T > &params)
#define IsA
Declare the TObject style functions.