ATLAS Offline Software
ObjectCutFlowHistAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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 
22 namespace CP
23 {
24 
26  initialize ()
27  {
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 (label);
45  m_allCutsNum ++;
46  }
47  assert (m_allCutsNum+1 == m_labels.size());
48 
49  return StatusCode::SUCCESS;
50  }
51 
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;
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) {
83  unsigned cutIndex = 1;
84  histIter->second->Fill (0);
85  for (size_t i{}; i < m_selections.size(); i++) {
86  if (m_selections.at(i).getBool (*particle, sys) > 0) {
87  histIter->second->Fill (cutIndex);
88  }
89  cutIndex++;
90  }
91  }
92  }
93 
94  }
95  return StatusCode::SUCCESS;
96  }
97 }
CP::ObjectCutFlowHistAlg::m_allCutsNum
unsigned m_allCutsNum
the total number of cuts configured (needed to configure histograms)
Definition: ObjectCutFlowHistAlg.h:67
CP::ObjectCutFlowHistAlg::m_selectionNameSvc
ServiceHandle< ISelectionNameSvc > m_selectionNameSvc
the selection name service
Definition: ObjectCutFlowHistAlg.h:53
ObjectCutFlowHistAlg.h
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
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::ObjectCutFlowHistAlg::m_labels
std::vector< std::string > m_labels
histogram bin labels
Definition: ObjectCutFlowHistAlg.h:75
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
CP::ObjectCutFlowHistAlg::m_systematicsList
SysListHandle m_systematicsList
the systematics list we run
Definition: ObjectCutFlowHistAlg.h:35
CP::ObjectCutFlowHistAlg::m_histTitle
Gaudi::Property< std::string > m_histTitle
the histogram title to use
Definition: ObjectCutFlowHistAlg.h:57
CP::SysHandleArray::initialize
StatusCode initialize(Args &&...args)
Create and initialize all the sub-handles.
CP::ObjectCutFlowHistAlg::m_inputHandle
SysReadHandle< xAOD::IParticleContainer > m_inputHandle
the particle collection we run on
Definition: ObjectCutFlowHistAlg.h:39
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
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:40
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
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
CP::SysHandleArray::size
std::size_t size() const noexcept
The number of defined handles.
CP::ObjectCutFlowHistAlg::m_histPattern
Gaudi::Property< std::string > m_histPattern
the pattern for histogram names
Definition: ObjectCutFlowHistAlg.h:49
CP::ObjectCutFlowHistAlg::execute
StatusCode execute() override
Definition: ObjectCutFlowHistAlg.cxx:53
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
CP::ObjectCutFlowHistAlg::m_selections
SysReadSelectionHandleArray m_selections
the input object selections for which to create a cutflow
Definition: ObjectCutFlowHistAlg.h:61
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
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
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::ObjectCutFlowHistAlg::m_preselection
SysReadSelectionHandle m_preselection
the preselection we apply to our input
Definition: ObjectCutFlowHistAlg.h:44
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
CP::ObjectCutFlowHistAlg::initialize
StatusCode initialize() override
Definition: ObjectCutFlowHistAlg.cxx:26
CP::ObjectCutFlowHistAlg::m_hist
std::unordered_map< CP::SystematicSet, TH1 * > m_hist
the created histograms
Definition: ObjectCutFlowHistAlg.h:71