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_(); |
void guess_(); |
19 |
} |
} |
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 |
|
/** |
263 |
|
* Method to fill minimization-routine common |
264 |
|
*/ |
265 |
|
void TrkTrack::FillMiniStruct(cMini2track& track){ |
266 |
|
|
267 |
|
for(int i=0; i<6; i++){ |
268 |
|
|
269 |
|
track.xgood[i]=xgood[i]; |
270 |
|
track.ygood[i]=ygood[i]; |
271 |
|
|
272 |
|
track.xm[i]=xm[i]; |
273 |
|
track.ym[i]=ym[i]; |
274 |
|
track.zm[i]=zm[i]; |
275 |
|
|
276 |
|
// --- temporaneo ---------------------------- |
277 |
|
// andrebbe inserita la dimensione del sensore |
278 |
|
float segment = 100.; |
279 |
|
track.xm_a[i]=xm[i]; |
280 |
|
track.xm_b[i]=xm[i]; |
281 |
|
track.ym_a[i]=ym[i]; |
282 |
|
track.ym_b[i]=ym[i]; |
283 |
|
if( xgood[i] && !ygood[i] ){ |
284 |
|
track.ym_a[i] = track.ym_a[i]+segment; |
285 |
|
track.ym_b[i] = track.ym_b[i]-segment; |
286 |
|
}else if( !xgood[i] && ygood[i]){ |
287 |
|
track.xm_a[i] = track.xm_a[i]+segment; |
288 |
|
track.xm_b[i] = track.xm_b[i]-segment; |
289 |
|
} |
290 |
|
// --- temporaneo ---------------------------- |
291 |
|
|
292 |
|
track.resx[i]=resx[i]; |
293 |
|
track.resy[i]=resy[i]; |
294 |
|
} |
295 |
|
|
296 |
|
for(int i=0; i<5; i++) track.al[i]=al[i]; |
297 |
|
track.zini = 23.5; |
298 |
|
// ZINI = 23.5 !!! it should be the same parameter in all codes |
299 |
|
|
300 |
|
} |
301 |
|
/** |
302 |
|
* Method to set values from minimization-routine common |
303 |
|
*/ |
304 |
|
void TrkTrack::SetFromMiniStruct(cMini2track *track){ |
305 |
|
|
306 |
|
for(int i=0; i<5; i++) { |
307 |
|
al[i]=track->al[i]; |
308 |
|
for(int j=0; j<5; j++) coval[i][j]=track->cov[i][j]; |
309 |
|
} |
310 |
|
chi2 = track->chi2; |
311 |
|
nstep = track->nstep; |
312 |
|
for(int i=0; i<6; i++){ |
313 |
|
xv[i] = track->xv[i]; |
314 |
|
yv[i] = track->yv[i]; |
315 |
|
zv[i] = track->zv[i]; |
316 |
|
xm[i] = track->xm[i]; |
317 |
|
ym[i] = track->ym[i]; |
318 |
|
zm[i] = track->zm[i]; |
319 |
|
axv[i] = track->axv[i]; |
320 |
|
ayv[i] = track->ayv[i]; |
321 |
|
} |
322 |
|
|
323 |
|
|
324 |
|
} |
325 |
/** |
/** |
326 |
* Tracking method. It calls F77 mini routine. |
* Tracking method. It calls F77 mini routine. |
327 |
*/ |
*/ |
331 |
|
|
332 |
extern cMini2track track_; |
extern cMini2track track_; |
333 |
fail = 0; |
fail = 0; |
334 |
// extern cMini2fitinfo fit_info_; |
FillMiniStruct(track_); |
|
// extern void mini_2_(int*,int*); |
|
|
// track_.xm[0]=1.0; |
|
|
|
|
|
cout << "fitting routine "<<endl; |
|
|
|
|
|
for(int i=0; i<6; i++) track_.xm[i]=xm[i]; |
|
|
for(int i=0; i<6; i++) track_.ym[i]=ym[i]; |
|
|
for(int i=0; i<6; i++) track_.zm[i]=zm[i]; |
|
|
for(int i=0; i<6; i++) track_.resx[i]=resx[i]; |
|
|
for(int i=0; i<6; i++) track_.resy[i]=resy[i]; |
|
|
for(int i=0; i<6; i++) track_.xgood[i]=xgood[i]; |
|
|
for(int i=0; i<6; i++) track_.ygood[i]=ygood[i]; |
|
|
|
|
|
// initial guess of "al" with linear fit |
|
|
// if(al[0]==-9999.&&al[1]==-9999.&&al[2]==-9999.&&al[3]==-9999.&&al[4]==-9999.){ |
|
|
|
|
|
// cout << "initial guess "<<endl; |
|
|
|
|
|
// double szz=0., szx=0., szy=0., ssx=0., ssy=0., sz=0., s1=0.; |
|
|
// double det, ax, ay, bx, by; |
|
|
// for(int i=0; i<NPLANE; i++) { |
|
|
// szz=szz+zm[i]*zm[i]; |
|
|
// szx=szx+zm[i]*xm[i]; |
|
|
// szy=szy+zm[i]*ym[i]; |
|
|
// ssx=ssx+xm[i]; |
|
|
// ssy=ssy+ym[i]; |
|
|
// sz=sz+zm[i]; |
|
|
// s1=s1+1.; |
|
|
// } |
|
|
// det=szz*s1-sz*sz; |
|
|
// ax=(szx*s1-sz*ssx)/det; |
|
|
// bx=(szz*ssx-szx*sz)/det; |
|
|
// ay=(szy*s1-sz*ssy)/det; |
|
|
// by=(szz*ssy-szy*sz)/det; |
|
|
// al[0]=ax*23.5+bx; // ZINI = 23.5 !!! it should be the same parameter in all codes |
|
|
// al[1]=ay*23.5+by; // " |
|
|
// al[2]= sqrt(pow(ax,2)+pow(ay,2))/ sqrt(pow(ax,2)+pow(ay,2)+1.); |
|
|
// al[3]=0.; |
|
|
// if( (ax!=0.)||(ay!=0.) ) { |
|
|
// al[3]= asin(ay/ sqrt(pow(ax,2)+pow(ay,2))); |
|
|
// if(ax<0.) al[3]=acos(-1.)-al[3]; |
|
|
// } |
|
|
// al[4]=0.; |
|
335 |
|
|
336 |
// } |
// if fit variables have been reset, evaluate the initial guess |
|
// end guess |
|
|
for(int i=0; i<5; i++) track_.al[i]=al[i]; |
|
|
track_.zini = 23.5; // ZINI = 23.5 !!! it should be the same parameter in all codes |
|
|
|
|
|
// elena ----- |
|
337 |
if(al[0]==-9999.&&al[1]==-9999.&&al[2]==-9999.&&al[3]==-9999.&&al[4]==-9999.)guess_(); |
if(al[0]==-9999.&&al[1]==-9999.&&al[2]==-9999.&&al[3]==-9999.&&al[4]==-9999.)guess_(); |
|
// elena ----- |
|
338 |
|
|
339 |
|
// --------------------- free momentum |
340 |
if(pfixed==0.) { |
if(pfixed==0.) { |
341 |
// al[4]=0.; // free momentum |
track_.pfixed=0.; |
|
track_.pfixed=0.; // " |
|
342 |
} |
} |
343 |
|
// --------------------- fixed momentum |
344 |
if(pfixed!=0.) { |
if(pfixed!=0.) { |
345 |
al[4]=1./pfixed; // to fix the momentum |
al[4]=1./pfixed; |
346 |
track_.pfixed=pfixed; // " |
track_.pfixed=pfixed; |
347 |
} |
} |
348 |
|
|
349 |
// store temporarily the initial guess |
// store temporarily the initial guess |
350 |
for(int i=0; i<5; i++) al_ini[i]=track_.al[i]; |
for(int i=0; i<5; i++) al_ini[i]=track_.al[i]; |
351 |
|
|
352 |
|
// ------------------------------------------ |
353 |
|
// call mini routine |
354 |
int istep=0; |
int istep=0; |
355 |
int ifail=0; |
int ifail=0; |
356 |
mini2_(&istep,&ifail, &iprint); |
mini2_(&istep,&ifail, &iprint); |
357 |
if(ifail!=0) { |
if(ifail!=0) { |
358 |
if(iprint==1)cout << "ERROR: ifail= " << ifail << endl; |
if(iprint)cout << "ERROR: ifail= " << ifail << endl; |
359 |
fail = 1; |
fail = 1; |
|
// return; |
|
360 |
} |
} |
361 |
|
// ------------------------------------------ |
362 |
|
|
363 |
|
SetFromMiniStruct(&track_); |
364 |
// cout << endl << "eta ===> " << track_.al[4] << endl; |
// cout << endl << "eta ===> " << track_.al[4] << endl; |
365 |
|
|
366 |
for(int i=0; i<5; i++) al[i]=track_.al[i]; |
// for(int i=0; i<5; i++) al[i]=track_.al[i]; |
367 |
chi2=track_.chi2; |
// chi2=track_.chi2; |
368 |
nstep=track_.nstep; |
// nstep=track_.nstep; |
369 |
for(int i=0; i<6; i++) xv[i]=track_.xv[i]; |
// for(int i=0; i<6; i++) xv[i]=track_.xv[i]; |
370 |
for(int i=0; i<6; i++) yv[i]=track_.yv[i]; |
// for(int i=0; i<6; i++) yv[i]=track_.yv[i]; |
371 |
for(int i=0; i<6; i++) zv[i]=track_.zv[i]; |
// for(int i=0; i<6; i++) zv[i]=track_.zv[i]; |
372 |
for(int i=0; i<6; i++) axv[i]=track_.axv[i]; |
// for(int i=0; i<6; i++) axv[i]=track_.axv[i]; |
373 |
for(int i=0; i<6; i++) ayv[i]=track_.ayv[i]; |
// for(int i=0; i<6; i++) ayv[i]=track_.ayv[i]; |
374 |
for(int i=0; i<5; i++) { |
// for(int i=0; i<5; i++) { |
375 |
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]; |
376 |
} |
// } |
377 |
|
|
378 |
if(fail){ |
// if(fail && iprint){ |
379 |
cout << " >>>> fit failed >>>> drawing initial par"<<endl; |
// cout << " >>>> fit failed >>>> drawing initial par"<<endl; |
380 |
for(int i=0; i<5; i++) al[i]=al_ini[i]; |
// for(int i=0; i<5; i++) al[i]=al_ini[i]; |
381 |
} |
// } |
382 |
|
|
383 |
}; |
}; |
384 |
/* |
/* |
966 |
* Loads the magnetic field. |
* Loads the magnetic field. |
967 |
* @param s Path of the magnetic-field files. |
* @param s Path of the magnetic-field files. |
968 |
*/ |
*/ |
969 |
void TrkLevel2::LoadField(TString s){ |
void TrkLevel2::LoadField(TString path){ |
970 |
readb_(s.Data()); |
// |
971 |
|
strcpy(path_.path,path.Data()); |
972 |
|
path_.pathlen = path.Length(); |
973 |
|
path_.error = 0; |
974 |
|
readb_(); |
975 |
|
// |
976 |
}; |
}; |
977 |
//-------------------------------------- |
//-------------------------------------- |
978 |
// |
// |
1119 |
|
|
1120 |
} |
} |
1121 |
|
|
1122 |
|
/** |
1123 |
|
* Evaluates the trajectory in the apparatus associated to the track. |
1124 |
|
* 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. |
1125 |
|
* @param t pointer to an object of the class Trajectory, |
1126 |
|
* which z coordinates should be previously initialized by calling the proper constructor ( Trajectory::Trajectory(int n, float* zin) ). |
1127 |
|
* @return error flag. |
1128 |
|
*/ |
1129 |
|
int Trajectory::DoTrack2(float* al){ |
1130 |
|
|
1131 |
|
double *dxout = new double[npoint]; |
1132 |
|
double *dyout = new double[npoint]; |
1133 |
|
double *dthxout = new double[npoint]; |
1134 |
|
double *dthyout = new double[npoint]; |
1135 |
|
double *dtlout = new double[npoint]; |
1136 |
|
double *dzin = new double[npoint]; |
1137 |
|
double dal[5]; |
1138 |
|
|
1139 |
|
int ifail = 0; |
1140 |
|
|
1141 |
|
for (int i=0; i<5; i++) dal[i] = (double)al[i]; |
1142 |
|
for (int i=0; i<npoint; i++) dzin[i] = (double)z[i]; |
1143 |
|
|
1144 |
|
dotrack2_(&(npoint),dzin,dxout,dyout,dthxout,dthyout,dtlout,dal,&ifail); |
1145 |
|
|
1146 |
|
for (int i=0; i<npoint; i++){ |
1147 |
|
x[i] = (float)*dxout++; |
1148 |
|
y[i] = (float)*dyout++; |
1149 |
|
thx[i] = (float)*dthxout++; |
1150 |
|
thy[i] = (float)*dthyout++; |
1151 |
|
tl[i] = (float)*dtlout++; |
1152 |
|
} |
1153 |
|
|
1154 |
|
return ifail; |
1155 |
|
}; |
1156 |
|
|
1157 |
ClassImp(TrkLevel2); |
ClassImp(TrkLevel2); |
1158 |
ClassImp(TrkSinglet); |
ClassImp(TrkSinglet); |