I created a macro ‘deltat.C’, ran it on my file ‘file.root’ with the ntuple ‘MeritTuple’. deltat.C successfully looped over my ntuple to produce the values I wanted, but I’m not entirely sure how I can save these values to the ntuple. I know that I either need to somehow save these computed values to an ntuple and friend the two tuples together or somehow modify the original tuple to add the new data. I don’t really prefer either method (but would love to know how to do both) and am unsure how to proceed in either direction.
The more flexible is to create a new TTree and make it a friend of the original:TFile *file = TFile::Open("input.root",'UPDATE");
TTree *input = 0; file->GetObject("input",input);
TTree *output = new TTree("input_addition","addition to the input");
output->Branch(.....);
for(Long64_t entry = 0; entry < input->GetEntries(); ++entry) {
input->GetEntry(entry); // This can changed as needed to only read the needed subset.
.. set the new values ..
output->Fill();
}
input->AddFriend(output);
file->Write();
Adding a new branch is not recommended as it decreases the efficiency of reading the TTree.