Getting started with Geant4 using MSVC++ .NET

Introduction

Geant4 is a toolkit for the simulation of the passage of particles through matter.
Its application areas include high energy physics and nuclear experiments, medical, accelerator and space physics studies. You can find more information about Geant4 at http://wwwinfo.cern.ch/asd/geant4/geant4.html

The purpose of this site is to provide information and tools to enable the development and use of the Geant4 toolkit on Windows platforms using the Visual C++ .NET compiler.

Geant4 Code

The toolkit is written in C++ and is officially supported on Windows platforms using the Microsoft Visual C++ v6 compiler. Building the libraries, however, requires the installation of a UNIX environment ( http://cygwin.com/ ) and the use of UNIX command-line tools.  

This project is based on GEANT4 v5.0 available from http://pcitapiww.cern.ch/geant4/source/source/geant4_5_0.zip and CLHEP version 1.8.0 available at http://cern.ch/clhep/DISTRIBUTION/clhep.html .

VC++ .NET

This project uses the .NET version of the Microsoft Visual C++ compiler ( http://msdn.microsoft.com/visualc/ ) . An introduction for new users can be found here.  

Code Patches

The geant4 code, as released, does not compile under VC++ .NET, so some patches are required. These have been archived into a file in ZIP format and is available here. This assumes the same directory structure as the geant4 source distribution ZIP file and should be unzipped in the same way. This will overwrite the existing code in the geant4_5_0 directory. Descriptions of the modifications can be found here. Please note that these are not sanctioned modifications.

Using the .NET compiler with cygwin tools

For users accustomed to using the UNIX tools under cygwin, a shell script has been written by Matt Langston to define the MSVC++ .NET environmental variables usually provided by the vsvars.bat file. This file can be downloaded here. You may have to redefine the install directory to reflect your local installation. A  minimal geant4 setup script can be found here. You will need to modify this to point to your local clhep installation. These files should be copied to the source directory of the geant4 installation. You should now be able to build the geant4 libraries with the following commands in cygwin:

MSVC++ .NET solution and project files

For users desiring to develop geant4 applications completely within the Visual Studio environment, a solution file and project files for the individual libraries have been developed. Every effort has been made to replicate the compiler options used in the official geant4 distribution mechanism, but users should note that this is a first test release. This distribution also only contains the debug target. 

This first release does not contain the correct dependency structure for the projects. Instead, all the include files (*.h, *.hh and *.icc) have been collected into a single directory and the projects use this as the "Additional Include Directory". This, of course, violates all sorts of good coding practices, and resolving this is fairly high on my list of priorities for this undertaking. (I would appreciate hearing from anyone with expertise in resolving code package dependencies on Windows.) A ZIP file containing the necessary include files can be found here. This assumes the same directory structure as the geant4 source distribution ZIP file and should be unzipped in the same way. The solution file and projects for the geant4 static libraries can be found here. A .bat file is provided to set up the appropriate local environmental variables and then invoke the IDE. Users should only need to redefine G4INSTALL and CLHEP_BASE_DIR. Double-clicking on the .bat file icon should then spawn the IDE.

Contact

If you have any comments, suggestions, or contributions, please contact me at Norman.Graf@slac.stanford.edu .

Acknowledgements

Both Tracy Usher and Matt Langston have provided useful support for this project.