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

Chem2 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

Chem2 example.

Definition in file chem2.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 70 of file chem2.cc.

References Parse(), and parser().

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  G4RunManager* runManager(nullptr);
84  if ((commandLine = parser->GetCommandIfActive("-mt")))
85  {
86  runManager = new G4MTRunManager();
87  int nThreads = 2;
88  const G4String& option = commandLine->GetOption();
89  if(option == "")
90  {
91  nThreads = G4UIcommand::ConvertToInt(commandLine->GetDefaultOption());
92  }
93  else if(option == "NMAX")
94  {
95  nThreads = G4Threading::G4GetNumberOfCores();
96  }
97  else
98  {
99  nThreads = G4UIcommand::ConvertToInt(option);
100  }
101 
102  G4cout << "===== Chem2 is started with " << nThreads
103  << " threads =====" << G4endl;
104 
105  ((G4MTRunManager*) runManager)->SetNumberOfThreads(nThreads);
106  }
107  else
108  {
109  runManager = new G4RunManager();
110  }
111 #else
112  G4RunManager* runManager = new G4RunManager();
113 #endif
114 
116  // Set mandatory user initialization classes
117  //
118  DetectorConstruction* detector = new DetectorConstruction();
119  runManager->SetUserInitialization(new PhysicsList);
120  runManager->SetUserInitialization(detector);
121  runManager->SetUserInitialization(new ActionInitialization());
122 
123  // Initialize visualization
124  G4VisManager* visManager = nullptr;
125 
126  // Get the pointer to the User Interface manager
127  G4UImanager* UImanager = G4UImanager::GetUIpointer();
128  G4UIExecutive* ui(nullptr);
129 
130  // interactive mode : define UI session
131  if ((commandLine = parser->GetCommandIfActive("-gui")))
132  {
133  visManager = new G4VisExecutive;
134  visManager->Initialize();
135 
136  ui = new G4UIExecutive(argc, argv, commandLine->GetOption());
137 
138  if(parser->GetCommandIfActive("-novis") == 0)
139  {
140  // visualization is used by default
141  if((commandLine = parser->GetCommandIfActive("-vis")))
142  {
143  // select a visualization driver if needed (e.g. HepFile)
144  UImanager->ApplyCommand(G4String("/vis/open ")+
145  commandLine->GetOption());
146  }
147  else
148  {
149  // by default OGL is used
150  UImanager->ApplyCommand("/vis/open OGL 800x600-0+0");
151  }
152  UImanager->ApplyCommand("/control/execute vis.mac");
153  }
154 
155  if(ui->IsGUI())
156  {
157  UImanager->ApplyCommand("/control/execute gui.mac");
158  }
159  }
160  else if ((commandLine = parser->GetCommandIfActive("-vis")))
161  {
162  // to be use visualization file (= store the visualization into
163  // an external file:
164  // ASCIITree ; DAWNFILE ; HepRepFile ; VRML(1,2)FILE ; gMocrenFile ...
165  visManager = new G4VisExecutive;
166  visManager->Initialize();
167 
168  ui = new G4UIExecutive(argc, argv, commandLine->GetOption());
169  UImanager->ApplyCommand(G4String("/vis/open ")+commandLine->GetOption());
170  UImanager->ApplyCommand("/control/execute vis.mac");
171  }
172 
173  if ((commandLine = parser->GetCommandIfActive("-mac")))
174  {
175  G4String command = "/control/execute ";
176  UImanager->ApplyCommand(command + commandLine->GetOption());
177  }
178  else
179  {
180  UImanager->ApplyCommand("/control/execute beam.in");
181  }
182 
183  if(ui)
184  {
185  ui->SessionStart();
186  delete ui;
187  }
188  // Job termination
189  // Free the store: user actions, physics_list and detector_description are
190  // owned and deleted by the run manager, so they should not be deleted
191  // in the main() program !
192 
193  delete visManager;
194  delete runManager;
195 
196  CommandLineParser::DeleteInstance();
197 
198  return 0;
199 }
void Parse(int &argc, char **argv)
Definition: chem2.cc:201
CommandLineParser * parser(0)
void Parse ( int &  argc,
char **  argv 
)

Definition at line 201 of file chem2.cc.

References parser().

Referenced by main().

202 {
204  // Parse options given in commandLine
205  //
206  parser = CommandLineParser::GetParser();
207 
208  parser->AddCommand("-gui",
209  Command::OptionNotCompulsory,
210  "Select geant4 UI or just launch a geant4 terminal session",
211  "qt");
212 
213  parser->AddCommand("-mac",
214  Command::WithOption,
215  "Give a mac file to execute",
216  "macFile.mac");
217 
218 // You cann your own command, as for instance:
219 // parser->AddCommand("-seed",
220 // Command::WithOption,
221 // "Give a seed value in argument to be tested", "seed");
222 // it is then up to you to manage this option
223 
224 #ifdef G4MULTITHREADED
225  parser->AddCommand("-mt", Command::OptionNotCompulsory,
226  "Launch in MT mode (events computed in parallel,"
227  " NOT RECOMMANDED WITH CHEMISTRY)",
228  "2");
229 #endif
230 
231  parser->AddCommand("-chemOFF",
232  Command::WithoutOption,
233  "Deactivate chemistry");
234 
235  parser->AddCommand("-vis",
236  Command::WithOption,
237  "Select a visualization driver",
238  "OGL 600x600-0+0");
239 
240  parser->AddCommand("-novis",
241  Command::WithoutOption,
242  "Deactivate visualization when using GUI");
243 
245  // If -h or --help is given in option : print help and exit
246  //
247  if (parser->Parse(argc, argv) != 0) // help is being printed
248  {
249  // if you are using ROOT, create a TApplication in this condition in order
250  // to print the help from ROOT as well
251  CommandLineParser::DeleteInstance();
252  std::exit(0);
253  }
254 
256  // Kill application if wrong argument in command line
257  //
258  if (parser->CheckIfNotHandledOptionsExists(argc, argv))
259  {
260  // if you are using ROOT, you should initialise your TApplication
261  // before this condition
262  abort();
263  }
264 }
CommandLineParser * parser(0)
CommandLineParser* parser ( )

Referenced by main(), and Parse().