#define tree_cxx #include "tree.h" #include #include #include #include "TLorentzVector.h" #include #include #include #include #include using namespace std; void tree::Loop() { // In a ROOT session, you can do: // Root > .L tree.C // Root > tree t // Root > t.GetEntry(12); // Fill t data members with entry number 12 // Root > t.Show(); // Show values of entry 12 // Root > t.Show(16); // Read and show values of entry 16 // Root > t.Loop(); // Loop on all entries // This is the loop skeleton where: // jentry is the global entry number in the chain // ientry is the entry number in the current Tree // Note that the argument to GetEntry must be: // jentry for TChain::GetEntry // ientry for TTree::GetEntry and TBranch::GetEntry // // To read only selected branches, Insert statements like: // METHOD1: // fChain->SetBranchStatus("*",0); // disable all branches // fChain->SetBranchStatus("branchname",1); // activate branchname // METHOD2: replace line // fChain->GetEntry(jentry); //read all branches //by b_branchname->GetEntry(ientry); //read only this branch if (fChain == 0) return; fChain->SetBranchStatus("*", 0); // disable all branches std::ifstream file("sample2.txt"); std::string str; while (std::getline(file, str)) { fChain->SetBranchStatus(str.c_str(),"1"); } TH1D *jetpt = new TH1D("jetpt", "GeV/c", 150, 0, 2300); TLorentzVector l1,l2,jet_i; vector nlep; Long64_t nentries = fChain->GetEntriesFast(); vector> jet_pt; TFile *nfile = new TFile("delete2.root","recreate"); // TTree *ntree = new TTree("ntree","ntree"); TTree *tree = fChain->CloneTree(0); tree->Branch("jet_pt",&jet_pt); // tree->Branch("nlep",&nlep); vector jet_pt_row ; Long64_t nbytes = 0, nb = 0,a=0,b=0,si=0; for (Long64_t jentry=0; jentry<100;jentry++) { Long64_t ientry = LoadTree(jentry); if (ientry < 0) break; nb = fChain->GetEntry(jentry); nbytes += nb; // TFile *nfile = TFile::Open("delete1.root","update"); // TTree *ntree = (TTree*)nfile->Get("ntree"); b=0; // vector jet_pt_row[nJet] ; for (Int_t j = 0; j Fill(Jet_pt[j]); jet_pt_row.push_back(jet_i.Pt()); } jet_pt.push_back(jet_pt_row); a=a+1; cout<Fill(); } cout<Draw(); nfile->cd(); tree->Print(); tree->AutoSave(); nfile->Close(); cout<