00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include <math.h>
00014 #include "CLHEP/Vector/ThreeVector.h"
00015 #include "CLHEP/Geometry/Point3D.h"
00016 #ifndef ENABLE_BACKWARDS_COMPATIBILITY
00017 typedef HepGeom::Point3D<double> HepPoint3D;
00018 #endif
00019 #include "TrkFitter/TrkBmSpotOnTrk.h"
00020 #include "TrkBase/TrkDifTraj.h"
00021 #include "TrkBase/TrkPoca.h"
00022 #include "TrkBase/TrkDifPoca.h"
00023 #include "TrkBase/TrkRep.h"
00024 using CLHEP::Hep3Vector;
00025
00026 static HepPoint3D dum1(0,0,0),dum2(0,0,1);
00027
00028 TrkBmSpotOnTrk::TrkBmSpotOnTrk(const HepPoint3D& ip, const HepSymMatrix& size)
00029 : TrkHitOnTrk(0,0.5e-4),
00030 _beamTraj(FindBeamTrajectory(ip,size)),
00031 _ip(ip),
00032 _size(size)
00033 {}
00034
00035
00036 TrkBmSpotOnTrk::TrkBmSpotOnTrk(const TrkBmSpotOnTrk &hot, TrkRep *newRep, const TrkDifTraj *trkTraj)
00037 : TrkHitOnTrk(hot,newRep,trkTraj),
00038 _beamTraj(hot._beamTraj),
00039 _ip(hot.ip()),
00040 _size(hot._size)
00041 {}
00042
00043
00044 TrkBmSpotOnTrk::~TrkBmSpotOnTrk()
00045 { }
00046
00047 TrkBmSpotOnTrk*
00048 TrkBmSpotOnTrk::clone(TrkRep *rep, const TrkDifTraj *trkTraj) const
00049 {
00050 return new TrkBmSpotOnTrk(*this,rep,trkTraj);
00051 }
00052
00053
00054 TrkErrCode
00055 TrkBmSpotOnTrk::updateMeasurement(const TrkDifTraj* traj,bool x)
00056 {
00057 TrkErrCode status=updatePoca(traj,x);
00058 if (status.success()) {
00059 assert(_poca!=0);
00060 setHitResid(_poca->doca());
00061 setHitRms(GetRms());
00062 } else {
00063 #ifdef MDCPATREC_WARNING
00064 std::cout<<"ErrMsg(warning) TrkBmSpotOnTrk::updateMeasurement failed" << std::endl;
00065 #endif
00066 setHitResid(9999.9);
00067 setHitRms(9999.9);
00068 }
00069 return status;
00070 }
00071
00072 TrkEnums::TrkViewInfo
00073 TrkBmSpotOnTrk::whatView() const
00074 {
00075 return TrkEnums::xyView;
00076 }
00077
00078 const Trajectory*
00079 TrkBmSpotOnTrk::hitTraj() const
00080 {
00081 return &_beamTraj;
00082 }
00083
00084 const HepPoint3D&
00085 TrkBmSpotOnTrk::ip() const
00086 {
00087 return _ip;
00088 }
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102 double TrkBmSpotOnTrk::GetRms()
00103 {
00104
00105
00106
00107 const TrkDifTraj& trkTraj = getParentRep()->traj();
00108 Hep3Vector trkDir = trkTraj.direction(fltLen());
00109
00110
00111
00112
00113 double Mxx = 1.0/_size.fast(1,1);
00114 double Myy = 1.0/_size.fast(2,2);
00115
00116
00117
00118
00119 double vx = trkDir[0];
00120 double vy = trkDir[1];
00121 double normxy = (vx*vx + vy*vy);
00122 if (normxy <= 0) return 999.9;
00123 normxy = sqrt(normxy);
00124
00125 vx /= normxy;
00126 vy /= normxy;
00127
00128
00129
00130
00131 double s = vx*vy*(Mxx-Myy)/(vx*vx*Mxx + vy*vy*Myy);
00132
00133 double dx = (-vy + s*vx);
00134 double dy = (+vx + s*vy);
00135
00136 double chi2 = dx*dx*Mxx + dy*dy*Myy;
00137
00138 return chi2 <= 0 ? 0.0 : (1.0/sqrt(chi2));
00139 }
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156 const TrkLineTraj TrkBmSpotOnTrk::FindBeamTrajectory( const HepPoint3D &point,
00157 const HepSymMatrix &error )
00158 {
00159 int ifail;
00160 HepSymMatrix cover(error.inverse(ifail));
00161
00162 if (ifail) {
00163 #ifdef MDCPATREC_FATAL
00164 std::cout<<"ErrMsg(fatal) TrkLineTraj: "
00165 <<"Error inverting beamspot error matrix" << std::endl;
00166 #endif
00167 }
00168 double dx = -cover.fast(3,1)/cover.fast(1,1);
00169 double dy = -cover.fast(3,2)/cover.fast(2,2);
00170
00171 HepPoint3D p1 = point + Hep3Vector(-dx,-dy,-1);
00172 HepPoint3D p2 = point + Hep3Vector(+dx,+dy,+1);
00173
00174 return TrkLineTraj( p1, p2 );
00175 }