ATLAS Offline Software
TGCSimHitVariables.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  TGCSimHitVariables::TGCSimHitVariables(MuonTesterTree& tree, const std::string& container_name, MSG::Level msglvl) :
13  PrdTesterModule(tree, "TGC_Sim", false, 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 
21  SG::ReadHandle<TGCSimHitCollection> tgcContainer{m_key, ctx};
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  }
87  ++numHits;
88  }
89  m_TGC_nSimHits = numHits;
90 
91  ATH_MSG_DEBUG("processed " << m_TGC_nSimHits << " Tgc hits");
92  return true;
93  }
94 }
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
TgcHitIdHelper::GetGasGap
int GetGasGap(const int &hid) const
Definition: TgcHitIdHelper.cxx:71
MuonPRDTest::TGCSimHitVariables::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: TGCSimHitVariables.cxx:16
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
MuonPRDTest::TGCSimHitVariables::m_TGC_kineticEnergy
VectorBranch< float > & m_TGC_kineticEnergy
Definition: TGCSimHitVariables.h:30
tree
TChain * tree
Definition: tile_monitor.h:30
MuonPRDTest::PrdTesterModule::getDetMgr
const MuonGM::MuonDetectorManager * getDetMgr(const EventContext &ctx) const
Definition: PrdTesterModule.cxx:15
isValid
bool isValid(const T &p)
Definition: AtlasPID.h:214
GenParticle.h
PowhegPy8EG_H2a.pdgId
dictionary pdgId
Definition: PowhegPy8EG_H2a.py:128
MuonPRDTest::TGCSimHitVariables::m_TGC_truthEl
VectorBranch< int > & m_TGC_truthEl
Definition: TGCSimHitVariables.h:34
TgcHitIdHelper
Definition: TgcHitIdHelper.h:13
MuonVal::MuonTesterBranch::declare_dependency
bool declare_dependency(Key &key)
Declares the ReadHandle/ ReadCondHandleKey as data dependency of the algorithm.
MuonGM::MuonDetectorManager::getTgcReadoutElement
const TgcReadoutElement * getTgcReadoutElement(const Identifier &id) const
access via extended identifier (requires unpacking)
Definition: MuonDetDescr/MuonReadoutGeometry/src/MuonDetectorManager.cxx:247
MuonVal::ThreeVectorBranch::push_back
void push_back(const Amg::Vector3D &vec)
interface using the Amg::Vector3D
Definition: ThreeVectorBranch.cxx:23
MuonVal::TgcIdentifierBranch::push_back
void push_back(const Identifier &id) override final
Definition: IdentifierBranch.cxx:66
MuonPRDTest::TGCSimHitVariables::m_TGC_globalTime
VectorBranch< float > & m_TGC_globalTime
Definition: TGCSimHitVariables.h:23
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
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
TgcHitIdHelper::GetStationName
std::string GetStationName(const int &hid) const
Definition: TgcHitIdHelper.cxx:52
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
MuonPRDTest::TGCSimHitVariables::m_TGC_depositEnergy
VectorBranch< float > & m_TGC_depositEnergy
Definition: TGCSimHitVariables.h:31
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
HepMC::barcode
int barcode(const T *p)
Definition: Barcode.h:16
MuonPRDTest::TGCSimHitVariables::m_TGC_hitLocalPosition
ThreeVectorBranch m_TGC_hitLocalPosition
Definition: TGCSimHitVariables.h:25
MuonPRDTest::PrdTesterModule
Definition: PrdTesterModule.h:15
MuonGM::TgcReadoutElement
A TgcReadoutElement corresponds to a single TGC chamber; therefore typically a TGC station contains s...
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/TgcReadoutElement.h:42
TgcHitIdHelper::GetHelper
static const TgcHitIdHelper * GetHelper()
Definition: TgcHitIdHelper.cxx:23
MuonGM::MuonReadoutElement::globalPosition
const Amg::Vector3D globalPosition() const
Definition: MuonDetDescr/MuonReadoutGeometry/src/MuonReadoutElement.cxx:47
MuonPRDTest::TGCSimHitVariables::m_key
SG::ReadHandleKey< TGCSimHitCollection > m_key
Definition: TGCSimHitVariables.h:19
MuonPRDTest::TGCSimHitVariables::TGCSimHitVariables
TGCSimHitVariables(MuonTesterTree &tree, const std::string &container_name, MSG::Level msglvl)
Definition: TGCSimHitVariables.cxx:12
AthMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AthMessaging.h:164
MuonGM::TgcReadoutElement::localToGlobalTransf
const Amg::Transform3D & localToGlobalTransf(const Identifier &id) const
Returns the local -> global transformation x-axis: Parallel to the wires (strips) if the Identifier b...
MuonVal::VectorBranch::push_back
void push_back(const T &value)
Adds a new element at the end of the vector.
TgcHitIdHelper::GetStationPhi
int GetStationPhi(const int &hid) const
Definition: TgcHitIdHelper.cxx:61
MuonPRDTest::TGCSimHitVariables::m_TGC_trackId
VectorBranch< int > & m_TGC_trackId
Definition: TGCSimHitVariables.h:33
HepMC::ConstGenParticlePtr
const GenParticle * ConstGenParticlePtr
Definition: GenParticle.h:38
errorcheck.h
Helpers for checking error return status codes and reporting errors.
MuonPRDTest::TGCSimHitVariables::m_TGC_detector_globalPosition
ThreeVectorBranch m_TGC_detector_globalPosition
Definition: TGCSimHitVariables.h:27
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
MuonPRDTest::TGCSimHitVariables::m_TGC_hitGlobalPosition
ThreeVectorBranch m_TGC_hitGlobalPosition
Definition: TGCSimHitVariables.h:26
MuonPRDTest::TGCSimHitVariables::m_TGC_particleEncoding
VectorBranch< int > & m_TGC_particleEncoding
Definition: TGCSimHitVariables.h:29
TGCSimHit
Definition: TGCSimHit.h:19
Muon::IMuonIdHelperSvc::tgcIdHelper
virtual const TgcIdHelper & tgcIdHelper() const =0
access to TgcIdHelper
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
MuonPRDTest::TGCSimHitVariables::m_TGC_StepLength
VectorBranch< float > & m_TGC_StepLength
Definition: TGCSimHitVariables.h:32
DEBUG
#define DEBUG
Definition: page_access.h:11
MuonPRDTest::TGCSimHitVariables::m_TGC_id
TgcIdentifierBranch m_TGC_id
Definition: TGCSimHitVariables.h:22
MuonPRDTest
Definition: CSCDigitVariables.h:10
MuonPRDTest::PrdTesterModule::idHelperSvc
const Muon::IMuonIdHelperSvc * idHelperSvc() const
Definition: PrdTesterModule.cxx:14
TgcHitIdHelper::GetStationEta
int GetStationEta(const int &hid) const
Definition: TgcHitIdHelper.cxx:66
TgcIdHelper::channelID
Identifier channelID(int stationName, int stationEta, int stationPhi, int gasGap, int isStrip, int channel) const
Definition: TgcIdHelper.cxx:583
TgcReadoutElement.h
HitID
int HitID
Definition: GenericMuonSimHit.h:13
TgcHitIdHelper.h
MuonPRDTest::TGCSimHitVariables::m_TGC_nSimHits
ScalarBranch< unsigned int > & m_TGC_nSimHits
Definition: TGCSimHitVariables.h:35
MuonPRDTest::TGCSimHitVariables::declare_keys
bool declare_keys() override final
Definition: TGCSimHitVariables.cxx:14
TGCSimHitVariables.h