/[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.57 by pam-fi, Tue Nov 27 15:23:02 2007 UTC
# Line 367  void PamTrack::Delete(){ Line 367  void PamTrack::Delete(){
367   * Default Constructor   * Default Constructor
368   */   */
369  PamLevel2::PamLevel2(){  PamLevel2::PamLevel2(){
370    Initialize();      Initialize();
371  };  };
372    
373  /**  /**
# Line 385  PamLevel2::PamLevel2(){ Line 385  PamLevel2::PamLevel2(){
385   * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB   * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB
386   */   */
387  PamLevel2::PamLevel2(TString ddir,TString list,TString detlist){  PamLevel2::PamLevel2(TString ddir,TString list,TString detlist){
388    Initialize();      Initialize();
389    GetPamTree(GetListOfLevel2Files(ddir,list),detlist);      TList*  listf = GetListOfLevel2Files(ddir,list);
390    GetRunTree(GetListOfLevel2Files(ddir,list));      GetPamTree(listf,detlist);
391        GetRunTree(listf);
392  };  };
393    
394  /**  /**
# Line 398  PamLevel2::PamLevel2(TString ddir,TStrin Line 399  PamLevel2::PamLevel2(TString ddir,TStrin
399   * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB   * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB
400   */   */
401  PamLevel2::PamLevel2(TString ddir,TString list){  PamLevel2::PamLevel2(TString ddir,TString list){
402    Initialize();      Initialize();
403    GetPamTree(GetListOfLevel2Files(ddir,list),"");      TList*  listf = GetListOfLevel2Files(ddir,list);
404    GetRunTree(GetListOfLevel2Files(ddir,list));      GetPamTree(listf,"");
405        GetRunTree(listf);
406  };  };
407    
408    
# Line 426  void PamLevel2::Initialize(){ Line 428  void PamLevel2::Initialize(){
428      run_obj   = 0;//new GL_RUN();      run_obj   = 0;//new GL_RUN();
429      soft_obj   = 0;// Emiliano      soft_obj   = 0;// Emiliano
430      irun = -1LL;      irun = -1LL;
431        irunt = -1LL;
432      runfirstentry = 0LL;      runfirstentry = 0LL;
433      runlastentry = 0LL;      runlastentry = 0LL;
434    
# Line 448  void PamLevel2::Initialize(){ Line 451  void PamLevel2::Initialize(){
451    
452      totdltime[0] = 0LL;      totdltime[0] = 0LL;
453      totdltime[1] = 0LL;      totdltime[1] = 0LL;
454        totdltime[2] = 0LL;
455    
456      host = "mysql://localhost/pamelaprod";      host = "mysql://localhost/pamelaprod";
457      user = "anonymous";      user = "anonymous";
# Line 538  void PamLevel2::Delete(){ Line 542  void PamLevel2::Delete(){
542      if(l0_file)l0_file->Close();      if(l0_file)l0_file->Close();
543      //    if(pam_tree)pam_tree->Delete();;      //    if(pam_tree)pam_tree->Delete();;
544    
545    if ( pam_tree ){      if ( pam_tree ){
546      //          //
547      // 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...
548      //          //
549      TList *temp = pam_tree->GetListOfFriends();          TList *temp = pam_tree->GetListOfFriends();
550      TList *contents  = new TList; // create chain friend list          TList *contents  = new TList; // create chain friend list
551      contents->SetOwner();          contents->SetOwner();
552      TIter next(temp);          TIter next(temp);
553      TChain *questo = 0;          TChain *questo = 0;
554      while ( (questo = (TChain*) next()) ){          while ( (questo = (TChain*) next()) ){
555        TString name =  questo->GetName();              TString name =  questo->GetName();
556        contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list              contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list
557      };          };
558      //          //
559      // deleting the main chain          // deleting the main chain
560      //          //
561      pam_tree->Delete();          pam_tree->Delete();
562      //          //
563      // deleting the friends...          // deleting the friends...
564      //          //
565      TIter next2(contents);          TIter next2(contents);
566      TChain *questa = 0;          TChain *questa = 0;
567      while ( questa = (TChain*)next2() ){          while ( questa = (TChain*)next2() ){
568        TString name =  questa->GetName();              TString name =  questa->GetName();
569        questa->Delete();                    questa->Delete();      
570        questa=NULL;              questa=NULL;
571            };
572            //
573      };      };
574      //      pam_tree = NULL;
   };  
   pam_tree = NULL;  
575    
576      if(run_tree)run_tree->Delete();;      if(run_tree)run_tree->Delete();;
577      if(sel_tree)sel_tree->Delete();;      if(sel_tree)sel_tree->Delete();;
# Line 575  void PamLevel2::Delete(){ Line 579  void PamLevel2::Delete(){
579      if(run_tree_clone)run_tree_clone->Delete();;      if(run_tree_clone)run_tree_clone->Delete();;
580      if(sel_tree_clone)sel_tree_clone->Delete();;      if(sel_tree_clone)sel_tree_clone->Delete();;
581            
582        if(irunoffset) delete [] irunoffset;
583    
584  };  };
585    
# Line 621  void PamLevel2::Clear(){ Line 626  void PamLevel2::Clear(){
626  };  };
627    
628  void PamLevel2::Reset(){  void PamLevel2::Reset(){
   //  
   // First of all clear everything  
   //  
   Clear();  
   //  
   // close and reset chains and pointers  
   //      
   if ( pam_tree ){  
629      //      //
630      // 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
631        //
632        Clear();
633        //
634        // close and reset chains and pointers
635        //    
636        if ( pam_tree ){
637            //
638            // 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...
639            //
640            TList *temp = pam_tree->GetListOfFriends();
641            TList *contents  = new TList; // create chain friend list
642            contents->SetOwner();
643            TIter next(temp);
644            TChain *questo = 0;
645            while ( (questo = (TChain*) next()) ){
646                TString name =  questo->GetName();
647                contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list
648            };
649            //
650            // deleting the main chain
651            //
652            pam_tree->Delete();
653            //
654            // deleting the friends...
655            //
656            TIter next2(contents);
657            TChain *questa = 0;
658            while ( questa = (TChain*)next2() ){
659                TString name =  questa->GetName();
660                questa->Delete();      
661                questa=NULL;
662            };
663            //
664        };
665        pam_tree = NULL;
666        //
667        if(run_tree)run_tree->Delete();;
668        run_tree = NULL;
669        if(sel_tree)sel_tree->Delete();;
670        sel_tree = NULL;
671        //
672        // Close file
673        //
674        if(l0_file)l0_file->Close("R");
675        l0_file = NULL;
676        //
677        h0_obj    = 0;
678        trk0_obj  = 0;
679        calo0_obj  = 0;
680        //
681        trk2_obj  = 0;
682        trk1_obj  = 0;
683        trkh_obj  = 0;
684        calo1_obj = 0;
685        calo2_obj = 0;
686        tof_obj   = 0;
687        trig_obj  = 0;
688        s4_obj    = 0;
689        nd_obj    = 0;
690        ac_obj    = 0;
691        orb_obj   = 0;
692        gp_obj    = 0;
693        //
694        // Reset run pointers
695        //
696        run_obj   = 0;//new GL_RUN();
697        soft_obj   = 0;// Emiliano
698        irun = -1;
699        irunt = -1;
700        runfirstentry = 0ULL;
701        runlastentry = 0ULL;    
702        //
703        totdltime[0] = 0LL;
704        totdltime[1] = 0LL;
705        totdltime[2] = 0LL;
706      //      //
     TList *temp = pam_tree->GetListOfFriends();  
     TList *contents  = new TList; // create chain friend list  
     contents->SetOwner();  
     TIter next(temp);  
     TChain *questo = 0;  
     while ( (questo = (TChain*) next()) ){  
       TString name =  questo->GetName();  
       contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list  
     };  
     //  
     // deleting the main chain  
     //  
     pam_tree->Delete();  
     //  
     // deleting the friends...  
     //  
     TIter next2(contents);  
     TChain *questa = 0;  
     while ( questa = (TChain*)next2() ){  
       TString name =  questa->GetName();  
       questa->Delete();        
       questa=NULL;  
     };  
     //  
   };  
   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;  
   //  
707  };  };
708    
709  Bool_t PamLevel2::IsGood(){  Bool_t PamLevel2::IsGood(){
710    Bool_t goodev=true;      Bool_t goodev=true;
711    //  if(trk2_obj && trk2_obj->UnpackError() != 0 ) goodev = false;      //  if(trk2_obj && trk2_obj->UnpackError() != 0 ) goodev = false;
712    if(calo2_obj && calo2_obj->good != 1) goodev = false;      if(calo2_obj && calo2_obj->good != 1) goodev = false;
713    if(tof_obj && tof_obj->unpackError != 0) goodev = false;        if(tof_obj && tof_obj->unpackError != 0) goodev = false;  
714    if(trig_obj && trig_obj->unpackError != 0) goodev = false;      if(trig_obj && trig_obj->unpackError != 0) goodev = false;
715    if(s4_obj && s4_obj->unpackError != 0) goodev = false;        if(s4_obj && s4_obj->unpackError != 0) goodev = false;  
716    if(nd_obj && nd_obj->unpackError != 0) goodev = false;        if(nd_obj && nd_obj->unpackError != 0) goodev = false;  
717    if(ac_obj && ac_obj->unpackError != 255) goodev = false;        if(ac_obj && ac_obj->unpackError != 255) goodev = false;  
718      //  if(orb_obj)        //  if(orb_obj)  
719    return goodev;      return goodev;
720  };  };
721    
722  //--------------------------------------  //--------------------------------------
# Line 795  void *PamLevel2::GetPointerTo(const char Line 802  void *PamLevel2::GetPointerTo(const char
802   * Retrieves the calorimeter track matching the seqno-th tracker stored track.   * Retrieves the calorimeter track matching the seqno-th tracker stored track.
803   * (If seqno = -1 retrieves the self-trigger calorimeter track)   * (If seqno = -1 retrieves the self-trigger calorimeter track)
804   */   */
805   CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){  CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){
806            
807       if( !calo2_obj )return 0;      if( !calo2_obj )return 0;
808    
809       if( calo2_obj->CaloLevel2::ntrk()==0 ){      if( calo2_obj->CaloLevel2::ntrk()==0 ){
810           cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<<endl;          cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<<endl;
811           return NULL;          return NULL;
812       };      };
813            
814       CaloTrkVar *c = 0;      CaloTrkVar *c = 0;
815       Int_t it_calo=0;      Int_t it_calo=0;
816            
817       do{      do{
818           c = calo2_obj->CaloLevel2::GetCaloTrkVar(it_calo);          c = calo2_obj->CaloLevel2::GetCaloTrkVar(it_calo);
819           it_calo++;          it_calo++;
820       } while( c && seqno != c->trkseqno && it_calo < calo2_obj->CaloLevel2::ntrk());          } while( c && seqno != c->trkseqno && it_calo < calo2_obj->CaloLevel2::ntrk());    
821            
822       if(!c || seqno != c->trkseqno){      if(!c || seqno != c->trkseqno){
823           c = 0;          c = 0;
824           if(seqno!=-1)cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match Calorimeter stored tracks"<<endl;          if(seqno!=-1)cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match Calorimeter stored tracks"<<endl;
825       };      };
826       return c;      return c;
827            
828   };  };
829  //--------------------------------------  //--------------------------------------
830   //  //
831   //  //
832  //--------------------------------------  //--------------------------------------
833  /**  /**
834    * Retrieves the ToF track matching the seqno-th tracker stored track.   * Retrieves the ToF track matching the seqno-th tracker stored track.
835    * (If seqno = -1 retrieves the tracker-independent tof track)   * (If seqno = -1 retrieves the tracker-independent tof track)
836   */   */
837   ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){  ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){
838                    
839       if( !tof_obj )return 0;      if( !tof_obj )return 0;
840    
841       if( tof_obj->ToFLevel2::ntrk()==0 ){      if( tof_obj->ToFLevel2::ntrk()==0 ){
842           cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no ToF tracks are stored"<<endl;          cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no ToF tracks are stored"<<endl;
843           return NULL;          return NULL;
844       };      };
845            
846       ToFTrkVar *c = 0;      ToFTrkVar *c = 0;
847       Int_t it_tof=0;      Int_t it_tof=0;
848            
849       do{      do{
850           c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);          c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);
851           it_tof++;          it_tof++;
852       } while( c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());              } while( c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());
853            
854       if(!c || seqno != c->trkseqno){      if(!c || seqno != c->trkseqno){
855           c = 0;          c = 0;
856           if(seqno!=-1)cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match ToF stored tracks"<<endl;          if(seqno!=-1)cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match ToF stored tracks"<<endl;
857       };      };
858       return c;      return c;
859            
860   };  };
861    
862  //--------------------------------------  //--------------------------------------
863   //  //
864   //  //
865  //--------------------------------------  //--------------------------------------
866  /**  /**
867   * 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 and tof track information.
868   */   */
869   PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){  PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){
870            
871       cout <<"PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** "<<endl;      cout <<"PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** "<<endl;
872       cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;      cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;
873    
874       CaloTrkVar *c = 0;      CaloTrkVar *c = 0;
875       ToFTrkVar  *o = 0;      ToFTrkVar  *o = 0;
876            
877       if(CAL2) c = GetCaloStoredTrack(t->GetSeqNo());      if(CAL2) c = GetCaloStoredTrack(t->GetSeqNo());
878       if(TOF) o = GetToFStoredTrack(t->GetSeqNo());      if(TOF) o = GetToFStoredTrack(t->GetSeqNo());
879            
880  //    if(t && c && o)track = new PamTrack(t,c,o);  //    if(t && c && o)track = new PamTrack(t,c,o);
881       PamTrack *track = new PamTrack(t,c,o);      PamTrack *track = new PamTrack(t,c,o);
882            
883       return track;      return track;
884    
885   };  };
886  //--------------------------------------  //--------------------------------------
887  //  //
888  //  //
# Line 911  PamTrack* PamLevel2::GetStoredTrack(Int_ Line 918  PamTrack* PamLevel2::GetStoredTrack(Int_
918  //  //
919    
920  /**  /**
921   * 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.
922   **/   **/
923  void PamLevel2::SortTracks(TString how){  void PamLevel2::SortTracks(TString how){
924    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());
925    howtosort = how;        howtosort = how;  
926    SortTracks();      SortTracks();
927  };  };
928    
929  //  //
930  //--------------------------------------  //--------------------------------------
931  /**  /**
932   * Sort physical (tracker) tracks and stores them in the TRefArray (of TrkTrack objects) which pointer is  PamLevel2::sorted_tracks.   * Sort physical (tracker) tracks.
933   * @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...).
934   * Sorting cryteria:   * Sorting cryteria:
935   * TRK: lower chi**2   * TRK: lower chi**2
936   * CAL: lower Y spatial residual on the first calorimeter plane   * CAL: lower Y spatial residual on the first calorimeter plane
937   * 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).
938     * S1: (ask Emiliano)
939     * S2: (ask Emiliano)
940     * S3: (ask Emiliano)
941     * GP: more GP hits
942   * The default sorting cryterium is "TOF+CAL".   * The default sorting cryterium is "TOF+CAL".
943   *   *
944   * 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).
945   */   */
946  void PamLevel2::SortTracks(){  void PamLevel2::SortTracks(){
947    TString how = howtosort;      TString how = howtosort;
948    
949        //  cout <<" PamLevel2::SortTracks(TString how) "<<endl;
950        if( !trk2_obj ){
951            cout << "void PamLevel2::SortTracks():  TrkLevel2 not loaded !!!";
952            return;
953        };
954        //Save current Object count
955        Int_t ObjectNumber = TProcessID::GetObjectCount();
956    
957    //  cout <<" PamLevel2::SortTracks(TString how) "<<endl;      // create TCloneArrays to store tracks and its images
958    if( !trk2_obj ){      if(!tsorted)tsorted = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
959      cout << "void PamLevel2::SortTracks():  TrkLevel2 not loaded !!!";      tsorted->Delete();
960      return;      TClonesArray &ttsorted = *tsorted;
961    };  
962    //    cout << "call SortTracs() "<<endl;      if(!timage)timage = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
963    //Save current Object count      timage->Delete();
964    Int_t ObjectNumber = TProcessID::GetObjectCount();      TClonesArray &ttimage = *timage;
   
   //    cout << "ObjectNumber  "<<ObjectNumber <<endl;  
   
   //     if(!sorted_tracks)sorted_tracks = new TRefArray();  
   //     sorted_tracks->Clear();  
   //    sorted_tracks.Clear();  
   
   if(!tsorted)tsorted = new TClonesArray("PamTrack",trk2_obj->GetNTracks());  
   tsorted->Delete();  
   TClonesArray &ttsorted = *tsorted;  
   if(!timage)timage = new TClonesArray("PamTrack",trk2_obj->GetNTracks());  
   timage->Delete();  
   TClonesArray &ttimage = *timage;  
965    
966    
967    
968    //--------------------------------------------------      //--------------------------------------------------
969    // retrieve sorting method      // retrieve sorting method
970    //--------------------------------------------------      //--------------------------------------------------
971    Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);      Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
972    Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);      Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
973    Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);      Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
974    Bool_t use_S1 = how.Contains("S1", TString::kIgnoreCase);      Bool_t use_S1 = how.Contains("S1", TString::kIgnoreCase);
975    Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase);      Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase);
976    Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase);      Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase);
977        Bool_t use_GP = how.Contains("GP", TString::kIgnoreCase);
978        
979    if ( use_TOF ){      if ( use_TOF ){
980      use_S1 = true;          use_S1 = true;
981      use_S2 = true;          use_S2 = true;
982      use_S3 = true;          use_S3 = true;
983    };      };
984    if( !CAL2 &&  use_CAL) use_CAL = false;      if( !CAL2 &&  use_CAL) use_CAL = false;
985    if( !TOF ){      if( !TOF ){
986      use_TOF = false;          use_TOF = false;
987      use_S1  = false;          use_S1  = false;
988      use_S2  = false;          use_S2  = false;
989      use_S3  = false;          use_S3  = false;
990    }      }
991        if( !GP ){
992    if( !TRK2 ){          use_GP  = false;
993      //  cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;      }
994      return;  
995    };      if( !TRK2 ){
996            cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;
997            return;
998        };
999    
1000    //   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;
1001        
1002    
1003    //--------------------------------------------------      //--------------------------------------------------
1004    // loop over "physical" tracks sorted by the tracker      // loop over "physical" tracks sorted by the tracker
1005    //--------------------------------------------------      //--------------------------------------------------
1006    for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){      for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){
1007                    
1008      TrkTrack   *ts = 0;          TrkTrack   *ts = 0;
1009      CaloTrkVar *cs = 0;          CaloTrkVar *cs = 0;
1010      ToFTrkVar  *os = 0;          ToFTrkVar  *os = 0;
1011                    
1012      // get tracker tracks          // get tracker tracks
1013      TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker          TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker
1014      CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());          CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());
1015      ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());          ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());
1016    
1017      TrkTrack   *ti = 0; //tracker (image)          TrkTrack   *ti = 0; //tracker (image)
1018      CaloTrkVar *ci = 0;          CaloTrkVar *ci = 0;
1019      ToFTrkVar  *oi = 0;          ToFTrkVar  *oi = 0;
1020      //  cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;          //      cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
1021      // if track has an image, check image selection          // if track has an image, check image selection
1022    
1023      Int_t tp_score = 0;  //main track sorted by the tracker          Int_t tp_score = 0;  //main track sorted by the tracker
1024      Int_t ti_score = 0;  //image track          Int_t ti_score = 0;  //image track
1025      Int_t totp_score = 0;  //main track sorted by the tracker          Int_t totp_score = 0;  //main track sorted by the tracker
1026      Int_t toti_score = 0;  //image track          Int_t toti_score = 0;  //image track
1027    
1028      if(tp->HasImage()){          if(tp->HasImage()){
1029                            
1030        ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image)              ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image)
1031        ci = GetCaloStoredTrack(ti->GetSeqNo());              ci = GetCaloStoredTrack(ti->GetSeqNo());
1032        oi = GetToFStoredTrack(ti->GetSeqNo());              oi = GetToFStoredTrack(ti->GetSeqNo());
1033                            
1034        //            cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;              //      cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;
1035    
1036        //assign starting scores              //assign starting scores
1037        tp_score = 0;  //main track sorted by the tracker              tp_score = 0;  //main track sorted by the tracker
1038        ti_score = 0;  //image track              ti_score = 0;  //image track
1039                            
1040        // -----------------------------------------------------------------------------------------              // -----------------------------------------------------------------------------------------
1041        // calorimeter check              // *****************************************************************************************
1042        // -----------------------------------------------------------------------------------------              // -----------------------------------------------------------------------------------------
1043        // check the Y spatial residual on the first calorimeter plane              // calorimeter check
1044        // (cut on calorimeter variables from Emiliano)              // -----------------------------------------------------------------------------------------
1045        if( use_CAL && !calo2_obj ){              if( use_CAL && !calo2_obj ){
1046          cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but CaloLevel2 not loaded !!!";                  cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but CaloLevel2 not loaded !!!";
1047          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);  
               };  
1048              };              };
1049            };              if( use_CAL && !cp &&  ci ){
1050            if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){                  ti_score++;
1051              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);  
               };  
1052              };              };
1053            };              if( use_CAL &&  cp && !ci ){
1054            if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){                  tp_score++;
1055              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);  
               };  
1056              };              };
1057            };              if(
1058                    use_CAL            &&
1059                    cp && ci &&
1060                    true){
1061    
1062                    
1063                    if(
1064                        cp->npresh > ci->npresh &&
1065                        true){
1066                        tp_score++;
1067                        totp_score++;
1068                    };
1069                    if(
1070                        cp->npresh < ci->npresh &&
1071                        true){
1072                        ti_score++;
1073                        toti_score++;
1074                    };
1075    
1076                    //      cout << "CALO "<<tp_score<<ti_score<<endl;
1077    
           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);  
1078              };              };
1079            };              // -----------------------------------------------------------------------------------------
1080            //              // *****************************************************************************************
1081            ti->DoTrack2(tr);              // -----------------------------------------------------------------------------------------
1082            //              // TOF check
1083            if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){              // -----------------------------------------------------------------------------------------
1084              for (Int_t ih=0; ih < oi->npmtadc; ih++){              // check the number of hit pmts along the track
1085                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );              // on S12 S21 and S32, where paddles are parallel to Y axis
1086                if(pl == 0){              if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !tof_obj ){
1087                  nphit_i++;                  cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but ToFLevel2 not loaded !!!";
1088                  enhit_i += (op->dedx).At(ih);                  return;
               };  
1089              };              };
1090            };              //
1091            if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){              if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !op && oi ){
1092              for (Int_t ih=0; ih < oi->npmtadc; ih++){                  ti_score++;
1093                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );                  toti_score++;
               if(pl == 3){  
                 nphit_i++;  
                 enhit_i += (op->dedx).At(ih);  
               };  
1094              };              };
1095            };              if( (use_TOF || use_S1 || use_S2 || use_S3 ) && op && !oi ){
1096            if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){                  tp_score++;
1097              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);  
               };  
1098              };              };
1099            };                          if( (use_TOF || use_S1 || use_S2 || use_S3 ) && op && oi ){
1100                    //
1101                    Float_t sen = 0.;
1102                    for (Int_t ih=0; ih < op->npmtadc; ih++){
1103                        Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1104                        if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (op->dedx).At(ih);
1105                    };
1106                    for (Int_t ih=0; ih < oi->npmtadc; ih++){
1107                        Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1108                        if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (oi->dedx).At(ih);
1109                    };
1110                    //
1111                    if (  sen >= sortthr && false){ // temporary disabled NUCLEI special algorithm since the new one should work for every particle (to be checked!)
1112                        //printf(" IS A NUCLEUS! en = %f \n",sen);
1113                        //
1114                        // is a nucleus use a different algorithm
1115                        //
1116                        Int_t nz = 6; Float_t zin[6];                                          // << define TOF z-coordinates
1117                        for(Int_t ip=0; ip<nz; ip++)
1118                            zin[ip] = tof_obj->ToFLevel2::GetZTOF(tof_obj->ToFLevel2::GetToFPlaneID(ip));     // << read ToF plane z-coordinates
1119                        Trajectory *tr = new Trajectory(nz,zin);
1120                        //
1121                        Int_t nphit_p =0;
1122                        Int_t nphit_i =0;
1123                        Float_t enhit_p = 0.;
1124                        Float_t enhit_i = 0.;
1125                        //
1126                        for (Int_t ih=0; ih < op->npmtadc; ih++){
1127                            Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1128                            if(pl == 1 || pl == 2 || pl == 5){
1129                                nphit_p++;
1130                                enhit_p += (op->dedx).At(ih);
1131                            };
1132                        };
1133                        //
1134                        tp->DoTrack2(tr);
1135                        //
1136                        if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){
1137                            for (Int_t ih=0; ih < op->npmtadc; ih++){
1138                                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1139                                if(pl == 0){
1140                                    nphit_p++;
1141                                    enhit_p += (op->dedx).At(ih);
1142                                };
1143                            };
1144                        };
1145                        if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){
1146                            for (Int_t ih=0; ih < op->npmtadc; ih++){
1147                                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1148                                if(pl == 3){
1149                                    nphit_p++;
1150                                    enhit_p += (op->dedx).At(ih);
1151                                };
1152                            };
1153                        };
1154                        if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
1155                            for (Int_t ih=0; ih < op->npmtadc; ih++){
1156                                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1157                                if(pl == 4){
1158                                    nphit_p++;
1159                                    enhit_p += (op->dedx).At(ih);
1160                                };
1161                            };
1162                        };
1163    
1164                        for (Int_t ih=0; ih < oi->npmtadc; ih++){
1165                            Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1166                            if(pl == 1 || pl == 2 || pl == 5){
1167                                nphit_i++;  
1168                                enhit_i += (op->dedx).At(ih);
1169                            };
1170                        };
1171                        //
1172                        ti->DoTrack2(tr);
1173                        //
1174                        if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){
1175                            for (Int_t ih=0; ih < oi->npmtadc; ih++){
1176                                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1177                                if(pl == 0){
1178                                    nphit_i++;
1179                                    enhit_i += (op->dedx).At(ih);
1180                                };
1181                            };
1182                        };
1183                        if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){
1184                            for (Int_t ih=0; ih < oi->npmtadc; ih++){
1185                                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1186                                if(pl == 3){
1187                                    nphit_i++;
1188                                    enhit_i += (op->dedx).At(ih);
1189                                };
1190                            };
1191                        };
1192                        if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
1193                            for (Int_t ih=0; ih < oi->npmtadc; ih++){
1194                                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1195                                if(pl == 4){
1196                                    nphit_i++;
1197                                    enhit_i += (op->dedx).At(ih);
1198                                };
1199                            };
1200                        };          
1201    
1202                                    
1203            if(                      if(
1204               (use_TOF || use_S1 || use_S2 || use_S3)            &&                          (use_TOF || use_S1 || use_S2 || use_S3)            &&
1205               (nphit_p+nphit_i) !=0 &&                            (nphit_p+nphit_i) !=0 &&        
1206               true){                          true){
1207                                            
1208              //      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);
1209              //      printf(" score p %i score i %i \n",tp_score,ti_score);                          //          printf(" score p %i score i %i \n",tp_score,ti_score);
1210              //            if( enhit_p > enhit_i ) tp_score++;                          //                if( enhit_p > enhit_i ) tp_score++;
1211              //            if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;                          //                if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;
1212              if ( nphit_p > nphit_i ) tp_score++;                          if ( nphit_p > nphit_i ) tp_score++;
1213              if ( nphit_p < nphit_i ) ti_score++;                          if ( nphit_p < nphit_i ) ti_score++;
1214              if ( nphit_p == nphit_i ){                          if ( nphit_p == nphit_i ){
1215                if ( enhit_p > enhit_i ) tp_score++;                              if ( enhit_p > enhit_i ) tp_score++;
1216                else ti_score++;                              else ti_score++;
1217              };                          };
1218              //      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);
1219            };                      };
1220            delete tr;                      delete tr;
1221            //                      //
1222          } else {                  } else {
1223            //                      // -------------
1224            // NOT a NUCLEUS                      // NOT a NUCLEUS
1225            //                      // -------------
1226            //printf(" NOT a NUCLEUS! en = %f \n",sen);                      //printf(" NOT a NUCLEUS! en = %f \n",sen);
1227    
1228            Int_t nphit_p =0;                      Int_t nphit_p =0;
1229            Int_t nphit_i =0;                      Int_t nphit_i =0;
1230                                    
1231                                    
1232            /*                            cout << "track: npmtadc "<< op->npmtadc << endl;                      /*                          cout << "track: npmtadc "<< op->npmtadc << endl;
1233              cout << "track: npmttdc "<< op->npmttdc << endl;                                                  cout << "track: npmttdc "<< op->npmttdc << endl;
1234              cout << "image: npmtadc "<< oi->npmtadc << endl;                                                  cout << "image: npmtadc "<< oi->npmtadc << endl;
1235              cout << "image: npmttdc "<< oi->npmttdc << endl;*/                                                  cout << "image: npmttdc "<< oi->npmttdc << endl;*/
1236                                    
1237  //        for (Int_t ih=0; ih < op->npmtadc; ih++){  //        for (Int_t ih=0; ih < op->npmtadc; ih++){
1238  //          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 1243  void PamLevel2::SortTracks(){
1243  //          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );  //          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1244  //          if(pl == 1 || pl == 2 || pl == 5)nphit_i++;  //          if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
1245  //        };  //        };
1246            // --- modified to count tdc signals (more efficient?)                      // --- modified to count tdc signals (more efficient?)
1247            // --- and to implement check on tdcflag                      // --- and to implement check on tdcflag
1248            for (Int_t ih=0; ih < op->npmttdc; ih++){                      for (Int_t ih=0; ih < op->npmttdc; ih++){
1249              Int_t pl = tof_obj->GetPlaneIndex( (op->pmttdc).At(ih) );                          Int_t pl = tof_obj->GetPlaneIndex( (op->pmttdc).At(ih) );
1250  //          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++;
1251              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 )) ){
1252                if( (op->tdcflag).At(ih)==0 )nphit_p++;                              if( (op->tdcflag).At(ih)==0 )nphit_p++;
1253              };                          };
1254            };                      };
1255                                    
1256            for (Int_t ih=0; ih < oi->npmttdc; ih++){                      for (Int_t ih=0; ih < oi->npmttdc; ih++){
1257              Int_t pl = tof_obj->GetPlaneIndex( (oi->pmttdc).At(ih) );                          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmttdc).At(ih) );
1258  //          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++;  
1259              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 )) ){
1260                if( (oi->tdcflag).At(ih)==0 )nphit_i++;                                if( (oi->tdcflag).At(ih)==0 )nphit_i++;    
1261              };                          };
1262            };                      };
1263                                    
1264            if(                      if(
1265               (nphit_p+nphit_i) !=0 &&                            (nphit_p+nphit_i) !=0 &&        
1266               true){                          true){
1267                                            
1268              if ( nphit_p != nphit_i ){                          if ( nphit_p != nphit_i ){
1269                totp_score += nphit_p;                              totp_score += nphit_p;
1270                toti_score += nphit_i;                              toti_score += nphit_i;
1271                tp_score+=nphit_p;                              tp_score+=nphit_p;
1272                ti_score+=nphit_i;                              ti_score+=nphit_i;
1273                            };
1274                            //          if     ( nphit_p > nphit_i) tp_score+=nphit_p;
1275                            //          else if( nphit_p < nphit_i) ti_score+=nphit_i;
1276                            //          else ;//niente
1277                        };
1278                    };
1279                    //      cout << "TOF "<<tp_score<<ti_score<<endl;
1280              };              };
             //      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;  
       };  
1281    
1282    
1283  //      if(tp_score == ti_score) use_TRK = true;  //      if(tp_score == ti_score) use_TRK = true;
1284    
1285    
1286        // -----------------------------------------------------------------------------------------              // -----------------------------------------------------------------------------------------
1287        // tracker check              // *****************************************************************************************
1288        // -----------------------------------------------------------------------------------------              // -----------------------------------------------------------------------------------------
1289        // chi**2 difference is not always large enough to distinguish among              // tracker check
1290        // the real track and its image.              // -----------------------------------------------------------------------------------------
1291        // Tracker check will be applied always when calorimeter and tof information is ambiguous.              // chi**2 difference is not always large enough to distinguish among
1292        // *** MODIFIED ON AUGUST 2007 ***              // the real track and its image.
1293        if(use_TRK){              // Tracker check will be applied always when calorimeter and tof information is ambiguous.
1294                // *** MODIFIED ON AUGUST 2007 ***
1295                if(use_TRK){
1296  //      if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;  //      if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
1297  //      else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;  //      else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
1298    
1299            // CHECK 1 : number of points along X                    // CHECK 1 : number of points along X  
1300          if ( tp->GetNX() >= ti->GetNX() ){                  if ( tp->GetNX() >= ti->GetNX() ){
1301            tp_score++ ;                      tp_score++ ;
1302            totp_score++ ;                      totp_score++ ;
1303          };                  };
1304          if ( tp->GetNX() <= ti->GetNX() ){                  if ( tp->GetNX() <= ti->GetNX() ){
1305            ti_score++ ;                      ti_score++ ;
1306            toti_score++ ;                      toti_score++ ;
1307          };                  };
1308            // CHECK 2 : number of points along Y                    // CHECK 2 : number of points along Y  
1309          if ( tp->GetNY() >= ti->GetNY() ){                  if ( tp->GetNY() >= ti->GetNY() ){
1310            tp_score++ ;                      tp_score++ ;
1311            totp_score++ ;                      totp_score++ ;
1312          };                  };
1313          if ( tp->GetNY() <= ti->GetNY() ){                  if ( tp->GetNY() <= ti->GetNY() ){
1314            ti_score++ ;                      ti_score++ ;
1315            toti_score++ ;                      toti_score++ ;
1316          };                  };
           // 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++ ;  
1317    
1318          //      cout << "TRK "<<tp_score<<ti_score<<endl;                  //      cout << "TRK "<<tp_score<<ti_score<<endl;
1319        };              };
1320                            
1321    
1322                // -----------------------------------------------------------------------------------------
1323                // *****************************************************************************************
1324                // -----------------------------------------------------------------------------------------
1325                // GPamela check
1326                // -----------------------------------------------------------------------------------------
1327                
1328                //---------------------------------------------------
1329                // count the number of GP hits
1330                //---------------------------------------------------
1331                if(use_GP){
1332                    int ngphits_p=0;
1333                    int ngphits_i=0;
1334                    float toll = 0.02; //200 micron
1335                    for(int ih=0; ih<GetGPamela()->Nthspe; ih++){
1336                        int ip = (Int_t) GetGPamela()->Itrpb[ih] - 1;
1337                        if(
1338                            tp &&
1339                            tp->YGood(ip) &&
1340                            fabs(tp->ym[ip]- GetGPamela()->Yavspe[ih])<toll &&
1341                            true) ngphits_p++;
1342                        if( ti &&
1343                            ti->YGood(ip) &&
1344                            fabs(ti->ym[ip]- GetGPamela()->Yavspe[ih])<toll &&
1345                            true) ngphits_i++;
1346                    }
1347                    if(
1348                        ngphits_p > ngphits_i &&
1349                        true){
1350                        tp_score++ ;
1351                        totp_score++ ;                  
1352                    }
1353                    if(
1354                        ngphits_p < ngphits_i &&
1355                        true){
1356                        ti_score++ ;
1357                        toti_score++ ;                  
1358                    }
1359                }
1360    
1361    
1362        // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*              // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1363        // the winner is....              // the winner is....
1364        // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*              // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1365        if      (tp_score > ti_score) {              if      (tp_score > ti_score) {
1366                    
1367    
1368        }else if (tp_score < ti_score) {              }else if (tp_score < ti_score) {
1369    
1370    
1371          ts = ti;//its image!!                  ts = ti;//its image!!
1372          cs = ci;                  cs = ci;
1373          os = oi;                  os = oi;
1374          Int_t totis = toti_score;                  Int_t totis = toti_score;
1375    
1376          ti = tp;//its image!!                  ti = tp;//its image!!
1377          ci = cp;                  ci = cp;
1378          oi = op;                  oi = op;
1379    
1380          tp = ts;//its image!!                  tp = ts;//its image!!
1381          cp = cs;                  cp = cs;
1382          op = os;                  op = os;
1383    
1384          toti_score = totp_score;                  toti_score = totp_score;
1385          totp_score = totis;                  totp_score = totis;
1386    
1387                                    
1388        }else {              }else {
1389    
1390  //      cout << "Warning - track image ambiguity not solved" << endl;  //      cout << "Warning - track image ambiguity not solved" << endl;
1391    
1392        };              };
1393                            
1394      }else{          }else{
1395        totp_score = 1;              totp_score = 1;
1396        toti_score = 0;              toti_score = 0;
1397                
1398        //            ts = tp;              //      ts = tp;
1399        //            cs = cp;              //      cs = cp;
1400        //            os = op;              //      os = op;
1401      };          };
1402                    
1403      //  cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;          //      cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
1404      //  sorted_tracks->Add(ts);//save the track in the sorted array          //      sorted_tracks->Add(ts);//save the track in the sorted array
1405      //  sorted_tracks.Add(ts);//save the track in the sorted array          //      sorted_tracks.Add(ts);//save the track in the sorted array
1406      //  sorted_tracks.Add(tp);//save the track in the sorted array          //      sorted_tracks.Add(tp);//save the track in the sorted array
1407      //  cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;          //      cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
1408      //  cout<<"o "<<tp<<endl;          //      cout<<"o "<<tp<<endl;
1409      //  cout<<"o "<<cp<<endl;          //      cout<<"o "<<cp<<endl;
1410      //  cout<<"o "<<op<<endl;          //      cout<<"o "<<op<<endl;
1411    
1412      new(ttsorted[i]) PamTrack(tp,cp,op);          new(ttsorted[i]) PamTrack(tp,cp,op);
1413      new(ttimage[i])  PamTrack(ti,ci,oi);          new(ttimage[i])  PamTrack(ti,ci,oi);
1414    
1415      ((PamTrack*)(ttsorted[i]))->SetPScore(totp_score);          ((PamTrack*)(ttsorted[i]))->SetPScore(totp_score);
1416      ((PamTrack*)(ttsorted[i]))->SetIScore(toti_score);          ((PamTrack*)(ttsorted[i]))->SetIScore(toti_score);
1417      ((PamTrack*)(ttimage[i]))->SetPScore(totp_score);          ((PamTrack*)(ttimage[i]))->SetPScore(totp_score);
1418      ((PamTrack*)(ttimage[i]))->SetIScore(toti_score);          ((PamTrack*)(ttimage[i]))->SetIScore(toti_score);
1419    };      };
1420    
1421    if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){      if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){
1422      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;
1423      tsorted->Delete(); tsorted=0;          tsorted->Delete(); tsorted=0;
1424      timage->Delete(); timage=0;          timage->Delete(); timage=0;    
1425    }      }
1426    
1427    //Restore Object count      //Restore Object count
1428    //To save space in the table keeping track of all referenced objects      //To save space in the table keeping track of all referenced objects
1429    //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.
1430    TProcessID::SetObjectCount(ObjectNumber);      TProcessID::SetObjectCount(ObjectNumber);
1431            
1432  };  };
1433  //--------------------------------------  //--------------------------------------
# Line 1417  TClonesArray *PamLevel2::GetTracks(){ Line 1456  TClonesArray *PamLevel2::GetTracks(){
1456    
1457      return tsorted;      return tsorted;
1458            
1459   };  };
1460  //--------------------------------------  //--------------------------------------
1461   //  //
1462   //  //
1463  //--------------------------------------  //--------------------------------------
1464  /**  /**
1465   * Retrieves the it-th Pamela "physical" track.   * Retrieves the it-th Pamela "physical" track.
# Line 1552  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1591  TTree *PamLevel2::GetPamTree(TFile *f, T
1591          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 ");
1592          return pam_tree;          return pam_tree;
1593      };      };
1594    //      //
1595    
1596      cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;      cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;
1597    
# Line 1698  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1737  TTree *PamLevel2::GetPamTree(TFile *f, T
1737    
1738      TTree *L = (TTree*)f->Get("SelectionList");      TTree *L = (TTree*)f->Get("SelectionList");
1739      if(L && SELLI==1) {      if(L && SELLI==1) {
1740  //      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;  
1741          sel_tree = 0;          sel_tree = 0;
1742      }else{      }else{
1743          cout << "SelectionList  : missing tree"<<endl;          cout << "SelectionList  : missing tree"<<endl;
# Line 1749  TList*  PamLevel2::GetListOfLevel2Files( Line 1782  TList*  PamLevel2::GetListOfLevel2Files(
1782      //    if(ddir=="")ddir = wdir;      //    if(ddir=="")ddir = wdir;
1783  //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);  //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
1784      if ( ddir != ""){      if ( ddir != ""){
1785        cout << "Level2 data directory : "<<  ddir << endl;          cout << "Level2 data directory : "<<  ddir << endl;
1786      } else {      } else {
1787        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;
1788      };      };
1789      TList *contents  = new TList; // create output list      TList *contents  = new TList; // create output list
1790      contents->SetOwner();      contents->SetOwner();
# Line 1768  TList*  PamLevel2::GetListOfLevel2Files( Line 1801  TList*  PamLevel2::GetListOfLevel2Files(
1801  //          return 0;  //          return 0;
1802  //      }        //      }      
1803  //      flisttxt = fullpath;  //      flisttxt = fullpath;
1804        if ( !flisttxt.EndsWith(".root") ){          if ( !flisttxt.EndsWith(".root") ){
1805    
1806          flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));              flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1807    
1808          if( !gSystem->ChangeDirectory(ddir) ){              if( !gSystem->ChangeDirectory(ddir) ){
1809              cout << "Cannot change directory : "<<ddir<<endl;                  cout << "Cannot change directory : "<<ddir<<endl;
1810              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;  
1811              }              }
1812              if(file.Contains("#"))file = file(0,file.First("#"));          
1813                cout <<"Input file list : " << flisttxt <<endl;
1814                ifstream in;
1815                in.open(flisttxt, ios::in); //open input file list
1816                if(!in.good()){
1817                    cout <<" ERROR opening the file "<<endl;
1818                    gSystem->ChangeDirectory(wdir); // back to the working directory
1819                    return 0;
1820                }  
1821                int line=0;
1822                while (1) {
1823                    TString file;
1824                    in >> file;
1825                    if (!in.good()) break;
1826                    line++;
1827    //          cout <<"(1) " << file << endl;
1828                    if(file.IsNull()){
1829                        cout << "-- list interrupted at line "<<line <<endl;
1830                        break;
1831                    }
1832                    if(file.Contains("#"))file = file(0,file.First("#"));
1833  //          cout <<"(2) " << file << endl;  //          cout <<"(2) " << file << endl;
1834  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){
1835  //          if( (fullpath = gSystem->FindFile(ddir,file)) ){  //          if( (fullpath = gSystem->FindFile(ddir,file)) ){
1836              if( file.EndsWith(".root") ){                  if( file.EndsWith(".root") ){
1837                TString filedir;                      TString filedir;
1838                if (ddir != ""){                      if (ddir != ""){
1839                  filedir = ddir; // take the input dir                          filedir = ddir; // take the input dir
1840                } else {                      } else {
1841                  gSystem->ChangeDirectory(wdir); // back to the working directory                          gSystem->ChangeDirectory(wdir); // back to the working directory
1842                  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
1843                };                      };
1844                  char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir),gSystem->BaseName(file));                      char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir),gSystem->BaseName(file));
1845                  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
1846                  delete fullpath;                      delete fullpath;
1847              }                  }
1848  //          }else{  //          }else{
1849  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;
1850  //          };  //          };
1851          };              };
1852          in.close();              in.close();
1853        } else {          } else {
1854            if(flisttxt.Contains("#"))flisttxt = flisttxt(0,flisttxt.First("#"));              if(flisttxt.Contains("#"))flisttxt = flisttxt(0,flisttxt.First("#"));
1855            char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));              char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1856            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
1857            delete fullpath;              delete fullpath;
1858        };                  };      
1859      }else{      }else{
1860                    
1861          cout << "No input file list given."<<endl;          cout << "No input file list given."<<endl;
1862          cout << "Check for existing root files."<<endl;          cout << "Check for existing root files."<<endl;
1863  //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;  //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;
1864          if ( ddir == "" ){          if ( ddir == "" ){
1865            ddir = wdir;              ddir = wdir;
1866            cout << "Level2 data directory : "<<  ddir << endl;              cout << "Level2 data directory : "<<  ddir << endl;
1867          };          };
1868    
1869          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
# Line 1887  TChain *PamLevel2::GetPamTree(TList *fl, Line 1920  TChain *PamLevel2::GetPamTree(TList *fl,
1920            
1921      TChain *Trout =0;      TChain *Trout =0;
1922    
1923            // -------------------------------------------
1924        // set flags to include/exclude trees/branches
1925        // -------------------------------------------
1926      if( detlist.Contains("+AUTO", TString::kIgnoreCase) ) {      if( detlist.Contains("+AUTO", TString::kIgnoreCase) ) {
1927          if( fl->GetEntries()>0 ){          if( fl->GetEntries()>0 ){
1928              cout << "+AUTO"<<endl;              cout << "+AUTO"<<endl;
1929              TFile *fprimo = new TFile( fl->At(0)->GetName() );              TFile *fprimo = new TFile( fl->At(0)->GetName() );
1930              GetWhichTrees(fprimo);              GetWhichTrees(fprimo);
1931                fprimo->Close();// AAAAARGGGGGHHHHH!!!!!!! non commentare questa riga, altrimenti si incasina il TChain
1932              fprimo->Delete();              fprimo->Delete();
1933          }          }
1934      };      };
1935      SetWhichTrees(detlist);          SetWhichTrees(detlist);    
1936    
1937    
1938        // -------------------------------------------
1939        // build chains
1940        // -------------------------------------------
1941        TChain *T = 0;      
1942        TChain *C = 0;
1943        TChain *O = 0;
1944        TChain *R = 0;
1945        TChain *S = 0;
1946        TChain *N = 0;
1947        TChain *A = 0;
1948        TChain *B = 0;
1949        TChain *G = 0;
1950    
1951  //    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;  
1952            
1953      if(TRK2||TRK1||TRKh) T = new TChain("Tracker");          if(TRK2||TRK1||TRKh) T = new TChain("Tracker");    
1954      if(CAL2||CAL1)       C = new TChain("Calorimeter");      if(CAL2||CAL1)       C = new TChain("Calorimeter");
# Line 1945  TChain *PamLevel2::GetPamTree(TList *fl, Line 1981  TChain *PamLevel2::GetPamTree(TList *fl,
1981          };          };
1982      };      };
1983            
1984      cout << "done chain \n";      cout << "done chains\n";
1985      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
1986    
1987  //    UInt_t *found=0;  
1988        // -------------------------------------------
1989        // make friends
1990        // -------------------------------------------
1991    
1992  // Tracker  // Tracker
1993        cout << "Friends: "<<endl;
1994      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;  
1995          if(!Trout)Trout=T;          if(!Trout)Trout=T;
1996          else Trout->AddFriend("Tracker");          else Trout->AddFriend("Tracker");
1997      }else{  //      cout << "+Tacker"<<endl;
 //        cout << "Tracker      : missing tree"<<endl;  
1998      };      };
1999      // Calorimeter      // Calorimeter
2000      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;  
2001          if(!Trout)Trout=C;          if(!Trout)Trout=C;
2002          else Trout->AddFriend("Calorimeter");          else Trout->AddFriend("Calorimeter");
2003      }else{  //      cout << "+Calorimeter"<<endl;
 //        cout << "Calorimeter  : missing tree"<<endl;  
2004      };      };
2005      // ToF          // ToF    
2006      if(O && TOF) {      if(O && TOF) {
 //        O->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));  
 //        cout << "ToF          : set branch address ToFLevel2"<<endl;  
2007          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2008          else Trout->AddFriend("ToF");          else Trout->AddFriend("ToF");
2009      }else{  //      cout << "+ToF"<<endl;
 //        cout << "ToF         : missing tree"<<endl;  
2010      };      };
2011      // Trigger      // Trigger
2012      if(R && TRG) {      if(R && TRG) {
 //        R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));  
 //        cout << "Trigger      : set branch address TrigLevel2"<<endl;  
2013          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2014          else Trout->AddFriend("Trigger");          else Trout->AddFriend("Trigger");
2015      }else{  //      cout << "+Trigger"<<endl;
 //        cout << "Trigger      : missing tree"<<endl;  
2016      };      };
2017      // S4      // S4
2018      if(S && S4) {      if(S && S4) {
 //        S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));  
 //        cout << "S4           : set branch address S4Level2"<<endl;  
2019          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2020          else Trout->AddFriend("S4");          else Trout->AddFriend("S4");
2021      }else{  //      cout << "+S4"<<endl;
 //        cout << "S4           : missing tree"<<endl;  
2022      };      };
2023      // Neutron Detector      // Neutron Detector
2024      if(N && ND) {      if(N && ND) {
 //        N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));  
 //        cout << "NeutronD     : set branch address NDLevel2"<<endl;  
2025          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2026          else Trout->AddFriend("NeutronD");          else Trout->AddFriend("NeutronD");
2027      }else{  //      cout << "+NeutronD"<<endl;
 //        cout << "NeutronD     : missing tree"<<endl;  
2028      };      };
2029      // Anticounters      // Anticounters
2030      if(A && AC) {      if(A && AC) {
 //        A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));  
 //        cout << "Anticounter  : set branch address AcLevel2"<<endl;  
2031          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2032          else Trout->AddFriend("Anticounter");          else Trout->AddFriend("Anticounter");
2033      }else{  //      cout << "+Anticounter"<<endl;
 //        cout << "Anticounter  : missing tree"<<endl;  
2034      };      };
2035      // Orbital Info      // Orbital Info
2036      if(B && ORB) {      if(B && ORB) {
 //      B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));  
 //      cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;  
2037          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2038          else Trout->AddFriend("OrbitalInfo");          else Trout->AddFriend("OrbitalInfo");
2039      }else{  //      cout << "+OrbitalInfo"<<endl;
 //      cout << "OrbitalInfo  : missing tree"<<endl;  
2040      };      };
2041      // GPamela      // GPamela
2042      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;  
2043          if(!Trout)Trout=G;          if(!Trout)Trout=G;
2044          else Trout->AddFriend("h20");          else Trout->AddFriend("h20");
2045      }else{  //      cout << "+h20"<<endl;
 //      cout << "h20          : missing tree"<<endl;  
2046      };      };
2047    
2048  //  =====================================  //  =====================================
# Line 2050  TChain *PamLevel2::GetPamTree(TList *fl, Line 2050  TChain *PamLevel2::GetPamTree(TList *fl,
2050  //  =====================================  //  =====================================
2051      SetBranchAddress(Trout);      SetBranchAddress(Trout);
2052    
2053    
2054    //  ------------------------------------
2055    //  finally handle selection trees...
2056    //  (it is not friend of pamela tree)
2057    //  ------------------------------------
2058    
2059      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2060    
2061      // Selection List      // Selection List
2062      if(L && SELLI==1) {      if(L && SELLI==1) {
2063          cout<<">>> Found selection-list <<<"<<endl;          cout<<">>> Found selection-list <<<"<<endl;
2064          L->SetBranchAddress("RunEntry",&irun);  //      L->SetBranchAddress("RunEntry",&irun);
2065            L->SetBranchAddress("RunEntry",&irunt);//NEWNEW
2066          cout << "SelectionList: set branch address RunEntry"<<endl;          cout << "SelectionList: set branch address RunEntry"<<endl;
2067          L->SetBranchAddress("EventEntry",&irunentry);          L->SetBranchAddress("EventEntry",&irunentry);
2068          cout << "SelectionList: set branch address EventEntry"<<endl;          cout << "SelectionList: set branch address EventEntry"<<endl;
2069          sel_tree = L;          sel_tree = L;
2070  //      if(!Trout)Trout=O;  //      if(!Trout)Trout=O;
2071  //      else Trout->AddFriend("SelectionList");  //      else Trout->AddFriend("SelectionList");
2072          cout << "----------------------------------------------------" <<endl;          cout << "+SelectionList"<<endl;
2073            cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2074      }else{      }else{
2075  //      cout << "SelectionList  : missing tree"<<endl;  //      cout << "SelectionList  : missing tree"<<endl;
2076          if(L)L->Delete();          if(L)L->Delete();
2077      };      };
       
 //    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;  
 //     };  
2078    
2079    //  --------------------------------------------
2080    //  return the pamela chain with all the friends
2081    //  --------------------------------------------
2082    
2083      pam_tree = Trout;      pam_tree = Trout;
2084            
# Line 2177  void PamLevel2::SetBranchAddress(TTree * Line 2171  void PamLevel2::SetBranchAddress(TTree *
2171          gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri          gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2172          cout << "h20          : set branch address GPamela "<<endl;          cout << "h20          : set branch address GPamela "<<endl;
2173      };      };
     // 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;  
     };  
2174            
2175  }  }
2176  /**  /**
# Line 2205  void PamLevel2::SetBranchAddress(TChain Line 2192  void PamLevel2::SetBranchAddress(TChain
2192  //    GP     = GP & t->GetBranchStatus("h20");  //    GP     = GP & t->GetBranchStatus("h20");
2193    
2194      // Tracker      // Tracker
2195       if(TRK2) {      if(TRK2) {
2196          t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));          t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
2197          cout << "Tracker      : set branch address TrkLevel2"<<endl;          cout << "Tracker      : set branch address TrkLevel2"<<endl;
2198      };      };
# Line 2213  void PamLevel2::SetBranchAddress(TChain Line 2200  void PamLevel2::SetBranchAddress(TChain
2200          t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));          t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
2201          cout << "Tracker      : set branch address TrkLevel1"<<endl;          cout << "Tracker      : set branch address TrkLevel1"<<endl;
2202      };      };
2203       if(TRKh) {      if(TRKh) {
2204          t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));          t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
2205          cout << "Tracker      : set branch address TrkHough"<<endl;          cout << "Tracker      : set branch address TrkHough"<<endl;
2206       };      };
2207            
2208      // Calorimeter      // Calorimeter
2209      if(CAL2) {      if(CAL2) {
# Line 2267  void PamLevel2::SetBranchAddress(TChain Line 2254  void PamLevel2::SetBranchAddress(TChain
2254          cout << "h20          : set branch address GPamela "<<endl;          cout << "h20          : set branch address GPamela "<<endl;
2255      };      };
2256      // SelectionList      // SelectionList
2257      if(SELLI==1) {  //     if(SELLI==1){
2258          t->SetBranchAddress("RunEntry", &irun);  //      t->SetBranchAddress("RunEntry",&irunt);//NEWNEW
2259          cout << "SelectionList: set branch address RunEntry"<<endl;  //      cout << "SelectionList: set branch address RunEntry"<<endl;
2260          t->SetBranchAddress("EventEntry", &irunentry);  //      t->SetBranchAddress("EventEntry",&irunentry);
2261          cout << "SelectionList: set branch address EventEntry"<<endl;  //      cout << "SelectionList: set branch address EventEntry"<<endl;
2262      };          
2263        //     }
2264    
2265  }  }
2266    
2267    
# Line 2287  void PamLevel2::SetBranchAddress(TChain Line 2275  void PamLevel2::SetBranchAddress(TChain
2275   * @return Pointer to a TChain   * @return Pointer to a TChain
2276   */   */
2277  TChain *PamLevel2::GetRunTree(TList *fl){  TChain *PamLevel2::GetRunTree(TList *fl){
2278    //      //
2279    //      //
2280    //      //
2281    if ( run_tree ){      if ( run_tree ){
2282      printf("WARNING: TChain *PamLevel2::GetRunTree(TList *fl) -- run_tree already exists!\n ");          printf("WARNING: TChain *PamLevel2::GetRunTree(TList *fl) -- run_tree already exists!\n ");
2283      return run_tree;          return run_tree;
2284    };          };  
2285    //      //
2286    TChain *R = new TChain("Run");      TChain *R = new TChain("Run");
2287            
2288      // loop over files and create chains              // loop over files and create chains        
2289      TIter next(fl);      TIter next(fl);
# Line 2314  TChain *PamLevel2::GetRunTree(TList *fl) Line 2302  TChain *PamLevel2::GetRunTree(TList *fl)
2302          cout << "Run         : set branch address RunInfo"<<endl;          cout << "Run         : set branch address RunInfo"<<endl;
2303          R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano          R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
2304          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
2305    
2306            irunoffset = new int[R->GetNtrees()];
2307            cout << "----------------------------------------------------"<<endl;
2308            cout << "irun\t | ";
2309            cout << "tree\t |";
2310    //      cout << "offset\t |";
2311            cout << "RUN\t";
2312            cout << "FRAG\t";
2313            cout << "NEVENTS\t";
2314            cout << "absolute time\t\t\t";
2315            cout << "on-board time";
2316            cout<<endl;
2317            for (Int_t ii=0; ii<R->GetEntries(); ii++){
2318                R->GetEntry(ii);
2319                cout << ii<< "\t | ";
2320                cout << R->GetTreeNumber()<< "\t |";
2321    //          cout << R->GetChainOffset()<< "\t |";
2322                cout <<GetRunInfo()->ID<<"\t";
2323                cout <<GetRunInfo()->ID_RUN_FRAG<<"\t";
2324                cout <<GetRunInfo()->NEVENTS<< "\t";
2325                cout <<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME <<"\t";
2326                cout <<GetRunInfo()->RUNHEADER_OBT<<" <---> "<<GetRunInfo()->RUNTRAILER_OBT<<"\t";
2327                cout <<endl;
2328                irunoffset[R->GetTreeNumber()]=R->GetChainOffset();
2329            }
2330            cout << "----------------------------------------------------"<<endl;
2331    
2332    
2333    
2334      }else{      }else{
2335          delete R;          delete R;
2336          R=0;          R=0;
# Line 2334  TChain *PamLevel2::GetRunTree(TList *fl) Line 2351  TChain *PamLevel2::GetRunTree(TList *fl)
2351   * @return Pointer to a TTree   * @return Pointer to a TTree
2352   */   */
2353  TTree *PamLevel2::GetRunTree(TFile *f){  TTree *PamLevel2::GetRunTree(TFile *f){
2354    if ( run_tree ){      if ( run_tree ){
2355      printf("WARNING: TTree *PamLevel2::GetRunTree(TFile *f) -- run_tree already exists!\n ");          printf("WARNING: TTree *PamLevel2::GetRunTree(TFile *f) -- run_tree already exists!\n ");
2356      return run_tree;          return run_tree;
2357    };      };
2358                    
2359    
2360      cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;      cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;
# Line 2349  TTree *PamLevel2::GetRunTree(TFile *f){ Line 2366  TTree *PamLevel2::GetRunTree(TFile *f){
2366          cout << "Run         : set branch address RunInfo"<<endl;          cout << "Run         : set branch address RunInfo"<<endl;
2367          T->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano          T->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
2368          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
2369    
2370      }      }
2371    
2372      run_tree = (TChain*)T;      run_tree = (TChain*)T;
# Line 2362  TTree *PamLevel2::GetRunTree(TFile *f){ Line 2380  TTree *PamLevel2::GetRunTree(TFile *f){
2380   * @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
2381   */   */
2382  Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev){  Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev){
2383    //      //
2384    // check if we have already called once GetEntry, if not call it      // check if we have already called once GetEntry, if not call it
2385    //      //
2386      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;
2387      if(!run){      if(!run){
2388            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;
2389            return(false);                  return(false);  
2390      }      }
2391      if ( run->GetEntries() <= 0 ) return(false);      if ( run->GetEntries() <= 0 ) return(false);
2392    //      //
2393        
2394    //  Int_t oldrun = irun;      //  Int_t oldrun = irun;
2395    Long64_t oldrun = irun;      Long64_t oldrun = irun;
2396    
2397        // --------------------------------------
2398        // if it is a full file (not preselected)
2399        // --------------------------------------
2400        if(SELLI==0){
2401    
2402            //
2403            // the absolute time is necessary to relate the event with the run
2404            //
2405            if( !GetOrbitalInfo() && !ISGP){
2406                cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
2407                return(false);
2408            }
2409    
2410            ULong64_t abstime = 0;
2411            if( GetOrbitalInfo() )abstime=GetOrbitalInfo()->absTime;
2412    
2413    
2414    // --------------------------------------          //
2415    // if it is a full file (not preselected)          // the first time the routine is called, set run search from the beginning
2416    // --------------------------------------          //
2417    if(SELLI==0){          if ( irun < 0LL ){
2418                irun = 0LL;
2419        //              run->GetEntry(irun);
2420        // the absolute time is necessary to relate the event with the run              runfirstentry = 0LL;
2421        //              runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2422        if( !GetOrbitalInfo() && !ISGP){              if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
           cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;  
           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;  
2423                        
2424            if( ISGP && run->GetEntries()!=1 ){              if( ISGP && run->GetEntries()!=1 ){
2425                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;
2426                cout << "** WARNING ** run will not be updated"<<endl;                  cout << "** WARNING ** run will not be updated"<<endl;
2427            }              }
2428    
2429        };                };      
2430        //          //
2431        if(ISGP)abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO          if(ISGP)abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO
2432        //          //
2433        if ( irun == run->GetEntries()-1LL &&          if ( irun == run->GetEntries()-1LL &&
2434             !(abstime >= GetRunInfo()->RUNHEADER_TIME &&               !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
2435               abstime <= GetRunInfo()->RUNTRAILER_TIME)                 abstime <= GetRunInfo()->RUNTRAILER_TIME)
2436              ){              ){
2437           irun = -1LL;              irun = -1LL;
2438           runfirstentry = 0LL;              irunt = -1LL;
2439           runlastentry = -1LL;              runfirstentry = 0LL;
2440         };              runlastentry = -1LL;
2441        // modificato il controllo sull'aggiornamento del run, per evitare problemi          };
2442        // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)          // modificato il controllo sull'aggiornamento del run, per evitare problemi
2443        //          // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)
2444        bool fromfirst = true;          //
2445        //          bool fromfirst = true;
2446        while ( !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1LL ){          //
2447            while ( !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1LL ){
2448  //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){  //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){
2449            irun++;              irun++;
2450            run->GetEntry(irun);              run->GetEntry(irun);
2451            runfirstentry = runlastentry;              runfirstentry = runlastentry;
2452            if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runfirstentry += 1LL;              if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runfirstentry += 1LL;
2453            runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);              runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2454  //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;  //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2455  //        cout << "runfirstentry "<<runfirstentry<<endl;  //        cout << "runfirstentry "<<runfirstentry<<endl;
2456            //      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)));
2457            //      printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME);              //    printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME);
2458            //      printf(" IDRUN %u \n",GetRunInfo()->ID);              //    printf(" IDRUN %u \n",GetRunInfo()->ID);
2459            //              //
2460  //        prevshift = 0;  //        prevshift = 0;
2461            //              //
2462            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)){
2463                printf(" resetting irun  (it should NOT happen!!!)\n");                  printf(" resetting irun  (it should NOT happen!!!)\n");
2464                fromfirst = false;                  fromfirst = false;
2465                irun = 0;                  irun = 0;
2466                run->GetEntry(irun);                  run->GetEntry(irun);
2467                runfirstentry = 0ULL;                  runfirstentry = 0ULL;
2468                runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);                  runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2469                if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;                  if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
2470            };              };
2471            //              //
2472        };          };
2473        //          //
2474        if (          if (
2475             !(abstime >= GetRunInfo()->RUNHEADER_TIME &&              !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
2476               abstime <= GetRunInfo()->RUNTRAILER_TIME)                abstime <= GetRunInfo()->RUNTRAILER_TIME)
2477            ) {              ) {
2478          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);
2479            return false;              return false;
2480        }          }
2481        //          //
2482        if ( irun == oldrun || irun >= run->GetEntries() ) return(false);          if ( irun == oldrun || irun >= run->GetEntries() ) return(false);
2483        //          //
2484        //  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);
2485        //          //
2486        prevshift = 0;          prevshift = 0;
2487        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;          cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2488  //      cout << "runfirstentry "<<runfirstentry<<endl;  //      cout << "runfirstentry "<<runfirstentry<<endl;
2489        return(true);              return(true);    
2490    };      };
2491    // ----------------------------------------------------      // ----------------------------------------------------
2492    // if it is a preselected file (there is SelectionList)      // if it is a preselected file (there is SelectionList)
2493    // NBNB - the event tree MUST be read first      // NBNB - the event tree MUST be read first
2494    // ----------------------------------------------------      // ----------------------------------------------------
2495    if(SELLI==1){            if(SELLI==1){      
2496        sel_tree->GetEntry(iev);          sel_tree->GetEntry(iev);
2497  //      cout << irun << " "<< irunentry << endl;  //      cout << irun << " "<< irunentry << endl;
2498        if(irun != oldrun){          if(irun != oldrun){
2499            run->GetEntry(irun);              run->GetEntry(irun);
2500            cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;              cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2501            prevshift = 0;              prevshift = 0;
2502            return true;              return true;
2503        }          }
2504        return false;          return false;
2505    }      }
2506    
2507    return false;      return false;
2508    //      //
2509  };  };
2510    
2511  Bool_t PamLevel2::UpdateRunInfo(Long64_t iev){  Bool_t PamLevel2::UpdateRunInfo(Long64_t iev){
# Line 2502  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2521  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2521        
2522      Int_t oldrun = irun; // store current run index      Int_t oldrun = irun; // store current run index
2523    
2524        // -----------------------------------------------------------------------
2525        // the first time the routine is called, set run search from the beginning
2526        // -----------------------------------------------------------------------
2527    
2528        if ( irun < 0 ){
2529            irun = 0LL;
2530            irunt = 0LL;
2531            irunentry = 0;
2532            prevshift = 0;
2533            run_tree->GetEntry(irun);
2534            if( !GetOrbitalInfo() )cout << "** WARNING ** missing OrbitalInfo ---> run info might be not correctly updated "<<endl;
2535        };      
2536        // ---------------------------------------------------------------
2537        // retrieve OBT and absolute time of the event
2538        // ---------------------------------------------------------------
2539        ULong64_t abstime = 0LL;
2540        ULong64_t obt     = 0LL;
2541        if( GetOrbitalInfo() ){
2542            abstime = GetOrbitalInfo()->absTime;
2543            obt     = GetOrbitalInfo()->OBT;
2544    //      cout << " ABS >>> "<<abstime<<" OBT >>> "<<obt<<" "<<endl;
2545        }else{
2546            abstime = GetRunInfo()->RUNHEADER_TIME;
2547            obt     = GetRunInfo()->RUNHEADER_OBT;
2548        }
2549    //    cout << ISGP << " "<<abstime<<endl;
2550        // ---------------------------------------------------------------
2551        // the absolute time is necessary to relate the event with the run
2552        // ---------------------------------------------------------------
2553    //     if( !GetOrbitalInfo() && !ISGP ){
2554    //      cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
2555    //      return(false);
2556    //     }
2557        // -----------------------------------------------------------------------
2558        // if it is simulation, assign abstime by hand (temporaneo!!!)
2559        // -----------------------------------------------------------------------
2560    //     if(ISGP){
2561    //      abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO
2562    //      obt     = GetRunInfo()->RUNHEADER_OBT; // BARBATRUCCO
2563    //     }
2564        
2565    
2566      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2567      // if it is a full file (not preselected)      // if it is a full file (not preselected)
2568      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2569      if(SELLI==0){      if(SELLI==0){
2570    
2571          // ---------------------------------------------------------------          // ---------------------------------------------------------------
2572          // increment dead and live-time counters          // increment dead and live-time counters
2573            // (only when reading a file not preselected)
2574          // ---------------------------------------------------------------          // ---------------------------------------------------------------
2575          if( GetTrigLevel2() ){          if(SELLI==0){
2576              totdltime[0]+=GetTrigLevel2()->dltime[0];              if( GetTrigLevel2() ){
2577              totdltime[1]+=GetTrigLevel2()->dltime[1];                  totdltime[0]+=GetTrigLevel2()->dltime[0];
2578                    totdltime[1]+=GetTrigLevel2()->dltime[1];
2579                }
2580                totdltime[2]++;
2581          }          }
         totdltime[2]++;  
   
2582  //      cout << setw(10)<<totdltime[0]<<setw(10)<<totdltime[1]<<setw(10)<<totdltime[2]<<endl;  //      cout << setw(10)<<totdltime[0]<<setw(10)<<totdltime[1]<<setw(10)<<totdltime[2]<<endl;
2583    
2584          // ---------------------------------------------------------------  //      // ---------------------------------------------------------------
2585          // retrieve OBT and absolute time of the event  //      // retrieve OBT and absolute time of the event
2586          // ---------------------------------------------------------------  //      // ---------------------------------------------------------------
2587          ULong64_t abstime = 0;  //      ULong64_t abstime = 0;
2588          ULong64_t obt     = 0;  //      ULong64_t obt     = 0;
2589          if( GetOrbitalInfo() ){  //      if( GetOrbitalInfo() ){
2590              abstime = GetOrbitalInfo()->absTime;  //          abstime = GetOrbitalInfo()->absTime;
2591              obt     = GetOrbitalInfo()->OBT;  //          obt     = GetOrbitalInfo()->OBT;
2592          }  //      }
2593          // ---------------------------------------------------------------  //      // ---------------------------------------------------------------
2594          // the absolute time is necessary to relate the event with the run  //      // the absolute time is necessary to relate the event with the run
2595          // ---------------------------------------------------------------  //      // ---------------------------------------------------------------
2596          if( !GetOrbitalInfo() && !ISGP ){  //      if( !GetOrbitalInfo() && !ISGP ){
2597              cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;  //          cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
2598              return(false);  //          return(false);
2599          }  //      }
2600                
2601          // -----------------------------------------------------------------------  //      // -----------------------------------------------------------------------
2602          // the first time the routine is called, set run search from the beginning  //      // the first time the routine is called, set run search from the beginning
2603          // -----------------------------------------------------------------------  //      // -----------------------------------------------------------------------
2604          if ( irun < 0 ){  //      if ( irun < 0 ){
2605              irun = 0LL;  //          irun = 0LL;
2606              irunentry = 0;  //          irunt = 0LL;
2607              prevshift = 0;  //          irunentry = 0;
2608              run_tree->GetEntry(irun);  //          prevshift = 0;
2609    //          run_tree->GetEntry(irun);
2610              if( ISGP && run_tree->GetEntries()!=1 ){  
2611                  cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run_tree->GetEntries() << endl;  //          if( ISGP && run_tree->GetEntries()!=1 ){
2612                  cout << "** WARNING ** run will not be updated"<<endl;  //              cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run_tree->GetEntries() << endl;
2613              }  //              cout << "** WARNING ** run will not be updated"<<endl;
2614          };        //          }
2615    //      };      
2616    
2617          // -----------------------------------------------------------------------  //      // -----------------------------------------------------------------------
2618          // if it is simulation, assign abstime by hand (temporaneo!!!)  //      // if it is simulation, assign abstime by hand (temporaneo!!!)
2619          // -----------------------------------------------------------------------  //      // -----------------------------------------------------------------------
2620          if(ISGP){  //      if(ISGP){
2621              abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO  //          abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO
2622              obt     = GetRunInfo()->RUNHEADER_OBT; // BARBATRUCCO  //          obt     = GetRunInfo()->RUNHEADER_OBT; // BARBATRUCCO
2623          }  //      }
2624          //          //
2625          bool fromfirst = true; // first loop over runs          bool fromfirst = true; // first loop over runs
2626    
# Line 2579  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2643  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2643  //              || !(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
2644                  || !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift)                  || !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift)
2645                  )                  )
2646                  && irun < run_tree->GetEntries() ){              && irun < run_tree->GetEntries() ){
2647    
2648              // - - - - - - - - - - - - -              // - - - - - - - - - - - - -
2649              // irunentry = position of current entry, relative to the run              // irunentry = position of current entry, relative to the run
# Line 2589  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2653  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2653              // -----------------------------------------              // -----------------------------------------
2654              // store dead and live-time of previous run              // store dead and live-time of previous run
2655              // -----------------------------------------              // -----------------------------------------
2656              if(fromfirst){  //          if(SELLI==0){
2657                  if(oldrun==irun){                  if(fromfirst){
2658                      /// decrement counters                      if(oldrun==irun){
2659                      if( GetTrigLevel2()){                          /// decrement counters
2660                          totdltime[0]-=GetTrigLevel2()->dltime[0];//live-time                          if( GetTrigLevel2()){
2661                          totdltime[1]-=GetTrigLevel2()->dltime[1];//dead-time                              totdltime[0]-=GetTrigLevel2()->dltime[0];//live-time
2662                                totdltime[1]-=GetTrigLevel2()->dltime[1];//dead-time
2663                            }
2664                            totdltime[2]--;                              //event counter
2665                            cout << endl;
2666                            cout << "n.events     : "<<totdltime[2]<<endl;
2667                            cout << "RUN LIVE-TIME: "<<totdltime[0]*0.16<<" ms"<<endl;
2668                            cout << "RUN DEAD-TIME: "<<totdltime[1]*0.01<<" ms"<<endl;          
2669                        }else{
2670                            totdltime[0]=0;//live-time
2671                            totdltime[1]=0;//dead-time
2672                            totdltime[2]=0;                             //event counter
2673                            cout << " *** JUMP RUN *** irun "<<irun<<endl;
2674                      }                      }
2675                      totdltime[2]--;                              //event counter                      /// add an entry
2676                      cout << endl;                      if(run_tree_clone)
2677                      cout << "n.events     : "<<totdltime[2]<<endl;                          if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
2678                      cout << "RUN LIVE-TIME: "<<totdltime[0]*0.16<<" ms"<<endl;                              run_tree_clone->GetBranch("DeadLiveTime")->Fill();
2679                      cout << "RUN DEAD-TIME: "<<totdltime[1]*0.01<<" ms"<<endl;                            /// reset counters
2680                  }else{                      if( GetTrigLevel2() ){
2681                      totdltime[0]=0;//live-time                          totdltime[0]=GetTrigLevel2()->dltime[0];//live-time
2682                      totdltime[1]=0;//dead-time                          totdltime[1]=0;                         //dead-time
2683                      totdltime[2]=0;                             //event counter                      }
2684                      cout << " *** JUMP RUN *** irun "<<irun<<endl;                      totdltime[2]=1;                             //event counter
                 }  
                 /// add an entry  
                 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  
2685                  }                  }
2686                  totdltime[2]=1;                             //event counter  //          }
             }  
   
2687    
2688              irun++;              irun++;        
2689              // ------------------------------------              // ------------------------------------
2690              // if the end of run tree is reached...              // if the end of run tree is reached...
2691              // ------------------------------------              // ------------------------------------
# Line 2648  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2713  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2713              if(irun>0)runfirstentry += (GetRunInfo()->NEVENTS)-prevshift;              if(irun>0)runfirstentry += (GetRunInfo()->NEVENTS)-prevshift;
2714              irunentry = 0;              irunentry = 0;
2715              prevshift = 0;                        prevshift = 0;          
2716              run_tree->GetEntry(irun);                    run_tree->GetEntry(irun);
2717                irunt = irun - irunoffset[run_tree->GetTreeNumber()];
2718              if(GetRunInfo()->RUNHEADER_OBT>GetRunInfo()->RUNTRAILER_OBT ){              if(GetRunInfo()->RUNHEADER_OBT>GetRunInfo()->RUNTRAILER_OBT ){
2719                  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;
2720                  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 2671  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2737  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2737    
2738    
2739    
 //      // -----------------------------------------  
 //      // 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  
           
2740    
2741          // --------------------------------------          // --------------------------------------
2742          // ---> exit with TRUE          // ---> exit with TRUE
# Line 2741  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2759  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2759      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2760      // if it is a preselected file (there is SelectionList)      // if it is a preselected file (there is SelectionList)
2761      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2762        // irun  = run entry relative to the chain
2763        // irunt = run entry relative to the tree
2764      if(SELLI==1){            if(SELLI==1){      
2765          sel_tree->GetEntry(iev);          sel_tree->GetEntry(iev);// read irunt from SelectionList
2766            irun = irunt + irunoffset[sel_tree->GetTreeNumber()];//NEWNEW
2767          if(irun != oldrun){          if(irun != oldrun){
2768              run_tree->GetEntry(irun);              run_tree->GetEntry(irun);
2769                // check if the time is ok (with merged files it is not...)
2770                // if not loop over run and look for the proper entry
2771                bool SECONDO_GIRO=false;
2772                Long64_t irun_start   = irun;
2773                int      offset_start = irunoffset[sel_tree->GetTreeNumber()];
2774                while (
2775                    (
2776                        (
2777                            !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
2778                              abstime <= GetRunInfo()->RUNTRAILER_TIME)
2779                            ||
2780                            !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
2781                              obt <= GetRunInfo()->RUNTRAILER_OBT)
2782                            )
2783                        || GetRunInfo()->NEVENTS==0
2784                        )
2785    //              && irun < run_tree->GetEntries()
2786                    ){
2787                    cout << " (test) ";
2788                    cout << " tree "<<sel_tree->GetTreeNumber();
2789                    cout << " irunt "<<irunt;
2790                    cout << " offset "<<irunoffset[sel_tree->GetTreeNumber()];
2791                    cout << " abs "<<abstime;
2792                    cout <<" >> "<<GetRunInfo()->RUNHEADER_TIME<<" "<<GetRunInfo()->RUNTRAILER_TIME;
2793                    cout << " obt "<<obt;
2794                    cout <<" >> "<<GetRunInfo()->RUNHEADER_OBT<<" "<<GetRunInfo()->RUNTRAILER_OBT;
2795                    cout << " *** JUMP RUN *** irun "<<irun;
2796    //              if(!SECONDO_GIRO)cout << " (don't worry)";
2797    //              else             cout << " (start worring...)";
2798                    cout << endl;
2799    //              irun++;
2800                    irunoffset[sel_tree->GetTreeNumber()]++;
2801                    irun = irunt + irunoffset[sel_tree->GetTreeNumber()];//NEWNEW          
2802    //              if(irun == run_tree->GetEntries() && SECONDO_GIRO){
2803                    if(irun == irun_start){
2804                        cout << " ...grrrvzzkhhhajsdkj!!!! "<<endl;
2805                        irunoffset[sel_tree->GetTreeNumber()] = offset_start;
2806                        return false;
2807                    }
2808                    if(irun == run_tree->GetEntries()){
2809                        SECONDO_GIRO=true;
2810                        irun=0;
2811                        irunoffset[sel_tree->GetTreeNumber()]=-irunt;
2812                    }
2813                    run_tree->GetEntry(irun);
2814                }
2815    
2816                cout << " (test) ";
2817                cout << " tree "<<sel_tree->GetTreeNumber();
2818                cout << " irunt "<<irunt;
2819                cout << " offset "<<irunoffset[sel_tree->GetTreeNumber()];
2820                cout << " abs "<<abstime;
2821                cout <<" >> "<<GetRunInfo()->RUNHEADER_TIME<<" "<<GetRunInfo()->RUNTRAILER_TIME;
2822                cout << " obt "<<obt;
2823                cout <<" >> "<<GetRunInfo()->RUNHEADER_OBT<<" "<<GetRunInfo()->RUNTRAILER_OBT;
2824                cout << endl;
2825              cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;              cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2826                cout << endl;
2827              prevshift = 0;              prevshift = 0;
2828              return true;              return true;
2829          }          }
# Line 2761  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2839  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2839   * @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
2840   */   */
2841  Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev){  Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev){
2842    return(UpdateRunInfo((TChain*)run,iev));      return(UpdateRunInfo((TChain*)run,iev));
2843  };  };
2844    
2845  //--------------------------------------  //--------------------------------------
# Line 2771  Bool_t PamLevel2::UpdateRunInfo(TTree *r Line 2849  Bool_t PamLevel2::UpdateRunInfo(TTree *r
2849  /**  /**
2850   * Set which trees shoul be analysed   * Set which trees shoul be analysed
2851   * @param detlist TString containing the sequence of trees required   * @param detlist TString containing the sequence of trees required
2852  */   */
2853  void PamLevel2::SetWhichTrees(TString detlist){  void PamLevel2::SetWhichTrees(TString detlist){
2854            
2855  //    if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){  //    if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){
2856      if( detlist.Contains("+ALL", TString::kIgnoreCase)){      if( detlist.Contains("+ALL", TString::kIgnoreCase)){
2857    
2858          cout << " ======================================================== "<<endl;          cout << " ======================================================== "<<endl;
2859          cout << "                       (( WARNING ))                      "<< endl;          cout << "                       (( WARNING ))                      "<<endl;
2860          cout << " The meaning of the option +ALL has changed!!             "<<endl;          cout << " The meaning of the option +ALL has changed!!             "<<endl;
2861          cout << " Now it includes really all (level0+level1+level2+gpamela)"<<endl;          cout << " Now it includes really all (level0+level1+level2+gpamela)"<<endl;
2862          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;
2863          cout << " trees or level0 files are not available!!                "<<endl;          cout << " all trees or  if level0 files are not available!!        "<<endl;
2864          cout << " ======================================================== "<<endl;          cout << " ======================================================== "<<endl;
2865                            
2866          CAL0 = true;          CAL0 = true;
# Line 2892  void PamLevel2::SetWhichTrees(TString de Line 2970  void PamLevel2::SetWhichTrees(TString de
2970      if( detlist.Contains("-GP", TString::kIgnoreCase) )GP = false;      if( detlist.Contains("-GP", TString::kIgnoreCase) )GP = false;
2971      else if( detlist.Contains("+GP", TString::kIgnoreCase) )GP = true;      else if( detlist.Contains("+GP", TString::kIgnoreCase) )GP = true;
2972    
2973      cout<< "Set detector list from input --> ";      cout<< "tree/branch list from input --> ";
2974      if(TRK0)cout<<"TRK0 ";      if(TRK0)cout<<"TRK0 ";
2975      if(TRK1)cout<<"TRK1 ";      if(TRK1)cout<<"TRK1 ";
2976      if(TRK2)cout<<"TRK2 ";      if(TRK2)cout<<"TRK2 ";
# Line 3071  void  PamLevel2::GetWhichTrees(TFile* f) Line 3149  void  PamLevel2::GetWhichTrees(TFile* f)
3149            
3150  //    delete lk;  //    delete lk;
3151    
3152      cout<< "Get detector list from input file --> ";      cout<< "tree/branch list from file  --> ";
3153      if(TRK1)cout<<"TRK1 ";      if(TRK1)cout<<"TRK1 ";
3154      if(TRK2)cout<<"TRK2 ";      if(TRK2)cout<<"TRK2 ";
3155      if(TRKh)cout<<"TRKH ";      if(TRKh)cout<<"TRKH ";
# Line 3119  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3197  Bool_t  PamLevel2::CheckLevel2File(TStri
3197            
3198      Bool_t SELLI__ok  = false;      Bool_t SELLI__ok  = false;
3199    
3200      cout << "Checking file: "<<name<<endl;  //    cout << "Checking file: "<<name<<endl;
3201      TFile *f = new TFile(name.Data());      TFile *f = new TFile(name.Data());
3202      if( !f || f->IsZombie() ){      if( !f || f->IsZombie() ){
3203          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 3471  void PamLevel2::CreateCloneTrees(TFile * Line 3549  void PamLevel2::CreateCloneTrees(TFile *
3549      // ------------------      // ------------------
3550      // replicate run tree      // replicate run tree
3551      // ------------------      // ------------------
3552      cout << "----------------------------------------------------"<<endl;  //    cout << "----------------------------------------------------"<<endl;
3553      cout << "irun\t | RUN\t NEVENTS\t absolute time"<<endl;  //    cout << "irun\t | RUN\t NEVENTS\t absolute time"<<endl;
3554      for (Int_t i=0; i<run_tree->GetEntries(); i++){      for (Int_t i=0; i<run_tree->GetEntries(); i++){
3555          run_tree->GetEntry(i);          run_tree->GetEntry(i);
3556          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;
3557          run_tree_clone->Fill();          run_tree_clone->Fill();
3558      }      }
3559      cout << "----------------------------------------------------"<<endl;      cout << "----------------------------------------------------"<<endl;
# Line 3488  void PamLevel2::CreateCloneTrees(TFile * Line 3566  void PamLevel2::CreateCloneTrees(TFile *
3566    
3567    
3568      sel_tree_clone = new TTree("SelectionList","List of selected events ");      sel_tree_clone = new TTree("SelectionList","List of selected events ");
3569      sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");  //    sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");
3570        sel_tree_clone->Branch("RunEntry",&irunt,"runentry/L");//NEWNEW
3571      sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/L");      sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/L");
3572            
3573    
# Line 3666  Int_t PamLevel2::GetEntry(Long64_t iee){ Line 3745  Int_t PamLevel2::GetEntry(Long64_t iee){
3745          return 0;          return 0;
3746      }      }
3747    
 //    cout << " gp_obj->P0 "<<gp_obj->P0<<endl;  
3748      //      //
3749      // ... 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.
3750      // 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
# Line 3919  Int_t PamLevel2::GetYodaEntry(){ Line 3997  Int_t PamLevel2::GetYodaEntry(){
3997  //      printf(" IDRUN %u \n",GetRunInfo()->ID);  //      printf(" IDRUN %u \n",GetRunInfo()->ID);
3998  //  //
3999          if ( prevshift != 0 && (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() ){          if ( prevshift != 0 && (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() ){
4000            prevshift = 0;              prevshift = 0;
4001            shift = -1;              shift = -1;
4002          };          };
4003    
4004      }while( ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) ||      }while( ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) ||

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

  ViewVC Help
Powered by ViewVC 1.1.23