Skip to content

Commit

Permalink
Merge pull request #36 from niclaurenti/clean-refactor
Browse files Browse the repository at this point in the history
clean refactor
  • Loading branch information
niclaurenti authored Mar 27, 2024
2 parents db0ba50 + da0db3c commit d14ffb3
Show file tree
Hide file tree
Showing 42 changed files with 464 additions and 1,389 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ When using this code please cite [![arXiv](https://img.shields.io/badge/arXiv-24

The code depends on the public library ```gsl```.

Optional dependencies are the library ```pybind11``` and the Python module ```scikit-build``` (both public), that are required for building the Pyhton bindings.
Optional dependencies are the library ```pybind11``` and the Python module ```scikit-build``` (both public), that are required for building the Python bindings.

## Installation

Expand Down Expand Up @@ -40,7 +40,7 @@ or
```bash
g++ -Wall -I/your/installation/path/include -L/your/installation/path/lib/ -o test.exe test.cpp -ladani
```
In the first case remember to run
In both cases remember to run
```bash
export PATH=$PATH:/your/installation/path/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/your/installation/path/lib
Expand Down
53 changes: 35 additions & 18 deletions examples/test.cpp
Original file line number Diff line number Diff line change
@@ -1,38 +1,55 @@
// See README.md for compilation suggestions

#include <adani/adani.h>
#include <iostream>
#include <cmath>
#include <iostream>

using namespace std ;
using namespace std;

int main() {

double x, logx, logx_min=-4, logx_max=0;
double Q, logQ, logQ_min=1, logQ_max=2;
int N=5;
double x, logx, logx_min = -4, logx_max = 0;
double Q, logQ, logQ_min = 1, logQ_max = 2;
int N = 5;

double dlogx=(logx_max - logx_min) / N;
double dlogQ=(logQ_max - logQ_min) / N;
double dlogx = (logx_max - logx_min) / N;
double dlogQ = (logQ_max - logQ_min) / N;

double m = 4.92, m2Q2, m2mu2 ;
int nf = 4 ;
double m = 4.92, m2Q2, m2mu2;
int nf = 4;

for(int i=0; i<N; i++) {
for(int j=0; j<N; j++) {
ApproximateCoefficientFunction F2g(
3, '2', 'g', true, "improved", 1e-3, 1e-3, 1000, false, 25000
);
ApproximateCoefficientFunction FLg(
3, 'L', 'g', true, "improved", 1e-3, 1e-3, 1000, false, 25000
);
ApproximateCoefficientFunction F2q(
3, '2', 'q', true, "exact", 1e-3, 1e-3, 1000, false, 25000
);
ApproximateCoefficientFunction FLq(
3, 'L', 'q', true, "exact", 1e-3, 1e-3, 1000, false, 25000
);

for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {

logx = logx_min + i * dlogx;
x = pow(10, logx);
logQ = logQ_min + j * dlogQ;
Q = pow(10, logQ);

m2Q2 = m * m / (Q * Q) ;
m2mu2 = m2Q2 ;

cout << "C2_g^(3)(x=" << x << ", Q="<< Q << ") = "<< C2_g3_approximation(x, m2Q2, m2mu2, nf) << endl ;
cout << "C2_ps^(3)(x=" << x << ", Q="<< Q << ") = "<< C2_ps3_approximation(x, m2Q2, m2mu2, nf) << endl ;
cout << "CL_g^(3)(x=" << x << ", Q="<< Q << ") = "<< CL_g3_approximation(x, m2Q2, m2mu2, nf) << endl ;
cout << "CL_ps^(3)(x=" << x << ", Q="<< Q << ") = "<< CL_ps3_approximation(x, m2Q2, m2mu2, nf) << endl ;
m2Q2 = m * m / (Q * Q);
m2mu2 = m2Q2;

cout << "C2_g^(3)(x=" << x << ", Q=" << Q
<< ") = " << F2g.fxBand(x, m2Q2, m2mu2, nf) << endl;
cout << "C2_ps^(3)(x=" << x << ", Q=" << Q
<< ") = " << F2q.fxBand(x, m2Q2, m2mu2, nf) << endl;
cout << "CL_g^(3)(x=" << x << ", Q=" << Q
<< ") = " << FLg.fxBand(x, m2Q2, m2mu2, nf) << endl;
cout << "CL_ps^(3)(x=" << x << ", Q=" << Q
<< ") = " << FLq.fxBand(x, m2Q2, m2mu2, nf) << endl;
}
}
return 0;
Expand Down
15 changes: 10 additions & 5 deletions examples/test.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import adani
import adani as ad
import numpy as np

nf = 4
m = 4.92

F2g = ad.ApproximateCoefficientFunction(3, '2', 'g', True, "improved", 1e-3, 1e-3, 1000, False, 25000)
FLg = ad.ApproximateCoefficientFunction(3, 'L', 'g', True, "improved", 1e-3, 1e-3, 1000, False, 25000)
F2q = ad.ApproximateCoefficientFunction(3, '2', 'q', True, "exact", 1e-3, 1e-3, 1000, False, 25000)
FLq = ad.ApproximateCoefficientFunction(3, 'L', 'q', True, "exact", 1e-3, 1e-3, 1000, False, 25000)

for x in np.geomspace(1e-4, 1, 5):
for Q in np.geomspace(10, 100, 5):
m2Q2 = m**2 / Q**2
m2mu2 = m2Q2
print("C2_g^(3)(x=", x, ", Q=", Q, ") = ", adani.C2_g3_approximation(x, m2Q2, m2mu2, nf))
print("C2_ps^(3)(x=", x, ", Q=", Q, ") = ", adani.C2_ps3_approximation(x, m2Q2, m2mu2, nf))
print("CL_g^(3)(x=", x, ", Q=", Q, ") = ", adani.CL_g3_approximation(x, m2Q2, m2mu2, nf))
print("CL_ps^(3)(x=", x, ", Q=", Q, ") = ", adani.CL_ps3_approximation(x, m2Q2, m2mu2, nf))
print("C2_g^(3)(x=", x, ", Q=", Q, ") = ", F2g.fx(x, m2Q2, m2mu2, nf))
print("C2_ps^(3)(x=", x, ", Q=", Q, ") = ", F2g.fx(x, m2Q2, m2mu2, nf))
print("CL_g^(3)(x=", x, ", Q=", Q, ") = ", F2g.fx(x, m2Q2, m2mu2, nf))
print("CL_ps^(3)(x=", x, ", Q=", Q, ") = ", F2g.fx(x, m2Q2, m2mu2, nf))
123 changes: 8 additions & 115 deletions inc/adani/ApproximateCoefficientFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class AbstractApproximate : public CoefficientFunction {
AbstractApproximate(
const int &order, const char &kind, const char &channel,
const double &abserr = 1e-3, const double &relerr = 1e-3,
const int &dim = 1000, const int &method_flag = 0,
const int &dim = 1000, const bool &MCintegral = false,
const int &MCcalls = 25000
);
~AbstractApproximate();
Expand All @@ -89,10 +89,10 @@ class ApproximateCoefficientFunction : public AbstractApproximate {
public:
ApproximateCoefficientFunction(
const int &order, const char &kind, const char &channel,
const bool &NLL = true, const bool &exact_highscale = false,
const bool &revised_approx_highscale = true,
const bool &NLL = true,
const string &highscale_version = "original",
const double &abserr = 1e-3, const double &relerr = 1e-3,
const int &dim = 1000, const int &method_flag = 0,
const int &dim = 1000, const bool &MCintegral = false,
const int &MCcalls = 25000
);
~ApproximateCoefficientFunction() override;
Expand Down Expand Up @@ -122,10 +122,10 @@ class ApproximateCoefficientFunctionKLMV : public AbstractApproximate {
public:
ApproximateCoefficientFunctionKLMV(
const int &order, const char &kind, const char &channel,
const bool &revised_approx_highscale = true, const bool &lowxi = false,
const double &abserr = 1e-3, const double &relerr = 1e-3,
const int &dim = 1000, const int &method_flag = 0,
const int &MCcalls = 25000
const string &highscale_version = "original",
const bool &lowxi = false, const double &abserr = 1e-3,
const double &relerr = 1e-3, const int &dim = 1000,
const bool &MCintegral = false, const int &MCcalls = 25000
);
~ApproximateCoefficientFunctionKLMV() override;

Expand All @@ -151,111 +151,4 @@ class ApproximateCoefficientFunctionKLMV : public AbstractApproximate {
Value ApproximateNLL(double x, double m2Q2) const;
};

// //==========================================================================================//
// // Approximate coefficient functions
// // O(as^3)
// //------------------------------------------------------------------------------------------//

// #define default_method 0

// double C2_g3_approximation(
// double x, double m2Q2, double m2mu2, int nf, int v = 0,
// int method_flag = default_method
// );
// double C2_g30_approximation(double x, double m2Q2, int nf);
// double C2_g30_approximation_implicit(
// double x, double m2Q2, int nf, double A, double B, double C, double D,
// double a, double b, int v1, int v2
// );
// double C2_g30_approximation_BAND(
// double x, double m2Q2, int nf, int v, double var, double fact
// );
// double
// C2_ps3_approximation(double x, double m2Q2, double m2mu2, int nf, int v = 0);
// double C2_ps30_approximation(double x, double m2Q2, int nf);
// double C2_ps30_approximation_implicit(
// double x, double m2Q2, int nf, double A, double B, double C, double D,
// double a, double b, int v
// );
// double C2_ps30_approximation_BAND(
// double x, double m2Q2, int nf, int v, double var, double fact
// );

// double CL_g3_approximation(
// double x, double m2Q2, double m2mu2, int nf, int v = 0,
// int method_flag = default_method
// );
// double CL_g30_approximation(double x, double m2Q2, int nf);
// double CL_g30_approximation_implicit(
// double x, double m2Q2, int nf, double A, double B, double C, double D,
// double a, double b, int v
// );
// double CL_g30_approximation_BAND(
// double x, double m2Q2, int nf, int v, double var, double fact
// );

// double
// CL_ps3_approximation(double x, double m2Q2, double m2mu2, int nf, int v = 0);
// double CL_ps30_approximation(double x, double m2Q2, int nf);
// double CL_ps30_approximation_implicit(
// double x, double m2Q2, int nf, double A, double B, double C, double D,
// double a, double b, int v
// );
// double CL_ps30_approximation_BAND(
// double x, double m2Q2, int nf, int v, double var, double fact
// );

// //==========================================================================================//
// // Approximate coefficient functions
// // O(as^2) from [arXiv:1205.5727] klmv =
// // Kawamura, Lo Presti, Moch, Vogt
// //------------------------------------------------------------------------------------------//

// double C2_g2_approximationA_klmv(double x, double m2Q2, double m2mu2);
// double C2_g2_approximationB_klmv(double x, double m2Q2, double m2mu2);

// double C2_ps2_approximationA_klmv(double x, double m2Q2, double m2mu2);
// double C2_ps2_approximationB_klmv(double x, double m2Q2, double m2mu2);

// //==========================================================================================//
// // Approximate coefficient functions
// // O(as^3) from [arXiv:1205.5727] klmv =
// // Kawamura, Lo Presti, Moch, Vogt
// //------------------------------------------------------------------------------------------//

// //==========================================================================================//
// // the functions labeled with 'paper' use some approximate
// // results for which at the time of the paper
// // [arXiv:1205.5727] the exact result was not known (like
// // aQqPS30) or for which now we have a better approximation
// // (aQg30_B). They are only used as a benchmark against the
// // plots of the paper
// //------------------------------------------------------------------------------------------//

// double C2_g3_approximationA_klmv(
// double x, double m2Q2, double m2mu2, int nf,
// int method_flag = default_method
// );
// double C2_g3_approximationB_klmv(
// double x, double m2Q2, double m2mu2, int nf,
// int method_flag = default_method
// );
// double C2_g3_approximationB_klmv_paper(
// double x, double m2Q2, double m2mu2, int nf,
// int method_flag = default_method
// );
// double C2_g3_approximationBlowxi_klmv(
// double x, double m2Q2, double m2mu2, int nf,
// int method_flag = default_method
// );

// double C2_ps3_approximationA_klmv(double x, double m2Q2, double m2mu2, int
// nf); double C2_ps3_approximationB_klmv(double x, double m2Q2, double m2mu2,
// int nf);

// double
// C2_ps3_approximationA_klmv_paper(double x, double m2Q2, double m2mu2, int
// nf); double C2_ps3_approximationB_klmv_paper(double x, double m2Q2, double
// m2mu2, int nf);

#endif
9 changes: 3 additions & 6 deletions inc/adani/AsymptoticCoefficientFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,17 @@ class AsymptoticCoefficientFunction
public:
AsymptoticCoefficientFunction(
const int &order, const char &kind, const char &channel,
const bool &NLL = true, const bool &exact_highscale = false,
const bool &revised_approx_highscale = true
const bool &NLL = true, const string &highscale_version = "original"
);
~AsymptoticCoefficientFunction();

double fx(double x, double m2Q2, double m2mu2, int nf) const override;
// double MuIndependentTerms(double x, double m2Q2, int nf) const
// override ; double MuDependentTerms(double x, double m2Q2, double
// m2mu2, int nf) const override ;

Value
fxBand(double x, double m2Q2, double m2mu2, int nf) const override;

vector<double> AllVariations(double x, double m2Q2, double m2mu2, int nf) const;
vector<double>
AllVariations(double x, double m2Q2, double m2mu2, int nf) const;

private:
HighScaleCoefficientFunction *highscale_;
Expand Down
12 changes: 6 additions & 6 deletions inc/adani/Convolution.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class AbstractConvolution {
double GetAbserr() const { return abserr_; };
double GetRelerr() const { return relerr_; };
int GetDim() const { return dim_; };
gsl_integration_workspace *GetWorkspace() const {return w_; };
gsl_integration_workspace *GetWorkspace() const { return w_; };
CoefficientFunction *GetCoeffFunc() const { return coefffunc_; };
AbstractSplittingFunction *GetSplitFunc() const { return splitfunc_; };

Expand Down Expand Up @@ -94,7 +94,7 @@ class Convolution : public AbstractConvolution {
double SingularPart(double x, double m2Q2, int nf) const override;
double LocalPart(double x, double m2Q2, int nf) const override;

// support function for the integral. it is static in order to be passed
// support function for the integral. It is static in order to be passed
// to gsl
static double regular_integrand(double z, void *p);
static double singular_integrand(double z, void *p);
Expand Down Expand Up @@ -141,7 +141,7 @@ class DoubleConvolution : public AbstractConvolution {
CoefficientFunction *coefffunc,
AbstractSplittingFunction *splitfunc, const double &abserr = 1e-3,
const double &relerr = 1e-3, const int &dim = 1000,
const int &method_flag = 0, const int &MCcalls = 25000
const bool &MCintegral = false, const int &MCcalls = 25000
);
~DoubleConvolution() override;

Expand All @@ -150,11 +150,11 @@ class DoubleConvolution : public AbstractConvolution {
double LocalPart(double x, double m2Q2, int nf) const override;

// get methods
int GetMethodFlag() const { return method_flag_; };
bool GetMCintegral() const { return MCintegral_; };
int GetMCcalls() const { return MCcalls_; };

// set methods
void SetMethodFlag(const int &method_flag);
void SetMCintegral(const bool &MCintegral);
void SetMCcalls(const int &MCcalls);

// support function for the integral. it is static in order to be passed
Expand All @@ -168,7 +168,7 @@ class DoubleConvolution : public AbstractConvolution {
static double singular3_integrand(double z, void *p);

private:
int method_flag_;
bool MCintegral_;
int MCcalls_;
gsl_monte_vegas_state *s_;
gsl_rng *r_;
Expand Down
21 changes: 1 addition & 20 deletions inc/adani/ExactCoefficientFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,11 @@ class ExactCoefficientFunction : public CoefficientFunction {
ExactCoefficientFunction(
const int &order, const char &kind, const char &channel,
const double &abserr = 1e-3, const double &relerr = 1e-3,
const int &dim = 1000, const int &method_flag = 0,
const int &dim = 1000, const bool &MCintegral = false,
const int &MCcalls = 25000
);
~ExactCoefficientFunction() override;

// get methods
int GetMethodFlag() const { return method_flag_; };
int GetAbserr() const { return abserr_; };
int GetRelerr() const { return relerr_; };
int GetMCcalls() const { return MCcalls_; };
int GetDim() const { return dim_; };

// set methods
void SetMethodFlag(const int &method_flag);
void SetAbserr(const double &abserr);
void SetRelerr(const double &relerr);
void SetMCcalls(const int &MCcalls);
void SetDim(const int &dim);

double fx(double x, double m2Q2, double m2mu2, int nf) const override;
double MuIndependentTerms(double x, double m2Q2, int nf) const override;
double MuDependentTerms(
Expand All @@ -64,11 +50,6 @@ class ExactCoefficientFunction : public CoefficientFunction {
void SetFunctions();

private:
int method_flag_;
double abserr_;
double relerr_;
int MCcalls_;
int dim_;

double (ExactCoefficientFunction::*mu_indep_)(
double, double, int
Expand Down
Loading

0 comments on commit d14ffb3

Please sign in to comment.