# Convolution of Breit–Wigner and crystal ball function

**URL:** <https://root-forum.cern.ch/t/convolution-of-breit-wigner-and-crystal-ball-function/58347>\
**Category:** Newbie\
**Tags:** root\
**Created:** [March 1, 2024, 11:05am UTC](https://root-forum.cern.ch/t/convolution-of-breit-wigner-and-crystal-ball-function/58347 "2024-03-01T11:05:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gami](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/d6d6ee/32.png) [@gami](https://root-forum.cern.ch/u/gami)\
**Post date:** [March 1, 2024, 11:05am UTC](https://root-forum.cern.ch/t/convolution-of-breit-wigner-and-crystal-ball-function/58347/1 "2024-03-01T11:05:30Z")

</div>

Hello all,  
I am trying to take convolution of Breit–Wigner and crystal ball function to fit phi resonance signal and polynomial of order 2 to fit background. in fitting with convolution of Breit–Wigner and crystal ball for BW I got 3 parameters like mass, width and yield and for CB I got 4 alpha, n , sigma and mean from this 7 parameters I want to extract mass, width and resolution of phi resonance. can anybody please help me how to extract this parameters.

```auto
Double_t CB(Double_t *x, Double_t *par)
{
    return(ROOT::Math::crystalball_pdf(x[0], par[0], par[1], par[2], par[3]));
}
Double_t BW(Double_t *x, Double_t *par)
{
    return (0.5 * par[2] * par[1] / TMath::Pi() / ((x[0] - par[0]) * (x[0] - par[0]) + 0.25 * par[1] * par[1]));
}

Double_t polynomial2(Double_t *x, Double_t *par)
{
    double poly2 = par[2] + par[1] * x[0] + par[0] * x[0] * x[0];
    return (poly2);
}

Double_t bwcb(Double_t *x, Double_t *par)
{
    Double_t bw_value = BW(x, par); 
    Double_t cb_value = CB(x, &par[3]);
    Double_t convolution = cb_value * bw_value;

    return convolution;
}
Double_t bwcbp(Double_t *x, Double_t *par)
{
    Double_t bwcb_value = bwcb(x, par);
    Double_t poly2_value = polynomial2(x, &par[6]);
    Double_t result = bwcb_value + poly2_value;

    return result;
} 

```

this is function defined in my header file.  
in my cxx file I am setting my parameters as below

```auto
TF1 *fitFcn = new TF1("fitfunc", CB, lowfitrange[ip], highfitrange[ip], 7);

// Set initial parameters for the fit function
fitFcn->SetParameter(0, 1.02); // Breit-Wigner: yield
fitFcn->FixParameter(1, 0.0042); // Breit-Wigner: mass peak
fitFcn->SetParameter(2, 3000000); // Breit-Wigner: width
fitFcn->SetParameter(0, 3); // Crystal Ball: alpha
fitFcn->SetParameter(1, 300000); // Crystal Ball: n
fitFcn->SetParameter(3, 1.02); // Crystal Ball: mean
fitFcn->SetParameter(2, 0.0042); // Crystal Ball: sigma
r = hfsig->Fit(fitFcn, "REBMS0E+"); 

```

Thanks in advance.  
Sarjeeta

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [March 1, 2024, 12:13pm UTC](https://root-forum.cern.ch/t/convolution-of-breit-wigner-and-crystal-ball-function/58347/2 "2024-03-01T12:13:19Z")

</div>

Dear Sarjeeta,

Thanks for the question and welcome to the ROOT community!

I think you are basically there. The `r` object you have as a result of your fit is a TResultPtr instance, that allows you to access all the information about the fit. You can learn how to use a TResultPtr instance here [Fitting histograms - ROOT](https://root.cern/manual/fitting/#the-fit-result-object) (r.g. `r->Parameter(0)` or `r->ParError(0)`)

I hope this helps!

Cheers,  
D

---

<div class="post-metadata">

**Author:** ![Eddy\_Offermann](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eddy_offermann/32/25079_2.png) [@Eddy\_Offermann](https://root-forum.cern.ch/u/Eddy_Offermann)\
**Post date:** [March 6, 2024, 8:41pm UTC](https://root-forum.cern.ch/t/convolution-of-breit-wigner-and-crystal-ball-function/58347/3 "2024-03-06T20:41:22Z")

</div>

Hi Sarjeeta,

You seem to multiply two functions but you mention convolution ?!

Maybe [this](https://root.cern/doc/master/fitConvolution_8C.html) is what you are  
looking for.

-Eddy
