Proton Calorimetry/Detector Simulation: Difference between revisions

From PBTWiki
Jump to navigation Jump to search
No edit summary
 
(51 intermediate revisions by the same user not shown)
Line 4: Line 4:
To use the existing installation, follow [http://www.hep.ucl.ac.uk/pbt/wiki/Software/Geant4 this dedicated page].
To use the existing installation, follow [http://www.hep.ucl.ac.uk/pbt/wiki/Software/Geant4 this dedicated page].


== Local Installation on MacOS ==
== Local Installation of GEANT4 on MacOS ==


''Correct for MacOS High Sierra 10.13.6''
''Tested on macOS Ventura 13.3.1''


* Install Xcode 10 or higher from Mac App Store and install command line tools by executing in a terminal window <code>xcode-select --install</code>.
* Install Xcode 13 or higher from the Mac App Store and install command line tools by executing in a terminal window <code>xcode-select --install</code>. Agree to the Xcode license: <code>sudo xcodebuild -license</code>
* Install CMake 3.8 or higher [https://github.com/Kitware/CMake/releases/download/v3.16.4/cmake-3.16.4-Darwin-x86_64.dmg]
* Install XQuartz [https://www.xquartz.org/]
* Optional: Install CLHEP 2.4.1.0 or higher [http://proj-clhep.web.cern.ch/proj-clhep/dist1/clhep-2.4.1.3.tgz] (see README for build/install instructions)
* Install MacPorts appropriate for your system [https://www.macports.org/install.php].
** <code><source_code_dir><code> is the directory where the README is located.
* Install CMake using MacPorts: <code> sudo port install cmake </code>
** <code><build_directory><code> can be any folder you like (can be deleted after installation).
* Install Qt5 [https://www.qt.io/download-open-source]
** <code><install_directory><code> should be the default: <code>/usr/local<code>
** You will need to register for an account as an open-source developer.
* Install Expat 2.0.1 or higher [https://github.com/libexpat/libexpat/archive/R_2_2_9.tar.gz] (see README for build/install instructions)
** Only need to install the latest version of Qt5 (5.15.2)
** Execute <code>./buildconf.sh<code> and then <code>./configure<code> in the directory <code><download_directory>/expat<code>
*Install GEANT4 [http://geant4.web.cern.ch/support/download]
** Might need to use <code>sudo<code> when executing <code>make install<code>
**See installation guide [http://geant4-userdoc.web.cern.ch/geant4-userdoc/UsersGuides/InstallationGuide/html/installguide.html here]
* Install zlib 1.2.3 or higher [https://zlib.net/zlib-1.2.11.tar.gz] (see README for build/install instructions)
**Download the GEANT4 source code and copy to a convenient location, e.g. in the Applications folder: <code>/Applications/GEANT4/geant4-vX.Y.Z</code> and then create parallel directories for the build and install folders.
** Might need to use <code>sudo when executing <code>make install<code>
**In the GEANT4 build folder, execute: <code>cmake -DCMAKE_INSTALL_PREFIX=../geant4-vX.Y.Z-install -DGEANT4_BUILD_MULTITHREADED=ON -DGEANT4_INSTALL_DATA=ON -DGEANT4_USE_GDML=OFF -DGEANT4_USE_QT=ON -DQT_QMAKE_EXECUTABLE=<path to Qt installation folder>/5.15.2/clang_64/bin/qmake -DCMAKE_PREFIX_PATH=<path to Qt installation folder>/5.15.2/clang_64/lib/cmake -DGEANT4_USE_OPENGL_X11=OFF -DGEANT4_USE_RAYTRACER_X11=OFF -DGEANT4_USE_SYSTEM_EXPAT=OFF -DGEANT4_USE_SYSTEM_ZLIB=OFF ../geant4-vX.Y.Z</code>
* Install Xerces-C++ headers and library 3 or higher [http://xerces.apache.org/xerces-c/download.cgi]
**Then execute: <code>make -jN</code> where N is the number of cores your machine has.
** Will need to install GPG [https://gpgtools.org/] to verify KEYS
**Then execute: <code>make install</code>
* Install GEANT4 [http://geant4-userdoc.web.cern.ch/geant4-userdoc/UsersGuides/InstallationGuide/html/installguide.html#geant4buildoptions]
*Source the geant4.sh script as appropriate for your shell so that the environment is set every time a new terminal window is opened:
** Enable additional build options: multithreading, install data, GDML, QT, OpenGL, RayTracer, zlib
**If using bash, in your <code>.bash_profile</code> (in your home directory, press CMD+SHIFT+. to make the file visible) add the line <code>. <path to GEANT4 installation folder>/bin/geant4.sh</code>
** Apparently system CLHEP should not be used unless absolutely necessary
**If using zsh, in your <code>.z_profile</code> (in your home directory, press CMD+SHIFT+. to make the file visible) add the line <code>pushd <path to GEANT4 installation folder>/bin >/dev/null; source geant4.sh; popd >/dev/null</code>
*Try compiling the basic example B1:
**Copy the source folder of example B1: <code><path to GEANT4 installation folder>/share/Geant4-<your version here>/examples/basic/B1</code> to a convenient directory.
**Make a directory in which to build: <code>mkdir build</code> and then move to this directory, <code>cd build</code>
**Execute <code>cmake -DCMAKE_PREFIX_PATH=<path to GEANT4 installation folder>/lib/ ../</code>
**Execute <code>make -jN</code> where N is the number of cores your machine has.
**Run the example: <code>./exampleB1</code>
 
== Running QUARC Detector Simulation ==
 
*You can copy the simulation files from this path on the HEP cluster: <code>/unix/pbt/users/sshaikh/Simulation</code>  
*In the folder 'build', execute: <code>sudo cmake -DCMAKE_PREFIX_PATH=/usr/local/lib/Geant4-<YOUR VERSION HERE>/ <YOUR PATH TO SIMULATION FOLDER></code>
*Then, execute: <code>sudo make</code>
*To run the simulation with the default macro, <code>inter.mac</code>, execute: <code>./ProtonSimulation</code>
*To run the simulation with a different macro, e.g. <code>interactive.mac</code>, execute: <code>./ProtonSimulation ../macros/interactive.mac</code>
 
=== Running QUARC Detector Simulation in Eclipse IDE ===
*Create new makefile project with existing code in Eclipse and choose the directory containing <code>CMakeLists.txt</code> as the Existing Code Location.
*Under Run -> External Tools -> External Tools Configurations:
**Create a new launch configuration and set the variables Location to <code>${workspace_loc:/Simulation/eclipse_build.sh}</code> and Working Directory to: <code>${workspace_loc:/Simulation/build}</code> (adjust paths if needed).
**This will run <code>cmake</code>, which is necessary before building.
**Set Refresh behaviour to refresh the workspace after completion.
**Uncheck Build Before Launch
*Under Project Properties –> C/C++ build:
**Uncheck "Use Default Build Command" and "Generate Makefiles Automatically".
**Set the build command to: <code>make -jN</code> where N is the number of cores your machine has.
**Set the build location to: <code>${workspace_loc:/Simulation}/build</code>, adjusting path if needed.
*Under Project Properties –> C/C++ General –> Paths and Symbols -> Includes, add the variables to include GEANT4 headers (for all languages and configurations, adjusting directories appropriately for your installations):
**<code>/usr/local/include/GEANT4</code>
**<code>/usr/local/include/CLHEP</code> (May not be necessary and requires non-GEANT4 installation of CLHEP).
**<code>/Applications/root_v6.20.00</code> (If ROOT is required)
*Under Run -> Run Configurations, create a new configuration of type C/C++ application for the project:
**Set C/C++ application to <code>build/ProtonSimulation</code>
**Under Arguments, set the working directory to: <code>${workspace_loc:Simulation}/build</code>
**Under Environment, define the variables pointing to GEANT4's data sets:
***These are defined at the bottom of <code>/usr/local/bin/geant4.sh</code> under 'Export resource file paths'
***e.g. Variable: <code>G4ENSDFSTATEDATA</code>, Value: <code>/usr/local/share/Geant4-10.6.1/data/G4ENSDFSTATE2.2</code>
***There are 11 of them in GEANT4 10.6.1.
*To then run the simulation, run the external tool and then run the launch configuration (which by default will make and run the application).
 
== General Notes ==
 
* In output file <code>EdepAccurate</code>, each number represents the energy deposited in the user-defined sheet thickness, divided by spatial resolution (not in file name)
** e.g. <code>EdepAccurate_252.7MeV_200x2_500mustep_100p_refl.out</code> represents 252.7 MeV beam, 200 sheets of 2mm thickness, 500 micron StepMax, 100 protons, reflection allowed.  
** StepMax represents the minimum resolution in GEANT4’s tracking of particles, characteristics are calculated in distance intervals. If undefined, GEANT4 will choose a step size that represents the finest increment required by the various physics lists. Default value might be ~2mm.
* Can choose to record number of photons produced or number of photons that reach the edge of the scintillator. In the latter, allowing reflections is necessary.
** Number of photons produced is stored in <code>NPhoton</code>
** Number of photons that reach edge of scintillator is stored in <code>NPhotonTop</code>
* In file Hits, there is a list of all protons produced in simulation with their energy, 2 mystery numbers and their stopping depth.
** Small numbers are indicative of a nuclear interaction, which results in a proton being deflected sufficient to warrant a new particle ID.
* The parameter <code>rangeCut</code> defines the minimum range of a secondary particle (electrons, positrons & gammas) such that it is tracked until it stops. Such particles with ranges below <code>rangeCut</code> just have their energy deposited in place and are then deleted. This is such to avoid long-computation times.
** This does not however apply to any other secondaries, e.g. neutrons or alpha particles.
* Notation: e.g. <code>/control/multiply x {y} {z} </code>
** x = y times z
** Brackets are required when using previously defined variables
* Positional origin of simulation is in middle of scintillator
* It is more important to have sufficient numbers of protons in simulation in order to accurately simulate the energy deposition curve. While in reality approx. 10000 photons per MeV lost in protons is produced, this would take far too long to simulate and would require reducing the number of protons. However, the depth-light curve can only ever be as good as the energy deposition curve – so sampling more photons with only few protons will NOT give a good depth-light curve.
 
== Existing Issues ==
*The macros, e.g. <code>inter.mac</code> attempt to define aspects of the detector geometry, but fail do so. It appears that GEANT4 defines a geometry based on <code>PTDetectorConstruction</code> and then does not allow the macro to update the geometry. See <code>ProtonSimulation.cc</code>: the macro is called after the geometry is defined. Find some code where a macro redefines the geometry successfully to find out where to place the macro-defined geometry parameters. Probably needs work in the Messenger source files or <code>PTDetectorConstruction::UpdateGeometry()</code>.

Latest revision as of 00:25, 21 November 2023

This page contains information on the Geant4 code that form the Proton Calorimetry detector simulation.

In order to run Geant4 simulations, you will either need to download and install the software yourself or make use of the existing installation on the UCL HEP Linux cluster. To use the existing installation, follow this dedicated page.

Local Installation of GEANT4 on MacOS

Tested on macOS Ventura 13.3.1

  • Install Xcode 13 or higher from the Mac App Store and install command line tools by executing in a terminal window xcode-select --install. Agree to the Xcode license: sudo xcodebuild -license
  • Install XQuartz [1]
  • Install MacPorts appropriate for your system [2].
  • Install CMake using MacPorts: sudo port install cmake
  • Install Qt5 [3]
    • You will need to register for an account as an open-source developer.
    • Only need to install the latest version of Qt5 (5.15.2)
  • Install GEANT4 [4]
    • See installation guide here
    • Download the GEANT4 source code and copy to a convenient location, e.g. in the Applications folder: /Applications/GEANT4/geant4-vX.Y.Z and then create parallel directories for the build and install folders.
    • In the GEANT4 build folder, execute: cmake -DCMAKE_INSTALL_PREFIX=../geant4-vX.Y.Z-install -DGEANT4_BUILD_MULTITHREADED=ON -DGEANT4_INSTALL_DATA=ON -DGEANT4_USE_GDML=OFF -DGEANT4_USE_QT=ON -DQT_QMAKE_EXECUTABLE=<path to Qt installation folder>/5.15.2/clang_64/bin/qmake -DCMAKE_PREFIX_PATH=<path to Qt installation folder>/5.15.2/clang_64/lib/cmake -DGEANT4_USE_OPENGL_X11=OFF -DGEANT4_USE_RAYTRACER_X11=OFF -DGEANT4_USE_SYSTEM_EXPAT=OFF -DGEANT4_USE_SYSTEM_ZLIB=OFF ../geant4-vX.Y.Z
    • Then execute: make -jN where N is the number of cores your machine has.
    • Then execute: make install
  • Source the geant4.sh script as appropriate for your shell so that the environment is set every time a new terminal window is opened:
    • If using bash, in your .bash_profile (in your home directory, press CMD+SHIFT+. to make the file visible) add the line . <path to GEANT4 installation folder>/bin/geant4.sh
    • If using zsh, in your .z_profile (in your home directory, press CMD+SHIFT+. to make the file visible) add the line pushd <path to GEANT4 installation folder>/bin >/dev/null; source geant4.sh; popd >/dev/null
  • Try compiling the basic example B1:
    • Copy the source folder of example B1: <path to GEANT4 installation folder>/share/Geant4-<your version here>/examples/basic/B1 to a convenient directory.
    • Make a directory in which to build: mkdir build and then move to this directory, cd build
    • Execute cmake -DCMAKE_PREFIX_PATH=<path to GEANT4 installation folder>/lib/ ../
    • Execute make -jN where N is the number of cores your machine has.
    • Run the example: ./exampleB1

Running QUARC Detector Simulation

  • You can copy the simulation files from this path on the HEP cluster: /unix/pbt/users/sshaikh/Simulation
  • In the folder 'build', execute: sudo cmake -DCMAKE_PREFIX_PATH=/usr/local/lib/Geant4-<YOUR VERSION HERE>/ <YOUR PATH TO SIMULATION FOLDER>
  • Then, execute: sudo make
  • To run the simulation with the default macro, inter.mac, execute: ./ProtonSimulation
  • To run the simulation with a different macro, e.g. interactive.mac, execute: ./ProtonSimulation ../macros/interactive.mac

Running QUARC Detector Simulation in Eclipse IDE

  • Create new makefile project with existing code in Eclipse and choose the directory containing CMakeLists.txt as the Existing Code Location.
  • Under Run -> External Tools -> External Tools Configurations:
    • Create a new launch configuration and set the variables Location to ${workspace_loc:/Simulation/eclipse_build.sh} and Working Directory to: ${workspace_loc:/Simulation/build} (adjust paths if needed).
    • This will run cmake, which is necessary before building.
    • Set Refresh behaviour to refresh the workspace after completion.
    • Uncheck Build Before Launch
  • Under Project Properties –> C/C++ build:
    • Uncheck "Use Default Build Command" and "Generate Makefiles Automatically".
    • Set the build command to: make -jN where N is the number of cores your machine has.
    • Set the build location to: ${workspace_loc:/Simulation}/build, adjusting path if needed.
  • Under Project Properties –> C/C++ General –> Paths and Symbols -> Includes, add the variables to include GEANT4 headers (for all languages and configurations, adjusting directories appropriately for your installations):
    • /usr/local/include/GEANT4
    • /usr/local/include/CLHEP (May not be necessary and requires non-GEANT4 installation of CLHEP).
    • /Applications/root_v6.20.00 (If ROOT is required)
  • Under Run -> Run Configurations, create a new configuration of type C/C++ application for the project:
    • Set C/C++ application to build/ProtonSimulation
    • Under Arguments, set the working directory to: ${workspace_loc:Simulation}/build
    • Under Environment, define the variables pointing to GEANT4's data sets:
      • These are defined at the bottom of /usr/local/bin/geant4.sh under 'Export resource file paths'
      • e.g. Variable: G4ENSDFSTATEDATA, Value: /usr/local/share/Geant4-10.6.1/data/G4ENSDFSTATE2.2
      • There are 11 of them in GEANT4 10.6.1.
  • To then run the simulation, run the external tool and then run the launch configuration (which by default will make and run the application).

General Notes

  • In output file EdepAccurate, each number represents the energy deposited in the user-defined sheet thickness, divided by spatial resolution (not in file name)
    • e.g. EdepAccurate_252.7MeV_200x2_500mustep_100p_refl.out represents 252.7 MeV beam, 200 sheets of 2mm thickness, 500 micron StepMax, 100 protons, reflection allowed.
    • StepMax represents the minimum resolution in GEANT4’s tracking of particles, characteristics are calculated in distance intervals. If undefined, GEANT4 will choose a step size that represents the finest increment required by the various physics lists. Default value might be ~2mm.
  • Can choose to record number of photons produced or number of photons that reach the edge of the scintillator. In the latter, allowing reflections is necessary.
    • Number of photons produced is stored in NPhoton
    • Number of photons that reach edge of scintillator is stored in NPhotonTop
  • In file Hits, there is a list of all protons produced in simulation with their energy, 2 mystery numbers and their stopping depth.
    • Small numbers are indicative of a nuclear interaction, which results in a proton being deflected sufficient to warrant a new particle ID.
  • The parameter rangeCut defines the minimum range of a secondary particle (electrons, positrons & gammas) such that it is tracked until it stops. Such particles with ranges below rangeCut just have their energy deposited in place and are then deleted. This is such to avoid long-computation times.
    • This does not however apply to any other secondaries, e.g. neutrons or alpha particles.
  • Notation: e.g. /control/multiply x {y} {z}
    • x = y times z
    • Brackets are required when using previously defined variables
  • Positional origin of simulation is in middle of scintillator
  • It is more important to have sufficient numbers of protons in simulation in order to accurately simulate the energy deposition curve. While in reality approx. 10000 photons per MeV lost in protons is produced, this would take far too long to simulate and would require reducing the number of protons. However, the depth-light curve can only ever be as good as the energy deposition curve – so sampling more photons with only few protons will NOT give a good depth-light curve.

Existing Issues

  • The macros, e.g. inter.mac attempt to define aspects of the detector geometry, but fail do so. It appears that GEANT4 defines a geometry based on PTDetectorConstruction and then does not allow the macro to update the geometry. See ProtonSimulation.cc: the macro is called after the geometry is defined. Find some code where a macro redefines the geometry successfully to find out where to place the macro-defined geometry parameters. Probably needs work in the Messenger source files or PTDetectorConstruction::UpdateGeometry().