File indexing completed on 2025-01-30 09:19:32
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
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 #include "ActionInitialization.hh"
0064 #include "CaTSVersion.hh"
0065 #include "ConfigurationManager.hh"
0066 #include "DetectorConstruction.hh"
0067 #include "PhysicsConfigurator.hh"
0068
0069 #include "G4RunManager.hh"
0070 #include "G4RunManagerFactory.hh"
0071 #include "G4Timer.hh"
0072 #include "G4UIExecutive.hh"
0073 #include "G4UImanager.hh"
0074 #include "G4VModularPhysicsList.hh"
0075 #include "G4VisExecutive.hh"
0076 #include <G4Threading.hh>
0077 #ifdef WITH_G4OPTICKS
0078 # include "OPTICKS_LOG.hh"
0079 #endif
0080 #include "TROOT.h"
0081 #include <thread>
0082
0083 int main(int argc, char** argv)
0084 {
0085 #ifdef G4MULTITHREADED
0086 G4int nThreads = 0;
0087 #endif
0088 G4bool interactive = false;
0089 G4String physicsconf = "";
0090 G4String gdmlfile = "";
0091 G4String macrofile = "";
0092 G4UIExecutive* ui = nullptr;
0093 for(G4int i = 1; i < argc; i = i + 2)
0094 {
0095 if(G4String(argv[i]) == "-g")
0096 {
0097 gdmlfile = argv[i + 1];
0098 }
0099 else if(G4String(argv[i]) == "-pl")
0100 {
0101 physicsconf = G4String(argv[i + 1]);
0102 }
0103 else if(G4String(argv[i]) == "-m")
0104 {
0105 macrofile = G4String(argv[i + 1]);
0106 }
0107 #ifdef G4MULTITHREADED
0108 else if(G4String(argv[i]) == "-t")
0109 {
0110 nThreads = G4UIcommand::ConvertToInt(argv[i + 1]);
0111 }
0112 #endif
0113 }
0114 if(gdmlfile == "")
0115 {
0116 G4cout << "Error! Mandatory input file is not specified!" << G4endl;
0117 G4cout << G4endl;
0118 G4cout << G4endl;
0119 G4cout << "Usage: CaTS -g input_gdml_file:mandatory" << G4endl;
0120 G4cout << G4endl;
0121 return -1;
0122 }
0123 G4cout
0124 << G4endl
0125 << "---------------------------------------------------------------------"
0126 << G4endl
0127 << "* |\\___/| "
0128 "*"
0129 << G4endl
0130 << "* ) ( *"
0131 << G4endl
0132 << "* =\\ /= "
0133 "*"
0134 << G4endl
0135 << "* )===( Welcome to: *"
0136 << G4endl
0137 << "* / \\ CaTS: Calorimeter and Tracker Simulation "
0138 "*"
0139 << G4endl
0140 << "* | | a flexible and extend-able framework *"
0141 << G4endl
0142 << "* / \\ for the simulation of various detector "
0143 "*"
0144 << G4endl
0145 << "* \\ / systems *"
0146 << G4endl
0147 << "* \\__ _/ https://github.com/hanswenzel/CaTS "
0148 "*"
0149 << G4endl
0150 << "* ( ( *"
0151 << G4endl << "* ) ) Version: " << CaTSVersion
0152 << " *" << G4endl
0153 << "* (_( Date: " << CaTSDate << " *"
0154 << G4endl
0155 << "---------------------------------------------------------------------"
0156 << G4endl << G4endl;
0157 if(physicsconf == "")
0158 {
0159 G4cout << "Warning! no physics configuration specified!" << G4endl;
0160 G4cout << "Using default FTFP_BERT+OPTICAL+STEPLIMIT" << G4endl;
0161 physicsconf = "FTFP_BERT+OPTICAL+STEPLIMIT";
0162 G4cout << "Usage: CaTS -pl physicsconfiguration" << G4endl;
0163 G4cout << G4endl;
0164 }
0165 if(macrofile == "")
0166 {
0167 G4cout << "Warning! no macro specified!" << G4endl;
0168 G4cout << "assume interactive mode" << G4endl;
0169 interactive = true;
0170 ui = new G4UIExecutive(argc, argv);
0171 G4cout << G4endl;
0172 G4cout << G4endl;
0173 G4cout << "Usage: CaTS -m macrofile" << G4endl;
0174 G4cout << G4endl;
0175 }
0176 G4Timer* eventTimer = new G4Timer;
0177 eventTimer->Start();
0178 #ifdef WITH_G4OPTICKS
0179 OPTICKS_LOG(argc, argv);
0180 #endif
0181 G4VModularPhysicsList* phys =
0182 PhysicsConfigurator::getInstance()->Construct(physicsconf);
0183 G4String DumpFilename = gdmlfile + "_G4";
0184 ConfigurationManager::getInstance()->setGDMLFileName(DumpFilename);
0185 DetectorConstruction* dc = new DetectorConstruction(gdmlfile);
0186
0187 auto* rm = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Default);
0188
0189
0190 #ifdef G4MULTITHREADED
0191
0192 if(nThreads == 0)
0193 {
0194 nThreads = G4Threading::G4GetNumberOfCores();
0195 }
0196 if(nThreads > 0)
0197 {
0198 rm->SetNumberOfThreads(nThreads);
0199 }
0200 #endif
0201 rm->SetUserInitialization(dc);
0202 rm->SetUserInitialization(phys);
0203 ActionInitialization* actionInitialization = new ActionInitialization();
0204 rm->SetUserInitialization(actionInitialization);
0205 G4UImanager* UImanager = G4UImanager::GetUIpointer();
0206 if(interactive)
0207 {
0208 G4VisManager* visManager = new G4VisExecutive;
0209 visManager->Initialize();
0210 UImanager->ApplyCommand("/control/execute init_vis.mac");
0211 ui->SessionStart();
0212 delete ui;
0213 delete visManager;
0214 }
0215 else
0216 {
0217
0218 G4String command = "/control/execute ";
0219 UImanager->ApplyCommand(command + macrofile);
0220
0221 delete ui;
0222 }
0223 eventTimer->Stop();
0224 double totalCPUTime =
0225 eventTimer->GetUserElapsed() + eventTimer->GetSystemElapsed();
0226 G4int precision_t = G4cout.precision(3);
0227 std::ios::fmtflags flags_t = G4cout.flags();
0228 G4cout.setf(std::ios::fixed, std::ios::floatfield);
0229 G4cout << "TimeTotal> " << eventTimer->GetRealElapsed() << " " << totalCPUTime
0230 << G4endl;
0231 G4cout.setf(flags_t);
0232 G4cout.precision(precision_t);
0233 delete eventTimer;
0234 delete rm;
0235 return 0;
0236 }