Skip to content

Commit

Permalink
Drop support for EDM4eic 4.0.0 and older (#1435)
Browse files Browse the repository at this point in the history
Resolves #1389
  • Loading branch information
veprbl authored and Alexander Jentsch committed May 20, 2024
1 parent be6c91b commit 70b2eb4
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 167 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ find_package(algorithms 1.0.0 REQUIRED Core)
find_package(Eigen3 REQUIRED)
find_package(podio REQUIRED)
find_package(EDM4HEP 0.7.1 REQUIRED)
find_package(EDM4EIC 3.0 REQUIRED)
find_package(EDM4EIC 5.0 REQUIRED)

# spdlog
find_package(spdlog REQUIRED)
Expand Down
165 changes: 59 additions & 106 deletions src/algorithms/tracking/CKFTracking.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <ActsExamples/EventData/MeasurementCalibration.hpp>
#include <ActsExamples/EventData/Track.hpp>
#include <edm4eic/Cov3f.h>
#include <edm4eic/EDM4eicVersion.h>
#include <edm4eic/Cov6f.h>
#include <edm4eic/Measurement2DCollection.h>
#include <edm4eic/TrackParametersCollection.h>
#include <edm4eic/TrajectoryCollection.h>
Expand All @@ -46,10 +46,6 @@
#include <optional>
#include <utility>

#if EDM4EIC_VERSION_MAJOR >= 5
#include <edm4eic/Cov6f.h>
#endif

#include "ActsGeometryProvider.h"
#include "DD4hepBField.h"
#include "extensions/spdlog/SpdlogFormatters.h" // IWYU pragma: keep
Expand All @@ -59,22 +55,20 @@ namespace eicrecon {

using namespace Acts::UnitLiterals;

#if EDM4EIC_VERSION_MAJOR >= 5
// This array relates the Acts and EDM4eic covariance matrices, including
// the unit conversion to get from Acts units into EDM4eic units.
//
// Note: std::map is not constexpr, so we use a constexpr std::array
// std::array initialization need double braces since arrays are aggregates
// ref: https://en.cppreference.com/w/cpp/language/aggregate_initialization
static constexpr std::array<std::pair<Acts::BoundIndices, double>, 6> edm4eic_indexed_units{{
{Acts::eBoundLoc0, Acts::UnitConstants::mm},
{Acts::eBoundLoc1, Acts::UnitConstants::mm},
{Acts::eBoundPhi, 1.},
{Acts::eBoundTheta, 1.},
{Acts::eBoundQOverP, 1. / Acts::UnitConstants::GeV},
{Acts::eBoundTime, Acts::UnitConstants::ns}
}};
#endif
// This array relates the Acts and EDM4eic covariance matrices, including
// the unit conversion to get from Acts units into EDM4eic units.
//
// Note: std::map is not constexpr, so we use a constexpr std::array
// std::array initialization need double braces since arrays are aggregates
// ref: https://en.cppreference.com/w/cpp/language/aggregate_initialization
static constexpr std::array<std::pair<Acts::BoundIndices, double>, 6> edm4eic_indexed_units{{
{Acts::eBoundLoc0, Acts::UnitConstants::mm},
{Acts::eBoundLoc1, Acts::UnitConstants::mm},
{Acts::eBoundPhi, 1.},
{Acts::eBoundTheta, 1.},
{Acts::eBoundQOverP, 1. / Acts::UnitConstants::GeV},
{Acts::eBoundTime, Acts::UnitConstants::ns}
}};

CKFTracking::CKFTracking() {
}
Expand Down Expand Up @@ -163,22 +157,13 @@ namespace eicrecon {
double charge = std::copysign(1., track_parameter.getQOverP());

Acts::BoundSquareMatrix cov = Acts::BoundSquareMatrix::Zero();
#if EDM4EIC_VERSION_MAJOR >= 5
for (size_t i = 0; const auto& [a, x] : edm4eic_indexed_units) {
for (size_t j = 0; const auto& [b, y] : edm4eic_indexed_units) {
cov(a, b) = track_parameter.getCovariance()(i,j) * x * y;
++j;
}
++i;
for (size_t i = 0; const auto& [a, x] : edm4eic_indexed_units) {
for (size_t j = 0; const auto& [b, y] : edm4eic_indexed_units) {
cov(a, b) = track_parameter.getCovariance()(i,j) * x * y;
++j;
}
#else
cov(Acts::eBoundLoc0, Acts::eBoundLoc0) = std::pow( track_parameter.getLocError().xx ,2)*Acts::UnitConstants::mm*Acts::UnitConstants::mm;
cov(Acts::eBoundLoc1, Acts::eBoundLoc1) = std::pow( track_parameter.getLocError().yy,2)*Acts::UnitConstants::mm*Acts::UnitConstants::mm;
cov(Acts::eBoundTheta, Acts::eBoundTheta) = std::pow( track_parameter.getMomentumError().xx,2);
cov(Acts::eBoundPhi, Acts::eBoundPhi) = std::pow( track_parameter.getMomentumError().yy,2);
cov(Acts::eBoundQOverP, Acts::eBoundQOverP) = std::pow( track_parameter.getMomentumError().zz,2) / (Acts::UnitConstants::GeV*Acts::UnitConstants::GeV);
cov(Acts::eBoundTime, Acts::eBoundTime) = std::pow( track_parameter.getTimeError(),2)*Acts::UnitConstants::ns*Acts::UnitConstants::ns;
#endif
++i;
}

// Construct a perigee surface as the target surface
auto pSurface = Acts::Surface::makeShared<const Acts::PerigeeSurface>(Acts::Vector3(0,0,0));
Expand Down Expand Up @@ -351,10 +336,6 @@ namespace eicrecon {

// Create trajectory
auto trajectory = trajectories->create();
#if EDM4EIC_VERSION_MAJOR < 5
trajectory.setChi2(trajectoryState.chi2Sum);
trajectory.setNdf(trajectoryState.NDF);
#endif
trajectory.setNMeasurements(trajectoryState.nMeasurements);
trajectory.setNStates(trajectoryState.nStates);
trajectory.setNOutliers(trajectoryState.nOutliers);
Expand Down Expand Up @@ -390,66 +371,46 @@ namespace eicrecon {
pars.setPhi(static_cast<float>(parameter[Acts::eBoundPhi]));
pars.setQOverP(static_cast<float>(parameter[Acts::eBoundQOverP]));
pars.setTime(static_cast<float>(parameter[Acts::eBoundTime]));
#if EDM4EIC_VERSION_MAJOR >= 5
edm4eic::Cov6f cov;
for (size_t i = 0; const auto& [a, x] : edm4eic_indexed_units) {
for (size_t j = 0; const auto& [b, y] : edm4eic_indexed_units) {
// FIXME why not pars.getCovariance()(i,j) = covariance(a,b) / x / y;
cov(i,j) = covariance(a,b) / x / y;
}
edm4eic::Cov6f cov;
for (size_t i = 0; const auto& [a, x] : edm4eic_indexed_units) {
for (size_t j = 0; const auto& [b, y] : edm4eic_indexed_units) {
// FIXME why not pars.getCovariance()(i,j) = covariance(a,b) / x / y;
cov(i,j) = covariance(a,b) / x / y;
}
pars.setCovariance(cov);
#else
pars.setCharge(static_cast<float>(boundParam.charge()));
pars.setLocError({
static_cast<float>(covariance(Acts::eBoundLoc0, Acts::eBoundLoc0)),
static_cast<float>(covariance(Acts::eBoundLoc1, Acts::eBoundLoc1)),
static_cast<float>(covariance(Acts::eBoundLoc0, Acts::eBoundLoc1))
});
pars.setMomentumError({
static_cast<float>(covariance(Acts::eBoundTheta, Acts::eBoundTheta)),
static_cast<float>(covariance(Acts::eBoundPhi, Acts::eBoundPhi)),
static_cast<float>(covariance(Acts::eBoundQOverP, Acts::eBoundQOverP)),
static_cast<float>(covariance(Acts::eBoundTheta, Acts::eBoundPhi)),
static_cast<float>(covariance(Acts::eBoundTheta, Acts::eBoundQOverP)),
static_cast<float>(covariance(Acts::eBoundPhi, Acts::eBoundQOverP))
});
pars.setTimeError(sqrt(static_cast<float>(covariance(Acts::eBoundTime, Acts::eBoundTime))));
#endif
}
pars.setCovariance(cov);

trajectory.addToTrackParameters(pars);

// Fill tracks
#if EDM4EIC_VERSION_MAJOR >= 5
auto track = tracks->create();
track.setType( // Flag that defines the type of track
pars.getType()
);
track.setPosition( // Track 3-position at the vertex
edm4hep::Vector3f()
);
track.setMomentum( // Track 3-momentum at the vertex [GeV]
edm4hep::Vector3f()
);
track.setPositionMomentumCovariance( // Covariance matrix in basis [x,y,z,px,py,pz]
edm4eic::Cov6f()
);
track.setTime( // Track time at the vertex [ns]
static_cast<float>(parameter[Acts::eBoundTime])
);
track.setTimeError( // Error on the track vertex time
sqrt(static_cast<float>(covariance(Acts::eBoundTime, Acts::eBoundTime)))
);
track.setCharge( // Particle charge
std::copysign(1., parameter[Acts::eBoundQOverP])
);
track.setChi2(trajectoryState.chi2Sum); // Total chi2
track.setNdf(trajectoryState.NDF); // Number of degrees of freedom
track.setPdg( // PDG particle ID hypothesis
boundParam.particleHypothesis().absolutePdg()
);
track.setTrajectory(trajectory); // Trajectory of this track
#endif
auto track = tracks->create();
track.setType( // Flag that defines the type of track
pars.getType()
);
track.setPosition( // Track 3-position at the vertex
edm4hep::Vector3f()
);
track.setMomentum( // Track 3-momentum at the vertex [GeV]
edm4hep::Vector3f()
);
track.setPositionMomentumCovariance( // Covariance matrix in basis [x,y,z,px,py,pz]
edm4eic::Cov6f()
);
track.setTime( // Track time at the vertex [ns]
static_cast<float>(parameter[Acts::eBoundTime])
);
track.setTimeError( // Error on the track vertex time
sqrt(static_cast<float>(covariance(Acts::eBoundTime, Acts::eBoundTime)))
);
track.setCharge( // Particle charge
std::copysign(1., parameter[Acts::eBoundQOverP])
);
track.setChi2(trajectoryState.chi2Sum); // Total chi2
track.setNdf(trajectoryState.NDF); // Number of degrees of freedom
track.setPdg( // PDG particle ID hypothesis
boundParam.particleHypothesis().absolutePdg()
);
track.setTrajectory(trajectory); // Trajectory of this track

// save measurement2d to good measurements or outliers according to srclink index
// fix me: ideally, this should be integrated into multitrajectoryhelper
Expand All @@ -472,22 +433,14 @@ namespace eicrecon {
} else {
auto meas2D = meas2Ds[srclink_index];
if (typeFlags.test(Acts::TrackStateFlag::MeasurementFlag)) {
#if EDM4EIC_VERSION_MAJOR >= 5
track.addToMeasurements(meas2D);
trajectory.addToMeasurements_deprecated(meas2D);
#else
trajectory.addToMeasurementHits(meas2D);
#endif
track.addToMeasurements(meas2D);
trajectory.addToMeasurements_deprecated(meas2D);
m_log->debug("Measurement on geo id={}, index={}, loc={},{}",
geoID, srclink_index, meas2D.getLoc().a, meas2D.getLoc().b);

}
else if (typeFlags.test(Acts::TrackStateFlag::OutlierFlag)) {
#if EDM4EIC_VERSION_MAJOR >= 5
trajectory.addToOutliers_deprecated(meas2D);
#else
trajectory.addToOutlierHits(meas2D);
#endif
trajectory.addToOutliers_deprecated(meas2D);
m_log->debug("Outlier on geo id={}, index={}, loc={},{}",
geoID, srclink_index, meas2D.getLoc().a, meas2D.getLoc().b);

Expand Down
21 changes: 1 addition & 20 deletions src/algorithms/tracking/IterativeVertexFinder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
#include <Acts/Vertexing/ZScanVertexFinder.hpp>
#include <ActsExamples/EventData/Trajectories.hpp>
#include <boost/container/vector.hpp>
#include <edm4eic/Cov3f.h>
#include <edm4eic/EDM4eicVersion.h>
#include <edm4eic/Cov4f.h>
#include <math.h>
#include <Eigen/Core>
#include <Eigen/Geometry>
Expand Down Expand Up @@ -118,7 +117,6 @@ std::unique_ptr<edm4eic::VertexCollection> eicrecon::IterativeVertexFinder::prod
}

for (const auto& vtx : vertices) {
#if EDM4EIC_VERSION_MAJOR >= 5
edm4eic::Cov4f cov(vtx.fullCovariance()(0,0), vtx.fullCovariance()(1,1), vtx.fullCovariance()(2,2), vtx.fullCovariance()(3,3),
vtx.fullCovariance()(0,1), vtx.fullCovariance()(0,2), vtx.fullCovariance()(0,3),
vtx.fullCovariance()(1,2), vtx.fullCovariance()(1,3),
Expand All @@ -134,23 +132,6 @@ std::unique_ptr<edm4eic::VertexCollection> eicrecon::IterativeVertexFinder::prod
(float)vtx.time(),
}); // vtxposition
eicvertex.setPositionError(cov); // covariance
#else
edm4eic::Cov3f cov(vtx.covariance()(0, 0), vtx.covariance()(1, 1), vtx.covariance()(2, 2),
vtx.covariance()(0, 1), vtx.covariance()(0, 2), vtx.covariance()(1, 2));

auto eicvertex = outputVertices->create();
eicvertex.setPrimary(1); // boolean flag if vertex is primary vertex of event
eicvertex.setChi2((float)vtx.fitQuality().first); // chi2
eicvertex.setProbability((float)vtx.fitQuality().second); // ndf
eicvertex.setPosition({
(float)vtx.position().x(),
(float)vtx.position().y(),
(float)vtx.position().z()
}); // vtxposition
eicvertex.setPositionError(cov); // covariance
eicvertex.setAlgorithmType(1); // algorithmtype
eicvertex.setTime((float)vtx.time()); // time
#endif
}

return std::move(outputVertices);
Expand Down
29 changes: 9 additions & 20 deletions src/algorithms/tracking/TrackParamTruthInit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

#include <Evaluator/DD4hepUnits.h>
#include <TParticlePDG.h>
#include <edm4eic/EDM4eicVersion.h>
#include <edm4hep/Vector3d.h>
#include <edm4hep/Vector3f.h>
#include <edm4eic/Cov6f.h>
#include <fmt/core.h>
#include <spdlog/common.h>
#include <Eigen/Core>
Expand All @@ -22,10 +22,6 @@
#include <memory>
#include <utility>

#if EDM4EIC_VERSION_MAJOR >= 5
#include <edm4eic/Cov6f.h>
#endif

#include "extensions/spdlog/SpdlogFormatters.h" // IWYU pragma: keep


Expand Down Expand Up @@ -132,21 +128,14 @@ eicrecon::TrackParamTruthInit::produce(const edm4hep::MCParticleCollection* mcpa
track_parameter.setTheta(theta); // theta [rad]
track_parameter.setQOverP(charge / (pinit / dd4hep::GeV)); // Q/p [e/GeV]
track_parameter.setTime(mcparticle.getTime()); // time [ns]
#if EDM4EIC_VERSION_MAJOR >= 5
edm4eic::Cov6f cov;
cov(0,0) = 1.0; // loc0
cov(1,1) = 1.0; // loc1
cov(2,2) = 0.05; // phi
cov(3,3) = 0.01; // theta
cov(4,4) = 0.1; // qOverP
cov(5,5) = 10e9; // time
track_parameter.setCovariance(cov);
#else
track_parameter.setCharge(charge); // charge
track_parameter.setLocError({1.0, 1.0}); // sqrt(variance) of location [mm]
track_parameter.setMomentumError({0.01, 0.05, 0.1}); // sqrt(variance) on theta, phi, q/p [rad, rad, e/GeV]
track_parameter.setTimeError(10e9); // error on time [ns]
#endif
edm4eic::Cov6f cov;
cov(0,0) = 1.0; // loc0
cov(1,1) = 1.0; // loc1
cov(2,2) = 0.05; // phi
cov(3,3) = 0.01; // theta
cov(4,4) = 0.1; // qOverP
cov(5,5) = 10e9; // time
track_parameter.setCovariance(cov);

// Debug output
if (m_log->level() <= spdlog::level::debug) {
Expand Down
29 changes: 9 additions & 20 deletions src/algorithms/tracking/TrackSeeding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <Acts/Utilities/Result.hpp>
#include <boost/container/small_vector.hpp>
#include <boost/container/vector.hpp>
#include <edm4eic/EDM4eicVersion.h>
#include <edm4eic/Cov6f.h>
#include <Eigen/Core>
#include <Eigen/Geometry>
#include <cmath>
Expand All @@ -28,10 +28,6 @@
#include <tuple>
#include <type_traits>

#if EDM4EIC_VERSION_MAJOR >= 5
#include <edm4eic/Cov6f.h>
#endif

namespace
{
//! convenience square method
Expand Down Expand Up @@ -238,21 +234,14 @@ std::unique_ptr<edm4eic::TrackParametersCollection> eicrecon::TrackSeeding::make
trackparam.setTheta(theta); //theta [rad]
trackparam.setQOverP(qOverP); // Q/p [e/GeV]
trackparam.setTime(10); // time in ns
#if EDM4EIC_VERSION_MAJOR >= 5
edm4eic::Cov6f cov;
cov(0,0) = m_cfg.locaError / Acts::UnitConstants::mm; // loc0
cov(1,1) = m_cfg.locbError / Acts::UnitConstants::mm; // loc1
cov(2,2) = m_cfg.phiError / Acts::UnitConstants::rad; // phi
cov(3,3) = m_cfg.thetaError / Acts::UnitConstants::rad; // theta
cov(4,4) = m_cfg.qOverPError * Acts::UnitConstants::GeV; // qOverP
cov(5,5) = m_cfg.timeError / Acts::UnitConstants::ns; // time
trackparam.setCovariance(cov);
#else
trackparam.setCharge(static_cast<float>(charge)); // charge
trackparam.setLocError({m_cfg.locaError, m_cfg.locbError}); //covariance of location
trackparam.setMomentumError({m_cfg.thetaError, m_cfg.phiError, m_cfg.qOverPError}); // covariance on theta/phi/q/p
trackparam.setTimeError(m_cfg.timeError); // error on time
#endif
edm4eic::Cov6f cov;
cov(0,0) = m_cfg.locaError / Acts::UnitConstants::mm; // loc0
cov(1,1) = m_cfg.locbError / Acts::UnitConstants::mm; // loc1
cov(2,2) = m_cfg.phiError / Acts::UnitConstants::rad; // phi
cov(3,3) = m_cfg.thetaError / Acts::UnitConstants::rad; // theta
cov(4,4) = m_cfg.qOverPError * Acts::UnitConstants::GeV; // qOverP
cov(5,5) = m_cfg.timeError / Acts::UnitConstants::ns; // time
trackparam.setCovariance(cov);
}

return std::move(trackparams);
Expand Down

0 comments on commit 70b2eb4

Please sign in to comment.