Skip to content

Commit

Permalink
Merge branch 'main' into refactor-direction-transform-jacobian
Browse files Browse the repository at this point in the history
  • Loading branch information
andiwand authored Dec 21, 2023
2 parents 8b9afba + 73553d3 commit cdd4f96
Show file tree
Hide file tree
Showing 81 changed files with 3,187 additions and 1,443 deletions.
Binary file modified CI/physmon/reference/performance_amvf_gridseeder_ttbar_hist.root
Binary file not shown.
101 changes: 99 additions & 2 deletions Core/include/Acts/Detector/GeometryIdGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ class GeometryIdGenerator final : public IGeometryIdGenerator {

~GeometryIdGenerator() override = default;

/// @brief Interface method to generata a geometry id cache
/// @return a geometry id cache decorated in a std::any object
/// @brief Interface method to generate a geometry id cache
/// @return a geometry id cache wrapped in a std::any object
IGeometryIdGenerator::GeoIdCache generateCache() const final;

/// @brief Method for assigning a geometry id to a detector volume
Expand Down Expand Up @@ -121,5 +121,102 @@ class GeometryIdGenerator final : public IGeometryIdGenerator {
std::unique_ptr<const Logger> m_logger;
};

/// This is a chained tgeometry id generator that will be in seuqnce
/// @tparam generators_t the generators that will be called in sequence
///
/// @note the generators are expected to be of pointer type
template <typename... generators_t>
class ChainedGeometryIdGenerator : public IGeometryIdGenerator {
public:
struct Cache {
/// The caches
std::array<IGeometryIdGenerator::GeoIdCache, sizeof...(generators_t)>
storage;
};

/// The stored generators
std::tuple<generators_t...> generators;

/// Constructor for chained generators_t in a tuple, this will unroll
/// the tuple and call them in sequence
///
/// @param gens the updators to be called in chain
/// @param mlogger is the logging instance
ChainedGeometryIdGenerator(const std::tuple<generators_t...>&& gens,
std::unique_ptr<const Logger> mlogger =
getDefaultLogger("ChainedGeometryIdGenerator",
Logging::INFO))
: generators(std::move(gens)), m_logger(std::move(mlogger)) {}

/// @brief Interface method to generate a geometry id cache
/// @return a geometry id cache wrapped in a std::any object
IGeometryIdGenerator::GeoIdCache generateCache() const final {
// Unfold the tuple and add the attachers
Cache cache;
std::size_t it = 0;
std::apply(
[&](auto&&... generator) {
((cache.storage[it++] = generator->generateCache()), ...);
},
generators);
return cache;
}

/// @brief Method for assigning a geometry id to a detector volume
///
/// @param cache is the cache object for e.g. object counting
/// @param dVolume the detector volume to assign the geometry id to
void assignGeometryId(IGeometryIdGenerator::GeoIdCache& cache,
DetectorVolume& dVolume) const final {
ACTS_VERBOSE("Assigning chained geometry id to volume.");
assign(cache, dVolume);
}

/// @brief Method for assigning a geometry id to a portal
///
/// @param cache is the cache object for e.g. object counting
/// @param portal the portal to assign the geometry id to
void assignGeometryId(IGeometryIdGenerator::GeoIdCache& cache,
Portal& portal) const final {
ACTS_VERBOSE("Assigning chained geometry id to portal.");
assign(cache, portal);
}

/// @brief Method for assigning a geometry id to a surface
///
/// @param cache is the cache object for e.g. object counting
/// @param surface the surface to assign the geometry id to
void assignGeometryId(IGeometryIdGenerator::GeoIdCache& cache,
Surface& surface) const final {
ACTS_VERBOSE("Assigning chained geometry id to surface.");
assign(cache, surface);
}

private:
/// @brief Helper to run through the chain of generators
///
/// @tparam gometry_object_t the geometry object type
///
/// @param the cache object with the array of sub caches
/// @param object the object to assign the geometry id to
template <typename gometry_object_t>
void assign(IGeometryIdGenerator::GeoIdCache& cache,
gometry_object_t& object) const {
std::size_t it = 0;
auto& sCache = std::any_cast<Cache&>(cache);
std::apply(
[&](auto&&... generator) {
(generator->assignGeometryId(sCache.storage[it++], object), ...);
},
generators);
}

/// Private access method to the logger
const Logger& logger() const { return *m_logger; }

/// logging instance
std::unique_ptr<const Logger> m_logger;
};

} // namespace Experimental
} // namespace Acts
148 changes: 148 additions & 0 deletions Core/include/Acts/Detector/GeometryIdMapper.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
// This file is part of the Acts project.
//
// Copyright (C) 2023 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#pragma once

#include "Acts/Detector/DetectorVolume.hpp"
#include "Acts/Detector/Portal.hpp"
#include "Acts/Detector/interface/IGeometryIdGenerator.hpp"
#include "Acts/Geometry/GeometryIdentifier.hpp"
#include "Acts/Surfaces/Surface.hpp"

#include <map>

namespace Acts {
namespace Experimental {

/// @brief This is a mapper of geometry ids, which can be used to
/// assign predefined geometry ids to objects
///
/// @tparam SourceIdentifier is the type of the source identifier
/// @tparam SourceCapture is the type of the source capture function/struct
///
/// The source capture function/struct is a callable object/function that
/// can navigate from the provided surface to the source identifier. Usually
/// this would happen via the associated detector element.
///
/// The only requirement is that the source identifier can be established
/// from the object that receives the target geometry id itself.
template <typename SourceIdentifier, typename SourceCapture>
class GeometryIdMapper final : public IGeometryIdGenerator {
public:
/// @brief Nested config struct
struct Config {
/// The source identifier to target geometry Id map
std::map<SourceIdentifier, GeometryIdentifier> sourceTargetMap;
/// The source capture function
SourceCapture sourceCapture = SourceCapture();
};

/// @brief Cache object
struct Cache {
unsigned int volumeCounter = 0u;
unsigned int portalCounter = 0u;
unsigned int surfaceCounter = 0u;
};

/// @brief Constructor with config
///
/// @param cfg is the geometry configuration object
/// @param mlogger is the logging instance
GeometryIdMapper(const Config& cfg,
std::unique_ptr<const Logger> mlogger =
getDefaultLogger("GeometryIdMapper", Logging::INFO))
: m_cfg(cfg), m_logger(std::move(mlogger)) {}

~GeometryIdMapper() override = default;

/// @brief Interface method to generate a geometry id cache
/// @return a geometry id cache wrapped in a std::any object
IGeometryIdGenerator::GeoIdCache generateCache() const final {
return Cache{0u, 0u, 0u};
}

/// @brief Method for assigning a geometry id to a detector volume
///
/// @param cache is the cache object for e.g. object counting
/// @param dVolume the detector volume to assign the geometry id to
void assignGeometryId(IGeometryIdGenerator::GeoIdCache& cache,
DetectorVolume& dVolume) const final {
auto& sCache = std::any_cast<Cache&>(cache);
/// Retrieve the source id for the detector volume
SourceIdentifier vID = m_cfg.sourceCapture(dVolume);
auto source = m_cfg.sourceTargetMap.find(vID);
if (source != m_cfg.sourceTargetMap.end()) {
dVolume.assignGeometryId(source->second);
ACTS_VERBOSE("Assigning geometry id " << source->second << " to volume "
<< dVolume.name() << " with id "
<< vID);
sCache.volumeCounter++;
}

// Portals
std::for_each(dVolume.portalPtrs().begin(), dVolume.portalPtrs().end(),
[&](auto& portal) { assignGeometryId(cache, *portal); });

// Surfaces
std::for_each(dVolume.surfacePtrs().begin(), dVolume.surfacePtrs().end(),
[&](auto& surface) { assignGeometryId(cache, *surface); });

// Sub volumes
std::for_each(dVolume.volumePtrs().begin(), dVolume.volumePtrs().end(),
[&](auto& volume) { assignGeometryId(cache, *volume); });
}

/// @brief Method for assigning a geometry id to a portal
///
/// @param cache is the cache object for e.g. object counting
/// @param portal the portal to assign the geometry id to
void assignGeometryId(IGeometryIdGenerator::GeoIdCache& cache,
Portal& portal) const final {
auto& sCache = std::any_cast<Cache&>(cache);
/// Retrieve the source id for the portal
SourceIdentifier pID = m_cfg.sourceCapture(portal);
auto source = m_cfg.sourceTargetMap.find(pID);
if (source != m_cfg.sourceTargetMap.end()) {
portal.surface().assignGeometryId(source->second);
ACTS_VERBOSE("Assigning geometry id " << source->second << " to portal "
<< " with id " << pID);
sCache.portalCounter++;
}
}

/// @brief Method for assigning a geometry id to a surface
///
/// @param cache is the cache object for e.g. object counting
/// @param surface the surface to assign the geometry id to
void assignGeometryId(IGeometryIdGenerator::GeoIdCache& cache,
Surface& surface) const final {
auto& sCache = std::any_cast<Cache&>(cache);
/// Retrieve the source id for the surface
SourceIdentifier sID = m_cfg.sourceCapture(surface);
auto source = m_cfg.sourceTargetMap.find(sID);
if (source != m_cfg.sourceTargetMap.end()) {
ACTS_VERBOSE("Assigning geometry id " << source->second << " to surface "
<< " with id " << sID);
surface.assignGeometryId(source->second);
sCache.surfaceCounter++;
}
}

private:
/// Configuration object
Config m_cfg;

/// Private access method to the logger
const Logger& logger() const { return *m_logger; }

/// logging instance
std::unique_ptr<const Logger> m_logger;
};

} // namespace Experimental
} // namespace Acts
4 changes: 2 additions & 2 deletions Core/include/Acts/Detector/interface/IGeometryIdGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class IGeometryIdGenerator {

virtual ~IGeometryIdGenerator() = default;

/// @brief Virtual interface method to generata a geometry id cache
/// @return a geometry id cache decorated in a std::any object
/// @brief Virtual interface method to generate a geometry id cache
/// @return a geometry id cache wrapped in a std::any object
virtual GeoIdCache generateCache() const = 0;

/// The virtual interface definition for assigning a geometry id to
Expand Down
Loading

0 comments on commit cdd4f96

Please sign in to comment.