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 for(uint i_vertex=0; i_vertex<bsmVertices.size(); ++i_vertex) {
51 const auto* bsmVertex = bsmVertices[i_vertex];
52 if(isFromVertexOfInterest(particle, bsmVertex)) {
53 m_truthMuonVertexMuonLinks[i_vertex].push_back((particle->index()));
54 }
55 }
56 }
57
58
59
60 if(!m_tree.fill(ctx)) {
61 return StatusCode::FAILURE;
62 }
63 return StatusCode::SUCCESS;
64 }
65
66/*
67@brief Selects vertices of BSM particles decaying to muons
68*/
69
71
72 if (vertex->nIncomingParticles() != 1)
73 return false;
74
75 if (vertex->nOutgoingParticles() < 2)
76 return false;
77
78 const xAOD::TruthParticle *truthPart = vertex->incomingParticle(0);
79 if (not truthPart)
80 return false;
81
82 //-- Keep particles of the pdgid requested (if any set requested, else
83 // everything is kept)
84 if (m_pdgIdsToKeepVertex.size() > 0 &&
85 std::find(m_pdgIdsToKeepVertex.begin(), m_pdgIdsToKeepVertex.end(),
86 std::abs(truthPart->pdgId())) == m_pdgIdsToKeepVertex.end()){
87 return false;
88 }
89
90 return true;
91}
92
93void TruthMuonVertexDumperAlg::printChildren(const xAOD::TruthParticle* particle, int indentLevel) const {
94 std::string indent(indentLevel * 2, ' ');
95 ATH_MSG_VERBOSE(indent << "Particle: PDG ID = " << particle->pdgId() << ", pT = " << particle->pt()
96 << ", eta = " << particle->eta() << ", phi = " << particle->phi() << ", charge = " << particle->charge());
97 for (size_t i=0; i<particle->nChildren(); ++i) {
98 const auto* child = particle->child(i);
99 printChildren(child, indentLevel + 1);
100 }
101}
102
104 if (!particle->prodVtx()) {
105 return false;
106 }
107 if (particle->prodVtx() == vertex) return true;
108
109 for (size_t i=0; i<particle->prodVtx()->nIncomingParticles(); ++i) {
110 const auto* parent = particle->prodVtx()->incomingParticle(i);
111 if (isFromVertexOfInterest(parent, vertex)) {
112 return true;
113 }
114 }
115 return false;
116}
117
118} // 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
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.