/[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.9 by pam-fi, Tue Sep 5 12:52:20 2006 UTC revision 1.21 by pam-fi, Thu Jan 11 10:20:58 2007 UTC
# Line 4  Line 4 
4   */   */
5  #include <TrkLevel2.h>  #include <TrkLevel2.h>
6  #include <iostream>  #include <iostream>
7    #include <math.h>
8  using namespace std;  using namespace std;
9  //......................................  //......................................
10  // F77 routines  // F77 routines
# Line 11  using namespace std; Line 12  using namespace std;
12  extern "C" {      extern "C" {    
13      void dotrack_(int*, double*, double*, double*, double*, int*);      void dotrack_(int*, double*, double*, double*, double*, int*);
14      void dotrack2_(int*, double*, double*, double*, double*,double*, double*, double*,int*);      void dotrack2_(int*, double*, double*, double*, double*,double*, double*, double*,int*);
15      int  readb_(const char*);  //    int  readb_(const char*);
16        int  readb_();
17        void mini2_(int*,int*,int*);
18        void guess_();
19  }  }
20  //--------------------------------------  //--------------------------------------
21  //  //
22  //  //
23  //--------------------------------------  //--------------------------------------
24  TrkTrack::TrkTrack(){  TrkTrack::TrkTrack(){
25    //    cout << "TrkTrack::TrkTrack()" << endl;
26      seqno = -1;      seqno = -1;
27      image = -1;      image = -1;
28      chi2  = 0;      chi2  = 0;
29        nstep = 0;
30      for(int it1=0;it1<5;it1++){      for(int it1=0;it1<5;it1++){
31                  al[it1] = 0;          al[it1] = 0;
32                  for(int it2=0;it2<5;it2++)coval[it1][it2] = 0;          for(int it2=0;it2<5;it2++)coval[it1][it2] = 0;
33      };      };
34      for(int ip=0;ip<6;ip++){      for(int ip=0;ip<6;ip++){
35                  xgood[ip]  = 0;          xgood[ip]  = 0;
36                  ygood[ip]  = 0;          ygood[ip]  = 0;
37                  xm[ip]     = 0;          xm[ip]     = 0;
38                  ym[ip]     = 0;          ym[ip]     = 0;
39                  zm[ip]     = 0;          zm[ip]     = 0;
40                  resx[ip]   = 0;          resx[ip]   = 0;
41                  resy[ip]   = 0;          resy[ip]   = 0;
42                  xv[ip]     = 0;          xv[ip]     = 0;
43                  yv[ip]     = 0;          yv[ip]     = 0;
44                  zv[ip]     = 0;          zv[ip]     = 0;
45                  axv[ip]    = 0;          axv[ip]    = 0;
46                  ayv[ip]    = 0;          ayv[ip]    = 0;
47                  dedx_x[ip] = 0;          dedx_x[ip] = 0;
48                  dedx_y[ip] = 0;          dedx_y[ip] = 0;
49  //              clx[ip]    = 0;      };
50  //              cly[ip]    = 0;      clx = 0;
51          };      cly = 0;
         clx = new TRefArray(6,0);  
         cly = new TRefArray(6,0);  
52  };  };
53  //--------------------------------------  //--------------------------------------
54  //  //
# Line 54  TrkTrack::TrkTrack(const TrkTrack& t){ Line 58  TrkTrack::TrkTrack(const TrkTrack& t){
58      seqno = t.seqno;      seqno = t.seqno;
59      image = t.image;      image = t.image;
60      chi2  = t.chi2;      chi2  = t.chi2;
61        nstep = t.nstep;
62      for(int it1=0;it1<5;it1++){      for(int it1=0;it1<5;it1++){
63                  al[it1] = t.al[it1];          al[it1] = t.al[it1];
64                  for(int it2=0;it2<5;it2++)coval[it1][it2] = t.coval[it1][it2];          for(int it2=0;it2<5;it2++)coval[it1][it2] = t.coval[it1][it2];
65      };      };
66      for(int ip=0;ip<6;ip++){      for(int ip=0;ip<6;ip++){
67                  xgood[ip]  = t.xgood[ip];          xgood[ip]  = t.xgood[ip];
68                  ygood[ip]  = t.ygood[ip];          ygood[ip]  = t.ygood[ip];
69                  xm[ip]     = t.xm[ip];          xm[ip]     = t.xm[ip];
70                  ym[ip]     = t.ym[ip];          ym[ip]     = t.ym[ip];
71                  zm[ip]     = t.zm[ip];          zm[ip]     = t.zm[ip];
72                  resx[ip]   = t.resx[ip];          resx[ip]   = t.resx[ip];
73                  resy[ip]   = t.resy[ip];          resy[ip]   = t.resy[ip];
74                  xv[ip]     = t.xv[ip];          xv[ip]     = t.xv[ip];
75                  yv[ip]     = t.yv[ip];          yv[ip]     = t.yv[ip];
76                  zv[ip]     = t.zv[ip];          zv[ip]     = t.zv[ip];
77                  axv[ip]    = t.axv[ip];          axv[ip]    = t.axv[ip];
78                  ayv[ip]    = t.ayv[ip];          ayv[ip]    = t.ayv[ip];
79                  dedx_x[ip] = t.dedx_x[ip];          dedx_x[ip] = t.dedx_x[ip];
80                  dedx_y[ip] = t.dedx_y[ip];          dedx_y[ip] = t.dedx_y[ip];
81          //      clx[ip]    = 0;//<<<<pointer      };
82          //      cly[ip]    = 0;//<<<<pointer      clx = new TRefArray(*(t.clx));
83          };      cly = new TRefArray(*(t.cly));
         clx = new TRefArray(*(t.clx));  
         cly = new TRefArray(*(t.cly));  
84                    
85  };  };
86  //--------------------------------------  //--------------------------------------
87  //  //
88  //  //
89  //--------------------------------------  //--------------------------------------
90    void TrkTrack::Copy(TrkTrack& t){
91    
92        t.seqno = seqno;
93        t.image = image;
94        t.chi2  = chi2;
95        t.nstep = nstep;
96        for(int it1=0;it1<5;it1++){
97            t.al[it1] = al[it1];
98            for(int it2=0;it2<5;it2++)t.coval[it1][it2] = coval[it1][it2];
99        };
100        for(int ip=0;ip<6;ip++){
101            t.xgood[ip]  = xgood[ip];
102            t.ygood[ip]  = ygood[ip];
103            t.xm[ip]     = xm[ip];
104            t.ym[ip]     = ym[ip];
105            t.zm[ip]     = zm[ip];
106            t.resx[ip]   = resx[ip];
107            t.resy[ip]   = resy[ip];
108            t.xv[ip]     = xv[ip];
109            t.yv[ip]     = yv[ip];
110            t.zv[ip]     = zv[ip];
111            t.axv[ip]    = axv[ip];
112            t.ayv[ip]    = ayv[ip];
113            t.dedx_x[ip] = dedx_x[ip];
114            t.dedx_y[ip] = dedx_y[ip];
115                
116        };
117        
118    };
119    //--------------------------------------
120    //
121    //
122    //--------------------------------------
123  /**  /**
124   * Evaluates the trajectory in the apparatus associated to the track.   * Evaluates the trajectory in the apparatus associated to the track.
125   * 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.     * 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.  
# Line 194  Float_t TrkTrack::GetDEDX(){ Line 230  Float_t TrkTrack::GetDEDX(){
230  //--------------------------------------  //--------------------------------------
231  void TrkTrack::Dump(){  void TrkTrack::Dump(){
232      cout << endl << "========== Track " ;      cout << endl << "========== Track " ;
233        cout << endl << "seq.  n. : "<< seqno;
234        cout << endl << "image n. : "<< image;
235      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] << " ";
236      cout << endl << "chi^2    : "<< chi2;      cout << endl << "chi^2    : "<< chi2;
237        cout << endl << "n.step   : "<< nstep;
238      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] ;
239      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] ;
240      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] << " ";
241      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] << " ";
242      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] << " ";
243        cout << endl << "xv       : "; for(int i=0; i<6; i++)cout << xv[i] << " ";
244        cout << endl << "yv       : "; for(int i=0; i<6; i++)cout << yv[i] << " ";
245        cout << endl << "zv       : "; for(int i=0; i<6; i++)cout << zv[i] << " ";
246        cout << endl << "resx     : "; for(int i=0; i<6; i++)cout << resx[i] << " ";
247        cout << endl << "resy     : "; for(int i=0; i<6; i++)cout << resy[i] << " ";
248        cout << endl << "coval    : "; for(int i=0; i<5; i++)cout << coval[0][i]<<" ";
249        cout << endl << "           "; for(int i=0; i<5; i++)cout << coval[1][i]<<" ";
250        cout << endl << "           "; for(int i=0; i<5; i++)cout << coval[2][i]<<" ";
251        cout << endl << "           "; for(int i=0; i<5; i++)cout << coval[3][i]<<" ";
252        cout << endl << "           "; for(int i=0; i<5; i++)cout << coval[4][i]<<" ";
253      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] << " ";
254      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] << " ";
255        cout << endl;
256    }
257    /**
258     * Set the TrkTrack position measurements
259     */
260    void TrkTrack::SetMeasure(double *xmeas, double *ymeas, double *zmeas){
261        for(int i=0; i<6; i++) xm[i]=*xmeas++;
262        for(int i=0; i<6; i++) ym[i]=*ymeas++;
263        for(int i=0; i<6; i++) zm[i]=*zmeas++;
264    }
265    /**
266     * Set the TrkTrack position resolution
267     */
268    void TrkTrack::SetResolution(double *rx, double *ry){
269        for(int i=0; i<6; i++) resx[i]=*rx++;
270        for(int i=0; i<6; i++) resy[i]=*ry++;
271    }
272    /**
273     * Set the TrkTrack good measurement
274     */
275    void TrkTrack::SetGood(int *xg, int *yg){
276        for(int i=0; i<6; i++) xgood[i]=*xg++;
277        for(int i=0; i<6; i++) ygood[i]=*yg++;
278    }
279    
280    /**
281     * Load the magnetic field
282     */
283    void TrkTrack::LoadField(TString path){
284        
285        strcpy(path_.path,path.Data());
286        path_.pathlen = path.Length();
287        path_.error   = 0;
288        readb_();
289    
290    };
291    
292    /**
293     * Method to fill minimization-routine common
294     */
295    void TrkTrack::FillMiniStruct(cMini2track& track){
296    
297        for(int i=0; i<6; i++){
298    
299            track.xgood[i]=xgood[i];
300            track.ygood[i]=ygood[i];
301            
302            track.xm[i]=xm[i];
303            track.ym[i]=ym[i];
304            track.zm[i]=zm[i];
305            
306    //      --- temporaneo ----------------------------
307    //      andrebbe inserita la dimensione del sensore
308            float segment = 100.;
309            track.xm_a[i]=xm[i];
310            track.xm_b[i]=xm[i];
311            track.ym_a[i]=ym[i];
312            track.ym_b[i]=ym[i];
313            if(       xgood[i] && !ygood[i] ){
314                track.ym_a[i] = track.ym_a[i]+segment;
315                track.ym_b[i] = track.ym_b[i]-segment;
316            }else if( !xgood[i] && ygood[i]){
317                track.xm_a[i] = track.xm_a[i]+segment;
318                track.xm_b[i] = track.xm_b[i]-segment;
319            }
320    //      --- temporaneo ----------------------------
321            
322            track.resx[i]=resx[i];
323            track.resy[i]=resy[i];
324        }
325    
326        for(int i=0; i<5; i++) track.al[i]=al[i];
327        track.zini = 23.5;
328    // ZINI = 23.5 !!! it should be the same parameter in all codes
329        
330    }
331    /**
332     * Method to set values from  minimization-routine common
333     */
334    void TrkTrack::SetFromMiniStruct(cMini2track *track){
335    
336        for(int i=0; i<5; i++) {
337            al[i]=track->al[i];
338            for(int j=0; j<5; j++) coval[i][j]=track->cov[i][j];
339        }
340        chi2  = track->chi2;
341        nstep = track->nstep;
342        for(int i=0; i<6; i++){
343            xv[i]  = track->xv[i];
344            yv[i]  = track->yv[i];
345            zv[i]  = track->zv[i];
346            xm[i]  = track->xm[i];
347            ym[i]  = track->ym[i];
348            zm[i]  = track->zm[i];
349            axv[i] = track->axv[i];
350            ayv[i] = track->ayv[i];
351        }
352    
353        
354    }
355    /**
356     * Tracking method. It calls F77 mini routine.
357     */
358    void TrkTrack::Fit(double pfixed, int& fail, int iprint){
359    
360        float al_ini[] = {0.,0.,0.,0.,0.};
361    
362        extern cMini2track track_;
363        fail = 0;
364        FillMiniStruct(track_);
365    
366        // if fit variables have been reset, evaluate the initial guess
367        if(al[0]==-9999.&&al[1]==-9999.&&al[2]==-9999.&&al[3]==-9999.&&al[4]==-9999.)guess_();
368    
369        // --------------------- free momentum
370        if(pfixed==0.) {
371            track_.pfixed=0.;
372        }
373        // --------------------- fixed momentum
374        if(pfixed!=0.) {
375            al[4]=1./pfixed;    
376            track_.pfixed=pfixed;
377        }
378    
379        //  store temporarily the initial guess
380        for(int i=0; i<5; i++) al_ini[i]=track_.al[i];
381    
382        //  ------------------------------------------
383        //  call mini routine
384        int istep=0;
385        int ifail=0;
386        mini2_(&istep,&ifail, &iprint);
387        if(ifail!=0) {
388            if(iprint)cout << "ERROR: ifail= " << ifail << endl;
389            fail = 1;
390        }
391        //  ------------------------------------------
392        
393        SetFromMiniStruct(&track_);
394    //    cout << endl << "eta ===> " << track_.al[4] << endl;
395    
396    //     for(int i=0; i<5; i++) al[i]=track_.al[i];
397    //     chi2=track_.chi2;
398    //     nstep=track_.nstep;
399    //     for(int i=0; i<6; i++) xv[i]=track_.xv[i];
400    //     for(int i=0; i<6; i++) yv[i]=track_.yv[i];
401    //     for(int i=0; i<6; i++) zv[i]=track_.zv[i];
402    //     for(int i=0; i<6; i++) axv[i]=track_.axv[i];
403    //     for(int i=0; i<6; i++) ayv[i]=track_.ayv[i];
404    //     for(int i=0; i<5; i++) {
405    //      for(int j=0; j<5; j++) coval[i][j]=track_.cov[i][j];
406    //     }
407    
408        if(fail){
409            if(iprint)cout << " >>>> fit failed >>>> drawing initial par"<<endl;
410            for(int i=0; i<5; i++) al[i]=al_ini[i];
411        }
412    
413    };
414    /*
415     * Reset the fit parameters
416     */
417    void TrkTrack::FitReset(){
418        for(int i=0; i<5; i++) al[i]=-9999.;
419        chi2=0.;
420        nstep=0;
421        for(int i=0; i<6; i++) xv[i]=0.;
422        for(int i=0; i<6; i++) yv[i]=0.;
423        for(int i=0; i<6; i++) zv[i]=0.;
424        for(int i=0; i<6; i++) axv[i]=0.;
425        for(int i=0; i<6; i++) ayv[i]=0.;
426        for(int i=0; i<5; i++) {
427            for(int j=0; j<5; j++) coval[i][j]=0.;
428        }
429  }  }
430    
431    //--------------------------------------
432    //
433    //
434    //--------------------------------------
435    void TrkTrack::Clear(){
436    //    cout << "TrkTrack::Clear()"<<endl;
437        seqno = -1;
438        image = -1;
439        chi2  = 0;
440        nstep = 0;
441        for(int it1=0;it1<5;it1++){
442            al[it1] = 0;
443            for(int it2=0;it2<5;it2++)coval[it1][it2] = 0;
444        };
445        for(int ip=0;ip<6;ip++){
446            xgood[ip]  = 0;
447            ygood[ip]  = 0;
448            xm[ip]     = 0;
449            ym[ip]     = 0;
450            zm[ip]     = 0;
451            resx[ip]   = 0;
452            resy[ip]   = 0;
453            xv[ip]     = 0;
454            yv[ip]     = 0;
455            zv[ip]     = 0;
456            axv[ip]    = 0;
457            ayv[ip]    = 0;
458            dedx_x[ip] = 0;
459            dedx_y[ip] = 0;
460    
461        };
462        if(clx)clx->Clear();
463        if(cly)cly->Clear();
464    };
465    //--------------------------------------
466    //
467    //
468    //--------------------------------------
469    void TrkTrack::Delete(){
470    //    cout << "TrkTrack::Delete()"<<endl;
471    //    Clear();
472        if(clx)delete clx;
473        if(cly)delete cly;
474    };
475    //--------------------------------------
476    //
477    //
478    //--------------------------------------
479    
480  //--------------------------------------  //--------------------------------------
481  //  //
482  //  //
483  //--------------------------------------  //--------------------------------------
484  TrkSinglet::TrkSinglet(){  TrkSinglet::TrkSinglet(){
485    //    cout << "TrkSinglet::TrkSinglet() " << GetUniqueID()<<endl;
486      plane    = 0;      plane    = 0;
487      coord[0] = 0;      coord[0] = 0;
488      coord[1] = 0;      coord[1] = 0;
489      sgnl     = 0;      sgnl     = 0;
490          cls      = 0;  //    cls      = 0;
491  };  };
492  //--------------------------------------  //--------------------------------------
493  //  //
494  //  //
495  //--------------------------------------  //--------------------------------------
496  TrkSinglet::TrkSinglet(const TrkSinglet& s){  TrkSinglet::TrkSinglet(const TrkSinglet& s){
497    //    cout << "TrkSinglet::TrkSinglet(const TrkSinglet& s) " << GetUniqueID()<<endl;
498      plane    = s.plane;      plane    = s.plane;
499      coord[0] = s.coord[0];      coord[0] = s.coord[0];
500      coord[1] = s.coord[1];      coord[1] = s.coord[1];
501      sgnl     = s.sgnl;      sgnl     = s.sgnl;
502  //      cls      = 0;//<<<<pointer  //      cls      = 0;//<<<<pointer
503          cls      = TRef(s.cls);      cls      = TRef(s.cls);
504  };  };
505  //--------------------------------------  //--------------------------------------
506  //  //
# Line 242  void TrkSinglet::Dump(){ Line 517  void TrkSinglet::Dump(){
517  //  //
518  //  //
519  //--------------------------------------  //--------------------------------------
520    void TrkSinglet::Clear(){
521    //    cout << "TrkSinglet::Clear() " << GetUniqueID()<<endl;
522    //    cls=0;
523        plane=-1;
524        coord[0]=-999;
525        coord[1]=-999;
526        sgnl=0;
527        
528    }
529    //--------------------------------------
530    //
531    //
532    //--------------------------------------
533  TrkLevel2::TrkLevel2(){  TrkLevel2::TrkLevel2(){
534      good2    = -1;  //    cout <<"TrkLevel2::TrkLevel2()"<<endl;
535      for(Int_t i=0; i<12 ; i++){      for(Int_t i=0; i<12 ; i++){
536          crc[i] = -1;                  good[i] = -1;
537      };          };
538      Track    = new TClonesArray("TrkTrack");  //    Track    = new TClonesArray("TrkTrack");
539      SingletX = new TClonesArray("TrkSinglet");  //    SingletX = new TClonesArray("TrkSinglet");
540      SingletY = new TClonesArray("TrkSinglet");  //    SingletY = new TClonesArray("TrkSinglet");
541        Track    = 0;
542        SingletX = 0;
543        SingletY = 0;
544    
 //      PhysicalTrack = new TClonesArray("TrkTrack");  
         //sostituire con TRefArray... appena ho capito come si usa  
545  }  }
546  //--------------------------------------  //--------------------------------------
547  //  //
548  //  //
549  //--------------------------------------  //--------------------------------------
550  void TrkLevel2::Dump(){  void TrkLevel2::Dump(){
551      TClonesArray &t  = *Track;          
552      TClonesArray &sx = *SingletX;          //
     TClonesArray &sy = *SingletY;  
   
553      cout << endl << endl << "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-";      cout << endl << endl << "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-";
554      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];  
555      cout << endl << "ntrk()   : " << this->ntrk() ;      cout << endl << "ntrk()   : " << this->ntrk() ;
556      cout << endl << "nclsx()  : " << this->nclsx();      cout << endl << "nclsx()  : " << this->nclsx();
557      cout << endl << "nclsy()  : " << this->nclsy();      cout << endl << "nclsy()  : " << this->nclsy();
558      for(int i=0; i<this->ntrk(); i++)     ((TrkTrack *)t[i])->Dump();  //     TClonesArray &t  = *Track;
559      for(int i=0; i<this->nclsx(); i++) ((TrkSinglet *)sx[i])->Dump();  //     TClonesArray &sx = *SingletX;
560      for(int i=0; i<this->nclsy(); i++) ((TrkSinglet *)sy[i])->Dump();  //     TClonesArray &sy = *SingletY;
561    //     for(int i=0; i<ntrk(); i++)     ((TrkTrack *)t[i])->Dump();
562    //     for(int i=0; i<nclsx(); i++) ((TrkSinglet *)sx[i])->Dump();
563    //     for(int i=0; i<nclsy(); i++) ((TrkSinglet *)sy[i])->Dump();
564        if(Track){
565            TClonesArray &t  = *Track;
566            for(int i=0; i<ntrk(); i++)     ((TrkTrack *)t[i])->Dump();
567        }      
568        if(SingletX){
569            TClonesArray &sx = *SingletX;
570            for(int i=0; i<nclsx(); i++) ((TrkSinglet *)sx[i])->Dump();
571        }
572        if(SingletY){
573            TClonesArray &sy = *SingletY;
574            for(int i=0; i<nclsy(); i++) ((TrkSinglet *)sy[i])->Dump();
575        }
576  }  }
577  //--------------------------------------  //--------------------------------------
578  //  //
# Line 281  void TrkLevel2::Dump(){ Line 582  void TrkLevel2::Dump(){
582   * 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).
583   */   */
584  void TrkLevel2::SetFromLevel2Struct(cTrkLevel2 *l2){  void TrkLevel2::SetFromLevel2Struct(cTrkLevel2 *l2){
585      //  
586  //    Track    = new TClonesArray("TrkTrack");          //  temporary objects:
 //    SingletX = new TClonesArray("TrkSinglet");  
 //    SingletY = new TClonesArray("TrkSinglet");  
 //  temporary objects:  
587      TrkSinglet* t_singlet = new TrkSinglet();      TrkSinglet* t_singlet = new TrkSinglet();
588      TrkTrack*   t_track   = new TrkTrack();      TrkTrack*   t_track   = new TrkTrack();
589  //  general variables  
590      good2 = l2->good2;          //  **** general variables ****
591    //    good2 = l2->good2;
592      for(Int_t i=0; i<12 ; i++){      for(Int_t i=0; i<12 ; i++){
593          crc[i] = l2->crc[i];  //              crc[i] = l2->crc[i];
594      };                  good[i] = l2->good[i];
595  //  *** TRACKS ***          };
596            //  *** TRACKS ***
597        if(!Track) Track = new TClonesArray("TrkTrack");
598      TClonesArray &t = *Track;      TClonesArray &t = *Track;
599      for(int i=0; i<l2->ntrk; i++){      for(int i=0; i<l2->ntrk; i++){
600                  t_track->seqno = i;// NBNBNBNB deve sempre essere = i          t_track->seqno = i;// NBNBNBNB deve sempre essere = i
601                  t_track->image = l2->image[i]-1;          t_track->image = l2->image[i]-1;
602          //      cout << "track "<<i<<t_track->seqno << t_track->image<<endl;          //      cout << "track "<<i<<t_track->seqno << t_track->image<<endl;
603                  t_track->chi2  = l2->chi2_nt[i];          t_track->chi2  = l2->chi2_nt[i];
604                  for(int it1=0;it1<5;it1++){          t_track->nstep = l2->nstep_nt[i];
605                          t_track->al[it1] = l2->al_nt[i][it1];          for(int it1=0;it1<5;it1++){
606                          for(int it2=0;it2<5;it2++)              t_track->al[it1] = l2->al_nt[i][it1];
607                          t_track->coval[it1][it2] = l2->coval[i][it2][it1];              for(int it2=0;it2<5;it2++)
608                  };                  t_track->coval[it1][it2] = l2->coval[i][it2][it1];
609                  for(int ip=0;ip<6;ip++){          };
610                          t_track->xgood[ip]  = l2->xgood_nt[i][ip];          for(int ip=0;ip<6;ip++){
611                          t_track->ygood[ip]  = l2->ygood_nt[i][ip];              t_track->xgood[ip]  = l2->xgood_nt[i][ip];
612                          t_track->xm[ip]     = l2->xm_nt[i][ip];              t_track->ygood[ip]  = l2->ygood_nt[i][ip];
613                          t_track->ym[ip]     = l2->ym_nt[i][ip];              t_track->xm[ip]     = l2->xm_nt[i][ip];
614                          t_track->zm[ip]     = l2->zm_nt[i][ip];              t_track->ym[ip]     = l2->ym_nt[i][ip];
615                          t_track->resx[ip]   = l2->resx_nt[i][ip];              t_track->zm[ip]     = l2->zm_nt[i][ip];
616                          t_track->resy[ip]   = l2->resy_nt[i][ip];              t_track->resx[ip]   = l2->resx_nt[i][ip];
617                          t_track->xv[ip]     = l2->xv_nt[i][ip];              t_track->resy[ip]   = l2->resy_nt[i][ip];
618                          t_track->yv[ip]     = l2->yv_nt[i][ip];              t_track->xv[ip]     = l2->xv_nt[i][ip];
619                          t_track->zv[ip]     = l2->zv_nt[i][ip];              t_track->yv[ip]     = l2->yv_nt[i][ip];
620                          t_track->axv[ip]    = l2->axv_nt[i][ip];              t_track->zv[ip]     = l2->zv_nt[i][ip];
621                          t_track->ayv[ip]    = l2->ayv_nt[i][ip];              t_track->axv[ip]    = l2->axv_nt[i][ip];
622                          t_track->dedx_x[ip] = l2->dedx_x[i][ip];              t_track->ayv[ip]    = l2->ayv_nt[i][ip];
623                          t_track->dedx_y[ip] = l2->dedx_y[i][ip];              t_track->dedx_x[ip] = l2->dedx_x[i][ip];
624                t_track->dedx_y[ip] = l2->dedx_y[i][ip];
625  //                      t_track->clx[ip] = 0;  //                      t_track->clx[ip] = 0;
626  //                      t_track->cly[ip] = 0;  //                      t_track->cly[ip] = 0;
627                  };          };
628                  new(t[i]) TrkTrack(*t_track);          new(t[i]) TrkTrack(*t_track);
629                  t_track->Clear();          t_track->Clear();
630      };      };
631  //  *** SINGLETS ***  //  *** SINGLETS ***
632        if(!SingletX)SingletX = new TClonesArray("TrkSinglet");
633      TClonesArray &sx = *SingletX;      TClonesArray &sx = *SingletX;
634      for(int i=0; i<l2->nclsx; i++){      for(int i=0; i<l2->nclsx; i++){
635                  t_singlet->plane    = l2->planex[i];          t_singlet->plane    = l2->planex[i];
636                  t_singlet->coord[0] = l2->xs[i][0];          t_singlet->coord[0] = l2->xs[i][0];
637                  t_singlet->coord[1] = l2->xs[i][1];          t_singlet->coord[1] = l2->xs[i][1];
638                  t_singlet->sgnl     = l2->signlxs[i];          t_singlet->sgnl     = l2->signlxs[i];
639  //              t_singlet->cls      = 0;  //              t_singlet->cls      = 0;
640                  new(sx[i]) TrkSinglet(*t_singlet);          new(sx[i]) TrkSinglet(*t_singlet);
641                  t_singlet->Clear();          t_singlet->Clear();
642      }      }
643        if(!SingletY)SingletY = new TClonesArray("TrkSinglet");
644      TClonesArray &sy = *SingletY;      TClonesArray &sy = *SingletY;
645      for(int i=0; i<l2->nclsy; i++){      for(int i=0; i<l2->nclsy; i++){
646                  t_singlet->plane    = l2->planey[i];          t_singlet->plane    = l2->planey[i];
647                  t_singlet->coord[0] = l2->ys[i][0];          t_singlet->coord[0] = l2->ys[i][0];
648                  t_singlet->coord[1] = l2->ys[i][1];          t_singlet->coord[1] = l2->ys[i][1];
649                  t_singlet->sgnl     = l2->signlys[i];          t_singlet->sgnl     = l2->signlys[i];
650  //              t_singlet->cls      = 0;  //              t_singlet->cls      = 0;
651                  new(sy[i]) TrkSinglet(*t_singlet);          new(sy[i]) TrkSinglet(*t_singlet);
652                  t_singlet->Clear();          t_singlet->Clear();
653          };      };
654                    
655          delete t_track;      delete t_track;
656          delete t_singlet;      delete t_singlet;
657  }  }
658  //--------------------------------------  //--------------------------------------
659  //  //
# Line 365  void TrkLevel2::SetFromLevel2Struct(cTrk Line 669  void TrkLevel2::SetFromLevel2Struct(cTrk
669          TrkSinglet* t_singlet = new TrkSinglet();          TrkSinglet* t_singlet = new TrkSinglet();
670          TrkTrack*   t_track   = new TrkTrack();          TrkTrack*   t_track   = new TrkTrack();
671  // general variables  // general variables
672          good2 = l2->good2;  //      good2 = l2->good2;
673          for(Int_t i=0; i<12 ; i++){          for(Int_t i=0; i<12 ; i++){
674                  crc[i] = l2->crc[i];  //              crc[i] = l2->crc[i];
675                    good[i] = l2->good[i];
676          };          };
677  // *** TRACKS ***  // *** TRACKS ***
678            if(!Track) Track = new TClonesArray("TrkTrack");
679          TClonesArray &t = *Track;          TClonesArray &t = *Track;
680            if(!t_track->clx)t_track->clx = new TRefArray(6,0);
681            if(!t_track->cly)t_track->cly = new TRefArray(6,0);
682          for(int i=0; i<l2->ntrk; i++){          for(int i=0; i<l2->ntrk; i++){
683                  t_track->seqno = i;// NBNBNBNB deve sempre essere = i                  t_track->seqno = i;// NBNBNBNB deve sempre essere = i
684                  t_track->image = l2->image[i]-1;                  t_track->image = l2->image[i]-1;
685  //              cout << "track "<<i<<t_track->seqno << t_track->image<<endl;  //              cout << "track "<<i<<t_track->seqno << t_track->image<<endl;
686                  t_track->chi2  = l2->chi2_nt[i];                  t_track->chi2  = l2->chi2_nt[i];
687                    t_track->nstep = l2->nstep_nt[i];
688                  for(int it1=0;it1<5;it1++){                  for(int it1=0;it1<5;it1++){
689                          t_track->al[it1] = l2->al_nt[i][it1];                          t_track->al[it1] = l2->al_nt[i][it1];
690                          for(int it2=0;it2<5;it2++)                          for(int it2=0;it2<5;it2++)
# Line 398  void TrkLevel2::SetFromLevel2Struct(cTrk Line 707  void TrkLevel2::SetFromLevel2Struct(cTrk
707                          t_track->dedx_y[ip] = l2->dedx_y[i][ip];                          t_track->dedx_y[ip] = l2->dedx_y[i][ip];
708  //                      cout << "traccia "<<i<<"  --  "<< ip << " "<< l2->cltrx[i][ip] <<" "<< l2->cltry[i][ip] <<" "<< t_track->xgood[ip] << t_track->ygood[ip]<<endl;  //                      cout << "traccia "<<i<<"  --  "<< ip << " "<< l2->cltrx[i][ip] <<" "<< l2->cltry[i][ip] <<" "<< t_track->xgood[ip] << t_track->ygood[ip]<<endl;
709                          //-----------------------------------------------------                          //-----------------------------------------------------
710  //                      t_track->clx[ip] = l1->GetCluster(l2->cltrx[i][ip]-1);                          //-----------------------------------------------------
 //                      t_track->cly[ip] = l1->GetCluster(l2->cltry[i][ip]-1);  
711                          if(t_track->xgood[ip])t_track->clx->AddAt(l1->GetCluster(l2->cltrx[i][ip]-1),ip);                          if(t_track->xgood[ip])t_track->clx->AddAt(l1->GetCluster(l2->cltrx[i][ip]-1),ip);
712                          if(t_track->ygood[ip])t_track->cly->AddAt(l1->GetCluster(l2->cltry[i][ip]-1),ip);                          if(t_track->ygood[ip])t_track->cly->AddAt(l1->GetCluster(l2->cltry[i][ip]-1),ip);
713    //                      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;
714    //                      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;
715                            //-----------------------------------------------------
716                          //-----------------------------------------------------                          //-----------------------------------------------------
717                  };                  };
718                  new(t[i]) TrkTrack(*t_track);                  new(t[i]) TrkTrack(*t_track);
719                  t_track->Clear();                  t_track->Clear();
720          };          };
721  // *** SINGLETS ***  // *** SINGLETS ***
722            if(!SingletX)SingletX = new TClonesArray("TrkSinglet");
723          TClonesArray &sx = *SingletX;          TClonesArray &sx = *SingletX;
724          for(int i=0; i<l2->nclsx; i++){          for(int i=0; i<l2->nclsx; i++){
725                  t_singlet->plane    = l2->planex[i];                  t_singlet->plane    = l2->planex[i];
# Line 417  void TrkLevel2::SetFromLevel2Struct(cTrk Line 729  void TrkLevel2::SetFromLevel2Struct(cTrk
729                  //-----------------------------------------------------                  //-----------------------------------------------------
730  //              cout << "singolo x "<<i<<"  --  "<<  l2->clsx[i] <<endl;  //              cout << "singolo x "<<i<<"  --  "<<  l2->clsx[i] <<endl;
731                  t_singlet->cls      = l1->GetCluster(l2->clsx[i]-1);                  t_singlet->cls      = l1->GetCluster(l2->clsx[i]-1);
732    //              cout<<" i "<<i<<" l2->clsx[i] "<<l2->clsx[i]<< " l1->GetCluster(l2->clsx[i]-1) "<<l1->GetCluster(l2->clsx[i]-1)<<endl;          
733                  //-----------------------------------------------------                  //-----------------------------------------------------
734                  new(sx[i]) TrkSinglet(*t_singlet);                  new(sx[i]) TrkSinglet(*t_singlet);
735                  t_singlet->Clear();                  t_singlet->Clear();
736          }          }
737            if(!SingletY)SingletY = new TClonesArray("TrkSinglet");
738          TClonesArray &sy = *SingletY;          TClonesArray &sy = *SingletY;
739          for(int i=0; i<l2->nclsy; i++){          for(int i=0; i<l2->nclsy; i++){
740                  t_singlet->plane    = l2->planey[i];                  t_singlet->plane    = l2->planey[i];
# Line 430  void TrkLevel2::SetFromLevel2Struct(cTrk Line 744  void TrkLevel2::SetFromLevel2Struct(cTrk
744                  //-----------------------------------------------------                  //-----------------------------------------------------
745  //              cout << "singolo y "<<i<<"  --  "<<  l2->clsy[i] <<endl;  //              cout << "singolo y "<<i<<"  --  "<<  l2->clsy[i] <<endl;
746                  t_singlet->cls      = l1->GetCluster(l2->clsy[i]-1);                  t_singlet->cls      = l1->GetCluster(l2->clsy[i]-1);
747    //              cout<<" i "<<i<<" l2->clsy[i] "<<l2->clsy[i]<< " l1->GetCluster(l2->clsy[i]-1) "<<l1->GetCluster(l2->clsy[i]-1)<<endl;          
748                  //-----------------------------------------------------                  //-----------------------------------------------------
749                  new(sy[i]) TrkSinglet(*t_singlet);                  new(sy[i]) TrkSinglet(*t_singlet);
750                  t_singlet->Clear();                  t_singlet->Clear();
# Line 445  void TrkLevel2::SetFromLevel2Struct(cTrk Line 760  void TrkLevel2::SetFromLevel2Struct(cTrk
760  void TrkLevel2::GetLevel2Struct(cTrkLevel2 *l2) const {  void TrkLevel2::GetLevel2Struct(cTrkLevel2 *l2) const {
761        
762  //  general variables  //  general variables
763      l2->good2 = good2 ;  //    l2->good2 = good2 ;
764      for(Int_t i=0; i<12 ; i++){      for(Int_t i=0; i<12 ; i++){
765          l2->crc[i] = crc[i];  //      l2->crc[i] = crc[i];
766                    l2->good[i] = good[i];
767      };      };
768  //  *** TRACKS ***  //  *** TRACKS ***
769    
770      l2->ntrk              =  Track->GetEntries();          if(Track){
771      for(Int_t i=0;i<l2->ntrk;i++){          l2->ntrk              =  Track->GetEntries();    
772        l2->image[i] = 1 + ((TrkTrack *)Track->At(i))->image;          for(Int_t i=0;i<l2->ntrk;i++){
773        l2->chi2_nt[i] =  ((TrkTrack *)Track->At(i))->chi2;              l2->image[i] = 1 + ((TrkTrack *)Track->At(i))->image;
774        for(int it1=0;it1<5;it1++){              l2->chi2_nt[i] =  ((TrkTrack *)Track->At(i))->chi2;
775          l2->al_nt[i][it1] = ((TrkTrack *)Track->At(i))->al[it1];              l2->nstep_nt[i] =  ((TrkTrack *)Track->At(i))->nstep;
776          for(int it2=0;it2<5;it2++)              for(int it1=0;it1<5;it1++){
777            l2->coval[i][it2][it1] = ((TrkTrack *)Track->At(i))->coval[it1][it2];                  l2->al_nt[i][it1] = ((TrkTrack *)Track->At(i))->al[it1];
778        };                  for(int it2=0;it2<5;it2++)
779        for(int ip=0;ip<6;ip++){                      l2->coval[i][it2][it1] = ((TrkTrack *)Track->At(i))->coval[it1][it2];
780          l2->xgood_nt[i][ip] = ((TrkTrack *)Track->At(i))->xgood[ip];              };
781          l2->ygood_nt[i][ip] = ((TrkTrack *)Track->At(i))->ygood[ip];              for(int ip=0;ip<6;ip++){
782          l2->xm_nt[i][ip]    = ((TrkTrack *)Track->At(i))->xm[ip];                  l2->xgood_nt[i][ip] = ((TrkTrack *)Track->At(i))->xgood[ip];
783          l2->ym_nt[i][ip]    = ((TrkTrack *)Track->At(i))->ym[ip];                  l2->ygood_nt[i][ip] = ((TrkTrack *)Track->At(i))->ygood[ip];
784          l2->zm_nt[i][ip]    = ((TrkTrack *)Track->At(i))->zm[ip];                  l2->xm_nt[i][ip]    = ((TrkTrack *)Track->At(i))->xm[ip];
785          l2->resx_nt[i][ip]  = ((TrkTrack *)Track->At(i))->resx[ip];                  l2->ym_nt[i][ip]    = ((TrkTrack *)Track->At(i))->ym[ip];
786          l2->resy_nt[i][ip]  = ((TrkTrack *)Track->At(i))->resy[ip];                  l2->zm_nt[i][ip]    = ((TrkTrack *)Track->At(i))->zm[ip];
787          l2->xv_nt[i][ip]    = ((TrkTrack *)Track->At(i))->xv[ip];                  l2->resx_nt[i][ip]  = ((TrkTrack *)Track->At(i))->resx[ip];
788          l2->yv_nt[i][ip]    = ((TrkTrack *)Track->At(i))->yv[ip];                  l2->resy_nt[i][ip]  = ((TrkTrack *)Track->At(i))->resy[ip];
789          l2->zv_nt[i][ip]    = ((TrkTrack *)Track->At(i))->zv[ip];                  l2->xv_nt[i][ip]    = ((TrkTrack *)Track->At(i))->xv[ip];
790          l2->axv_nt[i][ip]   = ((TrkTrack *)Track->At(i))->axv[ip];                  l2->yv_nt[i][ip]    = ((TrkTrack *)Track->At(i))->yv[ip];
791          l2->ayv_nt[i][ip]   = ((TrkTrack *)Track->At(i))->ayv[ip];                  l2->zv_nt[i][ip]    = ((TrkTrack *)Track->At(i))->zv[ip];
792          l2->dedx_x[i][ip]   = ((TrkTrack *)Track->At(i))->dedx_x[ip];                  l2->axv_nt[i][ip]   = ((TrkTrack *)Track->At(i))->axv[ip];
793          l2->dedx_y[i][ip]   = ((TrkTrack *)Track->At(i))->dedx_y[ip];                  l2->ayv_nt[i][ip]   = ((TrkTrack *)Track->At(i))->ayv[ip];
794        };                  l2->dedx_x[i][ip]   = ((TrkTrack *)Track->At(i))->dedx_x[ip];
795                    l2->dedx_y[i][ip]   = ((TrkTrack *)Track->At(i))->dedx_y[ip];
796                };
797            }
798      }      }
   
799  //  *** SINGLETS ***      //  *** SINGLETS ***    
800      l2->nclsx              = SingletX->GetEntries();      if(SingletX){
801      for(Int_t i=0;i<l2->nclsx;i++){          l2->nclsx              = SingletX->GetEntries();
802        l2->planex[i]  = ((TrkSinglet *)SingletX->At(i))->plane;          for(Int_t i=0;i<l2->nclsx;i++){
803        l2->xs[i][0]   = ((TrkSinglet *)SingletX->At(i))->coord[0];              l2->planex[i]  = ((TrkSinglet *)SingletX->At(i))->plane;
804        l2->xs[i][1]   = ((TrkSinglet *)SingletX->At(i))->coord[1];              l2->xs[i][0]   = ((TrkSinglet *)SingletX->At(i))->coord[0];
805        l2->signlxs[i] = ((TrkSinglet *)SingletX->At(i))->sgnl;              l2->xs[i][1]   = ((TrkSinglet *)SingletX->At(i))->coord[1];
806      }              l2->signlxs[i] = ((TrkSinglet *)SingletX->At(i))->sgnl;
807      l2->nclsy              = SingletY->GetEntries();          }
808      for(Int_t i=0;i<l2->nclsy;i++){      }
809        l2->planey[i]  = ((TrkSinglet *)SingletY->At(i))->plane;  
810        l2->ys[i][0]   = ((TrkSinglet *)SingletY->At(i))->coord[0];      if(SingletY){
811        l2->ys[i][1]   = ((TrkSinglet *)SingletY->At(i))->coord[1];          l2->nclsy              = SingletY->GetEntries();
812        l2->signlys[i] = ((TrkSinglet *)SingletY->At(i))->sgnl;          for(Int_t i=0;i<l2->nclsy;i++){
813                l2->planey[i]  = ((TrkSinglet *)SingletY->At(i))->plane;
814                l2->ys[i][0]   = ((TrkSinglet *)SingletY->At(i))->coord[0];
815                l2->ys[i][1]   = ((TrkSinglet *)SingletY->At(i))->coord[1];
816                l2->signlys[i] = ((TrkSinglet *)SingletY->At(i))->sgnl;
817            }
818      }      }
819  }  }
820  //--------------------------------------  //--------------------------------------
# Line 499  void TrkLevel2::GetLevel2Struct(cTrkLeve Line 822  void TrkLevel2::GetLevel2Struct(cTrkLeve
822  //  //
823  //--------------------------------------  //--------------------------------------
824  void TrkLevel2::Clear(){  void TrkLevel2::Clear(){
     good2    = -1;  
825      for(Int_t i=0; i<12 ; i++){      for(Int_t i=0; i<12 ; i++){
826          crc[i] = -1;          good[i] = -1;
827      };      };
828  /*    Track->RemoveAll();  //    if(Track)Track->Clear("C");
829      SingletX->RemoveAll();  //    if(SingletX)SingletX->Clear("C");
830      SingletY->RemoveAll();*/  //    if(SingletY)SingletY->Clear("C");
831          // modify to avoid memory leakage      if(Track)Track->Delete();
832          Track->Clear();      if(SingletX)SingletX->Delete();
833          SingletX->Clear();      if(SingletY)SingletY->Delete();
834          SingletY->Clear();  }
835    // //--------------------------------------
836    // //
837    // //
838    // //--------------------------------------
839    void TrkLevel2::Delete(){
840            
841    //    cout << "void TrkLevel2::Delete()"<<endl;
842        Clear();
843        if(Track)delete Track;
844        if(SingletX)delete SingletX;
845        if(SingletY)delete SingletY;
846    
847  }  }
848  //--------------------------------------  //--------------------------------------
849  //  //
# Line 519  void TrkLevel2::Clear(){ Line 853  void TrkLevel2::Clear(){
853   * 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).
854   * 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.
855   */   */
856  // TClonesArray *TrkLevel2::GetTracks(){  TRefArray *TrkLevel2::GetTracks_NFitSorted(){
 //      TClonesArray *sorted = GetTracks_NFitSorted();  
 //      return sorted;  
 // };  
857    
858  /*TClonesArray *TrkLevel2::GetTracks_Chi2Sorted(){      if(!Track)return 0;
859    
860      TClonesArray *sorted = new TClonesArray("TrkTrack");      TRefArray *sorted = new TRefArray();
861      TClonesArray &t = *Track;          
862      TClonesArray &ts = *sorted;      TClonesArray &t  = *Track;
863      int N=this->ntrk();  //    TClonesArray &ts = *PhysicalTrack;
864        int N = ntrk();
865      vector<int> m(N); for(int i=0; i<N; i++)m[i]=1;      vector<int> m(N); for(int i=0; i<N; i++)m[i]=1;
866    //      int m[50]; for(int i=0; i<N; i++)m[i]=1;
867            
868      int indo=0;      int indo=0;
869      int indi=0;      int indi=0;
870      while(N != 0){      while(N != 0){
871          float chi2ref=1000000;          int nfit =0;
872            float chi2ref = numeric_limits<float>::max();
873                    
874            // first loop to search maximum num. of fit points
875            for(int i=0; i < ntrk(); i++){
876                if( ((TrkTrack *)t[i])->GetNtot() >= nfit && m[i]==1){
877                    nfit =    ((TrkTrack *)t[i])->GetNtot();
878                }
879            }
880            //second loop to search minimum chi2 among selected
881          for(int i=0; i<this->ntrk(); i++){          for(int i=0; i<this->ntrk(); i++){
882              if(((TrkTrack *)t[i])->chi2 < chi2ref && m[i]==1){              Float_t chi2 = ((TrkTrack *)t[i])->chi2;
883                if(chi2 < 0) chi2 = chi2*1000;
884                if(    chi2 < chi2ref
885                       && ((TrkTrack *)t[i])->GetNtot() == nfit
886                       && m[i]==1){
887                  chi2ref = ((TrkTrack *)t[i])->chi2;                  chi2ref = ((TrkTrack *)t[i])->chi2;
888                  indi = i;                  indi = i;
889              }              };
890          }          };
891          if( ((TrkTrack *)t[indi])->image != -1 ){          if( ((TrkTrack *)t[indi])->HasImage() ){
892              m[((TrkTrack *)t[indi])->image] = 0;              m[((TrkTrack *)t[indi])->image] = 0;
893              N--;              N--;
894          }          
895          new(ts[indo]) TrkTrack(*(TrkTrack*)t[indi]);              //      cout << "i** "<< ((TrkTrack *)t[indi])->image << " " << nfiti <<" "<<chi2i<<endl;
896            };
897            sorted->Add( (TrkTrack*)t[indi] );      
898                    
899          m[indi] = 0;          m[indi] = 0;
900    //              cout << "SORTED "<< indo << " "<< indi << " "<< N << endl;
901          N--;              N--;    
902          indo++;          indo++;
903      }      }
904      return sorted;      m.clear();
 }*/  
 /*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(){  
 TRefArray *TrkLevel2::GetTracks_NFitSorted(){  
   
 //      cout << "GetTracks_NFitSorted(it): new TRefArray()"<< endl;  
 //      TClonesArray *sorted = new TClonesArray("TrkTrack");  
 //      TClonesArray &ts = *sorted;  
         TRefArray *sorted = new TRefArray();  
           
         TClonesArray &t  = *Track;  
 //    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( ((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++){  
                         Float_t chi2 = ((TrkTrack *)t[i])->chi2;  
                         if(chi2 < 0) chi2 = chi2*1000;  
                         if(    chi2 < chi2ref  
                                 && ((TrkTrack *)t[i])->GetNtot() == nfit  
                                 && m[i]==1){  
                                 chi2ref = ((TrkTrack *)t[i])->chi2;  
                                 indi = i;  
                         };  
                 };  
                 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]);  
 //              cout << "GetTracks_NFitSorted(it): Add("<<indo<<")"<< endl;  
                 sorted->Add( (TrkTrack*)t[indi] );        
                   
                 m[indi] = 0;  
 //              cout << "SORTED "<< indo << " "<< indi << " "<< N << endl;  
                 N--;      
                 indo++;  
         }  
         m.clear();  
905  //      cout << "GetTracks_NFitSorted(it): Done"<< endl;  //      cout << "GetTracks_NFitSorted(it): Done"<< endl;
906    
907          return sorted;      return sorted;
908  //    return PhysicalTrack;  //    return PhysicalTrack;
909  }  }
910  //--------------------------------------  //--------------------------------------
# Line 681  TrkTrack *TrkLevel2::GetStoredTrack(int Line 923  TrkTrack *TrkLevel2::GetStoredTrack(int
923          cout << "                Stored tracks ntrk() = "<< this->ntrk() << endl;          cout << "                Stored tracks ntrk() = "<< this->ntrk() << endl;
924          return 0;          return 0;
925      }      }
926        if(!Track){
927            cout << "TrkTrack *TrkLevel2::GetStoredTrack(int is) >> (TClonesArray*) Track ==0 "<<endl;
928        };
929      TClonesArray &t = *(Track);      TClonesArray &t = *(Track);
930      TrkTrack *track = (TrkTrack*)t[is];      TrkTrack *track = (TrkTrack*)t[is];
931      return track;      return track;
# Line 700  TrkSinglet *TrkLevel2::GetSingletX(int i Line 945  TrkSinglet *TrkLevel2::GetSingletX(int i
945                  cout << "                Stored x-singlets nclsx() = "<< this->nclsx() << endl;                  cout << "                Stored x-singlets nclsx() = "<< this->nclsx() << endl;
946                  return 0;                  return 0;
947          }          }
948            if(!SingletX)return 0;
949          TClonesArray &t = *(SingletX);          TClonesArray &t = *(SingletX);
950          TrkSinglet *singlet = (TrkSinglet*)t[is];          TrkSinglet *singlet = (TrkSinglet*)t[is];
951          return singlet;          return singlet;
# Line 719  TrkSinglet *TrkLevel2::GetSingletY(int i Line 965  TrkSinglet *TrkLevel2::GetSingletY(int i
965                  cout << "                Stored y-singlets nclsy() = "<< this->nclsx() << endl;                  cout << "                Stored y-singlets nclsy() = "<< this->nclsx() << endl;
966                  return 0;                  return 0;
967          }          }
968            if(!SingletY)return 0;
969          TClonesArray &t = *(SingletY);          TClonesArray &t = *(SingletY);
970          TrkSinglet *singlet = (TrkSinglet*)t[is];          TrkSinglet *singlet = (TrkSinglet*)t[is];
971          return singlet;          return singlet;
# Line 731  TrkSinglet *TrkLevel2::GetSingletY(int i Line 978  TrkSinglet *TrkLevel2::GetSingletY(int i
978   * Retrieves the it-th "physical" track, sorted by the method GetNTracks().   * Retrieves the it-th "physical" track, sorted by the method GetNTracks().
979   * @param it Track number, ranging from 0 to GetNTracks().   * @param it Track number, ranging from 0 to GetNTracks().
980   */   */
981  /*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;  
 }*/  
982  TrkTrack *TrkLevel2::GetTrack(int it){  TrkTrack *TrkLevel2::GetTrack(int it){
983            
984          if(it >= this->GetNTracks()){          if(it >= this->GetNTracks()){
# Line 755  TrkTrack *TrkLevel2::GetTrack(int it){ Line 988  TrkTrack *TrkLevel2::GetTrack(int it){
988          }          }
989                    
990          TRefArray *sorted = GetTracks();  //TEMPORANEO            TRefArray *sorted = GetTracks();  //TEMPORANEO  
991            if(!sorted)return 0;
992          TrkTrack *track = (TrkTrack*)sorted->At(it);          TrkTrack *track = (TrkTrack*)sorted->At(it);
993          sorted->Delete();          sorted->Clear();
994            delete sorted;
995          return track;          return track;
996  }  }
997  /**  /**
# Line 765  TrkTrack *TrkLevel2::GetTrack(int it){ Line 1000  TrkTrack *TrkLevel2::GetTrack(int it){
1000  Int_t TrkLevel2::GetNTracks(){  Int_t TrkLevel2::GetNTracks(){
1001                                    
1002          Float_t ntot=0;          Float_t ntot=0;
1003            if(!Track)return 0;
1004          TClonesArray &t = *Track;          TClonesArray &t = *Track;
1005          for(int i=0; i<ntrk(); i++) {          for(int i=0; i<ntrk(); i++) {    
1006                  if( ((TrkTrack *)t[i])->GetImageSeqNo() == -1 ) ntot+=1.;                  if( ((TrkTrack *)t[i])->GetImageSeqNo() == -1 ) ntot+=1.;
1007                  else ntot+=0.5;                  else ntot+=0.5;
1008          }          }
# Line 781  Int_t TrkLevel2::GetNTracks(){ Line 1017  Int_t TrkLevel2::GetNTracks(){
1017   * 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().
1018   * @param it Track number, ranging from 0 to GetNTracks().   * @param it Track number, ranging from 0 to GetNTracks().
1019   */   */
1020  /*TrkTrack *TrkLevel2::GetTrackImage(int it){  TrkTrack *TrkLevel2::GetTrackImage(int it){
1021    
1022      if(it >= this->GetNTracks()){      if(it >= this->GetNTracks()){
1023          cout << "** TrkLevel2 ** Track "<< it << "does not exits! " << endl;          cout << "** TrkLevel2 ** Track "<< it << "does not exits! " << endl;
# Line 789  Int_t TrkLevel2::GetNTracks(){ Line 1025  Int_t TrkLevel2::GetNTracks(){
1025          return 0;          return 0;
1026      }      }
1027                    
1028          TClonesArray* sorted = GetTracks();      TRefArray* sorted = GetTracks(); //TEMPORANEO
1029          TClonesArray &ts = *sorted;      if(!sorted)return 0;
1030          TrkTrack *track = (TrkTrack*)ts[it];      TrkTrack *track = (TrkTrack*)sorted->At(it);
1031  //    TrkTrack *track = (TrkTrack*)(*(this->GetTracks()))[it];          
1032            if(!track->HasImage()){
         if(!track->HasImage()){  
1033          cout << "** TrkLevel2 ** Track "<< it << "does not have image! " << endl;          cout << "** TrkLevel2 ** Track "<< it << "does not have image! " << endl;
1034          return 0;          return 0;
1035      }      }
1036        if(!Track)return 0;
1037      TrkTrack *image = (TrkTrack*)(*Track)[track->image];      TrkTrack *image = (TrkTrack*)(*Track)[track->image];
1038    
1039  //      GetTracks()->Delete(); ////TEMPORANEO      sorted->Delete();
1040          sorted->Delete(); ////TEMPORANEO      delete sorted;
           
     return image;  
       
 }*/  
 TrkTrack *TrkLevel2::GetTrackImage(int it){  
1041    
1042          if(it >= this->GetNTracks()){      return image;
                 cout << "** TrkLevel2 ** Track "<< it << "does not exits! " << endl;  
                 cout << "                Physical tracks GetNTracks() = "<< this->ntrk() << endl;  
                 return 0;  
         }  
           
         TRefArray* sorted = GetTracks(); //TEMPORANEO  
         TrkTrack *track = (TrkTrack*)sorted->At(it);  
           
         if(!track->HasImage()){  
                 cout << "** TrkLevel2 ** Track "<< it << "does not have image! " << endl;  
                 return 0;  
         }  
         TrkTrack *image = (TrkTrack*)(*Track)[track->image];  
   
         sorted->Delete();  
           
         return image;  
1043            
1044  }  }
1045  //--------------------------------------  //--------------------------------------
# Line 836  TrkTrack *TrkLevel2::GetTrackImage(int i Line 1050  TrkTrack *TrkLevel2::GetTrackImage(int i
1050   * Loads the magnetic field.   * Loads the magnetic field.
1051   * @param s Path of the magnetic-field files.   * @param s Path of the magnetic-field files.
1052   */   */
1053  void TrkLevel2::LoadField(TString s){  void TrkLevel2::LoadField(TString path){
1054      readb_(s.Data());  //
1055        strcpy(path_.path,path.Data());
1056        path_.pathlen = path.Length();
1057        path_.error   = 0;
1058        readb_();
1059    //
1060  };  };
1061  //--------------------------------------  //--------------------------------------
1062  //  //
# Line 935  Trajectory::Trajectory(int n, float* zin Line 1154  Trajectory::Trajectory(int n, float* zin
1154      tl = new float[npoint];      tl = new float[npoint];
1155      int i=0;      int i=0;
1156      do{      do{
1157                  x[i] = 0;          x[i] = 0;
1158                  y[i] = 0;          y[i] = 0;
1159                  z[i] = zin[i];          z[i] = zin[i];
1160                  thx[i] = 0;          thx[i] = 0;
1161                  thy[i] = 0;          thy[i] = 0;
1162                  tl[i] = 0;          tl[i] = 0;
1163                  i++;                      i++;            
1164      }while(zin[i-1] > zin[i] && i < npoint);      }while(zin[i-1] > zin[i] && i < npoint);
1165      npoint=i;      npoint=i;
1166      if(npoint != n)cout << "NB! Trajectory created with "<<npoint<<" points"<<endl;      if(npoint != n)cout << "NB! Trajectory created with "<<npoint<<" points"<<endl;
1167  }  }
1168    void Trajectory::Delete(){
1169        
1170        if(x) delete [] x;
1171        if(y) delete [] y;
1172        if(z) delete [] z;
1173        if(thx) delete [] thx;
1174        if(thy) delete [] thy;
1175        if(tl) delete [] tl;
1176    
1177    }
1178  //--------------------------------------  //--------------------------------------
1179  //  //
1180  //  //
# Line 984  float Trajectory::GetLength(int ifirst, Line 1213  float Trajectory::GetLength(int ifirst,
1213    
1214  }  }
1215    
1216    /**
1217     * Evaluates the trajectory in the apparatus associated to the track.
1218     * 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.  
1219     * @param t pointer to an object of the class Trajectory,
1220     * which z coordinates should be previously initialized by calling the proper constructor ( Trajectory::Trajectory(int n, float* zin) ).
1221     * @return error flag.
1222     */
1223    int Trajectory::DoTrack2(float* al){
1224    
1225        double *dxout   = new double[npoint];
1226        double *dyout   = new double[npoint];
1227        double *dthxout = new double[npoint];
1228        double *dthyout = new double[npoint];
1229        double *dtlout  = new double[npoint];
1230        double *dzin    = new double[npoint];
1231        double dal[5];
1232    
1233        int ifail = 0;
1234    
1235        for (int i=0; i<5; i++)      dal[i]  = (double)al[i];
1236        for (int i=0; i<npoint; i++) dzin[i] = (double)z[i];
1237    
1238        dotrack2_(&(npoint),dzin,dxout,dyout,dthxout,dthyout,dtlout,dal,&ifail);
1239        
1240        for (int i=0; i<npoint; i++){
1241            x[i]   = (float)*dxout++;
1242            y[i]   = (float)*dyout++;
1243            thx[i] = (float)*dthxout++;
1244            thy[i] = (float)*dthyout++;
1245            tl[i]  = (float)*dtlout++;
1246        }
1247    
1248        return ifail;
1249    };
1250    
1251  ClassImp(TrkLevel2);  ClassImp(TrkLevel2);
1252  ClassImp(TrkSinglet);  ClassImp(TrkSinglet);
1253  ClassImp(TrkTrack);  ClassImp(TrkTrack);

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.21

  ViewVC Help
Powered by ViewVC 1.1.23