/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Reconstruction/MdcPatRec/TrkFitter/TrkFitter-00-01-11/src/TrkBmSpotOnTrk.cxx

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 // File and Version Information:
00003 //      $Id: TrkBmSpotOnTrk.cxx,v 1.3 2006/03/28 01:03:35 zhangy Exp $
00004 //
00005 // Description:
00006 //     Implementation of class to add beam spot to track fit.
00007 //
00008 // Environment:
00009 //      Software developed for the BaBar Detector at the SLAC B-Factory.
00010 //
00011 // Authors: Steve Schaffner
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 //  Effectively a copy constructor
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 // GetRms
00093 //
00094 // Calculate RMS (hit width or resolution) based on local track
00095 // trajectory.
00096 //
00097 // We have to deal with the error ellipse carefully. To do
00098 // this, find the point along the linear trajectory in x and y
00099 // that minimizes the chi-squared, and then use doca/sqrt(chi2)
00100 // as the RMS.
00101 //
00102 double TrkBmSpotOnTrk::GetRms()
00103 {
00104         //
00105         // Get direction
00106         //
00107         const TrkDifTraj& trkTraj = getParentRep()->traj();
00108         Hep3Vector trkDir = trkTraj.direction(fltLen());
00109         
00110         //
00111         // Get errors (assume no correlation)
00112         //
00113         double Mxx = 1.0/_size.fast(1,1);
00114         double Myy = 1.0/_size.fast(2,2);
00115         
00116         //
00117         // Normalized track directions in x/y
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         // Solve for point of least chi2
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 // FindBeamTrajectory
00144 //
00145 // Calculate a linear trajectory that corresponds to the
00146 // beam spot and error matrix
00147 //
00148 // The simplest way I have to understand this calculation
00149 // is to consider which (x,y) point is required to minimize
00150 // the chi2 at +/- one unit in z.
00151 //
00152 // The following simple calculation assumes x and y are uncorrelated.
00153 // This is to save CPU. It is straight forward to extend the
00154 // calculation to finite x/y correlation.
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 }

Generated on Tue Nov 29 23:13:44 2016 for BOSS_7.0.2 by  doxygen 1.4.7