Skip to content

Commit

Permalink
Add new C++ program to display orders in a grid
Browse files Browse the repository at this point in the history
  • Loading branch information
cschwan committed Nov 4, 2023
1 parent 6efd750 commit 188a10d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
10 changes: 7 additions & 3 deletions examples/cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@ CXXFLAGS = -std=c++11 -O3 -Wall -Wextra
PINEAPPL_DEPS != pkg-config --cflags --libs pineappl_capi
LHAPDF_DEPS != pkg-config --cflags --libs lhapdf

all: convolute-grid display-channels fill-custom-grid fill-grid
all: convolute-grid display-channels display-orders fill-custom-grid fill-grid

test-examples: convolute-grid display-channels fill-custom-grid fill-grid
test-examples: convolute-grid display-channels display-orders fill-custom-grid fill-grid
./fill-grid
./fill-custom-grid
./convolute-grid
./display-channels
./display-orders

convolute-grid: convolute-grid.cpp
$(CXX) $(CXXFLAGS) $< $(LHAPDF_DEPS) $(PINEAPPL_DEPS) -o $@

display-channels: display-channels.cpp
$(CXX) $(CXXFLAGS) $< $(PINEAPPL_DEPS) -o $@

display-orders: display-orders.cpp
$(CXX) $(CXXFLAGS) $< $(PINEAPPL_DEPS) -o $@

fill-custom-grid: fill-grid.cpp
$(CXX) $(CXXFLAGS) $< -DUSE_CUSTOM_GRID_PARAMETERS $(PINEAPPL_DEPS) -o $@

Expand All @@ -26,4 +30,4 @@ fill-grid: fill-grid.cpp
PHONY: clean

clean:
rm -f convolute-grid display-channels fill-custom-grid fill-grid
rm -f convolute-grid display-channels display-orders fill-custom-grid fill-grid
52 changes: 52 additions & 0 deletions examples/cpp/display-orders.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <pineappl_capi.h>

#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

int main(int argc, char* argv[]) {
std::string filename = "drell-yan-rap-ll.pineappl.lz4";

switch (argc) {
case 2:
filename = argv[1];
case 1:
break;

default:
std::cout << "Usage: " << argv[0] << " [grid]\n";
}

// read the grid from a file
auto* grid = pineappl_grid_read(filename.c_str());

// how many perturbative orders does this grid contain?
std::size_t orders = pineappl_grid_order_count(grid);

std::vector<std::uint32_t> order_params(4 * orders);

// read out all exponents of the perturbative orders in the grid
pineappl_grid_order_params(grid, order_params.data());

for (std::size_t order = 0; order != orders; ++order) {
std::cout << std::setw(4) << order << ' ';

// exponent of the strong coupling
std::uint32_t exp_as = order_params.at(4 * order + 0);
// exponent of the electromagnetic/electroweak coupling
std::uint32_t exp_al = order_params.at(4 * order + 1);
// exponent of the renormalization log
std::uint32_t exp_lr = order_params.at(4 * order + 2);
// exponent of the factorization log
std::uint32_t exp_lf = order_params.at(4 * order + 3);

std::cout << "O(as^" << exp_as << " a^" << exp_al << " lr^" << exp_lr << " lf^" << exp_lf
<< ")\n";
}

// release memory
pineappl_grid_delete(grid);
}

0 comments on commit 188a10d

Please sign in to comment.