4#include "CLHEP/Units/PhysicalConstants.h"
5#include "CLHEP/Matrix/Vector.h"
6#include "CLHEP/Matrix/SymMatrix.h"
7#include "CLHEP/Matrix/Matrix.h"
9#include "CLHEP/Geometry/Point3D.h"
23#include "GaudiKernel/ISvcLocator.h"
24#include "GaudiKernel/Bootstrap.h"
25#include "GaudiKernel/IInterface.h"
26#include "GaudiKernel/Kernel.h"
27#include "GaudiKernel/Service.h"
28#include "GaudiKernel/SvcFactory.h"
29#include "GaudiKernel/IDataProviderSvc.h"
35const CgemGeomSvc* CgemHitOnTrack::_cgemGeomSvc = NULL;
51 StatusCode sc = Gaudi::svcLocator()->service(
"CgemGeomSvc", icgemGeomSvc);
53 if(sc==StatusCode::SUCCESS && cgemGeomSvc!=NULL){
76 _startLen = -1.*
length/2. - 5.;
119 _hitTraj = hot._hitTraj;
120 _fitTime = hot._fitTime;
121 _drift[0] = hot._drift[0];
122 _drift[1] = hot._drift[1];
123 _startLen = hot._startLen;
124 _endLen = hot._endLen;
125 _dHit = (hb==0?hot._dHit:hb);
126 _clusterr = hot._clusterr;
163 static Hep3Vector dir;
168 return BesAngle(dir.phi() - pos.phi());
174 static Hep3Vector dir;
214 bool forceIteration =
true;
221 double phi0 = par[1];
222 double omega = par[2];
223 double radius = fabs(omega)<0.00001 ? -9999: 1./fabs(omega);
224 double l = d0 + radius;
225 double r = _clusterr;
228 double phi_center = atan2(yc,xc);
230 double cosPhi = (radius * radius + l * l - r * r) / (2 * radius * l);
237 double x = radius*
sin(dPhi) - (radius + d0)*
sin(phi0);
238 double y = -1.*radius*
cos(dPhi) + (radius + d0)*
sin(phi0);
244 dca = (phiCluster - phiTrack).
rad();
252CgemHitOnTrack::updateCorrections()
254 std::cout<<__FILE__<<
" "<<__LINE__<<
" WARNING CgemHitOnTrack::updateCorrections not implemented "<<std::endl;
286 double newSig = -999;
369 std::cout<<__FILE__<<
" "<<__LINE__<<
" CgemHitOnTrack::hitTraj() not implemented, return NULL "<<std::endl;
405 double vec_z = _dHit->
getRecZ() ;
409 Gaudi::svcLocator()->service(
"MdcUtilitySvc",m_mdcUtilitySvc);
410 if (m_mdcUtilitySvc == NULL) cout<<
" Can not load MdcUtilitySvc"<<endl;
411 HepVector trkparbes = m_mdcUtilitySvc->
patPar2BesPar(trkpar);
412 trkparbes[2]=-trkparbes[2];
415 Helix cgem_helix_0(pivot, trkparbes);
416 HepMatrix J_dmdx(2,3,0), J_dxda(3,5,0), J(2,5,0) ;
417 HepSymMatrix V(2,0), W(2,0) ;
418 HepVector a_new(5), dm(2);
424 if(layer==0) { rl=79.838/10. ; R=87.5026/10.;
x_reso=0.1372/10.;
v_reso=0.1273/10.;
a_stero=45.94*3.1415926/180;}
425 else if (layer==1) { rl=125.104/10. ; R=132.7686/10.;
x_reso=0.1476/10.;
v_reso=0.1326/10.;
a_stero=31.10*3.1415926/180;}
426 else { rl=167.604/10.; R=175.2686/10.;
x_reso=0.1412/10.;
v_reso=0.1378/10.;
a_stero=32.99*3.1415926/180;}
433 double tmp_phi = atan2(y,
x);
434 double dphi = vec_phi - tmp_phi;
437 dm[0]=-dphi*rl*
sin(vec_phi);
439 J_dxda=cgem_helix_0.
delXDelA(d_phi);
441 for (
int i=0;i<5;i++){
443 derivs2[i+5]=J(2,i) ;
457 for (
int i=0;i<5;i++){
493 double vec_z = _dHit->
getRecZ() ;
497 Gaudi::svcLocator()->service(
"MdcUtilitySvc",m_mdcUtilitySvc);
498 if (m_mdcUtilitySvc == NULL) cout<<
" Can not load MdcUtilitySvc"<<endl;
499 HepVector trkparbes = m_mdcUtilitySvc->
patPar2BesPar(trkpar);
500 trkparbes[2]=-trkparbes[2];
503 Helix cgem_helix_0(pivot, trkparbes);
504 HepSymMatrix V(2,0), W(2,0) ;
508 if(layer==0) { rl=79.838/10. ; R=87.5026/10.;
x_reso=0.1372/10.;
v_reso=0.1273/10.;
a_stero=45.94*3.1415926/180;}
509 else if (layer==1) { rl=125.104/10. ; R=132.7686/10.;
x_reso=0.1476/10.;
v_reso=0.1326/10.;
a_stero=31.10*3.1415926/180;}
510 else { rl=167.604/10.; R=175.2686/10.;
x_reso=0.1412/10.;
v_reso=0.1378/10.;
a_stero=32.99*3.1415926/180;}
518 double tmp_phi = atan2(y,
x);
519 double dphi = vec_phi - tmp_phi;
523 dm[0]=dphi*rl*
sin(vec_phi);
549 double z_cluster = _dHit->
getRecZ()/10;
555 double r_X = readoutPlane->
getRX()/10;
556 double r_V = readoutPlane->
getRV()/10;
565 trkpar[0] = -trkpar[0];
566 trkpar[1] = trkpar[1]-
M_PI/2;
567 trkpar[2] = 333.567*trkpar[2];
568 trkpar[2] = -trkpar[2];
569 trkpar[3] = trkpar[3];
570 trkpar[4] = trkpar[4];
571 while(trkpar[1] < 0) trkpar[1] += 2*
M_PI;
572 while(trkpar[1] >= 2*
M_PI) trkpar[1] -= 2*
M_PI;
575 Helix cgem_helix_0(pivot, trkpar);
578 double x_cross = pos.x();
579 double y_cross = pos.y();
580 double z_cross = pos.z();
581 double phi_cross = pos.phi();
582 while( phi_cross < 0) phi_cross += 2*
M_PI;
583 while( phi_cross >= 2*
M_PI) phi_cross -= 2*
M_PI;
584 double r2 = pos.perp2();
586 double dphi = phi_cross - phi_cluster;
593 int iView(0), mode(1);
595 double Phi_tangent = cgem_helix_0.
direction(dPhi).phi();
596 double Phi_position = phi_cross;
597 double delta_phi=Phi_tangent - Phi_position;
598 while(delta_phi>
M_PI) delta_phi-=CLHEP::twopi;
599 while(delta_phi<-
M_PI) delta_phi+=CLHEP::twopi;
600 double sigma_X = _cgemCalibFunSvc->
getSigma(layer,0,mode,delta_phi,Q,T)/10;
601 double sigma_V = _cgemCalibFunSvc->
getSigma(layer,1,mode,delta_phi,Q,T)/10;
604 HepMatrix J_dmdx(2,3,0), J_dxda(3,5,0), J(2,5,0);
605 J_dmdx(1,1)=-r_X*y_cross/r2;
606 J_dmdx(1,2)= r_X*x_cross/r2;
616 double dr = cgem_helix_0.
dr();
617 double phi0 = cgem_helix_0.
phi0();
618 double kappa = cgem_helix_0.
kappa();
620 double dz = cgem_helix_0.
dz();
621 double tanl = cgem_helix_0.
tanl();
623 double cosPhi=
cos(dPhi);
624 double sinPhi=
sin(dPhi);
626 double dPhiDdr = -(kappa/
alpha-cosPhi/(dr+
alpha/kappa))/sinPhi;
630 double dPhiDkappa = -kappa*(dr*dr-r2)*(2*
alpha+dr*kappa)/(2*
alpha*(
alpha+dr*kappa)*(
alpha+dr*kappa)*sinPhi);
632 double dxDdr =
cos(phi0)+
alpha/kappa*
sin(phi0+dPhi)*dPhiDdr;
633 double dyDdr =
sin(phi0)-
alpha/kappa*
cos(phi0+dPhi)*dPhiDdr;
634 double dxDphi0 = -dr*
sin(phi0)+
alpha/kappa*(-
sin(phi0)+
sin(phi0+dPhi));
635 double dyDphi0 = -dr*
cos(phi0)+
alpha/kappa*(
cos(phi0)-
cos(phi0+dPhi));
636 double dxDkappa = -
alpha/(kappa*kappa)*(
cos(phi0)-
cos(phi0+dPhi))+
alpha/kappa*
sin(phi0+dPhi)*dPhiDkappa;
637 double dyDkappa = -
alpha/(kappa*kappa)*(
sin(phi0)-
sin(phi0+dPhi))-
alpha/kappa*
cos(phi0+dPhi)*dPhiDkappa;
638 double dzDdr = -
alpha/kappa*tanl*dPhiDdr;
639 double dzDkappa =
alpha/(kappa*kappa)*tanl*dPhi-
alpha/kappa*tanl*dPhiDkappa;
640 double dzDtanl = -
alpha/kappa*dPhi;
643 J_dxda(1,1) = -1*dxDdr;
644 J_dxda(1,2) = dxDphi0;
645 J_dxda(1,3) = -
alpha*dxDkappa;
646 J_dxda(2,1) = -1*dyDdr;
647 J_dxda(2,2) = dyDphi0;
648 J_dxda(2,3) = -
alpha*dyDkappa;
649 J_dxda(3,1) = -1*dzDdr;
650 J_dxda(3,3) = -
alpha*dzDkappa;
652 J_dxda(3,5) = dzDtanl;
655 for(
int i=1;i<=nPar;i++){
656 Xderivs(i) = J(1,i)/sigma_X;
657 Vderivs(i) = J(2,i)/sigma_V;
659 XdeltaChi = dphi*r_X/sigma_X;
665 Vderivs = HepVector(nPar,0);
677 double z_cluster = _dHit->
getRecZ()/10;
682 double r_X = readoutPlane->
getRX()/10;
683 double r_V = readoutPlane->
getRV()/10;
692 trkpar[0] = -trkpar[0];
693 trkpar[1] = trkpar[1]-
M_PI/2;
694 trkpar[2] = 333.567*trkpar[2];
695 trkpar[2] = -trkpar[2];
696 trkpar[3] = trkpar[3];
697 trkpar[4] = trkpar[4];
698 while(trkpar[1] < 0) trkpar[1] += 2*
M_PI;
699 while(trkpar[1] >= 2*
M_PI) trkpar[1] -= 2*
M_PI;
701 Helix cgem_helix_0(pivot, trkpar);
704 double x_cross = pos.x();
705 double y_cross = pos.y();
706 double z_cross = pos.z();
707 double phi_cross = pos.phi();
708 while( phi_cross < 0) phi_cross += 2*
M_PI;
709 while( phi_cross >= 2*
M_PI) phi_cross -= 2*
M_PI;
710 double r2 = pos.perp2();
712 double dphi = phi_cross - phi_cluster;
717 int iView(0), mode(1);
719 double Phi_tangent = cgem_helix_0.
direction(dPhi).phi();
720 double Phi_position = phi_cross;
721 double delta_phi=Phi_tangent - Phi_position;
722 while(delta_phi>
M_PI) delta_phi-=CLHEP::twopi;
723 while(delta_phi<-
M_PI) delta_phi+=CLHEP::twopi;
724 double sigma_X = _cgemCalibFunSvc->
getSigma(layer,0,mode,delta_phi,Q,T)/10;
725 double sigma_V = _cgemCalibFunSvc->
getSigma(layer,1,mode,delta_phi,Q,T)/10;
729 XdeltaChi = dphi*r_X/sigma_X;
double tan(const BesAngle a)
double sin(const BesAngle a)
double cos(const BesAngle a)
double getSigma(int layer, int xvFlag, int readoutMode, double angle, double Q, double T) const
double getLengthOfCgemLayer() const
CgemGeoLayer * getCgemLayer(int i) const
CgemGeoReadoutPlane * getReadoutPlane(int iLayer, int iSheet) const
void changeBase(RecCgemCluster *newBase)
double entranceAngleHit() const
double entranceAngle() const
void print(std::ostream &) const
virtual ~CgemHitOnTrack()
CgemHitOnTrack(const RecCgemCluster &baseHit, double fittime)
TrkEnums::TrkViewInfo whatView() const
TrkErrCode getFitStuff(HepVector &derivs, HepVector &derivs2, double &sigma1, double &sigma2, double &deltaChi1, double &deltaChi2) const
virtual bool timeAbsolute(double &t, double &tErr) const
virtual bool timeResid(double &t, double &tErr) const
const RecCgemCluster * baseHit() const
virtual const Trajectory * hitTraj() const
virtual TrkHitOnTrk * clone(TrkRep *, const TrkDifTraj *trkTraj=0) const
static const double halfPi
double IntersectCylinder(double r) const
HepPoint3D x(double dPhi=0.) const
returns position after rotating angle dPhi in phi direction.
HepMatrix delXDelA(double phi) const
double dr(void) const
returns an element of parameters.
Hep3Vector direction(double dPhi=0.) const
returns direction vector after rotating angle dPhi in phi direction.
virtual HepVector patPar2BesPar(const HepVector &helixPar) const =0
double getenergydeposit(void) const
double getRecZ(void) const
int getclusterid(void) const
int getlayerid(void) const
double getrecphi(void) const
double getrecv(void) const
int getsheetid(void) const
virtual void getInfo(double fltLen, HepPoint3D &pos, Hep3Vector &direction) const =0
virtual Hep3Vector direction(double) const =0
virtual const TrkDifTraj & traj() const =0
virtual const TrkSimpTraj * localTrajectory(double fltLen, double &localFlt) const =0
void setHitResid(double newResid)
friend class TrkBase::Functors::updateMeasurement
void setHitRms(double newRms)
const TrkDifTraj * _trkTraj
const TrkRep * getParentRep() const
const TrkDifTraj * trkTraj() const
const TrkErrCode & status() const
virtual double arrivalTime(double fltL) const
TrkRecoTrk * parentTrack()