Where is stored the background estimation?


I try to retrieve information about the background estimation as calculated with the ‘TH1 *TSpectrum::Background’ function. As far as I understand the background is return as a histogram and replace the source data, but I can not retrieve this information.
I would like to substract the estimated background from my data (histo): here is the code I use for this:

  TH1I *histo = new TH1I("histo", "My histo", 300, 100, 300.);

// y[i] are my data
for (int i = 0; i < 300; i++){

TH1F h2 = (TH1F)histo->Clone(“h2”);

//Use TSpectrum to find the peak candidates
//max_peak is the number of searched peaks

TSpectrum *s = new TSpectrum(max_peak,2);
Int_t nfound = s->Search(histo,2,“new”);
for (int i = 0; i < 300; i++){
h2->SetBinContent(i,h2->GetBinContent(i)- histo->GetBinContent(i));

Is there anyone who can help?

Many thanks.

c1.pdf (29.2 KB)


I do not understand your question. TSpectrum::Background returns the background histogram.



I am sorry because I am a very new user and I am not quite sure that the histogram I use to compute the background on is replaced by the estimated background itself. Is it the case? When I remove the background from my data and fit the new data, the fitted heights are equivalent to the heights before background removal (see my file).

If you would confirm me that, then I would search to understand better how works my fitting part.


To make progress it would be good if you couls send a self-contained script that explain/reproduce your problem.


Here is my script and the corresponding datafile. You can just type the following command to reproduce my problem:

.x test1sig.c(“gaas.gup”,10,30);

apparently, everything is going well, except that I expect to fit gauss peaks with sligtly lower heights than in the raw data, which is not the case .
test1sig.C (3.74 KB)

here is my data
(extension changed from .gup to .txt)
GAAS.txt (7.34 KB)

Hi René,

Now I understand. In the Background function the data corresponding to the estimated background are stored in *source:

Float_t * source = new float[size of my histo];
source[i] = my histo->GetBinContent(i + first);

and are deleted just before exiting the function.

delete [] source;
return hb; // (copy of my histo + estimated background)

I guess that I have to create my own background function if ever I want to access these data.

Thanks anyway.


As I already told you above, the background histogram is returned when you call TSpectrum::Background.
Simply replace your statement

s->Background(histo,n_iter,"same"); by

TH1 *background = s->Background(histo,n_iter,"same");