HISTOGRAM fill

Hi experts,
How to fill a histogram in which each bin will contain at least 5 counts.
Here is the macro:

  TFile *f1 = new TFile("count.root", "RECREATE");
  TTree *tr = new TTree("ntuple", "data");
  tr->ReadFile("hist_plot.dat", "x");
  TH1F *h1 = new TH1F("h1", "Gaussian Distribution", 20, -2.4, 2.9);
  h1->GetXaxis()->SetTitle("log_{10}(Value)");
  h1->GetYaxis()->SetTitle("Counts (Frequency)");   
  bool checkBins=true;
  int count, sum;
  for( int i=1; i<=20; i++) {
  do {
  if(h1->GetBinContent(i)<5) 
  checkBins=false; 
//    count = h1->GetBinContent(i); 
//   sum = count + h1->GetBinContent(i+1); }
//  else { continue;}
}
  while(checkBins && i <= h1->GetNbinsX());   
  tr->Project("h1", "log10(x)");
  f1->Write();   
  h1->Draw("hist"); 

However first two bins contain less than 5 counts, other bins are fine. How do I add these two bins to the next bin?

Thanks!!
Anil

Hi,
you can try to reduce the number of bins from 20 to 19 or 18.

Thank you @Dilicus
If i reduced the number of bins to 18 or 15 or 12 , first two bins contain less than 5 and at 10 only first bin contains 1 count.
However if number of bins reduced to 5, all the bins contain more than 5 counts. In case of gaussian fit to this histogram, should it be relevant?

It is not relevant for the fit at all (and you can always set some “xmin” and “xmax” when using the TH1::Fit method).

Ok. Thank you @Wile_E_Coyote