Skip to content

Commit

Permalink
Add new examples showing the extraction of channel information
Browse files Browse the repository at this point in the history
  • Loading branch information
cschwan committed Nov 4, 2023
1 parent 85b9479 commit da6af32
Show file tree
Hide file tree
Showing 2 changed files with 69 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,16 +3,20 @@ 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 fill-custom-grid fill-grid
all: convolute-grid display-channels fill-custom-grid fill-grid

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

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

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

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

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

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

#include <cstddef>
#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] [pdf]\n";
}

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

// extract all channels
auto* channels = pineappl_grid_lumi(grid);

// how many channels are there?
auto channel_count = pineappl_lumi_count(channels);

for (std::size_t channel = 0; channel != channel_count; ++channel) {
// print channel index
std::cout << std::setw(4) << channel << ' ';

// how many partonic combinations does this channel have?
auto combinations = pineappl_lumi_combinations(channels, channel);

std::vector<double> factors(combinations);
std::vector<int> pids(2 * combinations);

pineappl_lumi_entry(channels, channel, pids.data(), factors.data());

for (std::size_t combination = 0; combination != combinations; ++combination) {
auto factor = factors.at(combination);
auto pida = pids.at(2 * combination + 0);
auto pidb = pids.at(2 * combination + 1);

if (combination != 0) {
std::cout << " + ";
}

std::cout << factor << " x (" << std::setw(3) << pida << ',' << std::setw(4) << pidb
<< ")";
}

std::cout << '\n';
}

// release memory
pineappl_lumi_delete(channels);
pineappl_grid_delete(grid);
}

0 comments on commit da6af32

Please sign in to comment.