File indexing completed on 2026-03-28 07:50:45
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 #include "ActionInitialization.hh"
0045 #include "CommandLineParser.hh"
0046 #include "DetectorConstruction.hh"
0047 #include "PhysicsList.hh"
0048
0049 #include "G4DNAChemistryManager.hh"
0050 #include "G4RunManagerFactory.hh"
0051 #include "G4Timer.hh"
0052 #include "G4Types.hh"
0053 #include "G4UIExecutive.hh"
0054 #include "G4UImanager.hh"
0055 #include "G4VisExecutive.hh"
0056
0057
0058
0059 using namespace std;
0060 using namespace G4DNAPARSER;
0061
0062 CommandLineParser* parser(0);
0063
0064 void Parse(int& argc, char** argv);
0065
0066 int main(int argc, char** argv)
0067 {
0068
0069 G4Timer* timer = new G4Timer();
0070 timer->Start();
0071
0072
0073
0074
0075 Parse(argc, argv);
0076
0077
0078
0079
0080 Command* commandLine(0);
0081
0082 auto* runManager = G4RunManagerFactory::CreateRunManager();
0083
0084 if ((commandLine = parser->GetCommandIfActive("-mt"))) {
0085 G4int nThreads = 2;
0086
0087 if (commandLine->GetOption() == "NMAX") {
0088 nThreads = G4Threading::G4GetNumberOfCores();
0089 }
0090 else {
0091 nThreads = G4UIcommand::ConvertToInt(commandLine->GetOption());
0092 }
0093 runManager->SetNumberOfThreads(nThreads);
0094
0095 G4cout << "===== neuron is started with " << runManager->GetNumberOfThreads()
0096 << " threads of MT MODE =====" << G4endl;
0097 }
0098
0099
0100 DetectorConstruction* detector = new DetectorConstruction;
0101 runManager->SetUserInitialization(detector);
0102 runManager->SetUserInitialization(new PhysicsList);
0103
0104
0105 runManager->SetUserInitialization(new ActionInitialization(detector));
0106
0107
0108 G4VisManager* visManager = new G4VisExecutive;
0109 visManager->Initialize();
0110
0111
0112 G4UImanager* UImanager = G4UImanager::GetUIpointer();
0113 G4UIExecutive* ui(0);
0114
0115
0116 if ((commandLine = parser->GetCommandIfActive("-gui"))) {
0117 ui = new G4UIExecutive(argc, argv, commandLine->GetOption());
0118
0119 if (ui->IsGUI()) UImanager->ApplyCommand("/control/execute gui.mac");
0120
0121 if (parser->GetCommandIfActive("-novis") == 0)
0122
0123 {
0124 if ((commandLine = parser->GetCommandIfActive("-vis")))
0125
0126 {
0127 UImanager->ApplyCommand(G4String("/vis/open ") + commandLine->GetOption());
0128 }
0129 else
0130
0131 {
0132 UImanager->ApplyCommand("/vis/open OGL 800x600-0+0");
0133 }
0134 UImanager->ApplyCommand("/control/execute vis.mac");
0135 }
0136 }
0137 else
0138
0139
0140
0141 {
0142 if ((commandLine = parser->GetCommandIfActive("-vis"))) {
0143 UImanager->ApplyCommand(G4String("/vis/open ") + commandLine->GetOption());
0144 UImanager->ApplyCommand("/control/execute vis.mac");
0145 }
0146 }
0147
0148 if ((commandLine = parser->GetCommandIfActive("-mac"))) {
0149 G4String command = "/control/execute ";
0150 UImanager->ApplyCommand(command + commandLine->GetOption());
0151 }
0152 else {
0153 UImanager->ApplyCommand("/control/execute ");
0154 }
0155
0156 if ((commandLine = parser->GetCommandIfActive("-gui"))) {
0157 ui->SessionStart();
0158 delete ui;
0159 }
0160
0161
0162 timer->Stop();
0163 G4cout << " Calculation time = " << timer->GetRealElapsed() << " s \n"
0164 << G4endl;
0165
0166 delete visManager;
0167 delete runManager;
0168
0169 return 0;
0170 }
0171
0172
0173
0174 void GetNameAndPathOfExecutable(char** argv, G4String& executable, G4String& path)
0175 {
0176
0177 std::string aux(argv[0]);
0178
0179
0180 #if defined(_WIN32) || defined(WIN32)
0181 int pos = aux.rfind('\\');
0182 #else
0183 int pos = aux.rfind('/');
0184 #endif
0185
0186
0187 path = aux.substr(0, pos + 1);
0188 executable = aux.substr(pos + 1);
0189 }
0190
0191
0192
0193 void Parse(int& argc, char** argv)
0194 {
0195
0196
0197
0198 parser = CommandLineParser::GetParser();
0199
0200 parser->AddCommand("-gui", Command::OptionNotCompulsory,
0201 "Select geant4 UI or just launch a geant4 terminal session", "qt");
0202
0203 parser->AddCommand("-mac", Command::WithOption, "Give a mac file to execute", "macFile.mac");
0204
0205
0206
0207
0208
0209
0210
0211 parser->AddCommand("-mt", Command::WithOption, "Launch in MT mode (events computed in parallel)",
0212 " NOT RECOMMANDED WITH CHEMISTRY)", "2");
0213
0214 parser->AddCommand("-sXY", Command::OptionNotCompulsory,
0215 "Initial beam position uniformly spread on a square!");
0216 parser->AddCommand("-dXY", Command::OptionNotCompulsory,
0217 "Initial beam position uniformly spread on a disk!");
0218
0219 parser->AddCommand("-dnaliv", Command::OptionNotCompulsory, "Activate Livermore + DNAPhysics");
0220 parser->AddCommand("-dnachemON", Command::OptionNotCompulsory,
0221 "Activate Livermore + DNAPhysics + DNAChemistry");
0222 parser->AddCommand("-dnahad", Command::OptionNotCompulsory,
0223 "Activate Hadronic + Livermore + DNAPhysics");
0224
0225 parser->AddCommand("-swc", Command::WithOption, "Give a SWC file to simulation", "fileName.swc");
0226
0227 parser->AddCommand("-network",
0228 Command::WithOption,
0229 "Give a DAT file to simulation", "fileName.dat");
0230
0231 parser->AddCommand("-vis", Command::WithOption, "Select a visualization driver",
0232 "OGL 600x600-0+0");
0233
0234 parser->AddCommand("-novis", Command::WithoutOption, "Deactivate visualization when using GUI");
0235
0236 G4String exec;
0237 G4String path;
0238 GetNameAndPathOfExecutable(argv, exec, path);
0239
0240 parser->AddCommand("-out", Command::OptionNotCompulsory, "Output files", exec);
0241
0242
0243
0244
0245 if (parser->Parse(argc, argv) != 0)
0246 {
0247
0248
0249 CommandLineParser::DeleteInstance();
0250 std::exit(0);
0251 }
0252
0253
0254
0255 if (parser->CheckIfNotHandledOptionsExists(argc, argv)) {
0256
0257
0258 abort();
0259 }
0260 }