This macro fits the source spectrum using the AWMI algorithm from the "TSpectrumFit" class ("TSpectrum" class is used to find peaks).
created -9.82 53.1923 8
created -9.46 6.64904 1
created -9.1 26.5962 4
created -8.74 53.1923 8
created -8.38 53.1923 8
created -8.02 13.2981 2
created -7.66 39.8942 6
created -7.3 46.5433 7
created -6.94 33.2452 5
created -6.58 19.9471 3
created -6.22 6.64904 1
created -5.86 6.64904 1
created -5.5 53.1923 8
created -5.14 59.8413 9
created -4.78 19.9471 3
created -4.42 53.1923 8
created -4.06 66.4904 10
created -3.7 19.9471 3
created -3.34 66.4904 10
created -2.98 59.8413 9
created -2.62 13.2981 2
created -2.26 66.4904 10
created -1.9 13.2981 2
created -1.54 46.5433 7
created -1.18 46.5433 7
created -0.82 53.1923 8
created -0.46 33.2452 5
created -0.1 33.2452 5
created 0.26 33.2452 5
created 0.62 33.2452 5
created 0.98 6.64904 1
created 1.34 26.5962 4
created 1.7 59.8413 9
created 2.06 13.2981 2
created 2.42 6.64904 1
created 2.78 33.2452 5
created 3.14 53.1923 8
created 3.5 33.2452 5
created 3.86 59.8413 9
created 4.22 19.9471 3
created 4.58 13.2981 2
created 4.94 46.5433 7
created 5.3 53.1923 8
created 5.66 13.2981 2
created 6.02 66.4904 10
created 6.38 66.4904 10
created 6.74 46.5433 7
created 7.1 33.2452 5
created 7.46 53.1923 8
created 7.82 26.5962 4
created 8.18 46.5433 7
created 8.54 46.5433 7
created 8.9 6.64904 1
created 9.26 59.8413 9
created 9.62 66.4904 10
the total number of created peaks = 55 with sigma = 0.06
the total number of found peaks = 55 with sigma = 0.0600004 (+-1.62539e-05)
fit chi^2 = 3.81316e-06
found -4.06 (+-0.000158526) 66.4904 (+-0.173385) 10.0001 (+-0.00087459)
found -3.34 (+-0.000158597) 66.4905 (+-0.173395) 10.0001 (+-0.00087464)
found -2.26 (+-0.000157734) 66.4901 (+-0.173283) 10 (+-0.000874077)
found 6.02 (+-0.000158508) 66.4905 (+-0.173385) 10.0001 (+-0.000874591)
found 6.38 (+-0.000159076) 66.4907 (+-0.173458) 10.0001 (+-0.000874957)
found 9.62 (+-0.000157672) 66.4908 (+-0.173298) 10.0001 (+-0.000874149)
found -5.14 (+-0.000167214) 59.8414 (+-0.164501) 9.00007 (+-0.000829778)
found -2.98 (+-0.000167194) 59.8415 (+-0.164501) 9.00008 (+-0.000829778)
found 1.7 (+-0.000166649) 59.8412 (+-0.164434) 9.00004 (+-0.00082944)
found 3.86 (+-0.000166935) 59.8413 (+-0.164467) 9.00005 (+-0.000829605)
found 9.26 (+-0.00016696) 59.8414 (+-0.164477) 9.00007 (+-0.000829654)
found -8.38 (+-0.000177309) 53.1924 (+-0.155089) 8.00007 (+-0.000782303)
found -9.82 (+-0.000176611) 53.192 (+-0.155004) 8.00001 (+-0.000781871)
found -8.74 (+-0.000177651) 53.1925 (+-0.155124) 8.00008 (+-0.000782477)
found -5.5 (+-0.000177135) 53.1924 (+-0.155074) 8.00007 (+-0.000782228)
found -4.42 (+-0.000177665) 53.1925 (+-0.155127) 8.00009 (+-0.000782494)
found -0.82 (+-0.000177688) 53.1925 (+-0.155127) 8.00008 (+-0.000782494)
found 3.14 (+-0.000177471) 53.1924 (+-0.155103) 8.00007 (+-0.000782375)
found 5.3 (+-0.000177216) 53.1923 (+-0.155079) 8.00006 (+-0.00078225)
found 7.46 (+-0.000177341) 53.1923 (+-0.15509) 8.00006 (+-0.000782305)
found 6.74 (+-0.00019044) 46.5436 (+-0.145156) 7.0001 (+-0.000732195)
found -7.3 (+-0.00019003) 46.5434 (+-0.145115) 7.00007 (+-0.000731991)
found -1.54 (+-0.000189614) 46.5434 (+-0.145078) 7.00006 (+-0.000731805)
found -1.18 (+-0.000190497) 46.5436 (+-0.14516) 7.0001 (+-0.000732219)
found 4.94 (+-0.000189719) 46.5434 (+-0.145089) 7.00007 (+-0.000731857)
found 8.18 (+-0.000189999) 46.5434 (+-0.145113) 7.00007 (+-0.000731979)
found 8.54 (+-0.000189321) 46.5433 (+-0.145054) 7.00005 (+-0.00073168)
found -7.66 (+-0.000205021) 39.8944 (+-0.134334) 6.00006 (+-0.000677607)
found -0.46 (+-0.000225743) 33.2455 (+-0.122708) 5.00009 (+-0.000618963)
found 3.5 (+-0.000226347) 33.2457 (+-0.122751) 5.00011 (+-0.00061918)
found -6.94 (+-0.000225173) 33.2454 (+-0.122668) 5.00007 (+-0.000618764)
found -0.1 (+-0.000225274) 33.2454 (+-0.122674) 5.00007 (+-0.000618794)
found 0.26 (+-0.000225274) 33.2454 (+-0.122674) 5.00007 (+-0.000618794)
found 0.62 (+-0.000224164) 33.2452 (+-0.122602) 5.00004 (+-0.000618429)
found 2.78 (+-0.000224626) 33.2454 (+-0.122635) 5.00006 (+-0.000618598)
found 7.1 (+-0.000226073) 33.2456 (+-0.122731) 5.0001 (+-0.00061908)
found 7.82 (+-0.000253311) 26.5966 (+-0.109806) 4.0001 (+-0.000553885)
found -9.1 (+-0.000251548) 26.5964 (+-0.109711) 4.00006 (+-0.000553406)
found 1.34 (+-0.000251704) 26.5964 (+-0.109721) 4.00007 (+-0.000553454)
found -6.58 (+-0.000290415) 19.9472 (+-0.0950088) 3.00004 (+-0.000479244)
found -4.78 (+-0.000293825) 19.9477 (+-0.0951544) 3.00011 (+-0.000479979)
found -3.7 (+-0.000294405) 19.9479 (+-0.0951811) 3.00013 (+-0.000480114)
found 4.22 (+-0.000291961) 19.9475 (+-0.0950749) 3.00007 (+-0.000479578)
found -2.62 (+-0.000362244) 13.2988 (+-0.0777676) 2.00013 (+-0.000392276)
found -1.9 (+-0.000361647) 13.2987 (+-0.0777489) 2.00011 (+-0.000392182)
found 2.06 (+-0.000358142) 13.2984 (+-0.0776484) 2.00007 (+-0.000391675)
found -8.02 (+-0.000360758) 13.2986 (+-0.077721) 2.00009 (+-0.000392041)
found 5.66 (+-0.000361958) 13.2988 (+-0.0777586) 2.00012 (+-0.000392231)
found 4.58 (+-0.000359113) 13.2984 (+-0.0776718) 2.00007 (+-0.000391793)
found -9.46 (+-0.000513708) 6.64953 (+-0.0550137) 1.00008 (+-0.000277501)
found 8.9 (+-0.000516297) 6.64971 (+-0.0550555) 1.00011 (+-0.000277712)
found 0.979999 (+-0.000511886) 6.6494 (+-0.0549836) 1.00006 (+-0.000277349)
found -6.22 (+-0.000506477) 6.64918 (+-0.0549021) 1.00003 (+-0.000276938)
found -5.86 (+-0.00050992) 6.6494 (+-0.0549586) 1.00006 (+-0.000277223)
found 2.42 (+-0.000509793) 6.64931 (+-0.054952) 1.00005 (+-0.000277189)
#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()