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.
Please read tips for efficient and successful posting and posting code
ROOT Version: 6.18
Platform: Mac OS Big Sur
Compiler: Not Provided
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");
How to do it in a Graph ?
You can get the maximum (for a TGraph
gr of size
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.