# How to Draw error bar of a Graph2DErrors?

I defined a Graph2DErrors obj:
TGraph2DErrors dte = new TGraph2DErrors(nd);
for (Int_t i=0; iGetRandom2(x,y);
rnd = r.Uniform(-e,e); // Generate a random number in [-e,e]
z = f2->Eval(x,y)
(1+rnd);
dte->SetPoint(i,x,y,z);
ex = 5r.Rndm();
ey = 5
r.Rndm();
ez = TMath::Abs(z*rnd);
dte->SetPointError(i,ex,ey,ez);
}

f2->SetParameters(0.5,1.5);
dte->Fit(f2);
TF2 fit2 = (TF2)dte->FindObject(“f2”);

dte->SetMarkerStyle(21);
dte->Draw(“pi0”);
but cannot draw the error bar .How to draw the error bar in the case ?

You macro does not work. Please send working examples. Here is a working one which draws error bars:

``````{
gStyle->SetFrameBorderMode(0);
gStyle->SetCanvasBorderMode(0);

TCanvas *c = new TCanvas("c","Graph2DErrors example",0,0,600,600);
Double_t P = 6.;
Int_t np   = 200;

Double_t *rx=0, *ry=0, *rz=0;
Double_t *ex=0, *ey=0, *ez=0;

rx = new Double_t[np];
ry = new Double_t[np];
rz = new Double_t[np];
ex = new Double_t[np];
ey = new Double_t[np];
ez = new Double_t[np];

TRandom *r = new TRandom();

for (Int_t N=0; N<np>Rndm(N))-P;
ry[N] = 2*P*(r->Rndm(N))-P;
rz[N] = rx[N]*rx[N]-ry[N]*ry[N];
ex[N] = r->Rndm(N);
ey[N] = r->Rndm(N);
ez[N] = r->Rndm(N);
}
gStyle->SetPalette(1);

TGraph2DErrors *dte = new TGraph2DErrors(np, rx, ry, rz, ex, ey, ez);

dte->SetFillColor(29);
dte->SetMarkerSize(0.5);
dte->Draw("E");
}``````

As far as I can tell the macro described above will show the error bars of the interpolated surface made by TGraph2DErrors (am I right?).

My follow-up question is whether there is a way to plot the points given to TGraph2DErrors with error bars rather than those of the interpolated surface?

Best regards,

[quote]As far as I can tell the macro described above will show the error bars of the interpolated surface made by TGraph2DErrors (am I right?).

My follow-up question is whether there is a way to plot the points given to TGraph2DErrors with error bars rather than those of the interpolated surface?
[/quote]
Why do you draw this conclusion? it would not make sense.
The errors drawn are the ones specified.

Rene

Hi again,

My conclusion is that since that is what happens when I’m running the script above. I am using pyROOT though.

So there is a discrepancy between the pure ROOT version of TGraph2DErrors and the one of pyROOT!

Sorry for disturbing this forum. I will bring it up under the pyROOT forum instead. (Here.)

Kind Regards,
Erik

I have now tried to run the code from couet above, in ordinary ROOT, and get the same result! (The code is slightly altered since the original didn’t work. Se below.) I get the error bars of the interpolated surface in the plot instead of those of my points. Can you please tell me what I am doing wrong? Is there someone out there who has the same problem?

[code]{
gStyle->SetFrameBorderMode(0);
gStyle->SetCanvasBorderMode(0);

TCanvas *c = new TCanvas(“c”,“Graph2DErrors example”,0,0,600,600);
Double_t P = 6.;
Int_t np = 200;

Double_t *rx=0, *ry=0, *rz=0;
Double_t *ex=0, *ey=0, *ez=0;

rx = new Double_t[np];
ry = new Double_t[np];
rz = new Double_t[np];
ex = new Double_t[np];
ey = new Double_t[np];
ez = new Double_t[np];

TRandom *r = new TRandom();

for (Int_t N=0; N<np;N++){
rx[N] = 2P(r->Rndm(N))-P;
ry[N] = 2P(r->Rndm(N))-P;
rz[N] = rx[N]*rx[N]-ry[N]*ry[N];
ex[N] = r->Rndm(N);
ey[N] = r->Rndm(N);
ez[N] = r->Rndm(N);
}
gStyle->SetPalette(1);

TGraph2DErrors *dte = new TGraph2DErrors(np, rx, ry, rz, ex, ey, ez);

dte->SetFillColor(29);
dte->SetMarkerSize(0.5);
dte->Draw(“E”);
} [/code]

Looking at this problem again, I see that effectively the output does not make sense. This is a big bug that will be fixed by Olivier once he will back after his holidays.
Thanks for this report

Rene

The E option has not been implemented yet for TGraph2D and TGraph2DErrors.

Right now E option is considered as an histogram option and therefore the interpolated histogram is plotted with this option. For the time being the TGraph2D specific plotting options are listed in the help here: root.cern.ch/root/html/TGraph2D.html
any other option is considered as an histogram option and therefore the interpolated histogram is plotted.

I agree with you that a some development is needed to plot the error bars at the exact points. The ouput we get with “E” option right now does not make really sense.

Any progress after this topic? It seems that Graph2DErrors still uses the error bars calculated from fHistogram when it is drawn with “E” option.

No, nothing new yet for this request.
A new drawing method should be implement for TGraph2DErrors only.
(TGraph2D has no errors).

This option is now implemented in the SVN trunk.