ATLAS Offline Software
Loading...
Searching...
No Matches
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
15namespace {
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
32namespace DerivationFramework{
33MuonTruthIsolationDecorAlg::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());
57 ATH_CHECK(m_ptvarcone20_Key.initialize());
59 ATH_CHECK(m_ptvarcone30_Key.initialize());
60
61 return StatusCode::SUCCESS;
62}
63
64StatusCode 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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
ATLAS-specific HepMC functions.
An algorithm that can be simultaneously executed in multiple threads.
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_ptcone20_pt500_Key
PtCone20.
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_ptvarcone20_pt500_Key
PtVarCone20.
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_topoetcone20_Key
Decor handle keys. Never set them via the JO as they're overwritten.
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_ptvarcone30_Key
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_ptvarcone20_Key
virtual StatusCode execute(const EventContext &ctx) const override
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_ptvarcone30_pt500_Key
Pt varcone 30.
MuonTruthIsolationDecorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters.
SG::ReadHandleKey< xAOD::TruthEventContainer > m_truthSGKey
SG::ReadHandleKey< xAOD::IParticleContainer > m_partSGKey
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_ptcone20_Key
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:569
SG::Decorator< T, ALLOC > Decorator
Definition AuxElement.h:575
Handle mappings between names and auxid_t.
std::string getName(SG::auxid_t auxid) const
Return the name of an aux data item.
static AuxTypeRegistry & instance()
Return the singleton registry instance.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Class providing the definition of the 4-vector interface.
bool isNeutrino() const
Whether the particle is a neutrino (or antineutrino)
double abseta() const
The absolute pseudorapidity ( ) of the particle.
bool isCharged() const
Whether the particle is electrically charged.
virtual double pt() const override final
The transverse momentum ( ) of the particle.
virtual double phi() const override final
The azimuthal angle ( ) of the particle.
THE reconstruction tool.
bool is_same_particle(const T1 &p1, const T2 &p2)
Method to establish if two particles in the GenEvent actually represent the same 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...
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
double deltaR(double rapidity1, double phi1, double rapidity2, double phi2)
from bare bare rapidity,phi
TruthEvent_v1 TruthEvent
Typedef to implementation.
Definition TruthEvent.h:17
TruthParticle_v1 TruthParticle
Typedef to implementation.