ATLAS Offline Software
Loading...
Searching...
No Matches
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//____________________________________________________________________
33public:
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//____________________________________________________________________
55
56
57//____________________________________________________________________
58//Trk::GlobalMomentum SimHitHandle_TRTHit::momentumDirection() const
60{
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;
72 double mass = VP1ParticleData::particleMass(m_d->thehit->GetParticleEncoding(),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);
138 return Amg::CLHEPTransformToEigen(m_d->detelem->getAbsoluteTransform(m_d->strawID)) * Amg::Vector3D(m_d->thehit->GetPreStepX(),m_d->thehit->GetPreStepY(),m_d->thehit->GetPreStepZ());
139}
140
141//____________________________________________________________________
143{
144 if (!m_d->ensureDetElemInit())
145 return Amg::Vector3D(0,0,0);
146 return Amg::CLHEPTransformToEigen(m_d->detelem->getAbsoluteTransform(m_d->strawID)) * Amg::Vector3D(m_d->thehit->GetPostStepX(),m_d->thehit->GetPostStepY(),m_d->thehit->GetPostStepZ());
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;
182 c = VP1ParticleData::particleCharge(m_d->thehit->GetParticleEncoding(),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}
const PlainObject unit() const
This is a plugin that makes Eigen look like CLHEP & defines some convenience methods.
A number of constexpr particle constants to avoid hardcoding them directly in various places.
Header file for AthHistogramAlgorithm.
Virtual base class of TRT readout elements.
The Detector Manager for all TRT Detector elements, it acts as the interface to the detector elements...
double charge() const
void setCharge(const double &c)
bool hasCharge() const
double momentum() const
const TRTUncompressedHit * thehit
Imp(const TRTUncompressedHit *h)
const InDetDD::TRT_BaseElement * detelem
const HepMcParticleLink & particleLink() const
Trk::TrackParameters * createTrackParameters() const
SimHitHandle_TRTHit(const TRTUncompressedHit *)
Amg::Vector3D posStart() const
Amg::Vector3D momentumDirection() const
Amg::Vector3D posEnd() const
Class for a StraightLineSurface in the ATLAS detector to describe dirft tube and straw like detectors...
static const InDetDD::TRT_DetectorManager * trtDetMgr()
static void messageVerbose(const QString &)
Definition VP1Msg.cxx:84
static bool verbose()
Definition VP1Msg.h:31
static void messageDebug(const QString &)
Definition VP1Msg.cxx:39
static void message(const QString &, IVP1System *sys=0)
Definition VP1Msg.cxx:30
static double particleMass(const int &pdgcode, bool &ok)
static double particleCharge(const int &pdgcode, bool &ok)
static QString str(const QString &s)
Definition VP1String.h:49
Amg::Transform3D CLHEPTransformToEigen(const HepGeom::Transform3D &CLHEPtransf)
Converts a CLHEP-based HepGeom::Transform3D into an Eigen Amg::Transform3D.
Eigen::Matrix< double, 3, 1 > Vector3D
constexpr double chargedPionMassInMeV
the mass of the charged pion (in MeV)
ParametersT< TrackParametersDim, Charged, StraightLineSurface > AtaStraightLine
ParametersBase< TrackParametersDim, Charged > TrackParameters