ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
Algorithms
AsgAnalysisAlgorithms
Root
ObjectCutFlowHistAlg.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
7
8
9
//
10
// includes
11
//
12
13
#include <
AsgAnalysisAlgorithms/ObjectCutFlowHistAlg.h
>
14
15
#include <TH1.h>
16
17
//
18
// method implementations
19
//
20
21
namespace
CP
22
{
23
24
StatusCode ObjectCutFlowHistAlg ::
25
initialize ()
26
{
27
ANA_CHECK
(
m_inputHandle
.initialize (
m_systematicsList
));
28
ANA_CHECK
(
m_preselection
.initialize (
m_systematicsList
,
m_inputHandle
,
SG::AllowEmpty
));
29
ANA_CHECK
(
m_selections
.initialize (
m_systematicsList
,
m_inputHandle
));
30
ANA_CHECK
(
m_systematicsList
.initialize());
31
ANA_CHECK
(
m_selectionNameSvc
.retrieve());
32
33
// Total label
34
m_labels
.push_back (
"total"
);
35
// Individual labels
36
for
(
size_t
i{}; i <
m_selections
.size(); i++) {
37
std::string
label
=
m_selections
.at(i).getSelectionName();
38
// Check if the string ends with "_%SYS%"
39
if
(
label
.size() >= 6 &&
label
.substr(
label
.size() - 6) ==
"_%SYS%"
) {
40
// Remove "_%SYS%" from the end of the string
41
label
.erase(
label
.size() - 6);
42
}
43
m_labels
.push_back (std::move(
label
));
44
m_allCutsNum
++;
45
}
46
assert (
m_allCutsNum
+1 ==
m_labels
.size());
47
48
return
StatusCode::SUCCESS;
49
}
50
51
StatusCode ObjectCutFlowHistAlg ::
52
execute (
const
EventContext& ctx)
53
{
54
for
(
const
auto
& sys :
m_systematicsList
.systematicsVector())
55
{
56
const
xAOD::IParticleContainer
*input =
nullptr
;
57
ANA_CHECK
(
m_inputHandle
.retrieve (input, sys, ctx));
58
59
auto
histIter =
m_hist
.find (sys);
60
if
(histIter ==
m_hist
.end())
61
{
62
std::string
name
;
63
ANA_CHECK
(
m_systematicsList
.service().makeSystematicsName (
name
,
m_histPattern
, sys));
64
65
std::string title =
m_histTitle
.value();
66
if
(!sys.empty())
67
title +=
" ("
+ sys.name() +
")"
;
68
ANA_CHECK
(
book
(TH1F (
name
.c_str(), title.c_str(),
m_allCutsNum
+1, 0,
m_allCutsNum
+1)));
69
70
m_hist
.insert (std::make_pair (sys,
hist
(
name
)));
71
histIter =
m_hist
.find (sys);
72
assert (histIter !=
m_hist
.end());
73
74
for
(
unsigned
i = 0; i <
m_allCutsNum
+1; i++)
75
{
76
histIter->second->GetXaxis()->SetBinLabel(i + 1,
m_labels
[i].c_str());
77
}
78
}
79
80
for
(
const
xAOD::IParticle
*particle : *input) {
81
if
(
m_preselection
.getBool (*particle, sys)) {
82
unsigned
cutIndex = 1;
83
histIter->second->Fill (0);
84
bool
selected{
true
};
85
for
(
size_t
i{}; i <
m_selections
.size(); i++) {
86
if
((!
m_forceCutSequence
.value() || selected) &&
m_selections
.at(i).getBool (*particle, sys) > 0) {
87
histIter->second->Fill (cutIndex);
88
}
else
{
89
selected =
false
;
90
}
91
cutIndex++;
92
}
93
}
94
}
95
96
}
97
return
StatusCode::SUCCESS;
98
}
99
}
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
ObjectCutFlowHistAlg.h
AthHistogramming::book
StatusCode book(const TH1 &hist, const std::string &tDir="", const std::string &stream="")
Simplify the booking and registering (into THistSvc) of histograms.
Definition
AthHistogramming.h:305
AthHistogramming::hist
TH1 * hist(const std::string &histName, const std::string &tDir="", const std::string &stream="")
Simplify the retrieval of registered histograms of any type.
Definition
AthHistogramming.cxx:164
CP::ObjectCutFlowHistAlg::m_labels
std::vector< std::string > m_labels
histogram bin labels
Definition
ObjectCutFlowHistAlg.h:79
CP::ObjectCutFlowHistAlg::m_selections
SysReadSelectionHandleArray m_selections
the input object selections for which to create a cutflow
Definition
ObjectCutFlowHistAlg.h:61
CP::ObjectCutFlowHistAlg::m_allCutsNum
unsigned m_allCutsNum
the total number of cuts configured (needed to configure histograms)
Definition
ObjectCutFlowHistAlg.h:71
CP::ObjectCutFlowHistAlg::m_forceCutSequence
Gaudi::Property< bool > m_forceCutSequence
force cut sequence
Definition
ObjectCutFlowHistAlg.h:66
CP::ObjectCutFlowHistAlg::m_inputHandle
SysReadHandle< xAOD::IParticleContainer > m_inputHandle
the particle collection we run on
Definition
ObjectCutFlowHistAlg.h:39
CP::ObjectCutFlowHistAlg::m_histTitle
Gaudi::Property< std::string > m_histTitle
the histogram title to use
Definition
ObjectCutFlowHistAlg.h:57
CP::ObjectCutFlowHistAlg::m_preselection
SysReadSelectionHandle m_preselection
the preselection we apply to our input
Definition
ObjectCutFlowHistAlg.h:44
CP::ObjectCutFlowHistAlg::m_selectionNameSvc
ServiceHandle< ISelectionNameSvc > m_selectionNameSvc
the selection name service
Definition
ObjectCutFlowHistAlg.h:53
CP::ObjectCutFlowHistAlg::m_systematicsList
SysListHandle m_systematicsList
the systematics list we run
Definition
ObjectCutFlowHistAlg.h:35
CP::ObjectCutFlowHistAlg::m_hist
std::unordered_map< CP::SystematicSet, TH1 * > m_hist
the created histograms
Definition
ObjectCutFlowHistAlg.h:75
CP::ObjectCutFlowHistAlg::m_histPattern
Gaudi::Property< std::string > m_histPattern
the pattern for histogram names
Definition
ObjectCutFlowHistAlg.h:49
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition
Event/xAOD/xAODBase/xAODBase/IParticle.h:41
label
std::string label(const std::string &format, int i)
Definition
label.h:19
CP
Select isolated Photons, Electrons and Muons.
Definition
Control/xAODRootAccess/xAODRootAccess/TEvent.h:27
SG::AllowEmpty
@ AllowEmpty
Definition
StoreGate/StoreGate/VarHandleKey.h:27
xAOD::name
name
Definition
TriggerMenuJson_v1.cxx:29
xAOD::IParticleContainer
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.
Definition
xAOD/xAODBase/xAODBase/IParticleContainer.h:32
Generated on
for ATLAS Offline Software by
1.17.0