Belle II Software development
Helix.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 <string>
12
13#include "CLHEP/Matrix/Vector.h"
14#include "CLHEP/Matrix/SymMatrix.h"
15#ifndef CLHEP_THREEVECTOR_H
16#include "CLHEP/Vector/ThreeVector.h"
17#endif
18#include "CLHEP/Vector/LorentzVector.h"
19#ifndef CLHEP_POINT3D_H
20#include "CLHEP/Geometry/Point3D.h"
21#endif
22#ifndef ENABLE_BACKWARDS_COMPATIBILITY
24#endif
26
27typedef CLHEP::HepVector Vector;
28typedef CLHEP::HepSymMatrix SymMatrix;
29typedef CLHEP::Hep3Vector Vector3;
30typedef CLHEP::HepLorentzVector VectorL;
31typedef CLHEP::HepLorentzVector Vector4;
32typedef CLHEP::HepMatrix Matrix;
33
34using CLHEP::HepVector;
35using CLHEP::HepSymMatrix;
36using CLHEP::Hep3Vector;
37using CLHEP::HepLorentzVector;
38using CLHEP::HepMatrix;
39
40namespace Belle2 {
46 namespace CDC {
48 class Helix {
49
50 public:
52 Helix(const HepPoint3D& pivot,
53 const HepVector& a,
54 const HepSymMatrix& Ea);
55
57 Helix(const HepPoint3D& pivot,
58 const HepVector& a);
59
61 Helix(const HepPoint3D& position,
62 const Hep3Vector& momentum,
63 double charge);
64
66 virtual ~Helix();
67
68 public:// Selectors
70 const HepPoint3D& center(void) const;
71
73 const HepPoint3D& pivot(void) const;
74
76 double radius(void) const;
77
87 HepPoint3D x(double dPhi = 0.) const;
88
98 double* x(double dPhi, double p[3]) const;
99
101 HepPoint3D x(double dPhi, HepSymMatrix& Ex) const;
102
104 Hep3Vector direction(double dPhi = 0.) const;
105
107 Hep3Vector momentum(double dPhi = 0.) const;
108
110 Hep3Vector momentum(double dPhi, HepSymMatrix& Em) const;
111
113 HepLorentzVector momentum(double dPhi, double mass) const;
114
116 HepLorentzVector momentum(double dPhi, double mass, HepSymMatrix& Em) const;
117
119 HepLorentzVector momentum(double dPhi, double mass, HepPoint3D& x, HepSymMatrix& Emx) const;
120
121 public:
122
123 // Parametrization dependent functions.
124 // Prepared for tracking codes.
125 // Users should not use them.
126
131 double dr(void) const;
132
136 double phi0(void) const;
137
141 double kappa(void) const;
142
146 double dz(void) const;
147
151 double tanl(void) const;
152
156 double curv(void) const;
157
162 double sinPhi0(void) const;
163
167 double cosPhi0(void) const;
168
172 const HepVector& a(void) const;
173
177 const HepSymMatrix& Ea(void) const;
178
179 public:// Modifiers
181 const HepVector& a(const HepVector& newA);
182
184 const HepSymMatrix& Ea(const HepSymMatrix& newdA);
185
187 const HepPoint3D& pivot(const HepPoint3D& newPivot);
188
190 void set(const HepPoint3D& pivot,
191 const HepVector& a,
192 const HepSymMatrix& Ea);
193
202 void ignoreErrorMatrix(void);
203
211 double bFieldZ(double bz);
212
217 double bFieldZ(void) const;
218
220 static void set_limits(const HepVector& a_min, const HepVector& a_max);
222 static bool set_exception(bool);
223
227 static bool set_print(bool);
228
229 private:
231 static HepVector ms_amin;
233 static HepVector ms_amax;
235 static bool ms_check_range;
237 static bool ms_print_debug;
240
241 public: // Operators
242
244 Helix& operator = (const Helix&);
245
246 public: // Mathmatical functions
247
249 HepMatrix delApDelA(const HepVector& ap) const;
251 HepMatrix delXDelA(double phi) const;
253 HepMatrix delMDelA(double phi) const;
255 HepMatrix del4MDelA(double phi, double mass) const;
257 HepMatrix del4MXDelA(double phi, double mass) const;
258
259 private:
263 void updateCache(void);
264
270 void checkValid(void);
271
275 void debugPrint(void) const;
276
280 void debugHelix(void) const;
281 public:
283 static const double ConstantAlpha;
284
285 private:
286
292 double m_bField;
294 double m_alpha;
298 HepVector m_a;
300 HepSymMatrix m_Ea;
301
302 private: // caches
303
307 double m_cp;
309 double m_sp;
311 double m_pt;
313 double m_r;
315 double m_ac[5];
316
318 static const std::string invalidhelix;
319
320 };
321
322#if defined(BELLE_DEBUG)
323#define DEBUG_HELIX debugHelix()
324#define DEBUG_PRINT debugPrint()
325#else
326#define DEBUG_HELIX
327#define DEBUG_PRINT
328#endif
329
330//-----------------------------------------------------------------------------
331
332#ifdef Helix_NO_INLINE
333#define inline
334#else
335#undef inline
336#define Helix_INLINE_DEFINE_HERE
337#endif
338
339#ifdef Helix_INLINE_DEFINE_HERE
340
341 inline
342 const HepPoint3D&
343 Helix::center(void) const
344 {
345#if defined(BELLE_DEBUG)
346 if (!m_helixValid) {
347 DEBUG_PRINT;
348 if (msthrow_exception) throw invalidhelix;
349 }
350#endif
351 return m_center;
352 }
353
354 inline
355 const HepPoint3D&
356 Helix::pivot(void) const
357 {
358 DEBUG_HELIX;
359 return m_pivot;
360 }
361
362 inline
363 double
364 Helix::radius(void) const
365 {
366 DEBUG_HELIX;
367 return m_r;
368 }
369
370 inline
371 Hep3Vector
372 Helix::direction(double phi) const
373 {
374 DEBUG_HELIX;
375 return momentum(phi).unit();
376 }
377
378 inline
379 double
380 Helix::dr(void) const
381 {
382 DEBUG_HELIX;
383 return m_ac[0];
384 }
385
386 inline
387 double
388 Helix::phi0(void) const
389 {
390 DEBUG_HELIX;
391 return m_ac[1];
392 }
393
394 inline
395 double
396 Helix::kappa(void) const
397 {
398 DEBUG_HELIX;
399 return m_ac[2];
400 }
401
402 inline
403 double
404 Helix::dz(void) const
405 {
406 DEBUG_HELIX;
407 return m_ac[3];
408 }
409
410 inline
411 double
412 Helix::tanl(void) const
413 {
414 DEBUG_HELIX;
415 return m_ac[4];
416 }
417
418 inline
419 double
420 Helix::curv(void) const
421 {
422 DEBUG_HELIX;
423 return m_r;
424 }
425
426 inline
427 const HepVector&
428 Helix::a(void) const
429 {
430 DEBUG_HELIX;
431 return m_a;
432 }
433
434 inline
435 const HepSymMatrix&
436 Helix::Ea(void) const
437 {
438 DEBUG_HELIX;
439 return m_Ea;
440 }
441
442 inline
443 const HepVector&
444 Helix::a(const HepVector& i)
445 {
446 if (i.num_row() == 5) {
447 m_a = i;
448 m_helixValid = false;
449 updateCache();
450#if defined(BELLE_DEBUG)
451 DEBUG_HELIX;
452 } else {
453 {
454 std::cout << "Helix::input vector's num_row is not 5" << std::endl;
455 DEBUG_PRINT;
457 }
458#endif
459 }
460 return m_a;
461 }
462
463 inline
464 const HepSymMatrix&
465 Helix::Ea(const HepSymMatrix& i)
466 {
467 DEBUG_HELIX;
468 return m_Ea = i;
469 }
470
471 inline
472 double
474 {
475 DEBUG_HELIX;
476 m_bField = a;
477 m_alpha = 10000. / 2.99792458 / m_bField;
478 updateCache();
479 return m_bField;
480 }
481
482 inline
483 double
484 Helix::bFieldZ(void) const
485 {
486 DEBUG_HELIX;
487 return m_bField;
488 }
489
490 inline
491 double
492 Helix::sinPhi0(void) const
493 {
494 DEBUG_HELIX;
495 return m_sp;
496 }
497
498 inline
499 double
500 Helix::cosPhi0(void) const
501 {
502 DEBUG_HELIX;
503 return m_cp;
504 }
505
506#endif
507
508#undef inline
509 }
511} // end of namespace Belle2
Helix parameter class.
Definition: Helix.h:48
static bool ms_print_debug
Debug option flag.
Definition: Helix.h:237
void checkValid(void)
Check whether helix parameters is valid or not.
Definition: Helix.cc:895
HepMatrix delMDelA(double phi) const
DM/DA.
Definition: Helix.cc:710
HepMatrix del4MDelA(double phi, double mass) const
DM4/DA.
Definition: Helix.cc:749
void ignoreErrorMatrix(void)
Unsets error matrix.
Definition: Helix.cc:872
const HepPoint3D & pivot(void) const
returns pivot position.
Definition: Helix.h:356
HepMatrix delXDelA(double phi) const
DX/DA.
Definition: Helix.cc:654
HepPoint3D m_center
Cache of the center position of Helix.
Definition: Helix.h:305
const HepSymMatrix & Ea(void) const
Returns error matrix.
Definition: Helix.h:436
virtual ~Helix()
Destructor.
Definition: Helix.cc:192
const HepPoint3D & center(void) const
returns position of helix center(z = 0.);
Definition: Helix.h:343
static bool set_exception(bool)
set exception
Definition: Helix.cc:112
HepMatrix del4MXDelA(double phi, double mass) const
DMX4/DA.
Definition: Helix.cc:798
void updateCache(void)
updateCache
Definition: Helix.cc:508
bool m_matrixValid
True: matrix valid, False: matrix not valid.
Definition: Helix.h:288
double m_ac[5]
Cache of the helix parameter.
Definition: Helix.h:315
double tanl(void) const
Return helix parameter tangent lambda.
Definition: Helix.h:412
bool m_helixValid
True: helix valid, False: helix not valid.
Definition: Helix.h:290
Hep3Vector direction(double dPhi=0.) const
returns direction vector after rotating angle dPhi in phi direction.
Definition: Helix.h:372
double phi0(void) const
Return helix parameter phi0.
Definition: Helix.h:388
double radius(void) const
returns radious of helix.
Definition: Helix.h:364
static bool ms_throw_exception
Throw exception flag.
Definition: Helix.h:239
static bool ms_check_range
Check the helix parameter's range.
Definition: Helix.h:235
void set(const HepPoint3D &pivot, const HepVector &a, const HepSymMatrix &Ea)
Sets helix pivot position, parameters, and error matrix.
Definition: Helix.cc:467
const HepVector & a(void) const
Returns helix parameters.
Definition: Helix.h:428
double dr(void) const
Return helix parameter dr.
Definition: Helix.h:380
void debugHelix(void) const
Debug Helix.
Definition: Helix.cc:917
void debugPrint(void) const
Print the helix parameters to stdout.
Definition: Helix.cc:879
static HepVector ms_amin
minimum limit of Helix parameter a
Definition: Helix.h:231
HepMatrix delApDelA(const HepVector &ap) const
DAp/DA.
Definition: Helix.cc:584
HepVector m_a
Helix parameter.
Definition: Helix.h:298
double dz(void) const
Return helix parameter dz.
Definition: Helix.h:404
static const double ConstantAlpha
Constant alpha for uniform field.
Definition: Helix.h:283
double bFieldZ(void) const
Returns z componet of the magnetic field.
Definition: Helix.h:484
static HepVector ms_amax
maxiimum limit of Helix parameter a
Definition: Helix.h:233
Hep3Vector momentum(double dPhi=0.) const
returns momentum vector after rotating angle dPhi in phi direction.
Definition: Helix.cc:259
static const std::string invalidhelix
String "Invalid Helix".
Definition: Helix.h:318
Helix & operator=(const Helix &)
Copy operator.
Definition: Helix.cc:481
HepPoint3D x(double dPhi=0.) const
returns position after rotating angle dPhi in phi direction.
Definition: Helix.cc:197
double m_cp
Cache of the cos phi0.
Definition: Helix.h:307
double m_alpha
10000.0/(speed of light)/B.
Definition: Helix.h:294
HepSymMatrix m_Ea
Error of the helix parameter.
Definition: Helix.h:300
double m_sp
Cache of the sin phi0.
Definition: Helix.h:309
HepPoint3D m_pivot
Pivot.
Definition: Helix.h:296
double m_bField
Magnetic field, assuming uniform Bz in the unit of kG.
Definition: Helix.h:292
double m_r
Cache of the r.
Definition: Helix.h:313
double cosPhi0(void) const
Return cos phi0.
Definition: Helix.h:500
double kappa(void) const
Return helix parameter kappa.
Definition: Helix.h:396
double curv(void) const
Return curvature of helix.
Definition: Helix.h:420
double m_pt
Cache of the pt.
Definition: Helix.h:311
static void set_limits(const HepVector &a_min, const HepVector &a_max)
set limit for parameter "a"
Definition: Helix.cc:123
static bool set_print(bool)
Set print option for debugging.
Definition: Helix.cc:117
double sinPhi0(void) const
Return sin phi0.
Definition: Helix.h:492
Abstract base class for different kinds of events.