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