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

Chem1 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

Chem1 example.

Definition in file chem1.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 70 of file chem1.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  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 }
void Parse(int &argc, char **argv)
Definition: chem1.cc:192
CommandLineParser * parser(0)
void Parse ( int &  argc,
char **  argv 
)

Definition at line 192 of file chem1.cc.

References parser().

Referenced by main().

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 }
CommandLineParser * parser(0)