openloops is hosted by Hepforge, IPPP Durham

Native OpenLoops C/C++ interface

For all routines of the OpenLoops Fortran90 interface there are c-bindings available via the following interface

extern "C" {
  void ol_setparameter_int(const char* param, int val);
  void ol_setparameter_double(const char* param, double val);
  void ol_setparameter_string(const char* param, char* val);
  void ol_getparameter_int(const char* param, int* val);
  void ol_getparameter_double(const char* param, double* val);
  int ol_register_process(const char* process, int amptype);
  int ol_n_external(int id);
  void ol_phase_space_point(int id, double sqrt_s, double* pp);
  void ol_start();
  void ol_finish();
  void ol_evaluate_tree(int id, double* pp, double* m2tree);
  void ol_evaluate_cc(int id, double* pp, double* m2tree, double* m2cc, double* m2ew);
  void ol_evaluate_sc(int id, double* pp, int emitter, double* polvect, double* m2sc);
  void ol_evaluate_loop(int id, double* pp, double* m2tree, double* m2loop, double* acc);
  void ol_evaluate_loop2(int id, double* pp, double* m2loop2, double* acc);
  void ol_evaluate_ct(int id, double* pp, double* m2_tree, double* m2_ct);
}

Here (in contrast to the Fortran interface), any phase-space point has the format pp(5*N) according to the BLHA convention, where every fifth component is defined to be the mass of the corresponding external particle. This entry is currently not set by the Rambo interface routine ol_phase_space_point nor used by any of the OpenLoops routines.

More details on the C/C++ interface will follow soon.

Explicit C/C++ example

An explicit example is listed in the following. It calculates the one-loop amplitude of the process dd ➞ Zuu for a random phase-space point. The required library has to be downloaded before via

./scons auto=ppzjj


#include 

// Interface
extern "C" {
  void ol_setparameter_int(const char* param, int val);
  void ol_setparameter_double(const char* param, double val);
  int ol_register_process(const char* process, int amptype);
  int ol_n_external(int id);
  void ol_phase_space_point(int id, double sqrt_s, double* pp);
  void ol_start();
  void ol_finish();
  void ol_evaluate_tree(int id, double* pp, double* m2_tree);
  void ol_evaluate_loop(int id, double* pp, double* m2_tree, double* m2_loop, double* acc);
}

int main() {

  double sqrts = 1000., mu = 100., mZ = 91.2, alphas = 0.1;
  double m2_tree, m2_loop[3], acc;

  // coupling order alpha_ew^1, implies QCD correction for loop process
  ol_setparameter_int("order_ew", 1);

  // Set parameter: Z mass
  ol_setparameter_double("mass(23)", mZ);

  // Increase verbosity level to list loaded libraries
  ol_setparameter_int("verbose", 1);

  //
  // register one-loop amplitude for process d dbar -> Z u ubar.
  // The "ppzjj" process library must be installed before via
  // $ ./scons auto=ppzjj
  //
  // second argument of ol_register_process:
  // 1 for tree-like matrix elements (tree, color and spin correlations),
  // 11 for loop, 12 for loop^2
  int id = ol_register_process("1 -1 -> 23 2 -2", 11);

  // Initialize OpenLoops
  ol_start();

  if (id > 0) {
    // Set parameter: strong coupling
    ol_setparameter_double("alpha_s", alphas);
    // Set parameter: renormalization scale
    ol_setparameter_double("mu", 100.);

    // Obtain a random phase-space point in the format pp[5*N] from Rambo
    double pp[5*ol_n_external(id)];
    ol_phase_space_point(id, sqrts, pp);
    std::cout.precision(15);
    std::cout << std::endl;
    std::cout << "Tree and loop matrix element of the process" << std::endl;
    std::cout << "d dbar -> Z u ubar" << std::endl;
    std::cout << "for the phase-space point" << std::endl;
    for (int k = 0; k < 5; k++) {
      std::cout << "P[" << k+1 << "] = " << pp[5*k] << "  " << pp[5*k+1]
                << "  " << pp[5*k+2] << "  " << pp[5*k+3] << std::endl;
    }

    // evaluate tree matrix element
    ol_evaluate_tree(id, pp, &m2;_tree);

    // print tree result
    std::cout << std::endl;
    std::cout << "ol_evaluate_tree" << std::endl;
    std::cout << "Tree:       " << m2_tree << std::endl;

    // evaluate loop matrix element (which also returns the tree)
    ol_evaluate_loop(id, pp, &m2;_tree, m2_loop, &acc;);

    // print loop result
    std::cout << std::endl;
    std::cout << "ol_evaluate_loop" << std::endl;
    std::cout << "Tree:       " << m2_tree << std::endl;
    std::cout << "Loop ep^0:  " << m2_loop[0] << std::endl;
    std::cout << "Loop ep^-1: " << m2_loop[1] << std::endl;
    std::cout << "Loop ep^-2: " << m2_loop[2] << std::endl;
    std::cout << "Accuracy:   " << acc << std::endl;
    std::cout << std::endl;
  }


  ol_finish();

  return 0;
}


This example can also be found inside the file ./examples/OL_cpp.cpp of the OpenLoops installation and can be compiled via

cd ./examples
g++ -o OL_cpp.o -c OL_cpp.cpp
g++ -o OL_cpp -Wl,-rpath=../lib OL_cpp.o -L../lib -lopenloops

or with our SCons build system via

cd ./examples
../scons OL_cpp