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