Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 // 27 // 28 // 29 // ------------------------------------------- 30 // GEANT 4 - examplePar04 31 // ------------------------------------------- 32 // Comments 33 // 34 // Example of a main program demonstrating inf 35 // for fast simulation in calorimeters. 36 // 37 //-------------------------------------------- 38 #include "FTFP_BERT.hh" // for FTFP_BERT 39 #include "Par04ActionInitialisation.hh" // fo 40 #include "Par04DetectorConstruction.hh" // fo 41 #include "Par04ParallelFastWorld.hh" 42 #include "Par04ParallelFullWorld.hh" 43 44 #include "G4EmParameters.hh" // for G4EmParam 45 #include "G4Exception.hh" // for G4Exception 46 #include "G4ExceptionSeverity.hh" // for Fata 47 #include "G4FastSimulationPhysics.hh" // for 48 #include "G4HadronicProcessStore.hh" // for G 49 #include "G4ParallelWorldPhysics.hh" 50 #include "G4RunManager.hh" // for G4RunManage 51 #include "G4RunManagerFactory.hh" // for G4Ru 52 #include "G4String.hh" // for G4String 53 #include "G4Types.hh" // for G4bool, G4int 54 #include "G4UIExecutive.hh" // for G4UIExecut 55 #include "G4UImanager.hh" // for G4UImanager 56 #include "G4VisExecutive.hh" // for G4VisExec 57 #include "G4VisManager.hh" // for G4VisManage 58 #include "G4ios.hh" // for G4cout, G4endl 59 60 #include <ctime> // for time 61 #include <sstream> // for char_traits, operat 62 #include <string> // for allocator, operator+ 63 64 int main(int argc, char** argv) 65 { 66 // Macro name from arguments 67 G4String batchMacroName; 68 G4bool useInteractiveMode = false; 69 G4int numOfThreadsOrTasks = 8; 70 G4int runManagerTypeInt = 0; 71 G4RunManagerType runManagerType = G4RunManag 72 G4String helpMsg( 73 "Usage: " + G4String(argv[0]) + 74 " [option(s)] \n You need to specify the m 75 "\n\t-h\t\tdisplay this help message\n\t-m 76 "executing MACRO\n\t-i\t\truns interactiv 77 "\n\t-r\t\trun manager type (0=serial,1=MT 78 "\n\t-t\t\tnumber of threads for MT mode ( 79 ); 80 if (argc < 2) { 81 G4Exception("main", "No arguments", FatalE 82 ("No arguments passed to " + G 83 } 84 for (G4int i = 1; i < argc; ++i) { 85 G4String argument(argv[i]); 86 if (argument == "-h" || argument == "--hel 87 G4cout << helpMsg << G4endl; 88 return 0; 89 } 90 else if (argument == "-m") { 91 batchMacroName = G4String(argv[i + 1]); 92 ++i; 93 } 94 else if (argument == "-i") { 95 useInteractiveMode = true; 96 } 97 else if (argument == "-r") { 98 G4int tmp = atoi(argv[i + 1]); 99 ++i; 100 switch (tmp) { 101 case 0: 102 runManagerTypeInt = tmp; 103 runManagerType = G4RunManagerType::S 104 break; 105 case 1: 106 runManagerTypeInt = tmp; 107 runManagerType = G4RunManagerType::M 108 break; 109 case 2: 110 runManagerTypeInt = tmp; 111 runManagerType = G4RunManagerType::T 112 break; 113 default: 114 G4Exception("main", "Wrong Run Manag 115 "Choose 0 (serial, defau 116 break; 117 } 118 } 119 else if (argument == "-t") { 120 numOfThreadsOrTasks = atoi(argv[i + 1]); 121 ++i; 122 } 123 else { 124 G4Exception( 125 "main", "Unknown argument", FatalError 126 ("Unknown argument passed to " + G4Str 127 .c_str()); 128 } 129 } 130 131 // choose the Random engine 132 CLHEP::HepRandom::setTheEngine(new CLHEP::Ra 133 // set random seed with system time 134 G4long seed = time(NULL); 135 CLHEP::HepRandom::setTheSeed(seed); 136 137 // Instantiate G4UIExecutive if interactive 138 G4UIExecutive* ui = nullptr; 139 140 if (useInteractiveMode) { 141 ui = new G4UIExecutive(argc, argv); 142 runManagerType = G4RunManagerType::Serial; 143 } 144 145 // Initialization of default Run manager 146 auto* runManager = G4RunManagerFactory::Crea 147 if (runManagerTypeInt == 1) runManager->SetN 148 // Detector geometry: 149 auto detector = new Par04DetectorConstructio 150 auto parallelWorldFull = new Par04ParallelFu 151 auto parallelWorldFast = 152 new Par04ParallelFastWorld("parallelWorldF 153 detector->RegisterParallelWorld(parallelWorl 154 detector->RegisterParallelWorld(parallelWorl 155 runManager->SetUserInitialization(detector); 156 157 // Physics list 158 auto physicsList = new FTFP_BERT(); 159 // Add fast simulation physics 160 auto fastSimulationPhysics = new G4FastSimul 161 fastSimulationPhysics->BeVerbose(); 162 fastSimulationPhysics->ActivateFastSimulatio 163 fastSimulationPhysics->ActivateFastSimulatio 164 fastSimulationPhysics->ActivateFastSimulatio 165 physicsList->RegisterPhysics(fastSimulationP 166 // Add parallel world for readout 167 physicsList->RegisterPhysics(new G4ParallelW 168 physicsList->RegisterPhysics(new G4ParallelW 169 // reduce verbosity of physics lists 170 G4EmParameters::Instance()->SetVerbose(0); 171 runManager->SetUserInitialization(physicsLis 172 173 //------------------------------- 174 // UserAction classes 175 //------------------------------- 176 runManager->SetUserInitialization(new Par04A 177 //---------------- 178 // Visualization: 179 //---------------- 180 G4cout << "Instantiating Visualization Manag 181 G4VisManager* visManager = new G4VisExecutiv 182 visManager->Initialize(); 183 G4UImanager* UImanager = G4UImanager::GetUIp 184 185 if (useInteractiveMode) { 186 if (batchMacroName.empty()) { 187 G4Exception("main", "Unknown macro name" 188 ("No macro name passed to " 189 } 190 G4String command = "/control/execute "; 191 UImanager->ApplyCommand(command + batchMac 192 ui->SessionStart(); 193 delete ui; 194 } 195 else { 196 G4String command = "/control/execute "; 197 UImanager->ApplyCommand(command + batchMac 198 } 199 200 // Free the store: user actions, physics_lis 201 // owned and deleted by the 202 // be deleted in the main() 203 204 delete visManager; 205 delete runManager; 206 207 return 0; 208 } 209