Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
27 using namespace MuonVal;
28 using namespace MuonPRDTest;
29 namespace {
31  using TruthLinkDecor_t = SG::ConstAccessor<TruthLink_t>;
32 }
33 namespace MuonValR4 {
34  MuonHitTesterAlg::~MuonHitTesterAlg() = default;
36  int evOpts{0};
37  if (m_isMC) evOpts |= EventInfoBranch::isMC;
38  ATH_CHECK(m_evtKey.initialize());
39  m_tree.addBranch(std::make_shared<EventInfoBranch>(m_tree, evOpts,m_evtKey.key()));
40  ATH_CHECK(setupTruth());
41  ATH_CHECK(setupSimHits());
42  ATH_CHECK(setupDigits());
43  ATH_CHECK(setupPrds());
44  ATH_CHECK(detStore()->retrieve(m_detMgr));
45  ATH_CHECK(m_tree.init(this));
46  return StatusCode::SUCCESS;
47  }
48  StatusCode MuonHitTesterAlg::setupTruth() {
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  }
75  StatusCode MuonHitTesterAlg::setupSimHits() {
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  }
119  StatusCode MuonHitTesterAlg::setupDigits() {
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  }
140  StatusCode MuonHitTesterAlg::setupPrds() {
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 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
TgcStripVariables.h
MuonSimHitHelpers.h
xAOD::MuonSimHit_v1
Definition: MuonSimHit_v1.h:18
python.tests.PyTestsLib.finalize
def finalize(self)
_info( "content of StoreGate..." ) self.sg.dump()
Definition: PyTestsLib.py:50
TGCDigitVariables.h
vtune_athena.format
format
Definition: vtune_athena.py:14
RPCDigitVariables.h
ActsTrk::DetectorType
DetectorType
Simple enum to Identify the Type of the ACTS sub detector.
Definition: GeometryDefs.h:17
make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: SkimmingToolEXOT5.cxx:23
MuonVal::EventInfoBranch::isMC
@ isMC
Flag determining whether the branch is simulation.
Definition: EventInfoBranch.h:20
initialize
void initialize()
Definition: run_EoverP.cxx:894
TruthParticleContainer.h
ParticleVariables.h
ActsTrk::DetectorType::Tgc
@ Tgc
Resitive Plate Chambers.
xAOD::MuonSegment_v1
Class describing a MuonSegment.
Definition: MuonSegment_v1.h:33
EventInfoBranch.h
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
isValid
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition: AtlasPID.h:812
ActsTrk::DetectorType::sTgc
@ sTgc
Micromegas (NSW)
MuonVal::GenericAuxEleBranch
Definition: GenericDecorBranch.h:11
xAODTruthHelpers.h
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
LArG4FSStartPointFilterLegacy.execute
execute
Definition: LArG4FSStartPointFilterLegacy.py:20
MDTDigitVariables.h
ActsTrk::DetectorType::Mm
@ Mm
Maybe not needed in the migration.
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
AnalysisUtils::copy_if
Out copy_if(In first, const In &last, Out res, const Pred &p)
Definition: IFilterUtils.h:30
AthenaPoolTestRead.acc
acc
Definition: AthenaPoolTestRead.py:16
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
sTGCDigitVariables.h
MmClusterVariables.h
MdtDriftCircleVariables.h
MuonValR4
Lightweight algorithm to read xAOD MDT sim hits and (fast-digitised) drift circles from SG and fill a...
Definition: IPatternVisualizationTool.h:23
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
MuonVal
Class to store array like branches into the n-tuples.
Definition: HitValAlg.cxx:19
ActsTrk::DetectorType::Mdt
@ Mdt
MuonSpectrometer.
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
SimHitTester.h
a
TList * a
Definition: liststreamerinfos.cxx:10
MuonHitTesterAlg.h
RpcMeasurementVariables.h
MuonPRDTest
Definition: MuonHitTesterAlg.h:15
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:567
ActsTrk::DetectorType::Rpc
@ Rpc
Monitored Drift Tubes.
SegmentVariables.h
MMDigitVariables.h
MdtTwinDriftCircleVariables.h
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37