Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
extensibleFactory.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: extensibleFactory.cc 106244 2017-11-02 01:58:00Z rhatcher $
31 //
32 // -------------------------------------------------------------
33 // extensibleFactory
34 //
35 // Application demonstrating the extensible physics list factory
36 //
37 // Author of hadronic/Hadr00/Hadr00.cc
38 // V.Ivanchenko, 20 June 2008 (as hadronic/Hadr00/Hadr00.cc)
39 // Author of examples/extended/physicslists/factory/factory.cc
40 // I. Hrivnacova, 2017-09-26
41 
42 // Modified from factory.cc
43 // R.Hatcher 2017-10-31
44 // copied from examples/extended/physicslists/factory
45 // modified to use alternative extensible physics list factory
46 //
47 // -------------------------------------------------------------
48 //
49 //
50 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
51 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
52 
53 #include "DetectorConstruction.hh"
54 #include "ActionInitialization.hh"
55 #include "PrimaryGeneratorAction.hh"
56 
57 #ifdef G4MULTITHREADED
58 #include "G4MTRunManager.hh"
59 #else
60 #include "G4RunManager.hh"
61 #endif
62 
64 // The following change is the _only_ required changed to move from
65 // the non-extensible factory to the exensible factory. All other changes
66 // relative to the "factory" example are there to demonstrate new features.
68 //non-extensible: #include "G4PhysListFactory.hh"
69 #include "G4PhysListFactoryAlt.hh"
70 //use this for drop-in replacement: using namespace g4alt;
71 
73 // headers needed to demonstrate new featues
75 
76 // allow ourselves to extend the short names for physics ctor addition/replace
77 // along the same lines as EMX, EMY, etc
78 #include "G4PhysListRegistry.hh"
79 
80 // allow ourselves to give the user extra info about available physics ctors
82 
83 // pull in a user defined physics list definition into the main program
84 // and register it with the factory (doesn't have to be the main program
85 // but the .o containing the declaration _must_ get linked/loaded)
86 #include "G4PhysListStamper.hh" // defines macro for factory registration
87 #include "MySpecialPhysList.hh"
89 
91 
92 #include "G4VModularPhysicsList.hh"
93 #include "G4UImanager.hh"
94 #include "Randomize.hh"
95 #include "G4VisExecutive.hh"
96 #include "G4UIExecutive.hh"
97 
98 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
99 
100 namespace {
101 
102  void PrintAvailable(G4int verbosity) {
103  G4cout << G4endl;
104  G4cout << "extensibleFactory: here are the available physics lists:"
105  << G4endl;
106  g4alt::G4PhysListFactory factory;
107  factory.PrintAvailablePhysLists();
108 
109  // if user asked for extra verbosity then print physics ctors as well
110  if ( verbosity > 1 ) {
111  G4cout << G4endl;
112  G4cout << "extensibleFactory: "
113  << "here are the available physics ctors that can be added:"
114  << G4endl;
115  G4PhysicsConstructorRegistry* g4pctorFactory =
117  g4pctorFactory->PrintAvailablePhysicsConstructors();
118  }
119  }
120 
121  void PrintUsage(G4int verbosity) {
122  G4cerr << " Usage: " << G4endl;
123  G4cerr << " extensibleFactory [-m macro ] [-p physList ]"
124  << " [-u UIsession] [-t nThreads]" << G4endl
125  << " [-v | --verbose] [-h | --help]" << G4endl;
126  G4cerr << " note: -t option is available only for multi-threaded mode."
127  << G4endl;
128  G4cerr << " note: -v can be repeated to increase verbosity." << G4endl;
129  G4cerr << G4endl;
130 
131  if (verbosity>0) PrintAvailable(verbosity);
132  }
133 
134 }
135 
136 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
137 
138 int main(int argc,char** argv)
139 {
140  // Evaluate arguments
141  //
142  if ( argc > 13 ) {
143  PrintUsage(0);
144  return 1;
145  }
146 
147  G4String macro;
149  G4String physListName;
150  char* physListNameEnv = 0;
151  G4String gdmlFileName;
152 #ifdef G4MULTITHREADED
153  G4int nofThreads = 0;
154 #endif
155  G4int verbosity = 0;
156 
157  for ( G4int i=1; i<argc; i=i+2 ) {
158  G4String g4argv(argv[i]); // convert only once
159  if ( g4argv == "-m" ) macro = argv[i+1];
160  else if ( g4argv == "-u" ) session = argv[i+1];
161  else if ( g4argv == "-p" ) physListName = argv[i+1];
162 #ifdef G4MULTITHREADED
163  else if ( g4argv == "-t" ) {
164  nofThreads = G4UIcommand::ConvertToInt(argv[i+1]);
165  }
166 #endif
167  else if ( g4argv == "-v" || g4argv == "--verbose" ) {
168  ++verbosity; // verbose flag doesn't take an argument
169  --i ; // don't increment argc by two, just the one
170  }
171  else if ( g4argv == "-h" || g4argv == "--help" ) {
172  PrintUsage(verbosity+1);
173  return 1;
174  }
175  else {
176  PrintUsage(0);
177  return 1;
178  }
179  }
180 
181  // Detect interactive mode (if no arguments) and define UI session
182  //
183  G4UIExecutive* ui = 0;
184  if ( ! macro.size() ) {
185  ui = new G4UIExecutive(argc, argv, session);
186  }
187 
188  // Choose the Random engine //choose the Random engine
189  G4Random::setTheEngine(new CLHEP::RanecuEngine());
190 
191  // Construct the run manager
192 #ifdef G4MULTITHREADED
193  G4MTRunManager * runManager = new G4MTRunManager();
194  if ( nofThreads > 0 ) {
195  runManager->SetNumberOfThreads(nofThreads);
196  }
197 #else
198  G4RunManager * runManager = new G4RunManager();
199 #endif
200 
201  // g4alt::G4PhysListFactoryAlt is the extensible factory
202  // including the G4PhysListFactoryAlt.hh header and the line:
203  // using namespace g4alt;
204  // would make this a drop-in replacement, but we'll list the explicit
205  // namespace here just for clarity
206  g4alt::G4PhysListFactory factory;
207  G4VModularPhysicsList* physList = nullptr;
208 
209  // Show how an alternative default list could be set
210  // but set the default to the normal default FTFP_BERT.
211  // This is what is used when no -p flag is given and $PHYSLIST
212  // is not defined in the environment.
213  G4String defaultPhysListName = "FTFP_BERT";
214  if ( verbosity > 0 ) {
215  G4cout << "extensibleFactory: SetDefaultReferencePhysList to '"
216  << defaultPhysListName << "' ('' = system default)"
217  << G4endl << G4endl;
218  }
219  factory.SetDefaultReferencePhysList(defaultPhysListName);
220 
221  // set a short name for G4RadioactiveDecayPhysics
223  plreg->AddPhysicsExtension("RADIO","G4RadioactiveDecayPhysics");
224  plreg->AddPhysicsExtension("MYPHYSICS","MyG4PhysicsPhysics");
225  if ( verbosity > 0 ) {
226  G4cout << "extensibleFactory: adding extensions" << G4endl
227  << " RADIO ===> G4RadioactiveDecayPhysics" << G4endl
228  << " MYPHYSICS ===> MyG4PhysicsPhysics" << G4endl
229  << G4endl;
230  }
231 
232  // Get Reference PhysicsList via its name, or if none given
233  // from environment varialb e$PHYSLIST, with fall back to a default
234  if ( physListName.size() ) {
235  if ( verbosity > 0 ) {
236  G4cout << "extensibleFactory: explicitly using '"
237  << physListName << "'" << G4endl;
238  }
239  physList = factory.GetReferencePhysList(physListName);
240  } else {
241  if ( verbosity > 0 ) {
242  G4cout << "extensibleFactory: no -p flag;"
243  << " using ReferencePhysList() ($PHYSLIST or default)" << G4endl;
244  }
245  physList = factory.ReferencePhysList();
246 
247  if ( ! physList ) {
248  // failed? get what the user set, but we couldn't find
249  physListNameEnv = getenv("PHYSLIST");
250  if ( physListNameEnv ) {
251  G4cout << "extensibleFactory: $PHYSLIST="
252  << physListNameEnv << G4endl;
253  }
254  }
255 
256  }
257 
258  // deal with failure to get what the user wanted
259  // print what they _could_ use
260  if ( ! physList ) {
261  G4cerr << "extensibleFactory: PhysicsList '"
262  << ( physListNameEnv ? physListNameEnv : physListName )
263  << "' was not available in g4alt::PhysListFactory." << G4endl;
264  PrintAvailable(verbosity);
265 
266  // if we can't get what the user asked for...
267  // don't go on to use something else, that's confusing
269  ED << "The factory for the physicslist ["
270  << ( physListNameEnv ? physListNameEnv : physListName )
271  << "] does not exist!"
272  << G4endl;
273  G4Exception("extensibleFactory",
274  "extensibleFactory001", FatalException, ED);
275  exit(42);
276  }
277 
278  // Set mandatory initialization classes
279  runManager->SetUserInitialization(new DetectorConstruction());
280  runManager->SetUserInitialization(physList);
281 
282  // set user action classes
283  ActionInitialization* actinit =
284  new ActionInitialization("extensibleFactory");
285  runManager->SetUserInitialization(actinit);
286 
287 // Initialize visualization
288  G4VisManager* visManager = new G4VisExecutive;
289  // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
290  // G4VisManager* visManager = new G4VisExecutive("Quiet");
291  visManager->Initialize();
292 
293  // Get the pointer to the User Interface manager
294  G4UImanager* UImanager = G4UImanager::GetUIpointer();
295 
296  if ( macro.size() ) {
297  // batch mode
298  G4String command = "/control/execute ";
299  UImanager->ApplyCommand(command+macro);
300  }
301  else {
302  // interactive mode : define UI session
303  UImanager->ApplyCommand("/control/execute init_vis.mac");
304  ui->SessionStart();
305  delete ui;
306  }
307 
308  // Job termination
309  // Free the store: user actions, physics_list and detector_description are
310  // owned and deleted by the run manager, so they should not be deleted
311  // in the main() program !
312 
313  delete visManager;
314  delete runManager;
315 }
316 
317 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void SetNumberOfThreads(G4int n)
static G4UIterminal * session
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:45
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:466
#define G4endl
Definition: G4ios.hh:61
static G4PhysicsConstructorRegistry * Instance()
static G4PhysListRegistry * Instance()
G4_DECLARE_PHYSLIST_FACTORY(MySpecialPhysList)
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:73
Definition: QBBC.hh:44
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
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
void Initialize()
G4VModularPhysicsList * ReferencePhysList()
G4VModularPhysicsList * GetReferencePhysList(const G4String &)
Simple detector construction with a box volume placed in a world.
void SetDefaultReferencePhysList(const G4String &name="")
void AddPhysicsExtension(G4String name, G4String procname)