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
23
25
29using namespace MuonVal;
30using namespace MuonPRDTest;
31namespace {
33 using TruthLinkDecor_t = SG::ConstAccessor<TruthLink_t>;
34}
35namespace MuonValR4 {
38 ATH_CHECK(m_evtKey.initialize());
39 unsigned int evOpts = m_writePileUp ? EventInfoBranch::writePileUp : 0;
40 if (m_isMC) evOpts |= EventInfoBranch::isMC;
41 m_tree.addBranch(std::make_shared<EventInfoBranch>(m_tree, evOpts,m_evtKey.key()));
47 ATH_CHECK(detStore()->retrieve(m_detMgr));
48 ATH_CHECK(m_tree.init(this));
49 return StatusCode::SUCCESS;
50 }
52 if (!m_isMC) {
53 return StatusCode::SUCCESS;
54 }
55 if (m_writeTruthMuon) {
56 m_truthParts = std::make_shared<ParticleVariables>(m_tree, m_truthMuonCont, "truthMuon", msgLevel());
57 m_truthParts->addVariable<int>("truthOrigin");
58 m_truthParts->addVariable<int>("truthType");
59 m_tree.addBranch(m_truthParts);
60 }
61 if (m_writeTruthSeg) {
62 m_truthSegs = std::make_shared<SegmentVariables>(m_tree, m_truthSegCont, "truthSegment", msgLevel());
63 if (m_writeTruthMuon) {
65 m_tree, std::format("{}_truthLink", m_truthSegs->name()),
66 [this](const xAOD::MuonSegment& seg) -> unsigned short{
67 static const TruthLinkDecor_t acc{"truthParticleLink"};
68 if (!acc(seg).isValid()){
69 return -1;
70 }
71 return m_truthParts->push_back(*acc(seg));
72 }));
73 }
74 m_tree.addBranch(m_truthSegs);
75 }
76 return StatusCode::SUCCESS;
77 }
79 if (!m_writeSimHits || !m_isMC){
80 return StatusCode::SUCCESS;
81 }
82 auto addSimTester = [this](const std::string& key, const ActsTrk::DetectorType type){
83 auto testerBr = std::make_shared<SimHitTester>(m_tree, key, type, msgLevel());
84 if (m_truthSegs) {
85 m_tree.addBranch(std::make_shared<MuonVal::GenericAuxEleBranch<xAOD::MuonSegment, std::vector<unsigned short>>>(m_tree,
86 std::format("{:}_matched{:}Hits", m_truthSegs->name(), ActsTrk::to_string(type)),
87 [this, testerBr, type](const xAOD::MuonSegment&seg) -> std::vector<unsigned short>{
88 const auto hitSet = MuonR4::getMatchingSimHits(seg);
89 std::vector<const xAOD::MuonSimHit*> sortedHits{};
90 std::ranges::copy_if(hitSet, std::back_inserter(sortedHits), [this, type] (const xAOD::MuonSimHit* hit){
91 return m_detMgr->getReadoutElement(hit->identify())->detectorType() == type;
92 });
93 std::ranges::sort(sortedHits, [](const xAOD::MuonSimHit* a, const xAOD::MuonSimHit* b){
94 return a->identify() < b->identify();
95 });
96 std::vector<unsigned short> matchIds{};
97 std::ranges::transform(sortedHits, std::back_inserter(matchIds), [testerBr](const xAOD::MuonSimHit* hit){
98 return testerBr->push_back(*hit);
99 });
100 return matchIds;
101 }));
102 }
103 m_tree.addBranch(std::move(testerBr));
104 };
105 if (m_writeMdtSim) {
106 addSimTester(m_mdtSimHitKey, ActsTrk::DetectorType::Mdt);
107 }
108 if (m_writeRpcSim) {
109 addSimTester(m_rpcSimHitKey, ActsTrk::DetectorType::Rpc);
110 }
111 if (m_writeTgcSim) {
112 addSimTester(m_tgcSimHitKey, ActsTrk::DetectorType::Tgc);
113 }
114 if (m_writesTgcSim) {
115 addSimTester(m_sTgcSimHitKey, ActsTrk::DetectorType::sTgc);
116 }
117 if (m_writeMmSim) {
118 addSimTester(m_mmSimHitKey, ActsTrk::DetectorType::Mm);
119 }
120 return StatusCode::SUCCESS;
121 }
123 if (!m_writeDigits) {
124 return StatusCode::SUCCESS;
125 }
126 if (m_writeMdtDigits) {
127 m_tree.addBranch(std::make_shared<MdtDigitVariables>(m_tree, m_mdtDigitKey, msgLevel()));
128 }
129 if (m_writeRpcDigits) {
130 m_tree.addBranch(std::make_shared<RpcDigitVariables>(m_tree, m_rpcDigitKey, msgLevel()));
131 }
132 if (m_writeTgcDigits) {
133 m_tree.addBranch(std::make_shared<TgcDigitVariables>(m_tree, m_tgcDigitKey, msgLevel()));
134 }
135 if (m_writeMmDigits) {
136 m_tree.addBranch(std::make_shared<MMDigitVariables>(m_tree, m_mmDigitKey, msgLevel()));
137 }
138 if (m_writesTgcDigits) {
139 m_tree.addBranch(std::make_shared<sTgcDigitVariables>(m_tree, m_sTgcDigitKey, msgLevel()));
140 }
141 return StatusCode::SUCCESS;
142 }
144 if (!m_writePrds) {
145 return StatusCode::SUCCESS;
146 }
147 if (m_writeMdtPrds) {
148 m_tree.addBranch(std::make_shared<MdtDriftCircleVariables>(m_tree, m_mdtPrdKey, msgLevel()));
149 m_tree.addBranch(std::make_shared<MdtTwinDriftCircleVariables>(m_tree, m_mdtTwinPrdKey, msgLevel()));
150 }
151 if (m_writeRpcPrds) {
152 m_tree.addBranch(std::make_shared<RpcMeasurementVariables>(m_tree, m_rpcPrdKey, msgLevel()));
153 }
154 if (m_writeTgcPrds) {
155 m_tree.addBranch(std::make_shared<TgcStripVariables>(m_tree, m_tgcPrdKey, msgLevel()));
156 }
157 if (m_writeMmPrds) {
158 m_tree.addBranch(std::make_shared<MmClusterVariables>(m_tree, m_mmPrdKey, msgLevel()));
159 }
160 return StatusCode::SUCCESS;
161 }
163 if (!m_writeSpacePoints) {
164 return StatusCode::SUCCESS;
165 }
166 if (m_writeMuonSp) {
167 m_tree.addBranch(std::make_shared<SpacePointTesterModule>(m_tree, m_generalSpKey, msgLevel(), "Muon"));
168 }
169 if (m_writeNswSp) {
170 m_tree.addBranch(std::make_shared<SpacePointTesterModule>(m_tree, m_nswSpKey, msgLevel(), "NSW"));
171 }
172 return StatusCode::SUCCESS;
173 }
175 ATH_CHECK(m_tree.write());
176 return StatusCode::SUCCESS;
177 }
179 const EventContext& ctx{Gaudi::Hive::currentContext()};
180 return m_tree.fill(ctx) ? StatusCode::SUCCESS : StatusCode::FAILURE;
181 }
182}
#define ATH_CHECK
Evaluate an expression and check for errors.
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition AtlasPID.h:878
static Double_t a
if(febId1==febId2)
ElementLink< xAOD::TruthParticleContainer > TruthLink_t
const ServiceHandle< StoreGateSvc > & detStore() const
Gaudi::Property< bool > m_writeSpacePoints
StatusCode setupDigits()
Toggle whether the digit collections shall be tested.
Gaudi::Property< bool > m_writeMmPrds
Gaudi::Property< bool > m_writeNswSp
StatusCode execute() override final
Gaudi::Property< std::string > m_tgcDigitKey
Gaudi::Property< std::string > m_mmPrdKey
StatusCode initialize() override final
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.
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_isMC
Gaudi::Property< bool > m_writeSimHits
StatusCode finalize() override final
Gaudi::Property< bool > m_writeRpcDigits
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.
std::string to_string(const DetectorType &type)
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: