Simultaneous Fit of Two Sides of ONE Histogram

Hi All,

I have a 1D histogram and I need to fit the background. However, I am given two specific ranges for the fit, so basically, some data needs to be left out from the fit. The only way I have managed to do that is by applying two separate fits to the one histogram. Nevertheless, I need them to be simultaneous, i.e. one set of parameters instead of having two sets from the two fits. Does anyone know if that is even possible? I’ve been looking into it for hours and have had no luck, so your help will be greatly appreciated.

Please, do not hesitate in asking for more details if the above does not make sense.

Thanks a lot for your time.

You can (for example) add functions:

   TF1 *powerfunc = new TF1("powerfunc", "[0]*pow(x,[1])", 0.0, 25.0);
   TF1 *gaussfunc = new TF1("gaussfunc", "[0]*TMath::Gaus(x,[1],[2])", 25.0, 100.0);
   TF1 *totalfunc = new TF1("totalfunc", "powerfunc+gaussfunc");

And then use the totalfunc to fit your data

1 Like

Great, thank you. It does not immediately work, but it’s a great idea. So, I will play with it to see if I get it to work.

Thanks again!

1 Like


1 Like

Got it to work! I see that I that I had to apply the cuts in my background function.

Thank you both for the help @bellenot @Wile_E_Coyote .

1 Like