Resize (shrink, smaller) the x axis of an histogram TH1

Hi all,

I have been searching on this forum and also on the online documentation and I can’t figure out how to do the following:
[color=#FF0000]I would like to resize (or rebin) the x axis of an histogram to a shorter span (modify the x-axis from 0-8000 to 0-8). So all bins are compressed to 0-8 instead of 0-8000. Makes sense :question: [/color]

Also the histogram that I am trying to plot is coming from an inverse FFT (TVirtualFFT::FFT(1,&range,“C2R M K”) and like all FFT algorithms, the first half of the histogram is inversed with the last half. How can I reorganized the histogram properly so the convoluted gaussians would appear like it should? :confused:

So my code is almost complete, only these 2 problems at the end remains… Please help! :cry:

[color=#FF8040]Also, the ultimate goal is to fit my data with the convolution of a gaussian with a user defined function (which is another gaussian for now). Let me know if there’s a way to solve this with rooFit or another extension to ROOT. [/color]
I think it cannot be done with rooFit (RooFFTConvPdf), but please let me know if you’ve done it before, or if you’re aware of another extension to ROOT that could get the job done. I’ve been looking at rooFit and tried to modify the 2xx_***.C tutorials… but couldn’t take the convolution of a USER DEFINED FUNCTION with a gaussian. Only the functions already defined inside rooFit are allowed I believe. :neutral_face:

I really tried solving this by myself, I’ve spent 2 days of more than 12 hours each trying to fix this… Sorry if the answer is simple… :unamused:
It’s the first time in more than a year than I find myself at a dead end with ROOT, ususally I come here on the forums and my problems get solved reading the answers to the questions that other fellow ROOTers previously asked. I know it would take me a couple minutes to do this in matlab, but I don’t want to go back. Seriously. [-X

Please run the attached code (modified FFT.C) to understand better what I’m trying to do…
The first graphic you’ll get are the two gaussians on top of each other that I am trying to convolve (convolute?). Then on the second graph you got the screwed up convolution of those previously said gaussians. It is not correct cause the right part <—> left part and also it is spanning to long on the x-axis. :imp:

The result at the end should look like the convolution of the 2 gaussians on this webpage (Except shifted to the :arrow_right: ).
mathworld.wolfram.com/Convolution.html

Thanks a lot! [-o<
:mrgreen:

Matthieu
FFTconvolution.C (24.4 KB)

I don’t exactly know what you mean by “resize / rebin / shrink the X axis”.
If you want to preserve the number of X bins and just “scale” the X axis values of your histogram, see the “Can we shift histogram for several channels?” thread: [url]Can we shift histogram for several channels?

Hi Pepe!

I read your response 2 days after you posted it… but did not have time to check if your
solution is working, but I think it will!

I have a predoctoral exam soon (~ mid-january), so that’s why I couldn’t check your solution yet…
I have so much to study… X_X

As soon as my exam is done I’ll post a new code snippet cause I think I got the convolution working with user defined functions…

Thanks a lot!!! :slight_smile:

Matthieu