19 #include <momemta/ConfigurationReader.h> 20 #include <momemta/MoMEMta.h> 21 #include <momemta/Types.h> 22 #include <momemta/Utils.h> 24 #include "phaseSpaceGenerationTests.h" 32 void PSGenerationTestManager::registerTest(
PSGenerationTest test,
char mainBlock,
char secondaryBlock) {
33 assert(test.particle_names.size() == test.particle_masses.size());
35 if (secondaryBlock ==
'\0')
36 mainBlocks.emplace(mainBlock, test);
38 secondaryBlocks.emplace(std::make_pair(mainBlock, secondaryBlock), test);
41 void PSGenerationTestManager::parseArgs(
int argc,
char** argv) {
44 throw std::invalid_argument(
"Expected at least one argument!");
47 for (
int i = 1; i < argc; i++) {
48 std::string arg(argv[i]);
50 if (arg ==
"-h" || arg ==
"--help") {
55 if (arg.length() == 1)
57 else if (arg.length() == 2)
58 runTest(arg[0], arg[1]);
61 throw std::invalid_argument(
"Each argument has to be one or two characters!");
66 void PSGenerationTestManager::printHelpMessage() {
67 LOG(info) <<
"Usage: X[Y] [X[Y] ...]";
68 LOG(info) <<
"\t where X and Y are characters indicating which main [optionally in combination with a secondary] block is requested.";
69 LOG(info) <<
"Available block combinations:";
70 LOG(info) <<
"\tMain Blocks:";
71 for (
auto it: mainBlocks)
72 LOG(info) <<
"\t\t" << it.first;
73 LOG(info) <<
"\tMain Blocks with Secondary Blocks:";
74 for (
auto it: secondaryBlocks)
75 LOG(info) <<
"\t\t" << it.first.first <<
" (main) combined with " << it.first.second <<
" (secondary)";
78 void PSGenerationTestManager::runTest(
char mainBlock,
char secondaryBlock) {
79 if (secondaryBlock ==
'\0') {
80 LOG(debug) <<
"Attempting to run test for Main Block " << mainBlock;
81 auto it = mainBlocks.find(mainBlock);
82 if (it == mainBlocks.end()) {
84 throw std::invalid_argument(
"Could not find test for main block!");
88 LOG(debug) <<
"Attempting to run test for combination of Main Block " << mainBlock <<
" and Secondary Block " << secondaryBlock;
89 auto it = secondaryBlocks.find(std::make_pair(mainBlock, secondaryBlock));
90 if (it == secondaryBlocks.end()) {
92 throw std::invalid_argument(
"Could not find test for main and secondary block combination!");
100 MoMEMta weight(configuration.freeze());
102 std::vector<Particle> particles;
103 for (std::size_t i = 0; i < test.particle_names.size(); i++)
104 particles.push_back(
Particle(test.particle_names[i], getRandom4Vector(100, test.particle_masses[i]), 0));
106 auto start_time = system_clock::now();
107 std::vector<std::pair<double, double>> weights = weight.computeWeights(particles);
108 auto end_time = system_clock::now();
110 LOG(info) <<
"Result: " << weights.back().first <<
" +- " << weights.back().second;
111 LOG(info) <<
"Target value: " << test.target_value;
112 LOG(info) <<
"Ratio: " << std::fixed << std::setprecision(4) << weights.back().first / test.target_value <<
" +- " << weights.back().second / test.target_value;
114 LOG(info) <<
"Weight computed in " << std::chrono::duration_cast<milliseconds>(end_time - start_time).count() <<
"ms";
A lua configuration file parser.
Describe a reco particle. Used as input of MoMEMta::computeWeights.