This macro fits the source spectrum using the AWMI algorithm from the "TSpectrumFit" class ("TSpectrum" class is used to find peaks).
created -9.7 19.9471 5
created -9.1 11.9683 3
created -8.5 15.9577 4
created -7.9 35.9048 9
created -7.3 3.98942 1
created -6.7 27.926 7
created -6.1 19.9471 5
created -5.5 11.9683 3
created -4.9 27.926 7
created -4.3 31.9154 8
created -3.7 3.98942 1
created -3.1 23.9365 6
created -2.5 19.9471 5
created -1.9 35.9048 9
created -1.3 27.926 7
created -0.7 27.926 7
created -0.1 23.9365 6
created 0.5 15.9577 4
created 1.1 27.926 7
created 1.7 39.8942 10
created 2.3 3.98942 1
created 2.9 11.9683 3
created 3.5 35.9048 9
created 4.1 11.9683 3
created 4.7 35.9048 9
created 5.3 15.9577 4
created 5.9 39.8942 10
created 6.5 31.9154 8
created 7.1 7.97885 2
created 7.7 23.9365 6
created 8.3 15.9577 4
created 8.9 7.97885 2
created 9.5 31.9154 8
the total number of created peaks = 33 with sigma = 0.1
the total number of found peaks = 33 with sigma = 0.100002 (+-4.39221e-05)
fit chi^2 = 5.56434e-06
found 1.7 (+-0.000326052) 39.8939 (+-0.128699) 10.0001 (+-0.00105617)
found 5.9 (+-0.000327223) 39.8941 (+-0.128751) 10.0002 (+-0.00105659)
found -7.9 (+-0.000343243) 35.9044 (+-0.122075) 9.00006 (+-0.00100181)
found -1.9 (+-0.000345237) 35.9047 (+-0.122157) 9.00015 (+-0.00100248)
found 3.5 (+-0.000343786) 35.9044 (+-0.122096) 9.00008 (+-0.00100198)
found 4.7 (+-0.000344068) 35.9045 (+-0.122107) 9.00009 (+-0.00100207)
found 6.5 (+-0.000366049) 31.9154 (+-0.115169) 8.00015 (+-0.000945132)
found -4.3 (+-0.000364979) 31.9152 (+-0.115129) 8.0001 (+-0.000944802)
found 9.50001 (+-0.000362165) 31.9153 (+-0.115035) 8.00012 (+-0.000944033)
found -1.3 (+-0.000393108) 27.9263 (+-0.10779) 7.00021 (+-0.000884575)
found -6.7 (+-0.000389984) 27.9257 (+-0.107686) 7.00008 (+-0.000883721)
found -4.9 (+-0.000391741) 27.926 (+-0.107743) 7.00014 (+-0.000884192)
found -0.7 (+-0.000392449) 27.9261 (+-0.107766) 7.00017 (+-0.000884383)
found 1.1 (+-0.000392483) 27.9262 (+-0.107769) 7.00018 (+-0.000884403)
found -3.1 (+-0.000421599) 23.9364 (+-0.0997079) 6.00008 (+-0.000818252)
found -0.100001 (+-0.000423773) 23.9367 (+-0.0997691) 6.00014 (+-0.000818754)
found 7.7 (+-0.000421949) 23.9364 (+-0.0997161) 6.00008 (+-0.000818319)
found -9.7 (+-0.000462664) 19.9469 (+-0.0910305) 5.00004 (+-0.000747041)
found -6.1 (+-0.000464425) 19.9473 (+-0.0910819) 5.00013 (+-0.000747463)
found -2.5 (+-0.000466227) 19.9475 (+-0.0911273) 5.00019 (+-0.000747835)
found 0.500001 (+-0.000521712) 15.9581 (+-0.081516) 4.00017 (+-0.00066896)
found 5.3 (+-0.000523766) 15.9584 (+-0.0815598) 4.00025 (+-0.000669319)
found 8.3 (+-0.000519097) 15.9578 (+-0.0814637) 4.0001 (+-0.000668531)
found -8.5 (+-0.000520875) 15.958 (+-0.0815001) 4.00016 (+-0.00066883)
found -9.1 (+-0.00060195) 11.9685 (+-0.0705876) 3.00012 (+-0.000579276)
found -5.5 (+-0.000603628) 11.9687 (+-0.0706142) 3.00016 (+-0.000579495)
found 4.1 (+-0.00060642) 11.969 (+-0.0706596) 3.00023 (+-0.000579867)
found 2.90001 (+-0.000600863) 11.9686 (+-0.0705756) 3.00013 (+-0.000579178)
found 7.1 (+-0.000744043) 7.97942 (+-0.0577083) 2.00018 (+-0.000473582)
found 8.9 (+-0.000742355) 7.97932 (+-0.0576901) 2.00016 (+-0.000473433)
found -7.3 (+-0.00106479) 3.99018 (+-0.0408791) 1.00021 (+-0.000335474)
found -3.7 (+-0.0010625) 3.99008 (+-0.0408654) 1.00018 (+-0.000335361)
found 2.29998 (+-0.00105951) 3.99003 (+-0.0408496) 1.00017 (+-0.000335232)
#include <iostream>
{
delete gROOT->FindObject(
"h");
<< std::endl;
}
std::cout <<
"the total number of created peaks = " <<
npeaks <<
" with sigma = " <<
sigma << std::endl;
}
void FitAwmi(void)
{
else
for (i = 0; i < nbins; i++)
source[i] =
h->GetBinContent(i + 1);
for (i = 0; i <
nfound; i++) {
Amp[i] =
h->GetBinContent(bin);
}
pfit->SetFitParameters(0, (nbins - 1), 1000, 0.1,
pfit->kFitOptimChiCounts,
pfit->kFitAlphaHalving,
pfit->kFitPower2,
pfit->kFitTaylorOrderFirst);
delete gROOT->FindObject(
"d");
d->SetNameTitle(
"d",
"");
for (i = 0; i < nbins; i++)
d->SetBinContent(i + 1,
source[i]);
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++) {
Pos[i] =
d->GetBinCenter(bin);
Amp[i] =
d->GetBinContent(bin);
}
h->GetListOfFunctions()->Remove(
pm);
}
h->GetListOfFunctions()->Add(
pm);
delete s;
return;
}
bool Bool_t
Boolean (0=false, 1=true) (bool)
int Int_t
Signed integer 4 bytes (int)
double Double_t
Double 8 bytes.
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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
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.
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()