36 const int nsig = 5.E4;
37 const int nbkg = 1.e6;
38 int nEvents = nsig + nbkg;
41 double signal_mean = 3;
42 TF1 *f_cb =
new TF1(
"MyCrystalBall",
"crystalball", -5., 5.);
43 TF1 *f_exp =
new TF1(
"MyExponential",
"expo", -5., 5.);
54 TF1 *f_sum =
new TF1(
"fsum", *fnorm_exp_cb, -5., 5., fnorm_exp_cb->
GetNpar());
60 for (
int i = 2; i < f_sum->
GetNpar(); ++i)
66 TH1D *h_sum =
new TH1D(
"h_ExpCB",
"Exponential Bkg + CrystalBall function", nBins, -5., 5.);
68 printf(
"Time to generate %d events: ", nEvents);
73 h_sum->
Scale(1.,
"width");
77 new TCanvas(
"Fit",
"Fit", 800, 1000);
79 auto result = h_sum->
Fit(
"fsum",
"SQ");
82 printf(
"Time to fit using ROOT TF1Normsum: ");
86 std::vector<double> pref = {nsig, nbkg, signal_mean};
87 for (
unsigned int i = 0; i < pref.size(); ++i) {
89 Error(
"testFitNormSum",
"Difference found in fitted %s - difference is %g sigma", f_sum->
GetParName(i),
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
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 Int_t GetNpar() const
virtual Double_t GetParError(Int_t ipar) const
virtual const char * GetParName(Int_t ipar) const
virtual void SetParameters(const Double_t *params)
virtual void SetParName(Int_t ipar, const char *name)
virtual Double_t GetParameter(Int_t ipar) const
void Print(Option_t *option="") const override
Print result of the fit, by default chi2, parameter values and errors.
1-D histogram with a double per channel (see TH1 documentation)
virtual void FillRandom(TF1 *f1, Int_t ntimes=5000, TRandom *rng=nullptr)
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.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Bool_t AreEqualAbs(Double_t af, Double_t bf, Double_t epsilon)
Comparing floating points.