/[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.64 by mocchiut, Wed Oct 1 16:06:19 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 795  void *PamLevel2::GetPointerTo(const char Line 816  void *PamLevel2::GetPointerTo(const char
816   * Retrieves the calorimeter track matching the seqno-th tracker stored track.   * Retrieves the calorimeter track matching the seqno-th tracker stored track.
817   * (If seqno = -1 retrieves the self-trigger calorimeter track)   * (If seqno = -1 retrieves the self-trigger calorimeter track)
818   */   */
819   CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){  CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){
820            
821       if( !calo2_obj )return 0;      if( !calo2_obj )return 0;
822    
823       if( calo2_obj->CaloLevel2::ntrk()==0 ){      if( calo2_obj->CaloLevel2::ntrk()==0 ){
824           cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<<endl;          cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<<endl;
825           return NULL;          return NULL;
826       };      };
827            
828       CaloTrkVar *c = 0;      CaloTrkVar *c = 0;
829       Int_t it_calo=0;      Int_t it_calo=0;
830            
831       do{      do{
832           c = calo2_obj->CaloLevel2::GetCaloTrkVar(it_calo);          c = calo2_obj->CaloLevel2::GetCaloTrkVar(it_calo);
833           it_calo++;          it_calo++;
834       } while( c && seqno != c->trkseqno && it_calo < calo2_obj->CaloLevel2::ntrk());          } while( c && seqno != c->trkseqno && it_calo < calo2_obj->CaloLevel2::ntrk());    
835            
836       if(!c || seqno != c->trkseqno){      if(!c || seqno != c->trkseqno){
837           c = 0;          c = 0;
838           if(seqno!=-1)cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match Calorimeter stored tracks"<<endl;          if(seqno!=-1)cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match Calorimeter stored tracks"<<endl;
839       };      };
840       return c;      return c;
841            
842   };  };
843  //--------------------------------------  //--------------------------------------
844   //  //
845   //  //
846  //--------------------------------------  //--------------------------------------
847  /**  /**
848    * Retrieves the ToF track matching the seqno-th tracker stored track.   * Retrieves the ToF track matching the seqno-th tracker stored track.
849    * (If seqno = -1 retrieves the tracker-independent tof track)   * (If seqno = -1 retrieves the tracker-independent tof track)
850   */   */
851   ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){  ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){
852                    
853       if( !tof_obj )return 0;      if( !tof_obj )return 0;
854    
855       if( tof_obj->ToFLevel2::ntrk()==0 ){      if( tof_obj->ToFLevel2::ntrk()==0 ){
856           cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no ToF tracks are stored"<<endl;          cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no ToF tracks are stored"<<endl;
857           return NULL;          return NULL;
858       };      };
859            
860       ToFTrkVar *c = 0;      ToFTrkVar *c = 0;
861       Int_t it_tof=0;      Int_t it_tof=0;
862            
863       do{      do{
864           c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);          c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);
865           it_tof++;          it_tof++;
866       } while( c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());              } while( c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());
867            
868       if(!c || seqno != c->trkseqno){      if(!c || seqno != c->trkseqno){
869           c = 0;          c = 0;
870           if(seqno!=-1)cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match ToF stored tracks"<<endl;          if(seqno!=-1)cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match ToF stored tracks"<<endl;
871       };      };
872       return c;      return c;
873            
874   };  };
875    
876  //--------------------------------------  //--------------------------------------
877   //  //
878   //  //
879  //--------------------------------------  //--------------------------------------
880  /**  /**
881   * Give the pamela track associated to a tracker track, retrieving related calorimeter and tof track information.   * Retrieves the OrbitalInfo track matching the seqno-th tracker stored track.
882     * (If seqno = -1 retrieves the tracker-independent tof related track)
883   */   */
884   PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){  OrbitalInfoTrkVar *PamLevel2::GetOrbitalInfoStoredTrack(int seqno){
885            
886        if( !orb_obj )return 0;
887    
888        if( orb_obj->OrbitalInfo::ntrk()==0 ){
889            cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no OrbitalInfo tracks are stored"<<endl;
890            return NULL;
891        };
892        
893        OrbitalInfoTrkVar *c = 0;
894        Int_t it_tof=0;
895            
896       cout <<"PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** "<<endl;      do{
897       cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;          c = orb_obj->OrbitalInfo::GetOrbitalInfoTrkVar(it_tof);
898            it_tof++;
899        } while( c && seqno != c->trkseqno && it_tof < orb_obj->OrbitalInfo::ntrk());      
900        
901        if(!c || seqno != c->trkseqno){
902            c = 0;
903            if(seqno!=-1)cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match OrbitalInfo stored tracks"<<endl;
904        };
905        return c;
906        
907    };
908    
909    //--------------------------------------
910    //
911    //
912    //--------------------------------------
913    /**
914     * Give the pamela track associated to a tracker track, retrieving related calorimeter, orbitalinfo and tof track information.
915     */
916    PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){
917        
918        cout <<"PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** "<<endl;
919        cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;
920    
921       CaloTrkVar *c = 0;      CaloTrkVar *c = 0;
922       ToFTrkVar  *o = 0;      ToFTrkVar  *o = 0;
923        OrbitalInfoTrkVar  *r = 0;
924            
925       if(CAL2) c = GetCaloStoredTrack(t->GetSeqNo());      if(CAL2) c = GetCaloStoredTrack(t->GetSeqNo());
926       if(TOF) o = GetToFStoredTrack(t->GetSeqNo());      if(TOF) o = GetToFStoredTrack(t->GetSeqNo());
927        if(ORB) r = GetOrbitalInfoStoredTrack(t->GetSeqNo());
928            
929  //    if(t && c && o)track = new PamTrack(t,c,o);  //    if(t && c && o)track = new PamTrack(t,c,o);
930       PamTrack *track = new PamTrack(t,c,o);      PamTrack *track = new PamTrack(t,c,o,r);
931            
932       return track;      return track;
933    
934   };  };
935  //--------------------------------------  //--------------------------------------
936  //  //
937  //  //
# Line 889  void *PamLevel2::GetPointerTo(const char Line 945  void *PamLevel2::GetPointerTo(const char
945  PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){  PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){
946            
947      cout <<"PamLevel2::GetStoredTrack(Int_t itrk) **to-be-updated** "<<endl;      cout <<"PamLevel2::GetStoredTrack(Int_t itrk) **to-be-updated** "<<endl;
948      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;
949      cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;      cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;
950      PamTrack *track = 0;      PamTrack *track = 0;
951            
# Line 911  PamTrack* PamLevel2::GetStoredTrack(Int_ Line 967  PamTrack* PamLevel2::GetStoredTrack(Int_
967  //  //
968    
969  /**  /**
970   * 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.
971   **/   **/
972  void PamLevel2::SortTracks(TString how){  void PamLevel2::SortTracks(TString how){
973    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());
974    howtosort = how;        howtosort = how;  
975    SortTracks();      SortTracks();
976  };  };
977    
978  //  //
979  //--------------------------------------  //--------------------------------------
980  /**  /**
981   * Sort physical (tracker) tracks and stores them in the TRefArray (of TrkTrack objects) which pointer is  PamLevel2::sorted_tracks.   * Sort physical (tracker) tracks.
982   * @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...).
983   * Sorting cryteria:   * Sorting cryteria:
984   * TRK: lower chi**2   * TRK: lower chi**2
985   * CAL: lower Y spatial residual on the first calorimeter plane   * CAL: lower Y spatial residual on the first calorimeter plane
986   * 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).
987     * S1: (ask Emiliano)
988     * S2: (ask Emiliano)
989     * S3: (ask Emiliano)
990     * GP: more GP hits
991   * The default sorting cryterium is "TOF+CAL".   * The default sorting cryterium is "TOF+CAL".
992   *   *
993   * 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).
994   */   */
995  void PamLevel2::SortTracks(){  void PamLevel2::SortTracks(){
996    TString how = howtosort;      TString how = howtosort;
997    
998    //  cout <<" PamLevel2::SortTracks(TString how) "<<endl;      //  cout <<" PamLevel2::SortTracks(TString how) "<<endl;
999    if( !trk2_obj ){      if( !trk2_obj ){
1000      cout << "void PamLevel2::SortTracks():  TrkLevel2 not loaded !!!";          cout << "void PamLevel2::SortTracks():  TrkLevel2 not loaded !!!";
1001      return;          return;
1002    };      };
1003    //    cout << "call SortTracs() "<<endl;      //Save current Object count
1004    //Save current Object count      Int_t ObjectNumber = TProcessID::GetObjectCount();
1005    Int_t ObjectNumber = TProcessID::GetObjectCount();  
1006        // create TCloneArrays to store tracks and its images
1007    //    cout << "ObjectNumber  "<<ObjectNumber <<endl;      if(!tsorted)tsorted = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
1008        tsorted->Delete();
1009    //     if(!sorted_tracks)sorted_tracks = new TRefArray();      TClonesArray &ttsorted = *tsorted;
1010    //     sorted_tracks->Clear();  
1011    //    sorted_tracks.Clear();      if(!timage)timage = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
1012        timage->Delete();
1013    if(!tsorted)tsorted = new TClonesArray("PamTrack",trk2_obj->GetNTracks());      TClonesArray &ttimage = *timage;
   tsorted->Delete();  
   TClonesArray &ttsorted = *tsorted;  
   if(!timage)timage = new TClonesArray("PamTrack",trk2_obj->GetNTracks());  
   timage->Delete();  
   TClonesArray &ttimage = *timage;  
1014    
1015    
1016    
1017    //--------------------------------------------------      //--------------------------------------------------
1018    // retrieve sorting method      // retrieve sorting method
1019    //--------------------------------------------------      //--------------------------------------------------
1020    Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);      Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
1021    Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);      Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
1022    Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);      Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
1023    Bool_t use_S1 = how.Contains("S1", TString::kIgnoreCase);      Bool_t use_S1 = how.Contains("S1", TString::kIgnoreCase);
1024    Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase);      Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase);
1025    Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase);      Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase);
1026        Bool_t use_GP = how.Contains("GP", TString::kIgnoreCase);
1027        
1028    if ( use_TOF ){      if ( use_TOF ){
1029      use_S1 = true;          use_S1 = true;
1030      use_S2 = true;          use_S2 = true;
1031      use_S3 = true;          use_S3 = true;
1032    };      };
1033    if( !CAL2 &&  use_CAL) use_CAL = false;      if( !CAL2 &&  use_CAL) use_CAL = false;
1034    if( !TOF ){      if( !TOF ){
1035      use_TOF = false;          use_TOF = false;
1036      use_S1  = false;          use_S1  = false;
1037      use_S2  = false;          use_S2  = false;
1038      use_S3  = false;          use_S3  = false;
1039    }      }
1040        if( !GP ){
1041    if( !TRK2 ){          use_GP  = false;
1042      //  cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;      }
1043      return;  
1044    };      if( !TRK2 ){
1045            cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;
1046            return;
1047        };
1048    
1049    //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;      //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;
1050        
1051    
1052    //--------------------------------------------------      //--------------------------------------------------
1053    // loop over "physical" tracks sorted by the tracker      // loop over "physical" tracks sorted by the tracker
1054    //--------------------------------------------------      //--------------------------------------------------
1055    for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){      for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){
1056                    
1057      TrkTrack   *ts = 0;          TrkTrack   *ts = 0;
1058      CaloTrkVar *cs = 0;          CaloTrkVar *cs = 0;
1059      ToFTrkVar  *os = 0;          ToFTrkVar  *os = 0;
1060                    OrbitalInfoTrkVar  *rs = 0;
1061      // get tracker tracks          
1062      TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker          // get tracker tracks
1063      CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());          TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker
1064      ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());          CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());
1065            ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());
1066      TrkTrack   *ti = 0; //tracker (image)          OrbitalInfoTrkVar  *rp = GetOrbitalInfoStoredTrack(tp->GetSeqNo());
1067      CaloTrkVar *ci = 0;  
1068      ToFTrkVar  *oi = 0;          TrkTrack   *ti = 0; //tracker (image)
1069      //  cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;          CaloTrkVar *ci = 0;
1070      // if track has an image, check image selection          ToFTrkVar  *oi = 0;
1071            OrbitalInfoTrkVar  *ri = 0;
1072      Int_t tp_score = 0;  //main track sorted by the tracker          //      cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
1073      Int_t ti_score = 0;  //image track          // if track has an image, check image selection
1074      Int_t totp_score = 0;  //main track sorted by the tracker  
1075      Int_t toti_score = 0;  //image track          Int_t tp_score = 0;  //main track sorted by the tracker
1076            Int_t ti_score = 0;  //image track
1077            Int_t totp_score = 0;  //main track sorted by the tracker
1078            Int_t toti_score = 0;  //image track
1079    
1080      if(tp->HasImage()){          if(tp->HasImage()){
1081                            
1082        ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image)              ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image)
1083        ci = GetCaloStoredTrack(ti->GetSeqNo());              ci = GetCaloStoredTrack(ti->GetSeqNo());
1084        oi = GetToFStoredTrack(ti->GetSeqNo());              oi = GetToFStoredTrack(ti->GetSeqNo());
1085                ri = GetOrbitalInfoStoredTrack(ti->GetSeqNo());
1086                            
1087        //            cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;              //      cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;
1088    
1089        //assign starting scores              //assign starting scores
1090        tp_score = 0;  //main track sorted by the tracker              tp_score = 0;  //main track sorted by the tracker
1091        ti_score = 0;  //image track              ti_score = 0;  //image track
1092                            
1093        // -----------------------------------------------------------------------------------------              // -----------------------------------------------------------------------------------------
1094        // calorimeter check              // *****************************************************************************************
1095        // -----------------------------------------------------------------------------------------              // -----------------------------------------------------------------------------------------
1096        // check the Y spatial residual on the first calorimeter plane              // calorimeter check
1097        // (cut on calorimeter variables from Emiliano)              // -----------------------------------------------------------------------------------------
1098        if( use_CAL && !calo2_obj ){              if( use_CAL && !calo2_obj ){
1099          cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but CaloLevel2 not loaded !!!";                  cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but CaloLevel2 not loaded !!!";
1100          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);  
               };  
1101              };              };
1102            };              if( use_CAL && !cp &&  ci ){
1103            if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){                  ti_score++;
1104              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);  
               };  
1105              };              };
1106            };              if( use_CAL &&  cp && !ci ){
1107            if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){                  tp_score++;
1108              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);  
               };  
1109              };              };
1110            };              if(
1111                    use_CAL            &&
1112                    cp && ci &&
1113                    true){
1114    
1115                    
1116                    if(
1117                        cp->npresh > ci->npresh &&
1118                        true){
1119                        tp_score++;
1120                        totp_score++;
1121                    };
1122                    if(
1123                        cp->npresh < ci->npresh &&
1124                        true){
1125                        ti_score++;
1126                        toti_score++;
1127                    };
1128    
1129                    //      cout << "CALO "<<tp_score<<ti_score<<endl;
1130    
           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);  
1131              };              };
1132            };              // -----------------------------------------------------------------------------------------
1133            //              // *****************************************************************************************
1134            ti->DoTrack2(tr);              // -----------------------------------------------------------------------------------------
1135            //              // TOF check
1136            if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){              // -----------------------------------------------------------------------------------------
1137              for (Int_t ih=0; ih < oi->npmtadc; ih++){              // check the number of hit pmts along the track
1138                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );              // on S12 S21 and S32, where paddles are parallel to Y axis
1139                if(pl == 0){              if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !tof_obj ){
1140                  nphit_i++;                  cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but ToFLevel2 not loaded !!!";
1141                  enhit_i += (op->dedx).At(ih);                  return;
               };  
1142              };              };
1143            };              //
1144            if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){              if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !op && oi ){
1145              for (Int_t ih=0; ih < oi->npmtadc; ih++){                  ti_score++;
1146                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );                  toti_score++;
               if(pl == 3){  
                 nphit_i++;  
                 enhit_i += (op->dedx).At(ih);  
               };  
1147              };              };
1148            };              if( (use_TOF || use_S1 || use_S2 || use_S3 ) && op && !oi ){
1149            if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){                  tp_score++;
1150              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);  
               };  
1151              };              };
1152            };                          if( (use_TOF || use_S1 || use_S2 || use_S3 ) && op && oi ){
1153                    //
1154                    Float_t sen = 0.;
1155                    for (Int_t ih=0; ih < op->npmtadc; ih++){
1156                        Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1157                        if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (op->dedx).At(ih);
1158                    };
1159                    for (Int_t ih=0; ih < oi->npmtadc; ih++){
1160                        Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1161                        if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (oi->dedx).At(ih);
1162                    };
1163                    //
1164                    if (  sen >= sortthr && false){ // temporary disabled NUCLEI special algorithm since the new one should work for every particle (to be checked!)
1165                        //printf(" IS A NUCLEUS! en = %f \n",sen);
1166                        //
1167                        // is a nucleus use a different algorithm
1168                        //
1169                        Int_t nz = 6; Float_t zin[6];                                          // << define TOF z-coordinates
1170                        for(Int_t ip=0; ip<nz; ip++)
1171                            zin[ip] = tof_obj->ToFLevel2::GetZTOF(tof_obj->ToFLevel2::GetToFPlaneID(ip));     // << read ToF plane z-coordinates
1172                        Trajectory *tr = new Trajectory(nz,zin);
1173                        //
1174                        Int_t nphit_p =0;
1175                        Int_t nphit_i =0;
1176                        Float_t enhit_p = 0.;
1177                        Float_t enhit_i = 0.;
1178                        //
1179                        for (Int_t ih=0; ih < op->npmtadc; ih++){
1180                            Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1181                            if(pl == 1 || pl == 2 || pl == 5){
1182                                nphit_p++;
1183                                enhit_p += (op->dedx).At(ih);
1184                            };
1185                        };
1186                        //
1187                        tp->DoTrack2(tr);
1188                        //
1189                        if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){
1190                            for (Int_t ih=0; ih < op->npmtadc; ih++){
1191                                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1192                                if(pl == 0){
1193                                    nphit_p++;
1194                                    enhit_p += (op->dedx).At(ih);
1195                                };
1196                            };
1197                        };
1198                        if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){
1199                            for (Int_t ih=0; ih < op->npmtadc; ih++){
1200                                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1201                                if(pl == 3){
1202                                    nphit_p++;
1203                                    enhit_p += (op->dedx).At(ih);
1204                                };
1205                            };
1206                        };
1207                        if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
1208                            for (Int_t ih=0; ih < op->npmtadc; ih++){
1209                                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1210                                if(pl == 4){
1211                                    nphit_p++;
1212                                    enhit_p += (op->dedx).At(ih);
1213                                };
1214                            };
1215                        };
1216    
1217                        for (Int_t ih=0; ih < oi->npmtadc; ih++){
1218                            Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1219                            if(pl == 1 || pl == 2 || pl == 5){
1220                                nphit_i++;  
1221                                enhit_i += (op->dedx).At(ih);
1222                            };
1223                        };
1224                        //
1225                        ti->DoTrack2(tr);
1226                        //
1227                        if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){
1228                            for (Int_t ih=0; ih < oi->npmtadc; ih++){
1229                                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1230                                if(pl == 0){
1231                                    nphit_i++;
1232                                    enhit_i += (op->dedx).At(ih);
1233                                };
1234                            };
1235                        };
1236                        if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){
1237                            for (Int_t ih=0; ih < oi->npmtadc; ih++){
1238                                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1239                                if(pl == 3){
1240                                    nphit_i++;
1241                                    enhit_i += (op->dedx).At(ih);
1242                                };
1243                            };
1244                        };
1245                        if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
1246                            for (Int_t ih=0; ih < oi->npmtadc; ih++){
1247                                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1248                                if(pl == 4){
1249                                    nphit_i++;
1250                                    enhit_i += (op->dedx).At(ih);
1251                                };
1252                            };
1253                        };          
1254    
1255                                    
1256            if(                      if(
1257               (use_TOF || use_S1 || use_S2 || use_S3)            &&                          (use_TOF || use_S1 || use_S2 || use_S3)            &&
1258               (nphit_p+nphit_i) !=0 &&                            (nphit_p+nphit_i) !=0 &&        
1259               true){                          true){
1260                                            
1261              //      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);
1262              //      printf(" score p %i score i %i \n",tp_score,ti_score);                          //          printf(" score p %i score i %i \n",tp_score,ti_score);
1263              //            if( enhit_p > enhit_i ) tp_score++;                          //                if( enhit_p > enhit_i ) tp_score++;
1264              //            if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;                          //                if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;
1265              if ( nphit_p > nphit_i ) tp_score++;                          if ( nphit_p > nphit_i ) tp_score++;
1266              if ( nphit_p < nphit_i ) ti_score++;                          if ( nphit_p < nphit_i ) ti_score++;
1267              if ( nphit_p == nphit_i ){                          if ( nphit_p == nphit_i ){
1268                if ( enhit_p > enhit_i ) tp_score++;                              if ( enhit_p > enhit_i ) tp_score++;
1269                else ti_score++;                              else ti_score++;
1270              };                          };
1271              //      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);
1272            };                      };
1273            delete tr;                      delete tr;
1274            //                      //
1275          } else {                  } else {
1276            //                      // -------------
1277            // NOT a NUCLEUS                      // NOT a NUCLEUS
1278            //                      // -------------
1279            //printf(" NOT a NUCLEUS! en = %f \n",sen);                      //printf(" NOT a NUCLEUS! en = %f \n",sen);
1280    
1281            Int_t nphit_p =0;                      Int_t nphit_p =0;
1282            Int_t nphit_i =0;                      Int_t nphit_i =0;
1283                                    
1284                                    
1285            /*                            cout << "track: npmtadc "<< op->npmtadc << endl;                      /*                          cout << "track: npmtadc "<< op->npmtadc << endl;
1286              cout << "track: npmttdc "<< op->npmttdc << endl;                                                  cout << "track: npmttdc "<< op->npmttdc << endl;
1287              cout << "image: npmtadc "<< oi->npmtadc << endl;                                                  cout << "image: npmtadc "<< oi->npmtadc << endl;
1288              cout << "image: npmttdc "<< oi->npmttdc << endl;*/                                                  cout << "image: npmttdc "<< oi->npmttdc << endl;*/
1289                                    
1290  //        for (Int_t ih=0; ih < op->npmtadc; ih++){  //        for (Int_t ih=0; ih < op->npmtadc; ih++){
1291  //          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 1296  void PamLevel2::SortTracks(){
1296  //          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );  //          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1297  //          if(pl == 1 || pl == 2 || pl == 5)nphit_i++;  //          if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
1298  //        };  //        };
1299            // --- modified to count tdc signals (more efficient?)                      // --- modified to count tdc signals (more efficient?)
1300            // --- and to implement check on tdcflag                      // --- and to implement check on tdcflag
1301            for (Int_t ih=0; ih < op->npmttdc; ih++){                      for (Int_t ih=0; ih < op->npmttdc; ih++){
1302              Int_t pl = tof_obj->GetPlaneIndex( (op->pmttdc).At(ih) );                          Int_t pl = tof_obj->GetPlaneIndex( (op->pmttdc).At(ih) );
1303  //          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++;
1304              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 )) ){
1305                if( (op->tdcflag).At(ih)==0 )nphit_p++;                              if( (op->tdcflag).At(ih)==0 )nphit_p++;
1306              };                          };
1307            };                      };
1308                                    
1309            for (Int_t ih=0; ih < oi->npmttdc; ih++){                      for (Int_t ih=0; ih < oi->npmttdc; ih++){
1310              Int_t pl = tof_obj->GetPlaneIndex( (oi->pmttdc).At(ih) );                          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmttdc).At(ih) );
1311  //          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++;  
1312              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 )) ){
1313                if( (oi->tdcflag).At(ih)==0 )nphit_i++;                                if( (oi->tdcflag).At(ih)==0 )nphit_i++;    
1314              };                          };
1315            };                      };
1316                                    
1317            if(                      if(
1318               (nphit_p+nphit_i) !=0 &&                            (nphit_p+nphit_i) !=0 &&        
1319               true){                          true){
1320                                            
1321              if ( nphit_p != nphit_i ){                          if ( nphit_p != nphit_i ){
1322                totp_score += nphit_p;                              totp_score += nphit_p;
1323                toti_score += nphit_i;                              toti_score += nphit_i;
1324                tp_score+=nphit_p;                              tp_score+=nphit_p;
1325                ti_score+=nphit_i;                              ti_score+=nphit_i;
1326                            };
1327                            //          if     ( nphit_p > nphit_i) tp_score+=nphit_p;
1328                            //          else if( nphit_p < nphit_i) ti_score+=nphit_i;
1329                            //          else ;//niente
1330                        };
1331                    };
1332                    //      cout << "TOF "<<tp_score<<ti_score<<endl;
1333              };              };
             //      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;  
       };  
1334    
1335    
1336  //      if(tp_score == ti_score) use_TRK = true;  //      if(tp_score == ti_score) use_TRK = true;
1337    
1338    
1339        // -----------------------------------------------------------------------------------------              // -----------------------------------------------------------------------------------------
1340        // tracker check              // *****************************************************************************************
1341        // -----------------------------------------------------------------------------------------              // -----------------------------------------------------------------------------------------
1342        // chi**2 difference is not always large enough to distinguish among              // tracker check
1343        // the real track and its image.              // -----------------------------------------------------------------------------------------
1344        // Tracker check will be applied always when calorimeter and tof information is ambiguous.              // chi**2 difference is not always large enough to distinguish among
1345        // *** MODIFIED ON AUGUST 2007 ***              // the real track and its image.
1346        if(use_TRK){              // Tracker check will be applied always when calorimeter and tof information is ambiguous.
1347                // *** MODIFIED ON AUGUST 2007 ***
1348                if(use_TRK){
1349  //      if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;  //      if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
1350  //      else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;  //      else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
1351    
1352            // CHECK 1 : number of points along X                    // CHECK 1 : number of points along X  
1353          if ( tp->GetNX() >= ti->GetNX() ){                  if ( tp->GetNX() >= ti->GetNX() ){
1354            tp_score++ ;                      tp_score++ ;
1355            totp_score++ ;                      totp_score++ ;
1356          };                  };
1357          if ( tp->GetNX() <= ti->GetNX() ){                  if ( tp->GetNX() <= ti->GetNX() ){
1358            ti_score++ ;                      ti_score++ ;
1359            toti_score++ ;                      toti_score++ ;
1360          };                  };
1361            // CHECK 2 : number of points along Y                    // CHECK 2 : number of points along Y  
1362          if ( tp->GetNY() >= ti->GetNY() ){                  if ( tp->GetNY() >= ti->GetNY() ){
1363            tp_score++ ;                      tp_score++ ;
1364            totp_score++ ;                      totp_score++ ;
1365          };                  };
1366          if ( tp->GetNY() <= ti->GetNY() ){                  if ( tp->GetNY() <= ti->GetNY() ){
1367            ti_score++ ;                      ti_score++ ;
1368            toti_score++ ;                      toti_score++ ;
1369          };                  };
           // 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++ ;  
1370    
1371          //      cout << "TRK "<<tp_score<<ti_score<<endl;                  //      cout << "TRK "<<tp_score<<ti_score<<endl;
1372        };              };
1373                            
1374    
1375                // -----------------------------------------------------------------------------------------
1376                // *****************************************************************************************
1377                // -----------------------------------------------------------------------------------------
1378                // GPamela check
1379                // -----------------------------------------------------------------------------------------
1380                
1381                //---------------------------------------------------
1382                // count the number of GP hits
1383                //---------------------------------------------------
1384                if(use_GP){
1385                    int ngphits_p=0;
1386                    int ngphits_i=0;
1387                    float toll = 0.02; //200 micron
1388                    for(int ih=0; ih<GetGPamela()->Nthspe; ih++){
1389                        int ip = (Int_t) GetGPamela()->Itrpb[ih] - 1;
1390                        if(
1391                            tp &&
1392                            tp->YGood(ip) &&
1393                            fabs(tp->ym[ip]- GetGPamela()->Yavspe[ih])<toll &&
1394                            true) ngphits_p++;
1395                        if( ti &&
1396                            ti->YGood(ip) &&
1397                            fabs(ti->ym[ip]- GetGPamela()->Yavspe[ih])<toll &&
1398                            true) ngphits_i++;
1399                    }
1400                    if(
1401                        ngphits_p > ngphits_i &&
1402                        true){
1403                        tp_score++ ;
1404                        totp_score++ ;                  
1405                    }
1406                    if(
1407                        ngphits_p < ngphits_i &&
1408                        true){
1409                        ti_score++ ;
1410                        toti_score++ ;                  
1411                    }
1412                }
1413    
       // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*  
       // the winner is....  
       // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*  
       if      (tp_score > ti_score) {  
           
   
       }else if (tp_score < ti_score) {  
1414    
1415                // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1416                // the winner is....
1417                // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1418                if      (tp_score > ti_score) {
1419            
1420    
1421          ts = ti;//its image!!              }else if (tp_score < ti_score) {
         cs = ci;  
         os = oi;  
         Int_t totis = toti_score;  
1422    
         ti = tp;//its image!!  
         ci = cp;  
         oi = op;  
1423    
1424          tp = ts;//its image!!                  ts = ti;//its image!!
1425          cp = cs;                  cs = ci;
1426          op = os;                  os = oi;
1427                    rs = ri;
1428                    Int_t totis = toti_score;
1429    
1430                    ti = tp;//its image!!
1431                    ci = cp;
1432                    oi = op;
1433                    ri = rp;
1434    
1435                    tp = ts;//its image!!
1436                    cp = cs;
1437                    op = os;
1438                    rp = rs;
1439    
1440          toti_score = totp_score;                  toti_score = totp_score;
1441          totp_score = totis;                  totp_score = totis;
1442    
1443                                    
1444        }else {              }else {
1445    
1446  //      cout << "Warning - track image ambiguity not solved" << endl;  //      cout << "Warning - track image ambiguity not solved" << endl;
1447    
1448        };              };
1449                            
1450      }else{          }else{
1451        totp_score = 1;              totp_score = 1;
1452        toti_score = 0;              toti_score = 0;
1453                
1454        //            ts = tp;              //      ts = tp;
1455        //            cs = cp;              //      cs = cp;
1456        //            os = op;              //      os = op;
1457      };          };
1458                    
1459      //  cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;          //      cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
1460      //  sorted_tracks->Add(ts);//save the track in the sorted array          //      sorted_tracks->Add(ts);//save the track in the sorted array
1461      //  sorted_tracks.Add(ts);//save the track in the sorted array          //      sorted_tracks.Add(ts);//save the track in the sorted array
1462      //  sorted_tracks.Add(tp);//save the track in the sorted array          //      sorted_tracks.Add(tp);//save the track in the sorted array
1463      //  cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;          //      cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
1464      //  cout<<"o "<<tp<<endl;          //      cout<<"o "<<tp<<endl;
1465      //  cout<<"o "<<cp<<endl;          //      cout<<"o "<<cp<<endl;
1466      //  cout<<"o "<<op<<endl;          //      cout<<"o "<<op<<endl;
1467    
1468      new(ttsorted[i]) PamTrack(tp,cp,op);          new(ttsorted[i]) PamTrack(tp,cp,op,rp);
1469      new(ttimage[i])  PamTrack(ti,ci,oi);          new(ttimage[i])  PamTrack(ti,ci,oi,ri);
1470    
1471      ((PamTrack*)(ttsorted[i]))->SetPScore(totp_score);          ((PamTrack*)(ttsorted[i]))->SetPScore(totp_score);
1472      ((PamTrack*)(ttsorted[i]))->SetIScore(toti_score);          ((PamTrack*)(ttsorted[i]))->SetIScore(toti_score);
1473      ((PamTrack*)(ttimage[i]))->SetPScore(totp_score);          ((PamTrack*)(ttimage[i]))->SetPScore(totp_score);
1474      ((PamTrack*)(ttimage[i]))->SetIScore(toti_score);          ((PamTrack*)(ttimage[i]))->SetIScore(toti_score);
1475    };      };
1476    
1477    if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){      if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){
1478      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;
1479      tsorted->Delete(); tsorted=0;          tsorted->Delete(); tsorted=0;
1480      timage->Delete(); timage=0;          timage->Delete(); timage=0;    
1481    }      }
1482    
1483    //Restore Object count      //Restore Object count
1484    //To save space in the table keeping track of all referenced objects      //To save space in the table keeping track of all referenced objects
1485    //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.
1486    TProcessID::SetObjectCount(ObjectNumber);      TProcessID::SetObjectCount(ObjectNumber);
1487            
1488  };  };
1489  //--------------------------------------  //--------------------------------------
# Line 1417  TClonesArray *PamLevel2::GetTracks(){ Line 1512  TClonesArray *PamLevel2::GetTracks(){
1512    
1513      return tsorted;      return tsorted;
1514            
1515   };  };
1516  //--------------------------------------  //--------------------------------------
1517   //  //
1518   //  //
1519  //--------------------------------------  //--------------------------------------
1520  /**  /**
1521   * Retrieves the it-th Pamela "physical" track.   * Retrieves the it-th Pamela "physical" track.
# Line 1481  PamTrack *PamLevel2::GetTrack(int it){ Line 1576  PamTrack *PamLevel2::GetTrack(int it){
1576   */   */
1577  PamTrack *PamLevel2::GetTrackImage(int it){  PamTrack *PamLevel2::GetTrackImage(int it){
1578    
 //     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;  
   
   
1579  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1580      SortTracks();      SortTracks();
1581  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
# Line 1552  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1622  TTree *PamLevel2::GetPamTree(TFile *f, T
1622          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 ");
1623          return pam_tree;          return pam_tree;
1624      };      };
1625    //      //
1626    
1627      cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;      cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;
1628    
# Line 1698  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1768  TTree *PamLevel2::GetPamTree(TFile *f, T
1768    
1769      TTree *L = (TTree*)f->Get("SelectionList");      TTree *L = (TTree*)f->Get("SelectionList");
1770      if(L && SELLI==1) {      if(L && SELLI==1) {
1771  //      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;  
1772          sel_tree = 0;          sel_tree = 0;
1773      }else{      }else{
1774          cout << "SelectionList  : missing tree"<<endl;          cout << "SelectionList  : missing tree"<<endl;
# Line 1749  TList*  PamLevel2::GetListOfLevel2Files( Line 1813  TList*  PamLevel2::GetListOfLevel2Files(
1813      //    if(ddir=="")ddir = wdir;      //    if(ddir=="")ddir = wdir;
1814  //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);  //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
1815      if ( ddir != ""){      if ( ddir != ""){
1816        cout << "Level2 data directory : "<<  ddir << endl;          cout << "Level2 data directory : "<<  ddir << endl;
1817      } else {      } else {
1818        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;
1819      };      };
1820      TList *contents  = new TList; // create output list      TList *contents  = new TList; // create output list
1821      contents->SetOwner();      contents->SetOwner();
# Line 1768  TList*  PamLevel2::GetListOfLevel2Files( Line 1832  TList*  PamLevel2::GetListOfLevel2Files(
1832  //          return 0;  //          return 0;
1833  //      }        //      }      
1834  //      flisttxt = fullpath;  //      flisttxt = fullpath;
1835        if ( !flisttxt.EndsWith(".root") ){          if ( !flisttxt.EndsWith(".root") ){
1836    
1837          flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));              flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1838    
1839          if( !gSystem->ChangeDirectory(ddir) ){              if( !gSystem->ChangeDirectory(ddir) ){
1840              cout << "Cannot change directory : "<<ddir<<endl;                  cout << "Cannot change directory : "<<ddir<<endl;
1841              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;  
1842              }              }
1843              if(file.Contains("#"))file = file(0,file.First("#"));          
1844                cout <<"Input file list : " << flisttxt <<endl;
1845                ifstream in;
1846                in.open(flisttxt, ios::in); //open input file list
1847                if(!in.good()){
1848                    cout <<" ERROR opening the file "<<endl;
1849                    gSystem->ChangeDirectory(wdir); // back to the working directory
1850                    return 0;
1851                }  
1852                int line=0;
1853                while (1) {
1854                    TString file;
1855                    in >> file;
1856                    if (!in.good()) break;
1857                    line++;
1858    //          cout <<"(1) " << file << endl;
1859                    if(file.IsNull()){
1860                        cout << "-- list interrupted at line "<<line <<endl;
1861                        break;
1862                    }
1863                    if(file.Contains("#"))file = file(0,file.First("#"));
1864  //          cout <<"(2) " << file << endl;  //          cout <<"(2) " << file << endl;
1865  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){
1866  //          if( (fullpath = gSystem->FindFile(ddir,file)) ){  //          if( (fullpath = gSystem->FindFile(ddir,file)) ){
1867              if( file.EndsWith(".root") ){                  if( file.EndsWith(".root") ){
1868                TString filedir;                      TString filedir;
1869                if (ddir != ""){                      if (ddir != ""){
1870                  filedir = ddir; // take the input dir                          filedir = ddir; // take the input dir
1871                } else {                      } else {
1872                  gSystem->ChangeDirectory(wdir); // back to the working directory                          gSystem->ChangeDirectory(wdir); // back to the working directory
1873                  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
1874                };                      };
1875                  char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir),gSystem->BaseName(file));                      char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir),gSystem->BaseName(file));
1876                  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
1877                  delete fullpath;                      delete fullpath;
1878              }                  }
1879  //          }else{  //          }else{
1880  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;
1881  //          };  //          };
1882          };              };
1883          in.close();              in.close();
1884        } else {          } else {
1885            if(flisttxt.Contains("#"))flisttxt = flisttxt(0,flisttxt.First("#"));              if(flisttxt.Contains("#"))flisttxt = flisttxt(0,flisttxt.First("#"));
1886            char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));              char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1887            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
1888            delete fullpath;              delete fullpath;
1889        };                  };      
1890      }else{      }else{
1891                    
1892          cout << "No input file list given."<<endl;          cout << "No input file list given."<<endl;
1893          cout << "Check for existing root files."<<endl;          cout << "Check for existing root files."<<endl;
1894  //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;  //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;
1895          if ( ddir == "" ){          if ( ddir == "" ){
1896            ddir = wdir;              ddir = wdir;
1897            cout << "Level2 data directory : "<<  ddir << endl;              cout << "Level2 data directory : "<<  ddir << endl;
1898          };          };
1899    
1900          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
# Line 1887  TChain *PamLevel2::GetPamTree(TList *fl, Line 1951  TChain *PamLevel2::GetPamTree(TList *fl,
1951            
1952      TChain *Trout =0;      TChain *Trout =0;
1953    
1954            // -------------------------------------------
1955        // set flags to include/exclude trees/branches
1956        // -------------------------------------------
1957      if( detlist.Contains("+AUTO", TString::kIgnoreCase) ) {      if( detlist.Contains("+AUTO", TString::kIgnoreCase) ) {
1958          if( fl->GetEntries()>0 ){          if( fl->GetEntries()>0 ){
1959              cout << "+AUTO"<<endl;              cout << "+AUTO"<<endl;
1960              TFile *fprimo = new TFile( fl->At(0)->GetName() );              TFile *fprimo = new TFile( fl->At(0)->GetName() );
1961              GetWhichTrees(fprimo);              GetWhichTrees(fprimo);
1962                fprimo->Close();// AAAAARGGGGGHHHHH!!!!!!! non commentare questa riga, altrimenti si incasina il TChain
1963              fprimo->Delete();              fprimo->Delete();
1964          }          }
1965      };      };
1966      SetWhichTrees(detlist);          SetWhichTrees(detlist);    
1967    
1968    
1969        // -------------------------------------------
1970        // build chains
1971        // -------------------------------------------
1972        TChain *T = 0;      
1973        TChain *C = 0;
1974        TChain *O = 0;
1975        TChain *R = 0;
1976        TChain *S = 0;
1977        TChain *N = 0;
1978        TChain *A = 0;
1979        TChain *B = 0;
1980        TChain *G = 0;
1981    
1982  //    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;  
1983            
1984      if(TRK2||TRK1||TRKh) T = new TChain("Tracker");          if(TRK2||TRK1||TRKh) T = new TChain("Tracker");    
1985      if(CAL2||CAL1)       C = new TChain("Calorimeter");      if(CAL2||CAL1)       C = new TChain("Calorimeter");
# Line 1945  TChain *PamLevel2::GetPamTree(TList *fl, Line 2012  TChain *PamLevel2::GetPamTree(TList *fl,
2012          };          };
2013      };      };
2014            
2015      cout << "done chain \n";      cout << "done chains\n";
2016      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2017    
2018  //    UInt_t *found=0;  
2019        // -------------------------------------------
2020        // make friends
2021        // -------------------------------------------
2022    
2023  // Tracker  // Tracker
2024        cout << "Friends: "<<endl;
2025      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;  
2026          if(!Trout)Trout=T;          if(!Trout)Trout=T;
2027          else Trout->AddFriend("Tracker");          else Trout->AddFriend("Tracker");
2028      }else{  //      cout << "+Tacker"<<endl;
 //        cout << "Tracker      : missing tree"<<endl;  
2029      };      };
2030      // Calorimeter      // Calorimeter
2031      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;  
2032          if(!Trout)Trout=C;          if(!Trout)Trout=C;
2033          else Trout->AddFriend("Calorimeter");          else Trout->AddFriend("Calorimeter");
2034      }else{  //      cout << "+Calorimeter"<<endl;
 //        cout << "Calorimeter  : missing tree"<<endl;  
2035      };      };
2036      // ToF          // ToF    
2037      if(O && TOF) {      if(O && TOF) {
 //        O->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));  
 //        cout << "ToF          : set branch address ToFLevel2"<<endl;  
2038          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2039          else Trout->AddFriend("ToF");          else Trout->AddFriend("ToF");
2040      }else{  //      cout << "+ToF"<<endl;
 //        cout << "ToF         : missing tree"<<endl;  
2041      };      };
2042      // Trigger      // Trigger
2043      if(R && TRG) {      if(R && TRG) {
 //        R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));  
 //        cout << "Trigger      : set branch address TrigLevel2"<<endl;  
2044          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2045          else Trout->AddFriend("Trigger");          else Trout->AddFriend("Trigger");
2046      }else{  //      cout << "+Trigger"<<endl;
 //        cout << "Trigger      : missing tree"<<endl;  
2047      };      };
2048      // S4      // S4
2049      if(S && S4) {      if(S && S4) {
 //        S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));  
 //        cout << "S4           : set branch address S4Level2"<<endl;  
2050          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2051          else Trout->AddFriend("S4");          else Trout->AddFriend("S4");
2052      }else{  //      cout << "+S4"<<endl;
 //        cout << "S4           : missing tree"<<endl;  
2053      };      };
2054      // Neutron Detector      // Neutron Detector
2055      if(N && ND) {      if(N && ND) {
 //        N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));  
 //        cout << "NeutronD     : set branch address NDLevel2"<<endl;  
2056          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2057          else Trout->AddFriend("NeutronD");          else Trout->AddFriend("NeutronD");
2058      }else{  //      cout << "+NeutronD"<<endl;
 //        cout << "NeutronD     : missing tree"<<endl;  
2059      };      };
2060      // Anticounters      // Anticounters
2061      if(A && AC) {      if(A && AC) {
 //        A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));  
 //        cout << "Anticounter  : set branch address AcLevel2"<<endl;  
2062          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2063          else Trout->AddFriend("Anticounter");          else Trout->AddFriend("Anticounter");
2064      }else{  //      cout << "+Anticounter"<<endl;
 //        cout << "Anticounter  : missing tree"<<endl;  
2065      };      };
2066      // Orbital Info      // Orbital Info
2067      if(B && ORB) {      if(B && ORB) {
 //      B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));  
 //      cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;  
2068          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2069          else Trout->AddFriend("OrbitalInfo");          else Trout->AddFriend("OrbitalInfo");
2070      }else{  //      cout << "+OrbitalInfo"<<endl;
 //      cout << "OrbitalInfo  : missing tree"<<endl;  
2071      };      };
2072      // GPamela      // GPamela
2073      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;  
2074          if(!Trout)Trout=G;          if(!Trout)Trout=G;
2075          else Trout->AddFriend("h20");          else Trout->AddFriend("h20");
2076      }else{  //      cout << "+h20"<<endl;
 //      cout << "h20          : missing tree"<<endl;  
2077      };      };
2078    
2079  //  =====================================  //  =====================================
# Line 2050  TChain *PamLevel2::GetPamTree(TList *fl, Line 2081  TChain *PamLevel2::GetPamTree(TList *fl,
2081  //  =====================================  //  =====================================
2082      SetBranchAddress(Trout);      SetBranchAddress(Trout);
2083    
2084    
2085    //  ------------------------------------
2086    //  finally handle selection trees...
2087    //  (it is not friend of pamela tree)
2088    //  ------------------------------------
2089    
2090      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2091    
2092      // Selection List      // Selection List
2093      if(L && SELLI==1) {      if(L && SELLI==1) {
2094          cout<<">>> Found selection-list <<<"<<endl;          cout<<">>> Found selection-list <<<"<<endl;
2095          L->SetBranchAddress("RunEntry",&irun);  //      L->SetBranchAddress("RunEntry",&irun);
2096            L->SetBranchAddress("RunEntry",&irunt);//NEWNEW
2097          cout << "SelectionList: set branch address RunEntry"<<endl;          cout << "SelectionList: set branch address RunEntry"<<endl;
2098          L->SetBranchAddress("EventEntry",&irunentry);          L->SetBranchAddress("EventEntry",&irunentry);
2099          cout << "SelectionList: set branch address EventEntry"<<endl;          cout << "SelectionList: set branch address EventEntry"<<endl;
2100          sel_tree = L;          sel_tree = L;
2101  //      if(!Trout)Trout=O;  //      if(!Trout)Trout=O;
2102  //      else Trout->AddFriend("SelectionList");  //      else Trout->AddFriend("SelectionList");
2103          cout << "----------------------------------------------------" <<endl;          cout << "+SelectionList"<<endl;
2104            cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2105      }else{      }else{
2106  //      cout << "SelectionList  : missing tree"<<endl;  //      cout << "SelectionList  : missing tree"<<endl;
2107          if(L)L->Delete();          if(L)L->Delete();
2108      };      };
       
 //    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;  
 //     };  
2109    
2110    //  --------------------------------------------
2111    //  return the pamela chain with all the friends
2112    //  --------------------------------------------
2113    
2114      pam_tree = Trout;      pam_tree = Trout;
2115            
# Line 2174  void PamLevel2::SetBranchAddress(TTree * Line 2199  void PamLevel2::SetBranchAddress(TTree *
2199      if(GP) {      if(GP) {
2200  //      GetPointerTo("GPamela");  //      GetPointerTo("GPamela");
2201          if(!gp_obj)gp_obj = new GPamela();          if(!gp_obj)gp_obj = new GPamela();
2202          gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri  //      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2203    // //   t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
2204            if(SELLI) t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
2205            else      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2206    
2207          cout << "h20          : set branch address GPamela "<<endl;          cout << "h20          : set branch address GPamela "<<endl;
2208      };      };
     // 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;  
     };  
2209            
2210  }  }
2211  /**  /**
# Line 2205  void PamLevel2::SetBranchAddress(TChain Line 2227  void PamLevel2::SetBranchAddress(TChain
2227  //    GP     = GP & t->GetBranchStatus("h20");  //    GP     = GP & t->GetBranchStatus("h20");
2228    
2229      // Tracker      // Tracker
2230       if(TRK2) {      if(TRK2) {
2231          t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));          t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
2232          cout << "Tracker      : set branch address TrkLevel2"<<endl;          cout << "Tracker      : set branch address TrkLevel2"<<endl;
2233      };      };
# Line 2213  void PamLevel2::SetBranchAddress(TChain Line 2235  void PamLevel2::SetBranchAddress(TChain
2235          t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));          t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
2236          cout << "Tracker      : set branch address TrkLevel1"<<endl;          cout << "Tracker      : set branch address TrkLevel1"<<endl;
2237      };      };
2238       if(TRKh) {      if(TRKh) {
2239          t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));          t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
2240          cout << "Tracker      : set branch address TrkHough"<<endl;          cout << "Tracker      : set branch address TrkHough"<<endl;
2241       };      };
2242            
2243      // Calorimeter      // Calorimeter
2244      if(CAL2) {      if(CAL2) {
# Line 2263  void PamLevel2::SetBranchAddress(TChain Line 2285  void PamLevel2::SetBranchAddress(TChain
2285      if(GP) {      if(GP) {
2286  //      GetPointerTo("GPamela");  //      GetPointerTo("GPamela");
2287          if(!gp_obj)gp_obj = new GPamela();          if(!gp_obj)gp_obj = new GPamela();
2288          gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri          if(SELLI) t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
2289            else      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2290    //      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2291          cout << "h20          : set branch address GPamela "<<endl;          cout << "h20          : set branch address GPamela "<<endl;
2292      };      };
2293      // SelectionList      // SelectionList
2294      if(SELLI==1) {  //     if(SELLI==1){
2295          t->SetBranchAddress("RunEntry", &irun);  //      t->SetBranchAddress("RunEntry",&irunt);//NEWNEW
2296          cout << "SelectionList: set branch address RunEntry"<<endl;  //      cout << "SelectionList: set branch address RunEntry"<<endl;
2297          t->SetBranchAddress("EventEntry", &irunentry);  //      t->SetBranchAddress("EventEntry",&irunentry);
2298          cout << "SelectionList: set branch address EventEntry"<<endl;  //      cout << "SelectionList: set branch address EventEntry"<<endl;
2299      };          
2300        //     }
2301    
2302  }  }
2303    
2304    
# Line 2287  void PamLevel2::SetBranchAddress(TChain Line 2312  void PamLevel2::SetBranchAddress(TChain
2312   * @return Pointer to a TChain   * @return Pointer to a TChain
2313   */   */
2314  TChain *PamLevel2::GetRunTree(TList *fl){  TChain *PamLevel2::GetRunTree(TList *fl){
2315    //      //
2316    //      //
2317    //      //
2318    if ( run_tree ){      if ( run_tree ){
2319      printf("WARNING: TChain *PamLevel2::GetRunTree(TList *fl) -- run_tree already exists!\n ");          printf("WARNING: TChain *PamLevel2::GetRunTree(TList *fl) -- run_tree already exists!\n ");
2320      return run_tree;          return run_tree;
2321    };          };  
2322    //      //
2323    TChain *R = new TChain("Run");  
2324    
2325        TChain *R = new TChain("Run");
2326            
2327      // loop over files and create chains              // loop over files and create chains        
2328      TIter next(fl);      TIter next(fl);
# Line 2307  TChain *PamLevel2::GetRunTree(TList *fl) Line 2334  TChain *PamLevel2::GetRunTree(TList *fl)
2334              R->Add(name);              R->Add(name);
2335          };          };
2336      }      }
2337        
2338    
2339      if(R->GetNtrees()){      if(RUN && R->GetNtrees()){
2340            
2341          R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));          R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
2342          cout << "Run         : set branch address RunInfo"<<endl;          cout << "Run         : set branch address RunInfo"<<endl;
2343          R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano          R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
2344          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
2345    
2346            irunoffset = new int[R->GetNtrees()];
2347            if(DBG){
2348                cout << "----------------------------------------------------"<<endl;
2349                cout << "irun\t | ";
2350                cout << "tree\t |";
2351    //      cout << "offset\t |";
2352                cout << "RUN\t";
2353                cout << "FRAG\t";
2354                cout << "NEVENTS\t";
2355                cout << "absolute time\t\t\t";
2356                cout << "on-board time";
2357                cout<<endl;
2358            }
2359            for (Int_t ii=0; ii<R->GetEntries(); ii++){
2360                R->GetEntry(ii);
2361                if(DBG){
2362                    cout << ii<< "\t | ";
2363                    cout << R->GetTreeNumber()<< "\t |";
2364    //          cout << R->GetChainOffset()<< "\t |";
2365                    cout <<GetRunInfo()->ID<<"\t";
2366                    cout <<GetRunInfo()->ID_RUN_FRAG<<"\t";
2367                    cout <<GetRunInfo()->NEVENTS<< "\t";
2368                    cout <<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME <<"\t";
2369                    cout <<GetRunInfo()->RUNHEADER_OBT<<" <---> "<<GetRunInfo()->RUNTRAILER_OBT<<"\t";
2370                    cout <<endl;
2371                }
2372                irunoffset[R->GetTreeNumber()]=R->GetChainOffset();
2373            }
2374            cout << "N.run = "<<R->GetEntries()<<endl;
2375            cout << "----------------------------------------------------"<<endl;
2376    
2377    
2378      }else{      }else{
2379          delete R;          delete R;
2380          R=0;          R=0;
2381      }      }
2382        
2383    
2384      run_tree = R;      run_tree = R;
2385    
# Line 2334  TChain *PamLevel2::GetRunTree(TList *fl) Line 2396  TChain *PamLevel2::GetRunTree(TList *fl)
2396   * @return Pointer to a TTree   * @return Pointer to a TTree
2397   */   */
2398  TTree *PamLevel2::GetRunTree(TFile *f){  TTree *PamLevel2::GetRunTree(TFile *f){
2399    if ( run_tree ){      if ( run_tree ){
2400      printf("WARNING: TTree *PamLevel2::GetRunTree(TFile *f) -- run_tree already exists!\n ");          printf("WARNING: TTree *PamLevel2::GetRunTree(TFile *f) -- run_tree already exists!\n ");
2401      return run_tree;          return run_tree;
2402    };      };
2403                    
2404    
2405      cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;      cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;
# Line 2349  TTree *PamLevel2::GetRunTree(TFile *f){ Line 2411  TTree *PamLevel2::GetRunTree(TFile *f){
2411          cout << "Run         : set branch address RunInfo"<<endl;          cout << "Run         : set branch address RunInfo"<<endl;
2412          T->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano          T->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
2413          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
2414    
2415      }      }
2416    
2417      run_tree = (TChain*)T;      run_tree = (TChain*)T;
# Line 2362  TTree *PamLevel2::GetRunTree(TFile *f){ Line 2425  TTree *PamLevel2::GetRunTree(TFile *f){
2425   * @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
2426   */   */
2427  Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev){  Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev){
2428    //      //
2429    // check if we have already called once GetEntry, if not call it      // check if we have already called once GetEntry, if not call it
2430    //      //
2431      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;
2432      if(!run){      if(!run){
2433            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;
2434            return(false);                  return(false);  
2435      }      }
2436      if ( run->GetEntries() <= 0 ) return(false);      if ( run->GetEntries() <= 0 ) return(false);
2437    //      //
2438        
2439    //  Int_t oldrun = irun;      //  Int_t oldrun = irun;
2440    Long64_t oldrun = irun;      Long64_t oldrun = irun;
2441    
2442    // --------------------------------------      // --------------------------------------
2443    // if it is a full file (not preselected)      // if it is a full file (not preselected)
2444    // --------------------------------------      // --------------------------------------
2445    if(SELLI==0){      if(SELLI==0){
2446    
2447        //          //
2448        // the absolute time is necessary to relate the event with the run          // the absolute time is necessary to relate the event with the run
2449        //          //
2450        if( !GetOrbitalInfo() && !ISGP){          if( !GetOrbitalInfo() && !ISGP){
2451            cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;              cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
2452            return(false);              return(false);
2453        }          }
2454    
2455        ULong64_t abstime = 0;          ULong64_t abstime = 0;
2456        if( GetOrbitalInfo() )abstime=GetOrbitalInfo()->absTime;          if( GetOrbitalInfo() )abstime=GetOrbitalInfo()->absTime;
2457    
2458    
2459        //          //
2460        // the first time the routine is called, set run search from the beginning          // the first time the routine is called, set run search from the beginning
2461        //          //
2462        if ( irun < 0LL ){          if ( irun < 0LL ){
2463            irun = 0LL;              irun = 0LL;
2464            run->GetEntry(irun);              run->GetEntry(irun);
2465            runfirstentry = 0LL;              runfirstentry = 0LL;
2466            runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);              runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2467            if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;              if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
2468                        
2469            if( ISGP && run->GetEntries()!=1 ){              if( ISGP && run->GetEntries()!=1 ){
2470                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;
2471                cout << "** WARNING ** run will not be updated"<<endl;                  cout << "** WARNING ** run will not be updated"<<endl;
2472            }              }
2473    
2474        };                };      
2475        //          //
2476        if(ISGP)abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO          if(ISGP)abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO
2477        //          //
2478        if ( irun == run->GetEntries()-1LL &&          if ( irun == run->GetEntries()-1LL &&
2479             !(abstime >= GetRunInfo()->RUNHEADER_TIME &&               !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
2480               abstime <= GetRunInfo()->RUNTRAILER_TIME)                 abstime <= GetRunInfo()->RUNTRAILER_TIME)
2481              ){              ){
2482           irun = -1LL;              irun = -1LL;
2483           runfirstentry = 0LL;              irunt = -1LL;
2484           runlastentry = -1LL;              runfirstentry = 0LL;
2485         };              runlastentry = -1LL;
2486        // modificato il controllo sull'aggiornamento del run, per evitare problemi          };
2487        // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)          // modificato il controllo sull'aggiornamento del run, per evitare problemi
2488        //          // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)
2489        bool fromfirst = true;          //
2490        //          bool fromfirst = true;
2491        while ( !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1LL ){          //
2492            while ( !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1LL ){
2493  //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){  //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){
2494            irun++;              irun++;
2495            run->GetEntry(irun);              run->GetEntry(irun);
2496            runfirstentry = runlastentry;              runfirstentry = runlastentry;
2497            if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runfirstentry += 1LL;              if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runfirstentry += 1LL;
2498            runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);              runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2499  //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;  //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2500  //        cout << "runfirstentry "<<runfirstentry<<endl;  //        cout << "runfirstentry "<<runfirstentry<<endl;
2501            //      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)));
2502            //      printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME);              //    printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME);
2503            //      printf(" IDRUN %u \n",GetRunInfo()->ID);              //    printf(" IDRUN %u \n",GetRunInfo()->ID);
2504            //              //
2505  //        prevshift = 0;  //        prevshift = 0;
2506            //              //
2507            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)){
2508                printf(" resetting irun  (it should NOT happen!!!)\n");                  printf(" resetting irun  (it should NOT happen!!!)\n");
2509                fromfirst = false;                  fromfirst = false;
2510                irun = 0;                  irun = 0;
2511                run->GetEntry(irun);                  run->GetEntry(irun);
2512                runfirstentry = 0ULL;                  runfirstentry = 0ULL;
2513                runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);                  runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2514                if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;                  if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
2515            };              };
2516            //              //
2517        };          };
2518        //          //
2519        if (          if (
2520             !(abstime >= GetRunInfo()->RUNHEADER_TIME &&              !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
2521               abstime <= GetRunInfo()->RUNTRAILER_TIME)                abstime <= GetRunInfo()->RUNTRAILER_TIME)
2522            ) {              ) {
2523          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);
2524            return false;              return false;
2525        }          }
2526        //          //
2527        if ( irun == oldrun || irun >= run->GetEntries() ) return(false);          if ( irun == oldrun || irun >= run->GetEntries() ) return(false);
2528        //          //
2529        //  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);
2530        //          //
2531        prevshift = 0;          prevshift = 0;
2532        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;          cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2533  //      cout << "runfirstentry "<<runfirstentry<<endl;  //      cout << "runfirstentry "<<runfirstentry<<endl;
2534        return(true);              return(true);    
2535    };      };
2536    // ----------------------------------------------------      // ----------------------------------------------------
2537    // if it is a preselected file (there is SelectionList)      // if it is a preselected file (there is SelectionList)
2538    // NBNB - the event tree MUST be read first      // NBNB - the event tree MUST be read first
2539    // ----------------------------------------------------      // ----------------------------------------------------
2540    if(SELLI==1){            if(SELLI==1){      
2541        sel_tree->GetEntry(iev);          sel_tree->GetEntry(iev);
2542  //      cout << irun << " "<< irunentry << endl;  //      cout << irun << " "<< irunentry << endl;
2543        if(irun != oldrun){          if(irun != oldrun){
2544            run->GetEntry(irun);              run->GetEntry(irun);
2545            cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;              cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2546            prevshift = 0;              prevshift = 0;
2547            return true;              return true;
2548        }          }
2549        return false;          return false;
2550    }      }
2551    
2552    return false;      return false;
2553    //      //
2554  };  };
2555    
2556  Bool_t PamLevel2::UpdateRunInfo(Long64_t iev){  Bool_t PamLevel2::UpdateRunInfo(Long64_t iev){
# Line 2502  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2566  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2566        
2567      Int_t oldrun = irun; // store current run index      Int_t oldrun = irun; // store current run index
2568    
2569        // -----------------------------------------------------------------------
2570        // the first time the routine is called, set run search from the beginning
2571        // -----------------------------------------------------------------------
2572    
2573        if ( irun < 0 ){
2574            irun = 0LL;
2575            irunt = 0LL;
2576            irunentry = 0;
2577            prevshift = 0;
2578            run_tree->GetEntry(irun);
2579            if( !GetOrbitalInfo() )cout << "** WARNING ** missing OrbitalInfo ---> run info might be not correctly updated "<<endl;
2580        };      
2581        // ---------------------------------------------------------------
2582        // retrieve OBT and absolute time of the event
2583        // ---------------------------------------------------------------
2584        ULong64_t abstime = 0LL;
2585        ULong64_t obt     = 0LL;
2586        if( GetOrbitalInfo() ){
2587            abstime = GetOrbitalInfo()->absTime;
2588            obt     = GetOrbitalInfo()->OBT;
2589        }else{
2590            abstime = GetRunInfo()->RUNHEADER_TIME;
2591            obt     = GetRunInfo()->RUNHEADER_OBT;
2592        }
2593        
2594    
2595      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2596      // if it is a full file (not preselected)      // if it is a full file (not preselected)
2597      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2598      if(SELLI==0){      if(SELLI==0){
2599    
2600          // ---------------------------------------------------------------          // ---------------------------------------------------------------
2601          // increment dead and live-time counters          // increment dead and live-time counters
2602            // (only when reading a file not preselected)
2603          // ---------------------------------------------------------------          // ---------------------------------------------------------------
2604          if( GetTrigLevel2() ){          if(SELLI==0){
2605              totdltime[0]+=GetTrigLevel2()->dltime[0];              if( GetTrigLevel2() ){
2606              totdltime[1]+=GetTrigLevel2()->dltime[1];                  totdltime[0]+=GetTrigLevel2()->dltime[0];
2607          }                  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  
         // ---------------------------------------------------------------  
         if( !GetOrbitalInfo() && !ISGP ){  
             cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;  
             return(false);  
         }  
         
         // -----------------------------------------------------------------------  
         // the first time the routine is called, set run search from the beginning  
         // -----------------------------------------------------------------------  
         if ( irun < 0 ){  
             irun = 0LL;  
             irunentry = 0;  
             prevshift = 0;  
             run_tree->GetEntry(irun);  
   
             if( ISGP && run_tree->GetEntries()!=1 ){  
                 cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run_tree->GetEntries() << endl;  
                 cout << "** WARNING ** run will not be updated"<<endl;  
2608              }              }
2609          };                    totdltime[2]++;
   
         // -----------------------------------------------------------------------  
         // if it is simulation, assign abstime by hand (temporaneo!!!)  
         // -----------------------------------------------------------------------  
         if(ISGP){  
             abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO  
             obt     = GetRunInfo()->RUNHEADER_OBT; // BARBATRUCCO  
2610          }          }
2611    
2612          //          //
2613          bool fromfirst = true; // first loop over runs          bool fromfirst = true; // first loop over runs
2614    
 //      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;  
2615    
2616          // ------------------------------------------------------          // ------------------------------------------------------
2617          // loop over runs to find the one that contains the event          // loop over runs to find the one that contains the event
2618          // ------------------------------------------------------          // ------------------------------------------------------
2619          while (          while (
2620              (              (
2621                  (  //              (
2622                      !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)  //                  !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
2623                        abstime <= GetRunInfo()->RUNTRAILER_TIME) &&  //                    abstime <= GetRunInfo()->RUNTRAILER_TIME) &&
2624                      !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)  //                  !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
2625                        obt <= GetRunInfo()->RUNTRAILER_OBT)  //                    obt <= GetRunInfo()->RUNTRAILER_OBT)
2626                      )  //                  )
2627                  || GetRunInfo()->NEVENTS==0                  
2628                    !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
2629                      abstime <= GetRunInfo()->RUNTRAILER_TIME)
2630                    ||
2631                    !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
2632                      obt <= GetRunInfo()->RUNTRAILER_OBT)          
2633                    ||
2634                    GetRunInfo()->NEVENTS==0
2635  //              || !(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
2636                  || !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift)                  ||
2637                    !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift)
2638                  )                  )
2639                  && irun < run_tree->GetEntries() ){              && irun < run_tree->GetEntries() ){
2640    
2641    
2642    //          if( !(abstime >= GetRunInfo()->RUNHEADER_TIME &&abstime <= GetRunInfo()->RUNTRAILER_TIME)  )cout << "ABS TIME "<<abstime << " " <<GetRunInfo()->RUNTRAILER_TIME <<endl;
2643    //          if( !(obt >= GetRunInfo()->RUNHEADER_OBT && obt <= GetRunInfo()->RUNTRAILER_OBT) )cout << "OBT TIME "<< obt <<" "<< GetRunInfo()->RUNTRAILER_OBT << endl;
2644    //          if( GetRunInfo()->NEVENTS==0  )cout <<"GetRunInfo()->NEVENTS==0 "<<endl;
2645    //          if( !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift) ) cout << "irunentry > "<<GetRunInfo()->NEVENTS-1-prevshift << endl;
2646              // - - - - - - - - - - - - -              // - - - - - - - - - - - - -
2647              // irunentry = position of current entry, relative to the run              // irunentry = position of current entry, relative to the run
2648              // 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 2651  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2651              // -----------------------------------------              // -----------------------------------------
2652              // store dead and live-time of previous run              // store dead and live-time of previous run
2653              // -----------------------------------------              // -----------------------------------------
2654    //          if(SELLI==0){
2655              if(fromfirst){              if(fromfirst){
2656                  if(oldrun==irun){                  if(oldrun==irun){
2657                      /// decrement counters                      /// decrement counters
# Line 2618  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2681  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2681                  }                  }
2682                  totdltime[2]=1;                             //event counter                  totdltime[2]=1;                             //event counter
2683              }              }
2684    //          }
2685    
2686                irun++;        
             irun++;  
2687              // ------------------------------------              // ------------------------------------
2688              // if the end of run tree is reached...              // if the end of run tree is reached...
2689              // ------------------------------------              // ------------------------------------
# Line 2648  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2711  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2711              if(irun>0)runfirstentry += (GetRunInfo()->NEVENTS)-prevshift;              if(irun>0)runfirstentry += (GetRunInfo()->NEVENTS)-prevshift;
2712              irunentry = 0;              irunentry = 0;
2713              prevshift = 0;                        prevshift = 0;          
2714              run_tree->GetEntry(irun);                    run_tree->GetEntry(irun);//update runinfo
2715                irunt = irun - irunoffset[run_tree->GetTreeNumber()];
2716              if(GetRunInfo()->RUNHEADER_OBT>GetRunInfo()->RUNTRAILER_OBT ){              if(GetRunInfo()->RUNHEADER_OBT>GetRunInfo()->RUNTRAILER_OBT ){
2717                  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;
2718                  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 2734  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2734          // --------------------------------------          // --------------------------------------
2735    
2736    
   
 //      // -----------------------------------------  
 //      // 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  
           
   
2737          // --------------------------------------          // --------------------------------------
2738          // ---> exit with TRUE          // ---> exit with TRUE
2739          // --------------------------------------          // --------------------------------------
# Line 2741  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2755  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2755      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2756      // if it is a preselected file (there is SelectionList)      // if it is a preselected file (there is SelectionList)
2757      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2758        // irun  = run entry relative to the chain
2759        // irunt = run entry relative to the tree
2760      if(SELLI==1){            if(SELLI==1){      
2761          sel_tree->GetEntry(iev);          sel_tree->GetEntry(iev);// read irunt from SelectionList
2762          if(irun != oldrun){          irun = irunt + irunoffset[sel_tree->GetTreeNumber()];//NEWNEW
2763              run_tree->GetEntry(irun);          if(irun != oldrun ){
2764              cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;              if( irun < run_tree->GetEntries() )run_tree->GetEntry(irun);
2765                // check if the time is ok (with merged files it is not...)
2766                // if not loop over run and look for the proper entry
2767                bool SECONDO_GIRO=false;
2768                //      Long64_t irun_start   = irun;
2769                int      offset_start = irunoffset[sel_tree->GetTreeNumber()];
2770                while (
2771                    (
2772                        (
2773                            !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
2774                              abstime <= GetRunInfo()->RUNTRAILER_TIME)
2775    //                      ||
2776    //                      !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
2777    //                        obt <= GetRunInfo()->RUNTRAILER_OBT)
2778                            )
2779                        || GetRunInfo()->NEVENTS==0
2780                        )
2781    //              && irun < run_tree->GetEntries()
2782                    ){
2783    
2784                    if(DBG){
2785                        cout << " (test) ";
2786                        cout << " tree "<<sel_tree->GetTreeNumber();
2787                        cout << " irunt "<<irunt;
2788                        cout << " offset "<<irunoffset[sel_tree->GetTreeNumber()];
2789                        cout << " abs "<<abstime;
2790                        cout <<" >> "<<GetRunInfo()->RUNHEADER_TIME<<" "<<GetRunInfo()->RUNTRAILER_TIME;
2791                        cout << " obt "<<obt;
2792                        cout <<" >> "<<GetRunInfo()->RUNHEADER_OBT<<" "<<GetRunInfo()->RUNTRAILER_OBT;
2793                        cout << " *** JUMP RUN *** irun "<<irun;
2794    //              if(!SECONDO_GIRO)cout << " (don't worry)";
2795    //              else             cout << " (start worring...)";
2796                        cout << endl;
2797                    }
2798    //              irun++;
2799                    irunoffset[sel_tree->GetTreeNumber()]++;
2800                    irun = irunt + irunoffset[sel_tree->GetTreeNumber()];//NEWNEW          
2801                    if(irun == run_tree->GetEntries() && SECONDO_GIRO){
2802    //              if(irun == irun_start ){
2803                        cout << " ...grrrvzzkhhhajsdkj!!!! "<<endl;
2804                        irunoffset[sel_tree->GetTreeNumber()] = offset_start;
2805                        return false;
2806                    }
2807                    if( irun >= run_tree->GetEntries() || irun < 0){
2808                        cout << "irun = "<<irun<<" >>  search from the beginning... <<"<<endl;
2809                        SECONDO_GIRO=true;
2810                        irun=0;
2811                        irunoffset[sel_tree->GetTreeNumber()]=-irunt;
2812                    }
2813                    run_tree->GetEntry(irun);
2814                }
2815    
2816    
2817                if(DBG){
2818                    cout << " (test) ";
2819                    cout << " tree "<<sel_tree->GetTreeNumber();
2820                    cout << " irunt "<<irunt;
2821                    cout << " offset "<<irunoffset[sel_tree->GetTreeNumber()];
2822                    cout << " abs "<<abstime;
2823                    cout <<" >> "<<GetRunInfo()->RUNHEADER_TIME<<" "<<GetRunInfo()->RUNTRAILER_TIME;
2824                    cout << " obt "<<obt;
2825                    cout <<" >> "<<GetRunInfo()->RUNHEADER_OBT<<" "<<GetRunInfo()->RUNTRAILER_OBT;
2826                }
2827                cout << endl;
2828                cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" (run-entry "<<irun<<")"<<endl;
2829    //          cout << endl;
2830              prevshift = 0;              prevshift = 0;
2831              return true;              return true;
2832          }          }
# Line 2761  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2842  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2842   * @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
2843   */   */
2844  Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev){  Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev){
2845    return(UpdateRunInfo((TChain*)run,iev));      return(UpdateRunInfo((TChain*)run,iev));
2846  };  };
2847    
2848  //--------------------------------------  //--------------------------------------
# Line 2771  Bool_t PamLevel2::UpdateRunInfo(TTree *r Line 2852  Bool_t PamLevel2::UpdateRunInfo(TTree *r
2852  /**  /**
2853   * Set which trees shoul be analysed   * Set which trees shoul be analysed
2854   * @param detlist TString containing the sequence of trees required   * @param detlist TString containing the sequence of trees required
2855  */   */
2856  void PamLevel2::SetWhichTrees(TString detlist){  void PamLevel2::SetWhichTrees(TString detlist){
2857            
2858  //    if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){  //    if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){
2859      if( detlist.Contains("+ALL", TString::kIgnoreCase)){      if( detlist.Contains("+ALL", TString::kIgnoreCase)){
2860    
2861          cout << " ======================================================== "<<endl;          cout << " ======================================================== "<<endl;
2862          cout << "                       (( WARNING ))                      "<< endl;          cout << "                       (( WARNING ))                      "<<endl;
2863          cout << " The meaning of the option +ALL has changed!!             "<<endl;          cout << " The meaning of the option +ALL has changed!!             "<<endl;
2864          cout << " Now it includes really all (level0+level1+level2+gpamela)"<<endl;          cout << " Now it includes really all (level0+level1+level2+gpamela)"<<endl;
2865          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;
2866          cout << " trees or level0 files are not available!!                "<<endl;          cout << " all trees or  if level0 files are not available!!        "<<endl;
2867          cout << " ======================================================== "<<endl;          cout << " ======================================================== "<<endl;
2868                            
2869          CAL0 = true;          CAL0 = true;
# Line 2892  void PamLevel2::SetWhichTrees(TString de Line 2973  void PamLevel2::SetWhichTrees(TString de
2973      if( detlist.Contains("-GP", TString::kIgnoreCase) )GP = false;      if( detlist.Contains("-GP", TString::kIgnoreCase) )GP = false;
2974      else if( detlist.Contains("+GP", TString::kIgnoreCase) )GP = true;      else if( detlist.Contains("+GP", TString::kIgnoreCase) )GP = true;
2975    
2976      cout<< "Set detector list from input --> ";      cout<< "tree/branch list from input --> ";
2977      if(TRK0)cout<<"TRK0 ";      if(TRK0)cout<<"TRK0 ";
2978      if(TRK1)cout<<"TRK1 ";      if(TRK1)cout<<"TRK1 ";
2979      if(TRK2)cout<<"TRK2 ";      if(TRK2)cout<<"TRK2 ";
# Line 2952  void  PamLevel2::GetWhichTrees(TFile* f) Line 3033  void  PamLevel2::GetWhichTrees(TFile* f)
3033            
3034      RUN    = false;      RUN    = false;
3035                    
3036      cout << "Checking file: "<<f->GetName()<<endl;  //    cout << "Checking file: "<<f->GetName()<<endl;
3037      if( !f || f->IsZombie() ){      if( !f || f->IsZombie() ){
3038          cout << "File: "<< f->GetName() <<" Non valid root file"<< endl;          cout << "File: "<< f->GetName() <<" Non valid root file"<< endl;
3039          return;          return;
# Line 3071  void  PamLevel2::GetWhichTrees(TFile* f) Line 3152  void  PamLevel2::GetWhichTrees(TFile* f)
3152            
3153  //    delete lk;  //    delete lk;
3154    
3155      cout<< "Get detector list from input file --> ";      cout<< "tree/branch list from file  --> ";
3156      if(TRK1)cout<<"TRK1 ";      if(TRK1)cout<<"TRK1 ";
3157      if(TRK2)cout<<"TRK2 ";      if(TRK2)cout<<"TRK2 ";
3158      if(TRKh)cout<<"TRKH ";      if(TRKh)cout<<"TRKH ";
# Line 3119  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3200  Bool_t  PamLevel2::CheckLevel2File(TStri
3200            
3201      Bool_t SELLI__ok  = false;      Bool_t SELLI__ok  = false;
3202    
3203      cout << "Checking file: "<<name<<endl;  //    cout << "Checking file: "<<name<<endl;
3204      TFile *f = new TFile(name.Data());      TFile *f = new TFile(name.Data());
3205      if( !f || f->IsZombie() ){      if( !f || f->IsZombie() ){
3206          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 3408  Bool_t  PamLevel2::CheckLevel2File(TStri
3408    
3409    
3410      if(!RUN__ok) {      if(!RUN__ok) {
3411          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;
3412  //      return false;          RUN = false;
3413      };      };
3414    
3415      if(CAL1 && !CAL1__ok){      if(CAL1 && !CAL1__ok){
# Line 3451  void PamLevel2::CreateCloneTrees(TFile * Line 3532  void PamLevel2::CreateCloneTrees(TFile *
3532    
3533    
3534  //  if the pointer is null, create a default file  //  if the pointer is null, create a default file
3535        if(!run_tree)return;
3536    
3537      if(!ofile){      if(!ofile){
3538          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 3553  void PamLevel2::CreateCloneTrees(TFile *
3553      // ------------------      // ------------------
3554      // replicate run tree      // replicate run tree
3555      // ------------------      // ------------------
3556      cout << "----------------------------------------------------"<<endl;  //    cout << "----------------------------------------------------"<<endl;
3557      cout << "irun\t | RUN\t NEVENTS\t absolute time"<<endl;  //    cout << "irun\t | RUN\t NEVENTS\t absolute time"<<endl;
3558      for (Int_t i=0; i<run_tree->GetEntries(); i++){      for (Int_t i=0; i<run_tree->GetEntries(); i++){
3559          run_tree->GetEntry(i);          run_tree->GetEntry(i);
3560          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;
3561          run_tree_clone->Fill();          run_tree_clone->Fill();
3562      }      }
3563      cout << "----------------------------------------------------"<<endl;      cout << "----------------------------------------------------"<<endl;
# Line 3488  void PamLevel2::CreateCloneTrees(TFile * Line 3570  void PamLevel2::CreateCloneTrees(TFile *
3570    
3571    
3572      sel_tree_clone = new TTree("SelectionList","List of selected events ");      sel_tree_clone = new TTree("SelectionList","List of selected events ");
3573      sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");  //    sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");
3574        sel_tree_clone->Branch("RunEntry",&irunt,"runentry/L");//NEWNEW
3575      sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/L");      sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/L");
3576            
3577    
# Line 3666  Int_t PamLevel2::GetEntry(Long64_t iee){ Line 3749  Int_t PamLevel2::GetEntry(Long64_t iee){
3749          return 0;          return 0;
3750      }      }
3751    
 //    cout << " gp_obj->P0 "<<gp_obj->P0<<endl;  
3752      //      //
3753      // ... 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.
3754      // 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
3755      // a problem if you don't check the return code of getentry.      // a problem if you don't check the return code of getentry.
3756      //      //
3757      if(!run_tree ){      if(!RUN || !run_tree ){
3758          if ( TRK0 || CAL0 || TOF0 || RUN ) { //forse cosi` va bene per tornare 1?          if ( TRK0 || CAL0 || TOF0 || RUN ) { //forse cosi` va bene per tornare 1?
3759              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;
3760              return 0;              return 0;
# Line 3757  TTree* PamLevel2::GetYodaTree( ){ Line 3839  TTree* PamLevel2::GetYodaTree( ){
3839          // open the DB connection          // open the DB connection
3840          // (if not already opened)          // (if not already opened)
3841          //===================================          //===================================
3842          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;  
         }  
3843          GL_ROOT glroot = GL_ROOT();          GL_ROOT glroot = GL_ROOT();
3844          if( glroot.Query_GL_ROOT(iroot,dbc) ){          if( glroot.Query_GL_ROOT(iroot,dbc) ){
3845              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 3887  TTree* PamLevel2::GetYodaTree( ){
3887              cout << "PamLevel2::GetYodaTree() --- level0 TOF not implemented "<<endl;              cout << "PamLevel2::GetYodaTree() --- level0 TOF not implemented "<<endl;
3888          }          }
3889    
3890          dbc->Close();          dbc->Close(); // EMILIANO, do not leave open connections, open only when needed
3891    
3892    
3893      };      };
# Line 3832  TTree* PamLevel2::GetYodaTree( ){ Line 3901  TTree* PamLevel2::GetYodaTree( ){
3901          if( !TrkParams::IsLoaded(6) ){          if( !TrkParams::IsLoaded(6) ){
3902              cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- VK-mask not loaded"<<endl;              cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- VK-mask not loaded"<<endl;
3903          };          };
3904            if(!dbc || (dbc && !dbc->IsConnected()))SetDBConnection();
3905          TrkParams::SetCalib(run_obj,dbc);          TrkParams::SetCalib(run_obj,dbc);
3906          TrkParams::LoadCalib( );          TrkParams::LoadCalib( );
3907          if( !TrkParams::CalibIsLoaded() ){          if( !TrkParams::CalibIsLoaded() ){
3908              cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- Calibration not loaded"<<endl;              cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- Calibration not loaded"<<endl;
3909          };          };
3910            dbc->Close(); // EMILIANO, do not leave open connections, open only when needed
3911      }      }
3912    
3913    
# Line 3930  Int_t PamLevel2::GetYodaEntry(){ Line 4001  Int_t PamLevel2::GetYodaEntry(){
4001  //      printf(" IDRUN %u \n",GetRunInfo()->ID);  //      printf(" IDRUN %u \n",GetRunInfo()->ID);
4002  //  //
4003          if ( prevshift != 0 && (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() ){          if ( prevshift != 0 && (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() ){
4004            prevshift = 0;              prevshift = 0;
4005            shift = -1;              shift = -1;
4006          };          };
4007    
4008      }while( ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) ||      }while( ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) ||
# Line 3954  Int_t PamLevel2::GetYodaEntry(){ Line 4025  Int_t PamLevel2::GetYodaEntry(){
4025   */   */
4026  Bool_t PamLevel2::SetDBConnection(){  Bool_t PamLevel2::SetDBConnection(){
4027    
4028      cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;      if(DBG){
4029      cout<<"Connecting to DB"<<endl;          cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
4030      cout<<"HOST "<<host<<endl;          cout<<"Connecting to DB"<<endl;
4031      cout<<"USER "<<user<<endl;          cout<<"HOST "<<host<<endl;
4032      cout<<"PSW  "<<psw<<endl;          cout<<"USER "<<user<<endl;
4033            cout<<"PSW  "<<psw<<endl;
4034        }
4035      dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());      dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
4036      if( !dbc )return false;      if( !dbc )return false;
4037      if( !dbc->IsConnected() )return false;          if( !dbc->IsConnected() )return false;    
4038      cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;      stringstream myquery;  // EMILIANO
4039        myquery.str("");  // EMILIANO
4040        myquery << "SET time_zone='+0:00'";  // EMILIANO
4041        dbc->Query(myquery.str().c_str());  // EMILIANO
4042        if(DBG)cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
4043      return true;      return true;
4044    
4045  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.23