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