ATLAS Offline Software
TrackingVolume.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // TrackingVolume.cxx, (b) ATLAS Detector software
8 
9 // Gaudi Kernel
10 #include "GaudiKernel/MsgStream.h"
11 // Trk
15 #include "TrkGeometry/Layer.h"
17 #include "TrkGeometry/PlaneLayer.h"
21 //
32 //
37 #include "TrkSurfaces/Surface.h"
38 //
41 //
44 // CLHEP
46 #include <utility>
47 
49  : Volume()
50  , Material()
51  , m_motherVolume(nullptr)
52  , m_boundarySurfaces{}
53  , m_confinedLayers(nullptr)
54  , m_confinedVolumes(nullptr)
55  , m_confinedDetachedVolumes(nullptr)
56  , m_confinedDenseVolumes(nullptr)
57  , m_confinedArbitraryLayers(nullptr)
58  , m_outsideGlueVolumes(nullptr)
59  , m_layerAttemptsCalculator(nullptr)
60  , m_geometrySignature(Trk::Unsigned)
61  , m_geometryType(Trk::NumberOfGeometryTypes)
62  , m_name("undefined")
63  , m_colorCode(20)
64  , m_redoNavigation(false)
65 {}
66 
67 // constructor: 1 a)
69  VolumeBounds* volbounds,
70  LayerArray* subLayers,
71  TrackingVolumeArray* subVolumes,
72  const std::string& volumeName)
73  : Volume(htrans, volbounds)
74  , Material()
75  , m_motherVolume(nullptr)
76  , m_boundarySurfaces{}
77  , m_confinedLayers(subLayers)
78  , m_confinedVolumes(subVolumes)
79  , m_confinedDetachedVolumes(nullptr)
80  , m_confinedDenseVolumes(nullptr)
81  , m_confinedArbitraryLayers(nullptr)
82  , m_outsideGlueVolumes(nullptr)
83  , m_layerAttemptsCalculator(nullptr)
84  , m_geometrySignature(Trk::Unsigned)
85  , m_geometryType(Trk::NumberOfGeometryTypes)
86  , m_name(volumeName)
87  , m_colorCode(20)
88  , m_redoNavigation(false)
89 {
90  createBoundarySurfaces();
91  createLayerAttemptsCalculator();
92  interlinkLayers();
93 }
94 
95 // constructor: 2 a)
97  const Material& matprop,
98  LayerArray* subLayers,
99  TrackingVolumeArray* subVolumes,
100  const std::string& volumeName)
101  : Volume(volume)
102  , Material(matprop)
103  , m_motherVolume(nullptr)
104  , m_boundarySurfaces{}
105  , m_confinedLayers(subLayers)
106  , m_confinedVolumes(subVolumes)
107  , m_confinedDetachedVolumes(nullptr)
108  , m_confinedDenseVolumes(nullptr)
109  , m_confinedArbitraryLayers(nullptr)
110  , m_outsideGlueVolumes(nullptr)
111  , m_layerAttemptsCalculator(nullptr)
112  , m_geometrySignature(Trk::Unsigned)
113  , m_geometryType(Trk::NumberOfGeometryTypes)
114  , m_name(volumeName)
115  , m_colorCode(20)
116  , m_redoNavigation(false)
117 {
118  createBoundarySurfaces();
119  createLayerAttemptsCalculator();
120  interlinkLayers();
121 }
122 
123 // constructor: 3 a)
125  VolumeBounds* volbounds,
126  const Material& matprop,
127  LayerArray* subLayers,
128  TrackingVolumeArray* subVolumes,
129  const std::string& volumeName)
130  : Volume(htrans, volbounds)
131  , Material(matprop)
132  , m_motherVolume(nullptr)
133  , m_confinedLayers(subLayers)
134  , m_confinedVolumes(subVolumes)
135  , m_confinedDetachedVolumes(nullptr)
136  , m_confinedDenseVolumes(nullptr)
137  , m_confinedArbitraryLayers(nullptr)
138  , m_outsideGlueVolumes(nullptr)
139  , m_layerAttemptsCalculator(nullptr)
140  , m_geometrySignature(Trk::Unsigned)
141  , m_geometryType(Trk::NumberOfGeometryTypes)
142  , m_name(volumeName)
143  , m_colorCode(20)
144  , m_redoNavigation(false)
145 {
148  interlinkLayers();
149 }
150 
151 // 1 b)
153  Amg::Transform3D* htrans,
154  VolumeBounds* volbounds,
155  const Material& matprop,
156  std::vector<DetachedTrackingVolume*>* detachedSubVolumes,
157  const std::string& volumeName)
158  : Volume(htrans, volbounds)
159  , Material(matprop)
160  , m_motherVolume(nullptr)
161  , m_confinedLayers(nullptr)
162  , m_confinedVolumes(nullptr)
163  , m_confinedDetachedVolumes(detachedSubVolumes)
164  , m_confinedDenseVolumes(nullptr)
165  , m_confinedArbitraryLayers(nullptr)
166  , m_outsideGlueVolumes(nullptr)
167  , m_layerAttemptsCalculator(nullptr)
168  , m_geometrySignature(Trk::Unsigned)
169  , m_geometryType(Trk::NumberOfGeometryTypes)
170  , m_name(volumeName)
171  , m_colorCode(20)
172  , m_redoNavigation(false)
173 {
175 }
176 
177 // 2 b)
179  const Volume& volume,
180  const Material& matprop,
181  std::vector<DetachedTrackingVolume*>* detachedSubVolumes,
182  const std::string& volumeName)
183  : Volume(volume)
184  , Material(matprop)
185  , m_motherVolume(nullptr)
186  , m_confinedLayers(nullptr)
187  , m_confinedVolumes(nullptr)
188  , m_confinedDetachedVolumes(detachedSubVolumes)
189  , m_confinedDenseVolumes(nullptr)
190  , m_confinedArbitraryLayers(nullptr)
191  , m_outsideGlueVolumes(nullptr)
192  , m_layerAttemptsCalculator(nullptr)
193  , m_geometrySignature(Trk::Unsigned)
194  , m_geometryType(Trk::NumberOfGeometryTypes)
195  , m_name(volumeName)
196  , m_colorCode(20)
197  , m_redoNavigation(false)
198 {
200 }
201 
202 // 1 d)
204  Amg::Transform3D* htrans,
205  VolumeBounds* volbounds,
206  const Material& matprop,
207  const std::vector<TrackingVolume*>* unorderedSubVolumes,
208  const std::string& volumeName)
209  : Volume(htrans, volbounds)
210  , Material(matprop)
211  , m_motherVolume(nullptr)
212  , m_confinedLayers(nullptr)
213  , m_confinedVolumes(nullptr)
214  , m_confinedDetachedVolumes(nullptr)
215  , m_confinedDenseVolumes(unorderedSubVolumes)
216  , m_confinedArbitraryLayers(nullptr)
217  , m_outsideGlueVolumes(nullptr)
218  , m_layerAttemptsCalculator(nullptr)
219  , m_geometrySignature(Trk::Unsigned)
220  , m_geometryType(Trk::NumberOfGeometryTypes)
221  , m_name(volumeName)
222  , m_colorCode(20)
223  , m_redoNavigation(false)
224 {
226 }
227 
228 // 2 d)
230  const Volume& volume,
231  const Material& matprop,
232  const std::vector<TrackingVolume*>* unorderedSubVolumes,
233  const std::string& volumeName)
234  : Volume(volume)
235  , Material(matprop)
236  , m_motherVolume(nullptr)
237  , m_confinedLayers(nullptr)
238  , m_confinedVolumes(nullptr)
239  , m_confinedDetachedVolumes(nullptr)
240  , m_confinedDenseVolumes(unorderedSubVolumes)
241  , m_confinedArbitraryLayers(nullptr)
242  , m_outsideGlueVolumes(nullptr)
243  , m_layerAttemptsCalculator(nullptr)
244  , m_geometrySignature(Trk::Unsigned)
245  , m_geometryType(Trk::NumberOfGeometryTypes)
246  , m_name(volumeName)
247  , m_colorCode(20)
248  , m_redoNavigation(false)
249 {
251 }
252 
253 // 1 c)
255  VolumeBounds* volbounds,
256  const Material& matprop,
257  const std::vector<Layer*>* layers,
258  const std::string& volumeName)
259  : Volume(htrans, volbounds)
260  , Material(matprop)
261  , m_motherVolume(nullptr)
262  , m_confinedLayers(nullptr)
263  , m_confinedVolumes(nullptr)
264  , m_confinedDetachedVolumes(nullptr)
265  , m_confinedDenseVolumes(nullptr)
266  , m_confinedArbitraryLayers(layers)
267  , m_outsideGlueVolumes(nullptr)
268  , m_layerAttemptsCalculator(nullptr)
269  , m_geometrySignature(Trk::Unsigned)
270  , m_geometryType(Trk::NumberOfGeometryTypes)
271  , m_name(volumeName)
272  , m_colorCode(20)
273  , m_redoNavigation(false)
274 {
276 }
277 
278 // 2 c)
280  const Material& matprop,
281  const std::vector<Layer*>* layers,
282  const std::string& volumeName)
283  : Volume(volume)
284  , Material(matprop)
285  , m_motherVolume(nullptr)
286  , m_confinedLayers(nullptr)
287  , m_confinedVolumes(nullptr)
288  , m_confinedDetachedVolumes(nullptr)
289  , m_confinedDenseVolumes(nullptr)
290  , m_confinedArbitraryLayers(layers)
291  , m_outsideGlueVolumes(nullptr)
292  , m_layerAttemptsCalculator(nullptr)
293  , m_geometrySignature(Trk::Unsigned)
294  , m_geometryType(Trk::NumberOfGeometryTypes)
295  , m_name(volumeName)
296  , m_colorCode(20)
297  , m_redoNavigation(false)
298 {
300 }
301 
302 // 1 d)
304  Amg::Transform3D* htrans,
305  VolumeBounds* volbounds,
306  const std::vector<Layer*>* layers,
307  const std::vector<TrackingVolume*>* unorderedSubVolumes,
308  const Material& matprop,
309  const std::string& volumeName)
310  : Volume(htrans, volbounds)
311  , Material(matprop)
312  , m_motherVolume(nullptr)
313  , m_confinedLayers(nullptr)
314  , m_confinedVolumes(nullptr)
315  , m_confinedDetachedVolumes(nullptr)
316  , m_confinedDenseVolumes(unorderedSubVolumes)
317  , m_confinedArbitraryLayers(layers)
318  , m_outsideGlueVolumes(nullptr)
319  , m_layerAttemptsCalculator(nullptr)
320  , m_geometrySignature(Trk::Unsigned)
321  , m_geometryType(Trk::NumberOfGeometryTypes)
322  , m_name(volumeName)
323  , m_colorCode(20)
324  , m_redoNavigation(false)
325 {
327 }
328 
329 // 2 d)
331  const Volume& volume,
332  const std::vector<Layer*>* layers,
333  const std::vector<TrackingVolume*>* unorderedSubVolumes,
334  const Material& matprop,
335  const std::string& volumeName)
336  : Volume(volume)
337  , Material(matprop)
338  , m_motherVolume(nullptr)
339  , m_confinedLayers(nullptr)
340  , m_confinedVolumes(nullptr)
341  , m_confinedDetachedVolumes(nullptr)
342  , m_confinedDenseVolumes(unorderedSubVolumes)
343  , m_confinedArbitraryLayers(layers)
344  , m_outsideGlueVolumes(nullptr)
345  , m_layerAttemptsCalculator(nullptr)
346  , m_geometrySignature(Trk::Unsigned)
347  , m_geometryType(Trk::NumberOfGeometryTypes)
348  , m_name(volumeName)
349  , m_colorCode(20)
350  , m_redoNavigation(false)
351 {
353 }
354 
357  : Volume(trVol, transform)
358  , Material(trVol)
359  , m_motherVolume(trVol.m_motherVolume)
360  , m_boundarySurfaces{}
361  , m_confinedLayers(nullptr)
362  , m_confinedVolumes(nullptr)
363  , m_confinedDetachedVolumes(nullptr)
364  , m_confinedDenseVolumes(nullptr)
365  , m_confinedArbitraryLayers(nullptr)
366  , m_outsideGlueVolumes(nullptr)
367  , m_layerAttemptsCalculator(nullptr)
368  , m_geometrySignature(Trk::Unsigned)
369  , m_geometryType(Trk::NumberOfGeometryTypes)
370  , m_name(trVol.m_name)
371  , m_colorCode(trVol.m_colorCode)
372  , m_redoNavigation(trVol.m_redoNavigation)
373 {
374  // createBoundarySurfaces
375  m_boundarySurfaces.reserve(trVol.boundarySurfaces().size());
376  const Trk::TrackingVolume* in = nullptr;
377  const Trk::TrackingVolume* out = nullptr;
378  for (size_t ib = 0; ib < trVol.boundarySurfaces().size(); ib++) {
379  in = trVol.boundarySurfaces()[ib]->insideVolume() == &trVol ? this
380  : nullptr;
381  out = in == nullptr ? this : nullptr;
382  const Trk::CylinderSurface* cyl = dynamic_cast<const Trk::CylinderSurface*>(
383  trVol.boundarySurfaces()[ib]);
384  const Trk::DiscSurface* dis =
385  dynamic_cast<const Trk::DiscSurface*>(trVol.boundarySurfaces()[ib]);
386  const Trk::PlaneSurface* pla = dynamic_cast<const Trk::PlaneSurface*>(
387  trVol.boundarySurfaces()[ib]);
388  const Trk::SubtractedCylinderSurface* scyl =
389  dynamic_cast<const Trk::SubtractedCylinderSurface*>(
390  trVol.boundarySurfaces()[ib]);
391  const Trk::SubtractedPlaneSurface* spla =
392  dynamic_cast<const Trk::SubtractedPlaneSurface*>(
393  trVol.boundarySurfaces()[ib]);
394  if (scyl)
395  m_boundarySurfaces.push_back(
398  in, out, *scyl, transform)));
399  else if (spla)
400  m_boundarySurfaces.push_back(
403  in, out, *spla, transform)));
404  else if (cyl)
405  m_boundarySurfaces.push_back(
408  in, out, *cyl, transform)));
409  else if (dis)
410  m_boundarySurfaces.push_back(
413  in, out, *dis, transform)));
414  else if (pla)
415  m_boundarySurfaces.push_back(
418  in, out, *pla, transform)));
419  }
420 
421  // confined layers
422  const Trk::BinnedArray<Trk::Layer>* confinedLayers = trVol.confinedLayers();
423  if (confinedLayers) {
425  std::vector<Trk::SharedObject<Trk::Layer>> layerOrder;
426  layerOrder.reserve(layers.size());
427  for (const auto *layer : layers) {
428  const Trk::PlaneLayer* lay =
429  dynamic_cast<const Trk::PlaneLayer*>(layer);
430  if (lay) {
431  Trk::PlaneLayer* newlay = new Trk::PlaneLayer(*lay, transform);
432  layerOrder.push_back(Trk::SharedObject<Trk::Layer>(newlay));
433  }
434  }
435  const Trk::NavBinnedArray1D<Trk::Layer>* confLays =
436  dynamic_cast<const Trk::NavBinnedArray1D<Trk::Layer>*>(confinedLayers);
437  if (confLays)
438  m_confinedLayers = new Trk::NavBinnedArray1D<Trk::Layer>(
439  *confLays,
440  std::vector<Trk::SharedObject<Trk::Layer>>(layerOrder),
441  transform);
442  }
443 
444  // confined 'unordered' layers
445  Trk::ArraySpan<const Trk::Layer* const> confinedArbitraryLayers =
446  trVol.confinedArbitraryLayers();
447  if (!confinedArbitraryLayers.empty()) {
448  // clone & apply the transform
449  std::vector<Trk::Layer*> uLayers;
450  uLayers.reserve(confinedArbitraryLayers.size());
451  for (const auto *confinedArbitraryLayer : confinedArbitraryLayers) {
452  const Trk::SubtractedPlaneLayer* slayer =
453  dynamic_cast<const Trk::SubtractedPlaneLayer*>(
454  confinedArbitraryLayer);
455  const Trk::SubtractedCylinderLayer* sclayer =
456  dynamic_cast<const Trk::SubtractedCylinderLayer*>(
457  confinedArbitraryLayer);
458  const Trk::PlaneLayer* layer =
459  dynamic_cast<const Trk::PlaneLayer*>(confinedArbitraryLayer);
460  const Trk::CylinderLayer* clayer =
461  dynamic_cast<const Trk::CylinderLayer*>(confinedArbitraryLayer);
462 
463  if (slayer) {
465  new Trk::SubtractedPlaneLayer(*slayer, transform);
466  uLayers.push_back(lay);
467  } else if (layer) {
469  uLayers.push_back(lay);
470  } else if (sclayer) {
473  uLayers.push_back(lay);
474  } else if (clayer) {
475  Trk::CylinderLayer* lay = new Trk::CylinderLayer(*clayer, transform);
476  uLayers.push_back(lay);
477  }
478  }
479  m_confinedArbitraryLayers = new std::vector<Trk::Layer*>(uLayers);
480  }
481 
482  // confined volumes
483  const Trk::BinnedArray<Trk::TrackingVolume>* confinedVolumes =
484  trVol.confinedVolumes();
485  if (confinedVolumes) {
486  // retrieve array objects and apply the transform
488  confinedVolumes->arrayObjects();
489  std::vector<Trk::SharedObject<Trk::TrackingVolume>> volOrder;
490  volOrder.reserve(volumes.size());
491  for (const auto *volume : volumes) {
493  volOrder.push_back(Trk::SharedObject<TrackingVolume>(vol));
494  }
496  dynamic_cast<const Trk::NavBinnedArray1D<Trk::TrackingVolume>*>(confinedVolumes);
497  if (confVols)
498  m_confinedVolumes = new Trk::NavBinnedArray1D<Trk::TrackingVolume>(
499  *confVols,
500  std::vector<Trk::SharedObject<Trk::TrackingVolume>>(volOrder),
501  transform);
502  }
503 
504  // confined unordered volumes
506  trVol.confinedDenseVolumes();
507  if (!confinedDenseVolumes.empty()) {
508  std::vector<Trk::TrackingVolume*> newVol;
509  newVol.reserve(confinedDenseVolumes.size());
510  // retrieve array objects and apply the transform
511  for (const auto *confinedDenseVolume : confinedDenseVolumes) {
512  Trk::TrackingVolume* vol =
513  new Trk::TrackingVolume(*confinedDenseVolume, transform);
514  newVol.push_back(vol);
515  }
516  m_confinedDenseVolumes =
517  new std::vector<Trk::TrackingVolume*>(newVol);
518  }
519 }
520 
522 {
523  delete m_confinedLayers;
524  delete m_confinedVolumes;
525  delete m_confinedDetachedVolumes;
526  if (m_confinedDenseVolumes) {
527  for (auto * confinedDenseVolume : *m_confinedDenseVolumes){
528  delete confinedDenseVolume;
529  }
530  delete m_confinedDenseVolumes;
531  }
532  if (m_confinedArbitraryLayers) {
533  for (auto * confinedArbitraryLayer : *m_confinedArbitraryLayers){
534  delete confinedArbitraryLayer;
535  }
536  delete m_confinedArbitraryLayers;
537  }
538  delete m_layerAttemptsCalculator;
539 }
540 
541 void
543 {
544  if (m_confinedVolumes) {
545  delete m_confinedVolumes;
546  m_confinedVolumes = nullptr;
547  }
548  if (m_confinedLayers) {
549  delete m_confinedLayers;
550  m_confinedLayers = nullptr;
551  }
552  if (m_confinedDenseVolumes) {
553  for (auto * confinedDenseVolume : *m_confinedDenseVolumes){
554  delete confinedDenseVolume;
555  }
556  delete m_confinedDenseVolumes;
557  m_confinedDenseVolumes = nullptr;
558  }
559  if (m_confinedArbitraryLayers) {
560  for (auto *confinedArbitraryLayer : *m_confinedArbitraryLayers){
561  delete confinedArbitraryLayer;
562  }
563  delete m_confinedArbitraryLayers;
564  m_confinedArbitraryLayers = nullptr;
565  }
566 }
567 
568 const Trk::Layer*
570 {
571  // confined layers
572  if (m_confinedLayers)
573  return (confinedLayers()->object(gp));
574  // confined arbitrary
575  if (m_confinedArbitraryLayers) {
576  for (auto * confinedArbitraryLayer : *m_confinedArbitraryLayers){
577  if (confinedArbitraryLayer->isOnLayer(gp)){
578  return confinedArbitraryLayer;
579  }
580  }
581  }
582  return nullptr;
583 }
584 
585 Trk::Layer*
587 {
588  // confined layers
589  if (m_confinedLayers)
590  return (confinedLayers()->object(gp));
591  // confined arbitrary
592  if (m_confinedArbitraryLayers) {
593  for (auto * confinedArbitraryLayer : *m_confinedArbitraryLayers){
594  if (confinedArbitraryLayer->isOnLayer(gp)){
595  return confinedArbitraryLayer;
596  }
597  }
598  }
599  return nullptr;
600 }
601 
602 
603 
604 const Trk::Layer*
606  const Amg::Vector3D& mom,
607  bool associatedResult,
608  bool skipNavLayer) const
609 {
610  const Trk::Layer* nextLayer = nullptr;
611  if (m_confinedLayers)
612  nextLayer = (confinedLayers()->nextObject(gp, mom, associatedResult));
613  // forward it in this case
614  if (!skipNavLayer)
615  return nextLayer;
616  // if only material or layers
617  if (nextLayer &&
618  (nextLayer->layerMaterialProperties() || nextLayer->surfaceArray()))
619  return nextLayer;
620  // try to get the next layer that has either material or sub surfaces
621  while (nextLayer && (!(nextLayer->layerMaterialProperties()) &&
622  !(nextLayer->surfaceArray())))
623  nextLayer = (confinedLayers()->nextObject(gp, mom, associatedResult));
624  return nextLayer;
625 }
626 
629  const Amg::Vector3D& dir,
630  PropDirection pDir,
631  const BoundaryCheck& bchk) const
632 {
633  // the layer candidates to check
634  std::vector<const Layer*> layerCandidates;
635 
636  // ---------------- BOUNDARY LAYER SECTION (only for mapping) ----------
637  if (pDir == mappingMode) {
638  const auto& bSurfaces = boundarySurfaces();
639  for (size_t ib = 0; ib < bSurfaces.size(); ++ib) {
640  if (bSurfaces[ib]->surfaceRepresentation().materialLayer())
641  layerCandidates.push_back(
642  bSurfaces[ib]->surfaceRepresentation().materialLayer());
643  }
644  }
645  // ---------------- CONFINED LAYER SECTION --------------
646  if (m_confinedLayers) {
647  // the associated layer
648  const Trk::Layer* assocLayer = associatedLayer(gp);
649  const Trk::Layer* previousMatLayer = nullptr;
650  const Trk::Layer* nextMatLayer = nullptr;
651  // if the associated layer is a navigation layer - get the previous and next
652  // from this one
653  const Trk::NavigationLayer* navLayer =
654  dynamic_cast<const Trk::NavigationLayer*>(assocLayer);
655  if (navLayer) {
656  // get previous / next
657  previousMatLayer = navLayer->previousLayer();
658  nextMatLayer = navLayer->nextLayer();
659  if (previousMatLayer)
660  layerCandidates.push_back(previousMatLayer);
661  if (nextMatLayer)
662  layerCandidates.push_back(nextMatLayer);
663  } else
664  layerCandidates.push_back(assocLayer);
665  }
666  // --- solve for the layer candidates ---------------------
667  //
668  Trk::Intersection laySurfIntersection(
669  Amg::Vector3D(0., 0., 0.), 10e10, false);
670  // layer candidates found - continue
671  if (!layerCandidates.empty()) {
672  const Layer* cLayer = nullptr;
673  // iterate through and chose
674  for (auto& lcIter : layerCandidates) {
675  // only the forceFwd solution is possible here
676  bool forceDir = (pDir == alongMomentum || pDir == oppositeMomentum);
677  double dirScalor = (pDir == oppositeMomentum) ? -1. : 1.;
678  // get the intersection soltuion
679  Trk::Intersection sfI =
680  (*lcIter).surfaceRepresentation().straightLineIntersection(
681  gp, dirScalor * dir, forceDir, bchk);
682  if (sfI.valid &&
683  (sfI.pathLength * sfI.pathLength) <
684  (laySurfIntersection.pathLength * laySurfIntersection.pathLength)) {
685  laySurfIntersection = sfI;
686  cLayer = lcIter;
687  }
688  }
689  // now return the pair: in case of a valid intersection, or if no mapping
690  // mode is chosen
691  if (cLayer)
693  laySurfIntersection,
694  cLayer,
695  &(cLayer->surfaceRepresentation()),
696  nullptr,
697  pDir);
698  }
699  // mapping mode chosen, but no valid intersection yet
700  const Trk::TrackingVolume* nVolume = nextVolume(gp, dir, pDir);
701 
702  // forward the next Volume solution or a 0 solution
703  return (nVolume && nVolume != this)
704  ? nVolume->closestMaterialLayer(gp, dir, pDir, bchk)
706  laySurfIntersection, nullptr, nullptr, nullptr, pDir);
707 }
708 
709 const Trk::TrackingVolume*
711 {
712  if (m_confinedVolumes)
713  return (m_confinedVolumes->object(gp));
714 
715  if (m_confinedDetachedVolumes) {
716  for (auto *confinedDetachedVolume : *m_confinedDetachedVolumes) {
717  if (confinedDetachedVolume->trackingVolume()->inside(gp, 0.001)){
718  return confinedDetachedVolume->trackingVolume();
719  }
720  }
721  }
722 
723  if (m_confinedDenseVolumes) {
724  for (auto *confinedDenseVolume : *m_confinedDenseVolumes)
725  if (confinedDenseVolume->inside(gp, 0.001)){
726  return confinedDenseVolume;
727  }
728  }
729 
730  return this;
731 }
732 
735 {
736  if (m_confinedVolumes)
737  return (m_confinedVolumes->object(gp));
738 
739  if (m_confinedDetachedVolumes) {
740  for (auto *confinedDetachedVolume : *m_confinedDetachedVolumes) {
741  if (confinedDetachedVolume->trackingVolume()->inside(gp, 0.001)){
742  return confinedDetachedVolume->trackingVolume();
743  }
744  }
745  }
746 
747  if (m_confinedDenseVolumes) {
748  for (auto * confinedDenseVolume : *m_confinedDenseVolumes){
749  if (confinedDenseVolume->inside(gp, 0.001)){
750  return confinedDenseVolume;
751  }
752  }
753  }
754 
755  return this;
756 }
757 
758 
759 const Trk::TrackingVolume*
761  const Amg::Vector3D& dir,
762  Trk::PropDirection pDir) const
763 {
764  // get the boundary surfaces & intersect them
765  const Trk::TrackingVolume* nVolume = nullptr;
766  // fix the direction once
767  bool forceDir = (pDir == Trk::alongMomentum || pDir == Trk::oppositeMomentum);
768  double dirScalor = (pDir == Trk::oppositeMomentum) ? -1. : 1.;
769  Amg::Vector3D cDir = dirScalor * dir;
770  double pathLength = 10e10;
771  // now loop through the and find the closest
772  const auto& bSurfaces = boundarySurfaces();
773  for (size_t ib = 0; ib < bSurfaces.size(); ++ib) {
774  // get the intersection soltuion
775  Trk::Intersection sfI =
776  bSurfaces[ib]->surfaceRepresentation().straightLineIntersection(
777  gp, cDir, forceDir, true);
778  if (sfI.valid &&
779  (sfI.pathLength * sfI.pathLength) < (pathLength * pathLength)) {
780  // assign the next Volume
781  Trk::PropDirection attachedDir =
783  pathLength = sfI.pathLength;
784  nVolume = bSurfaces[ib]->attachedVolume(gp, cDir, attachedDir);
785  }
786  }
787  return nVolume;
788 }
789 
790 const Trk::TrackingVolume*
792  const Amg::Vector3D& mom) const
793 {
794  if (m_confinedVolumes)
795  return (m_confinedVolumes->nextObject(gp, mom));
796  return this;
797 }
798 
799 std::vector<const Trk::DetachedTrackingVolume*>
801  double tol) const
802 {
803  auto currVols = std::vector<const Trk::DetachedTrackingVolume*>();
804 
806  confinedDetachedVolumes();
807  if (!detVols.empty()) {
808  for (const auto *detVol : detVols) {
809  if (detVol->trackingVolume()->inside(gp, tol))
810  currVols.push_back(detVol);
811  }
812  }
813  return currVols;
814 }
815 
816 void
818  int& offset)
819 {
820  // the offset gets increased internally
821  // the static layers first
822  // ------------------------------------------------------------------
823  if (m_confinedLayers) {
825  for (Trk::Layer* layerptr : layers) {
826  // only index the material layers & only those that have not yet been
827  // singed
828  if (layerptr && layerptr->layerIndex().value() < 0) {
829  // sign only those with material properties - rest goes to 0
830  Trk::LayerIndex layIndex =
831  layerptr->layerMaterialProperties()
832  ? Trk::LayerIndex(
833  int(geoSig) * TRKDETDESCR_GEOMETRYSIGNATUREWEIGHT + (++offset))
834  : Trk::LayerIndex(0);
835  // now register the index
836  layerptr->registerLayerIndex(layIndex);
837  }
838  }
839  }
840 
841  // the boundary surface layer
842  auto& bSurfaces = boundarySurfaces();
843  for (const auto& bsIter : bSurfaces) {
844  Trk::Layer* mLayer = bsIter->surfaceRepresentation().materialLayer();
845  if (mLayer && mLayer->layerIndex().value() < 0.) {
846  Trk::LayerIndex layIndex = Trk::LayerIndex(
847  int(geoSig) * TRKDETDESCR_GEOMETRYSIGNATUREWEIGHT + (++offset));
848  mLayer->registerLayerIndex(layIndex);
849  }
850  }
851 
852  // step down the hierarchy to the contained volumes and index those
853  // ------------------------
854  if (confinedVolumes()) {
856  for (const auto& volumesIter : volumes) {
857  if (volumesIter)
858  volumesIter->indexContainedStaticLayers(geoSig, offset);
859  }
860  }
861 }
862 
863 void
865  int& offset)
866 {
867  // the offset gets increased internally
868  // the static layers first and check if they have surfaces with material
869  // layers that need index
870  if (m_confinedLayers) {
872  for (Trk::Layer* layerIter : layers) {
873  // only index the material layers & only those that have not yet been
874  // singed
875  if (layerIter) {
876  Trk::SurfaceArray* surfArray = layerIter->surfaceArray();
877  if (surfArray) {
878  Trk::BinnedArraySpan<Trk::Surface * const> layerSurfaces = surfArray->arrayObjects();
879  // loop over the surfaces - there can be 0 entries
880  for (Trk::Surface* const laySurf : layerSurfaces) {
881  Trk::Layer* materialLayer = laySurf ? laySurf->materialLayer() : nullptr;
882  if (materialLayer && materialLayer->layerIndex().value() < 0) {
883  // sign only those with material properties - rest goes to 0
884  Trk::LayerIndex layIndex =
885  materialLayer->layerMaterialProperties()
886  ? Trk::LayerIndex(int(geoSig) *
888  (++offset))
889  : Trk::LayerIndex(0);
890  // now register the index
891  materialLayer->registerLayerIndex(layIndex);
892  }
893  }
894  }
895  }
896  }
897  }
898 
899  // step down the hierarchy to the contained volumes and index those
900  // ------------------------
901  if (confinedVolumes()) {
903  for (Trk::TrackingVolume* volumesIter : volumes) {
904  if (volumesIter)
905  volumesIter->indexContainedMaterialLayers(geoSig, offset);
906  }
907  }
908 }
909 
910 void
912 {
913  // assume the scaling factor refers to the volume scaling
914  float flin = pow(fact, 0.33);
915  // average X0
916  double invX0 = X0 > 0. ? 1. / X0 : 0.;
917  double sum_invX0 = invX0 + flin / mprop.X0;
918  X0 = 1. / sum_invX0;
919  // average L0
920  double invL0 = L0 > 0. ? 1. / L0 : 0.;
921  double sum_invL0 = invL0 + flin / mprop.L0;
922  L0 = 1. / sum_invL0;
923  // add density
924  float rho1 = rho;
925  rho += fact * mprop.rho;
926  // averageZ
927  float n1 = Z > 0. ? rho1 / Z : 0.;
928  float n2 = fact * mprop.rho / mprop.Z;
929  Z = rho / (n1 + n2);
930  // averageA
931  n1 = A > 0. ? rho1 / A : 0.;
932  n2 = fact * mprop.rho / mprop.A;
933  A = rho / (n1 + n2);
934  // zOverAtimesRho
935  zOaTr = Z / A * rho;
936  // mean energy loss (linear scaling)
937  dEdX += flin * mprop.dEdX;
938 }
939 
940 void
942  Trk::GeometryType geotype)
943 {
944  // never overwrite what is already signed, that's a crime
945  if (m_geometrySignature == Trk::Unsigned) {
946  m_geometrySignature = geosign;
947  }
948  m_geometryType = geotype;
949 
950  // confined volumes
951  Trk::BinnedArray<Trk::TrackingVolume>* confVolumes = confinedVolumes();
952  if (confVolumes) {
954  confVolumes->arrayObjects();
955  for (const auto& volumesIter : volumes)
956  if (volumesIter)
957  volumesIter->sign(geosign, geotype);
958  }
959  // same procedure for the detached volumes
961  confinedDetachedVolumes();
962  if (!confDetachedVolumes.empty()) {
963  for (const auto& volumesIter : confDetachedVolumes) {
964  if (volumesIter) {
965  volumesIter->sign(geosign, geotype);
966  }
967  }
968  }
969  // confined dense volumes
971  confinedDenseVolumes();
972  if (!confDenseVolumes.empty()) {
973  for (const auto& volumesIter : confDenseVolumes) {
974  if (volumesIter) {
975  volumesIter->sign(geosign, geotype);
976  }
977  }
978  }
979 }
980 
981 std::vector<Trk::SharedObject<Trk::BoundarySurface<Trk::TrackingVolume>>>&
983 {
984  return m_boundarySurfaces;
985 }
986 
989 {
991  m_boundarySurfaces);
992 }
993 
996 {
997  return (std::as_const(m_boundarySurfaces)[oa]).get();
998 }
999 
1000 void
1002 {
1003  // prepare the BoundarySurfaces
1004  m_boundarySurfaces =
1005  std::vector<Trk::SharedObject<Trk::BoundarySurface<Trk::TrackingVolume>>>();
1006  // transform Surfaces To BoundarySurfaces
1007  const std::vector<const Trk::Surface*>* surfaces =
1009  std::vector<const Trk::Surface*>::const_iterator surfIter = surfaces->begin();
1010 
1011  // counter to flip the inner/outer position for Cylinders
1012  unsigned int sfCounter = 0;
1013  unsigned int sfNumber = surfaces->size();
1014 
1015  // memory optimisation
1016  m_boundarySurfaces.reserve(sfNumber + 1);
1017 
1018  // identify Subtracted/CombinedVolumes
1019  const Trk::SubtractedVolumeBounds* subtrVol =
1020  dynamic_cast<const Trk::SubtractedVolumeBounds*>(
1022  const Trk::CombinedVolumeBounds* combVol =
1023  dynamic_cast<const Trk::CombinedVolumeBounds*>(
1025  bool subtr = (subtrVol) ? 1 : 0;
1026  bool comb = (combVol) ? 1 : 0;
1027 
1028  if (!subtr && !comb) {
1029  const Trk::SimplePolygonBrepVolumeBounds* spbVol =
1030  dynamic_cast<const Trk::SimplePolygonBrepVolumeBounds*>(
1032 
1033  for (; surfIter != surfaces->end(); ++surfIter) {
1034  sfCounter++;
1035 
1036  Trk::TrackingVolume* in = this;
1037  Trk::TrackingVolume* out = nullptr;
1038 
1039  // ST update: subtracted surfaces may appear in 'simple' volumes
1040  // (SimplePolygonBrep...)
1041  const Trk::SubtractedPlaneSurface* spsf =
1042  dynamic_cast<const Trk::SubtractedPlaneSurface*>(*surfIter);
1043  const Trk::PlaneSurface* psf =
1044  dynamic_cast<const Trk::PlaneSurface*>(*surfIter);
1045  if (spsf) {
1046  if (spbVol && sfCounter == 1) {
1047  in = nullptr;
1048  out = this;
1049  }
1050  m_boundarySurfaces.push_back(
1053  in, out, *spsf)));
1054  delete spsf;
1055  continue;
1056  }
1057  if (psf) {
1058  m_boundarySurfaces.push_back(
1061  delete psf;
1062  continue;
1063  }
1064 
1065  const Trk::DiscSurface* dsf =
1066  dynamic_cast<const Trk::DiscSurface*>(*surfIter);
1067  if (dsf) {
1068  m_boundarySurfaces.push_back(
1071  delete dsf;
1072  continue;
1073  }
1074 
1075  const Trk::SubtractedCylinderSurface* scsf =
1076  dynamic_cast<const Trk::SubtractedCylinderSurface*>(*surfIter);
1077  const Trk::CylinderSurface* csf =
1078  dynamic_cast<const Trk::CylinderSurface*>(*surfIter);
1079  if (scsf) {
1080  Trk::TrackingVolume* inner =
1081  (sfCounter == 4 && sfNumber > 3) ? nullptr : this;
1082  Trk::TrackingVolume* outer = (inner) ? nullptr : this;
1083  m_boundarySurfaces.push_back(
1086  inner, outer, *scsf)));
1087  delete scsf;
1088  continue;
1089  }
1090  if (csf) {
1091  Trk::TrackingVolume* inner =
1092  (sfCounter == 4 && sfNumber > 3) ? nullptr : this;
1093  Trk::TrackingVolume* outer = (inner) ? nullptr : this;
1094  m_boundarySurfaces.push_back(
1097  inner, outer, *csf)));
1098  delete csf;
1099  continue;
1100  }
1101  }
1102 
1103  } else {
1104  const std::vector<bool> bOrient =
1105  subtrVol ? subtrVol->boundsOrientation() : combVol->boundsOrientation();
1106 
1107  for (; surfIter != surfaces->end(); ++surfIter) {
1108  Trk::TrackingVolume* in = bOrient[sfCounter] ? this : nullptr;
1109  Trk::TrackingVolume* out = bOrient[sfCounter] ? nullptr : this;
1110  sfCounter++;
1111 
1112  const Trk::SubtractedPlaneSurface* psf =
1113  dynamic_cast<const Trk::SubtractedPlaneSurface*>(*surfIter);
1114  if (psf) {
1115  m_boundarySurfaces.push_back(
1118  in, out, *psf)));
1119  delete psf;
1120  continue;
1121  }
1122 
1123  const Trk::SubtractedCylinderSurface* csf =
1124  dynamic_cast<const Trk::SubtractedCylinderSurface*>(*surfIter);
1125  if (csf) {
1126  m_boundarySurfaces.push_back(
1129  in, out, *csf)));
1130  delete csf;
1131  continue;
1132  }
1133  }
1134  }
1135 
1136  delete surfaces;
1137 }
1138 
1139 void
1141 {
1142  // check whether there's a static array
1143  if (m_confinedLayers) {
1144  // BinUtility
1145  const Trk::BinUtility* binUtility = m_confinedLayers->binUtility();
1146  if (binUtility) {
1147  if (binUtility->binningValue() == Trk::binR)
1148  m_layerAttemptsCalculator =
1150  if (binUtility->binningValue() == Trk::binZ)
1151  m_layerAttemptsCalculator = new Trk::DiscLayerAttemptsCalculator(1, 5);
1152  }
1153  }
1154 }
1155 
1157 {
1158  if (m_confinedLayers) {
1159  BinnedArraySpan<Trk::Layer* const> layers = m_confinedLayers->arrayObjects();
1160  // forward loop
1161  const Trk::Layer* lastLayer = nullptr;
1163  for (; layerIter != layers.end(); ++layerIter) {
1164  if (*layerIter) {
1165  // register the layers
1166  (**layerIter).setBinUtility(confinedLayers()->binUtility()
1167  ? confinedLayers()->binUtility()
1168  : nullptr);
1169  (**layerIter).setPreviousLayer(lastLayer);
1170  // register the volume
1171  (**layerIter).encloseTrackingVolume(*this);
1172  }
1173  lastLayer = (*layerIter);
1174  }
1175  // backward loop
1176  lastLayer = nullptr;
1177  layerIter = layers.end();
1178  --layerIter;
1179  for (;; --layerIter) {
1180  if (*layerIter) {
1181  (**layerIter).setNextLayer(lastLayer);
1182  }
1183  lastLayer = (*layerIter);
1184  if (layerIter == layers.begin()) {
1185  break;
1186  }
1187  }
1188  }
1189 }
1190 
1191 const Trk::LayerArray*
1193 {
1194  const Trk::LayerArray* checkoutLayers = m_confinedLayers;
1195  return checkoutLayers;
1196 }
1197 
1198 void
1200 {
1201  m_outsideGlueVolumes.store(std::unique_ptr<Trk::GlueVolumesDescriptor>(gvd));
1202 }
1203 
1206 {
1207  if (!m_outsideGlueVolumes) {
1208  m_outsideGlueVolumes.store(std::make_unique<Trk::GlueVolumesDescriptor>());
1209  }
1210  return (*m_outsideGlueVolumes);
1211 }
1212 
1215 {
1216  if (!m_outsideGlueVolumes) {
1217  m_outsideGlueVolumes.set(std::make_unique<Trk::GlueVolumesDescriptor>());
1218  }
1219  return (*m_outsideGlueVolumes);
1220 }
1221 
1222 void
1224 {
1225  if (m_transform) {
1226  Amg::Transform3D transf = shift * (*m_transform);
1227  this->m_transform = std::make_unique<Amg::Transform3D>(transf);
1228  } else {
1229  this->m_transform = std::make_unique<Amg::Transform3D>(shift);
1230  }
1231  this->m_center.store(
1232  std::make_unique<Amg::Vector3D>(m_transform->translation()));
1233 }
1234 
1236 {
1237  // clone the mother volume
1239 
1240  // clone 'ordered layers
1241  Trk::LayerArray* layerArray = nullptr;
1242  // confined layers
1243  const Trk::BinnedArray<Trk::Layer>* confLayers = confinedLayers();
1244  if (confLayers) {
1245  // retrieve array objects and apply the transform
1247  std::vector<Trk::SharedObject<Trk::Layer>> layerOrder;
1248  for (const auto *layer : layers) {
1249  const Trk::PlaneLayer* lay =
1250  dynamic_cast<const Trk::PlaneLayer*>(layer);
1251  if (lay) {
1252  Trk::PlaneLayer* newlay = new Trk::PlaneLayer(*lay, transform);
1253  layerOrder.push_back(Trk::SharedObject<Trk::Layer>(newlay));
1254  }
1255  }
1256  // recreate LayerArray
1257  const Trk::NavBinnedArray1D<Trk::Layer>* confLaysNav =
1258  dynamic_cast<const Trk::NavBinnedArray1D<Trk::Layer>*>(confLayers);
1259  if (confLaysNav)
1260  layerArray = new Trk::NavBinnedArray1D<Trk::Layer>(
1261  *confLaysNav,
1262  std::vector<Trk::SharedObject<Trk::Layer>>(layerOrder),
1263  transform);
1264  }
1265 
1266  // clone 'unordered' layers
1267  std::vector<Trk::Layer*>* unorderedLayers = nullptr;
1269  confinedArbitraryLayers();
1270  if (!confArbLayers.empty()) {
1271  // clone & apply the transform
1272  std::vector<Trk::Layer*> uLayers;
1273  for (const auto *confArbLayer : confArbLayers) {
1274  const Trk::SubtractedPlaneLayer* slayer =
1275  dynamic_cast<const Trk::SubtractedPlaneLayer*>(confArbLayer);
1276  const Trk::SubtractedCylinderLayer* sclayer =
1277  dynamic_cast<const Trk::SubtractedCylinderLayer*>(confArbLayer);
1278  const Trk::PlaneLayer* layer =
1279  dynamic_cast<const Trk::PlaneLayer*>(confArbLayer);
1280  const Trk::CylinderLayer* clayer =
1281  dynamic_cast<const Trk::CylinderLayer*>(confArbLayer);
1282 
1283  if (slayer) {
1285  lay->moveLayer(transform);
1286  uLayers.push_back(lay);
1287  } else if (layer) {
1288  Trk::PlaneLayer* lay = new Trk::PlaneLayer(*layer);
1289  lay->moveLayer(transform);
1290  uLayers.push_back(lay);
1291  } else if (sclayer) {
1293  new Trk::SubtractedCylinderLayer(*sclayer);
1294  lay->moveLayer(transform);
1295  uLayers.push_back(lay);
1296  } else if (clayer) {
1297  Trk::CylinderLayer* lay = new Trk::CylinderLayer(*clayer);
1298  lay->moveLayer(transform);
1299  uLayers.push_back(lay);
1300  }
1301  }
1302  unorderedLayers = new std::vector<Trk::Layer*>(uLayers);
1303  }
1304 
1305  // cloning confined volumes
1306  Trk::TrackingVolumeArray* volumeArray = nullptr;
1307  const Trk::BinnedArray<Trk::TrackingVolume>* confVolumes = confinedVolumes();
1308  if (confVolumes) {
1309  // retrieve array objects and apply the transform
1311  std::vector<Trk::SharedObject<TrackingVolume>> volOrder;
1312  for (const auto *volume : volumes) {
1313  Trk::TrackingVolume* vol = volume->cloneTV(transform);
1314  volOrder.push_back(Trk::SharedObject<TrackingVolume>(vol));
1315  }
1316  // recreate TrackingVolumeArray
1317  const Trk::NavBinnedArray1D<Trk::TrackingVolume>* confVolsNav =
1318  dynamic_cast<const Trk::NavBinnedArray1D<Trk::TrackingVolume>*>(
1319  confVolumes);
1320  if (confVolsNav)
1322  *confVolsNav, std::vector<Trk::SharedObject<TrackingVolume>>(volOrder), transform);
1323  }
1324 
1325  // cloning confined unordered volumes
1327  confinedDenseVolumes();
1328  std::vector<Trk::TrackingVolume*>* newDenseVol = nullptr;
1329  if (!confDenseVolumes.empty()) {
1330  std::vector<Trk::TrackingVolume*> newVol;
1331  // retrieve array objects and apply the transform
1332  for (const auto *confDenseVolume : confDenseVolumes) {
1333  Trk::TrackingVolume* vol =
1334  confDenseVolume->cloneTV(transform);
1335  newVol.push_back(vol);
1336  }
1337  newDenseVol = new std::vector<Trk::TrackingVolume*>(newVol);
1338  }
1339 
1340  // create the Tracking Volume
1341  Trk::TrackingVolume* newTrkVol = nullptr;
1342  if (!confArbLayers.empty() || !confDenseVolumes.empty()) {
1343  if (!confArbLayers.empty() && !confDenseVolumes.empty()) {
1344  newTrkVol = new Trk::TrackingVolume(
1345  *vol, unorderedLayers, newDenseVol, *this, volumeName());
1346  } else if (!confArbLayers.empty()) {
1347  newTrkVol =
1348  new Trk::TrackingVolume(*vol, *this, unorderedLayers, volumeName());
1349  } else {
1350  newTrkVol =
1351  new Trk::TrackingVolume(*vol, *this, newDenseVol, volumeName());
1352  }
1353  delete layerArray;
1354  } else {
1355  newTrkVol = new Trk::TrackingVolume(
1356  *vol, *this, layerArray, volumeArray, volumeName());
1357  }
1358  delete vol;
1359  // finally, position the mother volume
1360  newTrkVol->moveVolume(transform);
1361  // create boundary surfaces
1362  newTrkVol->m_boundarySurfaces.clear();
1363  newTrkVol->createBoundarySurfaces();
1364 
1365  delete volumeArray;
1366  return newTrkVol;
1367 }
1368 
1369 const Trk::Layer*
1371  const Amg::Vector3D& dir,
1372  const Trk::Layer& first,
1373  const Trk::Layer& second)
1374 {
1375  // use the distance solution for assigning the layer
1376  Trk::DistanceSolution distSolToPrevious =
1377  first.surfaceRepresentation().straightLineDistanceEstimate(pos, dir);
1378  Trk::DistanceSolution distSolToNext =
1379  second.surfaceRepresentation().straightLineDistanceEstimate(pos, dir);
1380  // find out which one
1381  return (distSolToPrevious.absClosest() < distSolToNext.absClosest()
1382  ? &first
1383  : &second);
1384 }
1385 
1386 void
1388 {
1389 
1390  this->moveVolume(transform);
1391 
1392  // confined 'ordered' layers
1393  Trk::BinnedArray<Trk::Layer>* confLayers = confinedLayers();
1394  if (confLayers)
1395  for (Trk::Layer* clayIter : confLayers->arrayObjects()){
1396  clayIter->moveLayer(transform);
1397  }
1398 
1399  // confined 'unordered' layers
1400  Trk::ArraySpan<Trk::Layer* const> confArbLayers =
1401  confinedArbitraryLayers();
1402  if (!confArbLayers.empty()){
1403  for (Trk::Layer* calayIter : confArbLayers){
1404  calayIter->moveLayer(transform);
1405  }
1406  }
1407 
1408  // confined volumes
1409  Trk::BinnedArray<Trk::TrackingVolume>* confVolumes = confinedVolumes();
1410  if (confVolumes)
1411  // retrieve array objects and apply the transform
1412  for (Trk::TrackingVolume* cVolumesIter : confVolumes->arrayObjects()){
1413  (cVolumesIter)->moveTV(transform);
1414  }
1415 
1416  // confined unordered volumes
1418  confinedDenseVolumes();
1419  if (!confDenseVolumes.empty())
1420  // retrieve array objects and apply the transform
1421  for (Trk::TrackingVolume* cVolumesIter : confDenseVolumes){
1422  cVolumesIter->moveTV(transform);
1423  }
1424 }
1425 
1426 void
1427 Trk::TrackingVolume::synchronizeLayers(MsgStream& msgstream, double envelope)
1428 {
1429  // case a : Layers exist
1430  Trk::BinnedArray<Trk::Layer>* confLayers = confinedLayers();
1431  if (confLayers) {
1432  for (Trk::Layer* clay : confLayers->arrayObjects())
1433  if (clay) {
1434  if (clay->surfaceRepresentation().type() ==
1436  !(center().isApprox(clay->surfaceRepresentation().center()))) {
1437  clay->resizeAndRepositionLayer(volumeBounds(), center(), envelope);
1438  } else {
1439  clay->resizeLayer(volumeBounds(), envelope);
1440  }
1441  } else
1442  msgstream << MSG::WARNING
1443  << " ---> found 0 pointer to layer in Volume [ "
1444  << volumeName() << " ], indicates problem." << endmsg;
1445  }
1446  // case b : container volume -> step down
1447  Trk::BinnedArray<Trk::TrackingVolume>* confVolumes = confinedVolumes();
1448  if (confVolumes) {
1449  for (const auto& cVolumesIter : confVolumes->arrayObjects())
1450  cVolumesIter->synchronizeLayers(msgstream, envelope);
1451  }
1452 }
1453 
1454 void
1455 Trk::TrackingVolume::compactify(size_t& cSurfaces, size_t& tSurfaces)
1456 {
1457  // confined 'ordered' layers
1458  Trk::BinnedArray<Trk::Layer>* confLayers = confinedLayers();
1459  if (confLayers) {
1461  for (const auto& clayIter : layers) {
1462  if (&(*clayIter) != nullptr)
1463  clayIter->compactify(cSurfaces, tSurfaces);
1464  else
1465  std::cout << "WARNING: Attempt to compactify nullptr layer in volume : "
1466  << volumeName() << std::endl;
1467  }
1468  }
1469  // confined 'unordered' layers
1470  Trk::ArraySpan<Trk::Layer* const> confArbLayers = confinedArbitraryLayers();
1471  if (!confArbLayers.empty()) {
1472  for (const auto& calayIter : confArbLayers) {
1473  if (calayIter != nullptr) {
1474  calayIter->compactify(cSurfaces, tSurfaces);
1475  } else {
1476  std::cout << "WARNING: Attempt to compactify nullptr layer."
1477  << std::endl;
1478  }
1479  }
1480  }
1481  // confined volumes
1482  Trk::BinnedArray<Trk::TrackingVolume>* confVolumes = confinedVolumes();
1483  if (confVolumes) {
1485  confVolumes->arrayObjects();
1486  for (const auto& cVolumesIter : volumes) {
1487  cVolumesIter->compactify(cSurfaces, tSurfaces);
1488  }
1489  }
1490  // confined unordered volumes
1492  confinedDenseVolumes();
1493  if (!confDenseVolumes.empty())
1494  for (const auto& cVolumesIter : (confDenseVolumes)) {
1495  cVolumesIter->compactify(cSurfaces, tSurfaces);
1496  }
1497 
1498  // detached volumes if any
1499  if (m_confinedDetachedVolumes)
1500  for (const auto& cdVolumesIter : (*m_confinedDetachedVolumes)) {
1501  cdVolumesIter->compactify(cSurfaces, tSurfaces);
1502  }
1503 }
1504 
1505 void
1507 {
1508  msg << "[[ Trk::TrackingVolume ]] called: " << volumeName() << std::endl;
1509  msg << '\t' << '\t' << "# position (x,y,z) : " << center().x() << ", "
1510  << center().y() << ", " << center().z() << std::endl;
1511  msg << '\t' << '\t' << "# bounds : " << volumeBounds() << endmsg;
1512 }
1513 
Trk::TrackingVolume::closest
static const Layer * closest(const Amg::Vector3D &pos, const Amg::Vector3D &dir, const Layer &first, const Layer &second)
Helper method - find closest of two layers.
Definition: TrackingVolume.cxx:1370
Trk::TrackingVolume::glueVolumesDescriptor
GlueVolumesDescriptor & glueVolumesDescriptor()
Definition: TrackingVolume.cxx:1205
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
BoundarySubtractedCylinderSurface.h
BoundaryPlaneSurface.h
Trk::TrackingVolume::nextSubVolume
const TrackingVolume * nextSubVolume(const Amg::Vector3D &gp, const Amg::Vector3D &dir) const
Return the next sub Volume if existing, returns THIS if no subVolume exists.
Definition: TrackingVolume.cxx:791
Trk::BoundarySurface
Definition: BoundarySurface.h:50
Trk::TrackingVolume::addMaterial
void addMaterial(const Material &mat, float fact=1.)
add Material
Definition: TrackingVolume.cxx:911
Trk::TrackingVolume::createBoundarySurfaces
void createBoundarySurfaces()
Create Boundary Surface.
Definition: TrackingVolume.cxx:1001
Trk::TrackingVolume::nextLayer
const Layer * nextLayer(const Amg::Vector3D &gp, const Amg::Vector3D &mom, bool asres=true, bool skipNavLayer=false) const
Return the next Layer if existing, NULL if no next layer corresponds.
Definition: TrackingVolume.cxx:605
Trk::Intersection
Definition: Intersection.h:24
Trk::TrackingVolume::moveVolume
void moveVolume(Amg::Transform3D &shift)
move Volume
Definition: TrackingVolume.cxx:1223
Trk::BoundarySubtractedCylinderSurface
Definition: BoundarySubtractedCylinderSurface.h:38
Trk::Material::L0
float L0
Definition: Material.h:120
NavigationLayer.h
Trk::SimplePolygonBrepVolumeBounds
Definition: SimplePolygonBrepVolumeBounds.h:44
Surface.h
DistanceSolution.h
GeometrySignature
Trk::SubtractedCylinderSurface
Definition: SubtractedCylinderSurface.h:33
Trk::DistanceSolution
Definition: DistanceSolution.h:25
Trk::TrackingVolume::closestMaterialLayer
LayerIntersection< Amg::Vector3D > closestMaterialLayer(const Amg::Vector3D &gp, const Amg::Vector3D &dir, PropDirection pDir=alongMomentum, const BoundaryCheck &bchk=true) const
Return the closest layer with material description.
Definition: TrackingVolume.cxx:628
Trk::binZ
@ binZ
Definition: BinningType.h:49
Trk::oppositeMomentum
@ oppositeMomentum
Definition: PropDirection.h:21
Trk::TrackingVolume::boundarySurfaces
std::vector< SharedObject< BoundarySurface< TrackingVolume > > > & boundarySurfaces()
Method to return the BoundarySurfaces.
Definition: TrackingVolume.cxx:982
Trk::TrackingVolume::~TrackingVolume
~TrackingVolume() override
Destructor.
Definition: TrackingVolume.cxx:521
Trk::Material::Z
float Z
Definition: Material.h:122
Trk::BinnedArray::nextObject
virtual T * nextObject(const Amg::Vector3D &gp, const Amg::Vector3D &mom, bool associatedResult=true) const =0
Returns the pointer to the templated class object from the BinnedArray, takes 3D position & direction...
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
Trk::Intersection::pathLength
double pathLength
Definition: Intersection.h:26
Trk::TrackingVolume::associatedSubVolume
const TrackingVolume * associatedSubVolume(const Amg::Vector3D &gp) const
Return the associated sub Volume, returns THIS if no subVolume exists.
Definition: TrackingVolume.cxx:710
BinUtility.h
module_driven_slicing.layers
layers
Definition: module_driven_slicing.py:114
Trk::NavigationLayer
Definition: NavigationLayer.h:39
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
CylinderLayerAttemptsCalculator.h
PlotCalibFromCool.ib
ib
Definition: PlotCalibFromCool.py:419
Trk::SubtractedPlaneLayer
Definition: SubtractedPlaneLayer.h:34
Trk::SubtractedPlaneLayer::moveLayer
virtual void moveLayer(Amg::Transform3D &shift) override final
move the Layer
Definition: SubtractedPlaneLayer.cxx:72
VolumeBounds.h
NavBinnedArray1D.h
Layer.h
Trk::alongMomentum
@ alongMomentum
Definition: PropDirection.h:20
Trk::DiscSurface
Definition: DiscSurface.h:54
Trk::TrackingVolume::checkoutConfinedLayers
const LayerArray * checkoutConfinedLayers() const
Return the subLayerarray including the ownership.
Definition: TrackingVolume.cxx:1192
Trk::TrackingVolume::indexContainedMaterialLayers
void indexContainedMaterialLayers(GeometrySignature geoSig, int &offset)
reIndex the material layers of the TrackingVolume
Definition: TrackingVolume.cxx:864
Trk::BoundaryPlaneSurface
Definition: BoundaryPlaneSurface.h:38
Trk::ObjectAccessor::value_type
int value_type
Definition: ObjectAccessor.h:17
TRKDETDESCR_GEOMETRYSIGNATUREWEIGHT
#define TRKDETDESCR_GEOMETRYSIGNATUREWEIGHT
Definition: LayerIndex.h:19
BoundarySubtractedPlaneSurface.h
Trk::Layer::surfaceArray
const SurfaceArray * surfaceArray() const
Return the entire SurfaceArray, returns nullptr if no SurfaceArray.
pdg_comparison.X0
X0
Definition: pdg_comparison.py:314
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
Trk::NumberOfGeometryTypes
@ NumberOfGeometryTypes
Definition: GeometrySignature.h:43
GeoPrimitives.h
Trk::VolumeBounds
Definition: VolumeBounds.h:45
Trk::TrackingVolume::TrackingVolume
TrackingVolume()
Default Constructor.
Definition: TrackingVolume.cxx:48
CylinderVolumeBounds.h
Trk::TrackingVolume::cloneTV
TrackingVolume * cloneTV(Amg::Transform3D &transform) const
clone at new position
Definition: TrackingVolume.cxx:1235
Trk::PropDirection
PropDirection
Definition: PropDirection.h:19
Trk::BoundaryDiscSurface
Definition: BoundaryDiscSurface.h:40
A
Trk::GeometrySignature
GeometrySignature
Definition: GeometrySignature.h:24
SubtractedPlaneSurface.h
Trk::TrackingVolume::indexContainedStaticLayers
void indexContainedStaticLayers(GeometrySignature geoSig, int &offset)
reIndex the static layers of the TrackingVolume
Definition: TrackingVolume.cxx:817
ParticleGun_EoverP_Config.mom
mom
Definition: ParticleGun_EoverP_Config.py:63
Trk::Layer::surfaceRepresentation
virtual const Surface & surfaceRepresentation() const =0
Transforms the layer into a Surface representation for extrapolation.
Trk::BoundarySubtractedPlaneSurface
Definition: BoundarySubtractedPlaneSurface.h:39
Trk::TrackingVolume::assocDetachedSubVolumes
std::vector< const DetachedTrackingVolume * > assocDetachedSubVolumes(const Amg::Vector3D &gp, double tol) const
Return the associated detached subvolumes.
Definition: TrackingVolume.cxx:800
Trk::SubtractedPlaneSurface
Definition: SubtractedPlaneSurface.h:32
Trk::LayerIndex
Definition: LayerIndex.h:37
Trk::Material::A
float A
Definition: Material.h:121
Trk::ArraySpan
std::span< T > ArraySpan
Definition: DetachedTrackingVolume.h:34
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
Trk::CylinderSurface
Definition: CylinderSurface.h:55
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
Trk::TrackingVolume::boundarySurface
const BoundarySurface< TrackingVolume > * boundarySurface(const ObjectAccessor::value_type &oa) const
Get the BoundarySurface to the appointed Accessor state.
Definition: TrackingVolume.cxx:995
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
Trk::TrackingVolume::registerOutsideGlueVolumes
void registerOutsideGlueVolumes(GlueVolumesDescriptor *gvd)
Register the outside glue volumes - ordering is in the TrackingVolume Frame:
Definition: TrackingVolume.cxx:1199
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
Trk::TrackingVolume::synchronizeLayers
void synchronizeLayers(MsgStream &msgstream, double envelope=1.)
method to synchronize the layers with potentially updated volume bounds:
Definition: TrackingVolume.cxx:1427
CylinderSurface.h
Trk::PlaneLayer
Definition: PlaneLayer.h:40
Trk::Volume::clone
virtual Volume * clone() const
Pseudo-constructor.
Definition: Volume.cxx:78
SubtractedCylinderSurface.h
Trk::Layer::nextLayer
const Layer * nextLayer(const Amg::Vector3D &gp, const Amg::Vector3D &udir) const
getting the next/previous Layer if registered - unit for direction vector required
Definition: Layer.cxx:175
CylinderLayer.h
Trk::Surface::materialLayer
const Trk::Layer * materialLayer() const
return the material Layer
Trk::PlaneLayer::moveLayer
virtual void moveLayer(Amg::Transform3D &shift) override final
move the Layer
Definition: PlaneLayer.cxx:83
Trk::TrackingVolume::clear
void clear()
remove content
Definition: TrackingVolume.cxx:542
SubtractedPlaneLayer.h
Trk::LayerIndex::value
int value() const
layerIndex expressed in an integer
Definition: LayerIndex.h:71
Trk::Unsigned
@ Unsigned
Definition: GeometrySignature.h:33
Trk::BinUtility::binningValue
BinningValue binningValue(size_t ba=0) const
The type/value of the binning.
Definition: BinUtility.h:231
Trk::Material::X0
float X0
Definition: Material.h:119
beamspotman.dir
string dir
Definition: beamspotman.py:623
Trk::BinUtility
Definition: BinUtility.h:39
Trk::CylinderLayer
Definition: CylinderLayer.h:43
Trk::ConstSharedPtrSpan
Definition: TrackingVolume.h:67
Trk::Layer::registerLayerIndex
void registerLayerIndex(const LayerIndex &lIdx)
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
BoundaryDiscSurface.h
SimplePolygonBrepVolumeBounds.h
Trk::BinnedArray::arrayObjects
virtual BinnedArraySpan< T *const > arrayObjects()=0
Return all objects of the Array non-const we can still modify the T.
Trk::DistanceSolution::absClosest
double absClosest() const
Absolute Distance to closest solution.
Trk::TrackingVolume::moveTV
void moveTV(Amg::Transform3D &transform)
move the Tracking Volume
Definition: TrackingVolume.cxx:1387
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Trk::Intersection::valid
bool valid
Definition: Intersection.h:28
Trk::GlueVolumesDescriptor
Definition: GlueVolumesDescriptor.h:40
Trk::Material::rho
float rho
Definition: Material.h:123
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
Trk::DiscLayerAttemptsCalculator
Definition: DiscLayerAttemptsCalculator.h:23
Trk::VolumeBounds::decomposeToSurfaces
virtual const std::vector< const Trk::Surface * > * decomposeToSurfaces(const Amg::Transform3D &transform)=0
Method to decompose the Bounds into Surfaces, the Volume can turn them into BoundarySurfaces.
Trk::BoundaryCylinderSurface
Definition: BoundaryCylinderSurface.h:37
Rtt_histogram.n1
n1
Definition: Rtt_histogram.py:21
Trk::binR
@ binR
Definition: BinningType.h:50
Trk::TrackingVolume::createLayerAttemptsCalculator
void createLayerAttemptsCalculator()
Create Layer Attempts Caluclator.
Definition: TrackingVolume.cxx:1140
TrackingVolume.h
Trk::SharedObject
std::shared_ptr< T > SharedObject
Definition: SharedObject.h:24
BoundaryCylinderSurface.h
Trk::NavBinnedArray1D
Definition: NavBinnedArray1D.h:36
Trk::PlaneSurface
Definition: PlaneSurface.h:64
Trk::TrackingVolume::nextVolume
const TrackingVolume * nextVolume(const Amg::Vector3D &gp, const Amg::Vector3D &dir, PropDirection pDir=alongMomentum) const
Return the next volume along the navigation stream.
Definition: TrackingVolume.cxx:760
Trk::BoundaryCheck
Definition: BoundaryCheck.h:51
PlaneSurface.h
Trk::TrackingVolume::sign
void sign(GeometrySignature signat, GeometryType gtype=Static)
sign the volume - the geometry builder has to do that
Definition: TrackingVolume.cxx:941
Trk::Layer::previousLayer
const Layer * previousLayer(bool skipNavLayer=false) const
getting what's stored to be the previous Layer, boolean to skip navigation layers
Definition: Layer.cxx:155
DeMoScan.first
bool first
Definition: DeMoScan.py:536
Trk::SubtractedVolumeBounds
Definition: SubtractedVolumeBounds.h:40
Trk::TrackingVolume::compactify
void compactify(size_t &rSurfaces, size_t &tSurfaces)
compactify the memory usage in the event by setting ownership to TackingGeometry the referenced types...
Definition: TrackingVolume.cxx:1455
Trk::Volume::volumeBounds
const VolumeBounds & volumeBounds() const
returns the volumeBounds()
Definition: Volume.h:97
Trk::SurfaceType::Cylinder
@ Cylinder
Trk::Layer::layerMaterialProperties
const LayerMaterialProperties * layerMaterialProperties() const
getting the LayerMaterialProperties including full/pre/post update
convertTimingResiduals.offset
offset
Definition: convertTimingResiduals.py:71
CombinedVolumeBounds.h
DiscSurface.h
Trk::CylinderLayerAttemptsCalculator
Definition: CylinderLayerAttemptsCalculator.h:24
Trk::CombinedVolumeBounds::boundsOrientation
std::vector< bool > boundsOrientation() const
This method returns bounds orientation.
Definition: CombinedVolumeBounds.h:128
Trk::GeometryType
GeometryType
Definition: GeometrySignature.h:37
Trk::Material::dEdX
float dEdX
Definition: Material.h:124
SubtractedCylinderLayer.h
Trk::CylinderLayer::moveLayer
virtual void moveLayer(Amg::Transform3D &shift) override final
move the Layer
Definition: CylinderLayer.cxx:186
Trk::FullIntersection
Class extension to return the object, a represenation & the result.
Definition: Intersection.h:64
Trk::Material
Definition: Material.h:116
Trk::SubtractedCylinderLayer::moveLayer
virtual void moveLayer(Amg::Transform3D &shift) override final
move the Layer
Definition: SubtractedCylinderLayer.cxx:75
Trk::TrackingVolume::interlinkLayers
void interlinkLayers()
Register Next - Previous for Layers, set volumelink.
Definition: TrackingVolume.cxx:1156
Trk::BinnedArray
Definition: BinnedArray.h:38
Trk::SubtractedVolumeBounds::boundsOrientation
std::vector< bool > boundsOrientation() const
This method returns bounds orientation.
Definition: SubtractedVolumeBounds.h:124
Trk::CombinedVolumeBounds
Definition: CombinedVolumeBounds.h:42
Trk::TrackingVolume::m_boundarySurfaces
std::vector< SharedObject< BoundarySurface< TrackingVolume > > > m_boundarySurfaces
Definition: TrackingVolume.h:454
Trk::Surface
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:75
Trk::Volume
Definition: Volume.h:35
Trk::TrackingVolume
Definition: TrackingVolume.h:121
Trk::TrackingVolume::associatedLayer
const Layer * associatedLayer(const Amg::Vector3D &gp) const
Return the associated Layer.
Definition: TrackingVolume.cxx:569
Trk::BinnedArraySpan
std::span< T > BinnedArraySpan
Definition: BinnedArray.h:34
Trk::mappingMode
@ mappingMode
Definition: PropDirection.h:23
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
fitman.rho
rho
Definition: fitman.py:532
Trk::L0
@ L0
Definition: AlignModuleList.h:32
DiscLayerAttemptsCalculator.h
Trk::TrackingVolume::screenDump
void screenDump(MsgStream &msg) const
Definition: TrackingVolume.cxx:1506
Trk::SubtractedCylinderLayer
Definition: SubtractedCylinderLayer.h:36
PlaneLayer.h
Trk::Layer
Definition: Layer.h:73
SubtractedVolumeBounds.h
Trk::Layer::layerIndex
const LayerIndex & layerIndex() const
get the layerIndex