Geant4  10.01.p02
microdosimetry.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 // The Geant4-DNA web site is available at http://geant4-dna.org
31 //
32 // $ID$
35 //
36 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
37 
38 #ifdef G4MULTITHREADED
39  #include "G4MTRunManager.hh"
40 #else
41  #include "G4RunManager.hh"
42 #endif
43 
44 #include "G4UImanager.hh"
45 #include "G4UIExecutive.hh"
46 #include "G4UIterminal.hh"
47 #include "G4UItcsh.hh"
48 #include "G4VisExecutive.hh"
49 
50 #include "ActionInitialization.hh"
51 #include "DetectorConstruction.hh"
52 #include "PhysicsList.hh"
53 #include "CommandLineParser.hh"
54 #include "G4UIQt.hh"
55 
56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
57 
58 using namespace G4DNAPARSER;
60 
61 void Parse(int& argc, char** argv);
62 
63 int main(int argc,char** argv)
64 {
65  // Choose the Random engine
66 
67  G4Random::setTheEngine(new CLHEP::RanecuEngine);
68 
70  // Parse options given in commandLine
71  //
72  Parse(argc, argv);
73 
75  // Construct the run manager according to whether MT is activated or not
76  //
77  Command* commandLine(0);
78 
79 #ifdef G4MULTITHREADED
80  G4MTRunManager* runManager= new G4MTRunManager;
81  if ((commandLine = parser->GetCommandIfActive("-mt")))
82  {
83  int nThreads = 2;
84  if(commandLine->GetOption() == "NMAX")
85  {
87  }
88  else
89  {
90  nThreads = G4UIcommand::ConvertToInt(commandLine->GetOption());
91  }
92  G4cout << "===== Microdosimetry is started with "
93  << runManager->GetNumberOfThreads()
94  << " threads =====" << G4endl;
95 
96  runManager->SetNumberOfThreads(nThreads);
97  }
98 #else
99  G4RunManager* runManager = new G4RunManager();
100 #endif
101 
102  // Set mandatory user initialization classes
104  runManager->SetUserInitialization(detector);
105 
106  runManager->SetUserInitialization(new PhysicsList);
107 
108  // User action initialization
109 
110  runManager->SetUserInitialization(new ActionInitialization());
111 
112  // Initialize G4 kernel
113 
114  runManager->Initialize();
115 
116  // Initialize visualization
117  G4VisManager* visManager = new G4VisExecutive;
118  // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
119  // G4VisManager* visManager = new G4VisExecutive("Quiet");
120  visManager->Initialize();
121 
122  // Get the pointer to the User Interface manager
123  G4UImanager* UImanager = G4UImanager::GetUIpointer();
124  G4UIExecutive* ui(0);
125 
126  // interactive mode : define UI session
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 }
191 
192 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
193 
194 void GetNameAndPathOfExecutable(char** argv,
195  G4String& executable,
196  G4String& path)
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 }
212 
213 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
214 
215 void Parse(int& argc, char** argv)
216 {
218  // Parse options given in commandLine
219  //
221 
222  parser->AddCommand("-gui",
224  "Select geant4 UI or just launch a geant4 terminal session",
225  "qt");
226 
227  parser->AddCommand("-mac",
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",
241  "Launch in MT mode (events computed in parallel)",
242  "2");
243 #endif
244 
245  parser->AddCommand("-vis",
247  "Select a visualization driver",
248  "OGL 600x600-0+0");
249 
250  parser->AddCommand("-novis",
252  "Deactivate visualization when using GUI");
253 
254  G4String exec;
255  G4String path;
256  GetNameAndPathOfExecutable(argv,exec, path);
257 
258  parser->AddCommand("-out",
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
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 }
284 
285 
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
int Parse(int &argc, char **argv)
void SetNumberOfThreads(G4int n)
void AddCommand(const G4String &marker, Command::Type, const G4String &description="", const G4String &defaultOption="", const G4String &optionName="")
Command * GetCommandIfActive(const G4String &marker)
bool CheckIfNotHandledOptionsExists(int &argc, char **argv)
static CommandLineParser * GetParser()
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4GLOB_DLL std::ostream G4cout
G4int G4GetNumberOfCores()
Definition: G4Threading.cc:126
G4int GetNumberOfThreads() const
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:435
void Parse(int &argc, char **argv)
Action initialization class.
void Initialize()
void GetNameAndPathOfExecutable(char **argv, G4String &executable, G4String &path)
G4UIsession * GetG4UIWindow() const
Definition: G4UImanager.hh:210
virtual void Initialize()
Detector construction class to demonstrate various ways of placement.
#define G4endl
Definition: G4ios.hh:61
G4bool IsGUI() const
CommandLineParser * parser(0)
virtual const G4String & GetOption()
int main(int argc, char **argv)
static const G4double pos
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:432