Geant4 Cross Reference |
>> 1 $Id: README,v 1.16 2010-11-29 10:34:36 gcosmo Exp $ 1 ---------------------------------------------- 2 ------------------------------------------------------------------- 2 3 3 ========================================= 4 ========================================================= 4 Geant4 - an Object-Oriented Toolkit for S 5 Geant4 - an Object-Oriented Toolkit for Simulation in HEP 5 ========================================= 6 ========================================================= 6 7 7 How to build and run an examp 8 How to build and run an example 8 ----------------------------- 9 ------------------------------- 9 10 10 All basic and most of extended examples have << 11 All novice, basic and most of extended examples have a similar structure. 11 The main () function is included in exampleXY 12 The main () function is included in exampleXYZ.cc in the example top directory 12 and the example source code is structered in 13 and the example source code is structered in include and src subdirectories. 13 When the example is built, the executable tak 14 When the example is built, the executable takes the same name as the file with 14 main() function without .cc extension, exampl 15 main() function without .cc extension, exampleXYZ. 15 16 16 Then several macros are provided to run the e 17 Then several macros are provided to run the example with various start-up 17 conditions. These macros have usually .mac ex 18 conditions. These macros have usually .mac extension. Besides these macros, 18 there is often a macro exampleXYZ.in (note it 19 there is often a macro exampleXYZ.in (note its different extension) 19 which is used in Geant4 testing and which out 20 which is used in Geant4 testing and which output, exampleXYZ.out, can also included 20 in the distribution. 21 in the distribution. 21 22 22 You can find all details about building the e 23 You can find all details about building the examples in the Geant4 Installation Guide: 23 "https://geant4-userdoc.web.cern.ch/UsersGuid << 24 "http://geant4.web.cern.ch/geant4/UserDocumentation/UsersGuides/InstallationGuide/html/index.html" 24 in the section How to Use the Geant4 Toolkit << 25 in the section 3.2. Building Applications with Geant4: 25 https://geant4-userdoc.web.cern.ch/UsersGuide << 26 http://geant4.web.cern.ch/geant4/UserDocumentation/UsersGuides/InstallationGuide/html/ch03s02.html" 26 Here we recall only the basics. 27 Here we recall only the basics. 27 28 28 1) COMPILE AND LINK TO GENERATE AN EXECUTABLE 29 1) COMPILE AND LINK TO GENERATE AN EXECUTABLE 29 30 30 % cd path_to_exampleXYZ # go to dir << 31 1a) With CMake 31 % mkdir exampleXYZ_build << 32 32 % cd exampleXYZ_build << 33 % cd path_to_exampleXYZ # go to directory which contains your example 33 % cmake -DGeant4_DIR=path_to_Geant4_ins << 34 % mkdir exampleXYZ_build 34 % make -j N exampleXYZ # "N" is th << 35 % cd exampleXYZ_build 35 % make install # this step << 36 % cmake -DGeant4_DIR=path_to_Geant4_installation/lib[64]/Geant4-9.6.0/ ../exampleXYZ >> 37 % make -j N exampleXYZ # "N" is the number of processes >> 38 % make install # this step is optional >> 39 >> 40 1b) With GNUmake >> 41 >> 42 To use GNUmake build system when Geant4 was installed with CMake, you have to source first >> 43 the setup script in order to define needed environment variables: >> 44 >> 45 % source path_to_Geant4_installation/share/Geant4-9.6.0/geant4make/geant4make.[c]sh >> 46 >> 47 Then to build example >> 48 >> 49 % cd path_to_exampleXYZ/exampleXYZ >> 50 % gmake >> 51 >> 52 An additional step is needed when building an example using shared classes >> 53 (usually from ../shared directory) or classes from common: >> 54 >> 55 % cd path_to_exampleXYZ/exampleXYZ >> 56 % gmake setup >> 57 % gmake >> 58 >> 59 When building the example in this way make sure that the path to the example executable >> 60 and its shared library is added in the paths defined on your system >> 61 (eg. PATH and LD_LIBRARY_PATH on Linux). 36 62 37 2) EXECUTE EXAMPLEXYZ IN 'BATCH' MODE FROM MA 63 2) EXECUTE EXAMPLEXYZ IN 'BATCH' MODE FROM MACRO FILES 38 64 39 ... go to the directory where the examp << 65 ... go to the directory where examples was built/installed 40 % ./exampleXYZ xyz.mac << 66 % exampleXYZ xyz.mac 41 67 42 3) EXECUTE EXAMPLEXYZ IN 'INTERACTIVE MODE' W 68 3) EXECUTE EXAMPLEXYZ IN 'INTERACTIVE MODE' WITH VISUALIZATION 43 69 44 ... go to the directory where the examp << 70 ... go to the directory where examples was built/installed 45 % ./exampleXYZ << 71 % exampleXYZ 46 .... 72 .... 47 Idle> type your commands 73 Idle> type your commands 48 .... 74 .... 49 Idle> exit 75 Idle> exit 50 76 51 77 52 Below we give the explicit instructions for t 78 Below we give the explicit instructions for the example 53 extended/electromagnetic/TestEm1. 79 extended/electromagnetic/TestEm1. 54 80 55 Let's suppose that the TestEm1 directory is a 81 Let's suppose that the TestEm1 directory is available in $HOME and Geant4 56 installation in /usr/local and we work within 82 installation in /usr/local and we work within bash shell on a 64-bit machine. 57 83 58 1) COMPILE AND LINK TESTEM1 TO GENERATE AN EX 84 1) COMPILE AND LINK TESTEM1 TO GENERATE AN EXECUTABLE 59 85 60 % cd $HOME << 86 1a) With CMake 61 % mkdir TestEm1_build << 87 62 % cd TestEm1_build << 88 % cd $HOME 63 % cmake -DGeant4_DIR=/usr/local/lib64/Gean << 89 % mkdir TestEm1_build 64 % make -j 2 TestEm1 << 90 % cd TestEm1_build >> 91 % cmake -DGeant4_DIR=/usr/local/lib64/Geant4-9.6.0/ ../TestEm1 >> 92 % make -j 2 TestEm1 >> 93 >> 94 1b) With GNUmake >> 95 >> 96 % cd $HOME/TestEm1 >> 97 % source /usr/local/share/Geant4-9.6.0/geant4make/geant4make.sh >> 98 % make 65 99 66 2) EXECUTE TESTEM1 IN 'BATCH' MODE FROM MACRO 100 2) EXECUTE TESTEM1 IN 'BATCH' MODE FROM MACRO FILES 67 101 68 % cd $HOME/TestEm1_build # or cd $HOME/ 102 % cd $HOME/TestEm1_build # or cd $HOME/TestEm1 if example was built with GNUmake 69 % ./TestEm1 annihil.mac << 103 % TestEm1 annihil.mac 70 % ./TestEm1 brem.mac << 104 % TestEm1 brem.mac 71 % ./TestEm1 TestEm1.in >& myTestEm1.out << 105 % TestEm1 TestEm1.in >& myTestEm1.out # redirecting output in a file 72 106 73 3) EXECUTE TESTEM1 IN 'INTERACTIVE MODE' WITH 107 3) EXECUTE TESTEM1 IN 'INTERACTIVE MODE' WITH VISUALIZATION 74 108 75 % cd $HOME/TestEm1_build # or cd $HOME/ 109 % cd $HOME/TestEm1_build # or cd $HOME/TestEm1 if example was built with GNUmake 76 % ./TestEm1 << 110 % TestEm1 77 PreInit> /run/initialize 111 PreInit> /run/initialize 78 Idle> /run/beamOn 1 112 Idle> /run/beamOn 1 79 ... 113 ... 80 Idle> exit 114 Idle> exit >> 115 >> 116 */