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

Implementation of the microdosimetry example. More...

#include "G4Types.hh"
#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"

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 194 of file microdosimetry.cc.

Referenced by Parse().

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

Definition at line 65 of file microdosimetry.cc.

References Parse(), and parser().

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

Definition at line 215 of file microdosimetry.cc.

References GetNameAndPathOfExecutable(), and parser().

Referenced by main().

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

Referenced by main(), and Parse().