Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
exampleGB01.cc
Go to the documentation of this file.
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 //
28 //
29 // $Id: $
30 //
31 
32 #ifdef G4MULTITHREADED
33 #include "G4MTRunManager.hh"
34 #else
35 #include "G4RunManager.hh"
36 #endif
38 
39 #include "G4UImanager.hh"
40 
43 
44 #include "FTFP_BERT.hh"
46 
47 #ifdef G4VIS_USE
48 #include "G4VisExecutive.hh"
49 #endif
50 
51 #ifdef G4UI_USE
52 #include "G4UIExecutive.hh"
53 #endif
54 
55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
56 
57 namespace {
58  void PrintUsage() {
59  G4cerr << " Usage: " << G4endl;
60  G4cerr << " ./exampleGB01 [-m macro ] "
61  << " [-b biasing {'on','off'}]"
62  << "\n or\n ./exampleGB01 [macro.mac]"
63  << G4endl;
64  }
65 }
66 
67 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
68 
69 int main(int argc,char** argv)
70 {
71  // Evaluate arguments
72  //
73  if ( argc > 5 ) {
74  PrintUsage();
75  return 1;
76  }
77 
78  G4String macro("");
79  G4String onOffBiasing("");
80  if ( argc == 2 ) macro = argv[1];
81  else
82  {
83  for ( G4int i=1; i<argc; i=i+2 )
84  {
85  if ( G4String(argv[i]) == "-m" ) macro = argv[i+1];
86  else if ( G4String(argv[i]) == "-b" ) onOffBiasing = argv[i+1];
87  else
88  {
89  PrintUsage();
90  return 1;
91  }
92  }
93  }
94 
95  if ( onOffBiasing == "" ) onOffBiasing = "on";
96 
97  // -- Construct the run manager : MT or sequential one
98 #ifdef G4MULTITHREADED
99  G4MTRunManager * runManager = new G4MTRunManager;
100  G4cout << " ********** Run Manager constructed in MT mode ************ " << G4endl;
101  // -- Choose 4 threads:
102  runManager->SetNumberOfThreads(4);
103 #else
104  G4RunManager * runManager = new G4RunManager;
105  G4cout << " ********** Run Manager constructed in sequential mode ************ " << G4endl;
106 #endif
107 
108  // -- Set mandatory initialization classes
110  runManager->SetUserInitialization(detector);
111  // -- Select a physics list:
112  FTFP_BERT* physicsList = new FTFP_BERT;
113  // -- and augment it with biasing facilities:
114  G4GenericBiasingPhysics* biasingPhysics = new G4GenericBiasingPhysics();
115  if ( onOffBiasing == "on" )
116  {
117  biasingPhysics->Bias("gamma");
118  biasingPhysics->Bias("neutron");
119  biasingPhysics->Bias("kaon0L");
120  biasingPhysics->Bias("kaon0S");
121  physicsList->RegisterPhysics(biasingPhysics);
122  G4cout << " ********************************************************* " << G4endl;
123  G4cout << " ********** processes are wrapped for biasing ************ " << G4endl;
124  G4cout << " ********************************************************* " << G4endl;
125  }
126  else
127  {
128  G4cout << " ************************************************* " << G4endl;
129  G4cout << " ********** processes are not wrapped ************ " << G4endl;
130  G4cout << " ************************************************* " << G4endl;
131  }
132  runManager->SetUserInitialization(physicsList);
133  // -- Action initialization:
135 
136  // Initialize G4 kernel
137  runManager->Initialize();
138 
139 
140 #ifdef G4VIS_USE
141  // Initialize visualization
142  G4VisManager* visManager = new G4VisExecutive;
143  // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
144  visManager->Initialize();
145 #endif
146 
147  // Get the pointer to the User Interface manager
148  G4UImanager* UImanager = G4UImanager::GetUIpointer();
149 
150  if ( macro != "" ) // batch mode
151  {
152  G4String command = "/control/execute ";
153  UImanager->ApplyCommand(command+macro);
154  }
155  else
156  { // interactive mode : define UI session
157 #ifdef G4UI_USE
158  G4UIExecutive* ui = new G4UIExecutive(argc, argv);
159 #ifdef G4VIS_USE
160  // UImanager->ApplyCommand("/control/execute vis.mac");
161 #endif
162  // if (ui->IsGUI())
163  // UImanager->ApplyCommand("/control/execute gui.mac");
164  ui->SessionStart();
165  delete ui;
166 #endif
167  }
168 
169 #ifdef G4VIS_USE
170  delete visManager;
171 #endif
172  delete runManager;
173 
174  return 0;
175 }
176 
177 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
void SetNumberOfThreads(G4int n)
Definition of the GB01DetectorConstruction class.
int main(int argc, char **argv)
Definition: genwindef.cpp:30
int G4int
Definition: G4Types.hh:78
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:59
G4GLOB_DLL std::ostream G4cout
void Initialize()
Definition of the GB01PrimaryGeneratorAction class.
TFTFP_BERT< G4VModularPhysicsList > FTFP_BERT
Definition: FTFP_BERT.hh:63
virtual void Initialize()
#define G4endl
Definition: G4ios.hh:61
Definition of the GB01ActionInitialization class.
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:447
G4GLOB_DLL std::ostream G4cerr
void Bias(const G4String &particleName)