GeomConverter/src/org/lcsim/geometry/segmentation
diff -u -r1.5 -r1.6
--- NonprojectiveCylinder.java 27 Jun 2005 22:14:19 -0000 1.5
+++ NonprojectiveCylinder.java 28 Jun 2005 23:15:05 -0000 1.6
@@ -18,6 +18,7 @@
import org.lcsim.geometry.util.IDDecoder;
import org.lcsim.geometry.util.IDDescriptor;
import org.lcsim.geometry.util.IDEncoder;
+import org.lcsim.geometry.subdetector.CylindricalCalorimeter;
/**
* @author jeremym
@@ -29,109 +30,166 @@
{
private double gridSizePhi;
private double gridSizeZ;
-
+
private int zIndex;
private int phiIndex;
-
+
+// private NonProjCalGeometry npgeom;
+
/** Creates a new instance of NonprojectiveCylinder */
public NonprojectiveCylinder(Element node) throws DataConversionException
{
super(node);
-
+
gridSizePhi = node.getAttribute("gridSizePhi").getDoubleValue();
gridSizeZ = node.getAttribute("gridSizeZ").getDoubleValue();
+
+// nppars = new NonProjCalGeometry( detector, gridSizeZ, gridSizePhi );
}
-
- /**
- * In the simulator, this is actually local because local -> global
- * is applied depending on cylinder's position. --JM
+
+ /**
+ * 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)
{
gridSizePhi = gsp;
}
-
+
void setGridSizeZ(double gsz)
{
gridSizeZ = gsz;
}
-
+
+ public double getGridSizePhi() {
+ return gridSizePhi;
+ }
+
+ public double getGridSizeZ() {
+ return gridSizeZ;
+ }
+
+ public double getZMin() {
+ return ((CylindricalCalorimeter)detector).getZMin();
+ }
+
+ public double getZMax() {
+ return ((CylindricalCalorimeter)detector).getZMax();
+ }
+
public double getPhi()
{
return (((double)getValue(phiIndex)) + 0.5) * computeDeltaPhiForLayer();
}
-
+
public double getTheta()
{
/** 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 detector.getDistanceToLayerSensorMid( getLayer() ) * cos( getPhi() );
}
-
+
public double getY()
{
return detector.getDistanceToLayerSensorMid( getLayer() ) * sin( getPhi() );
}
-
+
public double getZ()
{
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);
+ int nphi = (int)Math.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 boolean SupportsNeighbours()
+
+ public boolean supportsNeighbours()
{
- return false;
+ return true;
}
-
- public long[] getNeighbourIDs(int deltaLayer, int deltaTheta, int deltaPhi)
+
+ /** Find neighbouring cells to the current cell.
+ *
+ * Cell neighbors are found based on the direction (theta,phi) of
+ * the reference cell w.r.t the origin.
+ *
+ * @see org.lcsim.geometry.segmentation.SegmentationImpl#setID()
+ * @return array of cellIDs for the neighbouring cells
+ */
+ public long[] getNeighbourIDs(int layerRange, int zRange, int phiRange)
{
- /**
- * 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.");
- }
- /** Unreachable! */
- return new long[3];
+ encoder.setValues(values);
+
+ int nMax = (2*layerRange + 1)*(2*zRange + 1)*(2*phiRange + 1) - 1;
+ long[] result = new long[nMax];
+
+ int zBins = (int)Math.floor( (getZMax()-getZMin()) / getGridSizeZ() );
+ System.out.println("In z: zmin="+getZMin()+", zmax="+getZMax()
+ +", gridZ= "+getGridSizeZ()+", zBins="+zBins);
+
+ int size = 0;
+ for (int i=-layerRange;i<=layerRange;i++) {
+ int l = values[layerIndex] + i;
+
+ if (l<0 || l>=detector.getLayerCount()) continue;
+ encoder.setValue(layerIndex,l);
+
+ double dphi = this.computeDeltaPhiForLayer(i);
+ int phiBins = (int)Math.floor(2*Math.PI / dphi) ;
+ for (int j=-zRange;j<=zRange;j++) {
+ int t = values[zIndex] + j;
+
+ if (t<0 || t>=zBins) continue;
+ encoder.setValue(zIndex,t);
+
+ for (int k=-phiRange;k<=phiRange;k++) {
+ if (i==0 && j==0 && k==0) continue;
+
+ int p = values[phiIndex] + k;
+ if (p<0 || p>=phiBins) continue;
+
+ result[size++] = encoder.setValue(phiIndex,p);
+ }
+ }
+ }
+ if(size < result.length) {
+ long[] temp = new long[size];
+ System.arraycopy(result,0,temp,0,size);
+ result = temp;
+ }
+ return result;
}
-}
\ No newline at end of file
+}