Time to generate 1050000 events: Real time 0:00:00, CP time 0.160
****************************************
Minimizer is Minuit2 / Migrad
Chi2 = 1021.04
NDf = 993
Edm = 8.20993e-06
NCalls = 233
NSignal = 50083 +/- 1235.87
NBackground = 998896 +/- 1573.51
Mean = 2.99897 +/- 0.00224467
Sigma = 0.297886 +/- 0.00230899
Alpha = 2.12449 +/- 0.140023
N = 1.15624 +/- 0.474844
Slope = -0.300343 +/- 0.000644415
Time to fit using ROOT TF1Normsum: Real time 0:00:00, CP time 0.160
using namespace std;
void fitNormSum()
{
const int nsig = 5.E4;
const int nbkg = 1.e6;
Int_t NEvents = nsig+nbkg;
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.);
for (int i=0; i<NEvents; i++)
{
h_sum -> Fill(f_sum -> GetRandom());
}
printf("Time to generate %d events: ",NEvents);
h_sum -> Sumw2();
h_sum -> Scale(1., "width");
auto result = h_sum -> Fit("fsum","SQ");
result->Print();
printf("Time to fit using ROOT TF1Normsum: ");
std::vector<double> pref = {nsig, nbkg, signal_mean};
for (unsigned int i = 0; i< pref.size(); ++i) {
}
t2->Draw();
}
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
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...
Bool_t AreEqualAbs(Double_t af, Double_t bf, Double_t epsilon)