/[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.30 - (hide annotations) (download)
Fri Mar 16 11:38:33 2007 UTC (17 years, 8 months ago) by pam-fi
Branch: MAIN
Changes since 1.29: +13 -9 lines
new implementation of xgood ygood

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

  ViewVC Help
Powered by ViewVC 1.1.23