Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
microdosimetry.cc
이 파일의 문서화 페이지로 가기
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 #include "G4Types.hh"
38 
39 #ifdef G4MULTITHREADED
40  #include "G4MTRunManager.hh"
41 #else
42  #include "G4RunManager.hh"
43 #endif
44 
45 #include "G4UImanager.hh"
46 #include "G4UIExecutive.hh"
47 #include "G4UIterminal.hh"
48 #include "G4UItcsh.hh"
49 #include "G4VisExecutive.hh"
50 #ifdef G4UI_USE_QT
51 #include "G4UIQt.hh"
52 #endif
53 
54 #include "ActionInitialization.hh"
55 #include "DetectorConstruction.hh"
56 #include "PhysicsList.hh"
57 #include "CommandLineParser.hh"
58 
59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
60 
61 using namespace G4DNAPARSER;
63 
64 void Parse(int& argc, char** argv);
65 
66 int main(int argc,char** argv)
67 {
68  // Choose the Random engine
69  G4Random::setTheEngine(new CLHEP::RanecuEngine);
70 
72  // Parse options given in commandLine
73  //
74  Parse(argc, argv);
75 
77  // Construct the run manager according to whether MT is activated or not
78  //
79  Command* commandLine(0);
80 
81 #ifdef G4MULTITHREADED
82  G4MTRunManager* runManager= new G4MTRunManager;
83  if ((commandLine = parser->GetCommandIfActive("-mt")))
84  {
85  int nThreads = 2;
86  if(commandLine->GetOption() == "NMAX")
87  {
89  }
90  else
91  {
92  nThreads = G4UIcommand::ConvertToInt(commandLine->GetOption());
93  }
94  G4cout << "===== Microdosimetry is started with "
95  << runManager->GetNumberOfThreads()
96  << " threads =====" << G4endl;
97 
98  runManager->SetNumberOfThreads(nThreads);
99  }
100 #else
101  G4RunManager* runManager = new G4RunManager();
102 #endif
103 
104  // Set mandatory user initialization classes
105 
107  runManager->SetUserInitialization(detector);
108 
109  runManager->SetUserInitialization(new PhysicsList);
110 
111  // User action initialization
112 
113  runManager->SetUserInitialization(new ActionInitialization());
114 
115  // Initialize G4 kernel
116 
117  runManager->Initialize();
118 
119  // Initialize visualization
120 
121  G4VisManager* visManager = new G4VisExecutive;
122  visManager->Initialize();
123 
124  // Get the pointer to the User Interface manager
125 
126  G4UImanager* UImanager = G4UImanager::GetUIpointer();
127  G4UIExecutive* ui(0);
128 
129  // interactive mode : define UI session
130 
131  if ((commandLine = parser->GetCommandIfActive("-gui")))
132  {
133  ui = new G4UIExecutive(argc, argv,
134  commandLine->GetOption());
135 
136  if(ui->IsGUI())
137  UImanager->ApplyCommand("/control/execute gui.mac");
138 
139  if(parser->GetCommandIfActive("-novis") == 0)
140  // visualization is used by default
141  {
142  if((commandLine = parser->GetCommandIfActive("-vis")))
143  // select a visualization driver if needed (e.g. HepFile)
144  {
145  UImanager->ApplyCommand(G4String("/vis/open ")+
146  commandLine->GetOption());
147  }
148  else
149  // by default OGL is used
150  {
151  UImanager->ApplyCommand("/vis/open OGL 800x600-0+0");
152  }
153  UImanager->ApplyCommand("/control/execute vis.mac");
154  }
155  }
156  else
157  // to be use visualization file (= store the visualization into
158  // an external file:
159  // ASCIITree ; DAWNFILE ; HepRepFile ; VRML(1,2)FILE ; gMocrenFile ...
160  {
161  if ((commandLine = parser->GetCommandIfActive("-vis")))
162  {
163  UImanager->ApplyCommand(G4String("/vis/open ")+commandLine->GetOption());
164  UImanager->ApplyCommand("/control/execute vis.mac");
165  }
166  }
167 
168  if ((commandLine = parser->GetCommandIfActive("-mac")))
169  {
170  G4String command = "/control/execute ";
171  UImanager->ApplyCommand(command + commandLine->GetOption());
172  }
173  else
174  {
175  UImanager->ApplyCommand("/control/execute microdosimetry.in");
176  }
177 
178  if ((commandLine = parser->GetCommandIfActive("-gui")))
179  {
180 #ifdef G4UI_USE_QT
181  G4UIQt* UIQt = static_cast<G4UIQt*> (UImanager->GetG4UIWindow());
182  if ( UIQt) {
183  UIQt->AddViewerTabFromFile("README", "README from "+ G4String(argv[0]));
184  }
185 #endif
186  ui->SessionStart();
187  delete ui;
188  }
189 
190  delete visManager;
191  delete runManager;
192 
193  return 0;
194 }
195 
196 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
197 
198 void GetNameAndPathOfExecutable(char** argv,
199  G4String& executable,
200  G4String& path)
201 {
202  // Get the last position of '/'
203  std::string aux(argv[0]);
204 
205  // get '/' or '\\' depending on unix/mac or windows.
206 #if defined(_WIN32) || defined(WIN32)
207  int pos = aux.rfind('\\');
208 #else
209  int pos = aux.rfind('/');
210 #endif
211 
212  // Get the path and the name
213  path = aux.substr(0, pos + 1);
214  executable = aux.substr(pos + 1);
215 }
216 
217 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
218 
219 void Parse(int& argc, char** argv)
220 {
222  // Parse options given in commandLine
223  //
225 
226  parser->AddCommand("-gui",
228  "Select geant4 UI or just launch a geant4 terminal session",
229  "qt");
230 
231  parser->AddCommand("-mac",
233  "Give a mac file to execute",
234  "macFile.mac");
235 
236 // You cann your own command, as for instance:
237 // parser->AddCommand("-seed",
238 // Command::WithOption,
239 // "Give a seed value in argument to be tested", "seed");
240 // it is then up to you to manage this option
241 
242 #ifdef G4MULTITHREADED
243  parser->AddCommand("-mt",
245  "Launch in MT mode (events computed in parallel)",
246  "2");
247 #endif
248 
249  parser->AddCommand("-vis",
251  "Select a visualization driver",
252  "OGL 600x600-0+0");
253 
254  parser->AddCommand("-novis",
256  "Deactivate visualization when using GUI");
257 
258  G4String exec;
259  G4String path;
260  GetNameAndPathOfExecutable(argv,exec, path);
261 
262  parser->AddCommand("-out",
264  "Output files",
265  exec);
266 
268  // If -h or --help is given in option : print help and exit
269  //
270  if (parser->Parse(argc, argv) != 0) // help is being printed
271  {
272  // if you are using ROOT, create a TApplication in this condition in order
273  // to print the help from ROOT as well
275  std::exit(0);
276  }
277 
279  // Kill application if wrong argument in command line
280  //
281  if (parser->CheckIfNotHandledOptionsExists(argc, argv))
282  {
283  // if you are using ROOT, you should initialise your TApplication
284  // before this condition
285  abort();
286  }
287 }
void Parse(int &argc, char **argv)
Definition: chem1.cc:193
virtual const G4String & GetOption()
void SetNumberOfThreads(G4int n)
static CommandLineParser * GetParser()
static const G4double pos
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:466
#define G4endl
Definition: G4ios.hh:61
G4UIsession * GetG4UIWindow() const
Definition: G4UImanager.hh:212
G4int G4GetNumberOfCores()
Definition: G4Threading.cc:127
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:73
G4int GetNumberOfThreads() const
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:449
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
CommandLineParser * parser(0)
int main(int argc, char **argv)
Definition: genwindef.cc:359
void GetNameAndPathOfExecutable(char **argv, G4String &executable, G4String &path)
Command * GetCommandIfActive(const G4String &marker)
G4GLOB_DLL std::ostream G4cout
void Initialize()
bool CheckIfNotHandledOptionsExists(int &argc, char **argv)
G4bool IsGUI() const
void AddCommand(const G4String &marker, Command::Type, const G4String &description="", const G4String &defaultOption="", const G4String &optionName="")
virtual void Initialize()
Simple detector construction with a box volume placed in a world.