Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
neuron.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 // and papers
31 // M. Batmunkh et al. J Radiat Res Appl Sci 8 (2015) 498-507
32 // O. Belov et al. Physica Medica 32 (2016) 1510-1520
33 // The Geant4-DNA web site is available at http://geant4-dna.org
34 //
35 // -------------------------------------------------------------------
36 // November 2016
37 // -------------------------------------------------------------------
38 //
39 // $ID$
42 //
43 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
44 #include "G4Types.hh"
45 #ifdef G4MULTITHREADED
46  #include "G4MTRunManager.hh"
47 #else
48  #include "G4RunManager.hh"
49 #endif
50 #include "G4DNAChemistryManager.hh"
51 #include "G4Timer.hh"
52 #include "G4UImanager.hh"
53 #include "G4UIExecutive.hh"
54 #include "G4VisExecutive.hh"
55 #include "CommandLineParser.hh"
56 #include "ActionInitialization.hh"
57 #include "DetectorConstruction.hh"
58 #include "PhysicsList.hh"
59 
60 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
61 
62 using namespace std;
63 using namespace G4DNAPARSER;
65 
66 void Parse(int& argc, char** argv);
67 
68 int main(int argc,char** argv)
69 {
70 
71  // run time in Geant4
72  G4Timer *timer = new G4Timer();
73  timer->Start();
74 
75  // Choose the Random engine
76  G4Random::setTheEngine(new CLHEP::RanecuEngine);
77 
79  // Parse options given in commandLine
80  //
81  Parse(argc, argv);
82 
84  // Construct the run manager according to whether MT is activated or not
85  //
86  Command* commandLine(0);
87 
88 #ifdef G4MULTITHREADED
89  G4MTRunManager* runManager= new G4MTRunManager;
90  if ((commandLine = parser->GetCommandIfActive("-mt")))
91  {
92  int nThreads = 2;
93  if(commandLine->GetOption() == "NMAX")
94  {
96  }
97  else
98  {
99  nThreads = G4UIcommand::ConvertToInt(commandLine->GetOption());
100  }
101  G4cout << "===== neuron is started with "
102  << runManager->GetNumberOfThreads()
103  << " threads of MT MODE =====" << G4endl;
104 
105  runManager->SetNumberOfThreads(nThreads);
106  }
107 #else
108  G4RunManager* runManager = new G4RunManager();
109  G4cout << "===== neuron is started with "
110  << " SEQUENTIAL MODE =====" << G4endl;
111 #endif
112 
113  // Set mandatory user initialization classes
115  runManager->SetUserInitialization(detector);
116  runManager->SetUserInitialization(new PhysicsList);
117 
118  // User action initialization
119  runManager->SetUserInitialization(new ActionInitialization(detector));
120 
121  // Initialize G4 kernel
122  runManager->Initialize();
123 
124  // Initialize visualization
125  G4VisManager* visManager = new G4VisExecutive;
126  visManager->Initialize();
127 
128  // Get the pointer to the User Interface manager
129  G4UImanager* UImanager = G4UImanager::GetUIpointer();
130  G4UIExecutive* ui(0);
131 
132  // interactive mode : define UI session
133  if ((commandLine = parser->GetCommandIfActive("-gui")))
134  {
135  ui = new G4UIExecutive(argc, argv,
136  commandLine->GetOption());
137 
138  if(ui->IsGUI())
139  UImanager->ApplyCommand("/control/execute gui.mac");
140 
141  if(parser->GetCommandIfActive("-novis") == 0)
142  // visualization is used by default
143  {
144  if((commandLine = parser->GetCommandIfActive("-vis")))
145  // select a visualization driver if needed (e.g. HepFile)
146  {
147  UImanager->ApplyCommand(G4String("/vis/open ")+
148  commandLine->GetOption());
149  }
150  else
151  // by default OGL is used
152  {
153  UImanager->ApplyCommand("/vis/open OGL 800x600-0+0");
154  }
155  UImanager->ApplyCommand("/control/execute vis.mac");
156  }
157  }
158  else
159  // to be use visualization file (= store the visualization into
160  // an external file:
161  // ASCIITree ; DAWNFILE ; HepRepFile ; VRML(1,2)FILE ; gMocrenFile ...
162  {
163  if ((commandLine = parser->GetCommandIfActive("-vis")))
164  {
165  UImanager->ApplyCommand(G4String("/vis/open ")+commandLine->GetOption());
166  UImanager->ApplyCommand("/control/execute vis.mac");
167  }
168  }
169 
170  if ((commandLine = parser->GetCommandIfActive("-mac")))
171  {
172  G4String command = "/control/execute ";
173  UImanager->ApplyCommand(command + commandLine->GetOption());
174  }
175  else
176  {
177  UImanager->ApplyCommand("/control/execute "); //neuron.in
178  }
179 
180  if ((commandLine = parser->GetCommandIfActive("-gui")))
181  {
182  ui->SessionStart();
183  delete ui;
184  }
185 
186  // calculation time
187  timer->Stop();
188  G4cout << " Calculation time = "
189  << timer->GetRealElapsed() << " s \n"<< G4endl;
190 
191  delete visManager;
192  delete runManager;
193 
194  return 0;
195 }
196 
197 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
198 
199 void GetNameAndPathOfExecutable(char** argv,
200  G4String& executable,
201  G4String& path)
202 {
203  // Get the last position of '/'
204  std::string aux(argv[0]);
205 
206  // get '/' or '\\' depending on unix/mac or windows.
207 #if defined(_WIN32) || defined(WIN32)
208  int pos = aux.rfind('\\');
209 #else
210  int pos = aux.rfind('/');
211 #endif
212 
213  // Get the path and the name
214  path = aux.substr(0, pos + 1);
215  executable = aux.substr(pos + 1);
216 }
217 
218 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
219 
220 void Parse(int& argc, char** argv)
221 {
223  // Parse options given in commandLine
224  //
225  parser = CommandLineParser::GetParser();
226 
227  parser->AddCommand("-gui",
228  Command::OptionNotCompulsory,
229  "Select geant4 UI or just launch a geant4 terminal session",
230  "qt");
231 
232  parser->AddCommand("-mac",
233  Command::WithOption,
234  "Give a mac file to execute",
235  "macFile.mac");
236 
237 // You cann your own command, as for instance:
238 // parser->AddCommand("-seed",
239 // Command::WithOption,
240 // "Give a seed value in argument to be tested", "seed");
241 // it is then up to you to manage this option
242 
243 #ifdef G4MULTITHREADED
244  parser->AddCommand("-mt",
245  Command::WithOption,
246  "Launch in MT mode (events computed in parallel)",
247  " NOT RECOMMANDED WITH CHEMISTRY)",
248  "2");
249 #endif
250 
251  parser->AddCommand("-sXY", Command::OptionNotCompulsory,
252  "Initial beam position uniformly spread on a square!");
253  parser->AddCommand("-dXY", Command::OptionNotCompulsory,
254  "Initial beam position uniformly spread on a disk!");
255 
256  parser->AddCommand("-dnaliv", Command::OptionNotCompulsory,
257  "Activate Livermore + DNAPhysics");
258  parser->AddCommand("-dnachemON", Command::OptionNotCompulsory,
259  "Activate Livermore + DNAPhysics + DNAChemistry");
260  parser->AddCommand("-dnahad", Command::OptionNotCompulsory,
261  "Activate Hadronic + Livermore + DNAPhysics");
262 
263  parser->AddCommand("-swc",
264  Command::WithOption,
265  "Give a SWC file to simulation",
266  "fileName.swc");
267 
268  parser->AddCommand("-network",
269  Command::WithOption, //OptionNotCompulsory,
270  "Give a DAT file to simulation",
271  "fileName.dat");
272 
273  parser->AddCommand("-vis",
274  Command::WithOption,
275  "Select a visualization driver",
276  "OGL 600x600-0+0");
277 
278  parser->AddCommand("-novis",
279  Command::WithoutOption,
280  "Deactivate visualization when using GUI");
281 
282  G4String exec;
283  G4String path;
284  GetNameAndPathOfExecutable(argv,exec, path);
285 
286  parser->AddCommand("-out",
287  Command::OptionNotCompulsory,
288  "Output files",
289  exec);
290 
292  // If -h or --help is given in option : print help and exit
293  //
294  if (parser->Parse(argc, argv) != 0) // help is being printed
295  {
296  // if you are using ROOT, create a TApplication in this condition in order
297  // to print the help from ROOT as well
298  CommandLineParser::DeleteInstance();
299  std::exit(0);
300  }
301 
303  // Kill application if wrong argument in command line
304  //
305  if (parser->CheckIfNotHandledOptionsExists(argc, argv))
306  {
307  // if you are using ROOT, you should initialise your TApplication
308  // before this condition
309  abort();
310  }
311 }
void Parse(int &argc, char **argv)
Definition: chem1.cc:193
G4double GetRealElapsed() const
Definition: G4Timer.cc:122
virtual const G4String & GetOption()
void SetNumberOfThreads(G4int n)
static const G4double pos
void Start()
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:466
#define G4endl
Definition: G4ios.hh:61
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)
void Stop()
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.