# Subtracting exponential from Crystal ball

**URL:** <https://root-forum.cern.ch/t/subtracting-exponential-from-crystal-ball/34990>\
**Category:** Newbie\
**Created:** [July 3, 2019, 5:22pm UTC](https://root-forum.cern.ch/t/subtracting-exponential-from-crystal-ball/34990 "2019-07-03T17:22:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prya13](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ea666f/32.png) [@Prya13](https://root-forum.cern.ch/u/Prya13)\
**Post date:** [July 3, 2019, 5:22pm UTC](https://root-forum.cern.ch/t/subtracting-exponential-from-crystal-ball/34990/1 "2019-07-03T17:22:16Z")

</div>

Dear All,

Please requesting kind assistance with my macro, don’t see nor get the errors.

The macro, read in two histograms one fitted with a normal gaussian + exponential called hdndm and the other with a crystal ball function + exponential called CBh\_dndm.  
Before the hdndm worked perfectly but now somehow not printing on the canvas.  
Also with the addition of the crystal ball + exponential, got crash.

Section by section seems ok but together getting crash. Here is some of the message:

[crash\_report.pdf](https://root-forum.cern.ch/uploads/short-url/epTAG1hhOuTJ36rG2mfxrsbwCSg.pdf) (35.4 KB)

# \*\*\* Break \*\*\* segmentation violation

There was a crash (#6 0xf7191d2b in SigHandler(ESignals)  
#0 0xf76e0425 in \_\_kernel\_vsyscall ()  
#1 0xf6d57ee3 in \_\_waitpid\_nocancel () from /usr/lib/libc.so.6  
#2 0xf6cdda5e in do\_system () from /usr/lib/libc.so.6  
#3 0xf718bfdb in TUnixSystem::Exec(char const\*) ()

I have attached the code and the .root file for your most valuable assistance.

Cheers

[InitialCBnormfit.C](https://root-forum.cern.ch/uploads/short-url/svXU4Tr3NL6lqc4MulU3kAnGH9S.C) (16.8 KB)  
[hnorm.root](https://root-forum.cern.ch/uploads/short-url/4NslpBNPESnR5UP51atCU4n2MWu.root) (7.4 KB)

---

<div class="post-metadata">

**Author:** ![StephanH](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@StephanH](https://root-forum.cern.ch/u/StephanH)\
**Post date:** [July 8, 2019, 2:12pm UTC](https://root-forum.cern.ch/t/subtracting-exponential-from-crystal-ball/34990/2 "2019-07-08T14:12:37Z")

</div>

Hello @Prya13,

can you please compile the macro? In case you made a programming error, we would spot it much quicker.  
Compiling can be done as follows:

```auto
root [1] .L macroName.C+g

```

The `+g` is important, because it will also give us line numbers to pin down the location of the crash.

When you try this the first time, you will see complaints about missing headers. Just include them (such as `#include "TH1F.h"`) until it compiles.

---

<div class="post-metadata">

**Author:** ![Prya13](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ea666f/32.png) [@Prya13](https://root-forum.cern.ch/u/Prya13)\
**Post date:** [July 9, 2019, 7:13am UTC](https://root-forum.cern.ch/t/subtracting-exponential-from-crystal-ball/34990/3 "2019-07-09T07:13:28Z")

</div>

Hey StephanH,

Sorry for the late response. I did compile, wow so many errors came up, eg

/./InitialCBnormfit.C:208:31: error: too many decimal points in number  
cbfit-\>SetParameters(16,1.0,1.5.,3.097,0.07,100.,2.);  
^  
/./InitialCBnormfit.C:312:31: error: too many decimal points in number  
cbfit-\>SetParameters(16,1.0,1.5.,3.097,0.07,100.,2.);  
^  
/./InitialCBnormfit.C: In function ‘double CBFunction(double\*, double\*)’:  
/./InitialCBnormfit.C:26:35: error: ‘TMath’ has not been declared  
double A = pow(n/fabs(alpha),n)_TMath::Exp(-pow(fabs(alpha),2)/2.);  
^  
/./InitialCBnormfit.C:32:16: error: ‘TMath’ has not been declared  
val = norm_TMath::Exp(-0.5_pow(k,2));//val = Norm \* exp( -pow(x-x\_mean,2) / (2.0_pow(sigma,2)));  
^  
/./InitialCBnormfit.C: In function ‘double CBFunction\_bkg(double\*, double\*)’:  
/./InitialCBnormfit.C:50:35: error: ‘TMath’ has not been declared  
double A = pow(n/fabs(alpha),n)_TMath::Exp(-pow(fabs(alpha),2)/2.);  
^  
/./InitialCBnormfit.C:56:16: error: ‘TMath’ has not been declared  
val = norm_TMath::Exp(-0.5_pow(k,2));//val = Norm \* exp( -pow(x-x\_mean,2) / (2.0_pow(sigma,2)));  
^  
/./InitialCBnormfit.C:71:7: error: ‘TMath’ has not been declared  
if( TMath::IsNaN(val) )  
^  
/./InitialCBnormfit.C: At global scope:  
/./InitialCBnormfit.C:84:54: error: invalid conversion from ‘const char\*’ to ‘char’ [-fpermissive]  
void InitialCBnormfit(const char fname = “hnorm.root”)  
^  
/./InitialCBnormfit.C:87:3: error: ‘gStyle’ was not declared in this scope  
gStyle-\>SetOptStat(kFALSE);  
^  
/./InitialCBnormfit.C:91:3: error: ‘TFile’ was not declared in this scope  
TFile \*file = TFile::Open(“hnorm.root”);  
^  
/./InitialCBnormfit.C:91:10: error: ‘file’ was not declared in this scope  
TFile \*file = TFile::Open(“hnorm.root”);  
^  
/./InitialCBnormfit.C:91:17: error: ‘TFile’ is not a class or namespace  
TFile \*file = TFile::Open(“hnorm.root”);

But as you suggested I will added in the #includes  
I will update after I did it.

Cheers

---

<div class="post-metadata">

**Author:** ![StephanH](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@StephanH](https://root-forum.cern.ch/u/StephanH)\
**Post date:** [July 9, 2019, 2:45pm UTC](https://root-forum.cern.ch/t/subtracting-exponential-from-crystal-ball/34990/4 "2019-07-09T14:45:14Z")

</div>

It’s good that we get these errors. You will have to fix them first. If you are lucky, it will run after that.

---

<div class="post-metadata">

**Author:** ![Prya13](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ea666f/32.png) [@Prya13](https://root-forum.cern.ch/u/Prya13)\
**Post date:** [July 10, 2019, 1:44pm UTC](https://root-forum.cern.ch/t/subtracting-exponential-from-crystal-ball/34990/5 "2019-07-10T13:44:38Z")

</div>

Hey StephanH,

I have corrected all the errors now. It ran but function didn’t converge, some plots were produced and got following results:

```auto
Warning in <Fit>: Abnormal termination of minimization.
 FCN=10.2579 FROM MIGRAD STATUS=FAILED 404 CALLS 405 TOTAL
                     EDM=2.08108e-05 STRATEGY= 1 ERR MATRIX NOT POS-DEF
  EXT PARAMETER APPROXIMATE STEP FIRST   
  NO. NAME VALUE ERROR SIZE DERIVATIVE 
   1 amp_gauss 7.43015e+04 1.17493e+05 7.99008e+00 -4.12253e-08
   2 Mean_Gaus 6.65656e+01 7.73631e+03 8.51753e-01 2.06402e-08
   3 sigma_Gaus 4.82293e+02 6.73164e+02 9.73537e-02 6.44358e-06
 FCN=25.5236 FROM MIGRAD STATUS=CONVERGED 206 CALLS 207 TOTAL
                     EDM=7.98077e-09 STRATEGY= 1 ERROR MATRIX ACCURATE 
  EXT PARAMETER STEP FIRST   
  NO. NAME VALUE ERROR SIZE DERIVATIVE 
   1 amp_gauss 1.54164e+01 1.47183e+00 5.09820e-03 5.32093e-05
   2 Mean_Gaus 3.09700e+00 fixed    
   3 sigma_Gaus 8.06692e-03 2.66523e-03 9.37481e-06 6.83202e-03
   4 amp_exp 1.00294e+04 4.62617e+02 1.59419e+00 1.16244e-07
   5 exp_arg 1.90000e+00 fixed    
                               ERR DEF= 0.5
Warning in <Fit>: Abnormal termination of minimization.
 FCN=35.7224 FROM MIGRAD STATUS=CALL LIMIT 1951 CALLS 1952 TOTAL
                     EDM=0.000569661 STRATEGY= 1 ERR MATRIX NOT POS-DEF
  EXT PARAMETER APPROXIMATE STEP FIRST   
  NO. NAME VALUE ERROR SIZE DERIVATIVE 
   1 norm 9.31529e+01 4.49030e+00 -7.85305e-02 4.52400e-02
   2 alpha -1.06991e+00 3.75971e-02 3.29589e-04 -6.74695e-01
   3 n 5.86255e-01 8.56123e-02 1.50570e-03 -1.77838e+00
   4 mu 3.08897e+00 5.79251e-04 -1.02817e-05 -1.68369e+02
   5 sigma 5.61721e-02 5.28140e-08 4.62978e-10 1.13822e+02
   6 bkgnorm 2.03528e+03 6.38759e+01 -1.10861e+00 4.86929e-03
   7 bkgslope 1.40000e+00 9.00510e-03 -1.64570e-04 -6.14438e+01
                               ERR DEF= 0.5
Unknown function: cbnormfit
Fit N_J/Psi 15.4164 1.47183
Fit CBN_J/Psi 93.1529 4.4903
 FCN=2.80627 FROM MIGRAD STATUS=CONVERGED 82 CALLS 83 TOTAL
                     EDM=1.23566e-06 STRATEGY= 1 ERROR MATRIX ACCURATE 
  EXT PARAMETER STEP FIRST   
  NO. NAME VALUE ERROR SIZE DERIVATIVE 
   1 amp_gauss 1.63064e+00 5.80382e-01 6.05592e-04 -8.89368e-04
   2 Mean_Gaus 3.09700e+00 fixed    
   3 sigma_Gaus 5.71780e-02 4.47248e-02 4.32561e-05 2.98863e-02
   4 amp_exp 9.88453e+02 1.62479e+02 1.80877e-01 3.64061e-06
   5 exp_arg 1.90000e+00 fixed    
                               ERR DEF= 0.5
Error: exp param[0]=788.338 up:709 low:-inf out of range InitialCBnormfit.C:104:
 FCN=48250.9 FROM HESSE STATUS=FAILED 11 CALLS 403 TOTAL
                     EDM=0 STRATEGY= 1 ERROR MATRIX UNCERTAINTY 100.0 per cent
  EXT PARAMETER APPROXIMATE STEP FIRST   
  NO. NAME VALUE ERROR SIZE DERIVATIVE 
   1 p0 -6.21298e+06 1.00000e+00 0.00000e+00 0.00000e+00
   2 p1 0.00000e+00 1.00000e+00 0.00000e+00 0.00000e+00
   3 p2 0.00000e+00 1.00000e+00 0.00000e+00 0.00000e+00
   4 p3 0.00000e+00 1.00000e+00 0.00000e+00 0.00000e+00
   5 p4 0.00000e+00 1.00000e+00 0.00000e+00 0.00000e+00
   6 p5 0.00000e+00 1.00000e+00 0.00000e+00 0.00000e+00
   7 p6 0.00000e+00 1.00000e+00 0.00000e+00 0.00000e+00
                               ERR DEF= 0.5
(class TFitResultPtr)166423400
***Interpreter error recovered***

```

New code: [InitialCBnormfit.C](https://root-forum.cern.ch/uploads/short-url/idSDqAVgFqesvcNQhOqrANN64Z4.C) (18.6 KB)
