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);
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),
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.