delphi-edm4hep
DELPHI SDST/FDST -> EDM4hep converter
Loading...
Searching...
No Matches
Helix.h
Go to the documentation of this file.
1// Helix.h — DELPHI ↔ EDM4hep track-parameter conversion (public API).
2//
3// One value type that consolidates what used to be the free functions in
4// BasisConversion.h (TE-basis ↔ helix, omega ↔ momentum) and
5// PerigeeTrack.h (perigee weight-matrix → helix). Construct from a source
6// basis via a named factory (the conversion runs inward); read out the
7// EDM4hep helix params / cov / momentum, or emit an edm4hep::TrackState.
8//
9// The internal canonical basis is the EDM4hep helix
10// (D0, phi, omega, Z0, tanLambda, time) in mm / rad / 1-over-mm, with a
11// 6×6 lower-tri covariance (time row/col always 0). Analysts can use this
12// header standalone to convert without running the converter.
13//
14// omega [1/mm] = transverse curvature with the sign of the charge (EDM4hep).
15// DELPHI signs 1/R and 1/p geometrically: positive is counter-clockwise
16// seen from +z, opposite to the charge in its field. The perigee path sets
17// omega = -invR/10; fromTrackElement sets omega = -kOmega·B·invP, divided
18// by sin(theta) when the word is 1/p rather than 1/p_T (invPt flag).
19//
20// Bank *parsing* (te_bank::decode for the TE descriptor/cov, hpc::padDecode
21// for PXHGET) is a separate concern and feeds the factories here — it is
22// deliberately NOT part of this class.
23
24#pragma once
25
26#include <edm4hep/TrackState.h>
27#include <edm4hep/Vector3f.h>
28
29#include <array>
30
31namespace delphi_edm4hep {
32
33// 6×6 symmetric covariance, lower-triangular storage (21 floats):
34// off = i*(i+1)/2 + j for i >= j.
35// Shared by the TE-basis cov (te_bank::decode) and the helix-basis cov.
36using CovMatrix6 = std::array<float, 21>;
37
38inline constexpr int covOffset(int i, int j) {
39 return (i >= j) ? (i * (i + 1) / 2 + j) : (j * (j + 1) / 2 + i);
40}
41
42// Speed-of-light curvature constant (mm·GeV/T).
43inline constexpr double kOmega = 2.99792458e-4;
44
45// EDM4hep helix parameters.
47 float D0;
48 float phi;
49 float omega;
50 float Z0;
51 float tanLambda;
52 float time;
53};
54
55struct Momentum {
56 double px;
57 double py;
58 double pz;
59 double p; // |p|
60};
61
62class Helix {
63 public:
64 // ---- construct from a source basis (convert inward) --------------------
65
66 // DELPHI perigee at the IP (PA.TRAC / PA.ELTR):
67 // d0, z0 [cm], theta, phi [rad], invR [1/cm, signed].
68 // W = 15-element lower-tri weight matrix (= cov^-1); pass nullptr to
69 // skip cov. valid() is false on degenerate sin(theta) ~ 0.
70 static Helix fromPerigee(float d0, float z0, float theta, float phi,
71 float invR,
72 const std::array<float, 15>* W = nullptr);
73
74 // DELPHI TE / TRAX surface (PA.TE*, PA.TRAX): reference point
75 // (c1, c2, c3) [cm] + direction (theta, phi) [rad] + invP [1/GeV],
76 // TE-basis 6×6 cov and B [T]. invP must be signed geometrically, as
77 // DELPHI writes it (positive = counter-clockwise). D0 = Z0 = 0 at the
78 // reference point by construction.
79 // invPt: true if `invP` is 1/|p_T| (TE descriptor bit 11), false if 1/|p|;
80 // omega is formed accordingly so it equals the transverse curvature.
81 // cylindrical: true when the surface is a cylinder (TE descriptor bit 1),
82 // where the coordinates are stored as (R, R*Phi, z) rather than (x, y, z).
83 // Such an element is confined to its surface, so R is fixed and the
84 // covariance covers only (R*Phi, z): expressed in Cartesian terms its
85 // transverse block is rank one, along the azimuthal direction.
86 static Helix fromTrackElement(double c1, double c2, double c3,
87 double theta, double phi, double invP,
88 bool invPt, bool cylindrical,
89 const CovMatrix6& teCov,
90 double B);
91
92 // Already in the EDM4hep helix basis (no cov).
93 static Helix fromHelix(float D0, float phi, float omega,
94 float Z0, float tanLambda);
95
96 // ---- read out (convert outward) ----------------------------------------
97 bool valid() const { return valid_; }
98 bool hasCov() const { return hasCov_; }
99 const HelixParams& params() const { return p_; }
100 const CovMatrix6& cov() const { return cov_; }
101
102 // omega + direction + (B, q) -> momentum 4-vector.
103 Momentum momentum(double B, int charge) const;
104
105 // Emit an edm4hep::TrackState at the given location (e.g.
106 // edm4hep::TrackState::AtIP / AtOther / AtFirstHit). covMatrix is filled
107 // only when hasCov(); referencePoint comes from the source factory.
108 edm4hep::TrackState toTrackState(int location) const;
109
110 private:
111 Helix() = default;
112
113 HelixParams p_{};
114 CovMatrix6 cov_{};
115 edm4hep::Vector3f refPoint_{0.f, 0.f, 0.f};
116 bool valid_ = true;
117 bool hasCov_ = false;
118};
119
120} // namespace delphi_edm4hep
static Helix fromHelix(float D0, float phi, float omega, float Z0, float tanLambda)
Definition Helix.cpp:228
Momentum momentum(double B, int charge) const
Definition Helix.cpp:235
bool hasCov() const
Definition Helix.h:98
bool valid() const
Definition Helix.h:97
const CovMatrix6 & cov() const
Definition Helix.h:100
static Helix fromTrackElement(double c1, double c2, double c3, double theta, double phi, double invP, bool invPt, bool cylindrical, const CovMatrix6 &teCov, double B)
Definition Helix.cpp:158
static Helix fromPerigee(float d0, float z0, float theta, float phi, float invR, const std::array< float, 15 > *W=nullptr)
Definition Helix.cpp:109
const HelixParams & params() const
Definition Helix.h:99
edm4hep::TrackState toTrackState(int location) const
Definition Helix.cpp:248
std::array< float, 21 > CovMatrix6
Definition Helix.h:36
constexpr double kOmega
Definition Helix.h:43
constexpr int covOffset(int i, int j)
Definition Helix.h:38