34 const int nsig = 5.E4;
35 const int nbkg = 1.e6;
36 Int_t NEvents = nsig+nbkg;
39 double signal_mean = 3;
40 TF1 *f_cb =
new TF1(
"MyCrystalBall",
"crystalball",-5.,5.);
41 TF1 *f_exp =
new TF1(
"MyExponential",
"expo",-5.,5.);
52 TF1 * f_sum =
new TF1(
"fsum", *fnorm_exp_cb, -5., 5., fnorm_exp_cb->
GetNpar());
57 f_sum->SetParName(1,
"NBackground");
58 f_sum->SetParName(0,
"NSignal");
59 for (
int i = 2; i < f_sum->GetNpar(); ++i)
60 f_sum->SetParName(i,fnorm_exp_cb->
GetParName(i) );
65 TH1D *h_sum =
new TH1D(
"h_ExpCB",
"Exponential Bkg + CrystalBall function", NBins, -5., 5.);
66 for (
int i=0; i<NEvents; i++)
68 h_sum -> Fill(f_sum -> GetRandom());
70 printf(
"Time to generate %d events: ",NEvents);
76 h_sum -> Scale(1.,
"width");
80 new TCanvas(
"Fit",
"Fit",800,1000);
85 printf(
"Time to fit using ROOT TF1Normsum: ");
89 std::vector<double> pref = {nsig, nbkg, signal_mean};
90 for (
unsigned int i = 0; i< pref.size(); ++i) {
92 Error(
"testFitNormSum",
"Difference found in fitted %s - difference is %g sigma",f_sum->GetParName(i), (f_sum->GetParameter(i)-pref[i])/f_sum->GetParError(i));
97 auto t1 =
new TLatex(-2.5, 300000,
TString::Format(
"%s = %8.0f #pm %4.0f",
"NSignal",f_sum->GetParameter(0), f_sum->GetParError(0) ) );
98 auto t2 =
new TLatex(-2.5, 270000,
TString::Format(
"%s = %8.0f #pm %4.0f",
"Nbackgr",f_sum->GetParameter(1), f_sum->GetParError(1) ) );
void Print(Option_t *option="") const
Print the real and cpu time passed between the start and stop events.
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
R__EXTERN TStyle * gStyle
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
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...
std::vector< double > GetParameters() const
Return array of parameters.
To draw Mathematical Formula.
const char * GetParName(Int_t ipar) const
void Error(const char *location, const char *msgfmt,...)
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)
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
void SetOptStat(Int_t stat=1)
The type of information printed in the histogram statistics box can be selected via the parameter mod...
static void SetDefaultMinimizer(const char *type, const char *algo=0)