ATLAS Offline Software
SimHitHandle_TRTHit.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
7 // //
8 // Implementation of class SimHitHandle_TRTHit //
9 // //
10 // Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
11 // Initial version: March 2008 //
12 // //
14 
16 #include "VP1Utils/VP1DetInfo.h"
18 #include "VP1Base/VP1Msg.h"
19 
24 #include "TrkSurfaces/Surface.h"
28 
29 #include <bitset>
30 
31 //____________________________________________________________________
33 public:
34  Imp(const TRTUncompressedHit*h) : thehit(h), detelem(nullptr),strawID(0) {}
37  mutable size_t strawID;
38  bool ensureDetElemInit() const;
39 };
40 
41 
42 //____________________________________________________________________
44  : SimHitHandleBase(), m_d(new Imp(h))
45 {
46  if (!h)
47  VP1Msg::message("SimHitHandle_TRTHit constructor ERROR: Received null hit pointer");
48 }
49 
50 //____________________________________________________________________
52 {
53  delete m_d;
54 }
55 
56 
57 //____________________________________________________________________
58 //Trk::GlobalMomentum SimHitHandle_TRTHit::momentumDirection() const
60 {
61  if (VP1Msg::verbose()&&posStart()==posEnd())
62  VP1Msg::messageVerbose("SimHitHandle_SiHit::momentumDirection() ERROR: posStart()==posEnd()");
64 // return Trk::GlobalMomentum(u.x(),u.y(),u.z());
65  return Amg::Vector3D(u.x(),u.y(),u.z());
66 }
67 
68 //____________________________________________________________________
70 {
71  bool ok;
73  if (!ok) {
74  VP1Msg::message("SimHitHandle_TRTHit constructor WARNING: Could not determine mass for pdg code "
75  +QString::number(pdg())+". Assuming charged pion mass.");
76  mass = ParticleConstants::chargedPionMassInMeV;//Charged pion mass
77  }
78  const double ekin = m_d->thehit->GetKineticEnergy()*CLHEP::MeV;
79  const double gamma = 1.0 + ekin/mass;
80  double betasq = 1.0-1.0/(gamma*gamma);
81  if (betasq<=0.0)
82  return 0.0;
83  return sqrt(betasq)*(mass+ekin);
84 }
85 
86 //____________________________________________________________________
88 {
89  if (detelem)
90  return true;
92  if (!mgr) {
93  VP1Msg::messageDebug("SimHitHandle_TRTHit ERROR: Could not get TRT detector manager.");
94  return false;
95  }
96  size_t hitID = thehit->GetHitID(), moduleID(0), trtID(0),sectorID(0);
97  static const size_t mask = 0x1F;
98  static const size_t shift = 5;
99  std::bitset<32> idBits(hitID);
100  if (!idBits[21]/*IE: BARREL*/ ) {
101  size_t layerID(0), ringID(0);
102  strawID = hitID & mask;
103  hitID >>= shift;
104  layerID = hitID & mask;
105  hitID >>= shift;
106  moduleID = hitID & mask;
107  hitID >>= shift;
108  ringID = hitID & mask;
109  trtID = hitID >> shift;
110  detelem = mgr->getBarrelElement(trtID,ringID,moduleID,layerID);//fixme: handle case
111  }
112  else /*ENDCAP*/ {
113  size_t wheelID(0), planeID(0);
114  strawID = hitID & mask;
115  hitID >>= shift;
116  planeID = hitID & mask;
117  hitID >>= shift;
118  sectorID = hitID & mask;
119  hitID >>= shift;
120  wheelID = hitID & mask;
121  trtID = hitID >> shift;
122  bool isPositive = (trtID==2);
123  detelem = mgr->getEndcapElement(isPositive,wheelID,planeID,sectorID);
124  }
125  if (detelem) {
126  return true;
127  } else {
128  VP1Msg::messageDebug("SimHitHandle_TRTHit WARNING: Could not find detector element.");
129  return false;
130  }
131 }
132 
133 //____________________________________________________________________
135 {
136  if (!m_d->ensureDetElemInit())
137  return Amg::Vector3D(0,0,0);
139 }
140 
141 //____________________________________________________________________
143 {
144  if (!m_d->ensureDetElemInit())
145  return Amg::Vector3D(0,0,0);
147 }
148 
149 //____________________________________________________________________
151 {
152  return m_d->thehit->GetGlobalTime();
153 }
154 
155 //____________________________________________________________________
157 {
158  return m_d->thehit->particleLink();
159 }
160 
161 //____________________________________________________________________
163 {
164  return m_d->thehit->GetParticleEncoding();
165 }
166 
167 //____________________________________________________________________
169 {
170  if (!m_d->ensureDetElemInit())
171  return nullptr;
172  const Trk::StraightLineSurface * surf
173  = dynamic_cast<const Trk::StraightLineSurface *>( &(m_d->detelem->strawSurface(m_d->strawID)));
174  if (!surf) {
175  VP1Msg::message("SimHitHandle_TRTHit::createTrackParameters ERROR: could not get Trk::StraightLineSurface");
176  return nullptr;
177  }
178 
179  double c;
180  if ( !hasCharge() ) {
181  bool ok;
183  if (!ok) {
184  VP1Msg::message("SimHitHandle_TRTHit::createTrackParameters ERROR: Could not find particle charge (pdg="
185  +QString::number(m_d->thehit->GetParticleEncoding())+"). Assuming charge=+1.");
186  c = +1.0;
187  } else {
188  if (VP1Msg::verbose())
189  VP1Msg::messageVerbose("Looked up particle charge for trt simhit with pdg code "+VP1Msg::str(m_d->thehit->GetParticleEncoding())+": "+VP1Msg::str(c));
190  }
191  const_cast<SimHitHandle_TRTHit*>(this)->setCharge(c);
192  } else {
193  c = charge();
194  }
195  return new Trk::AtaStraightLine(0.5*(posStart()+posEnd()),momentum()*momentumDirection(),c,*surf);
196  //Fixme: Use constructor with local coords instead?:
197 }
SimHitHandle_TRTHit::actualPDGCodeFromSimHit
int actualPDGCodeFromSimHit() const
Definition: SimHitHandle_TRTHit.cxx:162
SimHitHandle_TRTHit::m_d
Imp * m_d
Definition: SimHitHandle_TRTHit.h:43
TRTUncompressedHit::GetHitID
int GetHitID() const
Definition: TRTUncompressedHit.h:42
SimHitHandle_TRTHit
Definition: SimHitHandle_TRTHit.h:23
StraightLineSurface.h
TrackParameters.h
SimHitHandle_TRTHit::~SimHitHandle_TRTHit
virtual ~SimHitHandle_TRTHit()
Definition: SimHitHandle_TRTHit.cxx:51
TRT_DetectorManager.h
Surface.h
TRTUncompressedHit::GetPreStepY
float GetPreStepY() const
Definition: TRTUncompressedHit.h:67
Base_Fragment.mass
mass
Definition: Sherpa_i/share/common/Base_Fragment.py:59
VP1Msg.h
SimHitHandle_TRTHit::actualMomentum
double actualMomentum() const
Definition: SimHitHandle_TRTHit.cxx:69
TRTUncompressedHit::GetParticleEncoding
int GetParticleEncoding() const
Definition: TRTUncompressedHit.h:55
SimHitHandle_TRTHit::momentumDirection
Amg::Vector3D momentumDirection() const
Definition: SimHitHandle_TRTHit.cxx:59
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
TRTUncompressedHit
Definition: TRTUncompressedHit.h:11
VP1ParticleData.h
TRTUncompressedHit::GetPostStepY
float GetPostStepY() const
Definition: TRTUncompressedHit.h:76
VP1String::str
static QString str(const QString &s)
Definition: VP1String.h:49
TRTUncompressedHit::GetGlobalTime
float GetGlobalTime() const
Definition: TRTUncompressedHit.h:82
TRTUncompressedHit::GetPreStepZ
float GetPreStepZ() const
Definition: TRTUncompressedHit.h:70
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
python.utils.AtlRunQueryLookup.mask
string mask
Definition: AtlRunQueryLookup.py:459
python.SystemOfUnits.MeV
float MeV
Definition: SystemOfUnits.py:172
Trk::AtaStraightLine
ParametersT< TrackParametersDim, Charged, StraightLineSurface > AtaStraightLine
Definition: Tracking/TrkEvent/TrkParameters/TrkParameters/TrackParameters.h:35
BchCleanup.mgr
mgr
Definition: BchCleanup.py:294
VP1DetInfo.h
ParticleConstants::PDG2011::chargedPionMassInMeV
constexpr double chargedPionMassInMeV
the mass of the charged pion (in MeV)
Definition: ParticleConstants.h:41
SimHitHandleBase::setCharge
void setCharge(const double &c)
Definition: SimHitHandleBase.h:57
SimHitHandle_TRTHit::SimHitHandle_TRTHit
SimHitHandle_TRTHit(const TRTUncompressedHit *)
Definition: SimHitHandle_TRTHit.cxx:43
TrigVtx::gamma
@ gamma
Definition: TrigParticleTable.h:27
ParticleConstants.h
TRTUncompressedHit::GetKineticEnergy
float GetKineticEnergy() const
Definition: TRTUncompressedHit.h:58
SimHitHandle_TRTHit::Imp::ensureDetElemInit
bool ensureDetElemInit() const
Definition: SimHitHandle_TRTHit.cxx:87
VP1ParticleData::particleCharge
static double particleCharge(const int &pdgcode, bool &ok)
Definition: VP1ParticleData.cxx:103
InDetDD::TRT_BaseElement::getAbsoluteTransform
const HepGeom::Transform3D getAbsoluteTransform(int straw) const
This is an alias to strawTransform(int straw)
Definition: TRT_BaseElement.cxx:42
SimHitHandle_TRTHit::createTrackParameters
Trk::TrackParameters * createTrackParameters() const
Definition: SimHitHandle_TRTHit.cxx:168
Trk::ParametersBase
Definition: ParametersBase.h:55
SimHitHandleBase::momentum
double momentum() const
Definition: SimHitHandleBase.h:41
SimHitHandle_TRTHit::hitTime
double hitTime() const
Definition: SimHitHandle_TRTHit.cxx:150
CLHEPtoEigenConverter.h
TRT_BaseElement.h
SimHitHandle_TRTHit::Imp
Definition: SimHitHandle_TRTHit.cxx:32
python.selection.number
number
Definition: selection.py:20
VP1Msg::messageVerbose
static void messageVerbose(const QString &)
Definition: VP1Msg.cxx:84
SimHitHandle_TRTHit::posEnd
Amg::Vector3D posEnd() const
Definition: SimHitHandle_TRTHit.cxx:142
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
InDetDD::TRT_DetectorManager
The Detector Manager for all TRT Detector elements, it acts as the interface to the detector elements...
Definition: TRT_DetectorManager.h:63
SimHitHandleBase::pdg
int pdg() const
Definition: SimHitHandleBase.h:82
TRTUncompressedHit::GetPreStepX
float GetPreStepX() const
Definition: TRTUncompressedHit.h:64
VP1Msg::messageDebug
static void messageDebug(const QString &)
Definition: VP1Msg.cxx:39
h
TRTUncompressedHit.h
SimHitHandle_TRTHit::Imp::thehit
const TRTUncompressedHit * thehit
Definition: SimHitHandle_TRTHit.cxx:35
SimHitHandle_TRTHit::particleLink
const HepMcParticleLink & particleLink() const
Definition: SimHitHandle_TRTHit.cxx:156
VP1Msg::message
static void message(const QString &, IVP1System *sys=0)
Definition: VP1Msg.cxx:30
Amg::CLHEPTransformToEigen
Amg::Transform3D CLHEPTransformToEigen(const HepGeom::Transform3D &CLHEPtransf)
Converts a CLHEP-based HepGeom::Transform3D into an Eigen Amg::Transform3D.
Definition: CLHEPtoEigenConverter.h:38
VP1DetInfo::trtDetMgr
static const InDetDD::TRT_DetectorManager * trtDetMgr()
Definition: VP1DetInfo.cxx:147
SimHitHandleBase::hasCharge
bool hasCharge() const
Definition: SimHitHandleBase.h:50
unit
const PlainObject unit() const
This is a plugin that makes Eigen look like CLHEP & defines some convenience methods.
Definition: AmgMatrixBasePlugin.h:21
SimHitHandle_TRTHit.h
VP1ParticleData::particleMass
static double particleMass(const int &pdgcode, bool &ok)
Definition: VP1ParticleData.cxx:83
TRTUncompressedHit::GetPostStepX
float GetPostStepX() const
Definition: TRTUncompressedHit.h:73
SimHitHandleBase
Definition: SimHitHandleBase.h:32
InDetDD::TRT_BaseElement::strawSurface
const Trk::StraightLineSurface & strawSurface(int straw) const
Straw Surface: access to the surface via integer.
Definition: TRT_BaseElement.cxx:121
SimHitHandleBase::charge
double charge() const
Definition: SimHitHandleBase.h:51
VP1Msg::verbose
static bool verbose()
Definition: VP1Msg.h:31
SimHitHandle_TRTHit::Imp::strawID
size_t strawID
Definition: SimHitHandle_TRTHit.cxx:37
SimHitHandle_TRTHit::Imp::Imp
Imp(const TRTUncompressedHit *h)
Definition: SimHitHandle_TRTHit.cxx:34
SimHitHandle_TRTHit::posStart
Amg::Vector3D posStart() const
Definition: SimHitHandle_TRTHit.cxx:134
TRTUncompressedHit::particleLink
const HepMcParticleLink & particleLink() const
Definition: TRTUncompressedHit.h:109
python.compressB64.c
def c
Definition: compressB64.py:93
SimHitHandle_TRTHit::Imp::detelem
const InDetDD::TRT_BaseElement * detelem
Definition: SimHitHandle_TRTHit.cxx:36
Trk::StraightLineSurface
Definition: StraightLineSurface.h:51
InDetDD::TRT_BaseElement
Definition: TRT_BaseElement.h:52
TRTUncompressedHit::GetPostStepZ
float GetPostStepZ() const
Definition: TRTUncompressedHit.h:79