ATLAS Offline Software
Loading...
Searching...
No Matches
DerivationFramework::MuonTruthClassifierFallback Class Reference

#include <MuonTruthClassifierFallback.h>

Inheritance diagram for DerivationFramework::MuonTruthClassifierFallback:
Collaboration diagram for DerivationFramework::MuonTruthClassifierFallback:

Public Member Functions

virtual StatusCode initialize () override
virtual StatusCode addBranches (const EventContext &ctx) const override

Private Attributes

SG::ReadHandleKey< xAOD::IParticleContainerm_containerKey {this, "ContainerKey", "", "Key of the container to be decorated"}
SG::ReadHandleKey< xAOD::TruthEventContainerm_truthSGKey {this, "TruthSGKey", "TruthEvents", "Key of the truth event container"}
SG::ReadHandleKey< xAOD::TruthPileupEventContainerm_truthPileupSGKey
SG::ReadHandleKey< xAOD::TruthParticleContainerm_truthMuonSGKey {this, "TruthMuonContainerKey", "MuonTruthParticles", ""}
SG::WriteDecorHandleKey< xAOD::IParticleContainerm_Truth_dR_Key
SG::WriteDecorHandleKey< xAOD::IParticleContainerm_Truth_type_Key
SG::WriteDecorHandleKey< xAOD::IParticleContainerm_Truth_origin_Key
SG::WriteDecorHandleKey< xAOD::IParticleContainerm_Truth_PU_dR_Key
SG::WriteDecorHandleKey< xAOD::IParticleContainerm_Truth_PU_type_Key
SG::WriteDecorHandleKey< xAOD::IParticleContainerm_Truth_PU_origin_Key
Gaudi::Property< float > m_minPt {this, "MinPt", 2500}
ToolHandle< IMCTruthClassifierm_mcTruthClassifier {this, "MCTruthClassifierTool", "", "Handle of the MC truth classifier"}

Detailed Description

Definition at line 22 of file MuonTruthClassifierFallback.h.

Member Function Documentation

◆ addBranches()

StatusCode DerivationFramework::MuonTruthClassifierFallback::addBranches ( const EventContext & ctx) const
overridevirtual

Definition at line 49 of file MuonTruthClassifierFallback.cxx.

49 {
50 // Retrieve main particle collection
51
52 SG::ReadHandle<xAOD::IParticleContainer> parts{m_containerKey, ctx};
53 if (!parts.isValid()) {
54 ATH_MSG_ERROR("No Muon collection with name " << m_containerKey.fullKey() << " found in StoreGate!");
55 return StatusCode::FAILURE;
56 }
57 SG::ReadHandle<xAOD::TruthEventContainer> tec{m_truthSGKey, ctx};
58 if (!tec.isValid()) {
59 ATH_MSG_ERROR("No truth collection with name " << m_truthSGKey.fullKey() << " found in StoreGate!");
60 return StatusCode::FAILURE;
61 }
62 SG::ReadHandle<xAOD::TruthPileupEventContainer> tpec{m_truthPileupSGKey, ctx};
63 if (!tpec.isValid()) {
64 ATH_MSG_DEBUG("No truth pileup collection with name " << m_truthPileupSGKey.fullKey() << " found in StoreGate. Pile-up information will not be filled");
65 }
66
67 SG::ReadHandle<xAOD::TruthParticleContainer> truthMuons{m_truthMuonSGKey, ctx};
68 if (!truthMuons.isValid()) {
69 ATH_MSG_ERROR("No truth muon collection with name " << m_truthMuonSGKey.fullKey() << " found in StoreGate!");
70 return StatusCode::FAILURE;
71 }
72
73 // Set up the decorator
74
75 for (const xAOD::IParticle* part : *parts) {
76 const xAOD::TruthParticle* closest = nullptr;
77 float minDR{FLT_MAX};
78 for (const xAOD::TruthParticle* muTruth : *truthMuons) {
79 const float dR = xAOD::P4Helpers::deltaR2(muTruth, part);
80 if (dR > minDR) continue;
81 closest = muTruth;
82 minDR = dR;
83 }
84
85 for (const xAOD::TruthEvent* event : *tec) {
86 for (size_t parti = 0; parti < event->nTruthParticles(); parti++) {
87 const xAOD::TruthParticle* tpart = event->truthParticle(parti);
88 if (!tpart || !MC::isStable(tpart) || HepMC::is_simulation_particle(tpart) || !tpart->charge() || tpart->isMuon() ||
89 tpart->pt() < m_minPt)
90 continue;
91 const float dR = xAOD::P4Helpers::deltaR2(tpart, part);
92 if (dR > minDR) continue;
93 closest = tpart;
94 minDR = dR;
95 }
96 }
97
98 decorator_dR(*part) = closest ? std::sqrt(minDR) : -1;
99
100 int newType{-1}, newOrigin{-1};
101 if (closest && closest->isMuon()) {
102 newType = acc_tT(*closest);
103 newOrigin = acc_tO(*closest);
104 } else if (closest) {
105 auto res = m_mcTruthClassifier->particleTruthClassifier(closest);
106 newType = res.first;
107 newOrigin = res.second;
108 }
109 decorator_type(*part) = newType;
110 decorator_origin(*part) = newOrigin;
111
112 decorator_pu_dR(*part) = -1;
113 decorator_pu_type(*part) = -1;
114 decorator_pu_origin(*part) = -1;
115
116 minDR = FLT_MAX;
117
118 if (tpec.isValid()) {
119 const xAOD::TruthParticle* closestPileup = nullptr;
120 for (auto event : *tpec) {
121 for (size_t parti = 0; parti < event->nTruthParticles(); parti++) {
122 const xAOD::TruthParticle* tpart = event->truthParticle(parti);
123 if (!tpart || !MC::isStable(tpart) || HepMC::is_simulation_particle(tpart) || !tpart->charge() || tpart->isMuon() ||
124 tpart->pt() < m_minPt)
125 continue;
126 const float dR = xAOD::P4Helpers::deltaR2(tpart, part);
127 if (dR > minDR) continue;
128 closestPileup = tpart;
129 minDR = dR;
130 }
131 }
132 decorator_pu_dR(*part) = (closestPileup ? std::sqrt(minDR) : -1);
133 int newPileupType{-1}, newPileupOrigin{-1};
134 if (closestPileup) {
135 auto res = m_mcTruthClassifier->particleTruthClassifier(closestPileup);
136 newPileupType = res.first;
137 newPileupOrigin = res.second;
138 }
139 decorator_pu_type(*part) = newPileupType;
140 decorator_pu_origin(*part) = newPileupOrigin;
141 }
142 }
143
144 return StatusCode::SUCCESS;
145}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
std::pair< std::vector< unsigned int >, bool > res
SG::ReadHandleKey< xAOD::TruthPileupEventContainer > m_truthPileupSGKey
SG::ReadHandleKey< xAOD::TruthEventContainer > m_truthSGKey
SG::ReadHandleKey< xAOD::IParticleContainer > m_containerKey
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthMuonSGKey
virtual bool isValid() override final
Can the handle be successfully dereferenced?
virtual double pt() const override final
The transverse momentum ( ) of the particle.
double charge() const
Physical charge.
bool isMuon() const
Whether the particle is a muon (or antimuon)
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 deltaR2(double rapidity1, double phi1, double rapidity2, double phi2)
from bare rapidity,phi
TruthEvent_v1 TruthEvent
Typedef to implementation.
Definition TruthEvent.h:17
TruthParticle_v1 TruthParticle
Typedef to implementation.

◆ initialize()

StatusCode DerivationFramework::MuonTruthClassifierFallback::initialize ( )
overridevirtual

Definition at line 27 of file MuonTruthClassifierFallback.cxx.

27 {
28 ATH_MSG_VERBOSE("initialize() ...");
30
31 ATH_CHECK(m_containerKey.initialize());
32 ATH_CHECK(m_truthSGKey.initialize());
33 ATH_CHECK(m_truthPileupSGKey.initialize());
34 ATH_CHECK(m_truthMuonSGKey.initialize());
35
36 // FIXME These WriteDecorHandles are not being used. The
37 // Decorators above are (incorrectly) used instead.
38 ATH_CHECK(m_Truth_dR_Key.initialize());
39 ATH_CHECK(m_Truth_type_Key.initialize());
40 ATH_CHECK(m_Truth_origin_Key.initialize());
41
42 ATH_CHECK(m_Truth_PU_dR_Key.initialize());
43 ATH_CHECK(m_Truth_PU_type_Key.initialize());
44 ATH_CHECK(m_Truth_PU_origin_Key.initialize());
45
46 return StatusCode::SUCCESS;
47}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_Truth_type_Key
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_Truth_origin_Key
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_Truth_dR_Key
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_Truth_PU_dR_Key
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_Truth_PU_origin_Key
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_Truth_PU_type_Key

Member Data Documentation

◆ m_containerKey

SG::ReadHandleKey<xAOD::IParticleContainer> DerivationFramework::MuonTruthClassifierFallback::m_containerKey {this, "ContainerKey", "", "Key of the container to be decorated"}
private

Definition at line 33 of file MuonTruthClassifierFallback.h.

33{this, "ContainerKey", "", "Key of the container to be decorated"};

◆ m_mcTruthClassifier

ToolHandle<IMCTruthClassifier> DerivationFramework::MuonTruthClassifierFallback::m_mcTruthClassifier {this, "MCTruthClassifierTool", "", "Handle of the MC truth classifier"}
private

Definition at line 57 of file MuonTruthClassifierFallback.h.

57{this, "MCTruthClassifierTool", "", "Handle of the MC truth classifier"};

◆ m_minPt

Gaudi::Property<float> DerivationFramework::MuonTruthClassifierFallback::m_minPt {this, "MinPt", 2500}
private

Definition at line 55 of file MuonTruthClassifierFallback.h.

55{this, "MinPt", 2500};

◆ m_Truth_dR_Key

SG::WriteDecorHandleKey<xAOD::IParticleContainer> DerivationFramework::MuonTruthClassifierFallback::m_Truth_dR_Key
private
Initial value:
{
this, "dRDecoration", m_containerKey, "MCTFallback_dR"}

Definition at line 42 of file MuonTruthClassifierFallback.h.

42 {
43 this, "dRDecoration", m_containerKey, "MCTFallback_dR"};

◆ m_Truth_origin_Key

SG::WriteDecorHandleKey<xAOD::IParticleContainer> DerivationFramework::MuonTruthClassifierFallback::m_Truth_origin_Key
private
Initial value:
{
this, "originDecoration", m_containerKey, "MCTFallback_truthOrigin"}

Definition at line 46 of file MuonTruthClassifierFallback.h.

46 {
47 this, "originDecoration", m_containerKey, "MCTFallback_truthOrigin"};

◆ m_Truth_PU_dR_Key

SG::WriteDecorHandleKey<xAOD::IParticleContainer> DerivationFramework::MuonTruthClassifierFallback::m_Truth_PU_dR_Key
private
Initial value:
{
this, "dRDecorationPU", m_containerKey, "MCTFallbackPU_dR"}

Definition at line 48 of file MuonTruthClassifierFallback.h.

48 {
49 this, "dRDecorationPU", m_containerKey, "MCTFallbackPU_dR"};

◆ m_Truth_PU_origin_Key

SG::WriteDecorHandleKey<xAOD::IParticleContainer> DerivationFramework::MuonTruthClassifierFallback::m_Truth_PU_origin_Key
private
Initial value:
{
this, "originDecorationPU", m_containerKey, "MCTFallbackPU_truthOrigin"}

Definition at line 52 of file MuonTruthClassifierFallback.h.

52 {
53 this, "originDecorationPU", m_containerKey, "MCTFallbackPU_truthOrigin"};

◆ m_Truth_PU_type_Key

SG::WriteDecorHandleKey<xAOD::IParticleContainer> DerivationFramework::MuonTruthClassifierFallback::m_Truth_PU_type_Key
private
Initial value:
{
this, "typeDecorationPU", m_containerKey, "MCTFallbackPU_truthType"}

Definition at line 50 of file MuonTruthClassifierFallback.h.

50 {
51 this, "typeDecorationPU", m_containerKey, "MCTFallbackPU_truthType"};

◆ m_Truth_type_Key

SG::WriteDecorHandleKey<xAOD::IParticleContainer> DerivationFramework::MuonTruthClassifierFallback::m_Truth_type_Key
private
Initial value:
{
this, "typeDecoration", m_containerKey, "MCTFallback_truthType"}

Definition at line 44 of file MuonTruthClassifierFallback.h.

44 {
45 this, "typeDecoration", m_containerKey, "MCTFallback_truthType"};

◆ m_truthMuonSGKey

SG::ReadHandleKey<xAOD::TruthParticleContainer> DerivationFramework::MuonTruthClassifierFallback::m_truthMuonSGKey {this, "TruthMuonContainerKey", "MuonTruthParticles", ""}
private

Definition at line 37 of file MuonTruthClassifierFallback.h.

37{this, "TruthMuonContainerKey", "MuonTruthParticles", ""};

◆ m_truthPileupSGKey

SG::ReadHandleKey<xAOD::TruthPileupEventContainer> DerivationFramework::MuonTruthClassifierFallback::m_truthPileupSGKey
private
Initial value:
{this, "TruthPileupContainerKey", "TruthPileupEvents",
"Key of the pile-up event container"}

Definition at line 35 of file MuonTruthClassifierFallback.h.

35 {this, "TruthPileupContainerKey", "TruthPileupEvents",
36 "Key of the pile-up event container"};

◆ m_truthSGKey

SG::ReadHandleKey<xAOD::TruthEventContainer> DerivationFramework::MuonTruthClassifierFallback::m_truthSGKey {this, "TruthSGKey", "TruthEvents", "Key of the truth event container"}
private

Definition at line 34 of file MuonTruthClassifierFallback.h.

34{this, "TruthSGKey", "TruthEvents", "Key of the truth event container"};

The documentation for this class was generated from the following files: