geant4-B1-example  1.0
 All Classes Files Functions Variables Pages
exampleB1.cc
Go to the documentation of this file.
1 
4 
5 #ifdef G4MULTITHREADED
6 #include "G4MTRunManager.hh"
7 #else
8 #include "G4RunManager.hh"
9 #endif
10 
11 
12 #include "Randomize.hh"
13 #include "QBBC.hh" // physics list
14 
15 #include "G4VisExecutive.hh"
16 
17 #include "G4UImanager.hh" // User Interface manager
18 #include "G4UIExecutive.hh" // for command terminal or macro input.
19 
20 
21 
22 
23 /*!
24  @brief Main program of the B1 example
25 
26  we create a runManager either from G4RunManager or G4MTRunManager.
27  runManager will use objects for detector construction, phyiscs process,
28  and the user actions.
29 
30  we create a visManager.
31  we create a UImanager.
32 
33  use UImanager to start session.
34  when we finish, delete all the managers.
35 */
36 int main(int argc,char** argv)
37 {
38 
39 
40  // Detect interactive mode (if no arguments) and define UI session
41  G4UIExecutive* ui = 0;
42  if ( argc == 1 ) { ui = new G4UIExecutive(argc, argv); }
43 
44 
45 
46 
47  // Choose the Random engine
48  G4Random::setTheEngine(new CLHEP::RanecuEngine);
49 
50 
51 
52  // Construct the default run manager
53 #ifdef G4MULTITHREADED
54  G4MTRunManager* runManager = new G4MTRunManager;
55 #else
56  G4RunManager* runManager = new G4RunManager;
57 #endif
58 
59 
60 
61 
62  // Detector construction
63  runManager->SetUserInitialization(new B1DetectorConstruction());
64 
65 
66  // Physics list
67  G4VModularPhysicsList* physicsList = new QBBC;
68  physicsList->SetVerboseLevel(1);
69  // VerboseLevel is related to print out. We have 0 to 4 levels.
70  runManager->SetUserInitialization(physicsList);
71 
72 
73  // User action initialization
74  runManager->SetUserInitialization(new B1ActionInitialization());
75 
76 
77 
78 
79 
80 
81 
82  // Initialize visualization
83  //
84  G4VisManager* visManager = new G4VisExecutive;
85  // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
86  // G4VisManager* visManager = new G4VisExecutive("Quiet");
87  visManager->Initialize();
88  // and we need to delete visManager in the end.
89 
90 
91 
92 
93  // Get the pointer to the User Interface manager
94  G4UImanager* UImanager = G4UImanager::GetUIpointer();
95 
96  // Process macro or start UI session
97  if ( ! ui ) {
98  // batch mode
99  G4String command = "/control/execute ";
100  G4String fileName = argv[1];
101  UImanager->ApplyCommand(command+fileName); // takeing macro from command line.
102  }
103  else {
104 
105  // interactive mode
106  UImanager->ApplyCommand("/control/execute init_vis.mac");
107 
108  ui->SessionStart();
109  //
110  // then, we can type in command manually.
111  //
112  delete ui;
113  }
114 
115  // Job termination
116  // Free the store: user actions, physics_list and detector_description are
117  // owned and deleted by the run manager, so they should not be deleted
118  // in the main() program !
119 
120  delete visManager;
121  delete runManager;
122 }
123 
124 
Definition of the B1DetectorConstruction class.
Detector construction class to define materials and geometry.
Definition of the B1ActionInitialization class.
a top-level class to control all the other user action objects.
int main(int argc, char **argv)
Main program of the B1 example.
Definition: exampleB1.cc:36