Back to home page

EIC code displayed by LXR

 
 

    


Warning, /drich-dev/doc/tutorials/1-setup-and-running-simulations.md is written in an unsupported language. File is not indexed.

0001 Tutorial 1: Setup and Running Simulations
0002 =========================================
0003 
0004 - [TUTORIAL RECORDING (mirror 1)](https://drive.google.com/file/d/1f8G-oGCrRXHA-6SYHbCELHprqWPgO8cE/view?usp=sharing)
0005   -- [CHAT](https://drive.google.com/file/d/1D9EcXTrWn79Ol8H6Ru9FrETlXhPvM83m/view?usp=sharing)
0006 - [TUTORIAL RECORDING (mirror 2)](https://duke.zoom.us/rec/play/Yw-MIwAVHgFw4XthFR1UMrXr5Byal0OaPAC1Q3TFoicZNJz3SUDnzCSfHp8BFv4Er-KoBVXTnUXV6GCK.eCqPDXFZFlyfCmZF?canPlayFromShare=true&from=my_recording&continueMode=true&componentName=rec-play&originRequestUrl=https%3A%2F%2Fduke.zoom.us%2Frec%2Fshare%2Fp8LyFsMFfAI1iKG5uaO_HITYEH1-mVHMGEkECwdl9_eRrReVg_FcsM_ksIbkI0o.SdMdb6ha55uUOTYJ)
0007 - [Return to Tutorial Landing Page](README.md)
0008 
0009 This is the first tutorial of the [dRICH Tutorial Series](README.md), which will cover setup and running of dRICH simulations.
0010 
0011 ## Prerequisite Common Training
0012 1. Setup of eic-shell and Github: <https://indico.bnl.gov/event/16826/>
0013 1. DD4hep geometry basics: <https://indico.bnl.gov/event/16828/>
0014 
0015 ## Clone Repositories
0016 First, clone the necessary repositories from [Github](https://github.com) and from [EICweb](https://eicweb.phy.anl.gov/EIC). If you are a member of the [EIC organization on Github](https://github.com/eic) and a member of the [EPIC Devs Team](https://github.com/orgs/eic/teams/epic-devs), you may clone Github repositories with `SSH`, otherwise you must clone with `HTTPS`. Direct contributions to Github repositories requires `SSH` access, otherwise you must fork repositories. The story is the same for [EICweb](https://eicweb.phy.anl.gov/EIC): use `SSH` if you are a member, otherwise use `HTTPS`.
0017 
0018 In today's tutorial we will only be working with the following repositories:
0019 - `drich-dev`
0020 - `epic`
0021 - `EICrecon` (some `drich-dev` local code is dependent on this)
0022 
0023 These are the only ones you need to clone for today. Future tutorials will use other repositories, so after today's tutorial, it is recommended to clone those as well. Here are the clone commands:
0024 
0025 - `drich-dev`
0026   - `SSH`:
0027     ```bash
0028     git clone git@github.com:eic/drich-dev.git
0029     ```
0030   - `HTTPS`:
0031     ```bash
0032     git clone https://github.com/eic/drich-dev.git
0033     ```
0034 
0035 Once you have a clone of `drich-dev`, you must `cd` into it, prior to cloning the other repositories:
0036 ```bash
0037 cd drich-dev
0038 ```
0039 Now proceed by cloning the other repositories (today we will only need `epic`):
0040 
0041 - Github Repositories:
0042   - `SSH`:
0043     ```bash
0044     git clone git@github.com:eic/epic.git
0045     git clone git@github.com:eic/irt.git
0046     git clone git@github.com:eic/EDM4eic.git
0047     git clone git@github.com:eic/EICrecon.git
0048     ```
0049   - `HTTPS`:
0050     ```bash
0051     git clone https://github.com/eic/epic.git
0052     git clone https://github.com/eic/irt.git
0053     git clone https://github.com/eic/EDM4eic.git
0054     git clone https://github.com/eic/EICrecon.git
0055     ```
0056 - EICweb Repositories:
0057   - `SSH`:
0058     ```bash
0059     git clone git@eicweb.phy.anl.gov:EIC/benchmarks/reconstruction_benchmarks.git
0060     ```
0061   - `HTTPS`:
0062     ```bash
0063     git clone https://eicweb.phy.anl.gov/EIC/benchmarks/reconstruction_benchmarks.git
0064     ```
0065 
0066 During development, you may make changes to multiple different repositories, and may be on different branches on each. To help keep track, there are two scripts:
0067 ```bash
0068 ./check_branches.sh   # list the current branch on every repository
0069 ./check_status.sh     # run 'git status' for each repository
0070 ```
0071 
0072 ## Building Repositories
0073 The `eic-shell` image contains all of the necessary software to run ePIC simulations and reconstruction, including builds of the repositories that you cloned above. We make our own clones here in `drich-dev`, so that you may override the `eic-shell` image builds and make changes.
0074 
0075 From here on, you must be in an `eic-shell` container shell.
0076 
0077 You can find which versions of software are installed in `eic-shell` by running:
0078 ```bash
0079 eic-info
0080 ```
0081 You may also find the installations themselves at `/opt/local`, which is useful if you want to check header files or libraries.
0082 
0083 Let's now build the local repositories, which will override the `eic-shell` builds.
0084 
0085 First, set the environment variables:
0086 ```bash
0087 source environ.sh
0088 ```
0089 
0090 Check if the number of CPUs was detected correctly:
0091 ```bash
0092 echo $BUILD_NPROC
0093 ```
0094 If it is wrong, then we need to fix the number detection in `environ.sh`; for now just hard code the correct number in `environ.sh` and run `source environ.sh` again, or just run
0095 ```bash
0096 export BUILD_NPROC=<CORRECT_NUMBER>
0097 ```
0098 replacing `<CORRECT_NUMBER>` with the correct number
0099 
0100 Practically all repositories use `cmake`, so you may proceed using the typical `cmake` commands. For convenience, `drich-dev` provides a `cmake` wrapper `build.sh` to build any local repository. The syntax is:
0101 ```bash
0102 build.sh <REPOSITORY>        # build a repository named <REPOSITORY>
0103 build.sh <REPOSITORY> clean  # remove the cmake buildsystem, and then build
0104 ```
0105 By default, the installation prefix (`CMAKE_INSTALL_PREFIX`) will be `$EIC_SHELL_PREFIX`. Running `source environ.sh` has modified your default `$EIC_SHELL_PREFIX` to a local directory: `./prefix`; this directory is where all the software that `build.sh` builds will be installed.
0106 
0107 Today, we only need to build `epic` (you do not need to build `EICrecon` yet):
0108 ```bash
0109 build.sh epic
0110 ```
0111 It's not yet necessary, but you may build the other repositories by running:
0112 ```bash
0113 build.sh irt
0114 build.sh EDM4eic
0115 build.sh EICrecon
0116 build.sh reconstruction_benchmarks
0117 ```
0118 Important: if you choose to build all of the repositories, you need to be sure to build them in the correct order of dependence. You can build all of the repositories in this order by running:
0119 ```bash
0120 rebuild_all.sh        # build all the repositories (that you have cloned) in the recommended order
0121 rebuild_all.sh clean  # remove the cmake buildsystems, and then build
0122 ```
0123 
0124 Notice that the build scripts allow for a `clean` option, which is useful for starting over from a clean state. In case you want to clean everything and start over, simply remove the `./prefix` directory, then run `rebuild_all.sh clean`. This is also useful to do after upgrading your `eic-shell` image (run `eic-shell --upgrade`), which you should do regularly, unless you are using a CVMFS build.
0125 
0126 After you have built the repositories, sourcing the environment variables file will set some additional variables to complete the override of `eic-shell`; run it again:
0127 ```bash
0128 source environ.sh
0129 ```
0130 Now that you have a build installed in `./prefix`, the next time you open an `eic-shell` container, you just need to run `source environ.sh` to get started.
0131 
0132 Finally, build the local code in `drich-dev`, which uses a `Makefile`:
0133 ```bash
0134 make        # build drich-dev code
0135 make clean  # remove drich-dev build (run 'make' again afterward to rebuild)
0136 ```
0137 
0138 ## Exploring the Geometry
0139 The `epic` repository contains the geometry for ePIC and is based on [DD4hep](https://github.com/AIDASoft/DD4hep). The [next tutorial](2-geometry-code.md) will go over the code within, but today we will learn how to run it.
0140 
0141 ### Viewing the Geometry
0142 First, let's look at the dRICH geometry itself. The `geoConverter` command is used for this; for convenience `drich-dev` provides a wrapper: `geometry.sh`. Run:
0143 ```
0144 geometry.sh      # print the usage guide
0145 geometry.sh -d   # make a TGeo ROOT file for the dRICH only
0146 geometry.sh -e   # make a TGeo ROOT file for the full ePIC detector
0147 ```
0148 By default the output file will be `geo/detector_geometry.root`. You may open it with ROOT or [JSROOT](https://root.cern/js/). For JSROOT, you may use a hosted instance (found in the aforementioned link), or you may host your own instance (see below; this is convenient if you intend to make many geometry changes).
0149 
0150 Coordinate system:
0151 - x axis is horizontal, to the left when facing the dRICH
0152 - y axis is vertical, toward the sky
0153 - z axis is along the electron beamline, toward the dRICH
0154 
0155 ![geo](img/geo.png)
0156 
0157 ### Geometry Constants
0158 There are several constant numbers in the geometry, for example, the z-position of the dRICH. You may view them using the `npdet_info` tool; for convenience, `drich-dev` provides a wrapper script `search_compact_params.sh`. Run:
0159 ```bash
0160 search_compact_params.sh                   # print the usage guide
0161 search_compact_params.sh -e                # dump all of the constants for ePIC
0162 search_compact_params.sh -e | grep DRICH   # dump all of the constants for the dRICH (they all begin with 'DRICH')
0163 ```
0164 The first column is the constant name, the second is the raw value (numbers in standard DD4hep units), and the third column is the original formula or specification used for the constant). Length units are centimeters.
0165 
0166 ### Aside: Checking for overlaps
0167 Checking for geometry overlaps is a computationally intensive procedure; therefore, it is better to let the Continuous Integration (CI) run overlap checks. CI jobs are triggered by every commit to a branch associated with a pull request. If you want to run overlap checks locally, run `overlap_check.sh`.
0168 
0169 ### Aside: Hosting JSROOT Yourself
0170 Using a remotely hosted JSROOT instance has its limitations; namely, every time you make a change to the geometry you must re-upload the TGeo ROOT file. For better productivity, consider self-hosting by following this guide.
0171 
0172 First, download a [release of JSROOT](https://github.com/root-project/jsroot/releases) and unpack it to somewhere, for example `~/jsroot`.
0173 
0174 Make a symbolic link to the `drich-dev/geo` subdirectory
0175 ```bash
0176 ln -s /path/to/drich-dev/geo ~/jsroot/
0177 ```
0178 
0179 Add the following script, named `jsroot` to your `$PATH`:
0180 ```bash
0181 #!/bin/bash
0182 pushd ${HOME}/jsroot  # change this to wherever you unpacked the jsroot release
0183 echo "FOR FULL DETECTOR:"
0184 printf "\nhttp://localhost:8000/?file=geo/detector_geometry.root&dark&opt=ctrl;\n\n"
0185 echo "FOR DRICH ONLY:"
0186 printf "\nhttp://localhost:8000/?file=geo/detector_geometry.root&dark&item=default/world_volume/DRICH_0/DRICH_gas_0&opt=ctrl;vislvl8;more\n\n"
0187 echo "FOR PFRICH ONLY:"
0188 printf "\nhttp://localhost:8000/?file=geo/detector_geometry.root&dark&item=default/world_volume/PFRICH_0/PFRICH_gas_0&opt=ctrl;vislvl8;more\n\n"
0189 echo "============================================"
0190 python -m http.server
0191 popd
0192 ```
0193 
0194 Run `jsroot` from your shell (not `eic-shell`) and open one of the URLs in your browser (when you are done, you may terminate the HTTP server by pressing `^C`). As you make changes to the geometry in `epic`, you just need to:
0195 ```
0196 build.sh epic && geometry.sh -d   # or your preferred option, such as -e
0197 ```
0198 Then refresh the webpage you have opened in your browser to see the update.
0199 
0200 ## Running Simulations
0201 Now let's throw particles at the dRICH. To run simulations in DD4hep, use `ddsim`; however, this will not enable Cherenkov physics. ePIC therefore uses [an extended version of `ddsim`, called `npsim`](https://github.com/eic/npsim), to enable Cherenkov physics and some [other settings for the PID detectors](https://github.com/eic/npsim/blob/main/src/dd4pod/python/npsim.py).
0202 
0203 Here in `drich-dev`, we have a wrapper of `npsim` specific for the dRICH: `simulate.py`. This script generates Geant4 macro files and runs them with `npsim`. You can either run one of the "tests" or supply a `hepmc` file. Run with no arguments for a usage guide:
0204 ```bash
0205 simulate.py
0206 ```
0207 
0208 Let's run test 1 with 10 events, which will throw 10 pi+s at the angle of theta=23.5 degrees, 20 GeV each (the defaults, at the time of writing this tutorial):
0209 ```bash
0210 simulate.py -t1 -n10
0211 ```
0212 _Exercise_: try other particles, energies, angles, or other tests.
0213 
0214 ### View The Results in ROOT
0215 
0216 The resulting file will be `out/sim.edm4hep.root` and it contains the `TTree` called `events`. Let's open the file:
0217 ```bash
0218 root out/sim.edm4hep.root
0219 new TBrowser()
0220 ```
0221 For convenience, `environ.sh` added a function `broot()` to automatically open a file in a `TBrowser`, so you could alternatively run `broot out/sim.edm4hep.root`.
0222 
0223 The dRICH simulated hits (pre-digitization) are in the `DRICHHits` branch. The datatype is `edm4hep::SimTrackerHit`, and as part of the common [Event Data Model for High Energy Physics (EDM4hep)](https://github.com/key4hep/EDM4hep), you may find [documentation here](https://github.com/key4hep/EDM4hep/blob/c19868254a63d684152056cb1ee371c23a011a41/edm4hep.yaml#L208-L239)
0224 
0225 Draw the number of incident photons per event:
0226 ```bash
0227 events->Draw("@DRICHHits.size()")   // the syntax for this particular TLeaf is a bit strange, but see the TBrowser view
0228 ```
0229 
0230 ![sim-nphot](img/sim-nphot.png)
0231 
0232 Draw the energy deposition:
0233 ```bash
0234 events->Draw("DRICHHits.EDep")
0235 ```
0236 The units are standard: GeV. Let's instead draw the wavelength in nanometers:
0237 ```bash
0238 events->Draw("1239.8/DRICHHits.EDep/1e9")
0239 ```
0240 
0241 ![sim-wavelength](img/sim-wavelength.png)
0242 
0243 (note there are cutoffs at 200 and 700 nm, because of issues in the material property tables).
0244 
0245 
0246 Draw the (true, non pixelated) hit positions:
0247 ```bash
0248 events->Draw("DRICHHits.position.y:DRICHHits.position.x")
0249 ```
0250 Zoom in on the Cherenkov rings
0251 
0252 ![sim-mc-hits](img/sim-mc-hits.png)
0253 
0254 Alternatively, `drich-dev` provides the executable `draw_hits` to draw these hits:
0255 ```bash
0256 draw_hits d
0257 display out/sim.edm4hep.hits.png
0258 ```
0259 
0260 ![sim-mc-hits-color](img/sim-mc-hits-color.png)
0261 
0262 
0263 _Exercise_: Check out the other branches and make some plots.
0264 
0265 _Exercise_: Run some of the other tests, for example, scanning over theta (test 4), theta and azimuth (test 5), or momentum (tests 7 and 8). Note that optics tests are special tests that will be described below.
0266 
0267 ### Event Display
0268 
0269 `drich-dev` provides an event display program. Run `event_display` for a usage guide.
0270 
0271 Draw all of the events in one:
0272 ```bash
0273 event_display d s out/sim.edm4hep.root
0274 ```
0275 View the image in `out/ev/`.
0276 
0277 ![sim-ev-all](img/sim-ev-all.png)
0278 
0279 You may also draw one event at a time (see the usage guide)
0280 ```bash
0281 event_display d s out/sim.edm4hep.root n 0 0
0282 ```
0283 View the images in `out/ev/`.
0284 
0285 Each green box is a single SiPM, and each histogram bin is a single SiPM pixel (8x8 pixels per SiPM). If you want to zoom in, use interactive mode by changing `n` to `i`, which will keep the `TCanvas` open and allow you to zoom in. For example, here is a closeup of the gas ring from a single event, by running
0286 ```bash
0287 event_display d s out/sim.edm4hep.root i 0
0288 ```
0289 
0290 ![sim-ev-all-zoom](img/sim-ev-all-zoom.png)
0291