Clone tree

Dear experts,

I used [1] to clone a tree, but when I used the TBrowser t to see the variables, I got these error message [2]. If I used [3] like in the tutorial, it works fine, but here, I need to give the tree a different name then the original one. Do you know what is wrong?

Regards

[1]
TFile* ifile = new TFile(input.c_str(),“READ”);
TTree itree = (TTree) ifile->Get(treename.c_str());
TFile* ofile = new TFile(outputfile.c_str(),“RECREATE”);
TTree newtree = (TTree)itree->Clone(“tree”);
newtree->Write();
ofile->Write();
delete ofile;
delete ifile;

[2]

Error in TFile::ReadBuffer: error reading all requested bytes from file syncntuple/lip_mt_VBFHToTauTauM125.root, got 0 of 119
Error in TFile::ReadBuffer: error reading all requested bytes from file syncntuple/lip_mt_VBFHToTauTauM125.root, got 0 of 119
Error in TFile::ReadBuffer: error reading all requested bytes from file syncntuple/lip_mt_VBFHToTauTauM125.root, got 0 of 119

[3]
TTree *newtree = oldtree->CloneTree();
root.cern.ch/root/html/tutorial … ree.C.html

Note that the tutorials are now in:
root.cern/doc/master/copytree_8C.html

Dear Couet,
thank you for your answer but I still do not see how I can rename my tree or why my macro does not work properly. Do you have an idea?
Regards

In the working example I guess it is enough to call SetName on the new tree.

Dear Couet,

thank you, “SetName” worked well.

Regards