Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
8 #include "StoreGate/ReadHandle.h"
12 
13 namespace 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};
62  if (!m_includePileUpTruth && HepMC::ignoreTruthLink(primHit->genParticleLink(), m_vetoPileUpTruthLinks)){
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};
71  if (!m_includePileUpTruth && HepMC::ignoreTruthLink(mergeMe->genParticleLink(), m_vetoPileUpTruthLinks)){
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 }
xAOD::MuonSimHit_v1
Definition: MuonSimHit_v1.h:18
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
TRTCalib_Extractor.hits
hits
Definition: TRTCalib_Extractor.py:35
MuonR4::TruthOverlay::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: TruthOverlay.h:25
MuonR4::TruthOverlay::m_mergeTime
Gaudi::Property< double > m_mergeTime
Define a detector merge time.
Definition: TruthOverlay.h:32
MuonR4::TruthOverlay::execute
StatusCode execute(const EventContext &ctx) const override final
Definition: TruthOverlay.cxx:26
MuonR4::TruthOverlay::m_bkgKey
SG::ReadHandleKey< xAOD::MuonSimHitContainer > m_bkgKey
Definition: TruthOverlay.h:22
MuonSimHitAuxContainer.h
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::ReadHandleKey
Property holding a SG store/key/clid from which a ReadHandle is made.
Definition: StoreGate/StoreGate/ReadHandleKey.h:39
HepMC::ignoreTruthLink
bool ignoreTruthLink(const T &p, bool vetoPileUp)
Helper function for SDO creation in PileUpTools.
Definition: MagicNumbers.h:345
TruthOverlay.h
MuonR4::TruthOverlay::m_deadTime
Gaudi::Property< double > m_deadTime
Define a detector dead time.
Definition: TruthOverlay.h:29
xAOD::ChamberViewer
Definition: ChamberViewer.h:65
WriteHandle.h
Handle class for recording to StoreGate.
xAOD::MuonSimHit_v1::genParticleLink
const HepMcParticleLink & genParticleLink() const
Returns the link to the HepMC particle producing this hit.
Definition: xAODMuonSimHit_V1.cxx:68
SG::get
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
Definition: ReadCondHandle.h:287
MuonR4::TruthOverlay::m_includePileUpTruth
Gaudi::Property< bool > m_includePileUpTruth
Definition: TruthOverlay.h:34
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
MuonR4::TruthOverlay::initialize
StatusCode initialize() override final
Definition: TruthOverlay.cxx:15
MuonR4::TruthOverlay::m_sigKey
SG::ReadHandleKey< xAOD::MuonSimHitContainer > m_sigKey
Definition: TruthOverlay.h:21
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
MuonR4::TruthOverlay::m_vetoPileUpTruthLinks
Gaudi::Property< int > m_vetoPileUpTruthLinks
Definition: TruthOverlay.h:35
xAOD::MuonSimHit_v1::setEnergyDeposit
void setEnergyDeposit(const float deposit)
Sets the energy deposited by the traversing particle inside the gas volume.
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
ChamberViewer.h
MuonR4
This header ties the generic definitions in this package.
Definition: HoughEventData.h:16
MuonR4::TruthOverlay::m_writeKey
SG::WriteHandleKey< xAOD::MuonSimHitContainer > m_writeKey
Definition: TruthOverlay.h:23
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
a
TList * a
Definition: liststreamerinfos.cxx:10
IdentifierByDetElSorter.h
Muon::IdentifierByDetElSorter
Definition: IdentifierByDetElSorter.h:17
ReadHandle.h
Handle class for reading from StoreGate.
HepMCHelpers.h
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
isMuon
bool isMuon(const T &p)
Definition: AtlasPID.h:194