LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
neuron.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // This example is provided by the Geant4-DNA collaboration
27 // Any report or published results obtained using the Geant4-DNA software
28 // shall cite the following Geant4-DNA collaboration publication:
29 // Med. Phys. 37 (2010) 4692-4708
30 // and papers
31 // M. Batmunkh et al. J Radiat Res Appl Sci 8 (2015) 498-507
32 // O. Belov et al. Physica Medica 32 (2016) 1510-1520
33 // The Geant4-DNA web site is available at http://geant4-dna.org
34 //
35 // -------------------------------------------------------------------
36 // November 2016
37 // -------------------------------------------------------------------
38 //
41 //
42 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
43 #include "G4Types.hh"
44 #ifdef G4MULTITHREADED
45  #include "G4MTRunManager.hh"
46 #else
47  #include "G4RunManager.hh"
48 #endif
49 #include "G4DNAChemistryManager.hh"
50 #include "G4Timer.hh"
51 #include "G4UImanager.hh"
52 #include "G4UIExecutive.hh"
53 #include "G4VisExecutive.hh"
54 #include "CommandLineParser.hh"
55 #include "ActionInitialization.hh"
56 #include "DetectorConstruction.hh"
57 #include "PhysicsList.hh"
58 
59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
60 
61 using namespace std;
62 using namespace G4DNAPARSER;
63 CommandLineParser* parser(0);
64 
65 void Parse(int& argc, char** argv);
66 
67 int main(int argc,char** argv)
68 {
69 
70  // run time in Geant4
71  G4Timer *timer = new G4Timer();
72  timer->Start();
73 
75  // Parse options given in commandLine
76  //
77  Parse(argc, argv);
78 
80  // Construct the run manager according to whether MT is activated or not
81  //
82  Command* commandLine(0);
83 
84 #ifdef G4MULTITHREADED
85  G4MTRunManager* runManager= new G4MTRunManager;
86  if ((commandLine = parser->GetCommandIfActive("-mt")))
87  {
88  int nThreads = 2;
89  if(commandLine->GetOption() == "NMAX")
90  {
91  nThreads = G4Threading::G4GetNumberOfCores();
92  }
93  else
94  {
95  nThreads = G4UIcommand::ConvertToInt(commandLine->GetOption());
96  }
97  G4cout << "===== neuron is started with "
98  << runManager->GetNumberOfThreads()
99  << " threads of MT MODE =====" << G4endl;
100 
101  runManager->SetNumberOfThreads(nThreads);
102  }
103 #else
104  G4RunManager* runManager = new G4RunManager();
105  G4cout << "===== neuron is started with "
106  << " SEQUENTIAL MODE =====" << G4endl;
107 #endif
108 
109  // Set mandatory user initialization classes
111  runManager->SetUserInitialization(detector);
112  runManager->SetUserInitialization(new PhysicsList);
113 
114  // User action initialization
115  runManager->SetUserInitialization(new ActionInitialization(detector));
116 
117  // Initialize G4 kernel
118  runManager->Initialize();
119 
120  // Initialize visualization
121  G4VisManager* visManager = new G4VisExecutive;
122  visManager->Initialize();
123 
124  // Get the pointer to the User Interface manager
125  G4UImanager* UImanager = G4UImanager::GetUIpointer();
126  G4UIExecutive* ui(0);
127 
128  // interactive mode : define UI session
129  if ((commandLine = parser->GetCommandIfActive("-gui")))
130  {
131  ui = new G4UIExecutive(argc, argv,
132  commandLine->GetOption());
133 
134  if(ui->IsGUI())
135  UImanager->ApplyCommand("/control/execute gui.mac");
136 
137  if(parser->GetCommandIfActive("-novis") == 0)
138  // visualization is used by default
139  {
140  if((commandLine = parser->GetCommandIfActive("-vis")))
141  // select a visualization driver if needed (e.g. HepFile)
142  {
143  UImanager->ApplyCommand(G4String("/vis/open ")+
144  commandLine->GetOption());
145  }
146  else
147  // by default OGL is used
148  {
149  UImanager->ApplyCommand("/vis/open OGL 800x600-0+0");
150  }
151  UImanager->ApplyCommand("/control/execute vis.mac");
152  }
153  }
154  else
155  // to be use visualization file (= store the visualization into
156  // an external file:
157  // ASCIITree ; DAWNFILE ; HepRepFile ; VRML(1,2)FILE ; gMocrenFile ...
158  {
159  if ((commandLine = parser->GetCommandIfActive("-vis")))
160  {
161  UImanager->ApplyCommand(G4String("/vis/open ")+commandLine->GetOption());
162  UImanager->ApplyCommand("/control/execute vis.mac");
163  }
164  }
165 
166  if ((commandLine = parser->GetCommandIfActive("-mac")))
167  {
168  G4String command = "/control/execute ";
169  UImanager->ApplyCommand(command + commandLine->GetOption());
170  }
171  else
172  {
173  UImanager->ApplyCommand("/control/execute "); //neuron.in
174  }
175 
176  if ((commandLine = parser->GetCommandIfActive("-gui")))
177  {
178  ui->SessionStart();
179  delete ui;
180  }
181 
182  // calculation time
183  timer->Stop();
184  G4cout << " Calculation time = "
185  << timer->GetRealElapsed() << " s \n"<< G4endl;
186 
187  delete visManager;
188  delete runManager;
189 
190  return 0;
191 }
192 
193 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
194 
195 void GetNameAndPathOfExecutable(char** argv,
196  G4String& executable,
197  G4String& path)
198 {
199  // Get the last position of '/'
200  std::string aux(argv[0]);
201 
202  // get '/' or '\\' depending on unix/mac or windows.
203 #if defined(_WIN32) || defined(WIN32)
204  int pos = aux.rfind('\\');
205 #else
206  int pos = aux.rfind('/');
207 #endif
208 
209  // Get the path and the name
210  path = aux.substr(0, pos + 1);
211  executable = aux.substr(pos + 1);
212 }
213 
214 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
215 
216 void Parse(int& argc, char** argv)
217 {
219  // Parse options given in commandLine
220  //
221  parser = CommandLineParser::GetParser();
222 
223  parser->AddCommand("-gui",
224  Command::OptionNotCompulsory,
225  "Select geant4 UI or just launch a geant4 terminal session",
226  "qt");
227 
228  parser->AddCommand("-mac",
229  Command::WithOption,
230  "Give a mac file to execute",
231  "macFile.mac");
232 
233 // You cann your own command, as for instance:
234 // parser->AddCommand("-seed",
235 // Command::WithOption,
236 // "Give a seed value in argument to be tested", "seed");
237 // it is then up to you to manage this option
238 
239 #ifdef G4MULTITHREADED
240  parser->AddCommand("-mt",
241  Command::WithOption,
242  "Launch in MT mode (events computed in parallel)",
243  " NOT RECOMMANDED WITH CHEMISTRY)",
244  "2");
245 #endif
246 
247  parser->AddCommand("-sXY", Command::OptionNotCompulsory,
248  "Initial beam position uniformly spread on a square!");
249  parser->AddCommand("-dXY", Command::OptionNotCompulsory,
250  "Initial beam position uniformly spread on a disk!");
251 
252  parser->AddCommand("-dnaliv", Command::OptionNotCompulsory,
253  "Activate Livermore + DNAPhysics");
254  parser->AddCommand("-dnachemON", Command::OptionNotCompulsory,
255  "Activate Livermore + DNAPhysics + DNAChemistry");
256  parser->AddCommand("-dnahad", Command::OptionNotCompulsory,
257  "Activate Hadronic + Livermore + DNAPhysics");
258 
259  parser->AddCommand("-swc",
260  Command::WithOption,
261  "Give a SWC file to simulation",
262  "fileName.swc");
263 
264  parser->AddCommand("-network",
265  Command::WithOption, //OptionNotCompulsory,
266  "Give a DAT file to simulation",
267  "fileName.dat");
268 
269  parser->AddCommand("-vis",
270  Command::WithOption,
271  "Select a visualization driver",
272  "OGL 600x600-0+0");
273 
274  parser->AddCommand("-novis",
275  Command::WithoutOption,
276  "Deactivate visualization when using GUI");
277 
278  G4String exec;
279  G4String path;
280  GetNameAndPathOfExecutable(argv,exec, path);
281 
282  parser->AddCommand("-out",
283  Command::OptionNotCompulsory,
284  "Output files",
285  exec);
286 
288  // If -h or --help is given in option : print help and exit
289  //
290  if (parser->Parse(argc, argv) != 0) // help is being printed
291  {
292  // if you are using ROOT, create a TApplication in this condition in order
293  // to print the help from ROOT as well
294  CommandLineParser::DeleteInstance();
295  std::exit(0);
296  }
297 
299  // Kill application if wrong argument in command line
300  //
301  if (parser->CheckIfNotHandledOptionsExists(argc, argv))
302  {
303  // if you are using ROOT, you should initialise your TApplication
304  // before this condition
305  abort();
306  }
307 }
void GetNameAndPathOfExecutable(char **argv, G4String &executable, G4String &path)
Definition: neuron.cc:195
void Parse(int &argc, char **argv)
Definition: neuron.cc:216
STL namespace.
int main(int argc, char **argv)
Definition: neuron.cc:67
CommandLineParser * parser(0)