This macro fits the source spectrum using the AWMI algorithm from the "TSpectrumFit" class ("TSpectrum" class is used to find peaks).
created -9.76 34.9074 7
created -9.28 49.8678 10
created -8.8 24.9339 5
created -8.32 14.9603 3
created -7.84 4.98678 1
created -7.36 14.9603 3
created -6.88 39.8942 8
created -6.4 44.881 9
created -5.92 14.9603 3
created -5.44 9.97356 2
created -4.96 4.98678 1
created -4.48 49.8678 10
created -4 49.8678 10
created -3.52 14.9603 3
created -3.04 39.8942 8
created -2.56 44.881 9
created -2.08 49.8678 10
created -1.6 44.881 9
created -1.12 19.9471 4
created -0.64 34.9074 7
created -0.16 19.9471 4
created 0.32 9.97356 2
created 0.8 29.9207 6
created 1.28 24.9339 5
created 1.76 4.98678 1
created 2.24 44.881 9
created 2.72 44.881 9
created 3.2 44.881 9
created 3.68 39.8942 8
created 4.16 39.8942 8
created 4.64 44.881 9
created 5.12 14.9603 3
created 5.6 4.98678 1
created 6.08 24.9339 5
created 6.56 9.97356 2
created 7.04 19.9471 4
created 7.52 19.9471 4
created 8 4.98678 1
created 8.48 9.97356 2
created 8.96 44.881 9
created 9.44 14.9603 3
the total number of created peaks = 41 with sigma = 0.08
the total number of found peaks = 41 with sigma = 0.0800011 (+-1.75257e-05)
fit chi^2 = 1.7387e-06
found -9.28 (+-0.000145099) 49.8677 (+-0.089191) 10.0001 (+-0.000590639)
found -4.48 (+-0.000144748) 49.8677 (+-0.0891686) 10.0001 (+-0.000590491)
found -4 (+-0.000145083) 49.8678 (+-0.089191) 10.0001 (+-0.000590639)
found -2.08 (+-0.000145537) 49.868 (+-0.0892243) 10.0002 (+-0.000590859)
found -6.4 (+-0.000152902) 44.881 (+-0.0846116) 9.00011 (+-0.000560314)
found -2.56 (+-0.000153533) 44.8813 (+-0.0846543) 9.00018 (+-0.000560596)
found -1.6 (+-0.000153166) 44.8811 (+-0.0846296) 9.00014 (+-0.000560432)
found 2.24 (+-0.000152605) 44.8809 (+-0.0845943) 9.0001 (+-0.000560199)
found 2.72 (+-0.000153538) 44.8813 (+-0.0846546) 9.00018 (+-0.000560598)
found 3.2 (+-0.000153466) 44.8813 (+-0.0846496) 9.00017 (+-0.000560565)
found 4.64 (+-0.000152902) 44.881 (+-0.0846116) 9.00011 (+-0.000560314)
found 8.96 (+-0.000152261) 44.8806 (+-0.0845691) 9.00005 (+-0.000560032)
found -6.88 (+-0.000162385) 39.8943 (+-0.0797854) 8.00012 (+-0.000528353)
found -3.04 (+-0.000162385) 39.8943 (+-0.0797854) 8.00012 (+-0.000528353)
found 3.68 (+-0.000162932) 39.8946 (+-0.0798182) 8.00017 (+-0.000528571)
found 4.16 (+-0.000162932) 39.8946 (+-0.0798182) 8.00017 (+-0.000528571)
found -9.76 (+-0.000173945) 34.9075 (+-0.0746449) 7.0001 (+-0.000494312)
found -0.64 (+-0.000173381) 34.9074 (+-0.07462) 7.00008 (+-0.000494147)
found 0.800001 (+-0.00018722) 29.9206 (+-0.0690829) 6.00007 (+-0.00045748)
found -8.8 (+-0.000206257) 24.9342 (+-0.0631096) 5.00013 (+-0.000417923)
found 1.28 (+-0.000205134) 24.9339 (+-0.0630669) 5.00007 (+-0.000417641)
found 6.08 (+-0.000204335) 24.9337 (+-0.0630362) 5.00003 (+-0.000417437)
found -1.12 (+-0.000231773) 19.9477 (+-0.056484) 4.00016 (+-0.000374047)
found -0.160002 (+-0.000230309) 19.9473 (+-0.0564377) 4.00009 (+-0.000373741)
found 7.04 (+-0.000229733) 19.9471 (+-0.056419) 4.00006 (+-0.000373617)
found 7.52 (+-0.000229291) 19.9471 (+-0.0564064) 4.00005 (+-0.000373533)
found -5.92 (+-0.000266969) 14.9607 (+-0.0489021) 3.00011 (+-0.000323838)
found -3.52 (+-0.000268842) 14.9611 (+-0.0489474) 3.00018 (+-0.000324139)
found 5.12 (+-0.00026639) 14.9606 (+-0.0488896) 3.0001 (+-0.000323756)
found 9.44 (+-0.000264744) 14.9607 (+-0.0488605) 3.00012 (+-0.000323563)
found -8.32 (+-0.000265557) 14.9604 (+-0.0488681) 3.00006 (+-0.000323613)
found -7.36 (+-0.00026621) 14.9606 (+-0.0488848) 3.00009 (+-0.000323724)
found -5.44 (+-0.000325465) 9.97363 (+-0.0399035) 2.00004 (+-0.000264248)
found 0.320001 (+-0.000328534) 9.97393 (+-0.039953) 2.0001 (+-0.000264576)
found 6.56 (+-0.000328189) 9.97388 (+-0.0399471) 2.00009 (+-0.000264537)
found 8.48001 (+-0.000327483) 9.97394 (+-0.0399387) 2.0001 (+-0.000264481)
found 1.76001 (+-0.0004709) 4.98743 (+-0.0283072) 1.00014 (+-0.000187456)
found -4.95999 (+-0.00046866) 4.98733 (+-0.0282887) 1.00012 (+-0.000187333)
found -7.84 (+-0.000465671) 4.98702 (+-0.02826) 1.00006 (+-0.000187143)
found 5.6 (+-0.000467214) 4.98712 (+-0.0282737) 1.00008 (+-0.000187233)
found 8 (+-0.000465449) 4.98702 (+-0.0282584) 1.00006 (+-0.000187132)
#include <iostream>
TH1F *FitAwmi_Create_Spectrum(
void)
{
delete gROOT->FindObject(
"h");
npeaks++;
<< std::endl;
}
std::cout <<
"the total number of created peaks = " << npeaks <<
" with sigma = " <<
sigma << std::endl;
}
void FitAwmi(void)
{
TH1F *
h = FitAwmi_Create_Spectrum();
if (!cFit)
cFit =
new TCanvas(
"cFit",
"cFit", 10, 10, 1000, 700);
else
for (i = 0; i < nbins; i++)
source[i] =
h->GetBinContent(i + 1);
for (i = 0; i < nfound; i++)
FixAmp[i] = FixPos[i] =
kFALSE;
for (i = 0; i < nfound; i++) {
bin = 1 +
Int_t(Pos[i] + 0.5);
Amp[i] =
h->GetBinContent(bin);
}
delete gROOT->FindObject(
"d");
d->SetNameTitle(
"d",
"");
for (i = 0; i < nbins; i++)
d->SetBinContent(i + 1, source[i]);
sigmaErr *= dx;
std::cout <<
"the total number of found peaks = " << nfound <<
" with sigma = " <<
sigma <<
" (+-" << sigmaErr <<
")"
<< std::endl;
std::cout <<
"fit chi^2 = " << pfit->
GetChi() << std::endl;
for (i = 0; i < nfound; i++) {
bin = 1 +
Int_t(Positions[i] + 0.5);
Pos[i] =
d->GetBinCenter(bin);
Amp[i] =
d->GetBinContent(bin);
Positions[i] =
x1 + Positions[i] * dx;
PositionsErrors[i] *= dx;
Areas[i] *= dx;
AreasErrors[i] *= dx;
std::cout << "found " << Positions[i] << " (+-" << PositionsErrors[i] << ") " << Amplitudes[i] << " (+-"
<< AmplitudesErrors[i] << ") " << Areas[i] << " (+-" << AreasErrors[i] << ")" << std::endl;
}
if (pm) {
h->GetListOfFunctions()->Remove(pm);
delete pm;
}
h->GetListOfFunctions()->Add(pm);
delete pfit;
delete[] Amp;
delete[] FixAmp;
delete[] FixPos;
delete s;
delete[] source;
return;
}
bool Bool_t
Boolean (0=false, 1=true) (bool)
int Int_t
Signed integer 4 bytes (int)
double Double_t
Double 8 bytes.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t dest
Option_t Option_t TPoint TPoint const char x1
R__EXTERN TRandom * gRandom
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
void Clear(Option_t *option="") override
Remove all primitives from the canvas.
1-D histogram with a float per channel (see TH1 documentation)
A PolyMarker is defined by an array on N points in a 2-D space.
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
virtual Double_t Uniform(Double_t x1=1)
Returns a uniform deviate on the interval (0, x1).
Advanced 1-dimensional spectra fitting functions.
void SetPeakParameters(Double_t sigma, Bool_t fixSigma, const Double_t *positionInit, const Bool_t *fixPosition, const Double_t *ampInit, const Bool_t *fixAmp)
This function sets the following fitting parameters of peaks:
Double_t * GetAmplitudesErrors() const
void FitAwmi(Double_t *source)
This function fits the source spectrum.
Double_t * GetAreasErrors() const
void GetSigma(Double_t &sigma, Double_t &sigmaErr)
This function gets the sigma parameter and its error.
Double_t * GetAreas() const
Double_t * GetAmplitudes() const
void SetFitParameters(Int_t xmin, Int_t xmax, Int_t numberIterations, Double_t alpha, Int_t statisticType, Int_t alphaOptim, Int_t power, Int_t fitTaylor)
This function sets the following fitting parameters:
Double_t * GetPositionsErrors() const
Double_t * GetPositions() const
Advanced Spectra Processing.
Int_t SearchHighRes(Double_t *source, Double_t *destVector, Int_t ssize, Double_t sigma, Double_t threshold, bool backgroundRemove, Int_t deconIterations, bool markov, Int_t averWindow)
One-dimensional high-resolution peak search function.
Double_t * GetPositionX() const
constexpr Double_t Sqrt2()
Double_t Sqrt(Double_t x)
Returns the square root of x.
constexpr Double_t TwoPi()