ATLAS Offline Software
Loading...
Searching...
No Matches
TRTCheckPeakSimple.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
8
10#include "dqm_core/exceptions.h"
11#include "dqm_core/AlgorithmConfig.h"
12#include "dqm_core/AlgorithmManager.h"
13#include "dqm_core/Result.h"
15#include "ers/ers.h"
16
17#include "TClass.h"
18#include "TH1.h"
19#include "TF1.h"
20
21#include <cmath>
22#include <iostream>
23#include <map>
24
26
27namespace dqm_algorithms
28{
29
31{
32 dqm_core::AlgorithmManager::instance().registerAlgorithm(m_name, this);
33}
34
38
39dqm_core::Algorithm *TRTCheckPeakSimple::clone()
40{
41 return new TRTCheckPeakSimple(*this);
42}
43
44
45dqm_core::Result *TRTCheckPeakSimple::execute(const std::string &name, const TObject &object, const dqm_core::AlgorithmConfig &config)
46{
47 const TH1 *histogram;
48
49 if (object.IsA()->InheritsFrom("TH1")) {
50 histogram = static_cast<const TH1*>(&object);
51 if (histogram->GetDimension() > 2) {
52 throw dqm_core::BadConfig(ERS_HERE, name, "dimension > 2 ");
53 }
54 } else {
55 throw dqm_core::BadConfig(ERS_HERE, name, "does not inherit from TH1");
56 }
57 const double minstat = dqm_algorithms::tools::GetFirstFromMap("MinStat", config.getParameters(), -1);
58
59 if (histogram->GetEntries() < minstat) {
60 // ERS_INFO("Histogram does not satisfy MinStat requirement " << histogram->GetName());
61 dqm_core::Result *result = new dqm_core::Result(dqm_core::Result::Undefined);
62 result->tags_["InsufficientEntries"] = histogram->GetEntries();
63 return result;
64 }
65
66 dqm_core::Result *result = new dqm_core::Result();
67
68 if (histogram->Integral() == 0 && histogram->GetEntries() > 0) {
69 ERS_DEBUG(1, "Histogram " << histogram->GetName() << " is filled with zeroes!");
70 result->status_ = dqm_core::Result::Red;
71 result->tags_["Integral"] = histogram->Integral();
72 return result;
73 }
74
75
76 const double gthreshold = dqm_algorithms::tools::GetFromMap("PeakPosition", config.getGreenThresholds());
77 const double rthreshold = dqm_algorithms::tools::GetFromMap("PeakPosition", config.getRedThresholds());
78 const std::vector<int> range = dqm_algorithms::tools::GetBinRange(histogram, config.getParameters());
79 const int xmin = range[0];
80 const int xmax = range[1];
81
82 //compute the weighted mean
83 float wmean = 0;
84 float sum = 0;
85 float integral = 0;
86 for (int i = xmin; i <= xmax; i++) {
87 integral += histogram->GetBinContent(i);
88 sum += i * (histogram->GetBinContent(i));
89 }
90 if (integral != 0) {
91 wmean = sum / integral; // make sure that integer division does not truncate decimal of mean
92 }
93
94 //find the most probable value (peak)
95 float maxbinsum = 0;
96 float binsum = 0;
97 float peakbin = 0;
98 float peakpos = 0;
99
100 for (int i = xmin + 1; i <= xmax - 1; i++) {
101 binsum = histogram->GetBinContent(i - 1) + histogram->GetBinContent(i) + histogram->GetBinContent(i + 1);
102 if (binsum > maxbinsum) {
103 maxbinsum = binsum;
104 if (maxbinsum != 0) {
105 peakbin = ((i - 1) * histogram->GetBinContent(i - 1) + i * histogram->GetBinContent(i) + (i + 1) * histogram->GetBinContent(i + 1)) / maxbinsum;
106 peakpos = (histogram->GetBinCenter(i - 1) * histogram->GetBinContent(i - 1) + histogram->GetBinCenter(i) * histogram->GetBinContent(i) + histogram->GetBinCenter(i + 1) * histogram->GetBinContent(i + 1)) / maxbinsum;
107 } else {
108 peakbin = 0;
109 peakpos = 0;
110 }
111 }
112 }
113
114 result->tags_["Weighted_mean"] = wmean;
115 result->tags_["PeakBin"] = peakbin;
116 result->tags_["PeakPosition"] = peakpos;
117
118 if (peakpos >= gthreshold) result->status_ = dqm_core::Result::Green;
119 else if (peakpos > rthreshold) result->status_ = dqm_core::Result::Yellow;
120 else result->status_ = dqm_core::Result::Red;
121 return result;
122}
123
125{
126 out << m_name << ": Checks on the most probable value (peak) in the histogram." << std::endl;
127}
128
129} // namespace dqm_algorithms
static dqm_algorithms::AveragePrint staticInstance
file declares the dqm_algorithms::TRTCheckPeakSimple class.
std::string histogram
Definition chains.cxx:52
virtual dqm_core::Result * execute(const std::string &, const TObject &, const dqm_core::AlgorithmConfig &)
virtual dqm_core::Algorithm * clone()
virtual void printDescription(std::ostream &out)
double integral(TH1 *h)
Definition computils.cxx:59
double xmax
Definition listroot.cxx:61
double xmin
Definition listroot.cxx:60
std::vector< int > GetBinRange(const TH1 *histogram, const std::map< std::string, double > &params)
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.