Skip to content

Commit

Permalink
Merge branch 'main' into feat-navigation-stream
Browse files Browse the repository at this point in the history
  • Loading branch information
asalzburger authored Aug 29, 2024
2 parents 92e39a7 + 809b378 commit e5bc617
Show file tree
Hide file tree
Showing 22 changed files with 1,277 additions and 325 deletions.
446 changes: 233 additions & 213 deletions Core/include/Acts/TrackFitting/GlobalChiSquareFitter.hpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,37 @@ class Surface;

namespace ActsExamples {

// Helper struct to find the sensitive surface candidates
struct SensitiveCandidates {
std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry = nullptr;
/// Find the sensitive surfaces for a given position
struct SensitiveCandidatesBase {
/// Get the sensitive surfaces for a given position
///
/// This fulfills the concept of a SensitiveCandidates
/// @param gctx the geometry context
/// @param position the position to look for sensitive surfaces
///
/// @return a vector of sensitive surfaces
virtual std::vector<const Acts::Surface*> queryPosition(
const Acts::GeometryContext& gctx,
const Acts::Vector3& position) const = 0;

/// Get all sensitive surfaces
///
/// @param gctx the geometry context
/// @param position the position to look for sensitive surfaces
///
/// @return a vector of sensitive surfaces
std::vector<const Acts::Surface*> operator()(
const Acts::GeometryContext& gctx, const Acts::Vector3& position) const {
std::vector<const Acts::Surface*> surfaces;

if (trackingGeometry != nullptr) {
auto layer = trackingGeometry->associatedLayer(gctx, position);

if (layer->surfaceArray() != nullptr) {
for (const auto& surface : layer->surfaceArray()->surfaces()) {
if (surface->associatedDetectorElement() != nullptr) {
surfaces.push_back(surface);
}
}
}
}
return surfaces;
}
virtual std::vector<const Acts::Surface*> queryAll() const = 0;

virtual ~SensitiveCandidatesBase() = default;
};

/// Implementation of the SensitiveCandidates for Gen1 geometry
struct SensitiveCandidates : public SensitiveCandidatesBase {
std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry = nullptr;

std::vector<const Acts::Surface*> queryPosition(
const Acts::GeometryContext& gctx,
const Acts::Vector3& position) const override;

std::vector<const Acts::Surface*> queryAll() const override;
};

/// This Mapper takes a (non-const) Geant4 geometry and maps
Expand All @@ -72,9 +75,6 @@ class SensitiveSurfaceMapper {
/// This prefix is used to indicate a sensitive volume that is matched
constexpr static std::string_view mappingPrefix = "ActsSensitive#";

using SensitiveCandidates = std::function<std::vector<const Acts::Surface*>(
const Acts::GeometryContext&, const Acts::Vector3&)>;

/// Configuration struct for the surface mapper
struct Config {
/// For which G4 material names we try to find a mapping
Expand All @@ -84,7 +84,7 @@ class SensitiveSurfaceMapper {
std::vector<std::string> volumeMappings;

/// The sensitive surfaces that are being mapped to
SensitiveCandidates candidateSurfaces;
std::shared_ptr<SensitiveCandidatesBase> candidateSurfaces;
};

/// State object that coutns the assignments and makes
Expand All @@ -94,6 +94,10 @@ class SensitiveSurfaceMapper {
/// there can be replicas)
std::multimap<const G4VPhysicalVolume*, const Acts::Surface*>
g4VolumeToSurfaces;

/// Record of the missing volumes
std::vector<std::pair<const G4VPhysicalVolume*, Acts::Transform3>>
missingVolumes;
};

/// Constructor with:
Expand All @@ -118,6 +122,20 @@ class SensitiveSurfaceMapper {
G4VPhysicalVolume* g4PhysicalVolume,
const Acts::Transform3& motherTransform) const;

/// Function that checks the success of the mapping, and exposes
/// some additional information for debugging
///
/// @param state state object after a call to remapSensitiveNames
/// @param gctx the geometry context
/// @param writeMissingG4VolsAsObj write the Geant4 volumes that are
/// not mapped to 'missing_g4_volumes.obj' in the working directory
/// @param writeMissingSurfacesAsObj write the sensitive surfaces that
/// where not mapped to 'missing_acts_surfaces.obj' in the working directory
/// @return Returns true only if all sensitive surfaces where mapped
bool checkMapping(const State& state, const Acts::GeometryContext& gctx,
bool writeMissingG4VolsAsObj = false,
bool writeMissingSurfacesAsObj = false) const;

protected:
/// Configuration object
Config m_cfg;
Expand Down
9 changes: 7 additions & 2 deletions Examples/Algorithms/Geant4/src/Geant4Simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,13 @@ ActsExamples::Geant4Simulation::Geant4Simulation(const Config& cfg,
"Remapping selected volumes from Geant4 to Acts::Surface::GeometryID");
cfg.sensitiveSurfaceMapper->remapSensitiveNames(
sState, Acts::GeometryContext{}, g4World, Acts::Transform3::Identity());
ACTS_INFO("Remapping successful for " << sState.g4VolumeToSurfaces.size()
<< " selected volumes.");

auto allSurfacesMapped = cfg.sensitiveSurfaceMapper->checkMapping(
sState, Acts::GeometryContext{}, false, false);
if (!allSurfacesMapped) {
ACTS_WARNING(
"Not all sensitive surfaces have been mapped to Geant4 volumes!");
}

sensitiveSteppingActionAccess->assignSurfaceMapping(
sState.g4VolumeToSurfaces);
Expand Down
Loading

0 comments on commit e5bc617

Please sign in to comment.