ATLAS Offline Software
EventCutFlowHistAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 
8 //
9 // includes
10 //
11 
13 
15 #include <TH1.h>
16 
17 //
18 // method implementations
19 //
20 
21 namespace CP
22 {
23 
25  initialize ()
26  {
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 (label);
44  m_allCutsNum ++;
45  }
46  assert (m_allCutsNum+1 == m_labels.size());
47 
48  return StatusCode::SUCCESS;
49  }
50 
52  execute ()
53  {
54  for (const auto& sys : m_systematicsList.systematicsVector())
55  {
56  const xAOD::EventInfo *evtInfo = nullptr;
57  ANA_CHECK (m_eventInfoHandle.retrieve (evtInfo, sys));
58 
59  auto histIter = m_hist.find (sys);
60  if (histIter == m_hist.end())
61  {
62  std::string name;
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  if (m_preselection.getBool (*evtInfo, sys)) {
81  unsigned cutIndex = 1;
82  histIter->second->Fill (0);
83  for (size_t i{}; i < m_selections.size(); i++) {
84  if (m_selections.at(i).getBool (*evtInfo, sys) > 0) {
85  histIter->second->Fill (cutIndex);
86  }
87  cutIndex++;
88  }
89  }
90  }
91  return StatusCode::SUCCESS;
92  }
93 }
CP::EventCutFlowHistAlg::m_allCutsNum
unsigned m_allCutsNum
the total number of cuts configured (needed to configure histograms)
Definition: EventCutFlowHistAlg.h:67
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:303
CP::EventCutFlowHistAlg::initialize
StatusCode initialize() override
Definition: EventCutFlowHistAlg.cxx:25
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
CP::SysHandleArray::initialize
StatusCode initialize(Args &&...args)
Create and initialize all the sub-handles.
CP::EventCutFlowHistAlg::m_histPattern
Gaudi::Property< std::string > m_histPattern
the pattern for histogram names
Definition: EventCutFlowHistAlg.h:49
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
CP::SysListHandle::systematicsVector
const std::vector< CP::SystematicSet > & systematicsVector() const
the list of systematics to loop over
Definition: SysListHandle.cxx:96
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
StringUtil.h
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
CP::SysListHandle::initialize
::StatusCode initialize()
intialize this property
Definition: SysListHandle.cxx:69
CP::SysReadSelectionHandle::getBool
bool getBool(const SG::AuxElement &element, const CP::SystematicSet &sys) const
get the selection as a bool
lumiFormat.i
int i
Definition: lumiFormat.py:92
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
covarianceTool.title
title
Definition: covarianceTool.py:542
CP::EventCutFlowHistAlg::m_selectionNameSvc
ServiceHandle< ISelectionNameSvc > m_selectionNameSvc
the selection name service
Definition: EventCutFlowHistAlg.h:53
CP::SysHandleArray::size
std::size_t size() const noexcept
The number of defined handles.
CP::EventCutFlowHistAlg::m_preselection
SysReadSelectionHandle m_preselection
the preselection we apply to our input
Definition: EventCutFlowHistAlg.h:44
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
CP::EventCutFlowHistAlg::m_systematicsList
SysListHandle m_systematicsList
the systematics list we run
Definition: EventCutFlowHistAlg.h:35
CP::ISystematicsSvc::makeSystematicsName
virtual StatusCode makeSystematicsName(std::string &result, const std::string &name, const CP::SystematicSet &sys) const =0
make the name for the given systematics
EventCutFlowHistAlg.h
CP::EventCutFlowHistAlg::m_histTitle
Gaudi::Property< std::string > m_histTitle
the histogram title to use
Definition: EventCutFlowHistAlg.h:57
TH1F
Definition: rootspy.cxx:320
CP::SysReadSelectionHandle::getSelectionName
const std::string & getSelectionName() const
get the name of the selection
Definition: SysReadSelectionHandle.cxx:84
CP::SysReadSelectionHandle::initialize
StatusCode initialize(SysListHandle &sysListHandle, const ISysHandleBase &objectHandle)
initialize the accessor
Definition: SysReadSelectionHandle.cxx:34
CP::EventCutFlowHistAlg::execute
StatusCode execute() override
Definition: EventCutFlowHistAlg.cxx:52
CP::EventCutFlowHistAlg::m_eventInfoHandle
SysReadHandle< xAOD::EventInfo > m_eventInfoHandle
the jet collection we run on
Definition: EventCutFlowHistAlg.h:39
CP::EventCutFlowHistAlg::m_labels
std::vector< std::string > m_labels
histogram bin labels
Definition: EventCutFlowHistAlg.h:75
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:198
CP::EventCutFlowHistAlg::m_selections
SysReadSelectionHandleArray m_selections
the input object selections for which to create a cutflow
Definition: EventCutFlowHistAlg.h:61
CP::EventCutFlowHistAlg::m_hist
std::unordered_map< CP::SystematicSet, TH1 * > m_hist
the created histograms
Definition: EventCutFlowHistAlg.h:71
CP::SysHandleArray::at
HANDLE & at(std::size_t idx)
Retrieve the handle at the specified index.
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
CP::SysListHandle::service
const ISystematicsSvc & service() const
the service we use