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*); |
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]; |
200 |
//-------------------------------------- |
//-------------------------------------- |
201 |
void TrkTrack::Dump(){ |
void TrkTrack::Dump(){ |
202 |
cout << endl << "========== Track " ; |
cout << endl << "========== Track " ; |
203 |
cout << endl << "seq. n. : "<< seqno; |
cout << endl << "seq. n. : "<< seqno; |
204 |
cout << endl << "image n. : "<< image; |
cout << endl << "image n. : "<< image; |
205 |
cout << endl << "al : "; for(int i=0; i<5; i++)cout << al[i] << " "; |
cout << endl << "al : "; for(int i=0; i<5; i++)cout << al[i] << " "; |
206 |
cout << endl << "chi^2 : "<< chi2; |
cout << endl << "chi^2 : "<< chi2; |
207 |
cout << endl << "n.step : "<< nstep; |
cout << endl << "n.step : "<< nstep; |
208 |
cout << endl << "xgood : "; for(int i=0; i<6; i++)cout << xgood[i] ; |
cout << endl << "xgood : "; for(int i=0; i<6; i++)cout << xgood[i] ; |
209 |
cout << endl << "ygood : "; for(int i=0; i<6; i++)cout << ygood[i] ; |
cout << endl << "ygood : "; for(int i=0; i<6; i++)cout << ygood[i] ; |
210 |
cout << endl << "xm : "; for(int i=0; i<6; i++)cout << xm[i] << " "; |
cout << endl << "xm : "; for(int i=0; i<6; i++)cout << xm[i] << " "; |
211 |
cout << endl << "ym : "; for(int i=0; i<6; i++)cout << ym[i] << " "; |
cout << endl << "ym : "; for(int i=0; i<6; i++)cout << ym[i] << " "; |
212 |
cout << endl << "zm : "; for(int i=0; i<6; i++)cout << zm[i] << " "; |
cout << endl << "zm : "; for(int i=0; i<6; i++)cout << zm[i] << " "; |
213 |
|
cout << endl << "xv : "; for(int i=0; i<6; i++)cout << xv[i] << " "; |
214 |
|
cout << endl << "yv : "; for(int i=0; i<6; i++)cout << yv[i] << " "; |
215 |
|
cout << endl << "zv : "; for(int i=0; i<6; i++)cout << zv[i] << " "; |
216 |
|
cout << endl << "resx : "; for(int i=0; i<6; i++)cout << resx[i] << " "; |
217 |
|
cout << endl << "resy : "; for(int i=0; i<6; i++)cout << resy[i] << " "; |
218 |
|
cout << endl << "coval : "; for(int i=0; i<5; i++)cout << coval[0][i]<<" "; |
219 |
|
cout << endl << " "; for(int i=0; i<5; i++)cout << coval[1][i]<<" "; |
220 |
|
cout << endl << " "; for(int i=0; i<5; i++)cout << coval[2][i]<<" "; |
221 |
|
cout << endl << " "; for(int i=0; i<5; i++)cout << coval[3][i]<<" "; |
222 |
|
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 |
229 |
|
*/ |
230 |
|
void TrkTrack::SetMeasure(double *xmeas, double *ymeas, double *zmeas){ |
231 |
|
for(int i=0; i<6; i++) xm[i]=*xmeas++; |
232 |
|
for(int i=0; i<6; i++) ym[i]=*ymeas++; |
233 |
|
for(int i=0; i<6; i++) zm[i]=*zmeas++; |
234 |
|
} |
235 |
|
/** |
236 |
|
* Set the TrkTrack position resolution |
237 |
|
*/ |
238 |
|
void TrkTrack::SetResolution(double *rx, double *ry){ |
239 |
|
for(int i=0; i<6; i++) resx[i]=*rx++; |
240 |
|
for(int i=0; i<6; i++) resy[i]=*ry++; |
241 |
|
} |
242 |
|
/** |
243 |
|
* Set the TrkTrack good measurement |
244 |
|
*/ |
245 |
|
void TrkTrack::SetGood(int *xg, int *yg){ |
246 |
|
for(int i=0; i<6; i++) xgood[i]=*xg++; |
247 |
|
for(int i=0; i<6; i++) ygood[i]=*yg++; |
248 |
|
} |
249 |
|
|
250 |
|
/** |
251 |
|
* Load the magnetic field |
252 |
|
*/ |
253 |
|
void TrkTrack::LoadField(TString path){ |
254 |
|
|
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. |
327 |
|
*/ |
328 |
|
void TrkTrack::Fit(double pfixed, int& fail, int iprint){ |
329 |
|
|
330 |
|
float al_ini[] = {0.,0.,0.,0.,0.}; |
331 |
|
|
332 |
|
extern cMini2track track_; |
333 |
|
fail = 0; |
334 |
|
FillMiniStruct(track_); |
335 |
|
|
336 |
|
// if fit variables have been reset, evaluate the initial guess |
337 |
|
if(al[0]==-9999.&&al[1]==-9999.&&al[2]==-9999.&&al[3]==-9999.&&al[4]==-9999.)guess_(); |
338 |
|
|
339 |
|
// --------------------- free momentum |
340 |
|
if(pfixed==0.) { |
341 |
|
track_.pfixed=0.; |
342 |
|
} |
343 |
|
// --------------------- fixed momentum |
344 |
|
if(pfixed!=0.) { |
345 |
|
al[4]=1./pfixed; |
346 |
|
track_.pfixed=pfixed; |
347 |
|
} |
348 |
|
|
349 |
|
// store temporarily the initial guess |
350 |
|
for(int i=0; i<5; i++) al_ini[i]=track_.al[i]; |
351 |
|
|
352 |
|
// ------------------------------------------ |
353 |
|
// call mini routine |
354 |
|
int istep=0; |
355 |
|
int ifail=0; |
356 |
|
mini2_(&istep,&ifail, &iprint); |
357 |
|
if(ifail!=0) { |
358 |
|
if(iprint)cout << "ERROR: ifail= " << ifail << endl; |
359 |
|
fail = 1; |
360 |
|
} |
361 |
|
// ------------------------------------------ |
362 |
|
|
363 |
|
SetFromMiniStruct(&track_); |
364 |
|
// cout << endl << "eta ===> " << track_.al[4] << endl; |
365 |
|
|
366 |
|
// for(int i=0; i<5; i++) al[i]=track_.al[i]; |
367 |
|
// chi2=track_.chi2; |
368 |
|
// nstep=track_.nstep; |
369 |
|
// 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]; |
371 |
|
// 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]; |
373 |
|
// for(int i=0; i<6; i++) ayv[i]=track_.ayv[i]; |
374 |
|
// for(int i=0; i<5; i++) { |
375 |
|
// for(int j=0; j<5; j++) coval[i][j]=track_.cov[i][j]; |
376 |
|
// } |
377 |
|
|
378 |
|
if(fail){ |
379 |
|
if(iprint)cout << " >>>> fit failed >>>> drawing initial par"<<endl; |
380 |
|
for(int i=0; i<5; i++) al[i]=al_ini[i]; |
381 |
|
} |
382 |
|
|
383 |
|
}; |
384 |
|
/* |
385 |
|
* Reset the fit parameters |
386 |
|
*/ |
387 |
|
void TrkTrack::FitReset(){ |
388 |
|
for(int i=0; i<5; i++) al[i]=-9999.; |
389 |
|
chi2=0.; |
390 |
|
nstep=0; |
391 |
|
for(int i=0; i<6; i++) xv[i]=0.; |
392 |
|
for(int i=0; i<6; i++) yv[i]=0.; |
393 |
|
for(int i=0; i<6; i++) zv[i]=0.; |
394 |
|
for(int i=0; i<6; i++) axv[i]=0.; |
395 |
|
for(int i=0; i<6; i++) ayv[i]=0.; |
396 |
|
for(int i=0; i<5; i++) { |
397 |
|
for(int j=0; j<5; j++) coval[i][j]=0.; |
398 |
|
} |
399 |
} |
} |
400 |
|
|
401 |
//-------------------------------------- |
//-------------------------------------- |
402 |
// |
// |
403 |
// |
// |
436 |
// |
// |
437 |
// |
// |
438 |
//-------------------------------------- |
//-------------------------------------- |
439 |
|
void TrkTrack::Delete(){ |
440 |
|
Clear(); |
441 |
|
clx->Delete(); |
442 |
|
cly->Delete(); |
443 |
|
}; |
444 |
|
//-------------------------------------- |
445 |
|
// |
446 |
|
// |
447 |
|
//-------------------------------------- |
448 |
|
|
449 |
//-------------------------------------- |
//-------------------------------------- |
450 |
// |
// |
767 |
// |
// |
768 |
// |
// |
769 |
//-------------------------------------- |
//-------------------------------------- |
770 |
|
void TrkLevel2::Delete(){ |
771 |
|
|
772 |
|
Clear(); |
773 |
|
Track->Delete(); |
774 |
|
SingletX->Delete(); |
775 |
|
SingletY->Delete(); |
776 |
|
} |
777 |
|
//-------------------------------------- |
778 |
|
// |
779 |
|
// |
780 |
|
//-------------------------------------- |
781 |
/** |
/** |
782 |
* Sort physical tracks and stores them in a TObjectArray, ordering by increasing chi**2 value (in case of track image, it selects the one with lower chi**2). The total number of physical tracks is given by GetNTracks() and the it-th physical track can be retrieved by means of the method GetTrack(int it). |
* Sort physical tracks and stores them in a TObjectArray, ordering by increasing chi**2 value (in case of track image, it selects the one with lower chi**2). The total number of physical tracks is given by GetNTracks() and the it-th physical track can be retrieved by means of the method GetTrack(int it). |
783 |
* This method is overridden by PamLevel2::GetTracks(), where calorimeter and TOF information is used. |
* This method is overridden by PamLevel2::GetTracks(), where calorimeter and TOF information is used. |
921 |
|
|
922 |
Float_t ntot=0; |
Float_t ntot=0; |
923 |
TClonesArray &t = *Track; |
TClonesArray &t = *Track; |
924 |
for(int i=0; i<ntrk(); i++) { |
for(int i=0; i<ntrk(); i++) { |
925 |
if( ((TrkTrack *)t[i])->GetImageSeqNo() == -1 ) ntot+=1.; |
if( ((TrkTrack *)t[i])->GetImageSeqNo() == -1 ) ntot+=1.; |
926 |
else ntot+=0.5; |
else ntot+=0.5; |
927 |
} |
} |
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); |