Ref: https://root.cern.ch/doc/master/classTF1.html
// Macro myfunc.C
Double_t myfunction(Double_t *x, Double_t *par)
{
Double_t f = TMath::Abs(par[0]*sin(par[1]*xx)/xx);
return f;
}
void myfunc()
{
auto f1 = new TF1(“myfunc”,myfunction,0,10,2);
f1 → SetParameters(2,1);
f1 → SetParNames(“constant”,“coefficient”);
}
void myfit()
{
auto h1 = new TH1F(“h1”,“test”,100,0,10);
h1 → FillRandom(“myfunc”,20000);
TF1 *f1 = (TF1 *)gROOT->GetFunction(“myfunc”);
f1 → SetParameters(800,1);
}
Can I add myfunction2 and then create “auto f1= new TF1(“myfunc”, myfunc + myfunc2, 0, 10, 2)” ?
Example exists in this version below , but not in c++ user defined functions?
{
auto fcos = new TF1 (“fcos”, “[0]*cos(x)”, 0., 10.);
fcos->SetParNames( “cos”);
fcos->SetParameter( 0, 1.1);
auto fsin = new TF1 (“fsin”, “[0]*sin(x)”, 0., 10.);
fsin->SetParNames( “sin”);
fsin->SetParameter( 0, 2.1);
auto fsincos = new TF1 (“fsc”, “fcos+fsin”);
auto fs2 = new TF1 (“fs2”, “fsc+fsc”);
}