29#include <edm4hep/TrackState.h>
42constexpr int kCountWord = 1;
43constexpr int kWordsNoCov = 8;
44constexpr int kWordsWithCov = 23;
45constexpr int kCovWords = 15;
46constexpr float kNotMeasured = std::numeric_limits<float>::quiet_NaN();
53int locationForDetector(
int det_id) {
55 case 0:
return edm4hep::TrackState::AtFirstHit;
56 case 9:
case 13:
case 22:
case 26:
57 return edm4hep::TrackState::AtCalorimeter;
58 default:
return edm4hep::TrackState::AtOther;
67CovMatrix6 covariance(
int lpt,
bool cylindrical) {
68 static constexpr int kCylinder[5] = {1, 2, 3, 4, 5};
69 static constexpr int kPlane [5] = {0, 1, 3, 4, 5};
70 const int* idx = cylindrical ? kCylinder : kPlane;
74 for (
int i = 0; i < 5; ++i) {
75 for (
int j = 0; j <= i; ++j, ++slot) {
76 cov[
covOffset(idx[i], idx[j])] = ph::Q(lpt + kWordsNoCov + 1 + slot);
82int nint(
float x) {
return static_cast<int>(std::lround(x)); }
91 const double B =
frame_.getParameter<
float>(
92 makeName(
"EVT",
"BField")).value_or(0.f);
95 if (paIdx >=
static_cast<int>(out.
pa_to_states.size())) {
99 if (ltrax <= 0)
return;
102 const int npts = nint(ph::Q(ltrax + 2));
106 for (
int ip = 0; ip < npts; ++ip) {
107 const int n_words = nint(ph::Q(lpt));
108 if (n_words < kWordsNoCov)
break;
109 if (lpt + n_words > ltrax + blen)
break;
111 const int det_id = nint(ph::Q(lpt + 1));
112 const bool cylindrical = nint(ph::Q(lpt + 2)) != 0;
113 const bool has_cov = n_words >= kWordsWithCov;
120 const double word = ph::Q(lpt + 8);
121 const double invP = q != 0 ? -q * std::fabs(word) : word;
124 ph::Q(lpt + 3), ph::Q(lpt + 4), ph::Q(lpt + 5),
125 ph::Q(lpt + 6), ph::Q(lpt + 7), invP,
128 has_cov ? covariance(lpt, cylindrical) :
CovMatrix6{},
131 auto state = helix.
toTrackState(locationForDetector(det_id));
134 if (!has_cov) state.covMatrix.values.fill(kNotMeasured);
137 lpt += n_words + kCountWord;
141 ctx_.trax = std::move(out);
std::string makeName(std::string_view bank, std::string_view readable) const
static Helix fromTrackElement(double c1, double c2, double c3, double theta, double phi, double invP, bool invPt, bool cylindrical, const CovMatrix6 &teCov, double B)
edm4hep::TrackState toTrackState(int location) const
int lphpa(const char *iddp, int lpa, int nump=0)
std::array< float, 21 > CovMatrix6
constexpr int covOffset(int i, int j)
std::vector< std::vector< edm4hep::TrackState > > pa_to_states