Remove x error bar

Hi,

How do I remove x error bar from TH1D histogram? I could not find any method.
Removing error bar for whole histogram without doing bin-by-bin will be more helpful. Global function is even more helpful.

Thanks.

gStyle->SetErrorX(0.0001);

Thanks.
Unfortunately, it is not working. I am using TH1::SetDefaultSumw2() also.

I tried with:

{
  TH1D hist("hist", "hist", 10, 0., 1.);
   hist.Sumw2();
   gStyle->SetErrorX(0.);    
   hist.Fill(.5);
   hist.Fill(.4);
   hist.Fill(.3);
   hist.SetBarWidth(.7);
   hist.SetFillColor(kRed);
   hist.Draw();
}

Do you have a simple code sample (like this one) showing what you do ?

I checked with simple code and it is working but in my real code it is not working. So, I dug it and found where it was happening but don’t know why. Reason is: if I do not open a new root file then it works, but if I open a new root file and write histogram in the file, it does not work. Here is a simple code:

This one works.

TH1::SetDefaultSumw2();
gStyle->SetErrorX(0.0001);

TH1D *h1 = new TH1D("h1", "h1", 50, -4.0, 4.0);
TRandom *rand = new TRandom();
for(int i=0; i<800; i++) h1->Fill(rand->Gaus());

h1->Draw();

This does not.

TH1::SetDefaultSumw2();
gStyle->SetErrorX(0.0001);

TFile *file = new TFile("tt.root", "recreate");

TH1D *h1 = new TH1D("h1", "h1", 50, -4.0, 4.0);
TRandom *rand = new TRandom();
for(int i=0; i<800; i++) h1->Fill(rand->Gaus());

h1->Write();
file->Close();

gStyle->SetErrorX() is purely graphics, it does not change the histogram content. It will NOT remove the errors along X in the histogram data structure. So you have to set it before you plot the histograms.

Yap, Thanks a lot.

Hi,

May be I am wrong but what about if Rooters implement a method that sets the x-error in a histogram. I recently encountered this problem many times, and most probably other people also. To remove the x-error bar, I have to write histogram points in a graph and set the x-error bar to zero (because there is no method to set x-error bar for histogram, SetError(…) sets the y-error bar).

Thanks.

Hi,
The histograms do not store errors in X, because they do not make much sense. The only thing could have some sense is displaying the bin width as an error in X.
If you have measurements in X and Y with their errors you should use the TGraphErrors class and not the histogram class (TH1)

Best Regards

Lorenzo