Time to generate 1050000 events: Real time 0:00:00, CP time 0.150
****************************************
Minimizer is Minuit2 / Migrad
Chi2 = 1018.73
NDf = 993
Edm = 9.65559e-06
NCalls = 233
NSignal = 50082 +/- 1231.21
NBackground = 998899 +/- 1569.86
Mean = 2.99896 +/- 0.0022426
Sigma = 0.297871 +/- 0.00230279
Alpha = 2.12493 +/- 0.1368
N = 1.1562 +/- 0.468136
Slope = -0.300341 +/- 0.000644187
Time to fit using ROOT TF1Normsum: Real time 0:00:00, CP time 0.150
{
const int nsig = 5.E4;
const int nbkg = 1.e6;
int nEvents = nsig + nbkg;
int nBins = 1e3;
double signal_mean = 3;
TF1 *f_cb =
new TF1(
"MyCrystalBall",
"crystalball", -5., 5.);
TF1 *f_exp =
new TF1(
"MyExponential",
"expo", -5., 5.);
TF1 *f_sum =
new TF1(
"fsum", *fnorm_exp_cb, -5., 5., fnorm_exp_cb->
GetNpar());
for (
int i = 2; i < f_sum->
GetNpar(); ++i)
TH1D *h_sum =
new TH1D(
"h_ExpCB",
"Exponential Bkg + CrystalBall function", nBins, -5., 5.);
printf("Time to generate %d events: ", nEvents);
h_sum->
Scale(1.,
"width");
new TCanvas(
"Fit",
"Fit", 800, 1000);
printf("Time to fit using ROOT TF1Normsum: ");
std::vector<double> pref = {nsig, nbkg, signal_mean};
for (unsigned int i = 0; i < pref.size(); ++i) {
Error(
"testFitNormSum",
"Difference found in fitted %s - difference is %g sigma", f_sum->
GetParName(i),
}
t2->Draw();
}
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
R__EXTERN TStyle * gStyle
static void SetDefaultMinimizer(const char *type, const char *algo=nullptr)
Set the default Minimizer type and corresponding algorithms.
Class adding two functions: c1*f1+c2*f2.
const char * GetParName(Int_t ipar) const
std::vector< double > GetParameters() const
Return array of parameters.
Int_t GetNpar() const
Return the number of (non constant) parameters including the coefficients: for 2 functions: c1,...
virtual Double_t GetParError(Int_t ipar) const
Return value of parameter number ipar.
virtual Int_t GetNpar() const
virtual const char * GetParName(Int_t ipar) const
virtual void SetParName(Int_t ipar, const char *name)
Set name of parameter number ipar.
virtual void SetParameters(const Double_t *params)
virtual Double_t GetParameter(Int_t ipar) const
1-D histogram with a double per channel (see TH1 documentation)
virtual void FillRandom(const char *fname, Int_t ntimes=5000, TRandom *rng=nullptr)
Fill histogram following distribution in function fname.
virtual TFitResultPtr Fit(const char *formula, Option_t *option="", Option_t *goption="", Double_t xmin=0, Double_t xmax=0)
Fit histogram with function fname.
void Draw(Option_t *option="") override
Draw this histogram with options.
virtual void Scale(Double_t c1=1, Option_t *option="")
Multiply this histogram by a constant c1.
virtual void Sumw2(Bool_t flag=kTRUE)
Create structure to store sum of squares of weights.
To draw Mathematical Formula.
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
void SetOptStat(Int_t stat=1)
The type of information printed in the histogram statistics box can be selected via the parameter mod...
Bool_t AreEqualAbs(Double_t af, Double_t bf, Double_t epsilon)
Comparing floating points.