[807] | 1 | // |
---|
| 2 | // ******************************************************************** |
---|
| 3 | // * License and Disclaimer * |
---|
| 4 | // * * |
---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
| 7 | // * conditions of the Geant4 Software License, included in the file * |
---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
| 9 | // * include a list of copyright holders. * |
---|
| 10 | // * * |
---|
| 11 | // * Neither the authors of this software system, nor their employing * |
---|
| 12 | // * institutes,nor the agencies providing financial support for this * |
---|
| 13 | // * work make any representation or warranty, express or implied, * |
---|
| 14 | // * regarding this software system or assume any liability for its * |
---|
| 15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
| 16 | // * for the full disclaimer and the limitation of liability. * |
---|
| 17 | // * * |
---|
| 18 | // * This code implementation is the result of the scientific and * |
---|
| 19 | // * technical work of the GEANT4 collaboration. * |
---|
| 20 | // * By using, copying, modifying or distributing the software (or * |
---|
| 21 | // * any work based on the software) you agree to acknowledge its * |
---|
| 22 | // * use in resulting scientific publications, and indicate your * |
---|
| 23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
| 24 | // ******************************************************************** |
---|
| 25 | // |
---|
| 26 | // |
---|
| 27 | // $Id: field04.cc,v 1.7 2007/11/02 10:53:41 gcosmo Exp $ |
---|
| 28 | // GEANT4 tag $Name: $ |
---|
| 29 | // |
---|
| 30 | // |
---|
| 31 | // -------------------------------------------------------------- |
---|
| 32 | // GEANT 4 - Example F04 |
---|
| 33 | // |
---|
| 34 | // -------------------------------------------------------------- |
---|
| 35 | // Comments |
---|
| 36 | // |
---|
| 37 | // |
---|
| 38 | // -------------------------------------------------------------- |
---|
| 39 | |
---|
| 40 | #ifndef WIN32 |
---|
| 41 | #include <unistd.h> |
---|
| 42 | #endif |
---|
| 43 | |
---|
| 44 | #include "G4RunManager.hh" |
---|
| 45 | #include "G4UImanager.hh" |
---|
| 46 | |
---|
| 47 | #include "G4UIterminal.hh" |
---|
| 48 | #include "G4UItcsh.hh" |
---|
| 49 | |
---|
| 50 | #include "Randomize.hh" |
---|
| 51 | |
---|
| 52 | #include "F04PhysicsList.hh" |
---|
| 53 | #include "F04DetectorConstruction.hh" |
---|
| 54 | #include "F04PrimaryGeneratorAction.hh" |
---|
| 55 | |
---|
| 56 | #include "F04RunAction.hh" |
---|
| 57 | #include "F04EventAction.hh" |
---|
| 58 | #include "F04TrackingAction.hh" |
---|
| 59 | #include "F04SteppingAction.hh" |
---|
| 60 | #include "F04StackingAction.hh" |
---|
| 61 | #include "F04SteppingVerbose.hh" |
---|
| 62 | |
---|
| 63 | #ifdef G4VIS_USE |
---|
| 64 | #include "G4VisExecutive.hh" |
---|
| 65 | #endif |
---|
| 66 | |
---|
| 67 | // argc holds the number of arguments (including the name) on the command line |
---|
| 68 | // -> it is ONE when only the name is given !!! |
---|
| 69 | // argv[0] is always the name of the program |
---|
| 70 | // argv[1] points to the first argument, and so on |
---|
| 71 | |
---|
| 72 | int main(int argc,char** argv) |
---|
| 73 | { |
---|
| 74 | G4bool useUItcsh = true; |
---|
| 75 | |
---|
| 76 | G4String physicsList = "QGSP_BERT"; |
---|
| 77 | |
---|
| 78 | G4int seed = 0; |
---|
| 79 | if (argc > 2) seed = atoi(argv[argc-1]); |
---|
| 80 | |
---|
| 81 | CLHEP::HepRandom::setTheSeed(seed); |
---|
| 82 | |
---|
| 83 | #ifndef WIN32 |
---|
| 84 | G4int c = 0; |
---|
| 85 | while ((c=getopt(argc,argv,"p:t")) != -1) |
---|
| 86 | { |
---|
| 87 | switch (c) |
---|
| 88 | { |
---|
| 89 | case 'p': |
---|
| 90 | physicsList = optarg; |
---|
| 91 | G4cout << "Physics List used is " << physicsList << G4endl; |
---|
| 92 | break; |
---|
| 93 | case 't': // Don't use a tcsh-style command line interface |
---|
| 94 | useUItcsh = false; |
---|
| 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 | // Choose the Random engine |
---|
| 108 | |
---|
| 109 | CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine); |
---|
| 110 | |
---|
| 111 | // My Verbose output class |
---|
| 112 | |
---|
| 113 | G4VSteppingVerbose::SetInstance(new F04SteppingVerbose); |
---|
| 114 | |
---|
| 115 | // Construct the default run manager |
---|
| 116 | |
---|
| 117 | G4RunManager * runManager = new G4RunManager; |
---|
| 118 | |
---|
| 119 | // Set mandatory initialization classes |
---|
| 120 | |
---|
| 121 | F04DetectorConstruction* detector = new F04DetectorConstruction(); |
---|
| 122 | |
---|
| 123 | runManager->SetUserInitialization(detector); |
---|
| 124 | runManager->SetUserInitialization(new F04PhysicsList(physicsList)); |
---|
| 125 | |
---|
| 126 | #ifdef G4VIS_USE |
---|
| 127 | |
---|
| 128 | // visualization manager |
---|
| 129 | |
---|
| 130 | G4VisManager* visManager = new G4VisExecutive(); |
---|
| 131 | visManager->Initialize(); |
---|
| 132 | |
---|
| 133 | #endif |
---|
| 134 | |
---|
| 135 | // Set mandatory user action class |
---|
| 136 | |
---|
| 137 | runManager->SetUserAction( new F04PrimaryGeneratorAction(detector) ); |
---|
| 138 | |
---|
| 139 | F04RunAction* runAction = new F04RunAction(); |
---|
| 140 | F04EventAction* eventAction = new F04EventAction(runAction); |
---|
| 141 | |
---|
| 142 | runManager->SetUserAction(runAction); |
---|
| 143 | runManager->SetUserAction(eventAction); |
---|
| 144 | runManager->SetUserAction( new F04TrackingAction() ); |
---|
| 145 | runManager->SetUserAction( new F04SteppingAction() ); |
---|
| 146 | runManager->SetUserAction( new F04StackingAction() ); |
---|
| 147 | |
---|
| 148 | // Get the pointer to the User Interface manager |
---|
| 149 | |
---|
| 150 | G4UImanager * UI = G4UImanager::GetUIpointer(); |
---|
| 151 | |
---|
| 152 | #ifndef WIN32 |
---|
| 153 | G4int optmax = argc; |
---|
| 154 | if (argc > 2) { optmax = optmax-1; } |
---|
| 155 | |
---|
| 156 | if (optind < optmax) |
---|
| 157 | { |
---|
| 158 | G4String command = "/control/execute "; |
---|
| 159 | for ( ; optind < optmax; optind++) |
---|
| 160 | { |
---|
| 161 | G4String macroFilename = argv[optind]; |
---|
| 162 | UI->ApplyCommand(command+macroFilename); |
---|
| 163 | } |
---|
| 164 | } |
---|
| 165 | else |
---|
| 166 | { |
---|
| 167 | // Define (G)UI terminal for interactive mode |
---|
| 168 | G4UIsession * session = 0; |
---|
| 169 | if (useUItcsh) |
---|
| 170 | { |
---|
| 171 | // G4UIterminal is a terminal with tcsh-like control. |
---|
| 172 | session = new G4UIterminal(new G4UItcsh); |
---|
| 173 | } |
---|
| 174 | else |
---|
| 175 | { |
---|
| 176 | // G4UIterminal is a (dumb) terminal. |
---|
| 177 | session = new G4UIterminal(); |
---|
| 178 | } |
---|
| 179 | session->SessionStart(); |
---|
| 180 | delete session; |
---|
| 181 | } |
---|
| 182 | #else // Simple UI for Windows runs, no possibility of additional arguments |
---|
| 183 | if (argc==1) // Define UI terminal for interactive mode |
---|
| 184 | { |
---|
| 185 | G4UIsession * session = new G4UIterminal; |
---|
| 186 | session->SessionStart(); |
---|
| 187 | delete session; |
---|
| 188 | } |
---|
| 189 | else // Batch mode |
---|
| 190 | { |
---|
| 191 | G4String command = "/control/execute "; |
---|
| 192 | G4String fileName = argv[1]; |
---|
| 193 | UI->ApplyCommand(command+fileName); |
---|
| 194 | } |
---|
| 195 | #endif |
---|
| 196 | // job termination |
---|
| 197 | |
---|
| 198 | #ifdef G4VIS_USE |
---|
| 199 | delete visManager; |
---|
| 200 | #endif |
---|
| 201 | delete runManager; |
---|
| 202 | |
---|
| 203 | return 0; |
---|
| 204 | } |
---|