LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
chem1.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 // 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 
52 #include "CommandLineParser.hh"
53 
54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
55 
56 /*
57  * WARNING : Geant4 was initially not intended for this kind of application
58  * This code is delivered as a prototype
59  * We will be happy to hear from you, do not hesitate to send your feedback and
60  * communicate on the difficulties you may encounter
61  * The user interface may change in the next releases since a reiteration of the
62  * code has started
63  */
64 
65 using namespace G4DNAPARSER;
66 CommandLineParser* parser(0);
67 
68 void Parse(int& argc, char** argv);
69 
70 int main(int argc, char** argv)
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(nullptr);
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  {
89  nThreads = G4Threading::G4GetNumberOfCores();
90  }
91  else
92  {
93  nThreads = G4UIcommand::ConvertToInt(commandLine->GetOption());
94  }
95  G4cout << "===== Chem1 is started with " << nThreads
96  << " threads =====" << G4endl;
97 
98  runManager->SetNumberOfThreads(nThreads);
99  }
100 #else
101  G4RunManager* runManager = new G4RunManager();
102 #endif
103 
104 
106  // Set mandatory user initialization classes
107  //
108  DetectorConstruction* detector = new DetectorConstruction();
109  runManager->SetUserInitialization(new PhysicsList);
110  runManager->SetUserInitialization(detector);
111  runManager->SetUserInitialization(new ActionInitialization());
112 
113  // Initialize visualization
114  G4VisManager* visManager = nullptr;
115 
116  // Get the pointer to the User Interface manager
117  G4UImanager* UImanager = G4UImanager::GetUIpointer();
118  G4UIExecutive* ui(nullptr);
119 
120  // interactive mode : define UI session
121  if ((commandLine = parser->GetCommandIfActive("-gui")))
122  {
123  visManager = new G4VisExecutive;
124  visManager->Initialize();
125 
126  ui = new G4UIExecutive(argc, argv, commandLine->GetOption());
127 
128  if(parser->GetCommandIfActive("-novis") == 0)
129  {
130  // visualization is used by default
131  if((commandLine = parser->GetCommandIfActive("-vis")))
132  {
133  // select a visualization driver if needed (e.g. HepFile)
134  UImanager->ApplyCommand(G4String("/vis/open ")+
135  commandLine->GetOption());
136  }
137  else
138  {
139  // by default OGL is used
140  UImanager->ApplyCommand("/vis/open OGL 800x600-0+0");
141  }
142  UImanager->ApplyCommand("/control/execute vis.mac");
143  }
144 
145  if(ui->IsGUI())
146  {
147  UImanager->ApplyCommand("/control/execute gui.mac");
148  }
149  }
150  else if ((commandLine = parser->GetCommandIfActive("-vis")))
151  {
152  // to be use visualization file (= store the visualization into
153  // an external file:
154  // ASCIITree ; DAWNFILE ; HepRepFile ; VRML(1,2)FILE ; gMocrenFile ...
155  visManager = new G4VisExecutive;
156  visManager->Initialize();
157 
158  ui = new G4UIExecutive(argc, argv, commandLine->GetOption());
159  UImanager->ApplyCommand(G4String("/vis/open ")+commandLine->GetOption());
160  UImanager->ApplyCommand("/control/execute vis.mac");
161  }
162 
163  if ((commandLine = parser->GetCommandIfActive("-mac")))
164  {
165  G4String command = "/control/execute ";
166  UImanager->ApplyCommand(command + commandLine->GetOption());
167  }
168  else
169  {
170  UImanager->ApplyCommand("/control/execute beam.in");
171  }
172 
173  if(ui)
174  {
175  ui->SessionStart();
176  delete ui;
177  }
178 
179  // Job termination
180  // Free the store: user actions, physics_list and detector_description are
181  // owned and deleted by the run manager, so they should not be deleted
182  // in the main() program !
183 
184  delete visManager;
185  delete runManager;
186 
187  CommandLineParser::DeleteInstance();
188 
189  return 0;
190 }
191 
192 void Parse(int& argc, char** argv)
193 {
195  // Parse options given in commandLine
196  //
197  parser = CommandLineParser::GetParser();
198 
199  parser->AddCommand(
200  "-gui", Command::OptionNotCompulsory,
201  "Select geant4 UI or just launch a geant4 terminal session", "qt");
202 
203  parser->AddCommand("-mac", Command::WithOption, "Give a mac file to execute",
204  "macFile.mac");
205 
206 // You cann your own command, as for instance:
207 // parser->AddCommand("-seed",
208 // Command::WithOption,
209 // "Give a seed value in argument to be tested", "seed");
210 // it is then up to you to manage this option
211 
212 #ifdef G4MULTITHREADED
213  parser->AddCommand("-mt",
214  Command::WithOption,
215  "Launch in MT mode (events computed in parallel,"
216  " NOT RECOMMANDED WITH CHEMISTRY)", "2");
217 #endif
218 
219  parser->AddCommand("-chemOFF", Command::WithoutOption,
220  "Deactivate chemistry");
221 
222  parser->AddCommand("-vis", Command::WithOption,
223  "Select a visualization driver", "OGL 600x600-0+0");
224 
225  parser->AddCommand("-novis", Command::WithoutOption,
226  "Deactivate visualization when using GUI");
227 
229  // If -h or --help is given in option : print help and exit
230  //
231  if (parser->Parse(argc, argv) != 0) // help is being printed
232  {
233  // if you are using ROOT, create a TApplication in this condition in order
234  // to print the help from ROOT as well
235  CommandLineParser::DeleteInstance();
236  std::exit(0);
237  }
238 
240  // Kill application if wrong argument in command line
241  //
242  if (parser->CheckIfNotHandledOptionsExists(argc, argv))
243  {
244  // if you are using ROOT, you should initialise your TApplication
245  // before this condition
246  abort();
247  }
248 }
void Parse(int &argc, char **argv)
Definition: chem1.cc:192
CommandLineParser * parser(0)
int main(int argc, char **argv)
Definition: chem1.cc:70