LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
microdosimetry.cc File Reference

Implementation of the microdosimetry example. More...

#include "G4RunManager.hh"
#include "G4UImanager.hh"
#include "G4UIExecutive.hh"
#include "G4UIterminal.hh"
#include "G4UItcsh.hh"
#include "G4VisExecutive.hh"
#include "ActionInitialization.hh"
#include "DetectorConstruction.hh"
#include "PhysicsList.hh"
#include "CommandLineParser.hh"
#include "G4UIQt.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 microdosimetry example.

Definition in file microdosimetry.cc.

Function Documentation

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

Definition at line 193 of file microdosimetry.cc.

Referenced by Parse().

196 {
197  // Get the last position of '/'
198  std::string aux(argv[0]);
199 
200  // get '/' or '\\' depending on unix/mac or windows.
201 #if defined(_WIN32) || defined(WIN32)
202  int pos = aux.rfind('\\');
203 #else
204  int pos = aux.rfind('/');
205 #endif
206 
207  // Get the path and the name
208  path = aux.substr(0, pos + 1);
209  executable = aux.substr(pos + 1);
210 }
int main ( int  argc,
char **  argv 
)

Definition at line 63 of file microdosimetry.cc.

References Parse(), and parser().

64 {
65  // Choose the Random engine
66  G4Random::setTheEngine(new CLHEP::RanecuEngine);
67 
69  // Parse options given in commandLine
70  //
71  Parse(argc, argv);
72 
74  // Construct the run manager according to whether MT is activated or not
75  //
76  Command* commandLine(0);
77 
78 #ifdef G4MULTITHREADED
79  G4MTRunManager* runManager= new G4MTRunManager;
80  if ((commandLine = parser->GetCommandIfActive("-mt")))
81  {
82  int nThreads = 2;
83  if(commandLine->GetOption() == "NMAX")
84  {
85  nThreads = G4Threading::G4GetNumberOfCores();
86  }
87  else
88  {
89  nThreads = G4UIcommand::ConvertToInt(commandLine->GetOption());
90  }
91  G4cout << "===== Microdosimetry is started with "
92  << runManager->GetNumberOfThreads()
93  << " threads =====" << G4endl;
94 
95  runManager->SetNumberOfThreads(nThreads);
96  }
97 #else
98  G4RunManager* runManager = new G4RunManager();
99 #endif
100 
101  // Set mandatory user initialization classes
103  runManager->SetUserInitialization(detector);
104 
105  runManager->SetUserInitialization(new PhysicsList);
106 
107  // User action initialization
108 
109  runManager->SetUserInitialization(new ActionInitialization());
110 
111  // Initialize G4 kernel
112 
113  runManager->Initialize();
114 
115  // Initialize visualization
116  G4VisManager* visManager = new G4VisExecutive;
117  // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
118  // G4VisManager* visManager = new G4VisExecutive("Quiet");
119  visManager->Initialize();
120 
121  // Get the pointer to the User Interface manager
122  G4UImanager* UImanager = G4UImanager::GetUIpointer();
123  G4UIExecutive* ui(0);
124 
125  // interactive mode : define UI session
126  if ((commandLine = parser->GetCommandIfActive("-gui")))
127  {
128  ui = new G4UIExecutive(argc, argv,
129  commandLine->GetOption());
130 
131  if(ui->IsGUI())
132  UImanager->ApplyCommand("/control/execute gui.mac");
133 
134  if(parser->GetCommandIfActive("-novis") == 0)
135  // visualization is used by default
136  {
137  if((commandLine = parser->GetCommandIfActive("-vis")))
138  // select a visualization driver if needed (e.g. HepFile)
139  {
140  UImanager->ApplyCommand(G4String("/vis/open ")+
141  commandLine->GetOption());
142  }
143  else
144  // by default OGL is used
145  {
146  UImanager->ApplyCommand("/vis/open OGL 800x600-0+0");
147  }
148  UImanager->ApplyCommand("/control/execute vis.mac");
149  }
150  }
151  else
152  // to be use visualization file (= store the visualization into
153  // an external file:
154  // ASCIITree ; DAWNFILE ; HepRepFile ; VRML(1,2)FILE ; gMocrenFile ...
155  {
156  if ((commandLine = parser->GetCommandIfActive("-vis")))
157  {
158  UImanager->ApplyCommand(G4String("/vis/open ")+commandLine->GetOption());
159  UImanager->ApplyCommand("/control/execute vis.mac");
160  }
161  }
162 
163  if ((commandLine = parser->GetCommandIfActive("-mac")))
164  {
165  G4String command = "/control/execute ";
166  UImanager->ApplyCommand(command + commandLine->GetOption());
167  }
168  else
169  {
170  UImanager->ApplyCommand("/control/execute microdosimetry.in");
171  }
172 
173  if ((commandLine = parser->GetCommandIfActive("-gui")))
174  {
175 #ifdef G4UI_USE_QT
176  G4UIQt* UIQt = static_cast<G4UIQt*> (UImanager->GetG4UIWindow());
177  if ( UIQt) {
178  UIQt->AddViewerTabFromFile("README", "README from "+ G4String(argv[0]));
179  }
180 #endif
181  ui->SessionStart();
182  delete ui;
183  }
184 
185  delete visManager;
186  delete runManager;
187 
188  return 0;
189 }
void Parse(int &argc, char **argv)
CommandLineParser * parser(0)
void Parse ( int &  argc,
char **  argv 
)

Definition at line 214 of file microdosimetry.cc.

References GetNameAndPathOfExecutable(), and parser().

Referenced by main().

215 {
217  // Parse options given in commandLine
218  //
219  parser = CommandLineParser::GetParser();
220 
221  parser->AddCommand("-gui",
222  Command::OptionNotCompulsory,
223  "Select geant4 UI or just launch a geant4 terminal session",
224  "qt");
225 
226  parser->AddCommand("-mac",
227  Command::WithOption,
228  "Give a mac file to execute",
229  "macFile.mac");
230 
231 // You cann your own command, as for instance:
232 // parser->AddCommand("-seed",
233 // Command::WithOption,
234 // "Give a seed value in argument to be tested", "seed");
235 // it is then up to you to manage this option
236 
237 #ifdef G4MULTITHREADED
238  parser->AddCommand("-mt",
239  Command::WithOption,
240  "Launch in MT mode (events computed in parallel)",
241  "2");
242 #endif
243 
244  parser->AddCommand("-vis",
245  Command::WithOption,
246  "Select a visualization driver",
247  "OGL 600x600-0+0");
248 
249  parser->AddCommand("-novis",
250  Command::WithoutOption,
251  "Deactivate visualization when using GUI");
252 
253  G4String exec;
254  G4String path;
255  GetNameAndPathOfExecutable(argv,exec, path);
256 
257  parser->AddCommand("-out",
258  Command::OptionNotCompulsory,
259  "Output files",
260  exec);
261 
263  // If -h or --help is given in option : print help and exit
264  //
265  if (parser->Parse(argc, argv) != 0) // help is being printed
266  {
267  // if you are using ROOT, create a TApplication in this condition in order
268  // to print the help from ROOT as well
269  CommandLineParser::DeleteInstance();
270  std::exit(0);
271  }
272 
274  // Kill application if wrong argument in command line
275  //
276  if (parser->CheckIfNotHandledOptionsExists(argc, argv))
277  {
278  // if you are using ROOT, you should initialise your TApplication
279  // before this condition
280  abort();
281  }
282 }
void GetNameAndPathOfExecutable(char **argv, G4String &executable, G4String &path)
CommandLineParser * parser(0)
CommandLineParser* parser ( )

Referenced by main(), and Parse().