How to fill the TGraphAsymmErrors

I have a question about filling the TGraphAsymmErrors object.
I set a gsyst to plot the statistic uncertainty band of h1. I set the code as:

gsyst = ROOT.TGraphAsymmErrors(h1)
for j in range (1,gsyst.GetN()+1):
    total_unc = 0
    total_unc += pow(h1.GetBinErrorj), 2)
    total_unc = sqrt(total_unc)
    gsyst.SetPointEYlow(j-1, total_unc)
    gsyst.SetPointEYhigh(j-1, total_unc)


What I am not sure is should I fill the gsyst with j or j-1? I mean should it be:

gsyst.SetPointEYlow(j, total_unc)
gsyst.SetPointEYhigh(j, total_unc)


 gsyst.SetPointEYlow(j-1, total_unc)
 gsyst.SetPointEYhigh(j-1, total_unc)


Dear Jen,

Welcome back to the ROOT Forum.
The first point of graphs, including TGraphAsymmErrors, is always indexed with zero.


do you mean I should use
gsyst.SetPointEYlow(j-1, total_unc)


And for h1 histogram, the first point is indexed with zero or one?

TGraphXXX classes deal with C++ vectors. So they are indexed from 0 to N-1 if they have N entries. In your example if j starts at 1 and you want to index the first entry of your TGraph, yes, in that case, you should use j-1.

Histogram classes deal with bins. If your histogram has N bins they are numbered from 1 to N

1 Like

ok. Thanks a lot.

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