35 const int nsig = 5.E4;
36 const int nbkg = 1.e6;
37 Int_t NEvents = nsig+nbkg;
40 double signal_mean = 3;
41 TF1 *f_cb =
new TF1(
"MyCrystalBall",
"crystalball",-5.,5.);
42 TF1 *f_exp =
new TF1(
"MyExponential",
"expo",-5.,5.);
53 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.);
67 for (
int i=0; i<NEvents; i++)
69 h_sum -> Fill(f_sum -> GetRandom());
71 printf(
"Time to generate %d events: ",NEvents);
77 h_sum -> Scale(1.,
"width");
81 new TCanvas(
"Fit",
"Fit",800,1000);
83 auto result = h_sum ->
Fit(
"fsum",
"SQ");
86 printf(
"Time to fit using ROOT TF1Normsum: ");
90 std::vector<double> pref = {nsig, nbkg, signal_mean};
91 for (
unsigned int i = 0; i< pref.size(); ++i) {
Int_t GetNpar() const
Return the number of (non constant) parameters including the coefficients: for 2 functions: c1...
virtual void SetParameters(const Double_t *params)
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
virtual void SetParName(Int_t ipar, const char *name)
Set name of parameter number ipar.
void Print(Option_t *option="") const
Print the real and cpu time passed between the start and stop events.
R__EXTERN TStyle * gStyle
const char * GetParName(Int_t ipar) const
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
virtual Double_t GetParError(Int_t ipar) const
Return value of parameter number ipar.
void SetParameters(TFitEditor::FuncParams_t &pars, TF1 *func)
Restore the parameters from pars into the function.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
To draw Mathematical Formula.
void Error(const char *location, const char *msgfmt,...)
virtual const char * GetParName(Int_t ipar) const
Bool_t AreEqualAbs(Double_t af, Double_t bf, Double_t epsilon)
Class adding two functions: c1*f1+c2*f2.
1-D histogram with a double per channel (see TH1 documentation)}
TFitResultPtr Fit(FitObject *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
std::vector< double > GetParameters() const
Return array of parameters.
virtual Int_t GetNpar() const
virtual Double_t GetParameter(Int_t ipar) const
void SetOptStat(Int_t stat=1)
The type of information printed in the histogram statistics box can be selected via the parameter mod...
THist< 1, double, THistStatContent, THistStatUncertainty > TH1D
static void SetDefaultMinimizer(const char *type, const char *algo=0)