Simple fitting example (1-d histogram with an interpreted function)
TFile** fillrandom.root
TFile* fillrandom.root
KEY: TFormula form1;1 abs(sin(x)/x)
KEY: TF1 sqroot;1 x*gaus(0) + [3]*form1
KEY: TH1F h1f;1 Test random numbers
Formula based function: sqroot
sqroot : x*gaus(0) + [3]*form1 Ndim= 1, Npar= 4, Number= 0
Formula expression:
x*[p0]*exp(-0.5*((x-[p1])/[p2])*((x-[p1])/[p2]))+[p3]*(abs(sin(x)/x))
****************************************
Minimizer is Minuit2 / Migrad
Chi2 = 198.935
NDf = 190
Edm = 1.49283e-07
NCalls = 149
p0 = 33.1658 +/- 0.545703
p1 = 4.00667 +/- 0.0165304
p2 = 0.984663 +/- 0.0128238
p3 = 63.4464 +/- 1.33233
fit1 : Real Time = 0.35 seconds Cpu Time = 0.35 seconds
c1->GetFrame()->SetFillColor(21);
c1->GetFrame()->SetBorderMode(-1);
c1->GetFrame()->SetBorderSize(5);
} else {
gROOT->ProcessLine(
Form(
".x %s../hist/fillrandom.C(0)",dir.
Data()));
if (!file) return;
}
if (!sqroot){
Error(
"fit1.C",
"Cannot find object sqroot of type TF1\n");
return;
}
if (!h1f){
Error(
"fit1.C",
"Cannot find object h1f of type TH1F\n");
return;
}
}
R__EXTERN TBenchmark * gBenchmark
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
R__EXTERN TSystem * gSystem
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
virtual void Start(const char *name)
Starts Benchmark with the specified name.
virtual void Show(const char *name)
Stops Benchmark name and Prints results.
void GetObject(const char *namecycle, T *&ptr)
Get an object with proper type checking.
void Print(Option_t *option="") const override
This method must be overridden when a class wants to print itself.
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
void ls(Option_t *option="") const override
List file contents.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
1-D histogram with a float per channel (see TH1 documentation)
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.
A Pave (see TPave) with text, lines or/and boxes inside.
const char * Data() const
TString & Append(const char *cs)
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
- Author
- Rene Brun
Definition in file fit1.C.