ATLAS Offline Software
Loading...
Searching...
No Matches
TruthOverlay.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 "TruthOverlay.h"
5
12
13namespace MuonR4{
14
16 ATH_CHECK(m_sigKey.initialize());
17 ATH_CHECK(m_bkgKey.initialize());
18 ATH_CHECK(m_writeKey.initialize());
19 ATH_CHECK(m_idHelperSvc.retrieve());
20 if (m_deadTime < m_mergeTime) {
21 ATH_MSG_FATAL("The "<<m_deadTime<<" should be greater than "<<m_mergeTime);
22 return StatusCode::FAILURE;
23 }
24 return StatusCode::SUCCESS;
25 }
26 StatusCode TruthOverlay::execute(const EventContext& ctx) const {
27
28
30 std::map<Identifier, std::vector<const xAOD::MuonSimHit*>,
32
34 auto fillMap = [&overlayed, &ctx, this] (const SG::ReadHandleKey<xAOD::MuonSimHitContainer>& key) -> StatusCode{
35 const xAOD::MuonSimHitContainer* hits{nullptr};
36 ATH_CHECK(SG::get(hits, key, ctx));
37 xAOD::ChamberViewer viewer{*hits, m_idHelperSvc.get()};
38 do {
39 for (const xAOD::MuonSimHit* hit : viewer) {
40 overlayed[hit->identify()].push_back(hit);
41 }
42 } while (viewer.next());
43
44 return StatusCode::SUCCESS;
45 };
46 ATH_CHECK(fillMap(m_sigKey));
47 ATH_CHECK(fillMap(m_bkgKey));
48
50 SG::WriteHandle writeHandle {m_writeKey, ctx};
51 ATH_CHECK(writeHandle.record(std::make_unique<xAOD::MuonSimHitContainer>(),
52 std::make_unique<xAOD::MuonSimHitAuxContainer>()));
53
54 for (auto& [mergeId, hits] : overlayed) {
55 ATH_MSG_VERBOSE("Perform truth overlay for "<<m_idHelperSvc->toString(mergeId));
56 std::ranges::sort(hits, [](const xAOD::MuonSimHit* a, const xAOD::MuonSimHit* b){
57 return a->globalTime() < b->globalTime();
58 });
59
60 for (auto itr = hits.begin(); itr != hits.end(); ++itr){
61 const xAOD::MuonSimHit* primHit{*itr};
63 ATH_MSG_VERBOSE("Reject background hit");
64 continue;
65 }
66 xAOD::MuonSimHit* merged = writeHandle->push_back(std::make_unique<xAOD::MuonSimHit>());
67 (*merged) = (*primHit);
68 auto mergeItr = itr +1;
69 for ( ; mergeItr !=hits.end(); ++mergeItr) {
70 const xAOD::MuonSimHit* mergeMe{*itr};
72 ATH_MSG_VERBOSE("Don't merge with a background hit.");
73 continue;
74 }
75 if(mergeMe->globalTime() - primHit->globalTime() < m_mergeTime) {
77 if (MC::isMuon(mergeMe) || (mergeMe->genParticleLink() && !merged->genParticleLink())){
78 (*merged) = (*mergeMe);
79 }
80 merged->setEnergyDeposit(mergeMe->energyDeposit() + primHit->energyDeposit());
81 } else if (mergeMe->globalTime() - primHit->globalTime() < m_deadTime) {
82 continue;
83 } else {
84 break;
85 }
86 }
87 itr = mergeItr - 1;
88 }
89 }
90 return StatusCode::SUCCESS;
91 }
92}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_VERBOSE(x)
ATLAS-specific HepMC functions.
static Double_t a
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Gaudi::Property< double > m_deadTime
Define a detector dead time.
SG::WriteHandleKey< xAOD::MuonSimHitContainer > m_writeKey
Gaudi::Property< bool > m_includePileUpTruth
SG::ReadHandleKey< xAOD::MuonSimHitContainer > m_sigKey
StatusCode execute(const EventContext &ctx) const override final
Gaudi::Property< int > m_vetoPileUpTruthLinks
SG::ReadHandleKey< xAOD::MuonSimHitContainer > m_bkgKey
StatusCode initialize() override final
Gaudi::Property< double > m_mergeTime
Define a detector merge time.
Property holding a SG store/key/clid from which a ReadHandle is made.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
bool next() noexcept
Loads the hits from the next chamber.
void setEnergyDeposit(const float deposit)
Sets the energy deposited by the traversing particle inside the gas volume.
float energyDeposit() const
Returns the energy deposited by the traversing particle inside the gas volume.
const HepMcParticleLink & genParticleLink() const
Returns the link to the HepMC particle producing this hit.
float globalTime() const
Returns the time ellapsed since the collision of the traversing particle.
bool ignoreTruthLink(const T &p, bool vetoPileUp)
Helper function for SDO creation in PileUpTools.
bool isMuon(const T &p)
This header ties the generic definitions in this package.
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
MuonSimHit_v1 MuonSimHit
Defined the version of the MuonSimHit.
Definition MuonSimHit.h:12
MuonSimHitContainer_v1 MuonSimHitContainer
Define the version of the pixel cluster container.