17#include "CLHEP/Matrix/Matrix.h"
18#include "GaudiKernel/StatusCode.h"
19#include "GaudiKernel/IInterface.h"
20#include "GaudiKernel/Kernel.h"
21#include "GaudiKernel/Service.h"
22#include "GaudiKernel/ISvcLocator.h"
23#include "GaudiKernel/SvcFactory.h"
24#include "GaudiKernel/IDataProviderSvc.h"
25#include "GaudiKernel/Bootstrap.h"
26#include "GaudiKernel/MsgStream.h"
27#include "GaudiKernel/SmartDataPtr.h"
28#include "GaudiKernel/IMessageSvc.h"
45const double Helix::ConstantAlpha = 333.564095;
50 StatusCode scmgn = Gaudi::svcLocator()->service(
"MagneticFieldSvc",
m_pmgnIMF);
51 if(scmgn!=StatusCode::SUCCESS) {
52 std::cout<<
"Unable to open Magnetic field service"<<std::endl;
69 const HepSymMatrix & Ea)
76 StatusCode scmgn = Gaudi::svcLocator()->service(
"MagneticFieldSvc",
m_pmgnIMF);
77 if(scmgn!=StatusCode::SUCCESS) {
78 std::cout<<
"Unable to open Magnetic field service"<<std::endl;
95 m_Ea(HepSymMatrix(5,0)) {
96 StatusCode scmgn = Gaudi::svcLocator()->service(
"MagneticFieldSvc",
m_pmgnIMF);
97 if(scmgn!=StatusCode::SUCCESS) {
99 std::cout<<
"Unable to open Magnetic field service"<<std::endl;
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;
133 m_a[2] = charge / perp;
161 double x = m_pivot.x() + m_ac[0] * m_cp + m_r * (m_cp -
cos(m_ac[1] +phi));
162 double y = m_pivot.y() + m_ac[0] * m_sp + m_r * (m_sp -
sin(m_ac[1] +phi));
163 double z = m_pivot.z() + m_ac[3] - m_r * m_ac[4] * phi;
178 p[0] = m_pivot.x() + m_ac[0] * m_cp + m_r * (m_cp -
cos(m_ac[1] + phi));
179 p[1] = m_pivot.y() + m_ac[0] * m_sp + m_r * (m_sp -
sin(m_ac[1] + phi));
180 p[2] = m_pivot.z() + m_ac[3] - m_r * m_ac[4] * phi;
187 double x = m_pivot.x() + m_ac[0] * m_cp + m_r * (m_cp -
cos(m_ac[1] +phi));
188 double y = m_pivot.y() + m_ac[0] * m_sp + m_r * (m_sp -
sin(m_ac[1] +phi));
189 double z = m_pivot.z() + m_ac[3] - m_r * m_ac[4] * phi;
200 if (m_matrixValid) Ex = m_Ea.similarity(
delXDelA(phi));
219 double px = - pt *
sin(m_ac[1] + phi);
220 double py = pt *
cos(m_ac[1] + phi);
221 double pz = pt * m_ac[4];
223 return Hep3Vector(px, py, pz);
239 double px = - pt *
sin(m_ac[1] + phi);
240 double py = pt *
cos(m_ac[1] + phi);
241 double pz = pt * m_ac[4];
243 if (m_matrixValid) Em = m_Ea.similarity(
delMDelA(phi));
246 return Hep3Vector(px, py, pz);
263 double px = - pt *
sin(m_ac[1] + phi);
264 double py = pt *
cos(m_ac[1] + phi);
265 double pz = pt * m_ac[4];
266 double E = sqrt(pt*pt*(1.+m_ac[4]*m_ac[4])+
mass*
mass);
268 return HepLorentzVector(px, py, pz, E);
286 double px = - pt *
sin(m_ac[1] + phi);
287 double py = pt *
cos(m_ac[1] + phi);
288 double pz = pt * m_ac[4];
289 double E = sqrt(pt*pt*(1.+m_ac[4]*m_ac[4])+
mass*
mass);
291 if (m_matrixValid) Em = m_Ea.similarity(
del4MDelA(phi,
mass));
294 return HepLorentzVector(px, py, pz, E);
301 HepSymMatrix & Emx)
const {
314 double px = - pt *
sin(m_ac[1] + phi);
315 double py = pt *
cos(m_ac[1] + phi);
316 double pz = pt * m_ac[4];
317 double E = sqrt(pt * pt * (1. + m_ac[4] * m_ac[4]) +
mass *
mass);
319 x.setX(m_pivot.x() + m_ac[0] * m_cp + m_r * (m_cp -
cos(m_ac[1] + phi)));
320 x.setY(m_pivot.y() + m_ac[0] * m_sp + m_r * (m_sp -
sin(m_ac[1] + phi)));
321 x.setZ(m_pivot.z() + m_ac[3] - m_r * m_ac[4] * phi);
326 return HepLorentzVector(px, py, pz, E);
332 const double &
dr = m_ac[0];
333 const double &
phi0 = m_ac[1];
334 const double &
kappa = m_ac[2];
335 const double &
dz = m_ac[3];
336 const double &
tanl = m_ac[4];
338 double rdr = dr + m_r;
340 double csf0 =
cos(phi);
341 double snf0 = (1. - csf0) * (1. + csf0);
342 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
343 if(phi >
M_PI) snf0 = - snf0;
345 double xc = m_pivot.x() + rdr * csf0;
346 double yc = m_pivot.y() + rdr * snf0;
349 csf = (xc - newPivot.x()) / m_r;
350 snf = (yc - newPivot.y()) / m_r;
351 double anrm = sqrt(csf * csf + snf * snf);
355 phi = atan2(snf, csf);
366 double phid = fmod(phi - phi0 +
M_PI8,
M_PI2);
368 double drp = (m_pivot.x() + dr * csf0 + m_r * (csf0 - csf) - newPivot.x())
370 + (m_pivot.y() + dr * snf0 + m_r * (snf0 - snf) - newPivot.y()) * snf;
371 double dzp = m_pivot.z() + dz - m_r * tanl * phid - newPivot.z();
381 if (m_matrixValid) m_Ea = m_Ea.similarity(
delApDelA(ap));
394 const HepSymMatrix & Ea) {
398 m_matrixValid =
true;
403Helix::operator = (
const Helix & i) {
404 if (
this == & i)
return *
this;
411 m_matrixValid = i.m_matrixValid;
413 m_center = i.m_center;
434 m_matrixValid = i.m_matrixValid;
436 m_center = i.m_center;
450Helix::updateCache(
void) {
466 if (m_ac[2] != 0.0) {
468 m_r = m_alpha / m_ac[2];
475 double x = m_pivot.x() + (m_ac[0] + m_r) * m_cp;
476 double y = m_pivot.y() + (m_ac[0] + m_r) * m_sp;
489 HepMatrix dApDA(5,5,0);
491 const double &
dr = m_ac[0];
492 const double &
phi0 = m_ac[1];
493 const double & cpa = m_ac[2];
495 const double & tnl = m_ac[4];
498 double phi0p = ap[1];
503 double rdr = m_r + dr;
505 if ((m_r + drp) != 0.0) {
506 rdrpr = 1. / (m_r + drp);
512 double csfd =
cos(phi0p - phi0);
513 double snfd =
sin(phi0p - phi0);
514 double phid = fmod(phi0p - phi0 +
M_PI8,
M_PI2);
518 dApDA[0][1] = rdr*snfd;
520 dApDA[0][2] = (m_r/cpa)*( 1.0 - csfd );
525 dApDA[1][0] = - rdrpr*snfd;
526 dApDA[1][1] = rdr*rdrpr*csfd;
528 dApDA[1][2] = (m_r/cpa)*rdrpr*snfd;
535 dApDA[3][0] = m_r*rdrpr*tnl*snfd;
536 dApDA[3][1] = m_r*tnl*(1.0 - rdr*rdrpr*csfd);
538 dApDA[3][2] = (m_r/cpa)*tnl*(phid - m_r*rdrpr*snfd);
543 dApDA[3][4] = - m_r*phid;
558 HepMatrix dXDA(3,5,0);
560 const double &
dr = m_ac[0];
561 const double &
phi0 = m_ac[1];
562 const double & cpa = m_ac[2];
564 const double & tnl = m_ac[4];
566 double cosf0phi =
cos(phi0 + phi);
567 double sinf0phi =
sin(phi0 + phi);
570 dXDA[0][1] = - dr * m_sp + m_r * (- m_sp + sinf0phi);
572 dXDA[0][2] = - (m_r / cpa) * (m_cp - cosf0phi);
580 dXDA[1][1] = dr * m_cp + m_r * (m_cp - cosf0phi);
582 dXDA[1][2] = - (m_r / cpa) * (m_sp - sinf0phi);
592 dXDA[2][2] = (m_r / cpa) * tnl * phi;
597 dXDA[2][4] = - m_r * phi;
612 HepMatrix dMDA(3,5,0);
614 const double &
phi0 = m_ac[1];
615 const double & cpa = m_ac[2];
616 const double & tnl = m_ac[4];
618 double cosf0phi =
cos(phi0+phi);
619 double sinf0phi =
sin(phi0+phi);
622 if(cpa != 0.)rho = 1./cpa;
626 if(cpa < 0.)charge = -1.;
628 dMDA[0][1] = -fabs(rho)*cosf0phi;
629 dMDA[0][2] = charge*rho*rho*sinf0phi;
631 dMDA[1][1] = -fabs(rho)*sinf0phi;
632 dMDA[1][2] = -charge*rho*rho*cosf0phi;
634 dMDA[2][2] = -charge*rho*rho*tnl;
635 dMDA[2][4] = fabs(rho);
649 HepMatrix d4MDA(4,5,0);
651 double phi0 = m_ac[1];
652 double cpa = m_ac[2];
653 double tnl = m_ac[4];
655 double cosf0phi =
cos(phi0+phi);
656 double sinf0phi =
sin(phi0+phi);
659 if(cpa != 0.)rho = 1./cpa;
663 if(cpa < 0.)charge = -1.;
665 double E = sqrt(rho*rho*(1.+tnl*tnl)+
mass*
mass);
667 d4MDA[0][1] = -fabs(rho)*cosf0phi;
668 d4MDA[0][2] = charge*rho*rho*sinf0phi;
670 d4MDA[1][1] = -fabs(rho)*sinf0phi;
671 d4MDA[1][2] = -charge*rho*rho*cosf0phi;
673 d4MDA[2][2] = -charge*rho*rho*tnl;
674 d4MDA[2][4] = fabs(rho);
676 if (cpa != 0.0 && E != 0.0) {
677 d4MDA[3][2] = (-1.-tnl*tnl)/(cpa*cpa*cpa*E);
678 d4MDA[3][4] = tnl/(cpa*cpa*E);
695 HepMatrix d4MXDA(7,5,0);
697 const double &
dr = m_ac[0];
698 const double &
phi0 = m_ac[1];
699 const double & cpa = m_ac[2];
701 const double & tnl = m_ac[4];
703 double cosf0phi =
cos(phi0+phi);
704 double sinf0phi =
sin(phi0+phi);
707 if(cpa != 0.)rho = 1./cpa;
711 if(cpa < 0.)charge = -1.;
713 double E = sqrt(rho * rho * (1. + tnl * tnl) +
mass *
mass);
715 d4MXDA[0][1] = - fabs(rho) * cosf0phi;
716 d4MXDA[0][2] = charge * rho * rho * sinf0phi;
718 d4MXDA[1][1] = - fabs(rho) * sinf0phi;
719 d4MXDA[1][2] = - charge * rho * rho * cosf0phi;
721 d4MXDA[2][2] = - charge * rho * rho * tnl;
722 d4MXDA[2][4] = fabs(rho);
724 if (cpa != 0.0 && E != 0.0) {
725 d4MXDA[3][2] = (- 1. - tnl * tnl) / (cpa * cpa * cpa * E);
726 d4MXDA[3][4] = tnl / (cpa * cpa * E);
733 d4MXDA[4][1] = - dr * m_sp + m_r * (- m_sp + sinf0phi);
735 d4MXDA[4][2] = - (m_r / cpa) * (m_cp - cosf0phi);
741 d4MXDA[5][1] = dr * m_cp + m_r * (m_cp - cosf0phi);
743 d4MXDA[5][2] = - (m_r / cpa) * (m_sp - sinf0phi);
745 d4MXDA[6][2] = (m_r / cpa) * tnl * phi;
753 d4MXDA[6][4] = - m_r * phi;
760 m_matrixValid =
false;
767 double l =
center().perp();
769 double cosPhi = (m_rad * m_rad + l * l - r * r) / (2 * m_rad * l);
771 if(cosPhi < -1 || cosPhi > 1)
return 0;
799 double dphi =
dPhi(hit);
800 double arcLength = fabs(m_r*dphi);
807 double arcLength = m_r*phi_turn;
808 arcLength = fabs(arcLength);
830 double cosLambda = 1/sqrt(1+m_ac[4]*m_ac[4]);
837 double isClockWise = m_r/fabs(m_r);
838 double x_cw =
center().x()-hit.x();
839 double y_cw =
center().y()-hit.y();
840 x_cw = isClockWise*x_cw;
841 y_cw = isClockWise*y_cw;
842 double phi_cw = atan2(y_cw,x_cw);
843 double dphi = phi_cw-
phi0();
846 while(dphi>0) dphi-=2*
M_PI;
850 while(dphi<0) dphi+=2*
M_PI;
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
NTuple::Item< double > m_pt
HepMatrix delApDelA(const HepVector &ap) const
HepMatrix delMDelA(double phi) const
IMagneticFieldSvc * m_pmgnIMF
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...
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
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.
virtual double getReferField()=0