// This is based on copyTree2.C, but without the TEvent ... // Might not work for ROOT versions < 3.02/07. void copy() { // -- Get old file, old tree and set top branch address TFile *oldfile = new TFile("bigfile.root"); TTree *oldtree = (TTree*)oldfile->Get("h300"); // -- Disable all branches ... oldtree->SetBranchStatus("*",0); // -- ... and switch on those you'd like to write out into the new tree oldtree->SetBranchStatus("charge",1); oldtree->SetBranchStatus("theta",1); oldtree->SetBranchStatus("ecal",1); oldtree->SetBranchStatus("phi",1); oldtree->SetBranchStatus("p",1); oldtree->SetBranchStatus("phiatemc",1); oldtree->SetBranchStatus("thetaatemc",1); oldtree->SetBranchStatus("runnumber",1); //-- Create a new file + a clone of old tree in new file TFile *newfile = new TFile("smallfile.root","recreate"); TTree *newtree = oldtree->CloneTree(); newtree->Print(); newfile->Write(); delete oldfile; delete newfile; }