/[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.2 by pam-fi, Thu Jun 1 09:03:09 2006 UTC revision 1.7 by pam-fi, Fri Jul 21 11:03:14 2006 UTC
# Line 18  extern "C" {     Line 18  extern "C" {    
18  //  //
19  //--------------------------------------  //--------------------------------------
20  TrkTrack::TrkTrack(){  TrkTrack::TrkTrack(){
21      image = 0;      seqno = -1;
22        image = -1;
23      chi2  = 0;      chi2  = 0;
24      for(int it1=0;it1<5;it1++){      for(int it1=0;it1<5;it1++){
25          al[it1] = 0;          al[it1] = 0;
# Line 47  TrkTrack::TrkTrack(){ Line 48  TrkTrack::TrkTrack(){
48  //  //
49  //--------------------------------------  //--------------------------------------
50  TrkTrack::TrkTrack(const TrkTrack& t){  TrkTrack::TrkTrack(const TrkTrack& t){
51        seqno = t.seqno;
52      image = t.image;      image = t.image;
53      chi2  = t.chi2;      chi2  = t.chi2;
54      for(int it1=0;it1<5;it1++){      for(int it1=0;it1<5;it1++){
# Line 238  TrkLevel2::TrkLevel2(){ Line 240  TrkLevel2::TrkLevel2(){
240      Track    = new TClonesArray("TrkTrack");      Track    = new TClonesArray("TrkTrack");
241      SingletX = new TClonesArray("TrkSinglet");      SingletX = new TClonesArray("TrkSinglet");
242      SingletY = new TClonesArray("TrkSinglet");      SingletY = new TClonesArray("TrkSinglet");
243    
244    //      PhysicalTrack = new TClonesArray("TrkTrack");
245            //sostituire con TRefArray... appena ho capito come si usa
246  }  }
247  //--------------------------------------  //--------------------------------------
248  //  //
# Line 265  void TrkLevel2::Dump(){ Line 270  void TrkLevel2::Dump(){
270  /**  /**
271   * 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).
272   */   */
273  void TrkLevel2::FillCommonVar(cTrkLevel2 *l2){  void TrkLevel2::SetFromLevel2Struct(cTrkLevel2 *l2){
274        //
275    //    Track    = new TClonesArray("TrkTrack");
276    //    SingletX = new TClonesArray("TrkSinglet");
277    //    SingletY = new TClonesArray("TrkSinglet");
278  //  temporary objects:  //  temporary objects:
279      TrkSinglet* t_singlet = new TrkSinglet();      TrkSinglet* t_singlet = new TrkSinglet();
280      TrkTrack*   t_track   = new TrkTrack();      TrkTrack*   t_track   = new TrkTrack();
# Line 277  void TrkLevel2::FillCommonVar(cTrkLevel2 Line 286  void TrkLevel2::FillCommonVar(cTrkLevel2
286  //  *** TRACKS ***  //  *** TRACKS ***
287      TClonesArray &t = *Track;      TClonesArray &t = *Track;
288      for(int i=0; i<l2->ntrk; i++){      for(int i=0; i<l2->ntrk; i++){
289            t_track->seqno = i;
290          t_track->image = l2->image[i]-1;          t_track->image = l2->image[i]-1;
291    //      cout << "track "<<i<<t_track->seqno << t_track->image<<endl;
292          t_track->chi2  = l2->chi2_nt[i];          t_track->chi2  = l2->chi2_nt[i];
293          for(int it1=0;it1<5;it1++){          for(int it1=0;it1<5;it1++){
294              t_track->al[it1] = l2->al_nt[i][it1];              t_track->al[it1] = l2->al_nt[i][it1];
# Line 322  void TrkLevel2::FillCommonVar(cTrkLevel2 Line 333  void TrkLevel2::FillCommonVar(cTrkLevel2
333          new(sy[i]) TrkSinglet(*t_singlet);          new(sy[i]) TrkSinglet(*t_singlet);
334          t_singlet->Clear();          t_singlet->Clear();
335          };          };
336            
337            delete t_track;
338            delete t_singlet;
339    }
340    /**
341     * Fills a struct cTrkLevel2 with values from a TrkLevel2 object (to put data into a F77 common).
342     */
343    
344    void TrkLevel2::GetLevel2Struct(cTrkLevel2 *l2) const {
345      
346    //  general variables
347        l2->good2 = good2 ;
348        for(Int_t i=0; i<12 ; i++){
349            l2->crc[i] = crc[i];
350        };
351    //  *** TRACKS ***
352    
353        l2->ntrk              =  Track->GetEntries();    
354        for(Int_t i=0;i<l2->ntrk;i++){
355          l2->image[i] = 1 + ((TrkTrack *)Track->At(i))->image;
356          l2->chi2_nt[i] =  ((TrkTrack *)Track->At(i))->chi2;
357          for(int it1=0;it1<5;it1++){
358            l2->al_nt[i][it1] = ((TrkTrack *)Track->At(i))->al[it1];
359            for(int it2=0;it2<5;it2++)
360              l2->coval[i][it2][it1] = ((TrkTrack *)Track->At(i))->coval[it1][it2];
361          };
362          for(int ip=0;ip<6;ip++){
363            l2->xgood_nt[i][ip] = ((TrkTrack *)Track->At(i))->xgood[ip];
364            l2->ygood_nt[i][ip] = ((TrkTrack *)Track->At(i))->ygood[ip];
365            l2->xm_nt[i][ip]    = ((TrkTrack *)Track->At(i))->xm[ip];
366            l2->ym_nt[i][ip]    = ((TrkTrack *)Track->At(i))->ym[ip];
367            l2->zm_nt[i][ip]    = ((TrkTrack *)Track->At(i))->zm[ip];
368            l2->resx_nt[i][ip]  = ((TrkTrack *)Track->At(i))->resx[ip];
369            l2->resy_nt[i][ip]  = ((TrkTrack *)Track->At(i))->resy[ip];
370            l2->xv_nt[i][ip]    = ((TrkTrack *)Track->At(i))->xv[ip];
371            l2->yv_nt[i][ip]    = ((TrkTrack *)Track->At(i))->yv[ip];
372            l2->zv_nt[i][ip]    = ((TrkTrack *)Track->At(i))->zv[ip];
373            l2->axv_nt[i][ip]   = ((TrkTrack *)Track->At(i))->axv[ip];
374            l2->ayv_nt[i][ip]   = ((TrkTrack *)Track->At(i))->ayv[ip];
375            l2->dedx_x[i][ip]   = ((TrkTrack *)Track->At(i))->dedx_x[ip];
376            l2->dedx_y[i][ip]   = ((TrkTrack *)Track->At(i))->dedx_y[ip];
377          };
378        }
379    
380    //  *** SINGLETS ***    
381        l2->nclsx              = SingletX->GetEntries();
382        for(Int_t i=0;i<l2->nclsx;i++){
383          l2->planex[i]  = ((TrkSinglet *)SingletX->At(i))->plane;
384          l2->xs[i][0]   = ((TrkSinglet *)SingletX->At(i))->coord[0];
385          l2->xs[i][1]   = ((TrkSinglet *)SingletX->At(i))->coord[1];
386          l2->signlxs[i] = ((TrkSinglet *)SingletX->At(i))->sgnl;
387        }
388        l2->nclsy              = SingletY->GetEntries();
389        for(Int_t i=0;i<l2->nclsy;i++){
390          l2->planey[i]  = ((TrkSinglet *)SingletY->At(i))->plane;
391          l2->ys[i][0]   = ((TrkSinglet *)SingletY->At(i))->coord[0];
392          l2->ys[i][1]   = ((TrkSinglet *)SingletY->At(i))->coord[1];
393          l2->signlys[i] = ((TrkSinglet *)SingletY->At(i))->sgnl;
394        }
395  }  }
396  //--------------------------------------  //--------------------------------------
397  //  //
# Line 332  void TrkLevel2::Clear(){ Line 402  void TrkLevel2::Clear(){
402      for(Int_t i=0; i<12 ; i++){      for(Int_t i=0; i<12 ; i++){
403          crc[i] = -1;          crc[i] = -1;
404      };      };
405      Track->RemoveAll();  /*    Track->RemoveAll();
406      SingletX->RemoveAll();      SingletX->RemoveAll();
407      SingletY->RemoveAll();      SingletY->RemoveAll();*/
408            // modify to avoid memory leakage
409            Track->Clear();
410            SingletX->Clear();
411            SingletY->Clear();
412  }  }
413  //--------------------------------------  //--------------------------------------
414  //  //
# Line 345  void TrkLevel2::Clear(){ Line 419  void TrkLevel2::Clear(){
419   * 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.
420   */   */
421  TClonesArray *TrkLevel2::GetTracks(){  TClonesArray *TrkLevel2::GetTracks(){
422        TClonesArray *sorted = GetTracks_NFitSorted();
423        return sorted;
424            
425            // fare di meglio...
426    /*      PhysicalTrack->Clear();
427            if(ntrk() > 0) GetTracks_NFitSorted();
428            return PhysicalTrack;*/
429    };
430    
431    /*TClonesArray *TrkLevel2::GetTracks_Chi2Sorted(){
432    
433      TClonesArray *sorted = new TClonesArray("TrkTrack");      TClonesArray *sorted = new TClonesArray("TrkTrack");
434      TClonesArray &t = *Track;      TClonesArray &t = *Track;
# Line 372  TClonesArray *TrkLevel2::GetTracks(){ Line 456  TClonesArray *TrkLevel2::GetTracks(){
456          indo++;          indo++;
457      }      }
458      return sorted;      return sorted;
459    }*/
460    TClonesArray *TrkLevel2::GetTracks_NFitSorted(){
461    
462            TClonesArray *sorted = new TClonesArray("TrkTrack");    
463        TClonesArray &t = *Track;
464            TClonesArray &ts = *sorted;
465    //    TClonesArray &ts = *PhysicalTrack;
466            int N=this->ntrk();
467        vector<int> m(N); for(int i=0; i<N; i++)m[i]=1;
468    
469        int indo=0;
470        int indi=0;
471        while(N != 0){
472            int nfit =0;
473            float chi2ref=1000000;
474            // first loop to search maximum num. of fit points
475            for(int i=0; i<this->ntrk(); i++){
476                if( ((TrkTrack *)t[i])->GetNtot() >= nfit && m[i]==1){
477                    nfit =    ((TrkTrack *)t[i])->GetNtot();
478    //              cout << "1** "<<i<< " " << nfit<<endl;
479                }
480            }
481            //second loop to search minimum chi2 among selected
482            for(int i=0; i<this->ntrk(); i++){
483                if(    ((TrkTrack *)t[i])->chi2 < chi2ref
484                    && ((TrkTrack *)t[i])->GetNtot()== nfit
485                    && m[i]==1){
486                    chi2ref = ((TrkTrack *)t[i])->chi2;
487                    indi = i;
488    //              cout << "2** "<<i<< " " << nfit <<" "<<chi2ref<<endl;
489                }
490            }
491            if( ((TrkTrack *)t[indi])->HasImage() ){
492                m[((TrkTrack *)t[indi])->image] = 0;
493                N--;
494    
495    //          Int_t nfiti=((TrkTrack *)t[((TrkTrack *)t[indi])->image  ])->GetNtot();
496    //          Float_t chi2i=((TrkTrack *)t[((TrkTrack *)t[indi])->image  ])->chi2;
497                    
498    //          cout << "i** "<< ((TrkTrack *)t[indi])->image << " " << nfiti <<" "<<chi2i<<endl;
499            }
500            new(ts[indo]) TrkTrack(*(TrkTrack*)t[indi]);
501            m[indi] = 0;
502            N--;    
503            indo++;
504        }
505        return sorted;
506    //    return PhysicalTrack;
507  }  }
508  //--------------------------------------  //--------------------------------------
509  //  //
# Line 398  TrkTrack *TrkLevel2::GetStoredTrack(int Line 530  TrkTrack *TrkLevel2::GetStoredTrack(int
530  //  //
531  //--------------------------------------  //--------------------------------------
532  /**  /**
533     * Retrieves the is-th stored X singlet.
534     * @param it Singlet number, ranging from 0 to nclsx().
535     */
536    TrkSinglet *TrkLevel2::GetSingletX(int is){
537    
538            if(is >= this->nclsx()){
539                    cout << "** TrkLevel2 ** Singlet "<< is << "doen not exits! " << endl;
540                    cout << "                Stored x-singlets nclsx() = "<< this->nclsx() << endl;
541                    return 0;
542            }
543            TClonesArray &t = *(SingletX);
544            TrkSinglet *singlet = (TrkSinglet*)t[is];
545            return singlet;
546    }
547    //--------------------------------------
548    //
549    //
550    //--------------------------------------
551    /**
552     * Retrieves the is-th stored Y singlet.
553     * @param it Singlet number, ranging from 0 to nclsx().
554     */
555    TrkSinglet *TrkLevel2::GetSingletY(int is){
556    
557            if(is >= this->nclsy()){
558                    cout << "** TrkLevel2 ** Singlet "<< is << "doen not exits! " << endl;
559                    cout << "                Stored y-singlets nclsy() = "<< this->nclsx() << endl;
560                    return 0;
561            }
562            TClonesArray &t = *(SingletY);
563            TrkSinglet *singlet = (TrkSinglet*)t[is];
564            return singlet;
565    }
566    //--------------------------------------
567    //
568    //
569    //--------------------------------------
570    /**
571   * Retrieves the it-th "physical" track, sorted by the method GetNTracks().   * Retrieves the it-th "physical" track, sorted by the method GetNTracks().
572   * @param it Track number, ranging from 0 to GetNTracks().   * @param it Track number, ranging from 0 to GetNTracks().
573   */   */
# Line 409  TrkTrack *TrkLevel2::GetTrack(int it){ Line 579  TrkTrack *TrkLevel2::GetTrack(int it){
579          return 0;          return 0;
580      }      }
581      TrkTrack *track = (TrkTrack*)(*(this->GetTracks()))[it];      TrkTrack *track = (TrkTrack*)(*(this->GetTracks()))[it];
582            GetTracks()->Delete();////TEMPORANEO
583      return track;      return track;
584  }  }
585    /**
586     * Give the number of "physical" tracks, sorted by the method GetTracks().
587     */
588    Int_t TrkLevel2::GetNTracks(){
589            Int_t ntot=0;
590            ntot = GetTracks()->GetEntries();
591            GetTracks()->Delete();////TEMPORANEO
592            return ntot;
593    };
594  //--------------------------------------  //--------------------------------------
595  //  //
596  //  //
# Line 432  TrkTrack *TrkLevel2::GetTrackImage(int i Line 612  TrkTrack *TrkLevel2::GetTrackImage(int i
612          return 0;          return 0;
613      }      }
614      TrkTrack *image = (TrkTrack*)(*Track)[track->image];      TrkTrack *image = (TrkTrack*)(*Track)[track->image];
615            GetTracks()->Delete(); ////TEMPORANEO
616      return image;      return image;
617            
618  }  }
# Line 451  void TrkLevel2::LoadField(TString s){ Line 632  void TrkLevel2::LoadField(TString s){
632  //  //
633  //--------------------------------------  //--------------------------------------
634  /**  /**
635     * Get tracker-plane (mechanical) z-coordinate
636     * @param plane_id plane index (1=TOP,2,3,4,5,6=BOTTOM)
637     */
638    Float_t TrkLevel2::GetZTrk(Int_t plane_id){
639            switch(plane_id){
640                    case 1: return ZTRK1;
641                    case 2: return ZTRK2;
642                    case 3: return ZTRK3;
643                    case 4: return ZTRK4;
644                    case 5: return ZTRK5;
645                    case 6: return ZTRK6;
646                    default: return 0.;
647            };
648    };
649    //--------------------------------------
650    //
651    //
652    //--------------------------------------
653    /**
654   * Trajectory default constructor.   * Trajectory default constructor.
655   * (By default is created with z-coordinates inside the tracking volume)   * (By default is created with z-coordinates inside the tracking volume)
656    */    */
# Line 462  Trajectory::Trajectory(){ Line 662  Trajectory::Trajectory(){
662      thx = new float[npoint];      thx = new float[npoint];
663      thy = new float[npoint];      thy = new float[npoint];
664      tl = new float[npoint];      tl = new float[npoint];
665      float dz = ((ZTRKUP)-(ZTRKDW))/(npoint-1);      float dz = ((ZTRK1)-(ZTRK6))/(npoint-1);
666      for(int i=0; i<npoint; i++){      for(int i=0; i<npoint; i++){
667          x[i] = 0;          x[i] = 0;
668          y[i] = 0;          y[i] = 0;
669          z[i] = (ZTRKUP) - i*dz;          z[i] = (ZTRK1) - i*dz;
670          thx[i] = 0;          thx[i] = 0;
671          thy[i] = 0;          thy[i] = 0;
672          tl[i] = 0;          tl[i] = 0;
# Line 493  Trajectory::Trajectory(int n){ Line 693  Trajectory::Trajectory(int n){
693      thx = new float[npoint];      thx = new float[npoint];
694      thy = new float[npoint];      thy = new float[npoint];
695      tl = new float[npoint];      tl = new float[npoint];
696      float dz = ((ZTRKUP)-(ZTRKDW))/(npoint-1);      float dz = ((ZTRK1)-(ZTRK6))/(npoint-1);
697      for(int i=0; i<npoint; i++){      for(int i=0; i<npoint; i++){
698          x[i] = 0;          x[i] = 0;
699          y[i] = 0;          y[i] = 0;
700          z[i] = (ZTRKUP) - i*dz;          z[i] = (ZTRK1) - i*dz;
701          thx[i] = 0;          thx[i] = 0;
702          thy[i] = 0;          thy[i] = 0;
703          tl[i] = 0;          tl[i] = 0;
# Line 571  float Trajectory::GetLength(int ifirst, Line 771  float Trajectory::GetLength(int ifirst,
771      return l;      return l;
772    
773  }  }
774    
775  ClassImp(TrkLevel2);  ClassImp(TrkLevel2);
776  ClassImp(TrkSinglet);  ClassImp(TrkSinglet);
777  ClassImp(TrkTrack);  ClassImp(TrkTrack);

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.7

  ViewVC Help
Powered by ViewVC 1.1.23