Skip to content

Commit

Permalink
Merge branch 'main' into TimeClustering
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Oct 4, 2024
2 parents 225a488 + 74244eb commit 23f4530
Show file tree
Hide file tree
Showing 12 changed files with 1,436 additions and 58 deletions.
225 changes: 225 additions & 0 deletions Core/include/Acts/Geometry/PortalShell.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
// This file is part of the ACTS project.
//
// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/.

#pragma once

#include "Acts/Geometry/BoundarySurfaceFace.hpp"
#include "Acts/Utilities/BinningType.hpp"
#include "Acts/Utilities/Logger.hpp"

#include <array>
#include <memory>

namespace Acts {

class Portal;
class TrackingVolume;
class GeometryContext;

/// @class PortalShellBase
/// The portal shell of a volume is the set of portals that describes
/// connections "outside" of the volume. Which boundary surfaces of a volume are
/// included in the shell depends on the volume. Portal shells are only used
/// during geometry construction, and are not part of the final geometry
/// description.
///
/// This class is the base class for all portal shells
class PortalShellBase {
public:
/// Virtusl destructor
virtual ~PortalShellBase() = default;

/// Connect a volume to the outer side of all portal shells. Which "side" is
/// "outer" depends on the volume type.
/// This method essentially creates a @c TrivialPortalLink on the unconnected
/// side of each portal that is part of the chell
/// @param volume The volume to connect
virtual void connectOuter(TrackingVolume& volume) = 0;

/// Get the number of portals in the shell. This number depends on the volume
/// type
/// @return The number of portals in the shell
virtual std::size_t size() const = 0;

/// Instruct the shell to register the portals with the volume, handing over
/// shared ownership in the process.
/// @note The target volume depends on the shell type, e.g. composite shells
/// like the @c CylinerStackPortalShell register portals to the *correct*
/// volumes.
virtual void applyToVolume() = 0;

/// Check if a portal is *valid*, e.g. if non of the portals has two
/// unconnected sides.
/// @return True if the shell is valid, false otherwise
virtual bool isValid() const = 0;

/// Get a label for the portal shell for debugging purposes
/// @return A label for the portal shell
virtual std::string label() const = 0;
};

/// @class CylinderPortalShell
/// Base class for cylinder shaped portal shells, e.g. shells for cylinder
/// volumes
class CylinderPortalShell : public PortalShellBase {
public:
/// Enum describing the possible faces of a cylinder portal shell
/// @note These values are synchronized with the BoundarySurfaceFace enum.
/// Once Gen1 is removed, this can be changed.
enum class Face : unsigned int {
PositiveDisc = BoundarySurfaceFace::positiveFaceXY,
NegativeDisc = BoundarySurfaceFace::negativeFaceXY,
OuterCylinder = BoundarySurfaceFace::tubeOuterCover,
InnerCylinder = BoundarySurfaceFace::tubeInnerCover,
NegativePhiPlane = BoundarySurfaceFace::tubeSectorNegativePhi,
PositivePhiPlane = BoundarySurfaceFace::tubeSectorPositivePhi
};

using enum Face;

/// Retrieve the portal associated to the given face. Can be nullptr if unset.
/// @param face The face to retrieve the portal for
/// @return The portal associated to the face
virtual Portal* portal(Face face) = 0;

/// Retrieve a shared_ptr for the portal associated to the given face. Can be
/// nullptr if unset.
/// @param face The face to retrieve the portal for
/// @return The portal associated to the face
virtual std::shared_ptr<Portal> portalPtr(Face face) = 0;

/// Set the portal associated to the given face.
/// @param portal The portal to set
/// @param face The face to set the portal
virtual void setPortal(std::shared_ptr<Portal> portal, Face face) = 0;

/// @copydoc PortalShellBase::connectOuter
void connectOuter(TrackingVolume& volume) override;
};

/// Output stream operator for the CylinderPortalShell::Face enum
/// @param os The output stream
/// @param face The face to output
/// @return The output stream
std::ostream& operator<<(std::ostream& os, CylinderPortalShell::Face face);

/// @class SingleCylinderPortalShell
/// This class describes a cylinder shell containing a single volume. The
/// available faces depend on the configuration of the cylinder volume bounds.
/// If a phi sector is configured, the shell will have corresponding portal
/// slots. If the inner radius is non-zero, the shell will have an inner
/// cylinder portal slot.
class SingleCylinderPortalShell : public CylinderPortalShell {
public:
/// Construct a single cylinder portal shell for the given volume
/// @param volume The volume to create the shell for
explicit SingleCylinderPortalShell(TrackingVolume& volume);

/// @copydoc PortalShellBase::size
std::size_t size() const final;

/// @copydoc CylinderPortalShell::portal
Portal* portal(Face face) final;

/// @copydoc CylinderPortalShell::portalPtr
std::shared_ptr<Portal> portalPtr(Face face) final;

/// @copydoc CylinderPortalShell::setPortal
void setPortal(std::shared_ptr<Portal> portal, Face face) final;

/// @copydoc PortalShellBase::applyToVolume
void applyToVolume() override;

/// @copydoc PortalShellBase::isValid
bool isValid() const override;

/// @copydoc PortalShellBase::label
std::string label() const override;

private:
std::array<std::shared_ptr<Portal>, 6> m_portals{};

TrackingVolume* m_volume;
};

/// @class CylinderStackPortalShell
/// This class describes a cylinder shell containing multiple volumes. The
/// available faces depend on the configuration of the cylinder volume bounds.
/// @note The stack shell currently does not support phi sectors
/// The stack can be oriented along the (local) z or r direction, which drives
/// the stacking. Depending on the direction, portals on the shells of children
/// are merged or fused. Subsequently, portal access respects shared portals
/// between shells. Below is an illustration of a stack in the r direction:
///
/// Fused +-----------------+
/// portals ----+ | |
/// | | v OuterCylinder
/// | +------+------+
/// | | | |
/// | | | |<--+
/// +--+---+ v | |
/// +---+---------+ |
/// | | | | Shared portal
/// | | |<--+--- (grid)
/// | v | | PositiveDisc
/// +-------------+ |
/// r ^ | | |
/// | | |<--+
/// | | |
/// | +-------------+ InnerCylinder
/// +-----> ^ (if rMin>0)
/// z | |
/// +-----------------+
///
/// @note The shells must be ordered in the given direction
/// Depending on the stack direction, the portal lookup will return different
/// portals. In the illustration above, the `PositiveDisc` portal is shared
/// among all shells, while the `OuterCylinder` and `InnerCylinder` portals are
/// looked up from the innermost and outermost shell in the r direction.
class CylinderStackPortalShell : public CylinderPortalShell {
public:
/// Construct the portal shell stack from the given shells
/// @param gctx The geometry context
/// @param shells The shells to stack
/// @note The shells must be ordered in the given direction
/// @param direction The stacking direction
/// @param logger A logging instance for debugging
CylinderStackPortalShell(const GeometryContext& gctx,
std::vector<CylinderPortalShell*> shells,
BinningValue direction,
const Logger& logger = getDummyLogger());

/// @copydoc PortalShellBase::size
std::size_t size() const final;

/// @copydoc CylinderPortalShell::portal
Portal* portal(Face face) final;

/// @copydoc CylinderPortalShell::portalPtr
std::shared_ptr<Portal> portalPtr(Face face) final;

/// @copydoc CylinderPortalShell::setPortal
void setPortal(std::shared_ptr<Portal> portal, Face face) final;

void applyToVolume() override {
// No-op, because it's a composite portal shell
}

/// @copydoc PortalShellBase::isValid
bool isValid() const override;

/// @copydoc PortalShellBase::label
std::string label() const override;

private:
BinningValue m_direction;
std::vector<CylinderPortalShell*> m_shells;
bool m_hasInnerCylinder{true};
};

} // namespace Acts
20 changes: 13 additions & 7 deletions Core/include/Acts/Seeding/detail/CylindricalSpacePointGrid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ template <typename external_spacepoint_t>
using CylindricalSpacePointGrid = Acts::Grid<
std::vector<const external_spacepoint_t*>,
Acts::Axis<Acts::AxisType::Equidistant, Acts::AxisBoundaryType::Closed>,
Acts::Axis<Acts::AxisType::Variable, Acts::AxisBoundaryType::Bound>,
Acts::Axis<Acts::AxisType::Variable, Acts::AxisBoundaryType::Bound>>;

/// Cylindrical Binned Group
Expand All @@ -35,22 +36,25 @@ using CylindricalBinnedGroupIterator = Acts::BinnedGroupIterator<

struct CylindricalSpacePointGridConfig {
// minimum pT to be found by seedFinder
float minPt = 0;
float minPt = 0 * Acts::UnitConstants::MeV;
// maximum extension of sensitive detector layer relevant for seeding as
// distance from x=y=0 (i.e. in r)
float rMax = 0;
float rMax = 320 * Acts::UnitConstants::mm;
// maximum extension of sensitive detector layer relevant for seeding as
// distance from x=y=0 (i.e. in r)
float rMin = 0 * Acts::UnitConstants::mm;
// maximum extension of sensitive detector layer relevant for seeding in
// positive direction in z
float zMax = 0;
float zMax = 0 * Acts::UnitConstants::mm;
// maximum extension of sensitive detector layer relevant for seeding in
// negative direction in z
float zMin = 0;
float zMin = 0 * Acts::UnitConstants::mm;
// maximum distance in r from middle space point to bottom or top spacepoint
float deltaRMax = 0;
float deltaRMax = 0 * Acts::UnitConstants::mm;
// maximum forward direction expressed as cot(theta)
float cotThetaMax = 0;
// maximum impact parameter in mm
float impactMax = 0;
float impactMax = 0 * Acts::UnitConstants::mm;
// minimum phi value for phiAxis construction
float phiMin = -M_PI;
// maximum phi value for phiAxis construction
Expand All @@ -65,7 +69,8 @@ struct CylindricalSpacePointGridConfig {
// maximum number of phi bins
int maxPhiBins = 10000;
// enable non equidistant binning in z
std::vector<float> zBinEdges;
std::vector<float> zBinEdges{};
std::vector<float> rBinEdges{};
bool isInInternalUnits = false;
CylindricalSpacePointGridConfig toInternalUnits() const {
if (isInInternalUnits) {
Expand All @@ -77,6 +82,7 @@ struct CylindricalSpacePointGridConfig {
CylindricalSpacePointGridConfig config = *this;
config.isInInternalUnits = true;
config.minPt /= 1_MeV;
config.rMin /= 1_mm;
config.rMax /= 1_mm;
config.zMax /= 1_mm;
config.zMin /= 1_mm;
Expand Down
54 changes: 21 additions & 33 deletions Core/include/Acts/Seeding/detail/CylindricalSpacePointGrid.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Acts::CylindricalSpacePointGridCreator::createGrid(
config.phiMin, config.phiMax, phiBins);

// vector that will store the edges of the bins of z
std::vector<AxisScalar> zValues;
std::vector<AxisScalar> zValues{};

// If zBinEdges is not defined, calculate the edges as zMin + bin * zBinSize
if (config.zBinEdges.empty()) {
Expand All @@ -130,9 +130,19 @@ Acts::CylindricalSpacePointGridCreator::createGrid(
}
}

std::vector<AxisScalar> rValues{};
rValues.reserve(std::max(2ul, config.rBinEdges.size()));
if (config.rBinEdges.empty()) {
rValues = {config.rMin, config.rMax};
} else {
rValues.insert(rValues.end(), config.rBinEdges.begin(),
config.rBinEdges.end());
}

Axis<AxisType::Variable, AxisBoundaryType::Bound> zAxis(std::move(zValues));
Axis<AxisType::Variable, AxisBoundaryType::Bound> rAxis(std::move(rValues));
return Acts::CylindricalSpacePointGrid<external_spacepoint_t>(
std::make_tuple(std::move(phiAxis), std::move(zAxis)));
std::make_tuple(std::move(phiAxis), std::move(zAxis), std::move(rAxis)));
}

template <typename external_spacepoint_t,
Expand All @@ -155,13 +165,13 @@ void Acts::CylindricalSpacePointGridCreator::fillGrid(
"SeedFinderOptions not in ACTS internal units in BinnedSPGroup");
}

// sort by radius
// add magnitude of beamPos to rMax to avoid excluding measurements
// create number of bins equal to number of millimeters rMax
// (worst case minR: configured minR + 1mm)
// binSizeR allows to increase or reduce numRBins if needed
std::size_t numRBins = static_cast<std::size_t>(
(config.rMax + options.beamPos.norm()) / config.binSizeR);
// Space points are assumed to be ALREADY CORRECTED for beamspot position
// phi, z and r space point selection comes naturally from the
// grid axis definition. No need to explicitly cut on those values.
// If a space point is outside the validity range of these quantities
// it goes in an over- or under-flow bin.
// Additional cuts can be applied by customizing the space point selector
// in the config object.

// keep track of changed bins while sorting
std::vector<bool> usedBinIndex(grid.size(), false);
Expand All @@ -172,37 +182,15 @@ void Acts::CylindricalSpacePointGridCreator::fillGrid(
for (external_spacepoint_iterator_t it = spBegin; it != spEnd;
it++, ++counter) {
const external_spacepoint_t& sp = *it;
float spX = sp.x();
float spY = sp.y();
float spZ = sp.z();

// remove SPs according to experiment specific cuts
if (!config.spacePointSelector(sp)) {
continue;
}

// remove SPs outside z and phi region
if (spZ > config.zMax || spZ < config.zMin) {
continue;
}

float spPhi = std::atan2(spY, spX);
if (spPhi > config.phiMax || spPhi < config.phiMin) {
continue;
}

// calculate r-Bin index and protect against overflow (underflow not
// possible)
std::size_t rIndex =
static_cast<std::size_t>(sp.radius() / config.binSizeR);
// if index out of bounds, the SP is outside the region of interest
if (rIndex >= numRBins) {
continue;
}

// fill rbins into grid
std::size_t globIndex =
grid.globalBinFromPosition(Acts::Vector2{sp.phi(), sp.z()});
std::size_t globIndex = grid.globalBinFromPosition(
Acts::Vector3{sp.phi(), sp.z(), sp.radius()});
auto& rbin = grid.at(globIndex);
rbin.push_back(&sp);

Expand Down
1 change: 1 addition & 0 deletions Core/src/Geometry/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ target_sources(
CompositePortalLink.cpp
PortalLinkBase.cpp
PortalError.cpp
PortalShell.cpp
)
Loading

0 comments on commit 23f4530

Please sign in to comment.