Belle II Software development
HelixHelper.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#pragma once
10
11#include <Math/Functor.h>
12#include <Math/BrentMinimizer1D.h>
13#include <Math/Vector3D.h>
14
15#include <cmath>
16
17namespace Belle2 {
29 constexpr static double c_cTimesB = (1.5 * 0.00299792458);
30 constexpr static double c_maxFlightLength = 150.0;
32 public:
34 HelixHelper(float z0, float d0, float omega, float cotTheta, float phi):
35 m_z0(z0), m_d0(d0), m_omega(omega), m_cotTheta(cotTheta), m_phi(phi),
36 m_poca(d0 * sin(phi), -d0 * cos(phi), z0)
37 { }
38
39
41 HelixHelper(const ROOT::Math::XYZVector& poca, const ROOT::Math::XYZVector& momentum_in_poca, int charge):
42 m_poca(poca)
43 {
44 const double pt = momentum_in_poca.Rho();
45 const double R = pt / c_cTimesB; //c and magnetic field, should come from some common database later...
46
47 const ROOT::Math::XYZVector& dirInPoca = momentum_in_poca.Unit();
48
49 //determine the angle phi, distribute it from -pi to pi
50 m_phi = atan2(dirInPoca.Y(), dirInPoca.X());
51
52 //determine sign of d0
53 //calculate the sign of the projection of pt(dirInPoca) at d0(poca)
54 const double d0Sign = TMath::Sign(1., poca.X() * dirInPoca.X()
55 + poca.Y() * dirInPoca.Y());
56
57 //Now set the helix parameters
58 m_d0 = d0Sign * poca.Rho();
59 m_omega = 1 / R * charge;
60 m_z0 = poca.Z();
61 m_cotTheta = dirInPoca.Z() / dirInPoca.Rho();
62 }
63
68 double pathLengthToPoint(const ROOT::Math::XYZVector& p) const
69 {
71 helix_object = this; //ok, this is ugly
72 //TODO create a functor object to wrap everything up
73
74 ROOT::Math::Functor1D functor(&distanceToPoint);
75 ROOT::Math::BrentMinimizer1D bm;
76 bm.SetFunction(functor, 0.0, c_maxFlightLength);
77 bm.Minimize(100); //#iterations, abs. error, rel. error
78
79 //bm.FValMinimum() is shortest distance
80 //bm.XMinimum() is corresponding path length
81 return bm.XMinimum();
82 }
83
87 double pathLengthToLine(const ROOT::Math::XYZVector& a, const ROOT::Math::XYZVector& b) const
88 {
91
92 helix_object = this; //ok, this is ugly
93 //TODO create a functor object to wrap everything up
94
95 ROOT::Math::Functor1D functor(&distanceToLine);
96 ROOT::Math::BrentMinimizer1D bm;
97 bm.SetFunction(functor, 0.0, c_maxFlightLength);
98 bm.Minimize(100); //#iterations, abs. error, rel. error
99
100 //bm.FValMinimum() is shortest distance
101 //bm.XMinimum() is corresponding path length
102 return bm.XMinimum();
103 }
104
105
109 ROOT::Math::XYZVector momentum(double s = 0) const
110 {
111 const float pt = c_cTimesB / TMath::Abs(m_omega);
112 return ROOT::Math::XYZVector(
113 pt * cos(m_phi - 2 * m_omega * s),
114 pt * sin(m_phi - 2 * m_omega * s),
115 pt * m_cotTheta
116 );
117 }
118
120 ROOT::Math::XYZVector position(double s) const
121 {
122 //approximation (but it does work for straight tracks)
123 return m_poca + ROOT::Math::XYZVector(
124 s * s * m_omega / 2 * sin(m_phi) + s * cos(m_phi),
125 -s * s * m_omega / 2 * cos(m_phi) + s * sin(m_phi),
126 s * m_cotTheta
127 );
128 }
129
130 private:
131 // helix parameters, with same convention as those stored in Track objects
133 float m_z0;
135 float m_d0;
137 float m_omega;
141 float m_phi;
142
144 ROOT::Math::XYZVector m_poca;
145
147 static double distanceToPoint(double s)
148 {
150 }
151
153 static double distanceToLine(double s)
154 {
155 const ROOT::Math::XYZVector& p = helix_object->position(s);
156 // d = |(p-a) \times (p-b)| / |b-a|
159 }
160
162 static ROOT::Math::XYZVector minimize_distance_to_point;
164 static ROOT::Math::XYZVector minimize_distance_to_line_a;
166 static ROOT::Math::XYZVector minimize_distance_to_line_b;
169 };
170
171 ROOT::Math::XYZVector HelixHelper::minimize_distance_to_point(0.0, 0.0, 0.0);
172 ROOT::Math::XYZVector HelixHelper::minimize_distance_to_line_a(0.0, 0.0, 0.0);
173 ROOT::Math::XYZVector HelixHelper::minimize_distance_to_line_b(0.0, 0.0, 0.0);
176}
double R
typedef autogenerated by FFTW
Helper class representing a helical track.
Definition: HelixHelper.h:28
float m_z0
minimal z distance of point of closest approach to origin
Definition: HelixHelper.h:133
double pathLengthToPoint(const ROOT::Math::XYZVector &p) const
returns the path length (along the helix) to the helix point closest to p.
Definition: HelixHelper.h:68
float m_omega
signed curvature
Definition: HelixHelper.h:137
ROOT::Math::XYZVector momentum(double s=0) const
momentum of the particle, at the helix point corresponding to a flown path length s (from poca).
Definition: HelixHelper.h:109
HelixHelper(float z0, float d0, float omega, float cotTheta, float phi)
construct a helix with given helix parameters, as defined for Track objects
Definition: HelixHelper.h:34
float m_phi
Phi at the perigee [-pi, pi].
Definition: HelixHelper.h:141
double pathLengthToLine(const ROOT::Math::XYZVector &a, const ROOT::Math::XYZVector &b) const
returns the path length (along the helix) to the helix point closest to the line going through points...
Definition: HelixHelper.h:87
ROOT::Math::XYZVector position(double s) const
point on helix corresponding to a flown path length s (from poca)
Definition: HelixHelper.h:120
static constexpr double c_cTimesB
magnetic filed times speed of light
Definition: HelixHelper.h:29
HelixHelper(const ROOT::Math::XYZVector &poca, const ROOT::Math::XYZVector &momentum_in_poca, int charge)
construct a helix at an arbitrary position 'poca' (helices built at different points are not comparab...
Definition: HelixHelper.h:41
static double distanceToLine(double s)
same as distanceToPoint, but ignoring z coordinate
Definition: HelixHelper.h:153
float m_cotTheta
cotangens of polar angle
Definition: HelixHelper.h:139
static double distanceToPoint(double s)
minimization function, calculates distance to minimize_distance_to_point
Definition: HelixHelper.h:147
float m_d0
minimal r distance of point of closest approach to origin
Definition: HelixHelper.h:135
ROOT::Math::XYZVector m_poca
point of closest approach to origin
Definition: HelixHelper.h:144
static constexpr double c_maxFlightLength
maximal path length (from origin) considered for extrapolation
Definition: HelixHelper.h:30
static ROOT::Math::XYZVector minimize_distance_to_line_b
second user supplied line we're trying to find the nearest helix point to
Definition: HelixHelper.h:166
static HelixHelper const * helix_object
keep a 'this' pointer around for minimization
Definition: HelixHelper.h:168
static ROOT::Math::XYZVector minimize_distance_to_line_a
first user supplied line we're trying to find the nearest helix point to
Definition: HelixHelper.h:164
static ROOT::Math::XYZVector minimize_distance_to_point
user supplied point we're trying to find the nearest helix point to
Definition: HelixHelper.h:162
Abstract base class for different kinds of events.