How can I retrieve the background data from spectrum

Hello everyone,
I have a spectrum in the form of a histogram. I have completed the background fitting.
Now, I would like to eliminate background from the spectrum.
Also, is there are a way to evaluate this background values at every point?

Thanks in advance for your help,
Regards
Robert Froast


ROOT Version: 6.14
Platform: Ubuntu
Compiler: Not Provided


Hi,

Can you please elaborate a bit more how you have performed the fitting ? Normally by fitting the background you get a function that you can evaluate at every point you wish

Lorenzo

Hi,


This is the spectrum that i was getting earlier.
Now i have to fit its background.
I added the code below.
//Estimate background using TSpectrum::Background
TH1 *hb = s->Background(h,20,“same”);
After running, I got this.

You can see the difference in the two figures.
First of all, please tell me is it the correct way to fit the background?

I see you are using TSpectrum. There is many “Background” tutorials in the reference guide.

Thanks for responding @couet


Is the background fine?
Can I get background slightly more smoother?

I am not sure. All the information we have about TSpectrum is here:

https://root.cern/doc/master/group__tutorial__spectrum.html
https://root.cern/doc/master/classTSpectrum.html
https://root.cern.ch/root/htmldoc/guides/spectrum/Spectrum.html

I got the error. Explain the meaning of this.

error: excess elements in scalar initializer
char *Background(s, n, 20);

Can you post a bit more of the code ?

ok @couet. I have define the spectrum.

 TSpectrum *s = new TSpectrum(2*npeaks);
 Int_t nfound = s->Search(h,2,"",0.06);
 printf("Found %d candidate peaks to fit\n",nfound); 

and then i use BACKGROUND ELIMINATION

1-DIMENSIONAL SPECTRA

char *Background(s, n, 20);

where I got the error.

We cannot help with that we need more complete code …
we need to see how are defined s , n , npeaks etc …
a small complete macro reproducing the error is required.

ok. @couet
I am uploading the complete code.
fithisto.C (3.2 KB)
and this is the text file.
eu_gu_1.txt (44.1 KB)

I do not understand what you are trying to do with this char *Background(s, n, 20); declaration in the middle of your code. There is many background examples in the spectrum tutorial’s (see the link I sent before). See how it is used there.

Thanks @couet
If instead of char *Background(s, n, 20);
i use TH1 *hb = s->Background(h,20,“same”); in my code then is it the correct way for estimating the background?

Look how it is done in the tutorials. Try them and you will understand how to use this functionality.

OK @couet
Using the links that you have mentioned above. I have run a auxiliary file i.e. cleanback.C (410 Bytes)
eu_gu_1.C (44.1 KB)
Please look at it once.

void cleanback()
{
   auto g = new TGraph("eu_gu_1.txt");
   auto s = new TSpectrum();

   double sourceX[6000];
   double sourceY[6000];
   int n = g->GetN();

   for (int i = 0; i < n; i++) {
      sourceX[i] = g->GetPointX(i);
      sourceY[i] = g->GetPointY(i);
   }

   s->Background(sourceY, n,
                10, TSpectrum::kBackDecreasingWindow,
                TSpectrum::kBackOrder8, kTRUE,
                TSpectrum::kBackSmoothing5, kTRUE);

   auto b = new TGraph(n, sourceX, sourceY);
   b->SetLineColor(kRed);

   g->Draw("AL");
   b->Draw("L");

}

And you should play a bit with the parameters of the Background function (again see doc and tutorials).

For instance:

void cleanback()
{
   auto g = new TGraph("eu_gu_1.txt");
   auto s = new TSpectrum();

   double sourceX[6000];
   double sourceY[6000];
   int n = g->GetN();

   for (int i = 0; i < n; i++) {
      sourceX[i] = g->GetPointX(i);
      sourceY[i] = g->GetPointY(i);
   }

   s->Background(sourceY, n,
                10, TSpectrum::kBackDecreasingWindow,
                TSpectrum::kBackOrder2, kTRUE,
                TSpectrum::kBackSmoothing3, kTRUE);

   auto b = new TGraph(n, sourceX, sourceY);
   b->SetLineColor(kRed);
   b->SetLineWidth(5);

   g->Draw("AL");
   b->Draw("L");
}

Thanks @couet.
I am getting this error in root terminal
error: no member named ‘GetPointX’ in ‘TGraph’
sourceX[i] = g->GetPointX(i);

error: no member named ‘GetPointY’ in ‘TGraph’
sourceY[i] = g->GetPointY(i);

void cleanback()
{
   auto C = new TCanvas();
   C->SetLogy();

   auto g = new TGraph("eu_gu_1.txt");
   auto s = new TSpectrum();

   double sourceX[6000];
   double sourceY[6000];
   int n = g->GetN();

   double *x = g->GetX();
   double *y = g->GetY();

   for (int i = 0; i < n; i++) {
      sourceX[i] = x[i];
      sourceY[i] = y[i];
   }

   s->Background(sourceY, n,
                10, TSpectrum::kBackDecreasingWindow,
                TSpectrum::kBackOrder2, kTRUE,
                TSpectrum::kBackSmoothing3, kTRUE);

   auto b = new TGraph(n, sourceX, sourceY);
   b->SetLineColor(kRed);
   b->SetLineWidth(5);

   g->Draw("AL");
   b->Draw("L");
}

Thanks @couet. for your help.