This macro fits the source spectrum using the AWMI algorithm from the "TSpectrumFit" class ("TSpectrum" class is used to find peaks).
created -9.88 79.7885 8
created -9.64 99.7356 10
created -9.4 39.8942 4
created -9.16 9.97356 1
created -8.92 19.9471 2
created -8.68 69.8149 7
created -8.44 9.97356 1
created -8.2 49.8678 5
created -7.96 39.8942 4
created -7.72 59.8413 6
created -7.48 19.9471 2
created -7.24 69.8149 7
created -7 39.8942 4
created -6.76 39.8942 4
created -6.52 19.9471 2
created -6.28 69.8149 7
created -6.04 39.8942 4
created -5.8 69.8149 7
created -5.56 89.762 9
created -5.32 49.8678 5
created -5.08 29.9207 3
created -4.84 69.8149 7
created -4.6 59.8413 6
created -4.36 79.7885 8
created -4.12 59.8413 6
created -3.88 49.8678 5
created -3.64 49.8678 5
created -3.4 19.9471 2
created -3.16 49.8678 5
created -2.92 79.7885 8
created -2.68 79.7885 8
created -2.44 29.9207 3
created -2.2 49.8678 5
created -1.96 29.9207 3
created -1.72 49.8678 5
created -1.48 59.8413 6
created -1.24 69.8149 7
created -1 9.97356 1
created -0.76 99.7356 10
created -0.52 29.9207 3
created -0.28 69.8149 7
created -0.04 79.7885 8
created 0.2 9.97356 1
created 0.44 59.8413 6
created 0.68 69.8149 7
created 0.92 59.8413 6
created 1.16 49.8678 5
created 1.4 99.7356 10
created 1.64 79.7885 8
created 1.88 19.9471 2
created 2.12 79.7885 8
created 2.36 59.8413 6
created 2.6 49.8678 5
created 2.84 39.8942 4
created 3.08 19.9471 2
created 3.32 19.9471 2
created 3.56 69.8149 7
created 3.8 49.8678 5
created 4.04 99.7356 10
created 4.28 59.8413 6
created 4.52 19.9471 2
created 4.76 49.8678 5
created 5 69.8149 7
created 5.24 39.8942 4
created 5.48 69.8149 7
created 5.72 69.8149 7
created 5.96 69.8149 7
created 6.2 19.9471 2
created 6.44 99.7356 10
created 6.68 89.762 9
created 6.92 99.7356 10
created 7.16 9.97356 1
created 7.4 69.8149 7
created 7.64 29.9207 3
created 7.88 9.97356 1
created 8.12 9.97356 1
created 8.36 49.8678 5
created 8.6 49.8678 5
created 8.84 99.7356 10
created 9.08 69.8149 7
created 9.32 59.8413 6
created 9.56 39.8942 4
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.5686e-05)
fit chi^2 = 1.21229e-05
found -9.64 (+-0.000182545) 99.7336 (+-0.448905) 10.0003 (+-0.00155957)
found 6.92 (+-0.000182053) 99.7331 (+-0.448776) 10.0003 (+-0.00155912)
found -0.76 (+-0.000181436) 99.7315 (+-0.448589) 10.0001 (+-0.00155847)
found 1.4 (+-0.000182665) 99.7339 (+-0.44894) 10.0003 (+-0.00155969)
found 4.04 (+-0.000182485) 99.7334 (+-0.448884) 10.0003 (+-0.00155949)
found 6.44 (+-0.000182304) 99.7334 (+-0.448841) 10.0003 (+-0.00155934)
found 8.84 (+-0.000182579) 99.7337 (+-0.448913) 10.0003 (+-0.00155959)
found -5.56 (+-0.000192589) 89.7606 (+-0.425913) 9.00032 (+-0.00147969)
found 6.68 (+-0.000193339) 89.7627 (+-0.426125) 9.00053 (+-0.00148042)
found -4.36 (+-0.00020445) 79.7876 (+-0.401598) 8.00032 (+-0.00139521)
found -2.68 (+-0.000204227) 79.7873 (+-0.401548) 8.00029 (+-0.00139504)
found -0.0400014 (+-0.000203602) 79.7865 (+-0.401408) 8.00021 (+-0.00139456)
found 1.64 (+-0.0002042) 79.7876 (+-0.401549) 8.00032 (+-0.00139504)
found -9.88 (+-0.000204529) 79.7871 (+-0.401588) 8.00027 (+-0.00139518)
found -2.92 (+-0.000204543) 79.7878 (+-0.401622) 8.00034 (+-0.0013953)
found 2.12 (+-0.000203793) 79.7865 (+-0.401444) 8.00021 (+-0.00139468)
found -1.24 (+-0.0002177) 69.8132 (+-0.37549) 7.00019 (+-0.00130451)
found 0.68 (+-0.000218778) 69.8145 (+-0.375707) 7.00032 (+-0.00130526)
found 5.72 (+-0.000219038) 69.8151 (+-0.375765) 7.00037 (+-0.00130547)
found 5.96 (+-0.00021817) 69.8138 (+-0.375583) 7.00024 (+-0.00130483)
found 9.08 (+-0.000219243) 69.8156 (+-0.375812) 7.00043 (+-0.00130563)
found -8.68 (+-0.000216974) 69.8121 (+-0.375337) 7.00008 (+-0.00130398)
found -7.24 (+-0.000217739) 69.8129 (+-0.375488) 7.00016 (+-0.0013045)
found -6.28 (+-0.000217739) 69.8129 (+-0.375488) 7.00016 (+-0.0013045)
found -5.8 (+-0.000218831) 69.8148 (+-0.375722) 7.00035 (+-0.00130532)
found -4.84 (+-0.000218281) 69.8137 (+-0.375601) 7.00024 (+-0.0013049)
found -0.279999 (+-0.000218529) 69.8143 (+-0.375657) 7.00029 (+-0.00130509)
found 3.56 (+-0.000217899) 69.8132 (+-0.375523) 7.00019 (+-0.00130462)
found 5 (+-0.000218329) 69.8137 (+-0.37561) 7.00024 (+-0.00130493)
found 5.48 (+-0.000218602) 69.8143 (+-0.37567) 7.00029 (+-0.00130514)
found 7.4 (+-0.00021721) 69.8124 (+-0.375384) 7.00011 (+-0.00130414)
found 9.8 (+-0.000216488) 69.8142 (+-0.375281) 7.00029 (+-0.00130379)
found 4.28 (+-0.000236276) 59.8415 (+-0.347843) 6.00032 (+-0.00120846)
found -7.72 (+-0.000235397) 59.8399 (+-0.347672) 6.00016 (+-0.00120787)
found -4.6 (+-0.000237027) 59.8423 (+-0.347975) 6.0004 (+-0.00120892)
found -4.12 (+-0.00023671) 59.8418 (+-0.347915) 6.00035 (+-0.00120871)
found -1.48 (+-0.000236573) 59.8415 (+-0.347888) 6.00032 (+-0.00120862)
found 0.919999 (+-0.000236573) 59.8415 (+-0.347888) 6.00032 (+-0.00120862)
found 2.36 (+-0.00023671) 59.8417 (+-0.347915) 6.00034 (+-0.00120871)
found 9.32 (+-0.000236386) 59.8412 (+-0.347853) 6.00029 (+-0.0012085)
found 0.440002 (+-0.000235503) 59.8404 (+-0.347703) 6.00021 (+-0.00120797)
found -5.32 (+-0.000259377) 49.8685 (+-0.317618) 5.00032 (+-0.00110345)
found -3.88 (+-0.000259365) 49.8682 (+-0.31761) 5.00029 (+-0.00110343)
found -3.64 (+-0.000258376) 49.8671 (+-0.317458) 5.00019 (+-0.0011029)
found -2.2 (+-0.00025822) 49.8669 (+-0.317431) 5.00016 (+-0.00110281)
found -1.72 (+-0.000258888) 49.8677 (+-0.317536) 5.00024 (+-0.00110317)
found 1.16 (+-0.000260196) 49.8695 (+-0.317747) 5.00043 (+-0.0011039)
found 2.6 (+-0.000259145) 49.8679 (+-0.317576) 5.00027 (+-0.00110331)
found 3.8 (+-0.000260375) 49.8698 (+-0.317776) 5.00045 (+-0.001104)
found 8.6 (+-0.000259998) 49.8692 (+-0.317716) 5.0004 (+-0.00110379)
found -8.2 (+-0.000257705) 49.8666 (+-0.317361) 5.00013 (+-0.00110256)
found -3.16 (+-0.000258906) 49.8679 (+-0.317545) 5.00027 (+-0.0011032)
found 4.76 (+-0.000258745) 49.8677 (+-0.317518) 5.00024 (+-0.00110311)
found 8.36 (+-0.000257922) 49.8668 (+-0.317395) 5.00016 (+-0.00110268)
found -9.4 (+-0.000289784) 39.8951 (+-0.284074) 4.00029 (+-0.000986917)
found -7.96 (+-0.000290541) 39.8951 (+-0.284152) 4.00029 (+-0.00098719)
found -7 (+-0.000290488) 39.8951 (+-0.284147) 4.00029 (+-0.00098717)
found -6.76 (+-0.000289062) 39.8938 (+-0.283965) 4.00016 (+-0.00098654)
found -6.04 (+-0.00029122) 39.8959 (+-0.284242) 4.00037 (+-0.000987501)
found 2.84 (+-0.00028933) 39.8941 (+-0.284) 4.00019 (+-0.000986661)
found 5.24 (+-0.00029122) 39.8959 (+-0.284242) 4.00037 (+-0.000987501)
found 9.56 (+-0.000291001) 39.8957 (+-0.284213) 4.00035 (+-0.0009874)
found -2.44 (+-0.000336963) 29.9226 (+-0.246231) 3.00035 (+-0.000855445)
found -0.520002 (+-0.000338024) 29.9237 (+-0.246339) 3.00045 (+-0.000855821)
found -5.08 (+-0.000336705) 29.9224 (+-0.246205) 3.00032 (+-0.000855353)
found -1.96 (+-0.000336108) 29.9218 (+-0.246144) 3.00027 (+-0.000855144)
found 7.64 (+-0.000334731) 29.9213 (+-0.246022) 3.00021 (+-0.000854719)
found 1.88 (+-0.000415868) 19.9504 (+-0.201265) 2.00043 (+-0.000699227)
found -7.48 (+-0.000414737) 19.9496 (+-0.201186) 2.00035 (+-0.000698952)
found -3.4 (+-0.000413437) 19.9488 (+-0.201096) 2.00027 (+-0.000698641)
found 4.52 (+-0.000413885) 19.949 (+-0.201127) 2.00029 (+-0.000698748)
found 6.2 (+-0.000416141) 19.9506 (+-0.201285) 2.00045 (+-0.000699297)
found -6.52 (+-0.000413772) 19.949 (+-0.201121) 2.00029 (+-0.000698725)
found 3.08 (+-0.000411093) 19.9477 (+-0.200941) 2.00016 (+-0.0006981)
found 3.32 (+-0.000412436) 19.9485 (+-0.201034) 2.00024 (+-0.000698424)
found -8.91999 (+-0.00041143) 19.9482 (+-0.200973) 2.00022 (+-0.000698213)
found 7.15999 (+-0.000594561) 9.97759 (+-0.142553) 1.00045 (+-0.000495252)
found 0.199996 (+-0.0005928) 9.97679 (+-0.142486) 1.00037 (+-0.000495019)
found -8.44 (+-0.000591402) 9.97625 (+-0.142435) 1.00032 (+-0.00049484)
found -0.999994 (+-0.000594561) 9.97759 (+-0.142553) 1.00045 (+-0.000495252)
found -9.16 (+-0.00058567) 9.97467 (+-0.142232) 1.00016 (+-0.000494136)
found 7.88 (+-0.000582713) 9.97413 (+-0.142133) 1.00011 (+-0.000493792)
found 8.12001 (+-0.000584663) 9.97467 (+-0.142203) 1.00016 (+-0.000494035)
#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()