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 |
12 |
extern "C" { |
extern "C" { |
13 |
void dotrack_(int*, double*, double*, double*, double*, int*); |
void dotrack_(int*, double*, double*, double*, double*, int*); |
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 |
|
int readb_(); |
17 |
void mini2_(int*,int*,int*); |
void mini2_(int*,int*,int*); |
18 |
|
void guess_(); |
19 |
} |
} |
20 |
//-------------------------------------- |
//-------------------------------------- |
21 |
// |
// |
25 |
seqno = -1; |
seqno = -1; |
26 |
image = -1; |
image = -1; |
27 |
chi2 = 0; |
chi2 = 0; |
28 |
nstep = 0; |
nstep = 0; |
29 |
for(int it1=0;it1<5;it1++){ |
for(int it1=0;it1<5;it1++){ |
30 |
al[it1] = 0; |
al[it1] = 0; |
31 |
for(int it2=0;it2<5;it2++)coval[it1][it2] = 0; |
for(int it2=0;it2<5;it2++)coval[it1][it2] = 0; |
32 |
}; |
}; |
33 |
for(int ip=0;ip<6;ip++){ |
for(int ip=0;ip<6;ip++){ |
34 |
xgood[ip] = 0; |
xgood[ip] = 0; |
59 |
seqno = t.seqno; |
seqno = t.seqno; |
60 |
image = t.image; |
image = t.image; |
61 |
chi2 = t.chi2; |
chi2 = t.chi2; |
62 |
nstep = t.nstep; |
nstep = t.nstep; |
63 |
for(int it1=0;it1<5;it1++){ |
for(int it1=0;it1<5;it1++){ |
64 |
al[it1] = t.al[it1]; |
al[it1] = t.al[it1]; |
65 |
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]; |
66 |
}; |
}; |
67 |
for(int ip=0;ip<6;ip++){ |
for(int ip=0;ip<6;ip++){ |
68 |
xgood[ip] = t.xgood[ip]; |
xgood[ip] = t.xgood[ip]; |
222 |
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]<<" "; |
223 |
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] << " "; |
224 |
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] << " "; |
225 |
|
cout << endl; |
226 |
} |
} |
227 |
/** |
/** |
228 |
* Set the TrkTrack position measurements |
* Set the TrkTrack position measurements |
250 |
/** |
/** |
251 |
* Load the magnetic field |
* Load the magnetic field |
252 |
*/ |
*/ |
253 |
void TrkTrack::LoadField(TString s){ |
void TrkTrack::LoadField(TString path){ |
254 |
readb_(s.Data()); |
|
255 |
|
strcpy(path_.path,path.Data()); |
256 |
|
path_.pathlen = path.Length(); |
257 |
|
path_.error = 0; |
258 |
|
readb_(); |
259 |
|
|
260 |
}; |
}; |
261 |
/** |
/** |
262 |
* Tracking method. It calls F77 mini routine. |
* Tracking method. It calls F77 mini routine. |
263 |
*/ |
*/ |
264 |
void TrkTrack::Fit(double pfixed, int& fail, int iprint){ |
void TrkTrack::Fit(double pfixed, int& fail, int iprint){ |
265 |
|
|
266 |
|
float al_ini[] = {0.,0.,0.,0.,0.}; |
267 |
|
|
268 |
extern cMini2track track_; |
extern cMini2track track_; |
269 |
fail = 0; |
fail = 0; |
270 |
// extern cMini2fitinfo fit_info_; |
|
|
// extern void mini_2_(int*,int*); |
|
|
// track_.xm[0]=1.0; |
|
271 |
for(int i=0; i<6; i++) track_.xm[i]=xm[i]; |
for(int i=0; i<6; i++) track_.xm[i]=xm[i]; |
272 |
for(int i=0; i<6; i++) track_.ym[i]=ym[i]; |
for(int i=0; i<6; i++) track_.ym[i]=ym[i]; |
273 |
for(int i=0; i<6; i++) track_.zm[i]=zm[i]; |
for(int i=0; i<6; i++) track_.zm[i]=zm[i]; |
275 |
for(int i=0; i<6; i++) track_.resy[i]=resy[i]; |
for(int i=0; i<6; i++) track_.resy[i]=resy[i]; |
276 |
for(int i=0; i<6; i++) track_.xgood[i]=xgood[i]; |
for(int i=0; i<6; i++) track_.xgood[i]=xgood[i]; |
277 |
for(int i=0; i<6; i++) track_.ygood[i]=ygood[i]; |
for(int i=0; i<6; i++) track_.ygood[i]=ygood[i]; |
278 |
|
|
279 |
// initial guess of "al" with linear fit |
// initial guess of "al" with linear fit |
280 |
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.){ |
281 |
double szz=0., szx=0., szy=0., ssx=0., ssy=0., sz=0., s1=0.; |
// cout << "initial guess "<<endl; |
282 |
double det, ax, ay, bx, by; |
// double szz=0., szx=0., szy=0., ssx=0., ssy=0., sz=0., s1=0.; |
283 |
for(int i=0; i<NPLANE; i++) { |
// double det, ax, ay, bx, by; |
284 |
szz=szz+zm[i]*zm[i]; |
// for(int i=0; i<NPLANE; i++) { |
285 |
szx=szx+zm[i]*xm[i]; |
// szz=szz+zm[i]*zm[i]; |
286 |
szy=szy+zm[i]*ym[i]; |
// szx=szx+zm[i]*xm[i]; |
287 |
ssx=ssx+xm[i]; |
// szy=szy+zm[i]*ym[i]; |
288 |
ssy=ssy+ym[i]; |
// ssx=ssx+xm[i]; |
289 |
sz=sz+zm[i]; |
// ssy=ssy+ym[i]; |
290 |
s1=s1+1.; |
// sz=sz+zm[i]; |
291 |
} |
// s1=s1+1.; |
292 |
det=szz*s1-sz*sz; |
// } |
293 |
ax=(szx*s1-sz*ssx)/det; |
// det=szz*s1-sz*sz; |
294 |
bx=(szz*ssx-szx*sz)/det; |
// ax=(szx*s1-sz*ssx)/det; |
295 |
ay=(szy*s1-sz*ssy)/det; |
// bx=(szz*ssx-szx*sz)/det; |
296 |
by=(szz*ssy-szy*sz)/det; |
// ay=(szy*s1-sz*ssy)/det; |
297 |
al[0]=ax*23.5+bx; // ZINI = 23.5 !!! it should be the same parameter in all codes |
// by=(szz*ssy-szy*sz)/det; |
298 |
al[1]=ay*23.5+by; // " |
// al[0]=ax*23.5+bx; // ZINI = 23.5 !!! it should be the same parameter in all codes |
299 |
al[2]= sqrt(pow(ax,2)+pow(ay,2))/ sqrt(pow(ax,2)+pow(ay,2)+1.); |
// al[1]=ay*23.5+by; // " |
300 |
al[3]=0.; |
// al[2]= sqrt(pow(ax,2)+pow(ay,2))/ sqrt(pow(ax,2)+pow(ay,2)+1.); |
301 |
if( (ax!=0.)||(ay!=0.) ) { |
// al[3]=0.; |
302 |
al[3]= asin(ay/ sqrt(pow(ax,2)+pow(ay,2))); |
// if( (ax!=0.)||(ay!=0.) ) { |
303 |
if(ax<0.) al[3]=acos(-1.)-al[3]; |
// al[3]= asin(ay/ sqrt(pow(ax,2)+pow(ay,2))); |
304 |
} |
// if(ax<0.) al[3]=acos(-1.)-al[3]; |
305 |
al[4]=0.; |
// } |
306 |
} |
// al[4]=0.; |
307 |
|
// } |
308 |
// end guess |
// end guess |
309 |
for(int i=0; i<5; i++) track_.al[i]=al[i]; |
|
310 |
|
for(int i=0; i<5; i++) track_.al[i]=al[i]; |
311 |
|
track_.zini = 23.5; |
312 |
|
// ZINI = 23.5 !!! it should be the same parameter in all codes |
313 |
|
|
314 |
|
if(al[0]==-9999.&&al[1]==-9999.&&al[2]==-9999.&&al[3]==-9999.&&al[4]==-9999.)guess_(); |
315 |
|
|
316 |
|
// --------------------- free momentum |
317 |
|
if(pfixed==0.) { |
318 |
|
// al[4]=0.; // free momentum |
319 |
|
track_.pfixed=0.; // " |
320 |
|
} |
321 |
|
// --------------------- fixed momentum |
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.; |
943 |
* Loads the magnetic field. |
* Loads the magnetic field. |
944 |
* @param s Path of the magnetic-field files. |
* @param s Path of the magnetic-field files. |
945 |
*/ |
*/ |
946 |
void TrkLevel2::LoadField(TString s){ |
void TrkLevel2::LoadField(TString path){ |
947 |
readb_(s.Data()); |
// |
948 |
|
strcpy(path_.path,path.Data()); |
949 |
|
path_.pathlen = path.Length(); |
950 |
|
path_.error = 0; |
951 |
|
readb_(); |
952 |
|
// |
953 |
}; |
}; |
954 |
//-------------------------------------- |
//-------------------------------------- |
955 |
// |
// |