From f26716d7f7661479bc5f12de2b4957829972a44c Mon Sep 17 00:00:00 2001
From: Whitney Armstrong <warmstrong@anl.gov>
Date: Fri, 21 May 2021 01:24:34 -0500
Subject: [PATCH] 	modified:   part1/simple_detector.md

---
 src/docs/part1/simple_detector.md | 56 +++++++++++++++++--------------
 1 file changed, 30 insertions(+), 26 deletions(-)

diff --git a/src/docs/part1/simple_detector.md b/src/docs/part1/simple_detector.md
index 1232e23..ce49a81 100644
--- a/src/docs/part1/simple_detector.md
+++ b/src/docs/part1/simple_detector.md
@@ -162,9 +162,9 @@ This is the local position in the segmentation cell (i.e. pixel, strip, readout
 
 At the top of the script you can see these lines:
 ```cpp
-  dd4hep::Detector& detector = dd4hep::Detector::getInstance();
-  detector.fromCompact("gem_tracker.xml");
-  dd4hep::rec::CellIDPositionConverter cellid_converter(detector);
+dd4hep::Detector& detector = dd4hep::Detector::getInstance();
+detector.fromCompact("gem_tracker.xml");
+dd4hep::rec::CellIDPositionConverter cellid_converter(detector);
 ```
 
 This 
@@ -215,14 +215,14 @@ Here `cell_dim` is a `std::vector<double>` passed by the specific segmentation i
 
 Look at the `readouts` tag of `gem_tracker.xml` and you will see this:
 ```xml
-    <readout name="GEMTrackerHits">
-      <segmentation type="CartesianGridXY" grid_size_x="1*cm" grid_size_y="3*cm" />
-      <id>system:8,barrel:2,layer:4,module:12,sensor:2,x:32:-16,y:-16</id>
-      <!--
-      <segmentation type="PolarGridRPhi" grid_size_phi="3.0*degree" grid_size_r="5.0*cm"/>
-      <id>system:5,barrel:3,layer:4,module:5,r:32:-16,phi:-16</id>
-      -->
-    </readout>
+<readout name="GEMTrackerHits">
+  <segmentation type="CartesianGridXY" grid_size_x="1*cm" grid_size_y="3*cm" />
+  <id>system:8,barrel:2,layer:4,module:12,sensor:2,x:32:-16,y:-16</id>
+  <!--
+  <segmentation type="PolarGridRPhi" grid_size_phi="3.0*degree" grid_size_r="5.0*cm"/>
+  <id>system:5,barrel:3,layer:4,module:5,r:32:-16,phi:-16</id>
+  -->
+</readout>
 ```
 
 Note the `grid_size_x` and `grid_size_y` attributes with values corresponding to the sizes above.
@@ -232,10 +232,10 @@ In the `CartesianGridXY` case, the cell sizes are always the same.
 
 1. Swap in the comment on segmentation and id to create the `PolarGridRPhi` segmentation. Should look like this:
 ```xml
-    <readout name="GEMTrackerHits">
-      <segmentation type="PolarGridRPhi" grid_size_phi="3.0*degree" grid_size_r="5.0*cm"/>
-      <id>system:5,barrel:3,layer:4,module:5,r:32:-16,phi:-16</id>
-    </readout>
+<readout name="GEMTrackerHits">
+  <segmentation type="PolarGridRPhi" grid_size_phi="3.0*degree" grid_size_r="5.0*cm"/>
+  <id>system:5,barrel:3,layer:4,module:5,r:32:-16,phi:-16</id>
+</readout>
 ```
 2. Re-run  npsim command above.
 3. Re-run the root script:
@@ -268,8 +268,8 @@ For example, a tracking covariance matrix could be computed using this method, a
 The cell ID is a 64bit integer with field names assigned to a few bits.
 Looking at the id specification we see the following:
 ```xml
-      <segmentation type="PolarGridRPhi" grid_size_phi="3.0*degree" grid_size_r="5.0*cm"/>
-      <id>system:5,barrel:3,layer:4,module:5,r:32:-16,phi:-16</id>
+<segmentation type="PolarGridRPhi" grid_size_phi="3.0*degree" grid_size_r="5.0*cm"/>
+<id>system:5,barrel:3,layer:4,module:5,r:32:-16,phi:-16</id>
 ```
 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.
@@ -303,11 +303,11 @@ system:0:8,barrel:8:2,layer:10:4,module:14:12,sensor:26:2,x:32:-16,y:48:-16
 This comes from the snippet at the initialization stage:
 
 ```cpp
-  fmt::print("ID specification:\n");
-  auto decoder = detector.readout("GEMTrackerHits").idSpec().decoder();
-  fmt::print("{}\n", decoder->fieldDescription());
-  auto layer_index = decoder->index("layer");
-  fmt::print(" \"layer\" index is {}.\n", layer_index);
+fmt::print("ID specification:\n");
+auto decoder = detector.readout("GEMTrackerHits").idSpec().decoder();
+fmt::print("{}\n", decoder->fieldDescription());
+auto layer_index = decoder->index("layer");
+fmt::print(" \"layer\" index is {}.\n", layer_index);
 ```
 
 This gets an index for the named field "layer" and initializes a decoder.
@@ -315,10 +315,10 @@ See [BitFieldCoder documentation](https://dd4hep.web.cern.ch/dd4hep/reference/cl
 
 Later in the loop over event hits.
 ```cpp
-      auto detector_layer = decoder->get(h.cellID, layer_index);
-      if ((detector_layer !=4 ) && (detector_layer !=5 )) {
-        continue;
-      }
+auto detector_layer = decoder->get(h.cellID, layer_index);
+if ((detector_layer !=4 ) && (detector_layer !=5 )) {
+  continue;
+}
 ```
 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.
@@ -328,6 +328,10 @@ Look at the generated plot in `results`:
 
 ![z_position](../z_position_part1.png)
 
+### Homework
+
+Can you adjust the compact description so that layers 4 and 5 have similar number of hits as the other layers? 
+
 ## References
 
 - [NPdet](https://eic.phy.anl.gov/npdet/)
-- 
GitLab