Converting TGraphAsymmErrors to TH1

I have the following problem. I would like to create efficiency plots with asymmetric error bars using BayesDivide method as in TGraphAsymmErrors::BayesDivide. However I need to store these plots in root files as TH1* objects.
Is there any way to construct an histogram object with asymmetric error bars from TGraphAsymmErrors::BayesDivide ?

Thanks in advance

Your question is a bit strange. Why you do not store your TGraphAsymmErrors objet directly in the root file?


I am writing my code within a software framework that provides a service to store and manage root objects in root files. However, for the moment this service does not support the storage of graphs, only histograms. I have already checked with the framework developers that this is not possible.

So it seems that I have two options:

1.Don’t use the software framework service until is has TGraph and do my own managing of root objects for the moment. This I know how to do.

  1. Convert the TGraph to TH1*, if it is possible and not too complex. Then I will not need to change my code when the software framework is ready.

Sorry if I am reporting problems that arise from working in a framework within another framework. I guess this situation is not that rare in an always evolving HEP experimental environment.

If there is not a simple solution to option 2, I will live with option 1.

I do not understand why and how your software framework could prevent you to store a Tgraph into a ROOT file. Simply get a pointer to the file
and write your graph to it. This should be 2 lines long.


Yes, you are right. That is possible.

Thanks a lot !


Hi Root Experts,

Rekindling an old thread, is there indeed some standard way to convert a TGraph to a TH1? I realize that TGraphs do not have bins, so I assume that I will have to specify binning. In my case, the x-axis entries are evenly spaced.

Alternatively, I am simply interested in “rebinning” or smoothing a TGraph. There may be other ways to accomplish this besides converting to a TH1.

Thanks in advance,

As you noticed TGraphs are unbinned data. So wanting to rebin them is a bin weird. … yes, in that case you should make a TH1. You can fit a TGraph if you want to “smooth it”.