ATLAS Offline Software
MDTSimHitVariables.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  MDTSimHitVariables::MDTSimHitVariables(MuonTesterTree& tree, const std::string& container_name, MSG::Level msglvl) :
13  PrdTesterModule(tree, "MDT_Sim", false, 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  }
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
MdtHitIdHelper::GetMultiLayer
int GetMultiLayer(const int &hid) const
Definition: MdtHitIdHelper.cxx:79
MdtReadoutElement.h
MuonPRDTest::MDTSimHitVariables::m_MDT_globalTime
VectorBranch< float > & m_MDT_globalTime
Definition: MDTSimHitVariables.h:25
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
MuonPRDTest::MDTSimHitVariables::m_MDT_particleEncoding
VectorBranch< int > & m_MDT_particleEncoding
Definition: MDTSimHitVariables.h:31
MuonVal::MdtIdentifierBranch::push_back
void push_back(const Identifier &id) override final
Definition: IdentifierBranch.cxx:24
MdtHitIdHelper
Definition: MdtHitIdHelper.h:13
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
MDTSimHit
Definition: MDTSimHit.h:21
MuonPRDTest::MDTSimHitVariables::m_MDT_driftRadius
VectorBranch< float > & m_MDT_driftRadius
Definition: MDTSimHitVariables.h:29
tree
TChain * tree
Definition: tile_monitor.h:30
MuonPRDTest::MDTSimHitVariables::m_MDT_hitGlobalPosition
ThreeVectorBranch m_MDT_hitGlobalPosition
Definition: MDTSimHitVariables.h:27
MuonPRDTest::MDTSimHitVariables::m_MDT_nSimHits
ScalarBranch< unsigned int > & m_MDT_nSimHits
Definition: MDTSimHitVariables.h:37
MuonPRDTest::PrdTesterModule::getDetMgr
const MuonGM::MuonDetectorManager * getDetMgr(const EventContext &ctx) const
Definition: PrdTesterModule.cxx:15
MuonPRDTest::MDTSimHitVariables::m_MDT_detector_globalPosition
ThreeVectorBranch m_MDT_detector_globalPosition
Definition: MDTSimHitVariables.h:28
MuonPRDTest::MDTSimHitVariables::m_MDT_id
MdtIdentifierBranch m_MDT_id
Definition: MDTSimHitVariables.h:24
MuonPRDTest::MDTSimHitVariables::declare_keys
bool declare_keys() override final
Definition: MDTSimHitVariables.cxx:95
MdtHitIdHelper::GetZSector
int GetZSector(const int &hid) const
Definition: MdtHitIdHelper.cxx:73
isValid
bool isValid(const T &p)
Definition: AtlasPID.h:214
MdtHitIdHelper::GetHelper
static const MdtHitIdHelper * GetHelper(unsigned int nTubes=78)
Definition: MdtHitIdHelper.cxx:24
GenParticle.h
PowhegPy8EG_H2a.pdgId
dictionary pdgId
Definition: PowhegPy8EG_H2a.py:128
MuonPRDTest::MDTSimHitVariables::m_MDT_truthEl
VectorBranch< int > & m_MDT_truthEl
Definition: MDTSimHitVariables.h:36
MuonVal::MuonTesterBranch::declare_dependency
bool declare_dependency(Key &key)
Declares the ReadHandle/ ReadCondHandleKey as data dependency of the algorithm.
MuonPRDTest::MDTSimHitVariables::MDTSimHitVariables
MDTSimHitVariables(MuonTesterTree &tree, const std::string &container_name, MSG::Level msglvl)
Definition: MDTSimHitVariables.cxx:12
MuonVal::ThreeVectorBranch::push_back
void push_back(const Amg::Vector3D &vec)
interface using the Amg::Vector3D
Definition: ThreeVectorBranch.cxx:23
MdtHitIdHelper::GetPhiSector
int GetPhiSector(const int &hid) const
Definition: MdtHitIdHelper.cxx:68
tubeMax
double tubeMax
Definition: MDT_ResponseTest.cxx:31
MdtHitIdHelper::GetStationName
std::string GetStationName(const int &hid) const
Definition: MdtHitIdHelper.cxx:57
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
MuonGM::MuonDetectorManager::getMdtReadoutElement
const MdtReadoutElement * getMdtReadoutElement(const Identifier &id) const
access via extended identifier (requires unpacking)
Definition: MuonDetDescr/MuonReadoutGeometry/src/MuonDetectorManager.cxx:204
MuonVal::MuonTesterTree
Definition: MuonTesterTree.h:30
MuonGM::MdtReadoutElement
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MdtReadoutElement.h:50
MuonPRDTest::MDTSimHitVariables::m_MDT_trackId
VectorBranch< int > & m_MDT_trackId
Definition: MDTSimHitVariables.h:35
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
MuonPRDTest::PrdTesterModule
Definition: PrdTesterModule.h:15
MuonPRDTest::MDTSimHitVariables::m_MDT_depositEnergy
VectorBranch< float > & m_MDT_depositEnergy
Definition: MDTSimHitVariables.h:33
MDTSimHitVariables.h
MdtHitIdHelper::GetLayer
int GetLayer(const int &hid) const
Definition: MdtHitIdHelper.cxx:84
MuonGM::MuonReadoutElement::globalPosition
const Amg::Vector3D globalPosition() const
Definition: MuonDetDescr/MuonReadoutGeometry/src/MuonReadoutElement.cxx:47
MuonGM::MdtReadoutElement::localToGlobalTransf
const Amg::Transform3D & localToGlobalTransf(const Identifier &id) const
AthMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AthMessaging.h:164
MuonPRDTest::MDTSimHitVariables::m_MDT_hitLocalPosition
ThreeVectorBranch m_MDT_hitLocalPosition
Definition: MDTSimHitVariables.h:26
MuonVal::VectorBranch::push_back
void push_back(const T &value)
Adds a new element at the end of the vector.
HepMC::ConstGenParticlePtr
const GenParticle * ConstGenParticlePtr
Definition: GenParticle.h:38
MdtIdHelper::channelID
Identifier channelID(int stationName, int stationEta, int stationPhi, int multilayer, int tubeLayer, int tube) const
Definition: MdtIdHelper.cxx:659
errorcheck.h
Helpers for checking error return status codes and reporting errors.
Muon::IMuonIdHelperSvc::mdtIdHelper
virtual const MdtIdHelper & mdtIdHelper() const =0
access to MdtIdHelper
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
MuonPRDTest::MDTSimHitVariables::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: MDTSimHitVariables.cxx:14
MdtHitIdHelper.h
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
Definition: CSCDigitVariables.h:10
MuonPRDTest::PrdTesterModule::idHelperSvc
const Muon::IMuonIdHelperSvc * idHelperSvc() const
Definition: PrdTesterModule.cxx:14
MdtHitIdHelper::GetTube
int GetTube(const int &hid) const
Definition: MdtHitIdHelper.cxx:89
dqt_zlumi_alleff_HIST.tl
tl
Definition: dqt_zlumi_alleff_HIST.py:73
MuonPRDTest::MDTSimHitVariables::m_MDT_StepLength
VectorBranch< float > & m_MDT_StepLength
Definition: MDTSimHitVariables.h:34
HitID
int HitID
Definition: GenericMuonSimHit.h:13
MuonPRDTest::MDTSimHitVariables::m_simHitKey
SG::ReadHandleKey< MDTSimHitCollection > m_simHitKey
Definition: MDTSimHitVariables.h:22
calibdata.tube
tube
Definition: calibdata.py:31
MuonPRDTest::MDTSimHitVariables::m_MDT_kineticEnergy
VectorBranch< float > & m_MDT_kineticEnergy
Definition: MDTSimHitVariables.h:32