/[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.76 by mocchiut, Thu Jan 29 10:00:55 2009 UTC
# Line 284  PamTrack::PamTrack(){ Line 284  PamTrack::PamTrack(){
284      trk_track  = 0;      trk_track  = 0;
285      calo_track = 0;      calo_track = 0;
286      tof_track  = 0;      tof_track  = 0;
287        orb_track  = 0;
288      candeleteobj = 0;      candeleteobj = 0;
289      pscore = 0;      pscore = 0;
290      iscore = 0;      iscore = 0;
# Line 295  PamTrack::PamTrack(){ Line 296  PamTrack::PamTrack(){
296  /**  /**
297   * Constructor   * Constructor
298   */   */
299  PamTrack::PamTrack(TrkTrack* t, CaloTrkVar* c, ToFTrkVar* o){  PamTrack::PamTrack(TrkTrack* t, CaloTrkVar* c, ToFTrkVar* o, OrbitalInfoTrkVar *r){
300    
301      trk_track  = 0;      trk_track  = 0;
302      calo_track = 0;      calo_track = 0;
303      tof_track  = 0;      tof_track  = 0;
304        orb_track  = 0;
305  //     if(t)trk_track  = new TrkTrack(*t);  //     if(t)trk_track  = new TrkTrack(*t);
306  //     if(c)calo_track = new CaloTrkVar(*c);  //     if(c)calo_track = new CaloTrkVar(*c);
307  //     if(o)tof_track  = new ToFTrkVar(*o);  //     if(o)tof_track  = new ToFTrkVar(*o);
308      if(t)trk_track  = t;      if(t)trk_track  = t;
309      if(c)calo_track = c;      if(c)calo_track = c;
310      if(o)tof_track  = o;      if(o)tof_track  = o;
311      candeleteobj = 0;      if(r) orb_track  = r;
312    
313       candeleteobj = 0;
314    
315  };  };
316  PamTrack::PamTrack(const PamTrack& track){  PamTrack::PamTrack(const PamTrack& track){
# Line 314  PamTrack::PamTrack(const PamTrack& track Line 318  PamTrack::PamTrack(const PamTrack& track
318      TrkTrack   *t = track.trk_track;      TrkTrack   *t = track.trk_track;
319      CaloTrkVar *c = track.calo_track;      CaloTrkVar *c = track.calo_track;
320      ToFTrkVar  *o = track.tof_track;      ToFTrkVar  *o = track.tof_track;
321        OrbitalInfoTrkVar  *r = track.orb_track;
322    
323      trk_track  = 0;      trk_track  = 0;
324      calo_track = 0;      calo_track = 0;
325      tof_track  = 0;      tof_track  = 0;
326        orb_track  = 0;
327      if(t)trk_track  = new TrkTrack(*t);      if(t)trk_track  = new TrkTrack(*t);
328      if(c)calo_track = new CaloTrkVar(*c);      if(c)calo_track = new CaloTrkVar(*c);
329      if(o)tof_track  = new ToFTrkVar(*o);      if(o)tof_track  = new ToFTrkVar(*o);
330        if(r)orb_track  = new OrbitalInfoTrkVar(*r);
331      candeleteobj = 1;      candeleteobj = 1;
332            
333  }  }
# Line 331  void PamTrack::Clear(){ Line 338  void PamTrack::Clear(){
338          if(trk_track)  trk_track->TrkTrack::Clear();          if(trk_track)  trk_track->TrkTrack::Clear();
339          if(calo_track) calo_track->CaloTrkVar::Clear();//???          if(calo_track) calo_track->CaloTrkVar::Clear();//???
340          if(tof_track)  tof_track->ToFTrkVar::Clear();//???          if(tof_track)  tof_track->ToFTrkVar::Clear();//???
341            if(orb_track)  orb_track->OrbitalInfoTrkVar::Clear();//???
342      }else{      }else{
343          trk_track  = 0;          trk_track  = 0;
344          calo_track = 0;          calo_track = 0;
345          tof_track  = 0;          tof_track  = 0;
346            orb_track  = 0;
347      }      }
348      pscore = 0;      pscore = 0;
349      iscore = 0;      iscore = 0;
# Line 355  void PamTrack::Delete(){ Line 364  void PamTrack::Delete(){
364              tof_track->ToFTrkVar::Clear();//???              tof_track->ToFTrkVar::Clear();//???
365              delete tof_track;              delete tof_track;
366          }          }
367            if(orb_track){
368                orb_track->OrbitalInfoTrkVar::Clear();//???
369                delete orb_track;
370            }
371      }else{      }else{
372          Clear();          Clear();
373      }      }
# Line 367  void PamTrack::Delete(){ Line 380  void PamTrack::Delete(){
380   * Default Constructor   * Default Constructor
381   */   */
382  PamLevel2::PamLevel2(){  PamLevel2::PamLevel2(){
383    Initialize();      Initialize();
384  };  };
385    
386  /**  /**
# Line 385  PamLevel2::PamLevel2(){ Line 398  PamLevel2::PamLevel2(){
398   * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB   * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB
399   */   */
400  PamLevel2::PamLevel2(TString ddir,TString list,TString detlist){  PamLevel2::PamLevel2(TString ddir,TString list,TString detlist){
401    Initialize();      Initialize();
402    GetPamTree(GetListOfLevel2Files(ddir,list),detlist);      TList*  listf = GetListOfLevel2Files(ddir,list);
403    GetRunTree(GetListOfLevel2Files(ddir,list));      GetPamTree(listf,detlist);
404        GetRunTree(listf);
405  };  };
406    
407    PamLevel2::PamLevel2(TString ddir,TList *list,TString detlist){
408        Initialize();
409        GetPamTree(list,detlist);
410        GetRunTree(list);
411    };
412  /**  /**
413   * Constructor   * Constructor
414   * @param ddir Name of directory where level2 files are stored.   * @param ddir Name of directory where level2 files are stored.
# Line 398  PamLevel2::PamLevel2(TString ddir,TStrin Line 417  PamLevel2::PamLevel2(TString ddir,TStrin
417   * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB   * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB
418   */   */
419  PamLevel2::PamLevel2(TString ddir,TString list){  PamLevel2::PamLevel2(TString ddir,TString list){
420    Initialize();      Initialize();
421    GetPamTree(GetListOfLevel2Files(ddir,list),"");      TList*  listf = GetListOfLevel2Files(ddir,list);
422    GetRunTree(GetListOfLevel2Files(ddir,list));      GetPamTree(listf,"");
423        GetRunTree(listf);
424  };  };
425    
426    
# Line 426  void PamLevel2::Initialize(){ Line 446  void PamLevel2::Initialize(){
446      run_obj   = 0;//new GL_RUN();      run_obj   = 0;//new GL_RUN();
447      soft_obj   = 0;// Emiliano      soft_obj   = 0;// Emiliano
448      irun = -1LL;      irun = -1LL;
449        irunt = -1LL;
450      runfirstentry = 0LL;      runfirstentry = 0LL;
451      runlastentry = 0LL;      runlastentry = 0LL;
452        gltsync = 0; // Emiliano
453    
454      l0_file = NULL;      l0_file = NULL;
455      l0_tree = NULL;      l0_tree = NULL;
# Line 448  void PamLevel2::Initialize(){ Line 470  void PamLevel2::Initialize(){
470    
471      totdltime[0] = 0LL;      totdltime[0] = 0LL;
472      totdltime[1] = 0LL;      totdltime[1] = 0LL;
473        totdltime[2] = 0LL;
474    
475      host = "mysql://localhost/pamelaprod";      host = "mysql://localhost/pamelaprod";
476      user = "anonymous";      user = "anonymous";
# Line 488  void PamLevel2::Initialize(){ Line 511  void PamLevel2::Initialize(){
511    
512      ISGP = false;      ISGP = false;
513    
514        DBG = false;
515    
516      tsorted=0;      tsorted=0;
517      timage=0;      timage=0;
518            
# Line 534  void PamLevel2::Delete(){ Line 559  void PamLevel2::Delete(){
559          dbc->Close();          dbc->Close();
560          delete dbc;          delete dbc;
561      }      }
562    
563        if ( gltsync ) delete gltsync;
564            
565      if(l0_file)l0_file->Close();      if(l0_file)l0_file->Close();
566      //    if(pam_tree)pam_tree->Delete();;      //    if(pam_tree)pam_tree->Delete();;
567    
568    if ( pam_tree ){      if ( pam_tree ){
569      //          //
570      // 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...
571      //          //
572      TList *temp = pam_tree->GetListOfFriends();          TList *temp = pam_tree->GetListOfFriends();
573      TList *contents  = new TList; // create chain friend list          TList *contents  = new TList; // create chain friend list
574      contents->SetOwner();          contents->SetOwner();
575      TIter next(temp);          TIter next(temp);
576      TChain *questo = 0;          TChain *questo = 0;
577      while ( (questo = (TChain*) next()) ){          while ( (questo = (TChain*) next()) ){
578        TString name =  questo->GetName();              TString name =  questo->GetName();
579        contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list              contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list
580      };          };
581      //          //
582      // deleting the main chain          // deleting the main chain
583      //          //
584      pam_tree->Delete();          pam_tree->Delete();
585      //          //
586      // deleting the friends...          // deleting the friends...
587      //          //
588      TIter next2(contents);          TIter next2(contents);
589      TChain *questa = 0;          TChain *questa = 0;
590      while ( questa = (TChain*)next2() ){          while ( questa = (TChain*)next2() ){
591        TString name =  questa->GetName();              TString name =  questa->GetName();
592        questa->Delete();                    questa->Delete();      
593        questa=NULL;              questa=NULL;
594            };
595            //
596      };      };
597      //      pam_tree = NULL;
   };  
   pam_tree = NULL;  
598    
599      if(run_tree)run_tree->Delete();;      if(run_tree)run_tree->Delete();;
600      if(sel_tree)sel_tree->Delete();;      if(sel_tree)sel_tree->Delete();;
# Line 575  void PamLevel2::Delete(){ Line 602  void PamLevel2::Delete(){
602      if(run_tree_clone)run_tree_clone->Delete();;      if(run_tree_clone)run_tree_clone->Delete();;
603      if(sel_tree_clone)sel_tree_clone->Delete();;      if(sel_tree_clone)sel_tree_clone->Delete();;
604            
605        if(irunoffset) delete [] irunoffset;
606    
607  };  };
608    
# Line 621  void PamLevel2::Clear(){ Line 649  void PamLevel2::Clear(){
649  };  };
650    
651  void PamLevel2::Reset(){  void PamLevel2::Reset(){
   //  
   // First of all clear everything  
   //  
   Clear();  
   //  
   // close and reset chains and pointers  
   //      
   if ( pam_tree ){  
652      //      //
653      // 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
654      //      //
655      TList *temp = pam_tree->GetListOfFriends();      Clear();
656      TList *contents  = new TList; // create chain friend list      //
657      contents->SetOwner();      // close and reset chains and pointers
658      TIter next(temp);      //    
659      TChain *questo = 0;      if ( pam_tree ){
660      while ( (questo = (TChain*) next()) ){          //
661        TString name =  questo->GetName();          // we have first to find which chains we have to delete, then delete the main chain and only after delete the friend chains. Any other order causes a segfault...
662        contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list          //
663            TList *temp = pam_tree->GetListOfFriends();
664            TList *contents  = new TList; // create chain friend list
665            contents->SetOwner();
666            TIter next(temp);
667            TChain *questo = 0;
668            while ( (questo = (TChain*) next()) ){
669                TString name =  questo->GetName();
670                contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list
671            };
672            //
673            // deleting the main chain
674            //
675            pam_tree->Delete();
676            //
677            // deleting the friends...
678            //
679            TIter next2(contents);
680            TChain *questa = 0;
681            while ( questa = (TChain*)next2() ){
682                TString name =  questa->GetName();
683                questa->Delete();      
684                questa=NULL;
685            };
686            //
687      };      };
688        pam_tree = NULL;
689      //      //
690      // deleting the main chain      if(run_tree)run_tree->Delete();;
691        run_tree = NULL;
692        if(sel_tree)sel_tree->Delete();;
693        sel_tree = NULL;
694      //      //
695      pam_tree->Delete();      // Close file
696      //      //
697      // deleting the friends...      if(l0_file)l0_file->Close("R");
698        l0_file = NULL;
699      //      //
700      TIter next2(contents);      h0_obj    = 0;
701      TChain *questa = 0;      trk0_obj  = 0;
702      while ( questa = (TChain*)next2() ){      calo0_obj  = 0;
703        TString name =  questa->GetName();      //
704        questa->Delete();            trk2_obj  = 0;
705        questa=NULL;      trk1_obj  = 0;
706      };      trkh_obj  = 0;
707        calo1_obj = 0;
708        calo2_obj = 0;
709        tof_obj   = 0;
710        trig_obj  = 0;
711        s4_obj    = 0;
712        nd_obj    = 0;
713        ac_obj    = 0;
714        orb_obj   = 0;
715        gp_obj    = 0;
716        //
717        // Reset run pointers
718        //
719        run_obj   = 0;//new GL_RUN();
720        soft_obj   = 0;// Emiliano
721        irun = -1;
722        irunt = -1;
723        runfirstentry = 0ULL;
724        runlastentry = 0ULL;    
725        //
726        totdltime[0] = 0LL;
727        totdltime[1] = 0LL;
728        totdltime[2] = 0LL;
729      //      //
   };  
   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;  
   //  
730  };  };
731    
732  Bool_t PamLevel2::IsGood(){  Bool_t PamLevel2::IsGood(Bool_t strict){
733    Bool_t goodev=true;    Bool_t goodev=true;
734    //  if(trk2_obj && trk2_obj->UnpackError() != 0 ) goodev = false;    //
735    if(calo2_obj && calo2_obj->good != 1) goodev = false;    if(calo2_obj && !calo2_obj->IsGood(strict) ) goodev = false;
736    if(tof_obj && tof_obj->unpackError != 0) goodev = false;      //
737    if(trig_obj && trig_obj->unpackError != 0) goodev = false;    if ( strict ){
738    if(s4_obj && s4_obj->unpackError != 0) goodev = false;        if(trk2_obj && trk2_obj->UnpackError() != 0 ) goodev = false;
739    if(nd_obj && nd_obj->unpackError != 0) goodev = false;        if(tof_obj && tof_obj->unpackError != 0) goodev = false;  
740    if(ac_obj && ac_obj->unpackError != 255) goodev = false;        if(trig_obj && trig_obj->unpackError != 0) goodev = false;
741        if(s4_obj && s4_obj->unpackError != 0) goodev = false;  
742        if(nd_obj && nd_obj->unpackError != 0) goodev = false;  
743        if(ac_obj && (ac_obj->unpackError != 0 || ((ac_obj->status[0]>>2)&1) || ((ac_obj->status[1]>>2)&1)) ) goodev = false;      
744      //  if(orb_obj)        //  if(orb_obj)  
745    return goodev;    } else {
746        if(nd_obj && nd_obj->unpackError != 0) goodev = false;  
747        if(ac_obj && (ac_obj->unpackError != 0 || ((ac_obj->status[0]>>2)&1) || ((ac_obj->status[1]>>2)&1)) ) goodev = false;      
748      };
749      return(goodev);
750  };  };
751    
752  //--------------------------------------  //--------------------------------------
# Line 735  void *PamLevel2::GetPointerTo(const char Line 772  void *PamLevel2::GetPointerTo(const char
772          return &trk2_obj;          return &trk2_obj;
773      };      };
774      if(!objname.CompareTo("TrkHough"))   {      if(!objname.CompareTo("TrkHough"))   {
775          if(!trkh_obj)  trkh_obj  = new TrkHough();          if(!trkh_obj)  {
776                trkh_obj  = new TrkHough();
777                trkh_obj->Set();
778            }
779          return &trkh_obj;          return &trkh_obj;
780      };      };
781      if(!objname.CompareTo("CaloLevel1")) {      if(!objname.CompareTo("CaloLevel1")) {
# Line 772  void *PamLevel2::GetPointerTo(const char Line 812  void *PamLevel2::GetPointerTo(const char
812          if(!ac_obj)    ac_obj    = new AcLevel2();          if(!ac_obj)    ac_obj    = new AcLevel2();
813          return &ac_obj;          return &ac_obj;
814      };      };
815      if(!objname.CompareTo("OrbitalInfo")){      if(!objname.CompareTo("OrbitalInfo"))  {
816          if(!orb_obj)   orb_obj   = new OrbitalInfo();          if(!orb_obj){
817                orb_obj   = new OrbitalInfo();
818                orb_obj->Set();
819            }
820          return &orb_obj;          return &orb_obj;
821      };      };
822    //     if(!objname.CompareTo("OrbitalInfo")){
823    //      if(!orb_obj)   orb_obj   = new OrbitalInfo();
824    //      return &orb_obj;
825    //     };
826      if(!objname.CompareTo("GPamela")){      if(!objname.CompareTo("GPamela")){
827          if(!gp_obj)   gp_obj   = new GPamela();          if(!gp_obj)   gp_obj   = new GPamela();
828          return &gp_obj;          return &gp_obj;
# Line 795  void *PamLevel2::GetPointerTo(const char Line 842  void *PamLevel2::GetPointerTo(const char
842   * Retrieves the calorimeter track matching the seqno-th tracker stored track.   * Retrieves the calorimeter track matching the seqno-th tracker stored track.
843   * (If seqno = -1 retrieves the self-trigger calorimeter track)   * (If seqno = -1 retrieves the self-trigger calorimeter track)
844   */   */
845   CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){  CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){
846        
847        if( !calo2_obj )return 0;
848    
849        if( calo2_obj->CaloLevel2::ntrk()==0 ){
850            cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<<endl;
851            return NULL;
852        };
853        
854        CaloTrkVar *c = 0;
855        Int_t it_calo=0;
856        
857        do{
858            c = calo2_obj->CaloLevel2::GetCaloTrkVar(it_calo);
859            it_calo++;
860        } while( c && seqno != c->trkseqno && it_calo < calo2_obj->CaloLevel2::ntrk());    
861            
862       if( !calo2_obj )return 0;      if(!c || seqno != c->trkseqno){
863            c = 0;
864            if(seqno!=-1)cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match Calorimeter stored tracks"<<endl;
865        };
866        return c;
867        
868    };
869    //--------------------------------------
870    //
871    //
872    //--------------------------------------
873    /**
874     * Retrieves the ToF track matching the seqno-th tracker stored track.
875     * (If seqno = -1 retrieves the tracker-independent tof track)
876     */
877    ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){
878            
879        if( !tof_obj )return 0;
880    
881       if( calo2_obj->CaloLevel2::ntrk()==0 ){      if( tof_obj->ToFLevel2::ntrk()==0 ){
882           cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<<endl;          cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no ToF tracks are stored"<<endl;
883           return NULL;          return NULL;
884       };      };
885            
886       CaloTrkVar *c = 0;      ToFTrkVar *c = 0;
887       Int_t it_calo=0;      Int_t it_tof=0;
888            
889       do{      do{
890           c = calo2_obj->CaloLevel2::GetCaloTrkVar(it_calo);          c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);
891           it_calo++;          it_tof++;
892       } while( c && seqno != c->trkseqno && it_calo < calo2_obj->CaloLevel2::ntrk());          } while( c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());
893            
894       if(!c || seqno != c->trkseqno){      if(!c || seqno != c->trkseqno){
895           c = 0;          c = 0;
896           if(seqno!=-1)cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match Calorimeter stored tracks"<<endl;          if(seqno!=-1)cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match ToF stored tracks"<<endl;
897       };      };
898       return c;      return c;
899            
900   };  };
901    
902  //--------------------------------------  //--------------------------------------
903   //  //
904   //  //
905  //--------------------------------------  //--------------------------------------
906  /**  /**
907    * Retrieves the ToF track matching the seqno-th tracker stored track.   * Retrieves the OrbitalInfo track matching the seqno-th tracker stored track.
908    * (If seqno = -1 retrieves the tracker-independent tof track)   * (If seqno = -1 retrieves the tracker-independent tof related track)
909   */   */
910   ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){  OrbitalInfoTrkVar *PamLevel2::GetOrbitalInfoStoredTrack(int seqno){
911                    
912       if( !tof_obj )return 0;      if( !orb_obj )return 0;
913    
914    
915       if( tof_obj->ToFLevel2::ntrk()==0 ){      if( orb_obj->OrbitalInfo::ntrk()==0 ){
916           cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no ToF tracks are stored"<<endl;  //       // TRICK BEGIN
917           return NULL;  //       OrbitalInfoTrkVar  *r = new OrbitalInfoTrkVar(); // TEMPORARY TRICK
918       };  //       Int_t nn = 0;
919    //       TClonesArray &tor = *orb_obj->OrbitalInfoTrk;
920    //       for(Int_t nt=0; nt < tof_obj->ToFLevel2::ntrk(); nt++){  
921    //      //
922    //      ToFTrkVar *ptt = tof_obj->ToFLevel2::GetToFTrkVar(nt);
923    //      if ( ptt->trkseqno != -1  ){
924    //        //
925    //        r->trkseqno = ptt->trkseqno;
926    //        //
927    //        r->Eij = 0;  
928    //        //
929    //        r->Sij = 0;
930    //        //        
931    //        r->pitch = -1000.;
932    //        //
933    //        r->cutoff = -1000.;
934    //        //
935    //        new(tor[nn]) OrbitalInfoTrkVar(*r);
936    //        nn++;
937    //        //
938    //        r->Clear();
939    //        //
940    //      };
941    //       };
942    //       delete r;
943    //       OrbitalInfoTrkVar *c = 0;
944    //       c = orb_obj->OrbitalInfo::GetOrbitalInfoTrkVar(0);
945    //       return c;
946    //       //TRICK END
947          cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no OrbitalInfo tracks are stored"<<endl;
948          return NULL;
949        };
950            
951       ToFTrkVar *c = 0;      OrbitalInfoTrkVar *c = 0;
952       Int_t it_tof=0;      Int_t it_tof=0;
953            
954       do{      do{
955           c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);          c = orb_obj->OrbitalInfo::GetOrbitalInfoTrkVar(it_tof);
956           it_tof++;          it_tof++;
957       } while( c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());              } while( c && seqno != c->trkseqno && it_tof < orb_obj->OrbitalInfo::ntrk());      
958            
959       if(!c || seqno != c->trkseqno){      if(!c || seqno != c->trkseqno){
960           c = 0;          c = 0;
961           if(seqno!=-1)cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match ToF stored tracks"<<endl;          if(seqno!=-1)cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match OrbitalInfo stored tracks"<<endl;
962       };      };
963       return c;      return c;
964            
965   };  };
966    
967  //--------------------------------------  //--------------------------------------
968   //  //
969   //  //
970  //--------------------------------------  //--------------------------------------
971  /**  /**
972   * Give the pamela track associated to a tracker track, retrieving related calorimeter and tof track information.   * Give the pamela track associated to a tracker track, retrieving related calorimeter, orbitalinfo and tof track information.
973   */   */
974   PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){  PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){
975            
976       cout <<"PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** "<<endl;      cout <<"PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** "<<endl;
977       cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;      cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;
978    
979       CaloTrkVar *c = 0;      CaloTrkVar *c = 0;
980       ToFTrkVar  *o = 0;      ToFTrkVar  *o = 0;
981        OrbitalInfoTrkVar  *r = 0;
982            
983       if(CAL2) c = GetCaloStoredTrack(t->GetSeqNo());      if(CAL2) c = GetCaloStoredTrack(t->GetSeqNo());
984       if(TOF) o = GetToFStoredTrack(t->GetSeqNo());      if(TOF) o = GetToFStoredTrack(t->GetSeqNo());
985        if(ORB) r = GetOrbitalInfoStoredTrack(t->GetSeqNo());
986            
987  //    if(t && c && o)track = new PamTrack(t,c,o);  //    if(t && c && o)track = new PamTrack(t,c,o);
988       PamTrack *track = new PamTrack(t,c,o);      PamTrack *track = new PamTrack(t,c,o,r);
989            
990       return track;      return track;
991    
992   };  };
993  //--------------------------------------  //--------------------------------------
994  //  //
995  //  //
# Line 889  void *PamLevel2::GetPointerTo(const char Line 1003  void *PamLevel2::GetPointerTo(const char
1003  PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){  PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){
1004            
1005      cout <<"PamLevel2::GetStoredTrack(Int_t itrk) **to-be-updated** "<<endl;      cout <<"PamLevel2::GetStoredTrack(Int_t itrk) **to-be-updated** "<<endl;
1006      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;
1007      cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;      cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;
1008      PamTrack *track = 0;      PamTrack *track = 0;
1009            
# Line 911  PamTrack* PamLevel2::GetStoredTrack(Int_ Line 1025  PamTrack* PamLevel2::GetStoredTrack(Int_
1025  //  //
1026    
1027  /**  /**
1028   * 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.
1029   **/   **/
1030  void PamLevel2::SortTracks(TString how){  void PamLevel2::SortTracks(TString how){
1031    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());
1032    howtosort = how;        howtosort = how;  
1033    SortTracks();      SortTracks();
1034  };  };
1035    
1036  //  //
1037  //--------------------------------------  //--------------------------------------
1038  /**  /**
1039   * Sort physical (tracker) tracks and stores them in the TRefArray (of TrkTrack objects) which pointer is  PamLevel2::sorted_tracks.   * Sort physical (tracker) tracks.
1040   * @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...).
1041   * Sorting cryteria:   * Sorting cryteria:
1042   * TRK: lower chi**2   * TRK: lower chi**2
1043   * CAL: lower Y spatial residual on the first calorimeter plane   * CAL: lower Y spatial residual on the first calorimeter plane
1044   * 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).
1045     * S1: (ask Emiliano)
1046     * S2: (ask Emiliano)
1047     * S3: (ask Emiliano)
1048     * GP: more GP hits
1049   * The default sorting cryterium is "TOF+CAL".   * The default sorting cryterium is "TOF+CAL".
1050   *   *
1051   * 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).
1052   */   */
1053  void PamLevel2::SortTracks(){  void PamLevel2::SortTracks(){
1054    TString how = howtosort;      TString how = howtosort;
1055    
1056    //  cout <<" PamLevel2::SortTracks(TString how) "<<endl;      //  cout <<" PamLevel2::SortTracks(TString how) "<<endl;
1057    if( !trk2_obj ){      if( !trk2_obj ){
1058      cout << "void PamLevel2::SortTracks():  TrkLevel2 not loaded !!!";          cout << "void PamLevel2::SortTracks():  TrkLevel2 not loaded !!!";
1059      return;          return;
1060    };      };
1061    //    cout << "call SortTracs() "<<endl;      //Save current Object count
1062    //Save current Object count      Int_t ObjectNumber = TProcessID::GetObjectCount();
1063    Int_t ObjectNumber = TProcessID::GetObjectCount();  
1064        // create TCloneArrays to store tracks and its images
1065    //    cout << "ObjectNumber  "<<ObjectNumber <<endl;      if(!tsorted)tsorted = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
1066        tsorted->Delete();
1067    //     if(!sorted_tracks)sorted_tracks = new TRefArray();      TClonesArray &ttsorted = *tsorted;
1068    //     sorted_tracks->Clear();  
1069    //    sorted_tracks.Clear();      if(!timage)timage = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
1070        timage->Delete();
1071    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;  
1072    
1073    
1074    
1075    //--------------------------------------------------      //--------------------------------------------------
1076    // retrieve sorting method      // retrieve sorting method
1077    //--------------------------------------------------      //--------------------------------------------------
1078    Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);      Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
1079    Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);      Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
1080    Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);      Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
1081    Bool_t use_S1 = how.Contains("S1", TString::kIgnoreCase);      Bool_t use_S1 = how.Contains("S1", TString::kIgnoreCase);
1082    Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase);      Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase);
1083    Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase);      Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase);
1084        Bool_t use_GP = how.Contains("GP", TString::kIgnoreCase);
1085        
1086    if ( use_TOF ){      if ( use_TOF ){
1087      use_S1 = true;          use_S1 = true;
1088      use_S2 = true;          use_S2 = true;
1089      use_S3 = true;          use_S3 = true;
1090    };      };
1091    if( !CAL2 &&  use_CAL) use_CAL = false;      if( !CAL2 &&  use_CAL) use_CAL = false;
1092    if( !TOF ){      if( !TOF ){
1093      use_TOF = false;          use_TOF = false;
1094      use_S1  = false;          use_S1  = false;
1095      use_S2  = false;          use_S2  = false;
1096      use_S3  = false;          use_S3  = false;
1097    }      }
1098        if( !GP ){
1099    if( !TRK2 ){          use_GP  = false;
1100      //  cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;      }
1101      return;  
1102    };      if( !TRK2 ){
1103            cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;
1104            return;
1105        };
1106    
1107    //   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;
1108        
1109    
1110    //--------------------------------------------------      //--------------------------------------------------
1111    // loop over "physical" tracks sorted by the tracker      // loop over "physical" tracks sorted by the tracker
1112    //--------------------------------------------------      //--------------------------------------------------
1113    for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){      for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){
1114                    
1115      TrkTrack   *ts = 0;          TrkTrack   *ts = 0;
1116      CaloTrkVar *cs = 0;          CaloTrkVar *cs = 0;
1117      ToFTrkVar  *os = 0;          ToFTrkVar  *os = 0;
1118                    OrbitalInfoTrkVar  *rs = 0;
1119      // get tracker tracks          
1120      TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker          // get tracker tracks
1121      CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());          TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker
1122      ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());          CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());
1123            ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());
1124      TrkTrack   *ti = 0; //tracker (image)          OrbitalInfoTrkVar  *rp = GetOrbitalInfoStoredTrack(tp->GetSeqNo());
1125      CaloTrkVar *ci = 0;  
1126      ToFTrkVar  *oi = 0;          TrkTrack   *ti = 0; //tracker (image)
1127      //  cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;          CaloTrkVar *ci = 0;
1128      // if track has an image, check image selection          ToFTrkVar  *oi = 0;
1129            OrbitalInfoTrkVar  *ri = 0;
1130      Int_t tp_score = 0;  //main track sorted by the tracker          //      cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
1131      Int_t ti_score = 0;  //image track          // if track has an image, check image selection
1132      Int_t totp_score = 0;  //main track sorted by the tracker  
1133      Int_t toti_score = 0;  //image track          Int_t tp_score = 0;  //main track sorted by the tracker
1134            Int_t ti_score = 0;  //image track
1135            Int_t totp_score = 0;  //main track sorted by the tracker
1136            Int_t toti_score = 0;  //image track
1137    
1138      if(tp->HasImage()){          if(tp->HasImage()){
1139                            
1140        ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image)              ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image)
1141        ci = GetCaloStoredTrack(ti->GetSeqNo());              ci = GetCaloStoredTrack(ti->GetSeqNo());
1142        oi = GetToFStoredTrack(ti->GetSeqNo());              oi = GetToFStoredTrack(ti->GetSeqNo());
1143                ri = GetOrbitalInfoStoredTrack(ti->GetSeqNo());
1144                            
1145        //            cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;              //      cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;
1146    
1147        //assign starting scores              //assign starting scores
1148        tp_score = 0;  //main track sorted by the tracker              tp_score = 0;  //main track sorted by the tracker
1149        ti_score = 0;  //image track              ti_score = 0;  //image track
1150                            
1151        // -----------------------------------------------------------------------------------------              // -----------------------------------------------------------------------------------------
1152        // calorimeter check              // *****************************************************************************************
1153        // -----------------------------------------------------------------------------------------              // -----------------------------------------------------------------------------------------
1154        // check the Y spatial residual on the first calorimeter plane              // calorimeter check
1155        // (cut on calorimeter variables from Emiliano)              // -----------------------------------------------------------------------------------------
1156        if( use_CAL && !calo2_obj ){              if( use_CAL && !calo2_obj ){
1157          cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but CaloLevel2 not loaded !!!";                  cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but CaloLevel2 not loaded !!!";
1158          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);  
1159              };              };
1160            };              if( use_CAL && !cp &&  ci ){
1161            //                  ti_score++;
1162            tp->DoTrack2(tr);                  toti_score++;
           //  
           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);  
               };  
1163              };              };
1164            };              if( use_CAL &&  cp && !ci ){
1165            if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){                  tp_score++;
1166              for (Int_t ih=0; ih < op->npmtadc; ih++){                  totp_score++;
               Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );  
               if(pl == 3){  
                 nphit_p++;  
                 enhit_p += (op->dedx).At(ih);  
               };  
1167              };              };
1168            };              if(
1169            if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){                  use_CAL            &&
1170              for (Int_t ih=0; ih < op->npmtadc; ih++){                  cp && ci &&
1171                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );                  true){
1172                if(pl == 4){  
1173                  nphit_p++;                  
1174                  enhit_p += (op->dedx).At(ih);                  if(
1175                };                      cp->npresh > ci->npresh &&
1176              };                      true){
1177            };                      tp_score++;
1178                        totp_score++;
1179                    };
1180                    if(
1181                        cp->npresh < ci->npresh &&
1182                        true){
1183                        ti_score++;
1184                        toti_score++;
1185                    };
1186    
1187                    //      cout << "CALO "<<tp_score<<ti_score<<endl;
1188    
           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);  
1189              };              };
1190            };              // -----------------------------------------------------------------------------------------
1191            //              // *****************************************************************************************
1192            ti->DoTrack2(tr);              // -----------------------------------------------------------------------------------------
1193            //              // TOF check
1194            if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){              // -----------------------------------------------------------------------------------------
1195              for (Int_t ih=0; ih < oi->npmtadc; ih++){              // check the number of hit pmts along the track
1196                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );              // on S12 S21 and S32, where paddles are parallel to Y axis
1197                if(pl == 0){              if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !tof_obj ){
1198                  nphit_i++;                  cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but ToFLevel2 not loaded !!!";
1199                  enhit_i += (op->dedx).At(ih);                  return;
               };  
1200              };              };
1201            };              //
1202            if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){              if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !op && oi ){
1203              for (Int_t ih=0; ih < oi->npmtadc; ih++){                  ti_score++;
1204                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );                  toti_score++;
               if(pl == 3){  
                 nphit_i++;  
                 enhit_i += (op->dedx).At(ih);  
               };  
1205              };              };
1206            };              if( (use_TOF || use_S1 || use_S2 || use_S3 ) && op && !oi ){
1207            if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){                  tp_score++;
1208              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);  
               };  
1209              };              };
1210            };                          if( (use_TOF || use_S1 || use_S2 || use_S3 ) && op && oi ){
1211                    //
1212                    Float_t sen = 0.;
1213                    for (Int_t ih=0; ih < op->npmtadc; ih++){
1214                        Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1215                        if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (op->dedx).At(ih);
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 == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (oi->dedx).At(ih);
1220                    };
1221                    //
1222                    if (  sen >= sortthr && false){ // temporary disabled NUCLEI special algorithm since the new one should work for every particle (to be checked!)
1223                        //printf(" IS A NUCLEUS! en = %f \n",sen);
1224                        //
1225                        // is a nucleus use a different algorithm
1226                        //
1227                        Int_t nz = 6; Float_t zin[6];                                          // << define TOF z-coordinates
1228                        for(Int_t ip=0; ip<nz; ip++)
1229                            zin[ip] = tof_obj->ToFLevel2::GetZTOF(tof_obj->ToFLevel2::GetToFPlaneID(ip));     // << read ToF plane z-coordinates
1230                        Trajectory *tr = new Trajectory(nz,zin);
1231                        //
1232                        Int_t nphit_p =0;
1233                        Int_t nphit_i =0;
1234                        Float_t enhit_p = 0.;
1235                        Float_t enhit_i = 0.;
1236                        //
1237                        for (Int_t ih=0; ih < op->npmtadc; ih++){
1238                            Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1239                            if(pl == 1 || pl == 2 || pl == 5){
1240                                nphit_p++;
1241                                enhit_p += (op->dedx).At(ih);
1242                            };
1243                        };
1244                        //
1245                        tp->DoTrack2(tr);
1246                        //
1247                        if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){
1248                            for (Int_t ih=0; ih < op->npmtadc; ih++){
1249                                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1250                                if(pl == 0){
1251                                    nphit_p++;
1252                                    enhit_p += (op->dedx).At(ih);
1253                                };
1254                            };
1255                        };
1256                        if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){
1257                            for (Int_t ih=0; ih < op->npmtadc; ih++){
1258                                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1259                                if(pl == 3){
1260                                    nphit_p++;
1261                                    enhit_p += (op->dedx).At(ih);
1262                                };
1263                            };
1264                        };
1265                        if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
1266                            for (Int_t ih=0; ih < op->npmtadc; ih++){
1267                                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1268                                if(pl == 4){
1269                                    nphit_p++;
1270                                    enhit_p += (op->dedx).At(ih);
1271                                };
1272                            };
1273                        };
1274    
1275                        for (Int_t ih=0; ih < oi->npmtadc; ih++){
1276                            Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1277                            if(pl == 1 || pl == 2 || pl == 5){
1278                                nphit_i++;  
1279                                enhit_i += (op->dedx).At(ih);
1280                            };
1281                        };
1282                        //
1283                        ti->DoTrack2(tr);
1284                        //
1285                        if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){
1286                            for (Int_t ih=0; ih < oi->npmtadc; ih++){
1287                                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1288                                if(pl == 0){
1289                                    nphit_i++;
1290                                    enhit_i += (op->dedx).At(ih);
1291                                };
1292                            };
1293                        };
1294                        if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){
1295                            for (Int_t ih=0; ih < oi->npmtadc; ih++){
1296                                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1297                                if(pl == 3){
1298                                    nphit_i++;
1299                                    enhit_i += (op->dedx).At(ih);
1300                                };
1301                            };
1302                        };
1303                        if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
1304                            for (Int_t ih=0; ih < oi->npmtadc; ih++){
1305                                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1306                                if(pl == 4){
1307                                    nphit_i++;
1308                                    enhit_i += (op->dedx).At(ih);
1309                                };
1310                            };
1311                        };          
1312    
1313                                    
1314            if(                      if(
1315               (use_TOF || use_S1 || use_S2 || use_S3)            &&                          (use_TOF || use_S1 || use_S2 || use_S3)            &&
1316               (nphit_p+nphit_i) !=0 &&                            (nphit_p+nphit_i) !=0 &&        
1317               true){                          true){
1318                                            
1319              //      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);
1320              //      printf(" score p %i score i %i \n",tp_score,ti_score);                          //          printf(" score p %i score i %i \n",tp_score,ti_score);
1321              //            if( enhit_p > enhit_i ) tp_score++;                          //                if( enhit_p > enhit_i ) tp_score++;
1322              //            if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;                          //                if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;
1323              if ( nphit_p > nphit_i ) tp_score++;                          if ( nphit_p > nphit_i ) tp_score++;
1324              if ( nphit_p < nphit_i ) ti_score++;                          if ( nphit_p < nphit_i ) ti_score++;
1325              if ( nphit_p == nphit_i ){                          if ( nphit_p == nphit_i ){
1326                if ( enhit_p > enhit_i ) tp_score++;                              if ( enhit_p > enhit_i ) tp_score++;
1327                else ti_score++;                              else ti_score++;
1328              };                          };
1329              //      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);
1330            };                      };
1331            delete tr;                      delete tr;
1332            //                      //
1333          } else {                  } else {
1334            //                      // -------------
1335            // NOT a NUCLEUS                      // NOT a NUCLEUS
1336            //                      // -------------
1337            //printf(" NOT a NUCLEUS! en = %f \n",sen);                      //printf(" NOT a NUCLEUS! en = %f \n",sen);
1338    
1339            Int_t nphit_p =0;                      Int_t nphit_p =0;
1340            Int_t nphit_i =0;                      Int_t nphit_i =0;
1341                                    
1342                                    
1343            /*                            cout << "track: npmtadc "<< op->npmtadc << endl;                      /*                          cout << "track: npmtadc "<< op->npmtadc << endl;
1344              cout << "track: npmttdc "<< op->npmttdc << endl;                                                  cout << "track: npmttdc "<< op->npmttdc << endl;
1345              cout << "image: npmtadc "<< oi->npmtadc << endl;                                                  cout << "image: npmtadc "<< oi->npmtadc << endl;
1346              cout << "image: npmttdc "<< oi->npmttdc << endl;*/                                                  cout << "image: npmttdc "<< oi->npmttdc << endl;*/
1347                                    
1348  //        for (Int_t ih=0; ih < op->npmtadc; ih++){  //        for (Int_t ih=0; ih < op->npmtadc; ih++){
1349  //          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 1354  void PamLevel2::SortTracks(){
1354  //          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );  //          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1355  //          if(pl == 1 || pl == 2 || pl == 5)nphit_i++;  //          if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
1356  //        };  //        };
1357            // --- modified to count tdc signals (more efficient?)                      // --- modified to count tdc signals (more efficient?)
1358            // --- and to implement check on tdcflag                      // --- and to implement check on tdcflag
1359            for (Int_t ih=0; ih < op->npmttdc; ih++){                      for (Int_t ih=0; ih < op->npmttdc; ih++){
1360              Int_t pl = tof_obj->GetPlaneIndex( (op->pmttdc).At(ih) );                          Int_t pl = tof_obj->GetPlaneIndex( (op->pmttdc).At(ih) );
1361  //          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++;
1362              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 )) ){
1363                if( (op->tdcflag).At(ih)==0 )nphit_p++;                              if( (op->tdcflag).At(ih)==0 )nphit_p++;
1364              };                          };
1365            };                      };
1366                                    
1367            for (Int_t ih=0; ih < oi->npmttdc; ih++){                      for (Int_t ih=0; ih < oi->npmttdc; ih++){
1368              Int_t pl = tof_obj->GetPlaneIndex( (oi->pmttdc).At(ih) );                          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmttdc).At(ih) );
1369  //          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++;  
1370              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 )) ){
1371                if( (oi->tdcflag).At(ih)==0 )nphit_i++;                                if( (oi->tdcflag).At(ih)==0 )nphit_i++;    
1372              };                          };
1373            };                      };
1374                                    
1375            if(                      if(
1376               (nphit_p+nphit_i) !=0 &&                            (nphit_p+nphit_i) !=0 &&        
1377               true){                          true){
1378                                            
1379              if ( nphit_p != nphit_i ){                          if ( nphit_p != nphit_i ){
1380                totp_score += nphit_p;                              totp_score += nphit_p;
1381                toti_score += nphit_i;                              toti_score += nphit_i;
1382                tp_score+=nphit_p;                              tp_score+=nphit_p;
1383                ti_score+=nphit_i;                              ti_score+=nphit_i;
1384                            };
1385                            //          if     ( nphit_p > nphit_i) tp_score+=nphit_p;
1386                            //          else if( nphit_p < nphit_i) ti_score+=nphit_i;
1387                            //          else ;//niente
1388                        };
1389                    };
1390                    //      cout << "TOF "<<tp_score<<ti_score<<endl;
1391              };              };
             //      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;  
       };  
1392    
1393    
1394  //      if(tp_score == ti_score) use_TRK = true;  //      if(tp_score == ti_score) use_TRK = true;
1395    
1396    
1397        // -----------------------------------------------------------------------------------------              // -----------------------------------------------------------------------------------------
1398        // tracker check              // *****************************************************************************************
1399        // -----------------------------------------------------------------------------------------              // -----------------------------------------------------------------------------------------
1400        // chi**2 difference is not always large enough to distinguish among              // tracker check
1401        // the real track and its image.              // -----------------------------------------------------------------------------------------
1402        // Tracker check will be applied always when calorimeter and tof information is ambiguous.              // chi**2 difference is not always large enough to distinguish among
1403        // *** MODIFIED ON AUGUST 2007 ***              // the real track and its image.
1404        if(use_TRK){              // Tracker check will be applied always when calorimeter and tof information is ambiguous.
1405                // *** MODIFIED ON AUGUST 2007 ***
1406                if(use_TRK){
1407  //      if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;  //      if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
1408  //      else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;  //      else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
1409    
1410            // CHECK 1 : number of points along X                    // CHECK 1 : number of points along X  
1411          if ( tp->GetNX() >= ti->GetNX() ){                  if ( tp->GetNX() >= ti->GetNX() ){
1412            tp_score++ ;                      tp_score++ ;
1413            totp_score++ ;                      totp_score++ ;
1414          };                  };
1415          if ( tp->GetNX() <= ti->GetNX() ){                  if ( tp->GetNX() <= ti->GetNX() ){
1416            ti_score++ ;                      ti_score++ ;
1417            toti_score++ ;                      toti_score++ ;
1418          };                  };
1419            // CHECK 2 : number of points along Y                    // CHECK 2 : number of points along Y  
1420          if ( tp->GetNY() >= ti->GetNY() ){                  if ( tp->GetNY() >= ti->GetNY() ){
1421            tp_score++ ;                      tp_score++ ;
1422            totp_score++ ;                      totp_score++ ;
1423          };                  };
1424          if ( tp->GetNY() <= ti->GetNY() ){                  if ( tp->GetNY() <= ti->GetNY() ){
1425            ti_score++ ;                      ti_score++ ;
1426            toti_score++ ;                      toti_score++ ;
1427          };                  };
           // 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++ ;  
1428    
1429          //      cout << "TRK "<<tp_score<<ti_score<<endl;                  //      cout << "TRK "<<tp_score<<ti_score<<endl;
1430        };              };
1431                            
1432    
1433                // -----------------------------------------------------------------------------------------
1434                // *****************************************************************************************
1435                // -----------------------------------------------------------------------------------------
1436                // GPamela check
1437                // -----------------------------------------------------------------------------------------
1438                
1439                //---------------------------------------------------
1440                // count the number of GP hits
1441                //---------------------------------------------------
1442                if(use_GP){
1443                    int ngphits_p=0;
1444                    int ngphits_i=0;
1445                    float toll = 0.02; //200 micron
1446                    for(int ih=0; ih<GetGPamela()->Nthspe; ih++){
1447                        int ip = (Int_t) GetGPamela()->Itrpb[ih] - 1;
1448                        if(
1449                            tp &&
1450                            tp->YGood(ip) &&
1451                            fabs(tp->ym[ip]- GetGPamela()->Yavspe[ih])<toll &&
1452                            true) ngphits_p++;
1453                        if( ti &&
1454                            ti->YGood(ip) &&
1455                            fabs(ti->ym[ip]- GetGPamela()->Yavspe[ih])<toll &&
1456                            true) ngphits_i++;
1457                    }
1458                    if(
1459                        ngphits_p > ngphits_i &&
1460                        true){
1461                        tp_score++ ;
1462                        totp_score++ ;                  
1463                    }
1464                    if(
1465                        ngphits_p < ngphits_i &&
1466                        true){
1467                        ti_score++ ;
1468                        toti_score++ ;                  
1469                    }
1470                }
1471    
       // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*  
       // the winner is....  
       // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*  
       if      (tp_score > ti_score) {  
           
   
       }else if (tp_score < ti_score) {  
1472    
1473                // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1474                // the winner is....
1475                // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1476                if      (tp_score > ti_score) {
1477            
1478    
1479          ts = ti;//its image!!              }else if (tp_score < ti_score) {
         cs = ci;  
         os = oi;  
         Int_t totis = toti_score;  
1480    
         ti = tp;//its image!!  
         ci = cp;  
         oi = op;  
1481    
1482          tp = ts;//its image!!                  ts = ti;//its image!!
1483          cp = cs;                  cs = ci;
1484          op = os;                  os = oi;
1485                    rs = ri;
1486                    Int_t totis = toti_score;
1487    
1488                    ti = tp;//its image!!
1489                    ci = cp;
1490                    oi = op;
1491                    ri = rp;
1492    
1493                    tp = ts;//its image!!
1494                    cp = cs;
1495                    op = os;
1496                    rp = rs;
1497    
1498          toti_score = totp_score;                  toti_score = totp_score;
1499          totp_score = totis;                  totp_score = totis;
1500    
1501                                    
1502        }else {              }else {
1503    
1504  //      cout << "Warning - track image ambiguity not solved" << endl;  //      cout << "Warning - track image ambiguity not solved" << endl;
1505    
1506        };              };
1507                            
1508      }else{          }else{
1509        totp_score = 1;              totp_score = 1;
1510        toti_score = 0;              toti_score = 0;
1511                
1512        //            ts = tp;              //      ts = tp;
1513        //            cs = cp;              //      cs = cp;
1514        //            os = op;              //      os = op;
1515      };          };
1516                    
1517      //  cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;          //      cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
1518      //  sorted_tracks->Add(ts);//save the track in the sorted array          //      sorted_tracks->Add(ts);//save the track in the sorted array
1519      //  sorted_tracks.Add(ts);//save the track in the sorted array          //      sorted_tracks.Add(ts);//save the track in the sorted array
1520      //  sorted_tracks.Add(tp);//save the track in the sorted array          //      sorted_tracks.Add(tp);//save the track in the sorted array
1521      //  cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;          //      cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
1522      //  cout<<"o "<<tp<<endl;          //      cout<<"o "<<tp<<endl;
1523      //  cout<<"o "<<cp<<endl;          //      cout<<"o "<<cp<<endl;
1524      //  cout<<"o "<<op<<endl;          //      cout<<"o "<<op<<endl;
1525    
1526      new(ttsorted[i]) PamTrack(tp,cp,op);          new(ttsorted[i]) PamTrack(tp,cp,op,rp);
1527      new(ttimage[i])  PamTrack(ti,ci,oi);          new(ttimage[i])  PamTrack(ti,ci,oi,ri);
1528    
1529      ((PamTrack*)(ttsorted[i]))->SetPScore(totp_score);          ((PamTrack*)(ttsorted[i]))->SetPScore(totp_score);
1530      ((PamTrack*)(ttsorted[i]))->SetIScore(toti_score);          ((PamTrack*)(ttsorted[i]))->SetIScore(toti_score);
1531      ((PamTrack*)(ttimage[i]))->SetPScore(totp_score);          ((PamTrack*)(ttimage[i]))->SetPScore(totp_score);
1532      ((PamTrack*)(ttimage[i]))->SetIScore(toti_score);          ((PamTrack*)(ttimage[i]))->SetIScore(toti_score);
1533    };      };
1534    
1535    if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){      if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){
1536      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;
1537      tsorted->Delete(); tsorted=0;          tsorted->Delete(); tsorted=0;
1538      timage->Delete(); timage=0;          timage->Delete(); timage=0;    
1539    }      }
1540    
1541    //Restore Object count      //Restore Object count
1542    //To save space in the table keeping track of all referenced objects      //To save space in the table keeping track of all referenced objects
1543    //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.
1544    TProcessID::SetObjectCount(ObjectNumber);      TProcessID::SetObjectCount(ObjectNumber);
1545            
1546  };  };
1547  //--------------------------------------  //--------------------------------------
# Line 1417  TClonesArray *PamLevel2::GetTracks(){ Line 1570  TClonesArray *PamLevel2::GetTracks(){
1570    
1571      return tsorted;      return tsorted;
1572            
1573   };  };
1574  //--------------------------------------  //--------------------------------------
1575   //  //
1576   //  //
1577  //--------------------------------------  //--------------------------------------
1578  /**  /**
1579   * Retrieves the it-th Pamela "physical" track.   * Retrieves the it-th Pamela "physical" track.
# Line 1481  PamTrack *PamLevel2::GetTrack(int it){ Line 1634  PamTrack *PamLevel2::GetTrack(int it){
1634   */   */
1635  PamTrack *PamLevel2::GetTrackImage(int it){  PamTrack *PamLevel2::GetTrackImage(int it){
1636    
 //     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;  
   
   
1637  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1638      SortTracks();      SortTracks();
1639  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
# Line 1552  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1680  TTree *PamLevel2::GetPamTree(TFile *f, T
1680          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 ");
1681          return pam_tree;          return pam_tree;
1682      };      };
1683    //      //
1684    
1685      cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;      cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;
1686    
# Line 1579  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1707  TTree *PamLevel2::GetPamTree(TFile *f, T
1707      if(ORB)cout<<"ORB ";      if(ORB)cout<<"ORB ";
1708      if(GP)cout<<"GP ";      if(GP)cout<<"GP ";
1709      cout << endl;      cout << endl;
1710      if(SELLI)cout<<">>> Found selection-list <<<"<<endl;      if(SELLI && SELLI!=2)cout<<">>> Found selection-list <<<"<<endl; //EMILIANO
1711    
1712      f->cd();      f->cd();
1713    
# Line 1698  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1826  TTree *PamLevel2::GetPamTree(TFile *f, T
1826    
1827      TTree *L = (TTree*)f->Get("SelectionList");      TTree *L = (TTree*)f->Get("SelectionList");
1828      if(L && SELLI==1) {      if(L && SELLI==1) {
1829  //      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;  
1830          sel_tree = 0;          sel_tree = 0;
1831      }else{      }else{
1832          cout << "SelectionList  : missing tree"<<endl;          cout << "SelectionList  : missing tree"<<endl;
# Line 1749  TList*  PamLevel2::GetListOfLevel2Files( Line 1871  TList*  PamLevel2::GetListOfLevel2Files(
1871      //    if(ddir=="")ddir = wdir;      //    if(ddir=="")ddir = wdir;
1872  //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);  //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
1873      if ( ddir != ""){      if ( ddir != ""){
1874        cout << "Level2 data directory : "<<  ddir << endl;          cout << "Level2 data directory : "<<  ddir << endl;
1875      } else {      } else {
1876        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;
1877      };      };
1878      TList *contents  = new TList; // create output list      TList *contents  = new TList; // create output list
1879      contents->SetOwner();      contents->SetOwner();
# Line 1768  TList*  PamLevel2::GetListOfLevel2Files( Line 1890  TList*  PamLevel2::GetListOfLevel2Files(
1890  //          return 0;  //          return 0;
1891  //      }        //      }      
1892  //      flisttxt = fullpath;  //      flisttxt = fullpath;
1893        if ( !flisttxt.EndsWith(".root") ){          if ( !flisttxt.EndsWith(".root") ){
1894    
1895          flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));              flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1896    
1897          if( !gSystem->ChangeDirectory(ddir) ){              if( !gSystem->ChangeDirectory(ddir) ){
1898              cout << "Cannot change directory : "<<ddir<<endl;                  cout << "Cannot change directory : "<<ddir<<endl;
1899              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;  
1900              }              }
1901              if(file.Contains("#"))file = file(0,file.First("#"));          
1902                cout <<"Input file list : " << flisttxt <<endl;
1903                ifstream in;
1904                in.open(flisttxt, ios::in); //open input file list
1905                if(!in.good()){
1906                    cout <<" ERROR opening the file "<<endl;
1907                    gSystem->ChangeDirectory(wdir); // back to the working directory
1908                    return 0;
1909                }  
1910                int line=0;
1911                while (1) {
1912                    TString file;
1913                    in >> file;
1914                    if (!in.good()) break;
1915                    line++;
1916    //          cout <<"(1) " << file << endl;
1917                    if(file.IsNull()){
1918                        cout << "-- list interrupted at line "<<line <<endl;
1919                        break;
1920                    }
1921                    if(file.Contains("#"))file = file(0,file.First("#"));
1922  //          cout <<"(2) " << file << endl;  //          cout <<"(2) " << file << endl;
1923  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){
1924  //          if( (fullpath = gSystem->FindFile(ddir,file)) ){  //          if( (fullpath = gSystem->FindFile(ddir,file)) ){
1925              if( file.EndsWith(".root") ){                  if( file.EndsWith(".root") ){
1926                TString filedir;                      TString filedir;
1927                if (ddir != ""){                      if (ddir != ""){
1928                  filedir = ddir; // take the input dir                          filedir = ddir; // take the input dir
1929                } else {                      } else {
1930                  gSystem->ChangeDirectory(wdir); // back to the working directory                          gSystem->ChangeDirectory(wdir); // back to the working directory
1931                  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
1932                };                      };
1933                  char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir),gSystem->BaseName(file));                      char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir),gSystem->BaseName(file));
1934                  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
1935                  delete fullpath;                      delete fullpath;
1936              }                  }
1937  //          }else{  //          }else{
1938  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;
1939  //          };  //          };
1940          };              };
1941          in.close();              in.close();
1942        } else {          } else {
1943            if(flisttxt.Contains("#"))flisttxt = flisttxt(0,flisttxt.First("#"));              if(flisttxt.Contains("#"))flisttxt = flisttxt(0,flisttxt.First("#"));
1944            char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));              char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1945            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
1946            delete fullpath;              delete fullpath;
1947        };                  };      
1948      }else{      }else{
1949                    
1950          cout << "No input file list given."<<endl;          cout << "No input file list given."<<endl;
1951          cout << "Check for existing root files."<<endl;          cout << "Check for existing root files."<<endl;
1952  //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;  //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;
1953          if ( ddir == "" ){          if ( ddir == "" ){
1954            ddir = wdir;              ddir = wdir;
1955            cout << "Level2 data directory : "<<  ddir << endl;              cout << "Level2 data directory : "<<  ddir << endl;
1956          };          };
1957    
1958          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
# Line 1887  TChain *PamLevel2::GetPamTree(TList *fl, Line 2009  TChain *PamLevel2::GetPamTree(TList *fl,
2009            
2010      TChain *Trout =0;      TChain *Trout =0;
2011    
2012            // -------------------------------------------
2013        // set flags to include/exclude trees/branches
2014        // -------------------------------------------
2015      if( detlist.Contains("+AUTO", TString::kIgnoreCase) ) {      if( detlist.Contains("+AUTO", TString::kIgnoreCase) ) {
2016          if( fl->GetEntries()>0 ){          if( fl->GetEntries()>0 ){
2017              cout << "+AUTO"<<endl;              cout << "+AUTO"<<endl;
2018              TFile *fprimo = new TFile( fl->At(0)->GetName() );              TFile *fprimo = new TFile( fl->At(0)->GetName() );
2019              GetWhichTrees(fprimo);              GetWhichTrees(fprimo);
2020                fprimo->Close();// AAAAARGGGGGHHHHH!!!!!!! non commentare questa riga, altrimenti si incasina il TChain
2021              fprimo->Delete();              fprimo->Delete();
2022          }          }
2023      };      };
2024      SetWhichTrees(detlist);          SetWhichTrees(detlist);    
2025    
2026    
2027        // -------------------------------------------
2028        // build chains
2029        // -------------------------------------------
2030        TChain *T = 0;      
2031        TChain *C = 0;
2032        TChain *O = 0;
2033        TChain *R = 0;
2034        TChain *S = 0;
2035        TChain *N = 0;
2036        TChain *A = 0;
2037        TChain *B = 0;
2038        TChain *G = 0;
2039    
2040  //    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;  
2041            
2042      if(TRK2||TRK1||TRKh) T = new TChain("Tracker");          if(TRK2||TRK1||TRKh) T = new TChain("Tracker");    
2043      if(CAL2||CAL1)       C = new TChain("Calorimeter");      if(CAL2||CAL1)       C = new TChain("Calorimeter");
# Line 1945  TChain *PamLevel2::GetPamTree(TList *fl, Line 2070  TChain *PamLevel2::GetPamTree(TList *fl,
2070          };          };
2071      };      };
2072            
2073      cout << "done chain \n";      cout << "done chains\n";
2074      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2075    
2076  //    UInt_t *found=0;  
2077        // -------------------------------------------
2078        // make friends
2079        // -------------------------------------------
2080    
2081  // Tracker  // Tracker
2082        cout << "Friends: "<<endl;
2083      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;  
2084          if(!Trout)Trout=T;          if(!Trout)Trout=T;
2085          else Trout->AddFriend("Tracker");          else Trout->AddFriend("Tracker");
2086      }else{  //      cout << "+Tacker"<<endl;
 //        cout << "Tracker      : missing tree"<<endl;  
2087      };      };
2088      // Calorimeter      // Calorimeter
2089      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;  
2090          if(!Trout)Trout=C;          if(!Trout)Trout=C;
2091          else Trout->AddFriend("Calorimeter");          else Trout->AddFriend("Calorimeter");
2092      }else{  //      cout << "+Calorimeter"<<endl;
 //        cout << "Calorimeter  : missing tree"<<endl;  
2093      };      };
2094      // ToF          // ToF    
2095      if(O && TOF) {      if(O && TOF) {
 //        O->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));  
 //        cout << "ToF          : set branch address ToFLevel2"<<endl;  
2096          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2097          else Trout->AddFriend("ToF");          else Trout->AddFriend("ToF");
2098      }else{  //      cout << "+ToF"<<endl;
 //        cout << "ToF         : missing tree"<<endl;  
2099      };      };
2100      // Trigger      // Trigger
2101      if(R && TRG) {      if(R && TRG) {
 //        R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));  
 //        cout << "Trigger      : set branch address TrigLevel2"<<endl;  
2102          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2103          else Trout->AddFriend("Trigger");          else Trout->AddFriend("Trigger");
2104      }else{  //      cout << "+Trigger"<<endl;
 //        cout << "Trigger      : missing tree"<<endl;  
2105      };      };
2106      // S4      // S4
2107      if(S && S4) {      if(S && S4) {
 //        S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));  
 //        cout << "S4           : set branch address S4Level2"<<endl;  
2108          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2109          else Trout->AddFriend("S4");          else Trout->AddFriend("S4");
2110      }else{  //      cout << "+S4"<<endl;
 //        cout << "S4           : missing tree"<<endl;  
2111      };      };
2112      // Neutron Detector      // Neutron Detector
2113      if(N && ND) {      if(N && ND) {
 //        N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));  
 //        cout << "NeutronD     : set branch address NDLevel2"<<endl;  
2114          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2115          else Trout->AddFriend("NeutronD");          else Trout->AddFriend("NeutronD");
2116      }else{  //      cout << "+NeutronD"<<endl;
 //        cout << "NeutronD     : missing tree"<<endl;  
2117      };      };
2118      // Anticounters      // Anticounters
2119      if(A && AC) {      if(A && AC) {
 //        A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));  
 //        cout << "Anticounter  : set branch address AcLevel2"<<endl;  
2120          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2121          else Trout->AddFriend("Anticounter");          else Trout->AddFriend("Anticounter");
2122      }else{  //      cout << "+Anticounter"<<endl;
 //        cout << "Anticounter  : missing tree"<<endl;  
2123      };      };
2124      // Orbital Info      // Orbital Info
2125      if(B && ORB) {      if(B && ORB) {
 //      B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));  
 //      cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;  
2126          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2127          else Trout->AddFriend("OrbitalInfo");          else Trout->AddFriend("OrbitalInfo");
2128      }else{  //      cout << "+OrbitalInfo"<<endl;
 //      cout << "OrbitalInfo  : missing tree"<<endl;  
2129      };      };
2130      // GPamela      // GPamela
2131      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;  
2132          if(!Trout)Trout=G;          if(!Trout)Trout=G;
2133          else Trout->AddFriend("h20");          else Trout->AddFriend("h20");
2134      }else{  //      cout << "+h20"<<endl;
 //      cout << "h20          : missing tree"<<endl;  
2135      };      };
2136    
2137  //  =====================================  //  =====================================
# Line 2050  TChain *PamLevel2::GetPamTree(TList *fl, Line 2139  TChain *PamLevel2::GetPamTree(TList *fl,
2139  //  =====================================  //  =====================================
2140      SetBranchAddress(Trout);      SetBranchAddress(Trout);
2141    
2142    
2143    //  ------------------------------------
2144    //  finally handle selection trees...
2145    //  (it is not friend of pamela tree)
2146    //  ------------------------------------
2147    
2148      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2149    
2150      // Selection List      // Selection List
2151      if(L && SELLI==1) {      if(L && SELLI==1) {
2152          cout<<">>> Found selection-list <<<"<<endl;          cout<<">>> Found selection-list <<<"<<endl;
2153          L->SetBranchAddress("RunEntry",&irun);  //      L->SetBranchAddress("RunEntry",&irun);
2154            L->SetBranchAddress("RunEntry",&irunt);//NEWNEW
2155          cout << "SelectionList: set branch address RunEntry"<<endl;          cout << "SelectionList: set branch address RunEntry"<<endl;
2156          L->SetBranchAddress("EventEntry",&irunentry);          L->SetBranchAddress("EventEntry",&irunentry);
2157          cout << "SelectionList: set branch address EventEntry"<<endl;          cout << "SelectionList: set branch address EventEntry"<<endl;
2158          sel_tree = L;          sel_tree = L;
2159  //      if(!Trout)Trout=O;  //      if(!Trout)Trout=O;
2160  //      else Trout->AddFriend("SelectionList");  //      else Trout->AddFriend("SelectionList");
2161          cout << "----------------------------------------------------" <<endl;          cout << "+SelectionList"<<endl;
2162            cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2163      }else{      }else{
2164  //      cout << "SelectionList  : missing tree"<<endl;  //      cout << "SelectionList  : missing tree"<<endl;
2165          if(L)L->Delete();          if(L)L->Delete();
2166      };      };
       
 //    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;  
 //     };  
2167    
2168    //  --------------------------------------------
2169    //  return the pamela chain with all the friends
2170    //  --------------------------------------------
2171    
2172      pam_tree = Trout;      pam_tree = Trout;
2173            
# Line 2174  void PamLevel2::SetBranchAddress(TTree * Line 2257  void PamLevel2::SetBranchAddress(TTree *
2257      if(GP) {      if(GP) {
2258  //      GetPointerTo("GPamela");  //      GetPointerTo("GPamela");
2259          if(!gp_obj)gp_obj = new GPamela();          if(!gp_obj)gp_obj = new GPamela();
2260          gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri  //      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2261    // //   t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
2262            if(SELLI) t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
2263            else      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2264    
2265          cout << "h20          : set branch address GPamela "<<endl;          cout << "h20          : set branch address GPamela "<<endl;
2266      };      };
     // 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;  
     };  
2267            
2268  }  }
2269  /**  /**
# Line 2205  void PamLevel2::SetBranchAddress(TChain Line 2285  void PamLevel2::SetBranchAddress(TChain
2285  //    GP     = GP & t->GetBranchStatus("h20");  //    GP     = GP & t->GetBranchStatus("h20");
2286    
2287      // Tracker      // Tracker
2288       if(TRK2) {      if(TRK2) {
2289          t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));          t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
2290          cout << "Tracker      : set branch address TrkLevel2"<<endl;          cout << "Tracker      : set branch address TrkLevel2"<<endl;
2291      };      };
# Line 2213  void PamLevel2::SetBranchAddress(TChain Line 2293  void PamLevel2::SetBranchAddress(TChain
2293          t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));          t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
2294          cout << "Tracker      : set branch address TrkLevel1"<<endl;          cout << "Tracker      : set branch address TrkLevel1"<<endl;
2295      };      };
2296       if(TRKh) {      if(TRKh) {
2297          t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));          t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
2298          cout << "Tracker      : set branch address TrkHough"<<endl;          cout << "Tracker      : set branch address TrkHough"<<endl;
2299       };      };
2300            
2301      // Calorimeter      // Calorimeter
2302      if(CAL2) {      if(CAL2) {
# Line 2263  void PamLevel2::SetBranchAddress(TChain Line 2343  void PamLevel2::SetBranchAddress(TChain
2343      if(GP) {      if(GP) {
2344  //      GetPointerTo("GPamela");  //      GetPointerTo("GPamela");
2345          if(!gp_obj)gp_obj = new GPamela();          if(!gp_obj)gp_obj = new GPamela();
2346          gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri          if(SELLI) t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
2347            else      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2348    //      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2349          cout << "h20          : set branch address GPamela "<<endl;          cout << "h20          : set branch address GPamela "<<endl;
2350      };      };
2351      // SelectionList      // SelectionList
2352      if(SELLI==1) {  //     if(SELLI==1){
2353          t->SetBranchAddress("RunEntry", &irun);  //      t->SetBranchAddress("RunEntry",&irunt);//NEWNEW
2354          cout << "SelectionList: set branch address RunEntry"<<endl;  //      cout << "SelectionList: set branch address RunEntry"<<endl;
2355          t->SetBranchAddress("EventEntry", &irunentry);  //      t->SetBranchAddress("EventEntry",&irunentry);
2356          cout << "SelectionList: set branch address EventEntry"<<endl;  //      cout << "SelectionList: set branch address EventEntry"<<endl;
2357      };          
2358        //     }
2359    
2360  }  }
2361    
2362    
# Line 2287  void PamLevel2::SetBranchAddress(TChain Line 2370  void PamLevel2::SetBranchAddress(TChain
2370   * @return Pointer to a TChain   * @return Pointer to a TChain
2371   */   */
2372  TChain *PamLevel2::GetRunTree(TList *fl){  TChain *PamLevel2::GetRunTree(TList *fl){
2373    //      //
2374    //      //
2375    //      //
2376    if ( run_tree ){      if ( run_tree ){
2377      printf("WARNING: TChain *PamLevel2::GetRunTree(TList *fl) -- run_tree already exists!\n ");          printf("WARNING: TChain *PamLevel2::GetRunTree(TList *fl) -- run_tree already exists!\n ");
2378      return run_tree;          return run_tree;
2379    };          };  
2380    //      //
2381    TChain *R = new TChain("Run");  
2382    
2383        TChain *R = new TChain("Run");
2384            
2385      // loop over files and create chains              // loop over files and create chains        
2386      TIter next(fl);      TIter next(fl);
# Line 2307  TChain *PamLevel2::GetRunTree(TList *fl) Line 2392  TChain *PamLevel2::GetRunTree(TList *fl)
2392              R->Add(name);              R->Add(name);
2393          };          };
2394      }      }
2395        
2396    
2397      if(R->GetNtrees()){      if(RUN && R->GetNtrees()){
2398            
2399          R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));          R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
2400          cout << "Run         : set branch address RunInfo"<<endl;          cout << "Run         : set branch address RunInfo"<<endl;
2401          R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano          R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
2402          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
2403    
2404            irunoffset = new int[R->GetNtrees()];
2405            if(DBG){
2406                cout << "----------------------------------------------------"<<endl;
2407                cout << "irun\t | ";
2408                cout << "tree\t |";
2409    //      cout << "offset\t |";
2410                cout << "RUN\t";
2411                cout << "FRAG\t";
2412                cout << "NEVENTS\t";
2413                cout << "absolute time\t\t\t";
2414                cout << "on-board time";
2415                cout<<endl;
2416            }
2417            for (Int_t ii=0; ii<R->GetEntries(); ii++){
2418                R->GetEntry(ii);
2419                if(DBG){
2420                    cout << ii<< "\t | ";
2421                    cout << R->GetTreeNumber()<< "\t |";
2422    //          cout << R->GetChainOffset()<< "\t |";
2423                    cout <<GetRunInfo()->ID<<"\t";
2424                    cout <<GetRunInfo()->ID_RUN_FRAG<<"\t";
2425                    cout <<GetRunInfo()->NEVENTS<< "\t";
2426                    cout <<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME <<"\t";
2427                    cout <<GetRunInfo()->RUNHEADER_OBT<<" <---> "<<GetRunInfo()->RUNTRAILER_OBT<<"\t";
2428                    cout <<endl;
2429                }
2430                irunoffset[R->GetTreeNumber()]=R->GetChainOffset();
2431            }
2432            cout << "N.run = "<<R->GetEntries()<<endl;
2433            cout << "----------------------------------------------------"<<endl;
2434    
2435    
2436      }else{      }else{
2437          delete R;          delete R;
2438          R=0;          R=0;
2439      }      }
2440        
2441    
2442      run_tree = R;      run_tree = R;
2443    
# Line 2334  TChain *PamLevel2::GetRunTree(TList *fl) Line 2454  TChain *PamLevel2::GetRunTree(TList *fl)
2454   * @return Pointer to a TTree   * @return Pointer to a TTree
2455   */   */
2456  TTree *PamLevel2::GetRunTree(TFile *f){  TTree *PamLevel2::GetRunTree(TFile *f){
2457    if ( run_tree ){      if ( run_tree ){
2458      printf("WARNING: TTree *PamLevel2::GetRunTree(TFile *f) -- run_tree already exists!\n ");          printf("WARNING: TTree *PamLevel2::GetRunTree(TFile *f) -- run_tree already exists!\n ");
2459      return run_tree;          return run_tree;
2460    };      };
2461                    
2462    
2463      cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;      cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;
# Line 2349  TTree *PamLevel2::GetRunTree(TFile *f){ Line 2469  TTree *PamLevel2::GetRunTree(TFile *f){
2469          cout << "Run         : set branch address RunInfo"<<endl;          cout << "Run         : set branch address RunInfo"<<endl;
2470          T->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano          T->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
2471          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
2472    
2473      }      }
2474    
2475      run_tree = (TChain*)T;      run_tree = (TChain*)T;
# Line 2362  TTree *PamLevel2::GetRunTree(TFile *f){ Line 2483  TTree *PamLevel2::GetRunTree(TFile *f){
2483   * @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
2484   */   */
2485  Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev){  Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev){
2486    //      //
2487    // check if we have already called once GetEntry, if not call it      // check if we have already called once GetEntry, if not call it
2488    //      //
2489      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;
2490      if(!run){      if(!run){
2491            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;
2492            return(false);                  return(false);  
2493      }      }
2494      if ( run->GetEntries() <= 0 ) return(false);      if ( run->GetEntries() <= 0 ) return(false);
2495    //      //
2496        
2497    //  Int_t oldrun = irun;      //  Int_t oldrun = irun;
2498    Long64_t oldrun = irun;      Long64_t oldrun = irun;
2499    
2500        // --------------------------------------
2501        // if it is a full file (not preselected)
2502        // --------------------------------------
2503        if(SELLI==0){
2504    
2505            //
2506            // the absolute time is necessary to relate the event with the run
2507            //
2508            if( !GetOrbitalInfo() && !ISGP){
2509                cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
2510                return(false);
2511            }
2512    
2513            ULong64_t abstime = 0;
2514            if( GetOrbitalInfo() )abstime=GetOrbitalInfo()->absTime;
2515    
2516    
2517    // --------------------------------------          //
2518    // if it is a full file (not preselected)          // the first time the routine is called, set run search from the beginning
2519    // --------------------------------------          //
2520    if(SELLI==0){          if ( irun < 0LL ){
2521                irun = 0LL;
2522        //              run->GetEntry(irun);
2523        // the absolute time is necessary to relate the event with the run              runfirstentry = 0LL;
2524        //              runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2525        if( !GetOrbitalInfo() && !ISGP){              if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
           cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;  
           return(false);  
       }  
   
       ULong64_t abstime = 0;  
       if( GetOrbitalInfo() )abstime=GetOrbitalInfo()->absTime;  
   
   
       //  
       // the first time the routine is called, set run search from the beginning  
       //  
       if ( irun < 0LL ){  
           irun = 0LL;  
           run->GetEntry(irun);  
           runfirstentry = 0LL;  
           runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);  
           if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;  
2526                        
2527            if( ISGP && run->GetEntries()!=1 ){              if( ISGP && run->GetEntries()!=1 ){
2528                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;
2529                cout << "** WARNING ** run will not be updated"<<endl;                  cout << "** WARNING ** run will not be updated"<<endl;
2530            }              }
2531    
2532        };                };      
2533        //          //
2534        if(ISGP)abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO          if(ISGP)abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO
2535        //          //
2536        if ( irun == run->GetEntries()-1LL &&          if ( irun == run->GetEntries()-1LL &&
2537             !(abstime >= GetRunInfo()->RUNHEADER_TIME &&               !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
2538               abstime <= GetRunInfo()->RUNTRAILER_TIME)                 abstime <= GetRunInfo()->RUNTRAILER_TIME)
2539              ){              ){
2540           irun = -1LL;              irun = -1LL;
2541           runfirstentry = 0LL;              irunt = -1LL;
2542           runlastentry = -1LL;              runfirstentry = 0LL;
2543         };              runlastentry = -1LL;
2544        // modificato il controllo sull'aggiornamento del run, per evitare problemi          };
2545        // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)          // modificato il controllo sull'aggiornamento del run, per evitare problemi
2546        //          // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)
2547        bool fromfirst = true;          //
2548        //          bool fromfirst = true;
2549        while ( !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1LL ){          //
2550            while ( !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1LL ){
2551  //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){  //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){
2552            irun++;              irun++;
2553            run->GetEntry(irun);              run->GetEntry(irun);
2554            runfirstentry = runlastentry;              runfirstentry = runlastentry;
2555            if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runfirstentry += 1LL;              if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runfirstentry += 1LL;
2556            runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);              runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2557  //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;  //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2558  //        cout << "runfirstentry "<<runfirstentry<<endl;  //        cout << "runfirstentry "<<runfirstentry<<endl;
2559            //      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)));
2560            //      printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME);              //    printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME);
2561            //      printf(" IDRUN %u \n",GetRunInfo()->ID);              //    printf(" IDRUN %u \n",GetRunInfo()->ID);
2562            //              //
2563  //        prevshift = 0;  //        prevshift = 0;
2564            //              //
2565            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)){
2566                printf(" resetting irun  (it should NOT happen!!!)\n");                  printf(" resetting irun  (it should NOT happen!!!)\n");
2567                fromfirst = false;                  fromfirst = false;
2568                irun = 0;                  irun = 0;
2569                run->GetEntry(irun);                  run->GetEntry(irun);
2570                runfirstentry = 0ULL;                  runfirstentry = 0ULL;
2571                runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);                  runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2572                if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;                  if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
2573            };              };
2574            //              //
2575        };          };
2576        //          //
2577        if (          if (
2578             !(abstime >= GetRunInfo()->RUNHEADER_TIME &&              !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
2579               abstime <= GetRunInfo()->RUNTRAILER_TIME)                abstime <= GetRunInfo()->RUNTRAILER_TIME)
2580            ) {              ) {
2581          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);
2582            return false;              return false;
2583        }          }
2584        //          //
2585        if ( irun == oldrun || irun >= run->GetEntries() ) return(false);          if ( irun == oldrun || irun >= run->GetEntries() ) return(false);
2586        //          //
2587        //  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);
2588        //          //
2589        prevshift = 0;          prevshift = 0;
2590        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;          cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2591  //      cout << "runfirstentry "<<runfirstentry<<endl;  //      cout << "runfirstentry "<<runfirstentry<<endl;
2592        return(true);              return(true);    
2593    };      };
2594    // ----------------------------------------------------      // ----------------------------------------------------
2595    // if it is a preselected file (there is SelectionList)      // if it is a preselected file (there is SelectionList)
2596    // NBNB - the event tree MUST be read first      // NBNB - the event tree MUST be read first
2597    // ----------------------------------------------------      // ----------------------------------------------------
2598    if(SELLI==1){            if(SELLI==1){      
2599        sel_tree->GetEntry(iev);          sel_tree->GetEntry(iev);
2600  //      cout << irun << " "<< irunentry << endl;  //      cout << irun << " "<< irunentry << endl;
2601        if(irun != oldrun){          if(irun != oldrun){
2602            run->GetEntry(irun);              run->GetEntry(irun);
2603            cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;              cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2604            prevshift = 0;              prevshift = 0;
2605            return true;              return true;
2606        }          }
2607        return false;          return false;
2608    }      }
2609    
2610    return false;      return false;
2611    //      //
2612  };  };
2613    
2614  Bool_t PamLevel2::UpdateRunInfo(Long64_t iev){  Bool_t PamLevel2::UpdateRunInfo(Long64_t iev){
# Line 2502  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2624  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2624        
2625      Int_t oldrun = irun; // store current run index      Int_t oldrun = irun; // store current run index
2626    
2627        // -----------------------------------------------------------------------
2628        // the first time the routine is called, set run search from the beginning
2629        // -----------------------------------------------------------------------
2630    
2631        if ( irun < 0 ){
2632            irun = 0LL;
2633            irunt = 0LL;
2634            irunentry = 0;
2635            prevshift = 0;
2636            run_tree->GetEntry(irun);
2637            if( !GetOrbitalInfo() )cout << "** WARNING ** missing OrbitalInfo ---> run info might be not correctly updated "<<endl;
2638            if ( gltsync ) delete gltsync; //Emiliano
2639            if(!dbc || (dbc && !dbc->IsConnected()) )SetDBConnection(); //Emiliano
2640            gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0,"ID",dbc,false); //Emiliano // the "false" means not to use level0 file (not necessary here)
2641            if ( dbc ) dbc->Close();// Emiliano
2642        };      
2643        // ---------------------------------------------------------------
2644        // retrieve OBT and absolute time of the event
2645        // ---------------------------------------------------------------
2646        ULong64_t abstime = 0LL;
2647        //    ULong64_t obt     = 0LL; // Emiliano
2648        Long64_t obt     = 0LL; // Emiliano, Long64_t GL_TIMESYNC::DBobt(UInt_t obt) since depending on the situation OBT is lowered or boosted
2649        if( GetOrbitalInfo() ){
2650            abstime = GetOrbitalInfo()->absTime;
2651            obt     = gltsync->DBobt(GetOrbitalInfo()->OBT); // Emiliano
2652        }else{
2653            abstime = GetRunInfo()->RUNHEADER_TIME;
2654            obt     = gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT); // Emiliano
2655        }
2656        
2657    
2658      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2659      // if it is a full file (not preselected)      // if it is a full file (not preselected)
2660      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2661      if(SELLI==0){      if(SELLI==0 || SELLI==2){ // Emiliano
   
         // ---------------------------------------------------------------  
         // increment dead and live-time counters  
         // ---------------------------------------------------------------  
         if( GetTrigLevel2() ){  
             totdltime[0]+=GetTrigLevel2()->dltime[0];  
             totdltime[1]+=GetTrigLevel2()->dltime[1];  
         }  
         totdltime[2]++;  
2662    
 //      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;  
         }  
2663          // ---------------------------------------------------------------          // ---------------------------------------------------------------
2664          // the absolute time is necessary to relate the event with the run          // increment dead and live-time counters
2665            // (only when reading a file not preselected)
2666          // ---------------------------------------------------------------          // ---------------------------------------------------------------
2667          if( !GetOrbitalInfo() && !ISGP ){          if(SELLI==0){
2668              cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;              if( GetTrigLevel2() ){
2669              return(false);                  totdltime[0]+=GetTrigLevel2()->dltime[0];
2670          }                  totdltime[1]+=GetTrigLevel2()->dltime[1];
         
         // -----------------------------------------------------------------------  
         // the first time the routine is called, set run search from the beginning  
         // -----------------------------------------------------------------------  
         if ( irun < 0 ){  
             irun = 0LL;  
             irunentry = 0;  
             prevshift = 0;  
             run_tree->GetEntry(irun);  
   
             if( ISGP && run_tree->GetEntries()!=1 ){  
                 cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run_tree->GetEntries() << endl;  
                 cout << "** WARNING ** run will not be updated"<<endl;  
2671              }              }
2672          };                    totdltime[2]++;
   
         // -----------------------------------------------------------------------  
         // if it is simulation, assign abstime by hand (temporaneo!!!)  
         // -----------------------------------------------------------------------  
         if(ISGP){  
             abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO  
             obt     = GetRunInfo()->RUNHEADER_OBT; // BARBATRUCCO  
2673          }          }
2674    
2675          //          //
2676          bool fromfirst = true; // first loop over runs          bool fromfirst = true; // first loop over runs
2677    
 //      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;  
2678    
2679          // ------------------------------------------------------          // ------------------------------------------------------
2680          // loop over runs to find the one that contains the event          // loop over runs to find the one that contains the event
2681          // ------------------------------------------------------          // ------------------------------------------------------
2682          while (          while (
2683              (              (
2684                  (  //              (
2685                      !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)  //                  !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
2686                        abstime <= GetRunInfo()->RUNTRAILER_TIME) &&  //                    abstime <= GetRunInfo()->RUNTRAILER_TIME) &&
2687                      !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)  //                  !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
2688                        obt <= GetRunInfo()->RUNTRAILER_OBT)  //                    obt <= GetRunInfo()->RUNTRAILER_OBT)
2689                      )  //                  )
2690                  || GetRunInfo()->NEVENTS==0                  
2691                    !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
2692                      abstime <= GetRunInfo()->RUNTRAILER_TIME)
2693                    ||
2694                    !(obt >= gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) &&         // additional check on OBT (ms) // Emiliano
2695                      obt <= gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT))           // Emiliano
2696                    ||
2697                    GetRunInfo()->NEVENTS==0
2698  //              || !(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
2699                  || !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift)                  ||
2700                    !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift)
2701                  )                  )
2702                  && irun < run_tree->GetEntries() ){              && irun < run_tree->GetEntries() ){
2703    
2704    
2705    //          if( !(abstime >= GetRunInfo()->RUNHEADER_TIME &&abstime <= GetRunInfo()->RUNTRAILER_TIME)  )cout << "ABS TIME "<<abstime << " " <<GetRunInfo()->RUNTRAILER_TIME <<endl;
2706    //          if( !(obt >= GetRunInfo()->RUNHEADER_OBT && obt <= GetRunInfo()->RUNTRAILER_OBT) )cout << "OBT TIME "<< obt <<" "<< GetRunInfo()->RUNTRAILER_OBT << endl;
2707    //          if( GetRunInfo()->NEVENTS==0  )cout <<"GetRunInfo()->NEVENTS==0 "<<endl;
2708    //          if( !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift) ) cout << "irunentry > "<<GetRunInfo()->NEVENTS-1-prevshift << endl;
2709              // - - - - - - - - - - - - -              // - - - - - - - - - - - - -
2710              // irunentry = position of current entry, relative to the run              // irunentry = position of current entry, relative to the run
2711              // 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 2714  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2714              // -----------------------------------------              // -----------------------------------------
2715              // store dead and live-time of previous run              // store dead and live-time of previous run
2716              // -----------------------------------------              // -----------------------------------------
2717    //          if(SELLI==0){
2718              if(SELLI!=2){
2719              if(fromfirst){              if(fromfirst){
2720                  if(oldrun==irun){                  if(oldrun==irun){
2721                      /// decrement counters                      /// decrement counters
# Line 2618  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2745  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2745                  }                  }
2746                  totdltime[2]=1;                             //event counter                  totdltime[2]=1;                             //event counter
2747              }              }
2748              }
2749              //        }
2750    
2751                irun++;        
             irun++;  
2752              // ------------------------------------              // ------------------------------------
2753              // if the end of run tree is reached...              // if the end of run tree is reached...
2754              // ------------------------------------              // ------------------------------------
# Line 2648  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2776  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2776              if(irun>0)runfirstentry += (GetRunInfo()->NEVENTS)-prevshift;              if(irun>0)runfirstentry += (GetRunInfo()->NEVENTS)-prevshift;
2777              irunentry = 0;              irunentry = 0;
2778              prevshift = 0;                        prevshift = 0;          
2779              run_tree->GetEntry(irun);                    run_tree->GetEntry(irun);//update runinfo
2780              if(GetRunInfo()->RUNHEADER_OBT>GetRunInfo()->RUNTRAILER_OBT ){              irunt = irun - irunoffset[run_tree->GetTreeNumber()];
2781                if ( gltsync ) delete gltsync; // Emiliano
2782                if(!dbc || (dbc && !dbc->IsConnected()) )SetDBConnection(); //Emiliano
2783                gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0,"ID",dbc,false); // Emiliano
2784                if ( dbc ) dbc->Close(); // Emiliano
2785                if(gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT)>gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT) ){ // Emiliano
2786                  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;
2787                  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;
2788              }              }
# Line 2670  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2803  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2803          // --------------------------------------          // --------------------------------------
2804    
2805    
   
 //      // -----------------------------------------  
 //      // 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  
           
   
2806          // --------------------------------------          // --------------------------------------
2807          // ---> exit with TRUE          // ---> exit with TRUE
2808          // --------------------------------------          // --------------------------------------
2809          cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;          if(DBG)cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2810            // ----------------------------------------------------
2811            // update the tracker parameters
2812            // (non ho trovato nessun altro modo sicuro di farlo...)
2813            // ----------------------------------------------------
2814            if(!dbc || (dbc && !dbc->IsConnected()) )SetDBConnection();
2815            TrkParams::Set(GetRunInfo() ,dbc);
2816            if(dbc)dbc->Close();
2817    
2818          // ----------------------------------------------------          // ----------------------------------------------------
2819          // then check if the run has a fragment          // then check if the run has a fragment
2820          // in this case we have to switch to the next fragment          // in this case we have to switch to the next fragment
# Line 2732  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2823  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2823          if(          if(
2824              GetRunInfo()->ID_RUN_FRAG != 0 &&              GetRunInfo()->ID_RUN_FRAG != 0 &&
2825  //          GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID &&  //          GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID &&
2826                DBG &&
2827              true ){              true ){
2828              cout << "* fragment *"<<endl;                            cout << "* fragment *"<<endl;              
2829          }          }
# Line 2741  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2833  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2833      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2834      // if it is a preselected file (there is SelectionList)      // if it is a preselected file (there is SelectionList)
2835      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2836        // irun  = run entry relative to the chain
2837        // irunt = run entry relative to the tree
2838      if(SELLI==1){            if(SELLI==1){      
2839          sel_tree->GetEntry(iev);          sel_tree->GetEntry(iev);// read irunt from SelectionList
2840          if(irun != oldrun){          irun = irunt + irunoffset[sel_tree->GetTreeNumber()];//NEWNEW
2841              run_tree->GetEntry(irun);          if(irun != oldrun ){
2842              cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;              if( irun < run_tree->GetEntries() )run_tree->GetEntry(irun);
2843                // check if the time is ok (with merged files it is not...)
2844                // if not loop over run and look for the proper entry
2845                bool SECONDO_GIRO=false;
2846                //      Long64_t irun_start   = irun;
2847                int      offset_start = irunoffset[sel_tree->GetTreeNumber()];
2848                while (
2849                    (
2850                        (
2851                            !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
2852                              abstime <= GetRunInfo()->RUNTRAILER_TIME)
2853    //                      ||
2854    //                      !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
2855    //                        obt <= GetRunInfo()->RUNTRAILER_OBT)
2856                            )
2857                        || GetRunInfo()->NEVENTS==0
2858                        )
2859    //              && irun < run_tree->GetEntries()
2860                    ){
2861    
2862                    if(DBG){
2863                        cout << " (test) ";
2864                        cout << " tree "<<sel_tree->GetTreeNumber();
2865                        cout << " irunt "<<irunt;
2866                        cout << " offset "<<irunoffset[sel_tree->GetTreeNumber()];
2867                        cout << " abs "<<abstime;
2868                        cout <<" >> "<<GetRunInfo()->RUNHEADER_TIME<<" "<<GetRunInfo()->RUNTRAILER_TIME;
2869                        cout << " obt "<<obt;
2870                        cout <<" >> "<<GetRunInfo()->RUNHEADER_OBT<<" "<<GetRunInfo()->RUNTRAILER_OBT;
2871                        cout << " *** JUMP RUN *** irun "<<irun;
2872                        cout << endl;
2873                    }
2874    //              irun++;
2875                    irunoffset[sel_tree->GetTreeNumber()]++;
2876                    irun = irunt + irunoffset[sel_tree->GetTreeNumber()];//NEWNEW          
2877                    if(irun == run_tree->GetEntries() && SECONDO_GIRO){
2878    //              if(irun == irun_start ){
2879                        cout << " ...grrrvzzkhhhajsdkj!!!! "<<endl;
2880                        irunoffset[sel_tree->GetTreeNumber()] = offset_start;
2881                        return false;
2882                    }
2883                    if( irun >= run_tree->GetEntries() || irun < 0){
2884                        cout << "irun = "<<irun<<" >>  search from the beginning... <<"<<endl;
2885                        SECONDO_GIRO=true;
2886                        irun=0;
2887                        irunoffset[sel_tree->GetTreeNumber()]=-irunt;
2888                    }
2889                    run_tree->GetEntry(irun);
2890                }
2891    
2892    
2893                if(DBG){
2894                    cout << " (test) ";
2895                    cout << " tree "<<sel_tree->GetTreeNumber();
2896                    cout << " irunt "<<irunt;
2897                    cout << " offset "<<irunoffset[sel_tree->GetTreeNumber()];
2898                    cout << " abs "<<abstime;
2899                    cout <<" >> "<<GetRunInfo()->RUNHEADER_TIME<<" "<<GetRunInfo()->RUNTRAILER_TIME;
2900                    cout << " obt "<<obt;
2901                    cout <<" >> "<<GetRunInfo()->RUNHEADER_OBT<<" "<<GetRunInfo()->RUNTRAILER_OBT;
2902                }
2903                if(DBG)cout << endl;
2904                if(DBG)cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" (run-entry "<<irun<<")"<<endl;
2905                // ----------------------------------------------------
2906                // update the tracker parameters
2907                // (non ho trovato nessun altro modo sicuro di farlo...)
2908                // ----------------------------------------------------
2909                if(!dbc || (dbc && !dbc->IsConnected()) )SetDBConnection();
2910                TrkParams::Set(GetRunInfo() ,dbc);
2911                if(dbc)dbc->Close();
2912    //          cout << endl;
2913              prevshift = 0;              prevshift = 0;
2914              return true;              return true;
2915          }          }
# Line 2761  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2925  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2925   * @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
2926   */   */
2927  Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev){  Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev){
2928    return(UpdateRunInfo((TChain*)run,iev));      return(UpdateRunInfo((TChain*)run,iev));
2929  };  };
2930    
2931  //--------------------------------------  //--------------------------------------
# Line 2771  Bool_t PamLevel2::UpdateRunInfo(TTree *r Line 2935  Bool_t PamLevel2::UpdateRunInfo(TTree *r
2935  /**  /**
2936   * Set which trees shoul be analysed   * Set which trees shoul be analysed
2937   * @param detlist TString containing the sequence of trees required   * @param detlist TString containing the sequence of trees required
2938  */   */
2939  void PamLevel2::SetWhichTrees(TString detlist){  void PamLevel2::SetWhichTrees(TString detlist){
2940            
2941  //    if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){  //    if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){
2942      if( detlist.Contains("+ALL", TString::kIgnoreCase)){      if( detlist.Contains("+ALL", TString::kIgnoreCase)){
2943    
2944          cout << " ======================================================== "<<endl;          cout << " ======================================================== "<<endl;
2945          cout << "                       (( WARNING ))                      "<< endl;          cout << "                       (( WARNING ))                      "<<endl;
2946          cout << " The meaning of the option +ALL has changed!!             "<<endl;          cout << " The meaning of the option +ALL has changed!!             "<<endl;
2947          cout << " Now it includes really all (level0+level1+level2+gpamela)"<<endl;          cout << " Now it includes really all (level0+level1+level2+gpamela)"<<endl;
2948          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;
2949          cout << " trees or level0 files are not available!!                "<<endl;          cout << " all trees or  if level0 files are not available!!        "<<endl;
2950          cout << " ======================================================== "<<endl;          cout << " ======================================================== "<<endl;
2951                            
2952          CAL0 = true;          CAL0 = true;
# Line 2892  void PamLevel2::SetWhichTrees(TString de Line 3056  void PamLevel2::SetWhichTrees(TString de
3056      if( detlist.Contains("-GP", TString::kIgnoreCase) )GP = false;      if( detlist.Contains("-GP", TString::kIgnoreCase) )GP = false;
3057      else if( detlist.Contains("+GP", TString::kIgnoreCase) )GP = true;      else if( detlist.Contains("+GP", TString::kIgnoreCase) )GP = true;
3058    
3059      cout<< "Set detector list from input --> ";      cout<< "tree/branch list from input --> ";
3060      if(TRK0)cout<<"TRK0 ";      if(TRK0)cout<<"TRK0 ";
3061      if(TRK1)cout<<"TRK1 ";      if(TRK1)cout<<"TRK1 ";
3062      if(TRK2)cout<<"TRK2 ";      if(TRK2)cout<<"TRK2 ";
# Line 2952  void  PamLevel2::GetWhichTrees(TFile* f) Line 3116  void  PamLevel2::GetWhichTrees(TFile* f)
3116            
3117      RUN    = false;      RUN    = false;
3118                    
3119      cout << "Checking file: "<<f->GetName()<<endl;  //    cout << "Checking file: "<<f->GetName()<<endl;
3120      if( !f || f->IsZombie() ){      if( !f || f->IsZombie() ){
3121          cout << "File: "<< f->GetName() <<" Non valid root file"<< endl;          cout << "File: "<< f->GetName() <<" Non valid root file"<< endl;
3122          return;          return;
# Line 3071  void  PamLevel2::GetWhichTrees(TFile* f) Line 3235  void  PamLevel2::GetWhichTrees(TFile* f)
3235            
3236  //    delete lk;  //    delete lk;
3237    
3238      cout<< "Get detector list from input file --> ";      cout<< "tree/branch list from file  --> ";
3239      if(TRK1)cout<<"TRK1 ";      if(TRK1)cout<<"TRK1 ";
3240      if(TRK2)cout<<"TRK2 ";      if(TRK2)cout<<"TRK2 ";
3241      if(TRKh)cout<<"TRKH ";      if(TRKh)cout<<"TRKH ";
# Line 3119  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3283  Bool_t  PamLevel2::CheckLevel2File(TStri
3283            
3284      Bool_t SELLI__ok  = false;      Bool_t SELLI__ok  = false;
3285    
3286      cout << "Checking file: "<<name<<endl;  //    cout << "Checking file: "<<name<<endl;
3287      TFile *f = new TFile(name.Data());      TFile *f = new TFile(name.Data());
3288      if( !f || f->IsZombie() ){      if( !f || f->IsZombie() ){
3289          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 3491  Bool_t  PamLevel2::CheckLevel2File(TStri
3491    
3492    
3493      if(!RUN__ok) {      if(!RUN__ok) {
3494          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;
3495  //      return false;          RUN = false;
3496      };      };
3497    
3498      if(CAL1 && !CAL1__ok){      if(CAL1 && !CAL1__ok){
# Line 3451  void PamLevel2::CreateCloneTrees(TFile * Line 3615  void PamLevel2::CreateCloneTrees(TFile *
3615    
3616    
3617  //  if the pointer is null, create a default file  //  if the pointer is null, create a default file
3618        if(!run_tree)return;
3619    
3620      if(!ofile){      if(!ofile){
3621          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 3636  void PamLevel2::CreateCloneTrees(TFile *
3636      // ------------------      // ------------------
3637      // replicate run tree      // replicate run tree
3638      // ------------------      // ------------------
3639      cout << "----------------------------------------------------"<<endl;  //    cout << "----------------------------------------------------"<<endl;
3640      cout << "irun\t | RUN\t NEVENTS\t absolute time"<<endl;  //    cout << "irun\t | RUN\t NEVENTS\t absolute time"<<endl;
3641      for (Int_t i=0; i<run_tree->GetEntries(); i++){      for (Int_t i=0; i<run_tree->GetEntries(); i++){
3642          run_tree->GetEntry(i);          run_tree->GetEntry(i);
3643          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;
3644          run_tree_clone->Fill();          run_tree_clone->Fill();
3645      }      }
3646      cout << "----------------------------------------------------"<<endl;      cout << "----------------------------------------------------"<<endl;
# Line 3483  void PamLevel2::CreateCloneTrees(TFile * Line 3648  void PamLevel2::CreateCloneTrees(TFile *
3648      // ------------------------------------      // ------------------------------------
3649      // add branch with dead and live times      // add branch with dead and live times
3650      // ------------------------------------      // ------------------------------------
3651      run_tree_clone->Branch("DeadLiveTime",totdltime,"dltime[3]/l");      if ( SELLI != 2 ){ // EMILIANO
3652      cout << "Run          : branch DeadLiveTime"<<endl;        run_tree_clone->Branch("DeadLiveTime",totdltime,"dltime[3]/l");
3653          cout << "Run          : branch DeadLiveTime"<<endl;
3654    
3655    
3656      sel_tree_clone = new TTree("SelectionList","List of selected events ");        sel_tree_clone = new TTree("SelectionList","List of selected events ");
3657      sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");        //    sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");
3658      sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/L");        sel_tree_clone->Branch("RunEntry",&irunt,"runentry/L");//NEWNEW
3659              sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/L");
3660        };
3661    
3662      Int_t i=0;      Int_t i=0;
3663      if(TRK1||TRK2||TRKh){      if(TRK1||TRK2||TRKh){
# Line 3563  void PamLevel2::CreateCloneTrees(TFile * Line 3730  void PamLevel2::CreateCloneTrees(TFile *
3730      };      };
3731      // OrbitalInfo      // OrbitalInfo
3732      if(ORB) {      if(ORB) {
3733          pam_tree_clone[i] = new TTree("OrbitalInfo","PAMELA oribital info  ");            pam_tree_clone[i] = new TTree("OrbitalInfo","PAMELA orbital info  ");  
3734          pam_tree_clone[i]->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo"));          pam_tree_clone[i]->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo"));
3735          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;
3736          i++;          i++;
3737      };      };
3738      // GPamela      // GPamela
3739      if(GP) {      if(GP) {
3740          pam_tree_clone[i] = new TTree("h20","PAMELA oribital info  ");            pam_tree_clone[i] = new TTree("h20","PAMELA orbital info  ");  
3741          pam_tree_clone[i]->Branch("GPamela","GPamela", GetPointerTo("GPamela"),32000,1);//split          pam_tree_clone[i]->Branch("GPamela","GPamela", GetPointerTo("GPamela"),32000,1);//split
3742          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;
3743          i++;          i++;
# Line 3620  void PamLevel2::WriteCloneTrees(){ Line 3787  void PamLevel2::WriteCloneTrees(){
3787      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
3788      cout << "Write clones of PAMELA trees "<<endl;      cout << "Write clones of PAMELA trees "<<endl;
3789      cout << run_tree_clone->GetName()<<endl;        cout << run_tree_clone->GetName()<<endl;  
3790      if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())      if ( SELLI != 2){// Emiliano
3791          if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
3792          run_tree_clone->GetBranch("DeadLiveTime")->Fill();          run_tree_clone->GetBranch("DeadLiveTime")->Fill();
3793        };
3794      run_tree_clone->Write();      run_tree_clone->Write();
3795      cout << sel_tree_clone->GetName()<<endl;          if ( SELLI != 2){ //Emiliano
3796      sel_tree_clone->Write();        cout << sel_tree_clone->GetName()<<endl;    
3797          sel_tree_clone->Write();
3798        };
3799      for(Int_t i=0; i<NCLONES; i++){          for(Int_t i=0; i<NCLONES; i++){    
3800          if(pam_tree_clone[i]){          if(pam_tree_clone[i]){
3801              cout << pam_tree_clone[i]->GetName()<<endl;              cout << pam_tree_clone[i]->GetName()<<endl;
# Line 3666  Int_t PamLevel2::GetEntry(Long64_t iee){ Line 3837  Int_t PamLevel2::GetEntry(Long64_t iee){
3837          return 0;          return 0;
3838      }      }
3839    
 //    cout << " gp_obj->P0 "<<gp_obj->P0<<endl;  
3840      //      //
3841      // ... 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.
3842      // 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
3843      // a problem if you don't check the return code of getentry.      // a problem if you don't check the return code of getentry.
3844      //      //
3845      if(!run_tree ){      if(!RUN || !run_tree ){
3846          if ( TRK0 || CAL0 || TOF0 || RUN ) { //forse cosi` va bene per tornare 1?          if ( TRK0 || CAL0 || TOF0 || RUN ) { //forse cosi` va bene per tornare 1?
3847              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;
3848              return 0;              return 0;
# Line 3686  Int_t PamLevel2::GetEntry(Long64_t iee){ Line 3856  Int_t PamLevel2::GetEntry(Long64_t iee){
3856  //    Bool_t UPDATED = UpdateRunInfo(run_tree,ii);  //    Bool_t UPDATED = UpdateRunInfo(run_tree,ii);
3857  //    Bool_t UPDATED = UpdateRunInfo(ii);  //    Bool_t UPDATED = UpdateRunInfo(ii);
3858      UpdateRunInfo(ii);      UpdateRunInfo(ii);
3859      if(SELLI==0)irunentry = iee-runfirstentry;      if(SELLI==0||SELLI==2)irunentry = iee-runfirstentry;
3860  //    if(UPDATED && run_tree_clone)run_tree_clone->Fill();  //    if(UPDATED && run_tree_clone)run_tree_clone->Fill();
3861        
3862  //    cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl;  //    cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl;
# Line 3757  TTree* PamLevel2::GetYodaTree( ){ Line 3927  TTree* PamLevel2::GetYodaTree( ){
3927          // open the DB connection          // open the DB connection
3928          // (if not already opened)          // (if not already opened)
3929          //===================================          //===================================
3930          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;  
         }  
3931          GL_ROOT glroot = GL_ROOT();          GL_ROOT glroot = GL_ROOT();
3932          if( glroot.Query_GL_ROOT(iroot,dbc) ){          if( glroot.Query_GL_ROOT(iroot,dbc) ){
3933              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 3975  TTree* PamLevel2::GetYodaTree( ){
3975              cout << "PamLevel2::GetYodaTree() --- level0 TOF not implemented "<<endl;              cout << "PamLevel2::GetYodaTree() --- level0 TOF not implemented "<<endl;
3976          }          }
3977    
3978          dbc->Close();          dbc->Close(); // EMILIANO, do not leave open connections, open only when needed
3979    
3980    
3981      };      };
# Line 3828  TTree* PamLevel2::GetYodaTree( ){ Line 3985  TTree* PamLevel2::GetYodaTree( ){
3985  //     }  //     }
3986    
3987      if ( TRK0 ){      if ( TRK0 ){
3988          TrkParams::Load(6);  //      TrkParams::Load(6);
3989          if( !TrkParams::IsLoaded(6) ){  //      if( !TrkParams::IsLoaded(6) ){
3990              cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- VK-mask not loaded"<<endl;  //          cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- VK-mask not loaded"<<endl;
3991          };  //      };
3992    //      if(!dbc || (dbc && !dbc->IsConnected()))SetDBConnection();
3993          TrkParams::SetCalib(run_obj,dbc);          TrkParams::SetCalib(run_obj,dbc);
3994          TrkParams::LoadCalib( );          TrkParams::LoadCalib( );
3995          if( !TrkParams::CalibIsLoaded() ){          if( !TrkParams::CalibIsLoaded() ){
3996              cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- Calibration not loaded"<<endl;              cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- Calibration not loaded"<<endl;
3997          };          };
3998    //      if(dbc)dbc->Close(); // EMILIANO, do not leave open connections, open only when needed
3999      }      }
4000    
4001    
# Line 3905  Int_t PamLevel2::GetYodaEntry(){ Line 4064  Int_t PamLevel2::GetYodaEntry(){
4064      do{      do{
4065          if(shift>0){              if(shift>0){    
4066              cout << " PKTNUM  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;              cout << " PKTNUM  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;
4067              cout << "         RUN: ID "<< GetRunInfo()->ID << " ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<" ID_RUN_FRAG "<<GetRunInfo()->ID_RUN_FRAG << " EV_FROM "<<GetRunInfo()->EV_FROM  <<endl;              if(DBG)cout << "         RUN: ID "<< GetRunInfo()->ID << " ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<" ID_RUN_FRAG "<<GetRunInfo()->ID_RUN_FRAG << " EV_FROM "<<GetRunInfo()->EV_FROM  <<endl;
4068              cout << "         L2 <--> L0 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" prevshift "<<prevshift<<" )"<<endl;              if(DBG)cout << "         L2 <--> L0 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" prevshift "<<prevshift<<" )"<<endl;
4069          }          }
4070          answer = l0_tree->GetEntry(quellagiusta+(Long64_t)shift+(Long64_t)prevshift);          answer = l0_tree->GetEntry(quellagiusta+(Long64_t)shift+(Long64_t)prevshift);
4071          shift++;          shift++;
# Line 3930  Int_t PamLevel2::GetYodaEntry(){ Line 4089  Int_t PamLevel2::GetYodaEntry(){
4089  //      printf(" IDRUN %u \n",GetRunInfo()->ID);  //      printf(" IDRUN %u \n",GetRunInfo()->ID);
4090  //  //
4091          if ( prevshift != 0 && (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() ){          if ( prevshift != 0 && (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() ){
4092            prevshift = 0;              prevshift = 0;
4093            shift = -1;              shift = -1;
4094          };          };
4095    
4096      }while( ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) ||      }while( ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) ||
# Line 3939  Int_t PamLevel2::GetYodaEntry(){ Line 4098  Int_t PamLevel2::GetYodaEntry(){
4098              && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() && shift < maxshift);              && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() && shift < maxshift);
4099    
4100      if ( (quellagiusta+(Long64_t)shift+(Long64_t)prevshift) > GetYodaTree()->GetEntries() || shift == maxshift ) {      if ( (quellagiusta+(Long64_t)shift+(Long64_t)prevshift) > GetYodaTree()->GetEntries() || shift == maxshift ) {
4101          cout << " Big trouble here, no such event in Level0 data! " <<endl;          cout << " Big trouble here, no such event in Level0 data! (NB maxshift set to "<<maxshift<<" )" <<endl;
4102          return 0;          return 0;
4103      }      }
4104  //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;  //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;
# Line 3954  Int_t PamLevel2::GetYodaEntry(){ Line 4113  Int_t PamLevel2::GetYodaEntry(){
4113   */   */
4114  Bool_t PamLevel2::SetDBConnection(){  Bool_t PamLevel2::SetDBConnection(){
4115    
4116      cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;  //    cout << "PamLevel2::SetDBConnection()" << endl;
4117      cout<<"Connecting to DB"<<endl;      if(DBG){
4118      cout<<"HOST "<<host<<endl;          cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
4119      cout<<"USER "<<user<<endl;          cout<<"Connecting to DB"<<endl;
4120      cout<<"PSW  "<<psw<<endl;          cout<<"HOST "<<host<<endl;
4121            cout<<"USER "<<user<<endl;
4122            cout<<"PSW  "<<psw<<endl;
4123        }
4124      dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());      dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
4125      if( !dbc )return false;      if( !dbc )return false;
4126      if( !dbc->IsConnected() )return false;          if( !dbc->IsConnected() )return false;    
4127      cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;      stringstream myquery;  // EMILIANO
4128        myquery.str("");  // EMILIANO
4129        myquery << "SET time_zone='+0:00'";  // EMILIANO
4130        dbc->Query(myquery.str().c_str());  // EMILIANO
4131        if(DBG)cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
4132      return true;      return true;
4133    
4134  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.23