-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
75 lines (61 loc) · 2.26 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <filesystem>
// Geant4 libraries
#include "G4RunManagerFactory.hh"
#include "G4SteppingVerbose.hh"
#include "G4UIExecutive.hh"
#include "G4UImanager.hh"
#include "G4VisExecutive.hh"
// my scripts
#include "action_initialization.hh"
#include "detector_construction.hh"
#include "energy_spectrum.hh"
#include "physics.hh"
int main(int argc, char **argv)
{
std::filesystem::create_directory("../results/");
std::filesystem::create_directory("../spectrums/");
// SETUP
// --------------------------------------------------------------------------------
// if no argument, interactive mode
G4UIExecutive *ui = nullptr;
if (argc == 1) ui = new G4UIExecutive(argc, argv);
G4int precision = 4;
G4SteppingVerbose::UseBestUnit(precision);
// save .dat files for energy spectrum
spectrum::save_spectrum_files();
// for running simulation
#ifndef G4MULTITHREADED
auto *runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Serial);
#else
auto *runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::MT);
#endif
runManager->SetUserInitialization(new DetectorConstruction); // detector
runManager->SetUserInitialization(new PhysicsList); // physics
runManager->SetUserInitialization(new ActionInitialization); // particles
// for visualization
auto *visManager = new G4VisExecutive;
visManager->Initialize();
// --------------------------------------------------------------------------------
// START PROGRAM
// --------------------------------------------------------------------------------
auto *uiManager = G4UImanager::GetUIpointer();
/* If no interactive mode, just execute in
the terminal. */
if (!ui) {
G4String command = "/control/execute ";
G4String fileName = argv[1];
uiManager->ApplyCommand(command + fileName);
}
/* If interactive mode, load macro file and
start visualization. */
else {
uiManager->ApplyCommand("/control/execute vis.mac");
DetectorConstruction::SetVisualization();
ui->SessionStart();
delete ui;
}
// --------------------------------------------------------------------------------
delete visManager;
delete runManager;
return 0;
}