Arbitrary rebinning

Dear rooters,
say I have a TH1F which has 20 bins, and I want to merge bin1 and bin2 into one bin,
bin4 and bin5 into one etc. If I do it myself, it is error prone. did TH1F support such kind
of rebinning?

Best regards,

Hi,

You can use TH1::Rebin method. For more details see the ROOT Reference Guide at root.cern.ch/root/htmldoc/TH1.html#TH1:Rebin

There is also user interfave avaialble via ROOT Graphics Editor, which allows you to do it interactively via the Binning tab of the histogram’s editors (see at root.cern.ch/root/htmldoc/TH2Editor.html).

Cheers, Ilka

Dear antcheva,
thanks for the guide.
the inerface TH1 provide is following
TH1 * Rebin(Int_t ngroup = 2, const char* newname = “”, const Double_t* xbins = 0)
if TH1 can provide something like
TH1 * Rebin(Int_t ngroup = 2, const char* newname = “”, const int* nobins=0)
I need only specify the bin no array, which is more convenient imho.

Hi,

As explained in the Reference Guide (case 1), when you call your_hist->Rebin(); every two bins will be merged in one and the current histogram is modified (previous contents of your_hist are lost). If you want to keep your_hist with no modification, specify the second parameter, i.e. in this case call TH1F *hnew = your_hist->Rebin(2, "hnew");
Cheers, Ilka

I also have a problem with Rebin. Can anyone help me?
My code:

Double_t abins[5] = {0.0, 0.001, 0.01, 0.05, 0.9};
 TH1F *hnew =  (TH1F*) x2_3->Rebin(4, "hnew", abins);

It doesnt work.
It post errors:

Error: Can't call TH1F::Rebin(4,"hnew",abins) in current scope FILE:plot.C LINE:263
Possible candidates are...
filename       line:size busy function type and name  (in TH1F)
filename       line:size busy function type and name  (in TH1)
(compiled)        0:0    0 public: virtual TH1* Rebin(Int_t ngroup=2,const char* newname=); //*MENU*
filename       line:size busy function type and name  (in TNamed)
filename       line:size busy function type and name  (in TObject)
filename       line:size busy function type and name  (in TAttLine)
filename       line:size busy function type and name  (in TAttFill)
filename       line:size busy function type and name  (in TAttMarker)
filename       line:size busy function type and name  (in TArrayF)
filename       line:size busy function type and name  (in TArray)
*** Interpreter error recovered ***

This means that
-You forgot to post your version of ROOT
-Likely you are using an old version

Rene

I use root -b on Lxplus

[lxplus231] ~ > root -b
  *******************************************
  *                                         *
  *        W E L C O M E  to  R O O T       *
  *                                         *
  *   Version   4.04/02       10 May 2005   *
  *                                         *
  *  You are welcome to visit our Web site  *
  *          http://root.cern.ch            *
  *                                         *
  *******************************************

Compiled for linux with thread support.

CINT/ROOT C/C++ Interpreter version 5.15.169, Mar 14 2005

Is it too old? How can I use more relevant version on Lxplus mashine?

see the addresses of the most recent AFS versions at root.cern.ch

Rene