/[PAMELA software]/DarthVader/TrackerLevel2/src/TrkLevel2.cpp
ViewVC logotype

Contents of /DarthVader/TrackerLevel2/src/TrkLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.37 - (show annotations) (download)
Wed Jun 6 09:36:07 2007 UTC (17 years, 6 months ago) by pam-fi
Branch: MAIN
Changes since 1.36: +50 -0 lines
new methods to evaluate chi**2 x,y and likelywood x,y

1 /**
2 * \file TrkLevel2.cpp
3 * \author Elena Vannuccini
4 */
5 #include <TrkLevel2.h>
6 #include <iostream>
7 #include <math.h>
8 using namespace std;
9 //......................................
10 // F77 routines
11 //......................................
12 extern "C" {
13 void dotrack_(int*, double*, double*, double*, double*, int*);
14 void dotrack2_(int*, double*, double*, double*, double*,double*, double*, double*,int*);
15 void mini2_(int*,int*,int*);
16 void guess_();
17 void gufld_(float*, float*);
18 float risxeta2_(float *);
19 float risxeta3_(float *);
20 float risxeta4_(float *);
21 float risyeta2_(float *);
22 }
23
24 //--------------------------------------
25 //
26 //
27 //--------------------------------------
28 TrkTrack::TrkTrack(){
29 // cout << "TrkTrack::TrkTrack()" << endl;
30 seqno = -1;
31 image = -1;
32 chi2 = 0;
33 nstep = 0;
34 for(int it1=0;it1<5;it1++){
35 al[it1] = 0;
36 for(int it2=0;it2<5;it2++)coval[it1][it2] = 0;
37 };
38 for(int ip=0;ip<6;ip++){
39 xgood[ip] = 0;
40 ygood[ip] = 0;
41 xm[ip] = 0;
42 ym[ip] = 0;
43 zm[ip] = 0;
44 resx[ip] = 0;
45 resy[ip] = 0;
46 tailx[ip] = 0;
47 taily[ip] = 0;
48 xv[ip] = 0;
49 yv[ip] = 0;
50 zv[ip] = 0;
51 axv[ip] = 0;
52 ayv[ip] = 0;
53 dedx_x[ip] = 0;
54 dedx_y[ip] = 0;
55 };
56 // clx = 0;
57 // cly = 0;
58 // clx = new TRefArray(6,0); //forse causa memory leak???
59 // cly = new TRefArray(6,0); //forse causa memory leak???
60 // clx = TRefArray(6,0);
61 // cly = TRefArray(6,0);
62
63 TrkParams::SetTrackingMode();
64 TrkParams::SetPrecisionFactor();
65 TrkParams::SetStepMin();
66 TrkParams::SetPFA();
67
68 };
69 //--------------------------------------
70 //
71 //
72 //--------------------------------------
73 TrkTrack::TrkTrack(const TrkTrack& t){
74 seqno = t.seqno;
75 image = t.image;
76 chi2 = t.chi2;
77 nstep = t.nstep;
78 for(int it1=0;it1<5;it1++){
79 al[it1] = t.al[it1];
80 for(int it2=0;it2<5;it2++)coval[it1][it2] = t.coval[it1][it2];
81 };
82 for(int ip=0;ip<6;ip++){
83 xgood[ip] = t.xgood[ip];
84 ygood[ip] = t.ygood[ip];
85 xm[ip] = t.xm[ip];
86 ym[ip] = t.ym[ip];
87 zm[ip] = t.zm[ip];
88 resx[ip] = t.resx[ip];
89 resy[ip] = t.resy[ip];
90 tailx[ip] = t.tailx[ip];
91 taily[ip] = t.taily[ip];
92 xv[ip] = t.xv[ip];
93 yv[ip] = t.yv[ip];
94 zv[ip] = t.zv[ip];
95 axv[ip] = t.axv[ip];
96 ayv[ip] = t.ayv[ip];
97 dedx_x[ip] = t.dedx_x[ip];
98 dedx_y[ip] = t.dedx_y[ip];
99 };
100 // clx = 0;
101 // cly = 0;
102 // if(t.clx)clx = new TRefArray(*(t.clx));
103 // if(t.cly)cly = new TRefArray(*(t.cly));
104 // clx = TRefArray(t.clx);
105 // cly = TRefArray(t.cly);
106
107 TrkParams::SetTrackingMode();
108 TrkParams::SetPrecisionFactor();
109 TrkParams::SetStepMin();
110 TrkParams::SetPFA();
111
112 };
113 //--------------------------------------
114 //
115 //
116 //--------------------------------------
117 void TrkTrack::Copy(TrkTrack& t){
118
119 t.seqno = seqno;
120 t.image = image;
121 t.chi2 = chi2;
122 t.nstep = nstep;
123 for(int it1=0;it1<5;it1++){
124 t.al[it1] = al[it1];
125 for(int it2=0;it2<5;it2++)t.coval[it1][it2] = coval[it1][it2];
126 };
127 for(int ip=0;ip<6;ip++){
128 t.xgood[ip] = xgood[ip];
129 t.ygood[ip] = ygood[ip];
130 t.xm[ip] = xm[ip];
131 t.ym[ip] = ym[ip];
132 t.zm[ip] = zm[ip];
133 t.resx[ip] = resx[ip];
134 t.resy[ip] = resy[ip];
135 t.tailx[ip] = tailx[ip];
136 t.taily[ip] = taily[ip];
137 t.xv[ip] = xv[ip];
138 t.yv[ip] = yv[ip];
139 t.zv[ip] = zv[ip];
140 t.axv[ip] = axv[ip];
141 t.ayv[ip] = ayv[ip];
142 t.dedx_x[ip] = dedx_x[ip];
143 t.dedx_y[ip] = dedx_y[ip];
144
145 };
146
147 // t.clx = TRefArray(clx);
148 // t.cly = TRefArray(cly);
149
150 };
151 //--------------------------------------
152 //
153 //
154 //--------------------------------------
155 /**
156 * Evaluates the trajectory in the apparatus associated to the track.
157 * 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.
158 * @param t pointer to an object of the class Trajectory,
159 * which z coordinates should be previously initialized by calling the proper constructor ( Trajectory::Trajectory(int n, float* zin) ).
160 * @return error flag.
161 */
162 int TrkTrack::DoTrack(Trajectory* t){
163
164 double *dxout = new double[t->npoint];
165 double *dyout = new double[t->npoint];
166 double *dzin = new double[t->npoint];
167 double dal[5];
168
169 int ifail = 0;
170
171 for (int i=0; i<5; i++) dal[i] = (double)al[i];
172 for (int i=0; i<t->npoint; i++) dzin[i] = (double)t->z[i];
173
174 TrkParams::Load(1);
175 if( !TrkParams::IsLoaded(1) ){
176 cout << "int TrkTrack::DoTrack(Trajectory* t) --- ERROR --- m.field not loaded"<<endl;
177 return 0;
178 }
179 dotrack_(&(t->npoint),dzin,dxout,dyout,dal,&ifail);
180
181 for (int i=0; i<t->npoint; i++){
182 t->x[i] = (float)*dxout++;
183 t->y[i] = (float)*dyout++;
184 }
185
186 // delete [] dxout;
187 // delete [] dyout;
188 // delete [] dzin;
189
190 return ifail;
191 };
192 //--------------------------------------
193 //
194 //
195 //--------------------------------------
196 /**
197 * Evaluates the trajectory in the apparatus associated to the track.
198 * 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.
199 * @param t pointer to an object of the class Trajectory,
200 * which z coordinates should be previously initialized by calling the proper constructor ( Trajectory::Trajectory(int n, float* zin) ).
201 * @return error flag.
202 */
203 int TrkTrack::DoTrack2(Trajectory* t){
204
205 double *dxout = new double[t->npoint];
206 double *dyout = new double[t->npoint];
207 double *dthxout = new double[t->npoint];
208 double *dthyout = new double[t->npoint];
209 double *dtlout = new double[t->npoint];
210 double *dzin = new double[t->npoint];
211 double dal[5];
212
213 int ifail = 0;
214
215 for (int i=0; i<5; i++) dal[i] = (double)al[i];
216 for (int i=0; i<t->npoint; i++) dzin[i] = (double)t->z[i];
217
218 TrkParams::Load(1);
219 if( !TrkParams::IsLoaded(1) ){
220 cout << "int TrkTrack::DoTrack2(Trajectory* t) --- ERROR --- m.field not loaded"<<endl;
221 return 0;
222 }
223 dotrack2_(&(t->npoint),dzin,dxout,dyout,dthxout,dthyout,dtlout,dal,&ifail);
224
225 for (int i=0; i<t->npoint; i++){
226 t->x[i] = (float)*dxout++;
227 t->y[i] = (float)*dyout++;
228 t->thx[i] = (float)*dthxout++;
229 t->thy[i] = (float)*dthyout++;
230 t->tl[i] = (float)*dtlout++;
231 }
232
233 // delete [] dxout;
234 // delete [] dyout;
235 // delete [] dzin;
236
237 return ifail;
238 };
239 //--------------------------------------
240 //
241 //
242 //--------------------------------------
243 //float TrkTrack::BdL(){
244 //};
245 //--------------------------------------
246 //
247 //
248 //--------------------------------------
249 Float_t TrkTrack::GetRigidity(){
250 Float_t rig=0;
251 if(chi2>0)rig=1./al[4];
252 if(rig<0) rig=-rig;
253 return rig;
254 };
255 //
256 Float_t TrkTrack::GetDeflection(){
257 Float_t def=0;
258 if(chi2>0)def=al[4];
259 return def;
260 };
261 //
262 /**
263 * Method to retrieve the dE/dx measured on a tracker view.
264 * @param ip plane (0-5)
265 * @param iv view (0=x 1=y)
266 */
267 Float_t TrkTrack::GetDEDX(int ip, int iv){
268 if(iv==0 && ip>=0 && ip<6)return fabs(dedx_x[ip]);
269 else if(iv==1 && ip>=0 && ip<6)return fabs(dedx_y[ip]);
270 else {
271 cout << "TrkTrack::GetDEDX(int ip, int iv) -- wrong input parameters "<<ip<<iv<<endl;
272 return 0.;
273 }
274 }
275 /**
276 * Method to evaluate the dE/dx measured on a tracker plane.
277 * The two measurements on x- and y-view are averaged.
278 * @param ip plane (0-5)
279 */
280 Float_t TrkTrack::GetDEDX(int ip){
281 if( (Int_t)XGood(ip)+(Int_t)YGood(ip) == 0 ) return 0;
282 return (GetDEDX(ip,0)+GetDEDX(ip,1))/((Int_t)XGood(ip)+(Int_t)YGood(ip));
283 };
284
285 /**
286 * Method to evaluate the dE/dx averaged over all planes.
287 */
288 Float_t TrkTrack::GetDEDX(){
289 Float_t dedx=0;
290 for(Int_t ip=0; ip<6; ip++)dedx+=GetDEDX(ip,0)*XGood(ip)+GetDEDX(ip,1)*YGood(ip);
291 dedx = dedx/(GetNX()+GetNY());
292 return dedx;
293 };
294 /**
295 * Returns 1 if the cluster on a tracker view includes bad strips.
296 * @param ip plane (0-5)
297 * @param iv view (0=x 1=y)
298 */
299 Bool_t TrkTrack::IsBad(int ip,int iv){
300 if(iv==0 && ip>=0 && ip<6)return (xgood[ip]<0) ;
301 else if(iv==1 && ip>=0 && ip<6)return (ygood[ip]<0) ;
302 else {
303 cout << "TrkTrack::IsBad(int ip, int iv) -- wrong input parameters "<<ip<<iv<<endl;
304 return 0.;
305 }
306 };
307 /**
308 * Returns 1 if the signal on a tracker view is saturated.
309 * @param ip plane (0-5)
310 * @param iv view (0=x 1=y)
311 */
312 Bool_t TrkTrack::IsSaturated(int ip,int iv){
313 if(iv==0 && ip>=0 && ip<6)return (dedx_x[ip]<0) ;
314 else if(iv==1 && ip>=0 && ip<6)return (dedx_y[ip]<0) ;
315 else {
316 cout << "TrkTrack::IsSaturated(int ip, int iv) -- wrong input parameters "<<ip<<iv<<endl;
317 return 0.;
318 }
319 };
320 /**
321 * Returns 1 if either the x or the y signal on a tracker plane is saturated.
322 * @param ip plane (0-5)
323 */
324 Bool_t TrkTrack::IsSaturated(int ip){
325 return (IsSaturated(ip,0)||IsSaturated(ip,1));
326 };
327 /**
328 * Returns 1 if there is at least a saturated signal along the track.
329 */
330 Bool_t TrkTrack::IsSaturated(){
331 for(int ip=0; ip<6; ip++)for(int iv=0; iv<2; iv++)if(IsSaturated(ip,iv))return true;
332 return false;
333 }
334 /**
335 * Returns the track "lever-arm" on the x view, defined as the distance (in planes) between
336 * the upper and lower x measurements (the maximum value of lever-arm is 6).
337 */
338 Int_t TrkTrack::GetLeverArmX(){
339 int first_plane = -1;
340 int last_plane = -1;
341 for(Int_t ip=0; ip<6; ip++){
342 if( XGood(ip) && first_plane == -1 )first_plane = ip;
343 if( XGood(ip) && first_plane != -1 )last_plane = ip;
344 }
345 if( first_plane == -1 || last_plane == -1){
346 cout<< "Int_t TrkTrack::GetLeverArmX() -- XGood(ip) always false ??? "<<endl;
347 return 0;
348 }
349 return (last_plane-first_plane+1);
350 }
351 /**
352 * Returns the track "lever-arm" on the y view, defined as the distance (in planes) between
353 * the upper and lower y measurements (the maximum value of lever-arm is 6).
354 */
355 Int_t TrkTrack::GetLeverArmY(){
356 int first_plane = -1;
357 int last_plane = -1;
358 for(Int_t ip=0; ip<6; ip++){
359 if( YGood(ip) && first_plane == -1 )first_plane = ip;
360 if( YGood(ip) && first_plane != -1 )last_plane = ip;
361 }
362 if( first_plane == -1 || last_plane == -1){
363 cout<< "Int_t TrkTrack::GetLeverArmY() -- YGood(ip) always false ??? "<<endl;
364 return 0;
365 }
366 return (last_plane-first_plane+1);
367 }
368 /**
369 * Returns the reduced chi-square of track x-projection
370 */
371 Float_t TrkTrack::GetChi2X(){
372 float chiq=0;
373 for(int ip=0; ip<6; ip++)if(XGood(ip))chiq+= pow((xv[ip]-xm[ip])/resx[ip],2.);
374 if(GetNX()>3)chiq=chiq/(GetNX()-3);
375 else chiq=0;
376 if(chiq==0)cout << " Float_t TrkTrack::GetChi2X() -- WARNING -- value not defined "<<chiq<<endl;
377 return chiq;
378 }
379 /**
380 * Returns the reduced chi-square of track y-projection
381 */
382 Float_t TrkTrack::GetChi2Y(){
383 float chiq=0;
384 for(int ip=0; ip<6; ip++)if(YGood(ip))chiq+= pow((yv[ip]-ym[ip])/resy[ip],2.);
385 if(GetNY()>2)chiq=chiq/(GetNY()-2);
386 else chiq=0;
387 if(chiq==0)cout << " Float_t TrkTrack::GetChi2Y() -- WARNING -- value not defined "<<chiq<<endl;
388 return chiq;
389 }
390 /**
391 * Returns the logarythm of the likeliwood-function of track x-projection
392 */
393 Float_t TrkTrack::GetLnLX(){
394 float lnl=0;
395 for(int ip=0; ip<6; ip++)
396 if( XGood(ip) && tailx[ip]!=0 )
397 lnl += (tailx[ip]+1.) * log( (tailx[ip]*pow(resx[ip],2.) + pow(xv[ip]-xm[ip],2.)) / (tailx[ip]*pow(resx[ip],2)) );
398 if(GetNX()>3)lnl=lnl/(GetNX()-3);
399 else lnl=0;
400 if(lnl==0)cout << " Float_t TrkTrack::GetLnLX() -- WARNING -- value not defined "<<lnl<<endl;
401 return lnl;
402
403 }
404 /**
405 * Returns the logarythm of the likeliwood-function of track y-projection
406 */
407 Float_t TrkTrack::GetLnLY(){
408 float lnl=0;
409 for(int ip=0; ip<6; ip++)
410 if( YGood(ip) && taily[ip]!=0 )
411 lnl += (taily[ip]+1.) * log( (taily[ip]*pow(resy[ip],2.) + pow(yv[ip]-ym[ip],2.)) / (taily[ip]*pow(resy[ip],2)) );
412 if(GetNY()>2)lnl=lnl/(GetNY()-2);
413 else lnl=0;
414 if(lnl==0)cout << " Float_t TrkTrack::GetLnLY() -- WARNING -- value not defined "<<lnl<<endl;
415 return lnl;
416
417 }
418 //--------------------------------------
419 //
420 //
421 //--------------------------------------
422 void TrkTrack::Dump(){
423 cout << endl << "========== Track " ;
424 cout << endl << "seq. n. : "<< seqno;
425 cout << endl << "image n. : "<< image;
426 cout << endl << "al : "; for(int i=0; i<5; i++)cout << al[i] << " ";
427 cout << endl << "chi^2 : "<< chi2;
428 cout << endl << "n.step : "<< nstep;
429 cout << endl << "xgood : "; for(int i=0; i<6; i++)cout << XGood(i) ;
430 cout << endl << "ygood : "; for(int i=0; i<6; i++)cout << YGood(i) ;
431 cout << endl << "xm : "; for(int i=0; i<6; i++)cout << xm[i] << " ";
432 cout << endl << "ym : "; for(int i=0; i<6; i++)cout << ym[i] << " ";
433 cout << endl << "zm : "; for(int i=0; i<6; i++)cout << zm[i] << " ";
434 cout << endl << "xv : "; for(int i=0; i<6; i++)cout << xv[i] << " ";
435 cout << endl << "yv : "; for(int i=0; i<6; i++)cout << yv[i] << " ";
436 cout << endl << "zv : "; for(int i=0; i<6; i++)cout << zv[i] << " ";
437 cout << endl << "resx : "; for(int i=0; i<6; i++)cout << resx[i] << " ";
438 cout << endl << "resy : "; for(int i=0; i<6; i++)cout << resy[i] << " ";
439 cout << endl << "tailx : "; for(int i=0; i<6; i++)cout << tailx[i] << " ";
440 cout << endl << "taily : "; for(int i=0; i<6; i++)cout << taily[i] << " ";
441 cout << endl << "coval : "; for(int i=0; i<5; i++)cout << coval[0][i]<<" ";
442 cout << endl << " "; for(int i=0; i<5; i++)cout << coval[1][i]<<" ";
443 cout << endl << " "; for(int i=0; i<5; i++)cout << coval[2][i]<<" ";
444 cout << endl << " "; for(int i=0; i<5; i++)cout << coval[3][i]<<" ";
445 cout << endl << " "; for(int i=0; i<5; i++)cout << coval[4][i]<<" ";
446 cout << endl << "dedx_x : "; for(int i=0; i<6; i++)cout << dedx_x[i] << " ";
447 cout << endl << "dedx_y : "; for(int i=0; i<6; i++)cout << dedx_y[i] << " ";
448 cout << endl;
449 }
450 /**
451 * Set the TrkTrack position measurements
452 */
453 void TrkTrack::SetMeasure(double *xmeas, double *ymeas, double *zmeas){
454 for(int i=0; i<6; i++) xm[i]=*xmeas++;
455 for(int i=0; i<6; i++) ym[i]=*ymeas++;
456 for(int i=0; i<6; i++) zm[i]=*zmeas++;
457 }
458 /**
459 * Set the TrkTrack position resolution
460 */
461 void TrkTrack::SetResolution(double *rx, double *ry){
462 for(int i=0; i<6; i++) resx[i]=*rx++;
463 for(int i=0; i<6; i++) resy[i]=*ry++;
464 }
465 /**
466 * Set the TrkTrack tails position resolution
467 */
468 void TrkTrack::SetTail(double *tx, double *ty, double factor){
469 for(int i=0; i<6; i++) tailx[i]=factor*(*tx++);
470 for(int i=0; i<6; i++) taily[i]=factor*(*ty++);
471 }
472 /**
473 * Set the TrkTrack Student parameter (resx,resy,tailx,taily)
474 * from previous gausian fit
475 *@param flag =0 standard, =1 with noise correction
476 */
477 void TrkTrack::SetStudentParam(int flag){
478 float sx[11]={0.000128242,
479 0.000136942,
480 0.000162718,
481 0.000202644,
482 0.00025597,
483 0.000317456,
484 0.000349048,
485 0.000384638,
486 0.000457295,
487 0.000512319,
488 0.000538573};
489 float tx[11]={1.79402,
490 2.04876,
491 2.88376,
492 3.3,
493 3.14084,
494 4.07686,
495 4.44736,
496 3.5179,
497 3.38697,
498 3.45739,
499 3.18627};
500 float sy[11]={0.000483075,
501 0.000466925,
502 0.000431658,
503 0.000428317,
504 0.000433854,
505 0.000444044,
506 0.000482098,
507 0.000537579,
508 0.000636279,
509 0.000741998,
510 0.000864261};
511 float ty[11]={0.997032,
512 1.11147,
513 1.18526,
514 1.61404,
515 2.21908,
516 3.08959,
517 4.48833,
518 4.42687,
519 4.65253,
520 4.52043,
521 4.29926};
522 int index;
523 float fact;
524 for(int i=0; i<6; i++) {
525 index = int((fabs(axv[i])+1.)/2.);
526 if(index>10) index=10;
527 tailx[i]=tx[index];
528 if(flag==1) {
529 if(fabs(axv[i])<=10.) fact = resx[i]/risxeta2_(&(axv[i]));
530 if(fabs(axv[i])>10.&&fabs(axv[i])<=15.) fact = resx[i]/risxeta3_(&(axv[i]));
531 if(fabs(axv[i])>15.) fact = resx[i]/risxeta4_(&(axv[i]));
532 } else fact = 1.;
533 resx[i] = sx[index]*fact;
534 }
535 for(int i=0; i<6; i++) {
536 index = int((fabs(ayv[i])+1.)/2.);
537 if(index>10) index=10;
538 taily[i]=ty[index];
539 if(flag==1) fact = resy[i]/risyeta2_(&(ayv[i]));
540 else fact = 1.;
541 resy[i] = sy[index]*fact;
542 }
543 }
544 /**
545 * Set the TrkTrack good measurement
546 */
547 void TrkTrack::SetGood(int *xg, int *yg){
548
549 for(int i=0; i<6; i++) xgood[i]=*xg++;
550 for(int i=0; i<6; i++) ygood[i]=*yg++;
551 }
552
553 /**
554 * Load the magnetic field
555 */
556 void TrkTrack::LoadField(TString path){
557
558 // strcpy(path_.path,path.Data());
559 // path_.pathlen = path.Length();
560 // path_.error = 0;
561 // readb_();
562
563 TrkParams::SetTrackingMode();
564 TrkParams::SetPrecisionFactor();
565 TrkParams::SetStepMin();
566
567 TrkParams::Set(path,1);
568 TrkParams::Load(1);
569
570 };
571
572
573 /**
574 * Method to fill minimization-routine common
575 */
576 void TrkTrack::FillMiniStruct(cMini2track& track){
577
578 for(int i=0; i<6; i++){
579
580 // cout << i<<" - "<<xgood[i]<<" "<<XGood(i)<<endl;
581 // cout << i<<" - "<<ygood[i]<<" "<<YGood(i)<<endl;
582 track.xgood[i]=XGood(i);
583 track.ygood[i]=YGood(i);
584
585 track.xm[i]=xm[i];
586 track.ym[i]=ym[i];
587 track.zm[i]=zm[i];
588
589 // --- temporaneo ----------------------------
590 // andrebbe inserita la dimensione del sensore
591 float segment = 100.;
592 track.xm_a[i]=xm[i];
593 track.xm_b[i]=xm[i];
594 track.ym_a[i]=ym[i];
595 track.ym_b[i]=ym[i];
596 if( XGood(i) && !YGood(i) ){
597 track.ym_a[i] = track.ym_a[i]+segment;
598 track.ym_b[i] = track.ym_b[i]-segment;
599 }else if( !XGood(i) && YGood(i)){
600 track.xm_a[i] = track.xm_a[i]+segment;
601 track.xm_b[i] = track.xm_b[i]-segment;
602 }
603 // --- temporaneo ----------------------------
604
605 track.resx[i]=resx[i];
606 track.resy[i]=resy[i];
607 track.tailx[i]=tailx[i];
608 track.taily[i]=taily[i];
609 }
610
611 for(int i=0; i<5; i++) track.al[i]=al[i];
612 track.zini = 23.5;
613 // ZINI = 23.5 !!! it should be the same parameter in all codes
614
615 }
616 /**
617 * Method to set values from minimization-routine common
618 */
619 void TrkTrack::SetFromMiniStruct(cMini2track *track){
620
621 for(int i=0; i<5; i++) {
622 al[i]=track->al[i];
623 for(int j=0; j<5; j++) coval[i][j]=track->cov[i][j];
624 }
625 chi2 = track->chi2;
626 nstep = track->nstep;
627 for(int i=0; i<6; i++){
628 xv[i] = track->xv[i];
629 yv[i] = track->yv[i];
630 zv[i] = track->zv[i];
631 xm[i] = track->xm[i];
632 ym[i] = track->ym[i];
633 zm[i] = track->zm[i];
634 axv[i] = track->axv[i];
635 ayv[i] = track->ayv[i];
636 }
637
638 }
639 /**
640 * \brief Method to re-evaluate coordinates of clusters associated with a track.
641 *
642 * The method can be applied only after recovering level1 information
643 * (either by reprocessing single events from level0 or from
644 * the TrkLevel1 branch, if present); it calls F77 subroutines that
645 * read the level1 common and fill the minimization-routine common.
646 * Some clusters can be excluded or added by means of the methods:
647 *
648 * TrkTrack::ResetXGood(int ip)
649 * TrkTrack::ResetYGood(int ip)
650 * TrkTrack::SetXGood(int ip, int cid, int is)
651 * TrkTrack::SetYGood(int ip, int cid, int is)
652 *
653 * NB! The method TrkTrack::SetGood(int *xg, int *yg) set the plane-mask (0-1)
654 * for the minimization-routine common. It deletes the cluster information
655 * (at least for the moment...) thus cannot be applied before
656 * TrkTrack::EvaluateClusterPositions().
657 *
658 * Different p.f.a. can be applied by calling (once) the method:
659 *
660 * TrkParams::SetPFA(0); //Set ETA p.f.a.
661 *
662 * @see TrkParams::SetPFA(int)
663 */
664 Bool_t TrkTrack::EvaluateClusterPositions(){
665
666 // cout << "void TrkTrack::GetClusterPositions() "<<endl;
667
668 TrkParams::Load( );
669 if( !TrkParams::IsLoaded() )return false;
670
671 for(int ip=0; ip<6; ip++){
672 // cout << ip<<" ** "<<xm[ip]<<" / "<<ym[ip]<<endl;;
673 int icx = GetClusterX_ID(ip)+1;
674 int icy = GetClusterY_ID(ip)+1;
675 int sensor = GetSensor(ip)+1;//<< convenzione "Paolo"
676 if(ip==5 && sensor!=0)sensor=3-sensor;//<< convenzione "Elena"
677 int ladder = GetLadder(ip)+1;
678 float ax = axv[ip];
679 float ay = ayv[ip];
680 float v[3];
681 v[0]=xv[ip];
682 v[1]=yv[ip];
683 v[2]=zv[ip];
684 float bfx = 10*TrkParams::GetBX(v);//Tesla
685 float bfy = 10*TrkParams::GetBY(v);//Tesla
686 int ipp=ip+1;
687 xyzpam_(&ipp,&icx,&icy,&ladder,&sensor,&ax,&ay,&bfx,&bfy);
688 if(icx<0 || icy<0)return false;
689 }
690 return true;
691 }
692 /**
693 * \brief Tracking method. It calls F77 mini routine.
694 *
695 * @param pfixed Particle momentum. If pfixed=0 the momentum
696 * is left as a free parameter, otherwise it is fixed to the input value.
697 * @param fail Output flag (!=0 if the fit failed).
698 * @param iprint Flag to set debug mode ( 0 = no output; 1 = verbose; 2 = debug).
699 * @param froml1 Flag to re-evaluate positions (see TrkTrack::GetClusterPositions()).
700 *
701 * The option to re-evaluate positions can be used only after recovering
702 * level1 information, eg. by reprocessing the single event.
703 *
704 * Example:
705 *
706 * if( !event->GetTrkLevel0() )return false;
707 * event->GetTrkLevel0()->ProcessEvent(); // re-processing level0->level1
708 * int fail=0;
709 * event->GetTrkLevel2()->GetTrack(0)->Fit(0.,fail,0,1);
710 *
711 * @see EvaluateClusterPositions()
712 *
713 * The fitting procedure can be varied by changing the tracking mode,
714 * the fit-precision factor and the minimum number of step.
715 * @see SetTrackingMode(int)
716 * @see SetPrecisionFactor(double)
717 * @see SetStepMin(int)
718 */
719 void TrkTrack::Fit(double pfixed, int& fail, int iprint, int froml1){
720
721 float al_ini[] = {0.,0.,0.,0.,0.};
722
723 TrkParams::Load( );
724 if( !TrkParams::IsLoaded() )return;
725
726 extern cMini2track track_;
727 fail = 0;
728
729 FillMiniStruct(track_);
730
731 if(froml1!=0){
732 if( !EvaluateClusterPositions() ){
733 cout << "void TrkTrack::Fit("<<pfixed<<","<<fail<<","<<iprint<<","<<froml1<<") --- ERROR evaluating cluster positions "<<endl;
734 FillMiniStruct(track_) ;
735 fail = 1;
736 return;
737 }
738 }else{
739 FillMiniStruct(track_);
740 }
741
742 // if fit variables have been reset, evaluate the initial guess
743 if(al[0]==-9999.&&al[1]==-9999.&&al[2]==-9999.&&al[3]==-9999.&&al[4]==-9999.)guess_();
744
745 // --------------------- free momentum
746 if(pfixed==0.) {
747 track_.pfixed=0.;
748 }
749 // --------------------- fixed momentum
750 if(pfixed!=0.) {
751 al[4]=1./pfixed;
752 track_.pfixed=pfixed;
753 }
754
755 // store temporarily the initial guess
756 for(int i=0; i<5; i++) al_ini[i]=track_.al[i];
757
758 // ------------------------------------------
759 // call mini routine
760 // TrkParams::Load(1);
761 // if( !TrkParams::IsLoaded(1) ){
762 // cout << "void TrkTrack::Fit(double pfixed, int& fail, int iprint) --- ERROR --- m.field not loaded"<<endl;
763 // return;
764 // }
765 int istep=0;
766 int ifail=0;
767 mini2_(&istep,&ifail, &iprint);
768 if(ifail!=0) {
769 if(iprint)cout << "ERROR: ifail= " << ifail << endl;
770 fail = 1;
771 }
772 // ------------------------------------------
773
774 SetFromMiniStruct(&track_);
775
776 if(fail){
777 if(iprint)cout << " >>>> fit failed "<<endl;
778 for(int i=0; i<5; i++) al[i]=al_ini[i];
779 }
780
781 };
782 /**
783 * Reset the fit parameters
784 */
785 void TrkTrack::FitReset(){
786 for(int i=0; i<5; i++) al[i]=-9999.;
787 chi2=0.;
788 nstep=0;
789 // for(int i=0; i<6; i++) xv[i]=0.;
790 // for(int i=0; i<6; i++) yv[i]=0.;
791 // for(int i=0; i<6; i++) zv[i]=0.;
792 // for(int i=0; i<6; i++) axv[i]=0.;
793 // for(int i=0; i<6; i++) ayv[i]=0.;
794 for(int i=0; i<5; i++) {
795 for(int j=0; j<5; j++) coval[i][j]=0.;
796 }
797 }
798 /**
799 * Set the tracking mode
800 */
801 void TrkTrack::SetTrackingMode(int trackmode){
802 extern cMini2track track_;
803 track_.trackmode = trackmode;
804 }
805 /**
806 * Set the factor scale for tracking precision
807 */
808 void TrkTrack::SetPrecisionFactor(double fact){
809 extern cMini2track track_;
810 track_.fact = fact;
811 }
812 /**
813 * Set the minimum number of steps for tracking precision
814 */
815 void TrkTrack::SetStepMin(int istepmin){
816 extern cMini2track track_;
817 track_.istepmin = istepmin;
818 }
819 /**
820 * Returns 1 if the track is inside the magnet cavity
821 * Set the minimum number of steps for tracking precision
822 */
823 Bool_t TrkTrack::IsInsideCavity(){
824 float xmagntop, ymagntop, xmagnbottom, ymagnbottom;
825 xmagntop = xv[0] + (ZMAGNHIGH-zv[0])*tan(cos(-1.0)*axv[0]/180.);
826 ymagntop = yv[0] + (ZMAGNHIGH-zv[0])*tan(cos(-1.0)*ayv[0]/180.);
827 xmagnbottom = xv[5] + (ZMAGNLOW-zv[5])*tan(cos(-1.0)*axv[5]/180.);
828 ymagnbottom = yv[5] + (ZMAGNLOW-zv[5])*tan(cos(-1.0)*ayv[5]/180.);
829 if( xmagntop>XMAGNLOW && xmagntop<XMAGNHIGH &&
830 ymagntop>YMAGNLOW && ymagntop<YMAGNHIGH &&
831 xmagnbottom>XMAGNLOW && xmagnbottom<XMAGNHIGH &&
832 ymagnbottom>YMAGNLOW && ymagnbottom<YMAGNHIGH ) return(true);
833 else return(false);
834 }
835 /**
836 * Method to retrieve ID (0,1,...) of x-cluster (if any) associated to this track.
837 * If no cluster is associated, ID=-1.
838 * @param ip Tracker plane (0-5)
839 */
840 Int_t TrkTrack::GetClusterX_ID(int ip){
841 return ((Int_t)fabs(xgood[ip]))%10000000-1;
842 };
843 /**
844 * Method to retrieve ID (0-xxx) of y-cluster (if any) associated to this track.
845 * If no cluster is associated, ID=-1.
846 * @param ip Tracker plane (0-5)
847 */
848 Int_t TrkTrack::GetClusterY_ID(int ip){
849 return ((Int_t)fabs(ygood[ip]))%10000000-1;
850 };
851 /**
852 * Method to retrieve the ladder (0-4, increasing x) traversed by the track on this plane.
853 * If no ladder is traversed (dead area) the metod retuns -1.
854 * @param ip Tracker plane (0-5)
855 */
856 Int_t TrkTrack::GetLadder(int ip){
857 if(XGood(ip))return (Int_t)fabs(xgood[ip]/100000000)-1;
858 if(YGood(ip))return (Int_t)fabs(ygood[ip]/100000000)-1;
859 return -1;
860 };
861 /**
862 * Method to retrieve the sensor (0-1, increasing y) traversed by the track on this plane.
863 * If no sensor is traversed (dead area) the metod retuns -1.
864 * @param ip Tracker plane (0-5)
865 */
866 Int_t TrkTrack::GetSensor(int ip){
867 if(XGood(ip))return (Int_t)((Int_t)fabs(xgood[ip]/10000000)%10)-1;
868 if(YGood(ip))return (Int_t)((Int_t)fabs(ygood[ip]/10000000)%10)-1;
869 return -1;
870 };
871
872 /**
873 * \brief Method to include a x-cluster to the track.
874 * @param ip Tracker plane (0-5)
875 * @param clid Cluster ID (0,1,...)
876 * @param is Sensor (0-1, increasing y)
877 * @see Fit(double pfixed, int& fail, int iprint, int froml1)
878 */
879 void TrkTrack::SetXGood(int ip, int clid, int is){
880 int il=0; //ladder (temporary)
881 bool bad=false; //ladder (temporary)
882 xgood[ip]=il*100000000+is*10000000+clid;
883 if(bad)xgood[ip]=-xgood[ip];
884 };
885 /**
886 * \brief Method to include a y-cluster to the track.
887 * @param ip Tracker plane (0-5)
888 * @param clid Cluster ID (0,1,...)
889 * @param is Sensor (0-1)
890 * @see Fit(double pfixed, int& fail, int iprint, int froml1)
891 */
892 void TrkTrack::SetYGood(int ip, int clid, int is){
893 int il=0; //ladder (temporary)
894 bool bad=false; //ladder (temporary)
895 ygood[ip]=il*100000000+is*10000000+clid;
896 if(bad)ygood[ip]=-ygood[ip];
897 };
898
899 //--------------------------------------
900 //
901 //
902 //--------------------------------------
903 void TrkTrack::Clear(){
904 // cout << "TrkTrack::Clear()"<<endl;
905 seqno = -1;
906 image = -1;
907 chi2 = 0;
908 nstep = 0;
909 for(int it1=0;it1<5;it1++){
910 al[it1] = 0;
911 for(int it2=0;it2<5;it2++)coval[it1][it2] = 0;
912 };
913 for(int ip=0;ip<6;ip++){
914 xgood[ip] = 0;
915 ygood[ip] = 0;
916 xm[ip] = 0;
917 ym[ip] = 0;
918 zm[ip] = 0;
919 resx[ip] = 0;
920 resy[ip] = 0;
921 tailx[ip] = 0;
922 taily[ip] = 0;
923 xv[ip] = 0;
924 yv[ip] = 0;
925 zv[ip] = 0;
926 axv[ip] = 0;
927 ayv[ip] = 0;
928 dedx_x[ip] = 0;
929 dedx_y[ip] = 0;
930
931 };
932 // if(clx)clx->Clear();
933 // if(cly)cly->Clear();
934 // clx.Clear();
935 // cly.Clear();
936 };
937 //--------------------------------------
938 //
939 //
940 //--------------------------------------
941 void TrkTrack::Delete(){
942 // cout << "TrkTrack::Delete()"<<endl;
943 Clear();
944 // if(clx)delete clx;
945 // if(cly)delete cly;
946 };
947 //--------------------------------------
948 //
949 //
950 //--------------------------------------
951
952 //--------------------------------------
953 //
954 //
955 //--------------------------------------
956 TrkSinglet::TrkSinglet(){
957 // cout << "TrkSinglet::TrkSinglet() " << GetUniqueID()<<endl;
958 plane = 0;
959 coord[0] = 0;
960 coord[1] = 0;
961 sgnl = 0;
962 // cls = 0;
963 };
964 //--------------------------------------
965 //
966 //
967 //--------------------------------------
968 TrkSinglet::TrkSinglet(const TrkSinglet& s){
969 // cout << "TrkSinglet::TrkSinglet(const TrkSinglet& s) " << GetUniqueID()<<endl;
970 plane = s.plane;
971 coord[0] = s.coord[0];
972 coord[1] = s.coord[1];
973 sgnl = s.sgnl;
974 // cls = 0;//<<<<pointer
975 // cls = TRef(s.cls);
976 };
977 //--------------------------------------
978 //
979 //
980 //--------------------------------------
981 void TrkSinglet::Dump(){
982 int i=0;
983 cout << endl << "========== Singlet " ;
984 cout << endl << "plane : " << plane;
985 cout << endl << "coord[2] : "; while( i<2 && cout << coord[i] << " ") i++;
986 cout << endl << "sgnl : " << sgnl;
987 }
988 //--------------------------------------
989 //
990 //
991 //--------------------------------------
992 void TrkSinglet::Clear(){
993 // cout << "TrkSinglet::Clear() " << GetUniqueID()<<endl;
994 // cls=0;
995 plane=-1;
996 coord[0]=-999;
997 coord[1]=-999;
998 sgnl=0;
999
1000 }
1001 //--------------------------------------
1002 //
1003 //
1004 //--------------------------------------
1005 TrkLevel2::TrkLevel2(){
1006 // cout <<"TrkLevel2::TrkLevel2()"<<endl;
1007 for(Int_t i=0; i<12 ; i++){
1008 good[i] = -1;
1009 VKmask[i] = 0;
1010 VKflag[i] = 0;
1011 };
1012 Track = 0;
1013 SingletX = 0;
1014 SingletY = 0;
1015
1016 }
1017 //--------------------------------------
1018 //
1019 //
1020 //--------------------------------------
1021 void TrkLevel2::Set(){
1022 if(!Track)Track = new TClonesArray("TrkTrack");
1023 if(!SingletX)SingletX = new TClonesArray("TrkSinglet");
1024 if(!SingletY)SingletY = new TClonesArray("TrkSinglet");
1025 }
1026 //--------------------------------------
1027 //
1028 //
1029 //--------------------------------------
1030 void TrkLevel2::Dump(){
1031
1032 //
1033 cout << endl << endl << "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-";
1034 cout << endl << "good : "; for(int i=0; i<12; i++) cout << good[i]<<" ";
1035 cout << endl << "ntrk() : " << this->ntrk() ;
1036 cout << endl << "nclsx() : " << this->nclsx();
1037 cout << endl << "nclsy() : " << this->nclsy();
1038 if(Track){
1039 TClonesArray &t = *Track;
1040 for(int i=0; i<ntrk(); i++) ((TrkTrack *)t[i])->Dump();
1041 }
1042 if(SingletX){
1043 TClonesArray &sx = *SingletX;
1044 for(int i=0; i<nclsx(); i++) ((TrkSinglet *)sx[i])->Dump();
1045 }
1046 if(SingletY){
1047 TClonesArray &sy = *SingletY;
1048 for(int i=0; i<nclsy(); i++) ((TrkSinglet *)sy[i])->Dump();
1049 }
1050 }
1051 /**
1052 * \brief Dump processing status
1053 */
1054 void TrkLevel2::StatusDump(int view){
1055 cout << "DSP n. "<<view+1<<" status: "<<hex<<good[view]<<endl;
1056 };
1057 /**
1058 * \brief Check event status
1059 *
1060 * Check the event status, according to a flag-mask given as input.
1061 * Return true if the view passes the check.
1062 *
1063 * @param view View number (0-11)
1064 * @param flagmask Mask of flags to check (eg. flagmask=0x111 no missing packet,
1065 * no crc error, no software alarm)
1066 *
1067 * @see TrkLevel2 class definition to know how the status flag is defined
1068 *
1069 */
1070 Bool_t TrkLevel2::StatusCheck(int view, int flagmask){
1071
1072 if( view<0 || view >= 12)return false;
1073 return !(good[view]&flagmask);
1074
1075 };
1076
1077
1078 //--------------------------------------
1079 //
1080 //
1081 //--------------------------------------
1082 /**
1083 * The method returns false if the viking-chip was masked
1084 * either apriori ,on the basis of the mask read from the DB,
1085 * or run-by-run, on the basis of the calibration parameters)
1086 * @param iv Tracker view (0-11)
1087 * @param ivk Viking-chip number (0-23)
1088 */
1089 Bool_t TrkLevel2::GetVKMask(int iv, int ivk){
1090 Int_t whichbit = (Int_t)pow(2,ivk);
1091 return (whichbit&VKmask[iv])!=0;
1092 }
1093 /**
1094 * The method returns false if the viking-chip was masked
1095 * for this event due to common-noise computation failure.
1096 * @param iv Tracker view (0-11)
1097 * @param ivk Viking-chip number (0-23)
1098 */
1099 Bool_t TrkLevel2::GetVKFlag(int iv, int ivk){
1100 Int_t whichbit = (Int_t)pow(2,ivk);
1101 return (whichbit&VKflag[iv])!=0;
1102 }
1103 /**
1104 * The method returns true if the viking-chip was masked, either
1105 * forced (see TrkLevel2::GetVKMask(int,int)) or
1106 * for this event only (TrkLevel2::GetVKFlag(int,int)).
1107 * @param iv Tracker view (0-11)
1108 * @param ivk Viking-chip number (0-23)
1109 */
1110 Bool_t TrkLevel2::IsMaskedVK(int iv, int ivk){
1111 return !(GetVKMask(iv,ivk)&&GetVKFlag(iv,ivk) );
1112 };
1113
1114 //--------------------------------------
1115 //
1116 //
1117 //--------------------------------------
1118 /**
1119 * Fills a TrkLevel2 object with values from a struct cTrkLevel2 (to get data from F77 common).
1120 * Ref to Level1 data (clusters) is also set. If l1==NULL no references are set.
1121 * (NB It make sense to set references only if events are stored in a tree that contains also the Level1 branch)
1122 */
1123 void TrkLevel2::SetFromLevel2Struct(cTrkLevel2 *l2, TrkLevel1 *l1){
1124
1125 // cout << "void TrkLevel2::SetFromLevel2Struct(cTrkLevel2 *l2, TrkLevel1 *l1)"<<endl;
1126 Clear();
1127
1128 // temporary objects:
1129 TrkSinglet* t_singlet = new TrkSinglet();
1130 TrkTrack* t_track = new TrkTrack();
1131
1132 // -----------------
1133 // general variables
1134 // -----------------
1135 for(Int_t i=0; i<12 ; i++){
1136 good[i] = l2->good[i];
1137 VKmask[i]=0;
1138 VKflag[i]=0;
1139 for(Int_t ii=0; ii<24 ; ii++){
1140 Int_t setbit = (Int_t)pow(2,ii);
1141 if( l2->vkflag[ii][i]!=-1 )VKmask[i]=VKmask[i]|setbit;
1142 if( l2->vkflag[ii][i]!=0 )VKflag[i]=VKflag[i]|setbit;
1143 };
1144 };
1145 // --------------
1146 // *** TRACKS ***
1147 // --------------
1148 if(!Track) Track = new TClonesArray("TrkTrack");
1149 TClonesArray &t = *Track;
1150
1151 for(int i=0; i<l2->ntrk; i++){
1152 t_track->seqno = i;// NBNBNBNB deve sempre essere = i
1153 t_track->image = l2->image[i]-1;
1154 t_track->chi2 = l2->chi2_nt[i];
1155 t_track->nstep = l2->nstep_nt[i];
1156 for(int it1=0;it1<5;it1++){
1157 t_track->al[it1] = l2->al_nt[i][it1];
1158 for(int it2=0;it2<5;it2++)
1159 t_track->coval[it1][it2] = l2->coval[i][it2][it1];
1160 };
1161 for(int ip=0;ip<6;ip++){
1162 // ---------------------------------
1163 // new implementation of xgood/ygood
1164 // ---------------------------------
1165 t_track->xgood[ip] = l2->cltrx[i][ip]; //cluster ID
1166 t_track->ygood[ip] = l2->cltry[i][ip]; //cluster ID
1167 t_track->xgood[ip] += 10000000*l2->ls[i][ip]; // ladder+sensor
1168 t_track->ygood[ip] += 10000000*l2->ls[i][ip]; // ladder+sensor
1169 if(l2->xbad[i][ip]>0)t_track->xgood[ip]=-t_track->xgood[ip];
1170 if(l2->ybad[i][ip]>0)t_track->ygood[ip]=-t_track->ygood[ip];
1171 // if(l2->xbad[i][ip]>0 || l2->ybad[i][ip]>0){
1172 // if(l2->dedx_x[i][ip]<0 || l2->dedx_y[i][ip]<0){
1173 // cout << ip << " - "<< l2->cltrx[i][ip] << " "<<l2->cltry[i][ip]<<" "<<l2->ls[i][ip]<<endl;
1174 // cout << ip << " - "<<t_track->xgood[ip]<<" "<<t_track->ygood[ip]<<endl;
1175 // cout << ip << " - "<<t_track->GetClusterX_ID(ip)<<" "<<t_track->GetClusterY_ID(ip)<<" "<<t_track->GetLadder(ip)<<" "<<t_track->GetSensor(ip)<<endl;
1176 // cout << ip << " - "<<t_track->BadClusterX(ip)<<" "<<t_track->BadClusterY(ip)<<endl;
1177 // cout << ip << " - "<<t_track->SaturatedClusterX(ip)<<" "<<t_track->SaturatedClusterY(ip)<<endl;
1178 // }
1179 t_track->xm[ip] = l2->xm_nt[i][ip];
1180 t_track->ym[ip] = l2->ym_nt[i][ip];
1181 t_track->zm[ip] = l2->zm_nt[i][ip];
1182 t_track->resx[ip] = l2->resx_nt[i][ip];
1183 t_track->resy[ip] = l2->resy_nt[i][ip];
1184 t_track->tailx[ip] = l2->tailx[i][ip];
1185 t_track->taily[ip] = l2->taily[i][ip];
1186 t_track->xv[ip] = l2->xv_nt[i][ip];
1187 t_track->yv[ip] = l2->yv_nt[i][ip];
1188 t_track->zv[ip] = l2->zv_nt[i][ip];
1189 t_track->axv[ip] = l2->axv_nt[i][ip];
1190 t_track->ayv[ip] = l2->ayv_nt[i][ip];
1191 t_track->dedx_x[ip] = l2->dedx_x[i][ip];
1192 t_track->dedx_y[ip] = l2->dedx_y[i][ip];
1193 //-----------------------------------------------------
1194 //-----------------------------------------------------
1195 //-----------------------------------------------------
1196 //-----------------------------------------------------
1197 };
1198 // if(t_track->IsSaturated())t_track->Dump();
1199 new(t[i]) TrkTrack(*t_track);
1200 t_track->Clear();
1201 };
1202
1203 // ----------------
1204 // *** SINGLETS ***
1205 // ----------------
1206 if(!SingletX)SingletX = new TClonesArray("TrkSinglet");
1207 TClonesArray &sx = *SingletX;
1208 for(int i=0; i<l2->nclsx; i++){
1209 t_singlet->plane = l2->planex[i];
1210 t_singlet->coord[0] = l2->xs[i][0];
1211 t_singlet->coord[1] = l2->xs[i][1];
1212 t_singlet->sgnl = l2->signlxs[i];
1213 //-----------------------------------------------------
1214 // if(l1) t_singlet->cls = l1->GetCluster(l2->clsx[i]-1);
1215 //-----------------------------------------------------
1216 new(sx[i]) TrkSinglet(*t_singlet);
1217 t_singlet->Clear();
1218 }
1219 if(!SingletY)SingletY = new TClonesArray("TrkSinglet");
1220 TClonesArray &sy = *SingletY;
1221 for(int i=0; i<l2->nclsy; i++){
1222 t_singlet->plane = l2->planey[i];
1223 t_singlet->coord[0] = l2->ys[i][0];
1224 t_singlet->coord[1] = l2->ys[i][1];
1225 t_singlet->sgnl = l2->signlys[i];
1226 //-----------------------------------------------------
1227 // if(l1) t_singlet->cls = l1->GetCluster(l2->clsy[i]-1);
1228 //-----------------------------------------------------
1229 new(sy[i]) TrkSinglet(*t_singlet);
1230 t_singlet->Clear();
1231 };
1232
1233 delete t_track;
1234 delete t_singlet;
1235 }
1236 /**
1237 * Fills a struct cTrkLevel2 with values from a TrkLevel2 object (to put data into a F77 common).
1238 */
1239
1240 void TrkLevel2::GetLevel2Struct(cTrkLevel2 *l2) const {
1241
1242 // general variables
1243 // l2->good2 = good2 ;
1244 for(Int_t i=0; i<12 ; i++){
1245 // l2->crc[i] = crc[i];
1246 l2->good[i] = good[i];
1247 };
1248 // *** TRACKS ***
1249
1250 if(Track){
1251 l2->ntrk = Track->GetEntries();
1252 for(Int_t i=0;i<l2->ntrk;i++){
1253 l2->image[i] = 1 + ((TrkTrack *)Track->At(i))->image;
1254 l2->chi2_nt[i] = ((TrkTrack *)Track->At(i))->chi2;
1255 l2->nstep_nt[i] = ((TrkTrack *)Track->At(i))->nstep;
1256 for(int it1=0;it1<5;it1++){
1257 l2->al_nt[i][it1] = ((TrkTrack *)Track->At(i))->al[it1];
1258 for(int it2=0;it2<5;it2++)
1259 l2->coval[i][it2][it1] = ((TrkTrack *)Track->At(i))->coval[it1][it2];
1260 };
1261 for(int ip=0;ip<6;ip++){
1262 l2->xgood_nt[i][ip] = ((TrkTrack *)Track->At(i))->XGood(ip);
1263 l2->ygood_nt[i][ip] = ((TrkTrack *)Track->At(i))->YGood(ip);
1264 l2->xm_nt[i][ip] = ((TrkTrack *)Track->At(i))->xm[ip];
1265 l2->ym_nt[i][ip] = ((TrkTrack *)Track->At(i))->ym[ip];
1266 l2->zm_nt[i][ip] = ((TrkTrack *)Track->At(i))->zm[ip];
1267 l2->resx_nt[i][ip] = ((TrkTrack *)Track->At(i))->resx[ip];
1268 l2->resy_nt[i][ip] = ((TrkTrack *)Track->At(i))->resy[ip];
1269 l2->tailx[i][ip] = ((TrkTrack *)Track->At(i))->tailx[ip];
1270 l2->taily[i][ip] = ((TrkTrack *)Track->At(i))->taily[ip];
1271 l2->xv_nt[i][ip] = ((TrkTrack *)Track->At(i))->xv[ip];
1272 l2->yv_nt[i][ip] = ((TrkTrack *)Track->At(i))->yv[ip];
1273 l2->zv_nt[i][ip] = ((TrkTrack *)Track->At(i))->zv[ip];
1274 l2->axv_nt[i][ip] = ((TrkTrack *)Track->At(i))->axv[ip];
1275 l2->ayv_nt[i][ip] = ((TrkTrack *)Track->At(i))->ayv[ip];
1276 l2->dedx_x[i][ip] = ((TrkTrack *)Track->At(i))->dedx_x[ip];
1277 l2->dedx_y[i][ip] = ((TrkTrack *)Track->At(i))->dedx_y[ip];
1278 };
1279 }
1280 }
1281 // *** SINGLETS ***
1282 if(SingletX){
1283 l2->nclsx = SingletX->GetEntries();
1284 for(Int_t i=0;i<l2->nclsx;i++){
1285 l2->planex[i] = ((TrkSinglet *)SingletX->At(i))->plane;
1286 l2->xs[i][0] = ((TrkSinglet *)SingletX->At(i))->coord[0];
1287 l2->xs[i][1] = ((TrkSinglet *)SingletX->At(i))->coord[1];
1288 l2->signlxs[i] = ((TrkSinglet *)SingletX->At(i))->sgnl;
1289 }
1290 }
1291
1292 if(SingletY){
1293 l2->nclsy = SingletY->GetEntries();
1294 for(Int_t i=0;i<l2->nclsy;i++){
1295 l2->planey[i] = ((TrkSinglet *)SingletY->At(i))->plane;
1296 l2->ys[i][0] = ((TrkSinglet *)SingletY->At(i))->coord[0];
1297 l2->ys[i][1] = ((TrkSinglet *)SingletY->At(i))->coord[1];
1298 l2->signlys[i] = ((TrkSinglet *)SingletY->At(i))->sgnl;
1299 }
1300 }
1301 }
1302 //--------------------------------------
1303 //
1304 //
1305 //--------------------------------------
1306 void TrkLevel2::Clear(){
1307 for(Int_t i=0; i<12 ; i++){
1308 good[i] = -1;
1309 VKflag[i] = 0;
1310 VKmask[i] = 0;
1311 };
1312 // if(Track)Track->Clear("C");
1313 // if(SingletX)SingletX->Clear("C");
1314 // if(SingletY)SingletY->Clear("C");
1315 if(Track)Track->Delete();
1316 if(SingletX)SingletX->Delete();
1317 if(SingletY)SingletY->Delete();
1318 }
1319 // //--------------------------------------
1320 // //
1321 // //
1322 // //--------------------------------------
1323 void TrkLevel2::Delete(){
1324
1325 // cout << "void TrkLevel2::Delete()"<<endl;
1326 Clear();
1327 if(Track)delete Track;
1328 if(SingletX)delete SingletX;
1329 if(SingletY)delete SingletY;
1330
1331 }
1332 //--------------------------------------
1333 //
1334 //
1335 //--------------------------------------
1336 /**
1337 * 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).
1338 * This method is overridden by PamLevel2::GetTracks(), where calorimeter and TOF information is used.
1339 */
1340 TRefArray *TrkLevel2::GetTracks_NFitSorted(){
1341
1342 if(!Track)return 0;
1343
1344 TRefArray *sorted = new TRefArray();
1345
1346 TClonesArray &t = *Track;
1347 // TClonesArray &ts = *PhysicalTrack;
1348 int N = ntrk();
1349 vector<int> m(N); for(int i=0; i<N; i++)m[i]=1;
1350 // int m[50]; for(int i=0; i<N; i++)m[i]=1;
1351
1352 int indo=0;
1353 int indi=0;
1354 while(N > 0){
1355 // while(N != 0){
1356 int nfit =0;
1357 float chi2ref = numeric_limits<float>::max();
1358
1359 // first loop to search maximum num. of fit points
1360 for(int i=0; i < ntrk(); i++){
1361 if( ((TrkTrack *)t[i])->GetNtot() >= nfit && m[i]==1){
1362 nfit = ((TrkTrack *)t[i])->GetNtot();
1363 }
1364 }
1365 //second loop to search minimum chi2 among selected
1366 for(int i=0; i<ntrk(); i++){
1367 Float_t chi2 = ((TrkTrack *)t[i])->chi2;
1368 if(chi2 < 0) chi2 = -chi2*1000;
1369 if( chi2 < chi2ref
1370 && ((TrkTrack *)t[i])->GetNtot() == nfit
1371 && m[i]==1){
1372 chi2ref = ((TrkTrack *)t[i])->chi2;
1373 indi = i;
1374 };
1375 };
1376 if( ((TrkTrack *)t[indi])->HasImage() ){
1377 m[((TrkTrack *)t[indi])->image] = 0;
1378 N--;
1379
1380 // cout << "i** "<< ((TrkTrack *)t[indi])->image << " " << nfiti <<" "<<chi2i<<endl;
1381 };
1382 sorted->Add( (TrkTrack*)t[indi] );
1383
1384 m[indi] = 0;
1385 // cout << "SORTED "<< indo << " "<< indi << " "<< N << " "<<((TrkTrack *)t[indi])->image<<" "<<chi2ref<<endl;
1386 N--;
1387 indo++;
1388 }
1389 m.clear();
1390 // cout << "GetTracks_NFitSorted(it): Done"<< endl;
1391
1392 return sorted;
1393 // return PhysicalTrack;
1394 }
1395 //--------------------------------------
1396 //
1397 //
1398 //--------------------------------------
1399 /**
1400 * Retrieves the is-th stored track.
1401 * @param it Track number, ranging from 0 to ntrk().
1402 * Fitted tracks ( images included ) are stored in a TObjectArray ( TrkLevel2::Track ) in the same order they are returned by the F77 fitting routine.
1403 */
1404 TrkTrack *TrkLevel2::GetStoredTrack(int is){
1405
1406 if(is >= this->ntrk()){
1407 cout << "** TrkLevel2 ** Track "<< is << "doen not exits! " << endl;
1408 cout << " Stored tracks ntrk() = "<< this->ntrk() << endl;
1409 return 0;
1410 }
1411 if(!Track){
1412 cout << "TrkTrack *TrkLevel2::GetStoredTrack(int is) >> (TClonesArray*) Track ==0 "<<endl;
1413 };
1414 TClonesArray &t = *(Track);
1415 TrkTrack *track = (TrkTrack*)t[is];
1416 return track;
1417 }
1418 //--------------------------------------
1419 //
1420 //
1421 //--------------------------------------
1422 /**
1423 * Retrieves the is-th stored X singlet.
1424 * @param it Singlet number, ranging from 0 to nclsx().
1425 */
1426 TrkSinglet *TrkLevel2::GetSingletX(int is){
1427
1428 if(is >= this->nclsx()){
1429 cout << "** TrkLevel2 ** Singlet "<< is << "doen not exits! " << endl;
1430 cout << " Stored x-singlets nclsx() = "<< this->nclsx() << endl;
1431 return 0;
1432 }
1433 if(!SingletX)return 0;
1434 TClonesArray &t = *(SingletX);
1435 TrkSinglet *singlet = (TrkSinglet*)t[is];
1436 return singlet;
1437 }
1438 //--------------------------------------
1439 //
1440 //
1441 //--------------------------------------
1442 /**
1443 * Retrieves the is-th stored Y singlet.
1444 * @param it Singlet number, ranging from 0 to nclsx().
1445 */
1446 TrkSinglet *TrkLevel2::GetSingletY(int is){
1447
1448 if(is >= this->nclsy()){
1449 cout << "** TrkLevel2 ** Singlet "<< is << "doen not exits! " << endl;
1450 cout << " Stored y-singlets nclsy() = "<< this->nclsx() << endl;
1451 return 0;
1452 }
1453 if(!SingletY)return 0;
1454 TClonesArray &t = *(SingletY);
1455 TrkSinglet *singlet = (TrkSinglet*)t[is];
1456 return singlet;
1457 }
1458 //--------------------------------------
1459 //
1460 //
1461 //--------------------------------------
1462 /**
1463 * Retrieves the it-th "physical" track, sorted by the method GetNTracks().
1464 * @param it Track number, ranging from 0 to GetNTracks().
1465 */
1466
1467 TrkTrack *TrkLevel2::GetTrack(int it){
1468
1469 if(it >= this->GetNTracks()){
1470 cout << "** TrkLevel2 ** Track "<< it << "does not exits! " << endl;
1471 cout << " Physical tracks GetNTracks() = "<< this->ntrk() << endl;
1472 return 0;
1473 }
1474
1475 TRefArray *sorted = GetTracks(); //TEMPORANEO
1476 if(!sorted)return 0;
1477 TrkTrack *track = (TrkTrack*)sorted->At(it);
1478 sorted->Clear();
1479 delete sorted;
1480 return track;
1481 }
1482 /**
1483 * Give the number of "physical" tracks, sorted by the method GetTracks().
1484 */
1485 Int_t TrkLevel2::GetNTracks(){
1486
1487 Float_t ntot=0;
1488 if(!Track)return 0;
1489 TClonesArray &t = *Track;
1490 for(int i=0; i<ntrk(); i++) {
1491 if( ((TrkTrack *)t[i])->GetImageSeqNo() == -1 ) ntot+=1.;
1492 else ntot+=0.5;
1493 }
1494 return (Int_t)ntot;
1495
1496 };
1497 //--------------------------------------
1498 //
1499 //
1500 //--------------------------------------
1501 /**
1502 * Retrieves (if present) the image of the it-th "physical" track, sorted by the method GetNTracks().
1503 * @param it Track number, ranging from 0 to GetNTracks().
1504 */
1505 TrkTrack *TrkLevel2::GetTrackImage(int it){
1506
1507 if(it >= this->GetNTracks()){
1508 cout << "** TrkLevel2 ** Track "<< it << "does not exits! " << endl;
1509 cout << " Physical tracks GetNTracks() = "<< this->ntrk() << endl;
1510 return 0;
1511 }
1512
1513 TRefArray* sorted = GetTracks(); //TEMPORANEO
1514 if(!sorted)return 0;
1515 TrkTrack *track = (TrkTrack*)sorted->At(it);
1516
1517 if(!track->HasImage()){
1518 cout << "** TrkLevel2 ** Track "<< it << "does not have image! " << endl;
1519 return 0;
1520 }
1521 if(!Track)return 0;
1522 TrkTrack *image = (TrkTrack*)(*Track)[track->image];
1523
1524 sorted->Delete();
1525 delete sorted;
1526
1527 return image;
1528
1529 }
1530 //--------------------------------------
1531 //
1532 //
1533 //--------------------------------------
1534 /**
1535 * Loads the magnetic field.
1536 * @param s Path of the magnetic-field files.
1537 */
1538 void TrkLevel2::LoadField(TString path){
1539 //
1540 // strcpy(path_.path,path.Data());
1541 // path_.pathlen = path.Length();
1542 // path_.error = 0;
1543 // readb_();
1544
1545 TrkParams::SetTrackingMode();
1546 TrkParams::SetPrecisionFactor();
1547 TrkParams::SetStepMin();
1548
1549 TrkParams::Set(path,1);
1550 TrkParams::Load(1);
1551
1552 //
1553 };
1554 // /**
1555 // * Get BY (kGauss)
1556 // * @param v (x,y,z) coordinates in cm
1557 // */
1558 // float TrkLevel2::GetBX(float* v){
1559 // float b[3];
1560 // gufld_(v,b);
1561 // return b[0]/10.;
1562 // }
1563 // /**
1564 // * Get BY (kGauss)
1565 // * @param v (x,y,z) coordinates in cm
1566 // */
1567 // float TrkLevel2::GetBY(float* v){
1568 // float b[3];
1569 // gufld_(v,b);
1570 // return b[1]/10.;
1571 // }
1572 // /**
1573 // * Get BY (kGauss)
1574 // * @param v (x,y,z) coordinates in cm
1575 // */
1576 // float TrkLevel2::GetBZ(float* v){
1577 // float b[3];
1578 // gufld_(v,b);
1579 // return b[2]/10.;
1580 // }
1581 //--------------------------------------
1582 //
1583 //
1584 //--------------------------------------
1585 /**
1586 * Get tracker-plane (mechanical) z-coordinate
1587 * @param plane_id plane index (1=TOP,2,3,4,5,6=BOTTOM)
1588 */
1589 Float_t TrkLevel2::GetZTrk(Int_t plane_id){
1590 switch(plane_id){
1591 case 1: return ZTRK1;
1592 case 2: return ZTRK2;
1593 case 3: return ZTRK3;
1594 case 4: return ZTRK4;
1595 case 5: return ZTRK5;
1596 case 6: return ZTRK6;
1597 default: return 0.;
1598 };
1599 };
1600 //--------------------------------------
1601 //
1602 //
1603 //--------------------------------------
1604 /**
1605 * Trajectory default constructor.
1606 * (By default is created with z-coordinates inside the tracking volume)
1607 */
1608 Trajectory::Trajectory(){
1609 npoint = 10;
1610 x = new float[npoint];
1611 y = new float[npoint];
1612 z = new float[npoint];
1613 thx = new float[npoint];
1614 thy = new float[npoint];
1615 tl = new float[npoint];
1616 float dz = ((ZTRK1)-(ZTRK6))/(npoint-1);
1617 for(int i=0; i<npoint; i++){
1618 x[i] = 0;
1619 y[i] = 0;
1620 z[i] = (ZTRK1) - i*dz;
1621 thx[i] = 0;
1622 thy[i] = 0;
1623 tl[i] = 0;
1624 }
1625 }
1626 //--------------------------------------
1627 //
1628 //
1629 //--------------------------------------
1630 /**
1631 * Trajectory constructor.
1632 * (By default is created with z-coordinates inside the tracking volume)
1633 * \param n Number of points
1634 */
1635 Trajectory::Trajectory(int n){
1636 if(n<=0){
1637 cout << "NB! Trajectory must have at least 1 point >>> created with 10 points" << endl;
1638 n=10;
1639 }
1640 npoint = n;
1641 x = new float[npoint];
1642 y = new float[npoint];
1643 z = new float[npoint];
1644 thx = new float[npoint];
1645 thy = new float[npoint];
1646 tl = new float[npoint];
1647 float dz = ((ZTRK1)-(ZTRK6))/(npoint-1);
1648 for(int i=0; i<npoint; i++){
1649 x[i] = 0;
1650 y[i] = 0;
1651 z[i] = (ZTRK1) - i*dz;
1652 thx[i] = 0;
1653 thy[i] = 0;
1654 tl[i] = 0;
1655 }
1656 }
1657 //--------------------------------------
1658 //
1659 //
1660 //--------------------------------------
1661 /**
1662 * Trajectory constructor.
1663 * \param n Number of points
1664 * \param pz Pointer to float array, defining z coordinates
1665 */
1666 Trajectory::Trajectory(int n, float* zin){
1667 npoint = 10;
1668 if(n>0)npoint = n;
1669 x = new float[npoint];
1670 y = new float[npoint];
1671 z = new float[npoint];
1672 thx = new float[npoint];
1673 thy = new float[npoint];
1674 tl = new float[npoint];
1675 int i=0;
1676 do{
1677 x[i] = 0;
1678 y[i] = 0;
1679 z[i] = zin[i];
1680 thx[i] = 0;
1681 thy[i] = 0;
1682 tl[i] = 0;
1683 i++;
1684 }while(zin[i-1] > zin[i] && i < npoint);
1685 npoint=i;
1686 if(npoint != n)cout << "NB! Trajectory created with "<<npoint<<" points"<<endl;
1687 }
1688 void Trajectory::Delete(){
1689
1690 if(x) delete [] x;
1691 if(y) delete [] y;
1692 if(z) delete [] z;
1693 if(thx) delete [] thx;
1694 if(thy) delete [] thy;
1695 if(tl) delete [] tl;
1696
1697 }
1698 //--------------------------------------
1699 //
1700 //
1701 //--------------------------------------
1702 /**
1703 * Dump the trajectory coordinates.
1704 */
1705 void Trajectory::Dump(){
1706 cout <<endl<< "Trajectory ========== "<<endl;
1707 for (int i=0; i<npoint; i++){
1708 cout << i <<" >> " << x[i] <<" "<< y[i] <<" "<< z[i] ;
1709 cout <<" -- " << thx[i] <<" "<< thy[i] ;
1710 cout <<" -- " << tl[i] << endl;
1711 };
1712 }
1713 //--------------------------------------
1714 //
1715 //
1716 //--------------------------------------
1717 /**
1718 * Get trajectory length between two points
1719 * @param ifirst first point (default 0)
1720 * @param ilast last point (default npoint)
1721 */
1722 float Trajectory::GetLength(int ifirst, int ilast){
1723 if( ifirst<0 ) ifirst = 0;
1724 if( ilast>=npoint) ilast = npoint-1;
1725 float l=0;
1726 for(int i=ifirst;i<=ilast;i++){
1727 l=l+tl[i];
1728 };
1729 if(z[ilast] > ZINI)l=l-tl[ilast];
1730 if(z[ifirst] < ZINI) l=l-tl[ifirst];
1731
1732 return l;
1733
1734 }
1735
1736 /**
1737 * Evaluates the trajectory in the apparatus associated to the track.
1738 * 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.
1739 * @param t pointer to an object of the class Trajectory,
1740 * which z coordinates should be previously initialized by calling the proper constructor ( Trajectory::Trajectory(int n, float* zin) ).
1741 * @return error flag.
1742 */
1743 int Trajectory::DoTrack2(float* al){
1744
1745 double *dxout = new double[npoint];
1746 double *dyout = new double[npoint];
1747 double *dthxout = new double[npoint];
1748 double *dthyout = new double[npoint];
1749 double *dtlout = new double[npoint];
1750 double *dzin = new double[npoint];
1751 double dal[5];
1752
1753 int ifail = 0;
1754
1755 for (int i=0; i<5; i++) dal[i] = (double)al[i];
1756 for (int i=0; i<npoint; i++) dzin[i] = (double)z[i];
1757
1758 TrkParams::Load(1);
1759 if( !TrkParams::IsLoaded(1) ){
1760 cout << "int Trajectory::DoTrack2(float* al) --- ERROR --- m.field not loaded"<<endl;
1761 return 0;
1762 }
1763 dotrack2_(&(npoint),dzin,dxout,dyout,dthxout,dthyout,dtlout,dal,&ifail);
1764
1765 for (int i=0; i<npoint; i++){
1766 x[i] = (float)*dxout++;
1767 y[i] = (float)*dyout++;
1768 thx[i] = (float)*dthxout++;
1769 thy[i] = (float)*dthyout++;
1770 tl[i] = (float)*dtlout++;
1771 }
1772
1773 return ifail;
1774 };
1775
1776 ClassImp(TrkLevel2);
1777 ClassImp(TrkSinglet);
1778 ClassImp(TrkTrack);
1779 ClassImp(Trajectory);

  ViewVC Help
Powered by ViewVC 1.1.23