ATLAS Offline Software
Loading...
Searching...
No Matches
CSCSimHitVariables.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 CSCSimHitVariables::CSCSimHitVariables(MuonTesterTree& tree, const std::string& container_name, MSG::Level msglvl) :
13 PrdTesterModule(tree, "CSC_Sim", msglvl),m_key{container_name} {}
15
16 bool CSCSimHitVariables::fill(const EventContext& ctx) {
17 ATH_MSG_DEBUG("do fillCSCSimHitVariables()");
18 const MuonGM::MuonDetectorManager* MuonDetMgr = getDetMgr(ctx);
19 if (!MuonDetMgr) { return false; }
20
22 if (!cscContainer.isValid()) {
23 ATH_MSG_FATAL("Failed to retrieve container " << m_key << ".");
24 return false;
25 }
26 // Get the CSC Id hit helper
27 const CscHitIdHelper* cschhelper = CscHitIdHelper::GetHelper();
28
29 unsigned int numHits{0};
30 for (const CSCSimHit& hit : *cscContainer) {
31 HitID hitid = hit.CSCid();
32
33 std::string stname = cschhelper->GetStationName(hitid);
34 int steta = cschhelper->GetZSector(hitid);
35 int stphi = cschhelper->GetPhiSector(hitid);
36 int clayer = cschhelper->GetChamberLayer(hitid);
37 int wlayer = cschhelper->GetWireLayer(hitid);
38
39
40 bool isValid = false;
41 Identifier offid = idHelperSvc()->cscIdHelper().channelID(stname, steta, stphi, clayer, wlayer, 1, 1, isValid);
42 if (!isValid) {
43 ATH_MSG_WARNING("Cannot build a valid Identifier for CSC stationName=" << stname << ", eta=" << steta << ", phi=" << stphi
44 << ", chamberLayer=" << clayer << ", wireLayer=" << wlayer
45 << "; skipping...");
46 continue;
47 }
48
49 const MuonGM::CscReadoutElement* cscdet = MuonDetMgr->getCscReadoutElement(offid);
50 if (!cscdet) {
51 ATH_MSG_ERROR("CSCSimHitVariables::fillVariables() - Failed to retrieve CscReadoutElement for "
52 << idHelperSvc()->toString(offid));
53 return false;
54 }
55
56 m_CSC_id.push_back(offid);
57 m_CSC_globalTime.push_back(hit.globalTime());
58
59 Amg::Vector3D simHitPosGlo = cscdet->localToGlobalCoords(hit.getHitStart(), offid);
60 m_CSC_hitGlobalPosition.push_back(simHitPosGlo);
61
62 Amg::Vector3D detpos = cscdet->globalPosition();
63 m_CSC_detector_globalPosition.push_back(detpos);
64
65 m_CSC_kineticEnergy.push_back(hit.kineticEnergy());
66 m_CSC_depositEnergy.push_back(hit.energyDeposit());
67
68
69 int pdgId{-999}, barcode{-999};
70 const HepMcParticleLink& pLink = hit.particleLink();
71 barcode = pLink.barcode();
72 if (pLink.isValid()) {
73 HepMC::ConstGenParticlePtr genP = pLink.cptr();
74 if (genP) {
75 pdgId = genP->pdg_id();
76 barcode = HepMC::barcode(genP);
77 } else {
78 ATH_MSG_WARNING("GenParticle is nullptr for hit in " << stname << " (eta=" << steta << ", phi=" << stphi << ", chamberlayer=" << clayer
79 << ", wirelayer=" << wlayer << ")");
80 }
81 } else {
82 // if barcode is 0, the hit was not created by a particle generated in the GenEvent step, thus link cannot be valid
83 if (msgLvl(barcode == 0 ? MSG::DEBUG : MSG::WARNING)) {
84 msg(barcode == 0 ? MSG::DEBUG : MSG::WARNING)
85 << "HepMcParticleLink with barcode=" << barcode << " is not valid for hit in " << stname << " (eta=" << steta
86 << ", phi=" << stphi << ", chamberlayer=" << clayer << ", wirelayer=" << wlayer << ")" << endmsg;
87 }
88 }
89 m_CSC_trackId.push_back(pdgId);
90 m_CSC_truthEl.push_back(barcode);
91 ++numHits;
92 }
93 m_CSC_nSimHits = numHits;
94
95 ATH_MSG_DEBUG("processed " << m_CSC_nSimHits << " Csc hits");
96 return true;
97 }
98}
#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.
int GetWireLayer(const int &hid) const
int GetZSector(const int &hid) const
int GetPhiSector(const int &hid) const
std::string GetStationName(const int &hid) const
int GetChamberLayer(const int &hid) const
static const CscHitIdHelper * GetHelper()
Identifier channelID(int stationName, int stationEta, int stationPhi, int chamberLayer, int wireLayer, int measuresPhi, int strip) const
Amg::Vector3D localToGlobalCoords(const Amg::Vector3D &x, const Identifier &id) const
localToGlobalCoords and Transf connect the Gas Gap Frame (defined as a Sensitive Detector) to the Glo...
The MuonDetectorManager stores the transient representation of the Muon Spectrometer geometry and pro...
const CscReadoutElement * getCscReadoutElement(const Identifier &id) const
access via extended identifier (requires unpacking)
CSCSimHitVariables(MuonTesterTree &tree, const std::string &container_name, MSG::Level msglvl)
VectorBranch< int > & m_CSC_trackId
VectorBranch< float > & m_CSC_depositEnergy
ScalarBranch< unsigned int > & m_CSC_nSimHits
VectorBranch< float > & m_CSC_globalTime
VectorBranch< float > & m_CSC_kineticEnergy
ThreeVectorBranch m_CSC_detector_globalPosition
SG::ReadHandleKey< CSCSimHitCollection > m_key
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_CSC_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 CscIdHelper & cscIdHelper() const =0
access to CscIdHelper
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