#include "TreeRead.h" #include "TTree.h" #include "TChain.h" #include "TStopwatch.h" #include "TLorentzVector.h" #include #include using namespace std ; TreeRead::TreeRead() : fChain( 0 ) { reset(); } TreeRead::~TreeRead() {} void TreeRead::init( TTree* tree ) { // Set branch addresses and branch pointers if (!tree) return; fChain = tree; fCurrent = -1; fChain->SetMakeClass(1); fChain->SetBranchAddress("evNumber", &evNumber, &b_evNumber); fChain->SetBranchAddress("runNumber", &runNumber, &b_runNumber); fChain->SetBranchAddress("numberOfTrack", &numberOfTrack, &b_numberOfTrack); fChain->SetBranchAddress("pt", &pt, &b_pt); fChain->SetBranchAddress("ptError", &ptError, &b_ptError); fChain->SetBranchAddress("p", &p, &b_p); fChain->SetBranchAddress("px", &px, &b_px); fChain->SetBranchAddress("py", &py, &b_py); fChain->SetBranchAddress("pz", &pz, &b_pz); fChain->SetBranchAddress("eta", &eta, &b_eta); fChain->SetBranchAddress("etaError", &etaError, &b_etaError); fChain->SetBranchAddress("phi", &phi, &b_phi); fChain->SetBranchAddress("phiError", &phiError, &b_phiError); fChain->SetBranchAddress("dxy_PV", &dxy_PV, &b_dxy_PV); fChain->SetBranchAddress("dxy_0", &dxy_0, &b_dxy_0); fChain->SetBranchAddress("dxyError", &dxyError, &b_dxyError); fChain->SetBranchAddress("dz", &dz, &b_dz); fChain->SetBranchAddress("dzError", &dzError, &b_dzError); fChain->SetBranchAddress("d0", &d0, &b_d0); fChain->SetBranchAddress("d0Error", &d0Error, &b_d0Error); fChain->SetBranchAddress("normalizedChi2", &normalizedChi2, &b_normalizedChi2); // fChain->SetBranchAddress("newdEdx1", &newdEdx1, &b_newdEdx1); // fChain->SetBranchAddress("olddEdx1", &olddEdx1, &b_olddEdx1); fChain->SetBranchAddress("chi2", &chi2, &b_chi2); fChain->SetBranchAddress("ndof", &ndof, &b_ndof); // fChain->SetBranchAddress("trk_algo", &trk_algo, &b_trk_algo); fChain->SetBranchAddress("beamSpot_x", &beamSpot_x, &b_beamSpot_x); fChain->SetBranchAddress("referencePoint_x", &referencePoint_x, &b_referencePoint_x); fChain->SetBranchAddress("innerPosition_x", &innerPosition_x, &b_innerPosition_x); fChain->SetBranchAddress("outerPosition_x", &outerPosition_x, &b_outerPosition_x); fChain->SetBranchAddress("beamSpot_y", &beamSpot_y, &b_beamSpot_y); fChain->SetBranchAddress("referencePoint_y", &referencePoint_y, &b_referencePoint_y); fChain->SetBranchAddress("innerPosition_y", &innerPosition_y, &b_innerPosition_y); fChain->SetBranchAddress("outerPosition_y", &outerPosition_y, &b_outerPosition_y); fChain->SetBranchAddress("beamSpot_z", &beamSpot_z, &b_beamSpot_z); fChain->SetBranchAddress("referencePoint_z", &referencePoint_z, &b_referencePoint_z); fChain->SetBranchAddress("innerPosition_z", &innerPosition_z, &b_innerPosition_z); fChain->SetBranchAddress("outerPosition_z", &outerPosition_z, &b_outerPosition_z); fChain->SetBranchAddress("charge", &charge, &b_charge); fChain->SetBranchAddress("trk_jetRef", &trk_jetRef, &b_trk_jetRef); fChain->SetBranchAddress("numberOfvalidHits", &numberOfvalidHits, &b_numberOfvalidHits); fChain->SetBranchAddress("numberOfLostHits", &numberOfLostHits, &b_numberOfLostHits); fChain->SetBranchAddress("highPurity_track", &highPurity_track, &b_highPurity_track); fChain->SetBranchAddress("numberOfJet", &numberOfJet, &b_numberOfJet); fChain->SetBranchAddress("jet_px", &jet_px, &b_jet_px); fChain->SetBranchAddress("jet_py", &jet_py, &b_jet_py); fChain->SetBranchAddress("jet_pz", &jet_pz, &b_jet_pz); fChain->SetBranchAddress("jet_energy", &jet_energy, &b_jet_energy); fChain->SetBranchAddress("jet_eta", &jet_eta, &b_jet_eta); fChain->SetBranchAddress("jet_phi", &jet_phi, &b_jet_phi); fChain->SetBranchAddress("jet_ecfr", &jet_ecfr, &b_jet_ecfr); fChain->SetBranchAddress("jet_enfr", &jet_enfr, &b_jet_enfr); fChain->SetBranchAddress("jet_hcfr", &jet_hcfr, &b_jet_hcfr); fChain->SetBranchAddress("jet_hnfr", &jet_hnfr, &b_jet_hnfr); fChain->SetBranchAddress("jet_mass", &jet_mass, &b_jet_mass); fChain->SetBranchAddress("jet_ene_c3", &jet_ene_c3, &b_jet_ene_c3); fChain->SetBranchAddress("Genp_status", &Genp_status, &b_Genp_status); fChain->SetBranchAddress("Genp_Id", &Genp_Id, &b_Genp_Id); // fChain->SetBranchAddress("Genp_vMom", &Genp_vMom, &b_Genp_vMom); // fChain->SetBranchAddress("Genp_vDau", &Genp_vDau, &b_Genp_vDau); fChain->SetBranchAddress("Genp_charge", &Genp_charge, &b_Genp_charge); fChain->SetBranchAddress("Genp_pt", &Genp_pt, &b_Genp_pt); fChain->SetBranchAddress("Genp_eta", &Genp_eta, &b_Genp_eta); fChain->SetBranchAddress("Genp_phi", &Genp_phi, &b_Genp_phi); // fChain->SetBranchAddress("Genp_mass", &Genp_mass, &b_Genp_mass); fChain->SetBranchAddress("Genp_vx", &Genp_vx, &b_Genp_vx); fChain->SetBranchAddress("Genp_vy", &Genp_vy, &b_Genp_vy); fChain->SetBranchAddress("Genp_vz", &Genp_vz, &b_Genp_vz); // fChain->SetBranchAddress("DeltaR_clst", &DeltaR_clst, &b_DeltaR_clst); // fChain->SetBranchAddress("DeltaPt_clst", &DeltaPt_clst, &b_DeltaPt_clst); // fChain->SetBranchAddress("Genp_idx_clst", &Genp_idx_clst, &b_Genp_idx_clst); Notify(); return; } Bool_t TreeRead::Notify() { // The Notify() function is called when a new file is opened. This // can be either for a new TTree in a TChain or when when a new TTree // is started when using PROOF. It is normally not necessary to make changes // to the generated code, but the routine can be extended by the // user if needed. The return value is currently not used. return kTRUE; } void TreeRead::getBranches() { return; } void TreeRead::reset() { // Set object pointer pt = 0; ptError = 0; p = 0; px = 0; py = 0; pz = 0; eta = 0; etaError = 0; phi = 0; phiError = 0; dxy_PV = 0; dxy_0 = 0; dxyError = 0; dz = 0; dzError = 0; d0 = 0; d0Error = 0; normalizedChi2 = 0; newdEdx1 = 0; olddEdx1 = 0; chi2 = 0; ndof = 0; trk_algo = 0; beamSpot_x = 0; referencePoint_x = 0; innerPosition_x = 0; outerPosition_x = 0; beamSpot_y = 0; referencePoint_y = 0; innerPosition_y = 0; outerPosition_y = 0; beamSpot_z = 0; referencePoint_z = 0; innerPosition_z = 0; outerPosition_z = 0; charge = 0; trk_jetRef = 0; numberOfvalidHits = 0; numberOfLostHits = 0; highPurity_track = 0; jet_px = 0; jet_py = 0; jet_pz = 0; jet_energy = 0; jet_eta = 0; jet_phi = 0; jet_ecfr = 0; jet_enfr = 0; jet_hcfr = 0; jet_hnfr = 0; jet_mass = 0; jet_ene_c3 = 0; Genp_status = 0; Genp_Id = 0; Genp_vMom = 0; Genp_vDau = 0; Genp_charge = 0; Genp_pt = 0; Genp_eta = 0; Genp_phi = 0; Genp_mass = 0; Genp_vx = 0; Genp_vy = 0; Genp_vz = 0; DeltaR_clst = 0; DeltaPt_clst = 0; Genp_idx_clst = 0; } Int_t TreeRead::GetEntry(Long64_t entry) { // Read contents of entry. if (!fChain) return 0; return fChain->GetEntry(entry); } Long64_t TreeRead::LoadTree(Long64_t entry) { // Set the environment to read one entry if (!fChain) return -5; Long64_t centry = fChain->LoadTree(entry); if (centry < 0) return centry; if (!fChain->InheritsFrom(TChain::Class())) return centry; TChain *chain = (TChain*)fChain; if (chain->GetTreeNumber() != fCurrent) { fCurrent = chain->GetTreeNumber(); Notify(); } return centry; } void TreeRead::Show(Long64_t entry) { // Print contents of entry. // If entry is not specified, print current entry if (!fChain) return; fChain->Show(entry); } void TreeRead::LoopMix( int evtmax ) { // initialize timer TStopwatch Twatch ; double TotalTime(0) ; // get number of events int evtnum = static_cast( fChain->GetEntries() ); // last required event if ( evtmax > evtnum ) evtmax = evtnum; // user initialization begin_analysis() ; cout << " # ==> Start analysis. Process " << evtmax << " events " << endl << endl ; // first loop over all events loop( evtmax ) ; return ; // then sort events vector SortedList ; SortedList = EvtSort() ; cout << " List size " << SortedList.size() << endl ; // return ; // for( int i=0 ; i< evtmax ; i++ ){ SortedList.push_back(i) ; } // then proceed to mxing Long64_t nbytes(0) ; // loop over all events vector ch1 ; vector ch2 ; vector tk1 ; vector tk2 ; // for ( int jentry = 0 ; jentry < SortedList.size()-1 ; jentry +=2 ) { // first entry if( jentry%1000 == 0 ) { cout << " At Event " << jentry << " of " << evtmax << " Elapsed Time " << Twatch.CpuTime() << " Total Time " << TotalTime << endl; TotalTime += Twatch.CpuTime() ; Twatch.Start() ; } int entry_1(-1), entry_2(-1) ; // entry_1 = SortedList.at( jentry ) ; // entry_2 = SortedList.at( jentry+1 ) ; SelectPair( jentry, entry_1, entry_2 ) ; // entry_1 = jentry ; // entry_2 = jentry+1 ; if( entry_1 < 0 || entry_2 < 0 ) continue ; if( jentry<20 ) cout << " selected " << jentry << " " << entry_1 << " " << entry_2 << endl ; if( LoadTree(entry_1) < 0 ) break ; nbytes += fChain->GetEntry( entry_1 ); tk1.erase( tk1.begin(), tk1.end() ) ; ch1.erase( ch1.begin(), ch1.end() ) ; analyze( -1, ch1, tk1 ); // 2nd entry if( LoadTree(entry_2) < 0 ) break ; nbytes += fChain->GetEntry( entry_2 ); tk2.erase( tk2.begin(), tk2.end() ) ; ch2.erase( ch2.begin(), ch2.end() ) ; analyze( -1, ch2, tk2 ); MixEvents( ch1, tk1 , ch2, tk2 ) ; } cout << endl << " # ==> End analysis. Processed " << evtmax << " events " << endl ; end_analysis() ; return; } void TreeRead::loop( int evtmax, int ifirst ) { // initialize timer TStopwatch Twatch ; double TotalTime(0) ; // get number of events int evtnum = static_cast( fChain->GetEntries() ); // last required event evtmax += ifirst; if ( evtmax > evtnum ) evtmax = evtnum; // user initialization begin_analysis() ; cout << " # ==> Start analysis. Process " << evtmax << " events " << endl << endl ; Long64_t nbytes(0) ; // loop over all events for ( int jentry = ifirst; jentry < evtmax; jentry++ ) { // read tree Long64_t ientry = LoadTree(jentry); if (ientry < 0) break; nbytes += fChain->GetEntry( jentry ); static int j=1; if ((ientry%j)==0) { double Time = Twatch.CpuTime() ; TotalTime += Time ; if ((ientry/j)==9) j*=10; cout << " Num " << ientry << " Run:Event analyzed " << runNumber << ":" << evNumber << " Elapsed Time " << Twatch.CpuTime() << " Total Time " << TotalTime << endl; Twatch.Start() ; } analyze( jentry ); } cout << endl << " # ==> End analysis. Processed " << evtmax << " events " << endl ; end_analysis() ; return; } // dummy routines // void TreeRead::analyze( int entry ) {}