Belle II Software  release-05-02-19
HelixHelper.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2012 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Christian Pulvermacher
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #ifndef HELIXHELPER_H
12 #define HELIXHELPER_H
13 
14 #include <TVector3.h>
15 #include <Math/Functor.h>
16 #include <Math/BrentMinimizer1D.h>
17 
18 #include <cmath>
19 
20 namespace Belle2 {
31  class HelixHelper {
32  constexpr static double c_cTimesB = (1.5 * 0.00299792458);
33  constexpr static double c_maxFlightLength = 150.0;
35  public:
37  HelixHelper(float z0, float d0, float omega, float cotTheta, float phi):
38  m_z0(z0), m_d0(d0), m_omega(omega), m_cotTheta(cotTheta), m_phi(phi),
39  m_poca(d0 * sin(phi), -d0 * cos(phi), z0)
40  { }
41 
42 
44  HelixHelper(const TVector3& poca, const TVector3& momentum_in_poca, int charge):
45  m_poca(poca)
46  {
47  const double pt = momentum_in_poca.Pt();
48  const double R = pt / c_cTimesB; //c and magnetic field, should come from some common database later...
49 
50  const TVector3& dirInPoca = momentum_in_poca.Unit();
51 
52  //determine the angle phi, distribute it from -pi to pi
53  m_phi = atan2(dirInPoca.y() , dirInPoca.x());
54 
55  //determine sign of d0
56  //calculate the sign of the projection of pt(dirInPoca) at d0(poca)
57  const double d0Sign = TMath::Sign(1., poca.x() * dirInPoca.x()
58  + poca.y() * dirInPoca.y());
59 
60  //Now set the helix parameters
61  m_d0 = d0Sign * poca.Perp();
62  m_omega = 1 / R * charge;
63  m_z0 = poca.z();
64  m_cotTheta = dirInPoca.z() / dirInPoca.Pt();
65  }
66 
71  double pathLengthToPoint(const TVector3& p) const
72  {
74  helix_object = this; //ok, this is ugly
75  //TODO create a functor object to wrap everything up
76 
77  ROOT::Math::Functor1D functor(&distanceToPoint);
78  ROOT::Math::BrentMinimizer1D bm;
79  bm.SetFunction(functor, 0.0, c_maxFlightLength);
80  bm.Minimize(100); //#iterations, abs. error, rel. error
81 
82  //bm.FValMinimum() is shortest distance
83  //bm.XMinimum() is corresponding path length
84  return bm.XMinimum();
85  }
86 
90  double pathLengthToLine(const TVector3& a, const TVector3& b) const
91  {
94 
95  helix_object = this; //ok, this is ugly
96  //TODO create a functor object to wrap everything up
97 
98  ROOT::Math::Functor1D functor(&distanceToLine);
99  ROOT::Math::BrentMinimizer1D bm;
100  bm.SetFunction(functor, 0.0, c_maxFlightLength);
101  bm.Minimize(100); //#iterations, abs. error, rel. error
102 
103  //bm.FValMinimum() is shortest distance
104  //bm.XMinimum() is corresponding path length
105  return bm.XMinimum();
106  }
107 
108 
112  TVector3 momentum(double s = 0) const
113  {
114  const float pt = c_cTimesB / TMath::Abs(m_omega);
115  return TVector3(
116  pt * cos(m_phi - 2 * m_omega * s),
117  pt * sin(m_phi - 2 * m_omega * s),
118  pt * m_cotTheta
119  );
120  }
121 
123  TVector3 position(double s) const
124  {
125  //aproximation (but it does work for straight tracks)
126  return m_poca + TVector3(
127  s * s * m_omega / 2 * sin(m_phi) + s * cos(m_phi),
128  -s * s * m_omega / 2 * cos(m_phi) + s * sin(m_phi),
129  s * m_cotTheta
130  );
131  }
132 
133  private:
134  // helix parameters, with same convention as those stored in Track objects
136  float m_z0;
138  float m_d0;
140  float m_omega;
142  float m_cotTheta;
144  float m_phi;
145 
147  TVector3 m_poca;
148 
150  static double distanceToPoint(double s)
151  {
153  }
154 
156  static double distanceToLine(double s)
157  {
158  const TVector3& p = helix_object->position(s);
159  // d = |(p-a) \times (p-b)| / |b-a|
162  }
163 
165  static TVector3 minimize_distance_to_point;
167  static TVector3 minimize_distance_to_line_a;
169  static TVector3 minimize_distance_to_line_b;
171  static HelixHelper const* helix_object;
172  };
173 
174  TVector3 HelixHelper::minimize_distance_to_point(0.0, 0.0, 0.0);
176  TVector3 HelixHelper::minimize_distance_to_line_b(0.0, 0.0, 0.0);
179 }
180 #endif
Belle2::HelixHelper::minimize_distance_to_line_a
static TVector3 minimize_distance_to_line_a
first user supplied line we're trying to find the nearest helix point to
Definition: HelixHelper.h:175
Belle2::HelixHelper::m_d0
float m_d0
minimal r distance of point of closest approach to origin
Definition: HelixHelper.h:146
Belle2::HelixHelper::pathLengthToLine
double pathLengthToLine(const TVector3 &a, const TVector3 &b) const
returns the path length (along the helix) to the helix point closest to the line going through points...
Definition: HelixHelper.h:98
Belle2::HelixHelper::momentum
TVector3 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:120
Belle2::HelixHelper::m_z0
float m_z0
minimal z distance of point of closest approach to origin
Definition: HelixHelper.h:144
Belle2::HelixHelper::HelixHelper
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:45
Belle2::HelixHelper::position
TVector3 position(double s) const
point on helix corresponding to a flown path length s (from poca)
Definition: HelixHelper.h:131
Belle2::HelixHelper
Helper class representing a helical track.
Definition: HelixHelper.h:39
Belle2::HelixHelper::m_omega
float m_omega
signed curvature
Definition: HelixHelper.h:148
Belle2::HelixHelper::distanceToPoint
static double distanceToPoint(double s)
minimization function, calculates distance to minimize_distance_to_point
Definition: HelixHelper.h:158
Belle2::HelixHelper::m_cotTheta
float m_cotTheta
cotangens of polar angle
Definition: HelixHelper.h:150
Belle2::HelixHelper::c_cTimesB
constexpr static double c_cTimesB
magnetic filed times speed of light
Definition: HelixHelper.h:40
Belle2::HelixHelper::minimize_distance_to_point
static TVector3 minimize_distance_to_point
user supplied point we're trying to find the nearest helix point to
Definition: HelixHelper.h:173
Belle2::HelixHelper::minimize_distance_to_line_b
static TVector3 minimize_distance_to_line_b
second user supplied line we're trying to find the nearest helix point to
Definition: HelixHelper.h:177
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::HelixHelper::m_phi
float m_phi
Phi at the perigee [-pi, pi].
Definition: HelixHelper.h:152
Belle2::HelixHelper::distanceToLine
static double distanceToLine(double s)
same as distanceToPoint, but ignoring z coordinate
Definition: HelixHelper.h:164
Belle2::HelixHelper::helix_object
static HelixHelper const * helix_object
keep a 'this' pointer around for minimization
Definition: HelixHelper.h:179
Belle2::HelixHelper::m_poca
TVector3 m_poca
point of closest approach to origin
Definition: HelixHelper.h:155
Belle2::HelixHelper::pathLengthToPoint
double pathLengthToPoint(const TVector3 &p) const
returns the path length (along the helix) to the helix point closest to p.
Definition: HelixHelper.h:79
Belle2::HelixHelper::c_maxFlightLength
constexpr static double c_maxFlightLength
maximal path length (from origin) considered for extrapolation
Definition: HelixHelper.h:41