R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
R3BNeulandAppOptionJson.cxx
Go to the documentation of this file.
2#include "JsonParse/GeneratorFactoryJson.h" // NOLINT
3#include "JsonParse/ParticleFilterJson.h" //NOLINT
5#include "R3BException.h"
7#include "R3BNeulandApp.h"
11#include "R3BNeulandSimApp.h"
12#include <R3BROOTTypeJson.h> //NOLINT
13#include <fmt/core.h>
14#include <magic_enum/magic_enum.hpp>
15#include <nlohmann/json.hpp>
16#include <nlohmann/json_fwd.hpp>
17#include <string>
18
19using json = nlohmann::ordered_json;
20
22{
23 void to_json(json& json_obj, const Params& param)
24 {
25 json_obj =
26 json{ { "fPMTThresh", param.pmt_thresh },
27 { "fSaturationCoefficient", param.saturation_coefficient },
28 { "fExperimentalDataIsCorrectedForSaturation", param.experimental_data_is_corrected_for_saturation },
29 { "fTimeRes", param.time_res },
30 { "fEResRel", param.energy_res_rel },
31 { "fEnergyGain", param.energy_gain },
32 { "fPedestal", param.pedestal },
33 { "fTimeMax", param.max_time },
34 { "fTimeMin", param.min_time },
35 { "fPileUpTimeWindow", param.pileup_time_window },
36 { "fPileUpDistance", param.pileup_distance },
37 { "fQdcMin", param.min_energy } };
38 }
39
40 void from_json(const json& json_obj, Params& param)
41 {
42 json_obj.at("fPMTThresh").get_to(param.pmt_thresh);
43 json_obj.at("fSaturationCoefficient").get_to(param.saturation_coefficient);
44 json_obj.at("fExperimentalDataIsCorrectedForSaturation")
46 json_obj.at("fTimeRes").get_to(param.time_res);
47 json_obj.at("fEResRel").get_to(param.energy_res_rel);
48 json_obj.at("fEnergyGain").get_to(param.energy_gain);
49 json_obj.at("fPedestal").get_to(param.pedestal);
50 json_obj.at("fTimeMax").get_to(param.max_time);
51 json_obj.at("fTimeMin").get_to(param.min_time);
52 json_obj.at("fPileUpTimeWindow").get_to(param.pileup_time_window);
53 json_obj.at("fPileUpDistance").get_to(param.pileup_distance);
54 json_obj.at("fQdcMin").get_to(param.min_energy);
55 }
56
57} // namespace R3B::Digitizing::Neuland::Tamex
58namespace R3B::Neuland
59{
60 template <>
61 void to_json(nlohmann::ordered_json& json_obj, const MinimizerLimVar& option)
62 {
63 json_obj = nlohmann::ordered_json{
64 { "init", option.init }, { "step", option.step }, { "lower", option.lower }, { "upper", option.upper }
65 };
66 }
67
68 template <>
69 void from_json(const nlohmann::ordered_json& json_obj, MinimizerLimVar& option)
70 {
71 json_obj.at("init").get_to(option.init);
72 json_obj.at("step").get_to(option.step);
73 json_obj.at("lower").get_to(option.lower);
74 json_obj.at("upper").get_to(option.upper);
75 }
76
77 // =============================================================================================
78 // general options:
79 template <>
80 void to_json(nlohmann::ordered_json& json_obj, const CLIApplication::Options& option)
81 {
82 json_obj = nlohmann::ordered_json{
83 { "run-id", option.run_id },
84 { "number-of-events", option.event_num },
85 { "enable-mpi", option.enable_mpi },
86 { "log-level", option.log_level },
87 { "verbose-level", option.verbose_level },
88 { "input", option.input },
89 { "output", option.output },
90 };
91 }
92
93 template <>
94 void from_json(const nlohmann::ordered_json& json_obj, CLIApplication::Options& option)
95 {
96 json_obj.at("run-id").get_to(option.run_id);
97 json_obj.at("number-of-events").get_to(option.event_num);
98 json_obj.at("enable-mpi").get_to(option.enable_mpi);
99 json_obj.at("log-level").get_to(option.log_level);
100 json_obj.at("verbose-level").get_to(option.verbose_level);
101 json_obj.at("input").get_to(option.input);
102 json_obj.at("output").get_to(option.output);
103 }
104
105 template <>
106 void to_json(nlohmann::ordered_json& json_obj, const CLIApplication::Options::Input& option)
107 {
108 json_obj = nlohmann::ordered_json{
109 { "working-dir", option.working_dir }, { "data", option.data }, { "tree-data", option.tree_data },
110 { "first-par", option.par }, { "second-par", option.par_2 },
111 };
112 }
113
114 template <>
115 void from_json(const nlohmann::ordered_json& json_obj, CLIApplication::Options::Input& option)
116 {
117 json_obj.at("working-dir").get_to(option.working_dir);
118 json_obj.at("data").get_to(option.data);
119 json_obj.at("tree-data").get_to(option.tree_data);
120 json_obj.at("first-par").get_to(option.par);
121 json_obj.at("second-par").get_to(option.par_2);
122 }
123
124 template <>
125 void to_json(nlohmann::ordered_json& json_obj, const CLIApplication::Options::Output& option)
126 {
127 json_obj = nlohmann::ordered_json{
128 { "working-dir", option.working_dir },
129 { "data", option.data },
130 { "par", option.par },
131 };
132 }
133
134 template <>
135 void from_json(const nlohmann::ordered_json& json_obj, CLIApplication::Options::Output& option)
136 {
137 json_obj.at("working-dir").get_to(option.working_dir);
138 json_obj.at("data").get_to(option.data);
139 json_obj.at("par").get_to(option.par);
140 }
141
142 // =============================================================================================
143 // Anaysis options:
144 template <>
145 void to_json(json& json_obj, const AnalysisApplication::Options& option)
146 {
147 json_obj = json{ { "general", option.general }, { "tasks", option.tasks } };
148 }
149
150 template <>
151 void from_json(const json& json_obj, AnalysisApplication::Options& option)
152 {
153 json_obj.at("general").get_to(option.general);
154 json_obj.at("tasks").get_to(option.tasks);
155 }
156
157 template <>
158 void to_json(json& json_obj, const AnalysisApplication::Options::Tasks& option)
159 {
160 json_obj = json{
161 { option.digi.name, option.digi },
162 { option.sim_cal_to_cal.name, option.sim_cal_to_cal },
163 { option.hit_monitor.name, option.hit_monitor },
164 { option.prim_inter_finder.name, option.prim_inter_finder },
165 { option.cluster_finder.name, option.cluster_finder },
168 { option.multi_bayes_train.name, option.multi_bayes_train },
169 { option.multi_bayes.name, option.multi_bayes },
170 { option.neutron_r_value.name, option.neutron_r_value },
172 };
173 }
174
175 template <>
177 {
178 json_obj.at(option.digi.name).get_to(option.digi);
179 json_obj.at(option.hit_monitor.name).get_to(option.hit_monitor);
180 json_obj.at(option.prim_inter_finder.name).get_to(option.prim_inter_finder);
181 json_obj.at(option.cluster_finder.name).get_to(option.cluster_finder);
182 json_obj.at(option.prim_cluster_finder.name).get_to(option.prim_cluster_finder);
183 json_obj.at(option.multi_calorimeter_train.name).get_to(option.multi_calorimeter_train);
184 json_obj.at(option.multi_bayes_train.name).get_to(option.multi_bayes_train);
185 json_obj.at(option.multi_bayes.name).get_to(option.multi_bayes);
186 json_obj.at(option.neutron_r_value.name).get_to(option.neutron_r_value);
187 json_obj.at(option.sim_cal_to_cal.name).get_to(option.sim_cal_to_cal);
188 json_obj.at(option.cal_to_hit_par_task.name).get_to(option.cal_to_hit_par_task);
189 }
190
191 // =============================================================================================
192 // tasks specialization:
193 template <>
194 void to_json(json& json_obj, const R3B::Neuland::DigiTaskOptions& option)
195 {
196 json_obj = json{
197 { "enable", option.enable },
198 { "channel", option.channel },
199 { "paddle", option.paddle },
200 { "point-filter", option.point_filter },
201 { "par", option.tamex_par },
202 { "pileup-strategy", magic_enum::enum_name(option.pileup_strategy) },
203 { "enable-sim-cal", option.enable_sim_cal },
204 { "enable-hit-par", option.enable_hit_par },
205 { "enable-size-monitor", option.enable_size_monitor },
206 { "read", option.read },
207 { "write", option.write },
208 };
209 }
210
211 template <>
212 void from_json(const json& json_obj, R3B::Neuland::DigiTaskOptions& option)
213 {
214 json_obj.at("enable").get_to(option.enable);
215 json_obj.at("channel").get_to(option.channel);
216 json_obj.at("paddle").get_to(option.paddle);
217 json_obj.at("par").get_to(option.tamex_par);
218 json_obj.at("enable-sim-cal").get_to(option.enable_sim_cal);
219 json_obj.at("enable-hit-par").get_to(option.enable_hit_par);
220 json_obj.at("enable-size-monitor").get_to(option.enable_size_monitor);
221 json_obj.at("read").get_to(option.read);
222 json_obj.at("write").get_to(option.write);
223 json_obj.at("point-filter").get_to(option.point_filter);
224
225 // parse enum string
226 auto enum_name = std::string{};
227 json_obj.at("pileup-strategy").get_to(enum_name);
228 auto enum_val = magic_enum::enum_cast<Digitizing::Neuland::Tamex::PeakPileUpStrategy>(
229 enum_name, magic_enum::case_insensitive);
230 if (enum_val.has_value())
231 {
232 option.pileup_strategy = enum_val.value();
233 }
234 else
235 {
236 throw R3B::logic_error(fmt::format("Cannot parse the enum string {:?} to PeakPileUpStrategy enum class. "
237 "Please check if the enum string is correct!",
238 enum_name));
239 }
240 }
241
242 template <>
243 void to_json(json& json_obj, const AnalysisApplication::Options::Tasks::MultiTrain& option)
244 {
245 json_obj = json{
246 { "enable", option.enable },
247 { "use-hit", option.use_hit },
248 { "weight", option.weight },
249 { "edep-opt", option.edep_opt },
250 { "edep-off-opt", option.edep_off_opt },
251 { "n-cluster-opt", option.n_cluster_opt },
252 { "n-cluster-off-opt", option.n_cluster_off_opt },
253 { "read", option.read },
254 { "write", option.write },
255 };
256 }
257
258 template <>
259 void from_json(const json& json_obj, AnalysisApplication::Options::Tasks::MultiTrain& option)
260 {
261 json_obj.at("enable").get_to(option.enable);
262 json_obj.at("use-hit").get_to(option.use_hit);
263 json_obj.at("weight").get_to(option.weight);
264 json_obj.at("edep-opt").get_to(option.edep_opt);
265 json_obj.at("edep-off-opt").get_to(option.edep_off_opt);
266 json_obj.at("n-cluster-opt").get_to(option.n_cluster_opt);
267 json_obj.at("n-cluster-off-opt").get_to(option.n_cluster_off_opt);
268 json_obj.at("read").get_to(option.read);
269 json_obj.at("write").get_to(option.write);
270 }
271
272 template <>
273 void to_json(json& json_obj, const AnalysisApplication::Options::Tasks::NeutronRValue& option)
274 {
275 json_obj = json{
276 { "enable", option.enable },
277 { "neutron-energy-MeV", option.neutron_energy_mev },
278 { "read", option.read },
279 { "write", option.write },
280 };
281 }
282
283 template <>
284 void from_json(const json& json_obj, AnalysisApplication::Options::Tasks::NeutronRValue& option)
285 {
286 json_obj.at("enable").get_to(option.enable);
287 json_obj.at("neutron-energy-MeV").get_to(option.neutron_energy_mev);
288 json_obj.at("read").get_to(option.read);
289 json_obj.at("write").get_to(option.write);
290 }
291
292 template <>
293 void to_json(json& json_obj, const AnalysisApplication::Options::Tasks::Cal2HitParTask& option)
294 {
295 json_obj = json{
296 { "enable", option.enable },
297 { "min-stat", option.min_stat },
298 { "method", magic_enum::enum_name(option.method) },
299 { "read", option.read },
300 { "write", option.write },
301 };
302 }
303
304 template <>
305 void from_json(const json& json_obj, AnalysisApplication::Options::Tasks::Cal2HitParTask& option)
306 {
307 json_obj.at("enable").get_to(option.enable);
308 json_obj.at("min-stat").get_to(option.min_stat);
309 json_obj.at("read").get_to(option.read);
310 json_obj.at("write").get_to(option.write);
311
312 auto method_str = std::string{};
313 json_obj.at("method").get_to(method_str);
314
315 auto enum_val = magic_enum::enum_cast<Cal2HitParMethod>(method_str, magic_enum::case_insensitive);
316 if (enum_val.has_value())
317 {
318 option.method = enum_val.value();
319 }
320 else
321 {
322 throw R3B::logic_error(fmt::format("{} cannot be parsed to the enum class Cal2HitParMethod!", method_str));
323 }
324 }
325
326 // =============================================================================================
327 // Simuation options:
328 template <>
329 void to_json(nlohmann::ordered_json& json_obj, const SimulationApplication::Options& option)
330 {
331 json_obj = json{ { "general", option.general },
332 { "simulation", option.simulation },
333 { "detectors", option.detectors } };
334 }
335
336 template <>
337 void from_json(const nlohmann::ordered_json& json_obj, SimulationApplication::Options& option)
338 {
339 json_obj.at("general").get_to(option.general);
340 json_obj.at("simulation").get_to(option.simulation);
341 json_obj.at("detectors").get_to(option.detectors);
342 }
343
344 template <>
345 void to_json(nlohmann::ordered_json& json_obj, const SimulationApplication::Options::Simulation& option)
346 {
347 json_obj = json{
348 { "event-print-num", option.event_print_num },
349 { "store-trajectory", option.store_trajectory },
350 { "material-filename", option.material_filename },
351 { "engine", option.engine },
352 { "random-seed", option.random_seed },
353 { "generator", option.generator },
354 };
355 }
356
357 template <>
358 void from_json(const nlohmann::ordered_json& json_obj, SimulationApplication::Options::Simulation& option)
359 {
360 json_obj.at("event-print-num").get_to(option.event_print_num);
361 json_obj.at("store-trajectory").get_to(option.store_trajectory);
362 json_obj.at("material-filename").get_to(option.material_filename);
363 json_obj.at("engine").get_to(option.engine);
364 json_obj.at("generator").get_to(option.generator);
365 }
366
367 template <>
368 void to_json(nlohmann::ordered_json& json_obj, const SimulationApplication::Options::Detector& option)
369 {
370 json_obj = json{ { "cave", option.cave }, { "neuland", option.neuland } };
371 }
372
373 template <>
374 void from_json(const nlohmann::ordered_json& json_obj, SimulationApplication::Options::Detector& option)
375 {
376 json_obj.at("cave").get_to(option.cave);
377 json_obj.at("neuland").get_to(option.neuland);
378 }
379
380 // =============================================================================================
381 // Detector options:
382
383 template <>
384 void to_json(nlohmann::ordered_json& json_obj, const SimulationApplication::Options::Detector::Cave& option)
385 {
386 json_obj = json{ { "enable", option.enable }, { "name", option.name }, { "geo-file", option.geo_file } };
387 }
388
389 template <>
390 void from_json(const nlohmann::ordered_json& json_obj, SimulationApplication::Options::Detector::Cave& option)
391 {
392 json_obj.at("enable").get_to(option.enable);
393 json_obj.at("name").get_to(option.name);
394 json_obj.at("geo-file").get_to(option.geo_file);
395 }
396
397 template <>
398 void to_json(nlohmann::ordered_json& json_obj, const SimulationApplication::Options::Detector::Neuland& option)
399 {
400 json_obj = json{ { "enable", option.enable },
401 { "name", option.name },
402 { "num-of-dp", option.num_of_dp },
403 { "location", option.location },
404 { "enable-auto-geo-build", option.enable_auto_geo_build } };
405 }
406
407 template <>
408 void from_json(const nlohmann::ordered_json& json_obj, SimulationApplication::Options::Detector::Neuland& option)
409 {
410 json_obj.at("enable").get_to(option.enable);
411 json_obj.at("name").get_to(option.name);
412 json_obj.at("num-of-dp").get_to(option.num_of_dp);
413 json_obj.at("location").get_to(option.location);
414 json_obj.at("enable-auto-geo-build").get_to(option.enable_auto_geo_build);
415 }
416} // 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::HitMon hit_monitor
struct R3B::Neuland::AnalysisApplication::Options::Tasks::SimCal2Cal sim_cal_to_cal
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::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
Pileup strategy for the tamex channel.
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
Tamex parameters used in the Digitizer.
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