Subtracting exponential from Crystal ball

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 (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 (16.8 KB)
hnorm.root (7.4 KB)

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:

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.

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.5pow(k,2));//val = Norm * exp( -pow(x-x_mean,2) / (2.0pow(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.5pow(k,2));//val = Norm * exp( -pow(x-x_mean,2) / (2.0pow(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

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

Hey StephanH,

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

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 (18.6 KB)