Skip to content

Commit

Permalink
refactor: TrackingVolume and VolumeBounds mutability (acts-project#3037)
Browse files Browse the repository at this point in the history
This PR:

- Updates the `TrackingVolume.cpp` files, moving some methods
- `TrackingVolume` holds mother volume as mutable
- `CuboidVolumeBounds` and `CylinderVolumeBounds`:
  - Produce their boundary surfaces when requested instead of ahead of time
  - Gain `set()` functions to modify their defining parameters (used for volume synchronization)
- `Volume` holds `VolumeBounds` as mutable internally, propagates mutability correctly (allows mutating non-const `Volume` instances)
- Removes the `TrackingVolume::create` factories (they don't really have a reason at this point)

Blocked by:

- acts-project#3026 
- acts-project#3030 
- acts-project#3032
- acts-project#3031
  • Loading branch information
paulgessinger authored and asalzburger committed May 21, 2024
1 parent 95a2a94 commit 9b77c9e
Show file tree
Hide file tree
Showing 25 changed files with 410 additions and 350 deletions.
20 changes: 12 additions & 8 deletions Core/include/Acts/Geometry/CuboidVolumeBounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,17 @@ class CuboidVolumeBounds : public VolumeBounds {
/// Constructor - from a fixed size array
///
/// @param values iw the bound values
CuboidVolumeBounds(const std::array<ActsScalar, eSize>& values) noexcept(
false)
: m_values(values) {
checkConsistency();
buildSurfaceBounds();
}
CuboidVolumeBounds(const std::array<ActsScalar, eSize>& values);

/// Copy Constructor
///
/// @param bobo is the source volume bounds to be copied
CuboidVolumeBounds(const CuboidVolumeBounds& bobo);
CuboidVolumeBounds(const CuboidVolumeBounds& bobo) = default;

/// Assignment operator
///
/// @param bobo is the source volume bounds to be assigned
CuboidVolumeBounds& operator=(const CuboidVolumeBounds& bobo);
CuboidVolumeBounds& operator=(const CuboidVolumeBounds& bobo) = default;

~CuboidVolumeBounds() override = default;

Expand Down Expand Up @@ -143,6 +138,15 @@ class CuboidVolumeBounds : public VolumeBounds {
/// @param bValue the class nested enum for the array access
ActsScalar get(BoundValues bValue) const { return m_values[bValue]; }

/// Set a bound value
/// @param bValue the bound value identifier
/// @param value the value to be set
void set(BoundValues bValue, ActsScalar value);

/// Set a range of bound values
/// @param keyValues the initializer list of key value pairs
void set(std::initializer_list<std::pair<BoundValues, ActsScalar>> keyValues);

/// Output Method for std::ostream
///
/// @param os is ostream operator to be dumped into
Expand Down
37 changes: 16 additions & 21 deletions Core/include/Acts/Geometry/CylinderVolumeBounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@
#include "Acts/Geometry/Volume.hpp"
#include "Acts/Geometry/VolumeBounds.hpp"
#include "Acts/Utilities/BinningType.hpp"
#include "Acts/Utilities/detail/periodic.hpp"

#include <array>
#include <cmath>
#include <iomanip>
#include <initializer_list>
#include <iosfwd>
#include <memory>
#include <ostream>
#include <stdexcept>
#include <vector>

namespace Acts {
Expand Down Expand Up @@ -96,36 +93,24 @@ class CylinderVolumeBounds : public VolumeBounds {
/// @param bevelMaxZ The bevel angle, in radians, for the positive side
CylinderVolumeBounds(ActsScalar rmin, ActsScalar rmax, ActsScalar halfz,
ActsScalar halfphi = M_PI, ActsScalar avgphi = 0.,
ActsScalar bevelMinZ = 0.,
ActsScalar bevelMaxZ = 0.) noexcept(false)
: m_values({rmin, rmax, halfz, halfphi, avgphi, bevelMinZ, bevelMaxZ}) {
checkConsistency();
buildSurfaceBounds();
}
ActsScalar bevelMinZ = 0., ActsScalar bevelMaxZ = 0.);

/// Constructor - from a fixed size array
///
/// @param values The bound values
CylinderVolumeBounds(const std::array<ActsScalar, eSize>& values) noexcept(
false)
: m_values(values) {
checkConsistency();
buildSurfaceBounds();
}
CylinderVolumeBounds(const std::array<ActsScalar, eSize>& values);

/// Constructor - extruded from cylinder bounds and thickness
///
/// @param cBounds the cylinder bounds
/// @param thickness of the extrusion
CylinderVolumeBounds(const CylinderBounds& cBounds,
ActsScalar thickness) noexcept(false);
CylinderVolumeBounds(const CylinderBounds& cBounds, ActsScalar thickness);

/// Constructor - extruded from radial bounds and thickness
///
/// @param rBounds the Radial bounds
/// @param thickness
CylinderVolumeBounds(const RadialBounds& rBounds,
ActsScalar thickness) noexcept(false);
CylinderVolumeBounds(const RadialBounds& rBounds, ActsScalar thickness);

/// Copy Constructor
///
Expand Down Expand Up @@ -199,9 +184,19 @@ class CylinderVolumeBounds : public VolumeBounds {
/// @param bValue the class nested enum for the array access
ActsScalar get(BoundValues bValue) const { return m_values[bValue]; }

/// Set a bound value
/// @param bValue the bound value identifier
/// @param value the value to be set
void set(BoundValues bValue, ActsScalar value);

/// Set a range of bound values
/// @param keyValues the initializer list of key value pairs
void set(std::initializer_list<std::pair<BoundValues, ActsScalar>> keyValues);

private:
/// The internal version of the bounds can be float/ActsScalar
std::array<ActsScalar, eSize> m_values{};

/// Bounds of the inner CylinderBounds
std::shared_ptr<const CylinderBounds> m_innerCylinderBounds{nullptr};
/// Bounds of the inner CylinderBounds
Expand All @@ -213,7 +208,7 @@ class CylinderVolumeBounds : public VolumeBounds {

/// Check the input values for consistency,
/// will throw a logic_exception if consistency is not given
void checkConsistency() noexcept(false);
void checkConsistency();

/// Helper method to create the surface bounds
void buildSurfaceBounds();
Expand Down
4 changes: 2 additions & 2 deletions Core/include/Acts/Geometry/CylinderVolumeHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class CylinderVolumeHelper : public ITrackingVolumeHelper {
MutableTrackingVolumePtr createTrackingVolume(
const GeometryContext& gctx, const LayerVector& layers,
std::shared_ptr<const IVolumeMaterial> volumeMaterial,
std::shared_ptr<const VolumeBounds> volumeBounds,
std::shared_ptr<VolumeBounds> volumeBounds,
MutableTrackingVolumeVector mtvVector = {},
const Transform3& transform = Transform3::Identity(),
const std::string& volumeName = "UndefinedVolume",
Expand Down Expand Up @@ -205,7 +205,7 @@ class CylinderVolumeHelper : public ITrackingVolumeHelper {
/// @param bType is the type of binning: equidistant, arbitrary
bool estimateAndCheckDimension(
const GeometryContext& gctx, const LayerVector& layers,
const CylinderVolumeBounds*& cylinderVolumeBounds,
std::shared_ptr<CylinderVolumeBounds>& cylinderVolumeBounds,
const Transform3& transform, double& rMinClean, double& rMaxClean,
double& zMinClean, double& zMaxClean, BinningValue& bValue,
BinningType bType = arbitrary) const;
Expand Down
2 changes: 1 addition & 1 deletion Core/include/Acts/Geometry/ITrackingVolumeHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ITrackingVolumeHelper {
virtual MutableTrackingVolumePtr createTrackingVolume(
const GeometryContext& gctx, const LayerVector& layers,
std::shared_ptr<const IVolumeMaterial> volumeMaterial,
std::shared_ptr<const VolumeBounds> volumeBounds,
std::shared_ptr<VolumeBounds> volumeBounds,
MutableTrackingVolumeVector mtvVector = {},
const Transform3& transform = Transform3::Identity(),
const std::string& volumeName = "UndefinedVolume",
Expand Down
157 changes: 27 additions & 130 deletions Core/include/Acts/Geometry/TrackingVolume.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,51 +113,38 @@ class TrackingVolume : public Volume {
TrackingVolume(const TrackingVolume&) = delete;
TrackingVolume& operator=(const TrackingVolume&) = delete;

/// Factory constructor for a container TrackingVolume
/// - by definition a Vacuum volume
/// Constructor for a container Volume
/// - vacuum filled volume either as a for other tracking volumes
///
/// @param transform is the global 3D transform to position the volume in
/// space
/// @param volumeBounds is the description of the volume boundaries
/// @param containedVolumes are the static volumes that fill this volume
/// @param volbounds is the description of the volume boundaries
/// @param containedVolumeArray are the static volumes that fill this volume
/// @param volumeName is a string identifier
///
/// @return shared pointer to a new TrackingVolume
static MutableTrackingVolumePtr create(
const Transform3& transform,
std::shared_ptr<const VolumeBounds> volumeBounds,
const std::shared_ptr<const TrackingVolumeArray>& containedVolumes =
nullptr,
const std::string& volumeName = "undefined") {
return MutableTrackingVolumePtr(new TrackingVolume(
transform, std::move(volumeBounds), containedVolumes, volumeName));
}
/// Factory constructor for Tracking Volumes with content
/// - can not be a container volume
TrackingVolume(const Transform3& transform,
std::shared_ptr<VolumeBounds> volbounds,
const std::shared_ptr<const TrackingVolumeArray>&
containedVolumeArray = nullptr,
const std::string& volumeName = "undefined");

/// Constructor for a full equipped Tracking Volume
///
/// @param transform is the global 3D transform to position the volume in
/// space
/// @param volumeBounds is the description of the volume boundaries
/// @param volumeMaterial is are materials of the tracking volume
/// @param containedLayers is the confined layer array (optional)
/// @param containedVolumes is the confined volume array (optional)
/// @param denseVolumes is the array of dense volulmes (optional)
/// @param staticLayerArray is the confined layer array (optional)
/// @param containedVolumeArray are the sub volumes if the volume is a
/// container
/// @param denseVolumeVector The contained dense volumes
/// @param volumeName is a string identifier
///
/// @return shared pointer to a new TrackingVolume
static MutableTrackingVolumePtr create(
const Transform3& transform,
std::shared_ptr<const VolumeBounds> volumeBounds,
TrackingVolume(
const Transform3& transform, std::shared_ptr<VolumeBounds> volumeBounds,
std::shared_ptr<const IVolumeMaterial> volumeMaterial,
std::unique_ptr<const LayerArray> containedLayers = nullptr,
std::shared_ptr<const TrackingVolumeArray> containedVolumes = nullptr,
MutableTrackingVolumeVector denseVolumes = {},
const std::string& volumeName = "undefined") {
return MutableTrackingVolumePtr(new TrackingVolume(
transform, std::move(volumeBounds), std::move(volumeMaterial),
std::move(containedLayers), std::move(containedVolumes),
std::move(denseVolumes), volumeName));
}
std::unique_ptr<const LayerArray> staticLayerArray = nullptr,
std::shared_ptr<const TrackingVolumeArray> containedVolumeArray = nullptr,
MutableTrackingVolumeVector denseVolumeVector = {},
const std::string& volumeName = "undefined");

/// Return the associated Layer to the global position
///
Expand Down Expand Up @@ -200,21 +187,6 @@ class TrackingVolume : public Volume {
const Vector3& direction, const NavigationOptions<Surface>& options,
const Logger& logger = getDummyLogger()) const;

/// @brief Return surfaces in given direction from bounding volume hierarchy
/// @tparam options_t Type of navigation options object for decomposition
///
/// @param gctx The current geometry context object, e.g. alignment
/// @param position The position to start from
/// @param direction The direction towards which to test
/// @param angle The opening angle
/// @param options The templated navigation options
///
/// @return Vector of surface candidates
std::vector<SurfaceIntersection> compatibleSurfacesFromHierarchy(
const GeometryContext& gctx, const Vector3& position,
const Vector3& direction, double angle,
const NavigationOptions<Surface>& options) const;

/// Return the associated sub Volume, returns THIS if no subVolume exists
///
/// @param gctx The current geometry context object, e.g. alignment
Expand Down Expand Up @@ -413,45 +385,13 @@ class TrackingVolume : public Volume {
/// Return the MotherVolume - if it exists
const TrackingVolume* motherVolume() const;

/// Return the MotherVolume - if it exists
TrackingVolume* motherVolume();

/// Set the MotherVolume
///
/// @param mvol is the mother volume
void setMotherVolume(const TrackingVolume* mvol);

protected:
/// Constructor for a container Volume
/// - vacuum filled volume either as a for other tracking volumes
///
/// @param transform is the global 3D transform to position the volume in
/// space
/// @param volbounds is the description of the volume boundaries
/// @param containedVolumeArray are the static volumes that fill this volume
/// @param volumeName is a string identifier
TrackingVolume(const Transform3& transform,
std::shared_ptr<const VolumeBounds> volbounds,
const std::shared_ptr<const TrackingVolumeArray>&
containedVolumeArray = nullptr,
const std::string& volumeName = "undefined");

/// Constructor for a full equipped Tracking Volume
///
/// @param transform is the global 3D transform to position the volume in
/// space
/// @param volumeBounds is the description of the volume boundaries
/// @param volumeMaterial is are materials of the tracking volume
/// @param staticLayerArray is the confined layer array (optional)
/// @param containedVolumeArray are the sub volumes if the volume is a
/// container
/// @param denseVolumeVector The contained dense volumes
/// @param volumeName is a string identifier
TrackingVolume(
const Transform3& transform,
std::shared_ptr<const VolumeBounds> volumeBounds,
std::shared_ptr<const IVolumeMaterial> volumeMaterial,
std::unique_ptr<const LayerArray> staticLayerArray = nullptr,
std::shared_ptr<const TrackingVolumeArray> containedVolumeArray = nullptr,
MutableTrackingVolumeVector denseVolumeVector = {},
const std::string& volumeName = "undefined");
void setMotherVolume(TrackingVolume* mvol);

private:
void connectDenseBoundarySurfaces(
Expand All @@ -474,7 +414,7 @@ class TrackingVolume : public Volume {
/// @param vol is the geometry id of the volume
/// as calculated by the TrackingGeometry
/// @param hook Identifier hook to be applied to surfaces
/// @param logger A @c LoggerWrapper instance
/// @param logger A @c Logger instance
///
void closeGeometry(
const IMaterialDecorator* materialDecorator,
Expand All @@ -489,7 +429,7 @@ class TrackingVolume : public Volume {
std::shared_ptr<const IVolumeMaterial> m_volumeMaterial{nullptr};

/// Remember the mother volume
const TrackingVolume* m_motherVolume{nullptr};
TrackingVolume* m_motherVolume{nullptr};

// the boundary surfaces
std::vector<TrackingVolumeBoundaryPtr> m_boundarySurfaces;
Expand All @@ -511,47 +451,4 @@ class TrackingVolume : public Volume {
std::string m_name;
};

inline const std::string& TrackingVolume::volumeName() const {
return m_name;
}

inline const IVolumeMaterial* TrackingVolume::volumeMaterial() const {
return m_volumeMaterial.get();
}

inline const std::shared_ptr<const IVolumeMaterial>&
TrackingVolume::volumeMaterialSharedPtr() const {
return m_volumeMaterial;
}

inline void TrackingVolume::assignVolumeMaterial(
std::shared_ptr<const IVolumeMaterial> material) {
m_volumeMaterial = std::move(material);
}

inline const LayerArray* TrackingVolume::confinedLayers() const {
return m_confinedLayers.get();
}

inline const MutableTrackingVolumeVector TrackingVolume::denseVolumes() const {
return m_confinedDenseVolumes;
}

inline std::shared_ptr<const TrackingVolumeArray>
TrackingVolume::confinedVolumes() const {
return m_confinedVolumes;
}

inline const TrackingVolume* TrackingVolume::motherVolume() const {
return m_motherVolume;
}

inline void TrackingVolume::setMotherVolume(const TrackingVolume* mvol) {
m_motherVolume = mvol;
}

#ifndef DOXYGEN
#include "Acts/Geometry/detail/TrackingVolume.ipp"
#endif

} // namespace Acts
Loading

0 comments on commit 9b77c9e

Please sign in to comment.