14 |
void dotrack2_(int*, double*, double*, double*, double*,double*, double*, double*,int*); |
void dotrack2_(int*, double*, double*, double*, double*,double*, double*, double*,int*); |
15 |
int readb_(const char*); |
int readb_(const char*); |
16 |
void mini2_(int*,int*,int*); |
void mini2_(int*,int*,int*); |
17 |
|
void guess_(); |
18 |
} |
} |
19 |
//-------------------------------------- |
//-------------------------------------- |
20 |
// |
// |
256 |
* Tracking method. It calls F77 mini routine. |
* Tracking method. It calls F77 mini routine. |
257 |
*/ |
*/ |
258 |
void TrkTrack::Fit(double pfixed, int& fail, int iprint){ |
void TrkTrack::Fit(double pfixed, int& fail, int iprint){ |
259 |
|
|
260 |
|
float al_ini[] = {0.,0.,0.,0.,0.}; |
261 |
|
|
262 |
extern cMini2track track_; |
extern cMini2track track_; |
263 |
fail = 0; |
fail = 0; |
264 |
// extern cMini2fitinfo fit_info_; |
// extern cMini2fitinfo fit_info_; |
265 |
// extern void mini_2_(int*,int*); |
// extern void mini_2_(int*,int*); |
266 |
// track_.xm[0]=1.0; |
// track_.xm[0]=1.0; |
267 |
|
|
268 |
|
cout << "fitting routine "<<endl; |
269 |
|
|
270 |
for(int i=0; i<6; i++) track_.xm[i]=xm[i]; |
for(int i=0; i<6; i++) track_.xm[i]=xm[i]; |
271 |
for(int i=0; i<6; i++) track_.ym[i]=ym[i]; |
for(int i=0; i<6; i++) track_.ym[i]=ym[i]; |
272 |
for(int i=0; i<6; i++) track_.zm[i]=zm[i]; |
for(int i=0; i<6; i++) track_.zm[i]=zm[i]; |
274 |
for(int i=0; i<6; i++) track_.resy[i]=resy[i]; |
for(int i=0; i<6; i++) track_.resy[i]=resy[i]; |
275 |
for(int i=0; i<6; i++) track_.xgood[i]=xgood[i]; |
for(int i=0; i<6; i++) track_.xgood[i]=xgood[i]; |
276 |
for(int i=0; i<6; i++) track_.ygood[i]=ygood[i]; |
for(int i=0; i<6; i++) track_.ygood[i]=ygood[i]; |
277 |
|
|
278 |
// initial guess of "al" with linear fit |
// initial guess of "al" with linear fit |
279 |
if(al[0]==-9999.&&al[1]==-9999.&&al[2]==-9999.&&al[3]==-9999.&&al[4]==-9999.){ |
// if(al[0]==-9999.&&al[1]==-9999.&&al[2]==-9999.&&al[3]==-9999.&&al[4]==-9999.){ |
280 |
double szz=0., szx=0., szy=0., ssx=0., ssy=0., sz=0., s1=0.; |
|
281 |
double det, ax, ay, bx, by; |
// cout << "initial guess "<<endl; |
282 |
for(int i=0; i<NPLANE; i++) { |
|
283 |
szz=szz+zm[i]*zm[i]; |
// double szz=0., szx=0., szy=0., ssx=0., ssy=0., sz=0., s1=0.; |
284 |
szx=szx+zm[i]*xm[i]; |
// double det, ax, ay, bx, by; |
285 |
szy=szy+zm[i]*ym[i]; |
// for(int i=0; i<NPLANE; i++) { |
286 |
ssx=ssx+xm[i]; |
// szz=szz+zm[i]*zm[i]; |
287 |
ssy=ssy+ym[i]; |
// szx=szx+zm[i]*xm[i]; |
288 |
sz=sz+zm[i]; |
// szy=szy+zm[i]*ym[i]; |
289 |
s1=s1+1.; |
// ssx=ssx+xm[i]; |
290 |
} |
// ssy=ssy+ym[i]; |
291 |
det=szz*s1-sz*sz; |
// sz=sz+zm[i]; |
292 |
ax=(szx*s1-sz*ssx)/det; |
// s1=s1+1.; |
293 |
bx=(szz*ssx-szx*sz)/det; |
// } |
294 |
ay=(szy*s1-sz*ssy)/det; |
// det=szz*s1-sz*sz; |
295 |
by=(szz*ssy-szy*sz)/det; |
// ax=(szx*s1-sz*ssx)/det; |
296 |
al[0]=ax*23.5+bx; // ZINI = 23.5 !!! it should be the same parameter in all codes |
// bx=(szz*ssx-szx*sz)/det; |
297 |
al[1]=ay*23.5+by; // " |
// ay=(szy*s1-sz*ssy)/det; |
298 |
al[2]= sqrt(pow(ax,2)+pow(ay,2))/ sqrt(pow(ax,2)+pow(ay,2)+1.); |
// by=(szz*ssy-szy*sz)/det; |
299 |
al[3]=0.; |
// al[0]=ax*23.5+bx; // ZINI = 23.5 !!! it should be the same parameter in all codes |
300 |
if( (ax!=0.)||(ay!=0.) ) { |
// al[1]=ay*23.5+by; // " |
301 |
al[3]= asin(ay/ sqrt(pow(ax,2)+pow(ay,2))); |
// al[2]= sqrt(pow(ax,2)+pow(ay,2))/ sqrt(pow(ax,2)+pow(ay,2)+1.); |
302 |
if(ax<0.) al[3]=acos(-1.)-al[3]; |
// al[3]=0.; |
303 |
} |
// if( (ax!=0.)||(ay!=0.) ) { |
304 |
al[4]=0.; |
// al[3]= asin(ay/ sqrt(pow(ax,2)+pow(ay,2))); |
305 |
} |
// if(ax<0.) al[3]=acos(-1.)-al[3]; |
306 |
|
// } |
307 |
|
// al[4]=0.; |
308 |
|
|
309 |
|
// } |
310 |
// end guess |
// end guess |
311 |
|
for(int i=0; i<5; i++) track_.al[i]=al[i]; |
312 |
|
track_.zini = 23.5; // ZINI = 23.5 !!! it should be the same parameter in all codes |
313 |
|
|
314 |
|
// elena ----- |
315 |
|
if(al[0]==-9999.&&al[1]==-9999.&&al[2]==-9999.&&al[3]==-9999.&&al[4]==-9999.)guess_(); |
316 |
|
// elena ----- |
317 |
|
|
318 |
if(pfixed==0.) { |
if(pfixed==0.) { |
319 |
al[4]=0.; // free momentum |
// al[4]=0.; // free momentum |
320 |
track_.pfixed=0.; // " |
track_.pfixed=0.; // " |
321 |
} |
} |
322 |
if(pfixed!=0.) { |
if(pfixed!=0.) { |
323 |
al[4]=1./pfixed; // to fix the momentum |
al[4]=1./pfixed; // to fix the momentum |
324 |
track_.pfixed=pfixed; // " |
track_.pfixed=pfixed; // " |
325 |
} |
} |
326 |
track_.zini = 23.5; // ZINI = 23.5 !!! it should be the same parameter in all codes |
|
327 |
for(int i=0; i<5; i++) track_.al[i]=al[i]; |
// store temporarily the initial guess |
328 |
|
for(int i=0; i<5; i++) al_ini[i]=track_.al[i]; |
329 |
|
|
330 |
|
|
331 |
int istep=0; |
int istep=0; |
332 |
int ifail=0; |
int ifail=0; |
333 |
mini2_(&istep,&ifail, &iprint); |
mini2_(&istep,&ifail, &iprint); |
336 |
fail = 1; |
fail = 1; |
337 |
// return; |
// return; |
338 |
} |
} |
339 |
|
|
340 |
|
|
341 |
// cout << endl << "eta ===> " << track_.al[4] << endl; |
// cout << endl << "eta ===> " << track_.al[4] << endl; |
342 |
|
|
351 |
for(int i=0; i<5; i++) { |
for(int i=0; i<5; i++) { |
352 |
for(int j=0; j<5; j++) coval[i][j]=track_.cov[i][j]; |
for(int j=0; j<5; j++) coval[i][j]=track_.cov[i][j]; |
353 |
} |
} |
354 |
|
|
355 |
|
if(fail){ |
356 |
|
cout << " >>>> fit failed >>>> drawing initial par"<<endl; |
357 |
|
for(int i=0; i<5; i++) al[i]=al_ini[i]; |
358 |
|
} |
359 |
|
|
360 |
}; |
}; |
361 |
/* |
/* |
362 |
* Reset the parameters fit |
* Reset the fit parameters |
363 |
*/ |
*/ |
364 |
void TrkTrack::FitReset(){ |
void TrkTrack::FitReset(){ |
365 |
for(int i=0; i<5; i++) al[i]=-9999.; |
for(int i=0; i<5; i++) al[i]=-9999.; |