*[Using detector description in analysis](#using-detector-description-in-analysis)
*[References](#references)
## Setup
## Setup
Note all these commands assume you are in an `eic-shell` singularity session.
Note all these commands assume you are in an `eic-shell` singularity session.
...
@@ -128,21 +139,26 @@ Refer to the [GPS Documentation](http://www.fe.infn.it/u/paterno/Geant4_tutorial
...
@@ -128,21 +139,26 @@ Refer to the [GPS Documentation](http://www.fe.infn.it/u/paterno/Geant4_tutorial
## Using detector description in analysis
## Using detector description in analysis
### Preface: data model
### Simulation output data model
First, the geant4 output data model used by `npsim` is [described in a single yaml file](https://eicweb.phy.anl.gov/EIC/NPDet/-/blob/master/src/dd4pod/dd4hep.yaml).
The geant4 output data model used by `npsim` is [described in a single yaml file](https://eicweb.phy.anl.gov/EIC/NPDet/-/blob/master/src/dd4pod/dd4hep.yaml).
Note that this is purposefully factorized from the larger EIC data model, `eicd`, which is used
Note that this is purposefully factorized from the larger EIC data model, `eicd`, which is used
at every step post geant4.
at every step post geant4.
https://eic.phy.anl.gov/eicd/
https://eic.phy.anl.gov/eicd/
Look at the generated file in results:

This is the local position in the segmentation (i.e. pixel, strip, readout pad, etc.).
### Cell ID to position
```bash
root -b-q scripts/tutorial1_hit_position.cxx+
```
Look at the generated plot in `results`:

### Cell ID (channel) to Position
This is the local position in the segmentation cell (i.e. pixel, strip, readout pad, etc.).
#### Detector handle
At the top of the script you can see these lines:
At the top of the script you can see these lines:
```cpp
```cpp
...
@@ -150,43 +166,151 @@ At the top of the script you can see these lines:
...
@@ -150,43 +166,151 @@ At the top of the script you can see these lines:
This means there are 5 bits associated with system (this is the `<detector>`'s `id`) this field is mandatory but can differ from 5 bits.
The subsequent fields are arbitrary but should result in a unique 64 bit integer.
Here 3 bits for the "barrel", 4 bits for a "layer", 5 bits for the "module".
More bit fields could be allocated if desired (in part 2 it will become clear why we might want to do this).
The last two bit fields start at the 32nd bit, leaving 15 unused bits. These "r" and "phi" fields are not associated with physical volumes but rather the 2D segmentation above. The segmentation is a virtual geometry applied the smallest geometry volumes (nodes). So the last 32 bits are split between these two fields and are signed.
Note the concept of a `VolumeID` is essentially equal to `CellID` but where the bits in `CellID` associated with a segmentation are set to zero. `VolumeID`s are associated with actual constructed and placed volumes.
fmt::print(" \"layer\" index is {}.\n",layer_index);
fmt::print(" \"layer\" index is {}.\n",layer_index);
```
```
This gets an index for the named field "layer" and initializes a decoder.
See [BitFieldCoder documentation](https://dd4hep.web.cern.ch/dd4hep/reference/classdd4hep_1_1DDSegmentation_1_1BitFieldCoder.html) documentation for more details.
See [BitFieldCoder documentation](https://dd4hep.web.cern.ch/dd4hep/reference/classdd4hep_1_1DDSegmentation_1_1BitFieldCoder.html) documentation for more details.
Later in the loop over event hits.
Later in the loop over event hits.
...
@@ -199,18 +323,9 @@ Later in the loop over event hits.
...
@@ -199,18 +323,9 @@ Later in the loop over event hits.
Note the `layer_index` is computed once in the beginning when the decoder is also initialized.
Note the `layer_index` is computed once in the beginning when the decoder is also initialized.
This means it will be fast because it only parses the ID specification string once.
This means it will be fast because it only parses the ID specification string once.
```bash
The statement above selects for the interior layers number 4 and 5: