Problem to rebin histograms


Right now I used the following function to rebin my histograms :

void RebinHisto(TH1D * m_histo, int m_nbins, int m_scale)
  int current_nbins  = m_histo -> GetNbinsX() ;
  int new_nbins      = m_nbins                ;

  if ( new_nbins <= current_nbins ) // Rebin ONLY if necessary
      // 1. Compute the numbers of bins to be merged
      // *******************************************
      double x              = double(current_nbins) / double(new_nbins) ; 
      int    nob_ToBeMerged = int(x) ; // nb. of bins to merge

      // 2. Rebin histogram, keep scale (optionnal)
      // ******************************************
      m_histo -> Rebin( 10 ) ;
      //m_histo -> Rebin( nob_ToBeMerged ) ;
      //if ( m_scale == 1 )  m_histo -> Scale( 1./nob_ToBeMerged ) ;
      string histo_title = m_histo -> GetTitle() ;
      cout << histo_title << " has at the basis " << current_nbins << " bins -"
	   << " It can't be rebinned with " << new_nbins << " bins" << endl ;
} // RebinHisto

But I noticed that after when doinf operation with th rebin histograms the results where not relevant. Should I rebin after all the analysis is done isntead ?


Could you send a concrete example that we can run? and specify your version of ROOT ?


I am using version 5.14 of ROOT since -shame on me- I am a little bit confused with the higher version as well as for the installation and for the chnages my Makefile needs.

I will try to prepare some code for you, do you just need some TH1D histograms or also some code I use ?

Please, give us the possibly smallest working code sample, which demonstrates undesirable behavior.

BTW. Sorry, but from your original posting I can’t understand your re-binning. If you have, say, 10 bins and want to re-bin to 5 bins, you’ll do:
int(10. / 5.) == 2 and hist->Rebin(2); //what does it mean?

Here is in attachment an example, I am sorry but in the time I have it’s the simplest thing I could made, but as you may see only a few parts of the code is necessary. If it’s too big and you don’t have the time please tell me.

So to sum up, first if you run the code test.cxx (typing make test) with the option :

const string Nbins    = "default"      ;

and then select the lower plot (asymmetry) and then rebin it using the editor you willl see something relevant the errors are staying in the same range but increase because of merging the information

then if you want to rebin using the code let’s say by typing :
const string Nbins = “100” ;

you will see that the errors are decreasing which is a nonsense !!

I add to that that all my histograms are created the option :

  TH1D * histo = new TH1D(histo_name.c_str(), histo_title.c_str(), 
			  Nbins, x1, x2 ) ;

  histo -> Sumw2() ; // To include bin errors

So I was expecting them to be correctly recalculated for the asymm. plot.

I am using the version 5.14

Thanks in advance for your time and for any help !! Nice Easter.

Another comment I could’nt manage to use the Asym option from ROOT so I wrote a personnal one, if you know how to use ROOT one thanks.
Example.tar.gz (22.8 KB)