Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Fatras/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ acts_add_library(
src/EventData/Particle.cpp
src/EventData/ParticleOutcome.cpp
src/EventData/ProcessType.cpp
src/EventData/HitContainer2.cpp
src/EventData/ParticleContainer2.cpp
src/Kernel/SimulationError.cpp
src/Physics/BetheHeitler.cpp
src/Physics/StandardInteractions.cpp
Expand Down
89 changes: 62 additions & 27 deletions Fatras/include/ActsFatras/EventData/Hit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "Acts/Definitions/Common.hpp"
#include "Acts/Geometry/GeometryIdentifier.hpp"
#include "ActsFatras/EventData/Barcode.hpp"
#include "ActsFatras/EventData/ParticleContainer2.hpp"

#include <cstdint>

Expand All @@ -28,82 +29,114 @@ class Hit {
public:
/// Construct default hit with (mostly) invalid information.
Hit() = default;

/// Construct from four-position and four-momenta.
///
/// @param geometryId Geometry identifier of the surface
/// @param particleId Particle identifier of the particle that created the hit
/// @param pos4 Particle space-time four-vector on the surface
/// @param before4 Particle four-momentum before the interaction
/// @param after4 Particle four-momentum after the interaction
/// @param index_ Hit index along the particle trajectory
/// @param geometryId Geometry identifier of the surface
/// @param particleBarcode Barcode of the particle that created the hit
/// @param particleId Particle index of the particle that created the hit
/// @param pos4 Particle space-time four-vector on the surface
/// @param before4 Particle four-momentum before the interaction
/// @param after4 Particle four-momentum after the interaction
/// @param particleHitIndex Hit index along the particle trajectory
///
/// All quantities are given in the global coordinate system. It is the
/// users responsibility to ensure that the position correspond to a
/// position on the given surface.
Hit(Acts::GeometryIdentifier geometryId, Barcode particleId,
Hit(Acts::GeometryIdentifier geometryId, Barcode particleBarcode,
const Acts::Vector4& pos4, const Acts::Vector4& before4,
const Acts::Vector4& after4, std::int32_t index_ = -1)
const Acts::Vector4& after4, std::int32_t particleHitIndex = -1)
: m_geometryId(geometryId),
m_particleBarcode(particleBarcode),
m_particleHitIndex(particleHitIndex),
m_pos4(pos4),
m_before4(before4),
m_after4(after4) {}

/// Construct from four-position and four-momenta.
///
/// @param geometryId Geometry identifier of the surface
/// @param particleBarcode Barcode of the particle that created the hit
/// @param particleId Particle index of the particle that created the hit
/// @param pos4 Particle space-time four-vector on the surface
/// @param before4 Particle four-momentum before the interaction
/// @param after4 Particle four-momentum after the interaction
/// @param particleHitIndex Hit index along the particle trajectory
///
/// All quantities are given in the global coordinate system. It is the
/// users responsibility to ensure that the position correspond to a
/// position on the given surface.
Hit(Acts::GeometryIdentifier geometryId, Barcode particleBarcode,
ParticleIndex2 particleId2, const Acts::Vector4& pos4,
const Acts::Vector4& before4, const Acts::Vector4& after4,
std::int32_t particleHitIndex = -1)
: m_geometryId(geometryId),
m_particleId(particleId),
m_index(index_),
m_particleBarcode(particleBarcode),
m_particleId2(particleId2),
m_particleHitIndex(particleHitIndex),
m_pos4(pos4),
m_before4(before4),
m_after4(after4) {}
/// Copy constructor
Hit(const Hit&) = default;
/// Move constructor
Hit(Hit&&) = default;
/// Copy assignment operator
/// @return Reference to this hit after copying
Hit& operator=(const Hit&) = default;
/// Move assignment operator
/// @return Reference to this hit after moving
Hit& operator=(Hit&&) = default;

/// Geometry identifier of the hit surface.
/// @return GeometryIdentifier of the surface where the hit occurred
constexpr Acts::GeometryIdentifier geometryId() const { return m_geometryId; }
/// Particle identifier of the particle that generated the hit.
/// @return Barcode identifier of the particle that created this hit
constexpr Barcode particleId() const { return m_particleId; }

constexpr Barcode particleId() const { return m_particleBarcode; }

constexpr Barcode particleBarcode() const { return m_particleBarcode; }

/// Particle index of the particle that generated the hit.
/// @return Particle index of the particle that created this hit
constexpr ParticleIndex2 particleId2() const { return m_particleId2; }

constexpr std::int32_t index() const { return m_particleHitIndex; }

/// Hit index along the particle trajectory.
///
/// @retval negative if the hit index is undefined.
constexpr std::int32_t index() const { return m_index; }
constexpr std::int32_t particleHitIndex() const { return m_particleHitIndex; }

/// Space-time position four-vector.
/// @return Reference to four-vector containing position and time coordinates
const Acts::Vector4& fourPosition() const { return m_pos4; }

/// Three-position, i.e. spatial coordinates without the time.
/// @return Three-dimensional position vector (x,y,z)
auto position() const { return m_pos4.segment<3>(Acts::ePos0); }

/// Time coordinate.
/// @return Time of the hit occurrence
double time() const { return m_pos4[Acts::eTime]; }

/// Particle four-momentum before the hit.
/// @return Reference to four-momentum vector before interaction
const Acts::Vector4& momentum4Before() const { return m_before4; }

/// Particle four-momentum after the hit.
/// @return Reference to four-momentum vector after interaction
const Acts::Vector4& momentum4After() const { return m_after4; }

/// Normalized particle direction vector before the hit.
/// @return Normalized three-dimensional direction vector before interaction
Acts::Vector3 directionBefore() const {
return m_before4.segment<3>(Acts::eMom0).normalized();
}

/// Normalized particle direction vector the hit.
/// @return Normalized three-dimensional direction vector after interaction
Acts::Vector3 directionAfter() const {
return m_after4.segment<3>(Acts::eMom0).normalized();
}

/// Average normalized particle direction vector through the surface.
/// @return Average normalized direction vector of particle momentum before and after
Acts::Vector3 direction() const {
auto dir0 = m_before4.segment<3>(Acts::eMom0).normalized();
auto dir1 = m_after4.segment<3>(Acts::eMom0).normalized();
return ((dir0 + dir1) / 2.).segment<3>(Acts::eMom0).normalized();
}

/// Energy deposited by the hit.
///
/// @retval positive if the particle lost energy when it passed the surface
Expand All @@ -115,10 +148,12 @@ class Hit {
private:
/// Identifier of the surface.
Acts::GeometryIdentifier m_geometryId;
/// Identifier of the generating particle.
Barcode m_particleId;
/// Barcode of the generating particle.
Barcode m_particleBarcode;
/// Index of the generating particle.
ParticleIndex2 m_particleId2{};
/// Index of the hit along the particle trajectory.
std::int32_t m_index = -1;
std::int32_t m_particleHitIndex = -1;
/// Global space-time position four-vector.
Acts::Vector4 m_pos4 = Acts::Vector4::Zero();
/// Global particle energy-momentum four-vector before the hit.
Expand Down
126 changes: 126 additions & 0 deletions Fatras/include/ActsFatras/EventData/HitContainer2.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// 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/GeometryIdentifier.hpp"
#include "ActsFatras/EventData/Hit.hpp"
#include "ActsFatras/EventData/ParticleContainer2.hpp"

#include <unordered_map>

namespace ActsFatras {

using HitIndex = std::uint32_t;
using HitIndexSubset = std::span<const HitIndex>;

class HitContainer2 {
public:
/// Type alias for particle index in container
using Index = HitIndex;
/// Type alias for subset of particle indices
using IndexSubset = HitIndexSubset;

/// Returns the number of hits in the container.
/// @return The number of hits in the container.
[[nodiscard]] std::uint32_t size() const noexcept { return m_hits.size(); }

Check warning on line 31 in Fatras/include/ActsFatras/EventData/HitContainer2.hpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

implicit conversion loses integer precision: 'size_type' (aka 'unsigned long') to 'std::uint32_t' (aka 'unsigned int')

See more on https://sonarcloud.io/project/issues?id=acts-project_acts&issues=AZzclz_eNLkPNfb8ANVI&open=AZzclz_eNLkPNfb8ANVI&pullRequest=5210
/// Checks if the container is empty.
/// @return True if the container is empty, false otherwise.
[[nodiscard]] bool empty() const noexcept { return m_hits.empty(); }

/// Reserves space for the given number of hits.
/// @param size The number of hits to reserve space for.
void reserve(std::uint32_t size) noexcept;

/// Clears the container, removing all hits and columns.
void clear() noexcept;

const std::vector<Hit>& hits() const noexcept { return m_hits; }

const std::unordered_map<ParticleIndex2, std::vector<HitIndex>>&
hitsByParticles() const noexcept {
return m_hitsByParticles;
}

const std::unordered_map<Acts::GeometryIdentifier, std::vector<HitIndex>>&
hitsBySurfaces() const noexcept {
return m_hitsBySurfaces;
}

Hit& push_back(const Hit& hit);

Hit& emplace_back(Acts::GeometryIdentifier geometryId,
Barcode particleBarcode, ParticleIndex2 particleId,
const Acts::Vector4& pos4, const Acts::Vector4& before4,
const Acts::Vector4& after4, std::int32_t index = -1);

Hit& operator[](std::size_t index) { return m_hits[index]; }
const Hit& operator[](std::size_t index) const { return m_hits[index]; }

Hit& at(std::size_t index) { return m_hits.at(index); }
const Hit& at(std::size_t index) const { return m_hits.at(index); }

auto begin() noexcept { return m_hits.begin(); }
auto end() noexcept { return m_hits.end(); }
auto begin() const noexcept { return m_hits.begin(); }
auto end() const noexcept { return m_hits.end(); }

std::span<const HitIndex> hitIndicesByParticle(
ParticleIndex2 particleId) const;
std::span<const HitIndex> hitIndicesBySurface(
Acts::GeometryIdentifier geometryId) const;

/// Subset facade over arbitrary index sets.
template <bool read_only>
class Subset : public Acts::detail::ContainerSubset<
Subset<read_only>, Subset<true>, HitContainer2,
std::conditional_t<read_only, const Hit&, Hit&>,
std::span<const Index>, read_only> {
public:
/// Base class type
using Base = Acts::detail::ContainerSubset<
Subset<read_only>, Subset<true>, HitContainer2,
std::conditional_t<read_only, const Hit&, Hit&>, std::span<const Index>,
read_only>;

using Base::Base;
};

/// Type alias for mutable subset of hits
using MutableSubset = Subset<false>;
/// Type alias for const subset of hits
using ConstSubset = Subset<true>;

/// Creates a mutable subset of hits from the given index subset.
/// @param subset The index subset to create the subset from.
/// @return A mutable subset of hits.
MutableSubset subset(const IndexSubset& subset) noexcept {
return MutableSubset(*this, subset);
}
/// Creates a const subset of hits from the given index subset.
/// @param subset The index subset to create the subset from.
/// @return A const subset of hits.
ConstSubset subset(const IndexSubset& subset) const noexcept {
return ConstSubset(*this, subset);
}

ConstSubset hitsByParticle(ParticleIndex2 particleId) const {
return subset(hitIndicesByParticle(particleId));
}
ConstSubset hitsBySurface(Acts::GeometryIdentifier geometryId) const {
return subset(hitIndicesBySurface(geometryId));
}

private:
std::vector<Hit> m_hits;
std::unordered_map<ParticleIndex2, std::vector<HitIndex>> m_hitsByParticles;
std::unordered_map<Acts::GeometryIdentifier, std::vector<HitIndex>>
m_hitsBySurfaces;
};

} // namespace ActsFatras
Loading
Loading