Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions examples/two_dimensional_distribution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,20 @@ int main()
auto integrand = hep::make_integrand<double>(
gauss,
2,
hep::distribution_parameters<double>{100, 100, min, max, min, max, ""}
hep::distribution_parameters<double>{100, 100, min, max, min, max, "gauss"}
);

// now integrate and record the differential distributions
auto const chkpt = hep::plain(integrand, std::vector<std::size_t>(1, 10000000));
auto const chkpt = hep::plain(
integrand,
std::vector<std::size_t>(1, 10000000),
hep::make_plain_chkpt<double, std::mt19937>(),
hep::callback<hep::plain_chkpt<double>>(hep::callback_mode::verbose_and_write_chkpt, "dist_chkpt")
);

auto const result = chkpt.results().back();

// integral is zero
std::cout << "integral is I = " << result.value() << " +- " << result.error() << "\n\n";

auto const& distribution = result.distributions()[0];
auto const& mid_points_x = hep::mid_points_x(distribution);
auto const& mid_points_y = hep::mid_points_y(distribution);

std::cout.setf(std::ios_base::scientific);

// print the distribution
for (std::size_t i = 0; i != mid_points_x.size(); ++i)
{
std::cout << mid_points_x[i] << '\t' << mid_points_y[i] << '\t'
<< distribution.results()[i].value() << '\t'
<< distribution.results()[i].error() << '\n';
}
std::cout << "integral is I = " << result.value() << " +- " << result.error() << "\n\n"
"to view the distribution use the checkpoint viewer: `chkpt dists dist_chkpt`\n";
}
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ if get_option('examples')
subdir('examples')
endif

subdir('src')
subdir('tests')
38 changes: 38 additions & 0 deletions src/chkpt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "read_type.hpp"
#include "operations.hpp"

#include <fstream>
#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>

int main(int argc, char* argv[])
{
std::ios_base::sync_with_stdio(false);

if (argc < 3)
{
std::cerr << hep::operations_help_string();

return 1;
}

// capture all arguments as strings, neglecting the first, second, and last argument
std::vector<std::string> arguments(&argv[2], &argv[argc - 1]);

try
{
std::string operation_name{argv[1]};
std::ifstream file{argv[argc - 1]};
auto const& type = hep::read_type(file);

hep::operations().at(type)(operation_name, arguments, file);
}
catch (std::runtime_error const& exception)
{
std::cerr << "Error: " << exception.what() << '\n';

return 1;
}
}
71 changes: 71 additions & 0 deletions src/make_chkpt.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#ifndef MAKE_CHKPT_HPP
#define MAKE_CHKPT_HPP

#include "hep/mc/chkpt.hpp"
#include "hep/mc/multi_channel_chkpt.hpp"
#include "hep/mc/plain_chkpt.hpp"
#include "hep/mc/vegas_chkpt.hpp"

namespace hep
{

template <typename Chkpt>
hep::chkpt_with_rng<hep::stream_rng, Chkpt> make_chkpt(std::istream& in);

template <>
hep::plain_chkpt_with_rng<hep::stream_rng, float> make_chkpt<hep::plain_chkpt<float>>(std::istream& in)
{
return hep::make_plain_chkpt<float, hep::stream_rng>(in);
}

template <>
hep::plain_chkpt_with_rng<hep::stream_rng, double> make_chkpt<hep::plain_chkpt<double>>(std::istream& in)
{
return hep::make_plain_chkpt<double, hep::stream_rng>(in);
}

template <>
hep::plain_chkpt_with_rng<hep::stream_rng, long double> make_chkpt<hep::plain_chkpt<long double>>(std::istream& in)
{
return hep::make_plain_chkpt<long double, hep::stream_rng>(in);
}

template <>
hep::vegas_chkpt_with_rng<hep::stream_rng, float> make_chkpt<hep::vegas_chkpt<float>>(std::istream& in)
{
return hep::make_vegas_chkpt<float, hep::stream_rng>(in);
}

template <>
hep::vegas_chkpt_with_rng<hep::stream_rng, double> make_chkpt<hep::vegas_chkpt<double>>(std::istream& in)
{
return hep::make_vegas_chkpt<double, hep::stream_rng>(in);
}

template <>
hep::vegas_chkpt_with_rng<hep::stream_rng, long double> make_chkpt<hep::vegas_chkpt<long double>>(std::istream& in)
{
return hep::make_vegas_chkpt<long double, hep::stream_rng>(in);
}

template <>
hep::multi_channel_chkpt_with_rng<hep::stream_rng, float> make_chkpt<hep::multi_channel_chkpt<float>>(std::istream& in)
{
return hep::make_multi_channel_chkpt<float, hep::stream_rng>(in);
}

template <>
hep::multi_channel_chkpt_with_rng<hep::stream_rng, double> make_chkpt<hep::multi_channel_chkpt<double>>(std::istream& in)
{
return hep::make_multi_channel_chkpt<double, hep::stream_rng>(in);
}

template <>
hep::multi_channel_chkpt_with_rng<hep::stream_rng, long double> make_chkpt<hep::multi_channel_chkpt<long double>>(std::istream& in)
{
return hep::make_multi_channel_chkpt<long double, hep::stream_rng>(in);
}

}

#endif
8 changes: 8 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
chkpt_srcs = [
'chkpt.cpp',
'operations.cpp',
'read_type.cpp',
'stream_rng.cpp',
]

executable('chkpt', chkpt_srcs, dependencies : hep_mc_dep)
Loading