/[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.52 by pam-fi, Mon Nov 5 13:10:13 2007 UTC revision 1.68 by pam-fi, Fri Dec 5 08:37:32 2008 UTC
# Line 284  PamTrack::PamTrack(){ Line 284  PamTrack::PamTrack(){
284      trk_track  = 0;      trk_track  = 0;
285      calo_track = 0;      calo_track = 0;
286      tof_track  = 0;      tof_track  = 0;
287        orb_track  = 0;
288      candeleteobj = 0;      candeleteobj = 0;
289      pscore = 0;      pscore = 0;
290      iscore = 0;      iscore = 0;
# Line 295  PamTrack::PamTrack(){ Line 296  PamTrack::PamTrack(){
296  /**  /**
297   * Constructor   * Constructor
298   */   */
299  PamTrack::PamTrack(TrkTrack* t, CaloTrkVar* c, ToFTrkVar* o){  PamTrack::PamTrack(TrkTrack* t, CaloTrkVar* c, ToFTrkVar* o, OrbitalInfoTrkVar *r){
300    
301      trk_track  = 0;      trk_track  = 0;
302      calo_track = 0;      calo_track = 0;
303      tof_track  = 0;      tof_track  = 0;
304        orb_track  = 0;
305  //     if(t)trk_track  = new TrkTrack(*t);  //     if(t)trk_track  = new TrkTrack(*t);
306  //     if(c)calo_track = new CaloTrkVar(*c);  //     if(c)calo_track = new CaloTrkVar(*c);
307  //     if(o)tof_track  = new ToFTrkVar(*o);  //     if(o)tof_track  = new ToFTrkVar(*o);
308      if(t)trk_track  = t;      if(t)trk_track  = t;
309      if(c)calo_track = c;      if(c)calo_track = c;
310      if(o)tof_track  = o;      if(o)tof_track  = o;
311        if(r)orb_track  = r;
312      candeleteobj = 0;      candeleteobj = 0;
313    
314  };  };
# Line 314  PamTrack::PamTrack(const PamTrack& track Line 317  PamTrack::PamTrack(const PamTrack& track
317      TrkTrack   *t = track.trk_track;      TrkTrack   *t = track.trk_track;
318      CaloTrkVar *c = track.calo_track;      CaloTrkVar *c = track.calo_track;
319      ToFTrkVar  *o = track.tof_track;      ToFTrkVar  *o = track.tof_track;
320        OrbitalInfoTrkVar  *r = track.orb_track;
321    
322      trk_track  = 0;      trk_track  = 0;
323      calo_track = 0;      calo_track = 0;
324      tof_track  = 0;      tof_track  = 0;
325        orb_track  = 0;
326      if(t)trk_track  = new TrkTrack(*t);      if(t)trk_track  = new TrkTrack(*t);
327      if(c)calo_track = new CaloTrkVar(*c);      if(c)calo_track = new CaloTrkVar(*c);
328      if(o)tof_track  = new ToFTrkVar(*o);      if(o)tof_track  = new ToFTrkVar(*o);
329        if(r)orb_track  = new OrbitalInfoTrkVar(*r);
330      candeleteobj = 1;      candeleteobj = 1;
331            
332  }  }
# Line 331  void PamTrack::Clear(){ Line 337  void PamTrack::Clear(){
337          if(trk_track)  trk_track->TrkTrack::Clear();          if(trk_track)  trk_track->TrkTrack::Clear();
338          if(calo_track) calo_track->CaloTrkVar::Clear();//???          if(calo_track) calo_track->CaloTrkVar::Clear();//???
339          if(tof_track)  tof_track->ToFTrkVar::Clear();//???          if(tof_track)  tof_track->ToFTrkVar::Clear();//???
340            if(orb_track)  orb_track->OrbitalInfoTrkVar::Clear();//???
341      }else{      }else{
342          trk_track  = 0;          trk_track  = 0;
343          calo_track = 0;          calo_track = 0;
344          tof_track  = 0;          tof_track  = 0;
345            orb_track  = 0;
346      }      }
347      pscore = 0;      pscore = 0;
348      iscore = 0;      iscore = 0;
# Line 355  void PamTrack::Delete(){ Line 363  void PamTrack::Delete(){
363              tof_track->ToFTrkVar::Clear();//???              tof_track->ToFTrkVar::Clear();//???
364              delete tof_track;              delete tof_track;
365          }          }
366            if(orb_track){
367                orb_track->OrbitalInfoTrkVar::Clear();//???
368                delete orb_track;
369            }
370      }else{      }else{
371          Clear();          Clear();
372      }      }
# Line 367  void PamTrack::Delete(){ Line 379  void PamTrack::Delete(){
379   * Default Constructor   * Default Constructor
380   */   */
381  PamLevel2::PamLevel2(){  PamLevel2::PamLevel2(){
382    Initialize();      Initialize();
383  };  };
384    
385  /**  /**
# Line 385  PamLevel2::PamLevel2(){ Line 397  PamLevel2::PamLevel2(){
397   * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB   * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB
398   */   */
399  PamLevel2::PamLevel2(TString ddir,TString list,TString detlist){  PamLevel2::PamLevel2(TString ddir,TString list,TString detlist){
400    Initialize();      Initialize();
401    GetPamTree(GetListOfLevel2Files(ddir,list),detlist);      TList*  listf = GetListOfLevel2Files(ddir,list);
402    GetRunTree(GetListOfLevel2Files(ddir,list));      GetPamTree(listf,detlist);
403        GetRunTree(listf);
404  };  };
405    
406  /**  /**
# Line 398  PamLevel2::PamLevel2(TString ddir,TStrin Line 411  PamLevel2::PamLevel2(TString ddir,TStrin
411   * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB   * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB
412   */   */
413  PamLevel2::PamLevel2(TString ddir,TString list){  PamLevel2::PamLevel2(TString ddir,TString list){
414    Initialize();      Initialize();
415    GetPamTree(GetListOfLevel2Files(ddir,list),"");      TList*  listf = GetListOfLevel2Files(ddir,list);
416    GetRunTree(GetListOfLevel2Files(ddir,list));      GetPamTree(listf,"");
417        GetRunTree(listf);
418  };  };
419    
420    
# Line 426  void PamLevel2::Initialize(){ Line 440  void PamLevel2::Initialize(){
440      run_obj   = 0;//new GL_RUN();      run_obj   = 0;//new GL_RUN();
441      soft_obj   = 0;// Emiliano      soft_obj   = 0;// Emiliano
442      irun = -1LL;      irun = -1LL;
443        irunt = -1LL;
444      runfirstentry = 0LL;      runfirstentry = 0LL;
445      runlastentry = 0LL;      runlastentry = 0LL;
446    
# Line 448  void PamLevel2::Initialize(){ Line 463  void PamLevel2::Initialize(){
463    
464      totdltime[0] = 0LL;      totdltime[0] = 0LL;
465      totdltime[1] = 0LL;      totdltime[1] = 0LL;
466        totdltime[2] = 0LL;
467    
468      host = "mysql://localhost/pamelaprod";      host = "mysql://localhost/pamelaprod";
469      user = "anonymous";      user = "anonymous";
# Line 488  void PamLevel2::Initialize(){ Line 504  void PamLevel2::Initialize(){
504    
505      ISGP = false;      ISGP = false;
506    
507        DBG = false;
508    
509      tsorted=0;      tsorted=0;
510      timage=0;      timage=0;
511            
# Line 538  void PamLevel2::Delete(){ Line 556  void PamLevel2::Delete(){
556      if(l0_file)l0_file->Close();      if(l0_file)l0_file->Close();
557      //    if(pam_tree)pam_tree->Delete();;      //    if(pam_tree)pam_tree->Delete();;
558    
559    if ( pam_tree ){      if ( pam_tree ){
560      //          //
561      // 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...
562      //          //
563      TList *temp = pam_tree->GetListOfFriends();          TList *temp = pam_tree->GetListOfFriends();
564      TList *contents  = new TList; // create chain friend list          TList *contents  = new TList; // create chain friend list
565      contents->SetOwner();          contents->SetOwner();
566      TIter next(temp);          TIter next(temp);
567      TChain *questo = 0;          TChain *questo = 0;
568      while ( (questo = (TChain*) next()) ){          while ( (questo = (TChain*) next()) ){
569        TString name =  questo->GetName();              TString name =  questo->GetName();
570        contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list              contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list
571      };          };
572      //          //
573      // deleting the main chain          // deleting the main chain
574      //          //
575      pam_tree->Delete();          pam_tree->Delete();
576      //          //
577      // deleting the friends...          // deleting the friends...
578      //          //
579      TIter next2(contents);          TIter next2(contents);
580      TChain *questa = 0;          TChain *questa = 0;
581      while ( questa = (TChain*)next2() ){          while ( questa = (TChain*)next2() ){
582        TString name =  questa->GetName();              TString name =  questa->GetName();
583        questa->Delete();                    questa->Delete();      
584        questa=NULL;              questa=NULL;
585            };
586            //
587      };      };
588      //      pam_tree = NULL;
   };  
   pam_tree = NULL;  
589    
590      if(run_tree)run_tree->Delete();;      if(run_tree)run_tree->Delete();;
591      if(sel_tree)sel_tree->Delete();;      if(sel_tree)sel_tree->Delete();;
# Line 575  void PamLevel2::Delete(){ Line 593  void PamLevel2::Delete(){
593      if(run_tree_clone)run_tree_clone->Delete();;      if(run_tree_clone)run_tree_clone->Delete();;
594      if(sel_tree_clone)sel_tree_clone->Delete();;      if(sel_tree_clone)sel_tree_clone->Delete();;
595            
596        if(irunoffset) delete [] irunoffset;
597    
598  };  };
599    
# Line 621  void PamLevel2::Clear(){ Line 640  void PamLevel2::Clear(){
640  };  };
641    
642  void PamLevel2::Reset(){  void PamLevel2::Reset(){
   //  
   // First of all clear everything  
   //  
   Clear();  
   //  
   // close and reset chains and pointers  
   //      
   if ( pam_tree ){  
643      //      //
644      // 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
645        //
646        Clear();
647        //
648        // close and reset chains and pointers
649        //    
650        if ( pam_tree ){
651            //
652            // 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...
653            //
654            TList *temp = pam_tree->GetListOfFriends();
655            TList *contents  = new TList; // create chain friend list
656            contents->SetOwner();
657            TIter next(temp);
658            TChain *questo = 0;
659            while ( (questo = (TChain*) next()) ){
660                TString name =  questo->GetName();
661                contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list
662            };
663            //
664            // deleting the main chain
665            //
666            pam_tree->Delete();
667            //
668            // deleting the friends...
669            //
670            TIter next2(contents);
671            TChain *questa = 0;
672            while ( questa = (TChain*)next2() ){
673                TString name =  questa->GetName();
674                questa->Delete();      
675                questa=NULL;
676            };
677            //
678        };
679        pam_tree = NULL;
680        //
681        if(run_tree)run_tree->Delete();;
682        run_tree = NULL;
683        if(sel_tree)sel_tree->Delete();;
684        sel_tree = NULL;
685        //
686        // Close file
687        //
688        if(l0_file)l0_file->Close("R");
689        l0_file = NULL;
690        //
691        h0_obj    = 0;
692        trk0_obj  = 0;
693        calo0_obj  = 0;
694        //
695        trk2_obj  = 0;
696        trk1_obj  = 0;
697        trkh_obj  = 0;
698        calo1_obj = 0;
699        calo2_obj = 0;
700        tof_obj   = 0;
701        trig_obj  = 0;
702        s4_obj    = 0;
703        nd_obj    = 0;
704        ac_obj    = 0;
705        orb_obj   = 0;
706        gp_obj    = 0;
707        //
708        // Reset run pointers
709        //
710        run_obj   = 0;//new GL_RUN();
711        soft_obj   = 0;// Emiliano
712        irun = -1;
713        irunt = -1;
714        runfirstentry = 0ULL;
715        runlastentry = 0ULL;    
716        //
717        totdltime[0] = 0LL;
718        totdltime[1] = 0LL;
719        totdltime[2] = 0LL;
720      //      //
     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;  
   //  
721  };  };
722    
723  Bool_t PamLevel2::IsGood(){  Bool_t PamLevel2::IsGood(){
724    Bool_t goodev=true;      Bool_t goodev=true;
725    //  if(trk2_obj && trk2_obj->UnpackError() != 0 ) goodev = false;      if(trk2_obj && trk2_obj->UnpackError() != 0 ) goodev = false;
726    if(calo2_obj && calo2_obj->good != 1) goodev = false;      if(calo2_obj && calo2_obj->good != 1) goodev = false;
727    if(tof_obj && tof_obj->unpackError != 0) goodev = false;        if(tof_obj && tof_obj->unpackError != 0) goodev = false;  
728    if(trig_obj && trig_obj->unpackError != 0) goodev = false;      if(trig_obj && trig_obj->unpackError != 0) goodev = false;
729    if(s4_obj && s4_obj->unpackError != 0) goodev = false;        if(s4_obj && s4_obj->unpackError != 0) goodev = false;  
730    if(nd_obj && nd_obj->unpackError != 0) goodev = false;        if(nd_obj && nd_obj->unpackError != 0) goodev = false;  
731    if(ac_obj && ac_obj->unpackError != 255) goodev = false;        if(ac_obj && ac_obj->unpackError != 255) goodev = false;  
732      //  if(orb_obj)        //  if(orb_obj)  
733    return goodev;      return goodev;
734  };  };
735    
736  //--------------------------------------  //--------------------------------------
# Line 735  void *PamLevel2::GetPointerTo(const char Line 756  void *PamLevel2::GetPointerTo(const char
756          return &trk2_obj;          return &trk2_obj;
757      };      };
758      if(!objname.CompareTo("TrkHough"))   {      if(!objname.CompareTo("TrkHough"))   {
759          if(!trkh_obj)  trkh_obj  = new TrkHough();          if(!trkh_obj)  {
760                trkh_obj  = new TrkHough();
761                trkh_obj->Set();
762            }
763          return &trkh_obj;          return &trkh_obj;
764      };      };
765      if(!objname.CompareTo("CaloLevel1")) {      if(!objname.CompareTo("CaloLevel1")) {
# Line 795  void *PamLevel2::GetPointerTo(const char Line 819  void *PamLevel2::GetPointerTo(const char
819   * Retrieves the calorimeter track matching the seqno-th tracker stored track.   * Retrieves the calorimeter track matching the seqno-th tracker stored track.
820   * (If seqno = -1 retrieves the self-trigger calorimeter track)   * (If seqno = -1 retrieves the self-trigger calorimeter track)
821   */   */
822   CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){  CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){
823        
824        if( !calo2_obj )return 0;
825    
826        if( calo2_obj->CaloLevel2::ntrk()==0 ){
827            cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<<endl;
828            return NULL;
829        };
830        
831        CaloTrkVar *c = 0;
832        Int_t it_calo=0;
833        
834        do{
835            c = calo2_obj->CaloLevel2::GetCaloTrkVar(it_calo);
836            it_calo++;
837        } while( c && seqno != c->trkseqno && it_calo < calo2_obj->CaloLevel2::ntrk());    
838            
839       if( !calo2_obj )return 0;      if(!c || seqno != c->trkseqno){
840            c = 0;
841            if(seqno!=-1)cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match Calorimeter stored tracks"<<endl;
842        };
843        return c;
844        
845    };
846    //--------------------------------------
847    //
848    //
849    //--------------------------------------
850    /**
851     * Retrieves the ToF track matching the seqno-th tracker stored track.
852     * (If seqno = -1 retrieves the tracker-independent tof track)
853     */
854    ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){
855            
856        if( !tof_obj )return 0;
857    
858       if( calo2_obj->CaloLevel2::ntrk()==0 ){      if( tof_obj->ToFLevel2::ntrk()==0 ){
859           cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<<endl;          cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no ToF tracks are stored"<<endl;
860           return NULL;          return NULL;
861       };      };
862            
863       CaloTrkVar *c = 0;      ToFTrkVar *c = 0;
864       Int_t it_calo=0;      Int_t it_tof=0;
865            
866       do{      do{
867           c = calo2_obj->CaloLevel2::GetCaloTrkVar(it_calo);          c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);
868           it_calo++;          it_tof++;
869       } while( c && seqno != c->trkseqno && it_calo < calo2_obj->CaloLevel2::ntrk());          } while( c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());
870            
871       if(!c || seqno != c->trkseqno){      if(!c || seqno != c->trkseqno){
872           c = 0;          c = 0;
873           if(seqno!=-1)cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match Calorimeter stored tracks"<<endl;          if(seqno!=-1)cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match ToF stored tracks"<<endl;
874       };      };
875       return c;      return c;
876            
877   };  };
878    
879  //--------------------------------------  //--------------------------------------
880   //  //
881   //  //
882  //--------------------------------------  //--------------------------------------
883  /**  /**
884    * Retrieves the ToF track matching the seqno-th tracker stored track.   * Retrieves the OrbitalInfo track matching the seqno-th tracker stored track.
885    * (If seqno = -1 retrieves the tracker-independent tof track)   * (If seqno = -1 retrieves the tracker-independent tof related track)
886   */   */
887   ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){  OrbitalInfoTrkVar *PamLevel2::GetOrbitalInfoStoredTrack(int seqno){
888                    
889       if( !tof_obj )return 0;      if( !orb_obj )return 0;
890    
891       if( tof_obj->ToFLevel2::ntrk()==0 ){      if( orb_obj->OrbitalInfo::ntrk()==0 ){
892           cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no ToF tracks are stored"<<endl;          cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no OrbitalInfo tracks are stored"<<endl;
893           return NULL;          return NULL;
894       };      };
895            
896       ToFTrkVar *c = 0;      OrbitalInfoTrkVar *c = 0;
897       Int_t it_tof=0;      Int_t it_tof=0;
898            
899       do{      do{
900           c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);          c = orb_obj->OrbitalInfo::GetOrbitalInfoTrkVar(it_tof);
901           it_tof++;          it_tof++;
902       } while( c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());              } while( c && seqno != c->trkseqno && it_tof < orb_obj->OrbitalInfo::ntrk());      
903            
904       if(!c || seqno != c->trkseqno){      if(!c || seqno != c->trkseqno){
905           c = 0;          c = 0;
906           if(seqno!=-1)cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match ToF stored tracks"<<endl;          if(seqno!=-1)cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match OrbitalInfo stored tracks"<<endl;
907       };      };
908       return c;      return c;
909            
910   };  };
911    
912  //--------------------------------------  //--------------------------------------
913   //  //
914   //  //
915  //--------------------------------------  //--------------------------------------
916  /**  /**
917   * Give the pamela track associated to a tracker track, retrieving related calorimeter and tof track information.   * Give the pamela track associated to a tracker track, retrieving related calorimeter, orbitalinfo and tof track information.
918   */   */
919   PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){  PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){
920            
921       cout <<"PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** "<<endl;      cout <<"PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** "<<endl;
922       cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;      cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;
923    
924       CaloTrkVar *c = 0;      CaloTrkVar *c = 0;
925       ToFTrkVar  *o = 0;      ToFTrkVar  *o = 0;
926        OrbitalInfoTrkVar  *r = 0;
927            
928       if(CAL2) c = GetCaloStoredTrack(t->GetSeqNo());      if(CAL2) c = GetCaloStoredTrack(t->GetSeqNo());
929       if(TOF) o = GetToFStoredTrack(t->GetSeqNo());      if(TOF) o = GetToFStoredTrack(t->GetSeqNo());
930        if(ORB) r = GetOrbitalInfoStoredTrack(t->GetSeqNo());
931            
932  //    if(t && c && o)track = new PamTrack(t,c,o);  //    if(t && c && o)track = new PamTrack(t,c,o);
933       PamTrack *track = new PamTrack(t,c,o);      PamTrack *track = new PamTrack(t,c,o,r);
934            
935       return track;      return track;
936    
937   };  };
938  //--------------------------------------  //--------------------------------------
939  //  //
940  //  //
# Line 889  void *PamLevel2::GetPointerTo(const char Line 948  void *PamLevel2::GetPointerTo(const char
948  PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){  PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){
949            
950      cout <<"PamLevel2::GetStoredTrack(Int_t itrk) **to-be-updated** "<<endl;      cout <<"PamLevel2::GetStoredTrack(Int_t itrk) **to-be-updated** "<<endl;
951      cout <<"for the moment, better use separately the methods: TrkLevel2::GetStoredTrack(seqno) CaloLevel2::GetCaloTrkVar(Int_t notrack) ToFLevel2::GetToFTrkVar(Int_t notrack)"<<endl;      cout <<"for the moment, better use separately the methods: TrkLevel2::GetStoredTrack(seqno) CaloLevel2::GetCaloTrkVar(Int_t notrack) ToFLevel2::GetToFTrkVar(Int_t notrack) OrbitalInfo::GetOrbitalInfoTrkVar(Int_t notrack)"<<endl;
952      cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;      cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;
953      PamTrack *track = 0;      PamTrack *track = 0;
954            
# Line 911  PamTrack* PamLevel2::GetStoredTrack(Int_ Line 970  PamTrack* PamLevel2::GetStoredTrack(Int_
970  //  //
971    
972  /**  /**
973   * 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.
974   **/   **/
975  void PamLevel2::SortTracks(TString how){  void PamLevel2::SortTracks(TString how){
976    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());
977    howtosort = how;        howtosort = how;  
978    SortTracks();      SortTracks();
979  };  };
980    
981  //  //
982  //--------------------------------------  //--------------------------------------
983  /**  /**
984   * Sort physical (tracker) tracks and stores them in the TRefArray (of TrkTrack objects) which pointer is  PamLevel2::sorted_tracks.   * Sort physical (tracker) tracks.
985   * @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...).
986   * Sorting cryteria:   * Sorting cryteria:
987   * TRK: lower chi**2   * TRK: lower chi**2
988   * CAL: lower Y spatial residual on the first calorimeter plane   * CAL: lower Y spatial residual on the first calorimeter plane
989   * 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).
990     * S1: (ask Emiliano)
991     * S2: (ask Emiliano)
992     * S3: (ask Emiliano)
993     * GP: more GP hits
994   * The default sorting cryterium is "TOF+CAL".   * The default sorting cryterium is "TOF+CAL".
995   *   *
996   * 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).
997   */   */
998  void PamLevel2::SortTracks(){  void PamLevel2::SortTracks(){
999    TString how = howtosort;      TString how = howtosort;
1000    
1001    //  cout <<" PamLevel2::SortTracks(TString how) "<<endl;      //  cout <<" PamLevel2::SortTracks(TString how) "<<endl;
1002    if( !trk2_obj ){      if( !trk2_obj ){
1003      cout << "void PamLevel2::SortTracks():  TrkLevel2 not loaded !!!";          cout << "void PamLevel2::SortTracks():  TrkLevel2 not loaded !!!";
1004      return;          return;
1005    };      };
1006    //    cout << "call SortTracs() "<<endl;      //Save current Object count
1007    //Save current Object count      Int_t ObjectNumber = TProcessID::GetObjectCount();
   Int_t ObjectNumber = TProcessID::GetObjectCount();  
   
   //    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;  
1008    
1009        // create TCloneArrays to store tracks and its images
1010        if(!tsorted)tsorted = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
1011        tsorted->Delete();
1012        TClonesArray &ttsorted = *tsorted;
1013    
1014        if(!timage)timage = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
1015        timage->Delete();
1016        TClonesArray &ttimage = *timage;
1017    
1018    
1019    //--------------------------------------------------  
1020    // retrieve sorting method      //--------------------------------------------------
1021    //--------------------------------------------------      // retrieve sorting method
1022    Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);      //--------------------------------------------------
1023    Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);      Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
1024    Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);      Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
1025    Bool_t use_S1 = how.Contains("S1", TString::kIgnoreCase);      Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
1026    Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase);      Bool_t use_S1 = how.Contains("S1", TString::kIgnoreCase);
1027    Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase);      Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase);
1028        Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase);
1029        Bool_t use_GP = how.Contains("GP", TString::kIgnoreCase);
1030        
1031    if ( use_TOF ){      if ( use_TOF ){
1032      use_S1 = true;          use_S1 = true;
1033      use_S2 = true;          use_S2 = true;
1034      use_S3 = true;          use_S3 = true;
1035    };      };
1036    if( !CAL2 &&  use_CAL) use_CAL = false;      if( !CAL2 &&  use_CAL) use_CAL = false;
1037    if( !TOF ){      if( !TOF ){
1038      use_TOF = false;          use_TOF = false;
1039      use_S1  = false;          use_S1  = false;
1040      use_S2  = false;          use_S2  = false;
1041      use_S3  = false;          use_S3  = false;
1042    }      }
1043        if( !GP ){
1044    if( !TRK2 ){          use_GP  = false;
1045      //  cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;      }
     return;  
   };  
1046    
1047    //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;      if( !TRK2 ){
1048            cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;
1049            return;
1050        };
1051    
1052        //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;
1053        
1054    
1055    //--------------------------------------------------      //--------------------------------------------------
1056    // loop over "physical" tracks sorted by the tracker      // loop over "physical" tracks sorted by the tracker
1057    //--------------------------------------------------      //--------------------------------------------------
1058    for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){      for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){
1059                    
1060      TrkTrack   *ts = 0;          TrkTrack   *ts = 0;
1061      CaloTrkVar *cs = 0;          CaloTrkVar *cs = 0;
1062      ToFTrkVar  *os = 0;          ToFTrkVar  *os = 0;
1063                    OrbitalInfoTrkVar  *rs = 0;
1064      // get tracker tracks          
1065      TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker          // get tracker tracks
1066      CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());          TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker
1067      ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());          CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());
1068            ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());
1069      TrkTrack   *ti = 0; //tracker (image)          OrbitalInfoTrkVar  *rp = GetOrbitalInfoStoredTrack(tp->GetSeqNo());
1070      CaloTrkVar *ci = 0;  
1071      ToFTrkVar  *oi = 0;          TrkTrack   *ti = 0; //tracker (image)
1072      //  cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;          CaloTrkVar *ci = 0;
1073      // if track has an image, check image selection          ToFTrkVar  *oi = 0;
1074            OrbitalInfoTrkVar  *ri = 0;
1075      Int_t tp_score = 0;  //main track sorted by the tracker          //      cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
1076      Int_t ti_score = 0;  //image track          // if track has an image, check image selection
1077      Int_t totp_score = 0;  //main track sorted by the tracker  
1078      Int_t toti_score = 0;  //image track          Int_t tp_score = 0;  //main track sorted by the tracker
1079            Int_t ti_score = 0;  //image track
1080            Int_t totp_score = 0;  //main track sorted by the tracker
1081            Int_t toti_score = 0;  //image track
1082    
1083      if(tp->HasImage()){          if(tp->HasImage()){
1084                            
1085        ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image)              ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image)
1086        ci = GetCaloStoredTrack(ti->GetSeqNo());              ci = GetCaloStoredTrack(ti->GetSeqNo());
1087        oi = GetToFStoredTrack(ti->GetSeqNo());              oi = GetToFStoredTrack(ti->GetSeqNo());
1088                ri = GetOrbitalInfoStoredTrack(ti->GetSeqNo());
1089                            
1090        //            cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;              //      cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;
1091    
1092        //assign starting scores              //assign starting scores
1093        tp_score = 0;  //main track sorted by the tracker              tp_score = 0;  //main track sorted by the tracker
1094        ti_score = 0;  //image track              ti_score = 0;  //image track
1095                            
1096        // -----------------------------------------------------------------------------------------              // -----------------------------------------------------------------------------------------
1097        // calorimeter check              // *****************************************************************************************
1098        // -----------------------------------------------------------------------------------------              // -----------------------------------------------------------------------------------------
1099        // check the Y spatial residual on the first calorimeter plane              // calorimeter check
1100        // (cut on calorimeter variables from Emiliano)              // -----------------------------------------------------------------------------------------
1101        if( use_CAL && !calo2_obj ){              if( use_CAL && !calo2_obj ){
1102          cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but CaloLevel2 not loaded !!!";                  cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but CaloLevel2 not loaded !!!";
1103          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);  
               };  
1104              };              };
1105            };              if( use_CAL && !cp &&  ci ){
1106            if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){                  ti_score++;
1107              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);  
               };  
1108              };              };
1109            };              if( use_CAL &&  cp && !ci ){
1110            if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){                  tp_score++;
1111              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);  
               };  
1112              };              };
1113            };              if(
1114                    use_CAL            &&
1115                    cp && ci &&
1116                    true){
1117    
1118                    
1119                    if(
1120                        cp->npresh > ci->npresh &&
1121                        true){
1122                        tp_score++;
1123                        totp_score++;
1124                    };
1125                    if(
1126                        cp->npresh < ci->npresh &&
1127                        true){
1128                        ti_score++;
1129                        toti_score++;
1130                    };
1131    
1132                    //      cout << "CALO "<<tp_score<<ti_score<<endl;
1133    
           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);  
1134              };              };
1135            };              // -----------------------------------------------------------------------------------------
1136            //              // *****************************************************************************************
1137            ti->DoTrack2(tr);              // -----------------------------------------------------------------------------------------
1138            //              // TOF check
1139            if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){              // -----------------------------------------------------------------------------------------
1140              for (Int_t ih=0; ih < oi->npmtadc; ih++){              // check the number of hit pmts along the track
1141                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );              // on S12 S21 and S32, where paddles are parallel to Y axis
1142                if(pl == 0){              if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !tof_obj ){
1143                  nphit_i++;                  cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but ToFLevel2 not loaded !!!";
1144                  enhit_i += (op->dedx).At(ih);                  return;
               };  
1145              };              };
1146            };              //
1147            if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){              if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !op && oi ){
1148              for (Int_t ih=0; ih < oi->npmtadc; ih++){                  ti_score++;
1149                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );                  toti_score++;
               if(pl == 3){  
                 nphit_i++;  
                 enhit_i += (op->dedx).At(ih);  
               };  
1150              };              };
1151            };              if( (use_TOF || use_S1 || use_S2 || use_S3 ) && op && !oi ){
1152            if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){                  tp_score++;
1153              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);  
               };  
1154              };              };
1155            };                          if( (use_TOF || use_S1 || use_S2 || use_S3 ) && op && oi ){
1156                    //
1157                    Float_t sen = 0.;
1158                    for (Int_t ih=0; ih < op->npmtadc; ih++){
1159                        Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1160                        if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (op->dedx).At(ih);
1161                    };
1162                    for (Int_t ih=0; ih < oi->npmtadc; ih++){
1163                        Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1164                        if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (oi->dedx).At(ih);
1165                    };
1166                    //
1167                    if (  sen >= sortthr && false){ // temporary disabled NUCLEI special algorithm since the new one should work for every particle (to be checked!)
1168                        //printf(" IS A NUCLEUS! en = %f \n",sen);
1169                        //
1170                        // is a nucleus use a different algorithm
1171                        //
1172                        Int_t nz = 6; Float_t zin[6];                                          // << define TOF z-coordinates
1173                        for(Int_t ip=0; ip<nz; ip++)
1174                            zin[ip] = tof_obj->ToFLevel2::GetZTOF(tof_obj->ToFLevel2::GetToFPlaneID(ip));     // << read ToF plane z-coordinates
1175                        Trajectory *tr = new Trajectory(nz,zin);
1176                        //
1177                        Int_t nphit_p =0;
1178                        Int_t nphit_i =0;
1179                        Float_t enhit_p = 0.;
1180                        Float_t enhit_i = 0.;
1181                        //
1182                        for (Int_t ih=0; ih < op->npmtadc; ih++){
1183                            Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1184                            if(pl == 1 || pl == 2 || pl == 5){
1185                                nphit_p++;
1186                                enhit_p += (op->dedx).At(ih);
1187                            };
1188                        };
1189                        //
1190                        tp->DoTrack2(tr);
1191                        //
1192                        if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){
1193                            for (Int_t ih=0; ih < op->npmtadc; ih++){
1194                                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1195                                if(pl == 0){
1196                                    nphit_p++;
1197                                    enhit_p += (op->dedx).At(ih);
1198                                };
1199                            };
1200                        };
1201                        if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){
1202                            for (Int_t ih=0; ih < op->npmtadc; ih++){
1203                                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1204                                if(pl == 3){
1205                                    nphit_p++;
1206                                    enhit_p += (op->dedx).At(ih);
1207                                };
1208                            };
1209                        };
1210                        if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
1211                            for (Int_t ih=0; ih < op->npmtadc; ih++){
1212                                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1213                                if(pl == 4){
1214                                    nphit_p++;
1215                                    enhit_p += (op->dedx).At(ih);
1216                                };
1217                            };
1218                        };
1219    
1220                        for (Int_t ih=0; ih < oi->npmtadc; ih++){
1221                            Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1222                            if(pl == 1 || pl == 2 || pl == 5){
1223                                nphit_i++;  
1224                                enhit_i += (op->dedx).At(ih);
1225                            };
1226                        };
1227                        //
1228                        ti->DoTrack2(tr);
1229                        //
1230                        if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){
1231                            for (Int_t ih=0; ih < oi->npmtadc; ih++){
1232                                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1233                                if(pl == 0){
1234                                    nphit_i++;
1235                                    enhit_i += (op->dedx).At(ih);
1236                                };
1237                            };
1238                        };
1239                        if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){
1240                            for (Int_t ih=0; ih < oi->npmtadc; ih++){
1241                                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1242                                if(pl == 3){
1243                                    nphit_i++;
1244                                    enhit_i += (op->dedx).At(ih);
1245                                };
1246                            };
1247                        };
1248                        if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
1249                            for (Int_t ih=0; ih < oi->npmtadc; ih++){
1250                                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1251                                if(pl == 4){
1252                                    nphit_i++;
1253                                    enhit_i += (op->dedx).At(ih);
1254                                };
1255                            };
1256                        };          
1257    
1258                                    
1259            if(                      if(
1260               (use_TOF || use_S1 || use_S2 || use_S3)            &&                          (use_TOF || use_S1 || use_S2 || use_S3)            &&
1261               (nphit_p+nphit_i) !=0 &&                            (nphit_p+nphit_i) !=0 &&        
1262               true){                          true){
1263                                            
1264              //      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);
1265              //      printf(" score p %i score i %i \n",tp_score,ti_score);                          //          printf(" score p %i score i %i \n",tp_score,ti_score);
1266              //            if( enhit_p > enhit_i ) tp_score++;                          //                if( enhit_p > enhit_i ) tp_score++;
1267              //            if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;                          //                if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;
1268              if ( nphit_p > nphit_i ) tp_score++;                          if ( nphit_p > nphit_i ) tp_score++;
1269              if ( nphit_p < nphit_i ) ti_score++;                          if ( nphit_p < nphit_i ) ti_score++;
1270              if ( nphit_p == nphit_i ){                          if ( nphit_p == nphit_i ){
1271                if ( enhit_p > enhit_i ) tp_score++;                              if ( enhit_p > enhit_i ) tp_score++;
1272                else ti_score++;                              else ti_score++;
1273              };                          };
1274              //      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);
1275            };                      };
1276            delete tr;                      delete tr;
1277            //                      //
1278          } else {                  } else {
1279            //                      // -------------
1280            // NOT a NUCLEUS                      // NOT a NUCLEUS
1281            //                      // -------------
1282            //printf(" NOT a NUCLEUS! en = %f \n",sen);                      //printf(" NOT a NUCLEUS! en = %f \n",sen);
1283    
1284            Int_t nphit_p =0;                      Int_t nphit_p =0;
1285            Int_t nphit_i =0;                      Int_t nphit_i =0;
1286                                    
1287                                    
1288            /*                            cout << "track: npmtadc "<< op->npmtadc << endl;                      /*                          cout << "track: npmtadc "<< op->npmtadc << endl;
1289              cout << "track: npmttdc "<< op->npmttdc << endl;                                                  cout << "track: npmttdc "<< op->npmttdc << endl;
1290              cout << "image: npmtadc "<< oi->npmtadc << endl;                                                  cout << "image: npmtadc "<< oi->npmtadc << endl;
1291              cout << "image: npmttdc "<< oi->npmttdc << endl;*/                                                  cout << "image: npmttdc "<< oi->npmttdc << endl;*/
1292                                    
1293  //        for (Int_t ih=0; ih < op->npmtadc; ih++){  //        for (Int_t ih=0; ih < op->npmtadc; ih++){
1294  //          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 1299  void PamLevel2::SortTracks(){
1299  //          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );  //          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1300  //          if(pl == 1 || pl == 2 || pl == 5)nphit_i++;  //          if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
1301  //        };  //        };
1302            // --- modified to count tdc signals (more efficient?)                      // --- modified to count tdc signals (more efficient?)
1303            // --- and to implement check on tdcflag                      // --- and to implement check on tdcflag
1304            for (Int_t ih=0; ih < op->npmttdc; ih++){                      for (Int_t ih=0; ih < op->npmttdc; ih++){
1305              Int_t pl = tof_obj->GetPlaneIndex( (op->pmttdc).At(ih) );                          Int_t pl = tof_obj->GetPlaneIndex( (op->pmttdc).At(ih) );
1306  //          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++;
1307              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 )) ){
1308                if( (op->tdcflag).At(ih)==0 )nphit_p++;                              if( (op->tdcflag).At(ih)==0 )nphit_p++;
1309              };                          };
1310            };                      };
1311                                    
1312            for (Int_t ih=0; ih < oi->npmttdc; ih++){                      for (Int_t ih=0; ih < oi->npmttdc; ih++){
1313              Int_t pl = tof_obj->GetPlaneIndex( (oi->pmttdc).At(ih) );                          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmttdc).At(ih) );
1314  //          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++;  
1315              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 )) ){
1316                if( (oi->tdcflag).At(ih)==0 )nphit_i++;                                if( (oi->tdcflag).At(ih)==0 )nphit_i++;    
1317              };                          };
1318            };                      };
1319                                    
1320            if(                      if(
1321               (nphit_p+nphit_i) !=0 &&                            (nphit_p+nphit_i) !=0 &&        
1322               true){                          true){
1323                                            
1324              if ( nphit_p != nphit_i ){                          if ( nphit_p != nphit_i ){
1325                totp_score += nphit_p;                              totp_score += nphit_p;
1326                toti_score += nphit_i;                              toti_score += nphit_i;
1327                tp_score+=nphit_p;                              tp_score+=nphit_p;
1328                ti_score+=nphit_i;                              ti_score+=nphit_i;
1329                            };
1330                            //          if     ( nphit_p > nphit_i) tp_score+=nphit_p;
1331                            //          else if( nphit_p < nphit_i) ti_score+=nphit_i;
1332                            //          else ;//niente
1333                        };
1334                    };
1335                    //      cout << "TOF "<<tp_score<<ti_score<<endl;
1336              };              };
             //      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;  
       };  
1337    
1338    
1339  //      if(tp_score == ti_score) use_TRK = true;  //      if(tp_score == ti_score) use_TRK = true;
1340    
1341    
1342        // -----------------------------------------------------------------------------------------              // -----------------------------------------------------------------------------------------
1343        // tracker check              // *****************************************************************************************
1344        // -----------------------------------------------------------------------------------------              // -----------------------------------------------------------------------------------------
1345        // chi**2 difference is not always large enough to distinguish among              // tracker check
1346        // the real track and its image.              // -----------------------------------------------------------------------------------------
1347        // Tracker check will be applied always when calorimeter and tof information is ambiguous.              // chi**2 difference is not always large enough to distinguish among
1348        // *** MODIFIED ON AUGUST 2007 ***              // the real track and its image.
1349        if(use_TRK){              // Tracker check will be applied always when calorimeter and tof information is ambiguous.
1350                // *** MODIFIED ON AUGUST 2007 ***
1351                if(use_TRK){
1352  //      if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;  //      if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
1353  //      else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;  //      else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
1354    
1355            // CHECK 1 : number of points along X                    // CHECK 1 : number of points along X  
1356          if ( tp->GetNX() >= ti->GetNX() ){                  if ( tp->GetNX() >= ti->GetNX() ){
1357            tp_score++ ;                      tp_score++ ;
1358            totp_score++ ;                      totp_score++ ;
1359          };                  };
1360          if ( tp->GetNX() <= ti->GetNX() ){                  if ( tp->GetNX() <= ti->GetNX() ){
1361            ti_score++ ;                      ti_score++ ;
1362            toti_score++ ;                      toti_score++ ;
1363          };                  };
1364            // CHECK 2 : number of points along Y                    // CHECK 2 : number of points along Y  
1365          if ( tp->GetNY() >= ti->GetNY() ){                  if ( tp->GetNY() >= ti->GetNY() ){
1366            tp_score++ ;                      tp_score++ ;
1367            totp_score++ ;                      totp_score++ ;
1368          };                  };
1369          if ( tp->GetNY() <= ti->GetNY() ){                  if ( tp->GetNY() <= ti->GetNY() ){
1370            ti_score++ ;                      ti_score++ ;
1371            toti_score++ ;                      toti_score++ ;
1372          };                  };
           // 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++ ;  
1373    
1374          //      cout << "TRK "<<tp_score<<ti_score<<endl;                  //      cout << "TRK "<<tp_score<<ti_score<<endl;
1375        };              };
1376                            
1377    
1378                // -----------------------------------------------------------------------------------------
1379                // *****************************************************************************************
1380                // -----------------------------------------------------------------------------------------
1381                // GPamela check
1382                // -----------------------------------------------------------------------------------------
1383                
1384                //---------------------------------------------------
1385                // count the number of GP hits
1386                //---------------------------------------------------
1387                if(use_GP){
1388                    int ngphits_p=0;
1389                    int ngphits_i=0;
1390                    float toll = 0.02; //200 micron
1391                    for(int ih=0; ih<GetGPamela()->Nthspe; ih++){
1392                        int ip = (Int_t) GetGPamela()->Itrpb[ih] - 1;
1393                        if(
1394                            tp &&
1395                            tp->YGood(ip) &&
1396                            fabs(tp->ym[ip]- GetGPamela()->Yavspe[ih])<toll &&
1397                            true) ngphits_p++;
1398                        if( ti &&
1399                            ti->YGood(ip) &&
1400                            fabs(ti->ym[ip]- GetGPamela()->Yavspe[ih])<toll &&
1401                            true) ngphits_i++;
1402                    }
1403                    if(
1404                        ngphits_p > ngphits_i &&
1405                        true){
1406                        tp_score++ ;
1407                        totp_score++ ;                  
1408                    }
1409                    if(
1410                        ngphits_p < ngphits_i &&
1411                        true){
1412                        ti_score++ ;
1413                        toti_score++ ;                  
1414                    }
1415                }
1416    
       // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*  
       // the winner is....  
       // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*  
       if      (tp_score > ti_score) {  
           
   
       }else if (tp_score < ti_score) {  
1417    
1418                // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1419                // the winner is....
1420                // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1421                if      (tp_score > ti_score) {
1422            
1423    
1424          ts = ti;//its image!!              }else if (tp_score < ti_score) {
         cs = ci;  
         os = oi;  
         Int_t totis = toti_score;  
1425    
         ti = tp;//its image!!  
         ci = cp;  
         oi = op;  
1426    
1427          tp = ts;//its image!!                  ts = ti;//its image!!
1428          cp = cs;                  cs = ci;
1429          op = os;                  os = oi;
1430                    rs = ri;
1431                    Int_t totis = toti_score;
1432    
1433                    ti = tp;//its image!!
1434                    ci = cp;
1435                    oi = op;
1436                    ri = rp;
1437    
1438                    tp = ts;//its image!!
1439                    cp = cs;
1440                    op = os;
1441                    rp = rs;
1442    
1443          toti_score = totp_score;                  toti_score = totp_score;
1444          totp_score = totis;                  totp_score = totis;
1445    
1446                                    
1447        }else {              }else {
1448    
1449  //      cout << "Warning - track image ambiguity not solved" << endl;  //      cout << "Warning - track image ambiguity not solved" << endl;
1450    
1451        };              };
1452                            
1453      }else{          }else{
1454        totp_score = 1;              totp_score = 1;
1455        toti_score = 0;              toti_score = 0;
1456                
1457        //            ts = tp;              //      ts = tp;
1458        //            cs = cp;              //      cs = cp;
1459        //            os = op;              //      os = op;
1460      };          };
1461                    
1462      //  cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;          //      cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
1463      //  sorted_tracks->Add(ts);//save the track in the sorted array          //      sorted_tracks->Add(ts);//save the track in the sorted array
1464      //  sorted_tracks.Add(ts);//save the track in the sorted array          //      sorted_tracks.Add(ts);//save the track in the sorted array
1465      //  sorted_tracks.Add(tp);//save the track in the sorted array          //      sorted_tracks.Add(tp);//save the track in the sorted array
1466      //  cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;          //      cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
1467      //  cout<<"o "<<tp<<endl;          //      cout<<"o "<<tp<<endl;
1468      //  cout<<"o "<<cp<<endl;          //      cout<<"o "<<cp<<endl;
1469      //  cout<<"o "<<op<<endl;          //      cout<<"o "<<op<<endl;
1470    
1471      new(ttsorted[i]) PamTrack(tp,cp,op);          new(ttsorted[i]) PamTrack(tp,cp,op,rp);
1472      new(ttimage[i])  PamTrack(ti,ci,oi);          new(ttimage[i])  PamTrack(ti,ci,oi,ri);
1473    
1474      ((PamTrack*)(ttsorted[i]))->SetPScore(totp_score);          ((PamTrack*)(ttsorted[i]))->SetPScore(totp_score);
1475      ((PamTrack*)(ttsorted[i]))->SetIScore(toti_score);          ((PamTrack*)(ttsorted[i]))->SetIScore(toti_score);
1476      ((PamTrack*)(ttimage[i]))->SetPScore(totp_score);          ((PamTrack*)(ttimage[i]))->SetPScore(totp_score);
1477      ((PamTrack*)(ttimage[i]))->SetIScore(toti_score);          ((PamTrack*)(ttimage[i]))->SetIScore(toti_score);
1478    };      };
1479    
1480    if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){      if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){
1481      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;
1482      tsorted->Delete(); tsorted=0;          tsorted->Delete(); tsorted=0;
1483      timage->Delete(); timage=0;          timage->Delete(); timage=0;    
1484    }      }
1485    
1486    //Restore Object count      //Restore Object count
1487    //To save space in the table keeping track of all referenced objects      //To save space in the table keeping track of all referenced objects
1488    //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.
1489    TProcessID::SetObjectCount(ObjectNumber);      TProcessID::SetObjectCount(ObjectNumber);
1490            
1491  };  };
1492  //--------------------------------------  //--------------------------------------
# Line 1417  TClonesArray *PamLevel2::GetTracks(){ Line 1515  TClonesArray *PamLevel2::GetTracks(){
1515    
1516      return tsorted;      return tsorted;
1517            
1518   };  };
1519  //--------------------------------------  //--------------------------------------
1520   //  //
1521   //  //
1522  //--------------------------------------  //--------------------------------------
1523  /**  /**
1524   * Retrieves the it-th Pamela "physical" track.   * Retrieves the it-th Pamela "physical" track.
# Line 1481  PamTrack *PamLevel2::GetTrack(int it){ Line 1579  PamTrack *PamLevel2::GetTrack(int it){
1579   */   */
1580  PamTrack *PamLevel2::GetTrackImage(int it){  PamTrack *PamLevel2::GetTrackImage(int it){
1581    
 //     if(!trk2_obj) return 0;  
   
 // //  *-*-*-*-*-*-*-*-*-*-*-*-*  
 //     SortTracks("+CAL+TOF");  
 // //  *-*-*-*-*-*-*-*-*-*-*-*-*  
 // //    if(!sorted_tracks)return 0;  
 //     if(sorted_tracks.IsEmpty())return 0;  
       
 //     PamTrack *image = 0;  
       
 //     if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() ){  
 //      TrkTrack *temp = (TrkTrack*)sorted_tracks.At(it);  
 //      if( temp->HasImage() ){  
 //          TrkTrack   *t = trk2_obj->TrkLevel2::GetStoredTrack(temp->GetImageSeqNo());  
 //          image = GetPamTrackAlong(t);  
 //      }else{  
 //          cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;  
 //      };  
 //     }else{  
 //      cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;  
 //     };  
       
 //     return image;  
   
   
1582  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1583      SortTracks();      SortTracks();
1584  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
# Line 1552  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1625  TTree *PamLevel2::GetPamTree(TFile *f, T
1625          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 ");
1626          return pam_tree;          return pam_tree;
1627      };      };
1628    //      //
1629    
1630      cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;      cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;
1631    
# Line 1698  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1771  TTree *PamLevel2::GetPamTree(TFile *f, T
1771    
1772      TTree *L = (TTree*)f->Get("SelectionList");      TTree *L = (TTree*)f->Get("SelectionList");
1773      if(L && SELLI==1) {      if(L && SELLI==1) {
1774  //      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;  
1775          sel_tree = 0;          sel_tree = 0;
1776      }else{      }else{
1777          cout << "SelectionList  : missing tree"<<endl;          cout << "SelectionList  : missing tree"<<endl;
# Line 1749  TList*  PamLevel2::GetListOfLevel2Files( Line 1816  TList*  PamLevel2::GetListOfLevel2Files(
1816      //    if(ddir=="")ddir = wdir;      //    if(ddir=="")ddir = wdir;
1817  //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);  //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
1818      if ( ddir != ""){      if ( ddir != ""){
1819        cout << "Level2 data directory : "<<  ddir << endl;          cout << "Level2 data directory : "<<  ddir << endl;
1820      } else {      } else {
1821        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;
1822      };      };
1823      TList *contents  = new TList; // create output list      TList *contents  = new TList; // create output list
1824      contents->SetOwner();      contents->SetOwner();
# Line 1768  TList*  PamLevel2::GetListOfLevel2Files( Line 1835  TList*  PamLevel2::GetListOfLevel2Files(
1835  //          return 0;  //          return 0;
1836  //      }        //      }      
1837  //      flisttxt = fullpath;  //      flisttxt = fullpath;
1838        if ( !flisttxt.EndsWith(".root") ){          if ( !flisttxt.EndsWith(".root") ){
1839    
1840          flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));              flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1841    
1842          if( !gSystem->ChangeDirectory(ddir) ){              if( !gSystem->ChangeDirectory(ddir) ){
1843              cout << "Cannot change directory : "<<ddir<<endl;                  cout << "Cannot change directory : "<<ddir<<endl;
1844              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;  
1845              }              }
1846              if(file.Contains("#"))file = file(0,file.First("#"));          
1847                cout <<"Input file list : " << flisttxt <<endl;
1848                ifstream in;
1849                in.open(flisttxt, ios::in); //open input file list
1850                if(!in.good()){
1851                    cout <<" ERROR opening the file "<<endl;
1852                    gSystem->ChangeDirectory(wdir); // back to the working directory
1853                    return 0;
1854                }  
1855                int line=0;
1856                while (1) {
1857                    TString file;
1858                    in >> file;
1859                    if (!in.good()) break;
1860                    line++;
1861    //          cout <<"(1) " << file << endl;
1862                    if(file.IsNull()){
1863                        cout << "-- list interrupted at line "<<line <<endl;
1864                        break;
1865                    }
1866                    if(file.Contains("#"))file = file(0,file.First("#"));
1867  //          cout <<"(2) " << file << endl;  //          cout <<"(2) " << file << endl;
1868  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){
1869  //          if( (fullpath = gSystem->FindFile(ddir,file)) ){  //          if( (fullpath = gSystem->FindFile(ddir,file)) ){
1870              if( file.EndsWith(".root") ){                  if( file.EndsWith(".root") ){
1871                TString filedir;                      TString filedir;
1872                if (ddir != ""){                      if (ddir != ""){
1873                  filedir = ddir; // take the input dir                          filedir = ddir; // take the input dir
1874                } else {                      } else {
1875                  gSystem->ChangeDirectory(wdir); // back to the working directory                          gSystem->ChangeDirectory(wdir); // back to the working directory
1876                  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
1877                };                      };
1878                  char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir),gSystem->BaseName(file));                      char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir),gSystem->BaseName(file));
1879                  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
1880                  delete fullpath;                      delete fullpath;
1881              }                  }
1882  //          }else{  //          }else{
1883  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;
1884  //          };  //          };
1885          };              };
1886          in.close();              in.close();
1887        } else {          } else {
1888            if(flisttxt.Contains("#"))flisttxt = flisttxt(0,flisttxt.First("#"));              if(flisttxt.Contains("#"))flisttxt = flisttxt(0,flisttxt.First("#"));
1889            char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));              char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1890            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
1891            delete fullpath;              delete fullpath;
1892        };                  };      
1893      }else{      }else{
1894                    
1895          cout << "No input file list given."<<endl;          cout << "No input file list given."<<endl;
1896          cout << "Check for existing root files."<<endl;          cout << "Check for existing root files."<<endl;
1897  //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;  //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;
1898          if ( ddir == "" ){          if ( ddir == "" ){
1899            ddir = wdir;              ddir = wdir;
1900            cout << "Level2 data directory : "<<  ddir << endl;              cout << "Level2 data directory : "<<  ddir << endl;
1901          };          };
1902    
1903          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
# Line 1887  TChain *PamLevel2::GetPamTree(TList *fl, Line 1954  TChain *PamLevel2::GetPamTree(TList *fl,
1954            
1955      TChain *Trout =0;      TChain *Trout =0;
1956    
1957            // -------------------------------------------
1958        // set flags to include/exclude trees/branches
1959        // -------------------------------------------
1960      if( detlist.Contains("+AUTO", TString::kIgnoreCase) ) {      if( detlist.Contains("+AUTO", TString::kIgnoreCase) ) {
1961          if( fl->GetEntries()>0 ){          if( fl->GetEntries()>0 ){
1962              cout << "+AUTO"<<endl;              cout << "+AUTO"<<endl;
1963              TFile *fprimo = new TFile( fl->At(0)->GetName() );              TFile *fprimo = new TFile( fl->At(0)->GetName() );
1964              GetWhichTrees(fprimo);              GetWhichTrees(fprimo);
1965                fprimo->Close();// AAAAARGGGGGHHHHH!!!!!!! non commentare questa riga, altrimenti si incasina il TChain
1966              fprimo->Delete();              fprimo->Delete();
1967          }          }
1968      };      };
1969      SetWhichTrees(detlist);          SetWhichTrees(detlist);    
1970    
1971    
1972        // -------------------------------------------
1973        // build chains
1974        // -------------------------------------------
1975        TChain *T = 0;      
1976        TChain *C = 0;
1977        TChain *O = 0;
1978        TChain *R = 0;
1979        TChain *S = 0;
1980        TChain *N = 0;
1981        TChain *A = 0;
1982        TChain *B = 0;
1983        TChain *G = 0;
1984    
1985  //    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;  
1986            
1987      if(TRK2||TRK1||TRKh) T = new TChain("Tracker");          if(TRK2||TRK1||TRKh) T = new TChain("Tracker");    
1988      if(CAL2||CAL1)       C = new TChain("Calorimeter");      if(CAL2||CAL1)       C = new TChain("Calorimeter");
# Line 1945  TChain *PamLevel2::GetPamTree(TList *fl, Line 2015  TChain *PamLevel2::GetPamTree(TList *fl,
2015          };          };
2016      };      };
2017            
2018      cout << "done chain \n";      cout << "done chains\n";
2019      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2020    
2021  //    UInt_t *found=0;  
2022        // -------------------------------------------
2023        // make friends
2024        // -------------------------------------------
2025    
2026  // Tracker  // Tracker
2027        cout << "Friends: "<<endl;
2028      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;  
2029          if(!Trout)Trout=T;          if(!Trout)Trout=T;
2030          else Trout->AddFriend("Tracker");          else Trout->AddFriend("Tracker");
2031      }else{  //      cout << "+Tacker"<<endl;
 //        cout << "Tracker      : missing tree"<<endl;  
2032      };      };
2033      // Calorimeter      // Calorimeter
2034      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;  
2035          if(!Trout)Trout=C;          if(!Trout)Trout=C;
2036          else Trout->AddFriend("Calorimeter");          else Trout->AddFriend("Calorimeter");
2037      }else{  //      cout << "+Calorimeter"<<endl;
 //        cout << "Calorimeter  : missing tree"<<endl;  
2038      };      };
2039      // ToF          // ToF    
2040      if(O && TOF) {      if(O && TOF) {
 //        O->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));  
 //        cout << "ToF          : set branch address ToFLevel2"<<endl;  
2041          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2042          else Trout->AddFriend("ToF");          else Trout->AddFriend("ToF");
2043      }else{  //      cout << "+ToF"<<endl;
 //        cout << "ToF         : missing tree"<<endl;  
2044      };      };
2045      // Trigger      // Trigger
2046      if(R && TRG) {      if(R && TRG) {
 //        R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));  
 //        cout << "Trigger      : set branch address TrigLevel2"<<endl;  
2047          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2048          else Trout->AddFriend("Trigger");          else Trout->AddFriend("Trigger");
2049      }else{  //      cout << "+Trigger"<<endl;
 //        cout << "Trigger      : missing tree"<<endl;  
2050      };      };
2051      // S4      // S4
2052      if(S && S4) {      if(S && S4) {
 //        S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));  
 //        cout << "S4           : set branch address S4Level2"<<endl;  
2053          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2054          else Trout->AddFriend("S4");          else Trout->AddFriend("S4");
2055      }else{  //      cout << "+S4"<<endl;
 //        cout << "S4           : missing tree"<<endl;  
2056      };      };
2057      // Neutron Detector      // Neutron Detector
2058      if(N && ND) {      if(N && ND) {
 //        N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));  
 //        cout << "NeutronD     : set branch address NDLevel2"<<endl;  
2059          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2060          else Trout->AddFriend("NeutronD");          else Trout->AddFriend("NeutronD");
2061      }else{  //      cout << "+NeutronD"<<endl;
 //        cout << "NeutronD     : missing tree"<<endl;  
2062      };      };
2063      // Anticounters      // Anticounters
2064      if(A && AC) {      if(A && AC) {
 //        A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));  
 //        cout << "Anticounter  : set branch address AcLevel2"<<endl;  
2065          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2066          else Trout->AddFriend("Anticounter");          else Trout->AddFriend("Anticounter");
2067      }else{  //      cout << "+Anticounter"<<endl;
 //        cout << "Anticounter  : missing tree"<<endl;  
2068      };      };
2069      // Orbital Info      // Orbital Info
2070      if(B && ORB) {      if(B && ORB) {
 //      B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));  
 //      cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;  
2071          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2072          else Trout->AddFriend("OrbitalInfo");          else Trout->AddFriend("OrbitalInfo");
2073      }else{  //      cout << "+OrbitalInfo"<<endl;
 //      cout << "OrbitalInfo  : missing tree"<<endl;  
2074      };      };
2075      // GPamela      // GPamela
2076      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;  
2077          if(!Trout)Trout=G;          if(!Trout)Trout=G;
2078          else Trout->AddFriend("h20");          else Trout->AddFriend("h20");
2079      }else{  //      cout << "+h20"<<endl;
 //      cout << "h20          : missing tree"<<endl;  
2080      };      };
2081    
2082  //  =====================================  //  =====================================
# Line 2050  TChain *PamLevel2::GetPamTree(TList *fl, Line 2084  TChain *PamLevel2::GetPamTree(TList *fl,
2084  //  =====================================  //  =====================================
2085      SetBranchAddress(Trout);      SetBranchAddress(Trout);
2086    
2087    
2088    //  ------------------------------------
2089    //  finally handle selection trees...
2090    //  (it is not friend of pamela tree)
2091    //  ------------------------------------
2092    
2093      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2094    
2095      // Selection List      // Selection List
2096      if(L && SELLI==1) {      if(L && SELLI==1) {
2097          cout<<">>> Found selection-list <<<"<<endl;          cout<<">>> Found selection-list <<<"<<endl;
2098          L->SetBranchAddress("RunEntry",&irun);  //      L->SetBranchAddress("RunEntry",&irun);
2099            L->SetBranchAddress("RunEntry",&irunt);//NEWNEW
2100          cout << "SelectionList: set branch address RunEntry"<<endl;          cout << "SelectionList: set branch address RunEntry"<<endl;
2101          L->SetBranchAddress("EventEntry",&irunentry);          L->SetBranchAddress("EventEntry",&irunentry);
2102          cout << "SelectionList: set branch address EventEntry"<<endl;          cout << "SelectionList: set branch address EventEntry"<<endl;
2103          sel_tree = L;          sel_tree = L;
2104  //      if(!Trout)Trout=O;  //      if(!Trout)Trout=O;
2105  //      else Trout->AddFriend("SelectionList");  //      else Trout->AddFriend("SelectionList");
2106          cout << "----------------------------------------------------" <<endl;          cout << "+SelectionList"<<endl;
2107            cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2108      }else{      }else{
2109  //      cout << "SelectionList  : missing tree"<<endl;  //      cout << "SelectionList  : missing tree"<<endl;
2110          if(L)L->Delete();          if(L)L->Delete();
2111      };      };
       
 //    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;  
 //     };  
2112    
2113    //  --------------------------------------------
2114    //  return the pamela chain with all the friends
2115    //  --------------------------------------------
2116    
2117      pam_tree = Trout;      pam_tree = Trout;
2118            
# Line 2174  void PamLevel2::SetBranchAddress(TTree * Line 2202  void PamLevel2::SetBranchAddress(TTree *
2202      if(GP) {      if(GP) {
2203  //      GetPointerTo("GPamela");  //      GetPointerTo("GPamela");
2204          if(!gp_obj)gp_obj = new GPamela();          if(!gp_obj)gp_obj = new GPamela();
2205          gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri  //      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2206    // //   t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
2207            if(SELLI) t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
2208            else      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2209    
2210          cout << "h20          : set branch address GPamela "<<endl;          cout << "h20          : set branch address GPamela "<<endl;
2211      };      };
     // 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;  
     };  
2212            
2213  }  }
2214  /**  /**
# Line 2205  void PamLevel2::SetBranchAddress(TChain Line 2230  void PamLevel2::SetBranchAddress(TChain
2230  //    GP     = GP & t->GetBranchStatus("h20");  //    GP     = GP & t->GetBranchStatus("h20");
2231    
2232      // Tracker      // Tracker
2233       if(TRK2) {      if(TRK2) {
2234          t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));          t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
2235          cout << "Tracker      : set branch address TrkLevel2"<<endl;          cout << "Tracker      : set branch address TrkLevel2"<<endl;
2236      };      };
# Line 2213  void PamLevel2::SetBranchAddress(TChain Line 2238  void PamLevel2::SetBranchAddress(TChain
2238          t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));          t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
2239          cout << "Tracker      : set branch address TrkLevel1"<<endl;          cout << "Tracker      : set branch address TrkLevel1"<<endl;
2240      };      };
2241       if(TRKh) {      if(TRKh) {
2242          t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));          t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
2243          cout << "Tracker      : set branch address TrkHough"<<endl;          cout << "Tracker      : set branch address TrkHough"<<endl;
2244       };      };
2245            
2246      // Calorimeter      // Calorimeter
2247      if(CAL2) {      if(CAL2) {
# Line 2263  void PamLevel2::SetBranchAddress(TChain Line 2288  void PamLevel2::SetBranchAddress(TChain
2288      if(GP) {      if(GP) {
2289  //      GetPointerTo("GPamela");  //      GetPointerTo("GPamela");
2290          if(!gp_obj)gp_obj = new GPamela();          if(!gp_obj)gp_obj = new GPamela();
2291          gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri          if(SELLI) t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
2292            else      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2293    //      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2294          cout << "h20          : set branch address GPamela "<<endl;          cout << "h20          : set branch address GPamela "<<endl;
2295      };      };
2296      // SelectionList      // SelectionList
2297      if(SELLI==1) {  //     if(SELLI==1){
2298          t->SetBranchAddress("RunEntry", &irun);  //      t->SetBranchAddress("RunEntry",&irunt);//NEWNEW
2299          cout << "SelectionList: set branch address RunEntry"<<endl;  //      cout << "SelectionList: set branch address RunEntry"<<endl;
2300          t->SetBranchAddress("EventEntry", &irunentry);  //      t->SetBranchAddress("EventEntry",&irunentry);
2301          cout << "SelectionList: set branch address EventEntry"<<endl;  //      cout << "SelectionList: set branch address EventEntry"<<endl;
2302      };          
2303        //     }
2304    
2305  }  }
2306    
2307    
# Line 2287  void PamLevel2::SetBranchAddress(TChain Line 2315  void PamLevel2::SetBranchAddress(TChain
2315   * @return Pointer to a TChain   * @return Pointer to a TChain
2316   */   */
2317  TChain *PamLevel2::GetRunTree(TList *fl){  TChain *PamLevel2::GetRunTree(TList *fl){
2318    //      //
2319    //      //
2320    //      //
2321    if ( run_tree ){      if ( run_tree ){
2322      printf("WARNING: TChain *PamLevel2::GetRunTree(TList *fl) -- run_tree already exists!\n ");          printf("WARNING: TChain *PamLevel2::GetRunTree(TList *fl) -- run_tree already exists!\n ");
2323      return run_tree;          return run_tree;
2324    };          };  
2325    //      //
2326    TChain *R = new TChain("Run");  
2327    
2328        TChain *R = new TChain("Run");
2329            
2330      // loop over files and create chains              // loop over files and create chains        
2331      TIter next(fl);      TIter next(fl);
# Line 2307  TChain *PamLevel2::GetRunTree(TList *fl) Line 2337  TChain *PamLevel2::GetRunTree(TList *fl)
2337              R->Add(name);              R->Add(name);
2338          };          };
2339      }      }
2340        
2341    
2342      if(R->GetNtrees()){      if(RUN && R->GetNtrees()){
2343            
2344          R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));          R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
2345          cout << "Run         : set branch address RunInfo"<<endl;          cout << "Run         : set branch address RunInfo"<<endl;
2346          R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano          R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
2347          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
2348    
2349            irunoffset = new int[R->GetNtrees()];
2350            if(DBG){
2351                cout << "----------------------------------------------------"<<endl;
2352                cout << "irun\t | ";
2353                cout << "tree\t |";
2354    //      cout << "offset\t |";
2355                cout << "RUN\t";
2356                cout << "FRAG\t";
2357                cout << "NEVENTS\t";
2358                cout << "absolute time\t\t\t";
2359                cout << "on-board time";
2360                cout<<endl;
2361            }
2362            for (Int_t ii=0; ii<R->GetEntries(); ii++){
2363                R->GetEntry(ii);
2364                if(DBG){
2365                    cout << ii<< "\t | ";
2366                    cout << R->GetTreeNumber()<< "\t |";
2367    //          cout << R->GetChainOffset()<< "\t |";
2368                    cout <<GetRunInfo()->ID<<"\t";
2369                    cout <<GetRunInfo()->ID_RUN_FRAG<<"\t";
2370                    cout <<GetRunInfo()->NEVENTS<< "\t";
2371                    cout <<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME <<"\t";
2372                    cout <<GetRunInfo()->RUNHEADER_OBT<<" <---> "<<GetRunInfo()->RUNTRAILER_OBT<<"\t";
2373                    cout <<endl;
2374                }
2375                irunoffset[R->GetTreeNumber()]=R->GetChainOffset();
2376            }
2377            cout << "N.run = "<<R->GetEntries()<<endl;
2378            cout << "----------------------------------------------------"<<endl;
2379    
2380    
2381      }else{      }else{
2382          delete R;          delete R;
2383          R=0;          R=0;
2384      }      }
2385        
2386    
2387      run_tree = R;      run_tree = R;
2388    
# Line 2334  TChain *PamLevel2::GetRunTree(TList *fl) Line 2399  TChain *PamLevel2::GetRunTree(TList *fl)
2399   * @return Pointer to a TTree   * @return Pointer to a TTree
2400   */   */
2401  TTree *PamLevel2::GetRunTree(TFile *f){  TTree *PamLevel2::GetRunTree(TFile *f){
2402    if ( run_tree ){      if ( run_tree ){
2403      printf("WARNING: TTree *PamLevel2::GetRunTree(TFile *f) -- run_tree already exists!\n ");          printf("WARNING: TTree *PamLevel2::GetRunTree(TFile *f) -- run_tree already exists!\n ");
2404      return run_tree;          return run_tree;
2405    };      };
2406                    
2407    
2408      cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;      cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;
# Line 2349  TTree *PamLevel2::GetRunTree(TFile *f){ Line 2414  TTree *PamLevel2::GetRunTree(TFile *f){
2414          cout << "Run         : set branch address RunInfo"<<endl;          cout << "Run         : set branch address RunInfo"<<endl;
2415          T->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano          T->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
2416          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
2417    
2418      }      }
2419    
2420      run_tree = (TChain*)T;      run_tree = (TChain*)T;
# Line 2362  TTree *PamLevel2::GetRunTree(TFile *f){ Line 2428  TTree *PamLevel2::GetRunTree(TFile *f){
2428   * @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
2429   */   */
2430  Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev){  Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev){
2431    //      //
2432    // check if we have already called once GetEntry, if not call it      // check if we have already called once GetEntry, if not call it
2433    //      //
2434      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;
2435      if(!run){      if(!run){
2436            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;
2437            return(false);                  return(false);  
2438      }      }
2439      if ( run->GetEntries() <= 0 ) return(false);      if ( run->GetEntries() <= 0 ) return(false);
2440    //      //
2441        
2442    //  Int_t oldrun = irun;      //  Int_t oldrun = irun;
2443    Long64_t oldrun = irun;      Long64_t oldrun = irun;
2444    
2445        // --------------------------------------
2446        // if it is a full file (not preselected)
2447        // --------------------------------------
2448        if(SELLI==0){
2449    
2450            //
2451            // the absolute time is necessary to relate the event with the run
2452            //
2453            if( !GetOrbitalInfo() && !ISGP){
2454                cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
2455                return(false);
2456            }
2457    
2458            ULong64_t abstime = 0;
2459            if( GetOrbitalInfo() )abstime=GetOrbitalInfo()->absTime;
2460    
2461    // --------------------------------------  
2462    // if it is a full file (not preselected)          //
2463    // --------------------------------------          // the first time the routine is called, set run search from the beginning
2464    if(SELLI==0){          //
2465            if ( irun < 0LL ){
2466        //              irun = 0LL;
2467        // the absolute time is necessary to relate the event with the run              run->GetEntry(irun);
2468        //              runfirstentry = 0LL;
2469        if( !GetOrbitalInfo() && !ISGP){              runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2470            cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;              if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
           return(false);  
       }  
   
       ULong64_t abstime = 0;  
       if( GetOrbitalInfo() )abstime=GetOrbitalInfo()->absTime;  
   
   
       //  
       // the first time the routine is called, set run search from the beginning  
       //  
       if ( irun < 0LL ){  
           irun = 0LL;  
           run->GetEntry(irun);  
           runfirstentry = 0LL;  
           runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);  
           if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;  
2471                        
2472            if( ISGP && run->GetEntries()!=1 ){              if( ISGP && run->GetEntries()!=1 ){
2473                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;
2474                cout << "** WARNING ** run will not be updated"<<endl;                  cout << "** WARNING ** run will not be updated"<<endl;
2475            }              }
2476    
2477        };                };      
2478        //          //
2479        if(ISGP)abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO          if(ISGP)abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO
2480        //          //
2481        if ( irun == run->GetEntries()-1LL &&          if ( irun == run->GetEntries()-1LL &&
2482             !(abstime >= GetRunInfo()->RUNHEADER_TIME &&               !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
2483               abstime <= GetRunInfo()->RUNTRAILER_TIME)                 abstime <= GetRunInfo()->RUNTRAILER_TIME)
2484              ){              ){
2485           irun = -1LL;              irun = -1LL;
2486           runfirstentry = 0LL;              irunt = -1LL;
2487           runlastentry = -1LL;              runfirstentry = 0LL;
2488         };              runlastentry = -1LL;
2489        // modificato il controllo sull'aggiornamento del run, per evitare problemi          };
2490        // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)          // modificato il controllo sull'aggiornamento del run, per evitare problemi
2491        //          // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)
2492        bool fromfirst = true;          //
2493        //          bool fromfirst = true;
2494        while ( !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1LL ){          //
2495            while ( !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1LL ){
2496  //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){  //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){
2497            irun++;              irun++;
2498            run->GetEntry(irun);              run->GetEntry(irun);
2499            runfirstentry = runlastentry;              runfirstentry = runlastentry;
2500            if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runfirstentry += 1LL;              if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runfirstentry += 1LL;
2501            runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);              runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2502  //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;  //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2503  //        cout << "runfirstentry "<<runfirstentry<<endl;  //        cout << "runfirstentry "<<runfirstentry<<endl;
2504            //      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)));
2505            //      printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME);              //    printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME);
2506            //      printf(" IDRUN %u \n",GetRunInfo()->ID);              //    printf(" IDRUN %u \n",GetRunInfo()->ID);
2507            //              //
2508  //        prevshift = 0;  //        prevshift = 0;
2509            //              //
2510            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)){
2511                printf(" resetting irun  (it should NOT happen!!!)\n");                  printf(" resetting irun  (it should NOT happen!!!)\n");
2512                fromfirst = false;                  fromfirst = false;
2513                irun = 0;                  irun = 0;
2514                run->GetEntry(irun);                  run->GetEntry(irun);
2515                runfirstentry = 0ULL;                  runfirstentry = 0ULL;
2516                runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);                  runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2517                if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;                  if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
2518            };              };
2519            //              //
2520        };          };
2521        //          //
2522        if (          if (
2523             !(abstime >= GetRunInfo()->RUNHEADER_TIME &&              !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
2524               abstime <= GetRunInfo()->RUNTRAILER_TIME)                abstime <= GetRunInfo()->RUNTRAILER_TIME)
2525            ) {              ) {
2526          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);
2527            return false;              return false;
2528        }          }
2529        //          //
2530        if ( irun == oldrun || irun >= run->GetEntries() ) return(false);          if ( irun == oldrun || irun >= run->GetEntries() ) return(false);
2531        //          //
2532        //  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);
2533        //          //
2534        prevshift = 0;          prevshift = 0;
2535        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;          cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2536  //      cout << "runfirstentry "<<runfirstentry<<endl;  //      cout << "runfirstentry "<<runfirstentry<<endl;
2537        return(true);              return(true);    
2538    };      };
2539    // ----------------------------------------------------      // ----------------------------------------------------
2540    // if it is a preselected file (there is SelectionList)      // if it is a preselected file (there is SelectionList)
2541    // NBNB - the event tree MUST be read first      // NBNB - the event tree MUST be read first
2542    // ----------------------------------------------------      // ----------------------------------------------------
2543    if(SELLI==1){            if(SELLI==1){      
2544        sel_tree->GetEntry(iev);          sel_tree->GetEntry(iev);
2545  //      cout << irun << " "<< irunentry << endl;  //      cout << irun << " "<< irunentry << endl;
2546        if(irun != oldrun){          if(irun != oldrun){
2547            run->GetEntry(irun);              run->GetEntry(irun);
2548            cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;              cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2549            prevshift = 0;              prevshift = 0;
2550            return true;              return true;
2551        }          }
2552        return false;          return false;
2553    }      }
2554    
2555    return false;      return false;
2556    //      //
2557  };  };
2558    
2559  Bool_t PamLevel2::UpdateRunInfo(Long64_t iev){  Bool_t PamLevel2::UpdateRunInfo(Long64_t iev){
# Line 2502  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2569  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2569        
2570      Int_t oldrun = irun; // store current run index      Int_t oldrun = irun; // store current run index
2571    
2572        // -----------------------------------------------------------------------
2573        // the first time the routine is called, set run search from the beginning
2574        // -----------------------------------------------------------------------
2575    
2576        if ( irun < 0 ){
2577            irun = 0LL;
2578            irunt = 0LL;
2579            irunentry = 0;
2580            prevshift = 0;
2581            run_tree->GetEntry(irun);
2582            if( !GetOrbitalInfo() )cout << "** WARNING ** missing OrbitalInfo ---> run info might be not correctly updated "<<endl;
2583        };      
2584        // ---------------------------------------------------------------
2585        // retrieve OBT and absolute time of the event
2586        // ---------------------------------------------------------------
2587        ULong64_t abstime = 0LL;
2588        ULong64_t obt     = 0LL;
2589        if( GetOrbitalInfo() ){
2590            abstime = GetOrbitalInfo()->absTime;
2591            obt     = GetOrbitalInfo()->OBT;
2592        }else{
2593            abstime = GetRunInfo()->RUNHEADER_TIME;
2594            obt     = GetRunInfo()->RUNHEADER_OBT;
2595        }
2596        
2597    
2598      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2599      // if it is a full file (not preselected)      // if it is a full file (not preselected)
2600      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2601      if(SELLI==0){      if(SELLI==0){
2602    
2603          // ---------------------------------------------------------------          // ---------------------------------------------------------------
2604          // increment dead and live-time counters          // increment dead and live-time counters
2605          // ---------------------------------------------------------------          // (only when reading a file not preselected)
         if( GetTrigLevel2() ){  
             totdltime[0]+=GetTrigLevel2()->dltime[0];  
             totdltime[1]+=GetTrigLevel2()->dltime[1];  
         }  
         totdltime[2]++;  
   
 //      cout << setw(10)<<totdltime[0]<<setw(10)<<totdltime[1]<<setw(10)<<totdltime[2]<<endl;  
   
         // ---------------------------------------------------------------  
         // retrieve OBT and absolute time of the event  
         // ---------------------------------------------------------------  
         ULong64_t abstime = 0;  
         ULong64_t obt     = 0;  
         if( GetOrbitalInfo() ){  
             abstime = GetOrbitalInfo()->absTime;  
             obt     = GetOrbitalInfo()->OBT;  
         }  
         // ---------------------------------------------------------------  
         // the absolute time is necessary to relate the event with the run  
2606          // ---------------------------------------------------------------          // ---------------------------------------------------------------
2607          if( !GetOrbitalInfo() && !ISGP ){          if(SELLI==0){
2608              cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;              if( GetTrigLevel2() ){
2609              return(false);                  totdltime[0]+=GetTrigLevel2()->dltime[0];
2610          }                  totdltime[1]+=GetTrigLevel2()->dltime[1];
         
         // -----------------------------------------------------------------------  
         // the first time the routine is called, set run search from the beginning  
         // -----------------------------------------------------------------------  
         if ( irun < 0 ){  
             irun = 0LL;  
             irunentry = 0;  
             prevshift = 0;  
             run_tree->GetEntry(irun);  
   
             if( ISGP && run_tree->GetEntries()!=1 ){  
                 cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run_tree->GetEntries() << endl;  
                 cout << "** WARNING ** run will not be updated"<<endl;  
2611              }              }
2612          };                    totdltime[2]++;
   
         // -----------------------------------------------------------------------  
         // if it is simulation, assign abstime by hand (temporaneo!!!)  
         // -----------------------------------------------------------------------  
         if(ISGP){  
             abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO  
             obt     = GetRunInfo()->RUNHEADER_OBT; // BARBATRUCCO  
2613          }          }
2614    
2615          //          //
2616          bool fromfirst = true; // first loop over runs          bool fromfirst = true; // first loop over runs
2617    
 //      Bool_t hasfrag = false;  
 //      if( GetRunInfo()->ID_RUN_FRAG!=0 && GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID)hasfrag=true;  
 //      ULong64_t fragid = GetRunInfo()->ID_RUN_FRAG;  
2618    
2619          // ------------------------------------------------------          // ------------------------------------------------------
2620          // loop over runs to find the one that contains the event          // loop over runs to find the one that contains the event
2621          // ------------------------------------------------------          // ------------------------------------------------------
2622          while (          while (
2623              (              (
2624                  (  //              (
2625                      !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)  //                  !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
2626                        abstime <= GetRunInfo()->RUNTRAILER_TIME) &&  //                    abstime <= GetRunInfo()->RUNTRAILER_TIME) &&
2627                      !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)  //                  !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
2628                        obt <= GetRunInfo()->RUNTRAILER_OBT)  //                    obt <= GetRunInfo()->RUNTRAILER_OBT)
2629                      )  //                  )
2630                  || GetRunInfo()->NEVENTS==0                  
2631                    !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
2632                      abstime <= GetRunInfo()->RUNTRAILER_TIME)
2633                    ||
2634                    !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
2635                      obt <= GetRunInfo()->RUNTRAILER_OBT)          
2636                    ||
2637                    GetRunInfo()->NEVENTS==0
2638  //              || !(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
2639                  || !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift)                  ||
2640                    !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift)
2641                  )                  )
2642                  && irun < run_tree->GetEntries() ){              && irun < run_tree->GetEntries() ){
2643    
2644    
2645    //          if( !(abstime >= GetRunInfo()->RUNHEADER_TIME &&abstime <= GetRunInfo()->RUNTRAILER_TIME)  )cout << "ABS TIME "<<abstime << " " <<GetRunInfo()->RUNTRAILER_TIME <<endl;
2646    //          if( !(obt >= GetRunInfo()->RUNHEADER_OBT && obt <= GetRunInfo()->RUNTRAILER_OBT) )cout << "OBT TIME "<< obt <<" "<< GetRunInfo()->RUNTRAILER_OBT << endl;
2647    //          if( GetRunInfo()->NEVENTS==0  )cout <<"GetRunInfo()->NEVENTS==0 "<<endl;
2648    //          if( !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift) ) cout << "irunentry > "<<GetRunInfo()->NEVENTS-1-prevshift << endl;
2649              // - - - - - - - - - - - - -              // - - - - - - - - - - - - -
2650              // irunentry = position of current entry, relative to the run              // irunentry = position of current entry, relative to the run
2651              // prevshift = shift needed to synchronize l0 and l2 data (nested events)              // prevshift = shift needed to synchronize l0 and l2 data (nested events)
# Line 2589  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2654  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2654              // -----------------------------------------              // -----------------------------------------
2655              // store dead and live-time of previous run              // store dead and live-time of previous run
2656              // -----------------------------------------              // -----------------------------------------
2657    //          if(SELLI==0){
2658              if(fromfirst){              if(fromfirst){
2659                  if(oldrun==irun){                  if(oldrun==irun){
2660                      /// decrement counters                      /// decrement counters
# Line 2618  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2684  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2684                  }                  }
2685                  totdltime[2]=1;                             //event counter                  totdltime[2]=1;                             //event counter
2686              }              }
2687    //          }
2688    
2689                irun++;        
             irun++;  
2690              // ------------------------------------              // ------------------------------------
2691              // if the end of run tree is reached...              // if the end of run tree is reached...
2692              // ------------------------------------              // ------------------------------------
# Line 2648  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2714  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2714              if(irun>0)runfirstentry += (GetRunInfo()->NEVENTS)-prevshift;              if(irun>0)runfirstentry += (GetRunInfo()->NEVENTS)-prevshift;
2715              irunentry = 0;              irunentry = 0;
2716              prevshift = 0;                        prevshift = 0;          
2717              run_tree->GetEntry(irun);                    run_tree->GetEntry(irun);//update runinfo
2718                irunt = irun - irunoffset[run_tree->GetTreeNumber()];
2719              if(GetRunInfo()->RUNHEADER_OBT>GetRunInfo()->RUNTRAILER_OBT ){              if(GetRunInfo()->RUNHEADER_OBT>GetRunInfo()->RUNTRAILER_OBT ){
2720                  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;
2721                  cout << "                                                            (NB!! in this case some events are assigned to a wrong run)"<<endl;                  cout << "                                                            (NB!! in this case some events are assigned to a wrong run)"<<endl;
# Line 2670  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 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          // ---> exit with TRUE          // ---> exit with TRUE
2742          // --------------------------------------          // --------------------------------------
2743          cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;          if(DBG)cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2744            // ----------------------------------------------------
2745            // update the tracker parameters
2746            // (non ho trovato nessun altro modo sicuro di farlo...)
2747            // ----------------------------------------------------
2748            if(!dbc || (dbc && !dbc->IsConnected()) )SetDBConnection();
2749            TrkParams::Set(GetRunInfo() ,dbc);
2750            if(dbc)dbc->Close();
2751    
2752          // ----------------------------------------------------          // ----------------------------------------------------
2753          // then check if the run has a fragment          // then check if the run has a fragment
2754          // in this case we have to switch to the next fragment          // in this case we have to switch to the next fragment
# Line 2732  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2757  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2757          if(          if(
2758              GetRunInfo()->ID_RUN_FRAG != 0 &&              GetRunInfo()->ID_RUN_FRAG != 0 &&
2759  //          GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID &&  //          GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID &&
2760                DBG &&
2761              true ){              true ){
2762              cout << "* fragment *"<<endl;                            cout << "* fragment *"<<endl;              
2763          }          }
# Line 2741  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2767  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2767      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2768      // if it is a preselected file (there is SelectionList)      // if it is a preselected file (there is SelectionList)
2769      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2770        // irun  = run entry relative to the chain
2771        // irunt = run entry relative to the tree
2772      if(SELLI==1){            if(SELLI==1){      
2773          sel_tree->GetEntry(iev);          sel_tree->GetEntry(iev);// read irunt from SelectionList
2774          if(irun != oldrun){          irun = irunt + irunoffset[sel_tree->GetTreeNumber()];//NEWNEW
2775              run_tree->GetEntry(irun);          if(irun != oldrun ){
2776              cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;              if( irun < run_tree->GetEntries() )run_tree->GetEntry(irun);
2777                // check if the time is ok (with merged files it is not...)
2778                // if not loop over run and look for the proper entry
2779                bool SECONDO_GIRO=false;
2780                //      Long64_t irun_start   = irun;
2781                int      offset_start = irunoffset[sel_tree->GetTreeNumber()];
2782                while (
2783                    (
2784                        (
2785                            !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
2786                              abstime <= GetRunInfo()->RUNTRAILER_TIME)
2787    //                      ||
2788    //                      !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
2789    //                        obt <= GetRunInfo()->RUNTRAILER_OBT)
2790                            )
2791                        || GetRunInfo()->NEVENTS==0
2792                        )
2793    //              && irun < run_tree->GetEntries()
2794                    ){
2795    
2796                    if(DBG){
2797                        cout << " (test) ";
2798                        cout << " tree "<<sel_tree->GetTreeNumber();
2799                        cout << " irunt "<<irunt;
2800                        cout << " offset "<<irunoffset[sel_tree->GetTreeNumber()];
2801                        cout << " abs "<<abstime;
2802                        cout <<" >> "<<GetRunInfo()->RUNHEADER_TIME<<" "<<GetRunInfo()->RUNTRAILER_TIME;
2803                        cout << " obt "<<obt;
2804                        cout <<" >> "<<GetRunInfo()->RUNHEADER_OBT<<" "<<GetRunInfo()->RUNTRAILER_OBT;
2805                        cout << " *** JUMP RUN *** irun "<<irun;
2806                        cout << endl;
2807                    }
2808    //              irun++;
2809                    irunoffset[sel_tree->GetTreeNumber()]++;
2810                    irun = irunt + irunoffset[sel_tree->GetTreeNumber()];//NEWNEW          
2811                    if(irun == run_tree->GetEntries() && SECONDO_GIRO){
2812    //              if(irun == irun_start ){
2813                        cout << " ...grrrvzzkhhhajsdkj!!!! "<<endl;
2814                        irunoffset[sel_tree->GetTreeNumber()] = offset_start;
2815                        return false;
2816                    }
2817                    if( irun >= run_tree->GetEntries() || irun < 0){
2818                        cout << "irun = "<<irun<<" >>  search from the beginning... <<"<<endl;
2819                        SECONDO_GIRO=true;
2820                        irun=0;
2821                        irunoffset[sel_tree->GetTreeNumber()]=-irunt;
2822                    }
2823                    run_tree->GetEntry(irun);
2824                }
2825    
2826    
2827                if(DBG){
2828                    cout << " (test) ";
2829                    cout << " tree "<<sel_tree->GetTreeNumber();
2830                    cout << " irunt "<<irunt;
2831                    cout << " offset "<<irunoffset[sel_tree->GetTreeNumber()];
2832                    cout << " abs "<<abstime;
2833                    cout <<" >> "<<GetRunInfo()->RUNHEADER_TIME<<" "<<GetRunInfo()->RUNTRAILER_TIME;
2834                    cout << " obt "<<obt;
2835                    cout <<" >> "<<GetRunInfo()->RUNHEADER_OBT<<" "<<GetRunInfo()->RUNTRAILER_OBT;
2836                }
2837                if(DBG)cout << endl;
2838                if(DBG)cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" (run-entry "<<irun<<")"<<endl;
2839                // ----------------------------------------------------
2840                // update the tracker parameters
2841                // (non ho trovato nessun altro modo sicuro di farlo...)
2842                // ----------------------------------------------------
2843                if(!dbc || (dbc && !dbc->IsConnected()) )SetDBConnection();
2844                TrkParams::Set(GetRunInfo() ,dbc);
2845                if(dbc)dbc->Close();
2846    //          cout << endl;
2847              prevshift = 0;              prevshift = 0;
2848              return true;              return true;
2849          }          }
# Line 2761  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2859  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2859   * @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
2860   */   */
2861  Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev){  Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev){
2862    return(UpdateRunInfo((TChain*)run,iev));      return(UpdateRunInfo((TChain*)run,iev));
2863  };  };
2864    
2865  //--------------------------------------  //--------------------------------------
# Line 2771  Bool_t PamLevel2::UpdateRunInfo(TTree *r Line 2869  Bool_t PamLevel2::UpdateRunInfo(TTree *r
2869  /**  /**
2870   * Set which trees shoul be analysed   * Set which trees shoul be analysed
2871   * @param detlist TString containing the sequence of trees required   * @param detlist TString containing the sequence of trees required
2872  */   */
2873  void PamLevel2::SetWhichTrees(TString detlist){  void PamLevel2::SetWhichTrees(TString detlist){
2874            
2875  //    if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){  //    if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){
2876      if( detlist.Contains("+ALL", TString::kIgnoreCase)){      if( detlist.Contains("+ALL", TString::kIgnoreCase)){
2877    
2878          cout << " ======================================================== "<<endl;          cout << " ======================================================== "<<endl;
2879          cout << "                       (( WARNING ))                      "<< endl;          cout << "                       (( WARNING ))                      "<<endl;
2880          cout << " The meaning of the option +ALL has changed!!             "<<endl;          cout << " The meaning of the option +ALL has changed!!             "<<endl;
2881          cout << " Now it includes really all (level0+level1+level2+gpamela)"<<endl;          cout << " Now it includes really all (level0+level1+level2+gpamela)"<<endl;
2882          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;
2883          cout << " trees or level0 files are not available!!                "<<endl;          cout << " all trees or  if level0 files are not available!!        "<<endl;
2884          cout << " ======================================================== "<<endl;          cout << " ======================================================== "<<endl;
2885                            
2886          CAL0 = true;          CAL0 = true;
# Line 2892  void PamLevel2::SetWhichTrees(TString de Line 2990  void PamLevel2::SetWhichTrees(TString de
2990      if( detlist.Contains("-GP", TString::kIgnoreCase) )GP = false;      if( detlist.Contains("-GP", TString::kIgnoreCase) )GP = false;
2991      else if( detlist.Contains("+GP", TString::kIgnoreCase) )GP = true;      else if( detlist.Contains("+GP", TString::kIgnoreCase) )GP = true;
2992    
2993      cout<< "Set detector list from input --> ";      cout<< "tree/branch list from input --> ";
2994      if(TRK0)cout<<"TRK0 ";      if(TRK0)cout<<"TRK0 ";
2995      if(TRK1)cout<<"TRK1 ";      if(TRK1)cout<<"TRK1 ";
2996      if(TRK2)cout<<"TRK2 ";      if(TRK2)cout<<"TRK2 ";
# Line 2952  void  PamLevel2::GetWhichTrees(TFile* f) Line 3050  void  PamLevel2::GetWhichTrees(TFile* f)
3050            
3051      RUN    = false;      RUN    = false;
3052                    
3053      cout << "Checking file: "<<f->GetName()<<endl;  //    cout << "Checking file: "<<f->GetName()<<endl;
3054      if( !f || f->IsZombie() ){      if( !f || f->IsZombie() ){
3055          cout << "File: "<< f->GetName() <<" Non valid root file"<< endl;          cout << "File: "<< f->GetName() <<" Non valid root file"<< endl;
3056          return;          return;
# Line 3071  void  PamLevel2::GetWhichTrees(TFile* f) Line 3169  void  PamLevel2::GetWhichTrees(TFile* f)
3169            
3170  //    delete lk;  //    delete lk;
3171    
3172      cout<< "Get detector list from input file --> ";      cout<< "tree/branch list from file  --> ";
3173      if(TRK1)cout<<"TRK1 ";      if(TRK1)cout<<"TRK1 ";
3174      if(TRK2)cout<<"TRK2 ";      if(TRK2)cout<<"TRK2 ";
3175      if(TRKh)cout<<"TRKH ";      if(TRKh)cout<<"TRKH ";
# Line 3119  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3217  Bool_t  PamLevel2::CheckLevel2File(TStri
3217            
3218      Bool_t SELLI__ok  = false;      Bool_t SELLI__ok  = false;
3219    
3220      cout << "Checking file: "<<name<<endl;  //    cout << "Checking file: "<<name<<endl;
3221      TFile *f = new TFile(name.Data());      TFile *f = new TFile(name.Data());
3222      if( !f || f->IsZombie() ){      if( !f || f->IsZombie() ){
3223          cout << "File: "<< f->GetName() <<" discarded ---- Non valid root file"<< endl; return false;          cout << "File: "<< f->GetName() <<" discarded ---- Non valid root file"<< endl; return false;
# Line 3327  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3425  Bool_t  PamLevel2::CheckLevel2File(TStri
3425    
3426    
3427      if(!RUN__ok) {      if(!RUN__ok) {
3428          cout << "File: "<< f->GetName() <<" *WARNING* ---- Missing RunInfo tree"<< endl;          cout << "File: "<< f->GetName() <<" *WARNING* ---- Missing RunInfo tree (NB: RUN infos will not be updated)"<< endl;
3429  //      return false;          RUN = false;
3430      };      };
3431    
3432      if(CAL1 && !CAL1__ok){      if(CAL1 && !CAL1__ok){
# Line 3451  void PamLevel2::CreateCloneTrees(TFile * Line 3549  void PamLevel2::CreateCloneTrees(TFile *
3549    
3550    
3551  //  if the pointer is null, create a default file  //  if the pointer is null, create a default file
3552        if(!run_tree)return;
3553    
3554      if(!ofile){      if(!ofile){
3555          cout << "void PamLevel2::CreateCloneTrees(TFile*) -- WARNING -- Creating file: clone-tree.root "<<endl;          cout << "void PamLevel2::CreateCloneTrees(TFile*) -- WARNING -- Creating file: clone-tree.root "<<endl;
# Line 3471  void PamLevel2::CreateCloneTrees(TFile * Line 3570  void PamLevel2::CreateCloneTrees(TFile *
3570      // ------------------      // ------------------
3571      // replicate run tree      // replicate run tree
3572      // ------------------      // ------------------
3573      cout << "----------------------------------------------------"<<endl;  //    cout << "----------------------------------------------------"<<endl;
3574      cout << "irun\t | RUN\t NEVENTS\t absolute time"<<endl;  //    cout << "irun\t | RUN\t NEVENTS\t absolute time"<<endl;
3575      for (Int_t i=0; i<run_tree->GetEntries(); i++){      for (Int_t i=0; i<run_tree->GetEntries(); i++){
3576          run_tree->GetEntry(i);          run_tree->GetEntry(i);
3577          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;
3578          run_tree_clone->Fill();          run_tree_clone->Fill();
3579      }      }
3580      cout << "----------------------------------------------------"<<endl;      cout << "----------------------------------------------------"<<endl;
# Line 3488  void PamLevel2::CreateCloneTrees(TFile * Line 3587  void PamLevel2::CreateCloneTrees(TFile *
3587    
3588    
3589      sel_tree_clone = new TTree("SelectionList","List of selected events ");      sel_tree_clone = new TTree("SelectionList","List of selected events ");
3590      sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");  //    sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");
3591        sel_tree_clone->Branch("RunEntry",&irunt,"runentry/L");//NEWNEW
3592      sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/L");      sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/L");
3593            
3594    
# Line 3666  Int_t PamLevel2::GetEntry(Long64_t iee){ Line 3766  Int_t PamLevel2::GetEntry(Long64_t iee){
3766          return 0;          return 0;
3767      }      }
3768    
 //    cout << " gp_obj->P0 "<<gp_obj->P0<<endl;  
3769      //      //
3770      // ... 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.
3771      // 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
3772      // a problem if you don't check the return code of getentry.      // a problem if you don't check the return code of getentry.
3773      //      //
3774      if(!run_tree ){      if(!RUN || !run_tree ){
3775          if ( TRK0 || CAL0 || TOF0 || RUN ) { //forse cosi` va bene per tornare 1?          if ( TRK0 || CAL0 || TOF0 || RUN ) { //forse cosi` va bene per tornare 1?
3776              cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loaded"<<endl;              cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loaded"<<endl;
3777              return 0;              return 0;
# Line 3757  TTree* PamLevel2::GetYodaTree( ){ Line 3856  TTree* PamLevel2::GetYodaTree( ){
3856          // open the DB connection          // open the DB connection
3857          // (if not already opened)          // (if not already opened)
3858          //===================================          //===================================
3859          if(!dbc || (dbc && !dbc->IsConnected())){          if(!dbc || (dbc && !dbc->IsConnected()))SetDBConnection();
             cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;  
             cout<<"Re-connecting to DB"<<endl;  
             cout<<"HOST "<<host<<endl;  
             cout<<"USER "<<user<<endl;  
             cout<<"PSW  "<<psw<<endl;  
             dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());  
             if( !dbc )return NULL;  
             if( !dbc->IsConnected() )return NULL;      
 //          cout<<"...done"<<endl;  
             cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;  
         }else{  
 //          cout<<"DB already connected"<<endl;  
         }  
3860          GL_ROOT glroot = GL_ROOT();          GL_ROOT glroot = GL_ROOT();
3861          if( glroot.Query_GL_ROOT(iroot,dbc) ){          if( glroot.Query_GL_ROOT(iroot,dbc) ){
3862              cout << "TTree* PamLevel2::GetYodaTree( ) -- ERROR -- level0 file iroot = "<<iroot<< " does not exists"<<endl;              cout << "TTree* PamLevel2::GetYodaTree( ) -- ERROR -- level0 file iroot = "<<iroot<< " does not exists"<<endl;
# Line 3818  TTree* PamLevel2::GetYodaTree( ){ Line 3904  TTree* PamLevel2::GetYodaTree( ){
3904              cout << "PamLevel2::GetYodaTree() --- level0 TOF not implemented "<<endl;              cout << "PamLevel2::GetYodaTree() --- level0 TOF not implemented "<<endl;
3905          }          }
3906    
3907          dbc->Close();          dbc->Close(); // EMILIANO, do not leave open connections, open only when needed
3908    
3909    
3910      };      };
# Line 3828  TTree* PamLevel2::GetYodaTree( ){ Line 3914  TTree* PamLevel2::GetYodaTree( ){
3914  //     }  //     }
3915    
3916      if ( TRK0 ){      if ( TRK0 ){
3917          TrkParams::Load(6);  //      TrkParams::Load(6);
3918          if( !TrkParams::IsLoaded(6) ){  //      if( !TrkParams::IsLoaded(6) ){
3919              cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- VK-mask not loaded"<<endl;  //          cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- VK-mask not loaded"<<endl;
3920          };  //      };
3921    //      if(!dbc || (dbc && !dbc->IsConnected()))SetDBConnection();
3922          TrkParams::SetCalib(run_obj,dbc);          TrkParams::SetCalib(run_obj,dbc);
3923          TrkParams::LoadCalib( );          TrkParams::LoadCalib( );
3924          if( !TrkParams::CalibIsLoaded() ){          if( !TrkParams::CalibIsLoaded() ){
3925              cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- Calibration not loaded"<<endl;              cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- Calibration not loaded"<<endl;
3926          };          };
3927    //      if(dbc)dbc->Close(); // EMILIANO, do not leave open connections, open only when needed
3928      }      }
3929    
3930    
# Line 3905  Int_t PamLevel2::GetYodaEntry(){ Line 3993  Int_t PamLevel2::GetYodaEntry(){
3993      do{      do{
3994          if(shift>0){              if(shift>0){    
3995              cout << " PKTNUM  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;              cout << " PKTNUM  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;
3996              cout << "         RUN: ID "<< GetRunInfo()->ID << " ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<" ID_RUN_FRAG "<<GetRunInfo()->ID_RUN_FRAG << " EV_FROM "<<GetRunInfo()->EV_FROM  <<endl;              if(DBG)cout << "         RUN: ID "<< GetRunInfo()->ID << " ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<" ID_RUN_FRAG "<<GetRunInfo()->ID_RUN_FRAG << " EV_FROM "<<GetRunInfo()->EV_FROM  <<endl;
3997              cout << "         L2 <--> L0 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" prevshift "<<prevshift<<" )"<<endl;              if(DBG)cout << "         L2 <--> L0 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" prevshift "<<prevshift<<" )"<<endl;
3998          }          }
3999          answer = l0_tree->GetEntry(quellagiusta+(Long64_t)shift+(Long64_t)prevshift);          answer = l0_tree->GetEntry(quellagiusta+(Long64_t)shift+(Long64_t)prevshift);
4000          shift++;          shift++;
# Line 3930  Int_t PamLevel2::GetYodaEntry(){ Line 4018  Int_t PamLevel2::GetYodaEntry(){
4018  //      printf(" IDRUN %u \n",GetRunInfo()->ID);  //      printf(" IDRUN %u \n",GetRunInfo()->ID);
4019  //  //
4020          if ( prevshift != 0 && (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() ){          if ( prevshift != 0 && (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() ){
4021            prevshift = 0;              prevshift = 0;
4022            shift = -1;              shift = -1;
4023          };          };
4024    
4025      }while( ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) ||      }while( ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) ||
# Line 3939  Int_t PamLevel2::GetYodaEntry(){ Line 4027  Int_t PamLevel2::GetYodaEntry(){
4027              && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() && shift < maxshift);              && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() && shift < maxshift);
4028    
4029      if ( (quellagiusta+(Long64_t)shift+(Long64_t)prevshift) > GetYodaTree()->GetEntries() || shift == maxshift ) {      if ( (quellagiusta+(Long64_t)shift+(Long64_t)prevshift) > GetYodaTree()->GetEntries() || shift == maxshift ) {
4030          cout << " Big trouble here, no such event in Level0 data! " <<endl;          cout << " Big trouble here, no such event in Level0 data! (NB maxshift set to "<<maxshift<<" )" <<endl;
4031          return 0;          return 0;
4032      }      }
4033  //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;  //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;
# Line 3954  Int_t PamLevel2::GetYodaEntry(){ Line 4042  Int_t PamLevel2::GetYodaEntry(){
4042   */   */
4043  Bool_t PamLevel2::SetDBConnection(){  Bool_t PamLevel2::SetDBConnection(){
4044    
4045      cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;  //    cout << "PamLevel2::SetDBConnection()" << endl;
4046      cout<<"Connecting to DB"<<endl;      if(DBG){
4047      cout<<"HOST "<<host<<endl;          cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
4048      cout<<"USER "<<user<<endl;          cout<<"Connecting to DB"<<endl;
4049      cout<<"PSW  "<<psw<<endl;          cout<<"HOST "<<host<<endl;
4050            cout<<"USER "<<user<<endl;
4051            cout<<"PSW  "<<psw<<endl;
4052        }
4053      dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());      dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
4054      if( !dbc )return false;      if( !dbc )return false;
4055      if( !dbc->IsConnected() )return false;          if( !dbc->IsConnected() )return false;    
4056      cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;      stringstream myquery;  // EMILIANO
4057        myquery.str("");  // EMILIANO
4058        myquery << "SET time_zone='+0:00'";  // EMILIANO
4059        dbc->Query(myquery.str().c_str());  // EMILIANO
4060        if(DBG)cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
4061      return true;      return true;
4062    
4063  }  }

Legend:
Removed from v.1.52  
changed lines
  Added in v.1.68

  ViewVC Help
Powered by ViewVC 1.1.23