Skip to content

Commit

Permalink
Merge branch 'main' into fpe-safe-eta-theta-conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
andiwand authored Nov 7, 2024
2 parents e5550eb + 436c636 commit f92f144
Show file tree
Hide file tree
Showing 35 changed files with 535 additions and 497 deletions.
13 changes: 11 additions & 2 deletions CI/physmon/workflows/physmon_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@
)
)

s.addWriter(
acts.examples.RootParticleWriter(
level=acts.logging.INFO,
inputParticles="particles_input",
filePath=tp / "particles.root",
)
)

addFatras(
s,
setup.trackingGeometry,
Expand Down Expand Up @@ -100,6 +108,7 @@
s.run()

for file, name in [
(tp / "particles.root", "particles_gun.root"),
(tp / "fatras" / "particles_simulation.root", "particles_fatras.root"),
(tp / "geant4" / "particles_simulation.root", "particles_geant4.root"),
]:
Expand Down Expand Up @@ -135,8 +144,8 @@
s.run()

for file, name in [
(tp / "pythia8_particles.root", "particles_ttbar.root"),
(tp / "pythia8_vertices.root", "vertices_ttbar.root"),
(tp / "particles.root", "particles_ttbar.root"),
(tp / "vertices.root", "vertices_ttbar.root"),
]:
assert file.exists(), "file not found"
shutil.copy(file, setup.outdir / name)
3 changes: 2 additions & 1 deletion Core/include/Acts/EventData/ProxyAccessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ struct ProxyAccessorBase {

/// Create the accessor from a string key
/// @param _key the key
ProxyAccessorBase(const std::string& _key) : key{hashString(_key)} {}
constexpr ProxyAccessorBase(const std::string& _key)
: key{hashString(_key)} {}

/// Access the stored key on the proxy given as an argument. Mutable version
/// @tparam proxy_t the type of the proxy
Expand Down
20 changes: 17 additions & 3 deletions Core/include/Acts/EventData/detail/GenerateParameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ struct GenerateQoverPOptions {
/// Indicate if the momentum referse to transverse momentum
bool pTransverse = true;

/// Indicate if the momentum should be uniformly distributed in log space.
bool pLogUniform = false;

/// Charge of the parameters.
double charge = 1;

Expand All @@ -157,6 +160,19 @@ inline double generateQoverP(generator_t& rng,
using UniformIndex = std::uniform_int_distribution<std::uint8_t>;
using UniformReal = std::uniform_real_distribution<double>;

auto drawP = [&options](generator_t& rng_, double theta_) -> double {
const double pTransverseScaling =
options.pTransverse ? 1. / std::sin(theta_) : 1.;

if (options.pLogUniform) {
UniformReal pLogDist(std::log(options.pMin), std::log(options.pMax));
return std::exp(pLogDist(rng_)) * pTransverseScaling;
}

UniformReal pDist(options.pMin, options.pMax);
return pDist(rng_) * pTransverseScaling;
};

// choose between particle/anti-particle if requested
// the upper limit of the distribution is inclusive
UniformIndex particleTypeChoice(0u, options.randomizeCharge ? 1u : 0u);
Expand All @@ -165,14 +181,12 @@ inline double generateQoverP(generator_t& rng,
options.charge,
-options.charge,
};
UniformReal pDist(options.pMin, options.pMax);

// draw parameters
const std::uint8_t type = particleTypeChoice(rng);
const double q = qChoices[type];

const double p =
pDist(rng) * (options.pTransverse ? 1. / std::sin(theta) : 1.);
const double p = drawP(rng, theta);
const double qOverP = (q != 0) ? q / p : 1 / p;

return qOverP;
Expand Down
19 changes: 15 additions & 4 deletions Core/include/Acts/Seeding/GbtsTrackingFilter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

// TODO: update to C++17 style
#include "Acts/Seeding/GbtsDataStorage.hpp" //includes geo which has trigindetsilayer, may move this to trigbase
#include "Acts/Utilities/Logger.hpp"

#include <algorithm>
#include <cmath>
Expand Down Expand Up @@ -112,8 +113,11 @@ template <typename external_spacepoint_t>
class GbtsTrackingFilter {
public:
GbtsTrackingFilter(const std::vector<Acts::TrigInDetSiLayer>& g,
std::vector<Acts::GbtsEdge<external_spacepoint_t>>& sb)
: m_geo(g), m_segStore(sb) {}
std::vector<Acts::GbtsEdge<external_spacepoint_t>>& sb,
std::unique_ptr<const Acts::Logger> logger =
Acts::getDefaultLogger("Filter",
Acts::Logging::Level::INFO))
: m_geo(g), m_segStore(sb), m_logger(std::move(logger)) {}

void followTrack(Acts::GbtsEdge<external_spacepoint_t>* pS,
GbtsEdgeState<external_spacepoint_t>& output) {
Expand Down Expand Up @@ -233,11 +237,15 @@ class GbtsTrackingFilter {
const float add_hit = 14.0;

if (ts.m_Cx[2][2] < 0.0 || ts.m_Cx[1][1] < 0.0 || ts.m_Cx[0][0] < 0.0) {
std::cout << "Negative cov_x" << std::endl;
ACTS_WARNING("Negative covariance detected in X components: "
<< "cov[2][2]=" << ts.m_Cx[2][2] << " cov[1][1]="
<< ts.m_Cx[1][1] << " cov[0][0]=" << ts.m_Cx[0][0]);
}

if (ts.m_Cy[1][1] < 0.0 || ts.m_Cy[0][0] < 0.0) {
std::cout << "Negative cov_y" << std::endl;
ACTS_WARNING("Negative covariance detected in Y components: "
<< "cov[1][1]=" << ts.m_Cy[1][1]
<< " cov[0][0]=" << ts.m_Cy[0][0]);
}

// add ms.
Expand Down Expand Up @@ -380,4 +388,7 @@ class GbtsTrackingFilter {
GbtsEdgeState<external_spacepoint_t> m_stateStore[MAX_EDGE_STATE];

int m_globalStateCounter{0};

const Acts::Logger& logger() const { return *m_logger; }
std::unique_ptr<const Acts::Logger> m_logger{nullptr};
};
2 changes: 1 addition & 1 deletion Core/include/Acts/Seeding/SeedFilter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class SeedFilter final {

const SeedFilterConfig m_cfg;
std::unique_ptr<const Acts::Logger> m_logger =
Acts::getDefaultLogger("SeedFilter", Logging::Level::INFO);
Acts::getDefaultLogger("Filter", Logging::Level::INFO);
const IExperimentCuts<external_spacepoint_t>* m_experimentCuts;
};
} // namespace Acts
Expand Down
12 changes: 6 additions & 6 deletions Core/include/Acts/Seeding/SeedFinder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ concept GridBinCollection =
std::ranges::random_access_range<Coll> &&
std::same_as<typename Coll::value_type, std::size_t>;

template <typename Coll, typename external_t, std::size_t N = 3ul>
concept CollectionStoresSeedsTo = requires(Coll coll, external_t sp) {
Acts::detail::pushBackOrInsertAtEnd(coll,
Acts::Seed<external_t, N>(sp, sp, sp));
};
template <typename collection_t, typename external_t, std::size_t N = 3ul>
concept CollectionStoresSeedsTo =
requires(collection_t coll, Acts::Seed<external_t, N> seed) {
Acts::detail::pushBackOrInsertAtEnd(coll, seed);
};

enum class SpacePointCandidateType : short { eBottom, eTop };

Expand Down Expand Up @@ -91,7 +91,7 @@ class SeedFinder {
/// @param logger the ACTS logger
SeedFinder(const Acts::SeedFinderConfig<external_spacepoint_t>& config,
std::unique_ptr<const Acts::Logger> logger =
getDefaultLogger("SeedFinder", Logging::Level::INFO));
getDefaultLogger("Finder", Logging::Level::INFO));
SeedFinder(SeedFinder<external_spacepoint_t, grid_t, platform_t>&&) noexcept =
default;
SeedFinder& operator=(SeedFinder<external_spacepoint_t, grid_t,
Expand Down
17 changes: 11 additions & 6 deletions Core/include/Acts/Seeding/SeedFinderGbts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "Acts/Seeding/SeedFinderConfig.hpp"
#include "Acts/Seeding/SeedFinderGbtsConfig.hpp"
#include "Acts/TrackFinding/RoiDescriptor.hpp"
#include "Acts/Utilities/KDTree.hpp"
#include "Acts/Utilities/Logger.hpp"

#include <array>
#include <iostream>
Expand Down Expand Up @@ -46,14 +46,15 @@ class SeedFinderGbts {
static constexpr std::size_t NDims = 3;

using seed_t = Seed<external_spacepoint_t>;
// using internal_sp_t = InternalSpacePoint<external_spacepoint_t>;
// using tree_t = KDTree<NDims, internal_sp_t *, ActsScalar, std::array, 4>;

// constructors
SeedFinderGbts(const SeedFinderGbtsConfig<external_spacepoint_t> &config,
const GbtsGeometry<external_spacepoint_t> &gbtsgeo);
const GbtsGeometry<external_spacepoint_t> &gbtsgeo,
std::unique_ptr<const Acts::Logger> logger =
Acts::getDefaultLogger("Finder",
Acts::Logging::Level::INFO));

~SeedFinderGbts(); //!!! is it dangerous not to use default? got def in ipp
~SeedFinderGbts() = default;
SeedFinderGbts() = default;
SeedFinderGbts(const SeedFinderGbts<external_spacepoint_t> &) = delete;
SeedFinderGbts<external_spacepoint_t> &operator=(
Expand Down Expand Up @@ -85,10 +86,14 @@ class SeedFinderGbts {
const Acts::GbtsGeometry<external_spacepoint_t> &gbtsgeo);

// needs to be member of class so can accessed by all member functions
GbtsDataStorage<external_spacepoint_t> *m_storage;
std::unique_ptr<GbtsDataStorage<external_spacepoint_t>> m_storage{nullptr};

// for create seeds:
std::vector<TrigInDetTriplet<external_spacepoint_t>> m_triplets;

const Acts::Logger &logger() const { return *m_logger; }
std::unique_ptr<const Acts::Logger> m_logger =
Acts::getDefaultLogger("Finder", Acts::Logging::Level::INFO);
};

} // namespace Acts
Expand Down
26 changes: 13 additions & 13 deletions Core/include/Acts/Seeding/SeedFinderGbts.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,18 @@ namespace Acts {
template <typename external_spacepoint_t>
SeedFinderGbts<external_spacepoint_t>::SeedFinderGbts(
const SeedFinderGbtsConfig<external_spacepoint_t>& config,
const GbtsGeometry<external_spacepoint_t>& gbtsGeo)
: m_config(config) {
m_storage = new GbtsDataStorage(gbtsGeo);
}

template <typename external_spacepoint_t>
SeedFinderGbts<external_spacepoint_t>::~SeedFinderGbts() {
delete m_storage;

m_storage = nullptr;
}
const GbtsGeometry<external_spacepoint_t>& gbtsGeo,
std::unique_ptr<const Acts::Logger> logger)
: m_config(config),
m_storage(
std::make_unique<GbtsDataStorage<external_spacepoint_t>>(gbtsGeo)),
m_logger(std::move(logger)) {}

// define loadspace points function
template <typename external_spacepoint_t>
void SeedFinderGbts<external_spacepoint_t>::loadSpacePoints(
const std::vector<GbtsSP<external_spacepoint_t>>& gbtsSPvect) {
ACTS_VERBOSE("Loading space points");
for (const auto& gbtssp : gbtsSPvect) {
bool is_Pixel = gbtssp.isPixel();
if (!is_Pixel) {
Expand All @@ -70,6 +66,7 @@ void SeedFinderGbts<external_spacepoint_t>::runGbts_TrackFinder(
std::vector<GbtsTrigTracklet<external_spacepoint_t>>& vTracks,
const Acts::RoiDescriptor& roi,
const Acts::GbtsGeometry<external_spacepoint_t>& gbtsGeo) {
ACTS_VERBOSE("Running GBTS Track Finder");
const float min_z0 = roi.zedMinus();
const float max_z0 = roi.zedPlus();
const float cut_zMinU = min_z0 + m_config.maxOuterRadius * roi.dzdrMinus();
Expand Down Expand Up @@ -328,6 +325,7 @@ void SeedFinderGbts<external_spacepoint_t>::runGbts_TrackFinder(
m_storage->getConnectingNodes(vNodes);

if (vNodes.empty()) {
ACTS_VERBOSE("No nodes");
return;
}

Expand Down Expand Up @@ -506,8 +504,9 @@ void SeedFinderGbts<external_spacepoint_t>::runGbts_TrackFinder(

// backtracking

GbtsTrackingFilter<external_spacepoint_t> tFilter(m_config.m_layerGeometry,
edgeStorage);
GbtsTrackingFilter<external_spacepoint_t> tFilter(
m_config.m_layerGeometry, edgeStorage,
logger().cloneWithSuffix("GbtsFilter"));

for (auto pS : vSeeds) {
if (pS->m_level == -1) {
Expand Down Expand Up @@ -651,6 +650,7 @@ void SeedFinderGbts<external_spacepoint_t>::createSeeds(
const Acts::RoiDescriptor& roi,
const Acts::GbtsGeometry<external_spacepoint_t>& gbtsGeo,
output_container_t& out_cont) {
ACTS_VERBOSE("Creating seeds");
std::vector<GbtsTrigTracklet<external_spacepoint_t>>
vTracks; // make empty vector

Expand Down
23 changes: 20 additions & 3 deletions Core/include/Acts/Seeding/SeedFinderOrthogonal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "Acts/Seeding/SeedFinderConfig.hpp"
#include "Acts/Seeding/SeedFinderOrthogonalConfig.hpp"
#include "Acts/Utilities/KDTree.hpp"
#include "Acts/Utilities/Logger.hpp"

#include <array>
#include <iostream>
Expand Down Expand Up @@ -53,10 +54,12 @@ class SeedFinderOrthogonal {
* @brief Construct a new orthogonal seed finder.
*
* @param config The configuration parameters for this seed finder.
* @param logger The ACTS logger.
*/
SeedFinderOrthogonal(
const Acts::SeedFinderOrthogonalConfig<external_spacepoint_t> &config);

const Acts::SeedFinderOrthogonalConfig<external_spacepoint_t> &config,
std::unique_ptr<const Acts::Logger> logger =
Acts::getDefaultLogger("Finder", Logging::Level::INFO));
/**
* @brief Destroy the orthogonal seed finder object.
*/
Expand All @@ -66,7 +69,11 @@ class SeedFinderOrthogonal {
SeedFinderOrthogonal(const SeedFinderOrthogonal<external_spacepoint_t> &) =
delete;
SeedFinderOrthogonal<external_spacepoint_t> &operator=(
const SeedFinderOrthogonal<external_spacepoint_t> &) = default;
const SeedFinderOrthogonal<external_spacepoint_t> &) = delete;
SeedFinderOrthogonal(
SeedFinderOrthogonal<external_spacepoint_t> &&) noexcept = default;
SeedFinderOrthogonal<external_spacepoint_t> &operator=(
SeedFinderOrthogonal<external_spacepoint_t> &&) noexcept = default;

/**
* @brief Perform seed finding, appending seeds to a container.
Expand Down Expand Up @@ -238,6 +245,16 @@ class SeedFinderOrthogonal {
* @brief The configuration for the seeding algorithm.
*/
Acts::SeedFinderOrthogonalConfig<external_spacepoint_t> m_config;

/**
* @brief Get the logger.
*/
const Logger &logger() const { return *m_logger; }

/**
* @brief The logger
*/
std::unique_ptr<const Acts::Logger> m_logger{getDummyLogger().clone()};
};
} // namespace Acts

Expand Down
12 changes: 10 additions & 2 deletions Core/include/Acts/Seeding/SeedFinderOrthogonal.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,9 @@ bool SeedFinderOrthogonal<external_spacepoint_t>::validTuple(

template <typename external_spacepoint_t>
SeedFinderOrthogonal<external_spacepoint_t>::SeedFinderOrthogonal(
const SeedFinderOrthogonalConfig<external_spacepoint_t> &config)
: m_config(config) {
const SeedFinderOrthogonalConfig<external_spacepoint_t> &config,
std::unique_ptr<const Acts::Logger> logger)
: m_config(config), m_logger(std::move(logger)) {
if (!config.isInInternalUnits) {
throw std::runtime_error(
"SeedFinderOrthogonalConfig not in ACTS internal units in "
Expand Down Expand Up @@ -687,6 +688,7 @@ auto SeedFinderOrthogonal<external_spacepoint_t>::createTree(
const std::vector<const external_spacepoint_t *> &spacePoints) const
-> tree_t {
std::vector<typename tree_t::pair_t> points;
points.reserve(spacePoints.size());

/*
* For every input point, we create a coordinate-pointer pair, which we then
Expand All @@ -703,6 +705,8 @@ auto SeedFinderOrthogonal<external_spacepoint_t>::createTree(
points.emplace_back(point, sp);
}

ACTS_VERBOSE("Created k-d tree populated with " << points.size()
<< " space points");
return tree_t(std::move(points));
}

Expand All @@ -711,6 +715,7 @@ template <typename input_container_t, typename output_container_t>
void SeedFinderOrthogonal<external_spacepoint_t>::createSeeds(
const Acts::SeedFinderOptions &options,
const input_container_t &spacePoints, output_container_t &out_cont) const {
ACTS_VERBOSE("Creating seeds with Orthogonal strategy");
if (!options.isInInternalUnits) {
throw std::runtime_error(
"SeedFinderOptions not in ACTS internal units in "
Expand All @@ -734,6 +739,7 @@ void SeedFinderOrthogonal<external_spacepoint_t>::createSeeds(
* take each external spacepoint, allocate a corresponding internal space
* point, and save it in a vector.
*/
ACTS_VERBOSE("Running on " << spacePoints.size() << " input space points");
Acts::Extent rRangeSPExtent;
std::vector<const external_spacepoint_t *> internal_sps;
internal_sps.reserve(spacePoints.size());
Expand All @@ -746,6 +752,8 @@ void SeedFinderOrthogonal<external_spacepoint_t>::createSeeds(
rRangeSPExtent.extend({p.x(), p.y(), p.z()});
internal_sps.push_back(&p);
}
ACTS_VERBOSE(rRangeSPExtent);

// variable middle SP radial region of interest
const Acts::Range1D<float> rMiddleSPRange(
std::floor(rRangeSPExtent.min(Acts::BinningValue::binR) / 2) * 2 +
Expand Down
Loading

0 comments on commit f92f144

Please sign in to comment.