Warning, /drich-dev/doc/tutorials/3-running-reconstruction.md is written in an unsupported language. File is not indexed.
0001 Tutorial 3: Running Reconstruction and Benchmarks
0002 =================================================
0003
0004 - [TUTORIAL RECORDING (mirror 1)](https://drive.google.com/file/d/1jvLbU0lfBD5aomfLHqDPhUpl5tguSXdY/view?usp=sharing)
0005 -- [CHAT](https://drive.google.com/file/d/1V-FVWUvpaNaFDlGeIgNpoJ4RlMppT2Zs/view?usp=sharing)
0006 - [TUTORIAL RECORDING (mirror 2)](https://duke.zoom.us/rec/share/d8i2JN70kmZTZn0k5ysEQlAHq3JhNYYmWMyZOA5Omlt7JWL23AcWRS4beIc2yXhh.pg_k04utdsKoYjJa)
0007 - [Return to Tutorial Landing Page](README.md)
0008
0009 ## Prerequisites
0010 Before attending this tutorial, please build the reconstruction and benchmarks software, since this may take some time; this section describes how to do so.
0011
0012 ### Obtaining the Software
0013
0014 If you do not yet have clones of `EICrecon` and `reconstruction_benchmarks`, you can clone and checkout the appropriate branch in one command. As in [tutorial 1](1-setup-and-running-simulations.md), use HTTPS or SSH depending on your access credentials:
0015
0016 - `EICrecon` SSH:
0017 ```bash
0018 git clone git@github.com:eic/EICrecon.git
0019 ```
0020 - `EICrecon` HTTPS:
0021 ```bash
0022 git clone https://github.com/eic/EICrecon.git
0023 ```
0024 - `reconstruction_benchmarks` SSH:
0025 ```bash
0026 git clone git@eicweb.phy.anl.gov:EIC/benchmarks/reconstruction_benchmarks.git
0027 ```
0028 - `reconstruction_benchmarks` HTTPS:
0029 ```bash
0030 git clone https://eicweb.phy.anl.gov/EIC/benchmarks/reconstruction_benchmarks.git
0031 ```
0032
0033 ### Building
0034
0035 Before anything, don't forget to be in an `eic-shell` container and to run `source environ.sh`.
0036
0037 #### Revert the Geometry
0038
0039 If you followed the previous tutorials, your `epic` repository may be in a non-default state. You can check this with either `./check_status.sh`, which runs `git status` on all repositories, or `cd epic` then run `git status`. If you see you have made changes, run `git diff` to show them. Revert your changes, if there are any.
0040
0041 Regardless of whether you made any changes in `epic` or not, it is recommended to rebuild `epic` in case you forgot that you made changes and have a modified build. Run `build.sh epic` (or your preferred `cmake` commands) to rebuild.
0042
0043 #### Build Reconstruction and Benchmarks
0044
0045 Now build the reconstruction and benchmarks code. You can use `build.sh` (see [tutorial 1](1-setup-and-running-simulations.md)) or your preferred `cmake` commands. If using `build.sh`, run the commands below. This will take some time; consider reducing the environment variable `BUILD_NPROC` so that the compilation does not use too many resources.
0046 ```bash
0047 build.sh EICrecon
0048 build.sh reconstruction_benchmarks
0049 ```
0050 or just run:
0051 ```bash
0052 rebuild_all.sh
0053 ```
0054
0055 Now you are ready to follow along with the interactive tutorial!
0056
0057 ## dRICH Reconstruction Flowchart
0058
0059 The reconstruction requires two ingredients:
0060 - **Collections**: a set of objects, such as dRICH sensor hits or PID results
0061 - **Algorithms**: a transformation of a set of collections to another set of collections, such as a PID algorithm which transforms digitized hits and projected tracks into PID hypotheses
0062
0063 ```mermaid
0064 flowchart TB
0065 classDef alg fill:#ff8888,color:black
0066 classDef col fill:#00aaaa,color:black
0067 i0(Input Collection):::col ==> a1[Algorithm]:::alg ==> o0(Output Collection):::col
0068 a2[Algorithm]:::alg
0069 i1(Input Collection 1):::col ==> a2
0070 i2(Input Collection 2):::col ==> a2
0071 i3(Input Collection 3):::col ==> a2
0072 a2 ==> o1(Output Collection 1):::col
0073 a2 ==> o2(Output Collection 2):::col
0074 ```
0075
0076 Both **Collections** and **Algorithms** are supposed to be (as) independent (as possible) from the underlying simulation and reconstruction frameworks; this follows the modularity paradigm, where pieces of ePIC software are as mutually orthogonal as possible.
0077
0078 The [EICrecon reconstruction framework](https://github.com/eic/EICrecon) is responsible for running these algorithms and handling the input and output collections. Using **Collections** and **Algorithms**, the full reconstruction forms a [Directed Acyclic Graph (DAG)](https://en.wikipedia.org/wiki/Directed_acyclic_graph), starting with Collections produced from DD4hep and ending with the final Collections requested by the user. Here we will call this DAG the "reconstruction flowchart."
0079
0080 **Important**: only the Collections which the user asks to be produced will be saved in the final reconstruction output; only the minimal set of algorithms will be executed such that all of the requested output collections are produced. In other words, the part of the reconstruction flowchart which is actually used depends on the requested output collections.
0081
0082 The default [set of output collections is found here](https://github.com/eic/EICrecon/blob/main/src/services/io/podio/JEventProcessorPODIO.cc). At the time of writing this tutorial, no dRICH output collections are included by default, therefore the dRICH PID does not yet run in the full production.
0083
0084 The [dRICH PID reconstruction flowchart is found here](https://github.com/eic/EICrecon/blob/main/src/detectors/DRICH/README.md). At the time of writing this tutorial, the general idea is:
0085
0086 - Transform the collection of MC dRICH sensor hits to digitized raw hits, using the digitization algorithm
0087 - Transform the CKF trajectories into projected tracks in the dRICH radiator, using the track propagation algorithm
0088 - Transform the digitized hits and projected tracks into PID hypotheses, using Indirect Ray Tracing
0089 - Link the PID hypotheses to final reconstructed particles, using proximity matching
0090
0091
0092 ```mermaid
0093 flowchart TB
0094 classDef alg fill:#ff8888,color:black
0095 classDef col fill:#00aaaa,color:black
0096 simHits(MC Sensor Hits):::col ==> digi[Digitization]:::alg ==> rawHits(Raw Hits):::col
0097 traj(Trajectories):::col ==> prop[Track Propagation]:::alg ==> proj(Projected Track Points):::col
0098 pid[PID Algorithm]:::alg
0099 rawHits ==> pid
0100 proj ==> pid
0101 pid ==> hyp(PID Hypotheses):::col
0102 traj ==> track(Tracking Algorithm Results):::col
0103 mc(MC Particles):::col
0104 prox[Proximity Matching]:::alg
0105 hyp ==> prox
0106 track ==> prox
0107 mc ==> prox
0108 prox ==> rec(Reconstructed Particles):::col
0109 ```
0110
0111 ## Running the Full Stack
0112
0113 Now let's run the full stack:
0114 - Simulation
0115 - Reconstruction
0116 - Benchmarks
0117
0118 ### Simulation
0119
0120 For details how to run simulation, [see tutorial 1](1-setup-and-running-simulations.md). Run a simulation of your choice; here are some examples (for the version of `simulate.py` as of the interactive tutorial):
0121
0122 - throw 50 pions at the default fixed momentum:
0123 ```bash
0124 simulate.py -t1 -n50
0125 ```
0126
0127 - throw 50 kaons at the default fixed momentum:
0128 ```bash
0129 simulate.py -t1 -n50 -pkaon+
0130 ```
0131
0132 - throw 20 pions at 3 different angles (**NOTE**: a hot-fix for this one was pushed just prior to the tutorial; if you try this one, run `git pull` from `drich-dev/` to pull the fix)
0133 ```bash
0134 simulate.py -t4 -n20 -k3
0135 ```
0136
0137 - throw 20 pions with 3 momentum values in the momentum range suitable for aerogel:
0138 ```bash
0139 simulate.py -t7 -n20 -k3
0140 ```
0141 or gas:
0142 ```bash
0143 simulate.py -t8 -n20 -k3
0144 ```
0145
0146 Note that there are new simulation tests that will be added soon, such as those
0147 which randomly vary the azimuthal angle. These example commands may differ in later
0148 versions of `simulate.py`; run `simulate.py` for a full usage guide
0149
0150 ### Reconstruction
0151
0152 Now that we have some simulated data, let's run the reconstruction.
0153
0154 At the time of writing this tutorial, we are in the middle of a re-design in the framework of how to handle configuration parameters. Currently all of our dRICH-specific configuration parameters are [hard-coded in DRICH.cc](https://github.com/eic/EICrecon/blob/5c330b91d6b837635b1607ae95e8758c216b426c/src/detectors/DRICH/DRICH.cc); all of these can be overridden by `eicrecon` commands in the form of `-Pparameter=value`.
0155
0156 To learn how to use `eicrecon`, see the [corresponding general tutorial](https://indico.bnl.gov/event/16833/). This dRICH tutorial will show you how to use our custom `eicrecon` wrapper, `recon.rb`.
0157
0158 It is envisioned that we will move to some sort of configuration file in the future, but that capability does not yet exist in EICrecon. Since such a feature is useful for us to have now, we have a wrapper of `eicrecon` here in `drich-dev`, called `recon.rb`, which:
0159 - reads configuration files in the [`config/`](../../config) directory
0160 - generates an `eicrecon` command, converting the configuration tree into a set of `-Pparameter=value` options
0161 - runs `eicrecon` with these options
0162
0163 `recon.rb` allows us to quickly change the configuration without rebuilding EICrecon, and allows us to have, for example, one configuration with SiPM noise enabled and another with it disabled.
0164
0165 To get started, check the usage guide by running
0166 ```bash
0167 recon.rb -h
0168 ```
0169
0170 _Exercise_: View the files in the [`config/`](../../config) directory, in particular, the default one; compare the settings to other configuration files in that directory.
0171
0172 _Exercise_: Notice in the default configuration file the output collections, under `podio:output_collections:`. Can you find all of these collections in the dRICH reconstruction flowchart?
0173
0174 _Exercise_: Run a "dry-run" of `recon.rb`, which will just print the `eicrecon` command it will run; notice the relation between configuration parameters in the configuration file, the `-Pparameter=value` options in the `eicrecon` command, and the corresponding (default) parameters that are set in the EICrecon code itself.
0175
0176 To run the reconstruction on your sample simulation file (assuming you have the default file name), just run with no options:
0177 ```bash
0178 recon.rb
0179 ```
0180
0181 If successful, you will find the output file (default name)
0182 ```bash
0183 out/rec.edm4hep.root
0184 ```
0185 If you open this file in `ROOT`, you will find an `events` tree, similar to what was produced from the simulation. If you include the collections from the simulation level in the reconstruction output, you will find the corresponding branches included here. Let's draw some distributions:
0186
0187 - Digitization:
0188 ```cpp
0189 events->Draw("DRICHRawHits.cellID") // distribution of SiPM pixel ID
0190 events->Draw("DRICHRawHits.charge") // ADC distribution
0191 events->Draw("DRICHRawHits.timeStamp") // TDC distribution
0192 ```
0193
0194 ![rec-dist-digi](img/rec-dist-digi.png)
0195
0196 - Track Projections:
0197 ```cpp
0198 events->Draw("DRICHAerogelTracks_0.position.z") // z position of projected track points in aerogel
0199 events->Draw("DRICHMergedTracks_0.position.x:DRICHMergedTracks_0.position.z") // top-view of the projected track points in both radiators
0200 events->Draw("DRICHGasTracks_0.position.x:DRICHGasTracks_0.position.z","","*same") // draw the gas points on top, with larger markers
0201 ```
0202
0203 ![rec-dist-track](img/rec-dist-track.png)
0204
0205 - Cherenkov PID (for gas; for aerogel change `Gas` to `Aerogel`)
0206 ```cpp
0207 events->Draw("DRICHGasIrtCherenkovParticleID.npe") // number of photoelectrons for each charged particle
0208 events->Draw("DRICHGasIrtCherenkovParticleID.photonEnergy") // average photon energy for each charged particle
0209
0210 // PID hypothesis weight for each PDG, for the 3rd charged particle (3rd event, if using particle gun):
0211 events->Draw("DRICHGasIrtCherenkovParticleID_0.PDG","DRICHGasIrtCherenkovParticleID_0.weight","barhist",1,3)
0212 ```
0213
0214 ![rec-dist-pid](img/rec-dist-pid.png)
0215
0216 Take a look at the list of branches. Notice that some of them are repeated, with suffixes such as `#0` or `_0`; this is because these branches are produced from [PODIO](https://github.com/AIDASoft/podio) using the [EDM4hep](https://github.com/key4hep/EDM4hep) and [EDM4eic](https://github.com/eic/EDM4eic) data models. We will cover more of this in [tutorial 4](4-reconstruction-code-part-1.md). While it is certainly possible to do an analysis using typical `ROOT` tools, you will gain a _significant_ advantage by using PODIO tools, since that will provide much simpler access to all of the data in the `TTree`, along with the relations between the data, such as a reconstructed particle and its relation to the set of PID hypotheses.
0217
0218 ### Aside: Event Display and Noise Injection
0219
0220 Recall that our dRICH-specific `event_display` program can handle input from reconstruction output. Let's take a look:
0221 ```bash
0222 event_display d s out/sim.edm4hep.root # event display on the simulated data (pre-digitization, quantum efficiency, and safety factor)
0223 event_display d r out/rec.edm4hep.root # event display on the reconstructed data (post-digitization)
0224 ```
0225 Notice there are significantly fewer hits after digitization:
0226
0227 ![rec-display](img/rec-display.png)
0228
0229 Now re-run the reconstruction, turning on the noise, and be sure to produce a differently named output file
0230 ```bash
0231 recon.rb -c config/recon_noise.yaml -r out/rec.noise.edm4hep.root
0232 ```
0233 At the time of writing this, the IRT usage is not really capable of handling the noise, but we can still take a look at the event display:
0234 ```bash
0235 event_display d r out/rec.noise.edm4hep.root
0236 ```
0237 This is the noise from all of the events; see `event_display` usage guide to see the noise for each event individually.
0238
0239 ![rec-display-noise](img/rec-display-noise.png)
0240
0241 ## Benchmarks
0242
0243 Between the time of announcing this interactive tutorial and the interactive tutorial itself, there have been some updates to the benchmarks. To get these updates, pull them and recompile:
0244 ```bash
0245 pushd reconstruction_benchmarks
0246 git pull
0247 popd
0248 build.sh reconstruction_benchmarks
0249 ```
0250
0251 The benchmarks are meant to be executable by single commands, such that they can be easily called in the CI; the command should return a nonzero exit code upon failure. It is up to subsystem experts to check the artifacts, to ensure things like subsystem performance is adequate.
0252
0253 The dRICH benchmarks produce several plots, similar to the ones we were producing above. They make use of the PODIO tools in order to read the reconstruction data.
0254
0255 The primary command for dRICH benchmarks is symbolically linked in `drich-dev`:
0256 ```bash
0257 ls -l benchmark.rb
0258 # result: benchmark.rb -> reconstruction_benchmarks/benchmarks/rich/run_benchmark.rb
0259 ```
0260
0261 To run the benchmarks:
0262 ```bash
0263 benchmark.rb # print the usage guide
0264 benchmark.rb -b # run the benchmarks on out/rec.edm4eic.root
0265 ```
0266 The following files will be produced (default names):
0267 - `out/ana.edm4hep.root`: ROOT file with the plots
0268 - `out/ana.plots/`: directory of plot images
0269
0270 **Photon spectra**: wavelength and multiplicity, before and after digitization
0271 ![benchmark-photon_spectra](img/benchmark-photon_spectra.png)
0272
0273 **Raw hits**: ADC and TDC
0274 ![benchmark-digitization](img/benchmark-digitization.png)
0275
0276 **PID from Aerogel**
0277 - top row:
0278 - number of photoelectrons (NPE)
0279 - Cherenkov angle
0280 - Cherenkov angle residual
0281 - Cherenkov angle residual, zoomed in, with a Gaussian fit
0282 - PDG with highest PID weight
0283 - middle row
0284 - NPE vs. momentum
0285 - Cherenkov angle vs. momentum, with expected curves (electron, pion, kaon, proton)
0286 - Cherenkov angle residual vs. momentum
0287 - Cherenkov angle correlation (theta vs. phi)
0288 - refractive index at photon emission point
0289 - bottom row:
0290 - NPE vs. pseudorapidity
0291 - Cherenkov angle vs. pseudorapidity
0292 - Cherenkov angle residual vs. pseudorapidity
0293
0294 ![benchmark-pidAerogel](img/benchmark-pidAerogel.png)
0295
0296 **PID from Gas**
0297
0298 _NOTE_: the Cherenkov angle residual is pseudorapidity dependent here; this is a bug and we have a fix ready for it, but it has not yet been merged into the branches used for the interactive tutorial
0299
0300 ![benchmark-pidGas](img/benchmark-pidGas.png)
0301
0302 **PID combined from both radiators**
0303 ![benchmark-pidMerged](img/benchmark-pidMerged.png)