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

Main program of the B4d example. More...

#include "B4dDetectorConstruction.hh"
#include "B4dActionInitialization.hh"
#include "B4Analysis.hh"
#include "G4RunManager.hh"
#include "G4UImanager.hh"
#include "FTFP_BERT.hh"
#include "G4VisExecutive.hh"
#include "G4UIExecutive.hh"
#include "Randomize.hh"
#include "G4TScoreNtupleWriter.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Main program of the B4d example.

Definition in file exampleB4d.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 60 of file exampleB4d.cc.

References PrintUsage(), and session.

61 {
62  // Evaluate arguments
63  //
64  if ( argc > 7 ) {
65  PrintUsage();
66  return 1;
67  }
68 
69  G4String macro;
71 #ifdef G4MULTITHREADED
72  G4int nThreads = 0;
73 #endif
74  for ( G4int i=1; i<argc; i=i+2 ) {
75  if ( G4String(argv[i]) == "-m" ) macro = argv[i+1];
76  else if ( G4String(argv[i]) == "-u" ) session = argv[i+1];
77 #ifdef G4MULTITHREADED
78  else if ( G4String(argv[i]) == "-t" ) {
79  nThreads = G4UIcommand::ConvertToInt(argv[i+1]);
80  }
81 #endif
82  else {
83  PrintUsage();
84  return 1;
85  }
86  }
87 
88  // Detect interactive mode (if no macro provided) and define UI session
89  //
90  G4UIExecutive* ui = nullptr;
91  if ( ! macro.size() ) {
92  ui = new G4UIExecutive(argc, argv, session);
93  }
94 
95  // Optionally: choose a different Random engine...
96  //
97  // G4Random::setTheEngine(new CLHEP::MTwistEngine);
98 
99  // Construct the MT run manager
100  //
101 #ifdef G4MULTITHREADED
102  auto runManager = new G4MTRunManager;
103  if ( nThreads > 0 ) {
104  runManager->SetNumberOfThreads(nThreads);
105  }
106 #else
107  auto runManager = new G4RunManager;
108 #endif
109 
110  // Set mandatory initialization classes
111  //
112  auto detConstruction = new B4dDetectorConstruction();
113  runManager->SetUserInitialization(detConstruction);
114 
115  auto physicsList = new FTFP_BERT;
116  runManager->SetUserInitialization(physicsList);
117 
118  auto actionInitialization = new B4dActionInitialization();
119  runManager->SetUserInitialization(actionInitialization);
120 
121  // Initialize visualization
122  auto visManager = new G4VisExecutive;
123  // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
124  // G4VisManager* visManager = new G4VisExecutive("Quiet");
125  visManager->Initialize();
126 
127  // Get the pointer to the User Interface manager
128  auto UImanager = G4UImanager::GetUIpointer();
129 
130  // Activate score ntuple writer
131  // The Root output type (Root) is selected in B3Analysis.hh.
132  G4TScoreNtupleWriter<G4AnalysisManager> scoreNtupleWriter;
133  // The verbose level can be set via UI commands
134  // /score/ntuple/writerVerbose level
135  // or via the score ntuple writer function:
136  // scoreNtupleWriter.SetVerboseLevel(1);
137 
138  // Process macro or start UI session
139  //
140  if ( macro.size() ) {
141  // batch mode
142  G4String command = "/control/execute ";
143  UImanager->ApplyCommand(command+macro);
144  }
145  else {
146  // interactive mode : define UI session
147  UImanager->ApplyCommand("/control/execute init_vis.mac");
148  if (ui->IsGUI()) {
149  UImanager->ApplyCommand("/control/execute gui.mac");
150  }
151  ui->SessionStart();
152  delete ui;
153  }
154 
155  // Job termination
156  // Free the store: user actions, physics_list and detector_description are
157  // owned and deleted by the run manager, so they should not be deleted
158  // in the main() program !
159 
160  delete visManager;
161  delete runManager;
162 }
static G4UIterminal * session
void PrintUsage()