| 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 |
// |
// |
| 22 |
// |
// |
| 23 |
//-------------------------------------- |
//-------------------------------------- |
| 24 |
|
/** |
| 25 |
|
* Evaluates the trajectory in the apparatus associated to the track. |
| 26 |
|
* It integrates the equations of motion in the magnetic field. The magnetic field should be previously loaded ( by calling TrkLevel2::LoadField() ), otherwise an error message is returned. |
| 27 |
|
* @param t pointer to an object of the class Trajectory, |
| 28 |
|
* which z coordinates should be previously initialized by calling the proper constructor ( Trajectory::Trajectory(int n, float* zin) ). |
| 29 |
|
* @return error flag. |
| 30 |
|
*/ |
| 31 |
|
int Trajectory::DoTrack2(float* al){ |
| 32 |
|
|
| 33 |
|
double *dxout = new double[t->npoint]; |
| 34 |
|
double *dyout = new double[t->npoint]; |
| 35 |
|
double *dthxout = new double[t->npoint]; |
| 36 |
|
double *dthyout = new double[t->npoint]; |
| 37 |
|
double *dtlout = new double[t->npoint]; |
| 38 |
|
double *dzin = new double[t->npoint]; |
| 39 |
|
double dal[5]; |
| 40 |
|
|
| 41 |
|
int ifail = 0; |
| 42 |
|
|
| 43 |
|
for (int i=0; i<5; i++) dal[i] = (double)al[i]; |
| 44 |
|
for (int i=0; i<t->npoint; i++) dzin[i] = (double)z[i]; |
| 45 |
|
|
| 46 |
|
dotrack2_(&(t->npoint),dzin,dxout,dyout,dthxout,dthyout,dtlout,dal,&ifail); |
| 47 |
|
|
| 48 |
|
for (int i=0; i<t->npoint; i++){ |
| 49 |
|
x[i] = (float)*dxout++; |
| 50 |
|
y[i] = (float)*dyout++; |
| 51 |
|
thx[i] = (float)*dthxout++; |
| 52 |
|
thy[i] = (float)*dthyout++; |
| 53 |
|
tl[i] = (float)*dtlout++; |
| 54 |
|
} |
| 55 |
|
|
| 56 |
|
return ifail; |
| 57 |
|
}; |
| 58 |
|
//--------------------------------------------- |
| 59 |
|
//--------------------------------------------- |
| 60 |
TrkTrack::TrkTrack(){ |
TrkTrack::TrkTrack(){ |
| 61 |
seqno = -1; |
seqno = -1; |
| 62 |
image = -1; |
image = -1; |
| 63 |
chi2 = 0; |
chi2 = 0; |
| 64 |
nstep = 0; |
nstep = 0; |
| 65 |
for(int it1=0;it1<5;it1++){ |
for(int it1=0;it1<5;it1++){ |
| 66 |
al[it1] = 0; |
al[it1] = 0; |
| 67 |
for(int it2=0;it2<5;it2++)coval[it1][it2] = 0; |
for(int it2=0;it2<5;it2++)coval[it1][it2] = 0; |
| 68 |
}; |
}; |
| 69 |
for(int ip=0;ip<6;ip++){ |
for(int ip=0;ip<6;ip++){ |
| 70 |
xgood[ip] = 0; |
xgood[ip] = 0; |
| 95 |
seqno = t.seqno; |
seqno = t.seqno; |
| 96 |
image = t.image; |
image = t.image; |
| 97 |
chi2 = t.chi2; |
chi2 = t.chi2; |
| 98 |
nstep = t.nstep; |
nstep = t.nstep; |
| 99 |
for(int it1=0;it1<5;it1++){ |
for(int it1=0;it1<5;it1++){ |
| 100 |
al[it1] = t.al[it1]; |
al[it1] = t.al[it1]; |
| 101 |
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]; |
| 102 |
}; |
}; |
| 103 |
for(int ip=0;ip<6;ip++){ |
for(int ip=0;ip<6;ip++){ |
| 104 |
xgood[ip] = t.xgood[ip]; |
xgood[ip] = t.xgood[ip]; |
| 258 |
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]<<" "; |
| 259 |
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] << " "; |
| 260 |
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] << " "; |
| 261 |
|
cout << endl; |
| 262 |
} |
} |
| 263 |
/** |
/** |
| 264 |
* Set the TrkTrack position measurements |
* Set the TrkTrack position measurements |
| 286 |
/** |
/** |
| 287 |
* Load the magnetic field |
* Load the magnetic field |
| 288 |
*/ |
*/ |
| 289 |
void TrkTrack::LoadField(TString s){ |
void TrkTrack::LoadField(TString path){ |
| 290 |
readb_(s.Data()); |
|
| 291 |
|
strcpy(path_.path,path.Data()); |
| 292 |
|
path_.pathlen = path.Length(); |
| 293 |
|
path_.error = 0; |
| 294 |
|
readb_(); |
| 295 |
|
|
| 296 |
}; |
}; |
| 297 |
/** |
/** |
| 298 |
* Tracking method. It calls F77 mini routine. |
* Tracking method. It calls F77 mini routine. |
| 299 |
*/ |
*/ |
| 300 |
void TrkTrack::Fit(double pfixed, int& fail, int iprint){ |
void TrkTrack::Fit(double pfixed, int& fail, int iprint){ |
| 301 |
|
|
| 302 |
|
float al_ini[] = {0.,0.,0.,0.,0.}; |
| 303 |
|
|
| 304 |
extern cMini2track track_; |
extern cMini2track track_; |
| 305 |
fail = 0; |
fail = 0; |
| 306 |
// extern cMini2fitinfo fit_info_; |
|
|
// extern void mini_2_(int*,int*); |
|
|
// track_.xm[0]=1.0; |
|
| 307 |
for(int i=0; i<6; i++) track_.xm[i]=xm[i]; |
for(int i=0; i<6; i++) track_.xm[i]=xm[i]; |
| 308 |
for(int i=0; i<6; i++) track_.ym[i]=ym[i]; |
for(int i=0; i<6; i++) track_.ym[i]=ym[i]; |
| 309 |
for(int i=0; i<6; i++) track_.zm[i]=zm[i]; |
for(int i=0; i<6; i++) track_.zm[i]=zm[i]; |
| 311 |
for(int i=0; i<6; i++) track_.resy[i]=resy[i]; |
for(int i=0; i<6; i++) track_.resy[i]=resy[i]; |
| 312 |
for(int i=0; i<6; i++) track_.xgood[i]=xgood[i]; |
for(int i=0; i<6; i++) track_.xgood[i]=xgood[i]; |
| 313 |
for(int i=0; i<6; i++) track_.ygood[i]=ygood[i]; |
for(int i=0; i<6; i++) track_.ygood[i]=ygood[i]; |
| 314 |
|
|
| 315 |
// initial guess of "al" with linear fit |
// initial guess of "al" with linear fit |
| 316 |
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.){ |
| 317 |
double szz=0., szx=0., szy=0., ssx=0., ssy=0., sz=0., s1=0.; |
// cout << "initial guess "<<endl; |
| 318 |
double det, ax, ay, bx, by; |
// double szz=0., szx=0., szy=0., ssx=0., ssy=0., sz=0., s1=0.; |
| 319 |
for(int i=0; i<NPLANE; i++) { |
// double det, ax, ay, bx, by; |
| 320 |
szz=szz+zm[i]*zm[i]; |
// for(int i=0; i<NPLANE; i++) { |
| 321 |
szx=szx+zm[i]*xm[i]; |
// szz=szz+zm[i]*zm[i]; |
| 322 |
szy=szy+zm[i]*ym[i]; |
// szx=szx+zm[i]*xm[i]; |
| 323 |
ssx=ssx+xm[i]; |
// szy=szy+zm[i]*ym[i]; |
| 324 |
ssy=ssy+ym[i]; |
// ssx=ssx+xm[i]; |
| 325 |
sz=sz+zm[i]; |
// ssy=ssy+ym[i]; |
| 326 |
s1=s1+1.; |
// sz=sz+zm[i]; |
| 327 |
} |
// s1=s1+1.; |
| 328 |
det=szz*s1-sz*sz; |
// } |
| 329 |
ax=(szx*s1-sz*ssx)/det; |
// det=szz*s1-sz*sz; |
| 330 |
bx=(szz*ssx-szx*sz)/det; |
// ax=(szx*s1-sz*ssx)/det; |
| 331 |
ay=(szy*s1-sz*ssy)/det; |
// bx=(szz*ssx-szx*sz)/det; |
| 332 |
by=(szz*ssy-szy*sz)/det; |
// ay=(szy*s1-sz*ssy)/det; |
| 333 |
al[0]=ax*23.5+bx; // ZINI = 23.5 !!! it should be the same parameter in all codes |
// by=(szz*ssy-szy*sz)/det; |
| 334 |
al[1]=ay*23.5+by; // " |
// al[0]=ax*23.5+bx; // ZINI = 23.5 !!! it should be the same parameter in all codes |
| 335 |
al[2]= sqrt(pow(ax,2)+pow(ay,2))/ sqrt(pow(ax,2)+pow(ay,2)+1.); |
// al[1]=ay*23.5+by; // " |
| 336 |
al[3]=0.; |
// al[2]= sqrt(pow(ax,2)+pow(ay,2))/ sqrt(pow(ax,2)+pow(ay,2)+1.); |
| 337 |
if( (ax!=0.)||(ay!=0.) ) { |
// al[3]=0.; |
| 338 |
al[3]= asin(ay/ sqrt(pow(ax,2)+pow(ay,2))); |
// if( (ax!=0.)||(ay!=0.) ) { |
| 339 |
if(ax<0.) al[3]=acos(-1.)-al[3]; |
// al[3]= asin(ay/ sqrt(pow(ax,2)+pow(ay,2))); |
| 340 |
} |
// if(ax<0.) al[3]=acos(-1.)-al[3]; |
| 341 |
al[4]=0.; |
// } |
| 342 |
} |
// al[4]=0.; |
| 343 |
|
// } |
| 344 |
// end guess |
// end guess |
| 345 |
for(int i=0; i<5; i++) track_.al[i]=al[i]; |
|
| 346 |
|
for(int i=0; i<5; i++) track_.al[i]=al[i]; |
| 347 |
|
track_.zini = 23.5; |
| 348 |
|
// ZINI = 23.5 !!! it should be the same parameter in all codes |
| 349 |
|
|
| 350 |
|
if(al[0]==-9999.&&al[1]==-9999.&&al[2]==-9999.&&al[3]==-9999.&&al[4]==-9999.)guess_(); |
| 351 |
|
|
| 352 |
|
// --------------------- free momentum |
| 353 |
|
if(pfixed==0.) { |
| 354 |
|
// al[4]=0.; // free momentum |
| 355 |
|
track_.pfixed=0.; // " |
| 356 |
|
} |
| 357 |
|
// --------------------- fixed momentum |
| 358 |
if(pfixed!=0.) { |
if(pfixed!=0.) { |
| 359 |
al[4]=1./pfixed; // to fix the momentum |
al[4]=1./pfixed; // to fix the momentum |
| 360 |
track_.pfixed=pfixed; // " |
track_.pfixed=pfixed; // " |
| 361 |
} |
} |
| 362 |
|
|
| 363 |
|
// store temporarily the initial guess |
| 364 |
|
for(int i=0; i<5; i++) al_ini[i]=track_.al[i]; |
| 365 |
|
|
| 366 |
|
|
| 367 |
int istep=0; |
int istep=0; |
| 368 |
int ifail=0; |
int ifail=0; |
| 369 |
mini2_(&istep,&ifail, &iprint); |
mini2_(&istep,&ifail, &iprint); |
| 372 |
fail = 1; |
fail = 1; |
| 373 |
// return; |
// return; |
| 374 |
} |
} |
| 375 |
|
|
| 376 |
|
|
| 377 |
// cout << endl << "eta ===> " << track_.al[4] << endl; |
// cout << endl << "eta ===> " << track_.al[4] << endl; |
| 378 |
|
|
| 387 |
for(int i=0; i<5; i++) { |
for(int i=0; i<5; i++) { |
| 388 |
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]; |
| 389 |
} |
} |
| 390 |
|
|
| 391 |
|
if(fail){ |
| 392 |
|
cout << " >>>> fit failed >>>> drawing initial par"<<endl; |
| 393 |
|
for(int i=0; i<5; i++) al[i]=al_ini[i]; |
| 394 |
|
} |
| 395 |
|
|
| 396 |
}; |
}; |
| 397 |
/* |
/* |
| 398 |
* Reset the parameters fit |
* Reset the fit parameters |
| 399 |
*/ |
*/ |
| 400 |
void TrkTrack::FitReset(){ |
void TrkTrack::FitReset(){ |
| 401 |
for(int i=0; i<5; i++) al[i]=-9999.; |
for(int i=0; i<5; i++) al[i]=-9999.; |
| 979 |
* Loads the magnetic field. |
* Loads the magnetic field. |
| 980 |
* @param s Path of the magnetic-field files. |
* @param s Path of the magnetic-field files. |
| 981 |
*/ |
*/ |
| 982 |
void TrkLevel2::LoadField(TString s){ |
void TrkLevel2::LoadField(TString path){ |
| 983 |
readb_(s.Data()); |
// |
| 984 |
|
strcpy(path_.path,path.Data()); |
| 985 |
|
path_.pathlen = path.Length(); |
| 986 |
|
path_.error = 0; |
| 987 |
|
readb_(); |
| 988 |
|
// |
| 989 |
}; |
}; |
| 990 |
//-------------------------------------- |
//-------------------------------------- |
| 991 |
// |
// |