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
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
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.
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.
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?
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");
}
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");
}