Dear rooters
I have an input file with one tree called (Tree0)
I want to copy part of entries with condition into a new tree,(separate one tree into multi trees)
so I wrote this script
TFile *input = new TFile(input_rootfile,"READ");
TTree *input_tree = (TTree*)input->Get("Tree0");
TFile *output = new TFile(output_rootfile,"RECREATE");
for (int k=0; k<number_of_channels; k++)
{
std::cout << k << endl;
sprintf(tree_name,"Channel_%02d",k); // name of tree
sprintf(condition,"ch==%d",k);
new_trees[k]= input_tree->CopyTree(condition);
new_trees[k]->SetName(tree_name);
new_trees[k]->Write();
}
output->Close();
I have two input files, first with two conditions (k=2), this work fine and seperate the input tree into two trees.
but I have another input file with 4 conditions(k=4), this file create an extra tree with name Tree0, and if I comment the line (new_trees[k]->Write()) I should not obtain any trees, but in this case I will still get the (Tree0) Tree with random numbers of entries.
does CopyTree Method not appropriate in this case,???
I will appreciate your ideas