#include <TRungeFitter.h>
Inheritance diagram for TRungeFitter:
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) |
void | tof (bool) |
void | tof (bool) |
TRungeFitter (const std::string &name, bool m_sag, int m_prop, bool m_tof) | |
TRungeFitter (const std::string &name) | |
Constructor. | |
TRungeFitter (const std::string &name, bool m_sag, int m_prop, bool m_tof) | |
TRungeFitter (const std::string &name) | |
Constructor. | |
virtual | ~TRungeFitter () |
Destructor. | |
virtual | ~TRungeFitter () |
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 Attributes | |
int | _propagation |
bool | _sag |
bool | _tof |
|
Constructor.
00054 : TMFitter(name), 00055 _sag(true),_propagation(1),_tof(false){ 00056 }
|
|
00059 : TMFitter(name), 00060 _sag(m_sag),_propagation(m_prop),_tof(m_tof){ 00061 }
|
|
Destructor.
00063 { 00064 }
|
|
Constructor.
|
|
|
|
Destructor.
|
|
dumps debug information.
Reimplemented from TMFitter. |
|
dumps debug information.
Reimplemented from TMFitter. |
|
|
|
Implements TMFitter. |
|
00079 { 00080 00081 //std::cout<<"TRungeFitter::fit start"<<std::endl; 00082 00083 //...Type check... 00084 if(tb.objectType() != Runge) return TFitUnavailable; 00085 TRunge& t = (TRunge&) tb; 00086 00087 //...Already fitted ?... 00088 if(t.fitted()) return TFitAlreadyFitted; 00089 00090 //...Count # of hits... 00091 AList<TMLink> cores = t.cores(); 00092 unsigned nCores = cores.length(); 00093 unsigned nStereoCores = NStereoHits(cores); 00094 00095 //...Check # of hits... 00096 if ((nStereoCores < 2) || (nCores - nStereoCores < 3)) 00097 return TFitErrorFewHits; 00098 00099 //...Move pivot to ORIGIN... 00100 const HepPoint3D pivot_bak = t.pivot(); 00101 t.pivot(ORIGIN); 00102 00103 //...Setup... 00104 Vector a(5),da(5); 00105 a = t.a(); 00106 Vector dDda(5); 00107 Vector dchi2da(5); 00108 SymMatrix d2chi2d2a(5,0); 00109 const SymMatrix zero5(5,0); 00110 double chi2; 00111 double chi2Old = DBL_MAX; 00112 int err = 0; 00113 00114 double factor = 0.1; 00115 Vector beta(5); 00116 SymMatrix alpha(5,0); 00117 SymMatrix alpha2(5,0); 00118 00119 double (*d)[5]=new double[nCores][5]; 00120 // double (*d2)[5]=new double[nCores][5]; 00121 Vector ea(5); 00122 00123 float tof; 00124 HepVector3D p; 00125 unsigned i; 00126 00127 double distance; 00128 double eDistance; 00129 00130 // ea... init 00131 const double ea_init=0.000001; 00132 ea[0]=ea_init; //dr 00133 ea[1]=ea_init; //phi0 00134 ea[2]=ea_init; //kappa 00135 ea[3]=ea_init; //dz 00136 ea[4]=ea_init; //tanl 00137 00138 //std::cout<<"TRF ::"<<a[0]<<","<<a[1]<<","<<a[2]<<","<<a[3]<<","<<a[4]<<std::endl; 00139 00140 //long int lclock0=clock()/1000; 00141 //long int lclock=lclock0; 00142 00143 Vector def_a(t.a()); 00144 Vector ta(def_a); 00145 00146 //...Fitting loop... 00147 unsigned nTrial = 0; 00148 while(nTrial < 100){ 00149 00150 //...Set up... 00151 chi2 = 0; 00152 for (unsigned j=0;j<5;j++) dchi2da[j]=0; 00153 d2chi2d2a=zero5; 00154 00155 def_a=t.a(); 00156 00157 //#### loop for shifted helix parameter set #### 00158 for(unsigned j=0;j<5;j++){ 00159 ta=def_a; 00160 ta[j]+=ea[j]; 00161 t.a(ta); 00162 //...Loop with hits... 00163 i=0; 00164 //std::cout<<"TRF:: cores="<<cores.length()<<std::endl; 00165 while(TMLink* l = cores[i++]){ 00166 //...Cal. closest points... 00167 t.approach(*l,tof,p,_sag); 00168 const HepPoint3D& onTrack=l->positionOnTrack(); 00169 const HepPoint3D& onWire=l->positionOnWire(); 00170 d[i-1][j]=(onTrack-onWire).mag(); 00171 //std::cout<<"TRF:: i="<<i<<std::endl; 00172 }//end of loop with hits 00173 //lclock=clock()/1000; 00174 //std::cout<<"TRF clock="<<lclock-lclock0<<std::endl; 00175 //lclock0=lclock; 00176 } 00177 /* 00178 for(int j=0;j<5;j++){ 00179 ta=def_a; 00180 ta[j]-=ea[j]; 00181 t.a(ta); 00182 //...Loop with hits... 00183 float tof_dummy; 00184 Vector3 p_dummy; 00185 unsigned i=0; 00186 while(TMLink* l = cores[i++]){ 00187 //...Cal. closest points... 00188 t.approach(*l,tof_dummy,p_dummy,_sag); 00189 const HepPoint3D& onTrack=l->positionOnTrack(); 00190 const HepPoint3D& onWire=l->positionOnWire(); 00191 d2[i-1][j]=(onTrack-onWire).mag(); 00192 }//end of loop with hits 00193 } 00194 */ 00195 t.a(def_a); 00196 00197 //#### original parameter set and calc. chi2 #### 00198 //...Loop with hits... 00199 i=0; 00200 while(TMLink* l = cores[i++]){ 00201 const TMDCWireHit& h = *l->hit(); 00202 00203 //...Cal. closest points... 00204 if(t.approach(*l,tof,p,_sag)<0){ 00205 std::cout<<"TrkReco:TRF:: bad wire"<<std::endl; 00206 continue; 00207 } 00208 const HepPoint3D& onTrack=l->positionOnTrack(); 00209 const HepPoint3D& onWire=l->positionOnWire(); 00210 unsigned leftRight = WireHitRight; 00211 if (onWire.cross(onTrack).z() < 0.) leftRight = WireHitLeft; 00212 00213 //...Obtain drift distance and its error... 00214 if ((t0Offset == 0.) && (_propagation==0) && (! _tof)) { 00215 //...No correction... 00216 distance = l->drift(leftRight); 00217 eDistance = h.dDrift(leftRight); 00218 }else{ 00219 //...T0 and propagation corrections... 00220 int wire = h.wire()->id(); 00221 int side = leftRight; 00222 if (side==0) side = -1; 00223 float tp[3] = {p.x(),p.y(),p.z()}; 00224 float x[3] = {onWire.x(), onWire.y(), onWire.z()}; 00225 float time = h.reccdc()->tdc + t0Offset - tof; 00226 float dist; 00227 float edist; 00228 int prop = _propagation; 00229 //zsl calcdc_driftdist_(& prop, 00230 // & wire, 00231 // & side, 00232 // tp, 00233 // x, 00234 // & time, 00235 // & dist, 00236 // & edist); 00237 distance = (double) dist; 00238 eDistance = (double) edist; 00239 } 00240 double eDistance2=eDistance*eDistance; 00241 00242 //...Residual... 00243 const double d0 = (onTrack-onWire).mag(); 00244 //if(d0>2) std::cout<<"TRF:: strange dist. d0="<<d0<<" x="<<distance 00245 // <<" ex="<<eDistance<<std::endl; 00246 double dDistance = d0 - distance; 00247 00248 //...dDda... 00249 for(int j=0;j<5;j++){ 00250 dDda[j]=(d[i-1][j]-d0)/ea[j]; 00251 //if(dDda[j]==0) std::cout<<"TRF:: dDda=0 j="<<j<<" ea="<<ea[j]<<std::endl; 00252 } 00253 // for(int j=0;j<5;j++) dDda[j]=(d[i-1][j]-d2[i-1][j])/ea[j]/2.; 00254 //...Chi2 related... 00255 dchi2da += (dDistance / eDistance2) * dDda; 00256 d2chi2d2a += vT_times_v(dDda) / eDistance2; 00257 double pChi2 = dDistance * dDistance / eDistance2; 00258 chi2 += pChi2; 00259 //if(!(pChi2<0 || pChi2>=0)){ 00260 // std::cout<<"TRF:: pChi2="<<pChi2<<" X="<<d0<<" fx="<<distance 00261 // <<" ex="<<eDistance<<std::endl; 00262 //} 00263 00264 //...Store results... 00265 l->update(onTrack, onWire, leftRight, pChi2); 00266 }//end of loop with hits 00267 00268 //...Check condition... 00269 double change = chi2Old - chi2; 00270 00271 if (0 <= change && change < 0.01) break; 00272 if (change < 0.) { 00273 factor *= 100; 00274 a += da; //recover 00275 if(-0.01 < change){ 00276 d2chi2d2a=alpha; 00277 chi2=chi2Old; 00278 break; 00279 } 00280 }else if(change > 0.){ 00281 chi2Old = chi2; 00282 factor *= 0.1; 00283 alpha=d2chi2d2a; 00284 beta=dchi2da; 00285 }else{ 00286 std::cout<<"TrkReco:TRF:: bad chi2 = "<<chi2<<std::endl; 00287 break; // protection for nan 00288 } 00289 alpha2=alpha; 00290 for(unsigned j=0;j<5;j++) alpha2[j][j]*=(1+factor); 00291 //...Cal. helix parameters for next loop... 00292 da = solve(alpha2,beta); 00293 00294 //lclock=clock()/1000; 00295 //std::cout<<"TRF "<<nTrial<<": " 00296 // <<"cl="<<lclock-lclock0<<": " 00297 // <<a[0]<<","<<a[1]<<","<<a[2]<<","<<a[3]<<","<<a[4]<<" " 00298 // <<chi2<<"/"<<nCores<<":"<<factor 00299 // <<" :da "<<da[0]<<","<<da[1]<<","<<da[2]<<","<<da[3]<<","<<da[4]<<std::endl; 00300 //lclock0=lclock; 00301 00302 a -= da; 00303 t.a(a); 00304 //ea = 0.0001*da; 00305 for(i=0;i<5;i++){ 00306 ea[i]=0.0001*abs(da[i]); 00307 if(ea[i]>ea_init) ea[i]=ea_init; 00308 if(ea[i]<1.0e-10) ea[i]=1.0e-10; 00309 } 00310 ++nTrial; 00311 } 00312 //std::cout<<"TRungeFitter:: nTrial="<<nTrial<<std::endl; 00313 00314 //...Cal. error matrix... 00315 SymMatrix Ea(5,0); 00316 unsigned dim; 00317 dim=5; 00318 Ea = d2chi2d2a.inverse(err); 00319 00320 //...Store information... 00321 if(! err){ 00322 t.a(a); 00323 t.Ea(Ea); 00324 t._fitted = true; 00325 }else{ 00326 err = TFitFailed; 00327 } 00328 00329 t._ndf = nCores - dim; 00330 t._chi2 = chi2; 00331 00332 //...Recover pivot... 00333 t.pivot(pivot_bak); 00334 00335 delete [] d; 00336 // delete [] d2; 00337 00338 return err; 00339 }
|
|
Implements TMFitter. 00075 { 00076 return fit(tb,0); 00077 }
|
|
sets the fitted flag. (Bad implementation)
|
|
sets the fitted flag. (Bad implementation)
|
|
returns name.
|
|
returns name.
00073 {
00074 return _name;
00075 }
|
|
|
|
00069 { 00070 _propagation = _in; 00071 }
|
|
|
|
00066 { 00067 _sag = _in; 00068 }
|
|
|
|
00072 { 00073 _tof = _in; 00074 }
|
|
|
|
|
|
|