Add the trees of a root chain with different weights

Hi Delo,

Indeed if you update the ROOT file (well any file) there is a risk that if something goes wrong (physical error in the hard drive, random crash due to any problem in your code or the library you use), the result would be a corrupted file.

The only safe solution (short of never having bug in your code or never tickling bug in the library code :slight_smile:) is to make a backup copy of the file. You can for example using the shell command cp or even TFile::Cp to make the copy or you could open the file read only and copy the content into a new file. For example:TFile *f1 = TFile::Open("zjet2DBS_15to20.root","READ"); TTree *tree = 0; f1->GetObject("myEvent",tree); TFile *output = TFile::Open("zjet2DBS_15to20_v2.root","NEW"); TTree *newtree = tree->CloneTree(-1,"fast"); newtree->SetWeight(0.4); output->Write(); delete f1; delete output;

Cheers,
Philippe.