R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
GeneratorFactoryJson.h
Go to the documentation of this file.
1#pragma once
2
5#include <R3BROOTTypeJson.h> // NOLINT
6#include <magic_enum/magic_enum.hpp>
7#include <nlohmann/json.hpp>
8#include <nlohmann/json_fwd.hpp>
9#include <string>
10
11namespace R3B::Neuland
12{
13 template <>
14 inline void to_json(nlohmann::ordered_json& json_obj, const GeneratorFactory::Options& options)
15 {
16 json_obj = nlohmann::ordered_json{
17 { "type", magic_enum::enum_name(options.generator_type) },
18 { "particle", options.particle_type },
19 { "multiplicity", options.multiplicity },
20 { "energy", options.energy },
21 { "theta", options.theta },
22 { "phi", options.phi },
23 { "position", options.position },
24 };
25 }
26
27 template <>
28 inline void from_json(const nlohmann::ordered_json& json_obj, GeneratorFactory::Options& options)
29 {
30 auto type_str = std::string{};
31 json_obj.at("type").get_to(type_str);
32 json_obj.at("particle").get_to(options.particle_type);
33 json_obj.at("multiplicity").get_to(options.multiplicity);
34 json_obj.at("energy").get_to(options.energy);
35 json_obj.at("theta").get_to(options.theta);
36 json_obj.at("phi").get_to(options.phi);
37 json_obj.at("position").get_to(options.position);
38 auto type_str_val = magic_enum::enum_cast<GeneratorType>(type_str, magic_enum::case_insensitive);
39 if (type_str_val.has_value())
40 {
41 options.generator_type = type_str_val.value();
42 }
43 }
44} // namespace R3B::Neuland
Simulation of NeuLAND Bar/Paddle.
void from_json(const nlohmann::ordered_json &json_obj, GeneratorFactory::Options &options)
void to_json(nlohmann::ordered_json &json_obj, const GeneratorFactory::Options &options)
MinMaxValueD theta
Theta min and max value for outgoing direction.
MinMaxValueD phi
Phi min and max value for outgoing direction.
ROOT::Math::XYZVectorD position
Location of particle generation.
ValueErrorD energy
energy value with error [MeV]