Skip to content

Commit f4d78b6

Browse files
authored
Add blog post (#219)
1 parent b739b8c commit f4d78b6

3 files changed

+33
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: "Differentiating electromagnetic showers in a sampling calorimeter"
3+
layout: post
4+
excerpt: "Report on our work to apply algorithmic differentiation to the simulation codes G4HepEm/HepEmShow"
5+
sitemap: false
6+
author: Max Aehle
7+
permalink: blogs/differentiating_electromagnetic_showers/
8+
banner_image: /images/blog/hepemshow-optimization.jpg
9+
date: 2024-06-07
10+
tags: ad
11+
---
12+
13+
### Introduction
14+
15+
I am [Max Aehle](https://www.scicomp.uni-kl.de/team/aehle/), a PhD student of [Nicolas R. Gauger](https://www.scicomp.uni-kl.de/team/gauger/) at the University of Kaiserslautern-Landau, Germany. I have collaborated with Vassil Vassilev and Mihály Novák on applying algorithmic differentiation to HEP simulations.
16+
17+
### Motivation
18+
19+
Algorithmic differentiation (AD) is a set of techniques to evaluate derivatives of computer-implemented functions. Recently, AD has begun to be explored for the gradient-based end-to-end optimization of particle detector designs, with potential applications ranging from HEP to medical physics to astrophysics. To that end, the ability to estimate derivatives of the [Geant4](https://geant4.web.cern.ch/) simulator for the passage of particles through matter would be a huge step forward.
20+
21+
However, besides the technical challenge of applying AD to over one million lines of code, there is a number of mathematical/statistical challenges: Does the high density of discontinuities, induced for example by 'if' and 'while' statements in the code, cause problems in the derivative computation? Are we allowed to treat random numbers like constants with respect to AD? How large is the error when the mean pathwise derivative is evaluated as a proxy for the actual derivative of expectancies computed by Monte-Carlo algorithms?
22+
23+
### Report
24+
25+
During a four-week stay with the CERN SFT group in November 2023, and another two-week stay in April 2024, we answered these questions for a smaller HEP simulation composed by the [G4HepEm](https://g4hepem.readthedocs.io/en/latest/) and [HepEmShow](https://hepemshow.readthedocs.io/en/latest/) packages. G4HepEm is a toolkit for the simulation of electromagnetic showers, extracting the relevant data and functionalities from Geant4 in a compact and standalone library. HepEmShow uses G4HepEm to simulate electromagnetic showers in a sampling calorimeter with a simple parametric geometry.
26+
27+
After first encouraging results with the novel machine-code-based AD tool [Derivgrind](https://www.scicomp.uni-kl.de/software/derivgrind/), we applied the operator-overloading AD tool [CoDiPack](https://www.scicomp.uni-kl.de/software/codi/) to the simulation parts of G4HepEm and HepEmShow. The code for the [differentiated G4HepEm](https://github.com/SciCompKL/g4hepem/) and [HepEmShow](https://github.com/SciCompKL/hepemshow/) is available on GitHub. It allows us to compute, e.g., the mean pathwise algorithmic derivative of the energy depositions in the layers of the calorimeter, with respect to the initial kinetic energy of the incoming electrons. It turns out that the code is "AD-friendly" once a single process called multiple scattering is disabled. Comparing with the numerical derivatives (difference quotients) of the mean energy depositions, we get only a small deviation of about 5%.
28+
29+
![Plot of the derivative of the energy deposition with respect to the primary energy.](d-edep-d-primaryenergy.jpg)
30+
31+
Similar observations can be made for derivatives of the energy deposition with respect to the thickness of the absorber and gap layers in the calorimeter. A small error is not a problem for gradient-based optimization, as we have demonstrated with a simple optimization study shown above, with gradient descent trajectories robustly converging to the minimizer.
32+
33+
Feel free to take a look at our [preprint](http://arxiv.org/abs/2405.07944) and to get in touch!

Diff for: images/blog/hepemshow-d-edep-d-primaryenergy.jpg

27.1 KB
Loading

Diff for: images/blog/hepemshow-optimization.jpg

220 KB
Loading

0 commit comments

Comments
 (0)