ATLAS Offline Software
MuonTruthIsolationDecorAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // MuonTruthIsolationDecorAlg.cxx, (c) ATLAS Detector software
8 // Runs on muons without a truth particle link.
9 // Finds the nearest stable truth particle and adds its info to the muon.
11 
15 namespace {
16  static const SG::AuxElement::ConstAccessor<ElementLink<xAOD::TruthParticleContainer>> acc_tpl("truthParticleLink");
17 
18  static const SG::AuxElement::Decorator<float> decorator_topoetcone20("topoetcone20_truth");
19 
20  static const SG::AuxElement::Decorator<float> decorator_ptcone20("ptcone20_truth");
21  static const SG::AuxElement::Decorator<float> decorator_ptvarcone20("ptvarcone20_truth");
22  static const SG::AuxElement::Decorator<float> decorator_ptvarcone30("ptvarcone30_truth");
23 
24  static const SG::AuxElement::Decorator<float> decorator_ptcone20_pt500("ptcone20_pt500_truth");
25  static const SG::AuxElement::Decorator<float> decorator_ptvarcone20_pt500("ptvarcone20_pt500_truth");
26  static const SG::AuxElement::Decorator<float> decorator_ptvarcone30_pt500("ptvarcone30_pt500_truth");
27 
28  static const Muon::MuonSectorMapping sector_mapping;
29 
30 } // namespace
31 // Constructor
32 namespace DerivationFramework{
33 MuonTruthIsolationDecorAlg::MuonTruthIsolationDecorAlg(const std::string& name, ISvcLocator* pSvcLocator) :
34  AthReentrantAlgorithm(name, pSvcLocator) {}
35 
36 // Athena initialize and finalize
38  ATH_MSG_VERBOSE("initialize() ...");
39  ATH_CHECK(m_partSGKey.initialize());
40  ATH_CHECK(m_truthSGKey.initialize());
41 
43  m_topoetcone20_Key = registry.getName(decorator_topoetcone20.auxid());
44 
45  m_ptcone20_pt500_Key = registry.getName(decorator_ptcone20_pt500.auxid());
46  m_ptvarcone20_pt500_Key = registry.getName(decorator_ptvarcone20_pt500.auxid());
47  m_ptvarcone30_pt500_Key = registry.getName(decorator_ptvarcone30_pt500.auxid());
48 
49  m_ptcone20_Key = registry.getName(decorator_ptcone20.auxid());
50  m_ptvarcone20_Key = registry.getName(decorator_ptvarcone20.auxid());
51  m_ptvarcone30_Key = registry.getName(decorator_ptvarcone30.auxid());
52 
53  ATH_CHECK(m_topoetcone20_Key.initialize());
54  ATH_CHECK(m_ptcone20_pt500_Key.initialize());
55  ATH_CHECK(m_ptcone20_Key.initialize());
56  ATH_CHECK(m_ptvarcone20_pt500_Key.initialize());
57  ATH_CHECK(m_ptvarcone20_Key.initialize());
58  ATH_CHECK(m_ptvarcone30_pt500_Key.initialize());
59  ATH_CHECK(m_ptvarcone30_Key.initialize());
60 
61  return StatusCode::SUCCESS;
62 }
63 
64 StatusCode MuonTruthIsolationDecorAlg::execute(const EventContext& ctx) const {
65  // Retrieve main particle collection
67  if (!parts.isValid()) {
68  ATH_MSG_ERROR("No Muon collection with name " << m_partSGKey.fullKey() << " found in StoreGate!");
69  return StatusCode::FAILURE;
70  }
72  if (!tec.isValid()) {
73  ATH_MSG_ERROR("No truth collection with name " << m_truthSGKey.fullKey() << " found in StoreGate!");
74  return StatusCode::FAILURE;
75  }
76  std::map<int, std::vector<const xAOD::TruthParticle*>> truth_map_calo;
77  std::map<int, std::vector<const xAOD::TruthParticle*>> truth_map_track;
78 
79  // sector_mapping
80  for (const xAOD::TruthEvent* event : *tec) {
81  for (size_t parti = 0; parti < event->nTruthParticles(); ++parti) {
82  const xAOD::TruthParticle* tpart = event->truthParticle(parti);
83  if (!tpart || tpart->pt() < 1 || !MC::isStable(tpart) || HepMC::is_simulation_particle(tpart) || tpart->isNeutrino()) continue;
84  const int sector = sector_mapping.getSector(tpart->phi());
85  truth_map_calo[sector].push_back(tpart);
86  if (tpart->pt() < 500 || !tpart->isCharged() || tpart->abseta() > 2.5) continue;
87  truth_map_track[sector].push_back(tpart);
88  }
89  }
90 
91  for (const xAOD::IParticle* part : *parts) {
92  const float varradius20 = std::min(10e3 / part->pt(), 0.2);
93  const float varradius30 = std::min(10e3 / part->pt(), 0.3);
94  const xAOD::TruthParticle* const truthLink = (acc_tpl(*part).isValid() ? *acc_tpl(*part) : nullptr);
95 
96  std::vector<int> sectors;
97  sector_mapping.getSectors(part->phi(), sectors);
98 
99  float new_topoetcone20{0}, new_ptcone20{0}, new_ptvarcone20{0}, new_ptvarcone30{0},
100  new_ptcone20_pt500{0}, new_ptvarcone20_pt500{0}, new_ptvarcone30_pt500{0};
102  for (const int sector : sectors) {
103  const std::vector<const xAOD::TruthParticle*>& calo_container = truth_map_calo[sector];
105  for (const xAOD::TruthParticle* calo_part : calo_container) {
106  if (calo_part == truthLink || (truthLink && HepMC::is_same_particle(truthLink,calo_part))) continue;
107  const float dR = xAOD::P4Helpers::deltaR(calo_part, part, false);
108  if (dR < 0.05 || dR > 0.2) continue;
109  new_topoetcone20 += calo_part->pt();
110  }
111 
112  const std::vector<const xAOD::TruthParticle*>& truth_container = truth_map_track[sector];
113  for (const xAOD::TruthParticle* trk_part : truth_container) {
114  if (trk_part == truthLink || (truthLink && HepMC::is_same_particle(truthLink,trk_part))) continue;
115  const float dR = xAOD::P4Helpers::deltaR(trk_part, part, false);
116  const float pt = trk_part->pt();
117  if (dR > 0.3) continue;
118  new_ptcone20_pt500 += (dR < 0.2) * pt;
119  new_ptvarcone20_pt500 += (dR < varradius20) * pt;
120  new_ptvarcone30_pt500 += (dR < varradius30) * pt;
121  if (pt < 1000) continue;
122  new_ptcone20 += (dR < 0.2) * pt;
123  new_ptvarcone20 += (dR < varradius20) * pt;
124  new_ptvarcone30 += (dR < varradius30) * pt;
125  }
126  }
127 
128  decorator_topoetcone20(*part) = new_topoetcone20;
129  decorator_ptcone20(*part) = new_ptcone20;
130  decorator_ptvarcone20(*part) = new_ptvarcone20;
131  decorator_ptvarcone30(*part) = new_ptvarcone30;
132  decorator_ptcone20_pt500(*part) = new_ptcone20_pt500;
133  decorator_ptvarcone20_pt500(*part) = new_ptvarcone20_pt500;
134  decorator_ptvarcone30_pt500(*part) = new_ptvarcone30_pt500;
135  }
136  return StatusCode::SUCCESS;
137 }
138 }
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
python.Dso.registry
registry
Definition: Control/AthenaServices/python/Dso.py:159
DerivationFramework::MuonTruthIsolationDecorAlg::m_partSGKey
SG::ReadHandleKey< xAOD::IParticleContainer > m_partSGKey
Definition: MuonTruthIsolationDecorAlg.h:26
DerivationFramework::MuonTruthIsolationDecorAlg::m_ptvarcone20_pt500_Key
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_ptvarcone20_pt500_Key
PtVarCone20.
Definition: MuonTruthIsolationDecorAlg.h:36
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition: AuxTypeRegistry.cxx:640
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
xAODP4Helpers.h
test_pyathena.pt
pt
Definition: test_pyathena.py:11
MuonTruthIsolationDecorAlg.h
DerivationFramework::MuonTruthIsolationDecorAlg::m_ptcone20_Key
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_ptcone20_Key
Definition: MuonTruthIsolationDecorAlg.h:34
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
HepMC::is_same_particle
bool is_same_particle(const T1 &p1, const T2 &p2)
Method to establish if two particles in the GenEvent actually represent the same particle.
Definition: MagicNumbers.h:354
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
SG::AuxTypeRegistry
Handle mappings between names and auxid_t.
Definition: AuxTypeRegistry.h:61
DerivationFramework::MuonTruthIsolationDecorAlg::m_topoetcone20_Key
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_topoetcone20_Key
Decor handle keys. Never set them via the JO as they're overwritten.
Definition: MuonTruthIsolationDecorAlg.h:31
DerivationFramework::MuonTruthIsolationDecorAlg::m_ptcone20_pt500_Key
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_ptcone20_pt500_Key
PtCone20.
Definition: MuonTruthIsolationDecorAlg.h:33
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CheckAppliedSFs.e3
e3
Definition: CheckAppliedSFs.py:264
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:59
HepMC::is_simulation_particle
bool is_simulation_particle(const T &p)
Method to establish if a particle (or barcode) was created during the simulation (TODO update to be s...
Definition: MagicNumbers.h:342
xAOD::P4Helpers::deltaR
double deltaR(double rapidity1, double phi1, double rapidity2, double phi2)
from bare bare rapidity,phi
Definition: xAODP4Helpers.h:150
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:37
DerivationFramework::MuonTruthIsolationDecorAlg::MuonTruthIsolationDecorAlg
MuonTruthIsolationDecorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters.
Definition: MuonTruthIsolationDecorAlg.cxx:33
xAOD::TruthEvent_v1
Class describing a signal truth event in the MC record.
Definition: TruthEvent_v1.h:35
DerivationFramework::MuonTruthIsolationDecorAlg::m_ptvarcone30_Key
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_ptvarcone30_Key
Definition: MuonTruthIsolationDecorAlg.h:40
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
xAOD::TruthParticle_v1::isCharged
bool isCharged() const
Whether the particle is electrically charged.
min
#define min(a, b)
Definition: cfImp.cxx:40
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
DerivationFramework::MuonTruthIsolationDecorAlg::m_ptvarcone30_pt500_Key
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_ptvarcone30_pt500_Key
Pt varcone 30.
Definition: MuonTruthIsolationDecorAlg.h:39
MC::isStable
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
Definition: HepMCHelpers.h:45
MuonSectorMapping.h
xAOD::TruthParticle_v1::phi
virtual double phi() const override final
The azimuthal angle ( ) of the particle.
Definition: TruthParticle_v1.cxx:181
DerivationFramework::MuonTruthIsolationDecorAlg::m_truthSGKey
SG::ReadHandleKey< xAOD::TruthEventContainer > m_truthSGKey
Definition: MuonTruthIsolationDecorAlg.h:28
DerivationFramework::MuonTruthIsolationDecorAlg::initialize
StatusCode initialize() override
Definition: MuonTruthIsolationDecorAlg.cxx:37
xAOD::TruthParticle_v1::pt
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition: TruthParticle_v1.cxx:166
doL1CaloHVCorrections.parts
parts
Definition: doL1CaloHVCorrections.py:334
Muon::MuonSectorMapping
Definition: MuonSectorMapping.h:20
xAOD::TruthParticle_v1::isNeutrino
bool isNeutrino() const
Whether the particle is a neutrino (or antineutrino)
DerivationFramework::MuonTruthIsolationDecorAlg::m_ptvarcone20_Key
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_ptvarcone20_Key
Definition: MuonTruthIsolationDecorAlg.h:37
HepMCHelpers.h
DerivationFramework::MuonTruthIsolationDecorAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: MuonTruthIsolationDecorAlg.cxx:64
xAOD::TruthParticle_v1::abseta
double abseta() const
The absolute pseudorapidity ( ) of the particle.
Definition: TruthParticle_v1.cxx:218