# Smooth a Graph with Gaussian Function

Hello,

I am performing some Monte Carlo simulation, where I am simulating a decay spectrum for a specific number of nuclei.
I need to smooth every decay spectrum with a gaussian function and compare it to the experimental spectrum and calculate the variance.
And I need to perform it for all the simulated nuclei.
Every simulated decay spectrum is saved as a Graph.

Please help, on how to perform this smoothing operation on a Graph. I need to make it automated, where it can automatically generate some mean and then fit it in within those limits.

thanks
MS

ROOT Version: 6.18
Platform: Mac OS Big Sur
Compiler: Not Provided

thanks.

Is there a way to automatically be able find the mean for the spectrum.

for example in a histogram we can do -

``````double meanMin, meanMax;
meanMin = .6 * gIntensity->GetBinCenter(gIntensityP->GetMaximumBin());
meanMax = 1.4* gIntensity->GetBinCenter(gIntensityP->GetMaximumBin());

//printf("\nmax: %f\nmin: %f\n",meanMax,meanMin);

TF1 *constrained_gaus = new TF1("constrained_gaus","gaus");
constrained_gaus->SetParLimits(1,meanMin, meanMax);

gIntensity->Fit("constrained_gaus");
gIntensity->Draw("same");
``````

How to do it in a Graph ?
MS

You can get the maximum (for a TGraph `gr` of size `n`) with

`````` Double_t max = TMath::MaxElement(n,gr->GetY());
``````

then you can loop over all the n points of the graph and find the x corresponding to that y (there might be more than one such point, so take care of that), using GetPoint.

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