Get the newly designed 1D-integrator class thread-safe (at the cost of numerous memory allocations and deallocations)
This commit is contained in:
34
src/external/BMWtools/BMWIntegrator.h
vendored
34
src/external/BMWtools/BMWIntegrator.h
vendored
@ -49,33 +49,15 @@ using namespace std;
|
|||||||
*/
|
*/
|
||||||
class T2Integrator {
|
class T2Integrator {
|
||||||
public:
|
public:
|
||||||
T2Integrator();
|
T2Integrator() {}; ///< default constructor
|
||||||
virtual ~T2Integrator();
|
virtual ~T2Integrator() {}; ///< default destructor
|
||||||
virtual double FuncAtX(double, const std::vector<double> &par) const = 0;
|
|
||||||
virtual double IntegrateFunc(double, double, const std::vector<double> &par);
|
virtual double IntegrateFunc(double, double, const std::vector<double> &par);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
virtual double FuncAtX(double, const std::vector<double> &par) const = 0;
|
||||||
static double FuncAtXgsl(double, void *);
|
static double FuncAtXgsl(double, void *);
|
||||||
ROOT::Math::GSLIntegrator *fIntegrator; ///< pointer to the GSL integrator
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>Constructor of the alternative base class for 1D integrations
|
|
||||||
* Allocation of memory for an integration using the adaptive 31 point Gauss-Kronrod rule
|
|
||||||
*/
|
|
||||||
inline T2Integrator::T2Integrator() {
|
|
||||||
fIntegrator = new ROOT::Math::GSLIntegrator(ROOT::Math::Integration::kADAPTIVE,ROOT::Math::Integration::kGAUSS31);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>Destructor of the alternative base class for 1D integrations
|
|
||||||
* Clean up.
|
|
||||||
*/
|
|
||||||
inline T2Integrator::~T2Integrator(){
|
|
||||||
delete fIntegrator;
|
|
||||||
fIntegrator=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Method for passing the integrand function value to the integrator.
|
* <p>Method for passing the integrand function value to the integrator.
|
||||||
*
|
*
|
||||||
@ -106,7 +88,13 @@ inline double T2Integrator::IntegrateFunc(double x1, double x2, const std::vecto
|
|||||||
pair<T2Integrator*, const vector<double>*> ptrPair;
|
pair<T2Integrator*, const vector<double>*> ptrPair;
|
||||||
ptrPair.first = (this);
|
ptrPair.first = (this);
|
||||||
ptrPair.second = ∥
|
ptrPair.second = ∥
|
||||||
return fIntegrator->Integral(&T2Integrator::FuncAtXgsl, static_cast<void*>(&ptrPair), x1, x2);
|
|
||||||
|
ROOT::Math::GSLIntegrator *integrator = new ROOT::Math::GSLIntegrator(ROOT::Math::Integration::kADAPTIVE,ROOT::Math::Integration::kGAUSS31);
|
||||||
|
double value(integrator->Integral(&T2Integrator::FuncAtXgsl, static_cast<void*>(&ptrPair), x1, x2));
|
||||||
|
delete integrator;
|
||||||
|
integrator = 0;
|
||||||
|
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -123,8 +111,6 @@ inline double T2Integrator::IntegrateFunc(double x1, double x2, const std::vecto
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Base class for 1D integrations using the GNU Scientific Library integrator.
|
* <p>Base class for 1D integrations using the GNU Scientific Library integrator.
|
||||||
* The function which should be integrated has to be implemented in a derived class.
|
* The function which should be integrated has to be implemented in a derived class.
|
||||||
|
Reference in New Issue
Block a user