ATLAS Offline Software
CSCSimHitVariables.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
11 namespace MuonPRDTest {
12  CSCSimHitVariables::CSCSimHitVariables(MuonTesterTree& tree, const std::string& container_name, MSG::Level msglvl) :
13  PrdTesterModule(tree, "CSC_Sim", false, 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 
21  SG::ReadHandle<CSCSimHitCollection> cscContainer{m_key, ctx};
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();
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  }
91  ++numHits;
92  }
93  m_CSC_nSimHits = numHits;
94 
95  ATH_MSG_DEBUG("processed " << m_CSC_nSimHits << " Csc hits");
96  return true;
97  }
98 }
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
MuonPRDTest::CSCSimHitVariables::fill
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...
Definition: CSCSimHitVariables.cxx:16
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
MuonVal::CscIdentifierBranch::push_back
void push_back(const Identifier &id) override final
Definition: IdentifierBranch.cxx:52
tree
TChain * tree
Definition: tile_monitor.h:30
MuonPRDTest::PrdTesterModule::getDetMgr
const MuonGM::MuonDetectorManager * getDetMgr(const EventContext &ctx) const
Definition: PrdTesterModule.cxx:15
MuonGM::CscReadoutElement
Definition: CscReadoutElement.h:56
isValid
bool isValid(const T &p)
Definition: AtlasPID.h:214
MuonPRDTest::CSCSimHitVariables::m_CSC_id
CscIdentifierBranch m_CSC_id
Definition: CSCSimHitVariables.h:22
GenParticle.h
CscHitIdHelper::GetChamberLayer
int GetChamberLayer(const int &hid) const
Definition: CscHitIdHelper.cxx:78
PowhegPy8EG_H2a.pdgId
dictionary pdgId
Definition: PowhegPy8EG_H2a.py:128
MuonPRDTest::CSCSimHitVariables::m_CSC_depositEnergy
VectorBranch< float > & m_CSC_depositEnergy
Definition: CSCSimHitVariables.h:28
CscHitIdHelper::GetPhiSector
int GetPhiSector(const int &hid) const
Definition: CscHitIdHelper.cxx:67
MuonVal::MuonTesterBranch::declare_dependency
bool declare_dependency(Key &key)
Declares the ReadHandle/ ReadCondHandleKey as data dependency of the algorithm.
MuonVal::ThreeVectorBranch::push_back
void push_back(const Amg::Vector3D &vec)
interface using the Amg::Vector3D
Definition: ThreeVectorBranch.cxx:23
CscHitIdHelper::GetHelper
static const CscHitIdHelper * GetHelper()
Definition: CscHitIdHelper.cxx:23
MuonPRDTest::CSCSimHitVariables::m_key
SG::ReadHandleKey< CSCSimHitCollection > m_key
Definition: CSCSimHitVariables.h:19
CSCSimHit
Definition: CSCSimHit.h:18
MuonPRDTest::CSCSimHitVariables::m_CSC_kineticEnergy
VectorBranch< float > & m_CSC_kineticEnergy
Definition: CSCSimHitVariables.h:27
Amg::toString
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Definition: GeoPrimitivesToStringConverter.h:40
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
AthMessaging::msgLvl
bool msgLvl(const MSG::Level lvl) const
Test the output level.
Definition: AthMessaging.h:151
MuonVal::MuonTesterTree
Definition: MuonTesterTree.h:30
MuonPRDTest::CSCSimHitVariables::declare_keys
bool declare_keys() override final
Definition: CSCSimHitVariables.cxx:14
MuonGM::MuonDetectorManager::getCscReadoutElement
const CscReadoutElement * getCscReadoutElement(const Identifier &id) const
access via extended identifier (requires unpacking)
Definition: MuonDetDescr/MuonReadoutGeometry/src/MuonDetectorManager.cxx:225
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
HepMC::barcode
int barcode(const T *p)
Definition: Barcode.h:16
CscHitIdHelper
Definition: CscHitIdHelper.h:13
MuonPRDTest::PrdTesterModule
Definition: PrdTesterModule.h:15
CscReadoutElement.h
CscHitIdHelper::GetWireLayer
int GetWireLayer(const int &hid) const
Definition: CscHitIdHelper.cxx:83
MuonGM::MuonReadoutElement::globalPosition
const Amg::Vector3D globalPosition() const
Definition: MuonDetDescr/MuonReadoutGeometry/src/MuonReadoutElement.cxx:47
AthMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AthMessaging.h:164
CscHitIdHelper.h
MuonVal::VectorBranch::push_back
void push_back(const T &value)
Adds a new element at the end of the vector.
MuonPRDTest::CSCSimHitVariables::m_CSC_globalTime
VectorBranch< float > & m_CSC_globalTime
Definition: CSCSimHitVariables.h:23
MuonGM::CscReadoutElement::localToGlobalCoords
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...
Definition: CscReadoutElement.cxx:97
HepMC::ConstGenParticlePtr
const GenParticle * ConstGenParticlePtr
Definition: GenParticle.h:38
CscIdHelper::channelID
Identifier channelID(int stationName, int stationEta, int stationPhi, int chamberLayer, int wireLayer, int measuresPhi, int strip) const
Definition: CscIdHelper.cxx:706
errorcheck.h
Helpers for checking error return status codes and reporting errors.
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
CscHitIdHelper::GetStationName
std::string GetStationName(const int &hid) const
Definition: CscHitIdHelper.cxx:56
MuonPRDTest::CSCSimHitVariables::m_CSC_detector_globalPosition
ThreeVectorBranch m_CSC_detector_globalPosition
Definition: CSCSimHitVariables.h:25
Muon::IMuonIdHelperSvc::cscIdHelper
virtual const CscIdHelper & cscIdHelper() const =0
access to CscIdHelper
CscHitIdHelper::GetZSector
int GetZSector(const int &hid) const
Definition: CscHitIdHelper.cxx:72
MuonPRDTest::CSCSimHitVariables::m_CSC_trackId
VectorBranch< int > & m_CSC_trackId
Definition: CSCSimHitVariables.h:29
MuonPRDTest::CSCSimHitVariables::m_CSC_hitGlobalPosition
ThreeVectorBranch m_CSC_hitGlobalPosition
Definition: CSCSimHitVariables.h:24
MuonGM::MuonDetectorManager
The MuonDetectorManager stores the transient representation of the Muon Spectrometer geometry and pro...
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MuonDetectorManager.h:49
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DEBUG
#define DEBUG
Definition: page_access.h:11
MuonPRDTest::CSCSimHitVariables::m_CSC_truthEl
VectorBranch< int > & m_CSC_truthEl
Definition: CSCSimHitVariables.h:30
MuonPRDTest
Definition: CSCDigitVariables.h:10
MuonPRDTest::PrdTesterModule::idHelperSvc
const Muon::IMuonIdHelperSvc * idHelperSvc() const
Definition: PrdTesterModule.cxx:14
MuonPRDTest::CSCSimHitVariables::CSCSimHitVariables
CSCSimHitVariables(MuonTesterTree &tree, const std::string &container_name, MSG::Level msglvl)
Definition: CSCSimHitVariables.cxx:12
CSCSimHitVariables.h
HitID
int HitID
Definition: GenericMuonSimHit.h:13
MuonPRDTest::CSCSimHitVariables::m_CSC_nSimHits
ScalarBranch< unsigned int > & m_CSC_nSimHits
Definition: CSCSimHitVariables.h:31