diff --git a/JugTrack/src/components/ParticlesFromTrackFit.cpp b/JugTrack/src/components/ParticlesFromTrackFit.cpp index 6f37947..1408e0d 100644 --- a/JugTrack/src/components/ParticlesFromTrackFit.cpp +++ b/JugTrack/src/components/ParticlesFromTrackFit.cpp @@ -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" @@ -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, 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 @@ -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(parameter[Acts::eBoundLoc0]), static_cast(parameter[Acts::eBoundLoc1]) - }; - const decltype(edm4eic::TrackParametersData::momentumError) momentumError { - static_cast(covariance(Acts::eBoundTheta, Acts::eBoundTheta)), - static_cast(covariance(Acts::eBoundPhi, Acts::eBoundPhi)), - static_cast(covariance(Acts::eBoundQOverP, Acts::eBoundQOverP)), - static_cast(covariance(Acts::eBoundTheta, Acts::eBoundPhi)), - static_cast(covariance(Acts::eBoundTheta, Acts::eBoundQOverP)), - static_cast(covariance(Acts::eBoundPhi, Acts::eBoundQOverP))}; - const decltype(edm4eic::TrackParametersData::locError) locError { - static_cast(covariance(Acts::eBoundLoc0, Acts::eBoundLoc0)), - static_cast(covariance(Acts::eBoundLoc1, Acts::eBoundLoc1)), - static_cast(covariance(Acts::eBoundLoc0, Acts::eBoundLoc1))}; - const float timeError{sqrt(static_cast(covariance(Acts::eBoundTime, Acts::eBoundTime)))}; - - edm4eic::TrackParameters pars{ - 0, // type: track head --> 0 - loc, - locError, - static_cast(parameter[Acts::eBoundTheta]), - static_cast(parameter[Acts::eBoundPhi]), - static_cast(parameter[Acts::eBoundQOverP]), - momentumError, - static_cast(parameter[Acts::eBoundTime]), - timeError, - static_cast(boundParam.charge())}; - track_pars->push_back(pars); + }); + pars.setTheta(static_cast(parameter[Acts::eBoundTheta])); + pars.setPhi(static_cast(parameter[Acts::eBoundPhi])); + pars.setQOverP(static_cast(parameter[Acts::eBoundQOverP])); + pars.setTime(static_cast(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(boundParam.charge())); + pars.setLocError({ + static_cast(covariance(Acts::eBoundLoc0, Acts::eBoundLoc0)), + static_cast(covariance(Acts::eBoundLoc1, Acts::eBoundLoc1)), + static_cast(covariance(Acts::eBoundLoc0, Acts::eBoundLoc1)) + }); + pars.setMomentumError({ + static_cast(covariance(Acts::eBoundTheta, Acts::eBoundTheta)), + static_cast(covariance(Acts::eBoundPhi, Acts::eBoundPhi)), + static_cast(covariance(Acts::eBoundQOverP, Acts::eBoundQOverP)), + static_cast(covariance(Acts::eBoundTheta, Acts::eBoundPhi)), + static_cast(covariance(Acts::eBoundTheta, Acts::eBoundQOverP)), + static_cast(covariance(Acts::eBoundPhi, Acts::eBoundQOverP)) + }); + pars.setTimeError(sqrt(static_cast(covariance(Acts::eBoundTime, Acts::eBoundTime)))); + #endif } auto tsize = trackTips.size(); diff --git a/JugTrack/src/components/TrackProjector.cpp b/JugTrack/src/components/TrackProjector.cpp index f34ce2f..1237555 100644 --- a/JugTrack/src/components/TrackProjector.cpp +++ b/JugTrack/src/components/TrackProjector.cpp @@ -148,7 +148,7 @@ namespace Jug::Reco { static_cast(parameter[Acts::eBoundLoc0]), static_cast(parameter[Acts::eBoundLoc1]) }; - const decltype(edm4eic::TrackParametersData::locError) locError { + const edm4eic::Cov2f locError { static_cast(covariance(Acts::eBoundLoc0, Acts::eBoundLoc0)), static_cast(covariance(Acts::eBoundLoc1, Acts::eBoundLoc1)), static_cast(covariance(Acts::eBoundLoc0, Acts::eBoundLoc1)) diff --git a/JugTrack/src/components/TruthTrackSeeding.cpp b/JugTrack/src/components/TruthTrackSeeding.cpp index 91de556..a8e80b1 100644 --- a/JugTrack/src/components/TruthTrackSeeding.cpp +++ b/JugTrack/src/components/TruthTrackSeeding.cpp @@ -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" @@ -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::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; diff --git a/external/algorithms/truth/src/ParticlesWithTruthPID.cpp b/external/algorithms/truth/src/ParticlesWithTruthPID.cpp index b0f604a..cce5f67 100644 --- a/external/algorithms/truth/src/ParticlesWithTruthPID.cpp +++ b/external/algorithms/truth/src/ParticlesWithTruthPID.cpp @@ -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::max();