G4OCCT 0.1.0
Geant4 interface to Open CASCADE Technology (OCCT) geometry definitions
Loading...
Searching...
No Matches
exampleB4c.cc
Go to the documentation of this file.
1// ********************************************************************
2// * License and Disclaimer *
3// * *
4// * The Geant4 software is copyright of the Copyright Holders of *
5// * the Geant4 Collaboration. It is provided under the terms and *
6// * conditions of the Geant4 Software License, included in the file *
7// * LICENSE and available at http://cern.ch/geant4/license . These *
8// * include a list of copyright holders. *
9// * *
10// * Neither the authors of this software system, nor their employing *
11// * institutes,nor the agencies providing financial support for this *
12// * work make any representation or warranty, express or implied, *
13// * regarding this software system or assume any liability for its *
14// * use. Please see the license in the file LICENSE and URL above *
15// * for the full disclaimer and the limitation of liability. *
16// * *
17// * This code implementation is the result of the scientific and *
18// * technical work of the GEANT4 collaboration. *
19// * By using, copying, modifying or distributing the software (or *
20// * any work based on the software) you agree to acknowledge its *
21// * use in resulting scientific publications, and indicate your *
22// * acceptance of all terms of the Geant4 Software license. *
23// ********************************************************************
24//
27
28#include "ActionInitialization.hh"
29#include "DetectorConstruction.hh"
30#include "FTFP_BERT.hh"
31
32#include "G4RunManagerFactory.hh"
33#include "G4SteppingVerbose.hh"
34#include "G4UIExecutive.hh"
35#include "G4UIcommand.hh"
36#include "G4UImanager.hh"
37#include "G4VisExecutive.hh"
38// #include "Randomize.hh"
39
40//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
41
42namespace {
43void PrintUsage() {
44 G4cerr << " Usage: " << G4endl;
45 G4cerr << " exampleB4c [-m macro ] [-u UIsession] [-t nThreads] [-vDefault]" << G4endl;
46 G4cerr << " note: -t option is available only for multi-threaded mode." << G4endl;
47}
48} // namespace
49
50//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
51
52int main(int argc, char** argv) {
53 // Evaluate arguments
54 //
55 if (argc > 7) {
56 PrintUsage();
57 return 1;
58 }
59
60 G4String macro;
61 G4String session;
62 G4bool verboseBestUnits = true;
63#ifdef G4MULTITHREADED
64 G4int nThreads = 0;
65#endif
66 for (G4int i = 1; i < argc; i = i + 2) {
67 if (G4String(argv[i]) == "-m")
68 macro = argv[i + 1];
69 else if (G4String(argv[i]) == "-u")
70 session = argv[i + 1];
71#ifdef G4MULTITHREADED
72 else if (G4String(argv[i]) == "-t") {
73 nThreads = G4UIcommand::ConvertToInt(argv[i + 1]);
74 }
75#endif
76 else if (G4String(argv[i]) == "-vDefault") {
77 verboseBestUnits = false;
78 --i; // this option is not followed with a parameter
79 } else {
80 PrintUsage();
81 return 1;
82 }
83 }
84
85 // Detect interactive mode (if no macro provided) and define UI session
86 //
87 G4UIExecutive* ui = nullptr;
88 if (!macro.size()) {
89 ui = new G4UIExecutive(argc, argv, session);
90 }
91
92 // Optionally: choose a different Random engine...
93 // G4Random::setTheEngine(new CLHEP::MTwistEngine);
94
95 // Use G4SteppingVerboseWithUnits
96 if (verboseBestUnits) {
97 G4int precision = 4;
98 G4SteppingVerbose::UseBestUnit(precision);
99 }
100
101 // Construct the default run manager
102 //
103 auto runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Default);
104#ifdef G4MULTITHREADED
105 if (nThreads > 0) {
106 runManager->SetNumberOfThreads(nThreads);
107 }
108#endif
109
110 // Set mandatory initialization classes
111 //
112 auto detConstruction = new B4c::DetectorConstruction();
113 runManager->SetUserInitialization(detConstruction);
114
115 auto physicsList = new FTFP_BERT(0); // 0: suppress physics-list verbosity
116 runManager->SetUserInitialization(physicsList);
117
118 auto actionInitialization = new B4c::ActionInitialization();
119 runManager->SetUserInitialization(actionInitialization);
120
121 // Initialize visualization in quiet mode to suppress driver-init noise in logs.
122 auto visManager = new G4VisExecutive("Quiet");
123 visManager->Initialize();
124
125 // Get the pointer to the User Interface manager
126 auto UImanager = G4UImanager::GetUIpointer();
127
128 // Process macro or start UI session
129 //
130 int exitCode = 0;
131 if (macro.size()) {
132 // batch mode
133 G4String command = "/control/execute ";
134 exitCode = UImanager->ApplyCommand(command + macro);
135 } else {
136 // interactive mode : define UI session
137 UImanager->ApplyCommand("/control/execute init_vis.mac");
138 if (ui->IsGUI()) {
139 UImanager->ApplyCommand("/control/execute gui.mac");
140 }
141 ui->SessionStart();
142 delete ui;
143 }
144
145 // Job termination
146 // Free the store: user actions, physics_list and detector_description are
147 // owned and deleted by the run manager, so they should not be deleted
148 // in the main() program !
149
150 delete visManager;
151 delete runManager;
152 return exitCode != 0 ? 1 : 0;
153}
154
155//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
Action initialization class.
int main(int argc, char **argv)
Definition exampleB4c.cc:52