00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "TrkReco/T3DLine.h"
00014 #include "TrkReco/T3DLineFitter.h"
00015 #include "TrkReco/TMDCWire.h"
00016 #include "TrkReco/TTrack.h"
00017
00018
00019 const T3DLineFitter T3DLine::_fitter = T3DLineFitter("T3DLine Default fitter");
00020
00021 T3DLine::T3DLine()
00022 : TTrackBase(),
00023 _dr(0),_phi0(0),_dz(0),_tanl(0),
00024 _chi2(0),_ndf(0),_Ea(SymMatrix(4,0)),
00025 _pivot(ORIGIN){
00026
00027 _cos_phi0 = 1;
00028 _sin_phi0 = 0;
00029
00030
00031 fitter(& T3DLine::_fitter);
00032
00033 _fitted = false;
00034 _fittedWithCathode = false;
00035 }
00036
00037 T3DLine::T3DLine(const TTrack& a)
00038 : TTrackBase((TTrackBase &) a),
00039 _dr(a.helix().dr()),
00040 _phi0(a.helix().phi0()),
00041 _dz(a.helix().dz()),
00042 _tanl(a.helix().tanl()),
00043 _chi2(0),_ndf(0),_Ea(SymMatrix(4,0)),
00044 _pivot(a.helix().pivot()){
00045
00046 _cos_phi0 = cos(_phi0);
00047 _sin_phi0 = sin(_phi0);
00048
00049
00050 fitter(& T3DLine::_fitter);
00051
00052 _fitted = false;
00053 _fittedWithCathode = false;
00054 }
00055
00056 T3DLine::~T3DLine(){
00057 }
00058
00059 T3DLine::T3DLine(const T3DLine& a)
00060 : TTrackBase((TTrackBase &) a),
00061 _dr(a.dr()),
00062 _phi0(a.phi0()),
00063 _dz(a.dz()),
00064 _tanl(a.tanl()),
00065 _chi2(a.chi2()),_ndf(a.ndf()),
00066 _Ea(a.Ea()),
00067 _pivot(a.pivot()){
00068
00069 _cos_phi0 = cos(_phi0);
00070 _sin_phi0 = sin(_phi0);
00071
00072
00073 fitter(& T3DLine::_fitter);
00074
00075 _fitted = false;
00076 _fittedWithCathode = false;
00077 }
00078
00079 double T3DLine::dr(void) const{
00080 return _dr;
00081 }
00082
00083 double T3DLine::phi0(void) const{
00084 return _phi0;
00085 }
00086
00087 double T3DLine::dz(void) const{
00088 return _dz;
00089 }
00090
00091 double T3DLine::tanl(void) const{
00092 return _tanl;
00093 }
00094
00095 double T3DLine::cosPhi0(void) const{
00096 return _cos_phi0;
00097 }
00098
00099 double T3DLine::sinPhi0(void) const{
00100 return _sin_phi0;
00101 }
00102
00103 const HepPoint3D& T3DLine::pivot(void) const{
00104 return _pivot;
00105 }
00106
00107 Vector T3DLine::a(void) const{
00108 Vector ta(4);
00109 ta[0] = _dr;
00110 ta[1] = _phi0;
00111 ta[2] = _dz;
00112 ta[3] = _tanl;
00113 return(ta);
00114 }
00115
00116 const SymMatrix& T3DLine::Ea(void) const{
00117 return(_Ea);
00118 }
00119
00120 Helix T3DLine::helix(void) const{
00121 HepVector a(5);
00122 a[0]=_dr;a[1]=_phi0;a[2]=1e-10;a[3]=_dz;a[4]=_tanl;
00123 Helix _helix(_pivot,a);
00124 return _helix;
00125 }
00126
00127 unsigned T3DLine::ndf(void) const{
00128 return _ndf;
00129 }
00130
00131 double T3DLine::chi2(void) const{
00132 return _chi2;
00133 }
00134
00135 double T3DLine::reducedchi2(void) const{
00136 if(_ndf==0){
00137 std::cout<<"error at T3DLine::reducedchi2 ndf=0"<<std::endl;
00138 return 0;
00139 }
00140 return (_chi2/_ndf);
00141 }
00142
00143 HepPoint3D T3DLine::x(double t) const{
00144 double tx= _pivot.x() + _dr * _cos_phi0 - t * _sin_phi0;
00145 double ty= _pivot.y() + _dr * _sin_phi0 + t * _cos_phi0;
00146 double tz= _pivot.z() + _dz + t * _tanl;
00147 HepPoint3D p(tx,ty,tz);
00148 return p;
00149 }
00150
00151 HepPoint3D T3DLine::x0(void) const{
00152 double tx= _pivot.x() + _dr * _cos_phi0;
00153 double ty= _pivot.y() + _dr * _sin_phi0;
00154 double tz= _pivot.z() + _dz;
00155 HepPoint3D p(tx,ty,tz);
00156 return p;
00157 }
00158 HepVector3D T3DLine::k(void) const{
00159 HepPoint3D p(-_sin_phi0,_cos_phi0,_tanl);
00160 return p;
00161 }
00162
00163 const HepPoint3D& T3DLine::pivot(const HepPoint3D& newpivot){
00164 double dr=(_pivot.x()-newpivot.x())*_cos_phi0
00165 +(_pivot.y()-newpivot.y())*_sin_phi0 + _dr;
00166 double dz=_pivot.z()-newpivot.z()+_dz
00167 +_tanl*((_pivot.x()-newpivot.x())*_sin_phi0
00168 +(newpivot.y()-_pivot.y())*_cos_phi0);
00169 _dr=dr;
00170 _dz=dz;
00171 _pivot=newpivot;
00172 return _pivot;
00173 }
00174
00175 void T3DLine::set(const HepPoint3D& t_pivot,
00176 double t_dr,double t_phi0,double t_dz,double t_tanl){
00177
00178 _pivot = t_pivot;
00179 _dr = t_dr;
00180 _phi0 = t_phi0;
00181 _dz = t_dz;
00182 _tanl = t_tanl;
00183 _cos_phi0 = cos(_phi0);
00184 _sin_phi0 = sin(_phi0);
00185 }
00186
00187 Vector T3DLine::a(const Vector& ta){
00188 _dr = ta[0];
00189 _phi0 = ta[1];
00190 _dz = ta[2];
00191 _tanl = ta[3];
00192 _cos_phi0 = cos(_phi0);
00193 _sin_phi0 = sin(_phi0);
00194 return(ta);
00195 }
00196
00197 const SymMatrix& T3DLine::Ea(const SymMatrix& tEa){
00198 _Ea = tEa;
00199 return(_Ea);
00200 }
00201
00202 int T3DLine::approach(TMLink& l,bool doSagCorrection) const{
00203
00204 const TMDCWire& w=*l.wire();
00205 HepPoint3D xw = w.xyPosition();
00206 HepPoint3D wireBackwardPosition = w.backwardPosition();
00207 HepVector3D v = w.direction();
00208
00209 HepPoint3D onWire,onTrack;
00210
00211 if(approach_line(wireBackwardPosition,v,onWire,onTrack)<0)
00212 return(-1);
00213
00214
00215
00216 if(!doSagCorrection){
00217 l.positionOnWire(onWire);
00218 l.positionOnTrack(onTrack);
00219 return(0);
00220 }
00221
00222
00223 double onWire_y = onWire.y();
00224 double onWire_z = onWire.z();
00225
00226 unsigned nTrial = 1;
00227 while(nTrial<100){
00228 w.wirePosition(onWire_z,xw,wireBackwardPosition,(HepVector3D&)v);
00229 if(approach_line(wireBackwardPosition,v,onWire,onTrack)<0)
00230 return(-1);
00231 if(fabs(onWire_y - onWire.y())<0.0001) break;
00232 onWire_y = onWire.y();
00233 onWire_z = onWire.z();
00234
00235 nTrial++;
00236 }
00237
00238 l.positionOnWire(onWire);
00239 l.positionOnTrack(onTrack);
00240 return(nTrial);
00241 }
00242
00243 int T3DLine::approach_line(const HepPoint3D& w0,const HepVector3D& v,
00244 HepPoint3D& onLine,HepPoint3D& onTrack) const{
00245
00246
00247
00248
00249 const HepVector3D k = this->k();
00250 const double v_k = v.dot(k);
00251 const double v_2 = v.mag2();
00252 const double k_2 = k.mag2();
00253 const double tk = v_k*v_k - v_2*k_2;
00254 if(tk==0) return(-1);
00255
00256 const HepPoint3D x0 = this->x0();
00257 const HepPoint3D dx = x0 - w0;
00258 const double t = dx.dot( v_2 * k - v_k * v)/tk;
00259 const double s = dx.dot( v_k * k - k_2 * v)/tk;
00260
00261 onLine = w0 + s * v;
00262 onTrack = x0 + t * k;
00263 return(0);
00264 }
00265
00266 int T3DLine::approach_point(const HepPoint3D& p0,HepPoint3D& onTrack) const{
00267
00268
00269
00270 const HepVector3D k = this->k();
00271 const HepPoint3D x0 = this->x0();
00272 const HepPoint3D dx = p0 - x0;
00273 const double t = dx.dot(k)/k.mag2();
00274
00275 onTrack = x0 + t * k;
00276 return(0);
00277 }