ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
graphics
VP1
VP1Systems
VP1TrackSystems
src
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
15
#include "
VP1TrackSystems/SimHitHandle_TRTHit.h
"
16
#include "
VP1Utils/VP1DetInfo.h
"
17
#include "
VP1Utils/VP1ParticleData.h
"
18
#include "
VP1Base/VP1Msg.h
"
19
20
#include "
InDetSimEvent/TRTUncompressedHit.h
"
21
#include "
TRT_ReadoutGeometry/TRT_BaseElement.h
"
22
#include "
TRT_ReadoutGeometry/TRT_DetectorManager.h
"
23
#include "
TrkSurfaces/StraightLineSurface.h
"
24
#include "
TrkSurfaces/Surface.h
"
25
#include "
TrkParameters/TrackParameters.h
"
26
#include "
GeoPrimitives/CLHEPtoEigenConverter.h
"
27
#include "
TruthUtils/ParticleConstants.h
"
28
29
#include <bitset>
30
31
//____________________________________________________________________
32
class
SimHitHandle_TRTHit::Imp
{
33
public
:
34
Imp
(
const
TRTUncompressedHit
*
h
) :
thehit
(
h
),
detelem
(nullptr),
strawID
(0) {}
35
const
TRTUncompressedHit
*
thehit
;
36
mutable
const
InDetDD::TRT_BaseElement
*
detelem
;
37
mutable
size_t
strawID
;
38
bool
ensureDetElemInit
()
const
;
39
};
40
41
42
//____________________________________________________________________
43
SimHitHandle_TRTHit::SimHitHandle_TRTHit
(
const
TRTUncompressedHit
*
h
)
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
//____________________________________________________________________
51
SimHitHandle_TRTHit::~SimHitHandle_TRTHit
()
52
{
53
delete
m_d
;
54
}
55
56
57
//____________________________________________________________________
58
//Trk::GlobalMomentum SimHitHandle_TRTHit::momentumDirection() const
59
Amg::Vector3D
SimHitHandle_TRTHit::momentumDirection
()
const
60
{
61
if
(
VP1Msg::verbose
()&&
posStart
()==
posEnd
())
62
VP1Msg::messageVerbose
(
"SimHitHandle_SiHit::momentumDirection() ERROR: posStart()==posEnd()"
);
63
Amg::Vector3D
u((
posEnd
()-
posStart
()).
unit
());
64
// return Trk::GlobalMomentum(u.x(),u.y(),u.z());
65
return
Amg::Vector3D
(u.x(),u.y(),u.z());
66
}
67
68
//____________________________________________________________________
69
double
SimHitHandle_TRTHit::actualMomentum
()
const
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
//____________________________________________________________________
87
bool
SimHitHandle_TRTHit::Imp::ensureDetElemInit
()
const
88
{
89
if
(
detelem
)
90
return
true
;
91
const
InDetDD::TRT_DetectorManager
* mgr =
VP1DetInfo::trtDetMgr
();
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
//____________________________________________________________________
134
Amg::Vector3D
SimHitHandle_TRTHit::posStart
()
const
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
//____________________________________________________________________
142
Amg::Vector3D
SimHitHandle_TRTHit::posEnd
()
const
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
//____________________________________________________________________
150
double
SimHitHandle_TRTHit::hitTime
()
const
151
{
152
return
m_d
->thehit->GetGlobalTime();
153
}
154
155
//____________________________________________________________________
156
const
HepMcParticleLink
&
SimHitHandle_TRTHit::particleLink
()
const
157
{
158
return
m_d
->thehit->particleLink();
159
}
160
161
//____________________________________________________________________
162
int
SimHitHandle_TRTHit::actualPDGCodeFromSimHit
()
const
163
{
164
return
m_d
->thehit->GetParticleEncoding();
165
}
166
167
//____________________________________________________________________
168
Trk::TrackParameters
*
SimHitHandle_TRTHit::createTrackParameters
()
const
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
}
CLHEPtoEigenConverter.h
unit
detray::unit< scalar_t > unit
Definition
DeviceTrackFindingAlg.cxx:17
ParticleConstants.h
A number of constexpr particle constants to avoid hardcoding them directly in various places.
SimHitHandle_TRTHit.h
StraightLineSurface.h
Surface.h
TRTUncompressedHit.h
TRT_BaseElement.h
TRT_DetectorManager.h
TrackParameters.h
VP1DetInfo.h
VP1Msg.h
VP1ParticleData.h
h
Header file for AthHistogramAlgorithm.
HepMcParticleLink
a link optimized in size for a GenParticle in a McEventCollection
Definition
HepMcParticleLink.h:72
InDetDD::TRT_BaseElement
Virtual base class of TRT readout elements.
Definition
TRT_BaseElement.h:56
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::charge
double charge() const
Definition
SimHitHandleBase.h:51
SimHitHandleBase::setCharge
void setCharge(const double &c)
Definition
SimHitHandleBase.h:57
SimHitHandleBase::pdg
int pdg() const
Definition
SimHitHandleBase.h:82
SimHitHandleBase::SimHitHandleBase
SimHitHandleBase()
Definition
SimHitHandleBase.h:34
SimHitHandleBase::hasCharge
bool hasCharge() const
Definition
SimHitHandleBase.h:50
SimHitHandleBase::momentum
double momentum() const
Definition
SimHitHandleBase.h:41
SimHitHandle_TRTHit::Imp
Definition
SimHitHandle_TRTHit.cxx:32
SimHitHandle_TRTHit::Imp::thehit
const TRTUncompressedHit * thehit
Definition
SimHitHandle_TRTHit.cxx:35
SimHitHandle_TRTHit::Imp::Imp
Imp(const TRTUncompressedHit *h)
Definition
SimHitHandle_TRTHit.cxx:34
SimHitHandle_TRTHit::Imp::detelem
const InDetDD::TRT_BaseElement * detelem
Definition
SimHitHandle_TRTHit.cxx:36
SimHitHandle_TRTHit::Imp::strawID
size_t strawID
Definition
SimHitHandle_TRTHit.cxx:37
SimHitHandle_TRTHit::Imp::ensureDetElemInit
bool ensureDetElemInit() const
Definition
SimHitHandle_TRTHit.cxx:87
SimHitHandle_TRTHit::hitTime
double hitTime() const
Definition
SimHitHandle_TRTHit.cxx:150
SimHitHandle_TRTHit::particleLink
const HepMcParticleLink & particleLink() const
Definition
SimHitHandle_TRTHit.cxx:156
SimHitHandle_TRTHit::createTrackParameters
Trk::TrackParameters * createTrackParameters() const
Definition
SimHitHandle_TRTHit.cxx:168
SimHitHandle_TRTHit::SimHitHandle_TRTHit
SimHitHandle_TRTHit(const TRTUncompressedHit *)
Definition
SimHitHandle_TRTHit.cxx:43
SimHitHandle_TRTHit::~SimHitHandle_TRTHit
virtual ~SimHitHandle_TRTHit()
Definition
SimHitHandle_TRTHit.cxx:51
SimHitHandle_TRTHit::actualPDGCodeFromSimHit
int actualPDGCodeFromSimHit() const
Definition
SimHitHandle_TRTHit.cxx:162
SimHitHandle_TRTHit::posStart
Amg::Vector3D posStart() const
Definition
SimHitHandle_TRTHit.cxx:134
SimHitHandle_TRTHit::actualMomentum
double actualMomentum() const
Definition
SimHitHandle_TRTHit.cxx:69
SimHitHandle_TRTHit::momentumDirection
Amg::Vector3D momentumDirection() const
Definition
SimHitHandle_TRTHit.cxx:59
SimHitHandle_TRTHit::posEnd
Amg::Vector3D posEnd() const
Definition
SimHitHandle_TRTHit.cxx:142
SimHitHandle_TRTHit::m_d
Imp * m_d
Definition
SimHitHandle_TRTHit.h:44
TRTUncompressedHit
Definition
TRTUncompressedHit.h:11
Trk::StraightLineSurface
Class for a StraightLineSurface in the ATLAS detector to describe dirft tube and straw like detectors...
Definition
StraightLineSurface.h:51
VP1DetInfo::trtDetMgr
static const InDetDD::TRT_DetectorManager * trtDetMgr()
Definition
VP1DetInfo.cxx:147
VP1Msg::messageVerbose
static void messageVerbose(const QString &)
Definition
VP1Msg.cxx:84
VP1Msg::verbose
static bool verbose()
Definition
VP1Msg.h:31
VP1Msg::messageDebug
static void messageDebug(const QString &)
Definition
VP1Msg.cxx:39
VP1Msg::message
static void message(const QString &, IVP1System *sys=0)
Definition
VP1Msg.cxx:30
VP1ParticleData::particleMass
static double particleMass(const int &pdgcode, bool &ok)
Definition
VP1ParticleData.cxx:42
VP1ParticleData::particleCharge
static double particleCharge(const int &pdgcode, bool &ok)
Definition
VP1ParticleData.cxx:59
VP1String::str
static QString str(const QString &s)
Definition
VP1String.h:49
Amg::CLHEPTransformToEigen
Amg::Transform3D CLHEPTransformToEigen(const HepGeom::Transform3D &CLHEPtransf)
Converts a CLHEP-based HepGeom::Transform3D into an Eigen Amg::Transform3D.
Definition
CLHEPtoEigenConverter.h:38
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition
GeoPrimitives.h:48
ParticleConstants::PDG2011::chargedPionMassInMeV
constexpr double chargedPionMassInMeV
the mass of the charged pion (in MeV)
Definition
ParticleConstants.h:41
Trk::AtaStraightLine
ParametersT< TrackParametersDim, Charged, StraightLineSurface > AtaStraightLine
Definition
Tracking/TrkEvent/TrkParameters/TrkParameters/TrackParameters.h:35
Trk::TrackParameters
ParametersBase< TrackParametersDim, Charged > TrackParameters
Definition
Tracking/TrkEvent/TrkParameters/TrkParameters/TrackParameters.h:27
Generated on
for ATLAS Offline Software by
1.17.0