Re: [ROOT] asymmetric SetBinError for TH1F

From: Rene Brun (Rene.Brun@cern.ch)
Date: Sat Jan 19 2002 - 10:47:42 MET


Hi Chris,

Histograms with asymmetric errors are not supported. But it is quite easy
to get the same functionality via TGraphAsymmErrors. Here is a small
example

void gaerrors() {
   TCanvas *c1 = new TCanvas("c1");
   c1->SetGrid();
   const Int_t n = 10;
   Float_t x[n];
   Float_t y[n]  = {1,2.9,5.6,7.4,9,9.6,8.7,6.3,4.5,1};
   Float_t exl[n] = {.5,1,.7,.7,.4,.5,.6,.7,.8,.5};
   Float_t eyl[n] = {.8,.7,.6,.5,.4,.4,.5,.6,.7,.8};
   Float_t exh[n] = {.2,.8,.5,.5,.3,.3,.4,.5,.6,.3};
   Float_t eyh[n] = {.6,.5,.4,.3,.2,.2,.3,.4,.5,.6};
   TH1F *h = new TH1F("h","Asymm errors histogram with labels",n,0,n);
   const char *labels[n] = {"Chris","John","Rene","Fons","Marc",
                            "Fred", "Ted","Louis","Ed","Jim"};
   for (Int_t i=0;i<n;i++) {
      x[i] = h->GetXaxis()->GetBinCenter(i+1);
      h->GetXaxis()->SetBinLabel(i+1,labels[i]);
      h->Fill(x[i],y[i]);
   }
   h->Draw("a");
   //h->GetXaxis()->LabelsOption("v");
   gr = new TGraphAsymmErrors(n,x,y,exl,exh,eyl,eyh);
   gr->SetMarkerStyle(21);
   gr->Draw("p");
}

Rene Brun

On Fri, 18 Jan 2002, Chris Hays wrote:

> 
>   I can't seem to find a function that lets me set an asymmetric error for
> a single TH1F bin, only for a TGraph bin.  Does one exist?  I would prefer
> an asymmetric TH1F error so I can use the TH1F functionality, particularly
> SetBinLabel and "same" (maybe these are possible with TGraph, but I am
> not aware of it).
> 
> 
> Chris
> 



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:38 MET