#include <T3DLineFitter.h>
Inheritance diagram for T3DLineFitter:
Public Member Functions | |
void | dump (const std::string &message=std::string(""), const std::string &prefix=std::string("")) const |
dumps debug information. | |
void | dump (const std::string &message=std::string(""), const std::string &prefix=std::string("")) const |
dumps debug information. | |
virtual int | fit (TTrackBase &, float t0Offset) const |
virtual int | fit (TTrackBase &) const |
virtual int | fit (TTrackBase &, float t0Offset) const |
virtual int | fit (TTrackBase &) const |
const std::string & | name (void) const |
returns name. | |
const std::string & | name (void) const |
returns name. | |
void | propagation (int) |
void | propagation (int) |
void | sag (bool) |
void | sag (bool) |
T3DLineFitter (const std::string &name, bool m_sag, int m_prop, bool m_tof) | |
T3DLineFitter (const std::string &name) | |
Constructor. | |
T3DLineFitter (const std::string &name, bool m_sag, int m_prop, bool m_tof) | |
T3DLineFitter (const std::string &name) | |
Constructor. | |
void | tof (bool) |
void | tof (bool) |
virtual | ~T3DLineFitter () |
Destructor. | |
virtual | ~T3DLineFitter () |
Destructor. | |
Protected Member Functions | |
void | fitDone (TTrackBase &) const |
sets the fitted flag. (Bad implementation) | |
void | fitDone (TTrackBase &) const |
sets the fitted flag. (Bad implementation) | |
Private Member Functions | |
void | drift (const T3DLine &, const TMLink &, float t0Offset, double &distance, double &err) const |
calculates drift distance and its error. | |
void | drift (const T3DLine &, const TMLink &, float t0Offset, double &distance, double &err) const |
calculates drift distance and its error. | |
int | dxda (const TMLink &, const T3DLine &, Vector &dxda, Vector &dyda, Vector &dzda, HepVector3D &wireDirection) const |
calculates dXda. 'TMLink' and 'T3DLine' are inputs. Others are outputs. | |
int | dxda (const TMLink &, const T3DLine &, Vector &dxda, Vector &dyda, Vector &dzda, HepVector3D &wireDirection) const |
calculates dXda. 'TMLink' and 'T3DLine' are inputs. Others are outputs. | |
Private Attributes | |
int | _propagation |
bool | _sag |
bool | _tof |
|
Constructor.
00081 : TMFitter(name), 00082 // _sag(true),_propagation(1),_tof(false){ 00083 _sag(false),_propagation(0),_tof(true){ //Liuqg, tmp 00084 00085 }
|
|
00088 : TMFitter(name), 00089 _sag(m_sag),_propagation(m_prop),_tof(m_tof){ 00090 }
|
|
Destructor.
00092 { 00093 }
|
|
Constructor.
|
|
|
|
Destructor.
|
|
calculates drift distance and its error.
|
|
calculates drift distance and its error.
00107 { 00108 00109 //read t0 from TDS-------------------------------------// 00110 double _t0_bes = -1.; 00111 IMessageSvc *msgSvc; 00112 Gaudi::svcLocator()->service("MessageSvc", msgSvc); 00113 MsgStream log(msgSvc, "TCosmicFitter"); 00114 00115 IDataProviderSvc* eventSvc = NULL; 00116 Gaudi::svcLocator()->service("EventDataSvc", eventSvc); 00117 00118 SmartDataPtr<RecEsTimeCol> aevtimeCol(eventSvc,"/Event/Recon/RecEsTimeCol"); 00119 if (aevtimeCol) { 00120 RecEsTimeCol::iterator iter_evt = aevtimeCol->begin(); 00121 _t0_bes = (*iter_evt)->getTest(); 00122 }else{ 00123 log << MSG::WARNING << "Could not find RecEsTimeCol" << endreq; 00124 } 00125 //----------------------------------------------------// 00126 00127 const TMDCWireHit& h = *l.hit(); 00128 const HepPoint3D& onTrack = l.positionOnTrack(); 00129 const HepPoint3D& onWire = l.positionOnWire(); 00130 unsigned leftRight = WireHitRight; 00131 // if (onWire.cross(onTrack).z() < 0) leftRight = WireHitLeft; 00132 if((onWire.x()*onTrack.y()-onWire.y()*onTrack.x())<0) leftRight = WireHitLeft; 00133 00134 //...No correction... 00135 /* if ((t0Offset == 0.) && (_propagation==0) && (! _tof)) { 00136 distance = l.drift(leftRight); 00137 err = h.dDrift(leftRight); 00138 return; 00139 }*/ 00140 00141 //...TOF correction... 00142 // momentum ???? or velocity -> assumued light velocity 00143 float tof = 0.; 00144 // if (_tof) { 00145 // double length = ((onTrack - t.x0())*t.k())/t.k().mag(); 00146 /* double tl = t.tanl(); 00147 double length = ((onTrack - t.x0())*t.k())/sqrt(1+tl*tl); 00148 static const double Ic = 1/29.9792; //1/[cm/ns] 00149 tof = length * Ic; 00150 */ 00151 //cal the time pass through the chamber 00152 /* const float Rad = 81; // cm 00153 float dRho = t.helix().a()[0]; 00154 float Lproj = sqrt(Rad*Rad - dRho*dRho); 00155 float tlmd = t.helix().a()[4]; 00156 float fct = sqrt(1. + tlmd * tlmd); 00157 00158 float x[3]={ onWire.x(), onWire.y(), onWire.z()}; 00159 00160 float Rad_wire = sqrt(x[0]*x[0]+x[1]*x[1]); // cm 00161 float L_wire = sqrt(Rad_wire*Rad_wire - dRho*dRho); 00162 float flyLength = Lproj - L_wire; 00163 if (x[1]<0) flyLength = Lproj + L_wire; 00164 float Tfly = flyLength/29.98*sqrt(1.0+(0.105/10)*(0.105/10))*fct; //approxiate... cm/ns 00165 */ 00166 double Tfly = _t0_bes/220.*(110.-onWire.y()); 00167 // } 00168 00169 //...T0 and propagation corrections... 00170 int wire = h.wire()->localId(); 00171 int layerId = h.wire()->layerId(); 00172 // int wire = h.wire()->id(); 00173 int side = leftRight; 00174 // if (side==0) side = -1; 00175 // float p[3] = {-t.sinPhi0(),t.cosPhi0(),t.tanl()}; 00176 // float x[3] = {onWire.x(), onWire.y(), onWire.z()}; 00177 // float time = h.reccdc()->tdc + t0Offset - tof; 00178 float time = h.reccdc()->tdc - Tfly; 00179 float dist; 00180 float edist; 00181 // int prop = _propagation; 00182 00183 IMdcCalibFunSvc* l_mdcCalFunSvc; 00184 Gaudi::svcLocator() -> service("MdcCalibFunSvc", l_mdcCalFunSvc); 00185 dist = l_mdcCalFunSvc->rawTimeNoTOFToDist(time, layerId, wire, side, 0.0); 00186 edist = l_mdcCalFunSvc->getSigma(layerId, side, dist, 0.0); 00187 // if(layerId<20) edist = 999999.; 00188 dist = dist/10.0; //mm->cm 00189 edist = edist/10.0; 00190 /*zsl 00191 calcdc_driftdist_(& prop, 00192 & wire, 00193 & side, 00194 p, 00195 x, 00196 & time, 00197 & dist, 00198 & edist); 00199 */ 00200 distance = (double) dist; 00201 err = (double) edist; 00202 return; 00203 }
|
|
dumps debug information.
Reimplemented from TMFitter. |
|
dumps debug information.
Reimplemented from TMFitter. |
|
calculates dXda. 'TMLink' and 'T3DLine' are inputs. Others are outputs.
|
|
calculates dXda. 'TMLink' and 'T3DLine' are inputs. Others are outputs.
00385 { 00386 // onTrack = x0 + t * k 00387 // onWire = w0 + s * wireDirection 00388 //...Setup... 00389 const TMDCWire& w = *l.wire(); 00390 const HepVector3D k = t.k(); 00391 const double cosPhi0 = t.cosPhi0(); 00392 const double sinPhi0 = t.sinPhi0(); 00393 const double dr = t.dr(); 00394 const HepPoint3D& onWire = l.positionOnWire(); 00395 const HepPoint3D& onTrack = l.positionOnTrack(); 00396 // const Vector3 u = onTrack - onWire; 00397 const double t_t = (onWire - t.x0()).dot(k)/k.mag2(); 00398 00399 //...Sag correction... 00400 HepPoint3D xw = w.xyPosition(); 00401 HepPoint3D wireBackwardPosition = w.backwardPosition(); 00402 wireDirection = w.direction(); 00403 if (_sag) w.wirePosition(onWire.z(), 00404 xw, 00405 wireBackwardPosition, 00406 (HepVector3D&)wireDirection); 00407 const HepVector3D& v = wireDirection; 00408 00409 // onTrack = x0 + t * k 00410 // onWire = w0 + s * v 00411 00412 const double v_k = v.dot(k); 00413 const double tvk = v_k*v_k-k.mag2(); 00414 if(tvk==0) return(-1); 00415 00416 const HepVector3D& dxdt_a = k; 00417 00418 const HepVector3D dxda_t[4] 00419 ={HepVector3D(cosPhi0,sinPhi0,0), 00420 HepVector3D(-dr*sinPhi0-t_t*cosPhi0,dr*cosPhi0-t_t*sinPhi0,0), 00421 HepVector3D(0,0,1), 00422 HepVector3D(0,0,t_t)}; 00423 00424 const HepVector3D dx0da[4] 00425 ={HepVector3D(cosPhi0,sinPhi0,0), 00426 HepVector3D(-dr*sinPhi0,dr*cosPhi0,0), 00427 HepVector3D(0,0,1), 00428 HepVector3D(0,0,0)}; 00429 00430 const HepVector3D dkda[4] 00431 ={HepVector3D(0,0,0), 00432 HepVector3D(-cosPhi0,-sinPhi0,0), 00433 HepVector3D(0,0,0), 00434 HepVector3D(0,0,1)}; 00435 00436 const HepVector3D d = t.x0() - wireBackwardPosition; 00437 const HepVector3D kvkv = k - v_k*v; 00438 00439 for(int i=0;i<4;i++){ 00440 const double v_dkda = v.dot(dkda[i]); 00441 00442 const double dtda = dx0da[i].dot(kvkv)/tvk 00443 + d.dot(dkda[i]-v_dkda*v)/tvk 00444 - d.dot(kvkv)*2*(v_k*v_dkda-k.dot(dkda[i]))/(tvk*tvk); 00445 00446 const HepVector3D dxda3D = dxda_t[i] + dtda*dxdt_a; 00447 00448 dxda[i] = dxda3D.x(); 00449 dyda[i] = dxda3D.y(); 00450 dzda[i] = dxda3D.z(); 00451 } 00452 00453 return 0; 00454 }
|
|
|
|
Implements TMFitter. |
|
00209 { 00210 00211 //std::cout<<"T3DLineFitter::fit start"<<std::endl; 00212 00213 //...Type check... 00214 if(tb.objectType() != Line3D) return TFitUnavailable; 00215 T3DLine& t = (T3DLine&) tb; 00216 00217 //...Already fitted ?... 00218 if(t.fitted()) return TFitAlreadyFitted; 00219 00220 //...Count # of hits... 00221 AList<TMLink> cores = t.cores(); 00222 unsigned nCores = cores.length(); 00223 unsigned nStereoCores = NStereoHits(cores); 00224 00225 00226 //...Check # of hits... 00227 bool flag2D = false; 00228 if ((nStereoCores == 0) && (nCores > 3)) flag2D = true; 00229 else if ((nStereoCores < 2) || (nCores - nStereoCores < 3)) 00230 return TFitErrorFewHits; 00231 00232 //...Move pivot to ORIGIN... 00233 const HepPoint3D pivot_bak = t.pivot(); 00234 t.pivot(ORIGIN); 00235 00236 //...Setup... 00237 Vector a(4),da(4); 00238 a = t.a(); 00239 Vector dxda(4); 00240 Vector dyda(4); 00241 Vector dzda(4); 00242 Vector dDda(4); 00243 Vector dchi2da(4); 00244 SymMatrix d2chi2d2a(4,0); 00245 static const SymMatrix zero4(4,0); 00246 double chi2; 00247 double chi2Old = DBL_MAX; 00248 double factor = 1.0; 00249 int err = 0; 00250 SymMatrix e(2,0); 00251 Vector f(2); 00252 00253 //...Fitting loop... 00254 unsigned nTrial = 0; 00255 while(nTrial < 100){ 00256 00257 //...Set up... 00258 chi2 = 0; 00259 for (unsigned j=0;j<4;j++) dchi2da[j]=0; 00260 d2chi2d2a=zero4; 00261 00262 //...Loop with hits... 00263 unsigned i=0; 00264 while(TMLink* l = cores[i++]){ 00265 const TMDCWireHit& h = *l->hit(); 00266 00267 //...Cal. closest points... 00268 t.approach(*l,_sag); 00269 const HepPoint3D& onTrack=l->positionOnTrack(); 00270 const HepPoint3D& onWire=l->positionOnWire(); 00271 unsigned leftRight = WireHitRight; 00272 if (onWire.cross(onTrack).z() < 0.) leftRight = WireHitLeft; 00273 00274 //...Obtain drift distance and its error... 00275 double distance; 00276 double eDistance; 00277 drift(t, * l, t0Offset, distance, eDistance); 00278 l->drift(distance,0); 00279 l->drift(distance,1); 00280 l->dDrift(eDistance,0); 00281 l->dDrift(eDistance,1); 00282 double eDistance2 = eDistance * eDistance; 00283 //cout<<"distance: "<< distance << " eDistance: " << eDistance << endl; 00284 00285 //...Residual... 00286 HepVector3D v = onTrack - onWire; 00287 double vmag = v.mag(); 00288 double dDistance = vmag - distance; 00289 00290 HepVector3D vw; 00291 //...dxda... 00292 this->dxda(*l, t, dxda, dyda, dzda, vw); 00293 00294 //...Chi2 related... 00295 dDda = (vmag > 0.) 00296 ? ((v.x() * (1. - vw.x() * vw.x()) - 00297 v.y() * vw.x() * vw.y() - v.z() * vw.x() * vw.z()) 00298 * dxda + 00299 (v.y() * (1. - vw.y() * vw.y()) - 00300 v.z() * vw.y() * vw.z() - v.x() * vw.y() * vw.x()) 00301 * dyda + 00302 (v.z() * (1. - vw.z() * vw.z()) - 00303 v.x() * vw.z() * vw.x() - v.y() * vw.z() * vw.y()) 00304 * dzda) / vmag : Vector(4,0); 00305 if (vmag <= 0.0) { 00306 std::cout << " in fit " << onTrack << ", " << onWire; 00307 h.dump(); 00308 } 00309 dchi2da += (dDistance / eDistance2) * dDda; 00310 d2chi2d2a += vT_times_v(dDda) / eDistance2; 00311 double pChi2 = dDistance * dDistance / eDistance2; 00312 chi2 += pChi2; 00313 00314 //...Store results... 00315 l->update(onTrack, onWire, leftRight, pChi2); 00316 } 00317 00318 //...Check condition... 00319 double change = chi2Old - chi2; 00320 00321 if (fabs(change) < 1.0e-5) break; 00322 if (change < 0.) { 00323 a += factor * da; //recover 00324 factor *= 0.1; 00325 }else{ 00326 chi2Old = chi2; 00327 if(flag2D){ 00328 f = dchi2da.sub(1,2); 00329 e = d2chi2d2a.sub(1,2); 00330 f = solve(e,f); 00331 da[0]=f[0]; 00332 da[1]=f[1]; 00333 da[2]= 0; 00334 da[3]= 0; 00335 }else{ 00336 //...Cal. helix parameters for next loop... 00337 da = solve(d2chi2d2a, dchi2da); 00338 } 00339 } 00340 a -= factor * da; 00341 t.a(a); 00342 ++nTrial; 00343 } 00344 00345 //...Cal. error matrix... 00346 SymMatrix Ea(4,0); 00347 unsigned dim; 00348 if(flag2D){ 00349 dim=2; 00350 SymMatrix Eb(3,0),Ec(3,0); 00351 Eb = d2chi2d2a.sub(1,3); 00352 Ec = Eb.inverse(err); 00353 Ea[0][0] = Ec[0][0]; 00354 Ea[0][1] = Ec[0][1]; 00355 Ea[0][2] = Ec[0][2]; 00356 Ea[1][1] = Ec[1][1]; 00357 Ea[1][2] = Ec[1][2]; 00358 Ea[2][2] = Ec[2][2]; 00359 }else{ 00360 dim=4; 00361 Ea = d2chi2d2a.inverse(err); 00362 } 00363 00364 //...Store information... 00365 if(! err){ 00366 t.a(a); 00367 t.Ea(Ea); 00368 t._fitted = true; 00369 if (flag2D) err = T3DLine2DFit; 00370 }else{ 00371 err = TFitFailed; 00372 } 00373 00374 t._ndf = nCores - dim; 00375 t._chi2 = chi2; 00376 00377 //...Recover pivot... 00378 t.pivot(pivot_bak); 00379 00380 return err; 00381 }
|
|
Implements TMFitter. 00205 { 00206 return fit(tb,0); 00207 }
|
|
sets the fitted flag. (Bad implementation)
|
|
sets the fitted flag. (Bad implementation)
|
|
returns name.
|
|
returns name.
00073 {
00074 return _name;
00075 }
|
|
|
|
00098 { 00099 _propagation = _in; 00100 }
|
|
|
|
00095 { 00096 _sag = _in; 00097 }
|
|
|
|
00101 { 00102 _tof = _in; 00103 }
|
|
|
|
|
|
|