HOWTO build and install GEANT4.10.02 on OS X

From GlueXWiki
Jump to: navigation, search

Building Geant 4.10.02 on OS X 10.9

I built this using clang 3.7.0 which I'd compiled and installed on my system. I'm not sure if these instructions will work for the native compiler which seems to be a mixture of gcc and clang (??). Documentation for earlier GEANT4 releases indicated that one *must* use the clang compiler on OS X. I did not have a lot of luck with that myself before.


0.) Download the source and any data files you don't have from:

http://geant4.web.cern.ch/geant4/support/download.shtml

1.) Unpack the source and create a build directory next to it as suggested by the build instructions.

> tar xzf geant4.10.02.tar
> mkdir geant4.10.02.${BMS_OSNAME}-build
> cd geant4.10.02.${BMS_OSNAME}-build


2.) Run cmake with appropriate flags to turn on GDML, OpenGL, and raytracer. The GDML is so it can read geometry converted from HDDS to GDML using the ROOT TGeoManager->Export() utility. Note that GDML requires xerces and that it be given explicitly.

Note that I had to download a newer version of CMake since this required 3.3 or greater. I have a symbolic link: /usr/bin/cmake that points to /Applications/CMake\ 3.4.1.app/Contents/bin/cmake

> cmake -DCMAKE_INSTALL_PREFIX=/usr/local/geant4/geant4.10.02.$BMS_OSNAME \
-DGEANT4_USE_GDML=ON \
-DXERCESC_ROOT_DIR=$XERCESCROOT \
-DGEANT4_USE_OPENGL_X11=ON \
-DGEANT4_USE_RAYTRACER_X11=ON \
-DGEANT4_BUILD_MULTITHREADED=ON \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
../geant4.10.02


3.) Run make (multi-threaded) followed by make install

> make -j8
> make install


4.) Link your data directory: You could install all of your data files in the 10.02 "share" directory but I prefer placing them centrally so other version of GEANT4 can use them without my having to make copies. Here's what I do: place the data files in a directory named "data" that is parallel to the geant4.10.02.$BMS_OSNAME directory. Then ...

> cd ../geant4.10.02.$BMS_OSNAME/share/Geant4-10.2.0
> ln -s ../../../data


5.) In my .cshrc file, I have the following lines:

setenv G4 /usr/local/geant4/geant4.10.02.Darwin_macosx10.9-x86_64-clang3.7.0
source $G4/bin/geant4.csh $G4/bin
source $G4/share/Geant4-10.2.0/geant4make/geant4make.csh $G4/share/Geant4-10.2.0/geant4make/


Reading the HDDS Geometry into Geant4 via GDML

Part of my motivation here was to try and read the full GlueX geometry into Geant4 for developing a simulation for the Charged Pion Polarizability (CPP) experiment. There is a utility called g3tog4 that comes with Geant4, but I did not have much luck with it in the past. It also relies on a ".rz" file produced by running the Geant3 program and since I am working on Mac OS X, that required running hdgeant on a Linux machine first. Instead, I did this via GDML. There already exists in HDDS the hdds-root tool which creates macros that express the HDDS defined geometry as ROOT geometry objects. ROOT also has the ability to export an entire geometry as a gdml file that is compatible with Geant4. Providing that GDML support was enabled when ROOT was built (do this by passing --enable-gdml to the configure script for ROOT 5.34/14).

To create the ".gdml" file, go to the HDDS src directory. This directory contains generated source and is the result of building HDDS. In it, there should be a file hddsroot.C.

> cd $HDDS_HOME/src
> root -l hddsroot.C
...
root> gGeoManager->Export("main_HDDS.gdml") 
root> .q

Note that documentation on the web says you need to set PYTHONPATH prior to using this. It seems this is not required for ROOT 5.34/14 (not sure about other versions).

To try reading in the GDML (and therefore, prove the principle) I used the first example in the gdml examples directory. Build this like so:

> cd $G4INSTALL/../examples/extended/persistency/gdml/G01
> make

Note that this assumes your G4WORKDIR environment variable is set since that is where the code will be compiled and linked.

The load_gdml test program will now be installed in $G4WORKDIR/bin/Darwin-clang. It requires the vis.mac macro be present in the current working directory so copy it there. For simplicity, just do this in the HDDS_HOME/src directory where the main_HDDS.gdml should now exist.

> cd $HDDS_HOME/src
> cp $G4INSTALL/../examples/extended/persistency/gdml/G01/vis.mac .
> $G4WORKDIR/bin/Darwin-clang/load_gdml main_HDDS.gdml


This should (eventually) pop up an X-window and draw a few objects in it. They look a bit far away and are not necessarily recognizable as the GlueX detector, but seeing something with no errors is probably a good indication that everything is working.

Troubleshooting

Note that this seems to require a network connection to download the schema from CERN. If the network is down, the program fails with the following message:

harriet:src> $G4WORKDIR/bin/Darwin-clang/load_gdml main_HDDS.gdml

Usage: load_gdml <intput_gdml_file:mandatory> <output_gdml_file:optional>

G4GDML: Reading 'main_HDDS.gdml'...
G4GDML: VALIDATION ERROR! unable to resolve host/address 'service-spi.web.cern.ch' at line: 0
G4GDML: VALIDATION ERROR! fatal error during schema scan at line: 2

-------- EEEE ------- G4Exception-START -------- EEEE -------

*** ExceptionHandler is not defined ***
*** G4Exception : InvalidRead
      issued by : G4GDMLRead::Read()
Empty document!
*** Fatal Exception ***
-------- EEEE -------- G4Exception-END --------- EEEE -------


*** G4Exception: Aborting execution ***
Abort

The schema file is contained in the source for Geant4, but does not seem to be installed (??) You can get around the limitation and even get a faster start-up of the program if you point your GDML file to the local schema file. I copied the schema file by hand into the directory parallel to my geant4 installation directory to make sure I would have it, even when I deleted the Geant4 source.

> cp /Users/davidl/Desktop/GEANT4/geant4.10.00/source/persistency/gdml/schema/gdml.xsd /usr/local/geant4

The main_HDDS.gdml file header must then be edited to point to the local file. Here's how it should look after editing:

<?xml version="1.0"?>
<gdml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file:///usr/local/geant4/gdml.xsd">
  <define>
    <position name="TGBM_1inTARMpos" x="0.000000" y="0.000000" z="0.000000" unit="cm"/>
    <position name="TGF1_1inTGFLpos" x="0.000000" y="0.000000" z="1.270000" unit="cm"/>
      .
      .
      .