This macro fits the source spectrum using the AWMI algorithm from the "TSpectrumFit" class ("TSpectrum" class is used to find peaks).
created -9.7 3.98942 1
created -9.1 11.9683 3
created -8.5 15.9577 4
created -7.9 39.8942 10
created -7.3 15.9577 4
created -6.7 15.9577 4
created -6.1 11.9683 3
created -5.5 7.97885 2
created -4.9 35.9048 9
created -4.3 19.9471 5
created -3.7 15.9577 4
created -3.1 27.926 7
created -2.5 35.9048 9
created -1.9 7.97885 2
created -1.3 27.926 7
created -0.7 39.8942 10
created -0.1 23.9365 6
created 0.5 15.9577 4
created 1.1 11.9683 3
created 1.7 3.98942 1
created 2.3 19.9471 5
created 2.9 11.9683 3
created 3.5 31.9154 8
created 4.1 11.9683 3
created 4.7 27.926 7
created 5.3 39.8942 10
created 5.9 19.9471 5
created 6.5 23.9365 6
created 7.1 39.8942 10
created 7.7 39.8942 10
created 8.3 27.926 7
created 8.9 19.9471 5
created 9.5 39.8942 10
the total number of created peaks = 33 with sigma = 0.1
the total number of found peaks = 33 with sigma = 0.100002 (+-4.82972e-05)
fit chi^2 = 6.88057e-06
found -7.9 (+-0.000363042) 39.8939 (+-0.143132) 10.0001 (+-0.00117461)
found -0.7 (+-0.000364157) 39.8941 (+-0.143184) 10.0002 (+-0.00117504)
found 5.3 (+-0.000363941) 39.8941 (+-0.143174) 10.0002 (+-0.00117496)
found 7.1 (+-0.000364651) 39.8943 (+-0.143209) 10.0002 (+-0.00117524)
found 7.7 (+-0.000364847) 39.8943 (+-0.143218) 10.0002 (+-0.00117532)
found 9.5 (+-0.000360892) 39.8942 (+-0.14305) 10.0002 (+-0.00117394)
found -4.9 (+-0.000382484) 35.9045 (+-0.135779) 9.00009 (+-0.00111427)
found -2.5 (+-0.00038293) 35.9046 (+-0.135799) 9.00011 (+-0.00111443)
found 3.5 (+-0.000405744) 31.9151 (+-0.128015) 8.00008 (+-0.00105056)
found 8.3 (+-0.00043678) 27.9262 (+-0.11985) 7.00019 (+-0.000983551)
found -3.1 (+-0.000436234) 27.9261 (+-0.119831) 7.00017 (+-0.000983396)
found -1.3 (+-0.000435555) 27.9261 (+-0.119811) 7.00016 (+-0.000983224)
found 4.7 (+-0.000436045) 27.9261 (+-0.119826) 7.00017 (+-0.000983351)
found -0.100002 (+-0.000472003) 23.9368 (+-0.110967) 6.00018 (+-0.000910652)
found 6.5 (+-0.00047239) 23.9369 (+-0.110979) 6.0002 (+-0.000910745)
found -4.3 (+-0.000517593) 19.9474 (+-0.101312) 5.00017 (+-0.000831419)
found 5.9 (+-0.000518723) 19.9476 (+-0.101341) 5.00021 (+-0.000831654)
found 2.3 (+-0.000513165) 19.9469 (+-0.101204) 5.00005 (+-0.000830533)
found 8.9 (+-0.000519081) 19.9476 (+-0.10135) 5.00022 (+-0.00083173)
found -7.3 (+-0.000580196) 15.9581 (+-0.0906483) 4.00018 (+-0.000743905)
found -3.7 (+-0.000579663) 15.958 (+-0.090636) 4.00016 (+-0.000743803)
found 0.499998 (+-0.000578039) 15.9579 (+-0.0906031) 4.00012 (+-0.000743533)
found -8.5 (+-0.000579546) 15.9581 (+-0.0906356) 4.00017 (+-0.0007438)
found -6.7 (+-0.000577018) 15.9578 (+-0.0905821) 4.00009 (+-0.000743361)
found 2.9 (+-0.000671736) 11.9687 (+-0.0785313) 3.00017 (+-0.000644466)
found 4.1 (+-0.000672909) 11.9688 (+-0.07855) 3.00019 (+-0.00064462)
found -9.1 (+-0.000665385) 11.9683 (+-0.0784348) 3.00006 (+-0.000643674)
found -6.1 (+-0.000666819) 11.9684 (+-0.0784549) 3.00008 (+-0.000643839)
found 1.1 (+-0.000665385) 11.9683 (+-0.0784348) 3.00007 (+-0.000643674)
found -5.49999 (+-0.000824958) 7.97932 (+-0.0641466) 2.00016 (+-0.000526418)
found -1.9 (+-0.000828809) 7.97953 (+-0.0641879) 2.00021 (+-0.000526757)
found 1.7 (+-0.00117185) 3.98976 (+-0.0453865) 1.0001 (+-0.000372463)
found -9.69999 (+-0.00115884) 3.98951 (+-0.0453139) 1.00004 (+-0.000371868)
#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()