ATLAS Offline Software
Loading...
Searching...
No Matches
TGCSimHitVariables.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 TGCSimHitVariables::TGCSimHitVariables(MuonTesterTree& tree, const std::string& container_name, MSG::Level msglvl) :
13 PrdTesterModule(tree, "TGC_Sim", msglvl),m_key{container_name} {}
15
16 bool TGCSimHitVariables::fill(const EventContext& ctx) {
17 ATH_MSG_DEBUG("do fillTGCSimHitVariables()");
18 const MuonGM::MuonDetectorManager* MuonDetMgr = getDetMgr(ctx);
19 if (!MuonDetMgr) { return false; }
20
22 if (!tgcContainer.isValid()) {
23 ATH_MSG_FATAL("Failed to retrieve container " << m_key << ".");
24 return false;
25 }
26 // Get the TGC Id hit helper
27 const TgcHitIdHelper* tgchhelper = TgcHitIdHelper::GetHelper();
28
29 unsigned int numHits{0};
30 for (const TGCSimHit& hit : *tgcContainer) {
31 HitID hitid = hit.TGCid();
32
33 std::string stname = tgchhelper->GetStationName(hitid);
34 int steta = tgchhelper->GetStationEta(hitid);
35 int stphi = tgchhelper->GetStationPhi(hitid);
36 int gasgap = tgchhelper->GetGasGap(hitid);
37
38 bool isValid = false;
39 Identifier offid = idHelperSvc()->tgcIdHelper().channelID(stname, steta, stphi, gasgap, 1, 1, isValid);
40 if (!isValid) {
41 ATH_MSG_WARNING("Cannot build a valid Identifier for TGC stationName=" << stname << ", eta=" << steta << ", phi=" << stphi
42 << ", gasgap=" <<gasgap << "; skipping...");
43 continue;
44 }
45
46 const MuonGM::TgcReadoutElement* tgcdet = MuonDetMgr->getTgcReadoutElement(offid);
47 if (!tgcdet) {
48 ATH_MSG_ERROR("TGCSimHitVariables::fillVariables() - Failed to retrieve TgcReadoutElement for "
49 << idHelperSvc()->toString(offid));
50 return false;
51 }
52
53 m_TGC_id.push_back(offid);
54 m_TGC_globalTime.push_back(hit.globalTime());
55
56 const Amg::Vector3D& localPosition = hit.localPosition();
57 m_TGC_hitLocalPosition.push_back(localPosition);
58 m_TGC_hitGlobalPosition.push_back(tgcdet->localToGlobalTransf(offid) *localPosition);
60
61 m_TGC_particleEncoding.push_back(hit.particleEncoding());
62 m_TGC_kineticEnergy.push_back(hit.kineticEnergy());
63 m_TGC_depositEnergy.push_back(hit.energyDeposit());
64 m_TGC_StepLength.push_back(hit.stepLength());
65
66 int pdgId{-999}, barcode{-999};
67 const HepMcParticleLink& pLink = hit.particleLink();
68 barcode = pLink.barcode();
69 if (pLink.isValid()) {
70 HepMC::ConstGenParticlePtr genP = pLink.cptr();
71 if (genP) {
72 pdgId = genP->pdg_id();
73 barcode = HepMC::barcode(genP);
74 } else {
75 ATH_MSG_WARNING("GenParticle is nullptr for hit in " << stname << " (eta=" << steta << ", phi=" << stphi << ", gasgap=" << gasgap << ")");
76 }
77 } else {
78 // if barcode is 0, the hit was not created by a particle generated in the GenEvent step, thus link cannot be valid
79 if (msgLvl(barcode == 0 ? MSG::DEBUG : MSG::WARNING)) {
80 msg(barcode == 0 ? MSG::DEBUG : MSG::WARNING)
81 << "HepMcParticleLink with barcode=" << barcode << " is not valid for hit in " << stname << " (eta=" << steta
82 << ", phi=" << stphi << ", gasgap=" << gasgap << ")" << endmsg;
83 }
84 }
85 m_TGC_trackId.push_back(pdgId);
86 m_TGC_truthEl.push_back(barcode);
87 ++numHits;
88 }
89 m_TGC_nSimHits = numHits;
90
91 ATH_MSG_DEBUG("processed " << m_TGC_nSimHits << " Tgc hits");
92 return true;
93 }
94}
#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
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 TgcReadoutElement * getTgcReadoutElement(const Identifier &id) const
access via extended identifier (requires unpacking)
A TgcReadoutElement corresponds to a single TGC chamber; therefore typically a TGC station contains s...
const Amg::Transform3D & localToGlobalTransf(const Identifier &id) const
Returns the local -> global transformation x-axis: Parallel to the wires (strips) if the Identifier b...
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< float > & m_TGC_depositEnergy
VectorBranch< float > & m_TGC_globalTime
VectorBranch< int > & m_TGC_trackId
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...
ThreeVectorBranch m_TGC_detector_globalPosition
TGCSimHitVariables(MuonTesterTree &tree, const std::string &container_name, MSG::Level msglvl)
ScalarBranch< unsigned int > & m_TGC_nSimHits
VectorBranch< float > & m_TGC_StepLength
VectorBranch< int > & m_TGC_truthEl
VectorBranch< int > & m_TGC_particleEncoding
VectorBranch< float > & m_TGC_kineticEnergy
SG::ReadHandleKey< TGCSimHitCollection > m_key
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 TgcIdHelper & tgcIdHelper() const =0
access to TgcIdHelper
virtual bool isValid() override final
Can the handle be successfully dereferenced?
int GetStationPhi(const int &hid) const
std::string GetStationName(const int &hid) const
int GetStationEta(const int &hid) const
int GetGasGap(const int &hid) const
static const TgcHitIdHelper * GetHelper()
Identifier channelID(int stationName, int stationEta, int stationPhi, int gasGap, int isStrip, int channel) const
Eigen::Matrix< double, 3, 1 > Vector3D
int barcode(const T *p)
Definition Barcode.h:16
const GenParticle * ConstGenParticlePtr
Definition GenParticle.h:38