Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
TrackingVolume.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 namespace Trk {
6 
7 inline const std::string&
8 TrackingVolume::volumeName() const
9 {
10  return m_name;
11 }
12 
13 inline unsigned int
14 TrackingVolume::layerAttempts(BoundarySurfaceFace exitFace) const
15 {
16  if (m_layerAttemptsCalculator)
17  return m_layerAttemptsCalculator->layerAttempts(exitFace);
18  return TRKGEOMETRY_MAXLAYERATTEMPTS;
19 }
20 
21 inline unsigned int
22 TrackingVolume::maxLayerAttempts() const
23 {
24  if (m_layerAttemptsCalculator){
25  return m_layerAttemptsCalculator->maxLayerAttempts();
26  }
27  return TRKGEOMETRY_MAXLAYERATTEMPTS;
28 }
29 
30 inline const LayerArray*
31 TrackingVolume::confinedLayers() const
32 {
33  return m_confinedLayers.get();
34 }
35 
36 inline LayerArray*
37 TrackingVolume::confinedLayers()
38 {
39  return m_confinedLayers.get();
40 }
41 
42 inline const TrackingVolumeArray*
43 TrackingVolume::confinedVolumes() const
44 {
45  return m_confinedVolumes.get();
46 }
47 
48 inline TrackingVolumeArray*
49 TrackingVolume::confinedVolumes()
50 {
51  return m_confinedVolumes.get();
52 }
53 
54 inline ArraySpan<Layer const* const>
55 TrackingVolume::confinedArbitraryLayers() const
56 {
57  if (m_confinedArbitraryLayers) {
58  return ArraySpan<Layer const* const>(m_confinedArbitraryLayers->begin(),
59  m_confinedArbitraryLayers->end());
60  }
61  return {};
62 }
63 
64 inline ArraySpan<Layer* const>
65 TrackingVolume::confinedArbitraryLayers()
66 {
67 
68  if (m_confinedArbitraryLayers) {
69  return ArraySpan<Layer* const>(m_confinedArbitraryLayers->begin(),
70  m_confinedArbitraryLayers->end());
71  }
72  return {};
73 }
74 
75 inline ArraySpan<DetachedTrackingVolume const * const>
76 TrackingVolume::confinedDetachedVolumes() const
77 {
78  if (m_confinedDetachedVolumes) {
79  return ArraySpan<DetachedTrackingVolume const* const>(
80  m_confinedDetachedVolumes->begin(), m_confinedDetachedVolumes->end());
81  }
82  return {};
83 }
84 
85 inline ArraySpan<DetachedTrackingVolume* const>
86 TrackingVolume::confinedDetachedVolumes()
87 {
88  if (m_confinedDetachedVolumes) {
89  return ArraySpan<DetachedTrackingVolume* const>(
90  m_confinedDetachedVolumes->begin(), m_confinedDetachedVolumes->end());
91  }
92  return {};
93 }
94 
95 inline ArraySpan<TrackingVolume const* const>
96 TrackingVolume::confinedDenseVolumes() const
97 {
98  if (m_confinedDenseVolumes) {
99  return ArraySpan<TrackingVolume const* const>(
100  m_confinedDenseVolumes->begin(), m_confinedDenseVolumes->end());
101  }
102  return {};
103 }
104 
105 inline ArraySpan<Trk::TrackingVolume* const>
106 TrackingVolume::confinedDenseVolumes()
107 {
108  if (m_confinedDenseVolumes) {
109  return ArraySpan<TrackingVolume* const>(m_confinedDenseVolumes->begin(),
110  m_confinedDenseVolumes->end());
111  }
112  return {};
113 }
114 
115 template<class T>
116 bool
117 TrackingVolume::onVolumeBoundary(const T& pars) const
118 {
119  // get the associated Surface
120  const Surface* pSurface = &pars.associatedSurface();
121  const auto& bSurfaces = boundarySurfaces();
122  // fast loop pointer comparison of the surfaces
123  for (size_t i = 0; i < bSurfaces.size(); ++i) {
124  const BoundarySurface<TrackingVolume>* bSurface = bSurfaces[i];
125  // pointer of the parameter surface is identical with one of the boundary
126  // surface pointers
127  if (pSurface == &bSurface->surfaceRepresentation())
128  return true;
129  }
130  // slow loop - checking the onSurface (does pointer comparison as well)
131  for (size_t i = 0; i < bSurfaces.size(); ++i) {
132  const BoundarySurface<TrackingVolume>* bSurface = bSurfaces[i];
133  // pointer of the parameter surface is identical with one of the boundary
134  // surface pointers
135  if (bSurface->onBoundary(pars))
136  return true;
137  }
138  // could not find an onSurface
139  return false;
140 }
141 
142 /** Return the material layers ordered based on straight line intersections
143  - start and end layer are always part of it
144 */
145 template<class T>
146 std::vector<LayerIntersection<T>>
147 TrackingVolume::materialLayersOrdered(const Layer* sLayer,
148  const Layer* eLayer,
149  const T& pars,
150  PropDirection pDir,
151  const BoundaryCheck& bchk,
152  bool resolveSubSurfaces) const
153 {
154  // get position and momentum from the parameters
155  const Amg::Vector3D& gp = pars.position();
156  const Amg::Vector3D& gm = pars.momentum();
157  // the layer intersections
158  std::vector<LayerIntersection<T>> lIntersections;
159  // assign the direction
160  const Amg::Vector3D& dir =
161  (pDir == alongMomentum ? gm.unit() : Amg::Vector3D(-1 * gm.unit()));
162  // the confinedLayers
163  if (m_confinedLayers) {
164  // cache the longest path length to avoid punch-through to the other side
165  Trk::Intersection sLayerIntersection(
166  Amg::Vector3D(0., 0., 0), 0., true, 0.);
167  const Trk::Surface* sLayerSurface = nullptr;
168  double validPathLength = 0.;
169  // start layer given or not - test layer
170  const Trk::Layer* tLayer = sLayer ? sLayer : associatedLayer(gp);
171  if (tLayer) {
172  do {
173  // collect material or sensitive layers, always provide the final layer
174  // for the navigation stop
175  if (tLayer->layerMaterialProperties() || tLayer->surfaceArray() ||
176  tLayer == eLayer) {
177  // get the approaching surface
178  const Surface& tSurface =
179  tLayer->surfaceOnApproach(gp, dir, pDir, bchk, resolveSubSurfaces);
180  // calculate the intersection with the layer
181  Trk::Intersection lIntersection =
182  tSurface.straightLineIntersection(gp, dir, true, bchk);
183  // (a) if the current layer is NOT the start layer - intersection is
184  // ok
185  if (tLayer != sLayer && lIntersection.valid) {
186  lIntersections.push_back(
187  LayerIntersection<T>(lIntersection, tLayer, &tSurface, 0, pDir));
188  validPathLength = lIntersection.pathLength;
189  } else if (tLayer == sLayer) {
190  // (b) the current layer is the start layer - we need to cache it
191  // and check with the path length
192  // this avoids potential punch-through to other side of
193  sLayerIntersection = lIntersection;
194  sLayerSurface = &tSurface;
195  } else if (tLayer == eLayer) {
196  // (c) it is the end layer after all - provide it and break the loop
197  lIntersections.push_back(
198  LayerIntersection<T>(lIntersection, tLayer, &tSurface, 0, pDir));
199  break;
200  }
201  }
202  // move to next one or break because you reached the end layer
203  tLayer = (tLayer == eLayer) ? nullptr : tLayer->nextLayer(gp, dir);
204  } while (tLayer);
205  }
206 
207  // final check for compatibility of the start layer in order to avoid
208  // punch-through
209  if (sLayer && sLayerIntersection.valid &&
210  sLayerIntersection.pathLength < validPathLength)
211  lIntersections.push_back(LayerIntersection<T>(
212  sLayerIntersection, sLayer, sLayerSurface, 0, pDir));
213  }
214  // and the arbitraray layers
215  if (m_confinedArbitraryLayers) {
216  // loop over the layers and intersect them
217  for (auto& layer : (*m_confinedArbitraryLayers)) {
218  // intersections
219  Trk::Intersection lIntersection =
220  layer->surfaceRepresentation().straightLineIntersection(
221  gp, dir, true, bchk);
222  if (lIntersection.valid)
223  lIntersections.push_back(LayerIntersection<T>(
224  lIntersection, layer, &(layer->surfaceRepresentation()), 0, pDir));
225  }
226  }
227 
228  // sort them accordingly to the path length
229  std::sort(lIntersections.begin(), lIntersections.end());
230  // and return
231  return lIntersections;
232 }
233 
234 /** Returns the boundary surfaces ordered in probability to hit them based on
235  * straight line intersection @todo change hard-coded default */
236 template<class T>
237 std::vector<BoundaryIntersection<T>>
238 TrackingVolume::boundarySurfacesOrdered(const T& pars,
239  PropDirection pDir,
240  bool) const
241 {
242 
243  // assign the direction
244 
245  const Amg::Vector3D dir =
246  (pDir == alongMomentum ? pars.momentum().unit()
247  : Amg::Vector3D(-1 * pars.momentum().unit()));
248  // loop over boundarySurfaces and calculate the intersection
249  std::vector<BoundaryIntersection<T>> bIntersections;
250  const auto& bSurfaces = boundarySurfaces();
251  for (size_t i = 0; i < bSurfaces.size(); ++i) {
252  const BoundarySurface<TrackingVolume>* bSurface = bSurfaces[i];
253  Intersection bsIntersection =
254  bSurface->surfaceRepresentation().straightLineIntersection(
255  pars.position(), dir, true, false);
256  if (bsIntersection.valid)
257  bIntersections.push_back(
258  BoundaryIntersection<T>(bsIntersection,
259  bSurface,
260  &(bSurface->surfaceRepresentation()),
261  0,
262  pDir));
263  }
264  // and now sort to get the closest
265  std::sort(bIntersections.begin(), bIntersections.end());
266  // and return
267  return bIntersections;
268 }
269 
270 inline GeometrySignature
271 TrackingVolume::geometrySignature() const
272 {
273  return m_geometrySignature;
274 }
275 
276 inline GeometryType
277 TrackingVolume::geometryType() const
278 {
279  return m_geometryType;
280 }
281 
282 inline void
283 TrackingVolume::registerColorCode(unsigned int icolor)
284 {
285  m_colorCode = icolor;
286 }
287 
288 inline unsigned int
289 TrackingVolume::colorCode() const
290 {
291  return m_colorCode;
292 }
293 
294 inline const TrackingVolume*
295 TrackingVolume::getMotherVolume() const
296 {
297  return m_motherVolume;
298 }
299 
300 inline void
301 TrackingVolume::setMotherVolume(const TrackingVolume* mvol)
302 {
303  m_motherVolume = mvol;
304 }
305 
306 inline bool
307 TrackingVolume::isAlignable() const
308 {
309  return false;
310 }
311 
312 }