/[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.60 by pam-fi, Tue Mar 11 13:48:40 2008 UTC revision 1.80 by pam-fi, Wed Mar 25 14:42:36 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 384  PamLevel2::PamLevel2(){ Line 397  PamLevel2::PamLevel2(){
397   * If no options are specified, the default is assumed. Default is:   * If no options are specified, the default is assumed. Default is:
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 llist,TString detlist){
401      Initialize();      Initialize();
402      TList*  listf = GetListOfLevel2Files(ddir,list);      TList*  listf = GetListOfLevel2Files(ddir,llist);
403      GetPamTree(listf,detlist);      if(listf)GetPamTree(listf,detlist);
404      GetRunTree(listf);      if(listf)GetRunTree(listf);
405  };  };
406    
407    PamLevel2::PamLevel2(TString ddir,TList *llist,TString detlist){
408        Initialize();
409        GetPamTree(llist,detlist);
410        GetRunTree(llist);
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 416  PamLevel2::PamLevel2(TString ddir,TStrin
416   * Default trees/branches are loaded. Default is:   * Default trees/branches are loaded. Default is:
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 llist){
420      Initialize();      Initialize();
421      TList*  listf = GetListOfLevel2Files(ddir,list);      TList*  listf = GetListOfLevel2Files(ddir,llist);
422      GetPamTree(listf,"");      GetPamTree(listf,"");
423      GetRunTree(listf);      GetRunTree(listf);
424  };  };
# Line 431  void PamLevel2::Initialize(){ Line 449  void PamLevel2::Initialize(){
449      irunt = -1LL;      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 540  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();;
# Line 708  void PamLevel2::Reset(){ Line 729  void PamLevel2::Reset(){
729      //      //
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      //
737      if ( strict ){
738        if(trk2_obj && trk2_obj->UnpackError() != 0 ) goodev = false;
739      if(tof_obj && tof_obj->unpackError != 0) goodev = false;        if(tof_obj && tof_obj->unpackError != 0) goodev = false;  
740      if(trig_obj && trig_obj->unpackError != 0) goodev = false;      if(trig_obj && trig_obj->unpackError != 0) goodev = false;
741      if(s4_obj && s4_obj->unpackError != 0) goodev = false;        if(s4_obj && s4_obj->unpackError != 0) goodev = false;  
742      if(nd_obj && nd_obj->unpackError != 0) goodev = false;        if(nd_obj && nd_obj->unpackError != 0) goodev = false;  
743      if(ac_obj && ac_obj->unpackError != 255) goodev = false;        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 744  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 781  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 866  ToFTrkVar *PamLevel2::GetToFStoredTrack( Line 904  ToFTrkVar *PamLevel2::GetToFStoredTrack(
904  //  //
905  //--------------------------------------  //--------------------------------------
906  /**  /**
907   * Give the pamela track associated to a tracker track, retrieving related calorimeter and tof track information.   * Retrieves the OrbitalInfo track matching the seqno-th tracker stored track.
908     * (If seqno = -1 retrieves the tracker-independent tof related track)
909     */
910    OrbitalInfoTrkVar *PamLevel2::GetOrbitalInfoStoredTrack(int seqno){
911            
912        if( !orb_obj )return 0;
913    
914    
915        if( orb_obj->OrbitalInfo::ntrk()==0 ){
916    //       // TRICK BEGIN
917    //       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        OrbitalInfoTrkVar *c = 0;
952        Int_t it_tof=0;
953        
954        do{
955            c = orb_obj->OrbitalInfo::GetOrbitalInfoTrkVar(it_tof);
956            it_tof++;
957        } while( c && seqno != c->trkseqno && it_tof < orb_obj->OrbitalInfo::ntrk());      
958        
959        if(!c || seqno != c->trkseqno){
960            c = 0;
961            if(seqno!=-1)cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match OrbitalInfo stored tracks"<<endl;
962        };
963        return c;
964        
965    };
966    
967    //--------------------------------------
968    //
969    //
970    //--------------------------------------
971    /**
972     * 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            
# Line 875  PamTrack* PamLevel2::GetPamTrackAlong(Tr Line 978  PamTrack* PamLevel2::GetPamTrackAlong(Tr
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    
# Line 898  PamTrack* PamLevel2::GetPamTrackAlong(Tr Line 1003  PamTrack* PamLevel2::GetPamTrackAlong(Tr
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 1010  void PamLevel2::SortTracks(){ Line 1115  void PamLevel2::SortTracks(){
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                    
1120          // get tracker tracks          // get tracker tracks
1121          TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker          TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker
1122          CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());          CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());
1123          ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());          ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());
1124            OrbitalInfoTrkVar  *rp = GetOrbitalInfoStoredTrack(tp->GetSeqNo());
1125    
1126          TrkTrack   *ti = 0; //tracker (image)          TrkTrack   *ti = 0; //tracker (image)
1127          CaloTrkVar *ci = 0;          CaloTrkVar *ci = 0;
1128          ToFTrkVar  *oi = 0;          ToFTrkVar  *oi = 0;
1129            OrbitalInfoTrkVar  *ri = 0;
1130          //      cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;          //      cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
1131          // if track has an image, check image selection          // if track has an image, check image selection
1132    
# Line 1032  void PamLevel2::SortTracks(){ Line 1140  void PamLevel2::SortTracks(){
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    
# Line 1373  void PamLevel2::SortTracks(){ Line 1482  void PamLevel2::SortTracks(){
1482                  ts = ti;//its image!!                  ts = ti;//its image!!
1483                  cs = ci;                  cs = ci;
1484                  os = oi;                  os = oi;
1485                    rs = ri;
1486                  Int_t totis = toti_score;                  Int_t totis = toti_score;
1487    
1488                  ti = tp;//its image!!                  ti = tp;//its image!!
1489                  ci = cp;                  ci = cp;
1490                  oi = op;                  oi = op;
1491                    ri = rp;
1492    
1493                  tp = ts;//its image!!                  tp = ts;//its image!!
1494                  cp = cs;                  cp = cs;
1495                  op = os;                  op = os;
1496                    rp = rs;
1497    
1498                  toti_score = totp_score;                  toti_score = totp_score;
1499                  totp_score = totis;                  totp_score = totis;
# Line 1411  void PamLevel2::SortTracks(){ Line 1523  void PamLevel2::SortTracks(){
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);
# Line 1522  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 1620  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 1780  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1867  TTree *PamLevel2::GetPamTree(TFile *f, T
1867  TList*  PamLevel2::GetListOfLevel2Files(TString ddir, TString flisttxt = ""){  TList*  PamLevel2::GetListOfLevel2Files(TString ddir, TString flisttxt = ""){
1868                    
1869      TString wdir = gSystem->WorkingDirectory();      TString wdir = gSystem->WorkingDirectory();
1870        
     //    if(ddir=="")ddir = wdir;  
 //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);  
1871      if ( ddir != ""){      if ( ddir != ""){
1872          cout << "Level2 data directory : "<<  ddir << endl;          cout << "Level2 data directory : "<<  ddir << endl;
1873      } else {      } else {
# Line 1791  TList*  PamLevel2::GetListOfLevel2Files( Line 1876  TList*  PamLevel2::GetListOfLevel2Files(
1876      TList *contents  = new TList; // create output list      TList *contents  = new TList; // create output list
1877      contents->SetOwner();      contents->SetOwner();
1878            
1879  //    char *fullpath;      // --------------------------------------
1880  //    const char *fullpath;      // case 1 : input file/file-list provided
1881            // --------------------------------------
     // if no input file list is given:    
1882      if ( flisttxt != "" ){      if ( flisttxt != "" ){
1883                    
1884  //      if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) ){                  // --------------------------------------
1885  //      if( !(fullpath = gSystem->FindFile("./",flisttxt)) ){          // a list of files given as input
1886  //          cout <<"File "<<flisttxt<<" not found"<<endl;          // --------------------------------------
 //          return 0;  
 //      }        
 //      flisttxt = fullpath;  
1887          if ( !flisttxt.EndsWith(".root") ){          if ( !flisttxt.EndsWith(".root") ){
1888    
1889              flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));              TString dir = gSystem->DirName(flisttxt);
1890    //          cout << " List directory "<<dir<<endl;
1891                if(dir == "." || dir == "")
1892                    flisttxt = gSystem->ConcatFileName(wdir.Data(),gSystem->BaseName(flisttxt));
1893    //              flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1894    
1895              if( !gSystem->ChangeDirectory(ddir) ){              if( !gSystem->ChangeDirectory(ddir) ){
1896                  cout << "Cannot change directory : "<<ddir<<endl;                  cout << "Cannot change directory : "<<ddir<<endl;
# Line 1816  TList*  PamLevel2::GetListOfLevel2Files( Line 1901  TList*  PamLevel2::GetListOfLevel2Files(
1901              ifstream in;              ifstream in;
1902              in.open(flisttxt, ios::in); //open input file list              in.open(flisttxt, ios::in); //open input file list
1903              if(!in.good()){              if(!in.good()){
1904                  cout <<" ERROR opening the file "<<endl;                  cout <<" TList*  PamLevel2::GetListOfLevel2Files(TString, TString) --> ERROR opening the file "<<endl;
1905                  gSystem->ChangeDirectory(wdir); // back to the working directory                  gSystem->ChangeDirectory(wdir); // back to the working directory
1906                  return 0;                  return 0;
1907              }                }  
1908              int line=0;              int line=0;
1909                // ...........................
1910                // loop over file-list records
1911                // ...........................
1912              while (1) {              while (1) {
1913                  TString file;                  TString file;
1914                  in >> file;                  in >> file;
1915                  if (!in.good()) break;                  if (!in.good()) break;
1916                  line++;                  line++;
1917  //          cout <<"(1) " << file << endl;                  cout <<"(*) " << file << endl;
1918                  if(file.IsNull()){                  if(file.IsNull()){
1919                      cout << "-- list interrupted at line "<<line <<endl;                      cout << "-- list interrupted at line "<<line <<endl;
1920                      break;                      break;
1921                  }                  }
1922                  if(file.Contains("#"))file = file(0,file.First("#"));                  if(file.Contains("#"))file = file(0,file.First("#"));
1923  //          cout <<"(2) " << file << endl;                  //
1924  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){                  // take only root files
1925  //          if( (fullpath = gSystem->FindFile(ddir,file)) ){                  //
1926                  if( file.EndsWith(".root") ){                  if( file.EndsWith(".root") ){
1927                      TString filedir;                      TString filedir;
1928                        cout << ddir << endl;
1929                      if (ddir != ""){                      if (ddir != ""){
1930                          filedir = ddir; // take the input dir                          filedir = ddir; // take the input dir
1931                      } else {                      } else {
1932                          gSystem->ChangeDirectory(wdir); // back to the working directory                          gSystem->ChangeDirectory(wdir); // back to the working directory
1933                          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
1934                      };                      };
1935                        filedir.Append("/");
1936                      char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir),gSystem->BaseName(file));                      char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir),gSystem->BaseName(file));
1937                      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
1938                        cout << fullpath << endl;
1939                      delete fullpath;                      delete fullpath;
1940                  }                  }
1941  //          }else{  //          }else{
# Line 1852  TList*  PamLevel2::GetListOfLevel2Files( Line 1943  TList*  PamLevel2::GetListOfLevel2Files(
1943  //          };  //          };
1944              };              };
1945              in.close();              in.close();
1946            // --------------------------------------
1947            // a single root file given as input
1948            // --------------------------------------
1949          } else {          } else {
1950              if(flisttxt.Contains("#"))flisttxt = flisttxt(0,flisttxt.First("#"));              if(flisttxt.Contains("#"))flisttxt = flisttxt(0,flisttxt.First("#"));
1951              char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));              char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1952              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
1953              delete fullpath;              delete fullpath;
1954          };                };      
1955        // ---------------------------------------------------------------------------------
1956        // case 2 : no input file/file-list provided --> read all files insede the directory
1957        // ---------------------------------------------------------------------------------
1958      }else{      }else{
1959                    
1960          cout << "No input file list given."<<endl;          cout << "No input file list given."<<endl;
# Line 1870  TList*  PamLevel2::GetListOfLevel2Files( Line 1967  TList*  PamLevel2::GetListOfLevel2Files(
1967    
1968          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
1969          TList *temp = datadir->GetListOfFiles();          TList *temp = datadir->GetListOfFiles();
1970            if(!temp)return 0;
1971  //              temp->Print();  //              temp->Print();
1972  //              cout << "*************************************" << endl;  //              cout << "*************************************" << endl;
1973                    
# Line 2170  void PamLevel2::SetBranchAddress(TTree * Line 2268  void PamLevel2::SetBranchAddress(TTree *
2268      if(GP) {      if(GP) {
2269  //      GetPointerTo("GPamela");  //      GetPointerTo("GPamela");
2270          if(!gp_obj)gp_obj = new GPamela();          if(!gp_obj)gp_obj = new GPamela();
2271          gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri  //      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2272  //      t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));  // //   t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
2273            if(SELLI) t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
2274            else      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2275    
2276          cout << "h20          : set branch address GPamela "<<endl;          cout << "h20          : set branch address GPamela "<<endl;
2277      };      };
2278            
# Line 2253  void PamLevel2::SetBranchAddress(TChain Line 2354  void PamLevel2::SetBranchAddress(TChain
2354      if(GP) {      if(GP) {
2355  //      GetPointerTo("GPamela");  //      GetPointerTo("GPamela");
2356          if(!gp_obj)gp_obj = new GPamela();          if(!gp_obj)gp_obj = new GPamela();
2357          gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri          if(SELLI) t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
2358            else      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2359    //      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2360          cout << "h20          : set branch address GPamela "<<endl;          cout << "h20          : set branch address GPamela "<<endl;
2361      };      };
2362      // SelectionList      // SelectionList
# Line 2543  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2646  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2646          prevshift = 0;          prevshift = 0;
2647          run_tree->GetEntry(irun);          run_tree->GetEntry(irun);
2648          if( !GetOrbitalInfo() )cout << "** WARNING ** missing OrbitalInfo ---> run info might be not correctly updated "<<endl;          if( !GetOrbitalInfo() )cout << "** WARNING ** missing OrbitalInfo ---> run info might be not correctly updated "<<endl;
2649            if ( gltsync ) delete gltsync; //Emiliano
2650            if(!dbc || (dbc && !dbc->IsConnected()) )SetDBConnection(); //Emiliano
2651            gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0,"ID",dbc,false); //Emiliano // the "false" means not to use level0 file (not necessary here)
2652            if ( dbc ) dbc->Close();// Emiliano
2653      };            };      
2654      // ---------------------------------------------------------------      // ---------------------------------------------------------------
2655      // retrieve OBT and absolute time of the event      // retrieve OBT and absolute time of the event
2656      // ---------------------------------------------------------------      // ---------------------------------------------------------------
2657      ULong64_t abstime = 0LL;      ULong64_t abstime = 0LL;
2658      ULong64_t obt     = 0LL;      //    ULong64_t obt     = 0LL; // Emiliano
2659        Long64_t obt     = 0LL; // Emiliano, Long64_t GL_TIMESYNC::DBobt(UInt_t obt) since depending on the situation OBT is lowered or boosted
2660      if( GetOrbitalInfo() ){      if( GetOrbitalInfo() ){
2661          abstime = GetOrbitalInfo()->absTime;          abstime = GetOrbitalInfo()->absTime;
2662          obt     = GetOrbitalInfo()->OBT;          obt     = gltsync->DBobt(GetOrbitalInfo()->OBT); // Emiliano
 //      cout << " ABS >>> "<<abstime<<" OBT >>> "<<obt<<" "<<endl;  
2663      }else{      }else{
2664          abstime = GetRunInfo()->RUNHEADER_TIME;          abstime = GetRunInfo()->RUNHEADER_TIME;
2665          obt     = GetRunInfo()->RUNHEADER_OBT;          obt     = gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT); // Emiliano
2666      }      }
 //    cout << ISGP << " "<<abstime<<endl;  
     // ---------------------------------------------------------------  
     // the absolute time is necessary to relate the event with the run  
     // ---------------------------------------------------------------  
 //     if( !GetOrbitalInfo() && !ISGP ){  
 //      cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;  
 //      return(false);  
 //     }  
     // -----------------------------------------------------------------------  
     // if it is simulation, assign abstime by hand (temporaneo!!!)  
     // -----------------------------------------------------------------------  
 //     if(ISGP){  
 //      abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO  
 //      obt     = GetRunInfo()->RUNHEADER_OBT; // BARBATRUCCO  
 //     }  
2667            
2668    
2669      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2670      // if it is a full file (not preselected)      // if it is a full file (not preselected)
2671      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2672      if(SELLI==0){      if(SELLI==0 || SELLI==2){ // Emiliano
2673    
2674          // ---------------------------------------------------------------          // ---------------------------------------------------------------
2675          // increment dead and live-time counters          // increment dead and live-time counters
# Line 2590  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2682  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2682              }              }
2683              totdltime[2]++;              totdltime[2]++;
2684          }          }
 //      cout << setw(10)<<totdltime[0]<<setw(10)<<totdltime[1]<<setw(10)<<totdltime[2]<<endl;  
2685    
 //      // ---------------------------------------------------------------  
 //      // retrieve OBT and absolute time of the event  
 //      // ---------------------------------------------------------------  
 //      ULong64_t abstime = 0;  
 //      ULong64_t obt     = 0;  
 //      if( GetOrbitalInfo() ){  
 //          abstime = GetOrbitalInfo()->absTime;  
 //          obt     = GetOrbitalInfo()->OBT;  
 //      }  
 //      // ---------------------------------------------------------------  
 //      // the absolute time is necessary to relate the event with the run  
 //      // ---------------------------------------------------------------  
 //      if( !GetOrbitalInfo() && !ISGP ){  
 //          cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;  
 //          return(false);  
 //      }  
         
 //      // -----------------------------------------------------------------------  
 //      // the first time the routine is called, set run search from the beginning  
 //      // -----------------------------------------------------------------------  
 //      if ( irun < 0 ){  
 //          irun = 0LL;  
 //          irunt = 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;  
 //          }  
 //      };        
   
 //      // -----------------------------------------------------------------------  
 //      // if it is simulation, assign abstime by hand (temporaneo!!!)  
 //      // -----------------------------------------------------------------------  
 //      if(ISGP){  
 //          abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO  
 //          obt     = GetRunInfo()->RUNHEADER_OBT; // BARBATRUCCO  
 //      }  
2686          //          //
2687          bool fromfirst = true; // first loop over runs          bool fromfirst = true; // first loop over runs
2688    
 //      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;  
2689    
2690          // ------------------------------------------------------          // ------------------------------------------------------
2691          // loop over runs to find the one that contains the event          // loop over runs to find the one that contains the event
2692          // ------------------------------------------------------          // ------------------------------------------------------
2693          while (          while (
2694              (              (
2695                  (  //              (
2696                      !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)  //                  !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
2697                        abstime <= GetRunInfo()->RUNTRAILER_TIME) &&  //                    abstime <= GetRunInfo()->RUNTRAILER_TIME) &&
2698                      !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)  //                  !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
2699                        obt <= GetRunInfo()->RUNTRAILER_OBT)  //                    obt <= GetRunInfo()->RUNTRAILER_OBT)
2700                      )  //                  )
2701                  || GetRunInfo()->NEVENTS==0                  
2702                    !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
2703                      abstime <= GetRunInfo()->RUNTRAILER_TIME)
2704                    ||
2705                    !(obt >= gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) &&         // additional check on OBT (ms) // Emiliano
2706                      obt <= gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT))           // Emiliano
2707                    ||
2708                    GetRunInfo()->NEVENTS==0
2709  //              || !(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
2710                  || !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift)                  ||
2711                    !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift)
2712                  )                  )
2713              && irun < run_tree->GetEntries() ){              && irun < run_tree->GetEntries() ){
2714    
2715    
2716    //          if( !(abstime >= GetRunInfo()->RUNHEADER_TIME &&abstime <= GetRunInfo()->RUNTRAILER_TIME)  )cout << "ABS TIME "<<abstime << " " <<GetRunInfo()->RUNTRAILER_TIME <<endl;
2717    //          if( !(obt >= GetRunInfo()->RUNHEADER_OBT && obt <= GetRunInfo()->RUNTRAILER_OBT) )cout << "OBT TIME "<< obt <<" "<< GetRunInfo()->RUNTRAILER_OBT << endl;
2718    //          if( GetRunInfo()->NEVENTS==0  )cout <<"GetRunInfo()->NEVENTS==0 "<<endl;
2719    //          if( !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift) ) cout << "irunentry > "<<GetRunInfo()->NEVENTS-1-prevshift << endl;
2720              // - - - - - - - - - - - - -              // - - - - - - - - - - - - -
2721              // irunentry = position of current entry, relative to the run              // irunentry = position of current entry, relative to the run
2722              // prevshift = shift needed to synchronize l0 and l2 data (nested events)              // prevshift = shift needed to synchronize l0 and l2 data (nested events)
# Line 2665  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2726  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2726              // store dead and live-time of previous run              // store dead and live-time of previous run
2727              // -----------------------------------------              // -----------------------------------------
2728  //          if(SELLI==0){  //          if(SELLI==0){
2729                  if(fromfirst){            if(SELLI!=2){
2730                      if(oldrun==irun){              if(fromfirst){
2731                          /// decrement counters                  if(oldrun==irun){
2732                          if( GetTrigLevel2()){                      /// decrement counters
2733                              totdltime[0]-=GetTrigLevel2()->dltime[0];//live-time                      if( GetTrigLevel2()){
2734                              totdltime[1]-=GetTrigLevel2()->dltime[1];//dead-time                          totdltime[0]-=GetTrigLevel2()->dltime[0];//live-time
2735                          }                          totdltime[1]-=GetTrigLevel2()->dltime[1];//dead-time
2736                          totdltime[2]--;                              //event counter                      }
2737                        totdltime[2]--;                              //event counter
2738                        if(DBG){
2739                          cout << endl;                          cout << endl;
2740                          cout << "n.events     : "<<totdltime[2]<<endl;                          cout << "n.events     : "<<totdltime[2]<<endl;
2741                          cout << "RUN LIVE-TIME: "<<totdltime[0]*0.16<<" ms"<<endl;                          cout << "RUN LIVE-TIME: "<<totdltime[0]*0.16<<" ms"<<endl;
2742                          cout << "RUN DEAD-TIME: "<<totdltime[1]*0.01<<" ms"<<endl;                                    cout << "RUN DEAD-TIME: "<<totdltime[1]*0.01<<" ms"<<endl;          
                     }else{  
                         totdltime[0]=0;//live-time  
                         totdltime[1]=0;//dead-time  
                         totdltime[2]=0;                             //event counter  
                         cout << " *** JUMP RUN *** irun "<<irun<<endl;  
                     }  
                     /// add an entry  
                     if(run_tree_clone)  
                         if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())  
                             run_tree_clone->GetBranch("DeadLiveTime")->Fill();  
                     /// reset counters  
                     if( GetTrigLevel2() ){  
                         totdltime[0]=GetTrigLevel2()->dltime[0];//live-time  
                         totdltime[1]=0;                         //dead-time  
2743                      }                      }
2744                      totdltime[2]=1;                             //event counter                  }else{
2745                        totdltime[0]=0;//live-time
2746                        totdltime[1]=0;//dead-time
2747                        totdltime[2]=0;                             //event counter
2748                        if(DBG)cout << " *** JUMP RUN *** irun "<<irun<<endl;
2749                    }
2750                    /// add an entry
2751                    if(run_tree_clone)
2752                        if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
2753                            run_tree_clone->GetBranch("DeadLiveTime")->Fill();
2754                    /// reset counters
2755                    if( GetTrigLevel2() ){
2756                        totdltime[0]=GetTrigLevel2()->dltime[0];//live-time
2757                        totdltime[1]=0;                         //dead-time
2758                  }                  }
2759  //          }                  totdltime[2]=1;                             //event counter
2760                }
2761              }
2762              //        }
2763    
2764              irun++;                      irun++;        
2765              // ------------------------------------              // ------------------------------------
# Line 2724  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2789  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2789              if(irun>0)runfirstentry += (GetRunInfo()->NEVENTS)-prevshift;              if(irun>0)runfirstentry += (GetRunInfo()->NEVENTS)-prevshift;
2790              irunentry = 0;              irunentry = 0;
2791              prevshift = 0;                        prevshift = 0;          
2792              run_tree->GetEntry(irun);              run_tree->GetEntry(irun);//update runinfo
2793              irunt = irun - irunoffset[run_tree->GetTreeNumber()];              irunt = irun - irunoffset[run_tree->GetTreeNumber()];
2794              if(GetRunInfo()->RUNHEADER_OBT>GetRunInfo()->RUNTRAILER_OBT ){              if ( gltsync ) delete gltsync; // Emiliano
2795                if(!dbc || (dbc && !dbc->IsConnected()) )SetDBConnection(); //Emiliano
2796                gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0,"ID",dbc,false); // Emiliano
2797                if ( dbc ) dbc->Close(); // Emiliano
2798                if(gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT)>gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT) ){ // Emiliano
2799                  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;
2800                  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;
2801              }              }
# Line 2747  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2816  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2816          // --------------------------------------          // --------------------------------------
2817    
2818    
   
   
2819          // --------------------------------------          // --------------------------------------
2820          // ---> exit with TRUE          // ---> exit with TRUE
2821          // --------------------------------------          // --------------------------------------
2822          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;
2823            // ----------------------------------------------------
2824            // update the tracker parameters
2825            // (non ho trovato nessun altro modo sicuro di farlo...)
2826            // ----------------------------------------------------
2827            if(!dbc || (dbc && !dbc->IsConnected()) )SetDBConnection();
2828            TrkParams::Set(GetRunInfo() ,dbc);
2829            if(dbc)dbc->Close();
2830    
2831          // ----------------------------------------------------          // ----------------------------------------------------
2832          // then check if the run has a fragment          // then check if the run has a fragment
2833          // in this case we have to switch to the next fragment          // in this case we have to switch to the next fragment
# Line 2761  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2836  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2836          if(          if(
2837              GetRunInfo()->ID_RUN_FRAG != 0 &&              GetRunInfo()->ID_RUN_FRAG != 0 &&
2838  //          GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID &&  //          GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID &&
2839                DBG &&
2840              true ){              true ){
2841              cout << "* fragment *"<<endl;                            cout << "* fragment *"<<endl;              
2842          }          }
# Line 2780  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2856  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2856              // check if the time is ok (with merged files it is not...)              // check if the time is ok (with merged files it is not...)
2857              // if not loop over run and look for the proper entry              // if not loop over run and look for the proper entry
2858              bool SECONDO_GIRO=false;              bool SECONDO_GIRO=false;
2859              Long64_t irun_start   = irun;              //      Long64_t irun_start   = irun;
2860              int      offset_start = irunoffset[sel_tree->GetTreeNumber()];              int      offset_start = irunoffset[sel_tree->GetTreeNumber()];
2861              while (              while (
2862                  (                  (
# Line 2806  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2882  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2882                      cout << " obt "<<obt;                      cout << " obt "<<obt;
2883                      cout <<" >> "<<GetRunInfo()->RUNHEADER_OBT<<" "<<GetRunInfo()->RUNTRAILER_OBT;                      cout <<" >> "<<GetRunInfo()->RUNHEADER_OBT<<" "<<GetRunInfo()->RUNTRAILER_OBT;
2884                      cout << " *** JUMP RUN *** irun "<<irun;                      cout << " *** JUMP RUN *** irun "<<irun;
 //              if(!SECONDO_GIRO)cout << " (don't worry)";  
 //              else             cout << " (start worring...)";  
2885                      cout << endl;                      cout << endl;
2886                  }                  }
2887  //              irun++;  //              irun++;
# Line 2839  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2913  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2913                  cout << " obt "<<obt;                  cout << " obt "<<obt;
2914                  cout <<" >> "<<GetRunInfo()->RUNHEADER_OBT<<" "<<GetRunInfo()->RUNTRAILER_OBT;                  cout <<" >> "<<GetRunInfo()->RUNHEADER_OBT<<" "<<GetRunInfo()->RUNTRAILER_OBT;
2915              }              }
2916              cout << endl;              if(DBG)cout << endl;
2917              cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" (run-entry "<<irun<<")"<<endl;              if(DBG)cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" (run-entry "<<irun<<")"<<endl;
2918                // ----------------------------------------------------
2919                // update the tracker parameters
2920                // (non ho trovato nessun altro modo sicuro di farlo...)
2921                // ----------------------------------------------------
2922                if(!dbc || (dbc && !dbc->IsConnected()) )SetDBConnection();
2923                TrkParams::Set(GetRunInfo() ,dbc);
2924                if(dbc)dbc->Close();
2925  //          cout << endl;  //          cout << endl;
2926              prevshift = 0;              prevshift = 0;
2927              return true;              return true;
# Line 3055  void  PamLevel2::GetWhichTrees(TFile* f) Line 3136  void  PamLevel2::GetWhichTrees(TFile* f)
3136      }      }
3137    
3138      TList *lk = f->GetListOfKeys();      TList *lk = f->GetListOfKeys();
3139        if(!lk)return;
3140      TIter next(lk);      TIter next(lk);
3141      TKey *key =0;      TKey *key =0;
3142    
# Line 3377  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3459  Bool_t  PamLevel2::CheckLevel2File(TStri
3459              if(GP){              if(GP){
3460                  Int_t nevt = ((TTree*)f->Get("h20"))->GetEntries();                  Int_t nevt = ((TTree*)f->Get("h20"))->GetEntries();
3461                  if( nev && nevt!=nev){                  if( nev && nevt!=nev){
3462                      cout << "File: "<< f->GetName() <<" discarded ---- OrbitalInfo tree has "<<nevt<<" events instead of "<<nev<< endl;                      cout << "File: "<< f->GetName() <<" discarded ---- h20 tree has "<<nevt<<" events instead of "<<nev<< endl;
3463                      return false;                      return false;
3464                  }                  }
3465                  nev=nevt;                  nev=nevt;
# Line 3580  void PamLevel2::CreateCloneTrees(TFile * Line 3662  void PamLevel2::CreateCloneTrees(TFile *
3662      // ------------------------------------      // ------------------------------------
3663      // add branch with dead and live times      // add branch with dead and live times
3664      // ------------------------------------      // ------------------------------------
3665      run_tree_clone->Branch("DeadLiveTime",totdltime,"dltime[3]/l");      if ( SELLI != 2 ){ // EMILIANO
3666      cout << "Run          : branch DeadLiveTime"<<endl;        run_tree_clone->Branch("DeadLiveTime",totdltime,"dltime[3]/l");
3667          cout << "Run          : branch DeadLiveTime"<<endl;
3668    
3669    
3670      sel_tree_clone = new TTree("SelectionList","List of selected events ");        sel_tree_clone = new TTree("SelectionList","List of selected events ");
3671  //    sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");        //    sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");
3672      sel_tree_clone->Branch("RunEntry",&irunt,"runentry/L");//NEWNEW        sel_tree_clone->Branch("RunEntry",&irunt,"runentry/L");//NEWNEW
3673      sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/L");        sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/L");
3674            };
3675    
3676      Int_t i=0;      Int_t i=0;
3677      if(TRK1||TRK2||TRKh){      if(TRK1||TRK2||TRKh){
# Line 3661  void PamLevel2::CreateCloneTrees(TFile * Line 3744  void PamLevel2::CreateCloneTrees(TFile *
3744      };      };
3745      // OrbitalInfo      // OrbitalInfo
3746      if(ORB) {      if(ORB) {
3747          pam_tree_clone[i] = new TTree("OrbitalInfo","PAMELA oribital info  ");            pam_tree_clone[i] = new TTree("OrbitalInfo","PAMELA orbital info  ");  
3748          pam_tree_clone[i]->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo"));          pam_tree_clone[i]->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo"));
3749          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;
3750          i++;          i++;
3751      };      };
3752      // GPamela      // GPamela
3753      if(GP) {      if(GP) {
3754          pam_tree_clone[i] = new TTree("h20","PAMELA oribital info  ");            pam_tree_clone[i] = new TTree("h20","GPAMELA info ");  
3755          pam_tree_clone[i]->Branch("GPamela","GPamela", GetPointerTo("GPamela"),32000,1);//split          pam_tree_clone[i]->Branch("GPamela","GPamela", GetPointerTo("GPamela"),32000,1);//split
3756          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;
3757          i++;          i++;
# Line 3718  void PamLevel2::WriteCloneTrees(){ Line 3801  void PamLevel2::WriteCloneTrees(){
3801      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
3802      cout << "Write clones of PAMELA trees "<<endl;      cout << "Write clones of PAMELA trees "<<endl;
3803      cout << run_tree_clone->GetName()<<endl;        cout << run_tree_clone->GetName()<<endl;  
3804      if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())      if ( SELLI != 2){// Emiliano
3805          if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
3806          run_tree_clone->GetBranch("DeadLiveTime")->Fill();          run_tree_clone->GetBranch("DeadLiveTime")->Fill();
3807        };
3808      run_tree_clone->Write();      run_tree_clone->Write();
3809      cout << sel_tree_clone->GetName()<<endl;          if ( SELLI != 2){ //Emiliano
3810      sel_tree_clone->Write();        cout << sel_tree_clone->GetName()<<endl;    
3811          sel_tree_clone->Write();
3812        };
3813      for(Int_t i=0; i<NCLONES; i++){          for(Int_t i=0; i<NCLONES; i++){    
3814          if(pam_tree_clone[i]){          if(pam_tree_clone[i]){
3815              cout << pam_tree_clone[i]->GetName()<<endl;              cout << pam_tree_clone[i]->GetName()<<endl;
# Line 3760  Int_t PamLevel2::GetEntry(Long64_t iee){ Line 3847  Int_t PamLevel2::GetEntry(Long64_t iee){
3847      //-------------------------------      //-------------------------------
3848      ii = iee;      ii = iee;
3849      if( !pam_tree->GetEntry(ii) ){            if( !pam_tree->GetEntry(ii) ){      
3850          cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading pam tree"<<endl;        cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading pam tree"<<endl;
3851          return 0;        return 0;
3852      }      }
   
3853      //      //
3854      // ... 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.
3855      // in theory one would like to return 1 if run is not loaded but now I don't have the will to add that 2 lines of code and it is not      // in theory one would like to return 1 if run is not loaded but now I don't have the will to add that 2 lines of code and it is not
# Line 3783  Int_t PamLevel2::GetEntry(Long64_t iee){ Line 3869  Int_t PamLevel2::GetEntry(Long64_t iee){
3869  //    Bool_t UPDATED = UpdateRunInfo(run_tree,ii);  //    Bool_t UPDATED = UpdateRunInfo(run_tree,ii);
3870  //    Bool_t UPDATED = UpdateRunInfo(ii);  //    Bool_t UPDATED = UpdateRunInfo(ii);
3871      UpdateRunInfo(ii);      UpdateRunInfo(ii);
3872      if(SELLI==0)irunentry = iee-runfirstentry;      if(SELLI==0||SELLI==2)irunentry = iee-runfirstentry;
3873  //    if(UPDATED && run_tree_clone)run_tree_clone->Fill();  //    if(UPDATED && run_tree_clone)run_tree_clone->Fill();
3874        
3875  //    cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl;  //    cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl;
# Line 3912  TTree* PamLevel2::GetYodaTree( ){ Line 3998  TTree* PamLevel2::GetYodaTree( ){
3998  //     }  //     }
3999    
4000      if ( TRK0 ){      if ( TRK0 ){
4001          TrkParams::Load(6);  //      TrkParams::Load(6);
4002          if( !TrkParams::IsLoaded(6) ){  //      if( !TrkParams::IsLoaded(6) ){
4003              cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- VK-mask not loaded"<<endl;  //          cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- VK-mask not loaded"<<endl;
4004          };  //      };
4005          if(!dbc || (dbc && !dbc->IsConnected()))SetDBConnection();  //      if(!dbc || (dbc && !dbc->IsConnected()))SetDBConnection();
4006          TrkParams::SetCalib(run_obj,dbc);          TrkParams::SetCalib(run_obj,dbc);
4007          TrkParams::LoadCalib( );          TrkParams::LoadCalib( );
4008          if( !TrkParams::CalibIsLoaded() ){          if( !TrkParams::CalibIsLoaded() ){
4009              cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- Calibration not loaded"<<endl;              cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- Calibration not loaded"<<endl;
4010          };          };
4011          dbc->Close(); // EMILIANO, do not leave open connections, open only when needed  //      if(dbc)dbc->Close(); // EMILIANO, do not leave open connections, open only when needed
4012      }      }
4013    
4014    
# Line 3991  Int_t PamLevel2::GetYodaEntry(){ Line 4077  Int_t PamLevel2::GetYodaEntry(){
4077      do{      do{
4078          if(shift>0){              if(shift>0){    
4079              cout << " PKTNUM  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;              cout << " PKTNUM  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;
4080              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;
4081              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;
4082          }          }
4083          answer = l0_tree->GetEntry(quellagiusta+(Long64_t)shift+(Long64_t)prevshift);          answer = l0_tree->GetEntry(quellagiusta+(Long64_t)shift+(Long64_t)prevshift);
4084          shift++;          shift++;
# Line 4025  Int_t PamLevel2::GetYodaEntry(){ Line 4111  Int_t PamLevel2::GetYodaEntry(){
4111              && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() && shift < maxshift);              && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() && shift < maxshift);
4112    
4113      if ( (quellagiusta+(Long64_t)shift+(Long64_t)prevshift) > GetYodaTree()->GetEntries() || shift == maxshift ) {      if ( (quellagiusta+(Long64_t)shift+(Long64_t)prevshift) > GetYodaTree()->GetEntries() || shift == maxshift ) {
4114          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;
4115          return 0;          return 0;
4116      }      }
4117  //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;  //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;
# Line 4040  Int_t PamLevel2::GetYodaEntry(){ Line 4126  Int_t PamLevel2::GetYodaEntry(){
4126   */   */
4127  Bool_t PamLevel2::SetDBConnection(){  Bool_t PamLevel2::SetDBConnection(){
4128    
4129      cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;  //    cout << "PamLevel2::SetDBConnection()" << endl;
4130      cout<<"Connecting to DB"<<endl;      if(DBG){
4131      cout<<"HOST "<<host<<endl;          cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
4132      cout<<"USER "<<user<<endl;          cout<<"Connecting to DB"<<endl;
4133      cout<<"PSW  "<<psw<<endl;          cout<<"HOST "<<host<<endl;
4134            cout<<"USER "<<user<<endl;
4135            cout<<"PSW  "<<psw<<endl;
4136        }
4137      dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());      dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
4138      if( !dbc )return false;      if( !dbc )return false;
4139      if( !dbc->IsConnected() )return false;          if( !dbc->IsConnected() )return false;    
# Line 4052  Bool_t PamLevel2::SetDBConnection(){ Line 4141  Bool_t PamLevel2::SetDBConnection(){
4141      myquery.str("");  // EMILIANO      myquery.str("");  // EMILIANO
4142      myquery << "SET time_zone='+0:00'";  // EMILIANO      myquery << "SET time_zone='+0:00'";  // EMILIANO
4143      dbc->Query(myquery.str().c_str());  // EMILIANO      dbc->Query(myquery.str().c_str());  // EMILIANO
4144      cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;      if(DBG)cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
4145      return true;      return true;
4146    
4147  }  }

Legend:
Removed from v.1.60  
changed lines
  Added in v.1.80

  ViewVC Help
Powered by ViewVC 1.1.23