ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
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
HepMcParticleLink
newLink(currentId, oldLink.
eventIndex
(),
HepMcParticleLink::IS_EVENTNUM
,
HepMcParticleLink::IS_ID
, ctx);
84
if
(currentId == referenceId && !(
m_keepElectronsLinkedToTRTHits
&& std::abs(pdgId) == 11)) {
85
newLink.
setTruthSuppressionType
(
EBC_PU_SUPPRESSED
);
86
}
87
return
newLink;
88
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition
AthMsgStreamMacros.h:28
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
hit
bool hit(const Container &ids, int pdgId)
Definition
JetIRCSafeLabelTool.cxx:64
MagicNumbers.h
EBC_PU_SUPPRESSED
@ EBC_PU_SUPPRESSED
Definition
MagicNumbers.h:31
TRT_HitsTruthRelink.h
HepMcParticleLink
a link optimized in size for a GenParticle in a McEventCollection
Definition
HepMcParticleLink.h:72
HepMcParticleLink::IS_EVENTNUM
@ IS_EVENTNUM
Definition
HepMcParticleLink.h:79
HepMcParticleLink::id
int id() const
Return the id of the target particle.
Definition
HepMcParticleLink.cxx:283
HepMcParticleLink::IS_ID
@ IS_ID
Definition
HepMcParticleLink.h:84
HepMcParticleLink::eventIndex
index_type eventIndex() const
Return the event number of the referenced GenEvent.
Definition
HepMcParticleLink.cxx:337
HepMcParticleLink::setTruthSuppressionType
void setTruthSuppressionType(EBC_SUPPRESSED_TRUTH truthSupp)
Return whether the truth particle has been suppressed.
HitsTruthRelinkBase::initialize
virtual StatusCode initialize() override
Definition
HitsTruthRelinkBase.cxx:14
HitsTruthRelinkBase::getReferenceId
StatusCode getReferenceId(const EventContext &ctx, int *id) const
Definition
HitsTruthRelinkBase.cxx:53
HitsTruthRelinkBase::HitsTruthRelinkBase
HitsTruthRelinkBase(const std::string &name, ISvcLocator *pSvcLocator)
Definition
HitsTruthRelinkBase.cxx:8
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
SG::VarHandleBase::store
std::string store() const
Return the name of the store holding the object we are proxying.
Definition
StoreGate/src/VarHandleBase.cxx:382
SG::VarHandleBase::name
const std::string & name() const
Return the StoreGate ID for the referenced object.
Definition
AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:75
SG::WriteHandle
Definition
StoreGate/StoreGate/WriteHandle.h:73
TRTUncompressedHit
Definition
TRTUncompressedHit.h:11
TRT_HitsTruthRelink::m_keepElectronsLinkedToTRTHits
Gaudi::Property< bool > m_keepElectronsLinkedToTRTHits
Definition
TRT_HitsTruthRelink.h:26
TRT_HitsTruthRelink::TRT_HitsTruthRelink
TRT_HitsTruthRelink(const std::string &name, ISvcLocator *pSvcLocator)
Definition
TRT_HitsTruthRelink.cxx:9
TRT_HitsTruthRelink::m_inputHitsKey
SG::ReadHandleKey< TRTUncompressedHitCollection > m_inputHitsKey
Definition
TRT_HitsTruthRelink.h:23
TRT_HitsTruthRelink::m_outputHitsKey
SG::WriteHandleKey< TRTUncompressedHitCollection > m_outputHitsKey
Definition
TRT_HitsTruthRelink.h:24
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
TRT_HitsTruthRelink::initialize
virtual StatusCode initialize() override
Definition
TRT_HitsTruthRelink.cxx:15
TRT_HitsTruthRelink::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition
TRT_HitsTruthRelink.cxx:28
HepMC::barcode
int barcode(const T *p)
Definition
Barcode.h:15
HepMC::UNDEFINED_ID
constexpr int UNDEFINED_ID
Definition
MagicNumbers.h:57
Generated on
for ATLAS Offline Software by
1.17.0