Save numbers to TFile

Dear all,

I have a very simple question, but somehow got confused what would be the best way to do it:

I would like to save a couple of numbers (Double_t) to a TFile, in addition to the tree which is saved there. Just to store some additional information about the tree which I will need later on. What is the simplest way to do that?

Thanks a lot,


You can add any TNamed* object to the Tree User Info.
For example, suppose you can save a set of numbers in a TH1* hinfo histogram named “hinfo” and do

mytree->GetUserInfo()->Add(hinfo); //fill your Tree and hinfo histogram //at the end of the job do mytree->Write(); //to the file
in the next job, do

TFile *f = TFile::open("myfile.root"); TTree *mytree = (TTree*)f->Get("mytreename"); TH1 *hinfo = (TH1*)mytree->GetUserInfo()->FindObject("hinfo");
You can add as many TNamed objects as you like in mytree->GetUserInfo()


Hi Rene,

thanks for the hint! This is exactly what I need.

Which class would you recommend as a container to store a few numbers? Naturally, I would use some kind of array, but the TArrays do not inherit from TNamed as far as I understand. Saving the data to some histogram or TGraph would of course be an option, but is there maybe something more light-weight?



You can use a TVectorD


1 Like

Thanks a lot, Rene, this works perfectly :slight_smile: