From da6af32ca835d205349d757624f17e7a0b42c71e Mon Sep 17 00:00:00 2001 From: Christopher Schwan Date: Sat, 4 Nov 2023 12:04:45 +0100 Subject: [PATCH] Add new examples showing the extraction of channel information --- examples/cpp/Makefile | 10 +++-- examples/cpp/display-channels.cpp | 62 +++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 examples/cpp/display-channels.cpp diff --git a/examples/cpp/Makefile b/examples/cpp/Makefile index a30d4073..22e7758f 100644 --- a/examples/cpp/Makefile +++ b/examples/cpp/Makefile @@ -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 $@ @@ -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 diff --git a/examples/cpp/display-channels.cpp b/examples/cpp/display-channels.cpp new file mode 100644 index 00000000..e3670aa8 --- /dev/null +++ b/examples/cpp/display-channels.cpp @@ -0,0 +1,62 @@ +#include + +#include +#include +#include +#include +#include + +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 factors(combinations); + std::vector 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); +}