ATLAS Offline Software
KinematicHistAlg.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  {
30  return StatusCode::SUCCESS;
31  }
32 
33 
34 
36  execute ()
37  {
38  for (const auto& sys : m_systematicsList.systematicsVector())
39  {
40  const xAOD::IParticleContainer *input = nullptr;
41  ANA_CHECK (m_inputHandle.retrieve (input, sys));
42 
43  auto histIter = m_hist.find (sys);
44  if (histIter == m_hist.end())
45  {
46  std::string name;
48 
49  name = RCU::substitute (m_histPattern, "%VAR%", "multiplicity");
51  ANA_CHECK (book (TH1F (name.c_str(), "multiplicity", 20, 0, 20)));
52  group.multiplicity = hist (name);
53 
54  m_hist.insert (std::make_pair (sys, group));
55  histIter = m_hist.find (sys);
56  assert (histIter != m_hist.end());
57  }
58 
59  std::size_t count = 0;
60  for (std::size_t iter = 0; iter != input->size(); ++ iter)
61  {
62  const xAOD::IParticle *particle = (*input)[iter];
64  {
65  while (histIter->second.perObject.size() <= count)
66  {
67  std::string name;
69 
70  name = RCU::substitute (m_histPattern, "%VAR%", "pt" + std::to_string(histIter->second.perObject.size()));
72  ANA_CHECK (book (TH1F (name.c_str(), "pt", 20, 0, 200e3)));
73  group.pt = hist (name);
74 
75  name = RCU::substitute (m_histPattern, "%VAR%", "eta" + std::to_string(histIter->second.perObject.size()));
77  ANA_CHECK (book (TH1F (name.c_str(), "eta", 20, -5, 5)));
78  group.eta = hist (name);
79 
80  name = RCU::substitute (m_histPattern, "%VAR%", "phi" + std::to_string(histIter->second.perObject.size()));
82  ANA_CHECK (book (TH1F (name.c_str(), "phi", 20, -M_PI, M_PI)));
83  group.phi = hist (name);
84 
85  histIter->second.perObject.push_back (group);
86  }
87 
88  HistSubgroup& group = histIter->second.perObject[count];
89 
90  group.pt->Fill (particle->pt());
91  group.eta->Fill (particle->eta());
92  group.phi->Fill (particle->phi());
93  count += 1;
94  }
95  }
96 
97  histIter->second.multiplicity->Fill (count);
98  }
99  return StatusCode::SUCCESS;
100  }
101 }
CP::KinematicHistAlg::initialize
StatusCode initialize() override
Definition: KinematicHistAlg.cxx:25
CP::KinematicHistAlg::m_inputHandle
SysReadHandle< xAOD::IParticleContainer > m_inputHandle
the jet collection we run on
Definition: KinematicHistAlg.h:41
CP::KinematicHistAlg::m_preselection
SysReadSelectionHandle m_preselection
the preselection we apply to our input
Definition: KinematicHistAlg.h:46
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
CP::KinematicHistAlg::m_systematicsList
SysListHandle m_systematicsList
the systematics list we run
Definition: KinematicHistAlg.h:37
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
M_PI
#define M_PI
Definition: ActiveFraction.h:11
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:41
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
StringUtil.h
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
CP::KinematicHistAlg::m_hist
std::unordered_map< CP::SystematicSet, HistGroup > m_hist
the created histograms
Definition: KinematicHistAlg.h:74
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
CheckAppliedSFs.e3
e3
Definition: CheckAppliedSFs.py:264
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
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
KinematicHistAlg.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
CP::KinematicHistAlg::m_histPattern
Gaudi::Property< std::string > m_histPattern
the pattern for histogram names
Definition: KinematicHistAlg.h:51
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
CP::KinematicHistAlg::HistSubgroup
the histograms we fill per systematic and object
Definition: KinematicHistAlg.h:57
RCU::substitute
std::string substitute(const std::string &str, const std::string &pattern, const std::string &with)
effects: substitute all occurences of "pattern" with "with" in the string "str" returns: the substitu...
Definition: StringUtil.cxx:24
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
CaloLCW_tf.group
group
Definition: CaloLCW_tf.py:28
CP::SysReadSelectionHandle::initialize
StatusCode initialize(SysListHandle &sysListHandle, const ISysHandleBase &objectHandle)
initialize the accessor
Definition: SysReadSelectionHandle.cxx:34
CP::KinematicHistAlg::HistGroup
the histograms we fill per systematic
Definition: KinematicHistAlg.h:67
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
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
CP::KinematicHistAlg::execute
StatusCode execute() override
Definition: KinematicHistAlg.cxx:36
CP::SysListHandle::service
const ISystematicsSvc & service() const
the service we use