This macro fits the source spectrum using the AWMI algorithm from the "TSpectrumFit" class ("TSpectrum" class is used to find peaks).
created -9.88 89.762 9
created -9.64 19.9471 2
created -9.4 19.9471 2
created -9.16 49.8678 5
created -8.92 99.7356 10
created -8.68 59.8413 6
created -8.44 99.7356 10
created -8.2 89.762 9
created -7.96 69.8149 7
created -7.72 29.9207 3
created -7.48 19.9471 2
created -7.24 39.8942 4
created -7 29.9207 3
created -6.76 29.9207 3
created -6.52 9.97356 1
created -6.28 49.8678 5
created -6.04 29.9207 3
created -5.8 9.97356 1
created -5.56 79.7885 8
created -5.32 69.8149 7
created -5.08 19.9471 2
created -4.84 19.9471 2
created -4.6 69.8149 7
created -4.36 49.8678 5
created -4.12 59.8413 6
created -3.88 89.762 9
created -3.64 79.7885 8
created -3.4 19.9471 2
created -3.16 49.8678 5
created -2.92 89.762 9
created -2.68 79.7885 8
created -2.44 79.7885 8
created -2.2 39.8942 4
created -1.96 79.7885 8
created -1.72 89.762 9
created -1.48 9.97356 1
created -1.24 29.9207 3
created -1 39.8942 4
created -0.76 79.7885 8
created -0.52 89.762 9
created -0.28 79.7885 8
created -0.04 9.97356 1
created 0.2 29.9207 3
created 0.44 69.8149 7
created 0.68 29.9207 3
created 0.92 29.9207 3
created 1.16 49.8678 5
created 1.4 9.97356 1
created 1.64 29.9207 3
created 1.88 9.97356 1
created 2.12 89.762 9
created 2.36 69.8149 7
created 2.6 19.9471 2
created 2.84 29.9207 3
created 3.08 69.8149 7
created 3.32 49.8678 5
created 3.56 89.762 9
created 3.8 49.8678 5
created 4.04 29.9207 3
created 4.28 9.97356 1
created 4.52 19.9471 2
created 4.76 39.8942 4
created 5 9.97356 1
created 5.24 69.8149 7
created 5.48 59.8413 6
created 5.72 49.8678 5
created 5.96 29.9207 3
created 6.2 49.8678 5
created 6.44 69.8149 7
created 6.68 49.8678 5
created 6.92 9.97356 1
created 7.16 29.9207 3
created 7.4 19.9471 2
created 7.64 49.8678 5
created 7.88 89.762 9
created 8.12 69.8149 7
created 8.36 19.9471 2
created 8.6 49.8678 5
created 8.84 39.8942 4
created 9.08 59.8413 6
created 9.32 69.8149 7
created 9.56 89.762 9
created 9.8 59.8413 6
the total number of created peaks = 83 with sigma = 0.04
the total number of found peaks = 83 with sigma = 0.040002 (+-1.50956e-05)
fit chi^2 = 1.03963e-05
found -8.44 (+-0.000169328) 99.7345 (+-0.415795) 10.0004 (+-0.00144454)
found -8.92 (+-0.000168991) 99.7334 (+-0.415691) 10.0003 (+-0.00144418)
found -8.2 (+-0.000178796) 89.762 (+-0.394544) 9.00045 (+-0.00137071)
found -3.88 (+-0.000178542) 89.7612 (+-0.394472) 9.00037 (+-0.00137046)
found -1.72 (+-0.000177736) 89.7598 (+-0.394269) 9.00023 (+-0.00136975)
found -0.52 (+-0.000178726) 89.7617 (+-0.394524) 9.00042 (+-0.00137064)
found 9.56 (+-0.000178454) 89.7609 (+-0.394448) 9.00035 (+-0.00137037)
found -9.88 (+-0.000177596) 89.758 (+-0.394186) 9.00006 (+-0.00136946)
found -2.92 (+-0.000178435) 89.7609 (+-0.394443) 9.00034 (+-0.00137036)
found 2.12 (+-0.000177649) 89.7595 (+-0.394244) 9.00021 (+-0.00136967)
found 3.56 (+-0.000178146) 89.7601 (+-0.394363) 9.00026 (+-0.00137008)
found 7.88 (+-0.000178348) 89.7606 (+-0.394419) 9.00032 (+-0.00137027)
found -3.64 (+-0.000189016) 79.7873 (+-0.371834) 8.00029 (+-0.00129181)
found -2.68 (+-0.000189832) 79.7889 (+-0.372028) 8.00045 (+-0.00129248)
found -2.44 (+-0.000189283) 79.7876 (+-0.371892) 8.00032 (+-0.00129201)
found -0.280002 (+-0.000188733) 79.787 (+-0.371774) 8.00026 (+-0.0012916)
found -5.56 (+-0.000188547) 79.7865 (+-0.371726) 8.00021 (+-0.00129143)
found -1.96 (+-0.000189374) 79.7879 (+-0.371915) 8.00034 (+-0.00129209)
found -0.759999 (+-0.000189374) 79.7879 (+-0.371915) 8.00034 (+-0.00129209)
found -7.96 (+-0.000202472) 69.8145 (+-0.347902) 7.00032 (+-0.00120867)
found -5.32 (+-0.000202147) 69.814 (+-0.347835) 7.00026 (+-0.00120843)
found 2.36 (+-0.000202249) 69.8143 (+-0.347858) 7.00029 (+-0.00120851)
found 8.12 (+-0.000202249) 69.8143 (+-0.347858) 7.00029 (+-0.00120851)
found 9.32 (+-0.000202934) 69.8153 (+-0.348) 7.0004 (+-0.00120901)
found -4.6 (+-0.000201787) 69.8132 (+-0.347754) 7.00018 (+-0.00120815)
found 0.44 (+-0.000201683) 69.8129 (+-0.34773) 7.00016 (+-0.00120807)
found 3.08 (+-0.000202008) 69.8135 (+-0.347798) 7.00021 (+-0.00120831)
found 5.24 (+-0.000201602) 69.8132 (+-0.347724) 7.00018 (+-0.00120805)
found 6.44 (+-0.000202335) 69.814 (+-0.347867) 7.00026 (+-0.00120854)
found -8.68 (+-0.00022009) 59.8436 (+-0.32236) 6.00053 (+-0.00111993)
found 9.8 (+-0.000217341) 59.8423 (+-0.321907) 6.0004 (+-0.00111836)
found -4.12 (+-0.000219325) 59.842 (+-0.322212) 6.00037 (+-0.00111941)
found 5.48 (+-0.000219079) 59.8415 (+-0.322163) 6.00032 (+-0.00111925)
found 9.08 (+-0.000218906) 59.8412 (+-0.322131) 6.00029 (+-0.00111913)
found 3.8 (+-0.000240197) 49.8684 (+-0.294131) 5.00032 (+-0.00102186)
found -4.36 (+-0.000240532) 49.8687 (+-0.29418) 5.00035 (+-0.00102203)
found 1.16 (+-0.000238415) 49.8663 (+-0.293857) 5.0001 (+-0.0010209)
found 3.32 (+-0.000240989) 49.8695 (+-0.294256) 5.00043 (+-0.00102229)
found 5.72 (+-0.000239744) 49.8677 (+-0.294056) 5.00024 (+-0.0010216)
found 6.2 (+-0.000239908) 49.8679 (+-0.294083) 5.00027 (+-0.00102169)
found 6.68 (+-0.00023919) 49.8674 (+-0.293981) 5.00021 (+-0.00102134)
found -9.16 (+-0.00024003) 49.8684 (+-0.29411) 5.00032 (+-0.00102178)
found -6.28 (+-0.000238415) 49.8663 (+-0.293857) 5.0001 (+-0.0010209)
found -3.16 (+-0.0002399) 49.8682 (+-0.294088) 5.0003 (+-0.00102171)
found 7.64 (+-0.0002399) 49.8682 (+-0.294088) 5.00029 (+-0.00102171)
found 8.6 (+-0.000239068) 49.8669 (+-0.293951) 5.00016 (+-0.00102123)
found -2.2 (+-0.000270058) 39.8965 (+-0.263273) 4.00043 (+-0.000914652)
found -0.999998 (+-0.0002689) 39.8951 (+-0.263124) 4.00029 (+-0.000914133)
found 8.84 (+-0.000269057) 39.8951 (+-0.263141) 4.00029 (+-0.000914192)
found -7.24 (+-0.0002674) 39.8935 (+-0.262931) 4.00013 (+-0.000913463)
found 4.76 (+-0.000266543) 39.893 (+-0.26283) 4.00008 (+-0.000913114)
found -7.72 (+-0.00031063) 29.9216 (+-0.227887) 3.00024 (+-0.000791714)
found -6.04 (+-0.000309436) 29.9208 (+-0.227774) 3.00016 (+-0.000791323)
found 0.679998 (+-0.000311096) 29.9218 (+-0.22793) 3.00027 (+-0.000791864)
found 4.04 (+-0.000309436) 29.9208 (+-0.227774) 3.00016 (+-0.000791323)
found 5.96 (+-0.000311254) 29.9218 (+-0.227943) 3.00027 (+-0.00079191)
found -7 (+-0.000310222) 29.921 (+-0.227842) 3.00019 (+-0.000791559)
found -6.76 (+-0.000308741) 29.9202 (+-0.227705) 3.00011 (+-0.000791084)
found 0.920001 (+-0.000310548) 29.9213 (+-0.227874) 3.00021 (+-0.000791671)
found 2.84 (+-0.00031063) 29.9216 (+-0.227887) 3.00024 (+-0.000791714)
found -1.24 (+-0.000309114) 29.9205 (+-0.227742) 3.00014 (+-0.000791211)
found 0.200004 (+-0.000309979) 29.9213 (+-0.22783) 3.00022 (+-0.000791517)
found 1.64 (+-0.000307648) 29.9197 (+-0.227606) 3.00006 (+-0.000790738)
found 7.16 (+-0.000308285) 29.92 (+-0.227662) 3.00008 (+-0.000790935)
found -9.64001 (+-0.000382571) 19.949 (+-0.186214) 2.0003 (+-0.000646937)
found -3.4 (+-0.000383986) 19.9496 (+-0.186304) 2.00035 (+-0.000647251)
found -5.08 (+-0.000381938) 19.9485 (+-0.186169) 2.00024 (+-0.000646779)
found 2.6 (+-0.000382618) 19.9488 (+-0.186212) 2.00027 (+-0.00064693)
found 8.36 (+-0.000383651) 19.9493 (+-0.186281) 2.00032 (+-0.000647168)
found -9.4 (+-0.000381162) 19.948 (+-0.186114) 2.00019 (+-0.00064659)
found -7.48 (+-0.000381368) 19.948 (+-0.186126) 2.00019 (+-0.00064663)
found -4.84 (+-0.000381938) 19.9485 (+-0.186169) 2.00024 (+-0.000646779)
found 7.4 (+-0.000381838) 19.9482 (+-0.186158) 2.00021 (+-0.000646741)
found 4.52 (+-0.000379772) 19.9474 (+-0.186026) 2.00013 (+-0.000646283)
found -1.48001 (+-0.000546875) 9.97627 (+-0.131879) 1.00032 (+-0.000458167)
found -0.0400097 (+-0.000546366) 9.976 (+-0.131859) 1.0003 (+-0.000458098)
found 1.4 (+-0.000544464) 9.97518 (+-0.131787) 1.00021 (+-0.000457849)
found 5.00001 (+-0.000546824) 9.97599 (+-0.131872) 1.00029 (+-0.000458145)
found 6.92 (+-0.000544464) 9.97519 (+-0.131787) 1.00021 (+-0.000457849)
found -6.52 (+-0.000544464) 9.97518 (+-0.131787) 1.00021 (+-0.000457849)
found -5.79999 (+-0.000546366) 9.976 (+-0.131859) 1.0003 (+-0.000458098)
found 1.88001 (+-0.000546875) 9.97626 (+-0.131879) 1.00032 (+-0.000458167)
found 4.28 (+-0.000541368) 9.97439 (+-0.131679) 1.00013 (+-0.000457475)
#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()