Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
factory.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 //
28 //
29 //
30 // $Id: Hadr00.cc 106244 2017-09-26 01:58:00Z gcosmo $
31 //
32 // -------------------------------------------------------------
33 // GEANT4 Hadr00
34 //
35 // Application demonstrating Geant4 hadronic cross sections
36 //
37 // Author: V.Ivanchenko 20 June 2008
38 //
39 // Modified:
40 //
41 // -------------------------------------------------------------
42 //
43 //
44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
45 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
46 
47 #include "DetectorConstruction.hh"
48 #include "ActionInitialization.hh"
49 #include "PrimaryGeneratorAction.hh"
50 
51 #ifdef G4MULTITHREADED
52 #include "G4MTRunManager.hh"
53 #else
54 #include "G4RunManager.hh"
55 #endif
56 
57 #include "G4PhysListFactory.hh"
58 #include "G4VModularPhysicsList.hh"
59 #include "G4UImanager.hh"
60 #include "Randomize.hh"
61 #include "G4VisExecutive.hh"
62 #include "G4UIExecutive.hh"
63 
64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
65 
66 namespace {
67  void PrintUsage() {
68  G4cerr << " Usage: " << G4endl;
69  G4cerr << " factory [-m macro ] [-p physList ] [-u UIsession] [-t nThreads]" << G4endl;
70  G4cerr << " note: -t option is available only for multi-threaded mode." << G4endl;
71  G4cerr << G4endl;
72  }
73 }
74 
75 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
76 
77 int main(int argc,char** argv)
78 {
79  // Evaluate arguments
80  //
81  if ( argc > 9 ) {
82  PrintUsage();
83  return 1;
84  }
85 
86  G4String macro;
88  G4String physListName;
89  G4String gdmlFileName;
90 #ifdef G4MULTITHREADED
91  G4int nofThreads = 0;
92 #endif
93  for ( G4int i=1; i<argc; i=i+2 ) {
94  if ( G4String(argv[i]) == "-m" ) macro = argv[i+1];
95  else if ( G4String(argv[i]) == "-u" ) session = argv[i+1];
96  else if ( G4String(argv[i]) == "-p" ) physListName = argv[i+1];
97 #ifdef G4MULTITHREADED
98  else if ( G4String(argv[i]) == "-t" ) {
99  nofThreads = G4UIcommand::ConvertToInt(argv[i+1]);
100  }
101 #endif
102  else {
103  PrintUsage();
104  return 1;
105  }
106  }
107 
108  // Detect interactive mode (if no arguments) and define UI session
109  //
110  G4UIExecutive* ui = 0;
111  if ( ! macro.size() ) {
112  ui = new G4UIExecutive(argc, argv, session);
113  }
114 
115  // Choose the Random engine //choose the Random engine
116  G4Random::setTheEngine(new CLHEP::RanecuEngine());
117 
118  // Construct the run manager
119 #ifdef G4MULTITHREADED
120  G4MTRunManager * runManager = new G4MTRunManager();
121  if ( nofThreads > 0 ) {
122  runManager->SetNumberOfThreads(nofThreads);
123  }
124 #else
125  G4RunManager * runManager = new G4RunManager();
126 #endif
127 
128  // Physics list factory
129  G4PhysListFactory factory;
130  G4VModularPhysicsList* physList = nullptr;
131 
132  // Get physics list name
133  if ( ! physListName.size() ) {
134  // Physics List is defined via environment variable PHYSLIST
135  char* physListNameEnv = getenv("PHYSLIST");
136  if ( physListNameEnv ) {
137  physListName = G4String(physListNameEnv);
138  }
139  }
140 
141  // Check if the name is known to the factory
142  if ( physListName.size() && (! factory.IsReferencePhysList(physListName) ) ) {
143  G4cerr << "Physics list " << physListName
144  << " is not available in PhysListFactory." << G4endl;
145  physListName.clear();
146  }
147 
148  // If name is not defined use FTFP_BERT
149  if ( ! physListName.size() ) {
150  physListName = "FTFP_BERT";
151  }
152 
153  // Reference PhysicsList via its name
154  physList = factory.GetReferencePhysList(physListName);
155 
156  // Set mandatory initialization classes
157  runManager->SetUserInitialization(new DetectorConstruction());
158  runManager->SetUserInitialization(physList);
159 
160  // set user action classes
161  runManager->SetUserInitialization(new ActionInitialization("factory"));
162 
163 // Initialize visualization
164  G4VisManager* visManager = new G4VisExecutive;
165  // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
166  // G4VisManager* visManager = new G4VisExecutive("Quiet");
167  visManager->Initialize();
168 
169  // Get the pointer to the User Interface manager
170  G4UImanager* UImanager = G4UImanager::GetUIpointer();
171 
172  if ( macro.size() ) {
173  // batch mode
174  G4String command = "/control/execute ";
175  UImanager->ApplyCommand(command+macro);
176  }
177  else {
178  // interactive mode : define UI session
179  UImanager->ApplyCommand("/control/execute init_vis.mac");
180  ui->SessionStart();
181  delete ui;
182  }
183 
184  // Job termination
185  // Free the store: user actions, physics_list and detector_description are
186  // owned and deleted by the run manager, so they should not be deleted
187  // in the main() program !
188 
189  delete visManager;
190  delete runManager;
191 }
192 
193 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void SetNumberOfThreads(G4int n)
static G4UIterminal * session
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:466
#define G4endl
Definition: G4ios.hh:61
G4bool IsReferencePhysList(const G4String &)
G4VModularPhysicsList * GetReferencePhysList(const G4String &)
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:73
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:449
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
int main(int argc, char **argv)
Definition: genwindef.cc:359
G4GLOB_DLL std::ostream G4cerr
int G4int
Definition: G4Types.hh:78
void Initialize()
Simple detector construction with a box volume placed in a world.