void skim() { //Get old file, old tree and set top branch address auto oldfile = TFile::Open("output_Coulomb_LER_study_100.root"); TChain* chain=new TChain("tree"); chain->Add("output_Coulomb_LER_study_100.root"); // Deactivate all branches chain->SetBranchStatus("*",0); // Activate 4 branches only: our skim chain->SetBranchStatus("StrSimHits",1); //Create a new file + a clone of old tree header. Do not copy events TFile * newfile = TFile::Open("small.root","recreate"); TTree * newtree = chain->CloneTree(0); // Here we copy the branches newtree->CopyEntries(chain); //newtree->CopyEntries(oldtree); // Flush to disk newfile->Write(); // Clean // delete oldfile; // delete newfile; }