Fitting the background

Hello everyone,

I have a spectrum (histogram) of kind TH1F called “h_tof” and I would like to fit the background using the function Background here in the documentation : root.cern.ch/root/html/TSpectru … Background

Since it outputs a TH1, that I will call for example “ambiant” I understand I need to declare it first, then use the function. I’m sorry I’m very new and this might be completely wrong, this I why I post something here

#include "TSpectrum.h" TSpectrum *s = new TSpectrum (); TH1 *ambiant = new TH1("ambiant"); ambiant=s->Background(h_tof,20,"");

I also tried TH1::TH1 *ambiant = new TH1::TH1("ambiant");
"this outputs : Error: Can’t call TH1::TH1(“arriereplan”) in current scope
None of them work.

Also , is there a way of evaluating this background fit afterwards at one given point? All this is of course to compute the signal to background ratio.

Thanks in advance for your help,
Regards
David Luis

You should NOT create the “ambiant” histogram yourself. It will be created in TSpectrum::Background with the same class as the “h_tof” (e.g. a TH1F or a TH1D).
See, for example, the “${ROOTSYS}/tutorials/spectrum/peaks.C” tutorial.

Thank you very much Wile!
It is nice to see that the very beginners also are helped!
Good evening