h2->Fill problem

I need to rescale my initial TH2D histogram to a physical meaningful histogram, namely, with re-calibrated x and y-axises.

I did the following :

 TH2D *RAW = new TH2D("RAW",histoname,binx,0,binx,biny,0,biny);   
  TH2D *RAW2 = new TH2D("RAW2",histoname,binx,0,binx,biny,0,biny*0.00064); 
  
 for (ifreq = ifmin; ifreq < ifmax; ifreq++){ 
     for (i_multi = 0; i_multi < n_of_multi; i_multi++) {
      RAW->SetBinContent(ifreq-ifmin_multi+1,i_multi+1, multi_taper_spektrum[i_multi][ifreq]); 
      RAW2->Fill(ifreq-ifmin_multi, (i_multi+1)*dtm, multi_taper_spektrum[i_multi][ifreq]); 
    }
  }

I attached also part of the results of both RAW and RAW2 in comparison. As one can see, in most cases both agrees, except in RAW2 1) missing data in the highest ybin of RAW2, which corresponding to biny=50 in RAW, 2) empty content in the middle yaxis, which corresponding to biny=25 in RAW, and also the new biny content at 26 in RAW2 is actually the sum of the biny conents at 25 and 26 in RAW…

I guess that the second point may related to floating point precision.
I was always confused on the fill …

Thanks for any comments or reply…


Hi,

[quote]I guess that the second point may related to floating point precision.
[/quote]
From the look of it, all the issues could be related to the floating precision (i.e. Fill not find the bin you expect), you would need to examine carefully the input and if it does indeed lay close to the boundary of bins or the under/overflow then this is likely the problem.

Cheers,
Philippe.

Thanks Philippe.

We, however, need this kind of re-scaling of x and y-axises so that they have physical meaning. Any trick to do it and also to avoid possible misfilling the bins?

For example, in Gnuplot, one can easily scale x and y axises by multiplying/adding a floating number.

A possible brutal fix …
Fill your histogram using bins that produce nice results.
Afterwards, change the ranges of the axes of your histogram, like in the “Can we shift histogram for several channels?” thread: [url]Can we shift histogram for several channels?
You don’t even need to change the source code presented there (as TH3 and TH2 inherit from TH1, it should work fine - all the methods for “X”, “Y” and “Z” axes are there).

thanks, Pepe Le Pew, It is beautiful… =D>