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 { "energy", options.energy },
20 { "theta", options.theta },
21 { "phi", options.phi },
22 { "position", options.position },
23 };
24 }
25
26 template <>
27 inline void from_json(const nlohmann::ordered_json& json_obj, GeneratorFactory::Options& options)
28 {
29 auto type_str = std::string{};
30 json_obj.at("type").get_to(type_str);
31 json_obj.at("particle").get_to(options.particle_type);
32 json_obj.at("energy").get_to(options.energy);
33 json_obj.at("theta").get_to(options.theta);
34 json_obj.at("phi").get_to(options.phi);
35 json_obj.at("position").get_to(options.position);
36 auto type_str_val = magic_enum::enum_cast<GeneratorType>(type_str, magic_enum::case_insensitive);
37 if (type_str_val.has_value())
38 {
39 options.generator_type = type_str_val.value();
40 }
41 }
42} // 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]