ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
DataQuality
dqm_algorithms
src
CheckBinSpike.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
// **********************************************************************
6
// $Id: CheckBinSpike.cxx,v 1.0 2024-06-12 19:40:53 jlieberm $
7
// **********************************************************************
8
9
#include "
dqm_algorithms/CheckBinSpike.h
"
10
11
#include <cmath>
12
#include <iostream>
13
14
15
#include "dqm_core/exceptions.h"
16
#include "dqm_core/AlgorithmManager.h"
17
#include "dqm_core/Result.h"
18
#include <
dqm_algorithms/tools/AlgorithmHelper.h
>
19
20
namespace
{
21
dqm_algorithms::CheckBinSpike
CheckBinSpike_1D(
"1D"
);
22
}
23
24
namespace
dqm_algorithms
{
25
26
// *********************************************************************
27
// Public Methods
28
// *********************************************************************
29
30
CheckBinSpike::CheckBinSpike
(
const
std::string & name )
31
:
m_name
( name )
32
{
33
dqm_core::AlgorithmManager::instance().registerAlgorithm(
"CheckBinSpike_"
+ name,
this
);
34
}
35
36
dqm_algorithms::CheckBinSpike
*
CheckBinSpike::clone
(){
37
return
new
CheckBinSpike
(
m_name
);
38
}
39
40
41
dqm_core::Result*
CheckBinSpike::execute
(
const
std::string& name,
const
TObject& data,
const
dqm_core::AlgorithmConfig & config ){
42
// Cast to the type of TObject to assess
43
const
TH1*
h
=
dynamic_cast<
const
TH1*
>
( &data );
44
if
(
h
== 0 ) {
45
throw
dqm_core::BadConfig( ERS_HERE, name,
"Cannot cast data to type TH1"
);
46
}
47
const
TH1*
ref
=
dynamic_cast<
const
TH1*
>
( config.getReference() );
48
if
(
ref
== 0 ) {
49
throw
dqm_core::BadConfig( ERS_HERE, name,
"Cannot obtain reference of type TH1"
);
50
}
51
double
greenThr, redThr;
52
53
std::string thrName=
"MaxDist"
;
54
55
try
{
56
greenThr =
dqm_algorithms::tools::GetFromMap
( thrName, config.getGreenThresholds() );
57
redThr =
dqm_algorithms::tools::GetFromMap
( thrName, config.getRedThresholds() );
58
}
59
catch
( dqm_core::Exception & ex ) {
60
throw
dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
61
62
}
63
float
bin
= 0;
64
float
maxValue
= 0;
65
checkBinByBin
(
h
,
maxValue
,
bin
);
66
std::unique_ptr<dqm_core::Result> result (
new
dqm_core::Result());
67
result->tags_[
"MaximumValue"
] =
maxValue
;
68
result->tags_[
"SpottedBin"
] =
bin
;
69
70
if
(
maxValue
< greenThr ) {
71
result->status_ = dqm_core::Result::Green;
72
}
73
else
if
(
maxValue
> redThr ) {
74
result->status_ = dqm_core::Result::Red;
75
}
76
else
{
77
result->status_ = dqm_core::Result::Yellow;
78
}
79
return
result.release();
80
}
81
82
void
CheckBinSpike::checkBinByBin
(
const
TH1* hist,
float
&result,
float
&detectedBin) {
83
std::vector<float> values;
84
for
(
int
ibin=1; ibin<hist->GetNbinsX()+1; ibin++ ){
85
float
ref
= (hist->GetBinContent(ibin-1) + hist->GetBinContent(ibin+1))*0.5;
86
if
( ibin==1 ) {
87
ref
= (hist->GetBinContent(hist->GetNbinsX()) + hist->GetBinContent(ibin+1))*0.5;
88
}
89
if
( ibin==hist->GetNbinsX() ){
90
ref
= (hist->GetBinContent(1) + hist->GetBinContent(ibin-1))*0.5;
91
}
92
float
test = hist->GetBinContent(ibin);
93
values.push_back(test/
ref
);
94
}
95
result = *std::max_element(values.begin(),values.end());
96
int
bin
= std::max_element(values.begin(),values.end()) - values.begin();
97
detectedBin = hist->GetXaxis()->GetBinCenter(
bin
);
98
}
99
100
void
CheckBinSpike::printDescription
(std::ostream& out){
101
std::string message;
102
message +=
"\n"
;
103
message +=
"Algorithm: \""
+
m_name
+
"\"\n"
;
104
message +=
"Description: Checks if the maximum ratio between bins in a TH1F\n"
;
105
message +=
" is above a given threshold. Useful for peak detection\n"
;
106
message +=
"Parameters: none\n"
;
107
message +=
"\n"
;
108
out << message;
109
}
110
111
}
// namespace dqm_algorithms
112
ref
const std::regex ref(r_ef)
AlgorithmHelper.h
CheckBinSpike.h
file declares the dqm_algorithms::CheckBinSpike class.
maxValue
#define maxValue(current, test)
Definition
CompoundLayerMaterialCreator.h:22
h
Header file for AthHistogramAlgorithm.
bin
Definition
BinsDiffFromStripMedian.h:43
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
dqm_algorithms::CheckBinSpike
Definition
CheckBinSpike.h:19
dqm_algorithms::CheckBinSpike::execute
dqm_core::Result * execute(const std::string &, const TObject &, const dqm_core::AlgorithmConfig &)
Definition
CheckBinSpike.cxx:41
dqm_algorithms::CheckBinSpike::checkBinByBin
void checkBinByBin(const TH1 *hist, float &result, float &detectedBin)
Definition
CheckBinSpike.cxx:82
dqm_algorithms::CheckBinSpike::CheckBinSpike
CheckBinSpike(const std::string &name)
Definition
CheckBinSpike.cxx:30
dqm_algorithms::CheckBinSpike::clone
CheckBinSpike * clone()
Definition
CheckBinSpike.cxx:36
dqm_algorithms::CheckBinSpike::printDescription
void printDescription(std::ostream &out)
Definition
CheckBinSpike.cxx:100
dqm_algorithms::CheckBinSpike::m_name
std::string m_name
Definition
CheckBinSpike.h:27
Generated on
for ATLAS Offline Software by
1.17.0