ATLAS Offline Software
Loading...
Searching...
No Matches
ZDCTestConstantVsLB.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#include <TGraphErrors.h>
18#include <TFitResult.h>
19
21
22namespace dqm_algorithms {
23
24 // *********************************************************************
25 // Public Methods
26 // *********************************************************************
27
28 void
30 printDescription(std::ostream& out)
31 {
32 std::string message;
33 message += "\n";
34 message += "Algorithm: \"" + m_name + "\"\n";
35 message += "Description: Calculates the mean of the LB dependence\n";
36 message += "A constant fit is performed, for bins with minimum statistics, and outliers are reported. Yellow is for any 5 sigma deviations, red is for 10 or more\n";
37 message += " Overflow (and Underflow) bins are not included\n";
38 message += "\n";
39
40 out << message;
41 }
42
45 : m_name("ZDCTestConstantVsLB")
46 {
47 dqm_core::AlgorithmManager::instance().registerAlgorithm( m_name, this );
48 }
49
50
55
56
57 dqm_core::Algorithm*
59 clone()
60 {
61 return new ZDCTestConstantVsLB(*this);
62 }
63
64
65 dqm_core::Result*
67 execute( const std::string& name, const TObject& object, const dqm_core::AlgorithmConfig& config)
68 {
69 //No status flags are set
70 dqm_core::Result* result = new dqm_core::Result();
71 result->status_ = dqm_core::Result::Undefined;
72 const TH2 * histogram;
73
74 if( object.IsA()->InheritsFrom( "TH2" ) ) {
75 histogram = static_cast<const TH2*>(&object);
76 if (histogram->GetDimension() > 2 ){
77 throw dqm_core::BadConfig( ERS_HERE, name, "dimension > 2 " );
78 }
79 } else {
80 throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH2" );
81 }
82
83 TProfile *profile = histogram->ProfileX();
84 TH1 *projection = histogram->ProjectionX("projection");
85 int Xbins = histogram->GetXaxis()->GetNbins();
86
87 float minstat = dqm_algorithms::tools::GetFirstFromMap( "MinStat", config.getParameters(), 100);
88 float NsigYellow = dqm_algorithms::tools::GetFirstFromMap( "NsigYellow", config.getParameters(), 5);
89 float NsigMultRed = dqm_algorithms::tools::GetFirstFromMap( "NsigMultRed", config.getParameters(), 10);
90
91 bool redflag = false;
92 bool yellowflag = false;
93 bool greenflag = true; // if nothing goes wrong, return green
94
95 TGraphErrors* ge = new TGraphErrors;
96 int nge =0;
97 for (int ilb = 0; ilb<Xbins ;ilb++)
98 {
99 if (projection->GetBinContent(ilb+1) >= minstat)
100 {
101 ge->SetPoint(nge,ilb,profile->GetBinContent(ilb+1));
102 ge->SetPointError(nge,ilb,profile->GetBinError(ilb+1));
103 nge++;
104 }
105 }
106
107 TFitResultPtr fit_res = ge->Fit("pol0","QNS0");
108 if (!fit_res.Get())
109 {
110 result->status_ = dqm_core::Result::Yellow;
111 return result;
112 }
113
114 double mean = fit_res->Value(0);
115
116 std::vector<int> yellowLBs;
117 std::vector<double> yellowR;
118 for (int ip = 0; ip<ge->GetN() ;ip++)
119 {
120 double x,y;
121 ge->GetPoint(ip,x,y);
122 double ey = ge->GetErrorY(ip);
123 double r = TMath::Abs(( y - mean ) / ey); // number of sigma from const mean, use only pointwise error
124 if (r>NsigYellow)
125 {
126 yellowflag = true;
127 yellowLBs.push_back(x); // store LB
128 yellowR.push_back(r); // store R
129 }
130 }
131
132 for (size_t iy=0;iy<yellowLBs.size();iy++)
133 {
134 int LB = yellowLBs.at(iy);
135 double R = yellowR.at(iy);
136 char ctag[256];
137 sprintf(ctag,"Bad LB %d with R", LB);
138 result->tags_[ctag] = R;
139 }
140
141 if (yellowLBs.size() > NsigMultRed)
142 {
143 redflag = true;
144 }
145
146 if (redflag)
147 {
148 result->status_ = dqm_core::Result::Red;
149 }
150 else if (yellowflag)
151 {
152 result->status_ = dqm_core::Result::Yellow;
153 }
154 else if (greenflag)
155 {
156 result->status_ = dqm_core::Result::Green;
157 }
158
159 return result;
160 }
161
162}
static dqm_algorithms::AveragePrint staticInstance
#define y
#define x
std::string histogram
Definition chains.cxx:52
virtual dqm_core::Algorithm * clone()
virtual dqm_core::Result * execute(const std::string &name, const TObject &data, const dqm_core::AlgorithmConfig &config)
virtual void printDescription(std::ostream &out)
void mean(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")
int r
Definition globals.cxx:22
double GetFirstFromMap(const std::string &paramName, const std::map< std::string, double > &params)
#define IsA
Declare the TObject style functions.