Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrackingVolume.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TrackingVolume.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2016-2018 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
17 #include "Acts/Geometry/Layer.hpp"
19 #include "Acts/Geometry/Volume.hpp"
30 #include "Acts/Utilities/Ray.hpp"
31 
32 #include <cstddef>
33 #include <functional>
34 #include <memory>
35 #include <string>
36 #include <unordered_map>
37 #include <utility>
38 #include <vector>
39 
40 #include <boost/container/small_vector.hpp>
41 
42 namespace Acts {
43 
44 class GlueVolumesDescriptor;
45 class VolumeBounds;
46 template <typename object_t>
48 class GeometryIdentifier;
49 class IMaterialDecorator;
50 class ISurfaceMaterial;
51 class IVolumeMaterial;
52 class Surface;
53 class TrackingVolume;
54 struct GeometryIdentifierHook;
55 
56 // master typedefs
57 using TrackingVolumePtr = std::shared_ptr<const TrackingVolume>;
58 using MutableTrackingVolumePtr = std::shared_ptr<TrackingVolume>;
59 
61  std::shared_ptr<const BoundarySurfaceT<TrackingVolume>>;
62 using TrackingVolumeBoundaries = std::vector<TrackingVolumeBoundaryPtr>;
63 
64 // possible contained
66 using TrackingVolumeVector = std::vector<TrackingVolumePtr>;
67 using MutableTrackingVolumeVector = std::vector<MutableTrackingVolumePtr>;
69 using LayerVector = std::vector<LayerPtr>;
70 
75 
83 
105 class TrackingVolume : public Volume {
106  friend class TrackingGeometry;
107 
108  public:
109  TrackingVolume() = delete;
110  ~TrackingVolume() override;
111  TrackingVolume(const TrackingVolume&) = delete;
112  TrackingVolume& operator=(const TrackingVolume&) = delete;
113 
126  const std::shared_ptr<const TrackingVolumeArray>& containedVolumes =
127  nullptr,
128  const std::string& volumeName = "undefined") {
130  transform, std::move(volumeBounds), containedVolumes, volumeName));
131  }
132 
146  const Transform3& transform, VolumeBoundsPtr volbounds,
147  std::vector<std::unique_ptr<Volume::BoundingBox>> boxStore,
148  std::vector<std::unique_ptr<const Volume>> descendants,
149  const Volume::BoundingBox* top,
150  std::shared_ptr<const IVolumeMaterial> volumeMaterial,
151  const std::string& volumeName = "undefined") {
153  transform, std::move(volbounds), std::move(boxStore),
154  std::move(descendants), top, std::move(volumeMaterial), volumeName));
155  }
156 
172  std::shared_ptr<const IVolumeMaterial> volumeMaterial,
173  std::unique_ptr<const LayerArray> containedLayers = nullptr,
174  std::shared_ptr<const TrackingVolumeArray> containedVolumes = nullptr,
176  const std::string& volumeName = "undefined") {
178  transform, std::move(volumeBounds), std::move(volumeMaterial),
179  std::move(containedLayers), std::move(containedVolumes),
181  }
182 
189  const Layer* associatedLayer(const GeometryContext& gctx,
190  const Vector3& position) const;
191 
203  boost::container::small_vector<LayerIntersection, 10> compatibleLayers(
204  const GeometryContext& gctx, const Vector3& position,
205  const Vector3& direction, const NavigationOptions<Layer>& options) const;
206 
219  boost::container::small_vector<BoundaryIntersection, 4> compatibleBoundaries(
220  const GeometryContext& gctx, const Vector3& position,
221  const Vector3& direction, const NavigationOptions<Surface>& options,
222  const Logger& logger = getDummyLogger()) const;
223 
234  std::vector<SurfaceIntersection> compatibleSurfacesFromHierarchy(
235  const GeometryContext& gctx, const Vector3& position,
236  const Vector3& direction, double angle,
237  const NavigationOptions<Surface>& options) const;
238 
247  const Vector3& position,
248  const double tol = 0.) const;
249 
252  const LayerArray* confinedLayers() const;
253 
255  std::shared_ptr<const TrackingVolumeArray> confinedVolumes() const;
256 
259 
269  template <ACTS_CONCEPT(SurfaceVisitor) visitor_t>
270  void visitSurfaces(visitor_t&& visitor) const {
271  if (!m_confinedVolumes) {
272  // no sub volumes => loop over the confined layers
273  if (m_confinedLayers) {
274  for (const auto& layer : m_confinedLayers->arrayObjects()) {
275  if (layer->surfaceArray() == nullptr) {
276  // no surface array (?)
277  continue;
278  }
279  for (const auto& srf : layer->surfaceArray()->surfaces()) {
280  visitor(srf);
281  }
282  }
283  }
284  } else {
285  // contains sub volumes
286  for (const auto& volume : m_confinedVolumes->arrayObjects()) {
287  volume->visitSurfaces(visitor);
288  }
289  }
290  }
291 
293  const std::string& volumeName() const;
294 
297 
299  const IVolumeMaterial* volumeMaterial() const;
300 
302  const std::shared_ptr<const IVolumeMaterial>& volumeMaterialSharedPtr() const;
303 
313  std::shared_ptr<const ISurfaceMaterial> surfaceMaterial,
314  BoundarySurfaceFace bsFace);
315 
323  void assignVolumeMaterial(std::shared_ptr<const IVolumeMaterial> material);
324 
333  void glueTrackingVolume(const GeometryContext& gctx,
334  BoundarySurfaceFace bsfMine, TrackingVolume* neighbor,
335  BoundarySurfaceFace bsfNeighbor);
336 
345  void glueTrackingVolumes(
346  const GeometryContext& gctx, BoundarySurfaceFace bsfMine,
347  const std::shared_ptr<TrackingVolumeArray>& neighbors,
348  BoundarySurfaceFace bsfNeighbor);
349 
360  std::shared_ptr<const BoundarySurfaceT<TrackingVolume>> bs,
361  bool checkmaterial = true);
362 
372 
379 
383  bool hasBoundingVolumeHierarchy() const;
384 
388  void registerColorCode(unsigned int icolor);
389 
391  unsigned int colorCode() const;
392 
394  const TrackingVolume* motherVolume() const;
395 
399  void setMotherVolume(const TrackingVolume* mvol);
400 
401  protected:
410  TrackingVolume(const Transform3& transform, VolumeBoundsPtr volbounds,
411  const std::shared_ptr<const TrackingVolumeArray>&
412  containedVolumeArray = nullptr,
413  const std::string& volumeName = "undefined");
414 
415  TrackingVolume(const Transform3& transform, VolumeBoundsPtr volbounds,
416  std::vector<std::unique_ptr<Volume::BoundingBox>> boxStore,
417  std::vector<std::unique_ptr<const Volume>> descendants,
418  const Volume::BoundingBox* top,
419  std::shared_ptr<const IVolumeMaterial> volumeMaterial,
420  const std::string& volumeName = "undefined");
421 
434  const Transform3& transform, VolumeBoundsPtr volumeBounds,
435  std::shared_ptr<const IVolumeMaterial> volumeMaterial,
436  std::unique_ptr<const LayerArray> staticLayerArray = nullptr,
437  std::shared_ptr<const TrackingVolumeArray> containedVolumeArray = nullptr,
438  MutableTrackingVolumeVector denseVolumeVector = {},
439  const std::string& volumeName = "undefined");
440 
441  private:
443  MutableTrackingVolumeVector& confinedDenseVolumes);
444 
446  void createBoundarySurfaces();
447 
452  void synchronizeLayers(double envelope = 1.) const;
453 
464  void closeGeometry(
465  const IMaterialDecorator* materialDecorator,
466  std::unordered_map<GeometryIdentifier, const TrackingVolume*>& volumeMap,
467  size_t& vol, const GeometryIdentifierHook& hook,
468  const Logger& logger = getDummyLogger());
469 
471  void interlinkLayers();
472 
474  std::shared_ptr<const IVolumeMaterial> m_volumeMaterial{nullptr};
475 
478 
479  // the boundary surfaces
480  std::vector<TrackingVolumeBoundaryPtr> m_boundarySurfaces;
481 
484  std::unique_ptr<const LayerArray> m_confinedLayers = nullptr;
485 
487  std::shared_ptr<const TrackingVolumeArray> m_confinedVolumes = nullptr;
488 
491 
494 
497 
499  unsigned int m_colorCode{20};
500 
502  std::vector<std::unique_ptr<const Volume::BoundingBox>> m_boundingBoxes;
503  std::vector<std::unique_ptr<const Volume>> m_descendantVolumes;
504  const Volume::BoundingBox* m_bvhTop{nullptr};
505 };
506 
508  return m_name;
509 }
510 
512  return m_volumeMaterial.get();
513 }
514 
515 inline const std::shared_ptr<const IVolumeMaterial>&
517  return m_volumeMaterial;
518 }
519 
521  std::shared_ptr<const IVolumeMaterial> material) {
522  m_volumeMaterial = std::move(material);
523 }
524 
526  return m_confinedLayers.get();
527 }
528 
530  return m_confinedDenseVolumes;
531 }
532 
533 inline std::shared_ptr<const TrackingVolumeArray>
535  return m_confinedVolumes;
536 }
537 
538 inline void TrackingVolume::registerColorCode(unsigned int icolor) {
539  m_colorCode = icolor;
540 }
541 
542 inline unsigned int TrackingVolume::colorCode() const {
543  return m_colorCode;
544 }
545 
547  return m_motherVolume;
548 }
549 
551  m_motherVolume = mvol;
552 }
553 
555  return m_bvhTop != nullptr;
556 }
557 
558 #ifndef DOXYGEN
560 #endif
561 
562 } // namespace Acts