/[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.20 by pam-fi, Fri Feb 16 15:00:35 2007 UTC revision 1.25 by mocchiut, Thu Mar 15 13:42:36 2007 UTC
# Line 969  TTree *PamLevel2::GetPamTree(TFile *f, T Line 969  TTree *PamLevel2::GetPamTree(TFile *f, T
969            
970      cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;      cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
971            
972        pam_tree = (TChain*)Trout;
973    
974      return Trout;      return Trout;
975            
976  }  }
# Line 997  TList*  PamLevel2::GetListOfLevel2Files( Line 999  TList*  PamLevel2::GetListOfLevel2Files(
999  //    char *fullpath;  //    char *fullpath;
1000  //    const char *fullpath;  //    const char *fullpath;
1001            
1002      // if no input file list is given:        // if input file list is given:    
1003      if ( flisttxt != "" ){      if ( flisttxt != "" ){
1004                    
1005  //      if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) ){          //      if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) ){        
# Line 1007  TList*  PamLevel2::GetListOfLevel2Files( Line 1009  TList*  PamLevel2::GetListOfLevel2Files(
1009  //      }        //      }      
1010  //      flisttxt = fullpath;  //      flisttxt = fullpath;
1011    
1012          if ( !flisttxt.EndsWith(".root") ){
1013          flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));          flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1014    
1015          if( !gSystem->ChangeDirectory(ddir) ){          if( !gSystem->ChangeDirectory(ddir) ){
# Line 1047  TList*  PamLevel2::GetListOfLevel2Files( Line 1050  TList*  PamLevel2::GetListOfLevel2Files(
1050  //          };  //          };
1051          };          };
1052          in.close();          in.close();
1053                  } else {
1054              char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1055              contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
1056              delete fullpath;
1057          };      
1058      }else{      }else{
1059                    
1060          cout << "No input file list given."<<endl;          cout << "No input file list given."<<endl;
# Line 1497  TTree *PamLevel2::GetRunTree(TFile *f){ Line 1504  TTree *PamLevel2::GetRunTree(TFile *f){
1504          R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano          R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
1505          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
1506      }      }
1507    
1508        run_tree = (TChain*)R;
1509    
1510      return R;      return R;
1511            
1512  }  }
# Line 1522  Bool_t PamLevel2::UpdateRunInfo(TChain * Line 1532  Bool_t PamLevel2::UpdateRunInfo(TChain *
1532            run->GetEntry(0);            run->GetEntry(0);
1533            runfirstentry = 0ULL;            runfirstentry = 0ULL;
1534            runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS) - 1ULL;            runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS) - 1ULL;
1535        };        };      
1536        while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){  
1537          if( !GetOrbitalInfo() ){
1538              cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
1539              return(false);
1540          }
1541          // modificato il controllo sull'aggiornamento del run, per evitare problemi
1542          // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)
1543          while ( GetOrbitalInfo()->absTime > GetRunInfo()->RUNTRAILER_TIME && irun < run->GetEntries() ){
1544    //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){
1545            //    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)));
1546            irun++;            irun++;
1547            run->GetEntry(irun);            run->GetEntry(irun);
1548            runfirstentry = runlastentry+1ULL;            runfirstentry = runlastentry+1ULL;
1549            runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS);            runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS);
1550        };        };
1551          
1552        //        //
1553        if ( irun == oldrun || irun >= run->GetEntries() ) return(false);        if ( irun == oldrun || irun >= run->GetEntries() ) return(false);
1554        //        //
# Line 2208  void PamLevel2::CreateCloneTrees(TFile * Line 2227  void PamLevel2::CreateCloneTrees(TFile *
2227              pam_tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));              pam_tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));
2228              pam_tree_clone[i]->BranchRef();              pam_tree_clone[i]->BranchRef();
2229              cout << "Tracker      : branch TrkLevel1"<<endl;              cout << "Tracker      : branch TrkLevel1"<<endl;
2230                cout << "CreateCloneTrees " << GetTrkLevel1()<<endl;
2231          };          };
2232          if(TRK2) {          if(TRK2) {
2233              pam_tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));              pam_tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));
# Line 2289  void PamLevel2::CreateCloneTrees(TFile * Line 2309  void PamLevel2::CreateCloneTrees(TFile *
2309  void PamLevel2::FillCloneTrees(){  void PamLevel2::FillCloneTrees(){
2310            
2311  //    cout << "PamLevel2::FillCloneTrees()" << irunentry << endl;  //    cout << "PamLevel2::FillCloneTrees()" << irunentry << endl;
2312    
2313      for(Int_t i=0; i<NCLONES; i++){      for(Int_t i=0; i<NCLONES; i++){
2314          if(pam_tree_clone[i])pam_tree_clone[i]->Fill();          if(pam_tree_clone[i])pam_tree_clone[i]->Fill();
2315      }      }
2316      if(sel_tree_clone)sel_tree_clone->Fill();          if(sel_tree_clone)sel_tree_clone->Fill();    
2317  //    if( irunentry == 0 || run_tree_clone->GetEntries()==0 )run_tree_clone->Fill();  
     Int_t nstoredruns = run_tree_clone->GetEntries();  
     if( irun ==  nstoredruns )run_tree_clone->Fill();  
     else if( irun > nstoredruns || irun < nstoredruns-1){  
         cout << " PamLevel2::FillCloneTrees() -- ERROR -- current run "<< irun <<" stored runs "<< nstoredruns <<endl;  
     }  
2318  }  }
2319    
2320    
# Line 2339  void PamLevel2::WriteCloneTrees(){ Line 2355  void PamLevel2::WriteCloneTrees(){
2355  }  }
2356    
2357  /**  /**
2358   * Method to get both level2-trees entry and corresponding run entry.   * Method to get level2-trees entry, the corresponding run entry and (if required) the level0 entry.
2359   */   */
   
   
2360  Int_t PamLevel2::GetEntry(Int_t iee){  Int_t PamLevel2::GetEntry(Int_t iee){
2361            
2362      if(!pam_tree){      if(!pam_tree){
2363          cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- level2 trees not loeaded"<<endl;          cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- level2 trees not loaded"<<endl;
         return 0;  
     }  
     if(!run_tree ){  
         cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loeaded"<<endl;  
2364          return 0;          return 0;
2365      }      }
2366    
# Line 2359  Int_t PamLevel2::GetEntry(Int_t iee){ Line 2369  Int_t PamLevel2::GetEntry(Int_t iee){
2369      ii = iee;      ii = iee;
2370      if( !pam_tree->GetEntry(ii) ) return 0;      if( !pam_tree->GetEntry(ii) ) return 0;
2371      //-------------------------------      //-------------------------------
2372    
2373        if(!run_tree ){
2374            cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loaded"<<endl;
2375            return 0;
2376        }
2377    
2378      ii = iee;      ii = iee;
2379      UpdateRunInfo(run_tree,ii);      Bool_t UPDATED = UpdateRunInfo(run_tree,ii);
2380      if(SELLI==0)irunentry = iee-runfirstentry;      if(SELLI==0)irunentry = iee-runfirstentry;
2381        if(UPDATED && run_tree_clone)run_tree_clone->Fill();
2382    
2383  //    cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl;  //    cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl;
2384    
# Line 2392  TTree* PamLevel2::GetYodaTree( ){ Line 2409  TTree* PamLevel2::GetYodaTree( ){
2409          return NULL;          return NULL;
2410      }          }    
2411      Int_t irootnew = run_obj->ID_ROOT_L0;      Int_t irootnew = run_obj->ID_ROOT_L0;
2412  //    cout << "iroot    "<<iroot<<endl;  //     cout << "iroot    "<<iroot<<endl;
2413  //    cout << "irootnew "<<irootnew<<endl;  //     cout << "irootnew "<<irootnew<<endl;
2414    
2415      //===================================      //===================================
2416      // load the level0 file      // load the level0 file
# Line 2420  TTree* PamLevel2::GetYodaTree( ){ Line 2437  TTree* PamLevel2::GetYodaTree( ){
2437  //          cout<<"DB already connected"<<endl;  //          cout<<"DB already connected"<<endl;
2438          }          }
2439          GL_ROOT glroot = GL_ROOT();          GL_ROOT glroot = GL_ROOT();
2440          if( glroot.Query_GL_ROOT(iroot,dbc) )return NULL;          if( glroot.Query_GL_ROOT(iroot,dbc) ){
2441                cout << "TTree* PamLevel2::GetYodaTree( ) -- ERROR -- level0 file iroot = "<<iroot<< " does not exists"<<endl;
2442                return NULL;
2443            };
2444          TString filename = glroot.PATH + glroot.NAME;          TString filename = glroot.PATH + glroot.NAME;
2445          if(l0_file){          if(l0_file){
2446              l0_file->Close();              l0_file->Close();
# Line 2460  TTree* PamLevel2::GetYodaTree( ){ Line 2480  TTree* PamLevel2::GetYodaTree( ){
2480    
2481      };      };
2482    
2483    //    cout << l0_tree << endl;
2484        
2485      return l0_tree;      return l0_tree;
2486    
2487  }  }
# Line 2476  Int_t PamLevel2::GetYodaEntry(){ Line 2498  Int_t PamLevel2::GetYodaEntry(){
2498      //  if file is NOT a preselected file      //  if file is NOT a preselected file
2499      //  ---------------------------------      //  ---------------------------------
2500      Int_t quellagiusta = irunentry + run_obj->EV_FROM;      Int_t quellagiusta = irunentry + run_obj->EV_FROM;
2501      //  ------------------------------------------  
2502      //  otherwise read the "preselected-list" tree      if( !GetOrbitalInfo() ){
2503      //  ------------------------------------------          cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo "<<endl;
2504            return 0;
2505        }
2506    
2507        // ---------------------------------------------------------------------
2508        // ATTENTION!!!
2509        // If data are not pre-processed with cleaner, the level0 tree may contain
2510        // spurious nested physics packets.
2511        // The GL_RUN variables EV_FROM, EV_TO and NEVENTS counts also these entries
2512        // while level2 tree DOES NOT!!
2513        // This means that "quellagiusta" in these cases is not correct.
2514        // In order to retrieve the correct level0 event, I implemented a check
2515        // of the OBT and pkt-number. In case of mismatch, the level0 entry number
2516        // is shift forward until when the packets match.
2517        // ---------------------------------------------------------------------
2518        Int_t answer = 0;
2519        Int_t shift =0;
2520        do{
2521    //      if(shift>0){
2522    //          cout << " level0 <--> level2 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" )"<<endl;
2523    //      }
2524            answer = GetYodaTree()->GetEntry(quellagiusta+shift);
2525            shift++;
2526            if( !GetEventHeader() ){
2527                cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader "<<endl;
2528                return 0;
2529            }
2530    //      if( (quellagiusta+shift) == GetYodaTree()->GetEntries()+1 )cout << ">>> end of level0 tree <<<"<<endl;
2531        }while( ( (UInt_t)(GetOrbitalInfo()->OBT) != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || GetOrbitalInfo()->pkt_num != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())) && (quellagiusta+shift) < (UInt_t)(GetYodaTree()->GetEntries()) );
2532    
2533  //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;  //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;
2534      return GetYodaTree()->GetEntry(quellagiusta);  //    return GetYodaTree()->GetEntry(quellagiusta);
2535            
2536      return 1;      return answer;
2537            
2538  }  }

Legend:
Removed from v.1.20  
changed lines
  Added in v.1.25

  ViewVC Help
Powered by ViewVC 1.1.23