ATLAS Offline Software
Loading...
Searching...
No Matches
MuonHitTesterAlg.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 "MuonHitTesterAlg.h"
5
8
16
19
24
25
27
31using namespace MuonVal;
32using namespace MuonPRDTest;
33namespace {
35 using TruthLinkDecor_t = SG::ConstAccessor<TruthLink_t>;
36}
37namespace MuonValR4 {
40 ATH_CHECK(m_evtKey.initialize());
41 unsigned int evOpts = m_writePileUp ? EventInfoBranch::writePileUp : 0;
42 if (m_isMC) evOpts |= EventInfoBranch::isMC;
43 m_tree.addBranch(std::make_shared<EventInfoBranch>(m_tree, evOpts,m_evtKey.key()));
49 ATH_CHECK(detStore()->retrieve(m_detMgr));
50 ATH_CHECK(m_tree.init(this));
51 return StatusCode::SUCCESS;
52 }
54 if (!m_isMC) {
55 return StatusCode::SUCCESS;
56 }
57 if (m_writeTruthMuon) {
58 m_truthParts = std::make_shared<ParticleVariables>(m_tree, m_truthMuonCont, "truthMuon", msgLevel());
59 m_truthParts->addVariable<int>("truthOrigin");
60 m_truthParts->addVariable<int>("truthType");
61 m_tree.addBranch(m_truthParts);
62 }
63 if (m_writeTruthSeg) {
64 m_truthSegs = std::make_shared<SegmentVariables>(m_tree, m_truthSegCont, "truthSegment", msgLevel());
65 if (m_writeTruthMuon) {
67 m_tree, std::format("{}_truthLink", m_truthSegs->name()),
68 [this](const xAOD::MuonSegment& seg) -> unsigned short{
69 static const TruthLinkDecor_t acc{"truthParticleLink"};
70 if (!acc(seg).isValid()){
71 return -1;
72 }
73 return m_truthParts->push_back(*acc(seg));
74 }));
75 }
76 m_tree.addBranch(m_truthSegs);
77 }
78 return StatusCode::SUCCESS;
79 }
81 if (!m_writeSimHits || !m_isMC){
82 return StatusCode::SUCCESS;
83 }
84 auto addSimTester = [this](const std::string& key, const ActsTrk::DetectorType type){
85 auto testerBr = std::make_shared<SimHitTester>(m_tree, key, type, msgLevel());
86 if (m_truthSegs) {
87 m_tree.addBranch(std::make_shared<MuonVal::GenericAuxEleBranch<xAOD::MuonSegment, std::vector<unsigned short>>>(m_tree,
88 std::format("{:}_matched{:}Hits", m_truthSegs->name(), type),
89 [this, testerBr, type](const xAOD::MuonSegment&seg) -> std::vector<unsigned short> {
90 std::vector<const xAOD::MuonSimHit*> sortedHits{MuonR4::getMatchingSimHits(seg)};
91 auto[begin, end] = std::ranges::remove_if(sortedHits, [this, type] (const xAOD::MuonSimHit* hit){
92 return m_detMgr->getReadoutElement(hit->identify())->detectorType() != type;
93 });
94 sortedHits.erase(begin, end);
95 std::vector<unsigned short> matchIds{};
96 std::ranges::transform(sortedHits, std::back_inserter(matchIds), [testerBr](const xAOD::MuonSimHit* hit){
97 return testerBr->push_back(*hit);
98 });
99 return matchIds;
100 }));
101 }
102 m_tree.addBranch(std::move(testerBr));
103 };
104 if (m_writeMdtSim) {
105 addSimTester(m_mdtSimHitKey, ActsTrk::DetectorType::Mdt);
106 }
107 if (m_writeRpcSim) {
108 addSimTester(m_rpcSimHitKey, ActsTrk::DetectorType::Rpc);
109 }
110 if (m_writeTgcSim) {
111 addSimTester(m_tgcSimHitKey, ActsTrk::DetectorType::Tgc);
112 }
113 if (m_writesTgcSim) {
114 addSimTester(m_sTgcSimHitKey, ActsTrk::DetectorType::sTgc);
115 }
116 if (m_writeMmSim) {
117 addSimTester(m_mmSimHitKey, ActsTrk::DetectorType::Mm);
118 }
119 return StatusCode::SUCCESS;
120 }
122 if (!m_writeDigits) {
123 return StatusCode::SUCCESS;
124 }
125 if (m_writeMdtDigits) {
126 m_tree.addBranch(std::make_shared<MdtDigitVariables>(m_tree, m_mdtDigitKey, msgLevel()));
127 }
128 if (m_writeRpcDigits) {
129 m_tree.addBranch(std::make_shared<RpcDigitVariables>(m_tree, m_rpcDigitKey, msgLevel()));
130 }
131 if (m_writeTgcDigits) {
132 m_tree.addBranch(std::make_shared<TgcDigitVariables>(m_tree, m_tgcDigitKey, msgLevel()));
133 }
134 if (m_writeMmDigits) {
135 m_tree.addBranch(std::make_shared<MMDigitVariables>(m_tree, m_mmDigitKey, msgLevel()));
136 }
137 if (m_writesTgcDigits) {
138 m_tree.addBranch(std::make_shared<sTgcDigitVariables>(m_tree, m_sTgcDigitKey, msgLevel()));
139 }
140 return StatusCode::SUCCESS;
141 }
143 if (!m_writePrds) {
144 return StatusCode::SUCCESS;
145 }
146 if (m_writeMdtPrds) {
147 m_tree.addBranch(std::make_shared<MdtDriftCircleVariables>(m_tree, m_mdtPrdKey, msgLevel()));
148 m_tree.addBranch(std::make_shared<MdtTwinDriftCircleVariables>(m_tree, m_mdtTwinPrdKey, msgLevel()));
149 }
150 if (m_writeRpcPrds) {
151 m_tree.addBranch(std::make_shared<RpcMeasurementVariables>(m_tree, m_rpcPrdKey, msgLevel()));
152 }
153 if (m_writeTgcPrds) {
154 m_tree.addBranch(std::make_shared<TgcStripVariables>(m_tree, m_tgcPrdKey, msgLevel()));
155 }
156 if (m_writeMmPrds) {
157 m_tree.addBranch(std::make_shared<MmClusterVariables>(m_tree, m_mmPrdKey, msgLevel()));
158 }
159 if (m_writeStgcPrds) {
161 }
162 return StatusCode::SUCCESS;
163 }
165 if (!m_writeSpacePoints) {
166 return StatusCode::SUCCESS;
167 }
168 if (m_writeMuonSp) {
169 m_tree.addBranch(std::make_shared<SpacePointTesterModule>(m_tree, m_generalSpKey, msgLevel(), "Muon"));
170 }
171 if (m_writeNswSp) {
172 m_tree.addBranch(std::make_shared<SpacePointTesterModule>(m_tree, m_nswSpKey, msgLevel(), "NSW"));
173 }
174 return StatusCode::SUCCESS;
175 }
177 ATH_CHECK(m_tree.write());
178 return StatusCode::SUCCESS;
179 }
180 StatusCode MuonHitTesterAlg::execute(const EventContext& ctx) {
181 return m_tree.fill(ctx) ? StatusCode::SUCCESS : StatusCode::FAILURE;
182 }
183}
#define ATH_CHECK
Evaluate an expression and check for errors.
bool hit(const Container &ids, int pdgId)
if(pathvar)
ElementLink< xAOD::TruthParticleContainer > TruthLink_t
const ServiceHandle< StoreGateSvc > & detStore() const
Gaudi::Property< bool > m_writeSpacePoints
Gaudi::Property< bool > m_writeStgcStripNumbers
StatusCode setupDigits()
Toggle whether the digit collections shall be tested.
Gaudi::Property< bool > m_writeMmPrds
Gaudi::Property< bool > m_writeNswSp
Gaudi::Property< std::string > m_stgcStripPrdKey
Gaudi::Property< bool > m_writeStgcStripCharges
Gaudi::Property< std::string > m_tgcDigitKey
Gaudi::Property< std::string > m_mmPrdKey
Gaudi::Property< bool > m_writeStgcStripTimes
StatusCode initialize() override final
Gaudi::Property< std::string > m_stgcPadPrdKey
StatusCode setupSimHits()
Toggle whether the simHit collection of each sub detector shall be written to disk.
Gaudi::Property< bool > m_writeTgcPrds
Gaudi::Property< bool > m_writeMdtDigits
Gaudi::Property< std::string > m_mdtTwinPrdKey
Gaudi::Property< bool > m_writeMuonSp
Gaudi::Property< std::string > m_nswSpKey
Gaudi::Property< std::string > m_tgcPrdKey
Gaudi::Property< std::string > m_rpcPrdKey
Gaudi::Property< bool > m_writePrds
StatusCode setupSpacePoints()
Toggle whether the spacepoint collections shall be tested.
StatusCode execute(const EventContext &ctx) override final
Execute method.
Gaudi::Property< bool > m_writeMmDigits
Gaudi::Property< std::string > m_truthSegCont
Name of the truth segment container.
Gaudi::Property< bool > m_writeDigits
Gaudi::Property< std::string > m_truthMuonCont
Name of the truth particle container.
Gaudi::Property< bool > m_writeStgcPrds
Gaudi::Property< bool > m_isMC
Gaudi::Property< bool > m_writeSimHits
StatusCode finalize() override final
Gaudi::Property< bool > m_writeRpcDigits
Gaudi::Property< std::string > m_stgcWirePrdKey
const MuonGMR4::MuonDetectorManager * m_detMgr
StatusCode setupPrds()
Toggle whether the uncalibrated measurement collections shall be tested.
Gaudi::Property< bool > m_writeTruthSeg
Flag toggling whether the truth segment container shall be written.
std::shared_ptr< MuonPRDTest::ParticleVariables > m_truthParts
Gaudi::Property< std::string > m_sTgcDigitKey
std::shared_ptr< MuonPRDTest::SegmentVariables > m_truthSegs
Gaudi::Property< bool > m_writeTgcDigits
Gaudi::Property< std::string > m_mdtPrdKey
Prd collection names.
Gaudi::Property< std::string > m_mdtDigitKey
Container keys of the particular digit collections.
MuonVal::MuonTesterTree m_tree
Gaudi::Property< bool > m_writeMdtPrds
Gaudi::Property< std::string > m_mmDigitKey
Gaudi::Property< std::string > m_generalSpKey
Prd collection names.
Gaudi::Property< bool > m_writesTgcDigits
Gaudi::Property< bool > m_writePileUp
Gaudi::Property< bool > m_writeRpcPrds
Gaudi::Property< bool > m_writeTruthMuon
Flag toggling whether the truth particle container shall be written.
Gaudi::Property< std::string > m_rpcDigitKey
SG::ReadHandleKey< xAOD::EventInfo > m_evtKey
@ writePileUp
Write pile-up information.
@ isMC
Flag determining whether the branch is simulation.
Helper class to provide constant type-safe access to aux data.
DetectorType
Simple enum to Identify the Type of the ACTS sub detector.
@ Mm
Maybe not needed in the migration.
@ Tgc
Resitive Plate Chambers.
@ sTgc
Micromegas (NSW).
@ Rpc
Monitored Drift Tubes.
@ Mdt
MuonSpectrometer.
Lightweight algorithm to read xAOD MDT sim hits and (fast-digitised) drift circles from SG and fill a...
Class to store array like branches into the n-tuples.
Definition HitValAlg.cxx:19
MuonSimHit_v1 MuonSimHit
Defined the version of the MuonSimHit.
Definition MuonSimHit.h:12
MuonSegment_v1 MuonSegment
Reference the current persistent version: