31double background(
double *
x,
double *par) {
32 return par[0] + par[1]*
x[0] + par[2]*
x[0]*
x[0];
36double lorentzianPeak(
double *
x,
double *par) {
38 TMath::Max( 1.e-10,(
x[0]-par[2])*(
x[0]-par[2]) + .25*par[1]*par[1]);
42double fitFunction(
double *
x,
double *par) {
43 return background(
x,par) + lorentzianPeak(
x,&par[3]);
46bool DoFit(
const char* fitter,
TVirtualPad *pad,
int npass) {
47 printf(
"\n*********************************************************************************\n");
48 printf(
"\t %s \n",fitter);
49 printf(
"*********************************************************************************\n");
59 std::string title = std::string(fitter) +
" fit bench";
60 histo =
new TH1D(fitter,title.c_str(),200,0,3);
69 for (
int pass=0;pass<npass;pass++) {
70 if (pass%100 == 0) printf(
"pass : %d\n",pass);
73 for (
int i=0;i<5000;i++) {
76 int iret = histo->
Fit(fitFcn,
"Q0");
78 if (iret!=0)
Error(
"DoFit",
"Fit pass %d failed !",pass);
81 if (!fitterType.Contains(
"Fumili"))
82 histo->
Fit(fitFcn,
"E");
84 histo->
Fit(fitFcn,
"");
91 double cputime = timer.
CpuTime();
92 printf(
"%s, npass=%d : RT=%7.3f s, Cpu=%7.3f s\n",fitter,npass,timer.
RealTime(),cputime);
101int minuit2FitBench(
int npass=20) {
107 fitFcn =
new TF1(
"fitFcn",fitFunction,0,3,6);
115 ok &= DoFit(
"Minuit",
gPad,npass);
119 ok &= DoFit(
"Fumili",
gPad,npass);
123 ok &= DoFit(
"Minuit2",
gPad,npass);
127 ok &= DoFit(
"Fumili2",
gPad,npass);
129 c1->SaveAs(
"FitBench.root");
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
static void SetDefaultMinimizer(const char *type, const char *algo=nullptr)
Set the default Minimizer type and corresponding algorithms.
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
TDirectory::TContext keeps track and restore the current directory.
virtual void SetNpx(Int_t npx=100)
virtual Double_t GetRandom(TRandom *rng=nullptr, Option_t *opt=nullptr)
virtual void SetParameters(const Double_t *params)
1-D histogram with a double per channel (see TH1 documentation)
TH1 is the base class of all histogram classes in ROOT.
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.
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
virtual TF1 * GetFunction(const char *name) const
Return pointer to function with name.
A Pave (see TPave) with a text centered in the Pave.
void Draw(Option_t *option="") override
Draw this pavelabel with its current attributes.
Random number generator class based on M.
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
Double_t CpuTime()
Stop the stopwatch (if it is running) and return the cputime (in seconds) passed between the start an...
void Stop()
Stop the stopwatch.
TVirtualPad is an abstract base class for the Pad and Canvas classes.
virtual void SetGrid(Int_t valuex=1, Int_t valuey=1)=0
virtual void SetLogy(Int_t value=1)=0
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.