Re: x-value to bin number?

From: Rene Brun (Rene.Brun@cern.ch)
Date: Wed Jun 04 1997 - 17:18:56 MEST


Robert Casties wrote:
> 
> Hello!
> 
> Is there a convenient method to get the bin no of a histogram from the
> value to be filled in? (I thought TH1::GetBin would do that)
> 
> Do I have to do all TH1::Fill(x) does (subtracting xmin, dividing, etc)?
> 

You can use TAxis::FindBin
Example in case of a 2-d histogram (same for 1-d and 3-d)
  TAxis *xaxis = h->GetXaxis();
  TAxis *yaxis = h->GetYaxis();
  Int_t binx = xaxis->FindBin(x);
  Int_t biny = yaxis->FindBin(y);
etc..

> Is there any other way to make my own histogram contents with errors? At
> the moment I'm using TH1::Fill(x,value) for the data but there's not the
> like for errors.
> 
> Actually, it's not really histograms I want but something which looks the
> same (plot of single equidistant values with errorbars).
> 

TH1::Fill increments bin contents and bin errors (if TH1::Sumw2 was called before).
If you just want to set bin content or bin error, use
  TH1::SetBinContent(bin,value)
  TH1::SetBinError(bin,error); 
Note that if TH1::Sumw2 was not called, SetBinError will automatically activate
the storage of errors.

Rene Brun



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:26:19 MET