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
27using namespace MuonVal;
28using namespace MuonPRDTest;
29namespace {
31 using TruthLinkDecor_t = SG::ConstAccessor<TruthLink_t>;
32}
33namespace MuonValR4 {
36 ATH_CHECK(m_evtKey.initialize());
37 unsigned int evOpts = m_writePileUp ? EventInfoBranch::writePileUp : 0;
38 if (m_isMC) evOpts |= EventInfoBranch::isMC;
39 m_tree.addBranch(std::make_shared<EventInfoBranch>(m_tree, evOpts,m_evtKey.key()));
44 ATH_CHECK(detStore()->retrieve(m_detMgr));
45 ATH_CHECK(m_tree.init(this));
46 return StatusCode::SUCCESS;
47 }
49 if (!m_isMC) {
50 return StatusCode::SUCCESS;
51 }
52 if (m_writeTruthMuon) {
53 m_truthParts = std::make_shared<ParticleVariables>(m_tree, m_truthMuonCont, "truthMuon", msgLevel());
54 m_truthParts->addVariable<int>("truthOrigin");
55 m_truthParts->addVariable<int>("truthType");
56 m_tree.addBranch(m_truthParts);
57 }
58 if (m_writeTruthSeg) {
59 m_truthSegs = std::make_shared<SegmentVariables>(m_tree, m_truthSegCont, "truthSegment", msgLevel());
60 if (m_writeTruthMuon) {
62 m_tree, std::format("{}_truthLink", m_truthSegs->name()),
63 [this](const xAOD::MuonSegment& seg) -> unsigned short{
64 static const TruthLinkDecor_t acc{"truthParticleLink"};
65 if (!acc(seg).isValid()){
66 return -1;
67 }
68 return m_truthParts->push_back(*acc(seg));
69 }));
70 }
71 m_tree.addBranch(m_truthSegs);
72 }
73 return StatusCode::SUCCESS;
74 }
76 if (!m_writeSimHits || !m_isMC){
77 return StatusCode::SUCCESS;
78 }
79 auto addSimTester = [this](const std::string& key, const ActsTrk::DetectorType type){
80 auto testerBr = std::make_shared<SimHitTester>(m_tree, key, type, msgLevel());
81 if (m_truthSegs) {
82 m_tree.addBranch(std::make_shared<MuonVal::GenericAuxEleBranch<xAOD::MuonSegment, std::vector<unsigned short>>>(m_tree,
83 std::format("{:}_matched{:}Hits", m_truthSegs->name(), ActsTrk::to_string(type)),
84 [this, testerBr, type](const xAOD::MuonSegment&seg) -> std::vector<unsigned short>{
85 const auto hitSet = MuonR4::getMatchingSimHits(seg);
86 std::vector<const xAOD::MuonSimHit*> sortedHits{};
87 std::ranges::copy_if(hitSet, std::back_inserter(sortedHits), [this, type] (const xAOD::MuonSimHit* hit){
88 return m_detMgr->getReadoutElement(hit->identify())->detectorType() == type;
89 });
90 std::ranges::sort(sortedHits, [](const xAOD::MuonSimHit* a, const xAOD::MuonSimHit* b){
91 return a->identify() < b->identify();
92 });
93 std::vector<unsigned short> matchIds{};
94 std::ranges::transform(sortedHits, std::back_inserter(matchIds), [testerBr](const xAOD::MuonSimHit* hit){
95 return testerBr->push_back(*hit);
96 });
97 return matchIds;
98 }));
99 }
100 m_tree.addBranch(std::move(testerBr));
101 };
102 if (m_writeMdtSim) {
103 addSimTester(m_mdtSimHitKey, ActsTrk::DetectorType::Mdt);
104 }
105 if (m_writeRpcSim) {
106 addSimTester(m_rpcSimHitKey, ActsTrk::DetectorType::Rpc);
107 }
108 if (m_writeTgcSim) {
109 addSimTester(m_tgcSimHitKey, ActsTrk::DetectorType::Tgc);
110 }
111 if (m_writesTgcSim) {
112 addSimTester(m_sTgcSimHitKey, ActsTrk::DetectorType::sTgc);
113 }
114 if (m_writeMmSim) {
115 addSimTester(m_mmSimHitKey, ActsTrk::DetectorType::Mm);
116 }
117 return StatusCode::SUCCESS;
118 }
120 if (!m_writeDigits) {
121 return StatusCode::SUCCESS;
122 }
123 if (m_writeMdtDigits) {
124 m_tree.addBranch(std::make_shared<MdtDigitVariables>(m_tree, m_mdtDigitKey, msgLevel()));
125 }
126 if (m_writeRpcDigits) {
127 m_tree.addBranch(std::make_shared<RpcDigitVariables>(m_tree, m_rpcDigitKey, msgLevel()));
128 }
129 if (m_writeTgcDigits) {
130 m_tree.addBranch(std::make_shared<TgcDigitVariables>(m_tree, m_tgcDigitKey, msgLevel()));
131 }
132 if (m_writeMmDigits) {
133 m_tree.addBranch(std::make_shared<MMDigitVariables>(m_tree, m_mmDigitKey, msgLevel()));
134 }
135 if (m_writesTgcDigits) {
136 m_tree.addBranch(std::make_shared<sTgcDigitVariables>(m_tree, m_sTgcDigitKey, msgLevel()));
137 }
138 return StatusCode::SUCCESS;
139 }
141 if (!m_writePrds) {
142 return StatusCode::SUCCESS;
143 }
144 if (m_writeMdtPrds) {
145 m_tree.addBranch(std::make_shared<MdtDriftCircleVariables>(m_tree, m_mdtPrdKey, msgLevel()));
146 m_tree.addBranch(std::make_shared<MdtTwinDriftCircleVariables>(m_tree, m_mdtTwinPrdKey, msgLevel()));
147 }
148 if (m_writeRpcPrds) {
149 m_tree.addBranch(std::make_shared<RpcMeasurementVariables>(m_tree, m_rpcPrdKey, msgLevel()));
150 }
151 if (m_writeTgcPrds) {
152 m_tree.addBranch(std::make_shared<TgcStripVariables>(m_tree, m_tgcPrdKey, msgLevel()));
153 }
154 if (m_writeMmPrds) {
155 m_tree.addBranch(std::make_shared<MmClusterVariables>(m_tree, m_mmPrdKey, msgLevel()));
156 }
157 return StatusCode::SUCCESS;
158 }
160 ATH_CHECK(m_tree.write());
161 return StatusCode::SUCCESS;
162 }
164 const EventContext& ctx{Gaudi::Hive::currentContext()};
165 return m_tree.fill(ctx) ? StatusCode::SUCCESS : StatusCode::FAILURE;
166 }
167}
#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
StatusCode setupDigits()
Toggle whether the digit collections shall be tested.
Gaudi::Property< bool > m_writeMmPrds
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< std::string > m_tgcPrdKey
Gaudi::Property< std::string > m_rpcPrdKey
Gaudi::Property< bool > m_writePrds
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< 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: