This macro fits the source spectrum using the AWMI algorithm from the "TSpectrumFit" class ("TSpectrum" class is used to find peaks).
created -9.7 35.9048 9
created -9.1 7.97885 2
created -8.5 23.9365 6
created -7.9 7.97885 2
created -7.3 23.9365 6
created -6.7 31.9154 8
created -6.1 15.9577 4
created -5.5 15.9577 4
created -4.9 27.926 7
created -4.3 15.9577 4
created -3.7 39.8942 10
created -3.1 7.97885 2
created -2.5 35.9048 9
created -1.9 3.98942 1
created -1.3 35.9048 9
created -0.7 27.926 7
created -0.1 19.9471 5
created 0.5 31.9154 8
created 1.1 11.9683 3
created 1.7 7.97885 2
created 2.3 3.98942 1
created 2.9 19.9471 5
created 3.5 31.9154 8
created 4.1 39.8942 10
created 4.7 23.9365 6
created 5.3 35.9048 9
created 5.9 39.8942 10
created 6.5 39.8942 10
created 7.1 15.9577 4
created 7.7 11.9683 3
created 8.3 3.98942 1
created 8.9 3.98942 1
created 9.5 3.98942 1
the total number of created peaks = 33 with sigma = 0.1
the total number of found peaks = 33 with sigma = 0.100002 (+-1.68944e-05)
fit chi^2 = 7.95087e-07
found -3.7 (+-0.000123194) 39.8938 (+-0.0486456) 10.0001 (+-0.00039921)
found 4.1 (+-0.00012385) 39.8942 (+-0.0486763) 10.0002 (+-0.000399461)
found 5.9 (+-0.000124141) 39.8944 (+-0.0486906) 10.0002 (+-0.000399579)
found 6.5 (+-0.0001238) 39.8942 (+-0.0486743) 10.0002 (+-0.000399445)
found -9.7 (+-0.000129993) 35.9042 (+-0.0461511) 9.00003 (+-0.000378739)
found -2.5 (+-0.000129513) 35.9043 (+-0.0461356) 9.00004 (+-0.000378611)
found -1.3 (+-0.00012999) 35.9045 (+-0.0461558) 9.0001 (+-0.000378777)
found 5.3 (+-0.000130767) 35.9049 (+-0.0461881) 9.00021 (+-0.000379042)
found -6.7 (+-0.000138353) 31.9153 (+-0.043533) 8.00013 (+-0.000357253)
found 0.499999 (+-0.000138145) 31.9152 (+-0.0435251) 8.0001 (+-0.000357188)
found 3.5 (+-0.000138739) 31.9155 (+-0.0435483) 8.00019 (+-0.000357378)
found -0.700001 (+-0.000148406) 27.9261 (+-0.0407387) 7.00018 (+-0.000334322)
found -4.9 (+-0.00014783) 27.9258 (+-0.0407187) 7.0001 (+-0.000334158)
found 4.7 (+-0.000160984) 23.9371 (+-0.0377377) 6.00025 (+-0.000309694)
found -8.5 (+-0.00015916) 23.9363 (+-0.0376838) 6.00005 (+-0.000309252)
found -7.3 (+-0.000159939) 23.9366 (+-0.0377067) 6.00013 (+-0.00030944)
found -0.0999996 (+-0.000176258) 19.9475 (+-0.0344472) 5.00019 (+-0.000282691)
found 2.9 (+-0.00017513) 19.9472 (+-0.0344204) 5.00012 (+-0.000282471)
found -6.1 (+-0.000196993) 15.958 (+-0.0308093) 4.00016 (+-0.000252837)
found -4.3 (+-0.000197729) 15.9583 (+-0.0308247) 4.00022 (+-0.000252963)
found 7.1 (+-0.000197008) 15.9581 (+-0.0308102) 4.00017 (+-0.000252843)
found -5.5 (+-0.00019686) 15.958 (+-0.0308065) 4.00014 (+-0.000252813)
found 1.1 (+-0.00022747) 11.9686 (+-0.0266823) 3.00013 (+-0.000218968)
found 7.7 (+-0.000226187) 11.9683 (+-0.0266627) 3.00007 (+-0.000218807)
found -3.1 (+-0.00028241) 7.97968 (+-0.0218273) 2.00025 (+-0.000179125)
found -9.1 (+-0.000281474) 7.97947 (+-0.0218167) 2.00019 (+-0.000179039)
found -7.9 (+-0.00028075) 7.97931 (+-0.0218085) 2.00016 (+-0.000178971)
found 1.7 (+-0.000277501) 7.9789 (+-0.0217746) 2.00005 (+-0.000178693)
found -1.9 (+-0.000403325) 3.99028 (+-0.0154576) 1.00023 (+-0.000126852)
found 2.30001 (+-0.000397447) 3.98971 (+-0.0154235) 1.00009 (+-0.000126573)
found 8.3 (+-0.000394869) 3.98955 (+-0.0154095) 1.00005 (+-0.000126458)
found 8.9 (+-0.000392733) 3.98945 (+-0.0153981) 1.00003 (+-0.000126365)
found 9.5 (+-0.000388897) 3.98945 (+-0.0153821) 1.00003 (+-0.000126233)
#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()