Remove background linearly and find Peaks

Hello,

I’m trying to remove background in my spectrum in a linear way from a poi A=(x1,y1) to a point B=(x2,y2):

{
   TCanvas c("", "", 1920, 1980);
   c.SetFillColor(0);
   c.SetBorderMode(0);
   c.SetBorderSize(2);
   c.SetGridx();
   c.SetGridy();
   c.SetTickx(1);
   c.SetTicky(1);
   c.SetFrameBorderMode(0);
   c.SetFrameBorderMode(0);

   gStyle->SetOptFit(111);

   TGraphErrors g("Xenon_Spectrum_15_Nov_2023_rescaled.txt", "%lg %lg %lg %lg");

   g.GetXaxis()->SetTitle("Wavelength [nm]");
   g.GetYaxis()->SetTitle("Charge [nC]");

   // Definisci la funzione lineare per il background
   TF1 background("background", "[0] + [1]*x", 250, 550);

   // Imposta i parametri iniziali della funzione lineare
   background.SetParameter(0, 25);             // Intersezione con l'asse y (punto A)
   background.SetParameter(1, (34.15 - 25) / (550 - 250));  // Coefficiente angolare (punti A e B)

   // Sottrai manualmente il background dal grafico principale
   for (int i = 0; i < g.GetN(); ++i) {
       Double_t x, y;
       g.GetPoint(i, x, y);
       Double_t backgroundValue = background.Eval(x);
       g.SetPoint(i, x, y - backgroundValue + 15);
   }

   g.Draw("ap");
}

And this works… but i also want to find the peaks and plot the FWHM over the centroid of the peaks (with error in y and x ) but TSpecrum is deprecated and i dont know how to use with TGrapherrors.

Any idea?

Thanks

see this discussion

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.