Print

Print


Commit in GeomConverter/src/org/lcsim/geometry/segmentation on MAIN
ProjectiveZPlane.java+106-851.18 -> 1.19
JM: code formatting

GeomConverter/src/org/lcsim/geometry/segmentation
ProjectiveZPlane.java 1.18 -> 1.19
diff -u -r1.18 -r1.19
--- ProjectiveZPlane.java	7 Dec 2005 10:39:37 -0000	1.18
+++ ProjectiveZPlane.java	7 Feb 2006 17:10:55 -0000	1.19
@@ -37,6 +37,7 @@
     {
         return thetaBins;
     }
+
     public int getPhiBins()
     {
         return phiBins;
@@ -44,13 +45,13 @@
 
     public double getPhi()
     {
-        double phi = (Math.PI*2) * ((getValue(phiIndex)+0.5)/phiBins);
+        double phi = (Math.PI * 2) * ((getValue(phiIndex) + 0.5) / phiBins);
         return phi;
     }
 
     public double getTheta()
     {
-        return (Math.PI) * ((getValue(thetaIndex)+0.5)/thetaBins);
+        return (Math.PI) * ((getValue(thetaIndex) + 0.5) / thetaBins);
     }
 
     public double getX()
@@ -65,12 +66,12 @@
 
     public double getZ()
     {
-        return -Math.signum(getTheta()-PI/2) * getDistanceToSensitive(getLayer() );
+        return -Math.signum(getTheta() - PI / 2) * getDistanceToSensitive(getLayer());
     }
 
     private double getSphericalRadius()
     {
-        return getZ() * tan(getTheta() );
+        return getZ() * tan(getTheta());
     }
 
     public void setIDDescription(IDDescriptor id)
@@ -83,41 +84,45 @@
 
     public long[] getNeighbourIDs(int deltaLayer, int deltaTheta, int deltaPhi)
     {
-	IDEncoder encoder = new IDEncoder( descriptor );
+        IDEncoder encoder = new IDEncoder(descriptor);
         encoder.setValues(values);
 
-        int nMax = (2*deltaLayer + 1)*(2*deltaTheta + 1)*(2*deltaPhi + 1) - 1;
+        int nMax = (2 * deltaLayer + 1) * (2 * deltaTheta + 1) * (2 * deltaPhi + 1) - 1;
         int size = 0;
         long[] result = new long[nMax];
-        for (int i=-deltaLayer;i<=deltaLayer;i++)
+        for (int i = -deltaLayer; i <= deltaLayer; i++)
         {
             int l = values[layerIndex] + i;
 
-            if (l<0 || l>= getNumberOfLayers() ) continue;
-            encoder.setValue(layerIndex,l);
+            if (l < 0 || l >= getNumberOfLayers())
+                continue;
+            encoder.setValue(layerIndex, l);
 
-            for (int j=-deltaTheta;j<=deltaTheta;j++)
+            for (int j = -deltaTheta; j <= deltaTheta; j++)
             {
                 int t = values[thetaIndex] + j;
 
-                if (t<0 || t>=thetaBins) continue;
-                encoder.setValue(thetaIndex,t);
+                if (t < 0 || t >= thetaBins)
+                    continue;
+                encoder.setValue(thetaIndex, t);
 
-                for (int k=-deltaPhi;k<=deltaPhi;k++)
+                for (int k = -deltaPhi; k <= deltaPhi; k++)
                 {
-                    if (i==0 && j==0 && k==0) continue;
+                    if (i == 0 && j == 0 && k == 0)
+                        continue;
 
                     int p = values[phiIndex] + k;
-                    if (p<0 || p>=phiBins) continue;
+                    if (p < 0 || p >= phiBins)
+                        continue;
 
-                    result[size++] = encoder.setValue(phiIndex,p);
+                    result[size++] = encoder.setValue(phiIndex, p);
                 }
             }
         }
         if (size < result.length)
         {
             long[] temp = new long[size];
-            System.arraycopy(result,0,temp,0,size);
+            System.arraycopy(result, 0, temp, 0, size);
             result = temp;
         }
         return result;
@@ -130,81 +135,97 @@
 
     /**
      * Return the cell which contains a given point (x,y,z), or zero.
-     *
-     * @param x,y,z cartesian coordinates of the point
-     * @return ID of cell containing the point (maybe either in
-     * absorber or live material)
+     * 
+     * @param x,y,z
+     *            cartesian coordinates of the point
+     * @return ID of cell containing the point (maybe either in absorber or live
+     *         material)
      */
-    public long findCellContainingXYZ(double x, double y, double z) {
+    public long findCellContainingXYZ(double x, double y, double z)
+    {
 
-	// validate point
-	if(z<getZMin()) return 0;
-	if(z>getZMax()) return 0;
-	double rho = Math.sqrt(x*x+y*y);
-	if(rho<getRMin()) return 0;
-	if(rho>getRMax()) return 0;
-
-	// ok, point is valid, so a valid ID should be returned
-	int ilay = getLayerBin(rho);
-
-	double phi = Math.atan2( y, x );
-	if(phi<0) phi += 2*Math.PI;
-	int iphi = (int)( phi / phiBins );
-
-	double theta = Math.atan2( rho, z );
-	if(theta<0) {
-	    // If never prints out, the whole if can be dropped
-	    System.out.println("ProjCylinder: Is this really needed?!?");
-	    theta += 2.*Math.PI;
-	}
-	int itheta = (int)(theta/thetaBins);
-
-	IDEncoder enc = new IDEncoder(descriptor);
-	enc.setValue("layer",ilay);
-	enc.setValue(thetaIndex,itheta);
-	enc.setValue(phiIndex,iphi);
-	long resultID = enc.getID();
+        // validate point
+        if (z < getZMin())
+            return 0;
+        if (z > getZMax())
+            return 0;
+        double rho = Math.sqrt(x * x + y * y);
+        if (rho < getRMin())
+            return 0;
+        if (rho > getRMax())
+            return 0;
+
+        // ok, point is valid, so a valid ID should be returned
+        int ilay = getLayerBin(rho);
+
+        double phi = Math.atan2(y, x);
+        if (phi < 0)
+            phi += 2 * Math.PI;
+        int iphi = (int) (phi / phiBins);
 
-	return resultID;
+        double theta = Math.atan2(rho, z);
+        if (theta < 0)
+        {
+            // If never prints out, the whole if can be dropped
+            System.out.println("ProjCylinder: Is this really needed?!?");
+            theta += 2. * Math.PI;
+        }
+        int itheta = (int) (theta / thetaBins);
+
+        IDEncoder enc = new IDEncoder(descriptor);
+        enc.setValue("layer", ilay);
+        enc.setValue(thetaIndex, itheta);
+        enc.setValue(phiIndex, iphi);
+        long resultID = enc.getID();
+
+        return resultID;
     }
 
     /**
      * Return the layer number based on the z-coordinate
-     *
-     * @param z z-coordinate
-     * @return layer number of layer corresponding to that distance
-     * (may be either in absorber or live material)
-     * @throws RuntimeException if abs(z)<zMin
+     * 
+     * @param z
+     *            z-coordinate
+     * @return layer number of layer corresponding to that distance (may be
+     *         either in absorber or live material)
+     * @throws RuntimeException
+     *             if abs(z)<zMin
      */
-    public int getLayerBin(double z) {
-	// In order to be general, we should not assume that all
-	// layers have the same thickness.  Therefore, one has to
-	// guess the starting layer (based on average thickness), and
-	// then navigate through layers until one finds the right one
-	double depth = Math.abs(z) - getZMin();
-	if(depth<0) throw new RuntimeException("ProjectiveZPlane: Error: z < zMin, z="+z+", zMin="+this.getZMin());
-
-	double mean_t = (getZMax()-getZMin()) / getNumberOfLayers();
-
-	int ilay = (int)Math.floor( depth / mean_t );
-	LayerStack stack = getLayering().getLayers();
-	Layer layer = stack.getLayer(ilay);
-	double depHi = stack.getThicknessToLayerBack(ilay);
-	double depLo = depHi - layer.getThickness();
-	for(;;) {
-	  if( depth>depLo && depth<=depHi ) return ilay;
-	  if( depth<=depLo ) {
-	      --ilay;
-	      depHi = depLo;
-	      layer = stack.getLayer(ilay);
-	      depLo -= layer.getThickness();
-	  }
-	  if( depth>depHi ) {
-	      ++ilay;
-	      depLo = depHi;
-	      layer = stack.getLayer(ilay);
-	      depHi += layer.getThickness();
-	  }
-	}
+    public int getLayerBin(double z)
+    {
+        // In order to be general, we should not assume that all
+        // layers have the same thickness. Therefore, one has to
+        // guess the starting layer (based on average thickness), and
+        // then navigate through layers until one finds the right one
+        double depth = Math.abs(z) - getZMin();
+        if (depth < 0)
+            throw new RuntimeException("ProjectiveZPlane: Error: z < zMin, z=" + z + ", zMin=" + this.getZMin());
+
+        double mean_t = (getZMax() - getZMin()) / getNumberOfLayers();
+
+        int ilay = (int) Math.floor(depth / mean_t);
+        LayerStack stack = getLayering().getLayers();
+        Layer layer = stack.getLayer(ilay);
+        double depHi = stack.getThicknessToLayerBack(ilay);
+        double depLo = depHi - layer.getThickness();
+        for (;;)
+        {
+            if (depth > depLo && depth <= depHi)
+                return ilay;
+            if (depth <= depLo)
+            {
+                --ilay;
+                depHi = depLo;
+                layer = stack.getLayer(ilay);
+                depLo -= layer.getThickness();
+            }
+            if (depth > depHi)
+            {
+                ++ilay;
+                depLo = depHi;
+                layer = stack.getLayer(ilay);
+                depHi += layer.getThickness();
+            }
+        }
     }
 }
CVSspam 0.2.8