ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
chem3.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file chem3.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 // J. Comput. Phys. 274 (2014) 841-882
31 // The Geant4-DNA web site is available at http://geant4-dna.org
32 //
33 //
36 
37 #include "DetectorConstruction.hh"
38 #include "PhysicsList.hh"
39 #include "ActionInitialization.hh"
40 
41 #ifdef G4MULTITHREADED
42 #include "G4MTRunManager.hh"
43 #else
44 #include "G4RunManager.hh"
45 #endif
46 
47 #include "G4DNAChemistryManager.hh"
48 #include "G4UImanager.hh"
49 #include "G4UIExecutive.hh"
50 #include "G4VisExecutive.hh"
51 #ifdef G4UI_USE_QT
52 #include "G4UIQt.hh"
53 #endif
54 #include "CommandLineParser.hh"
55 
56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
57 
58 /*
59  * WARNING : Geant4 was initially not intended for this kind of application
60  * This code is delivered as a prototype
61  * We will be happy to hear from you, do not hesitate to send your feedback and
62  * communicate on the difficulties you may encounter
63  * The user interface may change in the next releases since a reiteration of the
64  * code has started
65  */
66 
67 using namespace G4DNAPARSER;
69 
70 void Parse(int& argc, char** argv);
71 
72 int main(int argc, char** argv)
73 {
75  // Parse options given in commandLine
76  //
77  Parse(argc, argv);
78 
80  // Construct the run manager according to whether MT is activated or not
81  //
82  Command* commandLine(0);
83 
84 #ifdef G4MULTITHREADED
85  G4RunManager* runManager(0);
86  if ((commandLine = parser->GetCommandIfActive("-mt")))
87  {
88  runManager = new G4MTRunManager;
89  int nThreads = 2;
90  const G4String& option = commandLine->GetOption();
91  if(option == "")
92  {
93  nThreads = G4UIcommand::ConvertToInt(commandLine->GetDefaultOption());
94  }
95  else if(option == "NMAX")
96  {
98  }
99  else
100  {
101  nThreads = G4UIcommand::ConvertToInt(option);
102  }
103 
104  G4cout << "===== Chem3 is started with "
105  << ((G4MTRunManager*) runManager)->GetNumberOfThreads()
106  << " threads =====" << G4endl;
107 
108  ((G4MTRunManager*) runManager)->SetNumberOfThreads(nThreads);
109  }
110  else
111  {
112  runManager = new G4RunManager();
113  }
114 #else
115  G4RunManager* runManager = new G4RunManager();
116 #endif
117 
119  // Set mandatory user initialization classes
120  //
122  runManager->SetUserInitialization(new PhysicsList);
123  runManager->SetUserInitialization(detector);
124  runManager->SetUserInitialization(new ActionInitialization());
125 
126  // Initialize G4 kernel
127  runManager->Initialize();
128 
129  // Initialize visualization
130  G4VisManager* visManager = new G4VisExecutive;
131  // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
132  // G4VisManager* visManager = new G4VisExecutive("Quiet");
133  visManager->Initialize();
134 
135  // Get the pointer to the User Interface manager
136  G4UImanager* UImanager = G4UImanager::GetUIpointer();
137  G4UIExecutive* ui(0);
138 
139  // interactive mode : define UI session
140  if ((commandLine = parser->GetCommandIfActive("-gui")))
141  {
142  ui = new G4UIExecutive(argc, argv, commandLine->GetOption());
143 
144  if (parser->GetCommandIfActive("-novis") == 0)
145  // visualization is used by default
146  {
147  if ((commandLine = parser->GetCommandIfActive("-vis")))
148  // select a visualization driver if needed (e.g. HepFile)
149  {
150  UImanager->ApplyCommand(
151  G4String("/vis/open ") + commandLine->GetOption());
152  }
153  else
154  // by default OGL is used
155  {
156  UImanager->ApplyCommand("/vis/open OGL 800x600-0+0");
157  }
158  UImanager->ApplyCommand("/control/execute vis.mac");
159  }
160 
161  if (ui->IsGUI()) UImanager->ApplyCommand("/control/execute gui.mac");
162  }
163  else
164  // to be use visualization file (= store the visualization into
165  // an external file:
166  // ASCIITree ; DAWNFILE ; HepRepFile ; VRML(1,2)FILE ; gMocrenFile ...
167  {
168  if ((commandLine = parser->GetCommandIfActive("-vis")))
169  {
170  UImanager->ApplyCommand(
171  G4String("/vis/open ") + commandLine->GetOption());
172  UImanager->ApplyCommand("/control/execute vis.mac");
173  }
174  }
175 
176  if ((commandLine = parser->GetCommandIfActive("-mac")))
177  {
178  G4String command = "/control/execute ";
179  UImanager->ApplyCommand(command + commandLine->GetOption());
180  }
181  else
182  {
183  UImanager->ApplyCommand("/control/execute beam.in");
184  }
185 
186  if ((commandLine = parser->GetCommandIfActive("-gui")))
187  {
188 #ifdef G4UI_USE_QT
189  G4UIQt* UIQt = static_cast<G4UIQt*> (UImanager->GetG4UIWindow());
190  if ( UIQt) {
191  UIQt->AddViewerTabFromFile("README", "README from "+ G4String(argv[0]));
192  }
193 #endif
194  ui->SessionStart();
195  delete ui;
196  }
197 
198  // Job termination
199  // Free the store: user actions, physics_list and detector_description are
200  // owned and deleted by the run manager, so they should not be deleted
201  // in the main() program !
202 
203  delete visManager;
204  delete runManager;
205 
207 
208  return 0;
209 }
210 
211 void Parse(int& argc, char** argv)
212 {
214  // Parse options given in commandLine
215  //
217 
220  "Select geant4 UI or just launch a geant4 terminal session", "qt");
221 
222  parser->AddCommand("-mac", Command::WithOption, "Give a mac file to execute",
223  "macFile.mac");
224 
225 // You cann your own command, as for instance:
226 // parser->AddCommand("-seed",
227 // Command::WithOption,
228 // "Give a seed value in argument to be tested", "seed");
229 // it is then up to you to manage this option
230 
231 #ifdef G4MULTITHREADED
233  "Launch in MT mode (events computed in parallel,"
234  " NOT RECOMMANDED WITH CHEMISTRY)",
235  "2");
236 #endif
237 
239  "Deactivate chemistry");
240 
242  "Select a visualization driver", "OGL 600x600-0+0");
243 
245  "Deactivate visualization when using GUI");
246 
248  // If -h or --help is given in option : print help and exit
249  //
250  if (parser->Parse(argc, argv) != 0) // help is being printed
251  {
252  // if you are using ROOT, create a TApplication in this condition in order
253  // to print the help from ROOT as well
255  std::exit(0);
256  }
257 
259  // Kill application if wrong argument in command line
260  //
261  if (parser->CheckIfNotHandledOptionsExists(argc, argv))
262  {
263  // if you are using ROOT, you should initialise your TApplication
264  // before this condition
265  abort();
266  }
267 }