Belle II Software development
HelixSwimmer Class Reference

Utility for propagation of a particle along helix. More...

#include <HelixSwimmer.h>

Public Member Functions

 HelixSwimmer ()
 default constructor
 
void set (const ROOT::Math::XYZPoint &position, const ROOT::Math::XYZVector &momentum, double charge, double Bz)
 Sets the helix.
 
void setTransformation (const ROOT::Math::Transform3D &transform)
 Sets transformation from the frame in which helix is constructed (nominal frame) to module local frame.
 
void moveReferencePosition (double length)
 Moves reference position along helix by length.
 
ROOT::Math::XYZPoint getPosition (double length) const
 Returns particle position at given length.
 
ROOT::Math::XYZVector getDirection (double length) const
 Returns particle direction at given length.
 
double getDistanceToPlane (const ROOT::Math::XYZPoint &point, const ROOT::Math::XYZVector &normal) const
 Returns the distance along helix to the nearest intersection with the plane nearly parallel to z axis.
 

Private Member Functions

double shortestDistance (double cosAlpha, double phi) const
 Returns shortest distance.
 
double withinSingleTurn (double t) const
 Returns helix length within a single turn.
 

Private Attributes

double m_R = 0
 helix radius
 
double m_xc = 0
 helix axis position in x
 
double m_yc = 0
 helix axis position in y
 
double m_omega = 0
 angular speed [1/cm]
 
double m_kz = 0
 slope in z
 
double m_phi0 = 0
 phi of reference position
 
double m_z0 = 0
 z of reference position
 
double m_T0 = 0
 helix length of single turn
 
double & x0 = m_xc
 x of reference position for zero magnetic field
 
double & y0 = m_yc
 y of reference position for zero magnetic field
 
double & z0 = m_z0
 z of reference position for zero magnetic field
 
double & kx = m_R
 direction in x for zero magnetic field
 
double & ky = m_phi0
 direction in y for zero magnetic field
 
double & kz = m_kz
 direction in z for zero magnetic field
 
ROOT::Math::Transform3D m_transformInv
 transformation from nominal to local frame
 

Detailed Description

Utility for propagation of a particle along helix.

Helix representation here differs from the official one. Running parameter is the signed distance along helix measured from the reference position. Negative distance means propagating back in time.

Definition at line 30 of file HelixSwimmer.h.

Constructor & Destructor Documentation

◆ HelixSwimmer()

HelixSwimmer ( )
inline

default constructor

Definition at line 37 of file HelixSwimmer.h.

38 {}

Member Function Documentation

◆ getDirection()

XYZVector getDirection ( double  length) const

Returns particle direction at given length.

Parameters
lengthdistance along helix measured from the reference position
Returns
direction (in module local frame if transformation is set)

Definition at line 75 of file HelixSwimmer.cc.

76 {
77 if (m_omega != 0) {
78 double phi = m_phi0 + m_omega * length;
79 double k_T = m_omega * m_R;
80 XYZVector vec(-k_T * sin(phi), k_T * cos(phi), m_kz);
81 return m_transformInv * vec;
82 } else {
83 XYZVector vec(kx, ky, kz);
84 return m_transformInv * vec;
85 }
86 }
double m_phi0
phi of reference position
Definition: HelixSwimmer.h:105
double & kx
direction in x for zero magnetic field
Definition: HelixSwimmer.h:112
ROOT::Math::Transform3D m_transformInv
transformation from nominal to local frame
Definition: HelixSwimmer.h:116
double & ky
direction in y for zero magnetic field
Definition: HelixSwimmer.h:113
double & kz
direction in z for zero magnetic field
Definition: HelixSwimmer.h:114
double m_R
helix radius
Definition: HelixSwimmer.h:100
double m_omega
angular speed [1/cm]
Definition: HelixSwimmer.h:103
double m_kz
slope in z
Definition: HelixSwimmer.h:104

◆ getDistanceToPlane()

double getDistanceToPlane ( const ROOT::Math::XYZPoint &  point,
const ROOT::Math::XYZVector &  normal 
) const

Returns the distance along helix to the nearest intersection with the plane nearly parallel to z axis.

Parameters
pointpoint on the plane
normalplane normal
Returns
signed distance (NaN if cross-section doesn't exist)

Definition at line 88 of file HelixSwimmer.cc.

89 {
90 if (m_omega != 0) {
91 auto r = point - XYZPoint(m_xc, m_yc, m_z0);
92 double phi = normal.Phi();
93 double s = r.Dot(normal);
94 if (std::abs(s) > m_R) return std::numeric_limits<double>::quiet_NaN(); // no solution
95
96 double t = shortestDistance(s / m_R, phi);
97 double v = m_kz * normal.Z();
98 if (v == 0) return t;
99
100 double t_prev = t;
101 double dt_prev = 0;
102 for (int i = 0; i < 100; i++) {
103 double cosAlpha = (s - v * t) / m_R;
104 if (std::abs(cosAlpha) > 1) {
105 return std::numeric_limits<double>::quiet_NaN(); // no solution
106 }
107 t = shortestDistance(cosAlpha, phi);
108 double dt = t - t_prev;
109 if (dt == 0 or (dt + dt_prev) == 0) return t;
110 t_prev = t;
111 dt_prev = dt;
112 }
113 if (std::abs(dt_prev) < 1e-6) {
114 B2DEBUG(20, "TOP::HelixSwimmer::getDistanceToPlane: not converged"
115 << LogVar("v", v) << LogVar("dt", dt_prev));
116 return t;
117 } else {
118 B2DEBUG(20, "TOP::HelixSwimmer::getDistanceToPlane: not converged"
119 << LogVar("v", v) << LogVar("dt", dt_prev));
120 return std::numeric_limits<double>::quiet_NaN();
121 }
122 } else {
123 auto r = point - XYZPoint(x0, y0, z0);
124 auto v = XYZVector(kx, ky, kz);
125 return r.Dot(normal) / v.Dot(normal);
126 }
127 }
double & z0
z of reference position for zero magnetic field
Definition: HelixSwimmer.h:111
double & y0
y of reference position for zero magnetic field
Definition: HelixSwimmer.h:110
double shortestDistance(double cosAlpha, double phi) const
Returns shortest distance.
Definition: HelixSwimmer.h:121
double m_yc
helix axis position in y
Definition: HelixSwimmer.h:102
double m_z0
z of reference position
Definition: HelixSwimmer.h:106
double m_xc
helix axis position in x
Definition: HelixSwimmer.h:101
double & x0
x of reference position for zero magnetic field
Definition: HelixSwimmer.h:109
Class to store variables with their name which were sent to the logging service.

◆ getPosition()

XYZPoint getPosition ( double  length) const

Returns particle position at given length.

Parameters
lengthdistance along helix measured from the reference position
Returns
position (in module local frame if transformation is set)

Definition at line 63 of file HelixSwimmer.cc.

64 {
65 if (m_omega != 0) {
66 double phi = m_phi0 + m_omega * length;
67 XYZPoint vec(m_xc + m_R * cos(phi), m_yc + m_R * sin(phi), m_z0 + m_kz * length);
68 return m_transformInv * vec;
69 } else {
70 XYZPoint vec(x0 + kx * length, y0 + ky * length, z0 + kz * length);
71 return m_transformInv * vec;
72 }
73 }

◆ moveReferencePosition()

void moveReferencePosition ( double  length)

Moves reference position along helix by length.

Parameters
lengthdistance along helix measured from current reference position

Definition at line 51 of file HelixSwimmer.cc.

52 {
53 if (m_omega != 0) {
54 m_phi0 += m_omega * length;
55 m_z0 += m_kz * length;
56 } else {
57 x0 += kx * length;
58 y0 += ky * length;
59 z0 += kz * length;
60 }
61 }

◆ set()

void set ( const ROOT::Math::XYZPoint &  position,
const ROOT::Math::XYZVector &  momentum,
double  charge,
double  Bz 
)

Sets the helix.

Parameters
positionparticle position (= default reference position)
momentumparticle momentum
chargeparticle charge in units of elementary charge
Bzmagnetic field z-component (we assume other two are negligible)

Definition at line 26 of file HelixSwimmer.cc.

27 {
28 double p = momentum.R();
29 double pT = momentum.Rho();
30 double b = -Bz * charge * Const::speedOfLight;
31 if (std::abs(b / Unit::T) > pT) { // helix for R < 100 m
32 m_R = pT / std::abs(b);
33 m_omega = b / p;
34 m_kz = momentum.Z() / p;
35 m_phi0 = momentum.Phi() - copysign(M_PI / 2, m_omega);
36 m_xc = position.X() - m_R * cos(m_phi0);
37 m_yc = position.Y() - m_R * sin(m_phi0);
38 m_z0 = position.Z();
39 m_T0 = 2 * M_PI / std::abs(m_omega);
40 } else { // straight line
41 m_omega = 0; // distinguisher between straight line and helix
42 x0 = position.X();
43 y0 = position.Y();
44 z0 = position.Z();
45 kx = momentum.X() / p;
46 ky = momentum.Y() / p;
47 kz = momentum.Z() / p;
48 }
49 }
static const double speedOfLight
[cm/ns]
Definition: Const.h:695
double m_T0
helix length of single turn
Definition: HelixSwimmer.h:107
static const double T
[tesla]
Definition: Unit.h:120
double charge(int pdgCode)
Returns electric charge of a particle with given pdg code.
Definition: EvtPDLUtil.cc:44

◆ setTransformation()

void setTransformation ( const ROOT::Math::Transform3D &  transform)
inline

Sets transformation from the frame in which helix is constructed (nominal frame) to module local frame.

Parameters
transformtransformation from local to nominal frame

Definition at line 53 of file HelixSwimmer.h.

53{m_transformInv = transform.Inverse();}

◆ shortestDistance()

double shortestDistance ( double  cosAlpha,
double  phi 
) const
inlineprivate

Returns shortest distance.

Parameters
cosAlphacosine of alpha
phiphi of plane
Returns
signed shortest distance

Definition at line 121 of file HelixSwimmer.h.

122 {
123 double alpha = acos(cosAlpha);
124 double t1 = withinSingleTurn((phi - m_phi0 - alpha) / m_omega);
125 double t2 = withinSingleTurn((phi - m_phi0 + alpha) / m_omega);
126 double ta = std::min(t1, t2);
127 double tb = std::max(t1 - m_T0, t2 - m_T0);
128 double t = (std::abs(ta) < std::abs(tb)) ? ta : tb;
129 return t;
130 }
double withinSingleTurn(double t) const
Returns helix length within a single turn.
Definition: HelixSwimmer.h:132

◆ withinSingleTurn()

double withinSingleTurn ( double  t) const
inlineprivate

Returns helix length within a single turn.

Parameters
thelix length
Returns
helix length within single turn

Definition at line 132 of file HelixSwimmer.h.

133 {
134 t = fmod(t, m_T0);
135 if (t < 0) t += m_T0;
136 return t;
137 }

Member Data Documentation

◆ kx

double& kx = m_R
private

direction in x for zero magnetic field

Definition at line 112 of file HelixSwimmer.h.

◆ ky

double& ky = m_phi0
private

direction in y for zero magnetic field

Definition at line 113 of file HelixSwimmer.h.

◆ kz

double& kz = m_kz
private

direction in z for zero magnetic field

Definition at line 114 of file HelixSwimmer.h.

◆ m_kz

double m_kz = 0
private

slope in z

Definition at line 104 of file HelixSwimmer.h.

◆ m_omega

double m_omega = 0
private

angular speed [1/cm]

Definition at line 103 of file HelixSwimmer.h.

◆ m_phi0

double m_phi0 = 0
private

phi of reference position

Definition at line 105 of file HelixSwimmer.h.

◆ m_R

double m_R = 0
private

helix radius

Definition at line 100 of file HelixSwimmer.h.

◆ m_T0

double m_T0 = 0
private

helix length of single turn

Definition at line 107 of file HelixSwimmer.h.

◆ m_transformInv

ROOT::Math::Transform3D m_transformInv
private

transformation from nominal to local frame

Definition at line 116 of file HelixSwimmer.h.

◆ m_xc

double m_xc = 0
private

helix axis position in x

Definition at line 101 of file HelixSwimmer.h.

◆ m_yc

double m_yc = 0
private

helix axis position in y

Definition at line 102 of file HelixSwimmer.h.

◆ m_z0

double m_z0 = 0
private

z of reference position

Definition at line 106 of file HelixSwimmer.h.

◆ x0

double& x0 = m_xc
private

x of reference position for zero magnetic field

Definition at line 109 of file HelixSwimmer.h.

◆ y0

double& y0 = m_yc
private

y of reference position for zero magnetic field

Definition at line 110 of file HelixSwimmer.h.

◆ z0

double& z0 = m_z0
private

z of reference position for zero magnetic field

Definition at line 111 of file HelixSwimmer.h.


The documentation for this class was generated from the following files: