Print

Print


Commit in GeomConverter/src/org/lcsim/geometry/segmentation on MAIN
NonprojectiveCylinder.java+26-111.23 -> 1.24
MJC: Partial fix for neighbour-finding routine in NonprojectiveCylinder - problem is cells where A is a neighbour of B but B is not a neighbour of A. Still some screwy results for the very edges.

GeomConverter/src/org/lcsim/geometry/segmentation
NonprojectiveCylinder.java 1.23 -> 1.24
diff -u -r1.23 -r1.24
--- NonprojectiveCylinder.java	11 May 2007 00:21:10 -0000	1.23
+++ NonprojectiveCylinder.java	17 Apr 2008 12:40:33 -0000	1.24
@@ -138,6 +138,7 @@
         IDEncoder gnEncoder = new IDEncoder(descriptor);
         BaseIDDecoder gnDecoder = new BaseIDDecoder(descriptor);
         gnEncoder.setValues(values);
+        long origID = gnEncoder.getID();
         gnDecoder.setID(gnEncoder.getID());
 
         int nMax = (2*layerRange + 1)*(2*zRange + 1)*(2*phiRange + 1) - 1;
@@ -147,7 +148,16 @@
         double theta = getTheta();
         double phi = getPhi();
 
-        int zBins = (int) Math.floor((getZMax() - getZMin()) / getGridSizeZ());
+        // Be careful with # of Z bins.
+	// The rule is that (z >= getZMin() && z <= getZMax()).
+	// Usually there are zBins = floor(getZMax() - getZMin())/getGridSize() bins.
+	// If it happens that (getZMax() - getZMin()) is an integer multiple
+	// of getGridSizeZ() then there is actually one more bin (since both
+	// getZMin() and getZMax() are legal points for a bin).
+	double zBinsDouble = (getZMax() - getZMin()) / getGridSizeZ();
+        int zBins = (int) Math.floor(zBinsDouble);
+	boolean exactMultipleOfGridSizeZ = ( zBinsDouble == Math.floor(zBinsDouble) );
+	if (exactMultipleOfGridSizeZ) { zBins++; }
 
         int size = 0;
         for (int i = -layerRange; i <= layerRange; ++i)
@@ -159,18 +169,23 @@
             gnEncoder.setValue(layerIndex, ilay);
 
             double dphi = this.computeDeltaPhiForLayer(ilay);
-            int phiBins = (int) Math.floor(2 * Math.PI / dphi);
+            int phiBins = (int) Math.round(2 * Math.PI / dphi); // Use round() not floor() since a floor() was already applied in the definition of dphi
 
-            double cylR = getRadiusSensitiveMid(ilay);
-            double x = cylR * Math.cos(phi);
-            double y = cylR * Math.sin(phi);
-            double z = cylR / Math.tan(theta);
-
-            long id = this.findCellContainingXYZ(x,y,z);
-            if(id==0) continue;
+	    if (i != 0) {
+                double cylR = getRadiusSensitiveMid(ilay);
+                double x = cylR * Math.cos(phi);
+                double y = cylR * Math.sin(phi);
+                double z = cylR / Math.tan(theta);
+
+                long id = this.findCellContainingXYZ(x,y,z);
+                if(id==0) continue;
+                // save indices in a new array, as values[] keeps the original ref
+                gnDecoder.setID(id);
+            } else {
+		// This is the original layer => center cell is just the original cell
+                gnDecoder.setID(origID);
+            }
 
-            // save indices in a new array, as values[] keeps the original ref
-            gnDecoder.setID(id);
             for (int j = -zRange; j <= zRange; ++j)
             {
                 int iz = gnDecoder.getValue(zIndex) + j;
CVSspam 0.2.8