# Crystal ball function initial parameters

**URL:** <https://root-forum.cern.ch/t/crystal-ball-function-initial-parameters/54497>\
**Category:** Newbie\
**Tags:** hist, root\
**Created:** [April 15, 2023, 7:02am UTC](https://root-forum.cern.ch/t/crystal-ball-function-initial-parameters/54497 "2023-04-15T07:02:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![arazquin](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/df788c/32.png) [@arazquin](https://root-forum.cern.ch/u/arazquin)\
**Post date:** [April 15, 2023, 7:02am UTC](https://root-forum.cern.ch/t/crystal-ball-function-initial-parameters/54497/1 "2023-04-15T07:02:21Z")

</div>

_ROOT Version:_ 6.18/00  
_Platform:_ Red Hat 8.5.0-16  
_Compiler:_ gcc version 8.5.0

* * *

Hello everyone,  
I want to fit a histogram (see figure) with the crystal ball function following the code:

```auto
TF1 *fitFunction = new TF1("fitFunction", "crystalball", 84, 105);
fitFunction->SetParameters(p0, p1, p2, p3, p4);
hist->Fit("fitFunction");

```

But I am finding it hard to set the initial values p0…p4. First of, I am not sure what they refer to, since I couldn’t find the explicit definition of the “crystalball” function, and second, most examples I have seen fit around 0 so I am a bit confused.

I would appreciate it if you could help me understand and find the appropriate parameters, thank you!

 ![energy_dist](https://root-forum.cern.ch/uploads/default/original/3X/4/e/4e6dad7f24cc52b680a9c2b4ba8b23f2cd26094b.png)

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [April 15, 2023, 9:18am UTC](https://root-forum.cern.ch/t/crystal-ball-function-initial-parameters/54497/2 "2023-04-15T09:18:23Z")

</div>

Try: `fitFunction->Print();`

> [@Fitting Data with user defined function](https://root-forum.cern.ch/t/fitting-data-with-user-defined-function/30758/16):
>
> "crystalball" = "[Constant] \* ROOT::Math::crystalball\_function(x, [Alpha], [N], [Sigma], [Mean])" [Wikipedia → Crystal Ball function](https://en.wikipedia.org/wiki/Crystal_Ball_function) ; [ROOT::Math::crystalball\_function](https://root.cern/doc/master/group__PdfFunc.html#ga8f46b655fa77cceb930ddb11e4e12196) ; [${ROOTSYS}/tutorials/math/CrystalBall.C](https://root.cern.ch/doc/master/CrystalBall_8C.html) ; [${ROOTSYS}/tutorials/fit/fitNormSum.C](https://root.cern.ch/doc/master/fitNormSum_8C.html) ; [${ROOTSYS}/tutorials/fit/fitNormSum.py](https://root.cern.ch/doc/master/fitNormSum_8py.html)

---

<div class="post-metadata">

**Author:** ![arazquin](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/df788c/32.png) [@arazquin](https://root-forum.cern.ch/u/arazquin)\
**Post date:** [April 15, 2023, 9:56am UTC](https://root-forum.cern.ch/t/crystal-ball-function-initial-parameters/54497/3 "2023-04-15T09:56:00Z")

</div>

Thank you!
