Uso de ROOT
- https://root.cern.ch/doc/master/classTF1.html
- https://root.cern.ch/doc/master/classTGraph.html
- https://root.cern.ch/doc/master/namespaceTMath.html
- https://root.cern.ch/how-implement-mathematical-function-inside-framework
- https://root.cern.ch/doc/master/classTFile.html
- https://root.cern.ch/doc/master/classTMatrixT.html
- https://root.cern.ch/doc/master/classTVectorT.html
TGraph
{
TCanvas *c1 = new TCanvas("c1","A Simple Graph Example",200,10,700,500);
Double_t x[100], y[100];
Int_t n = 20;
for (Int_t i=0;i<n;i++) {
x[i] = i*0.1;
y[i] = 10*sin(x[i]+0.2);
}
gr = new TGraph(n,x,y);
gr->Draw("AC*");
return c1;
}TF1 *fa2 = new TF1("fa2","TMath::DiLog(x)",0,10);
fa2->Draw();Double_t myFunc(x) { return x+sin(x); } .... TF1 *fa3 = new TF1(
Double_t myFunc(x) { return x+sin(x); }
TF1 *fa3 = new TF1("fa3","myFunc(x)",-3,5);
fa3->Draw();TF1 *fa = new TF1("fa","[0]*x*sin([1]*x)",-3,3);
fa->SetParameter(0,value_first_parameter);
fa->SetParameter(1,value_second_parameter);TF1 *fb2 = new TF1("fa3","TMath::Landau(x,[0],[1],0)",-5,10);
fb2->SetParameters(0.2,1.3);
fb2->Draw();Consider the macro myfunc.C below:
// Macro myfunc.C
Double_t myfunction(Double_t *x, Double_t *par)
{
Float_t xx =x[0];
Double_t f = TMath::Abs(par[0]*sin(par[1]*xx)/xx);
return f;
}
void myfunc()
{
TF1 *f1 = new TF1("myfunc",myfunction,0,10,2);
f1->SetParameters(2,1);
f1->SetParNames("constant","coefficient");
f1->Draw();
}
void myfit()
{
TH1F *h1=new TH1F("h1","test",100,0,10);
h1->FillRandom("myfunc",20000);
TF1 *f1=gROOT->GetFunction("myfunc");
f1->SetParameters(800,1);
h1->Fit("myfunc");
}In an interactive session you can do:
Root > .L myfunc.C Root > myfunc(); Root > myfit();
