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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8 by pam-fi, Fri Aug 4 08:18:06 2006 UTC revision 1.13 by pam-fi, Thu Oct 26 16:22:37 2006 UTC
# Line 11  using namespace std; Line 11  using namespace std;
11  extern "C" {      extern "C" {    
12      void dotrack_(int*, double*, double*, double*, double*, int*);      void dotrack_(int*, double*, double*, double*, double*, int*);
13      void dotrack2_(int*, double*, double*, double*, double*,double*, double*, double*,int*);      void dotrack2_(int*, double*, double*, double*, double*,double*, double*, double*,int*);
14      int  readb_(const char*);      int  readb_(const char*);
15        void mini2_(int*,int*,int*);
16  }  }
17  //--------------------------------------  //--------------------------------------
18  //  //
# Line 21  TrkTrack::TrkTrack(){ Line 22  TrkTrack::TrkTrack(){
22      seqno = -1;      seqno = -1;
23      image = -1;      image = -1;
24      chi2  = 0;      chi2  = 0;
25      for(int it1=0;it1<5;it1++){          nstep = 0;
26          al[it1] = 0;          for(int it1=0;it1<5;it1++){
27          for(int it2=0;it2<5;it2++)                  al[it1] = 0;
28              coval[it1][it2] = 0;                  for(int it2=0;it2<5;it2++)coval[it1][it2] = 0;
29      };      };
30      for(int ip=0;ip<6;ip++){      for(int ip=0;ip<6;ip++){
31          xgood[ip]  = 0;                  xgood[ip]  = 0;
32          ygood[ip]  = 0;                  ygood[ip]  = 0;
33          xm[ip]     = 0;                  xm[ip]     = 0;
34          ym[ip]     = 0;                  ym[ip]     = 0;
35          zm[ip]     = 0;                  zm[ip]     = 0;
36          resx[ip]   = 0;                  resx[ip]   = 0;
37          resy[ip]   = 0;                  resy[ip]   = 0;
38          xv[ip]     = 0;                  xv[ip]     = 0;
39          yv[ip]     = 0;                  yv[ip]     = 0;
40          zv[ip]     = 0;                  zv[ip]     = 0;
41          axv[ip]    = 0;                  axv[ip]    = 0;
42          ayv[ip]    = 0;                  ayv[ip]    = 0;
43          dedx_x[ip] = 0;                  dedx_x[ip] = 0;
44          dedx_y[ip] = 0;                  dedx_y[ip] = 0;
45      };      //              clx[ip]    = 0;
46    //              cly[ip]    = 0;
47            };
48            clx = new TRefArray(6,0);
49            cly = new TRefArray(6,0);
50  };  };
51  //--------------------------------------  //--------------------------------------
52  //  //
# Line 51  TrkTrack::TrkTrack(const TrkTrack& t){ Line 56  TrkTrack::TrkTrack(const TrkTrack& t){
56      seqno = t.seqno;      seqno = t.seqno;
57      image = t.image;      image = t.image;
58      chi2  = t.chi2;      chi2  = t.chi2;
59      for(int it1=0;it1<5;it1++){          nstep = t.nstep;
60          al[it1] = t.al[it1];          for(int it1=0;it1<5;it1++){
61          for(int it2=0;it2<5;it2++)                  al[it1] = t.al[it1];
62              coval[it1][it2] = t.coval[it1][it2];                  for(int it2=0;it2<5;it2++)coval[it1][it2] = t.coval[it1][it2];
63      };      };
64      for(int ip=0;ip<6;ip++){      for(int ip=0;ip<6;ip++){
65          xgood[ip]  = t.xgood[ip];                  xgood[ip]  = t.xgood[ip];
66          ygood[ip]  = t.ygood[ip];                  ygood[ip]  = t.ygood[ip];
67          xm[ip]     = t.xm[ip];                  xm[ip]     = t.xm[ip];
68          ym[ip]     = t.ym[ip];                  ym[ip]     = t.ym[ip];
69          zm[ip]     = t.zm[ip];                  zm[ip]     = t.zm[ip];
70          resx[ip]   = t.resx[ip];                  resx[ip]   = t.resx[ip];
71          resy[ip]   = t.resy[ip];                  resy[ip]   = t.resy[ip];
72          xv[ip]     = t.xv[ip];                  xv[ip]     = t.xv[ip];
73          yv[ip]     = t.yv[ip];                  yv[ip]     = t.yv[ip];
74          zv[ip]     = t.zv[ip];                  zv[ip]     = t.zv[ip];
75          axv[ip]    = t.axv[ip];                  axv[ip]    = t.axv[ip];
76          ayv[ip]    = t.ayv[ip];                  ayv[ip]    = t.ayv[ip];
77          dedx_x[ip] = t.dedx_x[ip];                  dedx_x[ip] = t.dedx_x[ip];
78          dedx_y[ip] = t.dedx_y[ip];                  dedx_y[ip] = t.dedx_y[ip];
79      };              //      clx[ip]    = 0;//<<<<pointer
80            //      cly[ip]    = 0;//<<<<pointer
81            };
82            clx = new TRefArray(*(t.clx));
83            cly = new TRefArray(*(t.cly));
84            
85  };  };
86  //--------------------------------------  //--------------------------------------
87  //  //
# Line 187  Float_t TrkTrack::GetDEDX(){ Line 197  Float_t TrkTrack::GetDEDX(){
197  //--------------------------------------  //--------------------------------------
198  void TrkTrack::Dump(){  void TrkTrack::Dump(){
199      cout << endl << "========== Track " ;      cout << endl << "========== Track " ;
200        cout << endl << "seq.  n. : "<< seqno;
201        cout << endl << "image n. : "<< image;
202      cout << endl << "al       : "; for(int i=0; i<5; i++)cout << al[i] << " ";      cout << endl << "al       : "; for(int i=0; i<5; i++)cout << al[i] << " ";
203      cout << endl << "chi^2    : "<< chi2;      cout << endl << "chi^2    : "<< chi2;
204        cout << endl << "n.step   : "<< nstep;
205      cout << endl << "xgood    : "; for(int i=0; i<6; i++)cout << xgood[i] ;      cout << endl << "xgood    : "; for(int i=0; i<6; i++)cout << xgood[i] ;
206      cout << endl << "ygood    : "; for(int i=0; i<6; i++)cout << ygood[i] ;      cout << endl << "ygood    : "; for(int i=0; i<6; i++)cout << ygood[i] ;
207      cout << endl << "xm       : "; for(int i=0; i<6; i++)cout << xm[i] << " ";      cout << endl << "xm       : "; for(int i=0; i<6; i++)cout << xm[i] << " ";
208      cout << endl << "ym       : "; for(int i=0; i<6; i++)cout << ym[i] << " ";      cout << endl << "ym       : "; for(int i=0; i<6; i++)cout << ym[i] << " ";
209      cout << endl << "zm       : "; for(int i=0; i<6; i++)cout << zm[i] << " ";      cout << endl << "zm       : "; for(int i=0; i<6; i++)cout << zm[i] << " ";
210        cout << endl << "xv       : "; for(int i=0; i<6; i++)cout << xv[i] << " ";
211        cout << endl << "yv       : "; for(int i=0; i<6; i++)cout << yv[i] << " ";
212        cout << endl << "zv       : "; for(int i=0; i<6; i++)cout << zv[i] << " ";
213        cout << endl << "resx     : "; for(int i=0; i<6; i++)cout << resx[i] << " ";
214        cout << endl << "resy     : "; for(int i=0; i<6; i++)cout << resy[i] << " ";
215        cout << endl << "coval    : "; for(int i=0; i<5; i++)cout << coval[0][i]<<" ";
216        cout << endl << "           "; for(int i=0; i<5; i++)cout << coval[1][i]<<" ";
217        cout << endl << "           "; for(int i=0; i<5; i++)cout << coval[2][i]<<" ";
218        cout << endl << "           "; for(int i=0; i<5; i++)cout << coval[3][i]<<" ";
219        cout << endl << "           "; for(int i=0; i<5; i++)cout << coval[4][i]<<" ";
220      cout << endl << "dedx_x   : "; for(int i=0; i<6; i++)cout << dedx_x[i] << " ";      cout << endl << "dedx_x   : "; for(int i=0; i<6; i++)cout << dedx_x[i] << " ";
221      cout << endl << "dedx_y   : "; for(int i=0; i<6; i++)cout << dedx_y[i] << " ";      cout << endl << "dedx_y   : "; for(int i=0; i<6; i++)cout << dedx_y[i] << " ";
222  }  }
223    /**
224     * Set the TrkTrack position measurements
225     */
226    void TrkTrack::SetMeasure(double *xmeas, double *ymeas, double *zmeas){
227        for(int i=0; i<6; i++) xm[i]=*xmeas++;
228        for(int i=0; i<6; i++) ym[i]=*ymeas++;
229        for(int i=0; i<6; i++) zm[i]=*zmeas++;
230    }
231    /**
232     * Set the TrkTrack position resolution
233     */
234    void TrkTrack::SetResolution(double *rx, double *ry){
235        for(int i=0; i<6; i++) resx[i]=*rx++;
236        for(int i=0; i<6; i++) resy[i]=*ry++;
237    }
238    /**
239     * Set the TrkTrack good measurement
240     */
241    void TrkTrack::SetGood(int *xg, int *yg){
242        for(int i=0; i<6; i++) xgood[i]=*xg++;
243        for(int i=0; i<6; i++) ygood[i]=*yg++;
244    }
245    
246    /**
247     * Load the magnetic field
248     */
249    void TrkTrack::LoadField(TString s){
250        readb_(s.Data());
251    };
252    /**
253     * Tracking method. It calls F77 mini routine.
254     */
255    void TrkTrack::Fit(double pfixed, int& fail, int iprint){
256        extern cMini2track track_;
257        fail = 0;
258    //    extern cMini2fitinfo fit_info_;
259    //    extern void mini_2_(int*,int*);
260    //    track_.xm[0]=1.0;
261        for(int i=0; i<6; i++) track_.xm[i]=xm[i];
262        for(int i=0; i<6; i++) track_.ym[i]=ym[i];
263        for(int i=0; i<6; i++) track_.zm[i]=zm[i];
264        for(int i=0; i<6; i++) track_.resx[i]=resx[i];
265        for(int i=0; i<6; i++) track_.resy[i]=resy[i];
266        for(int i=0; i<6; i++) track_.xgood[i]=xgood[i];
267        for(int i=0; i<6; i++) track_.ygood[i]=ygood[i];
268    // initial guess of "al" with linear fit
269        if(al[0]==-9999.&&al[1]==-9999.&&al[2]==-9999.&&al[3]==-9999.&&al[4]==-9999.){
270            double szz=0., szx=0., szy=0., ssx=0., ssy=0., sz=0., s1=0.;
271            double det, ax, ay, bx, by;
272            for(int i=0; i<NPLANE; i++) {
273                szz=szz+zm[i]*zm[i];
274                szx=szx+zm[i]*xm[i];
275                szy=szy+zm[i]*ym[i];
276                ssx=ssx+xm[i];
277                ssy=ssy+ym[i];
278                sz=sz+zm[i];
279                s1=s1+1.;
280            }
281            det=szz*s1-sz*sz;
282            ax=(szx*s1-sz*ssx)/det;
283            bx=(szz*ssx-szx*sz)/det;
284            ay=(szy*s1-sz*ssy)/det;
285            by=(szz*ssy-szy*sz)/det;
286            al[0]=ax*23.5+bx; // ZINI = 23.5 !!! it should be the same parameter in all codes
287            al[1]=ay*23.5+by; //  "  
288            al[2]= sqrt(pow(ax,2)+pow(ay,2))/ sqrt(pow(ax,2)+pow(ay,2)+1.);
289            al[3]=0.;
290            if( (ax!=0.)||(ay!=0.) ) {
291                al[3]= asin(ay/ sqrt(pow(ax,2)+pow(ay,2)));
292                if(ax<0.) al[3]=acos(-1.)-al[3];
293            }
294            al[4]=0.;
295        }
296    // end guess
297        for(int i=0; i<5; i++) track_.al[i]=al[i];
298        if(pfixed!=0.) {
299            al[4]=1./pfixed;      // to fix the momentum
300            track_.pfixed=pfixed; //         "
301        }
302        int istep=0;
303        int ifail=0;
304        mini2_(&istep,&ifail, &iprint);
305        if(ifail!=0) {
306            if(iprint==1)cout << "ERROR: ifail= " << ifail << endl;
307            fail = 1;
308    //      return;
309        }
310    
311    //    cout << endl << "eta ===> " << track_.al[4] << endl;
312    
313        for(int i=0; i<5; i++) al[i]=track_.al[i];
314        chi2=track_.chi2;
315        nstep=track_.nstep;
316        for(int i=0; i<6; i++) xv[i]=track_.xv[i];
317        for(int i=0; i<6; i++) yv[i]=track_.yv[i];
318        for(int i=0; i<6; i++) zv[i]=track_.zv[i];
319        for(int i=0; i<6; i++) axv[i]=track_.axv[i];
320        for(int i=0; i<6; i++) ayv[i]=track_.ayv[i];
321        for(int i=0; i<5; i++) {
322            for(int j=0; j<5; j++) coval[i][j]=track_.cov[i][j];
323        }
324    };
325    /*
326     * Reset the parameters fit
327     */
328    void TrkTrack::FitReset(){
329        for(int i=0; i<5; i++) al[i]=-9999.;
330        chi2=0.;
331        nstep=0;
332        for(int i=0; i<6; i++) xv[i]=0.;
333        for(int i=0; i<6; i++) yv[i]=0.;
334        for(int i=0; i<6; i++) zv[i]=0.;
335        for(int i=0; i<6; i++) axv[i]=0.;
336        for(int i=0; i<6; i++) ayv[i]=0.;
337        for(int i=0; i<5; i++) {
338            for(int j=0; j<5; j++) coval[i][j]=0.;
339        }
340    }
341    
342    //--------------------------------------
343    //
344    //
345    //--------------------------------------
346    void TrkTrack::Clear(){
347            seqno = -1;
348            image = -1;
349            chi2  = 0;
350            nstep = 0;
351            for(int it1=0;it1<5;it1++){
352                    al[it1] = 0;
353                    for(int it2=0;it2<5;it2++)coval[it1][it2] = 0;
354            };
355            for(int ip=0;ip<6;ip++){
356                    xgood[ip]  = 0;
357                    ygood[ip]  = 0;
358                    xm[ip]     = 0;
359                    ym[ip]     = 0;
360                    zm[ip]     = 0;
361                    resx[ip]   = 0;
362                    resy[ip]   = 0;
363                    xv[ip]     = 0;
364                    yv[ip]     = 0;
365                    zv[ip]     = 0;
366                    axv[ip]    = 0;
367                    ayv[ip]    = 0;
368                    dedx_x[ip] = 0;
369                    dedx_y[ip] = 0;
370    //              clx[ip]    = 0;
371    //              cly[ip]    = 0;
372            };
373            clx->Clear();
374            cly->Clear();
375    };
376    //--------------------------------------
377    //
378    //
379    //--------------------------------------
380    void TrkTrack::Delete(){
381            Clear();
382            clx->Delete();
383            cly->Delete();
384    };
385            //--------------------------------------
386    //
387    //
388    //--------------------------------------
389    
390  //--------------------------------------  //--------------------------------------
391  //  //
392  //  //
# Line 206  TrkSinglet::TrkSinglet(){ Line 396  TrkSinglet::TrkSinglet(){
396      coord[0] = 0;      coord[0] = 0;
397      coord[1] = 0;      coord[1] = 0;
398      sgnl     = 0;      sgnl     = 0;
399            cls      = 0;
400  };  };
401  //--------------------------------------  //--------------------------------------
402  //  //
# Line 216  TrkSinglet::TrkSinglet(const TrkSinglet& Line 407  TrkSinglet::TrkSinglet(const TrkSinglet&
407      coord[0] = s.coord[0];      coord[0] = s.coord[0];
408      coord[1] = s.coord[1];      coord[1] = s.coord[1];
409      sgnl     = s.sgnl;      sgnl     = s.sgnl;
410    //      cls      = 0;//<<<<pointer
411            cls      = TRef(s.cls);
412  };  };
413  //--------------------------------------  //--------------------------------------
414  //  //
# Line 233  void TrkSinglet::Dump(){ Line 426  void TrkSinglet::Dump(){
426  //  //
427  //--------------------------------------  //--------------------------------------
428  TrkLevel2::TrkLevel2(){  TrkLevel2::TrkLevel2(){
429      good2    = -1;  //    good2    = -1;
430      for(Int_t i=0; i<12 ; i++){      for(Int_t i=0; i<12 ; i++){
431          crc[i] = -1;  //      crc[i] = -1;
432      };                  good[i] = -1;
433            };
434      Track    = new TClonesArray("TrkTrack");      Track    = new TClonesArray("TrkTrack");
435      SingletX = new TClonesArray("TrkSinglet");      SingletX = new TClonesArray("TrkSinglet");
436      SingletY = new TClonesArray("TrkSinglet");      SingletY = new TClonesArray("TrkSinglet");
# Line 249  TrkLevel2::TrkLevel2(){ Line 443  TrkLevel2::TrkLevel2(){
443  //  //
444  //--------------------------------------  //--------------------------------------
445  void TrkLevel2::Dump(){  void TrkLevel2::Dump(){
446            
447      TClonesArray &t  = *Track;      TClonesArray &t  = *Track;
448      TClonesArray &sx = *SingletX;      TClonesArray &sx = *SingletX;
449      TClonesArray &sy = *SingletY;      TClonesArray &sy = *SingletY;
450            //
451      cout << endl << endl << "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-";      cout << endl << endl << "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-";
452      cout << endl << "good2    : " << good2;      cout << endl << "good     : "; for(int i=0; i<12; i++) cout << good[i]<<" ";
     cout << endl << "crc      : "; for(int i=0; i<12; i++) cout << crc[i];  
453      cout << endl << "ntrk()   : " << this->ntrk() ;      cout << endl << "ntrk()   : " << this->ntrk() ;
454      cout << endl << "nclsx()  : " << this->nclsx();      cout << endl << "nclsx()  : " << this->nclsx();
455      cout << endl << "nclsy()  : " << this->nclsy();      cout << endl << "nclsy()  : " << this->nclsy();
# Line 271  void TrkLevel2::Dump(){ Line 465  void TrkLevel2::Dump(){
465   * Fills a TrkLevel2 object with values from a struct cTrkLevel2 (to get data from F77 common).   * Fills a TrkLevel2 object with values from a struct cTrkLevel2 (to get data from F77 common).
466   */   */
467  void TrkLevel2::SetFromLevel2Struct(cTrkLevel2 *l2){  void TrkLevel2::SetFromLevel2Struct(cTrkLevel2 *l2){
468      //  
469  //    Track    = new TClonesArray("TrkTrack");          //  temporary objects:
 //    SingletX = new TClonesArray("TrkSinglet");  
 //    SingletY = new TClonesArray("TrkSinglet");  
 //  temporary objects:  
470      TrkSinglet* t_singlet = new TrkSinglet();      TrkSinglet* t_singlet = new TrkSinglet();
471      TrkTrack*   t_track   = new TrkTrack();      TrkTrack*   t_track   = new TrkTrack();
472  //  general variables  
473      good2 = l2->good2;          //  **** general variables ****
474    //    good2 = l2->good2;
475      for(Int_t i=0; i<12 ; i++){      for(Int_t i=0; i<12 ; i++){
476          crc[i] = l2->crc[i];  //              crc[i] = l2->crc[i];
477      };                  good[i] = l2->good[i];
478  //  *** TRACKS ***          };
479            //  *** TRACKS ***
480      TClonesArray &t = *Track;      TClonesArray &t = *Track;
481      for(int i=0; i<l2->ntrk; i++){      for(int i=0; i<l2->ntrk; i++){
482          t_track->seqno = i;                  t_track->seqno = i;// NBNBNBNB deve sempre essere = i
483          t_track->image = l2->image[i]-1;                  t_track->image = l2->image[i]-1;
484  //      cout << "track "<<i<<t_track->seqno << t_track->image<<endl;          //      cout << "track "<<i<<t_track->seqno << t_track->image<<endl;
485          t_track->chi2  = l2->chi2_nt[i];                  t_track->chi2  = l2->chi2_nt[i];
486          for(int it1=0;it1<5;it1++){                  t_track->nstep = l2->nstep_nt[i];
487              t_track->al[it1] = l2->al_nt[i][it1];                  for(int it1=0;it1<5;it1++){
488              for(int it2=0;it2<5;it2++)                          t_track->al[it1] = l2->al_nt[i][it1];
489                  t_track->coval[it1][it2] = l2->coval[i][it2][it1];                          for(int it2=0;it2<5;it2++)
490          };                          t_track->coval[it1][it2] = l2->coval[i][it2][it1];
491          for(int ip=0;ip<6;ip++){                  };
492              t_track->xgood[ip]  = l2->xgood_nt[i][ip];                  for(int ip=0;ip<6;ip++){
493              t_track->ygood[ip]  = l2->ygood_nt[i][ip];                          t_track->xgood[ip]  = l2->xgood_nt[i][ip];
494              t_track->xm[ip]     = l2->xm_nt[i][ip];                          t_track->ygood[ip]  = l2->ygood_nt[i][ip];
495              t_track->ym[ip]     = l2->ym_nt[i][ip];                          t_track->xm[ip]     = l2->xm_nt[i][ip];
496              t_track->zm[ip]     = l2->zm_nt[i][ip];                          t_track->ym[ip]     = l2->ym_nt[i][ip];
497              t_track->resx[ip]   = l2->resx_nt[i][ip];                          t_track->zm[ip]     = l2->zm_nt[i][ip];
498              t_track->resy[ip]   = l2->resy_nt[i][ip];                          t_track->resx[ip]   = l2->resx_nt[i][ip];
499              t_track->xv[ip]     = l2->xv_nt[i][ip];                          t_track->resy[ip]   = l2->resy_nt[i][ip];
500              t_track->yv[ip]     = l2->yv_nt[i][ip];                          t_track->xv[ip]     = l2->xv_nt[i][ip];
501              t_track->zv[ip]     = l2->zv_nt[i][ip];                          t_track->yv[ip]     = l2->yv_nt[i][ip];
502              t_track->axv[ip]    = l2->axv_nt[i][ip];                          t_track->zv[ip]     = l2->zv_nt[i][ip];
503              t_track->ayv[ip]    = l2->ayv_nt[i][ip];                          t_track->axv[ip]    = l2->axv_nt[i][ip];
504              t_track->dedx_x[ip] = l2->dedx_x[i][ip];                          t_track->ayv[ip]    = l2->ayv_nt[i][ip];
505              t_track->dedx_y[ip] = l2->dedx_y[i][ip];                          t_track->dedx_x[ip] = l2->dedx_x[i][ip];
506          };                          t_track->dedx_y[ip] = l2->dedx_y[i][ip];
507          new(t[i]) TrkTrack(*t_track);  //                      t_track->clx[ip] = 0;
508          t_track->Clear();  //                      t_track->cly[ip] = 0;
509                    };
510                    new(t[i]) TrkTrack(*t_track);
511                    t_track->Clear();
512      };      };
513  //  *** SINGLETS ***  //  *** SINGLETS ***
514      TClonesArray &sx = *SingletX;      TClonesArray &sx = *SingletX;
515      for(int i=0; i<l2->nclsx; i++){      for(int i=0; i<l2->nclsx; i++){
516          t_singlet->plane    = l2->planex[i];                  t_singlet->plane    = l2->planex[i];
517          t_singlet->coord[0] = l2->xs[i][0];                  t_singlet->coord[0] = l2->xs[i][0];
518          t_singlet->coord[1] = l2->xs[i][1];                  t_singlet->coord[1] = l2->xs[i][1];
519          t_singlet->sgnl     = l2->signlxs[i];                  t_singlet->sgnl     = l2->signlxs[i];
520          new(sx[i]) TrkSinglet(*t_singlet);  //              t_singlet->cls      = 0;
521          t_singlet->Clear();                  new(sx[i]) TrkSinglet(*t_singlet);
522                    t_singlet->Clear();
523      }      }
524      TClonesArray &sy = *SingletY;      TClonesArray &sy = *SingletY;
525      for(int i=0; i<l2->nclsy; i++){      for(int i=0; i<l2->nclsy; i++){
526          t_singlet->plane    = l2->planey[i];                  t_singlet->plane    = l2->planey[i];
527          t_singlet->coord[0] = l2->ys[i][0];                  t_singlet->coord[0] = l2->ys[i][0];
528          t_singlet->coord[1] = l2->ys[i][1];                  t_singlet->coord[1] = l2->ys[i][1];
529          t_singlet->sgnl     = l2->signlys[i];                  t_singlet->sgnl     = l2->signlys[i];
530          new(sy[i]) TrkSinglet(*t_singlet);  //              t_singlet->cls      = 0;
531          t_singlet->Clear();                  new(sy[i]) TrkSinglet(*t_singlet);
532                    t_singlet->Clear();
533            };
534            
535            delete t_track;
536            delete t_singlet;
537    }
538    //--------------------------------------
539    //
540    //
541    //--------------------------------------
542    /**
543     * Fills a TrkLevel2 object with values from a struct cTrkLevel2 (to get data from F77 common).
544     * Ref to Level1 data (clusters) is also set.
545     */
546    void TrkLevel2::SetFromLevel2Struct(cTrkLevel2 *l2, TrkLevel1 *l1){
547    
548    //  temporary objects:
549            TrkSinglet* t_singlet = new TrkSinglet();
550            TrkTrack*   t_track   = new TrkTrack();
551    // general variables
552    //      good2 = l2->good2;
553            for(Int_t i=0; i<12 ; i++){
554    //              crc[i] = l2->crc[i];
555                    good[i] = l2->good[i];
556            };
557    // *** TRACKS ***
558            TClonesArray &t = *Track;
559            for(int i=0; i<l2->ntrk; i++){
560                    t_track->seqno = i;// NBNBNBNB deve sempre essere = i
561                    t_track->image = l2->image[i]-1;
562    //              cout << "track "<<i<<t_track->seqno << t_track->image<<endl;
563                    t_track->chi2  = l2->chi2_nt[i];
564                    t_track->nstep = l2->nstep_nt[i];
565                    for(int it1=0;it1<5;it1++){
566                            t_track->al[it1] = l2->al_nt[i][it1];
567                            for(int it2=0;it2<5;it2++)
568                                    t_track->coval[it1][it2] = l2->coval[i][it2][it1];
569                    };
570                    for(int ip=0;ip<6;ip++){
571                            t_track->xgood[ip]  = l2->xgood_nt[i][ip];
572                            t_track->ygood[ip]  = l2->ygood_nt[i][ip];
573                            t_track->xm[ip]     = l2->xm_nt[i][ip];
574                            t_track->ym[ip]     = l2->ym_nt[i][ip];
575                            t_track->zm[ip]     = l2->zm_nt[i][ip];
576                            t_track->resx[ip]   = l2->resx_nt[i][ip];
577                            t_track->resy[ip]   = l2->resy_nt[i][ip];
578                            t_track->xv[ip]     = l2->xv_nt[i][ip];
579                            t_track->yv[ip]     = l2->yv_nt[i][ip];
580                            t_track->zv[ip]     = l2->zv_nt[i][ip];
581                            t_track->axv[ip]    = l2->axv_nt[i][ip];
582                            t_track->ayv[ip]    = l2->ayv_nt[i][ip];
583                            t_track->dedx_x[ip] = l2->dedx_x[i][ip];
584                            t_track->dedx_y[ip] = l2->dedx_y[i][ip];
585    //                      cout << "traccia "<<i<<"  --  "<< ip << " "<< l2->cltrx[i][ip] <<" "<< l2->cltry[i][ip] <<" "<< t_track->xgood[ip] << t_track->ygood[ip]<<endl;
586                            //-----------------------------------------------------
587    //                      t_track->clx[ip] = l1->GetCluster(l2->cltrx[i][ip]-1);
588    //                      t_track->cly[ip] = l1->GetCluster(l2->cltry[i][ip]-1);
589                            if(t_track->xgood[ip])t_track->clx->AddAt(l1->GetCluster(l2->cltrx[i][ip]-1),ip);
590                            if(t_track->ygood[ip])t_track->cly->AddAt(l1->GetCluster(l2->cltry[i][ip]-1),ip);
591    //                      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;
592    //                      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;
593                            //-----------------------------------------------------
594                    };
595                    new(t[i]) TrkTrack(*t_track);
596                    t_track->Clear();
597            };
598    // *** SINGLETS ***
599            TClonesArray &sx = *SingletX;
600            for(int i=0; i<l2->nclsx; i++){
601                    t_singlet->plane    = l2->planex[i];
602                    t_singlet->coord[0] = l2->xs[i][0];
603                    t_singlet->coord[1] = l2->xs[i][1];
604                    t_singlet->sgnl     = l2->signlxs[i];
605                    //-----------------------------------------------------
606    //              cout << "singolo x "<<i<<"  --  "<<  l2->clsx[i] <<endl;
607                    t_singlet->cls      = l1->GetCluster(l2->clsx[i]-1);
608    //              cout<<" i "<<i<<" l2->clsx[i] "<<l2->clsx[i]<< " l1->GetCluster(l2->clsx[i]-1) "<<l1->GetCluster(l2->clsx[i]-1)<<endl;          
609                    //-----------------------------------------------------
610                    new(sx[i]) TrkSinglet(*t_singlet);
611                    t_singlet->Clear();
612            }
613            TClonesArray &sy = *SingletY;
614            for(int i=0; i<l2->nclsy; i++){
615                    t_singlet->plane    = l2->planey[i];
616                    t_singlet->coord[0] = l2->ys[i][0];
617                    t_singlet->coord[1] = l2->ys[i][1];
618                    t_singlet->sgnl     = l2->signlys[i];
619                    //-----------------------------------------------------
620    //              cout << "singolo y "<<i<<"  --  "<<  l2->clsy[i] <<endl;
621                    t_singlet->cls      = l1->GetCluster(l2->clsy[i]-1);
622    //              cout<<" i "<<i<<" l2->clsy[i] "<<l2->clsy[i]<< " l1->GetCluster(l2->clsy[i]-1) "<<l1->GetCluster(l2->clsy[i]-1)<<endl;          
623                    //-----------------------------------------------------
624                    new(sy[i]) TrkSinglet(*t_singlet);
625                    t_singlet->Clear();
626          };          };
627                    
628          delete t_track;          delete t_track;
# Line 344  void TrkLevel2::SetFromLevel2Struct(cTrk Line 635  void TrkLevel2::SetFromLevel2Struct(cTrk
635  void TrkLevel2::GetLevel2Struct(cTrkLevel2 *l2) const {  void TrkLevel2::GetLevel2Struct(cTrkLevel2 *l2) const {
636        
637  //  general variables  //  general variables
638      l2->good2 = good2 ;  //    l2->good2 = good2 ;
639      for(Int_t i=0; i<12 ; i++){      for(Int_t i=0; i<12 ; i++){
640          l2->crc[i] = crc[i];  //      l2->crc[i] = crc[i];
641                    l2->good[i] = good[i];
642      };      };
643  //  *** TRACKS ***  //  *** TRACKS ***
644    
# Line 354  void TrkLevel2::GetLevel2Struct(cTrkLeve Line 646  void TrkLevel2::GetLevel2Struct(cTrkLeve
646      for(Int_t i=0;i<l2->ntrk;i++){      for(Int_t i=0;i<l2->ntrk;i++){
647        l2->image[i] = 1 + ((TrkTrack *)Track->At(i))->image;        l2->image[i] = 1 + ((TrkTrack *)Track->At(i))->image;
648        l2->chi2_nt[i] =  ((TrkTrack *)Track->At(i))->chi2;        l2->chi2_nt[i] =  ((TrkTrack *)Track->At(i))->chi2;
649        for(int it1=0;it1<5;it1++){            l2->nstep_nt[i] =  ((TrkTrack *)Track->At(i))->nstep;
650              for(int it1=0;it1<5;it1++){
651          l2->al_nt[i][it1] = ((TrkTrack *)Track->At(i))->al[it1];          l2->al_nt[i][it1] = ((TrkTrack *)Track->At(i))->al[it1];
652          for(int it2=0;it2<5;it2++)          for(int it2=0;it2<5;it2++)
653            l2->coval[i][it2][it1] = ((TrkTrack *)Track->At(i))->coval[it1][it2];            l2->coval[i][it2][it1] = ((TrkTrack *)Track->At(i))->coval[it1][it2];
# Line 398  void TrkLevel2::GetLevel2Struct(cTrkLeve Line 691  void TrkLevel2::GetLevel2Struct(cTrkLeve
691  //  //
692  //--------------------------------------  //--------------------------------------
693  void TrkLevel2::Clear(){  void TrkLevel2::Clear(){
694      good2    = -1;  //    good2    = -1;
695      for(Int_t i=0; i<12 ; i++){      for(Int_t i=0; i<12 ; i++){
696          crc[i] = -1;  //      crc[i] = -1;
697      };                  good[i] = -1;
698            };
699  /*    Track->RemoveAll();  /*    Track->RemoveAll();
700      SingletX->RemoveAll();      SingletX->RemoveAll();
701      SingletY->RemoveAll();*/      SingletY->RemoveAll();*/
# Line 414  void TrkLevel2::Clear(){ Line 708  void TrkLevel2::Clear(){
708  //  //
709  //  //
710  //--------------------------------------  //--------------------------------------
711    void TrkLevel2::Delete(){
712            
713            Clear();
714            Track->Delete();
715            SingletX->Delete();
716            SingletY->Delete();
717    }
718    //--------------------------------------
719    //
720    //
721    //--------------------------------------
722  /**  /**
723   * 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).   * 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).
724   * This method is overridden by PamLevel2::GetTracks(), where calorimeter and TOF information is used.   * This method is overridden by PamLevel2::GetTracks(), where calorimeter and TOF information is used.
725   */   */
 // TClonesArray *TrkLevel2::GetTracks(){  
 //      TClonesArray *sorted = GetTracks_NFitSorted();  
 //      return sorted;  
 // };  
   
 /*TClonesArray *TrkLevel2::GetTracks_Chi2Sorted(){  
   
     TClonesArray *sorted = new TClonesArray("TrkTrack");  
     TClonesArray &t = *Track;  
     TClonesArray &ts = *sorted;  
     int N=this->ntrk();  
     vector<int> m(N); for(int i=0; i<N; i++)m[i]=1;  
   
     int indo=0;  
     int indi=0;  
     while(N != 0){  
         float chi2ref=1000000;  
         for(int i=0; i<this->ntrk(); i++){  
             if(((TrkTrack *)t[i])->chi2 < chi2ref && m[i]==1){  
                 chi2ref = ((TrkTrack *)t[i])->chi2;  
                 indi = i;  
             }  
         }  
         if( ((TrkTrack *)t[indi])->image != -1 ){  
             m[((TrkTrack *)t[indi])->image] = 0;  
             N--;  
         }  
         new(ts[indo]) TrkTrack(*(TrkTrack*)t[indi]);  
         m[indi] = 0;  
         N--;      
         indo++;  
     }  
     return sorted;  
 }*/  
 /*TClonesArray *TrkLevel2::GetTracks_NFitSorted(){  
   
         TClonesArray *sorted = new TClonesArray("TrkTrack");      
     TClonesArray &t  = *Track;  
         TClonesArray &ts = *sorted;  
 //    TClonesArray &ts = *PhysicalTrack;  
         int N = ntrk();  
     vector<int> m(N); for(int i=0; i<N; i++)m[i]=1;  
 //      int m[50]; for(int i=0; i<N; i++)m[i]=1;  
           
     int indo=0;  
     int indi=0;  
     while(N != 0){  
                 int nfit =0;  
                 float chi2ref = numeric_limits<float>::max();  
                 // first loop to search maximum num. of fit points  
                 for(int i=0; i < ntrk(); i++){  
 //                      if(N==ntrk())cout << "** "<<i<< " " << ((TrkTrack *)t[i])->GetImageSeqNo()<< " " <<((TrkTrack *)t[i])->GetNtot() << " " <<((TrkTrack *)t[i])->chi2 << endl;  
                         if( ((TrkTrack *)t[i])->GetNtot() >= nfit && m[i]==1){  
                         nfit =    ((TrkTrack *)t[i])->GetNtot();  
                         }  
                 }  
                 //second loop to search minimum chi2 among selected  
                 for(int i=0; i<this->ntrk(); i++){  
                         if(    ((TrkTrack *)t[i])->chi2 < chi2ref  
                         && ((TrkTrack *)t[i])->GetNtot()== nfit  
                         && m[i]==1){  
                         chi2ref = ((TrkTrack *)t[i])->chi2;  
                         indi = i;  
         //              cout << "2** "<<i<< " " << nfit <<" "<<chi2ref<<endl;  
                         }  
                 }  
                 if( ((TrkTrack *)t[indi])->HasImage() ){  
                         m[((TrkTrack *)t[indi])->image] = 0;  
                         N--;  
           
         //          Int_t nfiti=((TrkTrack *)t[((TrkTrack *)t[indi])->image  ])->GetNtot();  
         //          Float_t chi2i=((TrkTrack *)t[((TrkTrack *)t[indi])->image  ])->chi2;  
                           
         //          cout << "i** "<< ((TrkTrack *)t[indi])->image << " " << nfiti <<" "<<chi2i<<endl;  
                 }  
                 new(ts[indo]) TrkTrack(*(TrkTrack*)t[indi]);  
                 m[indi] = 0;  
 //              cout << "SORTED "<< indo << " "<< indi << " "<< N << endl;  
                 N--;      
                 indo++;  
     }  
         m.clear();  
     return sorted;  
 //    return PhysicalTrack;  
 }*/  
 //TClonesArray *TrkLevel2::GetTracks_NFitSorted(){  
726  TRefArray *TrkLevel2::GetTracks_NFitSorted(){  TRefArray *TrkLevel2::GetTracks_NFitSorted(){
727    
 //      cout << "GetTracks_NFitSorted(it): new TRefArray()"<< endl;  
 //      TClonesArray *sorted = new TClonesArray("TrkTrack");  
 //      TClonesArray &ts = *sorted;  
728          TRefArray *sorted = new TRefArray();          TRefArray *sorted = new TRefArray();
729                    
730          TClonesArray &t  = *Track;          TClonesArray &t  = *Track;
# Line 522  TRefArray *TrkLevel2::GetTracks_NFitSort Line 738  TRefArray *TrkLevel2::GetTracks_NFitSort
738          while(N != 0){          while(N != 0){
739                  int nfit =0;                  int nfit =0;
740                  float chi2ref = numeric_limits<float>::max();                  float chi2ref = numeric_limits<float>::max();
741                    
742                  // first loop to search maximum num. of fit points                  // first loop to search maximum num. of fit points
743                  for(int i=0; i < ntrk(); i++){                  for(int i=0; i < ntrk(); i++){
 //                      if(N==ntrk())cout << "** "<<i<< " " << ((TrkTrack *)t[i])->GetImageSeqNo()<< " " <<((TrkTrack *)t[i])->GetNtot() << " " <<((TrkTrack *)t[i])->chi2 << endl;  
744                          if( ((TrkTrack *)t[i])->GetNtot() >= nfit && m[i]==1){                          if( ((TrkTrack *)t[i])->GetNtot() >= nfit && m[i]==1){
745                                  nfit =    ((TrkTrack *)t[i])->GetNtot();                                  nfit =    ((TrkTrack *)t[i])->GetNtot();
746                          }                          }
747                  }                  }
748                  //second loop to search minimum chi2 among selected                  //second loop to search minimum chi2 among selected
749                  for(int i=0; i<this->ntrk(); i++){                  for(int i=0; i<this->ntrk(); i++){
750                          if(    ((TrkTrack *)t[i])->chi2 < chi2ref                          Float_t chi2 = ((TrkTrack *)t[i])->chi2;
751                                                            && ((TrkTrack *)t[i])->GetNtot()== nfit                          if(chi2 < 0) chi2 = chi2*1000;
752                                                            && m[i]==1){                          if(    chi2 < chi2ref
753                                    && ((TrkTrack *)t[i])->GetNtot() == nfit
754                                    && m[i]==1){
755                                  chi2ref = ((TrkTrack *)t[i])->chi2;                                  chi2ref = ((TrkTrack *)t[i])->chi2;
756                                  indi = i;                                  indi = i;
757          //              cout << "2** "<<i<< " " << nfit <<" "<<chi2ref<<endl;                          };
758                                                            }                  };
                 }  
759                  if( ((TrkTrack *)t[indi])->HasImage() ){                  if( ((TrkTrack *)t[indi])->HasImage() ){
760                          m[((TrkTrack *)t[indi])->image] = 0;                          m[((TrkTrack *)t[indi])->image] = 0;
761                          N--;                          N--;
762                    
         //          Int_t nfiti=((TrkTrack *)t[((TrkTrack *)t[indi])->image  ])->GetNtot();  
         //          Float_t chi2i=((TrkTrack *)t[((TrkTrack *)t[indi])->image  ])->chi2;  
                           
763          //          cout << "i** "<< ((TrkTrack *)t[indi])->image << " " << nfiti <<" "<<chi2i<<endl;          //          cout << "i** "<< ((TrkTrack *)t[indi])->image << " " << nfiti <<" "<<chi2i<<endl;
764                  }                  };
 //              new(ts[indo]) TrkTrack(*(TrkTrack*)t[indi]);  
 //              cout << "GetTracks_NFitSorted(it): Add("<<indo<<")"<< endl;  
765                  sorted->Add( (TrkTrack*)t[indi] );                        sorted->Add( (TrkTrack*)t[indi] );      
766                                    
767                  m[indi] = 0;                  m[indi] = 0;
# Line 629  TrkSinglet *TrkLevel2::GetSingletY(int i Line 841  TrkSinglet *TrkLevel2::GetSingletY(int i
841   * Retrieves the it-th "physical" track, sorted by the method GetNTracks().   * Retrieves the it-th "physical" track, sorted by the method GetNTracks().
842   * @param it Track number, ranging from 0 to GetNTracks().   * @param it Track number, ranging from 0 to GetNTracks().
843   */   */
844  /*TrkTrack *TrkLevel2::GetTrack(int it){  
       
     if(it >= this->GetNTracks()){  
         cout << "** TrkLevel2 ** Track "<< it << "does not exits! " << endl;  
         cout << "                Physical tracks GetNTracks() = "<< this->ntrk() << endl;  
         return 0;  
     }  
         TClonesArray* sorted = GetTracks();  
         TClonesArray &ts = *sorted;  
           
 //    TrkTrack *track = (TrkTrack*)ts[it];  
         TrkTrack *track = new TrkTrack( *(TrkTrack*)ts[it] ); //copia  
         sorted->Delete("all");////TEMPORANEO  
         return track;  
 }*/  
845  TrkTrack *TrkLevel2::GetTrack(int it){  TrkTrack *TrkLevel2::GetTrack(int it){
846            
847          if(it >= this->GetNTracks()){          if(it >= this->GetNTracks()){
# Line 664  Int_t TrkLevel2::GetNTracks(){ Line 862  Int_t TrkLevel2::GetNTracks(){
862                                    
863          Float_t ntot=0;          Float_t ntot=0;
864          TClonesArray &t = *Track;          TClonesArray &t = *Track;
865          for(int i=0; i<ntrk(); i++) {          for(int i=0; i<ntrk(); i++) {    
866                  if( ((TrkTrack *)t[i])->GetImageSeqNo() == -1 ) ntot+=1.;                  if( ((TrkTrack *)t[i])->GetImageSeqNo() == -1 ) ntot+=1.;
867                  else ntot+=0.5;                  else ntot+=0.5;
868          }          }
# Line 679  Int_t TrkLevel2::GetNTracks(){ Line 877  Int_t TrkLevel2::GetNTracks(){
877   * Retrieves (if present) the image of the it-th "physical" track, sorted by the method GetNTracks().   * Retrieves (if present) the image of the it-th "physical" track, sorted by the method GetNTracks().
878   * @param it Track number, ranging from 0 to GetNTracks().   * @param it Track number, ranging from 0 to GetNTracks().
879   */   */
 /*TrkTrack *TrkLevel2::GetTrackImage(int it){  
   
     if(it >= this->GetNTracks()){  
         cout << "** TrkLevel2 ** Track "<< it << "does not exits! " << endl;  
         cout << "                Physical tracks GetNTracks() = "<< this->ntrk() << endl;  
         return 0;  
     }  
           
         TClonesArray* sorted = GetTracks();  
         TClonesArray &ts = *sorted;  
         TrkTrack *track = (TrkTrack*)ts[it];  
 //    TrkTrack *track = (TrkTrack*)(*(this->GetTracks()))[it];  
       
         if(!track->HasImage()){  
         cout << "** TrkLevel2 ** Track "<< it << "does not have image! " << endl;  
         return 0;  
     }  
     TrkTrack *image = (TrkTrack*)(*Track)[track->image];  
   
 //      GetTracks()->Delete(); ////TEMPORANEO  
         sorted->Delete(); ////TEMPORANEO  
           
     return image;  
       
 }*/  
880  TrkTrack *TrkLevel2::GetTrackImage(int it){  TrkTrack *TrkLevel2::GetTrackImage(int it){
881    
882          if(it >= this->GetNTracks()){          if(it >= this->GetNTracks()){
# Line 833  Trajectory::Trajectory(int n, float* zin Line 1006  Trajectory::Trajectory(int n, float* zin
1006      tl = new float[npoint];      tl = new float[npoint];
1007      int i=0;      int i=0;
1008      do{      do{
1009          x[i] = 0;                  x[i] = 0;
1010          y[i] = 0;                  y[i] = 0;
1011          z[i] = zin[i];                  z[i] = zin[i];
1012          thx[i] = 0;                  thx[i] = 0;
1013          thy[i] = 0;                  thy[i] = 0;
1014          tl[i] = 0;                  tl[i] = 0;
1015          i++;                              i++;            
1016      }while(zin[i-1] > zin[i] && i < npoint);      }while(zin[i-1] > zin[i] && i < npoint);
1017      npoint=i;      npoint=i;
1018      if(npoint != n)cout << "NB! Trajectory created with "<<npoint<<" points"<<endl;      if(npoint != n)cout << "NB! Trajectory created with "<<npoint<<" points"<<endl;
# Line 882  float Trajectory::GetLength(int ifirst, Line 1055  float Trajectory::GetLength(int ifirst,
1055    
1056  }  }
1057    
1058    
1059  ClassImp(TrkLevel2);  ClassImp(TrkLevel2);
1060  ClassImp(TrkSinglet);  ClassImp(TrkSinglet);
1061  ClassImp(TrkTrack);  ClassImp(TrkTrack);

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.13

  ViewVC Help
Powered by ViewVC 1.1.23