/[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.14 - (show annotations) (download)
Fri Oct 27 16:59:20 2006 UTC (18 years, 3 months ago) by pam-fi
Branch: MAIN
Changes since 1.13: +16 -9 lines
*** empty log message ***

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 int readb_(const char*);
16 void mini2_(int*,int*,int*);
17 }
18 //--------------------------------------
19 //
20 //
21 //--------------------------------------
22 TrkTrack::TrkTrack(){
23 seqno = -1;
24 image = -1;
25 chi2 = 0;
26 nstep = 0;
27 for(int it1=0;it1<5;it1++){
28 al[it1] = 0;
29 for(int it2=0;it2<5;it2++)coval[it1][it2] = 0;
30 };
31 for(int ip=0;ip<6;ip++){
32 xgood[ip] = 0;
33 ygood[ip] = 0;
34 xm[ip] = 0;
35 ym[ip] = 0;
36 zm[ip] = 0;
37 resx[ip] = 0;
38 resy[ip] = 0;
39 xv[ip] = 0;
40 yv[ip] = 0;
41 zv[ip] = 0;
42 axv[ip] = 0;
43 ayv[ip] = 0;
44 dedx_x[ip] = 0;
45 dedx_y[ip] = 0;
46 // clx[ip] = 0;
47 // cly[ip] = 0;
48 };
49 clx = new TRefArray(6,0);
50 cly = new TRefArray(6,0);
51 };
52 //--------------------------------------
53 //
54 //
55 //--------------------------------------
56 TrkTrack::TrkTrack(const TrkTrack& t){
57 seqno = t.seqno;
58 image = t.image;
59 chi2 = t.chi2;
60 nstep = t.nstep;
61 for(int it1=0;it1<5;it1++){
62 al[it1] = t.al[it1];
63 for(int it2=0;it2<5;it2++)coval[it1][it2] = t.coval[it1][it2];
64 };
65 for(int ip=0;ip<6;ip++){
66 xgood[ip] = t.xgood[ip];
67 ygood[ip] = t.ygood[ip];
68 xm[ip] = t.xm[ip];
69 ym[ip] = t.ym[ip];
70 zm[ip] = t.zm[ip];
71 resx[ip] = t.resx[ip];
72 resy[ip] = t.resy[ip];
73 xv[ip] = t.xv[ip];
74 yv[ip] = t.yv[ip];
75 zv[ip] = t.zv[ip];
76 axv[ip] = t.axv[ip];
77 ayv[ip] = t.ayv[ip];
78 dedx_x[ip] = t.dedx_x[ip];
79 dedx_y[ip] = t.dedx_y[ip];
80 // clx[ip] = 0;//<<<<pointer
81 // cly[ip] = 0;//<<<<pointer
82 };
83 clx = new TRefArray(*(t.clx));
84 cly = new TRefArray(*(t.cly));
85
86 };
87 //--------------------------------------
88 //
89 //
90 //--------------------------------------
91 /**
92 * Evaluates the trajectory in the apparatus associated to the track.
93 * 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.
94 * @param t pointer to an object of the class Trajectory,
95 * which z coordinates should be previously initialized by calling the proper constructor ( Trajectory::Trajectory(int n, float* zin) ).
96 * @return error flag.
97 */
98 int TrkTrack::DoTrack(Trajectory* t){
99
100 double *dxout = new double[t->npoint];
101 double *dyout = new double[t->npoint];
102 double *dzin = new double[t->npoint];
103 double dal[5];
104
105 int ifail = 0;
106
107 for (int i=0; i<5; i++) dal[i] = (double)al[i];
108 for (int i=0; i<t->npoint; i++) dzin[i] = (double)t->z[i];
109
110 dotrack_(&(t->npoint),dzin,dxout,dyout,dal,&ifail);
111
112 for (int i=0; i<t->npoint; i++){
113 t->x[i] = (float)*dxout++;
114 t->y[i] = (float)*dyout++;
115 }
116
117 // delete [] dxout;
118 // delete [] dyout;
119 // delete [] dzin;
120
121 return ifail;
122 };
123 //--------------------------------------
124 //
125 //
126 //--------------------------------------
127 /**
128 * Evaluates the trajectory in the apparatus associated to the track.
129 * 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.
130 * @param t pointer to an object of the class Trajectory,
131 * which z coordinates should be previously initialized by calling the proper constructor ( Trajectory::Trajectory(int n, float* zin) ).
132 * @return error flag.
133 */
134 int TrkTrack::DoTrack2(Trajectory* t){
135
136 double *dxout = new double[t->npoint];
137 double *dyout = new double[t->npoint];
138 double *dthxout = new double[t->npoint];
139 double *dthyout = new double[t->npoint];
140 double *dtlout = new double[t->npoint];
141 double *dzin = new double[t->npoint];
142 double dal[5];
143
144 int ifail = 0;
145
146 for (int i=0; i<5; i++) dal[i] = (double)al[i];
147 for (int i=0; i<t->npoint; i++) dzin[i] = (double)t->z[i];
148
149 dotrack2_(&(t->npoint),dzin,dxout,dyout,dthxout,dthyout,dtlout,dal,&ifail);
150
151 for (int i=0; i<t->npoint; i++){
152 t->x[i] = (float)*dxout++;
153 t->y[i] = (float)*dyout++;
154 t->thx[i] = (float)*dthxout++;
155 t->thy[i] = (float)*dthyout++;
156 t->tl[i] = (float)*dtlout++;
157 }
158
159 // delete [] dxout;
160 // delete [] dyout;
161 // delete [] dzin;
162
163 return ifail;
164 };
165 //--------------------------------------
166 //
167 //
168 //--------------------------------------
169 //float TrkTrack::BdL(){
170 //};
171 //--------------------------------------
172 //
173 //
174 //--------------------------------------
175 Float_t TrkTrack::GetRigidity(){
176 Float_t rig=0;
177 if(chi2>0)rig=1./al[4];
178 if(rig<0) rig=-rig;
179 return rig;
180 };
181 //
182 Float_t TrkTrack::GetDeflection(){
183 Float_t def=0;
184 if(chi2>0)def=al[4];
185 return def;
186 };
187 //
188 Float_t TrkTrack::GetDEDX(){
189 Float_t dedx=0;
190 for(Int_t i=0; i<6; i++)dedx+=dedx_x[i]*xgood[i]+dedx_y[i]*ygood[i];
191 dedx = dedx/(this->GetNX()+this->GetNY());
192 return dedx;
193 };
194
195 //--------------------------------------
196 //
197 //
198 //--------------------------------------
199 void TrkTrack::Dump(){
200 cout << endl << "========== Track " ;
201 cout << endl << "seq. n. : "<< seqno;
202 cout << endl << "image n. : "<< image;
203 cout << endl << "al : "; for(int i=0; i<5; i++)cout << al[i] << " ";
204 cout << endl << "chi^2 : "<< chi2;
205 cout << endl << "n.step : "<< nstep;
206 cout << endl << "xgood : "; for(int i=0; i<6; i++)cout << xgood[i] ;
207 cout << endl << "ygood : "; for(int i=0; i<6; i++)cout << ygood[i] ;
208 cout << endl << "xm : "; for(int i=0; i<6; i++)cout << xm[i] << " ";
209 cout << endl << "ym : "; for(int i=0; i<6; i++)cout << ym[i] << " ";
210 cout << endl << "zm : "; for(int i=0; i<6; i++)cout << zm[i] << " ";
211 cout << endl << "xv : "; for(int i=0; i<6; i++)cout << xv[i] << " ";
212 cout << endl << "yv : "; for(int i=0; i<6; i++)cout << yv[i] << " ";
213 cout << endl << "zv : "; for(int i=0; i<6; i++)cout << zv[i] << " ";
214 cout << endl << "resx : "; for(int i=0; i<6; i++)cout << resx[i] << " ";
215 cout << endl << "resy : "; for(int i=0; i<6; i++)cout << resy[i] << " ";
216 cout << endl << "coval : "; for(int i=0; i<5; i++)cout << coval[0][i]<<" ";
217 cout << endl << " "; for(int i=0; i<5; i++)cout << coval[1][i]<<" ";
218 cout << endl << " "; for(int i=0; i<5; i++)cout << coval[2][i]<<" ";
219 cout << endl << " "; for(int i=0; i<5; i++)cout << coval[3][i]<<" ";
220 cout << endl << " "; for(int i=0; i<5; i++)cout << coval[4][i]<<" ";
221 cout << endl << "dedx_x : "; for(int i=0; i<6; i++)cout << dedx_x[i] << " ";
222 cout << endl << "dedx_y : "; for(int i=0; i<6; i++)cout << dedx_y[i] << " ";
223 cout << endl;
224 }
225 /**
226 * Set the TrkTrack position measurements
227 */
228 void TrkTrack::SetMeasure(double *xmeas, double *ymeas, double *zmeas){
229 for(int i=0; i<6; i++) xm[i]=*xmeas++;
230 for(int i=0; i<6; i++) ym[i]=*ymeas++;
231 for(int i=0; i<6; i++) zm[i]=*zmeas++;
232 }
233 /**
234 * Set the TrkTrack position resolution
235 */
236 void TrkTrack::SetResolution(double *rx, double *ry){
237 for(int i=0; i<6; i++) resx[i]=*rx++;
238 for(int i=0; i<6; i++) resy[i]=*ry++;
239 }
240 /**
241 * Set the TrkTrack good measurement
242 */
243 void TrkTrack::SetGood(int *xg, int *yg){
244 for(int i=0; i<6; i++) xgood[i]=*xg++;
245 for(int i=0; i<6; i++) ygood[i]=*yg++;
246 }
247
248 /**
249 * Load the magnetic field
250 */
251 void TrkTrack::LoadField(TString s){
252 readb_(s.Data());
253 };
254 /**
255 * Tracking method. It calls F77 mini routine.
256 */
257 void TrkTrack::Fit(double pfixed, int& fail, int iprint){
258 extern cMini2track track_;
259 fail = 0;
260 // extern cMini2fitinfo fit_info_;
261 // extern void mini_2_(int*,int*);
262 // track_.xm[0]=1.0;
263 for(int i=0; i<6; i++) track_.xm[i]=xm[i];
264 for(int i=0; i<6; i++) track_.ym[i]=ym[i];
265 for(int i=0; i<6; i++) track_.zm[i]=zm[i];
266 for(int i=0; i<6; i++) track_.resx[i]=resx[i];
267 for(int i=0; i<6; i++) track_.resy[i]=resy[i];
268 for(int i=0; i<6; i++) track_.xgood[i]=xgood[i];
269 for(int i=0; i<6; i++) track_.ygood[i]=ygood[i];
270 // initial guess of "al" with linear fit
271 if(al[0]==-9999.&&al[1]==-9999.&&al[2]==-9999.&&al[3]==-9999.&&al[4]==-9999.){
272 double szz=0., szx=0., szy=0., ssx=0., ssy=0., sz=0., s1=0.;
273 double det, ax, ay, bx, by;
274 for(int i=0; i<NPLANE; i++) {
275 szz=szz+zm[i]*zm[i];
276 szx=szx+zm[i]*xm[i];
277 szy=szy+zm[i]*ym[i];
278 ssx=ssx+xm[i];
279 ssy=ssy+ym[i];
280 sz=sz+zm[i];
281 s1=s1+1.;
282 }
283 det=szz*s1-sz*sz;
284 ax=(szx*s1-sz*ssx)/det;
285 bx=(szz*ssx-szx*sz)/det;
286 ay=(szy*s1-sz*ssy)/det;
287 by=(szz*ssy-szy*sz)/det;
288 al[0]=ax*23.5+bx; // ZINI = 23.5 !!! it should be the same parameter in all codes
289 al[1]=ay*23.5+by; // "
290 al[2]= sqrt(pow(ax,2)+pow(ay,2))/ sqrt(pow(ax,2)+pow(ay,2)+1.);
291 al[3]=0.;
292 if( (ax!=0.)||(ay!=0.) ) {
293 al[3]= asin(ay/ sqrt(pow(ax,2)+pow(ay,2)));
294 if(ax<0.) al[3]=acos(-1.)-al[3];
295 }
296 al[4]=0.;
297 }
298 // end guess
299 if(pfixed==0.) {
300 al[4]=0.; // free momentum
301 track_.pfixed=0.; // "
302 }
303 if(pfixed!=0.) {
304 al[4]=1./pfixed; // to fix the momentum
305 track_.pfixed=pfixed; // "
306 }
307 track_.zini = 23.5; // ZINI = 23.5 !!! it should be the same parameter in all codes
308 for(int i=0; i<5; i++) track_.al[i]=al[i];
309 int istep=0;
310 int ifail=0;
311 mini2_(&istep,&ifail, &iprint);
312 if(ifail!=0) {
313 if(iprint==1)cout << "ERROR: ifail= " << ifail << endl;
314 fail = 1;
315 // return;
316 }
317
318 // cout << endl << "eta ===> " << track_.al[4] << endl;
319
320 for(int i=0; i<5; i++) al[i]=track_.al[i];
321 chi2=track_.chi2;
322 nstep=track_.nstep;
323 for(int i=0; i<6; i++) xv[i]=track_.xv[i];
324 for(int i=0; i<6; i++) yv[i]=track_.yv[i];
325 for(int i=0; i<6; i++) zv[i]=track_.zv[i];
326 for(int i=0; i<6; i++) axv[i]=track_.axv[i];
327 for(int i=0; i<6; i++) ayv[i]=track_.ayv[i];
328 for(int i=0; i<5; i++) {
329 for(int j=0; j<5; j++) coval[i][j]=track_.cov[i][j];
330 }
331 };
332 /*
333 * Reset the parameters fit
334 */
335 void TrkTrack::FitReset(){
336 for(int i=0; i<5; i++) al[i]=-9999.;
337 chi2=0.;
338 nstep=0;
339 for(int i=0; i<6; i++) xv[i]=0.;
340 for(int i=0; i<6; i++) yv[i]=0.;
341 for(int i=0; i<6; i++) zv[i]=0.;
342 for(int i=0; i<6; i++) axv[i]=0.;
343 for(int i=0; i<6; i++) ayv[i]=0.;
344 for(int i=0; i<5; i++) {
345 for(int j=0; j<5; j++) coval[i][j]=0.;
346 }
347 }
348
349 //--------------------------------------
350 //
351 //
352 //--------------------------------------
353 void TrkTrack::Clear(){
354 seqno = -1;
355 image = -1;
356 chi2 = 0;
357 nstep = 0;
358 for(int it1=0;it1<5;it1++){
359 al[it1] = 0;
360 for(int it2=0;it2<5;it2++)coval[it1][it2] = 0;
361 };
362 for(int ip=0;ip<6;ip++){
363 xgood[ip] = 0;
364 ygood[ip] = 0;
365 xm[ip] = 0;
366 ym[ip] = 0;
367 zm[ip] = 0;
368 resx[ip] = 0;
369 resy[ip] = 0;
370 xv[ip] = 0;
371 yv[ip] = 0;
372 zv[ip] = 0;
373 axv[ip] = 0;
374 ayv[ip] = 0;
375 dedx_x[ip] = 0;
376 dedx_y[ip] = 0;
377 // clx[ip] = 0;
378 // cly[ip] = 0;
379 };
380 clx->Clear();
381 cly->Clear();
382 };
383 //--------------------------------------
384 //
385 //
386 //--------------------------------------
387 void TrkTrack::Delete(){
388 Clear();
389 clx->Delete();
390 cly->Delete();
391 };
392 //--------------------------------------
393 //
394 //
395 //--------------------------------------
396
397 //--------------------------------------
398 //
399 //
400 //--------------------------------------
401 TrkSinglet::TrkSinglet(){
402 plane = 0;
403 coord[0] = 0;
404 coord[1] = 0;
405 sgnl = 0;
406 cls = 0;
407 };
408 //--------------------------------------
409 //
410 //
411 //--------------------------------------
412 TrkSinglet::TrkSinglet(const TrkSinglet& s){
413 plane = s.plane;
414 coord[0] = s.coord[0];
415 coord[1] = s.coord[1];
416 sgnl = s.sgnl;
417 // cls = 0;//<<<<pointer
418 cls = TRef(s.cls);
419 };
420 //--------------------------------------
421 //
422 //
423 //--------------------------------------
424 void TrkSinglet::Dump(){
425 int i=0;
426 cout << endl << "========== Singlet " ;
427 cout << endl << "plane : " << plane;
428 cout << endl << "coord[2] : "; while( i<2 && cout << coord[i] << " ") i++;
429 cout << endl << "sgnl : " << sgnl;
430 }
431 //--------------------------------------
432 //
433 //
434 //--------------------------------------
435 TrkLevel2::TrkLevel2(){
436 // good2 = -1;
437 for(Int_t i=0; i<12 ; i++){
438 // crc[i] = -1;
439 good[i] = -1;
440 };
441 Track = new TClonesArray("TrkTrack");
442 SingletX = new TClonesArray("TrkSinglet");
443 SingletY = new TClonesArray("TrkSinglet");
444
445 // PhysicalTrack = new TClonesArray("TrkTrack");
446 //sostituire con TRefArray... appena ho capito come si usa
447 }
448 //--------------------------------------
449 //
450 //
451 //--------------------------------------
452 void TrkLevel2::Dump(){
453
454 TClonesArray &t = *Track;
455 TClonesArray &sx = *SingletX;
456 TClonesArray &sy = *SingletY;
457 //
458 cout << endl << endl << "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-";
459 cout << endl << "good : "; for(int i=0; i<12; i++) cout << good[i]<<" ";
460 cout << endl << "ntrk() : " << this->ntrk() ;
461 cout << endl << "nclsx() : " << this->nclsx();
462 cout << endl << "nclsy() : " << this->nclsy();
463 for(int i=0; i<this->ntrk(); i++) ((TrkTrack *)t[i])->Dump();
464 for(int i=0; i<this->nclsx(); i++) ((TrkSinglet *)sx[i])->Dump();
465 for(int i=0; i<this->nclsy(); i++) ((TrkSinglet *)sy[i])->Dump();
466 }
467 //--------------------------------------
468 //
469 //
470 //--------------------------------------
471 /**
472 * Fills a TrkLevel2 object with values from a struct cTrkLevel2 (to get data from F77 common).
473 */
474 void TrkLevel2::SetFromLevel2Struct(cTrkLevel2 *l2){
475
476 // temporary objects:
477 TrkSinglet* t_singlet = new TrkSinglet();
478 TrkTrack* t_track = new TrkTrack();
479
480 // **** general variables ****
481 // good2 = l2->good2;
482 for(Int_t i=0; i<12 ; i++){
483 // crc[i] = l2->crc[i];
484 good[i] = l2->good[i];
485 };
486 // *** TRACKS ***
487 TClonesArray &t = *Track;
488 for(int i=0; i<l2->ntrk; i++){
489 t_track->seqno = i;// NBNBNBNB deve sempre essere = i
490 t_track->image = l2->image[i]-1;
491 // cout << "track "<<i<<t_track->seqno << t_track->image<<endl;
492 t_track->chi2 = l2->chi2_nt[i];
493 t_track->nstep = l2->nstep_nt[i];
494 for(int it1=0;it1<5;it1++){
495 t_track->al[it1] = l2->al_nt[i][it1];
496 for(int it2=0;it2<5;it2++)
497 t_track->coval[it1][it2] = l2->coval[i][it2][it1];
498 };
499 for(int ip=0;ip<6;ip++){
500 t_track->xgood[ip] = l2->xgood_nt[i][ip];
501 t_track->ygood[ip] = l2->ygood_nt[i][ip];
502 t_track->xm[ip] = l2->xm_nt[i][ip];
503 t_track->ym[ip] = l2->ym_nt[i][ip];
504 t_track->zm[ip] = l2->zm_nt[i][ip];
505 t_track->resx[ip] = l2->resx_nt[i][ip];
506 t_track->resy[ip] = l2->resy_nt[i][ip];
507 t_track->xv[ip] = l2->xv_nt[i][ip];
508 t_track->yv[ip] = l2->yv_nt[i][ip];
509 t_track->zv[ip] = l2->zv_nt[i][ip];
510 t_track->axv[ip] = l2->axv_nt[i][ip];
511 t_track->ayv[ip] = l2->ayv_nt[i][ip];
512 t_track->dedx_x[ip] = l2->dedx_x[i][ip];
513 t_track->dedx_y[ip] = l2->dedx_y[i][ip];
514 // t_track->clx[ip] = 0;
515 // t_track->cly[ip] = 0;
516 };
517 new(t[i]) TrkTrack(*t_track);
518 t_track->Clear();
519 };
520 // *** SINGLETS ***
521 TClonesArray &sx = *SingletX;
522 for(int i=0; i<l2->nclsx; i++){
523 t_singlet->plane = l2->planex[i];
524 t_singlet->coord[0] = l2->xs[i][0];
525 t_singlet->coord[1] = l2->xs[i][1];
526 t_singlet->sgnl = l2->signlxs[i];
527 // t_singlet->cls = 0;
528 new(sx[i]) TrkSinglet(*t_singlet);
529 t_singlet->Clear();
530 }
531 TClonesArray &sy = *SingletY;
532 for(int i=0; i<l2->nclsy; i++){
533 t_singlet->plane = l2->planey[i];
534 t_singlet->coord[0] = l2->ys[i][0];
535 t_singlet->coord[1] = l2->ys[i][1];
536 t_singlet->sgnl = l2->signlys[i];
537 // t_singlet->cls = 0;
538 new(sy[i]) TrkSinglet(*t_singlet);
539 t_singlet->Clear();
540 };
541
542 delete t_track;
543 delete t_singlet;
544 }
545 //--------------------------------------
546 //
547 //
548 //--------------------------------------
549 /**
550 * Fills a TrkLevel2 object with values from a struct cTrkLevel2 (to get data from F77 common).
551 * Ref to Level1 data (clusters) is also set.
552 */
553 void TrkLevel2::SetFromLevel2Struct(cTrkLevel2 *l2, TrkLevel1 *l1){
554
555 // temporary objects:
556 TrkSinglet* t_singlet = new TrkSinglet();
557 TrkTrack* t_track = new TrkTrack();
558 // general variables
559 // good2 = l2->good2;
560 for(Int_t i=0; i<12 ; i++){
561 // crc[i] = l2->crc[i];
562 good[i] = l2->good[i];
563 };
564 // *** TRACKS ***
565 TClonesArray &t = *Track;
566 for(int i=0; i<l2->ntrk; i++){
567 t_track->seqno = i;// NBNBNBNB deve sempre essere = i
568 t_track->image = l2->image[i]-1;
569 // cout << "track "<<i<<t_track->seqno << t_track->image<<endl;
570 t_track->chi2 = l2->chi2_nt[i];
571 t_track->nstep = l2->nstep_nt[i];
572 for(int it1=0;it1<5;it1++){
573 t_track->al[it1] = l2->al_nt[i][it1];
574 for(int it2=0;it2<5;it2++)
575 t_track->coval[it1][it2] = l2->coval[i][it2][it1];
576 };
577 for(int ip=0;ip<6;ip++){
578 t_track->xgood[ip] = l2->xgood_nt[i][ip];
579 t_track->ygood[ip] = l2->ygood_nt[i][ip];
580 t_track->xm[ip] = l2->xm_nt[i][ip];
581 t_track->ym[ip] = l2->ym_nt[i][ip];
582 t_track->zm[ip] = l2->zm_nt[i][ip];
583 t_track->resx[ip] = l2->resx_nt[i][ip];
584 t_track->resy[ip] = l2->resy_nt[i][ip];
585 t_track->xv[ip] = l2->xv_nt[i][ip];
586 t_track->yv[ip] = l2->yv_nt[i][ip];
587 t_track->zv[ip] = l2->zv_nt[i][ip];
588 t_track->axv[ip] = l2->axv_nt[i][ip];
589 t_track->ayv[ip] = l2->ayv_nt[i][ip];
590 t_track->dedx_x[ip] = l2->dedx_x[i][ip];
591 t_track->dedx_y[ip] = l2->dedx_y[i][ip];
592 // cout << "traccia "<<i<<" -- "<< ip << " "<< l2->cltrx[i][ip] <<" "<< l2->cltry[i][ip] <<" "<< t_track->xgood[ip] << t_track->ygood[ip]<<endl;
593 //-----------------------------------------------------
594 // t_track->clx[ip] = l1->GetCluster(l2->cltrx[i][ip]-1);
595 // t_track->cly[ip] = l1->GetCluster(l2->cltry[i][ip]-1);
596 if(t_track->xgood[ip])t_track->clx->AddAt(l1->GetCluster(l2->cltrx[i][ip]-1),ip);
597 if(t_track->ygood[ip])t_track->cly->AddAt(l1->GetCluster(l2->cltry[i][ip]-1),ip);
598 // if(t_track->ygood[ip])cout<<" i "<<i<<" ip "<<ip<<" l2->cltry[i][ip] "<<l2->cltry[i][ip]<< " l1->GetCluster(l2->cltry[i][ip]-1) "<<l1->GetCluster(l2->cltry[i][ip]-1)<<endl;
599 // if(t_track->xgood[ip])cout<<" i "<<i<<" ip "<<ip<<" l2->cltrx[i][ip] "<<l2->cltrx[i][ip]<< " l1->GetCluster(l2->cltrx[i][ip]-1) "<<l1->GetCluster(l2->cltrx[i][ip]-1)<<endl;
600 //-----------------------------------------------------
601 };
602 new(t[i]) TrkTrack(*t_track);
603 t_track->Clear();
604 };
605 // *** SINGLETS ***
606 TClonesArray &sx = *SingletX;
607 for(int i=0; i<l2->nclsx; i++){
608 t_singlet->plane = l2->planex[i];
609 t_singlet->coord[0] = l2->xs[i][0];
610 t_singlet->coord[1] = l2->xs[i][1];
611 t_singlet->sgnl = l2->signlxs[i];
612 //-----------------------------------------------------
613 // cout << "singolo x "<<i<<" -- "<< l2->clsx[i] <<endl;
614 t_singlet->cls = l1->GetCluster(l2->clsx[i]-1);
615 // cout<<" i "<<i<<" l2->clsx[i] "<<l2->clsx[i]<< " l1->GetCluster(l2->clsx[i]-1) "<<l1->GetCluster(l2->clsx[i]-1)<<endl;
616 //-----------------------------------------------------
617 new(sx[i]) TrkSinglet(*t_singlet);
618 t_singlet->Clear();
619 }
620 TClonesArray &sy = *SingletY;
621 for(int i=0; i<l2->nclsy; i++){
622 t_singlet->plane = l2->planey[i];
623 t_singlet->coord[0] = l2->ys[i][0];
624 t_singlet->coord[1] = l2->ys[i][1];
625 t_singlet->sgnl = l2->signlys[i];
626 //-----------------------------------------------------
627 // cout << "singolo y "<<i<<" -- "<< l2->clsy[i] <<endl;
628 t_singlet->cls = l1->GetCluster(l2->clsy[i]-1);
629 // cout<<" i "<<i<<" l2->clsy[i] "<<l2->clsy[i]<< " l1->GetCluster(l2->clsy[i]-1) "<<l1->GetCluster(l2->clsy[i]-1)<<endl;
630 //-----------------------------------------------------
631 new(sy[i]) TrkSinglet(*t_singlet);
632 t_singlet->Clear();
633 };
634
635 delete t_track;
636 delete t_singlet;
637 }
638 /**
639 * Fills a struct cTrkLevel2 with values from a TrkLevel2 object (to put data into a F77 common).
640 */
641
642 void TrkLevel2::GetLevel2Struct(cTrkLevel2 *l2) const {
643
644 // general variables
645 // l2->good2 = good2 ;
646 for(Int_t i=0; i<12 ; i++){
647 // l2->crc[i] = crc[i];
648 l2->good[i] = good[i];
649 };
650 // *** TRACKS ***
651
652 l2->ntrk = Track->GetEntries();
653 for(Int_t i=0;i<l2->ntrk;i++){
654 l2->image[i] = 1 + ((TrkTrack *)Track->At(i))->image;
655 l2->chi2_nt[i] = ((TrkTrack *)Track->At(i))->chi2;
656 l2->nstep_nt[i] = ((TrkTrack *)Track->At(i))->nstep;
657 for(int it1=0;it1<5;it1++){
658 l2->al_nt[i][it1] = ((TrkTrack *)Track->At(i))->al[it1];
659 for(int it2=0;it2<5;it2++)
660 l2->coval[i][it2][it1] = ((TrkTrack *)Track->At(i))->coval[it1][it2];
661 };
662 for(int ip=0;ip<6;ip++){
663 l2->xgood_nt[i][ip] = ((TrkTrack *)Track->At(i))->xgood[ip];
664 l2->ygood_nt[i][ip] = ((TrkTrack *)Track->At(i))->ygood[ip];
665 l2->xm_nt[i][ip] = ((TrkTrack *)Track->At(i))->xm[ip];
666 l2->ym_nt[i][ip] = ((TrkTrack *)Track->At(i))->ym[ip];
667 l2->zm_nt[i][ip] = ((TrkTrack *)Track->At(i))->zm[ip];
668 l2->resx_nt[i][ip] = ((TrkTrack *)Track->At(i))->resx[ip];
669 l2->resy_nt[i][ip] = ((TrkTrack *)Track->At(i))->resy[ip];
670 l2->xv_nt[i][ip] = ((TrkTrack *)Track->At(i))->xv[ip];
671 l2->yv_nt[i][ip] = ((TrkTrack *)Track->At(i))->yv[ip];
672 l2->zv_nt[i][ip] = ((TrkTrack *)Track->At(i))->zv[ip];
673 l2->axv_nt[i][ip] = ((TrkTrack *)Track->At(i))->axv[ip];
674 l2->ayv_nt[i][ip] = ((TrkTrack *)Track->At(i))->ayv[ip];
675 l2->dedx_x[i][ip] = ((TrkTrack *)Track->At(i))->dedx_x[ip];
676 l2->dedx_y[i][ip] = ((TrkTrack *)Track->At(i))->dedx_y[ip];
677 };
678 }
679
680 // *** SINGLETS ***
681 l2->nclsx = SingletX->GetEntries();
682 for(Int_t i=0;i<l2->nclsx;i++){
683 l2->planex[i] = ((TrkSinglet *)SingletX->At(i))->plane;
684 l2->xs[i][0] = ((TrkSinglet *)SingletX->At(i))->coord[0];
685 l2->xs[i][1] = ((TrkSinglet *)SingletX->At(i))->coord[1];
686 l2->signlxs[i] = ((TrkSinglet *)SingletX->At(i))->sgnl;
687 }
688 l2->nclsy = SingletY->GetEntries();
689 for(Int_t i=0;i<l2->nclsy;i++){
690 l2->planey[i] = ((TrkSinglet *)SingletY->At(i))->plane;
691 l2->ys[i][0] = ((TrkSinglet *)SingletY->At(i))->coord[0];
692 l2->ys[i][1] = ((TrkSinglet *)SingletY->At(i))->coord[1];
693 l2->signlys[i] = ((TrkSinglet *)SingletY->At(i))->sgnl;
694 }
695 }
696 //--------------------------------------
697 //
698 //
699 //--------------------------------------
700 void TrkLevel2::Clear(){
701 // good2 = -1;
702 for(Int_t i=0; i<12 ; i++){
703 // crc[i] = -1;
704 good[i] = -1;
705 };
706 /* Track->RemoveAll();
707 SingletX->RemoveAll();
708 SingletY->RemoveAll();*/
709 // modify to avoid memory leakage
710 Track->Clear();
711 SingletX->Clear();
712 SingletY->Clear();
713 }
714 //--------------------------------------
715 //
716 //
717 //--------------------------------------
718 void TrkLevel2::Delete(){
719
720 Clear();
721 Track->Delete();
722 SingletX->Delete();
723 SingletY->Delete();
724 }
725 //--------------------------------------
726 //
727 //
728 //--------------------------------------
729 /**
730 * 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).
731 * This method is overridden by PamLevel2::GetTracks(), where calorimeter and TOF information is used.
732 */
733 TRefArray *TrkLevel2::GetTracks_NFitSorted(){
734
735 TRefArray *sorted = new TRefArray();
736
737 TClonesArray &t = *Track;
738 // TClonesArray &ts = *PhysicalTrack;
739 int N = ntrk();
740 vector<int> m(N); for(int i=0; i<N; i++)m[i]=1;
741 // int m[50]; for(int i=0; i<N; i++)m[i]=1;
742
743 int indo=0;
744 int indi=0;
745 while(N != 0){
746 int nfit =0;
747 float chi2ref = numeric_limits<float>::max();
748
749 // first loop to search maximum num. of fit points
750 for(int i=0; i < ntrk(); i++){
751 if( ((TrkTrack *)t[i])->GetNtot() >= nfit && m[i]==1){
752 nfit = ((TrkTrack *)t[i])->GetNtot();
753 }
754 }
755 //second loop to search minimum chi2 among selected
756 for(int i=0; i<this->ntrk(); i++){
757 Float_t chi2 = ((TrkTrack *)t[i])->chi2;
758 if(chi2 < 0) chi2 = chi2*1000;
759 if( chi2 < chi2ref
760 && ((TrkTrack *)t[i])->GetNtot() == nfit
761 && m[i]==1){
762 chi2ref = ((TrkTrack *)t[i])->chi2;
763 indi = i;
764 };
765 };
766 if( ((TrkTrack *)t[indi])->HasImage() ){
767 m[((TrkTrack *)t[indi])->image] = 0;
768 N--;
769
770 // cout << "i** "<< ((TrkTrack *)t[indi])->image << " " << nfiti <<" "<<chi2i<<endl;
771 };
772 sorted->Add( (TrkTrack*)t[indi] );
773
774 m[indi] = 0;
775 // cout << "SORTED "<< indo << " "<< indi << " "<< N << endl;
776 N--;
777 indo++;
778 }
779 m.clear();
780 // cout << "GetTracks_NFitSorted(it): Done"<< endl;
781
782 return sorted;
783 // return PhysicalTrack;
784 }
785 //--------------------------------------
786 //
787 //
788 //--------------------------------------
789 /**
790 * Retrieves the is-th stored track.
791 * @param it Track number, ranging from 0 to ntrk().
792 * Fitted tracks ( images included ) are stored in a TObjectArray ( TrkLevel2::Track ) in the same order they are returned by the F77 fitting routine.
793 */
794 TrkTrack *TrkLevel2::GetStoredTrack(int is){
795
796 if(is >= this->ntrk()){
797 cout << "** TrkLevel2 ** Track "<< is << "doen not exits! " << endl;
798 cout << " Stored tracks ntrk() = "<< this->ntrk() << endl;
799 return 0;
800 }
801 TClonesArray &t = *(Track);
802 TrkTrack *track = (TrkTrack*)t[is];
803 return track;
804 }
805 //--------------------------------------
806 //
807 //
808 //--------------------------------------
809 /**
810 * Retrieves the is-th stored X singlet.
811 * @param it Singlet number, ranging from 0 to nclsx().
812 */
813 TrkSinglet *TrkLevel2::GetSingletX(int is){
814
815 if(is >= this->nclsx()){
816 cout << "** TrkLevel2 ** Singlet "<< is << "doen not exits! " << endl;
817 cout << " Stored x-singlets nclsx() = "<< this->nclsx() << endl;
818 return 0;
819 }
820 TClonesArray &t = *(SingletX);
821 TrkSinglet *singlet = (TrkSinglet*)t[is];
822 return singlet;
823 }
824 //--------------------------------------
825 //
826 //
827 //--------------------------------------
828 /**
829 * Retrieves the is-th stored Y singlet.
830 * @param it Singlet number, ranging from 0 to nclsx().
831 */
832 TrkSinglet *TrkLevel2::GetSingletY(int is){
833
834 if(is >= this->nclsy()){
835 cout << "** TrkLevel2 ** Singlet "<< is << "doen not exits! " << endl;
836 cout << " Stored y-singlets nclsy() = "<< this->nclsx() << endl;
837 return 0;
838 }
839 TClonesArray &t = *(SingletY);
840 TrkSinglet *singlet = (TrkSinglet*)t[is];
841 return singlet;
842 }
843 //--------------------------------------
844 //
845 //
846 //--------------------------------------
847 /**
848 * Retrieves the it-th "physical" track, sorted by the method GetNTracks().
849 * @param it Track number, ranging from 0 to GetNTracks().
850 */
851
852 TrkTrack *TrkLevel2::GetTrack(int it){
853
854 if(it >= this->GetNTracks()){
855 cout << "** TrkLevel2 ** Track "<< it << "does not exits! " << endl;
856 cout << " Physical tracks GetNTracks() = "<< this->ntrk() << endl;
857 return 0;
858 }
859
860 TRefArray *sorted = GetTracks(); //TEMPORANEO
861 TrkTrack *track = (TrkTrack*)sorted->At(it);
862 sorted->Delete();
863 return track;
864 }
865 /**
866 * Give the number of "physical" tracks, sorted by the method GetTracks().
867 */
868 Int_t TrkLevel2::GetNTracks(){
869
870 Float_t ntot=0;
871 TClonesArray &t = *Track;
872 for(int i=0; i<ntrk(); i++) {
873 if( ((TrkTrack *)t[i])->GetImageSeqNo() == -1 ) ntot+=1.;
874 else ntot+=0.5;
875 }
876 return (Int_t)ntot;
877
878 };
879 //--------------------------------------
880 //
881 //
882 //--------------------------------------
883 /**
884 * Retrieves (if present) the image of the it-th "physical" track, sorted by the method GetNTracks().
885 * @param it Track number, ranging from 0 to GetNTracks().
886 */
887 TrkTrack *TrkLevel2::GetTrackImage(int it){
888
889 if(it >= this->GetNTracks()){
890 cout << "** TrkLevel2 ** Track "<< it << "does not exits! " << endl;
891 cout << " Physical tracks GetNTracks() = "<< this->ntrk() << endl;
892 return 0;
893 }
894
895 TRefArray* sorted = GetTracks(); //TEMPORANEO
896 TrkTrack *track = (TrkTrack*)sorted->At(it);
897
898 if(!track->HasImage()){
899 cout << "** TrkLevel2 ** Track "<< it << "does not have image! " << endl;
900 return 0;
901 }
902 TrkTrack *image = (TrkTrack*)(*Track)[track->image];
903
904 sorted->Delete();
905
906 return image;
907
908 }
909 //--------------------------------------
910 //
911 //
912 //--------------------------------------
913 /**
914 * Loads the magnetic field.
915 * @param s Path of the magnetic-field files.
916 */
917 void TrkLevel2::LoadField(TString s){
918 readb_(s.Data());
919 };
920 //--------------------------------------
921 //
922 //
923 //--------------------------------------
924 /**
925 * Get tracker-plane (mechanical) z-coordinate
926 * @param plane_id plane index (1=TOP,2,3,4,5,6=BOTTOM)
927 */
928 Float_t TrkLevel2::GetZTrk(Int_t plane_id){
929 switch(plane_id){
930 case 1: return ZTRK1;
931 case 2: return ZTRK2;
932 case 3: return ZTRK3;
933 case 4: return ZTRK4;
934 case 5: return ZTRK5;
935 case 6: return ZTRK6;
936 default: return 0.;
937 };
938 };
939 //--------------------------------------
940 //
941 //
942 //--------------------------------------
943 /**
944 * Trajectory default constructor.
945 * (By default is created with z-coordinates inside the tracking volume)
946 */
947 Trajectory::Trajectory(){
948 npoint = 10;
949 x = new float[npoint];
950 y = new float[npoint];
951 z = new float[npoint];
952 thx = new float[npoint];
953 thy = new float[npoint];
954 tl = new float[npoint];
955 float dz = ((ZTRK1)-(ZTRK6))/(npoint-1);
956 for(int i=0; i<npoint; i++){
957 x[i] = 0;
958 y[i] = 0;
959 z[i] = (ZTRK1) - i*dz;
960 thx[i] = 0;
961 thy[i] = 0;
962 tl[i] = 0;
963 }
964 }
965 //--------------------------------------
966 //
967 //
968 //--------------------------------------
969 /**
970 * Trajectory constructor.
971 * (By default is created with z-coordinates inside the tracking volume)
972 * \param n Number of points
973 */
974 Trajectory::Trajectory(int n){
975 if(n<=0){
976 cout << "NB! Trajectory must have at least 1 point >>> created with 10 points" << endl;
977 n=10;
978 }
979 npoint = n;
980 x = new float[npoint];
981 y = new float[npoint];
982 z = new float[npoint];
983 thx = new float[npoint];
984 thy = new float[npoint];
985 tl = new float[npoint];
986 float dz = ((ZTRK1)-(ZTRK6))/(npoint-1);
987 for(int i=0; i<npoint; i++){
988 x[i] = 0;
989 y[i] = 0;
990 z[i] = (ZTRK1) - i*dz;
991 thx[i] = 0;
992 thy[i] = 0;
993 tl[i] = 0;
994 }
995 }
996 //--------------------------------------
997 //
998 //
999 //--------------------------------------
1000 /**
1001 * Trajectory constructor.
1002 * \param n Number of points
1003 * \param pz Pointer to float array, defining z coordinates
1004 */
1005 Trajectory::Trajectory(int n, float* zin){
1006 npoint = 10;
1007 if(n>0)npoint = n;
1008 x = new float[npoint];
1009 y = new float[npoint];
1010 z = new float[npoint];
1011 thx = new float[npoint];
1012 thy = new float[npoint];
1013 tl = new float[npoint];
1014 int i=0;
1015 do{
1016 x[i] = 0;
1017 y[i] = 0;
1018 z[i] = zin[i];
1019 thx[i] = 0;
1020 thy[i] = 0;
1021 tl[i] = 0;
1022 i++;
1023 }while(zin[i-1] > zin[i] && i < npoint);
1024 npoint=i;
1025 if(npoint != n)cout << "NB! Trajectory created with "<<npoint<<" points"<<endl;
1026 }
1027 //--------------------------------------
1028 //
1029 //
1030 //--------------------------------------
1031 /**
1032 * Dump the trajectory coordinates.
1033 */
1034 void Trajectory::Dump(){
1035 cout <<endl<< "Trajectory ========== "<<endl;
1036 for (int i=0; i<npoint; i++){
1037 cout << i <<" >> " << x[i] <<" "<< y[i] <<" "<< z[i] ;
1038 cout <<" -- " << thx[i] <<" "<< thy[i] ;
1039 cout <<" -- " << tl[i] << endl;
1040 };
1041 }
1042 //--------------------------------------
1043 //
1044 //
1045 //--------------------------------------
1046 /**
1047 * Get trajectory length between two points
1048 * @param ifirst first point (default 0)
1049 * @param ilast last point (default npoint)
1050 */
1051 float Trajectory::GetLength(int ifirst, int ilast){
1052 if( ifirst<0 ) ifirst = 0;
1053 if( ilast>=npoint) ilast = npoint-1;
1054 float l=0;
1055 for(int i=ifirst;i<=ilast;i++){
1056 l=l+tl[i];
1057 };
1058 if(z[ilast] > ZINI)l=l-tl[ilast];
1059 if(z[ifirst] < ZINI) l=l-tl[ifirst];
1060
1061 return l;
1062
1063 }
1064
1065
1066 ClassImp(TrkLevel2);
1067 ClassImp(TrkSinglet);
1068 ClassImp(TrkTrack);
1069 ClassImp(Trajectory);

  ViewVC Help
Powered by ViewVC 1.1.23