|
| 1 | +--- |
| 2 | +sort: 9 |
| 3 | +title: Geant4 scoring |
| 4 | +--- |
| 5 | + |
| 6 | +# Geant4 scoring |
| 7 | + |
| 8 | +Geant4 can accumulate radiation maps — fluence, dose, 1 MeV neutron equivalent |
| 9 | +fluence, hadron fluence above 20 MeV — on a mesh laid over the ALICE geometry, |
| 10 | +without any change to detector code. The mesh is configured with Geant4 macro |
| 11 | +commands, the same way FLUKA users configure `USRBIN` cards, and the result is |
| 12 | +written as a text file at the end of the run. |
| 13 | + |
| 14 | +This page explains how to switch it on in `o2-sim`, how to write the macro, and |
| 15 | +how to read the output. The [FLUKA counterpart](flukacomparison.md) page gives |
| 16 | +the card-by-card translation and the differences you have to know about before |
| 17 | +comparing numbers. |
| 18 | + |
| 19 | +## Quick start |
| 20 | + |
| 21 | +Write a macro file `scoring.in`: |
| 22 | + |
| 23 | +``` |
| 24 | +/score/create/cylinderMesh fine |
| 25 | +/score/mesh/cylinderSize 10. 30. cm |
| 26 | +/score/mesh/nBin 100 60 1 |
| 27 | +/score/quantity/cellFlux flux percm2 |
| 28 | +/score/quantity/doseDeposit dose Gy |
| 29 | +/score/close |
| 30 | +``` |
| 31 | + |
| 32 | +Append it to the standard ALICE Geant4 configuration and run: |
| 33 | + |
| 34 | +```bash |
| 35 | +cat $O2_ROOT/share/Detectors/gconfig/g4config.in scoring.in > g4scoring.in |
| 36 | + |
| 37 | +o2-sim-serial -e TGeant4 -g pythia8pp -n 100 \ |
| 38 | + --configKeyValues "G4.g4scoring=true;G4.configMacroFile=$PWD/g4scoring.in" |
| 39 | +``` |
| 40 | + |
| 41 | +The run writes `fine.worker<pid>.txt` into the working directory, one file per |
| 42 | +mesh. |
| 43 | + |
| 44 | +`G4.configMacroFile` **replaces** the standard `g4config.in`, it does not add to |
| 45 | +it. Always concatenate, otherwise the run loses the ALICE physics settings |
| 46 | +(range cuts, PAI in the TRD, biasing, field steppers). |
| 47 | + |
| 48 | +## Meshes |
| 49 | + |
| 50 | +Each mesh is a block between `/score/create/...` and `/score/close`. Several |
| 51 | +meshes can coexist; they are parallel worlds and do not disturb the transport. |
| 52 | + |
| 53 | +| Command | Meaning | |
| 54 | +|---|---| |
| 55 | +| `/score/create/cylinderMesh <name>` | cylindrical mesh, axis along z | |
| 56 | +| `/score/create/boxMesh <name>` | box mesh | |
| 57 | +| `/score/mesh/cylinderSize <R> <dz> <unit>` | outer radius and **half** length | |
| 58 | +| `/score/mesh/boxSize <dx> <dy> <dz> <unit>` | **half** lengths | |
| 59 | +| `/score/mesh/nBin <nR> <nZ> <nPhi>` | bins of a cylinder mesh | |
| 60 | +| `/score/mesh/nBin <nX> <nY> <nZ>` | bins of a box mesh | |
| 61 | +| `/score/mesh/translate/xyz <x> <y> <z> <unit>` | move the mesh off the origin | |
| 62 | +| `/score/close` | end the mesh definition | |
| 63 | + |
| 64 | +A mesh is centred on the origin unless it is translated. Bins are equidistant. |
| 65 | +A single phi bin gives the phi-averaged map, which is what a radiation study |
| 66 | +normally wants. |
| 67 | + |
| 68 | +## Quantities and filters |
| 69 | + |
| 70 | +Inside a mesh, every `/score/quantity/...` line adds one scorer, and the |
| 71 | +`/score/filter/...` lines that follow apply to the scorer above them. |
| 72 | + |
| 73 | +| Command | Quantity | |
| 74 | +|---|---| |
| 75 | +| `/score/quantity/cellFlux <name> percm2` | track length per cell volume, i.e. fluence | |
| 76 | +| `/score/quantity/doseDeposit <name> Gy` | absorbed dose | |
| 77 | +| `/score/quantity/energyDeposit <name> MeV` | deposited energy | |
| 78 | +| `/score/quantity/nOfStep <name>` | number of steps, useful for debugging | |
| 79 | + |
| 80 | +| Filter | Selects | |
| 81 | +|---|---| |
| 82 | +| `/score/filter/particle <fname> <p1> <p2> ...` | those Geant4 particle names | |
| 83 | +| `/score/filter/particleWithKineticEnergy <fname> <emin> <emax> <unit> <p1> ...` | those particles in that kinetic energy range | |
| 84 | +| `/score/filter/charged <fname>` | all charged particles | |
| 85 | +| `/score/filter/neutral <fname>` | all neutral particles | |
| 86 | + |
| 87 | +Particle names are the Geant4 ones: `neutron`, `proton`, `anti_proton`, `pi+`, |
| 88 | +`pi-`, `kaon0L`, `gamma`, `e-`, `opticalphoton`, and so on. |
| 89 | + |
| 90 | +A scorer without a filter counts everything, **including optical photons**. |
| 91 | +Those dominate the total fluence around the FT0 and are not transported by |
| 92 | +FLUKA at all, so an unfiltered `cellFlux` is not a quantity you can compare |
| 93 | +between the two engines. Filter, or read the filtered scorers instead. |
| 94 | + |
| 95 | +## Output |
| 96 | + |
| 97 | +Each mesh is dumped at the end of the run to `<mesh>.worker<pid>.txt`: |
| 98 | + |
| 99 | +``` |
| 100 | +# mesh name: fine |
| 101 | +# primitive scorer name: flux |
| 102 | +# iZ, iPHI, iR, total(value) [percm2], total(val^2), entry |
| 103 | +0,0,0,1856.089717,405107.423708,10 |
| 104 | +``` |
| 105 | + |
| 106 | +The columns are the bin indices, the sum over the whole run, the sum of |
| 107 | +squares, and the number of contributing steps. Two things to keep in mind: |
| 108 | + |
| 109 | +- The value is summed over **all events of the run**, not per event. Divide by |
| 110 | + the number of events yourself. |
| 111 | +- `total(val^2)` is the sum of squares of the per-step contributions, so it is |
| 112 | + not the statistical error of the bin. Use several runs with different seeds |
| 113 | + if you need an uncertainty. |
| 114 | + |
| 115 | +Parallel `o2-sim` writes one file per worker and merges them into `<mesh>.txt` |
| 116 | +at the end of the run. If a merge has to be redone by hand, for example after |
| 117 | +collecting dumps from several jobs: |
| 118 | + |
| 119 | +```bash |
| 120 | +o2-sim-merge-g4scoring <directory> <expected number of workers> |
| 121 | +``` |
| 122 | + |
| 123 | +The second argument is optional; when given, the merger fails loudly if a |
| 124 | +worker file is missing, which is the common way to lose a few percent of the |
| 125 | +statistics without noticing. |
| 126 | + |
| 127 | +## 1 MeV neutron equivalent fluence |
| 128 | + |
| 129 | +Geant4 has no built-in NIEL scorer. The ALICE Geant4 build takes a per-step |
| 130 | +weight from a user function, and `o2-sim` feeds it with RD50 damage weights, so |
| 131 | +that a `cellFlux` scorer becomes a damage-weighted fluence: |
| 132 | + |
| 133 | +``` |
| 134 | +/score/quantity/cellFlux neq percm2 true |
| 135 | +``` |
| 136 | + |
| 137 | +The trailing `true` is the `scoreweighted` flag. It only exists for `cellFlux`. |
| 138 | + |
| 139 | +Switch the weights on with: |
| 140 | + |
| 141 | +```bash |
| 142 | +--configKeyValues "G4.g4scoring=true;G4.g4fluenceweight=true;G4.fluenceWeightFile=$PWD/rd50_niel.csv;G4.configMacroFile=$PWD/g4scoring.in" |
| 143 | +``` |
| 144 | + |
| 145 | +The weight file is a CSV of PDG code, kinetic energy in MeV and damage weight: |
| 146 | + |
| 147 | +``` |
| 148 | +# pdg,ekin[MeV],weight |
| 149 | +2112,1.025000e-10,1.575000e-02 |
| 150 | +``` |
| 151 | + |
| 152 | +The same curves ship with O2 as ROOT graphs in |
| 153 | +`$O2_ROOT/share/Detectors/gconfig/data/rd50_niel.root`, under the names |
| 154 | +`neutronDW`, `protonDW`, `pionDW` and `electronDW`. If you do not have the text |
| 155 | +file, write it out from there — the loader only accepts CSV. |
| 156 | + |
| 157 | +Only four tables are read — neutron (2112), proton (2212), pion (211) and |
| 158 | +electron (11) — and they are applied like this: |
| 159 | + |
| 160 | +| Particle | Weight used | |
| 161 | +|---|---| |
| 162 | +| neutron | neutron table | |
| 163 | +| e+, e- | electron table, zero if the table is absent | |
| 164 | +| all other baryons and antibaryons | proton table | |
| 165 | +| all other mesons | pion table | |
| 166 | +| everything else | zero | |
| 167 | + |
| 168 | +Outside the tabulated energy range the weight is clamped to the first or last |
| 169 | +tabulated value. |
| 170 | + |
| 171 | +The consequence for a comparison: **do not filter the NIEL scorer down to |
| 172 | +neutrons, protons and pions.** FLUKA's `SI1MEVNE` weights every hadron and |
| 173 | +electron, so an ALICE inner-tracker map scored only on n, p and pi comes out |
| 174 | +about 18% low. Kaons alone account for most of it. |
| 175 | + |
| 176 | +## A ready example |
| 177 | + |
| 178 | +[`g4scoring_alice.in`](g4scoring_alice.in) is the macro used for the ALICE |
| 179 | +FLUKA/Geant4 radiation comparison: a fine mesh over the inner tracker and a |
| 180 | +coarse one over the cavern, each with fluence, 1 MeV n eq, hadrons above |
| 181 | +20 MeV, charged fluence, energy deposit and dose. |
| 182 | + |
| 183 | +```bash |
| 184 | +cat $O2_ROOT/share/Detectors/gconfig/g4config.in g4scoring_alice.in > g4full.in |
| 185 | + |
| 186 | +o2-sim -e TGeant4 -g pythia8pp -n 1000 -j 8 \ |
| 187 | + --configKeyValues "G4.g4scoring=true;G4.g4fluenceweight=true;G4.fluenceWeightFile=$PWD/rd50_niel.csv;G4.configMacroFile=$PWD/g4full.in" |
| 188 | +``` |
| 189 | + |
| 190 | +{% include list.liquid all=true %} |
0 commit comments