Filtering PYTHIA Events In Starsim

Within the STAR framework, simulation files are created with the command starsim which runs both PYTHIA and GEANT.  Unfortunately, this means that there is no straightforward way to filter PYTHIA events before the GEANT reconstruction and producing simulation files for rare events can be very time consuming, as most of the CPU is wasted on the GEANT reconstruction of undesired events.

The trick around this is to modify the PYTHIA libraries themselves.  In particular we want to modify the PYEVNT subroutine which is run during the generation of each PYTHIA event.  Begin by

  •     Checking out a copy of the pythia libraries from cvs
  •     Create a back up of pyevnt.F in case anything goes wrong
  •     Open up pyevnt.F in your favorite text editor
  •     Rename SUBROUTINE PYEVNT to SUBROUTINE PYEVNT_ORG
  •     Now create your own subroutine, SUBROUTINE PYEVNT
  •     Copy the variable declarations and commonblocks from the original PYEVNT

The body of this new subroutine will in general go as the following

while(conditions have not been met)

Call the original PYEVNT
Call any necessary auxillery subroutines
Loop over particles
if(not desired characteristic a) continue
if(not desired characteristic b) continue
...
if(not desired characteristic i) continue
Calculate relevant kinematic variables
Check conditions
Call PYLIST

Note that to avoid too many nested if loops we abort when the first test fails.

For example, consider an analysis requiring a high energy electron in the endcap.  The usual PYTHIA settings allow one to require a high energy electron, but there is no way to restrict its location in the detector.  So in the above pseudocode becomes

while(no high pT electron in the endcap)

Call the original PYEVNT
Loop over particles
if(not electron) continue
Calculate pT
Calculate eta
if(pT < 15) continue
if(eta < 1) continue
if(eta > 2) continue
return
Call PYLIST

The main background to the above is charged hadrons/mesons.  In order to filter these we require that the particle has a charge of +/- 1, that is has the PDG ID of a hadron or a meson, that it has not decayed in the PYTHIA record, and fulfills the kinematic requirements.

while(no high pT jet in the endcap)

Call the original PYEVNT
Loop over the jets at the end of the PYTHIA record
if(not stable) continue
if(charge not equal +/- 1) continue
if(not hadron or meson) continue
Calculate pT
Calculate eta
if(pT < 15) continue
if(eta < 1) continue
if(eta > 2) continue
return
Call PYLIST

Once pyevnt.F has been succussfully modified it must be compiled with cons, and the path to the compiled library itself must be explicitly set in the kumac.  For example,

gexec $STAR_LIB/libpythia_6410.so

must be replaced by

gexec /star/u/username/path_to_directory/.slxx_gccxxxx/lib/name_of_new_pythia_library.so

Examples of modified pyevnt.F files for both the electron example and the jet example are attached, as is a kumac for use with the jet example.