Skip to content

Commit

Permalink
fix: forward support edm4eic v5
Browse files Browse the repository at this point in the history
  • Loading branch information
wdconinc committed Jan 22, 2024
1 parent 8e6d75c commit 61cf5c5
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 41 deletions.
79 changes: 52 additions & 27 deletions JugTrack/src/components/ParticlesFromTrackFit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "Acts/EventData/MultiTrajectoryHelpers.hpp"

// Event Model related classes
#include "edm4eic/EDM4eicVersion.h"
#include "edm4eic/ReconstructedParticleCollection.h"
#include "edm4eic/TrackerHitCollection.h"
#include "edm4eic/TrackParametersCollection.h"
Expand All @@ -37,6 +38,23 @@

namespace Jug::Reco {

#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::eBoundTheta, 1.},
{Acts::eBoundPhi, 1.},
{Acts::eBoundQOverP, 1. / Acts::UnitConstants::GeV},
{Acts::eBoundTime, Acts::UnitConstants::ns}
}};
#endif

/** Extract the particles form fit trajectories.
*
* \ingroup tracking
Expand Down Expand Up @@ -116,35 +134,42 @@ namespace Jug::Reco {
debug() << " chi2 = " << trajState.chi2Sum << endmsg;
}

const decltype(edm4eic::TrackParametersData::loc) loc {
auto pars = track_pars->create();
pars.setType(0); // type: track head --> 0
pars.setLoc({
static_cast<float>(parameter[Acts::eBoundLoc0]),
static_cast<float>(parameter[Acts::eBoundLoc1])
};
const decltype(edm4eic::TrackParametersData::momentumError) momentumError {
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))};
const decltype(edm4eic::TrackParametersData::locError) locError {
static_cast<float>(covariance(Acts::eBoundLoc0, Acts::eBoundLoc0)),
static_cast<float>(covariance(Acts::eBoundLoc1, Acts::eBoundLoc1)),
static_cast<float>(covariance(Acts::eBoundLoc0, Acts::eBoundLoc1))};
const float timeError{sqrt(static_cast<float>(covariance(Acts::eBoundTime, Acts::eBoundTime)))};

edm4eic::TrackParameters pars{
0, // type: track head --> 0
loc,
locError,
static_cast<float>(parameter[Acts::eBoundTheta]),
static_cast<float>(parameter[Acts::eBoundPhi]),
static_cast<float>(parameter[Acts::eBoundQOverP]),
momentumError,
static_cast<float>(parameter[Acts::eBoundTime]),
timeError,
static_cast<float>(boundParam.charge())};
track_pars->push_back(pars);
});
pars.setTheta(static_cast<float>(parameter[Acts::eBoundTheta]));
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;
}
}
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
}

auto tsize = trackTips.size();
Expand Down
2 changes: 1 addition & 1 deletion JugTrack/src/components/TrackProjector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ namespace Jug::Reco {
static_cast<float>(parameter[Acts::eBoundLoc0]),
static_cast<float>(parameter[Acts::eBoundLoc1])
};
const decltype(edm4eic::TrackParametersData::locError) locError {
const edm4eic::Cov2f locError {
static_cast<float>(covariance(Acts::eBoundLoc0, Acts::eBoundLoc0)),
static_cast<float>(covariance(Acts::eBoundLoc1, Acts::eBoundLoc1)),
static_cast<float>(covariance(Acts::eBoundLoc0, Acts::eBoundLoc1))
Expand Down
36 changes: 24 additions & 12 deletions JugTrack/src/components/TruthTrackSeeding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
//#include "Acts/Definitions/Common.hpp"
//#include "Acts/EventData/Charge.hpp"

#include "edm4eic/EDM4eicVersion.h"
#include "edm4hep/MCParticleCollection.h"
#include "edm4eic/TrackParametersCollection.h"
#include "Math/Vector3D.h"
Expand Down Expand Up @@ -93,23 +94,34 @@ namespace Jug::Reco {

const auto q_over_p = charge / p;

edm4eic::TrackParameters params{-1, // type --> seed (-1)
{0.0F, 0.0F}, // location on surface
{0.1, 0.1, 0.1}, // Covariance on location
theta, // theta (rad)
phi, // phi (rad)
q_over_p * .05F, // Q/P (e/GeV)
{0.1, 0.1, 0.1}, // Covariance on theta/phi/Q/P
part.getTime(), // Time (ns)
0.1, // Error on time
charge}; // Charge
auto params = init_trk_params->create();
params.setType(-1); // type --> seed (-1)
params.setLoc({0.0F, 0.0F}); // location on surface
params.setTheta(theta); // theta (rad)
params.setPhi(phi); // phi (rad)
params.setQOverP(q_over_p * .05F); // Q/P (e/GeV)
params.setTime(part.getTime()); // Time (ns)
#if EDM4EIC_VERSION_MAJOR >= 5
edm4eic::Cov6f cov;
cov(0,0) = 0.1; // loc0
cov(0,1) = 0.1; // loc0/loc1
cov(1,1) = 0.1; // loc1
cov(2,2) = 0.1; // theta
cov(3,3) = 0.1; // phi
cov(4,4) = 0.1; // qOverP
cov(5,5) = 0.1; // time
params.setCovariance(cov);
#else
params.setLocError({0.1, 0.1, 0.1}); // Covariance on location
params.setMomentumError({0.1, 0.1, 0.1}); // Covariance on theta/phi/Q/P
params.setTimeError(0.1); // Error on time
params.setCharge(charge); // Charge
#endif

////// Construct a perigee surface as the target surface
//auto pSurface = Acts::Surface::makeShared<Acts::PerigeeSurface>(
// Acts::Vector3{part.getVertex().x * mm, part.getVertex().y * mm, part.getVertex().z * mm});

init_trk_params->push_back(params);

if (msgLevel(MSG::DEBUG)) {
debug() << "Invoke track finding seeded by truth particle with p = " << p << " GeV" << endmsg;
debug() << " charge = " << charge << endmsg;
Expand Down
2 changes: 1 addition & 1 deletion external/algorithms/truth/src/ParticlesWithTruthPID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void ParticlesWithTruthPID::process(const ParticlesWithTruthPID::Input& input,
for (const auto& trk : tracks) {
const auto mom =
edm4hep::utils::sphericalToVector(1.0 / std::abs(trk.getQOverP()), trk.getTheta(), trk.getPhi());
const auto charge_rec = trk.getCharge();
const auto charge_rec = std::copysign(1., trk.getQOverP());
// utility variables for matching
int best_match = -1;
double best_delta = std::numeric_limits<double>::max();
Expand Down

0 comments on commit 61cf5c5

Please sign in to comment.