ustajan / grasshopper

GNU General Public License v3.0
5 stars 4 forks source link

grasshopper

This application is based on the geant4 development toolkit, which allows to program complex particle tracking (e.g. gamma, electrons, protons, etc) and particle-matter interaction MC simulations. Grasshopper is a simple geant4 application, where all the geometries and even generators parameters are defined in a gdml file, with the purpose of setting up quick and simple simulations. The goal is to allow users with no C++ and Geant4 knowledge quickly set up and run simulations.

Author: Areg Danagoulian

Creation time: 11/2015
Last update: continous

For copyright and licensing see files COPYRIGHT and LICENSE.

To install

The user is required to have the following

* xerces.  This will allow the GDML parser capability.
* For CMake Builds the User MUST Have CMake version 3.17 or higher.
* Built and installed geant4 libraries.  Also, in the cmake stage, the following flag needs to be passed:
`-DGEANT4_USE_GDML=ON`.  In some cases you also have to also add the location for Xerces with flags such as     
    `-DXERCESC_INCLUDE_DIR=/usr/local/include/ -DXERCESC_LIBRARY=/usr/local/lib/libxerces-c.so`.  See the geant4 instructions on how    to add Xerces for more detail on the paths.  Here's an example of what a Geant4 cmake command looks like:
    `cmake -DCMAKE_INSTALL_PREFIX=../geant4.10.05-install -DGEANT4_INSTALL_DATA=ON -DGEANT4_USE_GDML=ON ../geant4.10.05`
* ROOT -- optional.  Has been tested with version 6.22/07.  If you do not have ROOT the make process will recognize that and exclude        it from the build.
* When building grasshopper, the compiler might not find the GDML header files.  In that case just determine the actual file directories, and add them to the include list by appending `-I/directory_to_headers` to the `CPPFLAGS` env variable.

Version: grasshopper and been built against and tested with Geant4 10.6.

Important note: these days geant4 primarily works via the cmake framework. However grasshopper can also use the older Makefile framework. It is important that you source the appropriate shell script in geant4 directories to enable all the env. variables that are necessary for Makefile to work correctly. In my particular case I have the following line in my .bashrc file, please modify this accordingly for your build/configuration:

. /usr/local/geant4/geant4.10.05-install/share/Geant4-10.5.0/geant4make/geant4make.sh

If all the regular geant4 installations and configurations are ready, then the user can get the code by

> git clone https://github.com/ustajan/grasshopper.git

To build with GNUmake

> cd grasshopper

> make

To build with CMake

> mkdir RunGrasshopper && cd RunGrasshopper

> cmake ../../grasshopper && make -jN

To run

> grasshopper input.gdml output.root

Tutorial

The best way to learn how to use grasshopper is by using the tutorial on the project wiki, here. You can also get there by going to Wiki link above.

Input

Output

The code will generate three files:

The root output structure (which is identical to the ascii output) can be somewhat complex. The output of the simulation can be thought of as a table -- where every line is an entry corresponding to a particular set of information within an event. Below is a set of entries in the ASCII output from a simulation of a 40meV neutron beam undergoing capture inside two 3He ionization chamber (numbered 5 and 37):

alt text

By enabling the BriefOutput flag in the gdml, it's is possible to get the shorter version of the above:

alt text

There are three type of entries:

The variables in the tree/table are as following:

The CreatorProcessName for IsEdepositedTotalEntry==1 entries contains a concatenation of all the processes which contributed to the deposited energy. This is a good way to study the various effecst which, for example, contribute to the photopeak and the Compton continuum in a gamma detector.

Finally, it is also possible to request a brief output, in the form of EventID, Energy, ParticleName, and CreatorProcessName. To do this set the BriefOutputOn flag to 1, in the gdml input.

The output can be modified to be only limited for just one or two of these entry types. The gdml file allows to do this using the SaveSurfaceHitTrack, SaveTrackInfo, SaveEdepositedTotalEntry variables. For example, for a simulation where the flux is to be determined, only SaveSurfaceHitTrack needs to be set. For studying the energy deposition distribution for a particular type of detector the SaveEdepositedTotalEntry needs to be set. The use of these variables can significantly simplify the analysis of the MC output.

General status

In its current form, the code has been tested with <12MeV photons, neutrons, gammas, and electrons. Very general checks indicate that most processes are being simulated correctly.

A few known problems:

To do

Below is a prioritized list of future tasks.

* OUTPUT
  + Implement "simple" ascii text output, along with ROOT  -- DONE
  + Make the code be able to reliably switch between ROOT (when ROOT is available) and ASCII output -- DONE
* Write the python/javascript front end to the gdml? <<===== need a UROP
* Check the physics, by comparing to data and validated geant4 simulations -- DONE
  + Did some basic comparisons of gamma transmission to exp(-mu*x)
* automatic wrl generation (even in batch mode), limited to 300 tracks -- DONE
* Implement the keeper list, which should allow to dramatically speed up the simulations -- DONE
* Clean up the code:
  + Replace the char arrays in TTree with actual strings -- DONE

Requirements for the front end

The front end will read in a simple ASCII text file with "human readable" descriptions, parse it, populate a gdml file based on some template, and run the geant4 simulation. The ASCII input file needs to have the following fields and sections

* Particle Event Generator parameters
  + Particle type definition.  Ideally, this should include ions.  A list should be provided in a separate .md document
  + Particle energy
  + Directionality.  For simplicity, limit it to:  parallel;  isotropic.
  + Beam source x,y,z
  + Beam width
* Geometries
  + Number of geometries -- N (default:1).  No daughter geometries.
    If people want to do that, they can modify the gdml directly.
  + Materials: *only* limited to NIST materials, provided by a (long) list.
    If people want custom materials, they can modify the gdml directly.
  + Geometry1:
    - Sensitive?  If yes, its energy deposition will be measured and added to the output.
      An additional branch needs to be added, which will list the detector name.
    - volume -- shape
    - logical -- add material.
    - physical placement in the world.  If this is a sensitive volume, then the name needs to
      end with _number.  This number will go into the tree branch.
  + Geometry2, etc...
* Keeper list and cuts
  + This list should contain the following:  particle type; energy threshold E_th; volume volname
  + Now, for every particle type, only tracks with E>E_th *inside* volname will be tracked
  + Everything else will be killed
  + Example of how this will look:
    - neutron:  0.1 MeV,  everywhere
    - gamma  :  0.1 MeV,  everywhere
    - e-     :  0.1 MeV,  detector_volume
    - proton :  1.0 MeV,  detector_volume
  + The code will generate a vector, and for every step will loop over the vector, checking if these
    conditions are met.  If not, it will kill the track.