If you mean, you want to select certain events, then you can use TTree::CopyTree
.
If you mean, copy only certain branches, then you can disable branches you don’t want to see in the new file:
auto inFile = TFile::Open("in.root");
auto tree = (TTree*) inFile->Get("tree_name");
// Disable all branches
tree->SetBranchStatus("*", kFALSE);
// Re-enable desired branches
tree->SetBranchStatus("mass", kTRUE);
...
auto newFile = new TFile("out.root", "recreate");
// Copy only those parts of the tree for which the selection string is true
// Note that any branch needed in the selection needs to be enabled (and will therefore also be copied)
auto newTree = tree->CopyTree("mass > 100");
newTree->Write();
newFile->Write();
newFile->Close();
If you want to add branches whose value depends on some of the old branches, have a look at my post about a function that accomplishes that: Add a new branch to a tree given only a formula
All of this will hopefully become way easier, as soon as ROOT 6.10 is published with its TDataFrame
.