15#include "CLHEP/Matrix/Matrix.h"
16#include "GaudiKernel/StatusCode.h"
17#include "GaudiKernel/IInterface.h"
18#include "GaudiKernel/Kernel.h"
19#include "GaudiKernel/Service.h"
20#include "GaudiKernel/ISvcLocator.h"
21#include "GaudiKernel/SvcFactory.h"
22#include "GaudiKernel/IDataProviderSvc.h"
23#include "GaudiKernel/Bootstrap.h"
24#include "GaudiKernel/MsgStream.h"
25#include "GaudiKernel/SmartDataPtr.h"
26#include "GaudiKernel/IMessageSvc.h"
51 StatusCode scmgn = Gaudi::svcLocator()->service(
"MagneticFieldSvc",m_pmgnIMF);
52 if(scmgn!=StatusCode::SUCCESS) {
53 std::cout<<
"Unable to open Magnetic field service"<<std::endl;
57 m_alpha = 10000. / 2.99792458 / m_bField;
71 const HepSymMatrix & Ea)
78 StatusCode scmgn = Gaudi::svcLocator()->service(
"MagneticFieldSvc",m_pmgnIMF);
79 if(scmgn!=StatusCode::SUCCESS) {
80 std::cout<<
"Unable to open Magnetic field service"<<std::endl;
83 m_alpha = 10000. / 2.99792458 / m_bField;
96 m_Ea(HepSymMatrix(5,0)) {
97 StatusCode scmgn = Gaudi::svcLocator()->service(
"MagneticFieldSvc",m_pmgnIMF);
98 if(scmgn!=StatusCode::SUCCESS) {
100 std::cout<<
"Unable to open Magnetic field service"<<std::endl;
103 m_alpha = 10000. / 2.99792458 / m_bField;
116 m_matrixValid(
false),
117 m_Ea(HepSymMatrix(5,0)) {
118 StatusCode scmgn = Gaudi::svcLocator()->service(
"MagneticFieldSvc",m_pmgnIMF);
119 if(scmgn!=StatusCode::SUCCESS) {
121 std::cout<<
"Unable to open Magnetic field service"<<std::endl;
124 m_alpha = 10000. / 2.99792458 / m_bField;
132 m_a[2] = charge / perp;
160 double x = m_pivot.x() + m_ac[0] * m_cp + m_r * (m_cp -
cos(m_ac[1] +phi));
161 double y = m_pivot.y() + m_ac[0] * m_sp + m_r * (m_sp -
sin(m_ac[1] +phi));
162 double z = m_pivot.z() + m_ac[3] - m_r * m_ac[4] * phi;
177 p[0] = m_pivot.x() + m_ac[0] * m_cp + m_r * (m_cp -
cos(m_ac[1] + phi));
178 p[1] = m_pivot.y() + m_ac[0] * m_sp + m_r * (m_sp -
sin(m_ac[1] + phi));
179 p[2] = m_pivot.z() + m_ac[3] - m_r * m_ac[4] * phi;
186 double x = m_pivot.x() + m_ac[0] * m_cp + m_r * (m_cp -
cos(m_ac[1] +phi));
187 double y = m_pivot.y() + m_ac[0] * m_sp + m_r * (m_sp -
sin(m_ac[1] +phi));
188 double z = m_pivot.z() + m_ac[3] - m_r * m_ac[4] * phi;
199 if (m_matrixValid) Ex = m_Ea.similarity(
delXDelA(phi));
217 double pt = fabs(m_pt);
218 double px = -
pt *
sin(m_ac[1] + phi);
219 double py =
pt *
cos(m_ac[1] + phi);
220 double pz =
pt * m_ac[4];
222 return Hep3Vector(px, py, pz);
237 double pt = fabs(m_pt);
238 double px = -
pt *
sin(m_ac[1] + phi);
239 double py =
pt *
cos(m_ac[1] + phi);
240 double pz =
pt * m_ac[4];
242 if (m_matrixValid) Em = m_Ea.similarity(
delMDelA(phi));
245 return Hep3Vector(px, py, pz);
261 double pt = fabs(m_pt);
262 double px = -
pt *
sin(m_ac[1] + phi);
263 double py =
pt *
cos(m_ac[1] + phi);
264 double pz =
pt * m_ac[4];
267 return HepLorentzVector(px, py, pz, E);
284 double pt = fabs(m_pt);
285 double px = -
pt *
sin(m_ac[1] + phi);
286 double py =
pt *
cos(m_ac[1] + phi);
287 double pz =
pt * m_ac[4];
290 if (m_matrixValid) Em = m_Ea.similarity(
del4MDelA(phi,
mass));
293 return HepLorentzVector(px, py, pz, E);
300 HepSymMatrix & Emx)
const {
312 double pt = fabs(m_pt);
313 double px = -
pt *
sin(m_ac[1] + phi);
314 double py =
pt *
cos(m_ac[1] + phi);
315 double pz =
pt * m_ac[4];
316 double E = sqrt(
pt *
pt * (1. + m_ac[4] * m_ac[4]) +
mass *
mass);
318 x.setX(m_pivot.x() + m_ac[0] * m_cp + m_r * (m_cp -
cos(m_ac[1] + phi)));
319 x.setY(m_pivot.y() + m_ac[0] * m_sp + m_r * (m_sp -
sin(m_ac[1] + phi)));
320 x.setZ(m_pivot.z() + m_ac[3] - m_r * m_ac[4] * phi);
325 return HepLorentzVector(px, py, pz, E);
335 const double &
dr = m_ac[0];
336 const double &
phi0 = m_ac[1];
337 const double &
kappa = m_ac[2];
338 const double &
dz = m_ac[3];
339 const double &
tanl = m_ac[4];
341 double rdr =
dr + m_r;
343 double csf0 =
cos(phi);
344 double snf0 = (1. - csf0) * (1. + csf0);
345 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
346 if(phi >
M_PI) snf0 = - snf0;
348 double xc = m_pivot.x() + rdr * csf0;
349 double yc = m_pivot.y() + rdr * snf0;
352 csf = (xc - newPivot.x()) / m_r;
353 snf = (yc - newPivot.y()) / m_r;
354 double anrm = sqrt(csf * csf + snf * snf);
358 phi = atan2(snf, csf);
371 double drp = (m_pivot.x() +
dr * csf0 + m_r * (csf0 - csf) - newPivot.x())
373 + (m_pivot.y() +
dr * snf0 + m_r * (snf0 - snf) - newPivot.y()) * snf;
374 double dzp = m_pivot.z() +
dz - m_r *
tanl * phid - newPivot.z();
384 if (m_matrixValid) m_Ea = m_Ea.similarity(
delApDelA(ap));
397 const HepSymMatrix & Ea) {
401 m_matrixValid =
true;
407 if (
this == & i)
return *
this;
409 m_bField = i.m_bField;
414 m_matrixValid = i.m_matrixValid;
416 m_center = i.m_center;
432 m_bField = i.m_bField;
437 m_matrixValid = i.m_matrixValid;
439 m_center = i.m_center;
453Helix::updateCache(
void) {
471 if (m_ac[2] != 0.0) {
473 m_r = m_alpha / m_ac[2];
480 double x = m_pivot.x() + (m_ac[0] + m_r) * m_cp;
481 double y = m_pivot.y() + (m_ac[0] + m_r) * m_sp;
494 HepMatrix dApDA(5,5,0);
496 const double &
dr = m_ac[0];
497 const double &
phi0 = m_ac[1];
498 const double & cpa = m_ac[2];
499 const double &
dz = m_ac[3];
500 const double & tnl = m_ac[4];
503 double phi0p = ap[1];
508 double rdr = m_r +
dr;
510 if ((m_r + drp) != 0.0) {
511 rdrpr = 1. / (m_r + drp);
517 double csfd =
cos(phi0p -
phi0);
518 double snfd =
sin(phi0p -
phi0);
523 dApDA[0][1] = rdr*snfd;
525 dApDA[0][2] = (m_r/cpa)*( 1.0 - csfd );
530 dApDA[1][0] = - rdrpr*snfd;
531 dApDA[1][1] = rdr*rdrpr*csfd;
533 dApDA[1][2] = (m_r/cpa)*rdrpr*snfd;
540 dApDA[3][0] = m_r*rdrpr*tnl*snfd;
541 dApDA[3][1] = m_r*tnl*(1.0 - rdr*rdrpr*csfd);
543 dApDA[3][2] = (m_r/cpa)*tnl*(phid - m_r*rdrpr*snfd);
548 dApDA[3][4] = - m_r*phid;
563 HepMatrix dXDA(3,5,0);
565 const double &
dr = m_ac[0];
566 const double &
phi0 = m_ac[1];
567 const double & cpa = m_ac[2];
568 const double &
dz = m_ac[3];
569 const double & tnl = m_ac[4];
571 double cosf0phi =
cos(
phi0 + phi);
572 double sinf0phi =
sin(
phi0 + phi);
575 dXDA[0][1] = -
dr * m_sp + m_r * (- m_sp + sinf0phi);
577 dXDA[0][2] = - (m_r / cpa) * (m_cp - cosf0phi);
585 dXDA[1][1] =
dr * m_cp + m_r * (m_cp - cosf0phi);
587 dXDA[1][2] = - (m_r / cpa) * (m_sp - sinf0phi);
597 dXDA[2][2] = (m_r / cpa) * tnl * phi;
602 dXDA[2][4] = - m_r * phi;
617 HepMatrix dMDA(3,5,0);
619 const double &
phi0 = m_ac[1];
620 const double & cpa = m_ac[2];
621 const double & tnl = m_ac[4];
623 double cosf0phi =
cos(
phi0+phi);
624 double sinf0phi =
sin(
phi0+phi);
627 if(cpa != 0.)rho = 1./cpa;
631 if(cpa < 0.)charge = -1.;
633 dMDA[0][1] = -fabs(rho)*cosf0phi;
634 dMDA[0][2] = charge*rho*rho*sinf0phi;
636 dMDA[1][1] = -fabs(rho)*sinf0phi;
637 dMDA[1][2] = -charge*rho*rho*cosf0phi;
639 dMDA[2][2] = -charge*rho*rho*tnl;
640 dMDA[2][4] = fabs(rho);
654 HepMatrix d4MDA(4,5,0);
656 double phi0 = m_ac[1];
657 double cpa = m_ac[2];
658 double tnl = m_ac[4];
660 double cosf0phi =
cos(
phi0+phi);
661 double sinf0phi =
sin(
phi0+phi);
664 if(cpa != 0.)rho = 1./cpa;
668 if(cpa < 0.)charge = -1.;
670 double E = sqrt(rho*rho*(1.+tnl*tnl)+
mass*
mass);
672 d4MDA[0][1] = -fabs(rho)*cosf0phi;
673 d4MDA[0][2] = charge*rho*rho*sinf0phi;
675 d4MDA[1][1] = -fabs(rho)*sinf0phi;
676 d4MDA[1][2] = -charge*rho*rho*cosf0phi;
678 d4MDA[2][2] = -charge*rho*rho*tnl;
679 d4MDA[2][4] = fabs(rho);
681 if (cpa != 0.0 && E != 0.0) {
682 d4MDA[3][2] = (-1.-tnl*tnl)/(cpa*cpa*cpa*E);
683 d4MDA[3][4] = tnl/(cpa*cpa*E);
700 HepMatrix d4MXDA(7,5,0);
702 const double &
dr = m_ac[0];
703 const double &
phi0 = m_ac[1];
704 const double & cpa = m_ac[2];
705 const double &
dz = m_ac[3];
706 const double & tnl = m_ac[4];
708 double cosf0phi =
cos(
phi0+phi);
709 double sinf0phi =
sin(
phi0+phi);
712 if(cpa != 0.)rho = 1./cpa;
716 if(cpa < 0.)charge = -1.;
718 double E = sqrt(rho * rho * (1. + tnl * tnl) +
mass *
mass);
720 d4MXDA[0][1] = - fabs(rho) * cosf0phi;
721 d4MXDA[0][2] = charge * rho * rho * sinf0phi;
723 d4MXDA[1][1] = - fabs(rho) * sinf0phi;
724 d4MXDA[1][2] = - charge * rho * rho * cosf0phi;
726 d4MXDA[2][2] = - charge * rho * rho * tnl;
727 d4MXDA[2][4] = fabs(rho);
729 if (cpa != 0.0 && E != 0.0) {
730 d4MXDA[3][2] = (- 1. - tnl * tnl) / (cpa * cpa * cpa * E);
731 d4MXDA[3][4] = tnl / (cpa * cpa * E);
738 d4MXDA[4][1] = -
dr * m_sp + m_r * (- m_sp + sinf0phi);
740 d4MXDA[4][2] = - (m_r / cpa) * (m_cp - cosf0phi);
746 d4MXDA[5][1] =
dr * m_cp + m_r * (m_cp - cosf0phi);
748 d4MXDA[5][2] = - (m_r / cpa) * (m_sp - sinf0phi);
750 d4MXDA[6][2] = (m_r / cpa) * tnl * phi;
758 d4MXDA[6][4] = - m_r * phi;
765 m_matrixValid =
false;
772 double l =
center().perp();
774 double cosPhi = (m_rad * m_rad + l * l - r * r) / (2 * m_rad * l);
776 if(cosPhi < -1 || cosPhi > 1)
return 0;
804 double dphi =
dPhi(hit);
805 double arcLength = fabs(m_r*dphi);
827 double cosLambda = 1/sqrt(1+m_ac[4]*m_ac[4]);
834 double isClockWise = m_r/fabs(m_r);
835 double x_cw =
center().x()-hit.x();
836 double y_cw =
center().y()-hit.y();
837 x_cw = isClockWise*x_cw;
838 y_cw = isClockWise*y_cw;
839 double phi_cw = atan2(y_cw,x_cw);
840 double dphi = phi_cw-
phi0();
845 while(dphi>0) dphi-=2*
M_PI;
849 while(dphi<0) dphi+=2*
M_PI;
852 double delZ_2pi=2*
M_PI*fabs(m_r)*m_ac[4];
853 double delZ_current=hit.z()-
x(dphi).z();
855 if(delZ_2pi!=0&&fabs(delZ_current)>0.5*fabs(delZ_2pi))
857 double sign=delZ_current/delZ_2pi;
859 n2pi=floor(fabs(delZ_current/delZ_2pi)+0.5);
860 n2pi=-isClockWise*sign*n2pi;
869 double arcLength = m_r*phi_turn;
870 arcLength = fabs(arcLength);
877 double cosLambda = 1/sqrt(1+m_ac[4]*m_ac[4]);
double sin(const BesAngle a)
double cos(const BesAngle a)
**********INTEGER nmxhep !maximum number of particles DOUBLE PRECISION vhep INTEGER jdahep COMMON hepevt $ !serial number $ !number of particles $ !status code $ !particle ident KF $ !parent particles $ !childreen particles $ !four momentum
HepGeom::Point3D< double > HepPoint3D
virtual double getReferField()=0
HepMatrix delApDelA(const HepVector &ap) const
HepMatrix delMDelA(double phi) const
double dPhi(HepPoint3D &hit) const
double flightLength(HepPoint3D &hit) const
const HepPoint3D & center(void) const
returns position of helix center(z = 0.);
void set(const HepPoint3D &pivot, const HepVector &a, const HepSymMatrix &Ea)
sets helix pivot position, parameters, and error matrix.
void ignoreErrorMatrix(void)
unsets error matrix. Error calculations will be ignored after this function call until an error matri...
Helix & operator=(const Helix &)
Copy operator.
HepMatrix del4MXDelA(double phi, double mass) const
Hep3Vector momentum(double dPhi=0.) const
returns momentum vector after rotating angle dPhi in phi direction.
double IntersectCylinder(double r) const
static const double ConstantAlpha
Constant alpha for uniform field.
const HepSymMatrix & Ea(void) const
returns error matrix.
HepPoint3D x(double dPhi=0.) const
returns position after rotating angle dPhi in phi direction.
HepMatrix del4MDelA(double phi, double mass) const
HepMatrix delXDelA(double phi) const
double flightArc(HepPoint3D &hit) const
double radius(void) const
returns radious of helix.
double dr(void) const
returns an element of parameters.
virtual ~Helix()
Destructor.
const HepVector & a(void) const
returns helix parameters.
const HepPoint3D & pivot(void) const
returns pivot position.