4 |
*/ |
*/ |
5 |
#include <TrkLevel2.h> |
#include <TrkLevel2.h> |
6 |
#include <iostream> |
#include <iostream> |
7 |
|
#include <math.h> |
8 |
using namespace std; |
using namespace std; |
9 |
//...................................... |
//...................................... |
10 |
// F77 routines |
// F77 routines |
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 |
// |
// |
24 |
seqno = -1; |
seqno = -1; |
25 |
image = -1; |
image = -1; |
26 |
chi2 = 0; |
chi2 = 0; |
27 |
nstep = 0; |
nstep = 0; |
28 |
for(int it1=0;it1<5;it1++){ |
for(int it1=0;it1<5;it1++){ |
29 |
al[it1] = 0; |
al[it1] = 0; |
30 |
for(int it2=0;it2<5;it2++)coval[it1][it2] = 0; |
for(int it2=0;it2<5;it2++)coval[it1][it2] = 0; |
31 |
}; |
}; |
32 |
for(int ip=0;ip<6;ip++){ |
for(int ip=0;ip<6;ip++){ |
33 |
xgood[ip] = 0; |
xgood[ip] = 0; |
58 |
seqno = t.seqno; |
seqno = t.seqno; |
59 |
image = t.image; |
image = t.image; |
60 |
chi2 = t.chi2; |
chi2 = t.chi2; |
61 |
nstep = t.nstep; |
nstep = t.nstep; |
62 |
for(int it1=0;it1<5;it1++){ |
for(int it1=0;it1<5;it1++){ |
63 |
al[it1] = t.al[it1]; |
al[it1] = t.al[it1]; |
64 |
for(int it2=0;it2<5;it2++)coval[it1][it2] = t.coval[it1][it2]; |
for(int it2=0;it2<5;it2++)coval[it1][it2] = t.coval[it1][it2]; |
65 |
}; |
}; |
66 |
for(int ip=0;ip<6;ip++){ |
for(int ip=0;ip<6;ip++){ |
67 |
xgood[ip] = t.xgood[ip]; |
xgood[ip] = t.xgood[ip]; |
221 |
cout << endl << " "; for(int i=0; i<5; i++)cout << coval[4][i]<<" "; |
cout << endl << " "; for(int i=0; i<5; i++)cout << coval[4][i]<<" "; |
222 |
cout << endl << "dedx_x : "; for(int i=0; i<6; i++)cout << dedx_x[i] << " "; |
cout << endl << "dedx_x : "; for(int i=0; i<6; i++)cout << dedx_x[i] << " "; |
223 |
cout << endl << "dedx_y : "; for(int i=0; i<6; i++)cout << dedx_y[i] << " "; |
cout << endl << "dedx_y : "; for(int i=0; i<6; i++)cout << dedx_y[i] << " "; |
224 |
|
cout << endl; |
225 |
} |
} |
226 |
/** |
/** |
227 |
* Set the TrkTrack position measurements |
* Set the TrkTrack position measurements |
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]; |
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.) { |
319 |
|
// al[4]=0.; // free momentum |
320 |
|
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 |
|
|
327 |
|
// 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.; |