Fill a 1D histogram from a user-defined parametric function.
void hist002_TH1_fillrandom_userfunc()
{
TFormula form1(
"form1",
"abs(sin(x)/x)");
double rangeMin = 0.0;
double rangeMax = 10.0;
TF1 sqroot(
"sqroot",
"x*gaus(0) + [3]*form1", rangeMin, rangeMax);
sqroot.SetLineColor(4);
sqroot.SetLineWidth(6);
double gausScale = 10.0;
double gausMean = 4.0;
double gausVar = 1.0;
double form1Scale = 20.0;
sqroot.SetParameters(gausScale, gausMean, gausVar, form1Scale);
int nBins = 200;
TH1D h1d(
"h1d",
"Test random numbers", nBins, rangeMin, rangeMax);
h1d.FillRandom("sqroot", 10000);
auto myFile = std::unique_ptr<TFile>(
TFile::Open(
"fillrandom_userfunc.root",
"RECREATE"));
myFile->WriteObject(&form1, form1.GetName());
myFile->WriteObject(&sqroot, sqroot.GetName());
myFile->WriteObject(&h1d, h1d.GetName());
}
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 double per channel (see TH1 documentation)
- Date
- November 2024
- Author
- Rene Brun, Giacomo Parolini
Definition in file hist002_TH1_fillrandom_userfunc.C.