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"
27 
28 #include <bitset>
29 
30 //____________________________________________________________________
32 public:
33  Imp(const TRTUncompressedHit*h) : thehit(h), detelem(nullptr),strawID(0) {}
36  mutable size_t strawID;
37  bool ensureDetElemInit() const;
38 };
39 
40 
41 //____________________________________________________________________
43  : SimHitHandleBase(), m_d(new Imp(h))
44 {
45  if (!h)
46  VP1Msg::message("SimHitHandle_TRTHit constructor ERROR: Received null hit pointer");
47 }
48 
49 //____________________________________________________________________
51 {
52  delete m_d;
53 }
54 
55 
56 //____________________________________________________________________
57 //Trk::GlobalMomentum SimHitHandle_TRTHit::momentumDirection() const
59 {
60  if (VP1Msg::verbose()&&posStart()==posEnd())
61  VP1Msg::messageVerbose("SimHitHandle_SiHit::momentumDirection() ERROR: posStart()==posEnd()");
63 // return Trk::GlobalMomentum(u.x(),u.y(),u.z());
64  return Amg::Vector3D(u.x(),u.y(),u.z());
65 }
66 
67 //____________________________________________________________________
69 {
70  bool ok;
72  if (!ok) {
73  VP1Msg::message("SimHitHandle_TRTHit constructor WARNING: Could not determine mass for pdg code "
74  +QString::number(pdg())+". Assuming charged pion mass.");
75  mass = 139.57019*CLHEP::MeV;//Charged pion mass
76  }
77  const double ekin = m_d->thehit->GetKineticEnergy()*CLHEP::MeV;
78  const double gamma = 1.0 + ekin/mass;
79  double betasq = 1.0-1.0/(gamma*gamma);
80  if (betasq<=0.0)
81  return 0.0;
82  return sqrt(betasq)*(mass+ekin);
83 }
84 
85 //____________________________________________________________________
87 {
88  if (detelem)
89  return true;
91  if (!mgr) {
92  VP1Msg::messageDebug("SimHitHandle_TRTHit ERROR: Could not get TRT detector manager.");
93  return false;
94  }
95  size_t hitID = thehit->GetHitID(), moduleID(0), trtID(0),sectorID(0);
96  static const size_t mask = 0x1F;
97  static const size_t shift = 5;
98  std::bitset<32> idBits(hitID);
99  if (!idBits[21]/*IE: BARREL*/ ) {
100  size_t layerID(0), ringID(0);
101  strawID = hitID & mask;
102  hitID >>= shift;
103  layerID = hitID & mask;
104  hitID >>= shift;
105  moduleID = hitID & mask;
106  hitID >>= shift;
107  ringID = hitID & mask;
108  trtID = hitID >> shift;
109  detelem = mgr->getBarrelElement(trtID,ringID,moduleID,layerID);//fixme: handle case
110  }
111  else /*ENDCAP*/ {
112  size_t wheelID(0), planeID(0);
113  strawID = hitID & mask;
114  hitID >>= shift;
115  planeID = hitID & mask;
116  hitID >>= shift;
117  sectorID = hitID & mask;
118  hitID >>= shift;
119  wheelID = hitID & mask;
120  trtID = hitID >> shift;
121  bool isPositive = (trtID==2);
122  detelem = mgr->getEndcapElement(isPositive,wheelID,planeID,sectorID);
123  }
124  if (detelem) {
125  return true;
126  } else {
127  VP1Msg::messageDebug("SimHitHandle_TRTHit WARNING: Could not find detector element.");
128  return false;
129  }
130 }
131 
132 //____________________________________________________________________
134 {
135  if (!m_d->ensureDetElemInit())
136  return Amg::Vector3D(0,0,0);
138 }
139 
140 //____________________________________________________________________
142 {
143  if (!m_d->ensureDetElemInit())
144  return Amg::Vector3D(0,0,0);
146 }
147 
148 //____________________________________________________________________
150 {
151  return m_d->thehit->GetGlobalTime();
152 }
153 
154 //____________________________________________________________________
156 {
157  return m_d->thehit->particleLink();
158 }
159 
160 //____________________________________________________________________
162 {
163  return m_d->thehit->GetParticleEncoding();
164 }
165 
166 //____________________________________________________________________
168 {
169  if (!m_d->ensureDetElemInit())
170  return nullptr;
171  const Trk::StraightLineSurface * surf
172  = dynamic_cast<const Trk::StraightLineSurface *>( &(m_d->detelem->strawSurface(m_d->strawID)));
173  if (!surf) {
174  VP1Msg::message("SimHitHandle_TRTHit::createTrackParameters ERROR: could not get Trk::StraightLineSurface");
175  return nullptr;
176  }
177 
178  double c;
179  if ( !hasCharge() ) {
180  bool ok;
182  if (!ok) {
183  VP1Msg::message("SimHitHandle_TRTHit::createTrackParameters ERROR: Could not find particle charge (pdg="
184  +QString::number(m_d->thehit->GetParticleEncoding())+"). Assuming charge=+1.");
185  c = +1.0;
186  } else {
187  if (VP1Msg::verbose())
188  VP1Msg::messageVerbose("Looked up particle charge for trt simhit with pdg code "+VP1Msg::str(m_d->thehit->GetParticleEncoding())+": "+VP1Msg::str(c));
189  }
190  const_cast<SimHitHandle_TRTHit*>(this)->setCharge(c);
191  } else {
192  c = charge();
193  }
194  return new Trk::AtaStraightLine(0.5*(posStart()+posEnd()),momentum()*momentumDirection(),c,*surf);
195  //Fixme: Use constructor with local coords instead?:
196 }
SimHitHandle_TRTHit::actualPDGCodeFromSimHit
int actualPDGCodeFromSimHit() const
Definition: SimHitHandle_TRTHit.cxx:161
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:50
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:68
TRTUncompressedHit::GetParticleEncoding
int GetParticleEncoding() const
Definition: TRTUncompressedHit.h:55
python.SystemOfUnits.MeV
int MeV
Definition: SystemOfUnits.py:154
SimHitHandle_TRTHit::momentumDirection
Amg::Vector3D momentumDirection() const
Definition: SimHitHandle_TRTHit.cxx:58
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:460
Trk::AtaStraightLine
ParametersT< TrackParametersDim, Charged, StraightLineSurface > AtaStraightLine
Definition: Tracking/TrkEvent/TrkParameters/TrkParameters/TrackParameters.h:35
BchCleanup.mgr
mgr
Definition: BchCleanup.py:294
VP1DetInfo.h
SimHitHandleBase::setCharge
void setCharge(const double &c)
Definition: SimHitHandleBase.h:57
SimHitHandle_TRTHit::SimHitHandle_TRTHit
SimHitHandle_TRTHit(const TRTUncompressedHit *)
Definition: SimHitHandle_TRTHit.cxx:42
TrigVtx::gamma
@ gamma
Definition: TrigParticleTable.h:26
TRTUncompressedHit::GetKineticEnergy
float GetKineticEnergy() const
Definition: TRTUncompressedHit.h:58
SimHitHandle_TRTHit::Imp::ensureDetElemInit
bool ensureDetElemInit() const
Definition: SimHitHandle_TRTHit.cxx:86
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:167
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:149
CLHEPtoEigenConverter.h
TRT_BaseElement.h
SimHitHandle_TRTHit::Imp
Definition: SimHitHandle_TRTHit.cxx:31
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:141
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:69
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:34
SimHitHandle_TRTHit::particleLink
const HepMcParticleLink & particleLink() const
Definition: SimHitHandle_TRTHit.cxx:155
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:36
SimHitHandle_TRTHit::Imp::Imp
Imp(const TRTUncompressedHit *h)
Definition: SimHitHandle_TRTHit.cxx:33
SimHitHandle_TRTHit::posStart
Amg::Vector3D posStart() const
Definition: SimHitHandle_TRTHit.cxx:133
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:35
Trk::StraightLineSurface
Definition: StraightLineSurface.h:51
InDetDD::TRT_BaseElement
Definition: TRT_BaseElement.h:57
TRTUncompressedHit::GetPostStepZ
float GetPostStepZ() const
Definition: TRTUncompressedHit.h:79