#include "Math/Integrator.h" #include "Math/WrappedFunction.h" #include class formula { public: formula(); formula(double newY); ~formula(); double operator() (double x){ return x*y; }; void SetY( double newY) { y= newY; } protected: double x, y; }; formula::formula(){ y = 1; } formula::formula(double newY){ y = newY; } formula::~formula(){} void testIntegration() { formula f(2.); ROOT::Math::WrappedFunction wf(f); ROOT::Math::Integrator ig(wf); std::cout << ig.Integral(0,1) << std::endl; // changing the parameter in formula f.SetY(3.); // need to re-create a new WrappedFunction because we // used formula by value ig.SetFunction(ROOT::Math::WrappedFunction(f) ); std::cout << ig.Integral(0,1) << std::endl; // it is more efficient to use in WrappedFunction a reference // but we have to be sure now that formula is not delete before // WrappedFunction ROOT::Math::WrappedFunction wf2(f); ig.SetFunction(wf2); f.SetY(5.); std::cout << ig.Integral(0,1) << std::endl; f.SetY(10.); std::cout << ig.Integral(0,1) << std::endl; }