Deleting TBranch in a TTree

Hello everybody,

Does someone know whether it is possible to delete a branch of a Tree (or select particular branches in a tree) in order to have the same tree but in which this special branch would be removed ?
Thank you very much in advance,

Jerome

1 Like

Hi,

We do not support deleting a branch from an existing TTree (and anyway the space in the file would not be reclaimed even if we did). Instead we recommend to partially clone the TTree:TFile *input = TFile::Open("input.root"); TTree *inputtree; input->GetObject("tree",inputtree); TFile *output = TFile::Open("output.root","RECREATE"); inputtree->SetBranchStatus("indesirable_branch.*",0); TTree *outputtree = inputtree->CloneTree(-1,"fast"); output->Write(); delete input; delete output;

Cheers,
Philippe.