R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
R3BNeulandAppOptionJson.cxx
Go to the documentation of this file.
2#include "JsonParse/GeneratorFactoryJson.h" // IWYU pragma: keep
3#include "JsonParse/ParticleFilterJson.h" // IWYU pragma: keep
5#include "R3BException.h"
7#include "R3BNeulandApp.h"
10#include "R3BNeulandSimApp.h"
11#include <R3BROOTTypeJson.h> // IWYU pragma: keep
12#include <fmt/core.h>
13#include <fmt/ranges.h>
14#include <magic_enum/magic_enum.hpp>
15#include <nlohmann/json.hpp>
16#include <nlohmann/json_fwd.hpp>
17#include <string>
18#include <string_view>
19
20using json = nlohmann::ordered_json;
21
22namespace
23{
24 template <typename EnumType>
25 void set_enum_from_string(EnumType& enum_obj, const json& json_obj, std::string_view name)
26 {
27 auto enum_str = std::string{};
28 json_obj.at(name.data()).get_to(enum_str);
29 auto enum_val = magic_enum::enum_cast<EnumType>(enum_str, magic_enum::case_insensitive);
30 if (enum_val.has_value())
31 {
32 enum_obj = enum_val.value();
33 return;
34 }
35 constexpr auto enum_all_names = magic_enum::enum_names<EnumType>();
36 throw R3B::logic_error(fmt::format("{:?} cannot be parsed to its enum class! Available options: {}",
37 enum_str,
38 fmt::join(enum_all_names, ", ")));
39 }
40
41} // namespace
42
44{
45 void to_json(json& json_obj, const Params& param)
46 {
47 json_obj =
48 json{ { "fPMTThresh", param.pmt_thresh },
49 { "fSaturationCoefficient", param.saturation_coefficient },
50 { "fExperimentalDataIsCorrectedForSaturation", param.experimental_data_is_corrected_for_saturation },
51 { "fTimeRes", param.time_res },
52 { "fEResRel", param.energy_res_rel },
53 { "fEnergyGain", param.energy_gain },
54 { "fPedestal", param.pedestal },
55 { "fTimeMax", param.max_time },
56 { "fTimeMin", param.min_time },
57 { "fPileUpTimeWindow", param.pileup_time_window },
58 { "fPileUpDistance", param.pileup_distance },
59 { "fQdcMin", param.min_energy } };
60 }
61
62 void from_json(const json& json_obj, Params& param)
63 {
64 json_obj.at("fPMTThresh").get_to(param.pmt_thresh);
65 json_obj.at("fSaturationCoefficient").get_to(param.saturation_coefficient);
66 json_obj.at("fExperimentalDataIsCorrectedForSaturation")
68 json_obj.at("fTimeRes").get_to(param.time_res);
69 json_obj.at("fEResRel").get_to(param.energy_res_rel);
70 json_obj.at("fEnergyGain").get_to(param.energy_gain);
71 json_obj.at("fPedestal").get_to(param.pedestal);
72 json_obj.at("fTimeMax").get_to(param.max_time);
73 json_obj.at("fTimeMin").get_to(param.min_time);
74 json_obj.at("fPileUpTimeWindow").get_to(param.pileup_time_window);
75 json_obj.at("fPileUpDistance").get_to(param.pileup_distance);
76 json_obj.at("fQdcMin").get_to(param.min_energy);
77 }
78
79} // namespace R3B::Digitizing::Neuland::Tamex
80namespace R3B::Neuland
81{
82 template <>
83 void to_json(nlohmann::ordered_json& json_obj, const MinimizerLimVar& option)
84 {
85 json_obj = nlohmann::ordered_json{
86 { "init", option.init }, { "step", option.step }, { "lower", option.lower }, { "upper", option.upper }
87 };
88 }
89
90 template <>
91 void from_json(const nlohmann::ordered_json& json_obj, MinimizerLimVar& option)
92 {
93 json_obj.at("init").get_to(option.init);
94 json_obj.at("step").get_to(option.step);
95 json_obj.at("lower").get_to(option.lower);
96 json_obj.at("upper").get_to(option.upper);
97 }
98
99 // =============================================================================================
100 // general options:
101 template <>
102 void to_json(nlohmann::ordered_json& json_obj, const CLIApplication::Options& option)
103 {
104 json_obj = nlohmann::ordered_json{
105 { "run-id", option.run_id },
106 { "number-of-events", option.event_num },
107 { "enable-mpi", option.enable_mpi },
108 { "log-level", option.log_level },
109 { "verbose-level", option.verbose_level },
110 { "input", option.input },
111 { "output", option.output },
112 };
113 }
114
115 template <>
116 void from_json(const nlohmann::ordered_json& json_obj, CLIApplication::Options& option)
117 {
118 json_obj.at("run-id").get_to(option.run_id);
119 json_obj.at("number-of-events").get_to(option.event_num);
120 json_obj.at("enable-mpi").get_to(option.enable_mpi);
121 json_obj.at("log-level").get_to(option.log_level);
122 json_obj.at("verbose-level").get_to(option.verbose_level);
123 json_obj.at("input").get_to(option.input);
124 json_obj.at("output").get_to(option.output);
125 }
126
127 template <>
128 void to_json(nlohmann::ordered_json& json_obj, const CLIApplication::Options::Input& option)
129 {
130 json_obj = nlohmann::ordered_json{
131 { "working-dir", option.working_dir },
132 { "data", option.data },
133 { "tree-data", option.tree_data },
134 { "first-par", option.par },
135 };
136 }
137
138 template <>
139 void from_json(const nlohmann::ordered_json& json_obj, CLIApplication::Options::Input& option)
140 {
141 json_obj.at("working-dir").get_to(option.working_dir);
142 json_obj.at("data").get_to(option.data);
143 json_obj.at("tree-data").get_to(option.tree_data);
144 json_obj.at("first-par").get_to(option.par);
145 }
146
147 template <>
148 void to_json(nlohmann::ordered_json& json_obj, const CLIApplication::Options::Output& option)
149 {
150 json_obj = nlohmann::ordered_json{
151 { "working-dir", option.working_dir },
152 { "data", option.data },
153 { "par", option.par },
154 { "mode", option.mode },
155 };
156 }
157
158 template <>
159 void from_json(const nlohmann::ordered_json& json_obj, CLIApplication::Options::Output& option)
160 {
161 json_obj.at("working-dir").get_to(option.working_dir);
162 json_obj.at("data").get_to(option.data);
163 json_obj.at("par").get_to(option.par);
164 json_obj.at("mode").get_to(option.mode);
165 }
166
167 // =============================================================================================
168 // Analysis tasks specialization:
169 template <>
170 void to_json(json& json_obj, const R3B::Neuland::DigiTaskOptions& option)
171 {
172 json_obj = json{
173 { "enable", option.enable },
174 { "channel", option.channel },
175 { "paddle", option.paddle },
176 { "point-filter", option.point_filter },
177 { "par", option.tamex_par },
178 { "pileup-strategy", magic_enum::enum_name(option.pileup_strategy) },
179 { "enable-sim-cal", option.enable_sim_cal },
180 { "enable-hit-par", option.enable_hit_par },
181 { "enable-size-monitor", option.enable_size_monitor },
182 { "read", option.read },
183 { "write", option.write },
184 };
185 }
186
187 template <>
188 void from_json(const json& json_obj, R3B::Neuland::DigiTaskOptions& option)
189 {
190 json_obj.at("enable").get_to(option.enable);
191 json_obj.at("channel").get_to(option.channel);
192 json_obj.at("paddle").get_to(option.paddle);
193 json_obj.at("par").get_to(option.tamex_par);
194 json_obj.at("enable-sim-cal").get_to(option.enable_sim_cal);
195 json_obj.at("enable-hit-par").get_to(option.enable_hit_par);
196 json_obj.at("enable-size-monitor").get_to(option.enable_size_monitor);
197 json_obj.at("read").get_to(option.read);
198 json_obj.at("write").get_to(option.write);
199 json_obj.at("point-filter").get_to(option.point_filter);
200 set_enum_from_string(option.pileup_strategy, json_obj, "pileup-strategy");
201 }
202
203 template <>
204 void to_json(json& json_obj, const AnalysisApplication::Options::Tasks::MultiTrain& option)
205 {
206 json_obj = json{
207 { "enable", option.enable },
208 { "use-hit", option.use_hit },
209 { "weight", option.weight },
210 { "edep-opt", option.edep_opt },
211 { "edep-off-opt", option.edep_off_opt },
212 { "n-cluster-opt", option.n_cluster_opt },
213 { "n-cluster-off-opt", option.n_cluster_off_opt },
214 { "read", option.read },
215 { "write", option.write },
216 };
217 }
218
219 template <>
220 void from_json(const json& json_obj, AnalysisApplication::Options::Tasks::MultiTrain& option)
221 {
222 json_obj.at("enable").get_to(option.enable);
223 json_obj.at("use-hit").get_to(option.use_hit);
224 json_obj.at("weight").get_to(option.weight);
225 json_obj.at("edep-opt").get_to(option.edep_opt);
226 json_obj.at("edep-off-opt").get_to(option.edep_off_opt);
227 json_obj.at("n-cluster-opt").get_to(option.n_cluster_opt);
228 json_obj.at("n-cluster-off-opt").get_to(option.n_cluster_off_opt);
229 json_obj.at("read").get_to(option.read);
230 json_obj.at("write").get_to(option.write);
231 }
232
233 template <>
234 void to_json(json& json_obj, const AnalysisApplication::Options::Tasks::NeutronRValue& option)
235 {
236 json_obj = json{
237 { "enable", option.enable },
238 { "neutron-energy-MeV", option.neutron_energy_mev },
239 { "read", option.read },
240 { "write", option.write },
241 };
242 }
243
244 template <>
245 void from_json(const json& json_obj, AnalysisApplication::Options::Tasks::NeutronRValue& option)
246 {
247 json_obj.at("enable").get_to(option.enable);
248 json_obj.at("neutron-energy-MeV").get_to(option.neutron_energy_mev);
249 json_obj.at("read").get_to(option.read);
250 json_obj.at("write").get_to(option.write);
251 }
252
253 template <>
254 void to_json(json& json_obj, const AnalysisApplication::Options::Tasks::Cal2HitParTask& option)
255 {
256 json_obj = json{
257 { "enable", option.enable },
258 { "min-stat", option.min_stat },
259 { "mode", magic_enum::enum_name(option.mode) },
260 { "method", magic_enum::enum_name(option.method) },
261 { "read", option.read },
262 { "write", option.write },
263 };
264 }
265
266 template <>
267 void from_json(const json& json_obj, AnalysisApplication::Options::Tasks::Cal2HitParTask& option)
268 {
269 json_obj.at("enable").get_to(option.enable);
270 json_obj.at("min-stat").get_to(option.min_stat);
271 json_obj.at("read").get_to(option.read);
272 json_obj.at("write").get_to(option.write);
273 set_enum_from_string(option.method, json_obj, "method");
274 set_enum_from_string(option.mode, json_obj, "mode");
275 }
276
277 template <>
278 void to_json(json& json_obj, const AnalysisApplication::Options::Tasks::Map2CalParTask& option)
279 {
280 json_obj = json{
281 { "enable", option.enable },
282 { "has-trig-enabled", option.has_trig_enabled },
283 { "error-method", magic_enum::enum_name(option.error_method) },
284 { "read", option.read },
285 { "write", option.write },
286 };
287 }
288
289 template <>
290 void from_json(const json& json_obj, AnalysisApplication::Options::Tasks::Map2CalParTask& option)
291 {
292 json_obj.at("enable").get_to(option.enable);
293 json_obj.at("has-trig-enabled").get_to(option.has_trig_enabled);
294 set_enum_from_string(option.error_method, json_obj, "error-method");
295 json_obj.at("read").get_to(option.read);
296 json_obj.at("write").get_to(option.write);
297 }
298
299 template <>
300 void to_json(json& json_obj, const AnalysisApplication::Options::Tasks::Map2CalTask& option)
301 {
302 json_obj = json{
303 { "enable", option.enable },
304 { "enable-pulse-mode", option.enable_pulse_mode },
305 { "enable-walk-effect", option.enable_walk_effect },
306 { "min-stat", option.min_stat },
307 { "read", option.read },
308 { "write", option.write },
309 };
310 }
311
312 template <>
313 void from_json(const json& json_obj, AnalysisApplication::Options::Tasks::Map2CalTask& option)
314 {
315 json_obj.at("enable").get_to(option.enable);
316 json_obj.at("enable-pulse-mode").get_to(option.enable_pulse_mode);
317 json_obj.at("enable-walk-effect").get_to(option.enable_walk_effect);
318 json_obj.at("min-stat").get_to(option.min_stat);
319 json_obj.at("read").get_to(option.read);
320 json_obj.at("write").get_to(option.write);
321 }
322
323 template <>
324 void to_json(json& json_obj, const AnalysisApplication::Options::Tasks::Cal2HitTask& option)
325 {
326 json_obj = json{
327 { "enable", option.enable },
328 { "mode", magic_enum::enum_name(option.mode) },
329 { "global-time-offset", option.global_time_offset },
330 { "read", option.read },
331 { "write", option.write },
332 };
333 }
334
335 template <>
336 void from_json(const json& json_obj, AnalysisApplication::Options::Tasks::Cal2HitTask& option)
337 {
338 json_obj.at("enable").get_to(option.enable);
339 json_obj.at("global-time-offset").get_to(option.global_time_offset);
340 json_obj.at("read").get_to(option.read);
341 json_obj.at("write").get_to(option.write);
342 set_enum_from_string(option.mode, json_obj, "mode");
343 }
344 // =============================================================================================
345 // Anaysis general options:
346 template <>
347 void to_json(json& json_obj, const AnalysisApplication::Options::Tasks& option)
348 {
349 json_obj = json{
350 { option.digi.name, option.digi },
351 { option.sim_cal_to_cal.name, option.sim_cal_to_cal },
352 { option.hit_monitor.name, option.hit_monitor },
353 { option.prim_inter_finder.name, option.prim_inter_finder },
354 { option.cluster_finder.name, option.cluster_finder },
357 { option.multi_bayes_train.name, option.multi_bayes_train },
358 { option.multi_bayes.name, option.multi_bayes },
359 { option.neutron_r_value.name, option.neutron_r_value },
362 { option.map_to_cal_task.name, option.map_to_cal_task },
367 { option.cal_to_hit_task.name, option.cal_to_hit_task },
368 };
369 }
370
371 template <>
373 {
374 json_obj.at(option.digi.name).get_to(option.digi);
375 json_obj.at(option.hit_monitor.name).get_to(option.hit_monitor);
376 json_obj.at(option.prim_inter_finder.name).get_to(option.prim_inter_finder);
377 json_obj.at(option.cluster_finder.name).get_to(option.cluster_finder);
378 json_obj.at(option.prim_cluster_finder.name).get_to(option.prim_cluster_finder);
379 json_obj.at(option.multi_calorimeter_train.name).get_to(option.multi_calorimeter_train);
380 json_obj.at(option.multi_bayes_train.name).get_to(option.multi_bayes_train);
381 json_obj.at(option.multi_bayes.name).get_to(option.multi_bayes);
382 json_obj.at(option.neutron_r_value.name).get_to(option.neutron_r_value);
383 json_obj.at(option.sim_cal_to_cal.name).get_to(option.sim_cal_to_cal);
384 json_obj.at(option.map_to_cal_par_task.name).get_to(option.map_to_cal_par_task);
385 json_obj.at(option.map_data_converter_task.name).get_to(option.map_data_converter_task);
386 json_obj.at(option.map_to_cal_task.name).get_to(option.map_to_cal_task);
387 json_obj.at(option.cal_to_hit_par_task.name).get_to(option.cal_to_hit_par_task);
388 json_obj.at(option.los_map_to_cal_task.name).get_to(option.los_map_to_cal_task);
389 json_obj.at(option.los_map_to_cal_par_task.name).get_to(option.los_map_to_cal_par_task);
390 json_obj.at(option.los_provide_t_start.name).get_to(option.los_provide_t_start);
391 json_obj.at(option.cal_to_hit_task.name).get_to(option.cal_to_hit_task);
392 }
393
394 template <>
395 void to_json(json& json_obj, const AnalysisApplication::Options& option)
396 {
397 json_obj = json{ { "general", option.general }, { "tasks", option.tasks } };
398 }
399
400 template <>
401 void from_json(const json& json_obj, AnalysisApplication::Options& option)
402 {
403 json_obj.at("general").get_to(option.general);
404 json_obj.at("tasks").get_to(option.tasks);
405 }
406 // =============================================================================================
407 // Simuation options:
408 template <>
409 void to_json(nlohmann::ordered_json& json_obj, const SimulationApplication::Options& option)
410 {
411 json_obj = json{ { "general", option.general },
412 { "simulation", option.simulation },
413 { "detectors", option.detectors } };
414 }
415
416 template <>
417 void from_json(const nlohmann::ordered_json& json_obj, SimulationApplication::Options& option)
418 {
419 json_obj.at("general").get_to(option.general);
420 json_obj.at("simulation").get_to(option.simulation);
421 json_obj.at("detectors").get_to(option.detectors);
422 }
423
424 template <>
425 void to_json(nlohmann::ordered_json& json_obj, const SimulationApplication::Options::Simulation& option)
426 {
427 json_obj = json{
428 { "event-print-num", option.event_print_num },
429 { "store-trajectory", option.store_trajectory },
430 { "material-filename", option.material_filename },
431 { "engine", option.engine },
432 { "random-seed", option.random_seed },
433 { "generator", option.generator },
434 };
435 }
436
437 template <>
438 void from_json(const nlohmann::ordered_json& json_obj, SimulationApplication::Options::Simulation& option)
439 {
440 json_obj.at("event-print-num").get_to(option.event_print_num);
441 json_obj.at("store-trajectory").get_to(option.store_trajectory);
442 json_obj.at("material-filename").get_to(option.material_filename);
443 json_obj.at("engine").get_to(option.engine);
444 json_obj.at("generator").get_to(option.generator);
445 }
446
447 template <>
448 void to_json(nlohmann::ordered_json& json_obj, const SimulationApplication::Options::Detector& option)
449 {
450 json_obj = json{ { "cave", option.cave }, { "neuland", option.neuland } };
451 }
452
453 template <>
454 void from_json(const nlohmann::ordered_json& json_obj, SimulationApplication::Options::Detector& option)
455 {
456 json_obj.at("cave").get_to(option.cave);
457 json_obj.at("neuland").get_to(option.neuland);
458 }
459
460 // =============================================================================================
461 // Detector options:
462
463 template <>
464 void to_json(nlohmann::ordered_json& json_obj, const SimulationApplication::Options::Detector::Cave& option)
465 {
466 json_obj = json{ { "enable", option.enable }, { "name", option.name }, { "geo-file", option.geo_file } };
467 }
468
469 template <>
470 void from_json(const nlohmann::ordered_json& json_obj, SimulationApplication::Options::Detector::Cave& option)
471 {
472 json_obj.at("enable").get_to(option.enable);
473 json_obj.at("name").get_to(option.name);
474 json_obj.at("geo-file").get_to(option.geo_file);
475 }
476
477 template <>
478 void to_json(nlohmann::ordered_json& json_obj, const SimulationApplication::Options::Detector::Neuland& option)
479 {
480 json_obj = json{ { "enable", option.enable },
481 { "name", option.name },
482 { "num-of-dp", option.num_of_dp },
483 { "location", option.location },
484 { "enable-auto-geo-build", option.enable_auto_geo_build } };
485 }
486
487 template <>
488 void from_json(const nlohmann::ordered_json& json_obj, SimulationApplication::Options::Detector::Neuland& option)
489 {
490 json_obj.at("enable").get_to(option.enable);
491 json_obj.at("name").get_to(option.name);
492 json_obj.at("num-of-dp").get_to(option.num_of_dp);
493 json_obj.at("location").get_to(option.location);
494 json_obj.at("enable-auto-geo-build").get_to(option.enable_auto_geo_build);
495 }
496} // namespace R3B::Neuland
void from_json(const json &json_obj, Params &param)
void to_json(json &json_obj, const Params &param)
Simulation of NeuLAND Bar/Paddle.
void from_json(const nlohmann::ordered_json &json_obj, GeneratorFactory::Options &options)
nlohmann::ordered_json json
void to_json(nlohmann::ordered_json &json_obj, const GeneratorFactory::Options &options)
double energy_res_rel
Gaus(e, fEResRel * e) [].
double time_res
time + Gaus(0., fTimeRes) [ns]
double min_energy
minimal energy of a FQT peak [MeV]
double saturation_coefficient
Saturation coefficient of PMTs.
double pedestal
Energy offset parameter [ns].
bool experimental_data_is_corrected_for_saturation
Flag if saturation effect enabled.
struct R3B::Neuland::AnalysisApplication::Options::Tasks::Cal2HitTask cal_to_hit_task
struct R3B::Neuland::AnalysisApplication::Options::Tasks::LosProvideTStart los_provide_t_start
struct R3B::Neuland::AnalysisApplication::Options::Tasks::LosMap2CalParTask los_map_to_cal_par_task
struct R3B::Neuland::AnalysisApplication::Options::Tasks::HitMon hit_monitor
struct R3B::Neuland::AnalysisApplication::Options::Tasks::LosMap2CalTask los_map_to_cal_task
struct R3B::Neuland::AnalysisApplication::Options::Tasks::SimCal2Cal sim_cal_to_cal
struct R3B::Neuland::AnalysisApplication::Options::Tasks::Map2CalTask map_to_cal_task
struct R3B::Neuland::AnalysisApplication::Options::Tasks::PrimInteractionFinder prim_inter_finder
struct R3B::Neuland::AnalysisApplication::Options::Tasks::NeutronRValue neutron_r_value
struct R3B::Neuland::AnalysisApplication::Options::Tasks::Map2CalParTask map_to_cal_par_task
struct R3B::Neuland::AnalysisApplication::Options::Tasks::MapDataConverterTask map_data_converter_task
struct R3B::Neuland::AnalysisApplication::Options::Tasks::ClusterFinder cluster_finder
struct R3B::Neuland::AnalysisApplication::Options::Tasks::PrimClusterFinder prim_cluster_finder
struct R3B::Neuland::AnalysisApplication::Options::Tasks::MultiBayes multi_bayes
struct R3B::Neuland::AnalysisApplication::Options::Tasks::MultiBayesTrain multi_bayes_train
struct R3B::Neuland::AnalysisApplication::Options::Tasks::Cal2HitParTask cal_to_hit_par_task
struct R3B::Neuland::AnalysisApplication::Options::Tasks::MultiTrain multi_calorimeter_train
struct R3B::Neuland::AnalysisApplication::Options::Tasks tasks
struct R3B::Neuland::CLIApplication::Options::Input input
struct R3B::Neuland::CLIApplication::Options::Output output
Configuration struct for R3B::Neuland::Digitizer used in R3B::Neuland::AnalysisApplication.
std::string channel
Channel name used in the task.
Digitizing::Neuland::Tamex::PeakPileUpStrategy pileup_strategy
bool enable_sim_cal
Flag to enable the simulated cal level data output.
bool enable_hit_par
Flag to enable the usage of cal_to_hit parameter.
std::string read
Input data names required by the digitizer.
bool enable_size_monitor
Flag to enable the checking of hit/signal sizes in histograms.
std::string paddle
Paddle name used in the task.
bool enable
Flag to enable task.
ParticleFilter::Options point_filter
Point level filter options used in the digitizer.
R3B::Digitizing::Neuland::Tamex::Params tamex_par
std::string write
Output data names from the digitizer.
std::string name
Name of the task.
struct R3B::Neuland::SimulationApplication::Options::Simulation simulation
struct R3B::Neuland::SimulationApplication::Options::Detector detectors