/[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.25 - (hide annotations) (download)
Mon Feb 5 16:01:51 2007 UTC (17 years, 10 months ago) by pam-fi
Branch: MAIN
Changes since 1.24: +29 -0 lines
added methods to get magnetic field and p.f.a. parameters

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

  ViewVC Help
Powered by ViewVC 1.1.23