Fitting two peaks

Dear All,
I am trying to fit two gamma peaks close to each other,
for this I build two gaussian fitting +BG

TF1 *doublegaus= new TF1("doublegaus","([6]*x+[7])+([0]*exp((-0.5*(x-[1])*(x-[1]))/([2]*[2])))+([3]*exp((-0.5*(x-[4])*(x-[4]))/([5]*[5])))",26,38);
    
        doublegaus->SetParameter(0, 10000);           //constant1
        doublegaus->SetParameter(1, 30);              //main1
        doublegaus->SetParameter(2, 1);               //sigma1
    
        doublegaus->SetParameter(3, 100);             //constant2
        doublegaus->SetParameter(4, 35);              //main2
        doublegaus->SetParameter(5, 0.5);           //sigma2
    
        doublegaus->SetParameter(6, 0);             //BG
        doublegaus->SetParameter(7, 1000);           //BG
     
        h2_calibrated->Fit(doublegaus,"R0");
        doublegaus->SetLineColor(kRed);
        doublegaus->Draw("same");

Peak30 around bin number 30, and Peak35 around bin number 35.
the fitting converge

FCN=11138.4 FROM MIGRAD    STATUS=CONVERGED    2113 CALLS        2114 TOTAL
                     EDM=4.33375e-08    STRATEGY= 1      ERROR MATRIX ACCURATE 
  EXT PARAMETER                                   STEP         FIRST   
  NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE 
   1  p0           7.67244e+05   8.79483e+02   3.58009e+01   1.67668e-07
   2  p1           2.91784e+01   5.59168e-04   2.76273e-05  -1.94405e-01
   3  p2           5.54109e-01   4.64115e-04   1.73015e-05   1.00972e-01
   4  p3           1.73060e+05   4.13150e+02   1.72465e+01   6.57766e-08
   5  p4           3.34742e+01   1.32726e-03   6.78958e-05  -7.20144e-02
   6  p5          -6.04327e-01   1.12626e-03   4.44822e-05  -1.89956e-01
   7  p6          -1.71326e+03   1.25736e+01   6.35794e-02   9.97247e-05
   8  p7           7.43028e+04   4.39822e+02   2.19156e+00   3.25446e-06

No the sigma for the second peak (p5) has negative value, How this is possible???

one more question, to calculate the total number under the peak I used the integral function. for both the peak range and subtracted the BG integral

for example, to calculate the total number of peak 30.

TF1 *BG= new TF1("BG","([0]*x+[1])",26,38);
    BG->SetParameter(0, doublegaus->GetParameter(6));
    BG->SetParameter(1, doublegaus->GetParameter(7));
    BG->SetLineColor(kOrange);
   // BG->Draw("same");
    
    
    
    TF1 *Peak30= new TF1("Peak30","([0]*exp((-0.5*(x-[1])*(x-[1]))/([2]*[2])))",26,38);
    Peak30->SetParameter(0, doublegaus->GetParameter(0));
    Peak30->SetParameter(1, doublegaus->GetParameter(1));
    Peak30->SetParameter(2, doublegaus->GetParameter(2));
    Peak30->SetLineColor(kRed);
   // Peak30->Draw("same");
**double** Peak30_integral2= (Peak30 ->Integral(27,31)/h2_calibrated->GetBinWidth(0))- (BG->Integral(27,31)/h2_calibrated->GetBinWidth(0));

is this correct??

Cheers

Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided

This answer suggests sigma can certainly be negative, you should just take its absolute value.

Also, this expression

can be simplified:

[6]*x + [7] + [0]*exp(-0.5*TMath::Sq((x-[1])/[2])) + [3]*exp((-0.5*TMath::Sq((x-[4])/[5]))

Thank you for answer and the simplified formula.
what about the total number under the peak, In principle do I need to subtract the background? and am I doing it in the correct way??

If you want the number of signal events under the peak, then yeah, you have to subtract the bkg. I’d change your approach a bit:

double Peak30_integral2= Peak30->Integral(27, 31) - BG->Integral(27, 31);

It’s not clear to me why you divide by the bin width. TF1 objects are analytical formulas, they do not have bins like histograms.

Many Thanks for your assistance

Try:

TF1 *doublegaus= new TF1("doublegaus", "gausn(0) + gausn(3) + pol1(6)", 26., 38.);
doublegaus->Print();

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