How to fit the Spectrum Peaks

Dear Sir/Madam.
I’m working with the Nuclear Magnetic Resonance spectrum (NMR). and I want to fit the spectrum peaks to get information on peak areas. With a large number of peaks in the NMR spectrum, I am fitting for functions which are evaluated, and it takes a lot of time. How can I fit all the peaks for a short time? Could you show me a way? Thank you very much for your kind help.
Best regards,

Can you post a small example showing what you are doing ?

I refer and use a macro, which can read and fit the X-ray diffraction peaks of Ethylene TetraFluoroEthylene material (ETFE), gamma and X-ray spectrals are recorded by Genie2K software, etc …
I can send you the file data that I am using the spectrum and macro file for reading and fit the spectrum peaks. I hope you can help me figure out how to fit faster spectrum. And I’m having problems with the classes in the Root command to output the correlation coefficient after fit the spectrum peaks. Could you show me a way?
Spectrum_analysis_3peaks-E-G-4.2-sort.cxx (23.3 KB)
GraftedETFE-E-G-4.2-sort.txt (684 KB)

Dear Sir/Madam.
I’m really sorry for you. I’ve attached the files with the edited name. I’m running these files with named Spectrum Analysis 3peaks.cxx and GraftedETFE.txt. So, you can rename files attached to these names, you can run them on Root.
Best regards.

It seems your code has bugs:

Processing 3peaks.cxx...
In file included from input_line_9:1:
/Users/couet/Downloads/3peaks.cxx:121:49: error: extraneous ')' before ';'
        func = multipeakFitting(h, 5, -51.659, 249.492));
/Users/couet/Downloads/3peaks.cxx:138:24: error: use of undeclared identifier
        TF1 *f = new TF1("f", mixedF, min, max, 3*(N+1)-1);
/Users/couet/Downloads/3peaks.cxx:188:3: error: use of undeclared identifier
/Users/couet/Downloads/3peaks.cxx:189:3: error: use of undeclared identifier
/Users/couet/Downloads/3peaks.cxx:190:15: error: use of undeclared identifier
                func[i+2] = peak;
/Users/couet/Downloads/3peaks.cxx:193:9: warning: address of stack memory
      associated with local variable 'func' returned [-Wreturn-stack-address]
        return func;
/Users/couet/Downloads/3peaks.cxx:218:9: error: cannot initialize a variable of
      type 'float *' with an rvalue of type 'Double_t *' (aka 'double *')
        float *pos = s->GetPositionX();
               ^     ~~~~~~~~~~~~~~~~~
/Users/couet/Downloads/3peaks.cxx:553:3: error: use of undeclared identifier
/Users/couet/Downloads/3peaks.cxx:556:13: error: use of undeclared identifier
        h = (TH1F*)h_chemicalShift->Clone();
/Users/couet/Downloads/3peaks.cxx:809:9: error: use of undeclared identifier
        return Spectrum_analysis(filename);

  • I really do not understand why you run the code on the Root, the error appears. I think the code file that I’m using is written to read and fit for many types of spectroscopies, and it is saved together with many other files in a folder. I tried again and realized that just using 3 files saved in the root installation folder: C:\root\macros
  • Three files that i have used is GraftedETFE.txt, Spectrum_analysis_3peaks.cxx and run.GraftedETFE.ETFE.bat
  • I have run the file run.GraftedETFE.ETFE.bat and getting results.
  • I have sent you 3 files that I used to fit the NMR spectrum on Root and two image files are my results. Because the run.GraftedETFE.ETFE.bat file did not send in here, i compressed to the run.GraftedETFE.ETFE.rar file and added here.
  • I hope you can run and fit to the results, then give me advice on how to be a better fit with shorter time and how to add the code in Spectrum_analysis_3peaks.cxx to display the correlation coefficient.
    thank you so much!

    run.GraftedETFE.ETFE.rar (442 Bytes)

    Spectrum_analysis_3peaks.cxx (23.3 KB)
    GraftedETFE.txt (684 KB)


Your code has compilation errors. I guess you are running it with CINT. In order to speedup the code, I would first of all compile your macro and run it with AClic or use ROOT 6. I see you use CINT functions for TF1, these are known to have bad CPU performances


It looks like you are running ROOT on windows. In that case you cannot use ROOT 6. But you can use Aclic.
To use AClic on a macro a.C you simply have to do do:

root> .x a.C+