ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
exampleB4d.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file exampleB4d.cc
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
29 
32 #include "B4Analysis.hh"
33 
34 #ifdef G4MULTITHREADED
35 #include "G4MTRunManager.hh"
36 #else
37 #include "G4RunManager.hh"
38 #endif
39 
40 #include "G4UImanager.hh"
41 #include "FTFP_BERT.hh"
42 #include "G4VisExecutive.hh"
43 #include "G4UIExecutive.hh"
44 #include "Randomize.hh"
45 #include "G4TScoreNtupleWriter.hh"
46 
47 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
48 
49 namespace {
50  void PrintUsage() {
51  G4cerr << " Usage: " << G4endl;
52  G4cerr << " exampleB4d [-m macro ] [-u UIsession] [-t nThreads]" << G4endl;
53  G4cerr << " note: -t option is available only for multi-threaded mode."
54  << G4endl;
55  }
56 }
57 
58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
59 
60 int main(int argc,char** argv)
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 }
163 
164 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....