Warning, /tutorial-simulations-using-ddsim-and-geant4/episodes/02-physics-event-simulations.md is written in an unsupported language. File is not indexed.
0001 ---
0002 title: "Running physics simulations with `ddsim`"
0003 teaching: 30
0004 exercises: 20
0005 ---
0006
0007 ::::::::::::::::::::::::::::::::::::::::::::: questions
0008
0009 - How can I simulate events from physics event generators?
0010
0011 :::::::::::::::::::::::::::::::::::::::::::::
0012
0013 ::::::::::::::::::::::::::::::::::::::::::::: objectives
0014
0015 - `ddsim` can simulate HepMC3 events in DD4hep geometries.
0016 - `npsim` can be used as an alternative for simulations with optical photons.
0017
0018 :::::::::::::::::::::::::::::::::::::::::::::
0019
0020 We now move on to running simulations on HepMC3 event input files from (in this case) Pythia8.
0021
0022 ## Using centrally produced input files
0023
0024 The large input files for simulation campaigns are stored on xrootd, but the `eic-shell` environment allows us to access them. We can connect to the server and take a look at the file:
0025
0026 ```bash
0027 xrdfs root://dtn-eic.jlab.org
0028 ls /volatile/eic/EPIC/Tutorials/pythia8NCDIS_10x100_minQ2=1_beamEffects_xAngle=-0.025_hiDiv.hepmc
0029 exit
0030 ```
0031
0032 This input file is large (GBs). For this tutorial we only need the first few thousand lines. We can do this for the first 20000 lines using the following command:
0033
0034 ```bash
0035 xrdfs root://dtn-eic.jlab.org cat /volatile/eic/EPIC/Tutorials/pythia8NCDIS_10x100_minQ2=1_beamEffects_xAngle=-0.025_hiDiv.hepmc | head -n 20000 > pythia8NCDIS_10x100.hepmc
0036 ```
0037
0038 We can now specify this HepMC3 input file as input to `ddsim`:
0039
0040 ```bash
0041 ddsim --compactFile $DETECTOR_PATH/$DETECTOR_CONFIG.xml --numberOfEvents 10 --inputFiles pythia8NCDIS_10x100.hepmc --outputFile pythia8NCDIS_10x100.edm4hep.root
0042 ```
0043
0044 Instead of downloading files, we can also request events on-demand from the publicly accessible EIC XRootD server, but in this case we must use the `hepmc3.tree.root` input file extension:
0045
0046 ```bash
0047 ddsim --compactFile $DETECTOR_PATH/$DETECTOR_CONFIG.xml --numberOfEvents 10 --inputFiles root://dtn-eic.jlab.org//work/eic2/EPIC/Tutorials/pythia8NCDIS_10x100_minQ2=1_beamEffects_xAngle=-0.025_hiDiv.hepmc3.tree.root --outputFile pythia8NCDIS_10x100.edm4hep.root
0048 ```
0049
0050 ## Creating your own input files
0051
0052 Rather than relying on the centrally produced events, we can also create events ourselves. This gives us flexibility to run on and off certain event generator effects.
0053
0054 ### Head-on versus rotated collision frames: the "afterburner"
0055
0056 In this exercise, we will use Pythia8 to generate DIS neutral current interactions, but we could use other event generators as well. However, we have to pay attention to the reference frames in which interactions are generated. Most event generators are set up to generate events in the head-on collision frame of reference. This is not the reference frame in which beams collide at the EIC: the beams have a crossing angle of -0.025 mrad. In addition, there are beam energy smearing effects that cause the beam energies to deviated from the 'exact' values indicated in the settings: a 10 GeV electron beam contains in reality electrons with energies distributed around 10 GeV. To correct for crossing angle and beam energy smearing, we can modify the event generator or we can apply an "afterburner" which rotates and boosts events from the head-on fram into the correct frame. The afterburner is beyond the scope of this episode, but can be found at [eic/afterburner](https://github.com/eic/afterburner).
0057
0058 ### Using Pythia8 with crossing angle and beam energy corrections
0059
0060 Rather than relying on the afterburner, we have modified Pythia8 to include the required corrections directly upon event generation. The steering code and input files can be found at [eic/eicSimuBeamEffects](https://github.com/eic/eicSimuBeamEffects), so we start with using git to obtain this code.
0061
0062 ```bash
0063 git clone https://github.com/eic/eicSimuBeamEffects
0064 ```
0065
0066 We can compile the code inside the `eic-shell` environment (which includes the Pythia8 event generator libraries that are used by this simulation):
0067
0068 ```bash
0069 cd eicSimuBeamEffects/Pythia8
0070 make
0071 ```
0072
0073 After compilation, we can use the executable `runBeamShapeHepMC.exe` to generate events, but we need to provide some arguments:
0074
0075 ```bash
0076 ./runBeamShapeHepMC.exe
0077 Wrong number of arguments
0078 program.exe steer configuration hadronE leptonE xangle out.hist.root out.hepmc
0079 ```
0080
0081 The various steering files in `steerFiles` contain various beam conitions. Here we will use the 10 GeV electron on 100 GeV proton conditions in the high beam divergence setting (`hiDiv`), or the steering file `dis_eicBeam_hiDiv_10x100`. The `hiDiv` setting requires the `configuration` flag value `1` (as explained in the `README.md` file).
0082
0083 ```bash
0084 ./runBeamShapeHepMC.exe steerFiles/dis_eicBeam_hiDiv_10x100 1 100 10 -0.025 \
0085 pythia8NCDIS_10x100_minQ2=1_beamEffects_xAngle=-0.025_hiDiv.hist.root \
0086 pythia8NCDIS_10x100_minQ2=1_beamEffects_xAngle=-0.025_hiDiv.hepmc
0087 ```
0088
0089 We can now run the output files through the `ddsim` simulation as before.
0090
0091 ## NPSim as an alternative to `ddsim`
0092
0093 Since some of the options that we pass to `ddsim` can only be provided through a steering file (such as python functions), or are otherwise cumbersome to provide on the command line, we provide `npsim` as a layer on top of `ddsim` that has these options pre-configured. This is as if you would take your steering file options and contribute them back to a central location for others to use them.
0094
0095 `npsim` can be easily interpreted (since it has sections that look exactly like the steering file). We can look at its python source code, located at `/opt/local/bin/npsim.py` in the `eic-shell` environment.
0096
0097 Currently `npsim` has the following additional options:
0098
0099 - Cerenkov and optical photon physics are added through a python setup function,
0100 - an optical photon filter is created and added to the DRICH,
0101 - a modified tracking detector action which absorbs optical photon,
0102 - the minimal energy deposition in the tracker is set to zero.
0103
0104 You can run `npsim` exactly as you would run `ddsim`.
0105
0106 ::::::::::::::::::::::::::::::::::::::::::::: challenge
0107
0108 ## Exercise: compare `npsim` with `ddsim`
0109
0110 - Rerun the previous Pythia8 simulation with `npsim`, and notice any difference in running time. Because of the addition of optical photon physics, the simulation will run more slowly.
0111 - Open the output file and verify that more hits (from optical photons with PDG code -22) are stored in the hits branches for the relevant RICH detector.
0112
0113 ::::::::::::::: solution
0114
0115 Running `npsim` with the same `--compactFile`, `--inputFiles`, and `--outputFile` arguments as the
0116 earlier `ddsim` command takes noticeably longer because optical photon physics is now simulated.
0117 Inspecting the DRICH `*Hits` branch in the output shows many additional hits, including optical
0118 photons (PDG code -22), that were absent from the `ddsim` output.
0119
0120 :::::::::::::::
0121
0122 :::::::::::::::::::::::::::::::::::::::::::::
0123
0124 ::::::::::::::::::::::::::::::::::::::::::::: callout
0125
0126 For most full physics analyses, the use of `npsim` is strongly preferred. The performance of some detector systems, including Cherenkov detectors as mentioned above, will be very different if `ddsim` is used. Similarly, trackers and calorimeters may appear to perform very differently. For some specialist use cases, `ddsim` may be preferred. If you are unsure whether such cases apply, use `npsim` when running your simulations.
0127
0128 :::::::::::::::::::::::::::::::::::::::::::::
0129
0130 ::::::::::::::::::::::::::::::::::::::::::::: keypoints
0131
0132 - `ddsim` or `npsim` are both able to simulate physics events.
0133 - **`npsim` should be used in almost all regular use cases for ePIC simulations**.
0134
0135 :::::::::::::::::::::::::::::::::::::::::::::