/[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.30 by mocchiut, Sun Mar 18 20:25:54 2007 UTC
# Line 103  PamLevel2::PamLevel2(){ Line 103  PamLevel2::PamLevel2(){
103            
104      h0_obj    = 0;      h0_obj    = 0;
105      trk0_obj  = 0;      trk0_obj  = 0;
106        calo0_obj  = 0;
107    
108      trk2_obj  = 0;      trk2_obj  = 0;
109      trk1_obj  = 0;      trk1_obj  = 0;
# Line 126  PamLevel2::PamLevel2(){ Line 127  PamLevel2::PamLevel2(){
127      l0_tree = NULL;      l0_tree = NULL;
128      iroot   = -1;      iroot   = -1;
129      dbc     = 0;      dbc     = 0;
130    
131        prevshift = 0;
132            
133      irun = -1;      irun = -1;
134      run_tree = NULL;      run_tree = NULL;
# Line 188  void PamLevel2::Delete(){ Line 191  void PamLevel2::Delete(){
191  //    cout << "void PamLevel2::Clear()"<<endl;  //    cout << "void PamLevel2::Clear()"<<endl;
192      if(h0_obj)   delete h0_obj;      if(h0_obj)   delete h0_obj;
193      if(trk0_obj) delete trk0_obj;            if(trk0_obj) delete trk0_obj;      
194        if(calo0_obj) delete calo0_obj;    
195      if(trk1_obj) delete trk1_obj;            if(trk1_obj) delete trk1_obj;      
196      if(trk2_obj) delete trk2_obj;      if(trk2_obj) delete trk2_obj;
197      if(trkh_obj) delete trkh_obj;      if(trkh_obj) delete trkh_obj;
# Line 242  void PamLevel2::Clear(){ Line 246  void PamLevel2::Clear(){
246    
247      if(h0_obj)   h0_obj->Clear();            if(h0_obj)   h0_obj->Clear();      
248      if(trk0_obj) trk0_obj->Clear();          if(trk0_obj) trk0_obj->Clear();    
249        if(calo0_obj) calo0_obj->Clear();  
250      if(trk1_obj) trk1_obj->Clear();          if(trk1_obj) trk1_obj->Clear();    
251      if(trk2_obj) trk2_obj->Clear();      if(trk2_obj) trk2_obj->Clear();
252      if(trkh_obj) trkh_obj->Clear();      if(trkh_obj) trkh_obj->Clear();
# Line 554  void PamLevel2::SortTracks(TString how){ Line 559  void PamLevel2::SortTracks(TString how){
559                  use_CAL            &&                  use_CAL            &&
560                  calo2_obj->npcfit[1] > 15     &&   //no. of fit planes on Y view                  calo2_obj->npcfit[1] > 15     &&   //no. of fit planes on Y view
561                  calo2_obj->varcfit[1] < 1000. &&  //fit variance on Y view                  calo2_obj->varcfit[1] < 1000. &&  //fit variance on Y view
562                    cp && ci &&
563                  true){                  true){
564    
565                                    
# Line 575  void PamLevel2::SortTracks(TString how){ Line 581  void PamLevel2::SortTracks(TString how){
581                  cout << "void PamLevel2::SortTracks(TString how): how= "<<how<<" but ToFLevel2 not loaded !!!";                  cout << "void PamLevel2::SortTracks(TString how): how= "<<how<<" but ToFLevel2 not loaded !!!";
582                  return;                  return;
583              };              };
584              if( use_TOF ){              if( use_TOF && op && oi ){
585                                    
586                  Int_t nphit_p =0;                  Int_t nphit_p =0;
587                  Int_t nphit_i =0;                  Int_t nphit_i =0;
# Line 968  TTree *PamLevel2::GetPamTree(TFile *f, T Line 974  TTree *PamLevel2::GetPamTree(TFile *f, T
974      };      };
975            
976      cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;      cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
977    
978        pam_tree = (TChain*)Trout;
979            
980      return Trout;      return Trout;
981            
# Line 1006  TList*  PamLevel2::GetListOfLevel2Files( Line 1014  TList*  PamLevel2::GetListOfLevel2Files(
1014  //          return 0;  //          return 0;
1015  //      }        //      }      
1016  //      flisttxt = fullpath;  //      flisttxt = fullpath;
1017          if ( !flisttxt.EndsWith(".root") ){
1018    
1019          flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));          flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1020    
# Line 1047  TList*  PamLevel2::GetListOfLevel2Files( Line 1056  TList*  PamLevel2::GetListOfLevel2Files(
1056  //          };  //          };
1057          };          };
1058          in.close();          in.close();
1059                  } else {
1060              char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1061              contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
1062              delete fullpath;
1063          };        
1064      }else{      }else{
1065                    
1066          cout << "No input file list given."<<endl;          cout << "No input file list given."<<endl;
# Line 1497  TTree *PamLevel2::GetRunTree(TFile *f){ Line 1510  TTree *PamLevel2::GetRunTree(TFile *f){
1510          R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano          R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
1511          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
1512      }      }
1513    
1514        run_tree = (TChain*)R;
1515    
1516      return R;      return R;
1517            
1518  }  }
# Line 1519  Bool_t PamLevel2::UpdateRunInfo(TChain * Line 1535  Bool_t PamLevel2::UpdateRunInfo(TChain *
1535    if(SELLI==0){    if(SELLI==0){
1536        if ( irun < 0 ){        if ( irun < 0 ){
1537            irun = 0;            irun = 0;
1538            run->GetEntry(0);            run->GetEntry(irun);
1539            runfirstentry = 0ULL;            runfirstentry = 0ULL;
1540            runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS) - 1ULL;            runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS);
1541        };            if ( (ULong64_t)(this->GetRunInfo()->NEVENTS) > 0ULL ) runlastentry -= 1ULL;
1542        while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){            return(true);
1543            //    printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));        };      
1544    
1545          if( !GetOrbitalInfo() ){
1546              cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
1547              return(false);
1548          }
1549          // modificato il controllo sull'aggiornamento del run, per evitare problemi
1550          // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)
1551          while ( GetOrbitalInfo()->absTime > GetRunInfo()->RUNTRAILER_TIME && irun < run->GetEntries() ){
1552    //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){
1553    //      printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));
1554            irun++;            irun++;
1555            run->GetEntry(irun);            run->GetEntry(irun);
1556            runfirstentry = runlastentry+1ULL;            runfirstentry = runlastentry;
1557              if ( (ULong64_t)(this->GetRunInfo()->NEVENTS) > 0ULL ) runfirstentry += 1ULL;
1558            runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS);            runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS);
1559        };        };
1560          
1561        //        //
1562        if ( irun == oldrun || irun >= run->GetEntries() ) return(false);        if ( irun == oldrun || irun >= run->GetEntries() ) return(false);
1563        //        //
# Line 2208  void PamLevel2::CreateCloneTrees(TFile * Line 2236  void PamLevel2::CreateCloneTrees(TFile *
2236              pam_tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));              pam_tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));
2237              pam_tree_clone[i]->BranchRef();              pam_tree_clone[i]->BranchRef();
2238              cout << "Tracker      : branch TrkLevel1"<<endl;              cout << "Tracker      : branch TrkLevel1"<<endl;
2239                cout << "CreateCloneTrees " << GetTrkLevel1()<<endl;
2240          };          };
2241          if(TRK2) {          if(TRK2) {
2242              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 2318  void PamLevel2::CreateCloneTrees(TFile *
2318  void PamLevel2::FillCloneTrees(){  void PamLevel2::FillCloneTrees(){
2319            
2320  //    cout << "PamLevel2::FillCloneTrees()" << irunentry << endl;  //    cout << "PamLevel2::FillCloneTrees()" << irunentry << endl;
2321    
2322      for(Int_t i=0; i<NCLONES; i++){      for(Int_t i=0; i<NCLONES; i++){
2323          if(pam_tree_clone[i])pam_tree_clone[i]->Fill();          if(pam_tree_clone[i])pam_tree_clone[i]->Fill();
2324      }      }
2325      if(sel_tree_clone)sel_tree_clone->Fill();          if(sel_tree_clone)sel_tree_clone->Fill();    
2326  //    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;  
     }  
2327  }  }
2328    
2329    
# Line 2339  void PamLevel2::WriteCloneTrees(){ Line 2364  void PamLevel2::WriteCloneTrees(){
2364  }  }
2365    
2366  /**  /**
2367   * 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.
2368   */   */
   
   
2369  Int_t PamLevel2::GetEntry(Int_t iee){  Int_t PamLevel2::GetEntry(Int_t iee){
2370            
2371      if(!pam_tree){      if(!pam_tree){
2372          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;  
2373          return 0;          return 0;
2374      }      }
2375    
2376    
2377        //
2378        // This is a sort of bug: if you don't have the run tree you don't want to exit here you want to have loaded the event anyway...
2379        //
2380        //    if(!run_tree ){
2381        //  cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loeaded"<<endl;
2382        //  return 0;
2383        //    }
2384    
2385      Int_t ii=0;      Int_t ii=0;
2386      //-------------------------------      //-------------------------------
2387      ii = iee;      ii = iee;
2388      if( !pam_tree->GetEntry(ii) ) return 0;      if( !pam_tree->GetEntry(ii) ) return 0;
2389    
2390        //
2391        // ... 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.
2392        // 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
2393        // a problem if you don't check the return code of getentry.
2394        //
2395        if(!run_tree ){
2396            if ( TRK0 || CAL0 || TOF0 || RUN ) { //forse cosi` va bene per tornare 1?
2397                    cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loaded"<<endl;
2398                    return 0;
2399            }  else {
2400                    return 1; //cosi` se non c'e` run esce qua...
2401            }
2402        }
2403    
2404      //-------------------------------      //-------------------------------
2405      ii = iee;      ii = iee;
2406      UpdateRunInfo(run_tree,ii);      Bool_t UPDATED = UpdateRunInfo(run_tree,ii);
2407      if(SELLI==0)irunentry = iee-runfirstentry;      if(SELLI==0)irunentry = iee-runfirstentry;
2408        if(UPDATED && run_tree_clone)run_tree_clone->Fill();
2409    
2410  //    cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl;  //    cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl;
2411    
# Line 2392  TTree* PamLevel2::GetYodaTree( ){ Line 2436  TTree* PamLevel2::GetYodaTree( ){
2436          return NULL;          return NULL;
2437      }          }    
2438      Int_t irootnew = run_obj->ID_ROOT_L0;      Int_t irootnew = run_obj->ID_ROOT_L0;
2439  //    cout << "iroot    "<<iroot<<endl;  //     cout << "iroot    "<<iroot<<endl;
2440  //    cout << "irootnew "<<irootnew<<endl;  //     cout << "irootnew "<<irootnew<<endl;
2441    
2442      //===================================      //===================================
2443      // load the level0 file      // load the level0 file
# Line 2420  TTree* PamLevel2::GetYodaTree( ){ Line 2464  TTree* PamLevel2::GetYodaTree( ){
2464  //          cout<<"DB already connected"<<endl;  //          cout<<"DB already connected"<<endl;
2465          }          }
2466          GL_ROOT glroot = GL_ROOT();          GL_ROOT glroot = GL_ROOT();
2467          if( glroot.Query_GL_ROOT(iroot,dbc) )return NULL;          if( glroot.Query_GL_ROOT(iroot,dbc) ){
2468                cout << "TTree* PamLevel2::GetYodaTree( ) -- ERROR -- level0 file iroot = "<<iroot<< " does not exists"<<endl;
2469                return NULL;
2470            };
2471          TString filename = glroot.PATH + glroot.NAME;          TString filename = glroot.PATH + glroot.NAME;
2472          if(l0_file){          if(l0_file){
2473              l0_file->Close();              l0_file->Close();
# Line 2437  TTree* PamLevel2::GetYodaTree( ){ Line 2484  TTree* PamLevel2::GetYodaTree( ){
2484          l0_tree = (TTree*)l0_file->Get("Physics");          l0_tree = (TTree*)l0_file->Get("Physics");
2485          if(!h0_obj)h0_obj = new EventHeader();          if(!h0_obj)h0_obj = new EventHeader();
2486          l0_tree->SetBranchAddress("Header" ,&h0_obj);          l0_tree->SetBranchAddress("Header" ,&h0_obj);
2487            prevshift = 0;
2488          //---------------------------------------------------          //---------------------------------------------------
2489          // TRACKER:          // TRACKER:
2490          if(TRK0){          if(TRK0){
# Line 2445  TTree* PamLevel2::GetYodaTree( ){ Line 2493  TTree* PamLevel2::GetYodaTree( ){
2493                  trk0_obj->Set();                  trk0_obj->Set();
2494              };              };
2495              l0_tree->SetBranchAddress("Tracker" ,trk0_obj->GetPointerToTrackerEvent());              l0_tree->SetBranchAddress("Tracker" ,trk0_obj->GetPointerToTrackerEvent());
             TrkParams::SetCalib(run_obj,dbc);  
2496          }          }
2497          //---------------------------------------------------          //---------------------------------------------------
2498          // CALORIMETER:          // CALORIMETER:
2499          if(CAL0){          if(CAL0){
2500              cout << "PamLevel2::GetYodaTree() --- level0 calorimeter not implemented "<<endl;              if(!calo0_obj){
2501                    calo0_obj = new CaloLevel0();
2502                    calo0_obj->Set();
2503                };
2504                l0_tree->SetBranchAddress("Calorimeter" ,calo0_obj->GetPointerToCalorimeterEvent());
2505                //      cout << "PamLevel2::GetYodaTree() --- level0 calorimeter not implemented "<<endl;
2506          }          }
2507          //---------------------------------------------------          //---------------------------------------------------
2508          // TOF:          // TOF:
# Line 2460  TTree* PamLevel2::GetYodaTree( ){ Line 2512  TTree* PamLevel2::GetYodaTree( ){
2512    
2513      };      };
2514    
2515        if(!dbc || (dbc && !dbc->IsConnected())){
2516            cout << " TTree* PamLevel2::GetYodaTree( ) -- no DB connected... hai fatto qualche cazzata "<<endl;
2517        }
2518    
2519        if ( TRK0 ) TrkParams::SetCalib(run_obj,dbc);
2520    
2521    
2522    //    cout << l0_tree << endl;
2523        
2524      return l0_tree;      return l0_tree;
2525    
2526  }  }
# Line 2472  Int_t PamLevel2::GetYodaEntry(){ Line 2533  Int_t PamLevel2::GetYodaEntry(){
2533  //    cout << "Int_t PamLevel2::GetYodaEntry()"<<endl;  //    cout << "Int_t PamLevel2::GetYodaEntry()"<<endl;
2534      if(!GetYodaTree())return 0;      if(!GetYodaTree())return 0;
2535            
2536        // patch
2537        if( (Int_t)irunentry < 0){
2538            cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl;
2539            irunentry=0;
2540        }
2541      //  ---------------------------------      //  ---------------------------------
2542      //  if file is NOT a preselected file      //  if file is NOT a preselected file
2543      //  ---------------------------------      //  ---------------------------------
2544      Int_t quellagiusta = irunentry + run_obj->EV_FROM;      UInt_t quellagiusta = irunentry + run_obj->EV_FROM;
2545      //  ------------------------------------------      
2546      //  otherwise read the "preselected-list" tree  
2547      //  ------------------------------------------  //     cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;
2548    //     cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;
2549    //     cout << " time "<< GetOrbitalInfo()->absTime << endl;
2550    //     cout << " trk_calib_used "<<run_obj->TRK_CALIB_USED<< endl;
2551        
2552        if( !GetOrbitalInfo() ){
2553            cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo "<<endl;
2554            return 0;
2555        }
2556    
2557        // ---------------------------------------------------------------------
2558        // ATTENTION!!!
2559        // If data are not pre-processed with cleaner, the level0 tree may contain
2560        // spurious nested physics packets.
2561        // The GL_RUN variables EV_FROM, EV_TO and NEVENTS counts also these entries
2562        // while level2 tree DOES NOT!!
2563        // This means that "quellagiusta" in these cases is not correct.
2564        // In order to retrieve the correct level0 event, I implemented a check
2565        // of the OBT and pkt-number. In case of mismatch, the level0 entry number
2566        // is shift forward until when the packets match.
2567        // ---------------------------------------------------------------------
2568        Int_t answer = 0;
2569        Int_t shift =0;
2570        do{
2571            if(shift>0){    
2572              cout << " level0 <--> level2 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" )"<<endl;
2573            }
2574            answer = l0_tree->GetEntry(quellagiusta+shift+prevshift);
2575            shift++;
2576            if( !GetEventHeader() ){
2577                cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader "<<endl;
2578                return 0;
2579            }
2580    //      if( (quellagiusta+shift) == l0_tree->GetEntries()+1 )cout << ">>> end of level0 tree <<<"<<endl;
2581    //      cout << " GetOrbitalInfo()->OBT "<< GetOrbitalInfo()->OBT << endl;
2582    //      cout << " GetEventHeader()->GetPscuHeader()->GetOrbitalTime() "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime() << endl;
2583    //      cout << " GetOrbitalInfo()->pkt_num "<< GetOrbitalInfo()->pkt_num << endl;
2584    //      cout << " GetEventHeader()->GetPscuHeader()->GetCounter() "<< GetEventHeader()->GetPscuHeader()->GetCounter() << endl;
2585            if ( prevshift != 0 && (quellagiusta+shift) == GetYodaTree()->GetEntries() ){
2586              prevshift = 0;
2587              shift = -1;
2588            };
2589    
2590        }while( ( GetOrbitalInfo()->OBT != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || GetOrbitalInfo()->pkt_num != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())) && (quellagiusta+shift) < GetYodaTree()->GetEntries() );
2591    
2592        if ( (quellagiusta+shift) == GetYodaTree()->GetEntries() ) cout << " Big trouble here, no such event in Level0 data! " <<endl;
2593    
2594  //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;  //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;
2595      return GetYodaTree()->GetEntry(quellagiusta);  //    return GetYodaTree()->GetEntry(quellagiusta);
2596        if ( shift > 1 ) prevshift += (shift-1);
2597            
2598      return 1;      return answer;
2599            
2600  }  }
2601    
2602    

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

  ViewVC Help
Powered by ViewVC 1.1.23