ATLAS Offline Software
Loading...
Searching...
No Matches
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
7
8
9TRT_HitsTruthRelink::TRT_HitsTruthRelink(const std::string &name, ISvcLocator *pSvcLocator)
10 : HitsTruthRelinkBase(name, pSvcLocator)
11{
12}
13
14
16{
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
28StatusCode TRT_HitsTruthRelink::execute(const EventContext &ctx) const
29{
30 ATH_MSG_DEBUG("Doing truth relinking");
31
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
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
72HepMcParticleLink 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
84 if (currentId == referenceId && !(m_keepElectronsLinkedToTRTHits && std::abs(pdgId) == 11)) {
86 }
87 return newLink;
88}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
@ EBC_PU_SUPPRESSED
virtual StatusCode initialize() override
StatusCode getReferenceId(const EventContext &ctx, int *id) const
HitsTruthRelinkBase(const std::string &name, ISvcLocator *pSvcLocator)
virtual bool isValid() override final
Can the handle be successfully dereferenced?
std::string store() const
Return the name of the store holding the object we are proxying.
const std::string & name() const
Return the StoreGate ID for the referenced object.
int barcode(const T *p)
Definition Barcode.h:16
constexpr int UNDEFINED_ID