ATLAS Offline Software
Simulation
Tools
McEventCollectionFilter
src
TRT_HitsTruthRelink.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
TRT_HitsTruthRelink.h
"
6
#include "
TruthUtils/MagicNumbers.h
"
7
8
9
TRT_HitsTruthRelink::TRT_HitsTruthRelink
(
const
std::string &
name
, ISvcLocator *pSvcLocator)
10
:
HitsTruthRelinkBase
(
name
, pSvcLocator)
11
{
12
}
13
14
15
StatusCode
TRT_HitsTruthRelink::initialize
()
16
{
17
ATH_CHECK
(
HitsTruthRelinkBase::initialize
());
18
19
// Check and initialize keys
20
ATH_CHECK
(
m_inputHitsKey
.initialize() );
21
ATH_MSG_VERBOSE
(
"Initialized ReadHandleKey: "
<<
m_inputHitsKey
);
22
ATH_CHECK
(
m_outputHitsKey
.initialize() );
23
ATH_MSG_VERBOSE
(
"Initialized WriteHandleKey: "
<<
m_outputHitsKey
);
24
return
StatusCode::SUCCESS;
25
}
26
27
28
StatusCode
TRT_HitsTruthRelink::execute
(
const
EventContext &ctx)
const
29
{
30
ATH_MSG_DEBUG
(
"Doing truth relinking"
);
31
32
SG::ReadHandle<TRTUncompressedHitCollection>
inputCollection
(
m_inputHitsKey
, ctx);
33
if
(!
inputCollection
.isValid()) {
34
ATH_MSG_ERROR
(
"Could not get input hits collection "
<<
inputCollection
.name() <<
" from store "
<<
inputCollection
.store());
35
return
StatusCode::FAILURE;
36
}
37
ATH_MSG_DEBUG
(
"Found input hits collection "
<<
inputCollection
.name() <<
" in store "
<<
inputCollection
.store());
38
39
SG::WriteHandle<TRTUncompressedHitCollection>
outputCollection
(
m_outputHitsKey
, ctx);
40
ATH_CHECK
(
outputCollection
.record(std::make_unique<TRTUncompressedHitCollection>()));
41
if
(!
outputCollection
.isValid()) {
42
ATH_MSG_ERROR
(
"Could not record output hits collection "
<<
outputCollection
.name() <<
" to store "
<<
outputCollection
.store());
43
return
StatusCode::FAILURE;
44
}
45
ATH_MSG_DEBUG
(
"Recorded output hits collection "
<<
outputCollection
.name() <<
" in store "
<<
outputCollection
.store());
46
47
// Do relinking
48
int
referenceId{};
49
ATH_CHECK
(
getReferenceId
(ctx, &referenceId));
50
51
for
(
const
TRTUncompressedHit
&hit : *
inputCollection
) {
52
int
pdgID = hit.GetParticleEncoding();
53
HepMcParticleLink
particleLink =
updatedLink
(ctx, hit.particleLink(), referenceId, pdgID);
54
int
id
= hit.GetHitID();
55
float
kineticEnergy = hit.GetKineticEnergy();
56
float
energyDeposit
= hit.GetEnergyDeposit();
57
float
preX = hit.GetPreStepX();
58
float
preY = hit.GetPreStepY();
59
float
preZ = hit.GetPreStepZ();
60
float
postX = hit.GetPostStepX();
61
float
postY = hit.GetPostStepY() ;
62
float
postZ = hit.GetPostStepZ();
63
float
time
= hit.GetGlobalTime();
64
65
outputCollection
->Emplace(
id
, particleLink, pdgID, kineticEnergy,
energyDeposit
, preX, preY, preZ, postX, postY, postZ,
time
);
66
}
67
68
return
StatusCode::SUCCESS;
69
}
70
71
72
HepMcParticleLink
TRT_HitsTruthRelink::updatedLink
(
const
EventContext &ctx,
const
HepMcParticleLink
& oldLink,
int
referenceId,
int
pdgId
)
const
{
73
ATH_MSG_DEBUG
(
"oldLink.id() = "
<< oldLink.
id
());
74
int
currentId = oldLink.
id
();
75
// Hits previously linked to truth particles should now be linked to the reference truthParticle
76
if
(oldLink.
id
() !=
HepMC::UNDEFINED_ID
||
HepMC::barcode
(oldLink) !=
HepMC::UNDEFINED_ID
) {
// FIXME barcode-based for now to work around reading in HepMcParticleLink_p2 based EDM
77
// For the TRT truth electrons may optionally be kept
78
if
(!(
m_keepElectronsLinkedToTRTHits
&& std::abs(
pdgId
) == 11)) {
79
currentId = referenceId;
80
}
81
}
82
83
return
HepMcParticleLink
(currentId, oldLink.
eventIndex
(),
HepMcParticleLink::IS_EVENTNUM
,
HepMcParticleLink::IS_ID
, ctx);
84
}
TRT_HitsTruthRelink::updatedLink
virtual HepMcParticleLink updatedLink(const EventContext &ctx, const HepMcParticleLink &oldLink, int referenceId, int pdgID=0) const override final
Definition:
TRT_HitsTruthRelink.cxx:72
HepMcParticleLink::IS_EVENTNUM
@ IS_EVENTNUM
Definition:
HepMcParticleLink.h:78
TRT_HitsTruthRelink::m_outputHitsKey
SG::WriteHandleKey< TRTUncompressedHitCollection > m_outputHitsKey
Definition:
TRT_HitsTruthRelink.h:24
SG::ReadHandle
Definition:
StoreGate/StoreGate/ReadHandle.h:70
HitsTruthRelinkBase::getReferenceId
StatusCode getReferenceId(const EventContext &ctx, int *id) const
Definition:
HitsTruthRelinkBase.cxx:64
TRTUncompressedHit
Definition:
TRTUncompressedHit.h:11
TRT_HitsTruthRelink::m_keepElectronsLinkedToTRTHits
Gaudi::Property< bool > m_keepElectronsLinkedToTRTHits
Definition:
TRT_HitsTruthRelink.h:26
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition:
AthMsgStreamMacros.h:28
HepMcParticleLink::id
int id() const
Return the id of the target particle.
Definition:
HepMcParticleLink.cxx:253
TRT_HitsTruthRelink::m_inputHitsKey
SG::ReadHandleKey< TRTUncompressedHitCollection > m_inputHitsKey
Definition:
TRT_HitsTruthRelink.h:23
TRT_HitsTruthRelink::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition:
TRT_HitsTruthRelink.cxx:28
PowhegPy8EG_H2a.pdgId
dictionary pdgId
Definition:
PowhegPy8EG_H2a.py:128
TRT_HitsTruthRelink.h
TRT_HitsTruthRelink::TRT_HitsTruthRelink
TRT_HitsTruthRelink(const std::string &name, ISvcLocator *pSvcLocator)
Definition:
TRT_HitsTruthRelink.cxx:9
Trk::energyDeposit
@ energyDeposit
Definition:
MeasurementType.h:32
HitsTruthRelinkBase::initialize
virtual StatusCode initialize() override
Definition:
HitsTruthRelinkBase.cxx:14
PhysDESDM_SmpCaloId.inputCollection
inputCollection
Definition:
PhysDESDM_SmpCaloId.py:95
HepMcParticleLink
a link optimized in size for a GenParticle in a McEventCollection
Definition:
HepMcParticleLink.h:71
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition:
AthMsgStreamMacros.h:33
HepMcParticleLink::IS_ID
@ IS_ID
Definition:
HepMcParticleLink.h:83
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition:
PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition:
AthMsgStreamMacros.h:29
HepMC::barcode
int barcode(const T *p)
Definition:
Barcode.h:16
ATH_CHECK
#define ATH_CHECK
Definition:
AthCheckMacros.h:40
HepMC::UNDEFINED_ID
constexpr int UNDEFINED_ID
Definition:
MagicNumbers.h:55
postInclude.outputCollection
outputCollection
Definition:
postInclude.SortInput.py:27
HepMcParticleLink::eventIndex
index_type eventIndex() const
Return the event number of the referenced GenEvent.
Definition:
HepMcParticleLink.cxx:307
name
std::string name
Definition:
Control/AthContainers/Root/debug.cxx:195
MagicNumbers.h
SG::WriteHandle
Definition:
StoreGate/StoreGate/WriteHandle.h:76
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition:
CaloSwCorrections.py:242
HitsTruthRelinkBase
Definition:
HitsTruthRelinkBase.h:15
TRT_HitsTruthRelink::initialize
virtual StatusCode initialize() override
Definition:
TRT_HitsTruthRelink.cxx:15
Generated on Fri Jul 5 2024 21:31:37 for ATLAS Offline Software by
1.8.18