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) {
void Error(const char *location, const char *msgfmt,...)
void SetParameters(TFitEditor::FuncParams_t &pars, TF1 *func)
Restore the parameters from pars into the function.
R__EXTERN TStyle * gStyle
static void SetDefaultMinimizer(const char *type, const char *algo=0)
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 Draw(Option_t *option="")
Draw this function with its current attributes.
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)}
To draw Mathematical Formula.
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
void Print(Option_t *option="") const
Print the real and cpu time passed between the start and stop events.
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...
TFitResultPtr Fit(FitObject *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
Bool_t AreEqualAbs(Double_t af, Double_t bf, Double_t epsilon)