Finding the Std Deviation of each peak in a histogram

Hi everyone,

I am a newbie with root. I have a histogram with multiple peaks in it. I need to find the standard deviation and no. of counts in each peak. I used TSpectrum to search for all the peaks and the code works fine.
The place I am stuck is I am not sure how to find the Std Deviation and no. of counts in each peak of the histogram. I tried a bunch of things but I am getting an error. Can anyone please help?

The part which works fine is as follows -

    TSpectrum *mySpec = new TSpectrum();

    Int_t npeaksFound = mySpec->Search(hTOFbacksub,1);

    Double_t x[npeaksFound];

    cout << "No. of Peaks found is = " << npeaksFound << endl;

    Double_t *xpeaks = mySpec->GetPositionX();

    for(Int_t iter = 0; iter<npeaksFound; iter++ ) {
      cout << xpeaks[iter] << endl;

Thank you for your time and help! Really appreciate it!

ROOT Version: 6.18/04
Platform: C++
Compiler: Visual Studio Code

Welcome to the ROOT Forum! I think @moneta can give you some hints


As in the peaks.C tutorial (see ROOT: tutorials/spectrum/peaks.C File Reference ) you would need to fit your peak with a Gaussian function. Then from the fitted Gaussian sigma you obtain the std devotion and from the integral the number of counts. If you have a background you will have to consider and subtract the background component when getting the peak counts.


1 Like

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