created -9.76 14.9603 3
created -9.28 4.98678 1
created -8.8 44.881 9
created -8.32 14.9603 3
created -7.84 9.97356 2
created -7.36 24.9339 5
created -6.88 29.9207 6
created -6.4 29.9207 6
created -5.92 39.8942 8
created -5.44 14.9603 3
created -4.96 24.9339 5
created -4.48 44.881 9
created -4 34.9074 7
created -3.52 49.8678 10
created -3.04 29.9207 6
created -2.56 34.9074 7
created -2.08 4.98678 1
created -1.6 19.9471 4
created -1.12 9.97356 2
created -0.64 44.881 9
created -0.16 4.98678 1
created 0.32 14.9603 3
created 0.8 34.9074 7
created 1.28 19.9471 4
created 1.76 19.9471 4
created 2.24 39.8942 8
created 2.72 24.9339 5
created 3.2 9.97356 2
created 3.68 4.98678 1
created 4.16 14.9603 3
created 4.64 39.8942 8
created 5.12 14.9603 3
created 5.6 49.8678 10
created 6.08 9.97356 2
created 6.56 34.9074 7
created 7.04 44.881 9
created 7.52 39.8942 8
created 8 14.9603 3
created 8.48 49.8678 10
created 8.96 29.9207 6
created 9.44 24.9339 5
the total number of created peaks = 41 with sigma = 0.08
the total number of found peaks = 41 with sigma = 0.0800011 (+-2.30047e-05)
fit chi^2 = 2.85266e-06
found -3.52 (+-0.000185967) 49.8678 (+-0.114252) 10.0001 (+-0.000756599)
found 5.6 (+-0.000184927) 49.8674 (+-0.114177) 10 (+-0.0007561)
found 8.48 (+-0.000185486) 49.8676 (+-0.114217) 10.0001 (+-0.000756366)
found -8.8 (+-0.00019476) 44.8806 (+-0.108308) 9.00004 (+-0.000717233)
found -4.48 (+-0.000196051) 44.881 (+-0.108391) 9.00012 (+-0.000717785)
found -0.64 (+-0.000194565) 44.8805 (+-0.108295) 9.00003 (+-0.000717151)
found 7.04 (+-0.000196382) 44.8812 (+-0.108414) 9.00015 (+-0.000717935)
found -5.92 (+-0.000207667) 39.8941 (+-0.102176) 8.00009 (+-0.000676626)
found 2.24 (+-0.000207712) 39.8941 (+-0.102178) 8.00009 (+-0.000676641)
found 4.64 (+-0.000207204) 39.894 (+-0.102148) 8.00006 (+-0.000676444)
found 7.52 (+-0.000207998) 39.8943 (+-0.102197) 8.00012 (+-0.000676764)
found -4 (+-0.000223583) 34.9079 (+-0.0956619) 7.00019 (+-0.000633491)
found -2.56 (+-0.000221611) 34.9073 (+-0.0955585) 7.00007 (+-0.000632805)
found 0.8 (+-0.000221882) 34.9073 (+-0.0955699) 7.00007 (+-0.000632881)
found 6.56 (+-0.000222324) 34.9075 (+-0.0955953) 7.00011 (+-0.00063305)
found -6.4 (+-0.000241162) 29.921 (+-0.0885498) 6.00014 (+-0.000586393)
found -3.04 (+-0.000241571) 29.9211 (+-0.0885695) 6.00017 (+-0.000586523)
found 8.96 (+-0.00024124) 29.921 (+-0.088554) 6.00015 (+-0.000586421)
found -6.88 (+-0.000240693) 29.9208 (+-0.0885275) 6.00011 (+-0.000586245)
found 2.72 (+-0.000263563) 24.9341 (+-0.0808122) 5.0001 (+-0.000535153)
found 9.44 (+-0.000261473) 24.9341 (+-0.0807454) 5.00011 (+-0.000534711)
found -7.36 (+-0.00026322) 24.934 (+-0.0807981) 5.00008 (+-0.00053506)
found -4.96 (+-0.000264052) 24.9342 (+-0.0808307) 5.00012 (+-0.000535276)
found 1.28 (+-0.000295742) 19.9474 (+-0.072313) 4.00011 (+-0.00047887)
found -1.6 (+-0.000292972) 19.947 (+-0.0722282) 4.00003 (+-0.000478309)
found 1.76 (+-0.000295941) 19.9475 (+-0.0723197) 4.00012 (+-0.000478914)
found -8.32 (+-0.000341959) 14.9607 (+-0.0626383) 3.00011 (+-0.000414802)
found -5.44 (+-0.000343044) 14.9608 (+-0.0626631) 3.00013 (+-0.000414966)
found 5.12 (+-0.000344358) 14.9611 (+-0.0626964) 3.00018 (+-0.000415187)
found 8 (+-0.000344357) 14.9611 (+-0.0626964) 3.00018 (+-0.000415187)
found -9.76 (+-0.000338572) 14.9602 (+-0.0625522) 3.00001 (+-0.000414232)
found 0.320003 (+-0.000340735) 14.9605 (+-0.0626097) 3.00008 (+-0.000414612)
found 4.16 (+-0.000340986) 14.9606 (+-0.0626162) 3.00009 (+-0.000414656)
found 6.08 (+-0.00042357) 9.97429 (+-0.0512234) 2.00017 (+-0.000339211)
found -7.84 (+-0.000419775) 9.97383 (+-0.0511581) 2.00008 (+-0.000338778)
found -1.12 (+-0.0004219) 9.97409 (+-0.0511948) 2.00013 (+-0.000339021)
found 3.2 (+-0.000417972) 9.97373 (+-0.0511304) 2.00006 (+-0.000338595)
found -0.160008 (+-0.000601151) 4.98733 (+-0.036241) 1.00012 (+-0.000239994)
found -9.27999 (+-0.000601151) 4.98733 (+-0.036241) 1.00012 (+-0.000239994)
found -2.08 (+-0.000601028) 4.98727 (+-0.0362388) 1.00011 (+-0.00023998)
found 3.68 (+-0.000595125) 4.98697 (+-0.0361866) 1.00005 (+-0.000239634)
#include <iostream>
TH1F *FitAwmi_Create_Spectrum(
void) {
delete gROOT->FindObject(
"h");
npeaks++;
std::cout << "created "
<< area << 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);
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");
TH1F *
d =
new TH1F(*
h);
d->SetNameTitle(
"d",
"");
d->Reset(
"M");
for (
i = 0;
i < nbins;
i++)
d->SetBinContent(
i + 1, source[
i]);
sigma *= dx; 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;
std::cout << "found "
<< Positions[
i] <<
" (+-" << PositionsErrors[
i] <<
") "
<< Amplitudes[
i] <<
" (+-" << AmplitudesErrors[
i] <<
") "
<< Areas[
i] <<
" (+-" << AreasErrors[
i] <<
")"
<< std::endl;
}
d->SetLineColor(
kRed);
d->SetLineWidth(1);
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;
}
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()