Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // << 27 /// \file optical/wls/wls.cc 26 /// \file optical/wls/wls.cc 28 /// \brief Main program of the optical/wls exa 27 /// \brief Main program of the optical/wls example 29 // 28 // 30 //....oooOO0OOooo........oooOO0OOooo........oo << 29 // >> 30 // >> 31 // >> 32 // -------------------------------------------------------------- >> 33 // GEANT 4 - Example wls >> 34 // >> 35 // -------------------------------------------------------------- >> 36 // Comments >> 37 // >> 38 // >> 39 // -------------------------------------------------------------- 31 40 32 #include "FTFP_BERT.hh" << 41 #ifndef WIN32 33 #include "WLSActionInitialization.hh" << 42 #include <unistd.h> 34 #include "WLSDetectorConstruction.hh" << 43 #endif 35 44 36 #include "G4EmStandardPhysics_option4.hh" << 45 #include "G4RunManager.hh" 37 #include "G4OpticalPhysics.hh" << 38 #include "G4RunManagerFactory.hh" << 39 #include "G4Types.hh" << 40 #include "G4UIExecutive.hh" << 41 #include "G4UImanager.hh" 46 #include "G4UImanager.hh" >> 47 >> 48 #include "Randomize.hh" >> 49 >> 50 #include "WLSPhysicsList.hh" >> 51 #include "WLSDetectorConstruction.hh" >> 52 #include "WLSPrimaryGeneratorAction.hh" >> 53 >> 54 #include "WLSRunAction.hh" >> 55 #include "WLSEventAction.hh" >> 56 #include "WLSTrackingAction.hh" >> 57 #include "WLSSteppingAction.hh" >> 58 #include "WLSStackingAction.hh" >> 59 #include "WLSSteppingVerbose.hh" >> 60 >> 61 #ifdef G4VIS_USE 42 #include "G4VisExecutive.hh" 62 #include "G4VisExecutive.hh" >> 63 #endif 43 64 44 //....oooOO0OOooo........oooOO0OOooo........oo << 65 #ifdef G4UI_USE >> 66 #include "G4UIExecutive.hh" >> 67 #endif >> 68 >> 69 // argc holds the number of arguments (including the name) on the command line >> 70 // -> it is ONE when only the name is given !!! >> 71 // argv[0] is always the name of the program >> 72 // argv[1] points to the first argument, and so on 45 73 46 int main(int argc, char** argv) << 74 int main(int argc,char** argv) 47 { 75 { 48 // Instantiate G4UIExecutive if interactive << 76 G4String physName = "QGSP_BERT_EMV"; 49 G4UIExecutive* ui = nullptr; << 50 if (argc == 1) { << 51 ui = new G4UIExecutive(argc, argv); << 52 } << 53 77 54 auto runManager = G4RunManagerFactory::Creat << 55 G4int seed = 123; 78 G4int seed = 123; 56 if (argc > 2) seed = atoi(argv[argc - 1]); << 79 if (argc > 2) seed = atoi(argv[argc-1]); >> 80 >> 81 // Choose the Random engine 57 82 58 // Choose the Random engine and set the seed << 83 CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine); 59 // G4Random::setTheEngine(new CLHEP::RanecuE << 84 CLHEP::HepRandom::setTheSeed(seed); 60 G4Random::setTheSeed(seed); << 85 >> 86 #ifndef WIN32 >> 87 G4int c = 0; >> 88 while ((c=getopt(argc,argv,"p")) != -1) >> 89 { >> 90 switch (c) >> 91 { >> 92 case 'p': >> 93 physName = optarg; >> 94 G4cout << "Physics List used is " << physName << G4endl; >> 95 break; >> 96 case ':': /* -p without operand */ >> 97 fprintf(stderr, >> 98 "Option -%c requires an operand\n", optopt); >> 99 break; >> 100 case '?': >> 101 fprintf(stderr, >> 102 "Unrecognised option: -%c\n", optopt); >> 103 } >> 104 } >> 105 #endif >> 106 >> 107 // My Verbose output class >> 108 >> 109 G4VSteppingVerbose::SetInstance(new WLSSteppingVerbose); >> 110 >> 111 // Construct the default run manager >> 112 >> 113 G4RunManager * runManager = new G4RunManager; >> 114 >> 115 // Set mandatory initialization classes >> 116 >> 117 WLSDetectorConstruction* detector = new WLSDetectorConstruction(); 61 118 62 // Detector construction << 63 auto detector = new WLSDetectorConstruction( << 64 runManager->SetUserInitialization(detector); 119 runManager->SetUserInitialization(detector); 65 120 66 // Physics list << 121 runManager->SetUserInitialization(new WLSPhysicsList(physName)); 67 G4VModularPhysicsList* physicsList = new FTF << 68 physicsList->ReplacePhysics(new G4EmStandard << 69 auto opticalPhysics = new G4OpticalPhysics() << 70 << 71 auto opticalParams = G4OpticalParameters::In << 72 opticalParams->SetBoundaryInvokeSD(true); << 73 122 74 physicsList->RegisterPhysics(opticalPhysics) << 123 #ifdef G4VIS_USE 75 runManager->SetUserInitialization(physicsLis << 76 124 77 // User action initialization << 125 // visualization manager 78 runManager->SetUserInitialization(new WLSAct << 79 126 80 // Initialize visualization << 127 G4VisManager* visManager = new G4VisExecutive(); 81 G4VisManager* visManager = new G4VisExecutiv << 82 visManager->Initialize(); 128 visManager->Initialize(); 83 129 >> 130 #endif >> 131 >> 132 // Set mandatory user action class >> 133 >> 134 runManager->SetUserAction( new WLSPrimaryGeneratorAction(detector) ); >> 135 >> 136 WLSRunAction* runAction = new WLSRunAction(); >> 137 WLSEventAction* eventAction = new WLSEventAction(runAction); >> 138 >> 139 runManager->SetUserAction(runAction); >> 140 runManager->SetUserAction(eventAction); >> 141 runManager->SetUserAction( new WLSTrackingAction() ); >> 142 runManager->SetUserAction( new WLSSteppingAction(detector) ); >> 143 runManager->SetUserAction( new WLSStackingAction() ); >> 144 84 // Get the pointer to the User Interface man 145 // Get the pointer to the User Interface manager 85 G4UImanager* UImanager = G4UImanager::GetUIp << 86 146 87 if (ui) { << 147 G4UImanager * UImanager = G4UImanager::GetUIpointer(); 88 // Define (G)UI terminal for interactive m << 148 89 if (ui->IsGUI()) UImanager->ApplyCommand(" << 149 #ifndef WIN32 90 ui->SessionStart(); << 150 G4int optmax = argc; 91 delete ui; << 151 if (argc > 2) { optmax = optmax-1; } >> 152 >> 153 if (optind < optmax) >> 154 { >> 155 G4String command = "/control/execute "; >> 156 for ( ; optind < optmax; optind++) >> 157 { >> 158 G4String macroFilename = argv[optind]; >> 159 UImanager->ApplyCommand(command+macroFilename); >> 160 } 92 } 161 } 93 else { << 162 #else // Simple UI for Windows runs, no possibility of additional arguments 94 G4String command = "/control/execute "; << 163 if (argc!=1) 95 G4String fileName = argv[1]; << 164 { 96 UImanager->ApplyCommand(command + fileName << 165 G4String command = "/control/execute "; >> 166 G4String fileName = argv[1]; >> 167 UImanager->ApplyCommand(command+fileName); >> 168 } >> 169 #endif >> 170 else { >> 171 // Define (G)UI terminal for interactive mode >> 172 #ifdef G4UI_USE >> 173 G4UIExecutive * ui = new G4UIExecutive(argc,argv); >> 174 #ifdef G4VIS_USE >> 175 UImanager->ApplyCommand("/control/execute init.in"); >> 176 #endif >> 177 ui->SessionStart(); >> 178 delete ui; >> 179 #endif 97 } 180 } 98 181 99 // job termination 182 // job termination >> 183 >> 184 #ifdef G4VIS_USE 100 delete visManager; 185 delete visManager; >> 186 #endif 101 delete runManager; 187 delete runManager; >> 188 102 return 0; 189 return 0; 103 } 190 } 104 << 105 //....oooOO0OOooo........oooOO0OOooo........oo << 106 191