82#include <cdc/simulation/Helix.h>
83#include "CLHEP/Matrix/Matrix.h"
125 if (a_min.num_row() != 5 || a_max.num_row() != 5)
return;
134 const HepSymMatrix& Ea)
135 : m_matrixValid(true),
145 if (
m_a.num_row() == 5 &&
m_Ea.num_row() == 5) {
152 : m_matrixValid(false),
158 m_Ea(HepSymMatrix(5, 0))
161 if (
m_a.num_row() == 5) {
167 const Hep3Vector& momentum,
169 : m_matrixValid(false),
174 m_a(HepVector(5, 0)),
175 m_Ea(HepSymMatrix(5, 0))
183 m_a[2] = charge / perp;
186 m_a[2] = charge * (DBL_MAX);
272 double pt = fabs(
m_pt);
273 double px = - pt * sin(
m_ac[1] + phi);
274 double py = pt * cos(
m_ac[1] + phi);
275 double pz = pt *
m_ac[4];
277 return Hep3Vector(px, py, pz);
294 double pt = fabs(
m_pt);
295 double px = - pt * sin(
m_ac[1] + phi);
296 double py = pt * cos(
m_ac[1] + phi);
297 double pz = pt *
m_ac[4];
302 return Hep3Vector(px, py, pz);
320 double pt = fabs(
m_pt);
321 double px = - pt * sin(
m_ac[1] + phi);
322 double py = pt * cos(
m_ac[1] + phi);
323 double pz = pt *
m_ac[4];
324 double E =
sqrt(pt * pt * (1. +
m_ac[4] *
m_ac[4]) + mass * mass);
326 return HepLorentzVector(px, py, pz,
E);
345 double pt = fabs(
m_pt);
346 double px = - pt * sin(
m_ac[1] + phi);
347 double py = pt * cos(
m_ac[1] + phi);
348 double pz = pt *
m_ac[4];
349 double E =
sqrt(pt * pt * (1. +
m_ac[4] *
m_ac[4]) + mass * mass);
354 return HepLorentzVector(px, py, pz,
E);
361 HepSymMatrix& Emx)
const
375 double pt = fabs(
m_pt);
376 double px = - pt * sin(
m_ac[1] + phi);
377 double py = pt * cos(
m_ac[1] + phi);
378 double pz = pt *
m_ac[4];
379 double E =
sqrt(pt * pt * (1. +
m_ac[4] *
m_ac[4]) + mass * mass);
388 return HepLorentzVector(px, py, pz,
E);
396#if defined(BELLE_DEBUG)
399 const double&
dr =
m_ac[0];
402 const double&
dz =
m_ac[3];
405 double rdr =
dr +
m_r;
407 double csf0 = cos(phi);
408 double snf0 = (1. - csf0) * (1. + csf0);
409 snf0 =
sqrt((snf0 > 0.) ? snf0 : 0.);
410 if (phi > M_PI) snf0 = - snf0;
412 double xc =
m_pivot.x() + rdr * csf0;
413 double yc =
m_pivot.y() + rdr * snf0;
416 csf = (xc - newPivot.x()) /
m_r;
417 snf = (yc - newPivot.y()) /
m_r;
418 double anrm =
sqrt(csf * csf + snf * snf);
422 phi = atan2(snf, csf);
434 if (phid > M_PI) phid = phid -
M_PI2;
435 double drp = (
m_pivot.x() +
dr * csf0 +
m_r * (csf0 - csf) - newPivot.x())
437 + (
m_pivot.y() +
dr * snf0 +
m_r * (snf0 - snf) - newPivot.y()) * snf;
456#if defined(BELLE_DEBUG)
469 const HepSymMatrix& Ea)
483 if (
this == & i)
return *
this;
511#if defined(BELLE_DEBUG)
531 if (
m_ac[2] != 0.0) {
532 if (
m_ac[2] == DBL_MAX ||
m_ac[2] == (-DBL_MAX)) {
550#if defined(BELLE_DEBUG)
560 if (
m_ac[2] != 0.0) {
561 if (
m_ac[2] == DBL_MAX ||
m_ac[2] == (-DBL_MAX)) {
592 HepMatrix dApDA(5, 5, 0);
594 const double&
dr =
m_ac[0];
596 const double& cpa =
m_ac[2];
598 const double& tnl =
m_ac[4];
601 double phi0p = ap[1];
606 double rdr =
m_r +
dr;
608 if ((
m_r + drp) != 0.0) {
609 rdrpr = 1. / (
m_r + drp);
615 double csfd = cos(phi0p -
phi0);
616 double snfd = sin(phi0p -
phi0);
618 if (phid > M_PI) phid = phid -
M_PI2;
621 dApDA[0][1] = rdr * snfd;
623 dApDA[0][2] = (
m_r / cpa) * (1.0 - csfd);
625 dApDA[0][2] = (DBL_MAX);
628 dApDA[1][0] = - rdrpr * snfd;
629 dApDA[1][1] = rdr * rdrpr * csfd;
631 dApDA[1][2] = (
m_r / cpa) * rdrpr * snfd;
633 dApDA[1][2] = (DBL_MAX);
638 dApDA[3][0] =
m_r * rdrpr * tnl * snfd;
639 dApDA[3][1] =
m_r * tnl * (1.0 - rdr * rdrpr * csfd);
641 dApDA[3][2] = (
m_r / cpa) * tnl * (phid -
m_r * rdrpr * snfd);
643 dApDA[3][2] = (DBL_MAX);
646 dApDA[3][4] = -
m_r * phid;
663 HepMatrix dXDA(3, 5, 0);
665 const double&
dr =
m_ac[0];
667 const double& cpa =
m_ac[2];
669 const double& tnl =
m_ac[4];
671 double cosf0phi = cos(
phi0 + phi);
672 double sinf0phi = sin(
phi0 + phi);
677 dXDA[0][2] = - (
m_r / cpa) * (
m_cp - cosf0phi);
679 dXDA[0][2] = (DBL_MAX);
687 dXDA[1][2] = - (
m_r / cpa) * (
m_sp - sinf0phi);
689 dXDA[1][2] = (DBL_MAX);
697 dXDA[2][2] = (
m_r / cpa) * tnl * phi;
699 dXDA[2][2] = (DBL_MAX);
702 dXDA[2][4] = -
m_r * phi;
719 HepMatrix dMDA(3, 5, 0);
722 const double& cpa =
m_ac[2];
723 const double& tnl =
m_ac[4];
725 double cosf0phi = cos(
phi0 + phi);
726 double sinf0phi = sin(
phi0 + phi);
729 if (cpa != 0.)rho = 1. / cpa;
730 else rho = (DBL_MAX);
733 if (cpa < 0.)charge = -1.;
735 dMDA[0][1] = -fabs(rho) * cosf0phi;
736 dMDA[0][2] = charge * rho * rho * sinf0phi;
738 dMDA[1][1] = -fabs(rho) * sinf0phi;
739 dMDA[1][2] = -charge * rho * rho * cosf0phi;
741 dMDA[2][2] = -charge * rho * rho * tnl;
742 dMDA[2][4] = fabs(rho);
759 HepMatrix d4MDA(4, 5, 0);
762 double cpa =
m_ac[2];
763 double tnl =
m_ac[4];
765 double cosf0phi = cos(
phi0 + phi);
766 double sinf0phi = sin(
phi0 + phi);
769 if (cpa != 0.)rho = 1. / cpa;
770 else rho = (DBL_MAX);
773 if (cpa < 0.)charge = -1.;
775 double E =
sqrt(rho * rho * (1. + tnl * tnl) + mass * mass);
777 d4MDA[0][1] = -fabs(rho) * cosf0phi;
778 d4MDA[0][2] = charge * rho * rho * sinf0phi;
780 d4MDA[1][1] = -fabs(rho) * sinf0phi;
781 d4MDA[1][2] = -charge * rho * rho * cosf0phi;
783 d4MDA[2][2] = -charge * rho * rho * tnl;
784 d4MDA[2][4] = fabs(rho);
786 if (cpa != 0.0 &&
E != 0.0) {
787 d4MDA[3][2] = (-1. - tnl * tnl) / (cpa * cpa * cpa *
E);
788 d4MDA[3][4] = tnl / (cpa * cpa *
E);
790 d4MDA[3][2] = (DBL_MAX);
791 d4MDA[3][4] = (DBL_MAX);
808 HepMatrix d4MXDA(7, 5, 0);
810 const double&
dr =
m_ac[0];
812 const double& cpa =
m_ac[2];
814 const double& tnl =
m_ac[4];
816 double cosf0phi = cos(
phi0 + phi);
817 double sinf0phi = sin(
phi0 + phi);
820 if (cpa != 0.)rho = 1. / cpa;
821 else rho = (DBL_MAX);
824 if (cpa < 0.)charge = -1.;
826 double E =
sqrt(rho * rho * (1. + tnl * tnl) + mass * mass);
828 d4MXDA[0][1] = - fabs(rho) * cosf0phi;
829 d4MXDA[0][2] = charge * rho * rho * sinf0phi;
831 d4MXDA[1][1] = - fabs(rho) * sinf0phi;
832 d4MXDA[1][2] = - charge * rho * rho * cosf0phi;
834 d4MXDA[2][2] = - charge * rho * rho * tnl;
835 d4MXDA[2][4] = fabs(rho);
837 if (cpa != 0.0 &&
E != 0.0) {
838 d4MXDA[3][2] = (- 1. - tnl * tnl) / (cpa * cpa * cpa *
E);
839 d4MXDA[3][4] = tnl / (cpa * cpa *
E);
841 d4MXDA[3][2] = (DBL_MAX);
842 d4MXDA[3][4] = (DBL_MAX);
848 d4MXDA[4][2] = - (
m_r / cpa) * (
m_cp - cosf0phi);
850 d4MXDA[4][2] = (DBL_MAX);
856 d4MXDA[5][2] = - (
m_r / cpa) * (
m_sp - sinf0phi);
858 d4MXDA[6][2] = (
m_r / cpa) * tnl * phi;
860 d4MXDA[5][2] = (DBL_MAX);
862 d4MXDA[6][2] = (DBL_MAX);
866 d4MXDA[6][4] = -
m_r * phi;
882 const double dr =
m_a[0];
884 const double cpa =
m_a[2];
885 const double dz =
m_a[3];
886 const double tnl =
m_a[4];
888 std::cout <<
"Helix::dr = " <<
dr <<
" phi0 = " <<
phi0 <<
" cpa = " << cpa
889 <<
" dz = " <<
dz <<
" tnl = " << tnl << std::endl;
890 std::cout <<
" pivot = " <<
m_pivot << std::endl;
899 const double adr = fabs(
m_a[0]);
900 const double acpa = fabs(
m_a[2]);
909 if (
m_a[0] != 0.0 ||
m_a[1] != 0.0 ||
m_a[2] != 0.0 ||
910 m_a[3] != 0.0 ||
m_a[4] != 0.0) {
static bool ms_print_debug
Debug option flag.
void checkValid(void)
Check whether helix parameters is valid or not.
HepMatrix delMDelA(double phi) const
DM/DA.
HepMatrix del4MDelA(double phi, double mass) const
DM4/DA.
void ignoreErrorMatrix(void)
Unsets error matrix.
const HepPoint3D & pivot(void) const
returns pivot position.
HepMatrix delXDelA(double phi) const
DX/DA.
HepPoint3D m_center
Cache of the center position of Helix.
const HepSymMatrix & Ea(void) const
Returns error matrix.
virtual ~Helix()
Destructor.
static bool set_exception(bool)
set exception
HepMatrix del4MXDelA(double phi, double mass) const
DMX4/DA.
void updateCache(void)
updateCache
bool m_matrixValid
True: matrix valid, False: matrix not valid.
double m_ac[5]
Cache of the helix parameter.
double tanl(void) const
Return helix parameter tangent lambda.
bool m_helixValid
True: helix valid, False: helix not valid.
double phi0(void) const
Return helix parameter phi0.
static bool ms_throw_exception
Throw exception flag.
static bool ms_check_range
Check the helix parameter's range.
void set(const HepPoint3D &pivot, const HepVector &a, const HepSymMatrix &Ea)
Sets helix pivot position, parameters, and error matrix.
const HepVector & a(void) const
Returns helix parameters.
double dr(void) const
Return helix parameter dr.
void debugHelix(void) const
Debug Helix.
void debugPrint(void) const
Print the helix parameters to stdout.
static HepVector ms_amin
minimum limit of Helix parameter a
HepMatrix delApDelA(const HepVector &ap) const
DAp/DA.
HepVector m_a
Helix parameter.
double dz(void) const
Return helix parameter dz.
static const double ConstantAlpha
Constant alpha for uniform field.
static HepVector ms_amax
maxiimum limit of Helix parameter a
Hep3Vector momentum(double dPhi=0.) const
returns momentum vector after rotating angle dPhi in phi direction.
static const std::string invalidhelix
String "Invalid Helix".
Helix & operator=(const Helix &)
Copy operator.
HepPoint3D x(double dPhi=0.) const
returns position after rotating angle dPhi in phi direction.
double m_cp
Cache of the cos phi0.
double m_alpha
10000.0/(speed of light)/B.
HepSymMatrix m_Ea
Error of the helix parameter.
double m_sp
Cache of the sin phi0.
double m_bField
Magnetic field, assuming uniform Bz in the unit of kG.
double m_r
Cache of the r.
double kappa(void) const
Return helix parameter kappa.
double m_pt
Cache of the pt.
static void set_limits(const HepVector &a_min, const HepVector &a_max)
set limit for parameter "a"
static bool set_print(bool)
Set print option for debugging.
Helix()
Constructor initializing all perigee parameters to zero.
double sqrt(double a)
sqrt for double
Abstract base class for different kinds of events.