View Javadoc

1   /*
2    * BarrelCylinderSegmentationBase.java 20051124 - G.Lima - Created
3    */
4   
5   package org.lcsim.geometry.segmentation;
6   
7   import org.jdom.Element;
8   import org.lcsim.geometry.layer.Layer;
9   import org.lcsim.geometry.layer.LayerStack;
10  
11  /**
12   * Base implementation of a barrel segmentation, it provides common code
13   * implementation.
14   * 
15   * @author Guilherme Lima
16   * @version $Id: BarrelCylinderSegmentationBase.java,v 1.1 2005/12/07 10:39:37
17   *          lima Exp $
18   */
19  // FIXME This can probably be folded into some other class.  It only has one method.
20  public abstract class BarrelCylinderSegmentationBase extends SegmentationBase
21  {
22      public BarrelCylinderSegmentationBase(Element e)
23      {
24          super(e);
25      }
26  
27      /**
28       * Return the layer number based on the radial distance to cylinder axis.
29       * 
30       * @param r
31       *            radial distance to cylinder axis
32       * @return layer number of layer corresponding to that distance (may be
33       *         either in absorber or live material)
34       */
35      public int getLayerBin(double r)
36      {
37          // In order to be general, we should not assume that all
38          // layers have the same thickness. Therefore, one has to
39          // guess the starting layer (based on average thickness), and
40          // then navigate through layers until one finds the right one
41          double depth = r - getRMin();
42          double mean_t = (getRMax() - getRMin()) / getNumberOfLayers();
43  
44          int ilay = (int) Math.floor(depth / mean_t);
45          LayerStack stack = getLayering().getLayers();
46          Layer layer = stack.getLayer(ilay);
47          double depHi = stack.getThicknessToLayerBack(ilay);
48          double depLo = depHi - layer.getThickness();
49          for (;;)
50          {
51              if (depth > depLo && depth <= depHi)
52                  return ilay;
53              if (depth <= depLo)
54              {
55                  --ilay;
56                  depHi = depLo;
57                  layer = stack.getLayer(ilay);
58                  depLo -= layer.getThickness();
59              }
60              if (depth > depHi)
61              {
62                  ++ilay;
63                  depLo = depHi;
64                  layer = stack.getLayer(ilay);
65                  depHi += layer.getThickness();
66              }
67          }
68      }
69  }