# Documentation page for g4sbs

This page is maintained by the UConn group (Andrew Puckett) and as of July 22, 2015 is based on the "uconn_dev" branch of g4sbs on github.

## Getting the code and building the program

### Prerequisites

• Working ROOT installation. g4sbs is not yet compatible with root version 6!
• Working GEANT4 installation. For the uconn_dev branch, g4sbs is only compatible with GEANT4 version 10.0 and later.
• cmake (also required in any case to build GEANT4).

Note on GEANT4 build options:

• GEANT4_INSTALL_DATA=ON is needed
• On Mac OS X, I have built GEANT4 against Qt version 5.3.2. Newer versions of Qt seem to cause GEANT4 Qt-based visualization to crash.

The code is hosted on a github repository owned by JLab. To clone via ssh (preferred method on JLab batch farm), do:

 git clone git@github.com:JeffersonLab/g4sbs.git

For this method to work, the ssh public key on the machine where you want to get the code must be added to your github account (see Guide to generating ssh keys and adding to your github.com account.)

Cloning the repository defaults to the "master" branch. This page documents the "uconn_dev" branch, which will soon be merged into the master branch. To change to the "uconn_dev" branch, do:

 git checkout uconn_dev

### Building the program

Create a "build" directory that is parallel to the "g4sbs" source directory (this is not strictly required, but the build directory must be separate from the "g4sbs" directory. The following instructions assume that "build" is parallel to "g4sbs":

 mkdir build cd build cmake ../g4sbs make

If successful, the g4sbs executable and several other files and folders will be created in the "build" directory.

## How to run the program

g4sbs works in two different modes, batch mode or interactive mode. In interactive mode, visualization of the geometry and events is possible. To run in interactive mode, do

 ./g4sbs

This will launch an interactive g4sbs session which, depending on your GEANT4 build, might be a csh terminal, a Qt GUI, or something in between. The Qt GUI in particular has a complete help menu:

To run g4sbs in batch mode, do one of the following:

 ./g4sbs file.mac OR ./g4sbs preinit.mac postinit.mac,

where each ".mac" file is a text file containing valid GEANT4 and/or g4sbs commands, used to configure the simulation. If g4sbs is invoked with one command-line argument as in the first example, it will execute all the commands in "file.mac" after G4RunManager::Initialize(). If g4sbs is invoked with two command line arguments as in the second example, it will execute the commands in "preinit.mac" before G4RunManager::Initialize() and the commands in "postinit.mac" after G4RunManager::Initialize(). As detailed below, this feature was added to make it possible for the user to disable optical photon production via the Cherenkov and Scintillation processes without re-compiling the code, and a long-standing GEANT4 bug prevents disabling of the scintillation process via the standard /process/inactivate command.

## g4sbs commands

This section documents all g4sbs commands.

• /g4sbs/run nevent: runs the simulation with nevent events. Note that this command forces building or rebuilding of the geometry, in contrast to /run/beamOn, which does not re-initialize the G4 kernel. Presently, g4sbs will crash if the /g4sbs/run command is invoked more than once in a g4sbs session (bug is under investigation), meaning that configuration changes require separate simulation jobs.
• /g4sbs/gemconfig: expects one integer argument, defines BigBite GEM layout, possible values are 1 (default), 2, 3
• /g4sbs/CDetconfig: defines configuration of the coordinate detector. This command is obsolete and currently has no effect
• /g4sbs/ECALmap: Accepts one string argument which is the name of a text file listing active ECAL cells (rows, columns). File is assumed to be located in the database/ subdirectory. This command is obsolete and currently has no effect
• /g4sbs/filename: Define output ROOT file name.
• /g4sbs/sigmafile: File containing GEM coordinate resolutions by chamber ID number. This command is obsolete and currently has no effect
• /g4sbs/target: Choose target type. Possible values currently include:
• LH2: liquid hydrogen target with scattering chamber and vacuum snout. Density fixed at 0.071 g/cm$^3$
• LD2: liquid deuterium target with scattering chamber and vacuum snout. Density fixed at 0.1624 g/cm$^3$
• H2: Hydrogen gas target, fixed pressure of 10.5 atm at 300 K
• 3He: Helium-3 gas target, fixed pressure of 10.77 atm at 300 K.
• neutron: Free neutron target, fixed pressure of 10.5 atm at 300 K.
• Note: All gas targets are currently enclosed in a GE180 glass cell with endcap thickness of 0.126 mm and wall thickness of 1.61 mm
• /g4sbs/kine: Choose kinematics for event generator. In all cases, unless otherwise noted, interaction vertex is generated flat assuming a square raster centered at (x,y)=(0,0) with user-defined raster size in x and y, and z along the target length. Currently available kinematics types are:
• elastic: elastic electron-nucleon scattering. Electron polar and azimuthal angles are generated flat in $\cos \theta$ and $\phi$ within user-defined limits, everything else calculated from energy-momentum conservation. Cross section according to Kelly fit for GEp, GMp, GMn and Hall A GEn collaboration fit of GEn data. Behavior depends on target type:
• For H2 or LH2 or neutron targets: elastic electron scattering from free proton (or neutron) at rest
• For LD2 or $^3$He targets: Quasi-elastic electron-nucleon scattering with Fermi motion simulated by sampling the initial nucleon momentum from the momentum distribution in deuterium or $^3$He.
• flat: Generate electron angles flat in $\cos \theta$, $\phi$, and $E'$. Generate final nucleon assuming that the outgoing nucleon absorbs all of the three-momentum transfer from the electron. Not clear how much sense this makes physically.
• dis: Deep inelastic scattering. Generate scattered electron angles flat within user-defined limits, generate $E'$ flat in $0 \le E' \le E$. Reject event if not kinematically allowed. Don't generate any final hadrons. Cross section based on CTEQ6 PDFs and neglect of longitudinal structure function $F_L = 0$
• beam: Beam kinematics. Generate beam electrons 5 meters upstream of the target with (x,y) according to normal raster size definitions.
• sidis: Single-hadron semi-Inclusive deep inelastic scattering (SIDIS). Generate outgoing electron and hadron angles flat in $\cos \theta$ and $\phi$ within user-defined limits. Generate outgoing electron and hadron energies flat within user-defined limits. Check four-momentum conservation and reject event/try again until a kinematically allowed event is returned. Compute cross section according to CTEQ6 PDFs and DSS2007 fragmentation functions. Assume flavor-independent Gaussian transverse momentum widths for PDF and fragmentation function. Neglect the longitudinal cross section for SIDIS. On output, normalize phase-space volume for event generation according to the efficiency for generating kinematically allowed events.