int datagr()
{
TH1F * h = new TH1F("h", "h", 4, -2, 2);
h -> Sumw2();
h -> FillRandom("gaus", 500);
//h -> Print("all");
TGraphErrors * gr = new TGraphErrors(h);
TCanvas * c = new TCanvas;
gr -> Draw("AP");
gr -> SetMarkerStyle(20);
gr -> SetMarkerSize(1.0);
gr -> SetLineWidth(0);
return 0;
}
TGraphErrors has vertical and horizontal error bars. They are defined when you create the TGraphErrors. If you do not have errors along the X axis simply define these errors to 0.
void datagr()
{
TH1F * h = new TH1F("h", "h", 4, -2, 2);
h -> Sumw2();
h -> FillRandom("gaus", 500);
TGraphErrors * gr = new TGraphErrors(h);
gr -> SetMarkerStyle(20);
gr -> SetMarkerSize(1.0);
int n = gr->GetN();
double ey;
for (int i=0; i<n; i++) {
ey = gr->GetErrorY(i);
gr->SetPointError ( i, 0, ey);
}
gr -> Draw("AP");
}