15#include "KalFitAlg/helix/Helix.h"
16#include "CLHEP/Matrix/Matrix.h"
17#include "GaudiKernel/StatusCode.h"
18#include "GaudiKernel/IInterface.h"
19#include "GaudiKernel/Kernel.h"
20#include "GaudiKernel/Service.h"
21#include "GaudiKernel/ISvcLocator.h"
22#include "GaudiKernel/SvcFactory.h"
23#include "GaudiKernel/IDataProviderSvc.h"
24#include "GaudiKernel/Bootstrap.h"
25#include "GaudiKernel/MsgStream.h"
26#include "GaudiKernel/SmartDataPtr.h"
27#include "GaudiKernel/IMessageSvc.h"
51 const HepSymMatrix & Ea)
58 StatusCode scmgn = Gaudi::svcLocator()->service(
"MagneticFieldSvc",m_pmgnIMF);
59 if(scmgn!=StatusCode::SUCCESS) {
60 std::cout<<
"Unable to open Magnetic field service"<<std::endl;
63 m_alpha = 10000. / 2.99792458 / m_bField;
76 m_Ea(HepSymMatrix(5,0)) {
77 StatusCode scmgn = Gaudi::svcLocator()->service(
"MagneticFieldSvc",m_pmgnIMF);
78 if(scmgn!=StatusCode::SUCCESS) {
80 std::cout<<
"Unable to open Magnetic field service"<<std::endl;
83 m_alpha = 10000. / 2.99792458 / m_bField;
97 m_Ea(HepSymMatrix(5,0)) {
98 StatusCode scmgn = Gaudi::svcLocator()->service(
"MagneticFieldSvc",m_pmgnIMF);
99 if(scmgn!=StatusCode::SUCCESS) {
101 std::cout<<
"Unable to open Magnetic field service"<<std::endl;
104 m_alpha = 10000. / 2.99792458 / m_bField;
112 m_a[2] = charge / perp;
140 double x = m_pivot.x() + m_ac[0] * m_cp + m_r * (m_cp -
cos(m_ac[1] +phi));
141 double y = m_pivot.y() + m_ac[0] * m_sp + m_r * (m_sp -
sin(m_ac[1] +phi));
142 double z = m_pivot.z() + m_ac[3] - m_r * m_ac[4] * phi;
157 p[0] = m_pivot.x() + m_ac[0] * m_cp + m_r * (m_cp -
cos(m_ac[1] + phi));
158 p[1] = m_pivot.y() + m_ac[0] * m_sp + m_r * (m_sp -
sin(m_ac[1] + phi));
159 p[2] = m_pivot.z() + m_ac[3] - m_r * m_ac[4] * phi;
166 double x = m_pivot.x() + m_ac[0] * m_cp + m_r * (m_cp -
cos(m_ac[1] +phi));
167 double y = m_pivot.y() + m_ac[0] * m_sp + m_r * (m_sp -
sin(m_ac[1] +phi));
168 double z = m_pivot.z() + m_ac[3] - m_r * m_ac[4] * phi;
179 if (m_matrixValid) Ex = m_Ea.similarity(
delXDelA(phi));
197 double pt = fabs(m_pt);
198 double px = - pt *
sin(m_ac[1] + phi);
199 double py = pt *
cos(m_ac[1] + phi);
200 double pz = pt * m_ac[4];
202 return Hep3Vector(px, py, pz);
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 if (m_matrixValid) Em = m_Ea.similarity(
delMDelA(phi));
225 return Hep3Vector(px, py, pz);
241 double pt = fabs(m_pt);
242 double px = - pt *
sin(m_ac[1] + phi);
243 double py = pt *
cos(m_ac[1] + phi);
244 double pz = pt * m_ac[4];
245 double E = sqrt(pt*pt*(1.+m_ac[4]*m_ac[4])+
mass*
mass);
247 return HepLorentzVector(px, py, pz, E);
264 double pt = fabs(m_pt);
265 double px = - pt *
sin(m_ac[1] + phi);
266 double py = pt *
cos(m_ac[1] + phi);
267 double pz = pt * m_ac[4];
268 double E = sqrt(pt*pt*(1.+m_ac[4]*m_ac[4])+
mass*
mass);
270 if (m_matrixValid) Em = m_Ea.similarity(
del4MDelA(phi,
mass));
273 return HepLorentzVector(px, py, pz, E);
280 HepSymMatrix & Emx)
const {
292 double pt = fabs(m_pt);
293 double px = - pt *
sin(m_ac[1] + phi);
294 double py = pt *
cos(m_ac[1] + phi);
295 double pz = pt * m_ac[4];
296 double E = sqrt(pt * pt * (1. + m_ac[4] * m_ac[4]) +
mass *
mass);
298 x.setX(m_pivot.x() + m_ac[0] * m_cp + m_r * (m_cp -
cos(m_ac[1] + phi)));
299 x.setY(m_pivot.y() + m_ac[0] * m_sp + m_r * (m_sp -
sin(m_ac[1] + phi)));
300 x.setZ(m_pivot.z() + m_ac[3] - m_r * m_ac[4] * phi);
305 return HepLorentzVector(px, py, pz, E);
315 const double &
dr = m_ac[0];
316 const double &
phi0 = m_ac[1];
317 const double &
kappa = m_ac[2];
318 const double &
dz = m_ac[3];
319 const double &
tanl = m_ac[4];
321 double rdr =
dr + m_r;
323 double csf0 =
cos(phi);
324 double snf0 = (1. - csf0) * (1. + csf0);
325 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
326 if(phi >
M_PI) snf0 = - snf0;
328 double xc = m_pivot.x() + rdr * csf0;
329 double yc = m_pivot.y() + rdr * snf0;
332 csf = (xc - newPivot.x()) / m_r;
333 snf = (yc - newPivot.y()) / m_r;
334 double anrm = sqrt(csf * csf + snf * snf);
338 phi = atan2(snf, csf);
351 double drp = (m_pivot.x() +
dr * csf0 + m_r * (csf0 - csf) - newPivot.x())
353 + (m_pivot.y() +
dr * snf0 + m_r * (snf0 - snf) - newPivot.y()) * snf;
354 double dzp = m_pivot.z() +
dz - m_r *
tanl * phid - newPivot.z();
364 if (m_matrixValid) m_Ea = m_Ea.similarity(
delApDelA(ap));
377 const HepSymMatrix & Ea) {
381 m_matrixValid =
true;
387 if (
this == & i)
return *
this;
389 m_bField = i.m_bField;
394 m_matrixValid = i.m_matrixValid;
396 m_center = i.m_center;
411Helix::updateCache(
void) {
429 if (m_ac[2] != 0.0) {
431 m_r = m_alpha / m_ac[2];
438 double x = m_pivot.x() + (m_ac[0] + m_r) * m_cp;
439 double y = m_pivot.y() + (m_ac[0] + m_r) * m_sp;
452 HepMatrix dApDA(5,5,0);
454 const double &
dr = m_ac[0];
455 const double &
phi0 = m_ac[1];
456 const double & cpa = m_ac[2];
457 const double &
dz = m_ac[3];
458 const double & tnl = m_ac[4];
461 double phi0p = ap[1];
466 double rdr = m_r +
dr;
468 if ((m_r + drp) != 0.0) {
469 rdrpr = 1. / (m_r + drp);
475 double csfd =
cos(phi0p -
phi0);
476 double snfd =
sin(phi0p -
phi0);
481 dApDA[0][1] = rdr*snfd;
483 dApDA[0][2] = (m_r/cpa)*( 1.0 - csfd );
488 dApDA[1][0] = - rdrpr*snfd;
489 dApDA[1][1] = rdr*rdrpr*csfd;
491 dApDA[1][2] = (m_r/cpa)*rdrpr*snfd;
498 dApDA[3][0] = m_r*rdrpr*tnl*snfd;
499 dApDA[3][1] = m_r*tnl*(1.0 - rdr*rdrpr*csfd);
501 dApDA[3][2] = (m_r/cpa)*tnl*(phid - m_r*rdrpr*snfd);
506 dApDA[3][4] = - m_r*phid;
521 HepMatrix dXDA(3,5,0);
523 const double &
dr = m_ac[0];
524 const double &
phi0 = m_ac[1];
525 const double & cpa = m_ac[2];
526 const double &
dz = m_ac[3];
527 const double & tnl = m_ac[4];
529 double cosf0phi =
cos(
phi0 + phi);
530 double sinf0phi =
sin(
phi0 + phi);
533 dXDA[0][1] = -
dr * m_sp + m_r * (- m_sp + sinf0phi);
535 dXDA[0][2] = - (m_r / cpa) * (m_cp - cosf0phi);
543 dXDA[1][1] =
dr * m_cp + m_r * (m_cp - cosf0phi);
545 dXDA[1][2] = - (m_r / cpa) * (m_sp - sinf0phi);
555 dXDA[2][2] = (m_r / cpa) * tnl * phi;
560 dXDA[2][4] = - m_r * phi;
575 HepMatrix dMDA(3,5,0);
577 const double &
phi0 = m_ac[1];
578 const double & cpa = m_ac[2];
579 const double & tnl = m_ac[4];
581 double cosf0phi =
cos(
phi0+phi);
582 double sinf0phi =
sin(
phi0+phi);
585 if(cpa != 0.)rho = 1./cpa;
589 if(cpa < 0.)charge = -1.;
591 dMDA[0][1] = -fabs(rho)*cosf0phi;
592 dMDA[0][2] = charge*rho*rho*sinf0phi;
594 dMDA[1][1] = -fabs(rho)*sinf0phi;
595 dMDA[1][2] = -charge*rho*rho*cosf0phi;
597 dMDA[2][2] = -charge*rho*rho*tnl;
598 dMDA[2][4] = fabs(rho);
612 HepMatrix d4MDA(4,5,0);
614 double phi0 = m_ac[1];
615 double cpa = m_ac[2];
616 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 double E = sqrt(rho*rho*(1.+tnl*tnl)+
mass*
mass);
630 d4MDA[0][1] = -fabs(rho)*cosf0phi;
631 d4MDA[0][2] = charge*rho*rho*sinf0phi;
633 d4MDA[1][1] = -fabs(rho)*sinf0phi;
634 d4MDA[1][2] = -charge*rho*rho*cosf0phi;
636 d4MDA[2][2] = -charge*rho*rho*tnl;
637 d4MDA[2][4] = fabs(rho);
639 if (cpa != 0.0 && E != 0.0) {
640 d4MDA[3][2] = (-1.-tnl*tnl)/(cpa*cpa*cpa*E);
641 d4MDA[3][4] = tnl/(cpa*cpa*E);
658 HepMatrix d4MXDA(7,5,0);
660 const double &
dr = m_ac[0];
661 const double &
phi0 = m_ac[1];
662 const double & cpa = m_ac[2];
663 const double &
dz = m_ac[3];
664 const double & tnl = m_ac[4];
666 double cosf0phi =
cos(
phi0+phi);
667 double sinf0phi =
sin(
phi0+phi);
670 if(cpa != 0.)rho = 1./cpa;
674 if(cpa < 0.)charge = -1.;
676 double E = sqrt(rho * rho * (1. + tnl * tnl) +
mass *
mass);
678 d4MXDA[0][1] = - fabs(rho) * cosf0phi;
679 d4MXDA[0][2] = charge * rho * rho * sinf0phi;
681 d4MXDA[1][1] = - fabs(rho) * sinf0phi;
682 d4MXDA[1][2] = - charge * rho * rho * cosf0phi;
684 d4MXDA[2][2] = - charge * rho * rho * tnl;
685 d4MXDA[2][4] = fabs(rho);
687 if (cpa != 0.0 && E != 0.0) {
688 d4MXDA[3][2] = (- 1. - tnl * tnl) / (cpa * cpa * cpa * E);
689 d4MXDA[3][4] = tnl / (cpa * cpa * E);
696 d4MXDA[4][1] = -
dr * m_sp + m_r * (- m_sp + sinf0phi);
698 d4MXDA[4][2] = - (m_r / cpa) * (m_cp - cosf0phi);
704 d4MXDA[5][1] =
dr * m_cp + m_r * (m_cp - cosf0phi);
706 d4MXDA[5][2] = - (m_r / cpa) * (m_sp - sinf0phi);
708 d4MXDA[6][2] = (m_r / cpa) * tnl * phi;
716 d4MXDA[6][4] = - m_r * phi;
723 m_matrixValid =
false;
**********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
double sin(const BesAngle a)
double cos(const BesAngle a)
virtual double getReferField()=0
HepMatrix delApDelA(const HepVector &ap) const
HepMatrix delMDelA(double phi) const
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.
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 dr(void) const
returns an element of parameters.
virtual ~Helix()
Destructor.
const HepVector & a(void) const
returns helix parameters.
Helix(const HepPoint3D &pivot, const HepVector &a, const HepSymMatrix &Ea)
Constructor with pivot, helix parameter a, and its error matrix.
const HepPoint3D & pivot(void) const
returns pivot position.