LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
neuron.cc File Reference

Implementation of the neuron example. More...

#include "G4Types.hh"
#include "G4RunManager.hh"
#include "G4DNAChemistryManager.hh"
#include "G4Timer.hh"
#include "G4UImanager.hh"
#include "G4UIExecutive.hh"
#include "G4VisExecutive.hh"
#include "CommandLineParser.hh"
#include "ActionInitialization.hh"
#include "DetectorConstruction.hh"
#include "PhysicsList.hh"

Go to the source code of this file.

Functions

CommandLineParser * parser (0)
 
void Parse (int &argc, char **argv)
 
int main (int argc, char **argv)
 
void GetNameAndPathOfExecutable (char **argv, G4String &executable, G4String &path)
 

Detailed Description

Implementation of the neuron example.

Definition in file neuron.cc.

Function Documentation

void GetNameAndPathOfExecutable ( char **  argv,
G4String executable,
G4String path 
)

Definition at line 195 of file neuron.cc.

Referenced by Parse().

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 }
int main ( int  argc,
char **  argv 
)

Definition at line 67 of file neuron.cc.

References Parse(), and parser().

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 }
void Parse(int &argc, char **argv)
Definition: neuron.cc:216
CommandLineParser * parser(0)
void Parse ( int &  argc,
char **  argv 
)

Definition at line 216 of file neuron.cc.

References GetNameAndPathOfExecutable(), and parser().

Referenced by main().

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
CommandLineParser * parser(0)
CommandLineParser* parser ( )

Referenced by main(), and Parse().