Skip to content

Commit

Permalink
Merge branch 'main' into remove-unit-c
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Jul 8, 2023
2 parents 3bc622a + 5b1de63 commit 2b5899d
Show file tree
Hide file tree
Showing 29 changed files with 98 additions and 101 deletions.
2 changes: 1 addition & 1 deletion CI/physmon/fpe_masks.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"Fatras/include/ActsFatras/Physics/ElectroMagnetic/BetheHeitler.hpp:66":
FLTUND: 1
"Fatras/include/ActsFatras/Kernel/detail/SimulationActor.hpp:178":
"Fatras/include/ActsFatras/Kernel/detail/SimulationActor.hpp:177":
FLTUND: 1
"Core/include/Acts/TrackFitting/detail/GsfUtils.hpp:197":
FLTUND: 1
Expand Down
11 changes: 2 additions & 9 deletions Core/include/Acts/Seeding/SeedFinder.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -715,19 +715,12 @@ inline void SeedFinder<external_spacepoint_t, platform_t>::filterCandidates(
// maxPtScattering instead of pt.
// To avoid 0-divison the pT check is skipped in case of B2==0, and
// p2scatterSigma is calculated directly from maxPtScattering
if (B2 == 0) {
if (B2 == 0 or options.pTPerHelixRadius * std::sqrt(S2 / B2) >
2. * m_config.maxPtScattering) {
float pTscatterSigma =
(m_config.highland / m_config.maxPtScattering) *
m_config.sigmaScattering;
p2scatterSigma = pTscatterSigma * pTscatterSigma * iSinTheta2;
} else {
float pT = options.pTPerHelixRadius * std::sqrt(S2 / B2) / 2.;
if (pT > m_config.maxPtScattering) {
float pTscatterSigma =
(m_config.highland / m_config.maxPtScattering) *
m_config.sigmaScattering;
p2scatterSigma = pTscatterSigma * pTscatterSigma * iSinTheta2;
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions Core/include/Acts/Seeding/SeedFinderOrthogonal.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,8 @@ void SeedFinderOrthogonal<external_spacepoint_t>::filterCandidates(
if (!std::isinf(m_config.maxPtScattering)) {
// if pT > maxPtScattering, calculate allowed scattering angle using
// maxPtScattering instead of pt.
float pT = options.pTPerHelixRadius * std::sqrt(S2 / B2) / 2.;
if (pT > m_config.maxPtScattering) {
if (B2 == 0 or options.pTPerHelixRadius * std::sqrt(S2 / B2) >
2. * m_config.maxPtScattering) {
float pTscatterSigma =
(m_config.highland / m_config.maxPtScattering) *
m_config.sigmaScattering;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void PrimaryGeneratorAction::prepareParticleGun(
m_particleGun->SetParticleDefinition(particle);
// Particle properties
const auto pos = part.position() * convertLength;
const auto dir = part.unitDirection();
const auto dir = part.direction();
m_particleGun->SetParticlePosition({pos[0], pos[1], pos[2]});
m_particleGun->SetParticleMomentum(part.absoluteMomentum() * convertEnergy);
m_particleGun->SetParticleMomentumDirection({dir[0], dir[1], dir[2]});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ ActsExamples::ProcessCode ActsExamples::ParticlesPrinter::execute(
ACTS_INFO(" process_type: " << particle.process())
ACTS_INFO(" position: " << particle.position().transpose() / 1_mm
<< " mm");
ACTS_INFO(" direction: " << particle.unitDirection().transpose());
ACTS_INFO(" direction: " << particle.direction().transpose());
ACTS_INFO(" time: " << particle.time() / 1_ns << " ns");
ACTS_INFO(" |p|: " << particle.absoluteMomentum() / 1_GeV
<< " GeV");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ ActsExamples::ProcessCode ActsExamples::ParticleSelector::execute(
return (min <= x) and (x < max);
};
auto isValidParticle = [&](const ActsFatras::Particle& p) {
const auto eta = Acts::VectorHelpers::eta(p.unitDirection());
const auto phi = Acts::VectorHelpers::phi(p.unitDirection());
const auto eta = Acts::VectorHelpers::eta(p.direction());
const auto phi = Acts::VectorHelpers::phi(p.direction());
const auto rho = Acts::VectorHelpers::perp(p.position());
// define charge selection
const bool validNeutral = (p.charge() == 0) and not m_cfg.removeNeutral;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ ActsExamples::ProcessCode ActsExamples::ParticleSmearing::execute(

for (const auto& particle : vtxParticles) {
const auto time = particle.time();
const auto phi = Acts::VectorHelpers::phi(particle.unitDirection());
const auto theta = Acts::VectorHelpers::theta(particle.unitDirection());
const auto phi = Acts::VectorHelpers::phi(particle.direction());
const auto theta = Acts::VectorHelpers::theta(particle.direction());
const auto pt = particle.transverseMomentum();
const auto p = particle.absoluteMomentum();
const auto q = particle.charge();
Expand Down Expand Up @@ -107,7 +107,7 @@ ActsExamples::ProcessCode ActsExamples::ParticleSmearing::execute(
ctx.geoContext,
Acts::Vector2{params[Acts::eBoundLoc0],
params[Acts::eBoundLoc1]},
particle.unitDirection() * p)
particle.direction() * p)
.transpose()
<< ", " << params[Acts::eBoundTime] << ", "
<< params[Acts::eBoundPhi] << ", "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ ProcessCode TruthSeedSelector::execute(const AlgorithmContext& ctx) const {
return (min <= x) and (x < max);
};
auto isValidparticle = [&](const auto& p) {
const auto eta = Acts::VectorHelpers::eta(p.unitDirection());
const auto phi = Acts::VectorHelpers::phi(p.unitDirection());
const auto eta = Acts::VectorHelpers::eta(p.direction());
const auto phi = Acts::VectorHelpers::phi(p.direction());
const auto rho = Acts::VectorHelpers::perp(p.position());
// find the corresponding hits for this particle
const auto& hits = makeRange(particleHitsMap.equal_range(p.particleId()));
Expand Down
4 changes: 2 additions & 2 deletions Examples/Framework/src/Validation/DuplicationPlotTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ void ActsExamples::DuplicationPlotTool::fill(
void ActsExamples::DuplicationPlotTool::fill(
DuplicationPlotTool::DuplicationPlotCache& duplicationPlotCache,
const ActsFatras::Particle& truthParticle, size_t nDuplicatedTracks) const {
const auto t_phi = phi(truthParticle.unitDirection());
const auto t_eta = eta(truthParticle.unitDirection());
const auto t_phi = phi(truthParticle.direction());
const auto t_eta = eta(truthParticle.direction());
const auto t_pT = truthParticle.transverseMomentum();

PlotHelpers::fillProf(duplicationPlotCache.nDuplicated_vs_pT, t_pT,
Expand Down
4 changes: 2 additions & 2 deletions Examples/Framework/src/Validation/EffPlotTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ void ActsExamples::EffPlotTool::write(
void ActsExamples::EffPlotTool::fill(EffPlotTool::EffPlotCache& effPlotCache,
const ActsFatras::Particle& truthParticle,
bool status) const {
const auto t_phi = phi(truthParticle.unitDirection());
const auto t_eta = eta(truthParticle.unitDirection());
const auto t_phi = phi(truthParticle.direction());
const auto t_eta = eta(truthParticle.direction());
const auto t_pT = truthParticle.transverseMomentum();

PlotHelpers::fillEff(effPlotCache.trackEff_vs_pT, t_pT, status);
Expand Down
2 changes: 1 addition & 1 deletion Examples/Framework/src/Validation/FakeRatePlotTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void ActsExamples::FakeRatePlotTool::fill(
FakeRatePlotTool::FakeRatePlotCache& fakeRatePlotCache,
const ActsFatras::Particle& truthParticle, size_t nTruthMatchedTracks,
size_t nFakeTracks) const {
const auto t_eta = eta(truthParticle.unitDirection());
const auto t_eta = eta(truthParticle.direction());
const auto t_pT = truthParticle.transverseMomentum();

PlotHelpers::fillHisto(fakeRatePlotCache.nReco_vs_pT, t_pT,
Expand Down
8 changes: 4 additions & 4 deletions Examples/Framework/src/Validation/ResPlotTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void ActsExamples::ResPlotTool::fill(

// get the truth perigee parameter
auto lpResult = pSurface->globalToLocal(gctx, truthParticle.position(),
truthParticle.unitDirection());
truthParticle.direction());
if (lpResult.ok()) {
truthParameter[Acts::BoundIndices::eBoundLoc0] =
lpResult.value()[Acts::BoundIndices::eBoundLoc0];
Expand All @@ -175,15 +175,15 @@ void ActsExamples::ResPlotTool::fill(
ACTS_ERROR("Global to local transformation did not succeed.");
}
truthParameter[Acts::BoundIndices::eBoundPhi] =
phi(truthParticle.unitDirection());
phi(truthParticle.direction());
truthParameter[Acts::BoundIndices::eBoundTheta] =
theta(truthParticle.unitDirection());
theta(truthParticle.direction());
truthParameter[Acts::BoundIndices::eBoundQOverP] =
truthParticle.charge() / truthParticle.absoluteMomentum();
truthParameter[Acts::BoundIndices::eBoundTime] = truthParticle.time();

// get the truth eta and pT
const auto truthEta = eta(truthParticle.unitDirection());
const auto truthEta = eta(truthParticle.direction());
const auto truthPt = truthParticle.transverseMomentum();

// fill the histograms for residual and pull
Expand Down
6 changes: 3 additions & 3 deletions Examples/Io/Csv/src/CsvParticleWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ ActsExamples::ProcessCode ActsExamples::CsvParticleWriter::writeT(
data.vz = particle.position().z() / Acts::UnitConstants::mm;
data.vt = particle.time() / Acts::UnitConstants::ns;
const auto p = particle.absoluteMomentum() / Acts::UnitConstants::GeV;
data.px = p * particle.unitDirection().x();
data.py = p * particle.unitDirection().y();
data.pz = p * particle.unitDirection().z();
data.px = p * particle.direction().x();
data.py = p * particle.direction().y();
data.pz = p * particle.direction().z();
data.m = particle.mass() / Acts::UnitConstants::GeV;
data.q = particle.charge() / Acts::UnitConstants::e;
writer.append(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ struct ActsExamples::TrackFinderPerformanceWriter::Impl {
prtVz = particle.position().z() / Acts::UnitConstants::mm;
prtVt = particle.time() / Acts::UnitConstants::ns;
const auto p = particle.absoluteMomentum() / Acts::UnitConstants::GeV;
prtPx = p * particle.unitDirection().x();
prtPy = p * particle.unitDirection().y();
prtPz = p * particle.unitDirection().z();
prtPx = p * particle.direction().x();
prtPy = p * particle.direction().y();
prtPz = p * particle.direction().z();
prtM = particle.mass() / Acts::UnitConstants::GeV;
prtQ = particle.charge() / Acts::UnitConstants::e;
// reconstruction
Expand Down
12 changes: 6 additions & 6 deletions Examples/Io/Root/src/RootParticleWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,21 @@ ActsExamples::ProcessCode ActsExamples::RootParticleWriter::writeT(
// momentum
const auto p = particle.absoluteMomentum() / Acts::UnitConstants::GeV;
m_p.push_back(Acts::clampValue<float>(p));
m_px.push_back(Acts::clampValue<float>(p * particle.unitDirection().x()));
m_py.push_back(Acts::clampValue<float>(p * particle.unitDirection().y()));
m_pz.push_back(Acts::clampValue<float>(p * particle.unitDirection().z()));
m_px.push_back(Acts::clampValue<float>(p * particle.direction().x()));
m_py.push_back(Acts::clampValue<float>(p * particle.direction().y()));
m_pz.push_back(Acts::clampValue<float>(p * particle.direction().z()));
// particle constants
m_m.push_back(
Acts::clampValue<float>(particle.mass() / Acts::UnitConstants::GeV));
m_q.push_back(
Acts::clampValue<float>(particle.charge() / Acts::UnitConstants::e));
// derived kinematic quantities
m_eta.push_back(Acts::clampValue<float>(
Acts::VectorHelpers::eta(particle.unitDirection())));
Acts::VectorHelpers::eta(particle.direction())));
m_phi.push_back(Acts::clampValue<float>(
Acts::VectorHelpers::phi(particle.unitDirection())));
Acts::VectorHelpers::phi(particle.direction())));
m_pt.push_back(Acts::clampValue<float>(
p * Acts::VectorHelpers::perp(particle.unitDirection())));
p * Acts::VectorHelpers::perp(particle.direction())));
// decoded barcode components
m_vertexPrimary.push_back(particle.particleId().vertexPrimary());
m_vertexSecondary.push_back(particle.particleId().vertexSecondary());
Expand Down
20 changes: 10 additions & 10 deletions Examples/Io/Root/src/RootTrajectorySummaryWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,24 +273,24 @@ ActsExamples::ProcessCode ActsExamples::RootTrajectorySummaryWriter::writeT(
t_vx = particle.position().x();
t_vy = particle.position().y();
t_vz = particle.position().z();
t_px = t_p * particle.unitDirection().x();
t_py = t_p * particle.unitDirection().y();
t_pz = t_p * particle.unitDirection().z();
t_theta = theta(particle.unitDirection());
t_phi = phi(particle.unitDirection());
t_eta = eta(particle.unitDirection());
t_pT = t_p * perp(particle.unitDirection());
t_qop = particle.qop();
t_px = t_p * particle.direction().x();
t_py = t_p * particle.direction().y();
t_pz = t_p * particle.direction().z();
t_theta = theta(particle.direction());
t_phi = phi(particle.direction());
t_eta = eta(particle.direction());
t_pT = t_p * perp(particle.direction());
t_qop = particle.qOverP();

if (pSurface != nullptr) {
auto intersection =
pSurface->intersect(ctx.geoContext, particle.position(),
particle.unitDirection(), false);
particle.direction(), false);
auto position = intersection.intersection.position;

// get the truth perigee parameter
auto lpResult = pSurface->globalToLocal(ctx.geoContext, position,
particle.unitDirection());
particle.direction());
if (lpResult.ok()) {
t_d0 = lpResult.value()[Acts::BoundIndices::eBoundLoc0];
t_z0 = lpResult.value()[Acts::BoundIndices::eBoundLoc1];
Expand Down
2 changes: 1 addition & 1 deletion Examples/Python/tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ def test_truth_tracking_gsf(tmp_path, assert_root_hash, detector_config):
1,
),
(
"Fatras/include/ActsFatras/Kernel/detail/SimulationActor.hpp:178",
"Fatras/include/ActsFatras/Kernel/detail/SimulationActor.hpp:177",
acts.FpeType.FLTUND,
1,
),
Expand Down
36 changes: 21 additions & 15 deletions Fatras/include/ActsFatras/EventData/Particle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,16 @@ class Particle {
}
/// Set the direction three-vector
Particle &setDirection(const Vector3 &direction) {
m_unitDirection = direction;
m_unitDirection.normalize();
m_direction = direction;
m_direction.normalize();
return *this;
}
/// Set the direction three-vector from scalar components.
Particle &setDirection(Scalar dx, Scalar dy, Scalar dz) {
m_unitDirection[Acts::ePos0] = dx;
m_unitDirection[Acts::ePos1] = dy;
m_unitDirection[Acts::ePos2] = dz;
m_unitDirection.normalize();
m_direction[Acts::ePos0] = dx;
m_direction[Acts::ePos1] = dy;
m_direction[Acts::ePos2] = dz;
m_direction.normalize();
return *this;
}
/// Set the absolute momentum.
Expand Down Expand Up @@ -154,11 +154,15 @@ class Particle {
constexpr Acts::PdgParticle pdg() const { return m_pdg; }
/// Particle charge.
constexpr Scalar charge() const { return m_charge; }
/// Particle absolute charge.
constexpr Scalar absoluteCharge() const { return std::abs(m_charge); }
/// Particle mass.
constexpr Scalar mass() const { return m_mass; }
/// Particl qop.
constexpr Scalar qop() const {
return (charge() == 0 ? 1 : charge()) / absoluteMomentum();

/// Particl qOverP.
constexpr Scalar qOverP() const {
return charge() == 0 ? 1 / absoluteMomentum()
: charge() / absoluteMomentum();
}

/// Space-time position four-vector.
Expand All @@ -171,20 +175,22 @@ class Particle {
Vector4 fourMomentum() const {
Vector4 mom4;
// stored direction is always normalized
mom4[Acts::eMom0] = m_absMomentum * m_unitDirection[Acts::ePos0];
mom4[Acts::eMom1] = m_absMomentum * m_unitDirection[Acts::ePos1];
mom4[Acts::eMom2] = m_absMomentum * m_unitDirection[Acts::ePos2];
mom4[Acts::eMom0] = m_absMomentum * m_direction[Acts::ePos0];
mom4[Acts::eMom1] = m_absMomentum * m_direction[Acts::ePos1];
mom4[Acts::eMom2] = m_absMomentum * m_direction[Acts::ePos2];
mom4[Acts::eEnergy] = energy();
return mom4;
}
/// Unit three-direction, i.e. the normalized momentum three-vector.
const Vector3 &unitDirection() const { return m_unitDirection; }
const Vector3 &direction() const { return m_direction; }
/// Absolute momentum in the x-y plane.
Scalar transverseMomentum() const {
return m_absMomentum * m_unitDirection.segment<2>(Acts::eMom0).norm();
return m_absMomentum * m_direction.segment<2>(Acts::eMom0).norm();
}
/// Absolute momentum.
constexpr Scalar absoluteMomentum() const { return m_absMomentum; }
/// Absolute momentum.
Vector3 momentum() const { return absoluteMomentum() * direction(); }
/// Total energy, i.e. norm of the four-momentum.
Scalar energy() const { return std::hypot(m_mass, m_absMomentum); }

Expand Down Expand Up @@ -234,7 +240,7 @@ class Particle {
Scalar m_charge = Scalar(0);
Scalar m_mass = Scalar(0);
// kinematics, i.e. things that change over the particle lifetime.
Vector3 m_unitDirection = Vector3::UnitZ();
Vector3 m_direction = Vector3::UnitZ();
Scalar m_absMomentum = Scalar(0);
Vector4 m_position4 = Vector4::Zero();
// proper time in the particle rest frame
Expand Down
2 changes: 1 addition & 1 deletion Fatras/include/ActsFatras/Kernel/Simulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ struct SingleParticleSimulation {
actor.initialParticle = particle;
// use AnyCharge to be able to handle neutral and charged parameters
Acts::SingleCurvilinearTrackParameters<Acts::AnyCharge> start(
particle.fourPosition(), particle.unitDirection(),
particle.fourPosition(), particle.direction(),
particle.absoluteMomentum(), particle.charge());
auto result = propagator.propagate(start, options);
if (not result.ok()) {
Expand Down
9 changes: 4 additions & 5 deletions Fatras/include/ActsFatras/Kernel/detail/SimulationActor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ struct SimulationActor {
// it should in principle never happen, so probably it would be best
// to change to a model using transform() directly
auto lpResult = surface.globalToLocal(state.geoContext, before.position(),
before.unitDirection());
before.direction());
if (lpResult.ok()) {
Acts::Vector2 local = lpResult.value();
Acts::MaterialSlab slab =
Expand All @@ -170,8 +170,7 @@ struct SimulationActor {
auto normal = surface.normal(state.geoContext, local);
// dot-product(unit normal, direction) = cos(incidence angle)
// particle direction is normalized, not sure about surface normal
auto cosIncidenceInv =
normal.norm() / normal.dot(before.unitDirection());
auto cosIncidenceInv = normal.norm() / normal.dot(before.direction());
// apply abs in case `normal` and `before` produce an angle > 90°
slab.scaleThickness(std::abs(cosIncidenceInv));
// run the interaction simulation
Expand All @@ -196,8 +195,8 @@ struct SimulationActor {
}

// continue the propagation with the modified parameters
stepper.update(state.stepping, after.position(), after.unitDirection(),
after.qop(), after.time());
stepper.update(state.stepping, after.position(), after.direction(),
after.qOverP(), after.time());
}

/// Construct the current particle state from the stepper state.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ struct BetheHeitler {
bremPhoton(particle, sampledEnergyLoss, uDist(generator),
uDist(generator), uDist(generator), uDist(generator));
// Recoil input momentum
particle.setDirection(particle.unitDirection() *
particle.absoluteMomentum() -
photon.energy() * photon.unitDirection());
particle.setDirection(particle.direction() * particle.absoluteMomentum() -
photon.energy() * photon.direction());

// apply the energy loss
particle.correctEnergy(-sampledEnergyLoss);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ Particle::Vector3 PhotonConversion::generateChildDirection(
const auto psi =
std::uniform_real_distribution<double>(-M_PI, M_PI)(generator);

Acts::Vector3 direction = particle.unitDirection();
Acts::Vector3 direction = particle.direction();
// construct the combined rotation to the scattered direction
Acts::RotationMatrix3 rotation(
// rotation of the scattering deflector axis relative to the reference
Expand Down
Loading

0 comments on commit 2b5899d

Please sign in to comment.