Skip to content

Commit

Permalink
feat: volume agnostic material interaction (#2465)
Browse files Browse the repository at this point in the history
This PR introduces an `InteractionVolum` helper class that allows to switch between `TrackingVolume` and `DetectorVolume` and through that makes the material interaction recording struct quasi volume agnostic.
  • Loading branch information
asalzburger committed Sep 20, 2023
1 parent af4fb26 commit dc13bc0
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 11 deletions.
43 changes: 41 additions & 2 deletions Core/include/Acts/Material/MaterialInteraction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,52 @@
#pragma once

#include "Acts/Definitions/Algebra.hpp"
#include "Acts/Detector/DetectorVolume.hpp"
#include "Acts/Geometry/GeometryIdentifier.hpp"
#include "Acts/Geometry/TrackingVolume.hpp"
#include "Acts/Material/MaterialSlab.hpp"

namespace Acts {

class Surface;
class TrackingVolume;

/// @brief The Material interaction volume struct
/// It acts as a switch between detctor and tracking volume
/// as long as those co-exist alongside
struct InteractionVolume {
/// The tracking volume
const TrackingVolume* trackingVolume = nullptr;
/// The detector volume
const Experimental::DetectorVolume* detectorVolume = nullptr;

/// Empty constructor
InteractionVolume() = default;

/// Constructor from tracking volume
/// @param tv The tracking volume
InteractionVolume(const TrackingVolume* tv) : trackingVolume(tv) {}

/// Constructor from detector volume
/// @param dv The detector volume
InteractionVolume(const Experimental::DetectorVolume* dv)
: detectorVolume(dv) {}

/// Forward the geometry identifier
GeometryIdentifier geometryId() const {
if (trackingVolume != nullptr) {
return trackingVolume->geometryId();
} else if (detectorVolume != nullptr) {
return detectorVolume->geometryId();
} else {
return GeometryIdentifier();
}
}

/// Check if the volume is valid
bool empty() const {
return trackingVolume == nullptr and detectorVolume == nullptr;
}
};

/// @brief The Material interaction struct
/// It records the surface and the passed material
Expand All @@ -42,7 +81,7 @@ struct MaterialInteraction {
/// The surface where the interaction occurred.
const Surface* surface = nullptr;
/// The volume where the interaction occurred.
const TrackingVolume* volume = nullptr;
InteractionVolume volume{};
/// Update the volume step to implement the proper step size
bool updatedVolumeStep = false;
/// The path correction factor due to non-zero incidence on the surface.
Expand Down
6 changes: 3 additions & 3 deletions Core/include/Acts/Propagator/MaterialInteractor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ struct MaterialInteractor {
const navigator_t& navigator, result_type& result,
const Logger& logger) const {
// In case of Volume material update the result of the previous step
if (recordInteractions && !result.materialInteractions.empty() &&
result.materialInteractions.back().volume != nullptr &&
if (recordInteractions and not result.materialInteractions.empty() and
not result.materialInteractions.back().volume.empty() and
result.materialInteractions.back().updatedVolumeStep == false) {
updateResult(state, stepper, result);
}
Expand Down Expand Up @@ -146,7 +146,7 @@ struct MaterialInteractor {
mi.sigmaTheta2 = d.varianceTheta;
mi.sigmaQoP2 = d.varianceQoverP;
mi.surface = d.surface;
mi.volume = nullptr;
mi.volume = InteractionVolume();
mi.pathCorrection = d.pathCorrection;
mi.materialSlab = d.slab;
result.materialInteractions.push_back(std::move(mi));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "Acts/Definitions/PdgParticle.hpp"
#include "Acts/Geometry/TrackingVolume.hpp"
#include "Acts/Material/ISurfaceMaterial.hpp"
#include "Acts/Material/MaterialInteraction.hpp"
#include "Acts/Material/MaterialSlab.hpp"
#include "Acts/Surfaces/Surface.hpp"

Expand All @@ -20,8 +21,8 @@ namespace detail {

/// @brief Struct to handle volume material interaction
struct VolumeMaterialInteraction {
/// Data from the propagation state
const TrackingVolume* volume = nullptr;
/// The material interaction volume
InteractionVolume volume{};
/// The particle current position
const Vector3 pos = Vector3::Zero();
/// The particle current time
Expand Down
5 changes: 2 additions & 3 deletions Examples/Io/Root/src/RootMaterialTrackWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,9 @@ ActsExamples::ProcessCode ActsExamples::RootMaterialTrackWriter::writeT(

// store volume information
if (m_cfg.storeVolume) {
const Acts::Volume* volume = mint.volume;
Acts::GeometryIdentifier vlayerID;
if (volume != nullptr) {
vlayerID = volume->geometryId();
if (not mint.volume.empty()) {
vlayerID = mint.volume.geometryId();
m_vol_id.push_back(vlayerID.value());
} else {
vlayerID.setVolume(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ BOOST_AUTO_TEST_CASE(volume_material_interaction_test) {

// Build the VolumeMaterialInteraction & test assignments
detail::VolumeMaterialInteraction volMatInt(volume.get(), state, stepper);
BOOST_CHECK_EQUAL(volMatInt.volume, volume.get());
BOOST_CHECK_EQUAL(volMatInt.volume.trackingVolume, volume.get());
BOOST_CHECK_EQUAL(volMatInt.pos, stepper.position(state.stepping));
BOOST_CHECK_EQUAL(volMatInt.time, stepper.time(state.stepping));
BOOST_CHECK_EQUAL(volMatInt.dir, stepper.direction(state.stepping));
Expand Down

0 comments on commit dc13bc0

Please sign in to comment.