ATLAS Offline Software
Loading...
Searching...
No Matches
TruthMuonVertexDumper.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
9
10
11namespace MuonR4{
13 m_tree.addBranch(std::make_shared<MuonVal::EventHashBranch>(m_tree.tree()));
14 m_truthMuonP4 = std::make_unique<MuonVal::IParticleFourMomBranch>(m_tree, "truthMuon");
15 m_tree.addBranch(m_truthMuonP4);
16 ATH_CHECK(m_tree.init(this));
17
18 ATH_CHECK(m_truthMuonsKey.initialize(!m_truthMuonsKey.empty()));
19 ATH_CHECK(m_truthVertexKey.initialize(!m_truthVertexKey.empty()));
20
21 ATH_MSG_ALWAYS("Successfully initialized");
22
23 return StatusCode::SUCCESS;
24 }
25
27 ATH_CHECK(m_tree.write());
28 return StatusCode::SUCCESS;
29 }
30
32 const EventContext& ctx{Gaudi::Hive::currentContext()};
33
34 const xAOD::TruthParticleContainer* truthMuons{nullptr};
35 ATH_CHECK(SG::get(truthMuons, m_truthMuonsKey, ctx));
36 const xAOD::TruthVertexContainer* truthVertices{nullptr};
37 ATH_CHECK(SG::get(truthVertices, m_truthVertexKey, ctx));
38
39
40 std::vector<const xAOD::TruthVertex*> bsmVertices{};
41 for (const auto* vertex : *truthVertices) {
42 if(!selectDecayVertex(vertex)) continue;
43 bsmVertices.push_back(vertex);
44 m_truthMuonVertexPosition.push_back(Amg::Vector3D(vertex->x(), vertex->y(), vertex->z()));
45 }
46
47 // Filling the information about all final state muons
48 for (const auto* particle : *truthMuons) {
49 m_truthMuonP4->push_back(particle);
50 printParents(particle, 20);
51 for(uint i_vertex=0; i_vertex<bsmVertices.size(); ++i_vertex) {
52 const auto* bsmVertex = bsmVertices[i_vertex];
53 if(isFromVertexOfInterest(particle, bsmVertex)) {
54 m_truthMuonVertexMuonLinks[i_vertex].push_back((particle->index()));
55 }
56 }
57 }
58
59
60
61 if(!m_tree.fill(ctx)) {
62 return StatusCode::FAILURE;
63 }
64 return StatusCode::SUCCESS;
65 }
66
67/*
68@brief Selects vertices of BSM particles decaying to muons
69*/
70
72
73 if (vertex->nIncomingParticles() != 1)
74 return false;
75
76 if (vertex->nOutgoingParticles() < 2)
77 return false;
78
79 const xAOD::TruthParticle *truthPart = vertex->incomingParticle(0);
80 if (not truthPart)
81 return false;
82
83 //-- Keep particles of the pdgid requested (if any set requested, else
84 // everything is kept)
85 if (m_pdgIdsToKeepVertex.size() > 0 &&
86 std::find(m_pdgIdsToKeepVertex.begin(), m_pdgIdsToKeepVertex.end(),
87 std::abs(truthPart->pdgId())) == m_pdgIdsToKeepVertex.end()){
88 return false;
89 }
90
91 return true;
92}
93
94void TruthMuonVertexDumperAlg::printChildren(const xAOD::TruthParticle* particle, int indentLevel) const {
95 std::string indent(indentLevel * 2, ' ');
96 ATH_MSG_VERBOSE(indent << "Particle: PDG ID = " << particle->pdgId() << ", pT = " << particle->pt()
97 << ", eta = " << particle->eta() << ", phi = " << particle->phi() << ", charge = " << particle->charge());
98 for (size_t i=0; i<particle->nChildren(); ++i) {
99 const auto* child = particle->child(i);
100 printChildren(child, indentLevel + 1);
101 }
102}
103
104void TruthMuonVertexDumperAlg::printParents(const xAOD::TruthParticle* particle, int indentLevel) const {
105 std::string indent(indentLevel * 2, ' ');
106 ATH_MSG_VERBOSE(indent << "Particle: PDG ID = " << particle->pdgId() << ", pT = " << particle->pt()
107 << ", eta = " << particle->eta() << ", phi = " << particle->phi() << ", charge = " << particle->charge());
108 if (particle->prodVtx()) {
109 for (size_t i=0; i<particle->prodVtx()->nIncomingParticles(); ++i) {
110 const auto* parent = particle->prodVtx()->incomingParticle(i);
111 printParents(parent, indentLevel + 1);
112 }
113 }
114}
115
117 if (!particle->prodVtx()) {
118 return false;
119 }
120 if (particle->prodVtx() == vertex) return true;
121
122 for (size_t i=0; i<particle->prodVtx()->nIncomingParticles(); ++i) {
123 const auto* parent = particle->prodVtx()->incomingParticle(i);
124 if (isFromVertexOfInterest(parent, vertex)) {
125 return true;
126 }
127 }
128 return false;
129}
130
131} // namespace MuonR4
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_ALWAYS(x)
unsigned int uint
Handle class for reading from StoreGate.
MuonVal::ThreeVectorBranch m_truthMuonVertexPosition
void printChildren(const xAOD::TruthParticle *particle, int indentLevel) const
SG::ReadHandleKey< xAOD::TruthVertexContainer > m_truthVertexKey
virtual StatusCode initialize() override final
virtual StatusCode execute() override final
MuonVal::MatrixBranch< uint16_t > & m_truthMuonVertexMuonLinks
void printParents(const xAOD::TruthParticle *particle, int indentLevel) const
std::shared_ptr< MuonVal::IParticleFourMomBranch > m_truthMuonP4
Gaudi::Property< std::vector< int > > m_pdgIdsToKeepVertex
virtual StatusCode finalize() override final
bool selectDecayVertex(const xAOD::TruthVertex *vertex) const
bool isFromVertexOfInterest(const xAOD::TruthParticle *particle, const xAOD::TruthVertex *vertex) const
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthMuonsKey
int pdgId() const
PDG ID code.
Eigen::Matrix< double, 3, 1 > Vector3D
This header ties the generic definitions in this package.
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
TruthVertex_v1 TruthVertex
Typedef to implementation.
Definition TruthVertex.h:15
TruthVertexContainer_v1 TruthVertexContainer
Declare the latest version of the truth vertex container.
TruthParticle_v1 TruthParticle
Typedef to implementation.
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.