void TruncateTree(string locInputFileName, string locTreeName, int locNumEntries) { int locNumFinalStateParticles; //Get old file, old tree and set top branch address TFile *locInputFile = new TFile(locInputFileName.c_str()); TTree *locInputTree = (TTree*)locInputFile->Get(locTreeName.c_str()); Long64_t locNumTreeEntries = locInputTree->GetEntries(); int m_nPart; float m_e[3]; float m_px[3]; float m_py[3]; float m_pz[3]; float m_eBeam; float m_pxBeam; float m_pyBeam; float m_pzBeam; float m_weight; locInputTree->SetBranchAddress("NumFinalState", &m_nPart); locInputTree->SetBranchAddress("E_FinalState", m_e); locInputTree->SetBranchAddress("Px_FinalState", m_px); locInputTree->SetBranchAddress("Py_FinalState", m_py); locInputTree->SetBranchAddress("Pz_FinalState", m_pz); locInputTree->SetBranchAddress("E_Beam", &m_eBeam); locInputTree->SetBranchAddress("Px_Beam", &m_pxBeam); locInputTree->SetBranchAddress("Py_Beam", &m_pyBeam); locInputTree->SetBranchAddress("Pz_Beam", &m_pzBeam); if(locInputTree->GetBranch("Weight") != NULL) locInputTree->SetBranchAddress("Weight", &m_weight); //Create a new file + a clone of old tree in new file string locOutputFileName = locInputFileName.substr(0, locInputFileName.size() - 5) + string(".trunc.root"); TFile *locOutputFile = new TFile(locOutputFileName.c_str(), "RECREATE"); TTree *locOutputTree = locInputTree->CloneTree(0); int locActualNumEntries = locNumEntries; if(locActualNumEntries > locNumTreeEntries) locActualNumEntries = locNumTreeEntries; for(Long64_t loc_i = 0; loc_i < locActualNumEntries; ++loc_i) { locInputTree->GetEntry(loc_i); locOutputTree->Fill(); } locOutputTree->AutoSave(); delete locInputFile; delete locOutputFile; }