Geant4  10.03
pdb4dna.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 // Delage et al. PDB4DNA: implementation of DNA geometry from the Protein Data
31 // Bank (PDB) description for Geant4-DNA Monte-Carlo
32 // simulations (submitted to Comput. Phys. Commun.)
33 // The Geant4-DNA web site is available at http://geant4-dna.org
34 //
35 // $Id$
36 //
39 
40 #include "DetectorConstruction.hh"
41 #include "PhysicsList.hh"
42 #include "ActionInitialization.hh"
43 
44 #ifdef G4MULTITHREADED
45 #include "G4MTRunManager.hh"
46 #else
47 #include "G4RunManager.hh"
48 #endif
49 
50 #include "G4UImanager.hh"
51 #include "Randomize.hh"
52 #include "G4VisExecutive.hh"
53 #include "G4UIExecutive.hh"
54 #include "G4UIQt.hh"
55 #include "CommandLineParser.hh"
56 
57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
58 
59 using namespace G4DNAPARSER;
61 
62 void Parse(int& argc, char** argv);
63 
64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
65 
66 int main(int argc,char** argv)
67 {
69  // Parse options given in commandLine
70  //
71  Parse(argc, argv);
72 
73  // Set the Seed
74  CLHEP::RanecuEngine defaultEngine(1234567);
75  G4Random::setTheEngine(&defaultEngine);
76 
77  // Choose the Random engine
78  //
79  CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine);
80 
82  // Construct the run manager according to whether MT is activated or not
83  //
84  Command* commandLine(0);
85 
86 #ifdef G4MULTITHREADED
87  G4MTRunManager* runManager= new G4MTRunManager;
88  if ((commandLine = parser->GetCommandIfActive("-mt")))
89  {
90  int nThreads = 2;
91  if(commandLine->GetOption() == "NMAX")
92  {
94  }
95  else
96  {
97  nThreads = G4UIcommand::ConvertToInt(commandLine->GetOption());
98  }
99  G4cout << "===== PDB4DNA is started with "
100  << runManager->GetNumberOfThreads()
101  << " threads =====" << G4endl;
102 
103  runManager->SetNumberOfThreads(nThreads);
104  }
105 #else
106  G4RunManager* runManager = new G4RunManager();
107 #endif
108 
109  // Set user classes
110  //
111  runManager->SetUserInitialization(new DetectorConstruction());
112  runManager->SetUserInitialization(new PhysicsList);
113  runManager->SetUserInitialization(new ActionInitialization());
114 
115  // Initialize G4 keRnel
116  //
117  // runManager->Initialize();
118 
119  // Initialize visualization
120  G4VisManager* visManager = new G4VisExecutive;
121  visManager->Initialize();
122 
123  // Get the pointer to the User Interface manager
124  G4UImanager* UImanager = G4UImanager::GetUIpointer();
125  G4UIExecutive* ui(0);
126 
127  // interactive mode : define UI session
128  if ((commandLine = parser->GetCommandIfActive("-gui")))
129  {
130  ui = new G4UIExecutive(argc, argv,
131  commandLine->GetOption());
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 600x600-0+0");
146  }
147  UImanager->ApplyCommand("/control/execute vis.mac");
148  }
149  if (ui->IsGUI())
150  UImanager->ApplyCommand("/control/execute gui.mac");
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 ")+
160  commandLine->GetOption());
161  UImanager->ApplyCommand("/control/execute vis.mac");
162  }
163  }
164 
165  if ((commandLine = parser->GetCommandIfActive("-mac")))
166  {
167  G4String command = "/control/execute ";
168  UImanager->ApplyCommand(command + commandLine->GetOption());
169  }
170  else
171  {
172  UImanager->ApplyCommand("/control/execute init.mac");
173  }
174 
175  if ((commandLine = parser->GetCommandIfActive("-gui")))
176  {
177 #ifdef G4UI_USE_QT
178  G4UIQt* UIQt = static_cast<G4UIQt*> (UImanager->GetG4UIWindow());
179  if ( UIQt) {
180  UIQt->AddViewerTabFromFile("README", "README from "+ G4String(argv[0]));
181  }
182 #endif
183  ui->SessionStart();
184  delete ui;
185  }
186 
187  // Job termination
188  delete visManager;
189  delete runManager;
190 
191  return 0;
192 }
193 
194 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
195 
196 void Parse(int& argc, char** argv)
197 {
199  // Parse options given in commandLine
200  //
202 
203  parser->AddCommand("-gui",
205  "Select geant4 UI or just launch a geant4 terminal session",
206  "qt");
207 
208  parser->AddCommand("-mac",
210  "Give a mac file to execute",
211  "pdb4dna.in");
212 
213 // You cann your own command, as for instance:
214 // parser->AddCommand("-seed",
215 // Command::WithOption,
216 // "Give a seed value in argument to be tested", "seed");
217 // it is then up to you to manage this option
218 
219 #ifdef G4MULTITHREADED
221  "Launch in MT mode (events computed in parallel)",
222  "2");
223 #endif
224 
225  parser->AddCommand("-vis",
227  "Select a visualization driver",
228  "OGL 600x600-0+0");
229 
230  parser->AddCommand("-novis",
232  "Deactivate visualization when using GUI");
233 
235  // If -h or --help is given in option : print help and exit
236  //
237  if (parser->Parse(argc, argv) != 0) // help is being printed
238  {
239  // if you are using ROOT, create a TApplication in this condition in order
240  // to print the help from ROOT as well
242  std::exit(0);
243  }
244 
246  // Kill application if wrong argument in command line
247  //
248  if (parser->CheckIfNotHandledOptionsExists(argc, argv))
249  {
250  // if you are using ROOT, you should initialise your TApplication
251  // before this condition
252  abort();
253  }
254 }
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)
int main(int argc, char **argv)
Definition: pdb4dna.cc:66
bool CheckIfNotHandledOptionsExists(int &argc, char **argv)
static CommandLineParser * GetParser()
void Parse(int &argc, char **argv)
Definition: pdb4dna.cc:196
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4GLOB_DLL std::ostream G4cout
G4int G4GetNumberOfCores()
Definition: G4Threading.cc:143
G4int GetNumberOfThreads() const
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:435
Action initialization class.
void Initialize()
G4UIsession * GetG4UIWindow() const
Definition: G4UImanager.hh:210
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()
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:446
Physics list class.
Definition: PhysicsList.hh:47