R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
R3BNeulandSimApp.cxx
Go to the documentation of this file.
1#include "R3BNeulandSimApp.h"
2#include "R3BCave.h"
3#include "R3BNeuland.h"
4#include "R3BNeulandApp.h"
5#include <FairRun.h>
6#include <FairRunSim.h>
7#include <G4RunManager.hh>
8#include <R3BFieldConst.h>
10#include <TG4EventAction.h>
11#include <TGeoMatrix.h>
12#include <TRandom3.h>
13#include <functional>
14#include <memory>
15#include <string>
16#include <vector>
17
18namespace R3B::Neuland
19{
21 : CLIApplication{ "neuland_sim", std::make_unique<FairRunSim>(), std::ref(options_.general) }
22 {
23 options_.general.input.par.clear();
24 options_.general.input.data.clear();
25 options_.general.output.data = "sim.output.root";
26 options_.general.output.par = "sim.par.root";
27 }
28
30 {
31 auto* sim_run = dynamic_cast<FairRunSim*>(run);
32 setup_engine(sim_run);
33 setup_generator(sim_run);
34 setup_detectors(sim_run);
35 }
36
37 void SimulationApplication::post_init(FairRun* /*run*/)
38 {
39 const auto& options = options_.simulation;
40 auto* geant_run = G4RunManager::GetRunManager();
41 geant_run->SetPrintProgress(options.event_print_num);
42 auto* event =
43 dynamic_cast<TG4EventAction*>(const_cast<G4UserEventAction*>(geant_run->GetUserEventAction())); // NOLINT
44 event->VerboseLevel(0);
45 }
46
48 {
49 const auto& options = options_;
50 run->SetName(options.simulation.engine.c_str());
51 run->SetRunId(options.general.run_id);
52 run->SetStoreTraj(options.simulation.store_trajectory);
53 run->SetMaterials(options.simulation.material_filename.c_str());
54 auto fairField = std::make_unique<R3BFieldConst>();
55 run->SetField(fairField.release());
56 }
57
59 {
60 const auto& options_pos = options_.detectors.neuland;
61 random_gen_ = std::make_unique<TRandom3>(options_.simulation.random_seed);
62 generator_factory_.SetNumOfPlanes(options_pos.num_of_dp * 2);
63 generator_factory_.SetRandomGen(random_gen_.get());
64 run->SetGenerator(generator_factory_.Create().release());
65 }
66
68 {
69 const auto& options = options_.detectors;
70
71 const auto& cave_options = options.cave;
72 if (cave_options.enable)
73 {
74 auto cave = std::make_unique<R3BCave>(cave_options.name.c_str());
75 cave->SetGeometryFileName(cave_options.geo_file.c_str());
76 run->AddModule(cave.release());
77 }
78
79 const auto& neuland_options = options.neuland;
80 if (neuland_options.enable)
81 {
82
83 const auto& location = neuland_options.location;
84 auto const neulandGeoTrans = TGeoTranslation{ location.x(), location.y(), location.z() };
85 auto neuland = std::make_unique<R3BNeuland>(neuland_options.num_of_dp, neulandGeoTrans);
86 if (neuland_options.enable_auto_geo_build)
87 {
88 neuland->EnableAutoGeoBuild();
89 }
90 run->AddModule(neuland.release());
91 }
92 }
93
94 void SimulationApplication::ParseApplicationOption(const std::vector<std::string>& filename)
95 {
97 }
98
100
101 void SimulationApplication::dump_json_options(const std::string& filename)
102 {
104 }
105
106 void SimulationApplication::run_action(FairRun* run, int num_of_events) { run->Run(num_of_events); }
107} // namespace R3B::Neuland
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)
void dump_json_options(const std::string &filename) override
void run_action(FairRun *run, int num_of_events) override
void ParseApplicationOption(const std::vector< std::string > &filename) override
void post_init(FairRun *run) override
void pre_init(FairRun *run) override
void setup_detectors(FairRunSim *run) const
std::unique_ptr< TRandom3 > random_gen_
Simulation of NeuLAND Bar/Paddle.