Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
wholeNuclearDNA.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 
70  G4Random::setTheEngine(new CLHEP::RanecuEngine);
71 
73  // Parse options given in commandLine
74  //
75  Parse(argc, argv);
76 
78  // Construct the run manager according to whether MT is activated or not
79  //
80  Command* commandLine(0);
81 
82 #ifdef G4MULTITHREADED
83  G4MTRunManager* runManager= new G4MTRunManager;
84  if ((commandLine = parser->GetCommandIfActive("-mt")))
85  {
86  int nThreads = 2;
87  if(commandLine->GetOption() == "NMAX")
88  {
90  }
91  else
92  {
93  nThreads = G4UIcommand::ConvertToInt(commandLine->GetOption());
94  }
95  G4cout << "===== WholeNuclearDNA is started with "
96  << runManager->GetNumberOfThreads()
97  << " threads =====" << G4endl;
98 
99  runManager->SetNumberOfThreads(nThreads);
100  }
101 #else
102  G4RunManager* runManager = new G4RunManager();
103 #endif
104 
105  // Set mandatory user initialization classes
107  runManager->SetUserInitialization(detector);
108  runManager->SetUserInitialization(new PhysicsList);
109  runManager->SetUserInitialization(new ActionInitialization());
110 
111  // Initialize G4 kernel
112  runManager->Initialize();
113 
114  // Initialize visualization
115  G4VisManager* visManager = new G4VisExecutive;
116  // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
117  // G4VisManager* visManager = new G4VisExecutive("Quiet");
118  visManager->Initialize();
119 
120  // Get the pointer to the User Interface manager
121  G4UImanager* UImanager = G4UImanager::GetUIpointer();
122  G4UIExecutive* ui(0);
123 
124  // interactive mode : define UI session
125  if ((commandLine = parser->GetCommandIfActive("-gui")))
126  {
127  ui = new G4UIExecutive(argc, argv,
128  commandLine->GetOption());
129 
130  if(ui->IsGUI())
131  UImanager->ApplyCommand("/control/execute gui.mac");
132 
133  if(parser->GetCommandIfActive("-novis") == 0)
134  // visualization is used by default
135  {
136  if((commandLine = parser->GetCommandIfActive("-vis")))
137  // select a visualization driver if needed (e.g. HepFile)
138  {
139  UImanager->ApplyCommand(G4String("/vis/open ")+
140  commandLine->GetOption());
141  }
142  else
143  // by default OGL is used
144  {
145  UImanager->ApplyCommand("/vis/open OGL 800x600-0+0");
146  }
147  UImanager->ApplyCommand("/control/execute vis.mac");
148  }
149  }
150  else
151  // to be use visualization file (= store the visualization into
152  // an external file:
153  // ASCIITree ; DAWNFILE ; HepRepFile ; VRML(1,2)FILE ; gMocrenFile ...
154  {
155  if ((commandLine = parser->GetCommandIfActive("-vis")))
156  {
157  UImanager->ApplyCommand(G4String("/vis/open ")+commandLine->GetOption());
158  UImanager->ApplyCommand("/control/execute vis.mac");
159  }
160  }
161 
162  if ((commandLine = parser->GetCommandIfActive("-mac")))
163  {
164  G4String command = "/control/execute ";
165  UImanager->ApplyCommand(command + commandLine->GetOption());
166  }
167  else
168  {
169  UImanager->ApplyCommand("/control/execute wholeNuclearDNA.in");
170  }
171 
172  if ((commandLine = parser->GetCommandIfActive("-gui")))
173  {
174 #ifdef G4UI_USE_QT
175  G4UIQt* UIQt = static_cast<G4UIQt*> (UImanager->GetG4UIWindow());
176  if ( UIQt) {
177  UIQt->AddViewerTabFromFile("README", "README from "+ G4String(argv[0]));
178  }
179 #endif
180  ui->SessionStart();
181  delete ui;
182  }
183 
184  delete visManager;
185  delete runManager;
186 
187  return 0;
188 }
189 
190 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
191 
192 void GetNameAndPathOfExecutable(char** argv,
193  G4String& executable,
194  G4String& path)
195 {
196  // Get the last position of '/'
197  std::string aux(argv[0]);
198 
199  // get '/' or '\\' depending on unix/mac or windows.
200 #if defined(_WIN32) || defined(WIN32)
201  int pos = aux.rfind('\\');
202 #else
203  int pos = aux.rfind('/');
204 #endif
205 
206  // Get the path and the name
207  path = aux.substr(0, pos + 1);
208  executable = aux.substr(pos + 1);
209 }
210 
211 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
212 
213 void Parse(int& argc, char** argv)
214 {
216  // Parse options given in commandLine
217  //
219 
220  parser->AddCommand("-gui",
222  "Select geant4 UI or just launch a geant4 terminal session",
223  "qt");
224 
225  parser->AddCommand("-mac",
227  "Give a mac file to execute",
228  "macFile.mac");
229 
230 // You cann your own command, as for instance:
231 // parser->AddCommand("-seed",
232 // Command::WithOption,
233 // "Give a seed value in argument to be tested", "seed");
234 // it is then up to you to manage this option
235 
236 #ifdef G4MULTITHREADED
237  parser->AddCommand("-mt",
239  "Launch in MT mode (events computed in parallel)",
240  "2");
241 #endif
242 
243  parser->AddCommand("-vis",
245  "Select a visualization driver",
246  "OGL 600x600-0+0");
247 
248  parser->AddCommand("-novis",
250  "Deactivate visualization when using GUI");
251 
252  G4String exec;
253  G4String path;
254  GetNameAndPathOfExecutable(argv, exec, path);
255 
256  parser->AddCommand("-out",
258  "Output files (ROOT is used by default)",
259  exec);
260 
262  // If -h or --help is given in option : print help and exit
263  //
264  if (parser->Parse(argc, argv) != 0) // help is being printed
265  {
266  // if you are using ROOT, create a TApplication in this condition in order
267  // to print the help from ROOT as well
269  std::exit(0);
270  }
271 
273  // Kill application if wrong argument in command line
274  //
275  if (parser->CheckIfNotHandledOptionsExists(argc, argv))
276  {
277  // if you are using ROOT, you should initialise your TApplication
278  // before this condition
279  abort();
280  }
281 }
282 
283 
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.