Problem when trying to save histogram in a tree

Hi, I am trying to save a histogram/canvas as a leaf in a tree so I can call it later and make some adjustments. The code I am using:

TFile *myfile = TFile::Open("myFile.root","UPDATE");
h->Write();

I then go over the tree to look for it, but it is not there for some reason. Am I doing this the right way?

Thank you!

To retrieve it:

myfile->Get<TH1>(histogram_name);

It’s giving an error:

error: no matching member function for call to 'Get'
   myfile->Get<TH1>(h);

Which version of ROOT are you using? For older version

TH1 *h; myfile->GetObject(histogram_name, h);

What is the ‘type’ of ‘h’ in your failing case?

ROOT 6.18, Histo is TH1F.I think it worked when I added those lines:

f->Write()
f->Close()

But it got saved as a histogram. Is it not possible to save it among leaves so I can call it later? If not, is it possible to call the saved histogram and used leaves/branches methods on it? i.e. normalisation.

If not, is it possible to call the saved histogram and used leaves/branches methods on it?

It is possible but is unlikely to be what you want/mean. (you would need to add a branch to the Tree based on the histogram address/pointer and then call Fill … but just once and so there would be one entry for that branch and many entries for all the other branches).

used leaves/branches methods on it? i.e. normalisation.

What do you mean? (and related Where does the content of the histogram comes from?)

It’s a bit complicated. I think I’m just gonna manually take values and put them in a new histogram. Thanks for the help.

${ROOTSYS}/tutorials/tree/htest.C

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.