Commit in GeomConverter/src/org/lcsim/geometry/segmentation on MAIN
NonprojectiveCylinder.java+80-301.3 -> 1.4
Added first impl of NonprojectiveCylinder segmentation.  NEEDS TEST CASE.

GeomConverter/src/org/lcsim/geometry/segmentation
NonprojectiveCylinder.java 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- NonprojectiveCylinder.java	2 Jun 2005 02:54:41 -0000	1.3
+++ NonprojectiveCylinder.java	23 Jun 2005 19:13:35 -0000	1.4
@@ -5,6 +5,12 @@
  */
 package org.lcsim.geometry.segmentation;
 
+import static java.lang.Math.atan;
+import static java.lang.Math.cos;
+import static java.lang.Math.sin;
+import static java.lang.Math.sqrt;
+import static java.lang.Math.floor;
+import static java.lang.Math.PI;
 import org.jdom.DataConversionException;
 import org.jdom.Element;
 import org.lcsim.geometry.CalorimeterIDDecoder;
@@ -16,15 +22,17 @@
 
 /**
  * @author jeremym
+ *
+ * Nonprojective segmentation of a cylinder with delta z and phi as parameters.
+ *
  */
 public class NonprojectiveCylinder extends SegmentationImpl
-{   
+{
     private double gridSizePhi;
     private double gridSizeZ;
-            
+    
     private int zIndex;
-    private int phiIndex;    
-        
+    private int phiIndex;
     
     /** Creates a new instance of NonprojectiveCylinder */
     public NonprojectiveCylinder(Element node) throws DataConversionException
@@ -33,8 +41,15 @@
         
         gridSizePhi = node.getAttribute("gridSizePhi").getDoubleValue();
         gridSizeZ = node.getAttribute("gridSizeZ").getDoubleValue();
-        
-        coordinateSystemType = CoordinateSystemType.LOCAL;
+    }
+    
+    /** 
+     * In the simulator, this is actually local because local -> global 
+     * is applied depending on cylinder's position.  --JM 
+     */
+    public CoordinateSystemType getCoordinateSystemType()
+    {
+        return CoordinateSystemType.GLOBAL;
     }
     
     void setGridSizePhi(double gsp)
@@ -45,43 +60,78 @@
     void setGridSizeZ(double gsz)
     {
         gridSizeZ = gsz;
-    }        
-
+    }
+    
     public double getPhi()
     {
-        return 0;
+        return (((double)getValue(phiIndex)) + 0.5) * computeDeltaPhiForLayer();
     }
-  
+    
     public double getTheta()
     {
-        return 0;
+        /** theta = atan( sqrt((x^2 + y^2) / z) ) */
+        double theta = atan(sqrt((getX() * getX()) + (getY() * getY()) ) / getZ() );
+        
+        /** Normalize to positive theta. */
+        if ( theta < 0 )
+        {
+            theta += PI;
+        }
+        
+        return theta;
     }
     
     public double getX()
-    {    
-        return 0;
+    {
+        return detector.getDistanceToLayerSensorMid( getLayer() ) * cos( getPhi() );
     }
-   
+    
     public double getY()
     {
-        return 0;
+        return detector.getDistanceToLayerSensorMid( getLayer() ) * sin( getPhi() );
     }
-   
+    
     public double getZ()
-    {            
-        return 0;
-    }  
-       
+    {
+        return ((double)getValue(zIndex) + 0.5) * gridSizeZ;
+    }
+    
+    public double computeDeltaPhiForLayer(int layer)
+    {
+        double circ = detector.getDistanceToLayerSensorMid(layer) * ( 2 * PI );
+        int nphi = (int) floor(circ / gridSizePhi);
+        double deltaPhi = (2 * PI) / nphi;
+        return deltaPhi;
+    }
+    
+    public double computeDeltaPhiForLayer()
+    {
+        return computeDeltaPhiForLayer( getLayer() );
+    }
+    
     public void setIDDescription(IDDescriptor id)
     {
-      super.setIDDescription(id);
-      
-      phiIndex = id.indexOf("phi");
-      zIndex = id.indexOf("z");      
-   }           
-   
-   public long[] getNeighbourIDs(int deltaLayer, int deltaTheta, int deltaPhi)
-   {
-        return new long[3];   
-   }  
+        super.setIDDescription(id);
+        
+        phiIndex = id.indexOf("phi");
+        zIndex = id.indexOf("z");
+    }
+    
+    public boolean SupportsNeighbours()
+    {
+        return false;
+    }
+    
+    public long[] getNeighbourIDs(int deltaLayer, int deltaTheta, int deltaPhi)
+    {
+        /**
+         * This is kind of evil, but users should be aware that neighbours are not implemented for this seg
+         * rather than getting back an array with wrong values.  --JM
+         */
+        if ( true )
+        {
+            throw new RuntimeException("NonprojectiveCylinder.getNeighbourIDs() is not implemented.");
+        }
+        return new long[3];
+    }
 }
\ No newline at end of file
CVSspam 0.2.8