This macro fits the source spectrum using the AWMI algorithm from the "TSpectrumFit" class ("TSpectrum" class is used to find peaks).
created -9.88 69.8149 7
created -9.64 29.9207 3
created -9.4 19.9471 2
created -9.16 19.9471 2
created -8.92 9.97356 1
created -8.68 89.762 9
created -8.44 29.9207 3
created -8.2 49.8678 5
created -7.96 19.9471 2
created -7.72 49.8678 5
created -7.48 79.7885 8
created -7.24 89.762 9
created -7 9.97356 1
created -6.76 89.762 9
created -6.52 9.97356 1
created -6.28 79.7885 8
created -6.04 49.8678 5
created -5.8 69.8149 7
created -5.56 89.762 9
created -5.32 49.8678 5
created -5.08 69.8149 7
created -4.84 69.8149 7
created -4.6 99.7356 10
created -4.36 89.762 9
created -4.12 99.7356 10
created -3.88 99.7356 10
created -3.64 89.762 9
created -3.4 79.7885 8
created -3.16 79.7885 8
created -2.92 89.762 9
created -2.68 9.97356 1
created -2.44 89.762 9
created -2.2 99.7356 10
created -1.96 89.762 9
created -1.72 99.7356 10
created -1.48 19.9471 2
created -1.24 89.762 9
created -1 19.9471 2
created -0.76 59.8413 6
created -0.52 9.97356 1
created -0.28 59.8413 6
created -0.04 59.8413 6
created 0.2 59.8413 6
created 0.44 29.9207 3
created 0.68 49.8678 5
created 0.92 89.762 9
created 1.16 69.8149 7
created 1.4 49.8678 5
created 1.64 79.7885 8
created 1.88 19.9471 2
created 2.12 99.7356 10
created 2.36 69.8149 7
created 2.6 79.7885 8
created 2.84 49.8678 5
created 3.08 59.8413 6
created 3.32 69.8149 7
created 3.56 89.762 9
created 3.8 79.7885 8
created 4.04 79.7885 8
created 4.28 9.97356 1
created 4.52 69.8149 7
created 4.76 19.9471 2
created 5 79.7885 8
created 5.24 59.8413 6
created 5.48 9.97356 1
created 5.72 59.8413 6
created 5.96 79.7885 8
created 6.2 19.9471 2
created 6.44 29.9207 3
created 6.68 19.9471 2
created 6.92 89.762 9
created 7.16 59.8413 6
created 7.4 59.8413 6
created 7.64 99.7356 10
created 7.88 59.8413 6
created 8.12 19.9471 2
created 8.36 59.8413 6
created 8.6 59.8413 6
created 8.84 49.8678 5
created 9.08 19.9471 2
created 9.32 99.7356 10
created 9.56 69.8149 7
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.40275e-05)
fit chi^2 = 1.08251e-05
found -4.6 (+-0.000172874) 99.7347 (+-0.42431) 10.0004 (+-0.00147412)
found -4.12 (+-0.000173103) 99.7355 (+-0.424381) 10.0005 (+-0.00147437)
found -3.88 (+-0.000173103) 99.7355 (+-0.424381) 10.0005 (+-0.00147437)
found -2.2 (+-0.000173032) 99.7352 (+-0.424359) 10.0005 (+-0.00147429)
found -1.72 (+-0.00017227) 99.7334 (+-0.424136) 10.0003 (+-0.00147351)
found 7.64 (+-0.000172539) 99.7336 (+-0.424206) 10.0003 (+-0.00147376)
found 2.12 (+-0.000172114) 99.7329 (+-0.424087) 10.0002 (+-0.00147334)
found 9.32 (+-0.000172114) 99.7328 (+-0.424087) 10.0002 (+-0.00147334)
found -7.24 (+-0.000181364) 89.7598 (+-0.402317) 9.00024 (+-0.00139771)
found -5.56 (+-0.000181988) 89.7606 (+-0.40247) 9.00032 (+-0.00139824)
found -4.36 (+-0.000182698) 89.7627 (+-0.40267) 9.00053 (+-0.00139894)
found -3.64 (+-0.000182536) 89.7622 (+-0.402623) 9.00048 (+-0.00139878)
found -2.92 (+-0.000181364) 89.7598 (+-0.402317) 9.00024 (+-0.00139771)
found -1.96 (+-0.000182698) 89.7627 (+-0.40267) 9.00053 (+-0.00139894)
found 3.56 (+-0.000182284) 89.7614 (+-0.402552) 9.0004 (+-0.00139853)
found -8.68 (+-0.000180807) 89.7584 (+-0.402165) 9.0001 (+-0.00139718)
found -6.76 (+-0.00018037) 89.7579 (+-0.402058) 9.00005 (+-0.00139681)
found -2.44 (+-0.000181523) 89.7604 (+-0.402364) 9.00029 (+-0.00139787)
found -1.24 (+-0.000180882) 89.7585 (+-0.40218) 9.0001 (+-0.00139724)
found 0.92 (+-0.000181988) 89.7606 (+-0.40247) 9.00032 (+-0.00139824)
found 6.92 (+-0.000181438) 89.7595 (+-0.402326) 9.00021 (+-0.00139774)
found -3.4 (+-0.000193707) 79.7889 (+-0.379622) 8.00045 (+-0.00131887)
found -3.16 (+-0.000193707) 79.7889 (+-0.379622) 8.00045 (+-0.00131887)
found 2.6 (+-0.000193185) 79.7876 (+-0.379491) 8.00032 (+-0.00131841)
found 3.8 (+-0.000193707) 79.7889 (+-0.379622) 8.00045 (+-0.00131887)
found 4.04 (+-0.000192494) 79.7868 (+-0.379339) 8.00024 (+-0.00131788)
found 5.96 (+-0.000192576) 79.7865 (+-0.379348) 8.00021 (+-0.00131791)
found -7.48 (+-0.000193377) 79.7881 (+-0.37954) 8.00037 (+-0.00131858)
found -6.28 (+-0.00019217) 79.786 (+-0.379257) 8.00016 (+-0.0013176)
found 1.64 (+-0.000192457) 79.7863 (+-0.379318) 8.00019 (+-0.00131781)
found 5 (+-0.000192576) 79.7865 (+-0.379348) 8.00021 (+-0.00131791)
found -4.84 (+-0.000207299) 69.8159 (+-0.355154) 7.00045 (+-0.00123386)
found 1.16 (+-0.000206941) 69.8151 (+-0.355074) 7.00037 (+-0.00123358)
found 2.36 (+-0.000207413) 69.8161 (+-0.355179) 7.00048 (+-0.00123395)
found 3.32 (+-0.000207077) 69.8153 (+-0.355104) 7.0004 (+-0.00123369)
found 9.56 (+-0.000207175) 69.8156 (+-0.355126) 7.00043 (+-0.00123376)
found -9.88 (+-0.000205836) 69.8122 (+-0.354805) 7.00008 (+-0.00123265)
found -5.8 (+-0.000206941) 69.8151 (+-0.355074) 7.00037 (+-0.00123358)
found -5.08 (+-0.000206723) 69.8145 (+-0.355025) 7.00032 (+-0.00123341)
found 4.52 (+-0.000205031) 69.8121 (+-0.354677) 7.00008 (+-0.00123221)
found 7.16 (+-0.000223959) 59.8423 (+-0.328818) 6.0004 (+-0.00114237)
found 7.88 (+-0.000223271) 59.8415 (+-0.328697) 6.00032 (+-0.00114194)
found -0.04 (+-0.000223566) 59.8415 (+-0.328742) 6.00032 (+-0.0011421)
found 0.199999 (+-0.000223027) 59.8407 (+-0.328642) 6.00024 (+-0.00114175)
found 3.08 (+-0.000223551) 59.8415 (+-0.328739) 6.00032 (+-0.00114209)
found 5.24 (+-0.000222669) 59.8407 (+-0.32859) 6.00024 (+-0.00114157)
found 7.4 (+-0.000224073) 59.8426 (+-0.328841) 6.00043 (+-0.00114245)
found 8.6 (+-0.00022341) 59.8412 (+-0.328712) 6.00029 (+-0.001142)
found 9.8 (+-0.000221534) 59.8417 (+-0.328429) 6.00034 (+-0.00114101)
found -0.76 (+-0.000221616) 59.8391 (+-0.328393) 6.00008 (+-0.00114089)
found -0.279998 (+-0.000222401) 59.8402 (+-0.328537) 6.00019 (+-0.00114139)
found 5.72 (+-0.000222669) 59.8407 (+-0.32859) 6.00024 (+-0.00114157)
found 8.36 (+-0.000222769) 59.8404 (+-0.328598) 6.00021 (+-0.0011416)
found -5.32 (+-0.000245909) 49.8695 (+-0.300262) 5.00043 (+-0.00104316)
found -8.2 (+-0.000243708) 49.8666 (+-0.299915) 5.00013 (+-0.00104195)
found -6.04 (+-0.000245765) 49.8692 (+-0.300238) 5.0004 (+-0.00104308)
found 0.680002 (+-0.0002451) 49.8684 (+-0.300135) 5.00032 (+-0.00104272)
found 1.4 (+-0.000245765) 49.8692 (+-0.300238) 5.0004 (+-0.00104308)
found 2.84 (+-0.000245596) 49.869 (+-0.300211) 5.00037 (+-0.00104298)
found 8.84 (+-0.000244337) 49.8674 (+-0.300014) 5.00022 (+-0.0010423)
found -7.72 (+-0.000244656) 49.8679 (+-0.300067) 5.00027 (+-0.00104248)
found -8.44 (+-0.000318641) 29.9229 (+-0.232701) 3.00037 (+-0.000808441)
found -9.64 (+-0.000316971) 29.9215 (+-0.232538) 3.00024 (+-0.000807875)
found 0.439999 (+-0.000317904) 29.9221 (+-0.232626) 3.00029 (+-0.000808178)
found 6.44 (+-0.000315232) 29.9202 (+-0.232367) 3.00011 (+-0.000807281)
found -1.48 (+-0.000393898) 19.9512 (+-0.190253) 2.00051 (+-0.000660968)
found -1 (+-0.000392565) 19.9501 (+-0.190159) 2.0004 (+-0.000660642)
found 1.88 (+-0.000393582) 19.9509 (+-0.19023) 2.00048 (+-0.00066089)
found 6.2 (+-0.000390768) 19.949 (+-0.190037) 2.00029 (+-0.00066022)
found -7.96 (+-0.00039068) 19.9488 (+-0.190028) 2.00027 (+-0.000660186)
found 4.76 (+-0.000392634) 19.9501 (+-0.190163) 2.0004 (+-0.000660656)
found 8.12 (+-0.000391529) 19.9493 (+-0.190086) 2.00032 (+-0.000660388)
found 9.08 (+-0.000392423) 19.9501 (+-0.190151) 2.0004 (+-0.000660613)
found -9.4 (+-0.000387909) 19.9474 (+-0.189843) 2.00013 (+-0.000659546)
found -9.16 (+-0.000386294) 19.9469 (+-0.189742) 2.00008 (+-0.000659192)
found 6.68001 (+-0.000391078) 19.9493 (+-0.19006) 2.00032 (+-0.000660297)
found -7 (+-0.000562467) 9.97785 (+-0.13473) 1.00048 (+-0.000468074)
found -6.52 (+-0.000561937) 9.97758 (+-0.13471) 1.00045 (+-0.000468003)
found -2.68 (+-0.000562467) 9.97785 (+-0.13473) 1.00048 (+-0.000468074)
found 4.28 (+-0.000560824) 9.97705 (+-0.134668) 1.0004 (+-0.000467856)
found -0.52 (+-0.000558943) 9.97625 (+-0.134597) 1.00032 (+-0.000467613)
found 5.48 (+-0.000558942) 9.97625 (+-0.134597) 1.00032 (+-0.000467613)
found -8.91999 (+-0.000556723) 9.976 (+-0.134527) 1.0003 (+-0.000467367)
#include <iostream>
TH1F *FitAwmi_Create_Spectrum(
void) {
delete gROOT->FindObject(
"h");
npeaks++;
std::cout << "created "
<< area << 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);
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");
TH1F *
d =
new TH1F(*
h);
d->SetNameTitle(
"d",
"");
d->Reset(
"M");
for (i = 0; i < nbins; i++)
d->SetBinContent(i + 1, source[i]);
sigma *= dx; 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;
}
d->SetLineColor(
kRed);
d->SetLineWidth(1);
if (pm) {
h->GetListOfFunctions()->Remove(pm);
delete pm;
}
h->GetListOfFunctions()->Add(pm);
delete pfit;
delete [] Amp;
delete [] FixAmp;
delete [] FixPos;
delete [] source;
return;
}
static const double x1[5]
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="")
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.
static constexpr double s
constexpr Double_t Sqrt2()
Double_t Sqrt(Double_t x)
constexpr Double_t TwoPi()
#define dest(otri, vertexptr)