This macro fits the source spectrum using the AWMI algorithm from the "TSpectrumFit" class ("TSpectrum" class is used to find peaks).
created -9.88 39.8942 4
created -9.64 79.7885 8
created -9.4 79.7885 8
created -9.16 59.8413 6
created -8.92 49.8678 5
created -8.68 59.8413 6
created -8.44 49.8678 5
created -8.2 59.8413 6
created -7.96 49.8678 5
created -7.72 9.97356 1
created -7.48 89.762 9
created -7.24 79.7885 8
created -7 89.762 9
created -6.76 49.8678 5
created -6.52 39.8942 4
created -6.28 9.97356 1
created -6.04 39.8942 4
created -5.8 69.8149 7
created -5.56 19.9471 2
created -5.32 59.8413 6
created -5.08 29.9207 3
created -4.84 79.7885 8
created -4.6 69.8149 7
created -4.36 9.97356 1
created -4.12 99.7356 10
created -3.88 79.7885 8
created -3.64 9.97356 1
created -3.4 79.7885 8
created -3.16 19.9471 2
created -2.92 39.8942 4
created -2.68 59.8413 6
created -2.44 19.9471 2
created -2.2 29.9207 3
created -1.96 39.8942 4
created -1.72 19.9471 2
created -1.48 39.8942 4
created -1.24 49.8678 5
created -1 79.7885 8
created -0.76 29.9207 3
created -0.52 39.8942 4
created -0.28 49.8678 5
created -0.04 39.8942 4
created 0.2 69.8149 7
created 0.44 69.8149 7
created 0.68 49.8678 5
created 0.92 59.8413 6
created 1.16 19.9471 2
created 1.4 89.762 9
created 1.64 79.7885 8
created 1.88 69.8149 7
created 2.12 29.9207 3
created 2.36 69.8149 7
created 2.6 39.8942 4
created 2.84 89.762 9
created 3.08 19.9471 2
created 3.32 89.762 9
created 3.56 19.9471 2
created 3.8 89.762 9
created 4.04 9.97356 1
created 4.28 39.8942 4
created 4.52 39.8942 4
created 4.76 9.97356 1
created 5 9.97356 1
created 5.24 79.7885 8
created 5.48 49.8678 5
created 5.72 79.7885 8
created 5.96 99.7356 10
created 6.2 59.8413 6
created 6.44 59.8413 6
created 6.68 19.9471 2
created 6.92 69.8149 7
created 7.16 99.7356 10
created 7.4 9.97356 1
created 7.64 69.8149 7
created 7.88 19.9471 2
created 8.12 39.8942 4
created 8.36 59.8413 6
created 8.6 49.8678 5
created 8.84 59.8413 6
created 9.08 79.7885 8
created 9.32 89.762 9
created 9.56 99.7356 10
created 9.8 69.8149 7
the total number of created peaks = 83 with sigma = 0.04
the total number of found peaks = 83 with sigma = 0.040002 (+-1.58121e-05)
fit chi^2 = 1.22694e-05
found 5.96 (+-0.00018387) 99.7342 (+-0.451676) 10.0004 (+-0.00156919)
found 7.16 (+-0.000182985) 99.7326 (+-0.451427) 10.0002 (+-0.00156833)
found 9.56 (+-0.000184046) 99.7348 (+-0.45173) 10.0004 (+-0.00156938)
found -4.12 (+-0.000183071) 99.7328 (+-0.451454) 10.0002 (+-0.00156842)
found -7 (+-0.000193844) 89.7609 (+-0.428505) 9.00034 (+-0.0014887)
found 9.32 (+-0.000194332) 89.7622 (+-0.428642) 9.00048 (+-0.00148917)
found -7.48 (+-0.000193084) 89.7598 (+-0.428316) 9.00024 (+-0.00148804)
found 1.4 (+-0.000193361) 89.7601 (+-0.428382) 9.00026 (+-0.00148827)
found 2.84 (+-0.000192919) 89.759 (+-0.428259) 9.00016 (+-0.00148784)
found 3.32 (+-0.000192571) 89.7585 (+-0.42817) 9.00011 (+-0.00148753)
found 3.8 (+-0.000192298) 89.7582 (+-0.428105) 9.00008 (+-0.00148731)
found -9.4 (+-0.000205903) 79.7881 (+-0.404073) 8.00037 (+-0.00140381)
found -7.24 (+-0.000206324) 79.7892 (+-0.40418) 8.00048 (+-0.00140418)
found -3.88 (+-0.000205122) 79.7873 (+-0.403903) 8.00029 (+-0.00140322)
found 1.64 (+-0.000206118) 79.7886 (+-0.404127) 8.00042 (+-0.001404)
found 9.08 (+-0.000206002) 79.7884 (+-0.404099) 8.0004 (+-0.0014039)
found -9.64 (+-0.000205629) 79.7876 (+-0.404007) 8.00032 (+-0.00140358)
found -4.84 (+-0.000205352) 79.787 (+-0.40394) 8.00026 (+-0.00140335)
found -3.4 (+-0.000204063) 79.7852 (+-0.403643) 8.00008 (+-0.00140232)
found -1 (+-0.00020511) 79.7865 (+-0.403879) 8.00021 (+-0.00140314)
found 5.24 (+-0.000204589) 79.7859 (+-0.403766) 8.00016 (+-0.00140275)
found 5.72 (+-0.000205966) 79.7884 (+-0.404091) 8.0004 (+-0.00140388)
found -4.6 (+-0.000219258) 69.8138 (+-0.377808) 7.00024 (+-0.00131256)
found 0.439999 (+-0.000220082) 69.8145 (+-0.377968) 7.00032 (+-0.00131312)
found 1.88 (+-0.000219845) 69.8143 (+-0.37792) 7.00029 (+-0.00131295)
found 9.8 (+-0.000218547) 69.8158 (+-0.377714) 7.00045 (+-0.00131224)
found -5.8 (+-0.00021905) 69.8129 (+-0.37775) 7.00016 (+-0.00131236)
found 0.200001 (+-0.000219919) 69.8143 (+-0.377933) 7.00029 (+-0.001313)
found 2.36 (+-0.00021929) 69.8132 (+-0.377798) 7.00019 (+-0.00131253)
found 6.92 (+-0.000219818) 69.8145 (+-0.377922) 7.00032 (+-0.00131296)
found 7.64 (+-0.000218281) 69.8121 (+-0.377598) 7.00008 (+-0.00131183)
found 6.2 (+-0.000238553) 59.8425 (+-0.350092) 6.00043 (+-0.00121627)
found -9.16 (+-0.000238136) 59.8418 (+-0.350011) 6.00035 (+-0.00121599)
found -8.68 (+-0.000237681) 59.841 (+-0.349923) 6.00027 (+-0.00121569)
found -8.2 (+-0.000237681) 59.8409 (+-0.349923) 6.00027 (+-0.00121569)
found -2.68 (+-0.000236815) 59.8399 (+-0.349766) 6.00016 (+-0.00121514)
found 0.919999 (+-0.000237001) 59.8402 (+-0.349801) 6.00019 (+-0.00121526)
found 6.44 (+-0.000237165) 59.8404 (+-0.349833) 6.00021 (+-0.00121537)
found 8.36 (+-0.000237494) 59.8407 (+-0.349888) 6.00024 (+-0.00121557)
found 8.84 (+-0.000238136) 59.8418 (+-0.350011) 6.00035 (+-0.00121599)
found -5.32 (+-0.000236598) 59.8396 (+-0.349727) 6.00013 (+-0.00121501)
found -6.76 (+-0.000261199) 49.8687 (+-0.319571) 5.00035 (+-0.00111024)
found -8.92 (+-0.000261124) 49.8684 (+-0.319555) 5.00032 (+-0.00111019)
found -8.44 (+-0.000261124) 49.8684 (+-0.319555) 5.00032 (+-0.00111019)
found -7.96 (+-0.000259669) 49.8671 (+-0.319339) 5.00019 (+-0.00110943)
found -1.24 (+-0.000261047) 49.8684 (+-0.319545) 5.00032 (+-0.00111015)
found -0.28 (+-0.000260289) 49.8674 (+-0.319422) 5.00021 (+-0.00110972)
found 0.68 (+-0.000261303) 49.8687 (+-0.319584) 5.00035 (+-0.00111029)
found 5.48 (+-0.000261812) 49.8695 (+-0.319668) 5.00043 (+-0.00111058)
found 8.6 (+-0.000261124) 49.8684 (+-0.319555) 5.00032 (+-0.00111019)
found -6.52 (+-0.000290522) 39.8938 (+-0.285648) 4.00016 (+-0.000992388)
found -1.96 (+-0.000290491) 39.8935 (+-0.285636) 4.00013 (+-0.000992346)
found -0.519999 (+-0.000291462) 39.8943 (+-0.285758) 4.00021 (+-0.000992768)
found -0.039999 (+-0.000292511) 39.8954 (+-0.285893) 4.00032 (+-0.000993238)
found 2.6 (+-0.000293364) 39.8964 (+-0.286006) 4.00043 (+-0.000993631)
found 4.52 (+-0.000290254) 39.8935 (+-0.285613) 4.00013 (+-0.000992266)
found -9.88 (+-0.000291646) 39.8944 (+-0.285764) 4.00022 (+-0.00099279)
found -6.04 (+-0.000290976) 39.8943 (+-0.285709) 4.00021 (+-0.000992599)
found -2.92 (+-0.000291312) 39.8943 (+-0.285743) 4.00021 (+-0.000992715)
found -1.48 (+-0.000291073) 39.8941 (+-0.285711) 4.00019 (+-0.000992605)
found 4.28 (+-0.000290254) 39.8935 (+-0.285613) 4.00013 (+-0.000992266)
found 8.12 (+-0.000291312) 39.8943 (+-0.285743) 4.00021 (+-0.000992715)
found -0.760003 (+-0.000338635) 29.9223 (+-0.247679) 3.00032 (+-0.000860477)
found -5.08 (+-0.000339311) 29.9229 (+-0.247746) 3.00037 (+-0.000860709)
found 2.12 (+-0.000339336) 29.9229 (+-0.247748) 3.00037 (+-0.000860716)
found -2.2 (+-0.000336509) 29.9207 (+-0.24747) 3.00016 (+-0.000859751)
found -3.16 (+-0.000416627) 19.9493 (+-0.202358) 2.00032 (+-0.000703023)
found 3.08 (+-0.000419044) 19.9509 (+-0.202525) 2.00048 (+-0.000703604)
found 3.56 (+-0.000419045) 19.9509 (+-0.202525) 2.00048 (+-0.000703604)
found -5.56 (+-0.000417236) 19.9496 (+-0.202398) 2.00035 (+-0.000703162)
found -2.44 (+-0.00041526) 19.9485 (+-0.202264) 2.00024 (+-0.000702698)
found 1.16 (+-0.000417934) 19.9501 (+-0.202448) 2.0004 (+-0.000703335)
found 6.68 (+-0.000417235) 19.9496 (+-0.202398) 2.00035 (+-0.000703162)
found 7.88 (+-0.000416264) 19.949 (+-0.202332) 2.00029 (+-0.000702934)
found -1.72 (+-0.000414901) 19.9482 (+-0.202238) 2.00021 (+-0.000702608)
found 7.39999 (+-0.000598143) 9.97758 (+-0.143412) 1.00045 (+-0.000498236)
found -3.64 (+-0.000597687) 9.97732 (+-0.143394) 1.00043 (+-0.000498172)
found 4.03999 (+-0.000595213) 9.97652 (+-0.143305) 1.00035 (+-0.000497864)
found -4.35999 (+-0.000598143) 9.97759 (+-0.143412) 1.00046 (+-0.000498236)
found -7.71999 (+-0.000596137) 9.97679 (+-0.143338) 1.00038 (+-0.000497977)
found -6.28 (+-0.000591669) 9.97519 (+-0.143173) 1.00021 (+-0.000497406)
found 4.75999 (+-0.000587294) 9.9744 (+-0.143027) 1.00014 (+-0.000496899)
found 5.00001 (+-0.000590219) 9.97548 (+-0.143137) 1.00024 (+-0.000497281)
#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()