15#include "TrkReco/TRunge.h"
16#include "TrkReco/TRungeFitter.h"
17#include "TrkReco/TMDCWire.h"
18#include "TrkReco/TTrack.h"
20#include "CLHEP/Matrix/Matrix.h"
21#include "GaudiKernel/StatusCode.h"
22#include "GaudiKernel/IInterface.h"
23#include "GaudiKernel/Kernel.h"
24#include "GaudiKernel/Service.h"
25#include "GaudiKernel/ISvcLocator.h"
26#include "GaudiKernel/SvcFactory.h"
27#include "GaudiKernel/IDataProviderSvc.h"
28#include "GaudiKernel/Bootstrap.h"
29#include "GaudiKernel/MsgStream.h"
30#include "GaudiKernel/SmartDataPtr.h"
31#include "GaudiKernel/IMessageSvc.h"
43const double EPS = 1.0e-6;
50 _chi2(0),_ndf(0),_charge(1),_bfieldID(21),_Nstep(0),
72 StatusCode scmgn = Gaudi::svcLocator()->service(
"MagneticFieldSvc",m_pmgnIMF);
73 if(scmgn!=StatusCode::SUCCESS) {
74 std::cout<< __FILE__<<
" Unable to open Magnetic field service"<<std::endl;
81 _pivot(a.getPivot()),_a(a.helix()),_Ea(a.err()),
82 _chi2(a.chi2()),_ndf(a.ndof()),_bfieldID(21),_Nstep(0),
93 if(_a[2]<0) _charge=-1;
106 StatusCode scmgn = Gaudi::svcLocator()->service(
"MagneticFieldSvc",m_pmgnIMF);
107 if(scmgn!=StatusCode::SUCCESS) {
108 std::cout<<
"Unable to open Magnetic field service"<<std::endl;
116 _pivot(a.helix().pivot()),_a(a.helix().a()),_Ea(a.helix().Ea()),
117 _chi2(0),_ndf(0),_bfieldID(21),_Nstep(0),
123 fitter(& TRunge::_fitter);
128 if(_a[2]<0) _charge=-1;
141 StatusCode scmgn = Gaudi::svcLocator()->service(
"MagneticFieldSvc",m_pmgnIMF);
142 if(scmgn!=StatusCode::SUCCESS) {
143 std::cout<<
"Unable to open Magnetic field service"<<std::endl;
151 _pivot(h.pivot()),_a(h.a()),_Ea(h.Ea()),
152 _chi2(0),_ndf(0),_bfieldID(21),_Nstep(0),
158 fitter(& TRunge::_fitter);
163 if(_a[2]<0) _charge=-1;
180 _pivot(a.pivot()),_a(a.a()),_Ea(a.Ea()),
181 _chi2(a.chi2()),_ndf(a.ndf()),_bfieldID(a.BfieldID()),_Nstep(0),
182 _stepSize(a.StepSize()),_mass(a.Mass()),_eps(a.Eps()),
183 _stepSizeMax(a.StepSizeMax()),_stepSizeMin(a.StepSizeMin()),
184 _maxflightlength(a.MaxFlightLength()) {
187 fitter(& TRunge::_fitter);
192 if(_a[2]<0) _charge=-1;
199 for(
unsigned i=0;i<6;i++) _yscal[i]=
a.Yscal()[i];
239 return(
Helix(_pivot,_a,_Ea));
252 std::cout<<
"error at TRunge::reducedchi2 ndf=0"<<std::endl;
273 return(_stepSizeMax);
276 return(_stepSizeMin);
284 return(_maxflightlength);
291 tHelix.
pivot(newpivot);
301 if(_a[2]<0) _charge=-1;
327 for(
unsigned i=0;i<6;i++) _yscal[i]=y[i];
339 return(_stepSizeMax);
344 return(_stepSizeMin);
354 if(length>0) _maxflightlength=length;
357 return(_maxflightlength);
363 return(
approach(l,tof,p,material,doSagCorrection));
372 double onWire_x,onWire_y, onWire_z, zwf, zwb;
379 if(
approach_line(l,wireBackwardPosition,
v,onWire,onTrack,tof,p,material,stepNum)<0){
388 else if(onWire.z() < zwb)
393 if(!doSagCorrection){
396 double phipoint=atan((onTrack.y()-_pivot.y())/onTrack.x()-_pivot.x());
404 onWire_y = onWire.y();
405 onWire_z = onWire.z();
411 if(
approach_line(l,wireBackwardPosition,
v,onWire,onTrack,tof,p,material,stepNum)<0)
413 if(fabs(onWire_y - onWire.y())<0.0001)
break;
414 onWire_y = onWire.y();
415 onWire_z += (onWire.z()-onWire_z)/2;
417 if(onWire_z > zwf) onWire_z=zwf;
418 else if(onWire_z < zwb) onWire_z=zwb;
439 return(
approach_line(l,w0,
v,onLine,onTrack,tof,p,material ,stepNum));
447 if(_stepSize==0)
Fly_SC();
453 const double w0x = w0.x();
454 const double w0y = w0.y();
455 const double w0z = w0.z();
457 const double vx =
v.x();
458 const double vy =
v.y();
459 const double vz =
v.z();
460 const double v_2 = vx*vx+vy*vy+vz*vz;
462 const float clight=29.9792458;
465 const float p2 = _y[0][3]*_y[0][3]+_y[0][4]*_y[0][4]+_y[0][5]*_y[0][5];
466 const float tof_factor=1./clight*sqrt(1+_mass2/p2);
471 if(stepNum>_Nstep) stepNum=0;
474 if(stepNum==0 && _stepSize!=0){
475 const double dx = _y[0][0]-w0x;
476 const double dy = _y[0][1]-w0y;
478 (sqrt( (dx*dx+dy*dy)*(1+_a[4]*_a[4]) )/_stepSize);
484 mergin=(unsigned)(1.0/_stepSize);
486 if(stepNum>mergin) stepNum-=mergin;
488 if(stepNum>=_Nstep) stepNum=_Nstep-1;
491 unsigned inc=(mergin>>1)+1;
495 const double dx = _y[stepNumHi][0]-w0x;
496 const double dy = _y[stepNumHi][1]-w0y;
497 const double dz = _y[stepNumHi][2]-w0z;
498 const double t = (dx*vx+dy*vy+
dz*vz)/v_2;
506 pp.setX(_y[stepNumHi][0]);
507 pp.setY(_y[stepNumHi][1]);
508 pp.setZ(_y[stepNumHi][2]);
509 double zwire=hitv.dot(zvec)+w0z;
511 const double l2=dtl*dtl;
512 if(l2 > l2_old)
break;
517 if(stepNumHi>=_Nstep){
523 while(stepNumHi-stepNumLo>1){
524 unsigned j=(stepNumHi+stepNumLo)>>1;
525 const double dx = _y[j][0]-w0x;
526 const double dy = _y[j][1]-w0y;
527 const double dz = _y[j][2]-w0z;
528 const double t = (dx*vx+dy*vy+
dz*vz)/v_2;
536 point.setX(_y[j][0]);
537 point.setY(_y[j][1]);
538 point.setZ(_y[j][2]);
539 double zwir=hitv.dot(zv)+w0z;
540 double dtll=
DisToWire(l,zwir,point,onwir);
541 const double l2 =dtll*dtll;
571 for(
unsigned i=0;i<stepNum;i++) dstep+=_h[i];
572 tof=dstep*tof_factor;
574 tof=stepNum*_stepSize*tof_factor;
687 for(
unsigned i=0;i<6;i++) y[i]=_y[stepNum][i];
690 const double A[3][3]={{1-vx*vx/v_2, -vx*vy/v_2, -vx*vz/v_2},
691 { -vy*vx/v_2,1-vy*vy/v_2, -vy*vz/v_2},
692 { -vz*vx/v_2, -vz*vy/v_2,1-vz*vz/v_2}};
701 const double dx = y[0]-w0x;
702 const double dy = y[1]-w0y;
703 const double dz = y[2]-w0z;
704 const double t = (dx*vx+dy*vy+
dz*vz)/v_2;
705 const double d[3]={dx-
t*vx,dy-
t*vy,
dz-
t*vz};
715 double zwir=hitv.dot(zv)+w0z;
716 double dtll=
DisToWire(l,zwir,point,onwir);
717 const double l2=dtll*dtll;
720 for(k=0;k<3;k++) g[j]+=A[j][k]*d[k];
729 for(j=0;j<3;j++) Y+=y[j+3]*g[j];
731 for(j=0;j<3;j++) dYds+=f[j+3]*g[j];
740 for(k=0;k<3;k++) Af[j]+=(A[j][k]*f[k]);
741 for(k=0;k<3;k++) Af2[j]+=(A[j][k]*Af[k]);
746 const double step=-Y/dYds*factor;
748 if(fabs(step) < 0.00001)
break;
749 if(l2 > l2_old) factor/=2;
755 tof+=step2*tof_factor;
764 const double dx = y[0]-w0x;
765 const double dy = y[1]-w0y;
766 const double dz = y[2]-w0z;
767 const double s = (dx*vx+dy*vy+
dz*vz)/v_2;
771 onLine.setX(onwir.x());
772 onLine.setY(onwir.y());
773 onLine.setZ(onwir.z());
779 if(_stepSize==0)
Fly_SC();
794 for(stepNum=0;stepNum<_Nstep;stepNum++){
795 double l2=(_y[stepNum][0]-x0)*(_y[stepNum][0]-x0)+
796 (_y[stepNum][1]-y0)*(_y[stepNum][1]-y0)+
797 (_y[stepNum][2]-z0)*(_y[stepNum][2]-z0);
798 if(l2 > l2_old)
break;
805 if(stepNum>=_Nstep)
return(-1);
809 double y[6],y_old[6];
810 for(
unsigned i=0;i<6;i++) y[i]=_y[stepNum][i];
811 double step=_stepSize;
813 for(
unsigned i=0;i<6;i++) y_old[i]=y[i];
815 double l2=(y[0]-x0)*(y[0]-x0)+(y[1]-y0)*(y[1]-y0)+(y[2]-z0)*(y[2]-z0);
817 for(
unsigned i=0;i<6;i++) y[i]=y_old[i];
824 if(step < 0.0001)
break;
844 for(
unsigned j=0;j<6;j++) _y[
Nstep][j]=y[j];
849 if( y[2]>160 || y[2]<-80 || (y[0]*y[0]+y[1]*y[1])>8100 )
break;
853 flightlength += _stepSize;
854 if(flightlength>_maxflightlength)
break;
864 double f1[6],f2[6],f3[6],f4[6],yt[6];
868 const double mpi=0.13957;
874 for(i=0;i<6;i++) yt[i]=y[i]+hh*
f1[i];
883 for(i=0;i<6;i++) yt[i]=y[i]+hh*f2[i];
892 for(i=0;i<6;i++) yt[i]=y[i]+step*f3[i];
903 for(i=0;i<6;i++) y[i]+=h6*(
f1[i]+2*f2[i]+2*f3[i]+f4[i]);
930 pos.setX((
float)y[0]);
931 pos.setY((
float)y[1]);
932 pos.setZ((
float)y[2]);
938 pmag = sqrt(y[3]*y[3]+y[4]*y[4]+y[5]*y[5]);
946 double Bmag=sqrt(B.x()*B.x()+B.y()*B.y()+B.z()*B.z());
947 factor = ((double)_charge)/(0.333564095);
951 f[3] = factor*(f[1]*B.z()-f[2]*B.y());
952 f[4] = factor*(f[2]*B.x()-f[0]*B.z());
953 f[5] = factor*(f[0]*B.y()-f[1]*B.x());
958 const double cosPhi0=
cos(_a[1]);
959 const double sinPhi0=
sin(_a[1]);
960 const double invKappa=1/
abs(_a[2]);
962 y[0]= _pivot.x()+_a[0]*cosPhi0;
963 y[1]= _pivot.y()+_a[0]*sinPhi0;
964 y[2]= _pivot.z()+_a[3];
965 y[3]= -sinPhi0*invKappa;
966 y[4]= cosPhi0*invKappa;
967 y[5]= _a[4]*invKappa;
982 for(
unsigned i=0;i<6;i++) y[i]=_y[stepNum][i];
992 const double& step,
double yout[6])
const{
994 double f2[6],f3[6],f4[6],yt[6];
1000 for(i=0;i<6;i++) yt[i]=y[i]+hh*dydx[i];
1009 for(i=0;i<6;i++) yt[i]=y[i]+hh*f2[i];
1018 for(i=0;i<6;i++) yt[i]=y[i]+step*f3[i];
1029 for(i=0;i<6;i++) yout[i]=y[i]+h6*(dydx[i]+2*f2[i]+2*f3[i]+f4[i]);
1045#define FCOR 0.06666666
1047#define ERRCON 6.0e-4
1049 const double&
eps,
const double yscal[6],
1050 double& stepdid,
double& stepnext)
const{
1052 double ysav[6],dysav[6],ytemp[6];
1053 double h,hh,errmax,temp;
1056 for(i=0;i<6;i++) ysav[i]=y[i];
1058 for(i=0;i<6;i++) dysav[i]=dydx[i];
1072 ytemp[i]=y[i]-ytemp[i];
1073 temp=fabs(ytemp[i]/yscal[i]);
1074 if(errmax < temp) errmax=temp;
1085 for(i=0;i<6;i++) y[i]+=ytemp[i]*
FCOR;
1098 double y[6],dydx[6],yscal[6];
1100 double step,stepdid,stepnext;
1102 double flightlength;
1115 for(i=0;i<6;i++) _y[
Nstep][i]=y[i];
1121 Propagate_QC(y,dydx,step,_eps,_yscal,stepdid,stepnext);
1123 if( y[2]>160 || y[2]<-80 || (y[0]*y[0]+y[1]*y[1])>8100 )
break;
1127 flightlength += stepdid;
1128 if(flightlength>_maxflightlength)
break;
1132 if(stepnext<_stepSizeMin) step=_stepSizeMin;
1133 else if(stepnext>_stepSizeMax) step=_stepSizeMax;
1153 double rho = 333.564095/(hel.
kappa()*Bz);
1159 for(
int j=0;j<
cores.length();j++){
1169 for(
int i=0;i<10;i++){
1172 if(
abs(th.
dz())<0.1){
1195 const double vCrs = v0.x() * v1.y() - v0.y() * v1.x();
1196 const double vDot = v0.x() * v1.x() + v0.y() * v1.y();
1197 double phi = atan2(vCrs, vDot);
1199 double tz=hel.
x(phi).z();
1202 if(phi>phi_max) phi_max=phi;
1203 if(phi<phi_min) phi_min=phi;
1211 abs( rho*(phi_max-phi_min)*sqrt(1+
tanl*
tanl) )*1.2;
1213 return(_maxflightlength);
1225 onwire.setX(point.x());
1226 onwire.setY(point.y());
1230 double dist=sqrt((point.x()-
a.x())*(point.x()-
a.x())+(point.y()-
a.y())*(point.y()-
a.y())+(z-
a.z())*(z-
a.z()));
1242 double Density=0.00085144;
1243 double coeff=Density*z/
a;
1245 double isq=i * i * 1e-18;
1260const double Me = 0.000510999;
1262 double bsq = psq / (psq +
mass *
mass);
1265 double s = Me /
mass;
1266 double w = (4 * Me * esq
1267 / (1 + 2 *
s * sqrt(1 + esq)
1272 cc = 1+2*log(sqrt(isq)/(28.8E-09*sqrt(coeff)));
1277 double x1(3), xa(cc/4.606), aa;
1278 aa = 4.606*(xa-x0)/((x1-x0)*(x1-x0)*(x1-x0));
1280double x(log10(sqrt(esq)));
1283 if (
x < x1) delta=delta+aa*(x1-
x)*(x1-
x)*(x1-
x);
1287 float f1, f2, f3, f4, f5, ce;
1291 f4 = (
f1*0.42237+f2*0.0304-f3*0.00038)*1E12;
1292 f5 = (
f1*3.858-f2*0.1668+f3*0.00158)*1E18;
1293 ce = f4*isq+f5*isq*sqrt(isq);
1295 return (0.0001535 * coeff / bsq
1296 * (log(Me * esq * w / isq)
1297 - 2 * bsq-delta-2.0*ce/z)) * path;
1300double psq=y[5]*y[5]+y[3]*y[3]+y[4]*y[4];
1304double dE=materiral->
dE(
mass,path,p);
1306 psq += dE * (dE + 2 * sqrt(
mass *
mass + psq));
1308 psq += dE * (dE - 2 * sqrt(
mass *
mass + psq));
1309double pnew=sqrt(psq);
1319 double cosPhi = (m_rad * m_rad + l * l - r * r) / (2 * m_rad * l);
1321 if(cosPhi < -1 || cosPhi > 1)
return 0.;
1331 double d = r * r - (y - xc.y()) * (y - xc.y());
1335 if(xx > 0) xx -= sqrt(d);
1338 double l = (plane.inverse() *
1348 double d = r * r - (
x - xc.x()) * (
x - xc.x());
1352 if(yy > 0) yy -= sqrt(d);
1355 double l = (plane.inverse() *
EvtComplex exp(const EvtComplex &c)
double abs(const EvtComplex &c)
EvtTensor3C eps(const EvtVector3R &v)
double sin(const BesAngle a)
double cos(const BesAngle a)
CLHEP::HepSymMatrix SymMatrix
const HepPoint3D ORIGIN
Constants.
**********Class see also m_nmax DOUBLE PRECISION m_amel DOUBLE PRECISION m_x2 DOUBLE PRECISION m_alfinv DOUBLE PRECISION m_Xenph INTEGER m_KeyWtm INTEGER m_idyfs DOUBLE PRECISION m_zini DOUBLE PRECISION m_q2 DOUBLE PRECISION m_Wt_KF DOUBLE PRECISION m_WtCut INTEGER m_KFfin *COMMON c_KarLud $ !Input CMS energy[GeV] $ !CMS energy after beam spread beam strahlung[GeV] $ !Beam energy spread[GeV] $ !z boost due to beam spread $ !electron beam mass *ff pair spectrum $ !minimum v
HepGeom::Point3D< double > HepPoint3D
HepGeom::Transform3D HepTransform3D
const double default_maxflightlength
HepGeom::Transform3D HepTransform3D
const double default_stepSize0
const double default_stepSizeMin
const double default_stepSize
const double default_stepSizeMax
static Bfield * getBfield(int)
returns Bfield object.
const HepPoint3D & center(void) const
returns position of helix center(z = 0.);
const HepSymMatrix & Ea(void) const
returns error matrix.
HepPoint3D x(double dPhi=0.) const
returns position after rotating angle dPhi in phi direction.
double radius(void) const
returns radious of helix.
const HepVector & a(void) const
returns helix parameters.
const HepPoint3D & pivot(void) const
returns pivot position.
virtual StatusCode fieldVector(const HepGeom::Point3D< double > &xyz, HepGeom::Vector3D< double > &fvec) const =0
virtual double getReferField()=0
double dE(double mass, double path, double p) const
Calculate energy loss.
A class to represent a wire in MDC.
const HepVector3D & direction(void) const
returns direction vector of the wire.
const HepPoint3D & xyPosition(void) const
returns middle position of a wire. z componet is 0.
const HepPoint3D & forwardPosition(void) const
returns position in forward endplate.
const HepPoint3D & backwardPosition(void) const
returns position in backward endplate.
void wirePosition(float zPosition, HepPoint3D &xyPosition, HepPoint3D &backwardPosition, HepVector3D &direction) const
calculates position and direction vector with sag correction.
A class to relate TMDCWireHit and TTrack objects.
const HepPoint3D & positionOnWire(void) const
returns the closest point on wire to a track.
const HepPoint3D & positionOnTrack(void) const
returns the closest point on track to wire.
const TMDCWire *const wire(void) const
returns a pointer to a wire.
A class to fit a TTrackBase object to a 3D line.
A class to represent a track in tracking.
double dr(void) const
Track parameters (at pivot)
int GetXP(unsigned stepNum, double y[6]) const
double MaxFlightLength(void) const
return max flight length
Helix helix(void) const
returns helix class
unsigned Fly_SC(void) const
void SetFirst(double y[6]) const
set first point (position, momentum) s=0, phi=0
unsigned Nstep(void) const
access to trajectory cache
unsigned Fly(const RkFitMaterial material) const
make the trajectory in cache, return the number of step
double intersect_yz_plane(const HepTransform3D &plane, double x) const
const Vector & a(void) const
returns helix parameter
void eloss(double path, const RkFitMaterial *material, double mass, double y[6], int index) const
double intersect_xy_plane(double z) const
double SetFlightLength(void)
set flight length using wire hits
double intersect_zx_plane(const HepTransform3D &plane, double y) const
double DisToWire(TMLink &, double, HepPoint3D, HepPoint3D &)
int approach_point(TMLink &, const HepPoint3D &, HepPoint3D &onTrack, const RkFitMaterial material) const
caluculate closest point between a point and this track
int approach(TMLink &, const RkFitMaterial, bool sagCorrection=true)
double StepSize(void) const
returns step size
const double * Yscal(void) const
return error parameters for fitting with step size control
void Propagate_QC(double y[6], double dydx[6], const double &steptry, const double &eps, const double yscal[6], double &stepdid, double &stepnext) const
double StepSizeMax(void) const
void Function(const double y[6], double f[6]) const
int approach_line(TMLink &, const HepPoint3D &, const HepVector3D &, HepPoint3D &onLine, HepPoint3D &onTrack, const RkFitMaterial material)
caluculate closest points between a line and this track
const SymMatrix & Ea(void) const
returns error matrix
const HepPoint3D & pivot(void) const
pivot position
void Propagate1(const double y[6], const double dydx[6], const double &step, double yout[6]) const
double reducedchi2(void) const
returns reduced-chi2
float Mass(void) const
return mass
void Propagate(double y[6], const double &step, const RkFitMaterial material) const
propagate the track using 4th-order Runge-Kutta method
int BfieldID(void) const
returns B field ID
double StepSizeMin(void) const
int GetStep(unsigned stepNum, double &step) const
double dEpath(double, double, double) const
unsigned ndf(void) const
returns NDF
double chi2(void) const
returns chi2.
double intersect_cylinder(double r) const
A virtual class for a track class in tracking.
const TMFitter *const fitter(void) const
returns a pointer to a default fitter.
const AList< TMLink > & cores(unsigned mask=0) const
returns a list of masked TMLinks for fit. 'mask' will be applied if mask is not 0.
A class to represent a track in tracking.