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 24.9339 5
created -8.8 34.9074 7
created -8.32 34.9074 7
created -7.84 24.9339 5
created -7.36 24.9339 5
created -6.88 19.9471 4
created -6.4 34.9074 7
created -5.92 39.8942 8
created -5.44 14.9603 3
created -4.96 49.8678 10
created -4.48 39.8942 8
created -4 44.881 9
created -3.52 39.8942 8
created -3.04 39.8942 8
created -2.56 19.9471 4
created -2.08 34.9074 7
created -1.6 34.9074 7
created -1.12 44.881 9
created -0.64 19.9471 4
created -0.16 9.97356 2
created 0.32 49.8678 10
created 0.8 14.9603 3
created 1.28 24.9339 5
created 1.76 29.9207 6
created 2.24 34.9074 7
created 2.72 29.9207 6
created 3.2 29.9207 6
created 3.68 14.9603 3
created 4.16 29.9207 6
created 4.64 34.9074 7
created 5.12 9.97356 2
created 5.6 19.9471 4
created 6.08 24.9339 5
created 6.56 14.9603 3
created 7.04 39.8942 8
created 7.52 24.9339 5
created 8 29.9207 6
created 8.48 34.9074 7
created 8.96 29.9207 6
created 9.44 9.97356 2
the total number of created peaks = 41 with sigma = 0.08
the total number of found peaks = 41 with sigma = 0.0800011 (+-1.39058e-05)
fit chi^2 = 1.16705e-06
found -4.96 (+-0.000118761) 49.8677 (+-0.0730644) 10.0001 (+-0.000483846)
found 0.32 (+-0.000118283) 49.8673 (+-0.0730295) 10 (+-0.000483615)
found -4 (+-0.000125673) 44.8812 (+-0.0693477) 9.00016 (+-0.000459233)
found -1.12 (+-0.00012531) 44.8809 (+-0.069323) 9.00011 (+-0.000459069)
found -5.92 (+-0.000132904) 39.8942 (+-0.0653582) 8.0001 (+-0.000432814)
found -4.48 (+-0.000133613) 39.8946 (+-0.0654016) 8.00019 (+-0.000433101)
found -3.52 (+-0.000133487) 39.8945 (+-0.0653936) 8.00017 (+-0.000433048)
found -3.04 (+-0.000133089) 39.8943 (+-0.0653692) 8.00012 (+-0.000432887)
found 7.04 (+-0.000132742) 39.8941 (+-0.0653482) 8.00008 (+-0.000432748)
found -9.76 (+-0.000142108) 34.9072 (+-0.061133) 7.00005 (+-0.000404834)
found -8.8 (+-0.00014245) 34.9076 (+-0.0611563) 7.00012 (+-0.000404988)
found -8.32 (+-0.00014245) 34.9076 (+-0.0611563) 7.00012 (+-0.000404988)
found -6.4 (+-0.000142419) 34.9076 (+-0.0611549) 7.00012 (+-0.000404979)
found -2.08 (+-0.00014234) 34.9075 (+-0.0611505) 7.00011 (+-0.00040495)
found -1.6 (+-0.000142786) 34.9078 (+-0.0611747) 7.00016 (+-0.00040511)
found 2.24 (+-0.00014246) 34.9076 (+-0.0611567) 7.00012 (+-0.000404991)
found 4.64 (+-0.000141966) 34.9074 (+-0.0611312) 7.00008 (+-0.000404822)
found 8.48 (+-0.00014246) 34.9076 (+-0.0611567) 7.00012 (+-0.000404991)
found 2.72 (+-0.000154161) 29.9209 (+-0.0566336) 6.00013 (+-0.000375038)
found 3.2 (+-0.000153678) 29.9207 (+-0.0566114) 6.00009 (+-0.000374891)
found 8.96 (+-0.000153594) 29.9207 (+-0.0566082) 6.00009 (+-0.00037487)
found 1.76 (+-0.00015405) 29.9209 (+-0.0566285) 6.00012 (+-0.000375004)
found 4.16 (+-0.000153777) 29.9208 (+-0.0566161) 6.0001 (+-0.000374922)
found 8 (+-0.00015405) 29.9209 (+-0.0566285) 6.00012 (+-0.000375004)
found -9.28 (+-0.000169258) 24.9343 (+-0.0517145) 5.00014 (+-0.000342463)
found -7.84 (+-0.000169012) 24.9342 (+-0.0517047) 5.00012 (+-0.000342398)
found 7.52 (+-0.000169248) 24.9343 (+-0.0517141) 5.00014 (+-0.00034246)
found -7.36 (+-0.000168619) 24.934 (+-0.0516892) 5.00009 (+-0.000342295)
found 1.28 (+-0.000168575) 24.934 (+-0.0516878) 5.00009 (+-0.000342286)
found 6.08 (+-0.0001683) 24.9339 (+-0.0516769) 5.00007 (+-0.000342214)
found -2.56 (+-0.000189769) 19.9476 (+-0.0462723) 4.00015 (+-0.000306424)
found -0.640002 (+-0.000188931) 19.9474 (+-0.0462466) 4.00011 (+-0.000306253)
found -6.88 (+-0.000189341) 19.9475 (+-0.0462583) 4.00012 (+-0.000306331)
found 5.6 (+-0.000188393) 19.9472 (+-0.0462287) 4.00007 (+-0.000306135)
found 0.799998 (+-0.000219707) 14.9609 (+-0.040088) 3.00015 (+-0.00026547)
found -5.44 (+-0.000220257) 14.9611 (+-0.0401017) 3.00018 (+-0.000265561)
found 3.68 (+-0.000219275) 14.9607 (+-0.0400767) 3.00012 (+-0.000265395)
found 6.56 (+-0.000219417) 14.9608 (+-0.0400804) 3.00013 (+-0.00026542)
found -0.159996 (+-0.00027005) 9.97414 (+-0.0327486) 2.00014 (+-0.000216867)
found 5.12 (+-0.000269415) 9.97398 (+-0.0327372) 2.00011 (+-0.000216792)
found 9.44 (+-0.000265647) 9.97383 (+-0.0326848) 2.00008 (+-0.000216445)
#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()