LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
chem3.cc File Reference

Chem3 example. More...

#include "DetectorConstruction.hh"
#include "PhysicsList.hh"
#include "ActionInitialization.hh"
#include "G4RunManager.hh"
#include "G4DNAChemistryManager.hh"
#include "G4UImanager.hh"
#include "G4UIExecutive.hh"
#include "G4VisExecutive.hh"
#include "CommandLineParser.hh"

Go to the source code of this file.

Functions

CommandLineParser * parser (0)
 
void Parse (int &argc, char **argv)
 
int main (int argc, char **argv)
 

Detailed Description

Chem3 example.

Definition in file chem3.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 72 of file chem3.cc.

References Parse(), and parser().

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  {
97  nThreads = G4Threading::G4GetNumberOfCores();
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 
206  CommandLineParser::DeleteInstance();
207 
208  return 0;
209 }
void Parse(int &argc, char **argv)
Definition: chem3.cc:211
CommandLineParser * parser(0)
void Parse ( int &  argc,
char **  argv 
)

Definition at line 211 of file chem3.cc.

References parser().

Referenced by main().

212 {
214  // Parse options given in commandLine
215  //
216  parser = CommandLineParser::GetParser();
217 
218  parser->AddCommand(
219  "-gui", Command::OptionNotCompulsory,
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
232  parser->AddCommand("-mt", Command::OptionNotCompulsory,
233  "Launch in MT mode (events computed in parallel,"
234  " NOT RECOMMANDED WITH CHEMISTRY)",
235  "2");
236 #endif
237 
238  parser->AddCommand("-chemOFF", Command::WithoutOption,
239  "Deactivate chemistry");
240 
241  parser->AddCommand("-vis", Command::WithOption,
242  "Select a visualization driver", "OGL 600x600-0+0");
243 
244  parser->AddCommand("-novis", Command::WithoutOption,
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
254  CommandLineParser::DeleteInstance();
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 }
CommandLineParser * parser(0)
CommandLineParser* parser ( )

Referenced by main(), and Parse().