Problem fitting peaks using example peaks.C


_ROOT Version: 5.34/09
_Platform: Linux 3.11.10-100.fc18.x86_64
_Compiler: gcc version 4.7.2 20121109 (Red Hat 4.7.2-8) (GCC)


Hello,

I am using “peaks.C” file available at https://root.cern.ch/doc/v608/peaks_8C.html to learn and to see how the peak searching and fitting works. I am using “.x peaks.C” command to execute the code. With this the histogram “h” displays 10 peaks. However, histogram"h2" shows ONLY peaks with linearly decreasing background. But peak fitting is NOT working. Below, please find some information which might be helpful to diagnose the issue:

++++++++++++++++++++++
 Now fitting: Be patient
 FCN=18902.2 FROM HESSE     STATUS=FAILED         15 CALLS        1169 TOTAL
                     EDM=7.34152e-22    STRATEGY= 1  ERROR MATRIX UNCERTAINTY 100.0 per cent
  EXT PARAMETER                APPROXIMATE        STEP         FIRST   
  NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE 
   1  p0           5.65386e+02   8.01205e-01   5.37875e-02   3.38181e-11
   2  p1          -4.06380e-01   1.20528e-03   8.09144e-05   0.00000e+00
   3  p2          -3.88877e+05   4.24264e-01  -0.00000e+00   0.00000e+00
   4  p3           5.67454e+17   1.41421e+00  -0.00000e+00   0.00000e+00
++++++++++++++++++++++++++

I have also noticed that when I tried to the compiler it throws the following error:

=================================
root [0] .x peaks.C++
Info in <TUnixSystem::ACLiC>: creating shared library /home/ajay/Downloads/./peaks_C.so
In file included from /home/ajay/Downloads/peaks_C_ACLiC_dict.h:34:0,
                 from /home/ajay/Downloads/peaks_C_ACLiC_dict.cxx:17:
/home/ajay/Downloads/./peaks.C: In function ‘void peaks(Int_t)’:
/home/ajay/Downloads/./peaks.C:57:39: error: cannot convert ‘Float_t* {aka float*}’ to ‘Double_t* {aka double*}’ in initialization
g++: error: /home/ajay/Downloads/peaks_C_ACLiC_dict.o: No such file or directory
Error in <ACLiC>: Compilation failed!
Error: Function peaks() is not defined in current scope  :0:
*** Interpreter error recovered ***
root [1]
 =================================

Please help.

With best regards,

Ajay

1 Like

Great! That works perfectly.

Also, I would like to write following parameters (preferably to a file) after the fitting

(1) Area, (2) Error in Area, (3) FWHM, (4) Error in FHWM, (5) Peak Height, and (6) Error in Peak height.

for each fitted peak.

Can you suggest how to achieve this by editing the code you have mentioned earlier?

Thanking you in advance.

Ajay

also note this (for your future posts): Tips for Efficient and Successful Posting

Sorry for reposting the following, but it seems my earlier post got was probably left unnoticed.
Ajay

==========
Great! That works perfectly.

Also, I would like to write following parameters (preferably to a file) after the fitting:

(1) Area, (2) Error in Area, (3) FWHM, (4) Error in FHWM, (5) Peak Height, and (6) Error in Peak height.for each fitted peak.

Can you suggest how to achieve this by editing the code you have mentioned earlier?

Thanking you in advance.

Ajay

In the end of the “peaks” function (right after h2->Fit("fit");) add (the meanings of all parameters you need to “extract” from the “peaks” source code):

   for (Int_t i = 0; i < fit->GetNpar(); i++) printf("%s = %g +- %g\n", fit->GetParName(i), fit->GetParameter(i), fit->GetParError(i));

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