ATLAS Offline Software
Loading...
Searching...
No Matches
MDTSimHitVariables.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6
11namespace MuonPRDTest {
12 MDTSimHitVariables::MDTSimHitVariables(MuonTesterTree& tree, const std::string& container_name, MSG::Level msglvl) :
13 PrdTesterModule(tree, "MDT_Sim", msglvl), m_simHitKey{container_name} {}
14 bool MDTSimHitVariables::fill(const EventContext& ctx) {
15 ATH_MSG_DEBUG("do fillMDTSimHitVariables()");
16 const MuonGM::MuonDetectorManager* MuonDetMgr = getDetMgr(ctx);
17 if (!MuonDetMgr) { return false; }
18
20 if (!mdtContainer.isValid()) {
21 ATH_MSG_FATAL("Failed to retrieve container " << m_simHitKey << ".");
22 return false;
23 }
24 // Get the MDT Id hit helper
25 const MdtHitIdHelper* mdthhelper = MdtHitIdHelper::GetHelper(idHelperSvc()->mdtIdHelper().tubeMax());
26
27 unsigned int numHits{0};
28 for (const MDTSimHit& hit : *mdtContainer) {
29 HitID hitid = hit.MDTid();
30
31 std::string stname = mdthhelper->GetStationName(hitid);
32 int steta = mdthhelper->GetZSector(hitid);
33 int stphi = mdthhelper->GetPhiSector(hitid);
34 int ml = mdthhelper->GetMultiLayer(hitid);
35 int tl = mdthhelper->GetLayer(hitid);
36 int tube = mdthhelper->GetTube(hitid);
37
38 bool isValid = false;
39 Identifier offid = idHelperSvc()->mdtIdHelper().channelID(stname, steta, stphi, ml, tl, tube, isValid);
40 if (!isValid) {
41 ATH_MSG_WARNING("Cannot build a valid Identifier for MDT stationName=" << stname << ", eta=" << steta << ", phi=" << stphi
42 << ", multiLayer=" << ml << ", tubeLayer=" << tl
43 << ", tube=" << tube << "; skipping...");
44 continue;
45 }
46
47 const MuonGM::MdtReadoutElement* mdtdet = MuonDetMgr->getMdtReadoutElement(offid);
48 if (!mdtdet) {
49 ATH_MSG_ERROR("MDTSimHitVariables::fillVariables() - Failed to retrieve MdtReadoutElement for "
50 << idHelperSvc()->toString(offid));
51 return false;
52 }
53
54 m_MDT_id.push_back(offid);
55 m_MDT_globalTime.push_back(hit.globalTime());
56
57 const Amg::Vector3D& localPosition = hit.localPosition();
58 m_MDT_hitLocalPosition.push_back(localPosition);
59 m_MDT_hitGlobalPosition.push_back(mdtdet->localToGlobalTransf(offid)*localPosition);
61 m_MDT_driftRadius.push_back(hit.driftRadius());
62 m_MDT_particleEncoding.push_back(hit.particleEncoding());
63 m_MDT_kineticEnergy.push_back(hit.kineticEnergy());
64 m_MDT_depositEnergy.push_back(hit.energyDeposit());
65 m_MDT_StepLength.push_back(hit.stepLength());
66
67 int pdgId{-999}, barcode{-999};
68 const HepMcParticleLink& pLink = hit.particleLink();
69 barcode = pLink.barcode();
70 if (pLink.isValid()) {
71 HepMC::ConstGenParticlePtr genP = pLink.cptr();
72 if (genP) {
73 pdgId = genP->pdg_id();
74 barcode = HepMC::barcode(genP);
75 } else {
76 ATH_MSG_WARNING("GenParticle is nullptr for hit in " << stname << " (eta=" << steta << ", phi=" << stphi << ", ml="
77 << ml << ", tubelayer=" << tl << ", tube=" << tube << ")");
78 }
79 } else {
80 // if barcode is 0, the hit was not created by a particle generated in the GenEvent step, thus link cannot be valid
81 if (msgLvl(barcode == 0 ? MSG::DEBUG : MSG::WARNING)) {
82 msg(barcode == 0 ? MSG::DEBUG : MSG::WARNING)
83 << "HepMcParticleLink with barcode=" << barcode << " is not valid for hit in " << stname << " (eta=" << steta
84 << ", phi=" << stphi << ", ml=" << ml << ", tubelayer=" << tl << ", tube=" << tube << ")" << endmsg;
85 }
86 }
87 m_MDT_trackId.push_back(pdgId);
88 m_MDT_truthEl.push_back(barcode);
89 ++numHits;
90 }
91 m_MDT_nSimHits = numHits;
92 ATH_MSG_DEBUG("processed " << m_MDT_nSimHits << " Mdt hits");
93 return true;
94 }
96} // namespace MuonPRDTest
#define endmsg
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition AtlasPID.h:878
Helpers for checking error return status codes and reporting errors.
int HitID
double tubeMax
MsgStream & msg() const
The standard message stream.
bool msgLvl(const MSG::Level lvl) const
Test the output level.
static const MdtHitIdHelper * GetHelper(unsigned int nTubes=78)
int GetPhiSector(const int &hid) const
int GetMultiLayer(const int &hid) const
std::string GetStationName(const int &hid) const
int GetZSector(const int &hid) const
int GetLayer(const int &hid) const
int GetTube(const int &hid) const
Identifier channelID(int stationName, int stationEta, int stationPhi, int multilayer, int tubeLayer, int tube) const
const Amg::Transform3D & localToGlobalTransf(const Identifier &id) const
The MuonDetectorManager stores the transient representation of the Muon Spectrometer geometry and pro...
const MdtReadoutElement * getMdtReadoutElement(const Identifier &id) const
access via extended identifier (requires unpacking)
bool fill(const EventContext &ctx) override final
The fill method checks if enough information is provided such that the branch is cleared from the inf...
MDTSimHitVariables(MuonTesterTree &tree, const std::string &container_name, MSG::Level msglvl)
ThreeVectorBranch m_MDT_detector_globalPosition
VectorBranch< int > & m_MDT_trackId
ScalarBranch< unsigned int > & m_MDT_nSimHits
VectorBranch< float > & m_MDT_kineticEnergy
SG::ReadHandleKey< MDTSimHitCollection > m_simHitKey
VectorBranch< float > & m_MDT_driftRadius
VectorBranch< float > & m_MDT_globalTime
VectorBranch< float > & m_MDT_StepLength
VectorBranch< int > & m_MDT_particleEncoding
VectorBranch< float > & m_MDT_depositEnergy
VectorBranch< int > & m_MDT_truthEl
const MuonGM::MuonDetectorManager * getDetMgr(const EventContext &ctx) const
const Muon::IMuonIdHelperSvc * idHelperSvc() const
PrdTesterModule(MuonTesterTree &tree, const std::string &grp_name, MSG::Level msglvl)
bool declare_dependency(Key &key)
Declares the ReadHandle/ ReadCondHandleKey as data dependency of the algorithm.
TTree * tree() override final
Returns the underlying TTree object.
virtual const MdtIdHelper & mdtIdHelper() const =0
access to MdtIdHelper
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Eigen::Matrix< double, 3, 1 > Vector3D
int barcode(const T *p)
Definition Barcode.h:16
const GenParticle * ConstGenParticlePtr
Definition GenParticle.h:38