/[PAMELA software]/PamelaLevel2/src/PamLevel2.cpp
ViewVC logotype

Diff of /PamelaLevel2/src/PamLevel2.cpp

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

revision 1.54 by mocchiut, Fri Nov 9 09:20:25 2007 UTC revision 1.71 by mocchiut, Thu Dec 11 10:41:38 2008 UTC
# Line 284  PamTrack::PamTrack(){ Line 284  PamTrack::PamTrack(){
284      trk_track  = 0;      trk_track  = 0;
285      calo_track = 0;      calo_track = 0;
286      tof_track  = 0;      tof_track  = 0;
287        orb_track  = 0;
288      candeleteobj = 0;      candeleteobj = 0;
289      pscore = 0;      pscore = 0;
290      iscore = 0;      iscore = 0;
# Line 295  PamTrack::PamTrack(){ Line 296  PamTrack::PamTrack(){
296  /**  /**
297   * Constructor   * Constructor
298   */   */
299  PamTrack::PamTrack(TrkTrack* t, CaloTrkVar* c, ToFTrkVar* o){  PamTrack::PamTrack(TrkTrack* t, CaloTrkVar* c, ToFTrkVar* o, OrbitalInfoTrkVar *r){
300    
301      trk_track  = 0;      trk_track  = 0;
302      calo_track = 0;      calo_track = 0;
303      tof_track  = 0;      tof_track  = 0;
304        orb_track  = 0;
305  //     if(t)trk_track  = new TrkTrack(*t);  //     if(t)trk_track  = new TrkTrack(*t);
306  //     if(c)calo_track = new CaloTrkVar(*c);  //     if(c)calo_track = new CaloTrkVar(*c);
307  //     if(o)tof_track  = new ToFTrkVar(*o);  //     if(o)tof_track  = new ToFTrkVar(*o);
308      if(t)trk_track  = t;      if(t)trk_track  = t;
309      if(c)calo_track = c;      if(c)calo_track = c;
310      if(o)tof_track  = o;      if(o)tof_track  = o;
311      candeleteobj = 0;      if(r) orb_track  = r;
312    
313       candeleteobj = 0;
314    
315  };  };
316  PamTrack::PamTrack(const PamTrack& track){  PamTrack::PamTrack(const PamTrack& track){
# Line 314  PamTrack::PamTrack(const PamTrack& track Line 318  PamTrack::PamTrack(const PamTrack& track
318      TrkTrack   *t = track.trk_track;      TrkTrack   *t = track.trk_track;
319      CaloTrkVar *c = track.calo_track;      CaloTrkVar *c = track.calo_track;
320      ToFTrkVar  *o = track.tof_track;      ToFTrkVar  *o = track.tof_track;
321        OrbitalInfoTrkVar  *r = track.orb_track;
322    
323      trk_track  = 0;      trk_track  = 0;
324      calo_track = 0;      calo_track = 0;
325      tof_track  = 0;      tof_track  = 0;
326        orb_track  = 0;
327      if(t)trk_track  = new TrkTrack(*t);      if(t)trk_track  = new TrkTrack(*t);
328      if(c)calo_track = new CaloTrkVar(*c);      if(c)calo_track = new CaloTrkVar(*c);
329      if(o)tof_track  = new ToFTrkVar(*o);      if(o)tof_track  = new ToFTrkVar(*o);
330        if(r)orb_track  = new OrbitalInfoTrkVar(*r);
331      candeleteobj = 1;      candeleteobj = 1;
332            
333  }  }
# Line 331  void PamTrack::Clear(){ Line 338  void PamTrack::Clear(){
338          if(trk_track)  trk_track->TrkTrack::Clear();          if(trk_track)  trk_track->TrkTrack::Clear();
339          if(calo_track) calo_track->CaloTrkVar::Clear();//???          if(calo_track) calo_track->CaloTrkVar::Clear();//???
340          if(tof_track)  tof_track->ToFTrkVar::Clear();//???          if(tof_track)  tof_track->ToFTrkVar::Clear();//???
341            if(orb_track)  orb_track->OrbitalInfoTrkVar::Clear();//???
342      }else{      }else{
343          trk_track  = 0;          trk_track  = 0;
344          calo_track = 0;          calo_track = 0;
345          tof_track  = 0;          tof_track  = 0;
346            orb_track  = 0;
347      }      }
348      pscore = 0;      pscore = 0;
349      iscore = 0;      iscore = 0;
# Line 355  void PamTrack::Delete(){ Line 364  void PamTrack::Delete(){
364              tof_track->ToFTrkVar::Clear();//???              tof_track->ToFTrkVar::Clear();//???
365              delete tof_track;              delete tof_track;
366          }          }
367            if(orb_track){
368                orb_track->OrbitalInfoTrkVar::Clear();//???
369                delete orb_track;
370            }
371      }else{      }else{
372          Clear();          Clear();
373      }      }
# Line 367  void PamTrack::Delete(){ Line 380  void PamTrack::Delete(){
380   * Default Constructor   * Default Constructor
381   */   */
382  PamLevel2::PamLevel2(){  PamLevel2::PamLevel2(){
383    Initialize();      Initialize();
384  };  };
385    
386  /**  /**
# Line 385  PamLevel2::PamLevel2(){ Line 398  PamLevel2::PamLevel2(){
398   * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB   * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB
399   */   */
400  PamLevel2::PamLevel2(TString ddir,TString list,TString detlist){  PamLevel2::PamLevel2(TString ddir,TString list,TString detlist){
401    Initialize();      Initialize();
402    GetPamTree(GetListOfLevel2Files(ddir,list),detlist);      TList*  listf = GetListOfLevel2Files(ddir,list);
403    GetRunTree(GetListOfLevel2Files(ddir,list));      GetPamTree(listf,detlist);
404        GetRunTree(listf);
405  };  };
406    
407    PamLevel2::PamLevel2(TString ddir,TList *list,TString detlist){
408        Initialize();
409        GetPamTree(list,detlist);
410        GetRunTree(list);
411    };
412  /**  /**
413   * Constructor   * Constructor
414   * @param ddir Name of directory where level2 files are stored.   * @param ddir Name of directory where level2 files are stored.
# Line 398  PamLevel2::PamLevel2(TString ddir,TStrin Line 417  PamLevel2::PamLevel2(TString ddir,TStrin
417   * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB   * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB
418   */   */
419  PamLevel2::PamLevel2(TString ddir,TString list){  PamLevel2::PamLevel2(TString ddir,TString list){
420    Initialize();      Initialize();
421    GetPamTree(GetListOfLevel2Files(ddir,list),"");      TList*  listf = GetListOfLevel2Files(ddir,list);
422    GetRunTree(GetListOfLevel2Files(ddir,list));      GetPamTree(listf,"");
423        GetRunTree(listf);
424  };  };
425    
426    
# Line 426  void PamLevel2::Initialize(){ Line 446  void PamLevel2::Initialize(){
446      run_obj   = 0;//new GL_RUN();      run_obj   = 0;//new GL_RUN();
447      soft_obj   = 0;// Emiliano      soft_obj   = 0;// Emiliano
448      irun = -1LL;      irun = -1LL;
449        irunt = -1LL;
450      runfirstentry = 0LL;      runfirstentry = 0LL;
451      runlastentry = 0LL;      runlastentry = 0LL;
452    
# Line 448  void PamLevel2::Initialize(){ Line 469  void PamLevel2::Initialize(){
469    
470      totdltime[0] = 0LL;      totdltime[0] = 0LL;
471      totdltime[1] = 0LL;      totdltime[1] = 0LL;
472        totdltime[2] = 0LL;
473    
474      host = "mysql://localhost/pamelaprod";      host = "mysql://localhost/pamelaprod";
475      user = "anonymous";      user = "anonymous";
# Line 488  void PamLevel2::Initialize(){ Line 510  void PamLevel2::Initialize(){
510    
511      ISGP = false;      ISGP = false;
512    
513        DBG = false;
514    
515      tsorted=0;      tsorted=0;
516      timage=0;      timage=0;
517            
# Line 538  void PamLevel2::Delete(){ Line 562  void PamLevel2::Delete(){
562      if(l0_file)l0_file->Close();      if(l0_file)l0_file->Close();
563      //    if(pam_tree)pam_tree->Delete();;      //    if(pam_tree)pam_tree->Delete();;
564    
565    if ( pam_tree ){      if ( pam_tree ){
566      //          //
567      // we have first to find which chains we have to delete, then delete the main chain and only after delete the friend chains. Any other order causes a segfault...          // we have first to find which chains we have to delete, then delete the main chain and only after delete the friend chains. Any other order causes a segfault...
568      //          //
569      TList *temp = pam_tree->GetListOfFriends();          TList *temp = pam_tree->GetListOfFriends();
570      TList *contents  = new TList; // create chain friend list          TList *contents  = new TList; // create chain friend list
571      contents->SetOwner();          contents->SetOwner();
572      TIter next(temp);          TIter next(temp);
573      TChain *questo = 0;          TChain *questo = 0;
574      while ( (questo = (TChain*) next()) ){          while ( (questo = (TChain*) next()) ){
575        TString name =  questo->GetName();              TString name =  questo->GetName();
576        contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list              contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list
577      };          };
578      //          //
579      // deleting the main chain          // deleting the main chain
580      //          //
581      pam_tree->Delete();          pam_tree->Delete();
582      //          //
583      // deleting the friends...          // deleting the friends...
584      //          //
585      TIter next2(contents);          TIter next2(contents);
586      TChain *questa = 0;          TChain *questa = 0;
587      while ( questa = (TChain*)next2() ){          while ( questa = (TChain*)next2() ){
588        TString name =  questa->GetName();              TString name =  questa->GetName();
589        questa->Delete();                    questa->Delete();      
590        questa=NULL;              questa=NULL;
591            };
592            //
593      };      };
594      //      pam_tree = NULL;
   };  
   pam_tree = NULL;  
595    
596      if(run_tree)run_tree->Delete();;      if(run_tree)run_tree->Delete();;
597      if(sel_tree)sel_tree->Delete();;      if(sel_tree)sel_tree->Delete();;
# Line 575  void PamLevel2::Delete(){ Line 599  void PamLevel2::Delete(){
599      if(run_tree_clone)run_tree_clone->Delete();;      if(run_tree_clone)run_tree_clone->Delete();;
600      if(sel_tree_clone)sel_tree_clone->Delete();;      if(sel_tree_clone)sel_tree_clone->Delete();;
601            
602        if(irunoffset) delete [] irunoffset;
603    
604  };  };
605    
# Line 621  void PamLevel2::Clear(){ Line 646  void PamLevel2::Clear(){
646  };  };
647    
648  void PamLevel2::Reset(){  void PamLevel2::Reset(){
   //  
   // First of all clear everything  
   //  
   Clear();  
   //  
   // close and reset chains and pointers  
   //      
   if ( pam_tree ){  
649      //      //
650      // we have first to find which chains we have to delete, then delete the main chain and only after delete the friend chains. Any other order causes a segfault...      // First of all clear everything
651      //      //
652      TList *temp = pam_tree->GetListOfFriends();      Clear();
653      TList *contents  = new TList; // create chain friend list      //
654      contents->SetOwner();      // close and reset chains and pointers
655      TIter next(temp);      //    
656      TChain *questo = 0;      if ( pam_tree ){
657      while ( (questo = (TChain*) next()) ){          //
658        TString name =  questo->GetName();          // we have first to find which chains we have to delete, then delete the main chain and only after delete the friend chains. Any other order causes a segfault...
659        contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list          //
660            TList *temp = pam_tree->GetListOfFriends();
661            TList *contents  = new TList; // create chain friend list
662            contents->SetOwner();
663            TIter next(temp);
664            TChain *questo = 0;
665            while ( (questo = (TChain*) next()) ){
666                TString name =  questo->GetName();
667                contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list
668            };
669            //
670            // deleting the main chain
671            //
672            pam_tree->Delete();
673            //
674            // deleting the friends...
675            //
676            TIter next2(contents);
677            TChain *questa = 0;
678            while ( questa = (TChain*)next2() ){
679                TString name =  questa->GetName();
680                questa->Delete();      
681                questa=NULL;
682            };
683            //
684      };      };
685        pam_tree = NULL;
686      //      //
687      // deleting the main chain      if(run_tree)run_tree->Delete();;
688        run_tree = NULL;
689        if(sel_tree)sel_tree->Delete();;
690        sel_tree = NULL;
691      //      //
692      pam_tree->Delete();      // Close file
693      //      //
694      // deleting the friends...      if(l0_file)l0_file->Close("R");
695        l0_file = NULL;
696      //      //
697      TIter next2(contents);      h0_obj    = 0;
698      TChain *questa = 0;      trk0_obj  = 0;
699      while ( questa = (TChain*)next2() ){      calo0_obj  = 0;
700        TString name =  questa->GetName();      //
701        questa->Delete();            trk2_obj  = 0;
702        questa=NULL;      trk1_obj  = 0;
703      };      trkh_obj  = 0;
704        calo1_obj = 0;
705        calo2_obj = 0;
706        tof_obj   = 0;
707        trig_obj  = 0;
708        s4_obj    = 0;
709        nd_obj    = 0;
710        ac_obj    = 0;
711        orb_obj   = 0;
712        gp_obj    = 0;
713        //
714        // Reset run pointers
715        //
716        run_obj   = 0;//new GL_RUN();
717        soft_obj   = 0;// Emiliano
718        irun = -1;
719        irunt = -1;
720        runfirstentry = 0ULL;
721        runlastentry = 0ULL;    
722        //
723        totdltime[0] = 0LL;
724        totdltime[1] = 0LL;
725        totdltime[2] = 0LL;
726      //      //
   };  
   pam_tree = NULL;  
   //  
   if(run_tree)run_tree->Delete();;  
   run_tree = NULL;  
   if(sel_tree)sel_tree->Delete();;  
   sel_tree = NULL;  
   //  
   // Close file  
   //  
   if(l0_file)l0_file->Close("R");  
   l0_file = NULL;  
   //  
   h0_obj    = 0;  
   trk0_obj  = 0;  
   calo0_obj  = 0;  
   //  
   trk2_obj  = 0;  
   trk1_obj  = 0;  
   trkh_obj  = 0;  
   calo1_obj = 0;  
   calo2_obj = 0;  
   tof_obj   = 0;  
   trig_obj  = 0;  
   s4_obj    = 0;  
   nd_obj    = 0;  
   ac_obj    = 0;  
   orb_obj   = 0;  
   gp_obj    = 0;  
   //  
   // Reset run pointers  
   //  
   run_obj   = 0;//new GL_RUN();  
   soft_obj   = 0;// Emiliano  
   irun = -1;  
   runfirstentry = 0ULL;  
   runlastentry = 0ULL;      
   //  
   totdltime[0] = 0LL;  
   totdltime[1] = 0LL;  
   //  
727  };  };
728    
729  Bool_t PamLevel2::IsGood(){  Bool_t PamLevel2::IsGood(Bool_t strict){
730    Bool_t goodev=true;    Bool_t goodev=true;
731    //  if(trk2_obj && trk2_obj->UnpackError() != 0 ) goodev = false;    //
732    if(calo2_obj && calo2_obj->good != 1) goodev = false;    if(calo2_obj && !calo2_obj->IsGood(strict) ) goodev = false;
733    if(tof_obj && tof_obj->unpackError != 0) goodev = false;      //
734    if(trig_obj && trig_obj->unpackError != 0) goodev = false;    if ( strict ){
735    if(s4_obj && s4_obj->unpackError != 0) goodev = false;        if(trk2_obj && trk2_obj->UnpackError() != 0 ) goodev = false;
736    if(nd_obj && nd_obj->unpackError != 0) goodev = false;        if(tof_obj && tof_obj->unpackError != 0) goodev = false;  
737    if(ac_obj && ac_obj->unpackError != 255) goodev = false;        if(trig_obj && trig_obj->unpackError != 0) goodev = false;
738        if(s4_obj && s4_obj->unpackError != 0) goodev = false;  
739        if(nd_obj && nd_obj->unpackError != 0) goodev = false;  
740        if(ac_obj && (ac_obj->unpackError != 0 || ((ac_obj->status[0]>>3)&1) || ((ac_obj->status[0]>>3)&1)) ) goodev = false;      
741      //  if(orb_obj)        //  if(orb_obj)  
742    return goodev;    } else {
743        if(nd_obj && nd_obj->unpackError != 0) goodev = false;  
744        if(ac_obj && (ac_obj->unpackError != 0 || ((ac_obj->status[0]>>3)&1) || ((ac_obj->status[0]>>3)&1)) ) goodev = false;      
745      };
746      return(goodev);
747  };  };
748    
749  //--------------------------------------  //--------------------------------------
# Line 735  void *PamLevel2::GetPointerTo(const char Line 769  void *PamLevel2::GetPointerTo(const char
769          return &trk2_obj;          return &trk2_obj;
770      };      };
771      if(!objname.CompareTo("TrkHough"))   {      if(!objname.CompareTo("TrkHough"))   {
772          if(!trkh_obj)  trkh_obj  = new TrkHough();          if(!trkh_obj)  {
773                trkh_obj  = new TrkHough();
774                trkh_obj->Set();
775            }
776          return &trkh_obj;          return &trkh_obj;
777      };      };
778      if(!objname.CompareTo("CaloLevel1")) {      if(!objname.CompareTo("CaloLevel1")) {
# Line 772  void *PamLevel2::GetPointerTo(const char Line 809  void *PamLevel2::GetPointerTo(const char
809          if(!ac_obj)    ac_obj    = new AcLevel2();          if(!ac_obj)    ac_obj    = new AcLevel2();
810          return &ac_obj;          return &ac_obj;
811      };      };
812      if(!objname.CompareTo("OrbitalInfo")){      if(!objname.CompareTo("OrbitalInfo"))  {
813          if(!orb_obj)   orb_obj   = new OrbitalInfo();          if(!orb_obj){
814                orb_obj   = new OrbitalInfo();
815                orb_obj->Set();
816            }
817          return &orb_obj;          return &orb_obj;
818      };      };
819    //     if(!objname.CompareTo("OrbitalInfo")){
820    //      if(!orb_obj)   orb_obj   = new OrbitalInfo();
821    //      return &orb_obj;
822    //     };
823      if(!objname.CompareTo("GPamela")){      if(!objname.CompareTo("GPamela")){
824          if(!gp_obj)   gp_obj   = new GPamela();          if(!gp_obj)   gp_obj   = new GPamela();
825          return &gp_obj;          return &gp_obj;
# Line 795  void *PamLevel2::GetPointerTo(const char Line 839  void *PamLevel2::GetPointerTo(const char
839   * Retrieves the calorimeter track matching the seqno-th tracker stored track.   * Retrieves the calorimeter track matching the seqno-th tracker stored track.
840   * (If seqno = -1 retrieves the self-trigger calorimeter track)   * (If seqno = -1 retrieves the self-trigger calorimeter track)
841   */   */
842   CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){  CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){
843        
844        if( !calo2_obj )return 0;
845    
846        if( calo2_obj->CaloLevel2::ntrk()==0 ){
847            cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<<endl;
848            return NULL;
849        };
850        
851        CaloTrkVar *c = 0;
852        Int_t it_calo=0;
853        
854        do{
855            c = calo2_obj->CaloLevel2::GetCaloTrkVar(it_calo);
856            it_calo++;
857        } while( c && seqno != c->trkseqno && it_calo < calo2_obj->CaloLevel2::ntrk());    
858        
859        if(!c || seqno != c->trkseqno){
860            c = 0;
861            if(seqno!=-1)cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match Calorimeter stored tracks"<<endl;
862        };
863        return c;
864            
865       if( !calo2_obj )return 0;  };
866    //--------------------------------------
867    //
868    //
869    //--------------------------------------
870    /**
871     * Retrieves the ToF track matching the seqno-th tracker stored track.
872     * (If seqno = -1 retrieves the tracker-independent tof track)
873     */
874    ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){
875            
876        if( !tof_obj )return 0;
877    
878       if( calo2_obj->CaloLevel2::ntrk()==0 ){      if( tof_obj->ToFLevel2::ntrk()==0 ){
879           cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<<endl;          cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no ToF tracks are stored"<<endl;
880           return NULL;          return NULL;
881       };      };
882            
883       CaloTrkVar *c = 0;      ToFTrkVar *c = 0;
884       Int_t it_calo=0;      Int_t it_tof=0;
885            
886       do{      do{
887           c = calo2_obj->CaloLevel2::GetCaloTrkVar(it_calo);          c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);
888           it_calo++;          it_tof++;
889       } while( c && seqno != c->trkseqno && it_calo < calo2_obj->CaloLevel2::ntrk());          } while( c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());
890            
891       if(!c || seqno != c->trkseqno){      if(!c || seqno != c->trkseqno){
892           c = 0;          c = 0;
893           if(seqno!=-1)cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match Calorimeter stored tracks"<<endl;          if(seqno!=-1)cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match ToF stored tracks"<<endl;
894       };      };
895       return c;      return c;
896            
897   };  };
898    
899  //--------------------------------------  //--------------------------------------
900   //  //
901   //  //
902  //--------------------------------------  //--------------------------------------
903  /**  /**
904    * Retrieves the ToF track matching the seqno-th tracker stored track.   * Retrieves the OrbitalInfo track matching the seqno-th tracker stored track.
905    * (If seqno = -1 retrieves the tracker-independent tof track)   * (If seqno = -1 retrieves the tracker-independent tof related track)
906   */   */
907   ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){  OrbitalInfoTrkVar *PamLevel2::GetOrbitalInfoStoredTrack(int seqno){
908                    
909       if( !tof_obj )return 0;      if( !orb_obj )return 0;
910    
911    
912       if( tof_obj->ToFLevel2::ntrk()==0 ){      if( orb_obj->OrbitalInfo::ntrk()==0 ){
913           cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no ToF tracks are stored"<<endl;  //       // TRICK BEGIN
914           return NULL;  //       OrbitalInfoTrkVar  *r = new OrbitalInfoTrkVar(); // TEMPORARY TRICK
915       };  //       Int_t nn = 0;
916    //       TClonesArray &tor = *orb_obj->OrbitalInfoTrk;
917    //       for(Int_t nt=0; nt < tof_obj->ToFLevel2::ntrk(); nt++){  
918    //      //
919    //      ToFTrkVar *ptt = tof_obj->ToFLevel2::GetToFTrkVar(nt);
920    //      if ( ptt->trkseqno != -1  ){
921    //        //
922    //        r->trkseqno = ptt->trkseqno;
923    //        //
924    //        r->Eij = 0;  
925    //        //
926    //        r->Sij = 0;
927    //        //        
928    //        r->pitch = -1000.;
929    //        //
930    //        r->cutoff = -1000.;
931    //        //
932    //        new(tor[nn]) OrbitalInfoTrkVar(*r);
933    //        nn++;
934    //        //
935    //        r->Clear();
936    //        //
937    //      };
938    //       };
939    //       delete r;
940    //       OrbitalInfoTrkVar *c = 0;
941    //       c = orb_obj->OrbitalInfo::GetOrbitalInfoTrkVar(0);
942    //       return c;
943    //       //TRICK END
944          cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no OrbitalInfo tracks are stored"<<endl;
945          return NULL;
946        };
947            
948       ToFTrkVar *c = 0;      OrbitalInfoTrkVar *c = 0;
949       Int_t it_tof=0;      Int_t it_tof=0;
950            
951       do{      do{
952           c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);          c = orb_obj->OrbitalInfo::GetOrbitalInfoTrkVar(it_tof);
953           it_tof++;          it_tof++;
954       } while( c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());              } while( c && seqno != c->trkseqno && it_tof < orb_obj->OrbitalInfo::ntrk());      
955            
956       if(!c || seqno != c->trkseqno){      if(!c || seqno != c->trkseqno){
957           c = 0;          c = 0;
958           if(seqno!=-1)cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match ToF stored tracks"<<endl;          if(seqno!=-1)cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match OrbitalInfo stored tracks"<<endl;
959       };      };
960       return c;      return c;
961            
962   };  };
963    
964  //--------------------------------------  //--------------------------------------
965   //  //
966   //  //
967  //--------------------------------------  //--------------------------------------
968  /**  /**
969   * Give the pamela track associated to a tracker track, retrieving related calorimeter and tof track information.   * Give the pamela track associated to a tracker track, retrieving related calorimeter, orbitalinfo and tof track information.
970   */   */
971   PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){  PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){
972            
973       cout <<"PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** "<<endl;      cout <<"PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** "<<endl;
974       cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;      cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;
975    
976       CaloTrkVar *c = 0;      CaloTrkVar *c = 0;
977       ToFTrkVar  *o = 0;      ToFTrkVar  *o = 0;
978        OrbitalInfoTrkVar  *r = 0;
979            
980       if(CAL2) c = GetCaloStoredTrack(t->GetSeqNo());      if(CAL2) c = GetCaloStoredTrack(t->GetSeqNo());
981       if(TOF) o = GetToFStoredTrack(t->GetSeqNo());      if(TOF) o = GetToFStoredTrack(t->GetSeqNo());
982        if(ORB) r = GetOrbitalInfoStoredTrack(t->GetSeqNo());
983            
984  //    if(t && c && o)track = new PamTrack(t,c,o);  //    if(t && c && o)track = new PamTrack(t,c,o);
985       PamTrack *track = new PamTrack(t,c,o);      PamTrack *track = new PamTrack(t,c,o,r);
986            
987       return track;      return track;
988    
989   };  };
990  //--------------------------------------  //--------------------------------------
991  //  //
992  //  //
# Line 889  void *PamLevel2::GetPointerTo(const char Line 1000  void *PamLevel2::GetPointerTo(const char
1000  PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){  PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){
1001            
1002      cout <<"PamLevel2::GetStoredTrack(Int_t itrk) **to-be-updated** "<<endl;      cout <<"PamLevel2::GetStoredTrack(Int_t itrk) **to-be-updated** "<<endl;
1003      cout <<"for the moment, better use separately the methods: TrkLevel2::GetStoredTrack(seqno) CaloLevel2::GetCaloTrkVar(Int_t notrack) ToFLevel2::GetToFTrkVar(Int_t notrack)"<<endl;      cout <<"for the moment, better use separately the methods: TrkLevel2::GetStoredTrack(seqno) CaloLevel2::GetCaloTrkVar(Int_t notrack) ToFLevel2::GetToFTrkVar(Int_t notrack) OrbitalInfo::GetOrbitalInfoTrkVar(Int_t notrack)"<<endl;
1004      cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;      cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;
1005      PamTrack *track = 0;      PamTrack *track = 0;
1006            
# Line 911  PamTrack* PamLevel2::GetStoredTrack(Int_ Line 1022  PamTrack* PamLevel2::GetStoredTrack(Int_
1022  //  //
1023    
1024  /**  /**
1025   * Sort physical (tracker) tracks and stores them in the TRefArray (of TrkTrack objects) which pointer is  PamLevel2::sorted_tracks. Left here as backward compatibility method.   * Sort physical (tracker) tracks. Left here as backward compatibility method.
1026   **/   **/
1027  void PamLevel2::SortTracks(TString how){  void PamLevel2::SortTracks(TString how){
1028    printf(" WARNING! obsolete, use SortTracks() and SetSortingMethod(TString) instead! \n Setting sorting method to %s \n",how.Data());      printf(" WARNING! obsolete, use SortTracks() and SetSortingMethod(TString) instead! \n Setting sorting method to %s \n",how.Data());
1029    howtosort = how;        howtosort = how;  
1030    SortTracks();      SortTracks();
1031  };  };
1032    
1033  //  //
1034  //--------------------------------------  //--------------------------------------
1035  /**  /**
1036   * Sort physical (tracker) tracks and stores them in the TRefArray (of TrkTrack objects) which pointer is  PamLevel2::sorted_tracks.   * Sort physical (tracker) tracks.
1037   * @param how String to set the sorting cryterium (es: "CAL" or "TRK+CAL+TOF" ecc...).   * @param how String to set the sorting cryterium (es: "CAL" or "TRK+CAL+TOF" ecc...).
1038   * Sorting cryteria:   * Sorting cryteria:
1039   * TRK: lower chi**2   * TRK: lower chi**2
1040   * CAL: lower Y spatial residual on the first calorimeter plane   * CAL: lower Y spatial residual on the first calorimeter plane
1041   * TOF: bigger numebr of hit PMTs along the track, on S12 S21 S32 (where paddles are along the Y axis).   * TOF: bigger numebr of hit PMTs along the track, on S12 S21 S32 (where paddles are along the Y axis).
1042     * S1: (ask Emiliano)
1043     * S2: (ask Emiliano)
1044     * S3: (ask Emiliano)
1045     * GP: more GP hits
1046   * The default sorting cryterium is "TOF+CAL".   * The default sorting cryterium is "TOF+CAL".
1047   *   *
1048   * The total number of physical tracks is always given by GetNTracks() and the it-th physical track can be retrieved by means of the methods GetTrack(int it) and GetTrack(int it, TString how).   * The total number of physical tracks is always given by GetNTracks() and the it-th physical track can be retrieved by means of the methods GetTrack(int it) and GetTrack(int it, TString how).
1049   */   */
1050  void PamLevel2::SortTracks(){  void PamLevel2::SortTracks(){
1051    TString how = howtosort;      TString how = howtosort;
1052    
1053    //  cout <<" PamLevel2::SortTracks(TString how) "<<endl;      //  cout <<" PamLevel2::SortTracks(TString how) "<<endl;
1054    if( !trk2_obj ){      if( !trk2_obj ){
1055      cout << "void PamLevel2::SortTracks():  TrkLevel2 not loaded !!!";          cout << "void PamLevel2::SortTracks():  TrkLevel2 not loaded !!!";
1056      return;          return;
1057    };      };
1058    //    cout << "call SortTracs() "<<endl;      //Save current Object count
1059    //Save current Object count      Int_t ObjectNumber = TProcessID::GetObjectCount();
1060    Int_t ObjectNumber = TProcessID::GetObjectCount();  
1061        // create TCloneArrays to store tracks and its images
1062    //    cout << "ObjectNumber  "<<ObjectNumber <<endl;      if(!tsorted)tsorted = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
1063        tsorted->Delete();
1064    //     if(!sorted_tracks)sorted_tracks = new TRefArray();      TClonesArray &ttsorted = *tsorted;
1065    //     sorted_tracks->Clear();  
1066    //    sorted_tracks.Clear();      if(!timage)timage = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
1067        timage->Delete();
1068    if(!tsorted)tsorted = new TClonesArray("PamTrack",trk2_obj->GetNTracks());      TClonesArray &ttimage = *timage;
   tsorted->Delete();  
   TClonesArray &ttsorted = *tsorted;  
   if(!timage)timage = new TClonesArray("PamTrack",trk2_obj->GetNTracks());  
   timage->Delete();  
   TClonesArray &ttimage = *timage;  
1069    
1070    
1071    
1072    //--------------------------------------------------      //--------------------------------------------------
1073    // retrieve sorting method      // retrieve sorting method
1074    //--------------------------------------------------      //--------------------------------------------------
1075    Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);      Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
1076    Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);      Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
1077    Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);      Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
1078    Bool_t use_S1 = how.Contains("S1", TString::kIgnoreCase);      Bool_t use_S1 = how.Contains("S1", TString::kIgnoreCase);
1079    Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase);      Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase);
1080    Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase);      Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase);
1081        Bool_t use_GP = how.Contains("GP", TString::kIgnoreCase);
1082        
1083    if ( use_TOF ){      if ( use_TOF ){
1084      use_S1 = true;          use_S1 = true;
1085      use_S2 = true;          use_S2 = true;
1086      use_S3 = true;          use_S3 = true;
1087    };      };
1088    if( !CAL2 &&  use_CAL) use_CAL = false;      if( !CAL2 &&  use_CAL) use_CAL = false;
1089    if( !TOF ){      if( !TOF ){
1090      use_TOF = false;          use_TOF = false;
1091      use_S1  = false;          use_S1  = false;
1092      use_S2  = false;          use_S2  = false;
1093      use_S3  = false;          use_S3  = false;
1094    }      }
1095        if( !GP ){
1096    if( !TRK2 ){          use_GP  = false;
1097      //  cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;      }
1098      return;  
1099    };      if( !TRK2 ){
1100            cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;
1101            return;
1102        };
1103    
1104    //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;      //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;
1105        
1106    
1107    //--------------------------------------------------      //--------------------------------------------------
1108    // loop over "physical" tracks sorted by the tracker      // loop over "physical" tracks sorted by the tracker
1109    //--------------------------------------------------      //--------------------------------------------------
1110    for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){      for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){
1111                    
1112      TrkTrack   *ts = 0;          TrkTrack   *ts = 0;
1113      CaloTrkVar *cs = 0;          CaloTrkVar *cs = 0;
1114      ToFTrkVar  *os = 0;          ToFTrkVar  *os = 0;
1115                    OrbitalInfoTrkVar  *rs = 0;
1116      // get tracker tracks          
1117      TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker          // get tracker tracks
1118      CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());          TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker
1119      ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());          CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());
1120            ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());
1121      TrkTrack   *ti = 0; //tracker (image)          OrbitalInfoTrkVar  *rp = GetOrbitalInfoStoredTrack(tp->GetSeqNo());
1122      CaloTrkVar *ci = 0;  
1123      ToFTrkVar  *oi = 0;          TrkTrack   *ti = 0; //tracker (image)
1124      //  cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;          CaloTrkVar *ci = 0;
1125      // if track has an image, check image selection          ToFTrkVar  *oi = 0;
1126            OrbitalInfoTrkVar  *ri = 0;
1127      Int_t tp_score = 0;  //main track sorted by the tracker          //      cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
1128      Int_t ti_score = 0;  //image track          // if track has an image, check image selection
1129      Int_t totp_score = 0;  //main track sorted by the tracker  
1130      Int_t toti_score = 0;  //image track          Int_t tp_score = 0;  //main track sorted by the tracker
1131            Int_t ti_score = 0;  //image track
1132            Int_t totp_score = 0;  //main track sorted by the tracker
1133            Int_t toti_score = 0;  //image track
1134    
1135      if(tp->HasImage()){          if(tp->HasImage()){
1136                            
1137        ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image)              ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image)
1138        ci = GetCaloStoredTrack(ti->GetSeqNo());              ci = GetCaloStoredTrack(ti->GetSeqNo());
1139        oi = GetToFStoredTrack(ti->GetSeqNo());              oi = GetToFStoredTrack(ti->GetSeqNo());
1140                ri = GetOrbitalInfoStoredTrack(ti->GetSeqNo());
1141                            
1142        //            cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;              //      cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;
1143    
1144        //assign starting scores              //assign starting scores
1145        tp_score = 0;  //main track sorted by the tracker              tp_score = 0;  //main track sorted by the tracker
1146        ti_score = 0;  //image track              ti_score = 0;  //image track
1147                            
1148        // -----------------------------------------------------------------------------------------              // -----------------------------------------------------------------------------------------
1149        // calorimeter check              // *****************************************************************************************
1150        // -----------------------------------------------------------------------------------------              // -----------------------------------------------------------------------------------------
1151        // check the Y spatial residual on the first calorimeter plane              // calorimeter check
1152        // (cut on calorimeter variables from Emiliano)              // -----------------------------------------------------------------------------------------
1153        if( use_CAL && !calo2_obj ){              if( use_CAL && !calo2_obj ){
1154          cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but CaloLevel2 not loaded !!!";                  cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but CaloLevel2 not loaded !!!";
1155          return;                  return;
       };  
       if( use_CAL && !cp &&  ci ){  
         ti_score++;  
         toti_score++;  
       };  
       if( use_CAL &&  cp && !ci ){  
         tp_score++;  
         totp_score++;  
       };  
       if(  
          use_CAL            &&  
 //       calo2_obj->npcfit[1] > 5     &&   //no. of fit planes on Y view  
 //       calo2_obj->varcfit[1] < 1000. &&  //fit variance on Y view  
          cp && ci &&  
          true){  
   
                   
 //      Float_t resy_p = cp->tbar[0][1] - calo2_obj->cbar[0][1]; if(resy_p < 0)resy_p= - resy_p;  
 //      Float_t resy_i = ci->tbar[0][1] - calo2_obj->cbar[0][1]; if(resy_i < 0)resy_i= - resy_i;  
                   
 //      if(resy_p <= resy_i) tp_score++;  
 //      else                 ti_score++;  
           
   
         if( cp->npresh > ci->npresh){  
           tp_score++;  
           totp_score++;  
         };  
         if( cp->npresh < ci->npresh){  
           ti_score++;  
           toti_score++;  
         };  
   
         //      cout << "CALO "<<tp_score<<ti_score<<endl;  
   
       };  
       // -----------------------------------------------------------------------------------------  
       // TOF check  
       // -----------------------------------------------------------------------------------------  
       // check the number of hit pmts along the track  
       // on S12 S21 and S32, where paddles are parallel to Y axis  
       if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !tof_obj ){  
         cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but ToFLevel2 not loaded !!!";  
         return;  
       };  
       //  
       if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !op && oi ){  
         ti_score++;  
         toti_score++;  
       };  
       if( (use_TOF || use_S1 || use_S2 || use_S3 ) && op && !oi ){  
         tp_score++;  
         totp_score++;  
       };  
       if( (use_TOF || use_S1 || use_S2 || use_S3 ) && op && oi ){  
         //  
         Float_t sen = 0.;  
         for (Int_t ih=0; ih < op->npmtadc; ih++){  
           Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );  
           if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (op->dedx).At(ih);  
         };  
         for (Int_t ih=0; ih < oi->npmtadc; ih++){  
           Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );  
           if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (oi->dedx).At(ih);  
         };  
         //  
         if (  sen >= sortthr && false){ // temporary disabled NUCLEI special algorithm since the new one should work for every particle (to be checked!)  
           //printf(" IS A NUCLEUS! en = %f \n",sen);  
           //  
           // is a nucleus use a different algorithm  
           //  
           Int_t nz = 6; Float_t zin[6];                                          // << define TOF z-coordinates  
           for(Int_t ip=0; ip<nz; ip++)  
             zin[ip] = tof_obj->ToFLevel2::GetZTOF(tof_obj->ToFLevel2::GetToFPlaneID(ip));     // << read ToF plane z-coordinates  
           Trajectory *tr = new Trajectory(nz,zin);  
           //  
           Int_t nphit_p =0;  
           Int_t nphit_i =0;  
           Float_t enhit_p = 0.;  
           Float_t enhit_i = 0.;  
           //  
           for (Int_t ih=0; ih < op->npmtadc; ih++){  
             Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );  
             if(pl == 1 || pl == 2 || pl == 5){  
               nphit_p++;  
               enhit_p += (op->dedx).At(ih);  
             };  
           };  
           //  
           tp->DoTrack2(tr);  
           //  
           if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){  
             for (Int_t ih=0; ih < op->npmtadc; ih++){  
               Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );  
               if(pl == 0){  
                 nphit_p++;  
                 enhit_p += (op->dedx).At(ih);  
               };  
1156              };              };
1157            };              if( use_CAL && !cp &&  ci ){
1158            if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){                  ti_score++;
1159              for (Int_t ih=0; ih < op->npmtadc; ih++){                  toti_score++;
               Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );  
               if(pl == 3){  
                 nphit_p++;  
                 enhit_p += (op->dedx).At(ih);  
               };  
1160              };              };
1161            };              if( use_CAL &&  cp && !ci ){
1162            if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){                  tp_score++;
1163              for (Int_t ih=0; ih < op->npmtadc; ih++){                  totp_score++;
               Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );  
               if(pl == 4){  
                 nphit_p++;  
                 enhit_p += (op->dedx).At(ih);  
               };  
1164              };              };
1165            };              if(
1166                    use_CAL            &&
1167                    cp && ci &&
1168                    true){
1169    
1170                    
1171                    if(
1172                        cp->npresh > ci->npresh &&
1173                        true){
1174                        tp_score++;
1175                        totp_score++;
1176                    };
1177                    if(
1178                        cp->npresh < ci->npresh &&
1179                        true){
1180                        ti_score++;
1181                        toti_score++;
1182                    };
1183    
1184                    //      cout << "CALO "<<tp_score<<ti_score<<endl;
1185    
           for (Int_t ih=0; ih < oi->npmtadc; ih++){  
             Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );  
             if(pl == 1 || pl == 2 || pl == 5){  
               nphit_i++;          
               enhit_i += (op->dedx).At(ih);  
1186              };              };
1187            };              // -----------------------------------------------------------------------------------------
1188            //              // *****************************************************************************************
1189            ti->DoTrack2(tr);              // -----------------------------------------------------------------------------------------
1190            //              // TOF check
1191            if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){              // -----------------------------------------------------------------------------------------
1192              for (Int_t ih=0; ih < oi->npmtadc; ih++){              // check the number of hit pmts along the track
1193                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );              // on S12 S21 and S32, where paddles are parallel to Y axis
1194                if(pl == 0){              if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !tof_obj ){
1195                  nphit_i++;                  cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but ToFLevel2 not loaded !!!";
1196                  enhit_i += (op->dedx).At(ih);                  return;
               };  
1197              };              };
1198            };              //
1199            if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){              if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !op && oi ){
1200              for (Int_t ih=0; ih < oi->npmtadc; ih++){                  ti_score++;
1201                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );                  toti_score++;
               if(pl == 3){  
                 nphit_i++;  
                 enhit_i += (op->dedx).At(ih);  
               };  
1202              };              };
1203            };              if( (use_TOF || use_S1 || use_S2 || use_S3 ) && op && !oi ){
1204            if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){                  tp_score++;
1205              for (Int_t ih=0; ih < oi->npmtadc; ih++){                  totp_score++;
               Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );  
               if(pl == 4){  
                 nphit_i++;  
                 enhit_i += (op->dedx).At(ih);  
               };  
1206              };              };
1207            };                          if( (use_TOF || use_S1 || use_S2 || use_S3 ) && op && oi ){
1208                    //
1209                    Float_t sen = 0.;
1210                    for (Int_t ih=0; ih < op->npmtadc; ih++){
1211                        Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1212                        if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (op->dedx).At(ih);
1213                    };
1214                    for (Int_t ih=0; ih < oi->npmtadc; ih++){
1215                        Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1216                        if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (oi->dedx).At(ih);
1217                    };
1218                    //
1219                    if (  sen >= sortthr && false){ // temporary disabled NUCLEI special algorithm since the new one should work for every particle (to be checked!)
1220                        //printf(" IS A NUCLEUS! en = %f \n",sen);
1221                        //
1222                        // is a nucleus use a different algorithm
1223                        //
1224                        Int_t nz = 6; Float_t zin[6];                                          // << define TOF z-coordinates
1225                        for(Int_t ip=0; ip<nz; ip++)
1226                            zin[ip] = tof_obj->ToFLevel2::GetZTOF(tof_obj->ToFLevel2::GetToFPlaneID(ip));     // << read ToF plane z-coordinates
1227                        Trajectory *tr = new Trajectory(nz,zin);
1228                        //
1229                        Int_t nphit_p =0;
1230                        Int_t nphit_i =0;
1231                        Float_t enhit_p = 0.;
1232                        Float_t enhit_i = 0.;
1233                        //
1234                        for (Int_t ih=0; ih < op->npmtadc; ih++){
1235                            Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1236                            if(pl == 1 || pl == 2 || pl == 5){
1237                                nphit_p++;
1238                                enhit_p += (op->dedx).At(ih);
1239                            };
1240                        };
1241                        //
1242                        tp->DoTrack2(tr);
1243                        //
1244                        if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){
1245                            for (Int_t ih=0; ih < op->npmtadc; ih++){
1246                                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1247                                if(pl == 0){
1248                                    nphit_p++;
1249                                    enhit_p += (op->dedx).At(ih);
1250                                };
1251                            };
1252                        };
1253                        if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){
1254                            for (Int_t ih=0; ih < op->npmtadc; ih++){
1255                                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1256                                if(pl == 3){
1257                                    nphit_p++;
1258                                    enhit_p += (op->dedx).At(ih);
1259                                };
1260                            };
1261                        };
1262                        if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
1263                            for (Int_t ih=0; ih < op->npmtadc; ih++){
1264                                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1265                                if(pl == 4){
1266                                    nphit_p++;
1267                                    enhit_p += (op->dedx).At(ih);
1268                                };
1269                            };
1270                        };
1271    
1272                        for (Int_t ih=0; ih < oi->npmtadc; ih++){
1273                            Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1274                            if(pl == 1 || pl == 2 || pl == 5){
1275                                nphit_i++;  
1276                                enhit_i += (op->dedx).At(ih);
1277                            };
1278                        };
1279                        //
1280                        ti->DoTrack2(tr);
1281                        //
1282                        if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){
1283                            for (Int_t ih=0; ih < oi->npmtadc; ih++){
1284                                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1285                                if(pl == 0){
1286                                    nphit_i++;
1287                                    enhit_i += (op->dedx).At(ih);
1288                                };
1289                            };
1290                        };
1291                        if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){
1292                            for (Int_t ih=0; ih < oi->npmtadc; ih++){
1293                                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1294                                if(pl == 3){
1295                                    nphit_i++;
1296                                    enhit_i += (op->dedx).At(ih);
1297                                };
1298                            };
1299                        };
1300                        if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
1301                            for (Int_t ih=0; ih < oi->npmtadc; ih++){
1302                                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1303                                if(pl == 4){
1304                                    nphit_i++;
1305                                    enhit_i += (op->dedx).At(ih);
1306                                };
1307                            };
1308                        };          
1309    
1310                                    
1311            if(                      if(
1312               (use_TOF || use_S1 || use_S2 || use_S3)            &&                          (use_TOF || use_S1 || use_S2 || use_S3)            &&
1313               (nphit_p+nphit_i) !=0 &&                            (nphit_p+nphit_i) !=0 &&        
1314               true){                          true){
1315                                            
1316              //      printf(" seqno %i nphit_p %i nphit_i %i enhit_p %f enhit_i %f \n",trk2_obj->TrkLevel2::GetSeqNo(i),nphit_p,nphit_i,enhit_p,enhit_i);                          //          printf(" seqno %i nphit_p %i nphit_i %i enhit_p %f enhit_i %f \n",trk2_obj->TrkLevel2::GetSeqNo(i),nphit_p,nphit_i,enhit_p,enhit_i);
1317              //      printf(" score p %i score i %i \n",tp_score,ti_score);                          //          printf(" score p %i score i %i \n",tp_score,ti_score);
1318              //            if( enhit_p > enhit_i ) tp_score++;                          //                if( enhit_p > enhit_i ) tp_score++;
1319              //            if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;                          //                if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;
1320              if ( nphit_p > nphit_i ) tp_score++;                          if ( nphit_p > nphit_i ) tp_score++;
1321              if ( nphit_p < nphit_i ) ti_score++;                          if ( nphit_p < nphit_i ) ti_score++;
1322              if ( nphit_p == nphit_i ){                          if ( nphit_p == nphit_i ){
1323                if ( enhit_p > enhit_i ) tp_score++;                              if ( enhit_p > enhit_i ) tp_score++;
1324                else ti_score++;                              else ti_score++;
1325              };                          };
1326              //      printf(" dopo score p %i score i %i \n",tp_score,ti_score);                          //          printf(" dopo score p %i score i %i \n",tp_score,ti_score);
1327            };                      };
1328            delete tr;                      delete tr;
1329            //                      //
1330          } else {                  } else {
1331            //                      // -------------
1332            // NOT a NUCLEUS                      // NOT a NUCLEUS
1333            //                      // -------------
1334            //printf(" NOT a NUCLEUS! en = %f \n",sen);                      //printf(" NOT a NUCLEUS! en = %f \n",sen);
1335    
1336            Int_t nphit_p =0;                      Int_t nphit_p =0;
1337            Int_t nphit_i =0;                      Int_t nphit_i =0;
1338                                    
1339                                    
1340            /*                            cout << "track: npmtadc "<< op->npmtadc << endl;                      /*                          cout << "track: npmtadc "<< op->npmtadc << endl;
1341              cout << "track: npmttdc "<< op->npmttdc << endl;                                                  cout << "track: npmttdc "<< op->npmttdc << endl;
1342              cout << "image: npmtadc "<< oi->npmtadc << endl;                                                  cout << "image: npmtadc "<< oi->npmtadc << endl;
1343              cout << "image: npmttdc "<< oi->npmttdc << endl;*/                                                  cout << "image: npmttdc "<< oi->npmttdc << endl;*/
1344                                    
1345  //        for (Int_t ih=0; ih < op->npmtadc; ih++){  //        for (Int_t ih=0; ih < op->npmtadc; ih++){
1346  //          Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );  //          Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
# Line 1236  void PamLevel2::SortTracks(){ Line 1351  void PamLevel2::SortTracks(){
1351  //          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );  //          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1352  //          if(pl == 1 || pl == 2 || pl == 5)nphit_i++;  //          if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
1353  //        };  //        };
1354            // --- modified to count tdc signals (more efficient?)                      // --- modified to count tdc signals (more efficient?)
1355            // --- and to implement check on tdcflag                      // --- and to implement check on tdcflag
1356            for (Int_t ih=0; ih < op->npmttdc; ih++){                      for (Int_t ih=0; ih < op->npmttdc; ih++){
1357              Int_t pl = tof_obj->GetPlaneIndex( (op->pmttdc).At(ih) );                          Int_t pl = tof_obj->GetPlaneIndex( (op->pmttdc).At(ih) );
1358  //          if( (op->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_p++;  //          if( (op->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_p++;
1359              if ( (use_S1 && ( pl == 0 || pl == 1 )) || (use_S2 && ( pl == 2 || pl == 3 )) || (use_S3 && ( pl == 4 || pl == 5 )) ){                          if ( (use_S1 && ( pl == 0 || pl == 1 )) || (use_S2 && ( pl == 2 || pl == 3 )) || (use_S3 && ( pl == 4 || pl == 5 )) ){
1360                if( (op->tdcflag).At(ih)==0 )nphit_p++;                              if( (op->tdcflag).At(ih)==0 )nphit_p++;
1361              };                          };
1362            };                      };
1363                                    
1364            for (Int_t ih=0; ih < oi->npmttdc; ih++){                      for (Int_t ih=0; ih < oi->npmttdc; ih++){
1365              Int_t pl = tof_obj->GetPlaneIndex( (oi->pmttdc).At(ih) );                          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmttdc).At(ih) );
1366  //          if( (oi->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_i++;    //          if( (oi->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_i++;  
1367              if ( (use_S1 && ( pl == 0 || pl == 1 )) || (use_S2 && ( pl == 2 || pl == 3 )) || (use_S3 && ( pl == 4 || pl == 5 )) ){                          if ( (use_S1 && ( pl == 0 || pl == 1 )) || (use_S2 && ( pl == 2 || pl == 3 )) || (use_S3 && ( pl == 4 || pl == 5 )) ){
1368                if( (oi->tdcflag).At(ih)==0 )nphit_i++;                                if( (oi->tdcflag).At(ih)==0 )nphit_i++;    
1369              };                          };
1370            };                      };
1371                                    
1372            if(                      if(
1373               (nphit_p+nphit_i) !=0 &&                            (nphit_p+nphit_i) !=0 &&        
1374               true){                          true){
1375                                            
1376              if ( nphit_p != nphit_i ){                          if ( nphit_p != nphit_i ){
1377                totp_score += nphit_p;                              totp_score += nphit_p;
1378                toti_score += nphit_i;                              toti_score += nphit_i;
1379                tp_score+=nphit_p;                              tp_score+=nphit_p;
1380                ti_score+=nphit_i;                              ti_score+=nphit_i;
1381                            };
1382                            //          if     ( nphit_p > nphit_i) tp_score+=nphit_p;
1383                            //          else if( nphit_p < nphit_i) ti_score+=nphit_i;
1384                            //          else ;//niente
1385                        };
1386                    };
1387                    //      cout << "TOF "<<tp_score<<ti_score<<endl;
1388              };              };
             //      if     ( nphit_p > nphit_i) tp_score+=nphit_p;  
             //      else if( nphit_p < nphit_i) ti_score+=nphit_i;  
             //      else ;//niente  
           };  
         };  
         //      cout << "TOF "<<tp_score<<ti_score<<endl;  
       };  
1389    
1390    
1391  //      if(tp_score == ti_score) use_TRK = true;  //      if(tp_score == ti_score) use_TRK = true;
1392    
1393    
1394        // -----------------------------------------------------------------------------------------              // -----------------------------------------------------------------------------------------
1395        // tracker check              // *****************************************************************************************
1396        // -----------------------------------------------------------------------------------------              // -----------------------------------------------------------------------------------------
1397        // chi**2 difference is not always large enough to distinguish among              // tracker check
1398        // the real track and its image.              // -----------------------------------------------------------------------------------------
1399        // Tracker check will be applied always when calorimeter and tof information is ambiguous.              // chi**2 difference is not always large enough to distinguish among
1400        // *** MODIFIED ON AUGUST 2007 ***              // the real track and its image.
1401        if(use_TRK){              // Tracker check will be applied always when calorimeter and tof information is ambiguous.
1402                // *** MODIFIED ON AUGUST 2007 ***
1403                if(use_TRK){
1404  //      if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;  //      if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
1405  //      else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;  //      else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
1406    
1407            // CHECK 1 : number of points along X                    // CHECK 1 : number of points along X  
1408          if ( tp->GetNX() >= ti->GetNX() ){                  if ( tp->GetNX() >= ti->GetNX() ){
1409            tp_score++ ;                      tp_score++ ;
1410            totp_score++ ;                      totp_score++ ;
1411          };                  };
1412          if ( tp->GetNX() <= ti->GetNX() ){                  if ( tp->GetNX() <= ti->GetNX() ){
1413            ti_score++ ;                      ti_score++ ;
1414            toti_score++ ;                      toti_score++ ;
1415          };                  };
1416            // CHECK 2 : number of points along Y                    // CHECK 2 : number of points along Y  
1417          if ( tp->GetNY() >= ti->GetNY() ){                  if ( tp->GetNY() >= ti->GetNY() ){
1418            tp_score++ ;                      tp_score++ ;
1419            totp_score++ ;                      totp_score++ ;
1420          };                  };
1421          if ( tp->GetNY() <= ti->GetNY() ){                  if ( tp->GetNY() <= ti->GetNY() ){
1422            ti_score++ ;                      ti_score++ ;
1423            toti_score++ ;                      toti_score++ ;
1424          };                  };
           // CHECK 3 : chi**2 along X    
 //        if(      tp->GetChi2X() > 0 && (tp->GetChi2X() < ti->GetChi2X() || ti->GetChi2X() <=0) ) tp_score++ ;  
 //        if(      ti->GetChi2X() > 0 && (ti->GetChi2X() < tp->GetChi2X() || tp->GetChi2X() <=0) ) ti_score++ ;  
           // CHECK 4 : chi**2 along Y    
 //        if(      tp->GetChi2Y() > 0 && (tp->GetChi2Y() < ti->GetChi2Y() || ti->GetChi2Y() <=0) ) tp_score++ ;  
 //        if(      ti->GetChi2Y() > 0 && (ti->GetChi2Y() < tp->GetChi2Y() || tp->GetChi2Y() <=0) ) ti_score++ ;  
           // CHECK 5 : total chi**2    
 //        if(      tp->chi2 > 0 && (tp->chi2 < ti->chi2 || ti->chi2 <=0) ) tp_score++ ;  
 //        if(      ti->chi2 > 0 && (ti->chi2 < tp->chi2 || tp->chi2 <=0) ) ti_score++ ;  
1425    
1426          //      cout << "TRK "<<tp_score<<ti_score<<endl;                  //      cout << "TRK "<<tp_score<<ti_score<<endl;
1427        };              };
1428                            
1429    
1430                // -----------------------------------------------------------------------------------------
1431                // *****************************************************************************************
1432                // -----------------------------------------------------------------------------------------
1433                // GPamela check
1434                // -----------------------------------------------------------------------------------------
1435                
1436                //---------------------------------------------------
1437                // count the number of GP hits
1438                //---------------------------------------------------
1439                if(use_GP){
1440                    int ngphits_p=0;
1441                    int ngphits_i=0;
1442                    float toll = 0.02; //200 micron
1443                    for(int ih=0; ih<GetGPamela()->Nthspe; ih++){
1444                        int ip = (Int_t) GetGPamela()->Itrpb[ih] - 1;
1445                        if(
1446                            tp &&
1447                            tp->YGood(ip) &&
1448                            fabs(tp->ym[ip]- GetGPamela()->Yavspe[ih])<toll &&
1449                            true) ngphits_p++;
1450                        if( ti &&
1451                            ti->YGood(ip) &&
1452                            fabs(ti->ym[ip]- GetGPamela()->Yavspe[ih])<toll &&
1453                            true) ngphits_i++;
1454                    }
1455                    if(
1456                        ngphits_p > ngphits_i &&
1457                        true){
1458                        tp_score++ ;
1459                        totp_score++ ;                  
1460                    }
1461                    if(
1462                        ngphits_p < ngphits_i &&
1463                        true){
1464                        ti_score++ ;
1465                        toti_score++ ;                  
1466                    }
1467                }
1468    
       // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*  
       // the winner is....  
       // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*  
       if      (tp_score > ti_score) {  
           
   
       }else if (tp_score < ti_score) {  
1469    
1470                // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1471                // the winner is....
1472                // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1473                if      (tp_score > ti_score) {
1474            
1475    
1476          ts = ti;//its image!!              }else if (tp_score < ti_score) {
         cs = ci;  
         os = oi;  
         Int_t totis = toti_score;  
1477    
         ti = tp;//its image!!  
         ci = cp;  
         oi = op;  
1478    
1479          tp = ts;//its image!!                  ts = ti;//its image!!
1480          cp = cs;                  cs = ci;
1481          op = os;                  os = oi;
1482                    rs = ri;
1483                    Int_t totis = toti_score;
1484    
1485                    ti = tp;//its image!!
1486                    ci = cp;
1487                    oi = op;
1488                    ri = rp;
1489    
1490                    tp = ts;//its image!!
1491                    cp = cs;
1492                    op = os;
1493                    rp = rs;
1494    
1495          toti_score = totp_score;                  toti_score = totp_score;
1496          totp_score = totis;                  totp_score = totis;
1497    
1498                                    
1499        }else {              }else {
1500    
1501  //      cout << "Warning - track image ambiguity not solved" << endl;  //      cout << "Warning - track image ambiguity not solved" << endl;
1502    
1503        };              };
1504                            
1505      }else{          }else{
1506        totp_score = 1;              totp_score = 1;
1507        toti_score = 0;              toti_score = 0;
1508                
1509        //            ts = tp;              //      ts = tp;
1510        //            cs = cp;              //      cs = cp;
1511        //            os = op;              //      os = op;
1512      };          };
1513                    
1514      //  cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;          //      cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
1515      //  sorted_tracks->Add(ts);//save the track in the sorted array          //      sorted_tracks->Add(ts);//save the track in the sorted array
1516      //  sorted_tracks.Add(ts);//save the track in the sorted array          //      sorted_tracks.Add(ts);//save the track in the sorted array
1517      //  sorted_tracks.Add(tp);//save the track in the sorted array          //      sorted_tracks.Add(tp);//save the track in the sorted array
1518      //  cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;          //      cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
1519      //  cout<<"o "<<tp<<endl;          //      cout<<"o "<<tp<<endl;
1520      //  cout<<"o "<<cp<<endl;          //      cout<<"o "<<cp<<endl;
1521      //  cout<<"o "<<op<<endl;          //      cout<<"o "<<op<<endl;
1522    
1523      new(ttsorted[i]) PamTrack(tp,cp,op);          new(ttsorted[i]) PamTrack(tp,cp,op,rp);
1524      new(ttimage[i])  PamTrack(ti,ci,oi);          new(ttimage[i])  PamTrack(ti,ci,oi,ri);
1525    
1526      ((PamTrack*)(ttsorted[i]))->SetPScore(totp_score);          ((PamTrack*)(ttsorted[i]))->SetPScore(totp_score);
1527      ((PamTrack*)(ttsorted[i]))->SetIScore(toti_score);          ((PamTrack*)(ttsorted[i]))->SetIScore(toti_score);
1528      ((PamTrack*)(ttimage[i]))->SetPScore(totp_score);          ((PamTrack*)(ttimage[i]))->SetPScore(totp_score);
1529      ((PamTrack*)(ttimage[i]))->SetIScore(toti_score);          ((PamTrack*)(ttimage[i]))->SetIScore(toti_score);
1530    };      };
1531    
1532    if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){      if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){
1533      cout << "void PamLevel2::SortTracks(): tsorted->GetEntries() "<<tsorted->GetEntries()<<" != trk2_obj->GetNTracks() = "<<trk2_obj->GetNTracks() <<endl;          cout << "void PamLevel2::SortTracks(): tsorted->GetEntries() "<<tsorted->GetEntries()<<" != trk2_obj->GetNTracks() = "<<trk2_obj->GetNTracks() <<endl;
1534      tsorted->Delete(); tsorted=0;          tsorted->Delete(); tsorted=0;
1535      timage->Delete(); timage=0;          timage->Delete(); timage=0;    
1536    }      }
1537    
1538    //Restore Object count      //Restore Object count
1539    //To save space in the table keeping track of all referenced objects      //To save space in the table keeping track of all referenced objects
1540    //We reset the object count to what it was at the beginning of the event.      //We reset the object count to what it was at the beginning of the event.
1541    TProcessID::SetObjectCount(ObjectNumber);      TProcessID::SetObjectCount(ObjectNumber);
1542            
1543  };  };
1544  //--------------------------------------  //--------------------------------------
# Line 1417  TClonesArray *PamLevel2::GetTracks(){ Line 1567  TClonesArray *PamLevel2::GetTracks(){
1567    
1568      return tsorted;      return tsorted;
1569            
1570   };  };
1571  //--------------------------------------  //--------------------------------------
1572   //  //
1573   //  //
1574  //--------------------------------------  //--------------------------------------
1575  /**  /**
1576   * Retrieves the it-th Pamela "physical" track.   * Retrieves the it-th Pamela "physical" track.
# Line 1481  PamTrack *PamLevel2::GetTrack(int it){ Line 1631  PamTrack *PamLevel2::GetTrack(int it){
1631   */   */
1632  PamTrack *PamLevel2::GetTrackImage(int it){  PamTrack *PamLevel2::GetTrackImage(int it){
1633    
 //     if(!trk2_obj) return 0;  
   
 // //  *-*-*-*-*-*-*-*-*-*-*-*-*  
 //     SortTracks("+CAL+TOF");  
 // //  *-*-*-*-*-*-*-*-*-*-*-*-*  
 // //    if(!sorted_tracks)return 0;  
 //     if(sorted_tracks.IsEmpty())return 0;  
       
 //     PamTrack *image = 0;  
       
 //     if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() ){  
 //      TrkTrack *temp = (TrkTrack*)sorted_tracks.At(it);  
 //      if( temp->HasImage() ){  
 //          TrkTrack   *t = trk2_obj->TrkLevel2::GetStoredTrack(temp->GetImageSeqNo());  
 //          image = GetPamTrackAlong(t);  
 //      }else{  
 //          cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;  
 //      };  
 //     }else{  
 //      cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;  
 //     };  
       
 //     return image;  
   
   
1634  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1635      SortTracks();      SortTracks();
1636  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
# Line 1552  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1677  TTree *PamLevel2::GetPamTree(TFile *f, T
1677          printf("WARNING: TTree *PamLevel2::GetPamTree(TFile *fl, TString detlist) -- pam_tree already exists!\n ");          printf("WARNING: TTree *PamLevel2::GetPamTree(TFile *fl, TString detlist) -- pam_tree already exists!\n ");
1678          return pam_tree;          return pam_tree;
1679      };      };
1680    //      //
1681    
1682      cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;      cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;
1683    
# Line 1698  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1823  TTree *PamLevel2::GetPamTree(TFile *f, T
1823    
1824      TTree *L = (TTree*)f->Get("SelectionList");      TTree *L = (TTree*)f->Get("SelectionList");
1825      if(L && SELLI==1) {      if(L && SELLI==1) {
1826  //      L->SetBranchAddress("RunEntry",&irun);          cout << " TTree *PamLevel2::GetPamTree(TFile, TString) >>> SelectionList not implemented!!!!"<<endl;
 //      cout << "SelectionList: set branch address RunEntry"<<endl;  
 //      L->SetBranchAddress("EventEntry",&irunentry);  
 //      cout << "SelectionList: set branch address EventEntry"<<endl;  
 //      if(!Trout)Trout=O;  
 //      else Trout->AddFriend("SelectionList");  
         cout << " TTree *PamLevel2::GetPamTree(TFile, TString) >>> SelectionList not implemente!!!!"<<endl;  
1827          sel_tree = 0;          sel_tree = 0;
1828      }else{      }else{
1829          cout << "SelectionList  : missing tree"<<endl;          cout << "SelectionList  : missing tree"<<endl;
# Line 1749  TList*  PamLevel2::GetListOfLevel2Files( Line 1868  TList*  PamLevel2::GetListOfLevel2Files(
1868      //    if(ddir=="")ddir = wdir;      //    if(ddir=="")ddir = wdir;
1869  //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);  //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
1870      if ( ddir != ""){      if ( ddir != ""){
1871        cout << "Level2 data directory : "<<  ddir << endl;          cout << "Level2 data directory : "<<  ddir << endl;
1872      } else {      } else {
1873        cout << "Level2 data directory not given as input: trying to evaluate from list or taking working directory " << endl;          cout << "Level2 data directory not given as input: trying to evaluate from list or taking working directory " << endl;
1874      };      };
1875      TList *contents  = new TList; // create output list      TList *contents  = new TList; // create output list
1876      contents->SetOwner();      contents->SetOwner();
# Line 1768  TList*  PamLevel2::GetListOfLevel2Files( Line 1887  TList*  PamLevel2::GetListOfLevel2Files(
1887  //          return 0;  //          return 0;
1888  //      }        //      }      
1889  //      flisttxt = fullpath;  //      flisttxt = fullpath;
1890        if ( !flisttxt.EndsWith(".root") ){          if ( !flisttxt.EndsWith(".root") ){
1891    
1892          flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));              flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1893    
1894          if( !gSystem->ChangeDirectory(ddir) ){              if( !gSystem->ChangeDirectory(ddir) ){
1895              cout << "Cannot change directory : "<<ddir<<endl;                  cout << "Cannot change directory : "<<ddir<<endl;
1896              return 0;                  return 0;
         }  
           
         cout <<"Input file list : " << flisttxt <<endl;  
         ifstream in;  
         in.open(flisttxt, ios::in); //open input file list  
         if(!in.good()){  
             cout <<" ERROR opening the file "<<endl;  
             gSystem->ChangeDirectory(wdir); // back to the working directory  
             return 0;  
         }        
         int line=0;  
         while (1) {  
             TString file;  
             in >> file;  
             if (!in.good()) break;  
             line++;  
 //          cout <<"(1) " << file << endl;  
             if(file.IsNull()){  
                 cout << "-- list interrupted at line "<<line <<endl;  
                 break;  
1897              }              }
1898              if(file.Contains("#"))file = file(0,file.First("#"));          
1899                cout <<"Input file list : " << flisttxt <<endl;
1900                ifstream in;
1901                in.open(flisttxt, ios::in); //open input file list
1902                if(!in.good()){
1903                    cout <<" ERROR opening the file "<<endl;
1904                    gSystem->ChangeDirectory(wdir); // back to the working directory
1905                    return 0;
1906                }  
1907                int line=0;
1908                while (1) {
1909                    TString file;
1910                    in >> file;
1911                    if (!in.good()) break;
1912                    line++;
1913    //          cout <<"(1) " << file << endl;
1914                    if(file.IsNull()){
1915                        cout << "-- list interrupted at line "<<line <<endl;
1916                        break;
1917                    }
1918                    if(file.Contains("#"))file = file(0,file.First("#"));
1919  //          cout <<"(2) " << file << endl;  //          cout <<"(2) " << file << endl;
1920  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){
1921  //          if( (fullpath = gSystem->FindFile(ddir,file)) ){  //          if( (fullpath = gSystem->FindFile(ddir,file)) ){
1922              if( file.EndsWith(".root") ){                  if( file.EndsWith(".root") ){
1923                TString filedir;                      TString filedir;
1924                if (ddir != ""){                      if (ddir != ""){
1925                  filedir = ddir; // take the input dir                          filedir = ddir; // take the input dir
1926                } else {                      } else {
1927                  gSystem->ChangeDirectory(wdir); // back to the working directory                          gSystem->ChangeDirectory(wdir); // back to the working directory
1928                  filedir = gSystem->DirName(file); // this will take the path if exist in the list otherwise it will return automatically the working dir                          filedir = gSystem->DirName(file); // this will take the path if exist in the list otherwise it will return automatically the working dir
1929                };                      };
1930                  char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir),gSystem->BaseName(file));                      char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir),gSystem->BaseName(file));
1931                  contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list                      contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
1932                  delete fullpath;                      delete fullpath;
1933              }                  }
1934  //          }else{  //          }else{
1935  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;
1936  //          };  //          };
1937          };              };
1938          in.close();              in.close();
1939        } else {          } else {
1940            if(flisttxt.Contains("#"))flisttxt = flisttxt(0,flisttxt.First("#"));              if(flisttxt.Contains("#"))flisttxt = flisttxt(0,flisttxt.First("#"));
1941            char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));              char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1942            contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list              contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
1943            delete fullpath;              delete fullpath;
1944        };                  };      
1945      }else{      }else{
1946                    
1947          cout << "No input file list given."<<endl;          cout << "No input file list given."<<endl;
1948          cout << "Check for existing root files."<<endl;          cout << "Check for existing root files."<<endl;
1949  //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;  //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;
1950          if ( ddir == "" ){          if ( ddir == "" ){
1951            ddir = wdir;              ddir = wdir;
1952            cout << "Level2 data directory : "<<  ddir << endl;              cout << "Level2 data directory : "<<  ddir << endl;
1953          };          };
1954    
1955          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
# Line 1887  TChain *PamLevel2::GetPamTree(TList *fl, Line 2006  TChain *PamLevel2::GetPamTree(TList *fl,
2006            
2007      TChain *Trout =0;      TChain *Trout =0;
2008    
2009            // -------------------------------------------
2010        // set flags to include/exclude trees/branches
2011        // -------------------------------------------
2012      if( detlist.Contains("+AUTO", TString::kIgnoreCase) ) {      if( detlist.Contains("+AUTO", TString::kIgnoreCase) ) {
2013          if( fl->GetEntries()>0 ){          if( fl->GetEntries()>0 ){
2014              cout << "+AUTO"<<endl;              cout << "+AUTO"<<endl;
2015              TFile *fprimo = new TFile( fl->At(0)->GetName() );              TFile *fprimo = new TFile( fl->At(0)->GetName() );
2016              GetWhichTrees(fprimo);              GetWhichTrees(fprimo);
2017                fprimo->Close();// AAAAARGGGGGHHHHH!!!!!!! non commentare questa riga, altrimenti si incasina il TChain
2018              fprimo->Delete();              fprimo->Delete();
2019          }          }
2020      };      };
2021      SetWhichTrees(detlist);          SetWhichTrees(detlist);    
2022    
2023    
2024        // -------------------------------------------
2025        // build chains
2026        // -------------------------------------------
2027        TChain *T = 0;      
2028        TChain *C = 0;
2029        TChain *O = 0;
2030        TChain *R = 0;
2031        TChain *S = 0;
2032        TChain *N = 0;
2033        TChain *A = 0;
2034        TChain *B = 0;
2035        TChain *G = 0;
2036    
2037  //    if( !detlist.IsNull() )SetWhichTrees(detlist);      TChain *L = 0;
 //      
      TChain *T = 0;      
      TChain *C = 0;  
      TChain *O = 0;  
      TChain *R = 0;  
      TChain *S = 0;  
      TChain *N = 0;  
      TChain *A = 0;  
      TChain *B = 0;  
      TChain *G = 0;  
   
      TChain *L = 0;  
2038            
2039      if(TRK2||TRK1||TRKh) T = new TChain("Tracker");          if(TRK2||TRK1||TRKh) T = new TChain("Tracker");    
2040      if(CAL2||CAL1)       C = new TChain("Calorimeter");      if(CAL2||CAL1)       C = new TChain("Calorimeter");
# Line 1945  TChain *PamLevel2::GetPamTree(TList *fl, Line 2067  TChain *PamLevel2::GetPamTree(TList *fl,
2067          };          };
2068      };      };
2069            
2070      cout << "done chain \n";      cout << "done chains\n";
2071      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2072    
2073  //    UInt_t *found=0;  
2074        // -------------------------------------------
2075        // make friends
2076        // -------------------------------------------
2077    
2078  // Tracker  // Tracker
2079        cout << "Friends: "<<endl;
2080      if(T && (TRK2||TRK1||TRKh)) {      if(T && (TRK2||TRK1||TRKh)) {
 //      if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));  
 //      if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;  
 //      if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));  
 //      if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;  
 //      if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));  
 //      if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;  
2081          if(!Trout)Trout=T;          if(!Trout)Trout=T;
2082          else Trout->AddFriend("Tracker");          else Trout->AddFriend("Tracker");
2083      }else{  //      cout << "+Tacker"<<endl;
 //        cout << "Tracker      : missing tree"<<endl;  
2084      };      };
2085      // Calorimeter      // Calorimeter
2086      if(C && (CAL2||CAL1)) {      if(C && (CAL2||CAL1)) {
 //        if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));  
 //        if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;  
 //        if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));  
 //        if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;  
2087          if(!Trout)Trout=C;          if(!Trout)Trout=C;
2088          else Trout->AddFriend("Calorimeter");          else Trout->AddFriend("Calorimeter");
2089      }else{  //      cout << "+Calorimeter"<<endl;
 //        cout << "Calorimeter  : missing tree"<<endl;  
2090      };      };
2091      // ToF          // ToF    
2092      if(O && TOF) {      if(O && TOF) {
 //        O->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));  
 //        cout << "ToF          : set branch address ToFLevel2"<<endl;  
2093          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2094          else Trout->AddFriend("ToF");          else Trout->AddFriend("ToF");
2095      }else{  //      cout << "+ToF"<<endl;
 //        cout << "ToF         : missing tree"<<endl;  
2096      };      };
2097      // Trigger      // Trigger
2098      if(R && TRG) {      if(R && TRG) {
 //        R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));  
 //        cout << "Trigger      : set branch address TrigLevel2"<<endl;  
2099          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2100          else Trout->AddFriend("Trigger");          else Trout->AddFriend("Trigger");
2101      }else{  //      cout << "+Trigger"<<endl;
 //        cout << "Trigger      : missing tree"<<endl;  
2102      };      };
2103      // S4      // S4
2104      if(S && S4) {      if(S && S4) {
 //        S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));  
 //        cout << "S4           : set branch address S4Level2"<<endl;  
2105          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2106          else Trout->AddFriend("S4");          else Trout->AddFriend("S4");
2107      }else{  //      cout << "+S4"<<endl;
 //        cout << "S4           : missing tree"<<endl;  
2108      };      };
2109      // Neutron Detector      // Neutron Detector
2110      if(N && ND) {      if(N && ND) {
 //        N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));  
 //        cout << "NeutronD     : set branch address NDLevel2"<<endl;  
2111          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2112          else Trout->AddFriend("NeutronD");          else Trout->AddFriend("NeutronD");
2113      }else{  //      cout << "+NeutronD"<<endl;
 //        cout << "NeutronD     : missing tree"<<endl;  
2114      };      };
2115      // Anticounters      // Anticounters
2116      if(A && AC) {      if(A && AC) {
 //        A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));  
 //        cout << "Anticounter  : set branch address AcLevel2"<<endl;  
2117          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2118          else Trout->AddFriend("Anticounter");          else Trout->AddFriend("Anticounter");
2119      }else{  //      cout << "+Anticounter"<<endl;
 //        cout << "Anticounter  : missing tree"<<endl;  
2120      };      };
2121      // Orbital Info      // Orbital Info
2122      if(B && ORB) {      if(B && ORB) {
 //      B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));  
 //      cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;  
2123          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2124          else Trout->AddFriend("OrbitalInfo");          else Trout->AddFriend("OrbitalInfo");
2125      }else{  //      cout << "+OrbitalInfo"<<endl;
 //      cout << "OrbitalInfo  : missing tree"<<endl;  
2126      };      };
2127      // GPamela      // GPamela
2128      if(G && GP) {      if(G && GP) {
         if(!gp_obj)gp_obj = new GPamela();  
 //      ------------------------------------  
 //      ATTENZIONE!!!  
 //      non so per quale arcano motivo,  
 //      per l'albero di gpamela il branch address lo devo settare  
 //      DOPO aver fatto friend  
 //      FGRRRVZZZZUTSALKJMSLKJ!!!  
 //      ------------------------------------  
 //      gp_obj->SetBranchAddress(G); //ho dovuto fare in maniera diversa dagli altri  
 //      cout << "h20          : set branch address GPamela "<<endl;  
2129          if(!Trout)Trout=G;          if(!Trout)Trout=G;
2130          else Trout->AddFriend("h20");          else Trout->AddFriend("h20");
2131      }else{  //      cout << "+h20"<<endl;
 //      cout << "h20          : missing tree"<<endl;  
2132      };      };
2133    
2134  //  =====================================  //  =====================================
# Line 2050  TChain *PamLevel2::GetPamTree(TList *fl, Line 2136  TChain *PamLevel2::GetPamTree(TList *fl,
2136  //  =====================================  //  =====================================
2137      SetBranchAddress(Trout);      SetBranchAddress(Trout);
2138    
2139    
2140    //  ------------------------------------
2141    //  finally handle selection trees...
2142    //  (it is not friend of pamela tree)
2143    //  ------------------------------------
2144    
2145      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2146    
2147      // Selection List      // Selection List
2148      if(L && SELLI==1) {      if(L && SELLI==1) {
2149          cout<<">>> Found selection-list <<<"<<endl;          cout<<">>> Found selection-list <<<"<<endl;
2150          L->SetBranchAddress("RunEntry",&irun);  //      L->SetBranchAddress("RunEntry",&irun);
2151            L->SetBranchAddress("RunEntry",&irunt);//NEWNEW
2152          cout << "SelectionList: set branch address RunEntry"<<endl;          cout << "SelectionList: set branch address RunEntry"<<endl;
2153          L->SetBranchAddress("EventEntry",&irunentry);          L->SetBranchAddress("EventEntry",&irunentry);
2154          cout << "SelectionList: set branch address EventEntry"<<endl;          cout << "SelectionList: set branch address EventEntry"<<endl;
2155          sel_tree = L;          sel_tree = L;
2156  //      if(!Trout)Trout=O;  //      if(!Trout)Trout=O;
2157  //      else Trout->AddFriend("SelectionList");  //      else Trout->AddFriend("SelectionList");
2158          cout << "----------------------------------------------------" <<endl;          cout << "+SelectionList"<<endl;
2159            cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2160      }else{      }else{
2161  //      cout << "SelectionList  : missing tree"<<endl;  //      cout << "SelectionList  : missing tree"<<endl;
2162          if(L)L->Delete();          if(L)L->Delete();
2163      };      };
       
 //    cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;  
   
 //      ------------------------------------  
 //      ATTENZIONE!!!  
 //      non so per quale arcano motivo,  
 //      per l'albero di gpamela il branch address lo devo settare  
 //      DOPO aver fatto friend  
 //      FGRRRVZZZZUTSALKJMSLKJ!!!  
 //      ------------------------------------  
 //     cout << G << " --- "<<GP <<endl;  
 //     if(G && GP) {      
 //      gp_obj->SetBranchAddress(Trout); //ho dovuto fare in maniera diversa dagli altri  
 //      cout << "h20          : set branch address GPamela "<<endl;  
 //     }else{  
 //      cout << "h20          : missing tree"<<endl;  
 //     };  
2164    
2165    //  --------------------------------------------
2166    //  return the pamela chain with all the friends
2167    //  --------------------------------------------
2168    
2169      pam_tree = Trout;      pam_tree = Trout;
2170            
# Line 2174  void PamLevel2::SetBranchAddress(TTree * Line 2254  void PamLevel2::SetBranchAddress(TTree *
2254      if(GP) {      if(GP) {
2255  //      GetPointerTo("GPamela");  //      GetPointerTo("GPamela");
2256          if(!gp_obj)gp_obj = new GPamela();          if(!gp_obj)gp_obj = new GPamela();
2257          gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri  //      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2258    // //   t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
2259            if(SELLI) t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
2260            else      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2261    
2262          cout << "h20          : set branch address GPamela "<<endl;          cout << "h20          : set branch address GPamela "<<endl;
2263      };      };
     // SelectionList  
     if(SELLI==1) {  
         t->SetBranchAddress("RunEntry", &irun);  
         cout << "SelectionList: set branch address RunEntry"<<endl;  
         t->SetBranchAddress("EventEntry", &irunentry);  
         cout << "SelectionList: set branch address EventEntry"<<endl;  
     };  
2264            
2265  }  }
2266  /**  /**
# Line 2205  void PamLevel2::SetBranchAddress(TChain Line 2282  void PamLevel2::SetBranchAddress(TChain
2282  //    GP     = GP & t->GetBranchStatus("h20");  //    GP     = GP & t->GetBranchStatus("h20");
2283    
2284      // Tracker      // Tracker
2285       if(TRK2) {      if(TRK2) {
2286          t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));          t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
2287          cout << "Tracker      : set branch address TrkLevel2"<<endl;          cout << "Tracker      : set branch address TrkLevel2"<<endl;
2288      };      };
# Line 2213  void PamLevel2::SetBranchAddress(TChain Line 2290  void PamLevel2::SetBranchAddress(TChain
2290          t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));          t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
2291          cout << "Tracker      : set branch address TrkLevel1"<<endl;          cout << "Tracker      : set branch address TrkLevel1"<<endl;
2292      };      };
2293       if(TRKh) {      if(TRKh) {
2294          t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));          t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
2295          cout << "Tracker      : set branch address TrkHough"<<endl;          cout << "Tracker      : set branch address TrkHough"<<endl;
2296       };      };
2297            
2298      // Calorimeter      // Calorimeter
2299      if(CAL2) {      if(CAL2) {
# Line 2263  void PamLevel2::SetBranchAddress(TChain Line 2340  void PamLevel2::SetBranchAddress(TChain
2340      if(GP) {      if(GP) {
2341  //      GetPointerTo("GPamela");  //      GetPointerTo("GPamela");
2342          if(!gp_obj)gp_obj = new GPamela();          if(!gp_obj)gp_obj = new GPamela();
2343          gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri          if(SELLI) t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
2344            else      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2345    //      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2346          cout << "h20          : set branch address GPamela "<<endl;          cout << "h20          : set branch address GPamela "<<endl;
2347      };      };
2348      // SelectionList      // SelectionList
2349      if(SELLI==1) {  //     if(SELLI==1){
2350          t->SetBranchAddress("RunEntry", &irun);  //      t->SetBranchAddress("RunEntry",&irunt);//NEWNEW
2351          cout << "SelectionList: set branch address RunEntry"<<endl;  //      cout << "SelectionList: set branch address RunEntry"<<endl;
2352          t->SetBranchAddress("EventEntry", &irunentry);  //      t->SetBranchAddress("EventEntry",&irunentry);
2353          cout << "SelectionList: set branch address EventEntry"<<endl;  //      cout << "SelectionList: set branch address EventEntry"<<endl;
2354      };          
2355        //     }
2356    
2357  }  }
2358    
2359    
# Line 2287  void PamLevel2::SetBranchAddress(TChain Line 2367  void PamLevel2::SetBranchAddress(TChain
2367   * @return Pointer to a TChain   * @return Pointer to a TChain
2368   */   */
2369  TChain *PamLevel2::GetRunTree(TList *fl){  TChain *PamLevel2::GetRunTree(TList *fl){
2370    //      //
2371    //      //
2372    //      //
2373    if ( run_tree ){      if ( run_tree ){
2374      printf("WARNING: TChain *PamLevel2::GetRunTree(TList *fl) -- run_tree already exists!\n ");          printf("WARNING: TChain *PamLevel2::GetRunTree(TList *fl) -- run_tree already exists!\n ");
2375      return run_tree;          return run_tree;
2376    };          };  
2377    //      //
2378    TChain *R = new TChain("Run");  
2379    
2380        TChain *R = new TChain("Run");
2381            
2382      // loop over files and create chains              // loop over files and create chains        
2383      TIter next(fl);      TIter next(fl);
# Line 2307  TChain *PamLevel2::GetRunTree(TList *fl) Line 2389  TChain *PamLevel2::GetRunTree(TList *fl)
2389              R->Add(name);              R->Add(name);
2390          };          };
2391      }      }
2392        
2393    
2394      if(R->GetNtrees()){      if(RUN && R->GetNtrees()){
2395            
2396          R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));          R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
2397          cout << "Run         : set branch address RunInfo"<<endl;          cout << "Run         : set branch address RunInfo"<<endl;
2398          R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano          R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
2399          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
2400    
2401            irunoffset = new int[R->GetNtrees()];
2402            if(DBG){
2403                cout << "----------------------------------------------------"<<endl;
2404                cout << "irun\t | ";
2405                cout << "tree\t |";
2406    //      cout << "offset\t |";
2407                cout << "RUN\t";
2408                cout << "FRAG\t";
2409                cout << "NEVENTS\t";
2410                cout << "absolute time\t\t\t";
2411                cout << "on-board time";
2412                cout<<endl;
2413            }
2414            for (Int_t ii=0; ii<R->GetEntries(); ii++){
2415                R->GetEntry(ii);
2416                if(DBG){
2417                    cout << ii<< "\t | ";
2418                    cout << R->GetTreeNumber()<< "\t |";
2419    //          cout << R->GetChainOffset()<< "\t |";
2420                    cout <<GetRunInfo()->ID<<"\t";
2421                    cout <<GetRunInfo()->ID_RUN_FRAG<<"\t";
2422                    cout <<GetRunInfo()->NEVENTS<< "\t";
2423                    cout <<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME <<"\t";
2424                    cout <<GetRunInfo()->RUNHEADER_OBT<<" <---> "<<GetRunInfo()->RUNTRAILER_OBT<<"\t";
2425                    cout <<endl;
2426                }
2427                irunoffset[R->GetTreeNumber()]=R->GetChainOffset();
2428            }
2429            cout << "N.run = "<<R->GetEntries()<<endl;
2430            cout << "----------------------------------------------------"<<endl;
2431    
2432    
2433      }else{      }else{
2434          delete R;          delete R;
2435          R=0;          R=0;
2436      }      }
2437        
2438    
2439      run_tree = R;      run_tree = R;
2440    
# Line 2334  TChain *PamLevel2::GetRunTree(TList *fl) Line 2451  TChain *PamLevel2::GetRunTree(TList *fl)
2451   * @return Pointer to a TTree   * @return Pointer to a TTree
2452   */   */
2453  TTree *PamLevel2::GetRunTree(TFile *f){  TTree *PamLevel2::GetRunTree(TFile *f){
2454    if ( run_tree ){      if ( run_tree ){
2455      printf("WARNING: TTree *PamLevel2::GetRunTree(TFile *f) -- run_tree already exists!\n ");          printf("WARNING: TTree *PamLevel2::GetRunTree(TFile *f) -- run_tree already exists!\n ");
2456      return run_tree;          return run_tree;
2457    };      };
2458                    
2459    
2460      cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;      cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;
# Line 2349  TTree *PamLevel2::GetRunTree(TFile *f){ Line 2466  TTree *PamLevel2::GetRunTree(TFile *f){
2466          cout << "Run         : set branch address RunInfo"<<endl;          cout << "Run         : set branch address RunInfo"<<endl;
2467          T->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano          T->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
2468          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
2469    
2470      }      }
2471    
2472      run_tree = (TChain*)T;      run_tree = (TChain*)T;
# Line 2362  TTree *PamLevel2::GetRunTree(TFile *f){ Line 2480  TTree *PamLevel2::GetRunTree(TFile *f){
2480   * @return true if a new run has been read, false if it is still the same run   * @return true if a new run has been read, false if it is still the same run
2481   */   */
2482  Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev){  Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev){
2483    //      //
2484    // check if we have already called once GetEntry, if not call it      // check if we have already called once GetEntry, if not call it
2485    //      //
2486      cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev) --- ATTENZIONE --- NON E` MANTENUTA!!!!!!!.... "<<endl;      cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev) --- ATTENZIONE --- NON E` MANTENUTA!!!!!!!.... "<<endl;
2487      if(!run){      if(!run){
2488            cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing RunInfo tree "<<endl;          cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing RunInfo tree "<<endl;
2489            return(false);                  return(false);  
2490      }      }
2491      if ( run->GetEntries() <= 0 ) return(false);      if ( run->GetEntries() <= 0 ) return(false);
2492    //      //
2493        
2494    //  Int_t oldrun = irun;      //  Int_t oldrun = irun;
2495    Long64_t oldrun = irun;      Long64_t oldrun = irun;
2496    
2497        // --------------------------------------
2498        // if it is a full file (not preselected)
2499        // --------------------------------------
2500        if(SELLI==0){
2501    
2502            //
2503            // the absolute time is necessary to relate the event with the run
2504            //
2505            if( !GetOrbitalInfo() && !ISGP){
2506                cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
2507                return(false);
2508            }
2509    
2510            ULong64_t abstime = 0;
2511            if( GetOrbitalInfo() )abstime=GetOrbitalInfo()->absTime;
2512    
2513    // --------------------------------------  
2514    // if it is a full file (not preselected)          //
2515    // --------------------------------------          // the first time the routine is called, set run search from the beginning
2516    if(SELLI==0){          //
2517            if ( irun < 0LL ){
2518        //              irun = 0LL;
2519        // the absolute time is necessary to relate the event with the run              run->GetEntry(irun);
2520        //              runfirstentry = 0LL;
2521        if( !GetOrbitalInfo() && !ISGP){              runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2522            cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;              if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
           return(false);  
       }  
   
       ULong64_t abstime = 0;  
       if( GetOrbitalInfo() )abstime=GetOrbitalInfo()->absTime;  
   
   
       //  
       // the first time the routine is called, set run search from the beginning  
       //  
       if ( irun < 0LL ){  
           irun = 0LL;  
           run->GetEntry(irun);  
           runfirstentry = 0LL;  
           runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);  
           if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;  
2523                        
2524            if( ISGP && run->GetEntries()!=1 ){              if( ISGP && run->GetEntries()!=1 ){
2525                cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run->GetEntries() << endl;                  cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run->GetEntries() << endl;
2526                cout << "** WARNING ** run will not be updated"<<endl;                  cout << "** WARNING ** run will not be updated"<<endl;
2527            }              }
2528    
2529        };                };      
2530        //          //
2531        if(ISGP)abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO          if(ISGP)abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO
2532        //          //
2533        if ( irun == run->GetEntries()-1LL &&          if ( irun == run->GetEntries()-1LL &&
2534             !(abstime >= GetRunInfo()->RUNHEADER_TIME &&               !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
2535               abstime <= GetRunInfo()->RUNTRAILER_TIME)                 abstime <= GetRunInfo()->RUNTRAILER_TIME)
2536              ){              ){
2537           irun = -1LL;              irun = -1LL;
2538           runfirstentry = 0LL;              irunt = -1LL;
2539           runlastentry = -1LL;              runfirstentry = 0LL;
2540         };              runlastentry = -1LL;
2541        // modificato il controllo sull'aggiornamento del run, per evitare problemi          };
2542        // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)          // modificato il controllo sull'aggiornamento del run, per evitare problemi
2543        //          // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)
2544        bool fromfirst = true;          //
2545        //          bool fromfirst = true;
2546        while ( !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1LL ){          //
2547            while ( !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1LL ){
2548  //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){  //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){
2549            irun++;              irun++;
2550            run->GetEntry(irun);              run->GetEntry(irun);
2551            runfirstentry = runlastentry;              runfirstentry = runlastentry;
2552            if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runfirstentry += 1LL;              if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runfirstentry += 1LL;
2553            runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);              runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2554  //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;  //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2555  //        cout << "runfirstentry "<<runfirstentry<<endl;  //        cout << "runfirstentry "<<runfirstentry<<endl;
2556            //      printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));              //    printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));
2557            //      printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME);              //    printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME);
2558            //      printf(" IDRUN %u \n",GetRunInfo()->ID);              //    printf(" IDRUN %u \n",GetRunInfo()->ID);
2559            //              //
2560  //        prevshift = 0;  //        prevshift = 0;
2561            //              //
2562            if ( irun == (Long64_t)(run->GetEntries()-1LL) && fromfirst && !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME)){              if ( irun == (Long64_t)(run->GetEntries()-1LL) && fromfirst && !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME)){
2563                printf(" resetting irun  (it should NOT happen!!!)\n");                  printf(" resetting irun  (it should NOT happen!!!)\n");
2564                fromfirst = false;                  fromfirst = false;
2565                irun = 0;                  irun = 0;
2566                run->GetEntry(irun);                  run->GetEntry(irun);
2567                runfirstentry = 0ULL;                  runfirstentry = 0ULL;
2568                runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);                  runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2569                if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;                  if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
2570            };              };
2571            //              //
2572        };          };
2573        //          //
2574        if (          if (
2575             !(abstime >= GetRunInfo()->RUNHEADER_TIME &&              !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
2576               abstime <= GetRunInfo()->RUNTRAILER_TIME)                abstime <= GetRunInfo()->RUNTRAILER_TIME)
2577            ) {              ) {
2578          printf(" Something very wrong here: cannot find RUN containing absolute time %llu \n",abstime);              printf(" Something very wrong here: cannot find RUN containing absolute time %llu \n",abstime);
2579            return false;              return false;
2580        }          }
2581        //          //
2582        if ( irun == oldrun || irun >= run->GetEntries() ) return(false);          if ( irun == oldrun || irun >= run->GetEntries() ) return(false);
2583        //          //
2584        //  printf(" iev %llu irun %i nevents %u 1st %llu last %llu \n",iev,irun,this->GetRunInfo()->NEVENTS,(ULong64_t)runfirstentry,(ULong64_t)runlastentry);          //  printf(" iev %llu irun %i nevents %u 1st %llu last %llu \n",iev,irun,this->GetRunInfo()->NEVENTS,(ULong64_t)runfirstentry,(ULong64_t)runlastentry);
2585        //          //
2586        prevshift = 0;          prevshift = 0;
2587        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;          cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2588  //      cout << "runfirstentry "<<runfirstentry<<endl;  //      cout << "runfirstentry "<<runfirstentry<<endl;
2589        return(true);              return(true);    
2590    };      };
2591    // ----------------------------------------------------      // ----------------------------------------------------
2592    // if it is a preselected file (there is SelectionList)      // if it is a preselected file (there is SelectionList)
2593    // NBNB - the event tree MUST be read first      // NBNB - the event tree MUST be read first
2594    // ----------------------------------------------------      // ----------------------------------------------------
2595    if(SELLI==1){            if(SELLI==1){      
2596        sel_tree->GetEntry(iev);          sel_tree->GetEntry(iev);
2597  //      cout << irun << " "<< irunentry << endl;  //      cout << irun << " "<< irunentry << endl;
2598        if(irun != oldrun){          if(irun != oldrun){
2599            run->GetEntry(irun);              run->GetEntry(irun);
2600            cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;              cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2601            prevshift = 0;              prevshift = 0;
2602            return true;              return true;
2603        }          }
2604        return false;          return false;
2605    }      }
2606    
2607    return false;      return false;
2608    //      //
2609  };  };
2610    
2611  Bool_t PamLevel2::UpdateRunInfo(Long64_t iev){  Bool_t PamLevel2::UpdateRunInfo(Long64_t iev){
# Line 2502  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2621  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2621        
2622      Int_t oldrun = irun; // store current run index      Int_t oldrun = irun; // store current run index
2623    
2624        // -----------------------------------------------------------------------
2625        // the first time the routine is called, set run search from the beginning
2626        // -----------------------------------------------------------------------
2627    
2628        if ( irun < 0 ){
2629            irun = 0LL;
2630            irunt = 0LL;
2631            irunentry = 0;
2632            prevshift = 0;
2633            run_tree->GetEntry(irun);
2634            if( !GetOrbitalInfo() )cout << "** WARNING ** missing OrbitalInfo ---> run info might be not correctly updated "<<endl;
2635        };      
2636        // ---------------------------------------------------------------
2637        // retrieve OBT and absolute time of the event
2638        // ---------------------------------------------------------------
2639        ULong64_t abstime = 0LL;
2640        ULong64_t obt     = 0LL;
2641        if( GetOrbitalInfo() ){
2642            abstime = GetOrbitalInfo()->absTime;
2643            obt     = GetOrbitalInfo()->OBT;
2644        }else{
2645            abstime = GetRunInfo()->RUNHEADER_TIME;
2646            obt     = GetRunInfo()->RUNHEADER_OBT;
2647        }
2648        
2649    
2650      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2651      // if it is a full file (not preselected)      // if it is a full file (not preselected)
2652      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2653      if(SELLI==0){      if(SELLI==0){
2654    
2655          // ---------------------------------------------------------------          // ---------------------------------------------------------------
2656          // increment dead and live-time counters          // increment dead and live-time counters
2657          // ---------------------------------------------------------------          // (only when reading a file not preselected)
         if( GetTrigLevel2() ){  
             totdltime[0]+=GetTrigLevel2()->dltime[0];  
             totdltime[1]+=GetTrigLevel2()->dltime[1];  
         }  
         totdltime[2]++;  
   
 //      cout << setw(10)<<totdltime[0]<<setw(10)<<totdltime[1]<<setw(10)<<totdltime[2]<<endl;  
   
         // ---------------------------------------------------------------  
         // retrieve OBT and absolute time of the event  
2658          // ---------------------------------------------------------------          // ---------------------------------------------------------------
2659          ULong64_t abstime = 0;          if(SELLI==0){
2660          ULong64_t obt     = 0;              if( GetTrigLevel2() ){
2661          if( GetOrbitalInfo() ){                  totdltime[0]+=GetTrigLevel2()->dltime[0];
2662              abstime = GetOrbitalInfo()->absTime;                  totdltime[1]+=GetTrigLevel2()->dltime[1];
             obt     = GetOrbitalInfo()->OBT;  
         }  
         // ---------------------------------------------------------------  
         // the absolute time is necessary to relate the event with the run  
         // ---------------------------------------------------------------  
         if( !GetOrbitalInfo() && !ISGP ){  
             cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;  
             return(false);  
         }  
         
         // -----------------------------------------------------------------------  
         // the first time the routine is called, set run search from the beginning  
         // -----------------------------------------------------------------------  
         if ( irun < 0 ){  
             irun = 0LL;  
             irunentry = 0;  
             prevshift = 0;  
             run_tree->GetEntry(irun);  
   
             if( ISGP && run_tree->GetEntries()!=1 ){  
                 cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run_tree->GetEntries() << endl;  
                 cout << "** WARNING ** run will not be updated"<<endl;  
2663              }              }
2664          };                    totdltime[2]++;
   
         // -----------------------------------------------------------------------  
         // if it is simulation, assign abstime by hand (temporaneo!!!)  
         // -----------------------------------------------------------------------  
         if(ISGP){  
             abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO  
             obt     = GetRunInfo()->RUNHEADER_OBT; // BARBATRUCCO  
2665          }          }
2666    
2667          //          //
2668          bool fromfirst = true; // first loop over runs          bool fromfirst = true; // first loop over runs
2669    
 //      Bool_t hasfrag = false;  
 //      if( GetRunInfo()->ID_RUN_FRAG!=0 && GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID)hasfrag=true;  
 //      ULong64_t fragid = GetRunInfo()->ID_RUN_FRAG;  
2670    
2671          // ------------------------------------------------------          // ------------------------------------------------------
2672          // loop over runs to find the one that contains the event          // loop over runs to find the one that contains the event
2673          // ------------------------------------------------------          // ------------------------------------------------------
2674          while (          while (
2675              (              (
2676                  (  //              (
2677                      !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)  //                  !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
2678                        abstime <= GetRunInfo()->RUNTRAILER_TIME) &&  //                    abstime <= GetRunInfo()->RUNTRAILER_TIME) &&
2679                      !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)  //                  !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
2680                        obt <= GetRunInfo()->RUNTRAILER_OBT)  //                    obt <= GetRunInfo()->RUNTRAILER_OBT)
2681                      )  //                  )
2682                  || GetRunInfo()->NEVENTS==0                  
2683                    !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
2684                      abstime <= GetRunInfo()->RUNTRAILER_TIME)
2685                    ||
2686                    !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
2687                      obt <= GetRunInfo()->RUNTRAILER_OBT)          
2688                    ||
2689                    GetRunInfo()->NEVENTS==0
2690  //              || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift) // ERRORE!!! fa saltare i run con 1 evento  //              || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift) // ERRORE!!! fa saltare i run con 1 evento
2691                  || !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift)                  ||
2692                    !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift)
2693                  )                  )
2694                  && irun < run_tree->GetEntries() ){              && irun < run_tree->GetEntries() ){
2695    
2696    
2697    //          if( !(abstime >= GetRunInfo()->RUNHEADER_TIME &&abstime <= GetRunInfo()->RUNTRAILER_TIME)  )cout << "ABS TIME "<<abstime << " " <<GetRunInfo()->RUNTRAILER_TIME <<endl;
2698    //          if( !(obt >= GetRunInfo()->RUNHEADER_OBT && obt <= GetRunInfo()->RUNTRAILER_OBT) )cout << "OBT TIME "<< obt <<" "<< GetRunInfo()->RUNTRAILER_OBT << endl;
2699    //          if( GetRunInfo()->NEVENTS==0  )cout <<"GetRunInfo()->NEVENTS==0 "<<endl;
2700    //          if( !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift) ) cout << "irunentry > "<<GetRunInfo()->NEVENTS-1-prevshift << endl;
2701              // - - - - - - - - - - - - -              // - - - - - - - - - - - - -
2702              // irunentry = position of current entry, relative to the run              // irunentry = position of current entry, relative to the run
2703              // prevshift = shift needed to synchronize l0 and l2 data (nested events)              // prevshift = shift needed to synchronize l0 and l2 data (nested events)
# Line 2589  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2706  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2706              // -----------------------------------------              // -----------------------------------------
2707              // store dead and live-time of previous run              // store dead and live-time of previous run
2708              // -----------------------------------------              // -----------------------------------------
2709    //          if(SELLI==0){
2710              if(fromfirst){              if(fromfirst){
2711                  if(oldrun==irun){                  if(oldrun==irun){
2712                      /// decrement counters                      /// decrement counters
# Line 2618  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2736  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2736                  }                  }
2737                  totdltime[2]=1;                             //event counter                  totdltime[2]=1;                             //event counter
2738              }              }
2739    //          }
2740    
2741                irun++;        
             irun++;  
2742              // ------------------------------------              // ------------------------------------
2743              // if the end of run tree is reached...              // if the end of run tree is reached...
2744              // ------------------------------------              // ------------------------------------
# Line 2648  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2766  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2766              if(irun>0)runfirstentry += (GetRunInfo()->NEVENTS)-prevshift;              if(irun>0)runfirstentry += (GetRunInfo()->NEVENTS)-prevshift;
2767              irunentry = 0;              irunentry = 0;
2768              prevshift = 0;                        prevshift = 0;          
2769              run_tree->GetEntry(irun);                    run_tree->GetEntry(irun);//update runinfo
2770                irunt = irun - irunoffset[run_tree->GetTreeNumber()];
2771              if(GetRunInfo()->RUNHEADER_OBT>GetRunInfo()->RUNTRAILER_OBT ){              if(GetRunInfo()->RUNHEADER_OBT>GetRunInfo()->RUNTRAILER_OBT ){
2772                  cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun "<<irun<<"  has RUNHEADER_OBT>=RUNTRAILER_OBT " <<endl;                  cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun "<<irun<<"  has RUNHEADER_OBT>=RUNTRAILER_OBT " <<endl;
2773                  cout << "                                                            (NB!! in this case some events are assigned to a wrong run)"<<endl;                  cout << "                                                            (NB!! in this case some events are assigned to a wrong run)"<<endl;
# Line 2670  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2789  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2789          // --------------------------------------          // --------------------------------------
2790    
2791    
   
 //      // -----------------------------------------  
 //      // store dead and live-time of previous run  
 //      // -----------------------------------------  
 //      // --------------------------------------------------------------  
 //      // if the run is empty, fill the dead-live time branch with zeros  
 //      // --------------------------------------------------------------  
 //      /// if some runs have been jumped, fill with zeros  
 //      if(irun-oldrun>1){  
 //          ULong64_t  temp[3];  
 //          temp[0]=totdltime[0];  
 //          temp[1]=totdltime[1];  
 //          temp[2]=totdltime[2];  
 //          for(int i=oldrun+1; i<irun; irun++){  
 //              totdltime[0]=0;  
 //              totdltime[1]=0;  
 //              totdltime[2]=0;  
 //              cout << " ** JUMPED RUN **"<<endl;  
 //              if(run_tree_clone)  
 //                  if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())  
 //                      run_tree_clone->GetBranch("DeadLiveTime")->Fill();  
 //          }  
 //          totdltime[0]=temp[0];  
 //          totdltime[1]=temp[1];  
 //          totdltime[2]=temp[2];  
 //      }  
 //      /// decrement counters  
 //      if( GetTrigLevel2() ){  
 //          totdltime[0]-=GetTrigLevel2()->dltime[0];//live-time  
 //          totdltime[1]-=GetTrigLevel2()->dltime[1];//dead-time  
 //      }  
 //      totdltime[2]--;                              //event counter  
 //      /// add an entry  
 //      if(irun>0 ){  
 //          cout << endl;  
 //          cout << "n.events     : "<<totdltime[2]<<endl;  
 //          cout << "RUN LIVE-TIME: "<<totdltime[0]*0.16<<" ms"<<endl;  
 //          cout << "RUN DEAD-TIME: "<<totdltime[1]*0.01<<" ms"<<endl;        
 //          if(run_tree_clone)  
 //              if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())  
 //                  run_tree_clone->GetBranch("DeadLiveTime")->Fill();  
 //      }  
 //      /// reset counters  
 //      if( GetTrigLevel2() ){  
 //          totdltime[0]=GetTrigLevel2()->dltime[0];//live-time  
 //          totdltime[1]=0;                         //dead-time  
 //      }  
 //      totdltime[2]=1;                             //event counter  
           
   
2792          // --------------------------------------          // --------------------------------------
2793          // ---> exit with TRUE          // ---> exit with TRUE
2794          // --------------------------------------          // --------------------------------------
2795          cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;          if(DBG)cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2796            // ----------------------------------------------------
2797            // update the tracker parameters
2798            // (non ho trovato nessun altro modo sicuro di farlo...)
2799            // ----------------------------------------------------
2800            if(!dbc || (dbc && !dbc->IsConnected()) )SetDBConnection();
2801            TrkParams::Set(GetRunInfo() ,dbc);
2802            if(dbc)dbc->Close();
2803    
2804          // ----------------------------------------------------          // ----------------------------------------------------
2805          // then check if the run has a fragment          // then check if the run has a fragment
2806          // in this case we have to switch to the next fragment          // in this case we have to switch to the next fragment
# Line 2732  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2809  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2809          if(          if(
2810              GetRunInfo()->ID_RUN_FRAG != 0 &&              GetRunInfo()->ID_RUN_FRAG != 0 &&
2811  //          GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID &&  //          GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID &&
2812                DBG &&
2813              true ){              true ){
2814              cout << "* fragment *"<<endl;                            cout << "* fragment *"<<endl;              
2815          }          }
# Line 2741  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2819  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2819      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2820      // if it is a preselected file (there is SelectionList)      // if it is a preselected file (there is SelectionList)
2821      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2822        // irun  = run entry relative to the chain
2823        // irunt = run entry relative to the tree
2824      if(SELLI==1){            if(SELLI==1){      
2825          sel_tree->GetEntry(iev);          sel_tree->GetEntry(iev);// read irunt from SelectionList
2826          if(irun != oldrun){          irun = irunt + irunoffset[sel_tree->GetTreeNumber()];//NEWNEW
2827              run_tree->GetEntry(irun);          if(irun != oldrun ){
2828              cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;              if( irun < run_tree->GetEntries() )run_tree->GetEntry(irun);
2829                // check if the time is ok (with merged files it is not...)
2830                // if not loop over run and look for the proper entry
2831                bool SECONDO_GIRO=false;
2832                //      Long64_t irun_start   = irun;
2833                int      offset_start = irunoffset[sel_tree->GetTreeNumber()];
2834                while (
2835                    (
2836                        (
2837                            !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
2838                              abstime <= GetRunInfo()->RUNTRAILER_TIME)
2839    //                      ||
2840    //                      !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
2841    //                        obt <= GetRunInfo()->RUNTRAILER_OBT)
2842                            )
2843                        || GetRunInfo()->NEVENTS==0
2844                        )
2845    //              && irun < run_tree->GetEntries()
2846                    ){
2847    
2848                    if(DBG){
2849                        cout << " (test) ";
2850                        cout << " tree "<<sel_tree->GetTreeNumber();
2851                        cout << " irunt "<<irunt;
2852                        cout << " offset "<<irunoffset[sel_tree->GetTreeNumber()];
2853                        cout << " abs "<<abstime;
2854                        cout <<" >> "<<GetRunInfo()->RUNHEADER_TIME<<" "<<GetRunInfo()->RUNTRAILER_TIME;
2855                        cout << " obt "<<obt;
2856                        cout <<" >> "<<GetRunInfo()->RUNHEADER_OBT<<" "<<GetRunInfo()->RUNTRAILER_OBT;
2857                        cout << " *** JUMP RUN *** irun "<<irun;
2858                        cout << endl;
2859                    }
2860    //              irun++;
2861                    irunoffset[sel_tree->GetTreeNumber()]++;
2862                    irun = irunt + irunoffset[sel_tree->GetTreeNumber()];//NEWNEW          
2863                    if(irun == run_tree->GetEntries() && SECONDO_GIRO){
2864    //              if(irun == irun_start ){
2865                        cout << " ...grrrvzzkhhhajsdkj!!!! "<<endl;
2866                        irunoffset[sel_tree->GetTreeNumber()] = offset_start;
2867                        return false;
2868                    }
2869                    if( irun >= run_tree->GetEntries() || irun < 0){
2870                        cout << "irun = "<<irun<<" >>  search from the beginning... <<"<<endl;
2871                        SECONDO_GIRO=true;
2872                        irun=0;
2873                        irunoffset[sel_tree->GetTreeNumber()]=-irunt;
2874                    }
2875                    run_tree->GetEntry(irun);
2876                }
2877    
2878    
2879                if(DBG){
2880                    cout << " (test) ";
2881                    cout << " tree "<<sel_tree->GetTreeNumber();
2882                    cout << " irunt "<<irunt;
2883                    cout << " offset "<<irunoffset[sel_tree->GetTreeNumber()];
2884                    cout << " abs "<<abstime;
2885                    cout <<" >> "<<GetRunInfo()->RUNHEADER_TIME<<" "<<GetRunInfo()->RUNTRAILER_TIME;
2886                    cout << " obt "<<obt;
2887                    cout <<" >> "<<GetRunInfo()->RUNHEADER_OBT<<" "<<GetRunInfo()->RUNTRAILER_OBT;
2888                }
2889                if(DBG)cout << endl;
2890                if(DBG)cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" (run-entry "<<irun<<")"<<endl;
2891                // ----------------------------------------------------
2892                // update the tracker parameters
2893                // (non ho trovato nessun altro modo sicuro di farlo...)
2894                // ----------------------------------------------------
2895                if(!dbc || (dbc && !dbc->IsConnected()) )SetDBConnection();
2896                TrkParams::Set(GetRunInfo() ,dbc);
2897                if(dbc)dbc->Close();
2898    //          cout << endl;
2899              prevshift = 0;              prevshift = 0;
2900              return true;              return true;
2901          }          }
# Line 2761  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2911  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2911   * @return true if a new run has been read, false if it is still the same run   * @return true if a new run has been read, false if it is still the same run
2912   */   */
2913  Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev){  Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev){
2914    return(UpdateRunInfo((TChain*)run,iev));      return(UpdateRunInfo((TChain*)run,iev));
2915  };  };
2916    
2917  //--------------------------------------  //--------------------------------------
# Line 2771  Bool_t PamLevel2::UpdateRunInfo(TTree *r Line 2921  Bool_t PamLevel2::UpdateRunInfo(TTree *r
2921  /**  /**
2922   * Set which trees shoul be analysed   * Set which trees shoul be analysed
2923   * @param detlist TString containing the sequence of trees required   * @param detlist TString containing the sequence of trees required
2924  */   */
2925  void PamLevel2::SetWhichTrees(TString detlist){  void PamLevel2::SetWhichTrees(TString detlist){
2926            
2927  //    if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){  //    if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){
2928      if( detlist.Contains("+ALL", TString::kIgnoreCase)){      if( detlist.Contains("+ALL", TString::kIgnoreCase)){
2929    
2930          cout << " ======================================================== "<<endl;          cout << " ======================================================== "<<endl;
2931          cout << "                       (( WARNING ))                      "<< endl;          cout << "                       (( WARNING ))                      "<<endl;
2932          cout << " The meaning of the option +ALL has changed!!             "<<endl;          cout << " The meaning of the option +ALL has changed!!             "<<endl;
2933          cout << " Now it includes really all (level0+level1+level2+gpamela)"<<endl;          cout << " Now it includes really all (level0+level1+level2+gpamela)"<<endl;
2934          cout << " and the file is discarded if it does not contain all     "<<endl;          cout << " and the file is discarded if it does not contain         "<<endl;
2935          cout << " trees or level0 files are not available!!                "<<endl;          cout << " all trees or  if level0 files are not available!!        "<<endl;
2936          cout << " ======================================================== "<<endl;          cout << " ======================================================== "<<endl;
2937                            
2938          CAL0 = true;          CAL0 = true;
# Line 2892  void PamLevel2::SetWhichTrees(TString de Line 3042  void PamLevel2::SetWhichTrees(TString de
3042      if( detlist.Contains("-GP", TString::kIgnoreCase) )GP = false;      if( detlist.Contains("-GP", TString::kIgnoreCase) )GP = false;
3043      else if( detlist.Contains("+GP", TString::kIgnoreCase) )GP = true;      else if( detlist.Contains("+GP", TString::kIgnoreCase) )GP = true;
3044    
3045      cout<< "Set detector list from input --> ";      cout<< "tree/branch list from input --> ";
3046      if(TRK0)cout<<"TRK0 ";      if(TRK0)cout<<"TRK0 ";
3047      if(TRK1)cout<<"TRK1 ";      if(TRK1)cout<<"TRK1 ";
3048      if(TRK2)cout<<"TRK2 ";      if(TRK2)cout<<"TRK2 ";
# Line 2952  void  PamLevel2::GetWhichTrees(TFile* f) Line 3102  void  PamLevel2::GetWhichTrees(TFile* f)
3102            
3103      RUN    = false;      RUN    = false;
3104                    
3105      cout << "Checking file: "<<f->GetName()<<endl;  //    cout << "Checking file: "<<f->GetName()<<endl;
3106      if( !f || f->IsZombie() ){      if( !f || f->IsZombie() ){
3107          cout << "File: "<< f->GetName() <<" Non valid root file"<< endl;          cout << "File: "<< f->GetName() <<" Non valid root file"<< endl;
3108          return;          return;
# Line 3071  void  PamLevel2::GetWhichTrees(TFile* f) Line 3221  void  PamLevel2::GetWhichTrees(TFile* f)
3221            
3222  //    delete lk;  //    delete lk;
3223    
3224      cout<< "Get detector list from input file --> ";      cout<< "tree/branch list from file  --> ";
3225      if(TRK1)cout<<"TRK1 ";      if(TRK1)cout<<"TRK1 ";
3226      if(TRK2)cout<<"TRK2 ";      if(TRK2)cout<<"TRK2 ";
3227      if(TRKh)cout<<"TRKH ";      if(TRKh)cout<<"TRKH ";
# Line 3119  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3269  Bool_t  PamLevel2::CheckLevel2File(TStri
3269            
3270      Bool_t SELLI__ok  = false;      Bool_t SELLI__ok  = false;
3271    
3272      cout << "Checking file: "<<name<<endl;  //    cout << "Checking file: "<<name<<endl;
3273      TFile *f = new TFile(name.Data());      TFile *f = new TFile(name.Data());
3274      if( !f || f->IsZombie() ){      if( !f || f->IsZombie() ){
3275          cout << "File: "<< f->GetName() <<" discarded ---- Non valid root file"<< endl; return false;          cout << "File: "<< f->GetName() <<" discarded ---- Non valid root file"<< endl; return false;
# Line 3327  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3477  Bool_t  PamLevel2::CheckLevel2File(TStri
3477    
3478    
3479      if(!RUN__ok) {      if(!RUN__ok) {
3480          cout << "File: "<< f->GetName() <<" *WARNING* ---- Missing RunInfo tree"<< endl;          cout << "File: "<< f->GetName() <<" *WARNING* ---- Missing RunInfo tree (NB: RUN infos will not be updated)"<< endl;
3481  //      return false;          RUN = false;
3482      };      };
3483    
3484      if(CAL1 && !CAL1__ok){      if(CAL1 && !CAL1__ok){
# Line 3451  void PamLevel2::CreateCloneTrees(TFile * Line 3601  void PamLevel2::CreateCloneTrees(TFile *
3601    
3602    
3603  //  if the pointer is null, create a default file  //  if the pointer is null, create a default file
3604        if(!run_tree)return;
3605    
3606      if(!ofile){      if(!ofile){
3607          cout << "void PamLevel2::CreateCloneTrees(TFile*) -- WARNING -- Creating file: clone-tree.root "<<endl;          cout << "void PamLevel2::CreateCloneTrees(TFile*) -- WARNING -- Creating file: clone-tree.root "<<endl;
# Line 3471  void PamLevel2::CreateCloneTrees(TFile * Line 3622  void PamLevel2::CreateCloneTrees(TFile *
3622      // ------------------      // ------------------
3623      // replicate run tree      // replicate run tree
3624      // ------------------      // ------------------
3625      cout << "----------------------------------------------------"<<endl;  //    cout << "----------------------------------------------------"<<endl;
3626      cout << "irun\t | RUN\t NEVENTS\t absolute time"<<endl;  //    cout << "irun\t | RUN\t NEVENTS\t absolute time"<<endl;
3627      for (Int_t i=0; i<run_tree->GetEntries(); i++){      for (Int_t i=0; i<run_tree->GetEntries(); i++){
3628          run_tree->GetEntry(i);          run_tree->GetEntry(i);
3629          cout << i<< "\t | "<<GetRunInfo()->ID<<"\t "<<GetRunInfo()->NEVENTS<< "\t "<<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME<<endl;  //      cout << i<< "\t | "<<GetRunInfo()->ID<<"\t "<<GetRunInfo()->NEVENTS<< "\t "<<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME<<endl;
3630          run_tree_clone->Fill();          run_tree_clone->Fill();
3631      }      }
3632      cout << "----------------------------------------------------"<<endl;      cout << "----------------------------------------------------"<<endl;
# Line 3488  void PamLevel2::CreateCloneTrees(TFile * Line 3639  void PamLevel2::CreateCloneTrees(TFile *
3639    
3640    
3641      sel_tree_clone = new TTree("SelectionList","List of selected events ");      sel_tree_clone = new TTree("SelectionList","List of selected events ");
3642      sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");  //    sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");
3643        sel_tree_clone->Branch("RunEntry",&irunt,"runentry/L");//NEWNEW
3644      sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/L");      sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/L");
3645            
3646    
# Line 3666  Int_t PamLevel2::GetEntry(Long64_t iee){ Line 3818  Int_t PamLevel2::GetEntry(Long64_t iee){
3818          return 0;          return 0;
3819      }      }
3820    
 //    cout << " gp_obj->P0 "<<gp_obj->P0<<endl;  
3821      //      //
3822      // ... that's way I put it here. Notice that nothing change in the code (is backward compatible) since in any case you return with 0.      // ... that's way I put it here. Notice that nothing change in the code (is backward compatible) since in any case you return with 0.
3823      // in theory one would like to return 1 if run is not loaded but now I don't have the will to add that 2 lines of code and it is not      // in theory one would like to return 1 if run is not loaded but now I don't have the will to add that 2 lines of code and it is not
3824      // a problem if you don't check the return code of getentry.      // a problem if you don't check the return code of getentry.
3825      //      //
3826      if(!run_tree ){      if(!RUN || !run_tree ){
3827          if ( TRK0 || CAL0 || TOF0 || RUN ) { //forse cosi` va bene per tornare 1?          if ( TRK0 || CAL0 || TOF0 || RUN ) { //forse cosi` va bene per tornare 1?
3828              cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loaded"<<endl;              cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loaded"<<endl;
3829              return 0;              return 0;
# Line 3815  TTree* PamLevel2::GetYodaTree( ){ Line 3966  TTree* PamLevel2::GetYodaTree( ){
3966  //     }  //     }
3967    
3968      if ( TRK0 ){      if ( TRK0 ){
3969          TrkParams::Load(6);  //      TrkParams::Load(6);
3970          if( !TrkParams::IsLoaded(6) ){  //      if( !TrkParams::IsLoaded(6) ){
3971              cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- VK-mask not loaded"<<endl;  //          cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- VK-mask not loaded"<<endl;
3972          };  //      };
3973          if(!dbc || (dbc && !dbc->IsConnected()))SetDBConnection();  //      if(!dbc || (dbc && !dbc->IsConnected()))SetDBConnection();
3974          TrkParams::SetCalib(run_obj,dbc);          TrkParams::SetCalib(run_obj,dbc);
3975          TrkParams::LoadCalib( );          TrkParams::LoadCalib( );
3976          if( !TrkParams::CalibIsLoaded() ){          if( !TrkParams::CalibIsLoaded() ){
3977              cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- Calibration not loaded"<<endl;              cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- Calibration not loaded"<<endl;
3978          };          };
3979          dbc->Close(); // EMILIANO, do not leave open connections, open only when needed  //      if(dbc)dbc->Close(); // EMILIANO, do not leave open connections, open only when needed
3980      }      }
3981    
3982    
# Line 3894  Int_t PamLevel2::GetYodaEntry(){ Line 4045  Int_t PamLevel2::GetYodaEntry(){
4045      do{      do{
4046          if(shift>0){              if(shift>0){    
4047              cout << " PKTNUM  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;              cout << " PKTNUM  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;
4048              cout << "         RUN: ID "<< GetRunInfo()->ID << " ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<" ID_RUN_FRAG "<<GetRunInfo()->ID_RUN_FRAG << " EV_FROM "<<GetRunInfo()->EV_FROM  <<endl;              if(DBG)cout << "         RUN: ID "<< GetRunInfo()->ID << " ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<" ID_RUN_FRAG "<<GetRunInfo()->ID_RUN_FRAG << " EV_FROM "<<GetRunInfo()->EV_FROM  <<endl;
4049              cout << "         L2 <--> L0 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" prevshift "<<prevshift<<" )"<<endl;              if(DBG)cout << "         L2 <--> L0 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" prevshift "<<prevshift<<" )"<<endl;
4050          }          }
4051          answer = l0_tree->GetEntry(quellagiusta+(Long64_t)shift+(Long64_t)prevshift);          answer = l0_tree->GetEntry(quellagiusta+(Long64_t)shift+(Long64_t)prevshift);
4052          shift++;          shift++;
# Line 3919  Int_t PamLevel2::GetYodaEntry(){ Line 4070  Int_t PamLevel2::GetYodaEntry(){
4070  //      printf(" IDRUN %u \n",GetRunInfo()->ID);  //      printf(" IDRUN %u \n",GetRunInfo()->ID);
4071  //  //
4072          if ( prevshift != 0 && (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() ){          if ( prevshift != 0 && (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() ){
4073            prevshift = 0;              prevshift = 0;
4074            shift = -1;              shift = -1;
4075          };          };
4076    
4077      }while( ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) ||      }while( ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) ||
# Line 3928  Int_t PamLevel2::GetYodaEntry(){ Line 4079  Int_t PamLevel2::GetYodaEntry(){
4079              && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() && shift < maxshift);              && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() && shift < maxshift);
4080    
4081      if ( (quellagiusta+(Long64_t)shift+(Long64_t)prevshift) > GetYodaTree()->GetEntries() || shift == maxshift ) {      if ( (quellagiusta+(Long64_t)shift+(Long64_t)prevshift) > GetYodaTree()->GetEntries() || shift == maxshift ) {
4082          cout << " Big trouble here, no such event in Level0 data! " <<endl;          cout << " Big trouble here, no such event in Level0 data! (NB maxshift set to "<<maxshift<<" )" <<endl;
4083          return 0;          return 0;
4084      }      }
4085  //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;  //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;
# Line 3943  Int_t PamLevel2::GetYodaEntry(){ Line 4094  Int_t PamLevel2::GetYodaEntry(){
4094   */   */
4095  Bool_t PamLevel2::SetDBConnection(){  Bool_t PamLevel2::SetDBConnection(){
4096    
4097      cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;  //    cout << "PamLevel2::SetDBConnection()" << endl;
4098      cout<<"Connecting to DB"<<endl;      if(DBG){
4099      cout<<"HOST "<<host<<endl;          cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
4100      cout<<"USER "<<user<<endl;          cout<<"Connecting to DB"<<endl;
4101      cout<<"PSW  "<<psw<<endl;          cout<<"HOST "<<host<<endl;
4102            cout<<"USER "<<user<<endl;
4103            cout<<"PSW  "<<psw<<endl;
4104        }
4105      dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());      dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
4106      if( !dbc )return false;      if( !dbc )return false;
4107      if( !dbc->IsConnected() )return false;          if( !dbc->IsConnected() )return false;    
# Line 3955  Bool_t PamLevel2::SetDBConnection(){ Line 4109  Bool_t PamLevel2::SetDBConnection(){
4109      myquery.str("");  // EMILIANO      myquery.str("");  // EMILIANO
4110      myquery << "SET time_zone='+0:00'";  // EMILIANO      myquery << "SET time_zone='+0:00'";  // EMILIANO
4111      dbc->Query(myquery.str().c_str());  // EMILIANO      dbc->Query(myquery.str().c_str());  // EMILIANO
4112      cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;      if(DBG)cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
4113      return true;      return true;
4114    
4115  }  }

Legend:
Removed from v.1.54  
changed lines
  Added in v.1.71

  ViewVC Help
Powered by ViewVC 1.1.23