Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
genericPL.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 "G4GenericPhysicsList.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 physListMacro ] [-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 physListMacro;
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" ) physListMacro = 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  // Get the pointer to the User Interface manager
129  G4UImanager* UImanager = G4UImanager::GetUIpointer();
130 
131  // Physics List
132  G4VModularPhysicsList* physList = nullptr;
133  if ( physListMacro.size() ) {
134  // via macro
135  physList = new G4GenericPhysicsList();
136  UImanager->ApplyCommand("/control/execute "+physListMacro);
137  }
138  else {
139  // from vector of physics cobstructor names
140  std::vector<G4String>* myConstructors = new std::vector<G4String>;
141 
142  myConstructors->push_back("G4EmStandardPhysics");
143  myConstructors->push_back("G4EmExtraPhysics");
144  myConstructors->push_back("G4DecayPhysics");
145  myConstructors->push_back("G4HadronElasticPhysics");
146  myConstructors->push_back("G4HadronPhysicsFTFP_BERT");
147  myConstructors->push_back("G4StoppingPhysics");
148  myConstructors->push_back("G4IonPhysics");
149  myConstructors->push_back("G4NeutronTrackingCut");
150 
151  physList = new G4GenericPhysicsList(myConstructors);
152  }
153 
154  // Set mandatory initialization classes
155  runManager->SetUserInitialization(new DetectorConstruction());
156  runManager->SetUserInitialization(physList);
157 
158  // set user action classes
159  runManager->SetUserInitialization(new ActionInitialization("genericPL"));
160 
161  // Initialize visualization
162  G4VisManager* visManager = new G4VisExecutive;
163  // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
164  // G4VisManager* visManager = new G4VisExecutive("Quiet");
165  visManager->Initialize();
166 
167  if ( macro.size() ) {
168  // batch mode
169  G4String command = "/control/execute ";
170  UImanager->ApplyCommand(command+macro);
171  }
172  else {
173  // interactive mode : define UI session
174  UImanager->ApplyCommand("/control/execute init_vis.mac");
175  ui->SessionStart();
176  delete ui;
177  }
178 
179  // Job termination
180  // Free the store: user actions, physics_list and detector_description are
181  // owned and deleted by the run manager, so they should not be deleted
182  // in the main() program !
183 
184  delete visManager;
185  delete runManager;
186 }
187 
188 //....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
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:73
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:449
TG4GenericPhysicsList< G4VModularPhysicsList > G4GenericPhysicsList
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.