R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
R3BNeulandAnalysisApp.cxx
Go to the documentation of this file.
1#include "R3BNeulandApp.h"
5#include <CLI/CLI.hpp>
6#include <FairRun.h>
7#include <FairRunAna.h>
8#include <R3BEventHeader.h>
10#include <R3BNeulandAppOptionJson.h> // NOLINT
12#include <R3BNeulandDigitizer.h>
13#include <R3BNeulandHitMon.h>
20#include <fmt/core.h>
21#include <functional>
22#include <memory>
23#include <nlohmann/json.hpp>
24#include <nlohmann/json_fwd.hpp>
25#include <string>
26#include <string_view>
27#include <vector>
28
29using nlohmann::ordered_json;
30
31namespace R3B::Neuland
32{
34
36 : CLIApplication{ "neuland_ana", std::make_unique<FairRunAna>(), std::ref(options_.general) }
37 {
38 options_.general.input.data.emplace_back("sim.output.root");
39 options_.general.input.par = "sim.par.root";
40
41 options_.general.output.data = "digi.output.root";
42 options_.general.output.par = "digi.par.root";
43 }
44
45 void AnalysisApplication::setup_application_options(CLI::App& program_options)
46 {
47 const auto analysis_option_group = std::string{ "Analysis options" };
48 program_options.add_option("--paddle", options_.tasks.digi.paddle, R"(Set the paddle name. e.g. "neuland")")
49 ->capture_default_str()
50 ->group(analysis_option_group);
51 program_options.add_option("--channel", options_.tasks.digi.channel, R"(Set the channel name. e.g. "tamex")")
52 ->capture_default_str()
53 ->group(analysis_option_group);
54 }
55
57 {
58
59 auto EvntHeader = std::make_unique<R3BEventHeader>();
60 auto read_branch_names = std::vector<std::string>{};
61 auto write_branch_names = std::vector<std::string>{};
62 run->SetEventHeader(EvntHeader.release());
63
64 auto task_option = options_.tasks;
65 run->SetEventHeader(std::make_unique<R3BEventHeader>().release());
66
67 if (const auto& option = task_option.digi; option.enable)
68 {
69 auto task = Digitizer::Create(option, run);
70 run->AddTask(task.release());
71 }
72
73 if (const auto& option = task_option.sim_cal_to_cal; option.enable)
74 {
75 parse_io_branch_names(option, read_branch_names, 1, write_branch_names, 1);
76 auto task = std::make_unique<R3B::Neuland::SimCal2Cal>(read_branch_names.at(0), write_branch_names.at(0));
77 task->SetName(option.name.c_str());
78 run->AddTask(task.release());
79 }
80
81 if (const auto& option = task_option.hit_monitor; option.enable)
82 {
83 parse_io_branch_names(option, read_branch_names, 1, write_branch_names, 0);
84 auto task = std::make_unique<R3BNeulandHitMon>(read_branch_names.at(0));
85 task->SetName(option.name.c_str());
86 run->AddTask(task.release());
87 }
88
89 if (const auto& option = task_option.prim_inter_finder; option.enable)
90 {
91 parse_io_branch_names(option, read_branch_names, 2, write_branch_names, 3);
92 auto task = std::make_unique<R3BNeulandPrimaryInteractionFinder>(read_branch_names.at(0),
93 read_branch_names.at(1),
94 write_branch_names.at(0),
95 write_branch_names.at(1),
96 write_branch_names.at(2));
97 task->SetName(option.name.c_str());
98 run->AddTask(task.release());
99 }
100
101 if (const auto& option = task_option.cluster_finder; option.enable)
102 {
103 parse_io_branch_names(option, read_branch_names, 1, write_branch_names, 1);
104 auto task = std::make_unique<R3BNeulandClusterFinder>(read_branch_names.at(0), write_branch_names.at(0));
105 task->SetName(option.name.c_str());
106 run->AddTask(task.release());
107 }
108
109 if (const auto& option = task_option.prim_cluster_finder; option.enable)
110 {
111 parse_io_branch_names(option, read_branch_names, 2, write_branch_names, 2);
112 auto task = std::make_unique<R3BNeulandPrimaryClusterFinder>(
113 read_branch_names.at(0), read_branch_names.at(1), write_branch_names.at(0), write_branch_names.at(1));
114 task->SetName(option.name.c_str());
115 run->AddTask(task.release());
116 }
117
118 if (const auto& option = task_option.multi_calorimeter_train; option.enable)
119 {
120 parse_io_branch_names(option, read_branch_names, 3, write_branch_names, 0);
121 auto task = std::make_unique<R3BNeulandMultiplicityCalorimetricTrain>(
122 read_branch_names.at(0), read_branch_names.at(1), read_branch_names.at(2));
123 task->SetName(option.name.c_str());
124 task->SetUseHits(option.use_hit);
125 task->SetWeight(option.weight);
126 task->SetEdepOpt(option.edep_opt.init, option.edep_opt.step, option.edep_opt.lower, option.edep_opt.upper);
127 task->SetEdepOffOpt(option.edep_off_opt.init,
128 option.edep_off_opt.step,
129 option.edep_off_opt.lower,
130 option.edep_off_opt.upper);
131 task->SetNclusterOffOpt(option.n_cluster_opt.init,
132 option.n_cluster_opt.step,
133 option.n_cluster_opt.lower,
134 option.n_cluster_opt.upper);
135 task->SetNclusterOffOpt(option.n_cluster_off_opt.init,
136 option.n_cluster_off_opt.step,
137 option.n_cluster_off_opt.lower,
138 option.n_cluster_off_opt.upper);
139 run->AddTask(task.release());
140 }
141
142 if (const auto& option = task_option.multi_bayes_train; option.enable)
143 {
144 parse_io_branch_names(option, read_branch_names, 2, write_branch_names, 0);
145 auto task =
146 std::make_unique<R3BNeulandMultiplicityBayesTrain>(read_branch_names.at(0), read_branch_names.at(1));
147 task->SetName(option.name.c_str());
148 run->AddTask(task.release());
149 }
150
151 if (const auto& option = task_option.multi_bayes; option.enable)
152 {
153 parse_io_branch_names(option, read_branch_names, 1, write_branch_names, 1);
154 auto task =
155 std::make_unique<R3BNeulandMultiplicityBayes>(read_branch_names.at(0), write_branch_names.at(0));
156 task->SetName(option.name.c_str());
157 run->AddTask(task.release());
158 }
159
160 if (const auto& option = task_option.neutron_r_value; option.enable)
161 {
162 parse_io_branch_names(option, read_branch_names, 2, write_branch_names, 1);
163 auto task = std::make_unique<R3BNeulandNeutronsRValue>(
164 option.neutron_energy_mev, read_branch_names.at(0), read_branch_names.at(1), 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.cal_to_hit_par_task; option.enable)
170 {
171 parse_io_branch_names(option, read_branch_names, 2, write_branch_names, 1);
172 auto task = std::make_unique<R3B::Neuland::Cal2HitParTask>(
173 option.method, read_branch_names.at(0), read_branch_names.at(1), write_branch_names.at(0));
174 task->SetMinStat(option.min_stat);
175 run->AddTask(task.release());
176 }
177 }
178
180
182 {
183 auto json_obj = ordered_json{ options_ };
184 if (json_obj.is_array())
185 {
186 fmt::print("{}\n", json_obj.front().dump(4));
187 }
188 else
189 {
190 fmt::print("{}\n", json_obj.dump(4));
191 }
192 }
193
194 void AnalysisApplication::dump_json_options(const std::string& filename)
195 {
197 }
198
199 void AnalysisApplication::ParseApplicationOption(const std::vector<std::string>& filename)
200 {
202 }
203} // 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)