ATLAS Offline Software
Loading...
Searching...
No Matches
RPCSimHitVariables.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
5
9
10namespace MuonPRDTest {
11 RPCSimHitVariables::RPCSimHitVariables(MuonTesterTree& tree, const std::string& container_name, MSG::Level msglvl) :
12 PrdTesterModule(tree, "SIM_RPC", msglvl), m_key{container_name} {}
13
15
16 bool RPCSimHitVariables::fill(const EventContext& ctx) {
17 ATH_MSG_DEBUG("do fill RpcSDOVariable()");
19 if (!rpcContainer.isValid()) {
20 ATH_MSG_FATAL("Failed to retrieve digit container " << m_key.fullKey());
21 return false;
22 }
23 const MuonGM::MuonDetectorManager* MuonDetMgr = getDetMgr(ctx);
24 if (!MuonDetMgr) { return false; }
25 unsigned int n_hits{0};
26 // Get the RPC Id hit helper
27 const RpcHitIdHelper* rpchhelper = RpcHitIdHelper::GetHelper();
28 if (!rpcContainer->size()) ATH_MSG_DEBUG("RPC sdo container is empty");
29 for (const RPCSimHit& hit : *rpcContainer) {
30 HitID hitid = hit.RPCid();
31
32 std::string stname = rpchhelper->GetStationName(hitid);
33 int steta = rpchhelper->GetZSector(hitid);
34 int stphi = rpchhelper->GetPhiSector(hitid);
35 int dbr = rpchhelper->GetDoubletR(hitid);
36 int dbz = rpchhelper->GetDoubletZ(hitid);
37 int dbp = rpchhelper->GetDoubletPhi(hitid);
38 int gg = rpchhelper->GetGasGapLayer(hitid);
39 int mfi = rpchhelper->GetMeasuresPhi(hitid);
40
41 bool isValid = false;
42 // the last 2 arguments are:
43 // bool check -> set to true for validity check of identifier
44 // &bool isValid -> reference to boolean, which will be false in case of invalid identifier
45 // the channelID() function of the RpcIdHelper needs also a stripNumber, but the RpcHitIdHelper
46 // does not seem to return this, so we just give stripNumber=1 for now
47 Identifier offid = idHelperSvc()->rpcIdHelper().channelID(stname, steta, stphi, dbr, dbz, dbp, gg, mfi, 1, isValid);
48 if (!isValid) {
49 ATH_MSG_WARNING("Cannot build a valid Identifier for RPC stationName="
50 << stname << ", eta=" << steta << ", phi=" << stphi << ", doubletR=" << dbr << ", doubletZ=" << dbz
51 << ", doubletPhi=" << dbp << ", gasGap=" << gg << ", measuresPhi=" << mfi << "; skipping...");
52 continue;
53 }
54
55 const MuonGM::RpcReadoutElement* rpcdet = MuonDetMgr->getRpcReadoutElement(offid);
56 if (!rpcdet) {
57 ATH_MSG_ERROR("RPCSimHitVariables::fillVariables() - Failed to retrieve RpcReadoutElement for "
58 << idHelperSvc()->toString(offid));
59 return false;
60 }
61
62 m_rpc_Id.push_back(offid);
63 m_RPC_globalTime.push_back(hit.globalTime());
64 const Amg::Vector3D& localPosition = hit.localPosition();
65 m_RPC_hitLocalPositionX.push_back(localPosition.x());
66 m_RPC_hitLocalPositionY.push_back(localPosition.y());
67 Amg::Vector3D simHitPosGlo = rpcdet->localToGlobalCoords(localPosition, offid);
68 m_RPC_hitGlobalPosition.push_back(simHitPosGlo);
70 m_RPC_particleEncoding.push_back(hit.particleEncoding());
71 m_RPC_kineticEnergy.push_back(hit.kineticEnergy());
72 m_RPC_depositEnergy.push_back(hit.energyDeposit());
73 m_RPC_StepLength.push_back(hit.stepLength());
74
75 int pdgId = -999;
76 int barcode = -999;
77 const HepMcParticleLink& pLink = hit.particleLink();
78 barcode = pLink.barcode();
79 if (pLink.isValid()) {
80 HepMC::ConstGenParticlePtr genP = pLink.cptr();
81 if (genP) {
82 pdgId = genP->pdg_id();
83 barcode = HepMC::barcode(genP);
84 } else {
85 ATH_MSG_WARNING("GenParticle is nullptr for hit in "
86 << stname << " (eta=" << steta << ", phi=" << stphi << ", doubletR=" << dbr << ", doubletZ=" << dbz
87 << ", doubletPhi=" << dbp << ", gasgaplayer=" << gg << ", measuresPhi=" << mfi << ")");
88 }
89 } else {
90 // if barcode is 0, the hit was not created by a particle generated in the GenEvent step, thus link cannot be valid
91 if (msgLvl(barcode == 0 ? MSG::DEBUG : MSG::WARNING)) {
92 msg(barcode == 0 ? MSG::DEBUG : MSG::WARNING)
93 << "HepMcParticleLink with barcode=" << barcode << " is not valid for hit in " << stname << " (eta=" << steta
94 << ", phi=" << stphi << ", doubletR=" << dbr << ", doubletZ=" << dbz << ", doubletPhi=" << dbp
95 << ", gasgaplayer=" << gg << ", measuresPhi=" << mfi << ")" << endmsg;
96 }
97 }
98 m_RPC_trackId.push_back(pdgId);
99 m_RPC_truthEl.push_back(barcode);
100 ++n_hits;
101 }
102 m_RPC_nSimHits = n_hits;
103
104 ATH_MSG_DEBUG("processed " << m_RPC_nSimHits << " Rpc hits");
105 return true;
106 }
107
108} // 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
int HitID
MsgStream & msg() const
The standard message stream.
bool msgLvl(const MSG::Level lvl) const
Test the output level.
The MuonDetectorManager stores the transient representation of the Muon Spectrometer geometry and pro...
const RpcReadoutElement * getRpcReadoutElement(const Identifier &id) const
access via extended identifier (requires unpacking)
An RpcReadoutElement corresponds to a single RPC module; therefore typicaly a barrel muon station con...
Amg::Vector3D localToGlobalCoords(const Amg::Vector3D &x, const Identifier &id) const
Attention: these transformations do not represent the tracking transformations as obtained by the tra...
const MuonGM::MuonDetectorManager * getDetMgr(const EventContext &ctx) const
const Muon::IMuonIdHelperSvc * idHelperSvc() const
PrdTesterModule(MuonTesterTree &tree, const std::string &grp_name, MSG::Level msglvl)
VectorBranch< int > & m_RPC_particleEncoding
RPCSimHitVariables(MuonTesterTree &tree, const std::string &container_name, MSG::Level msglvl)
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...
VectorBranch< int > & m_RPC_trackId
VectorBranch< int > & m_RPC_truthEl
VectorBranch< float > & m_RPC_kineticEnergy
VectorBranch< float > & m_RPC_depositEnergy
ThreeVectorBranch m_RPC_detector_globalPosition
VectorBranch< float > & m_RPC_hitLocalPositionY
VectorBranch< float > & m_RPC_hitLocalPositionX
SG::ReadHandleKey< RPCSimHitCollection > m_key
VectorBranch< float > & m_RPC_globalTime
VectorBranch< float > & m_RPC_StepLength
ScalarBranch< unsigned int > & m_RPC_nSimHits
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 RpcIdHelper & rpcIdHelper() const =0
access to RpcIdHelper
int GetDoubletPhi(const int &hid) const
static const RpcHitIdHelper * GetHelper(unsigned int nGasGaps=2)
int GetPhiSector(const int &hid) const
int GetDoubletR(const int &hid) const
int GetGasGapLayer(const int &hid) const
int GetMeasuresPhi(const int &hid) const
std::string GetStationName(const int &hid) const
int GetDoubletZ(const int &hid) const
int GetZSector(const int &hid) const
Identifier channelID(int stationName, int stationEta, int stationPhi, int doubletR, int doubletZ, int doubletPhi, int gasGap, int measuresPhi, int strip) const
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