Create TF1 from a 1-D histogram

Hello,

I have a 1-D histogram with a bunch of peaks:

peaks

I want to create a custom TF1 from say bins, 2190 to 2260, which smoothly passes over the peaks in this histogram. Does anyone have any idea about ‘creating’ TF1 from any such histograms? Also, can I view this TF1 as an output on the screen after it is created?

Any help or a starting point is highly appreciated here, thank you!

ROOT Version: 5.34 / 38
Platform: Opensuse
Compiler: g++ (suse Linux) 7.4.1

Hi @tangophysics ,

one way to do this is to fit the histogram with some functional form. For example you can define a TF1 with some free parameters and then call histo.Fit(function). See e.g. ROOT: tutorials/hist/hlHisto4.C File Reference for code that fits a TF1 to a TH1. @moneta might be able to point to better resources.

Cheers,
Enrico

Hi,

You can see this example, for transforming a TH1 in a TF1 that is then used for fitting. If you want to smooth your histogram you can use
TH1::Interpolate that performs linear interpolation between bins, or TH1::Smooth.

Cheers

Lorenzo

Thank you @eguiraud for the references, this should help!

Thank you @moneta, this does seem the likely solution! :+1:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.