ATLAS Offline Software
Loading...
Searching...
No Matches
EventCutFlowHistAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7
8//
9// includes
10//
11
13
14#include <TH1.h>
15
16//
17// method implementations
18//
19
20namespace CP
21{
22
23 StatusCode EventCutFlowHistAlg ::
24 initialize ()
25 {
29 ANA_CHECK (m_systematicsList.initialize());
30 ANA_CHECK (m_selectionNameSvc.retrieve());
31
32 // Total label
33 m_labels.push_back ("total");
34 // Individual labels
35 for (size_t i{}; i < m_selections.size(); i++) {
36 std::string label = m_selections.at(i).getSelectionName();
37 // Check if the string ends with "_%SYS%"
38 if (label.size() >= 6 && label.substr(label.size() - 6) == "_%SYS%") {
39 // Remove "_%SYS%" from the end of the string
40 label.erase(label.size() - 6);
41 }
42 m_labels.push_back (std::move(label));
43 m_allCutsNum ++;
44 }
45 assert (m_allCutsNum+1 == m_labels.size());
46
47 return StatusCode::SUCCESS;
48 }
49
50 StatusCode EventCutFlowHistAlg ::
51 execute ()
52 {
53 for (const auto& sys : m_systematicsList.systematicsVector())
54 {
55 const xAOD::EventInfo *evtInfo = nullptr;
56 ANA_CHECK (m_eventInfoHandle.retrieve (evtInfo, sys));
57
58 auto histIter = m_hist.find (sys);
59 if (histIter == m_hist.end())
60 {
61 std::string name;
62 ANA_CHECK (m_systematicsList.service().makeSystematicsName (name, m_histPattern, sys));
63
64 std::string title = m_histTitle.value();
65 if (!sys.empty())
66 title += " (" + sys.name() + ")";
67 ANA_CHECK (book (TH1F (name.c_str(), title.c_str(), m_allCutsNum+1, 0, m_allCutsNum+1)));
68
69 m_hist.insert (std::make_pair (sys, hist (name)));
70 histIter = m_hist.find (sys);
71 assert (histIter != m_hist.end());
72
73 for (unsigned i = 0; i < m_allCutsNum+1; i++)
74 {
75 histIter->second->GetXaxis()->SetBinLabel(i + 1, m_labels[i].c_str());
76 }
77 }
78
79 if (m_preselection.getBool (*evtInfo, sys)) {
80 unsigned cutIndex = 1;
81 histIter->second->Fill (0);
82 for (size_t i{}; i < m_selections.size(); i++) {
83 if (m_selections.at(i).getBool (*evtInfo, sys) > 0) {
84 histIter->second->Fill (cutIndex);
85 }
86 cutIndex++;
87 }
88 }
89 }
90 return StatusCode::SUCCESS;
91 }
92}
#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
SysListHandle m_systematicsList
the systematics list we run
Gaudi::Property< std::string > m_histTitle
the histogram title to use
SysReadSelectionHandleArray m_selections
the input object selections for which to create a cutflow
std::unordered_map< CP::SystematicSet, TH1 * > m_hist
the created histograms
SysReadHandle< xAOD::EventInfo > m_eventInfoHandle
the jet collection we run on
SysReadSelectionHandle m_preselection
the preselection we apply to our input
Gaudi::Property< std::string > m_histPattern
the pattern for histogram names
ServiceHandle< ISelectionNameSvc > m_selectionNameSvc
the selection name service
unsigned m_allCutsNum
the total number of cuts configured (needed to configure histograms)
std::string label(const std::string &format, int i)
Definition label.h:19
Select isolated Photons, Electrons and Muons.
EventInfo_v1 EventInfo
Definition of the latest event info version.