File indexing completed on 2025-02-23 09:22:36
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 #include "FTFP_BERT.hh" // for FTFP_BERT
0039 #include "Par04ActionInitialisation.hh" // for Par04ActionInitialisation
0040 #include "Par04DetectorConstruction.hh" // for Par04DetectorConstruction
0041 #include "Par04ParallelFastWorld.hh"
0042 #include "Par04ParallelFullWorld.hh"
0043
0044 #include "G4EmParameters.hh" // for G4EmParameters
0045 #include "G4Exception.hh" // for G4Exception
0046 #include "G4ExceptionSeverity.hh" // for FatalErrorInArgument
0047 #include "G4FastSimulationPhysics.hh" // for G4FastSimulationPhysics
0048 #include "G4HadronicProcessStore.hh" // for G4HadronicProcessStore
0049 #include "G4ParallelWorldPhysics.hh"
0050 #include "G4RunManager.hh" // for G4RunManager
0051 #include "G4RunManagerFactory.hh" // for G4RunManagerFactory, G4RunMa...
0052 #include "G4String.hh" // for G4String
0053 #include "G4Types.hh" // for G4bool, G4int
0054 #include "G4UIExecutive.hh" // for G4UIExecutive
0055 #include "G4UImanager.hh" // for G4UImanager
0056 #include "G4VisExecutive.hh" // for G4VisExecutive
0057 #include "G4VisManager.hh" // for G4VisManager
0058 #include "G4ios.hh" // for G4cout, G4endl
0059
0060 #include <ctime> // for time
0061 #include <sstream> // for char_traits, operator<<, bas...
0062 #include <string> // for allocator, operator+, operat...
0063
0064 int main(int argc, char** argv)
0065 {
0066
0067 G4String batchMacroName;
0068 G4bool useInteractiveMode = false;
0069 G4int numOfThreadsOrTasks = 8;
0070 G4int runManagerTypeInt = 0;
0071 G4RunManagerType runManagerType = G4RunManagerType::Serial;
0072 G4String helpMsg(
0073 "Usage: " + G4String(argv[0]) +
0074 " [option(s)] \n You need to specify the mode and the macro file.\nOptions:"
0075 "\n\t-h\t\tdisplay this help message\n\t-m MACRO\ttriggers a batch mode "
0076 "executing MACRO\n\t-i\t\truns interactive mode, use it together with <-m vis*mac> macros"
0077 "\n\t-r\t\trun manager type (0=serial,1=MT,2=tasking)"
0078 "\n\t-t\t\tnumber of threads for MT mode (no change for other modes)."
0079 );
0080 if (argc < 2) {
0081 G4Exception("main", "No arguments", FatalErrorInArgument,
0082 ("No arguments passed to " + G4String(argv[0]) + "\n" + helpMsg).c_str());
0083 }
0084 for (G4int i = 1; i < argc; ++i) {
0085 G4String argument(argv[i]);
0086 if (argument == "-h" || argument == "--help") {
0087 G4cout << helpMsg << G4endl;
0088 return 0;
0089 }
0090 else if (argument == "-m") {
0091 batchMacroName = G4String(argv[i + 1]);
0092 ++i;
0093 }
0094 else if (argument == "-i") {
0095 useInteractiveMode = true;
0096 }
0097 else if (argument == "-r") {
0098 G4int tmp = atoi(argv[i + 1]);
0099 ++i;
0100 switch (tmp) {
0101 case 0:
0102 runManagerTypeInt = tmp;
0103 runManagerType = G4RunManagerType::Serial;
0104 break;
0105 case 1:
0106 runManagerTypeInt = tmp;
0107 runManagerType = G4RunManagerType::MTOnly;
0108 break;
0109 case 2:
0110 runManagerTypeInt = tmp;
0111 runManagerType = G4RunManagerType::Tasking;
0112 break;
0113 default:
0114 G4Exception("main", "Wrong Run Manager type", FatalErrorInArgument,
0115 "Choose 0 (serial, default), 1 (MT), 2 (tasking)");
0116 break;
0117 }
0118 }
0119 else if (argument == "-t") {
0120 numOfThreadsOrTasks = atoi(argv[i + 1]);
0121 ++i;
0122 }
0123 else {
0124 G4Exception(
0125 "main", "Unknown argument", FatalErrorInArgument,
0126 ("Unknown argument passed to " + G4String(argv[0]) + " : " + argument + "\n" + helpMsg)
0127 .c_str());
0128 }
0129 }
0130
0131
0132 CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine());
0133
0134 G4long seed = time(NULL);
0135 CLHEP::HepRandom::setTheSeed(seed);
0136
0137
0138 G4UIExecutive* ui = nullptr;
0139
0140 if (useInteractiveMode) {
0141 ui = new G4UIExecutive(argc, argv);
0142 runManagerType = G4RunManagerType::Serial;
0143 }
0144
0145
0146 auto* runManager = G4RunManagerFactory::CreateRunManager(runManagerType);
0147 if (runManagerTypeInt == 1) runManager->SetNumberOfThreads(numOfThreadsOrTasks);
0148
0149 auto detector = new Par04DetectorConstruction();
0150 auto parallelWorldFull = new Par04ParallelFullWorld("parallelWorldFullSim", detector);
0151 auto parallelWorldFast =
0152 new Par04ParallelFastWorld("parallelWorldFastSim", detector, parallelWorldFull);
0153 detector->RegisterParallelWorld(parallelWorldFull);
0154 detector->RegisterParallelWorld(parallelWorldFast);
0155 runManager->SetUserInitialization(detector);
0156
0157
0158 auto physicsList = new FTFP_BERT();
0159
0160 auto fastSimulationPhysics = new G4FastSimulationPhysics();
0161 fastSimulationPhysics->BeVerbose();
0162 fastSimulationPhysics->ActivateFastSimulation("e-");
0163 fastSimulationPhysics->ActivateFastSimulation("e+");
0164 fastSimulationPhysics->ActivateFastSimulation("gamma");
0165 physicsList->RegisterPhysics(fastSimulationPhysics);
0166
0167 physicsList->RegisterPhysics(new G4ParallelWorldPhysics("parallelWorldFullSim"));
0168 physicsList->RegisterPhysics(new G4ParallelWorldPhysics("parallelWorldFastSim"));
0169
0170 G4EmParameters::Instance()->SetVerbose(0);
0171 runManager->SetUserInitialization(physicsList);
0172
0173
0174
0175
0176 runManager->SetUserInitialization(new Par04ActionInitialisation(detector, parallelWorldFull));
0177
0178
0179
0180 G4cout << "Instantiating Visualization Manager......." << G4endl;
0181 G4VisManager* visManager = new G4VisExecutive;
0182 visManager->Initialize();
0183 G4UImanager* UImanager = G4UImanager::GetUIpointer();
0184
0185 if (useInteractiveMode) {
0186 if (batchMacroName.empty()) {
0187 G4Exception("main", "Unknown macro name", FatalErrorInArgument,
0188 ("No macro name passed to " + G4String(argv[0])).c_str());
0189 }
0190 G4String command = "/control/execute ";
0191 UImanager->ApplyCommand(command + batchMacroName);
0192 ui->SessionStart();
0193 delete ui;
0194 }
0195 else {
0196 G4String command = "/control/execute ";
0197 UImanager->ApplyCommand(command + batchMacroName);
0198 }
0199
0200
0201
0202
0203
0204 delete visManager;
0205 delete runManager;
0206
0207 return 0;
0208 }