R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
R3BNeulandAnalysisApp.cxx
Go to the documentation of this file.
1#include "R3BLosMapped2Cal.h"
2#include "R3BLosMapped2CalPar.h"
3#include "R3BLosProvideTStart.h"
4#include "R3BNeulandApp.h"
12#include <CLI/CLI.hpp>
13#include <FairRun.h>
14#include <FairRunAna.h>
15#include <R3BEventHeader.h>
17#include <R3BNeulandAppOptionJson.h> // NOLINT
19#include <R3BNeulandDigitizer.h>
20#include <R3BNeulandHitMon.h>
27#include <fairlogger/Logger.h>
28#include <fmt/base.h>
29#include <functional>
30#include <memory>
31#include <nlohmann/json.hpp>
32#include <nlohmann/json_fwd.hpp>
33#include <string>
34#include <string_view>
35#include <utility>
36#include <vector>
37
38using nlohmann::ordered_json;
39
40namespace R3B::Neuland
41{
43
45 : CLIApplication{ "neuland_ana", std::make_unique<FairRunAna>(), std::ref(options_.general) }
46 {
47 options_.general.input.data.emplace_back("sim.output.root");
48 options_.general.input.par.emplace_back("sim.par.root");
49
50 options_.general.output.data = "digi.output.root";
51 options_.general.output.par = "digi.par.root";
52 }
53
54 void AnalysisApplication::setup_application_options(CLI::App& program_options)
55 {
56 const auto analysis_option_group = std::string{ "Analysis options" };
57 program_options.add_option("--paddle", options_.tasks.digi.paddle, R"(Set the paddle name. e.g. "neuland")")
58 ->capture_default_str()
59 ->group(analysis_option_group);
60 program_options.add_option("--channel", options_.tasks.digi.channel, R"(Set the channel name. e.g. "tamex")")
61 ->capture_default_str()
62 ->group(analysis_option_group);
63 }
64
66 {
67
68 auto EvntHeader = std::make_unique<R3BEventHeader>();
69 auto read_branch_names = std::vector<std::string>{};
70 auto write_branch_names = std::vector<std::string>{};
71 LOGP(info, "Setting the event header to be R3BEventHeader!");
72 run->SetEventHeader(std::move(EvntHeader));
73
74 auto task_option = options_.tasks;
75
76 if (const auto& option = task_option.digi; option.enable)
77 {
78 auto task = Digitizer::Create(option, run);
79 run->AddTask(task.release());
80 }
81
82 if (const auto& option = task_option.sim_cal_to_cal; option.enable)
83 {
84 parse_io_branch_names(option, read_branch_names, 1, write_branch_names, 1);
85 auto task = std::make_unique<R3B::Neuland::SimCal2Cal>(read_branch_names.at(0), write_branch_names.at(0));
86 task->SetName(option.name.c_str());
87 run->AddTask(task.release());
88 }
89
90 if (const auto& option = task_option.hit_monitor; option.enable)
91 {
92 parse_io_branch_names(option, read_branch_names, 1, write_branch_names, 0);
93 auto task = std::make_unique<R3BNeulandHitMon>(read_branch_names.at(0));
94 task->SetName(option.name.c_str());
95 run->AddTask(task.release());
96 }
97
98 if (const auto& option = task_option.prim_inter_finder; option.enable)
99 {
100 parse_io_branch_names(option, read_branch_names, 2, write_branch_names, 3);
101 auto task = std::make_unique<R3BNeulandPrimaryInteractionFinder>(read_branch_names.at(0),
102 read_branch_names.at(1),
103 write_branch_names.at(0),
104 write_branch_names.at(1),
105 write_branch_names.at(2));
106 task->SetName(option.name.c_str());
107 run->AddTask(task.release());
108 }
109
110 if (const auto& option = task_option.cluster_finder; option.enable)
111 {
112 parse_io_branch_names(option, read_branch_names, 1, write_branch_names, 1);
113 auto task = std::make_unique<R3BNeulandClusterFinder>(read_branch_names.at(0), write_branch_names.at(0));
114 task->SetName(option.name.c_str());
115 run->AddTask(task.release());
116 }
117
118 if (const auto& option = task_option.prim_cluster_finder; option.enable)
119 {
120 parse_io_branch_names(option, read_branch_names, 2, write_branch_names, 2);
121 auto task = std::make_unique<R3BNeulandPrimaryClusterFinder>(
122 read_branch_names.at(0), read_branch_names.at(1), write_branch_names.at(0), write_branch_names.at(1));
123 task->SetName(option.name.c_str());
124 run->AddTask(task.release());
125 }
126
127 if (const auto& option = task_option.multi_calorimeter_train; option.enable)
128 {
129 parse_io_branch_names(option, read_branch_names, 3, write_branch_names, 0);
130 auto task = std::make_unique<R3BNeulandMultiplicityCalorimetricTrain>(
131 read_branch_names.at(0), read_branch_names.at(1), read_branch_names.at(2));
132 task->SetName(option.name.c_str());
133 task->SetUseHits(option.use_hit);
134 task->SetWeight(option.weight);
135 task->SetEdepOpt(option.edep_opt.init, option.edep_opt.step, option.edep_opt.lower, option.edep_opt.upper);
136 task->SetEdepOffOpt(option.edep_off_opt.init,
137 option.edep_off_opt.step,
138 option.edep_off_opt.lower,
139 option.edep_off_opt.upper);
140 task->SetNclusterOffOpt(option.n_cluster_opt.init,
141 option.n_cluster_opt.step,
142 option.n_cluster_opt.lower,
143 option.n_cluster_opt.upper);
144 task->SetNclusterOffOpt(option.n_cluster_off_opt.init,
145 option.n_cluster_off_opt.step,
146 option.n_cluster_off_opt.lower,
147 option.n_cluster_off_opt.upper);
148 run->AddTask(task.release());
149 }
150
151 if (const auto& option = task_option.multi_bayes_train; option.enable)
152 {
153 parse_io_branch_names(option, read_branch_names, 2, write_branch_names, 0);
154 auto task =
155 std::make_unique<R3BNeulandMultiplicityBayesTrain>(read_branch_names.at(0), read_branch_names.at(1));
156 task->SetName(option.name.c_str());
157 run->AddTask(task.release());
158 }
159
160 if (const auto& option = task_option.multi_bayes; option.enable)
161 {
162 parse_io_branch_names(option, read_branch_names, 1, write_branch_names, 1);
163 auto task =
164 std::make_unique<R3BNeulandMultiplicityBayes>(read_branch_names.at(0), write_branch_names.at(0));
165 task->SetName(option.name.c_str());
166 run->AddTask(task.release());
167 }
168
169 if (const auto& option = task_option.neutron_r_value; option.enable)
170 {
171 parse_io_branch_names(option, read_branch_names, 2, write_branch_names, 1);
172 auto task = std::make_unique<R3BNeulandNeutronsRValue>(
173 option.neutron_energy_mev, read_branch_names.at(0), read_branch_names.at(1), write_branch_names.at(0));
174 task->SetName(option.name.c_str());
175 run->AddTask(task.release());
176 }
177
178 if (const auto& option = task_option.map_data_converter_task; option.enable)
179 {
180 parse_io_branch_names(option, read_branch_names, 2, write_branch_names, 2);
181 auto task = std::make_unique<Calibration::MapDataConverterTask>(
182 read_branch_names.at(0), read_branch_names.at(1), write_branch_names.at(0), write_branch_names.at(1));
183 task->SetName(option.name.c_str());
184 run->AddTask(task.release());
185 }
186
187 if (const auto& option = task_option.map_to_cal_par_task; option.enable)
188 {
189 parse_io_branch_names(option, read_branch_names, 2, write_branch_names, 2);
190 auto task = std::make_unique<R3B::Neuland::Map2CalParTask>(
191 read_branch_names.at(0), read_branch_names.at(1), write_branch_names.at(0), write_branch_names.at(1));
192 task->SetTrigEnabled(option.has_trig_enabled);
193 task->SetErrorMethod(option.error_method);
194 run->AddTask(task.release());
195 }
196 if (const auto& option = task_option.map_to_cal_task; option.enable)
197 {
198 parse_io_branch_names(option, read_branch_names, 4, write_branch_names, 1);
199 auto task = std::make_unique<R3B::Neuland::Map2CalTask>(read_branch_names.at(0),
200 read_branch_names.at(1),
201 read_branch_names.at(2),
202 read_branch_names.at(3),
203 write_branch_names.at(0));
204 task->SetPulserMode(option.enable_pulse_mode);
205 task->SetNhitmin(option.min_stat);
206 task->EnableWalk(option.enable_walk_effect);
207 run->AddTask(task.release());
208 }
209
210 if (const auto& option = task_option.los_map_to_cal_par_task; option.enable)
211 {
212 parse_io_branch_names(option, read_branch_names, 2, write_branch_names, 1);
213 auto task = std::make_unique<R3BLosMapped2CalPar>();
214 run->AddTask(task.release());
215 }
216
217 if (const auto& option = task_option.los_map_to_cal_task; option.enable)
218 {
219 parse_io_branch_names(option, read_branch_names, 3, write_branch_names, 1);
220 auto task = std::make_unique<R3BLosMapped2Cal>();
221 static constexpr auto LOS_MODULE_NUM = 8;
222 task->SetNofModules(1, LOS_MODULE_NUM);
223 task->SetTrigger(1);
224 run->AddTask(task.release());
225 }
226 if (const auto& option = task_option.cal_to_hit_par_task; option.enable)
227 {
228 parse_io_branch_names(option, read_branch_names, 2, write_branch_names, 1);
229 auto task = std::make_unique<R3B::Neuland::Cal2HitParTask>(
230 option.method, read_branch_names.at(0), read_branch_names.at(1), write_branch_names.at(0));
231 task->SetMinStat(option.min_stat);
232 task->SetTrigger(option.mode);
233 run->AddTask(task.release());
234 }
235 if (const auto& option = task_option.los_provide_t_start; option.enable)
236 {
237 parse_io_branch_names(option, read_branch_names, 2, write_branch_names, 0);
238 auto task = std::make_unique<R3BLosProvideTStart>();
239 run->AddTask(task.release());
240 }
241
242 if (const auto& option = task_option.cal_to_hit_task; option.enable)
243 {
244 parse_io_branch_names(option, read_branch_names, 2, write_branch_names, 1);
245 auto task = std::make_unique<R3B::Neuland::Cal2HitTask>(
246 read_branch_names.at(0), read_branch_names.at(1), write_branch_names.at(0));
247 task->SetTrigger(option.mode);
248 task->SetGlobalTimeOffset(option.global_time_offset);
249 run->AddTask(task.release());
250 }
251 }
252
254
256 {
257 auto json_obj = ordered_json{ options_ };
258 if (json_obj.is_array())
259 {
260 fmt::print("{}\n", json_obj.front().dump(4));
261 }
262 else
263 {
264 fmt::print("{}\n", json_obj.dump(4));
265 }
266 }
267
268 void AnalysisApplication::dump_json_options(const std::string& filename)
269 {
271 }
272
273 void AnalysisApplication::ParseApplicationOption(const std::vector<std::string>& filename)
274 {
276 }
277} // namespace R3B::Neuland
void ParseApplicationOption(const std::vector< std::string > &filename) override
void setup_application_options(CLI::App &program_options) override
void dump_json_options(const std::string &filename) override
void run() override
Run the CLI program.
void ParseApplicationOptionImp(const std::vector< std::string > &filename, OptionType &options)
CLIApplication(std::string_view name, std::unique_ptr< FairRun > run, std::reference_wrapper< Options > option)
void dump_json_options(const OptionType &options, const std::string &filename)
static auto Create(const R3B::Neuland::DigiTaskOptions &option, FairRun *run) -> std::unique_ptr< Digitizer >
Generator of the digitizing class.
Simulation of NeuLAND Bar/Paddle.
AnalysisApplication::Options Options
void parse_io_branch_names(const Option &option, std::vector< std::string > &read, int read_num, std::vector< std::string > &write, int write_num)