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