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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.23 - (hide annotations) (download)
Tue Jan 16 10:03:48 2007 UTC (17 years, 10 months ago) by pam-fi
Branch: MAIN
Changes since 1.22: +16 -4 lines
Set()

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

  ViewVC Help
Powered by ViewVC 1.1.23