Belle II Software  release-05-02-19
Helix.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Y.Ohnishi, Y.Ohnishi, Y.Iwasaki, J.Tanaka *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #ifndef HELIX_H
12 #define HELIX_H
13 
14 #include <string>
15 
16 #include "CLHEP/Matrix/Vector.h"
17 #include "CLHEP/Matrix/SymMatrix.h"
18 #ifndef CLHEP_THREEVECTOR_H
19 #include "CLHEP/Vector/ThreeVector.h"
20 #endif
21 #include "CLHEP/Vector/LorentzVector.h"
22 #ifndef CLHEP_POINT3D_H
23 #include "CLHEP/Geometry/Point3D.h"
24 #endif
25 #ifndef ENABLE_BACKWARDS_COMPATIBILITY
27 #endif
28 using HepGeom::Point3D;
29 
30 typedef CLHEP::HepVector Vector;
31 typedef CLHEP::HepSymMatrix SymMatrix;
32 typedef CLHEP::Hep3Vector Vector3;
33 typedef CLHEP::HepLorentzVector VectorL;
34 typedef CLHEP::HepLorentzVector Vector4;
35 typedef CLHEP::HepMatrix Matrix;
36 
37 using CLHEP::HepVector;
38 using CLHEP::HepSymMatrix;
39 using CLHEP::Hep3Vector;
40 using CLHEP::HepLorentzVector;
41 using CLHEP::HepMatrix;
42 
43 namespace Belle2 {
49  namespace CDC {
51  class Helix {
52 
53  public:
55  Helix(const HepPoint3D& pivot,
56  const HepVector& a,
57  const HepSymMatrix& Ea);
58 
60  Helix(const HepPoint3D& pivot,
61  const HepVector& a);
62 
64  Helix(const HepPoint3D& position,
65  const Hep3Vector& momentum,
66  double charge);
67 
69  virtual ~Helix();
70 
71  public:// Selectors
73  const HepPoint3D& center(void) const;
74 
76  const HepPoint3D& pivot(void) const;
77 
79  double radius(void) const;
80 
90  HepPoint3D x(double dPhi = 0.) const;
91 
101  double* x(double dPhi, double p[3]) const;
102 
104  HepPoint3D x(double dPhi, HepSymMatrix& Ex) const;
105 
107  Hep3Vector direction(double dPhi = 0.) const;
108 
110  Hep3Vector momentum(double dPhi = 0.) const;
111 
113  Hep3Vector momentum(double dPhi, HepSymMatrix& Em) const;
114 
116  HepLorentzVector momentum(double dPhi, double mass) const;
117 
119  HepLorentzVector momentum(double dPhi, double mass, HepSymMatrix& Em) const;
120 
122  HepLorentzVector momentum(double dPhi, double mass, HepPoint3D& x, HepSymMatrix& Emx) const;
123 
124  public:
125 
126  // Parametrization dependent functions.
127  // Prepared for tracking codes.
128  // Users should not use them.
129 
134  double dr(void) const;
135 
139  double phi0(void) const;
140 
144  double kappa(void) const;
145 
149  double dz(void) const;
150 
154  double tanl(void) const;
155 
159  double curv(void) const;
160 
165  double sinPhi0(void) const;
166 
170  double cosPhi0(void) const;
171 
175  const HepVector& a(void) const;
176 
180  const HepSymMatrix& Ea(void) const;
181 
182  public:// Modifiers
184  const HepVector& a(const HepVector& newA);
185 
187  const HepSymMatrix& Ea(const HepSymMatrix& newdA);
188 
190  const HepPoint3D& pivot(const HepPoint3D& newPivot);
191 
193  void set(const HepPoint3D& pivot,
194  const HepVector& a,
195  const HepSymMatrix& Ea);
196 
205  void ignoreErrorMatrix(void);
206 
214  double bFieldZ(double bz);
215 
220  double bFieldZ(void) const;
221 
223  static void set_limits(const HepVector& a_min, const HepVector& a_max);
225  static bool set_exception(bool);
226 
230  static bool set_print(bool);
231 
232  private:
234  static HepVector ms_amin;
236  static HepVector ms_amax;
238  static bool ms_check_range;
240  static bool ms_print_debug;
242  static bool ms_throw_exception;
243 
244  public: // Operators
245 
247  Helix& operator = (const Helix&);
248 
249  public: // Mathmatical functions
250 
252  HepMatrix delApDelA(const HepVector& ap) const;
254  HepMatrix delXDelA(double phi) const;
256  HepMatrix delMDelA(double phi) const;
258  HepMatrix del4MDelA(double phi, double mass) const;
260  HepMatrix del4MXDelA(double phi, double mass) const;
261 
262  private:
266  void updateCache(void);
267 
273  void checkValid(void);
274 
278  void debugPrint(void) const;
279 
283  void debugHelix(void) const;
284  public:
286  static const double ConstantAlpha;
287 
288  private:
289 
295  double m_bField;
297  double m_alpha;
301  HepVector m_a;
303  HepSymMatrix m_Ea;
304 
305  private: // caches
306 
310  double m_cp;
312  double m_sp;
314  double m_pt;
316  double m_r;
318  double m_ac[5];
319 
321  static const std::string invalidhelix;
322 
323  };
324 
325 #if defined(BELLE_DEBUG)
326 #define DEBUG_HELIX debugHelix()
327 #define DEBUG_PRINT debugPrint()
328 #else
329 #define DEBUG_HELIX
330 #define DEBUG_PRINT
331 #endif
332 
333 //-----------------------------------------------------------------------------
334 
335 #ifdef Helix_NO_INLINE
336 #define inline
337 #else
338 #undef inline
339 #define Helix_INLINE_DEFINE_HERE
340 #endif
341 
342 #ifdef Helix_INLINE_DEFINE_HERE
343 
344  inline
345  const HepPoint3D&
346  Helix::center(void) const
347  {
348 #if defined(BELLE_DEBUG)
349  if (!m_helixValid) {
350  DEBUG_PRINT;
351  if (msthrow_exception) throw invalidhelix;
352  }
353 #endif
354  return m_center;
355  }
356 
357  inline
358  const HepPoint3D&
359  Helix::pivot(void) const
360  {
361  DEBUG_HELIX;
362  return m_pivot;
363  }
364 
365  inline
366  double
367  Helix::radius(void) const
368  {
369  DEBUG_HELIX;
370  return m_r;
371  }
372 
373  inline
374  Hep3Vector
375  Helix::direction(double phi) const
376  {
377  DEBUG_HELIX;
378  return momentum(phi).unit();
379  }
380 
381  inline
382  double
383  Helix::dr(void) const
384  {
385  DEBUG_HELIX;
386  return m_ac[0];
387  }
388 
389  inline
390  double
391  Helix::phi0(void) const
392  {
393  DEBUG_HELIX;
394  return m_ac[1];
395  }
396 
397  inline
398  double
399  Helix::kappa(void) const
400  {
401  DEBUG_HELIX;
402  return m_ac[2];
403  }
404 
405  inline
406  double
407  Helix::dz(void) const
408  {
409  DEBUG_HELIX;
410  return m_ac[3];
411  }
412 
413  inline
414  double
415  Helix::tanl(void) const
416  {
417  DEBUG_HELIX;
418  return m_ac[4];
419  }
420 
421  inline
422  double
423  Helix::curv(void) const
424  {
425  DEBUG_HELIX;
426  return m_r;
427  }
428 
429  inline
430  const HepVector&
431  Helix::a(void) const
432  {
433  DEBUG_HELIX;
434  return m_a;
435  }
436 
437  inline
438  const HepSymMatrix&
439  Helix::Ea(void) const
440  {
441  DEBUG_HELIX;
442  return m_Ea;
443  }
444 
445  inline
446  const HepVector&
447  Helix::a(const HepVector& i)
448  {
449  if (i.num_row() == 5) {
450  m_a = i;
451  m_helixValid = false;
452  updateCache();
453 #if defined(BELLE_DEBUG)
454  DEBUG_HELIX;
455  } else {
456  {
457  std::cout << "Helix::input vector's num_row is not 5" << std::endl;
458  DEBUG_PRINT;
459  if (ms_throw_exception) throw invalidhelix;
460  }
461 #endif
462  }
463  return m_a;
464  }
465 
466  inline
467  const HepSymMatrix&
468  Helix::Ea(const HepSymMatrix& i)
469  {
470  DEBUG_HELIX;
471  return m_Ea = i;
472  }
473 
474  inline
475  double
476  Helix::bFieldZ(double a)
477  {
478  DEBUG_HELIX;
479  m_bField = a;
480  m_alpha = 10000. / 2.99792458 / m_bField;
481  updateCache();
482  return m_bField;
483  }
484 
485  inline
486  double
487  Helix::bFieldZ(void) const
488  {
489  DEBUG_HELIX;
490  return m_bField;
491  }
492 
493  inline
494  double
495  Helix::sinPhi0(void) const
496  {
497  DEBUG_HELIX;
498  return m_sp;
499  }
500 
501  inline
502  double
503  Helix::cosPhi0(void) const
504  {
505  DEBUG_HELIX;
506  return m_cp;
507  }
508 
509 #endif
510 
511 #undef inline
512  }
514 } // end of namespace Belle2
515 
516 #endif /* HELIX_H */
Belle2::CDC::Helix::kappa
double kappa(void) const
Return helix parameter kappa.
Definition: Helix.h:399
Belle2::CDC::Helix::del4MXDelA
HepMatrix del4MXDelA(double phi, double mass) const
DMX4/DA.
Definition: Helix.cc:800
Belle2::CDC::Helix::m_cp
double m_cp
Cache of the cos phi0.
Definition: Helix.h:310
Belle2::CDC::Helix::m_ac
double m_ac[5]
Cache of the helix parameter.
Definition: Helix.h:318
Belle2::CDC::Helix::operator=
Helix & operator=(const Helix &)
Copy operator.
Definition: Helix.cc:483
Belle2::CDC::Helix::m_pt
double m_pt
Cache of the pt.
Definition: Helix.h:314
Belle2::CDC::Helix::tanl
double tanl(void) const
Return helix parameter tangent lambda.
Definition: Helix.h:415
Belle2::CDC::Helix::phi0
double phi0(void) const
Return helix parameter phi0.
Definition: Helix.h:391
Belle2::CDC::Helix::ms_amax
static HepVector ms_amax
maxiimum limit of Helix parameter a
Definition: Helix.h:236
Belle2::CDC::Helix::checkValid
void checkValid(void)
Check whether helix parameters is valid or not.
Definition: Helix.cc:897
Belle2::CDC::Helix::m_alpha
double m_alpha
10000.0/(speed of light)/B.
Definition: Helix.h:297
Belle2::CDC::Helix::del4MDelA
HepMatrix del4MDelA(double phi, double mass) const
DM4/DA.
Definition: Helix.cc:751
Belle2::CDC::Helix::curv
double curv(void) const
Return curvature of helix.
Definition: Helix.h:423
Belle2::CDC::Helix::momentum
Hep3Vector momentum(double dPhi=0.) const
returns momentum vector after rotating angle dPhi in phi direction.
Definition: Helix.cc:261
Belle2::CDC::Helix::m_r
double m_r
Cache of the r.
Definition: Helix.h:316
Belle2::CDC::Helix::pivot
const HepPoint3D & pivot(void) const
returns pivot position.
Definition: Helix.h:359
Belle2::CDC::Helix::x
HepPoint3D x(double dPhi=0.) const
returns position after rotating angle dPhi in phi direction.
Definition: Helix.cc:199
Belle2::CDC::Helix::~Helix
virtual ~Helix()
Destructor.
Definition: Helix.cc:194
Belle2::CDC::Helix::ms_throw_exception
static bool ms_throw_exception
Throw exception flag.
Definition: Helix.h:242
Belle2::CDC::Helix::debugHelix
void debugHelix(void) const
Debug Helix.
Definition: Helix.cc:919
Belle2::CDC::Helix::set_limits
static void set_limits(const HepVector &a_min, const HepVector &a_max)
set limit for parameter "a"
Definition: Helix.cc:125
Belle2::CDC::Helix::m_center
HepPoint3D m_center
Cache of the center position of Helix.
Definition: Helix.h:308
Belle2::CDC::Helix::ms_check_range
static bool ms_check_range
Check the helix parameter's range.
Definition: Helix.h:238
Belle2::CDC::Helix::ms_print_debug
static bool ms_print_debug
Debug option flag.
Definition: Helix.h:240
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::CDC::Helix::m_bField
double m_bField
Magnetic field, assuming uniform Bz in the unit of kG.
Definition: Helix.h:295
Belle2::CDC::Helix::delMDelA
HepMatrix delMDelA(double phi) const
DM/DA.
Definition: Helix.cc:712
Belle2::CDC::Helix::delApDelA
HepMatrix delApDelA(const HepVector &ap) const
DAp/DA.
Definition: Helix.cc:586
Belle2::CDC::Helix::radius
double radius(void) const
returns radious of helix.
Definition: Helix.h:367
Belle2::CDC::Helix::m_sp
double m_sp
Cache of the sin phi0.
Definition: Helix.h:312
Belle2::CDC::Helix::debugPrint
void debugPrint(void) const
Print the helix parameters to stdout.
Definition: Helix.cc:881
Belle2::CDC::Helix::invalidhelix
static const std::string invalidhelix
String "Invalid Helix".
Definition: Helix.h:321
Belle2::CDC::Helix::dz
double dz(void) const
Return helix parameter dz.
Definition: Helix.h:407
Belle2::CDC::Helix::m_helixValid
bool m_helixValid
True: helix valid, False: helix not valid.
Definition: Helix.h:293
Belle2::CDC::Helix::direction
Hep3Vector direction(double dPhi=0.) const
returns direction vector after rotating angle dPhi in phi direction.
Definition: Helix.h:375
Belle2::CDC::Helix::ConstantAlpha
static const double ConstantAlpha
Constant alpha for uniform field.
Definition: Helix.h:286
Belle2::CDC::Helix
Helix parameter class.
Definition: Helix.h:51
Belle2::CDC::Helix::set_print
static bool set_print(bool)
Set print option for debugging.
Definition: Helix.cc:119
Belle2::CDC::Helix::a
const HepVector & a(void) const
Returns helix parameters.
Definition: Helix.h:431
Belle2::CDC::Helix::delXDelA
HepMatrix delXDelA(double phi) const
DX/DA.
Definition: Helix.cc:656
Belle2::CDC::Helix::updateCache
void updateCache(void)
updateCache
Definition: Helix.cc:510
Belle2::CDC::Helix::m_pivot
HepPoint3D m_pivot
Pivot.
Definition: Helix.h:299
HepGeom::Point3D< double >
Belle2::CDC::Helix::bFieldZ
double bFieldZ(void) const
Returns z componet of the magnetic field.
Definition: Helix.h:487
Belle2::CDC::Helix::m_Ea
HepSymMatrix m_Ea
Error of the helix parameter.
Definition: Helix.h:303
Belle2::CDC::Helix::center
const HepPoint3D & center(void) const
returns position of helix center(z = 0.);
Definition: Helix.h:346
Belle2::CDC::Helix::ms_amin
static HepVector ms_amin
minimum limit of Helix parameter a
Definition: Helix.h:234
Belle2::CDC::Helix::m_matrixValid
bool m_matrixValid
True: matrix valid, False: matrix not valid.
Definition: Helix.h:291
Belle2::CDC::Helix::sinPhi0
double sinPhi0(void) const
Return sin phi0.
Definition: Helix.h:495
Belle2::Point3D
HepGeom::Point3D< double > Point3D
3D point
Definition: Cell.h:33
Belle2::CDC::Helix::set_exception
static bool set_exception(bool)
set exception
Definition: Helix.cc:114
Belle2::CDC::Helix::m_a
HepVector m_a
Helix parameter.
Definition: Helix.h:301
Belle2::CDC::Helix::Ea
const HepSymMatrix & Ea(void) const
Returns error matrix.
Definition: Helix.h:439
Belle2::CDC::Helix::set
void set(const HepPoint3D &pivot, const HepVector &a, const HepSymMatrix &Ea)
Sets helix pivot position, parameters, and error matrix.
Definition: Helix.cc:469
Belle2::CDC::Helix::Helix
Helix(const HepPoint3D &pivot, const HepVector &a, const HepSymMatrix &Ea)
Constructor with pivot, helix parameter a, and its error matrix.
Definition: Helix.cc:134
Belle2::CDC::Helix::ignoreErrorMatrix
void ignoreErrorMatrix(void)
Unsets error matrix.
Definition: Helix.cc:874
Belle2::CDC::Helix::cosPhi0
double cosPhi0(void) const
Return cos phi0.
Definition: Helix.h:503
Belle2::CDC::Helix::dr
double dr(void) const
Return helix parameter dr.
Definition: Helix.h:383