ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
MuonSpectrometer
MuonPhaseII
MuonPatternRecognition
MuonTruthAlgsR4
src
SimHitToTruthPartAssocAlg.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
#include "
SimHitToTruthPartAssocAlg.h
"
5
6
#include "
xAODTruth/TruthVertex.h
"
7
#include "
StoreGate/WriteDecorHandle.h
"
8
#include "
StoreGate/ReadHandle.h
"
9
10
#include "
xAODMuonViews/ContainerDecorator.h
"
11
12
namespace
{
13
using
SimHitVec_t = std::vector<const xAOD::MuonSimHit*>;
14
using
MCPartSimMap_t = std::unordered_map<HepMC::ConstGenParticlePtr, SimHitVec_t>;
15
using
IdDecorHandle_t =
xAOD::ContainerDecorator<xAOD::TruthParticleContainer, std::vector<unsigned long long>
>;
16
}
17
18
namespace
MuonR4
{
19
StatusCode
SimHitToTruthPartAssocAlg::initialize
() {
20
ATH_CHECK
(
m_idHelperSvc
.retrieve());
21
ATH_CHECK
(
m_truthKey
.initialize());
22
ATH_CHECK
(
m_hitDecorKey
.initialize());
23
ATH_CHECK
(
m_simHitKey
.initialize());
24
return
StatusCode::SUCCESS;
25
}
26
StatusCode
SimHitToTruthPartAssocAlg::execute
(
const
EventContext& ctx)
const
{
27
28
const
xAOD::MuonSimHitContainer
* simHits{
nullptr
};
29
ATH_CHECK
(
SG::get
(simHits,
m_simHitKey
, ctx));
30
31
MCPartSimMap_t hitIdMap{};
32
for
(
const
xAOD::MuonSimHit
*
hit
: *simHits) {
33
if
(!
hit
->genParticleLink().isValid()){
34
continue
;
35
}
36
const
auto
& pl{
hit
->genParticleLink()};
37
hitIdMap[pl].push_back(
hit
);
38
}
39
40
const
xAOD::TruthParticleContainer
* truthMuons{
nullptr
};
41
ATH_CHECK
(
SG::get
(truthMuons,
m_truthKey
, ctx));
42
IdDecorHandle_t idDecorator{
m_hitDecorKey
, ctx};
43
for
(
const
xAOD::TruthParticle
* muon : *truthMuons) {
44
std::vector<unsigned long long>& hitIds{idDecorator(*muon)};
45
auto
history =
HepMC::simulation_history
(muon, -1);
// Returns a list of unique IDs
46
for
(
const
auto
& [pl, hits] : hitIdMap) {
47
const
auto
linkId =
HepMC::uniqueID
(pl);
48
if
(std::ranges::any_of(history,[&linkId](
const
auto
uniqueId){
49
return
linkId == uniqueId;
50
})){
51
std::ranges::transform(hits, std::back_inserter(hitIds),
52
[](
const
xAOD::MuonSimHit
*
hit
) {
53
return
hit
->identify().get_compact();
54
});
55
}
56
}
57
}
58
return
StatusCode::SUCCESS;
59
}
60
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ContainerDecorator.h
hit
bool hit(const Container &ids, int pdgId)
Definition
JetIRCSafeLabelTool.cxx:64
SimHitToTruthPartAssocAlg.h
ReadHandle.h
Handle class for reading from StoreGate.
WriteDecorHandle.h
Handle class for adding a decoration to an object.
TruthVertex.h
MuonR4::SimHitToTruthPartAssocAlg::initialize
virtual StatusCode initialize() override final
Definition
SimHitToTruthPartAssocAlg.cxx:19
MuonR4::SimHitToTruthPartAssocAlg::m_hitDecorKey
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_hitDecorKey
Decoration to the hit identifier vector.
Definition
SimHitToTruthPartAssocAlg.h:34
MuonR4::SimHitToTruthPartAssocAlg::m_truthKey
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthKey
Data dependency on the truth input container to decorate.
Definition
SimHitToTruthPartAssocAlg.h:32
MuonR4::SimHitToTruthPartAssocAlg::m_simHitKey
SG::ReadHandleKey< xAOD::MuonSimHitContainer > m_simHitKey
Data dependency on the sim hit container.
Definition
SimHitToTruthPartAssocAlg.h:36
MuonR4::SimHitToTruthPartAssocAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
IdHelperSvc for Identifier printing / manipulation.
Definition
SimHitToTruthPartAssocAlg.h:29
MuonR4::SimHitToTruthPartAssocAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition
SimHitToTruthPartAssocAlg.cxx:26
xAOD::ContainerDecorator
Auxiliary class to instantiate WriteDecorHandles.The handles can be created in an empty state.
Definition
ContainerDecorator.h:18
HepMC::uniqueID
int uniqueID(const T &p)
Definition
MagicNumbers.h:89
HepMC::simulation_history
std::deque< int > simulation_history(const T &p, const int direction)
Function to calculate all the descendants(direction=1)/ancestors(direction=-1) of the particle.
Definition
MagicNumbers.h:160
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::MuonSimHitContainer
MuonSimHitContainer_v1 MuonSimHitContainer
Define the version of the pixel cluster container.
Definition
MuonSimHitContainer.h:14
xAOD::MuonSimHit
MuonSimHit_v1 MuonSimHit
Defined the version of the MuonSimHit.
Definition
MuonSimHit.h:12
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