ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
DataQuality
dqm_algorithms
src
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
9
#include "
dqm_algorithms/TRTCheckPeakSimple.h
"
10
#include "dqm_core/exceptions.h"
11
#include "dqm_core/AlgorithmConfig.h"
12
#include "dqm_core/AlgorithmManager.h"
13
#include "dqm_core/Result.h"
14
#include "
dqm_algorithms/tools/AlgorithmHelper.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
25
static
dqm_algorithms::TRTCheckPeakSimple
staticInstance
;
26
27
namespace
dqm_algorithms
28
{
29
30
TRTCheckPeakSimple::TRTCheckPeakSimple
():
m_name
(
"TRTCheckPeakSimple"
)
31
{
32
dqm_core::AlgorithmManager::instance().registerAlgorithm(
m_name
,
this
);
33
}
34
35
TRTCheckPeakSimple::~TRTCheckPeakSimple
()
36
{
37
}
38
39
dqm_core::Algorithm *
TRTCheckPeakSimple::clone
()
40
{
41
return
new
TRTCheckPeakSimple
(*
this
);
42
}
43
44
45
dqm_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
124
void
TRTCheckPeakSimple::printDescription
(std::ostream& out)
125
{
126
out <<
m_name
<<
": Checks on the most probable value (peak) in the histogram."
<< std::endl;
127
}
128
129
}
// namespace dqm_algorithms
AlgorithmHelper.h
staticInstance
static dqm_algorithms::AveragePrint staticInstance
Definition
AveragePrint.cxx:19
TRTCheckPeakSimple.h
file declares the dqm_algorithms::TRTCheckPeakSimple class.
histogram
std::string histogram
Definition
chains.cxx:52
dqm_algorithms::TRTCheckPeakSimple
Definition
TRTCheckPeakSimple.h:21
dqm_algorithms::TRTCheckPeakSimple::TRTCheckPeakSimple
TRTCheckPeakSimple()
Definition
TRTCheckPeakSimple.cxx:30
dqm_algorithms::TRTCheckPeakSimple::execute
virtual dqm_core::Result * execute(const std::string &, const TObject &, const dqm_core::AlgorithmConfig &)
Definition
TRTCheckPeakSimple.cxx:45
dqm_algorithms::TRTCheckPeakSimple::clone
virtual dqm_core::Algorithm * clone()
Definition
TRTCheckPeakSimple.cxx:39
dqm_algorithms::TRTCheckPeakSimple::printDescription
virtual void printDescription(std::ostream &out)
Definition
TRTCheckPeakSimple.cxx:124
dqm_algorithms::TRTCheckPeakSimple::m_name
std::string m_name
Definition
TRTCheckPeakSimple.h:32
dqm_algorithms::TRTCheckPeakSimple::~TRTCheckPeakSimple
virtual ~TRTCheckPeakSimple()
Definition
TRTCheckPeakSimple.cxx:35
integral
double integral(TH1 *h)
Definition
computils.cxx:59
xmax
double xmax
Definition
listroot.cxx:61
xmin
double xmin
Definition
listroot.cxx:60
dqm_algorithms::tools::GetBinRange
std::vector< int > GetBinRange(const TH1 *histogram, const std::map< std::string, double > ¶ms)
Definition
AlgorithmHelper.cxx:387
dqm_algorithms::tools::GetFirstFromMap
double GetFirstFromMap(const std::string ¶mName, const std::map< std::string, double > ¶ms)
Definition
AlgorithmHelper.cxx:346
dqm_algorithms::tools::GetFromMap
const T & GetFromMap(const std::string &pname, const std::map< std::string, T > ¶ms)
Definition
AlgorithmHelper.h:109
dqm_algorithms
Definition
AddReference.h:17
IsA
#define IsA
Declare the TObject style functions.
Definition
xAODTEventBranch.h:59
Generated on
for ATLAS Offline Software by
1.17.0