This macro fits the source spectrum using the AWMI algorithm from the "TSpectrumFit" class ("TSpectrum" class is used to find peaks).
created -9.88 59.8413 6
created -9.64 19.9471 2
created -9.4 79.7885 8
created -9.16 69.8149 7
created -8.92 59.8413 6
created -8.68 29.9207 3
created -8.44 99.7356 10
created -8.2 79.7885 8
created -7.96 19.9471 2
created -7.72 19.9471 2
created -7.48 69.8149 7
created -7.24 99.7356 10
created -7 99.7356 10
created -6.76 49.8678 5
created -6.52 29.9207 3
created -6.28 39.8942 4
created -6.04 19.9471 2
created -5.8 39.8942 4
created -5.56 9.97356 1
created -5.32 89.762 9
created -5.08 59.8413 6
created -4.84 9.97356 1
created -4.6 69.8149 7
created -4.36 99.7356 10
created -4.12 99.7356 10
created -3.88 79.7885 8
created -3.64 79.7885 8
created -3.4 19.9471 2
created -3.16 69.8149 7
created -2.92 59.8413 6
created -2.68 69.8149 7
created -2.44 59.8413 6
created -2.2 9.97356 1
created -1.96 19.9471 2
created -1.72 79.7885 8
created -1.48 29.9207 3
created -1.24 69.8149 7
created -1 59.8413 6
created -0.76 9.97356 1
created -0.52 49.8678 5
created -0.28 39.8942 4
created -0.04 29.9207 3
created 0.2 59.8413 6
created 0.44 19.9471 2
created 0.68 49.8678 5
created 0.92 9.97356 1
created 1.16 69.8149 7
created 1.4 19.9471 2
created 1.64 99.7356 10
created 1.88 39.8942 4
created 2.12 29.9207 3
created 2.36 99.7356 10
created 2.6 89.762 9
created 2.84 19.9471 2
created 3.08 99.7356 10
created 3.32 69.8149 7
created 3.56 39.8942 4
created 3.8 49.8678 5
created 4.04 29.9207 3
created 4.28 9.97356 1
created 4.52 69.8149 7
created 4.76 9.97356 1
created 5 69.8149 7
created 5.24 19.9471 2
created 5.48 69.8149 7
created 5.72 39.8942 4
created 5.96 49.8678 5
created 6.2 89.762 9
created 6.44 9.97356 1
created 6.68 99.7356 10
created 6.92 39.8942 4
created 7.16 69.8149 7
created 7.4 49.8678 5
created 7.64 89.762 9
created 7.88 49.8678 5
created 8.12 29.9207 3
created 8.36 29.9207 3
created 8.6 59.8413 6
created 8.84 69.8149 7
created 9.08 99.7356 10
created 9.32 99.7356 10
created 9.56 19.9471 2
created 9.8 9.97356 1
the total number of created peaks = 83 with sigma = 0.04
the total number of found peaks = 83 with sigma = 0.0400021 (+-7.59106e-06)
fit chi^2 = 2.81452e-06
found -7.24 (+-8.81849e-05) 99.7349 (+-0.216368) 10.0004 (+-0.000751695)
found -7 (+-8.80887e-05) 99.7344 (+-0.216339) 10.0004 (+-0.000751595)
found -4.36 (+-8.81849e-05) 99.7349 (+-0.216368) 10.0004 (+-0.000751695)
found -4.12 (+-8.82266e-05) 99.7352 (+-0.21638) 10.0005 (+-0.00075174)
found 9.08 (+-8.81849e-05) 99.7349 (+-0.216368) 10.0004 (+-0.000751695)
found 9.32 (+-8.78763e-05) 99.7336 (+-0.216279) 10.0003 (+-0.000751387)
found -8.44 (+-8.78885e-05) 99.7333 (+-0.216279) 10.0003 (+-0.000751387)
found 1.64 (+-8.76096e-05) 99.732 (+-0.216197) 10.0002 (+-0.000751101)
found 2.36 (+-8.79267e-05) 99.7336 (+-0.216291) 10.0003 (+-0.000751429)
found 3.08 (+-8.77613e-05) 99.7328 (+-0.216242) 10.0002 (+-0.00075126)
found 6.68 (+-8.74898e-05) 99.7318 (+-0.216165) 10.0001 (+-0.000750992)
found 2.6 (+-9.26916e-05) 89.7606 (+-0.205197) 9.00032 (+-0.000712887)
found -5.32 (+-9.23835e-05) 89.7592 (+-0.205115) 9.00018 (+-0.000712603)
found 6.2 (+-9.2329e-05) 89.759 (+-0.2051) 9.00016 (+-0.000712551)
found 7.64 (+-9.26914e-05) 89.76 (+-0.205191) 9.00026 (+-0.000712866)
found -8.2 (+-9.83909e-05) 79.7875 (+-0.19348) 8.00032 (+-0.000672182)
found -3.88 (+-9.8816e-05) 79.7891 (+-0.193581) 8.00048 (+-0.000672532)
found -3.64 (+-9.83001e-05) 79.787 (+-0.193457) 8.00027 (+-0.0006721)
found -9.4 (+-9.82497e-05) 79.7867 (+-0.193444) 8.00024 (+-0.000672055)
found -1.72 (+-9.79839e-05) 79.7857 (+-0.193379) 8.00013 (+-0.00067183)
found -9.16 (+-0.000105535) 69.815 (+-0.181056) 7.00037 (+-0.000629016)
found -2.68 (+-0.000105415) 69.8145 (+-0.181029) 7.00032 (+-0.000628923)
found 3.32 (+-0.000105491) 69.815 (+-0.181048) 7.00037 (+-0.000628988)
found 8.84 (+-0.000105639) 69.8156 (+-0.181079) 7.00043 (+-0.000629099)
found -7.48 (+-0.000105282) 69.8145 (+-0.181006) 7.00032 (+-0.000628842)
found -4.6 (+-0.000105116) 69.8143 (+-0.180975) 7.00029 (+-0.000628735)
found -3.16 (+-0.00010506) 69.8134 (+-0.180955) 7.00021 (+-0.000628667)
found -1.24 (+-0.000105176) 69.8137 (+-0.180978) 7.00024 (+-0.000628747)
found 1.16 (+-0.000104546) 69.8121 (+-0.18085) 7.00008 (+-0.000628303)
found 4.52 (+-0.000104383) 69.8118 (+-0.18082) 7.00005 (+-0.000628196)
found 5 (+-0.000104546) 69.8121 (+-0.18085) 7.00008 (+-0.000628303)
found 5.48 (+-0.000104914) 69.8129 (+-0.180923) 7.00016 (+-0.000628556)
found 7.16 (+-0.000105199) 69.8137 (+-0.180982) 7.00024 (+-0.00062876)
found -5.08 (+-0.0001136) 59.8409 (+-0.167561) 6.00027 (+-0.000582133)
found -8.92 (+-0.000113794) 59.8409 (+-0.167589) 6.00027 (+-0.000582231)
found -2.92 (+-0.000114141) 59.842 (+-0.167654) 6.00037 (+-0.000582456)
found -2.44 (+-0.000113474) 59.8404 (+-0.167536) 6.00021 (+-0.000582045)
found -1 (+-0.000113474) 59.8404 (+-0.167536) 6.00021 (+-0.000582045)
found 0.2 (+-0.000113319) 59.8396 (+-0.167502) 6.00013 (+-0.000581927)
found 8.6 (+-0.000113794) 59.8409 (+-0.167589) 6.00027 (+-0.000582231)
found -9.88 (+-0.000113287) 59.8388 (+-0.167481) 6.00006 (+-0.000581857)
found -6.76 (+-0.000125045) 49.8687 (+-0.153051) 5.00035 (+-0.000531723)
found 7.88 (+-0.000124977) 49.8684 (+-0.153039) 5.00032 (+-0.000531683)
found 3.8 (+-0.000124542) 49.8671 (+-0.152968) 5.00019 (+-0.000531437)
found 5.96 (+-0.000125102) 49.8687 (+-0.153058) 5.00035 (+-0.000531749)
found 7.4 (+-0.000125389) 49.8695 (+-0.153104) 5.00043 (+-0.000531908)
found -0.519999 (+-0.000124171) 49.8666 (+-0.152916) 5.00013 (+-0.000531253)
found 0.68 (+-0.000123899) 49.866 (+-0.152874) 5.00008 (+-0.000531109)
found 1.88 (+-0.000140083) 39.8957 (+-0.136929) 4.00035 (+-0.000475714)
found 6.92 (+-0.00014059) 39.8967 (+-0.136994) 4.00045 (+-0.00047594)
found -6.28 (+-0.000139131) 39.8935 (+-0.136806) 4.00013 (+-0.000475284)
found -0.280001 (+-0.000139596) 39.8943 (+-0.136864) 4.00021 (+-0.000475486)
found 3.56 (+-0.000140098) 39.8954 (+-0.136929) 4.00032 (+-0.000475712)
found 5.72 (+-0.000140098) 39.8954 (+-0.136929) 4.00032 (+-0.000475712)
found -5.8 (+-0.000138685) 39.893 (+-0.136753) 4.00008 (+-0.000475102)
found -1.48 (+-0.00016265) 29.9231 (+-0.118672) 3.0004 (+-0.000412285)
found -8.68 (+-0.000162734) 29.9234 (+-0.118681) 3.00043 (+-0.000412317)
found -6.52 (+-0.000161778) 29.9215 (+-0.118584) 3.00024 (+-0.00041198)
found 4.04 (+-0.000161003) 29.9208 (+-0.118513) 3.00016 (+-0.000411734)
found 8.12 (+-0.000161581) 29.9213 (+-0.118565) 3.00021 (+-0.000411914)
found -0.0399988 (+-0.000161929) 29.9218 (+-0.118599) 3.00027 (+-0.000412033)
found 2.12 (+-0.000162409) 29.9229 (+-0.118649) 3.00038 (+-0.000412206)
found 8.36 (+-0.000161731) 29.9215 (+-0.11858) 3.00024 (+-0.000411967)
found -7.96001 (+-0.000198898) 19.9488 (+-0.0968777) 2.00027 (+-0.000336568)
found -3.4 (+-0.000200204) 19.9501 (+-0.0969643) 2.0004 (+-0.000336869)
found 2.84 (+-0.000200849) 19.9512 (+-0.0970101) 2.00051 (+-0.000337029)
found 9.55999 (+-0.000198712) 19.9491 (+-0.0968703) 2.0003 (+-0.000336543)
found -9.64 (+-0.00020001) 19.9498 (+-0.0969509) 2.00037 (+-0.000336823)
found 0.439999 (+-0.000199425) 19.949 (+-0.0969102) 2.00029 (+-0.000336681)
found 1.4 (+-0.000200512) 19.9506 (+-0.0969864) 2.00045 (+-0.000336946)
found 5.24 (+-0.000200029) 19.9498 (+-0.096952) 2.00037 (+-0.000336827)
found -7.72 (+-0.000198726) 19.9485 (+-0.0968654) 2.00024 (+-0.000336526)
found -6.04 (+-0.000198717) 19.9482 (+-0.0968621) 2.00021 (+-0.000336514)
found -1.95999 (+-0.000198412) 19.9485 (+-0.0968483) 2.00024 (+-0.000336466)
found 6.44 (+-0.000287051) 9.97811 (+-0.0687087) 1.00051 (+-0.000238705)
found 4.76 (+-0.000285669) 9.97677 (+-0.068656) 1.00037 (+-0.000238522)
found -4.84 (+-0.000285336) 9.97652 (+-0.0686437) 1.00035 (+-0.000238479)
found -2.20001 (+-0.000282997) 9.9752 (+-0.0685616) 1.00022 (+-0.000238194)
found -0.760002 (+-0.000284629) 9.97598 (+-0.0686177) 1.00029 (+-0.000238389)
found -5.55999 (+-0.000285077) 9.97652 (+-0.068636) 1.00035 (+-0.000238452)
found 0.920004 (+-0.000284959) 9.97624 (+-0.06863) 1.00032 (+-0.000238432)
found 4.28001 (+-0.000283988) 9.97572 (+-0.0685962) 1.00027 (+-0.000238314)
found 9.8 (+-0.00027739) 9.97385 (+-0.0683915) 1.00008 (+-0.000237603)
#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 SetMarkerColor(Color_t mcolor=1)
Set the marker color.
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
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.
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()