ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
MuonSpectrometer
MuonPhaseII
MuonCnv
MuonBucketDump
src
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
5
#include "
TruthMuonVertexDumper.h
"
6
7
#include "
StoreGate/ReadHandle.h
"
8
#include "
MuonTesterTree/EventHashBranch.h
"
9
10
11
namespace
MuonR4
{
12
StatusCode
TruthMuonVertexDumperAlg::initialize
() {
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
26
StatusCode
TruthMuonVertexDumperAlg::finalize
() {
27
ATH_CHECK
(
m_tree
.write());
28
return
StatusCode::SUCCESS;
29
}
30
31
StatusCode
TruthMuonVertexDumperAlg::execute
(
const
EventContext& ctx) {
32
33
const
xAOD::TruthParticleContainer
* truthMuons{
nullptr
};
34
ATH_CHECK
(
SG::get
(truthMuons,
m_truthMuonsKey
, ctx));
35
const
xAOD::TruthVertexContainer
* truthVertices{
nullptr
};
36
ATH_CHECK
(
SG::get
(truthVertices,
m_truthVertexKey
, ctx));
37
38
39
std::vector<const xAOD::TruthVertex*> bsmVertices{};
40
for
(
const
auto
* vertex : *truthVertices) {
41
if
(!
selectDecayVertex
(vertex))
continue
;
42
bsmVertices.push_back(vertex);
43
m_truthMuonVertexPosition
.push_back(
Amg::Vector3D
(vertex->x(), vertex->y(), vertex->z()));
44
}
45
46
// Filling the information about all final state muons
47
for
(
const
auto
* particle : *truthMuons) {
48
m_truthMuonP4
->push_back(particle);
49
printParents
(particle, 20);
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
70
bool
TruthMuonVertexDumperAlg::selectDecayVertex
(
const
xAOD::TruthVertex
* vertex)
const
{
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
93
void
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
103
void
TruthMuonVertexDumperAlg::printParents
(
const
xAOD::TruthParticle
* particle,
int
indentLevel)
const
{
104
std::string indent(indentLevel * 2,
' '
);
105
ATH_MSG_VERBOSE
(indent <<
"Particle: PDG ID = "
<< particle->pdgId() <<
", pT = "
<< particle->pt()
106
<<
", eta = "
<< particle->eta() <<
", phi = "
<< particle->phi() <<
", charge = "
<< particle->charge());
107
if
(particle->prodVtx()) {
108
for
(
size_t
i=0; i<particle->prodVtx()->nIncomingParticles(); ++i) {
109
const
auto
* parent = particle->prodVtx()->incomingParticle(i);
110
printParents
(parent, indentLevel + 1);
111
}
112
}
113
}
114
115
bool
TruthMuonVertexDumperAlg::isFromVertexOfInterest
(
const
xAOD::TruthParticle
* particle,
const
xAOD::TruthVertex
* vertex)
const
{
116
if
(!particle->prodVtx()) {
117
return
false
;
118
}
119
if
(particle->prodVtx() == vertex)
return
true
;
120
121
for
(
size_t
i=0; i<particle->prodVtx()->nIncomingParticles(); ++i) {
122
const
auto
* parent = particle->prodVtx()->incomingParticle(i);
123
if
(
isFromVertexOfInterest
(parent, vertex)) {
124
return
true
;
125
}
126
}
127
return
false
;
128
}
129
130
}
// namespace MuonR4
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition
AthMsgStreamMacros.h:28
ATH_MSG_ALWAYS
#define ATH_MSG_ALWAYS(x)
Definition
AthMsgStreamMacros.h:35
EventHashBranch.h
uint
unsigned int uint
Definition
LArOFPhaseFill.cxx:19
ReadHandle.h
Handle class for reading from StoreGate.
TruthMuonVertexDumper.h
MuonR4::TruthMuonVertexDumperAlg::m_truthMuonVertexPosition
MuonVal::ThreeVectorBranch m_truthMuonVertexPosition
Definition
TruthMuonVertexDumper.h:46
MuonR4::TruthMuonVertexDumperAlg::printChildren
void printChildren(const xAOD::TruthParticle *particle, int indentLevel) const
Definition
TruthMuonVertexDumper.cxx:93
MuonR4::TruthMuonVertexDumperAlg::m_tree
MuonVal::MuonTesterTree m_tree
Definition
TruthMuonVertexDumper.h:37
MuonR4::TruthMuonVertexDumperAlg::execute
virtual StatusCode execute(const EventContext &ctx) override final
Execute method.
Definition
TruthMuonVertexDumper.cxx:31
MuonR4::TruthMuonVertexDumperAlg::m_truthVertexKey
SG::ReadHandleKey< xAOD::TruthVertexContainer > m_truthVertexKey
Definition
TruthMuonVertexDumper.h:33
MuonR4::TruthMuonVertexDumperAlg::initialize
virtual StatusCode initialize() override final
Definition
TruthMuonVertexDumper.cxx:12
MuonR4::TruthMuonVertexDumperAlg::m_truthMuonVertexMuonLinks
MuonVal::MatrixBranch< uint16_t > & m_truthMuonVertexMuonLinks
Definition
TruthMuonVertexDumper.h:47
MuonR4::TruthMuonVertexDumperAlg::printParents
void printParents(const xAOD::TruthParticle *particle, int indentLevel) const
Definition
TruthMuonVertexDumper.cxx:103
MuonR4::TruthMuonVertexDumperAlg::m_truthMuonP4
std::shared_ptr< MuonVal::IParticleFourMomBranch > m_truthMuonP4
Definition
TruthMuonVertexDumper.h:48
MuonR4::TruthMuonVertexDumperAlg::m_pdgIdsToKeepVertex
Gaudi::Property< std::vector< int > > m_pdgIdsToKeepVertex
Definition
TruthMuonVertexDumper.h:35
MuonR4::TruthMuonVertexDumperAlg::finalize
virtual StatusCode finalize() override final
Definition
TruthMuonVertexDumper.cxx:26
MuonR4::TruthMuonVertexDumperAlg::selectDecayVertex
bool selectDecayVertex(const xAOD::TruthVertex *vertex) const
Definition
TruthMuonVertexDumper.cxx:70
MuonR4::TruthMuonVertexDumperAlg::isFromVertexOfInterest
bool isFromVertexOfInterest(const xAOD::TruthParticle *particle, const xAOD::TruthVertex *vertex) const
Definition
TruthMuonVertexDumper.cxx:115
MuonR4::TruthMuonVertexDumperAlg::m_truthMuonsKey
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthMuonsKey
Definition
TruthMuonVertexDumper.h:32
xAOD::TruthParticle_v1::pdgId
int pdgId() const
PDG ID code.
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition
GeoPrimitives.h:47
MuonR4
This header ties the generic definitions in this package.
Definition
GlobalPattern.h:14
SG::get
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
Definition
ReadCondHandle.h:282
xAOD::TruthVertex
TruthVertex_v1 TruthVertex
Typedef to implementation.
Definition
TruthVertex.h:15
xAOD::TruthVertexContainer
TruthVertexContainer_v1 TruthVertexContainer
Declare the latest version of the truth vertex container.
Definition
TruthVertexContainer.h:17
xAOD::TruthParticle
TruthParticle_v1 TruthParticle
Typedef to implementation.
Definition
Event/xAOD/xAODTruth/xAODTruth/TruthParticle.h:15
xAOD::TruthParticleContainer
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.
Definition
Event/xAOD/xAODTruth/xAODTruth/TruthParticleContainer.h:17
Generated on
for ATLAS Offline Software by
1.17.0