File indexing completed on 2025-02-23 09:22:38
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052 #include "ActionInitialization.hh"
0053 #include "DetectorConstruction.hh"
0054 #include "PrimaryGeneratorAction.hh"
0055
0056 #include "G4RunManagerFactory.hh"
0057
0058
0059
0060
0061
0062
0063
0064 #include "G4PhysListFactoryAlt.hh"
0065
0066
0067
0068
0069
0070
0071
0072
0073 #include "G4PhysListRegistry.hh"
0074
0075
0076 #include "G4PhysicsConstructorFactory.hh"
0077
0078
0079
0080
0081 #include "MySpecialPhysList.hh"
0082
0083 #include "G4PhysListStamper.hh" // defines macro for factory registration
0084 G4_DECLARE_PHYSLIST_FACTORY(MySpecialPhysList);
0085
0086
0087
0088 #include "G4UIExecutive.hh"
0089 #include "G4UImanager.hh"
0090 #include "G4VModularPhysicsList.hh"
0091 #include "G4VisExecutive.hh"
0092 #include "Randomize.hh"
0093
0094
0095
0096 namespace
0097 {
0098
0099 void PrintAvailable(G4int verbosity)
0100 {
0101 G4cout << G4endl;
0102 G4cout << "extensibleFactory: here are the available physics lists:" << G4endl;
0103 g4alt::G4PhysListFactory factory;
0104 factory.PrintAvailablePhysLists();
0105
0106
0107 if (verbosity > 1) {
0108 G4cout << G4endl;
0109 G4cout << "extensibleFactory: "
0110 << "here are the available physics ctors that can be added:" << G4endl;
0111 G4PhysicsConstructorRegistry* g4pctorFactory = G4PhysicsConstructorRegistry::Instance();
0112 g4pctorFactory->PrintAvailablePhysicsConstructors();
0113 }
0114 }
0115
0116 void PrintUsage(G4int verbosity)
0117 {
0118 G4cerr << " Usage: " << G4endl;
0119 G4cerr << " extensibleFactory [-m macro ] [-p physList ]"
0120 << " [-u UIsession] [-t nThreads]" << G4endl << " [-v | --verbose] [-h | --help]"
0121 << G4endl;
0122 G4cerr << " note: -t option is available only for multi-threaded mode." << G4endl;
0123 G4cerr << " note: -v can be repeated to increase verbosity." << G4endl;
0124 G4cerr << G4endl;
0125
0126 if (verbosity > 0) PrintAvailable(verbosity);
0127 }
0128
0129 }
0130
0131
0132
0133 int main(int argc, char** argv)
0134 {
0135
0136
0137 if (argc > 13) {
0138 PrintUsage(0);
0139 return 1;
0140 }
0141
0142 G4String macro;
0143 G4String session;
0144 G4String physListName;
0145 char* physListNameEnv = nullptr;
0146 G4String gdmlFileName;
0147 #ifdef G4MULTITHREADED
0148 G4int nofThreads = 0;
0149 #endif
0150 G4int verbosity = 0;
0151
0152 for (G4int i = 1; i < argc; i = i + 2) {
0153 G4String g4argv(argv[i]);
0154 if (g4argv == "-m")
0155 macro = argv[i + 1];
0156 else if (g4argv == "-u")
0157 session = argv[i + 1];
0158 else if (g4argv == "-p")
0159 physListName = argv[i + 1];
0160 #ifdef G4MULTITHREADED
0161 else if (g4argv == "-t") {
0162 nofThreads = G4UIcommand::ConvertToInt(argv[i + 1]);
0163 }
0164 #endif
0165 else if (g4argv == "-v" || g4argv == "--verbose") {
0166 ++verbosity;
0167 --i;
0168 }
0169 else if (g4argv == "-h" || g4argv == "--help") {
0170 PrintUsage(verbosity + 1);
0171 return 1;
0172 }
0173 else {
0174 PrintUsage(0);
0175 return 1;
0176 }
0177 }
0178
0179
0180
0181 G4UIExecutive* ui = nullptr;
0182 if (!macro.size()) {
0183 ui = new G4UIExecutive(argc, argv, session);
0184 }
0185
0186
0187 G4Random::setTheEngine(new CLHEP::RanecuEngine());
0188
0189
0190 auto* runManager = G4RunManagerFactory::CreateRunManager();
0191 #ifdef G4MULTITHREADED
0192 if (nofThreads > 0) {
0193 runManager->SetNumberOfThreads(nofThreads);
0194 }
0195 #endif
0196
0197
0198
0199
0200
0201
0202 g4alt::G4PhysListFactory factory;
0203 G4VModularPhysicsList* physList = nullptr;
0204
0205
0206
0207
0208
0209 G4String defaultPhysListName = "FTFP_BERT";
0210 if (verbosity > 0) {
0211 G4cout << "extensibleFactory: SetDefaultReferencePhysList to '" << defaultPhysListName
0212 << "' ('' = system default)" << G4endl << G4endl;
0213 }
0214 factory.SetDefaultReferencePhysList(defaultPhysListName);
0215
0216
0217 G4PhysListRegistry* plreg = G4PhysListRegistry::Instance();
0218 plreg->AddPhysicsExtension("RADIO", "G4RadioactiveDecayPhysics");
0219 plreg->AddPhysicsExtension("MYPHYSICS", "MyG4PhysicsPhysics");
0220 if (verbosity > 0) {
0221 G4cout << "extensibleFactory: adding extensions" << G4endl
0222 << " RADIO ===> G4RadioactiveDecayPhysics" << G4endl
0223 << " MYPHYSICS ===> MyG4PhysicsPhysics" << G4endl << G4endl;
0224 }
0225
0226
0227
0228 if (physListName.size()) {
0229 if (verbosity > 0) {
0230 G4cout << "extensibleFactory: explicitly using '" << physListName << "'" << G4endl;
0231 }
0232 physList = factory.GetReferencePhysList(physListName);
0233 }
0234 else {
0235 if (verbosity > 0) {
0236 G4cout << "extensibleFactory: no -p flag;"
0237 << " using ReferencePhysList() ($PHYSLIST or default)" << G4endl;
0238 }
0239 physList = factory.ReferencePhysList();
0240
0241 if (!physList) {
0242
0243 physListNameEnv = std::getenv("PHYSLIST");
0244 if (physListNameEnv) {
0245 G4cout << "extensibleFactory: $PHYSLIST=" << physListNameEnv << G4endl;
0246 }
0247 }
0248 }
0249
0250
0251
0252 if (!physList) {
0253 G4cerr << "extensibleFactory: PhysicsList '"
0254 << (physListNameEnv ? physListNameEnv : physListName)
0255 << "' was not available in g4alt::PhysListFactory." << G4endl;
0256 PrintAvailable(verbosity);
0257
0258
0259
0260 G4ExceptionDescription ED;
0261 ED << "The factory for the physicslist [" << (physListNameEnv ? physListNameEnv : physListName)
0262 << "] does not exist!" << G4endl;
0263 G4Exception("extensibleFactory", "extensibleFactory001", FatalException, ED);
0264 exit(42);
0265 }
0266
0267
0268 runManager->SetUserInitialization(new DetectorConstruction());
0269 runManager->SetUserInitialization(physList);
0270
0271
0272 auto actinit = new ActionInitialization("extensibleFactory");
0273 runManager->SetUserInitialization(actinit);
0274
0275
0276 G4VisManager* visManager = new G4VisExecutive;
0277
0278
0279 visManager->Initialize();
0280
0281
0282 G4UImanager* UImanager = G4UImanager::GetUIpointer();
0283
0284 if (macro.size()) {
0285
0286 G4String command = "/control/execute ";
0287 UImanager->ApplyCommand(command + macro);
0288 }
0289 else {
0290
0291 UImanager->ApplyCommand("/control/execute init_vis.mac");
0292 ui->SessionStart();
0293 delete ui;
0294 }
0295
0296
0297
0298
0299
0300
0301 delete visManager;
0302 delete runManager;
0303 }
0304
0305