ATLAS Offline Software
TRT_BarrelElement.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "Identifier/Identifier.h"
9 
12 
13 #include "InDetIdentifier/TRT_ID.h"
14 
17 
19 
21 
22 
23 namespace InDetDD {
24 
25 TRT_BarrelElement::TRT_BarrelElement(const GeoVFullPhysVol* volume,
26  const TRT_BarrelDescriptor* descriptor,
27  bool isPositive,
28  unsigned int modIndex,
29  unsigned int phiIndex,
30  unsigned int strawLayIndex,
31  const TRT_ID* idHelper,
32  const TRT_Conditions* conditions)
33  : TRT_BaseElement(volume,
34  idHelper->layer_id((isPositive ? 1 : -1),
35  phiIndex,
36  modIndex,
37  strawLayIndex),
38  idHelper,
39  conditions)
40  , m_code(isPositive, modIndex, phiIndex, strawLayIndex)
41  , m_descriptor(descriptor)
42  , m_nextInPhi(nullptr)
43  , m_previousInPhi(nullptr)
44  , m_nextInR(nullptr)
45  , m_previousInR(nullptr)
46 
47 {
49  m_strawSurfaces.resize(m_nstraws);
51 }
52 
54  : TRT_BaseElement(right)
55  , m_code(right.m_code)
56  , m_descriptor(right.m_descriptor)
57  , m_nextInPhi(right.m_nextInPhi)
58  , m_previousInPhi(right.m_previousInPhi)
59  , m_nextInR(right.m_nextInR)
60  , m_previousInR(right.m_previousInR)
61 {
62  m_nstraws = right.m_nstraws;
63  m_strawSurfaces.resize(m_nstraws);
65 }
66 
67 const TRT_BarrelConditions * TRT_BarrelElement::getConditionsData()
68 {
69  return nullptr;
70 }
71 
73 {
74  return m_descriptor;
75 }
76 
78 {
79  m_nextInPhi=element;
80 }
81 
83 {
84  m_previousInPhi=element;
85 }
86 
88 {
89  m_nextInR=element;
90 }
91 
93 {
94  m_previousInR=element;
95 }
96 
97 
98 
100 {
101  // NB The tranformation to a straw is reconstructed here precisely as
102  // it was ... hopefully... in the factory. One could eliminate this
103  // requirement and make the code a little more robust in this regard but
104  // at the cost of doubling the descriptors. (One descriptor now suffices
105  // for both positive and negative endcaps).
106  //std::cout << "In calculateStrawTransform" << std::endl;
107 
108  const GeoXF::Function *f= m_descriptor->getStrawTransform();
109  if (f) {
110  size_t offsetInto = m_descriptor->getStrawTransformOffset();
111  double zPos = -m_descriptor->strawZPos();
112  double zAng = m_code.isPosZ() ? M_PI : 0;
113  return Amg::EigenTransformToCLHEP(getMaterialGeom()->getAbsoluteTransform()*((*f)(straw+offsetInto)))
114  * HepGeom::RotateY3D(zAng)*HepGeom::TranslateZ3D(zPos)
120  } else {
121  std::cout << "calculateStrawTransform: f is 0 !!!!" << std::endl;
122  return {};
123  }
124 }
125 
127 {
128  const TRTCond::StrawDxContainer* container = conditions()->dxContainer();
130  if(!container) {
131  // std::cout << " TRT_BarrelElement: no local transform found " << std::endl;
132  } else {
133  // important note: dx1 moves the 'negative' wire endpoint end dx2
134  // the 'positive' wire endpoint in the local straw frame. In the
135  // global frame, 'dx1' corresponds to the readout side and 'dx2'
136  // to the wire joint side for both sides of the barrel.
137 
138  int bec = getCode().isPosZ() ? +1 : -1 ;
139  int layer = getCode().getModuleIndex();
140  int phimodule = getCode().getPhiIndex();
141  int strawlayer = getCode().getStrawLayerIndex();
143  (bec,layer,phimodule,strawlayer,straw,TRTCond::ExpandedIdentifier::STRAW);
144  double dx1 = container->getDx1(id);
145  double dx2 = container->getDx2(id);
146  double ang = (dx2-dx1)/strawLength();
147  double dx = (dx2+dx1)/2.;
148  rc = HepGeom::TranslateX3D(dx)*HepGeom::RotateY3D(ang) ;
149  }
150  return rc ;
151 }
152 
154 {
155  return m_descriptor->strawBounds();
156 }
157 
159 {
160  if (not m_surface) {
161  m_surface.set(std::make_unique<Trk::PlaneSurface>(*this));
162  }
163  return *m_surface;
164 }
165 
167 {
168  // create the surface cache
169  if (!m_surfaceCache.isValid()) {
171  }
172  // creaete the surface (only if needed, links are still ok even if cache
173  // update)
174  if (!m_surface) {
175  elementSurface();
176  }
177 }
180 
181  // Calculate the surface from the two end straws.
182  int firstStraw = 0;
183  int lastStraw = nStraws() - 1;
184 
185  const Amg::Vector3D& centerFirstStraw =
186  center(m_idHelper->straw_id(identify(), firstStraw));
187  const Amg::Vector3D& centerLastStraw =
188  center(m_idHelper->straw_id(identify(), lastStraw));
189 
190  // Calculate center as the average position of the end straws.
191  auto center = Amg::Vector3D(0.5 * (centerFirstStraw + centerLastStraw));
192 
193  Amg::Vector3D phiAxis = centerLastStraw - centerFirstStraw;
194  double width = phiAxis.mag();
195  phiAxis = phiAxis.normalized();
196  double elementWidth =
197  width + 2 * m_descriptor->innerTubeRadius(); // Add the straw tube radius
198 
199  // Get local z-axis. This is roughly in +ve global z direction (exactly if no
200  // misalignment) We could probably use any straw for this but we average the
201  // first and last straw and renormalize to a unit vector.
202  Amg::Vector3D etaAxis = 0.5 * (strawAxis(firstStraw) + strawAxis(lastStraw));
203  etaAxis = etaAxis.normalized();
204 
205  // Calculate normal. This will point away from the beam line based
206  // on the assumption that the straw numbering goes in the direction
207  // of increasing phi and the straw axis is in +ve z direction.
208  auto normal = Amg::Vector3D(phiAxis.cross(etaAxis)); // phi cross z
209 
210  // Transform from local to global.
211  // local x axis -> phiAxis
212  // local y axis -> etaAxis
213  // local z axis -> cross product of local x and local y
214  // translation -> center
215 
217  rotation.col(0) = phiAxis;
218  rotation.col(1) = etaAxis;
219  rotation.col(2) = normal;
220 
221  // This constructor takes three points in the two coordinate systems.
223 
224  // create the element bounds
225  auto elementBounds = std::make_unique<Trk::RectangleBounds>(
226  0.5 * elementWidth, 0.5 * strawLength());
227 
228  return { transform, center, normal, std::move(elementBounds) };
229 }
230 
232 {
233  // Return +1 if the straw local axis is in the same direction as the z axis, -1 otherwise.
234  // The straw axis by convention goes in the direction away from the readout.
235  // So for -ve endcap this is the positive z direction (we return +1) and in the
236  // +ve endcap its in the -ve z direction (we return -1).
237  //
238  return !(m_code.isPosZ()) ? +1 : -1;
239 }
240 
241 
242 } // end namespace
InDetDD::TRT_BarrelElement::m_nextInPhi
const TRT_BarrelElement * m_nextInPhi
Definition: TRT_BarrelElement.h:139
InDetDD::TRT_BarrelElement
Definition: TRT_BarrelElement.h:44
TRT::Hit::straw
@ straw
Definition: HitInfo.h:82
InDetDD::TRT_BarrelElement::setPreviousInR
void setPreviousInR(const TRT_BarrelElement *element)
Sets the previous-in-r detector.
Definition: TRT_BarrelElement.cxx:92
InDetDD::TRT_BarrelElement::createSurfaceCache
virtual void createSurfaceCache() const override
create the cache for the element
Definition: TRT_BarrelElement.cxx:166
RectangleBounds.h
ParticleGun_SamplingFraction.bec
int bec
Definition: ParticleGun_SamplingFraction.py:89
InDetDD::TRT_BarrelDescriptor::getStrawTransformOffset
size_t getStrawTransformOffset() const
Get the offset into the transformation field:
Trk::SurfaceBounds
Definition: SurfaceBounds.h:47
InDetDD::TRT_BaseElement::nStraws
unsigned int nStraws() const
Number of straws in the element.
InDetDD::TRT_BarrelElement::calculateStrawTransform
virtual HepGeom::Transform3D calculateStrawTransform(int straw) const override
These transforms are effectively to the local coord system of a straw derived from GeoModel -> hence ...
Definition: TRT_BarrelElement.cxx:99
InDetDD::TRT_BarrelDescriptor
Definition: TRT_BarrelDescriptor.h:40
InDetDD::TRT_BaseElement::strawAxis
Amg::Vector3D strawAxis(int straw) const
Straw axis.
Definition: TRT_BaseElement.cxx:154
InDetDD::TRT_BarrelElement::m_nextInR
const TRT_BarrelElement * m_nextInR
Definition: TRT_BarrelElement.h:141
TRT_ID.h
This is an Identifier helper class for the TRT subdetector. This class is a factory for creating comp...
M_PI
#define M_PI
Definition: ActiveFraction.h:11
InDetDD::TRT_BarrelElement::strawBounds
virtual const Trk::SurfaceBounds & strawBounds() const override final
Surface bounds.
Definition: TRT_BarrelElement.cxx:153
InDetDD::TRT_BarrelElement::m_descriptor
const TRT_BarrelDescriptor * m_descriptor
Definition: TRT_BarrelElement.h:138
ExpandedIdentifier.h
InDetDD::TRT_Conditions
Definition: TRT_Conditions.h:30
InDetDD::TRT_BarrelDescriptor::innerTubeRadius
double innerTubeRadius() const
Get inner tube radius of the straw.
InDetDD::TRT_BarrelElement::setNextInPhi
void setNextInPhi(const TRT_BarrelElement *element)
Sets the next-in-phi detector.
Definition: TRT_BarrelElement.cxx:77
InDetDD::TRT_BarrelDescriptor::strawZPos
const double & strawZPos() const
Position of center of active region.
InDetDD::TRT_BarrelElement::setNextInR
void setNextInR(const TRT_BarrelElement *element)
Sets the next-in-r detector.
Definition: TRT_BarrelElement.cxx:87
InDetDD::TRT_BaseElement::m_nstraws
unsigned int m_nstraws
Definition: TRT_BaseElement.h:211
InDetDD::TRT_BarrelElement::m_previousInPhi
const TRT_BarrelElement * m_previousInPhi
Definition: TRT_BarrelElement.h:140
SurfaceCache.h
InDetDD::TRT_BaseElement::m_strawSurfaces
std::vector< CxxUtils::CachedUniquePtr< Trk::StraightLineSurface > > m_strawSurfaces
Definition: TRT_BaseElement.h:216
InDetDD::TRT_BarrelElement::getConditionsData
static const TRT_BarrelConditions * getConditionsData()
Returns a pointer to conditions data.
Definition: TRT_BarrelElement.cxx:67
InDetDD::TRT_BaseElement::m_surfaceCache
CxxUtils::CachedValue< SurfaceCache > m_surfaceCache
Definition: TRT_BaseElement.h:220
InDetDD::TRT_BarrelElement::createSurfaceCacheHelper
SurfaceCache createSurfaceCacheHelper() const
Definition: TRT_BarrelElement.cxx:179
InDetDD::TRT_BarrelElement::getDescriptor
const TRT_BarrelDescriptor * getDescriptor() const
Returns a pointer to a descriptor, giving common information on module construction:
Definition: TRT_BarrelElement.cxx:72
InDetDD::TRT_BarrelElement::strawLength
virtual const double & strawLength() const override final
Get the length of the straws (active length):
xAOD::rotation
rotation
Definition: TrackSurface_v1.cxx:15
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
InDetDD::TRT_BaseElement::m_idHelper
const TRT_ID * m_idHelper
Definition: TRT_BaseElement.h:212
InDetDD::TRT_BarrelElement::TRT_BarrelElement
TRT_BarrelElement(const GeoVFullPhysVol *volume, const TRT_BarrelDescriptor *descriptor, bool isPositive, unsigned int modIndex, unsigned int phiIndex, unsigned int strawLayIndex, const TRT_ID *idHelper, const TRT_Conditions *conditions)
Constructor:
Definition: TRT_BarrelElement.cxx:25
InDetDD::TRT_BarrelCode::getStrawLayerIndex
unsigned int getStrawLayerIndex() const
Definition: TRT_BarrelCode.h:98
InDetDD::TRT_BarrelDescriptor::getStrawTransform
const GeoXF::Function * getStrawTransform() const
Get the tranformation field, which we do not own: Does not include the z shift which is different for...
InDetDD::TRT_BaseElement::conditions
const TRT_Conditions * conditions() const
Return the TRT_Conditions object associated to this Detector element.
InDetDD::TRT_BaseElement::getAbsoluteTransform
const HepGeom::Transform3D getAbsoluteTransform(int straw) const
This is an alias to strawTransform(int straw)
Definition: TRT_BaseElement.cxx:42
InDetDD::TRT_BarrelElement::m_previousInR
const TRT_BarrelElement * m_previousInR
Definition: TRT_BarrelElement.h:142
InDetDD::TRT_BaseElement::identify
virtual Identifier identify() const override final
identifier of this detector element:
hist_file_dump.f
f
Definition: hist_file_dump.py:135
InDetDD::TRT_BarrelElement::calculateLocalStrawTransform
HepGeom::Transform3D calculateLocalStrawTransform(int straw) const
Definition: TRT_BarrelElement.cxx:126
InDetDD::TRT_BarrelCode::isPosZ
unsigned int isPosZ() const
Definition: TRT_BarrelCode.h:83
InDetDD::TRT_BarrelElement::getCode
const TRT_BarrelCode & getCode() const
Doomed (?):
TRT_BarrelElement.h
InDetDD::TRT_BarrelDescriptor::strawBounds
const Trk::SurfaceBounds & strawBounds() const
Get Bounds.
Definition: TRT_BarrelDescriptor.cxx:39
CLHEPtoEigenConverter.h
InDetDD::TRT_BarrelCode::getModuleIndex
unsigned int getModuleIndex() const
Definition: TRT_BarrelCode.h:88
GeoAlignmentStore.h
InDetDD::TRT_BaseElement::m_strawSurfacesCache
std::vector< CxxUtils::CachedUniquePtr< SurfaceCacheBase > > m_strawSurfacesCache
helper element surface for the cache
Definition: TRT_BaseElement.h:217
InDetDD::SurfaceCache
Definition: InnerDetector/InDetDetDescr/InDetReadoutGeometry/InDetReadoutGeometry/SurfaceCache.h:68
TRTCond::ExpandedIdentifier::STRAW
@ STRAW
Definition: InnerDetector/InDetConditions/TRT_ConditionsData/TRT_ConditionsData/ExpandedIdentifier.h:37
InDetDD::TRT_BarrelElement::strawDirection
virtual int strawDirection() const override final
StrawDirection.
Definition: TRT_BarrelElement.cxx:231
TRTCond::StrawDxContainer
Definition: StrawDxContainer.h:109
TRTCond::StrawDxContainerTemplate::getDx1
float getDx1(const ExpandedIdentifier &id) const
access to unpacked dx
Definition: StrawDxContainer.h:61
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
eflowRec::phiIndex
unsigned int phiIndex(float phi, float binsize)
calculate phi index for a given phi
Definition: EtaPhiLUT.cxx:23
TRT_ID
Definition: TRT_ID.h:84
Base_Fragment.width
width
Definition: Sherpa_i/share/common/Base_Fragment.py:59
InDetDD::TRT_BarrelElement::m_code
TRT_BarrelCode m_code
Definition: TRT_BarrelElement.h:137
InDetDD::TRT_BarrelElement::elementSurface
virtual const Trk::Surface & elementSurface() const override
return the surface of the element
Definition: TRT_BarrelElement.cxx:158
InDetDD
Message Stream Member.
Definition: FakeTrackBuilder.h:8
Amg::RotationMatrix3D
Eigen::Matrix< double, 3, 3 > RotationMatrix3D
Definition: GeoPrimitives.h:49
PlaneSurface.h
InDetDD::TRT_Conditions::dxContainer
const TRTCond::StrawDxContainer * dxContainer() const
Definition: TRT_Conditions.cxx:14
makeTRTBarrelCans.dx
tuple dx
Definition: makeTRTBarrelCans.py:20
Amg::Translation3D
Eigen::Translation< double, 3 > Translation3D
Definition: GeoPrimitives.h:44
InDetDD::TRT_BaseElement::center
virtual const Amg::Vector3D & center() const override final
Element Surface: center of a straw layer.
Amg::EigenTransformToCLHEP
HepGeom::Transform3D EigenTransformToCLHEP(const Amg::Transform3D &eigenTransf)
Converts an Eigen-based Amg::Transform3D into a CLHEP-based HepGeom::Transform3D.
Definition: CLHEPtoEigenConverter.h:120
InDetDD::TRT_BarrelElement::setPreviousInPhi
void setPreviousInPhi(const TRT_BarrelElement *element)
Sets the previous-in-phi detector.
Definition: TRT_BarrelElement.cxx:82
InDetDD::TRT_BaseElement::normal
virtual const Amg::Vector3D & normal() const override final
Element Surface: normal of a straw layer.
TRTCond::ExpandedIdentifier
Identifier for TRT detector elements in the conditions code.
Definition: InnerDetector/InDetConditions/TRT_ConditionsData/TRT_ConditionsData/ExpandedIdentifier.h:30
Trk::Surface
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:75
TRT_Conditions.h
InDetDD::TRT_BarrelCode::getPhiIndex
unsigned int getPhiIndex() const
Definition: TRT_BarrelCode.h:93
StrawDxContainer.h
Class for storing/accessing trt endpoint corrections data.
TRTCond::StrawDxContainerTemplate::getDx2
float getDx2(const ExpandedIdentifier &id) const
Definition: StrawDxContainer.h:65
InDetDD::TRT_BarrelDescriptor::nStraws
unsigned int nStraws() const
Get the number of straws:
InDetDD::TRT_BaseElement::m_surface
CxxUtils::CachedUniquePtr< Trk::Surface > m_surface
Definition: TRT_BaseElement.h:214
InDetDD::TRT_BaseElement
Definition: TRT_BaseElement.h:57
TRT_ID::straw_id
Identifier straw_id(int barrel_ec, int phi_module, int layer_or_wheel, int straw_layer, int straw) const
Three ways of getting id for a single straw:
Definition: TRT_ID.h:581
InDetDD::TRT_BaseElement::transform
virtual const Amg::Transform3D & transform() const override final
Element Surface: Get Transform of element in Tracking frame: Amg.