00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "TF1.h"
00010 #include "TMath.h"
00011 #include "TLegend.h"
00012
00013
00014 double MyFunc (double *x, double *p ) {
00015 return TMath::Gaus(x[0],p[0],p[1] );
00016 }
00017
00018
00019 struct MyDerivFunc {
00020 MyDerivFunc(TF1 * f): fFunc(f) {}
00021 double operator() (double *x, double * ) const {
00022 return fFunc->Derivative(*x);
00023 }
00024 TF1 * fFunc;
00025 };
00026
00027 struct MyIntegFunc {
00028 MyIntegFunc(TF1 * f): fFunc(f) {}
00029 double Integral (double *x, double * ) const {
00030 double a = fFunc->GetXmin();
00031 return fFunc->Integral(a, *x);
00032 }
00033 TF1 * fFunc;
00034 };
00035
00036
00037
00038 void exampleFunctor() {
00039
00040 double xmin = -10; double xmax = 10;
00041
00042
00043 TF1 * f1 = new TF1("f1",MyFunc,xmin,xmax,2);
00044 f1->SetParameters(0.,1.);
00045 f1->SetMaximum(3); f1->SetMinimum(-1);
00046 f1->Draw();
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 MyDerivFunc * deriv = new MyDerivFunc(f1);
00057 TF1 * f2 = new TF1("f2",deriv, xmin, xmax, 0, "MyDerivFunc");
00058
00059 f2->SetLineColor(kBlue);
00060 f2->Draw("same");
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 MyIntegFunc * intg = new MyIntegFunc(f1);
00072 TF1 * f3 = new TF1("f3",intg,&MyIntegFunc::Integral, xmin, xmax, 0, "MyIntegFunc","Integral");
00073
00074 f3->SetLineColor(kRed);
00075 f3->Draw("same");
00076
00077 TLegend * l = new TLegend(0.78, 0.25, 0.97 ,0.45);
00078 l->AddEntry(f1, "Func");
00079 l->AddEntry(f2, "Deriv.");
00080 l->AddEntry(f3, "Integral");
00081 l->Draw();
00082
00083
00084 }