7 modified files
GeomConverter/src/org/lcsim/geometry/segmentation
diff -u -r1.3 -r1.4
--- RegularNgonCartesianGridXY.java 9 Dec 2009 16:24:02 -0000 1.3
+++ RegularNgonCartesianGridXY.java 8 Mar 2010 19:33:28 -0000 1.4
@@ -68,6 +68,7 @@
{
if (this.getDecoder().getID() == 0)
throw new RuntimeException("No current ID is set.");
+ if(sensitiveSlices == null)initSensitiveSlices();
IDEncoder gnEncoder = new IDEncoder(descriptor);
BaseIDDecoder gnDecoder = new BaseIDDecoder(descriptor);
gnEncoder.setValues(values);
@@ -77,13 +78,13 @@
dupEncoder.setValues(values);
dupDecoder.setID(dupEncoder.getID());
- // Get number of layers.
- int nlayers = this.getNumberOfLayers();
+ // Get number of layers.
+ int nlayers = this.getNumberOfLayers();
- // Set values for current id.
- int currLayer = values[layerIndex];
- int currX = gnDecoder.getValue(xIndex);
- int currY = gnDecoder.getValue(yIndex);
+ // Set values for current id.
+ int currLayer = values[layerIndex];
+ int currX = gnDecoder.getValue(xIndex);
+ int currY = gnDecoder.getValue(yIndex);
int currModule = gnDecoder.getValue(moduleIndex);
// Initialize the border arrays the first time in
@@ -91,18 +92,18 @@
{
initializeBorders();
}
- // Create return array.
- List<Long> neighbors = new ArrayList<Long>();
+ // Create return array.
+ List<Long> neighbors = new ArrayList<Long>();
- // Loop over layer range.
- for (int ilayer=-layerRange; ilayer<=layerRange; ilayer++)
- {
+ // Loop over layer range.
+ for (int ilayer=-layerRange; ilayer<=layerRange; ilayer++)
+ {
// Compute layer value.
- int neighborLayer = currLayer + ilayer;
+ int neighborLayer = currLayer + ilayer;
- if (neighborLayer >= 0 && neighborLayer < nlayers)
- {
- gnEncoder.setValue(layerIndex, neighborLayer);
+ if (neighborLayer >= 0 && neighborLayer < nlayers)
+ {
+ gnEncoder.setValue(layerIndex, neighborLayer);
// Loop over X range.
for (int ix=-xRange; ix<=xRange; ix++)
{
@@ -148,40 +149,65 @@
if(borderCellIsDuplicate[neighborLayer])neighborX++;
}
}
- gnEncoder.setValue(xIndex, neighborX);
+ gnEncoder.setValue(xIndex, neighborX);
gnEncoder.setValue(moduleIndex, neighborModule);
// Loop over Y range.
for (int iy=-yRange; iy<=yRange; iy++)
{
- // Compute y value.
- int neighborY = currY + iy;
- // Set the neighbor fields.
- gnEncoder.setValue(yIndex, neighborY);
- // Add the neighbor id to the return array.
- if( this.getDecoder().getID()!= gnEncoder.getID())neighbors.add(gnEncoder.getID());
- // If we have a duplicate cell, add it
- if(dup)
- {
- dupEncoder.setValue(yIndex, neighborY);
- dupEncoder.setValue(xIndex, dupX);
- dupEncoder.setValue(layerIndex, neighborLayer);
- dupEncoder.setValue(moduleIndex, dupModule);
- neighbors.add(dupEncoder.getID());
- }
- }
- }
- }
- }
+ // Compute y value.
+ int neighborY = currY + iy;
+ // Set the neighbor fields.
+ gnEncoder.setValue(yIndex, neighborY);
+ // Add the neighbor id to the return array.
+ if(sliceIndex >= 0)
+ {
+ // Loop over sensitive slices
+ for(int is = 0;is < sensitiveSlices[neighborLayer].size();is++)
+ {
+ // Set the slic field.
+ gnEncoder.setValue(sliceIndex, ((Integer) (sensitiveSlices[neighborLayer].get(is))).intValue());
- long result[] = new long[neighbors.size()];
- int i = 0;
- for (Long id : neighbors)
- {
- result[i] = id;
- i++;
+ if( this.getDecoder().getID()!= gnEncoder.getID())neighbors.add(gnEncoder.getID());
+ // If we have a duplicate cell, add it
+ if(dup)
+ {
+ dupEncoder.setValue(yIndex, neighborY);
+ dupEncoder.setValue(xIndex, dupX);
+ dupEncoder.setValue(layerIndex, neighborLayer);
+ dupEncoder.setValue(moduleIndex, dupModule);
+ dupEncoder.setValue(sliceIndex, ((Integer) (sensitiveSlices[neighborLayer].get(is))).intValue());
+ neighbors.add(dupEncoder.getID());
+ }
+ }
+ }
+ else
+ {
+ if( this.getDecoder().getID()!= gnEncoder.getID())neighbors.add(gnEncoder.getID());
+ // If we have a duplicate cell, add it
+ if(dup)
+ {
+ dupEncoder.setValue(yIndex, neighborY);
+ dupEncoder.setValue(xIndex, dupX);
+ dupEncoder.setValue(layerIndex, neighborLayer);
+ dupEncoder.setValue(moduleIndex, dupModule);
+ neighbors.add(dupEncoder.getID());
+ }
+
+ }
+ }
}
- return result;
+ }
+ }
+
+ long result[] = new long[neighbors.size()];
+ int i = 0;
+ for (Long id : neighbors)
+ {
+ result[i] = id;
+ i++;
}
+ return result;
+ }
protected void initializeBorders()
{
nmodules = ((AbstractPolyhedraCalorimeter)getSubdetector()).getNumberOfSides();
GeomConverter/src/org/lcsim/geometry/segmentation
diff -u -r1.4 -r1.5
--- EcalBarrelCartesianGridXY.java 5 Feb 2010 20:04:10 -0000 1.4
+++ EcalBarrelCartesianGridXY.java 8 Mar 2010 19:33:28 -0000 1.5
@@ -25,13 +25,12 @@
*/
public class EcalBarrelCartesianGridXY extends CartesianGridXY
{
- private double gridSizeX = 0;
- private double gridSizeY = 0;
+ private double gridSizeX = 0;
+ private double gridSizeY = 0;
- private int xIndex = -1;
- private int yIndex = -1;
- private int moduleIndex = -1;
- private int sliceIndex = -1;
+ private int xIndex = -1;
+ private int yIndex = -1;
+ private int moduleIndex = -1;
private int nmodules = 12;
private int[] validXplusG;
@@ -52,35 +51,35 @@
private double cscth = 0.;
private int nlayers = 0;
- private int[] activeSlice;
- public EcalBarrelCartesianGridXY(Element node) throws DataConversionException
+ public EcalBarrelCartesianGridXY(Element node) throws DataConversionException
+ {
+ super(node);
+
+ if (node.getAttribute("gridSizeX") != null)
+ {
+ gridSizeX = node.getAttribute("gridSizeX").getDoubleValue();
+ }
+ else
{
- super(node);
+ throw new RuntimeException("Missing gridSizeX parameter.");
+ }
- if (node.getAttribute("gridSizeX") != null)
- {
- gridSizeX = node.getAttribute("gridSizeX").getDoubleValue();
- }
- else
- {
- throw new RuntimeException("Missing gridSizeX parameter.");
- }
-
- if (node.getAttribute("gridSizeY") != null)
- {
- gridSizeY = node.getAttribute("gridSizeY").getDoubleValue();
- }
- else
- {
- throw new RuntimeException("Missing gridSizeY parameter.");
- }
+ if (node.getAttribute("gridSizeY") != null)
+ {
+ gridSizeY = node.getAttribute("gridSizeY").getDoubleValue();
}
-
- public long[] getNeighbourIDs(int layerRange, int xRange, int yRange)
+ else
{
- if (this.getDecoder().getID() == 0)
- throw new RuntimeException("No current ID is set.");
+ throw new RuntimeException("Missing gridSizeY parameter.");
+ }
+ }
+
+ public long[] getNeighbourIDs(int layerRange, int xRange, int yRange)
+ {
+ if (this.getDecoder().getID() == 0)
+ throw new RuntimeException("No current ID is set.");
+ if(sensitiveSlices == null)initSensitiveSlices();
IDEncoder gnEncoder = new IDEncoder(descriptor);
BaseIDDecoder gnDecoder = new BaseIDDecoder(descriptor);
gnEncoder.setValues(values);
@@ -91,11 +90,11 @@
{
initializeMappings();
}
- // Set values for current id.
- int currLayer = gnDecoder.getValue(layerIndex);
- int currX = gnDecoder.getValue(xIndex);
- int currY = gnDecoder.getValue(yIndex);
- int currModule = gnDecoder.getValue(moduleIndex);
+ // Set values for current id.
+ int currLayer = gnDecoder.getValue(layerIndex);
+ int currX = gnDecoder.getValue(xIndex);
+ int currY = gnDecoder.getValue(yIndex);
+ int currModule = gnDecoder.getValue(moduleIndex);
// Find the neighbors within the current module
List<Long> nl = getNeighbourIDs(layerRange, xRange, yRange, gnEncoder, currLayer, currX, currY);
@@ -159,15 +158,11 @@
}
// Set the module
int neighborModule = (currModule +1)%nmodules;
- gnEncoder.setValue(moduleIndex, neighborModule);
+ gnEncoder.setValue(moduleIndex, neighborModule);
// Loop over the layer range
for(int neighborLayer = minl;neighborLayer<maxl;neighborLayer++)
{
- gnEncoder.setValue(layerIndex, neighborLayer);
- // Ugly, need to set the slice bin
- int iSlice = 2;
- if(neighborLayer == 0)iSlice = 0;
- gnEncoder.setValue(sliceIndex, iSlice);
+ gnEncoder.setValue(layerIndex, neighborLayer);
// In this module's coordinate system, calculate the
// intersection of y=yc(layer) with the box to find the
// X coordinate range inside the box.
@@ -188,8 +183,19 @@
// Compute y value.
int neighborY = currY + iy;
gnEncoder.setValue(yIndex, neighborY);
- // Add the neighbor
- nl.add(gnEncoder.getID());
+ if(sliceIndex >= 0)
+ {
+ // Loop over sensitive slices
+ for(int is = 0;is < sensitiveSlices[neighborLayer].size();is++)
+ {
+ // Set the slic field.
+ gnEncoder.setValue(sliceIndex, ((Integer) (sensitiveSlices[neighborLayer].get(is))).intValue());;
+ // Add the neighbor
+ nl.add(gnEncoder.getID());
+ }
+ }
+ else nl.add(gnEncoder.getID());
+
}
}
}
@@ -246,9 +252,6 @@
for(int neighborLayer = minl;neighborLayer<maxl;neighborLayer++)
{
gnEncoder.setValue(layerIndex, neighborLayer);
- int iSlice = 2;
- if(neighborLayer == 0)iSlice = 0;
- gnEncoder.setValue(sliceIndex, iSlice);
// Find intersection of y=yc[layer] with box to determine
// X range
double xpmax = Math.min(xcmax*secth + yc[neighborLayer]*tanth,
@@ -267,7 +270,17 @@
neighborY++)
{
gnEncoder.setValue(yIndex, neighborY);
- nl.add(gnEncoder.getID());
+ if(sliceIndex >= 0)
+ {
+ // Loop over sensitive slices
+ for(int is = 0;is < sensitiveSlices[neighborLayer].size();is++)
+ {
+ // Set the slic field.
+ gnEncoder.setValue(sliceIndex, ((Integer) (sensitiveSlices[neighborLayer].get(is))).intValue());;
+ nl.add(gnEncoder.getID());
+ }
+ }
+ else nl.add(gnEncoder.getID());
}
}
}
@@ -288,10 +301,7 @@
neighborLayer<=Math.min(nlayers-1,currLayer+layerRange);
neighborLayer++)
{
- gnEncoder.setValue(layerIndex, neighborLayer);
- int iSlice = 2;
- if(neighborLayer == 0)iSlice = 0;
- gnEncoder.setValue(sliceIndex, iSlice);
+ gnEncoder.setValue(layerIndex, neighborLayer);
for(int neighborX=Math.max(validXminusG[neighborLayer],currX-xRange);
neighborX<=Math.min(validXplusG[neighborLayer],currX+xRange);
neighborX++)
@@ -302,21 +312,30 @@
neighborY++)
{
gnEncoder.setValue(yIndex, neighborY);
- if( this.getDecoder().getID()!= gnEncoder.getID())rl.add(gnEncoder.getID());
+ if(sliceIndex >= 0)
+ {
+ // Loop over sensitive slices
+ for(int is = 0;is < sensitiveSlices[neighborLayer].size();is++)
+ {
+ // Set the slic field.
+ gnEncoder.setValue(sliceIndex, ((Integer) (sensitiveSlices[neighborLayer].get(is))).intValue());;
+ if( this.getDecoder().getID()!= gnEncoder.getID())rl.add(gnEncoder.getID());
+ }
+ }
+ else if( this.getDecoder().getID()!= gnEncoder.getID())rl.add(gnEncoder.getID());
}
}
}
return rl;
}
- public void setupGeomFields(IDDescriptor id)
- {
+ public void setupGeomFields(IDDescriptor id)
+ {
super.setupGeomFields(id);
- xIndex = id.indexOf("x");
- yIndex = id.indexOf("y");
- moduleIndex = id.indexOf("module");
- layerIndex = id.indexOf("layer");
- sliceIndex = id.indexOf("slice");
- }
+ xIndex = id.indexOf("x");
+ yIndex = id.indexOf("y");
+ moduleIndex = id.indexOf("module");
+ layerIndex = id.indexOf("layer");
+ }
protected void initializeMappings()
{
@@ -330,7 +349,6 @@
validXminusP = new int[this.getNumberOfLayers()];
validXplusG = new int[this.getNumberOfLayers()];
validXminusG = new int[this.getNumberOfLayers()];
- activeSlice = new int[this.getNumberOfLayers()];
// Calculate the trig functions needed for the rotations
sinth = Math.sin(2.*Math.PI/nmodules);
costh = Math.cos(2.*Math.PI/nmodules);
GeomConverter/src/org/lcsim/geometry/segmentation
diff -u -r1.6 -r1.7
--- CartesianGridXZ.java 28 Jan 2010 19:46:36 -0000 1.6
+++ CartesianGridXZ.java 8 Mar 2010 19:33:28 -0000 1.7
@@ -108,13 +108,22 @@
protected void setupGeomFields(IDDescriptor id)
{
- if (geomFields == null)
- {
- geomFields = new ArrayList<Integer>();
+ if (geomFields == null)
+ {
+ geomFields = new ArrayList<Integer>();
+
+ xIndex = id.indexOf("x");
+ zIndex = id.indexOf("z");
+ layerIndex = id.indexOf("layer");
+ try {
+ sliceIndex = id.indexOf("slice");
+ }
+ catch (IllegalArgumentException x)
+ {
+ System.err.println("WARNING: The slice field does not exist in this IDDecoder!");
+ sliceIndex = -1;
+ }
- xIndex = id.indexOf("x");
- zIndex = id.indexOf("z");
- layerIndex = id.indexOf("layer");
// Set geometry field list.
for (int i=0; i < id.fieldCount(); i++)
GeomConverter/src/org/lcsim/geometry/segmentation
diff -u -r1.3 -r1.4
--- RegularNgonCartesianGridXZ.java 9 Dec 2009 16:24:02 -0000 1.3
+++ RegularNgonCartesianGridXZ.java 8 Mar 2010 19:33:28 -0000 1.4
@@ -25,14 +25,14 @@
*/
public class RegularNgonCartesianGridXZ extends CartesianGridXZ
{
- private double gridSizeX = 0;
- private double gridSizeZ = 0;
+ private double gridSizeX = 0;
+ private double gridSizeZ = 0;
private int nmodules = 12;
- private int xIndex = -1;
- private int zIndex = -1;
- private int moduleIndex = -1;
- private int barrelIndex = -1;
+ private int xIndex = -1;
+ private int zIndex = -1;
+ private int moduleIndex = -1;
+ private int barrelIndex = -1;
private int nzbins = 0;
private int zbinmax = 0;
@@ -44,33 +44,34 @@
private double xslope = 0.;
private int ecsign = -1;
- public RegularNgonCartesianGridXZ(Element node) throws DataConversionException
- {
- super(node);
-
- if (node.getAttribute("gridSizeX") != null)
- {
- gridSizeX = node.getAttribute("gridSizeX").getDoubleValue();
- }
- else
- {
- throw new RuntimeException("Missing gridSizeX parameter.");
- }
+ public RegularNgonCartesianGridXZ(Element node) throws DataConversionException
+ {
+ super(node);
- if (node.getAttribute("gridSizeZ") != null)
- {
- gridSizeZ = node.getAttribute("gridSizeZ").getDoubleValue();
- }
- else
- {
- throw new RuntimeException("Missing gridSizeZ parameter.");
- }
+ if (node.getAttribute("gridSizeX") != null)
+ {
+ gridSizeX = node.getAttribute("gridSizeX").getDoubleValue();
+ }
+ else
+ {
+ throw new RuntimeException("Missing gridSizeX parameter.");
}
- public long[] getNeighbourIDs(int layerRange, int xRange, int zRange)
+ if (node.getAttribute("gridSizeZ") != null)
{
- if (this.getDecoder().getID() == 0)
- throw new RuntimeException("No current ID is set.");
+ gridSizeZ = node.getAttribute("gridSizeZ").getDoubleValue();
+ }
+ else
+ {
+ throw new RuntimeException("Missing gridSizeZ parameter.");
+ }
+ }
+
+ public long[] getNeighbourIDs(int layerRange, int xRange, int zRange)
+ {
+ if (this.getDecoder().getID() == 0)
+ throw new RuntimeException("No current ID is set.");
+ if(sensitiveSlices == null)initSensitiveSlices();
IDEncoder gnEncoder = new IDEncoder(descriptor);
BaseIDDecoder gnDecoder = new BaseIDDecoder(descriptor);
gnEncoder.setValues(values);
@@ -80,21 +81,21 @@
dupEncoder.setValues(values);
dupDecoder.setID(dupEncoder.getID());
- // Get number of layers.
- int nlayers = this.getNumberOfLayers();
+ // Get number of layers.
+ int nlayers = this.getNumberOfLayers();
// Initialize the border arrays the first time in
if (nvalidx == null)
{
initializeBorders();
}
- // Set values for current id.
- int currLayer = gnDecoder.getValue(layerIndex);
- int currX = gnDecoder.getValue(xIndex);
- int currZ = gnDecoder.getValue(zIndex);
- int currModule = gnDecoder.getValue(moduleIndex);
- // Create return array.
- List<Long> neighbors = new ArrayList<Long>();
+ // Set values for current id.
+ int currLayer = gnDecoder.getValue(layerIndex);
+ int currX = gnDecoder.getValue(xIndex);
+ int currZ = gnDecoder.getValue(zIndex);
+ int currModule = gnDecoder.getValue(moduleIndex);
+ // Create return array.
+ List<Long> neighbors = new ArrayList<Long>();
// Loop over Z range.
for (int iz=-zRange; iz<=zRange; iz++)
@@ -164,30 +165,55 @@
// Set the neighbor fields.
gnEncoder.setValue(layerIndex, neighborLayer);
// Add the neighbor id to the return array.
- if( this.getDecoder().getID()!= gnEncoder.getID())neighbors.add(gnEncoder.getID());
- // If we have a duplicate cell, add it
- if(dup)
+ if(sliceIndex >= 0)
{
- dupEncoder.setValue(zIndex, neighborZ);
- dupEncoder.setValue(xIndex, dupX);
- dupEncoder.setValue(layerIndex, neighborLayer);
- dupEncoder.setValue(moduleIndex, dupModule);
- neighbors.add(dupEncoder.getID());
+ // Loop over sensitive slices
+ for(int is = 0;is < sensitiveSlices[neighborLayer].size();is++)
+ {
+ // Set the slic field.
+ gnEncoder.setValue(sliceIndex, ((Integer) (sensitiveSlices[neighborLayer].get(is))).intValue());
+
+ if( this.getDecoder().getID()!= gnEncoder.getID())neighbors.add(gnEncoder.getID());
+ // If we have a duplicate cell, add it
+ if(dup)
+ {
+ dupEncoder.setValue(zIndex, neighborZ);
+ dupEncoder.setValue(xIndex, dupX);
+ dupEncoder.setValue(layerIndex, neighborLayer);
+ dupEncoder.setValue(moduleIndex, dupModule);
+ dupEncoder.setValue(sliceIndex, ((Integer) (sensitiveSlices[neighborLayer].get(is))).intValue());
+ neighbors.add(dupEncoder.getID());
+ }
+ }
+ }
+ else
+ {
+ if( this.getDecoder().getID()!= gnEncoder.getID())neighbors.add(gnEncoder.getID());
+ // If we have a duplicate cell, add it
+ if(dup)
+ {
+ dupEncoder.setValue(zIndex, neighborZ);
+ dupEncoder.setValue(xIndex, dupX);
+ dupEncoder.setValue(layerIndex, neighborLayer);
+ dupEncoder.setValue(moduleIndex, dupModule);
+ neighbors.add(dupEncoder.getID());
+ }
+
}
}
- }
- }
- }
+ }
+ }
+ }
}
- long result[] = new long[neighbors.size()];
- int i = 0;
- for (Long id : neighbors)
- {
- result[i] = id;
- i++;
- }
- return result;
+ long result[] = new long[neighbors.size()];
+ int i = 0;
+ for (Long id : neighbors)
+ {
+ result[i] = id;
+ i++;
+ }
+ return result;
}
protected void initializeBorders()
{
GeomConverter/src/org/lcsim/geometry/segmentation
diff -u -r1.5 -r1.6
--- GlobalGridXY.java 10 Feb 2010 00:37:03 -0000 1.5
+++ GlobalGridXY.java 8 Mar 2010 19:33:28 -0000 1.6
@@ -68,6 +68,14 @@
xIndex = id.indexOf("x");
yIndex = id.indexOf("y");
layerIndex = id.indexOf("layer");
+ try {
+ sliceIndex = id.indexOf("slice");
+ }
+ catch (IllegalArgumentException x)
+ {
+ System.err.println("WARNING: The slice field does not exist in this IDDecoder!");
+ sliceIndex = -1;
+ }
// Exclude "x" and "y" fields in field list.
for (int i=0; i < id.fieldCount(); i++)
GeomConverter/src/org/lcsim/geometry/segmentation
diff -u -r1.8 -r1.9
--- AbstractCartesianGrid.java 28 Jan 2010 19:46:36 -0000 1.8
+++ AbstractCartesianGrid.java 8 Mar 2010 19:33:28 -0000 1.9
@@ -15,6 +15,7 @@
import org.lcsim.geometry.util.BaseIDDecoder;
import org.lcsim.geometry.util.IDDescriptor;
import org.lcsim.geometry.util.IDEncoder;
+import org.lcsim.geometry.layer.Layering;
/**
* This is the abstract base class for Cartesian grid segmentation types.
@@ -25,327 +26,346 @@
*
* @author jeremym
*/
-public abstract class AbstractCartesianGrid extends SegmentationBase
-{
+public abstract class AbstractCartesianGrid extends SegmentationBase {
// Cached local position array.
- double[] localPosition = {0, 0, 0};
-
- // Cached global position array.
- double[] globalPosition = {0, 0, 0};
-
- // Flag if positions need to be recomputed.
- boolean needsCompute = true;
-
- // Geometry field indices.
- List<Integer> geomFields;
-
- // The grid cell sizes. (Can be zero.)
- double gridSizeX, gridSizeY, gridSizeZ;
-
- /**
- * This constructor does nothing. Sub-types will set their
- * grid values from the XML element.
- *
- * @param segmentation The XML element for the segmentation.
- */
- protected AbstractCartesianGrid(Element segmentation)
- {
- super(segmentation);
- }
-
- /**
- * Using the current ID, compute the local position in the readout volume
- * and set the <code>localPosition</code> array.
- */
- abstract protected void computeLocalPosition();
-
- /**
- * Make a list of fields that are geometric by stripping out this segmentation's
- * fields from the given <code>IDDescriptor</code>.
- *
- * @param id The description of the Id.
- */
- abstract protected void setupGeomFields(IDDescriptor id);
-
- /**
- * Check if the id is valid. It must be in bounds of the corresponding readout volume.
- *
- * @param rawId
- * @return True if id is valid for this segmentation type; False if not.
- */
- abstract public boolean boundsCheck(long rawId);
-
- /**
- * Set the segmentation field values on the given <code>IExpandedIdentifier</code>
- * given a local hit position.
- *
- * @param geomId The expanded id.
- * @param localPositionVec The local position of the hit.
- */
- abstract protected void setSegmentationValues(IExpandedIdentifier geomId, Hep3Vector localPositionVec);
-
- /**
- * Compute the integer bin value given a coordinate and a grid size.
- *
- * @param u The coordinate value.
- * @param gridSize The grid size.
- * @return The bin value.
- */
- public final int getBin(double u, double gridSize)
- {
- double u0 = gridSize / 2;
- int iu = (int) Math.floor((u - u0) / gridSize + 0.5);
- return iu;
- }
-
- /**
- * Compute the coordinate given a bin value.
- *
- * @param binValue The bin value.
- * @param gridSize The grid size.
- * @return The coordinate value.
- */
- public final double computeCoordinate(int binValue, double gridSize)
- {
- return (((double) binValue) + 0.5) * gridSize;
- }
-
- /**
- * Generic computation of hit's global position.
- * Sets the <code>globalPosition</code> array.
- */
- protected void computeGlobalPosition()
- {
- // Make an id only containing geometric fields and no segmentation fields.
- IExpandedIdentifier geomIdExp = detector.getDetectorElement().getIdentifierHelper().unpack(new Identifier(this.getDecoder().getID()), geomFields);
- IIdentifier geomId = detector.getDetectorElement().getIdentifierHelper().pack(geomIdExp);
-
- // Search for the the DetectorElement associated with the geometry id.
- List<IDetectorElement> deSearch = detector.getDetectorElement().findDetectorElement(geomId);
-
- // Check if the DetectorElement lookup failed.
- if (deSearch == null || deSearch.size() == 0)
- {
- throw new RuntimeException("Failed to find DetectorElement with geometry id <" + geomIdExp.toString() + "> !");
- }
-
- // Set the DetectorElement to use for the local to global transform.
- IDetectorElement sensor = deSearch.get(0);
-
- // Create a vector from the local position array.
- Hep3Vector posVecLocal = new BasicHep3Vector(localPosition[0], localPosition[1], localPosition[2]);
-
- // Compute the global position of the hit using the local position and the DetectorElement.
- Hep3Vector posVecGlobal = sensor.getGeometry().transformLocalToGlobal(posVecLocal);
-
- // Set the internal global position array.
- globalPosition[0] = posVecGlobal.x();
- globalPosition[1] = posVecGlobal.y();
- globalPosition[2] = posVecGlobal.z();
- }
-
- /**
- * Find the readout cell given a global position.
- *
- * @return The cell id for the position.
- */
- public long findCellContainingXYZ(double x, double y, double z)
- {
- Hep3Vector pos = new BasicHep3Vector(x,y,z);
- IDetectorElement de =
- getSubdetector().getDetectorElement().findDetectorElement(pos);
- if (!de.getGeometry().getPhysicalVolume().isSensitive())
- {
- throw new RuntimeException("The volume " + de.getName() + " is not sensitive.");
- }
- Hep3Vector localPositionVec = de.getGeometry().transformGlobalToLocal(pos);
- ExpandedIdentifier geomId = new ExpandedIdentifier(de.getExpandedIdentifier());
-
- setSegmentationValues(geomId, localPositionVec);
-
- return getSubdetector().getDetectorElement().getIdentifierHelper().pack(geomId).getValue();
- }
-
- /**
- * Get the position from the current cell ID. Recomputes the position if necessary.
- *
- * @return The position of the current cell.
- */
- public final double[] getPosition()
- {
- if (needsCompute)
- {
- computePosition();
- needsCompute = false;
- }
- return globalPosition;
- }
-
- /**
- * Compute and cache the cell's global position.
- */
- protected void computePosition()
- {
- computeLocalPosition();
- computeGlobalPosition();
- }
-
- /**
- * Create an id with geometry fields only given an id including geometry and segmentation fields.
- *
- * @param id The cell id.
- * @return A cell id with values for geometry fields only.
- */
- protected final IIdentifier makeGeometryIdentifier(long id)
- {
- IExpandedIdentifier geomIdExp = detector.getDetectorElement().getIdentifierHelper().unpack(new Identifier(id), geomFields);
- return detector.getDetectorElement().getIdentifierHelper().pack(geomIdExp);
- }
-
- /**
- * This method is overridden in order to flag the decoder as dirty
- * so that internal position data can be recomputed the next time a position
- * is retrieved by the user.
- */
- public final void setID(long id)
- {
- super.setID(id);
- needsCompute = true;
- }
-
- /**
- * We override this method to cache the geometry field information.
- */
- public void setIDDescription(IDDescriptor id)
- {
- super.setIDDescription(id);
- setupGeomFields(id);
- }
-
- /**
- * All implementations must support neighbor finding.
- *
- * @return True.
- */
- public final boolean supportsNeighbours()
- {
- return true;
- }
-
- /**
- * Get the X coordinate.
- *
- * @return The X coordinate.
- */
- public final double getX()
- {
- return getPosition()[0];
- }
-
- /**
- * Get the Y coordinate.
- *
- * @return The Y coordinate.
- */
- public final double getY()
- {
- return getPosition()[1];
- }
-
- /**
- * Get the Z coordinate.
- *
- * @return The Z coordinate.
- */
- public final double getZ()
- {
- return getPosition()[2];
- }
-
- /**
- * Utility method for finding neighbors in a 2D readout grid with layers.
- *
- * @param layerRange The layer range.
- * @param uRange The u range.
- * @param vRange The v range.
- * @param uIndex The u field index.
- * @param vIndex The v field index.
- * @return
- */
- protected final long[] getNeighbourIDs(int layerRange, int uRange, int vRange, int uIndex, int vIndex)
- {
- if (this.getDecoder().getID() == 0)
- throw new RuntimeException("No current ID is set.");
+
+ double[] localPosition = {0, 0, 0};
+ // Cached global position array.
+ double[] globalPosition = {0, 0, 0};
+ // Flag if positions need to be recomputed.
+ boolean needsCompute = true;
+ // Geometry field indices.
+ List<Integer> geomFields;
+ // The grid cell sizes. (Can be zero.)
+ double gridSizeX, gridSizeY, gridSizeZ;
+ // Cached sensitive slices
+ List[] sensitiveSlices;
+ protected int sliceIndex = -1;
+
+ /**
+ * This constructor does nothing. Sub-types will set their
+ * grid values from the XML element.
+ *
+ * @param segmentation The XML element for the segmentation.
+ */
+ protected AbstractCartesianGrid(Element segmentation) {
+ super(segmentation);
+ }
+
+ /**
+ * Using the current ID, compute the local position in the readout volume
+ * and set the <code>localPosition</code> array.
+ */
+ abstract protected void computeLocalPosition();
+
+ /**
+ * Make a list of fields that are geometric by stripping out this segmentation's
+ * fields from the given <code>IDDescriptor</code>.
+ *
+ * @param id The description of the Id.
+ */
+ abstract protected void setupGeomFields(IDDescriptor id);
+
+ /**
+ * Check if the id is valid. It must be in bounds of the corresponding readout volume.
+ *
+ * @param rawId
+ * @return True if id is valid for this segmentation type; False if not.
+ */
+ abstract public boolean boundsCheck(long rawId);
+
+ /**
+ * Set the segmentation field values on the given <code>IExpandedIdentifier</code>
+ * given a local hit position.
+ *
+ * @param geomId The expanded id.
+ * @param localPositionVec The local position of the hit.
+ */
+ abstract protected void setSegmentationValues(IExpandedIdentifier geomId, Hep3Vector localPositionVec);
+
+ /**
+ * Compute the integer bin value given a coordinate and a grid size.
+ *
+ * @param u The coordinate value.
+ * @param gridSize The grid size.
+ * @return The bin value.
+ */
+ public final int getBin(double u, double gridSize) {
+ double u0 = gridSize / 2;
+ int iu = (int) Math.floor((u - u0) / gridSize + 0.5);
+ return iu;
+ }
+
+ /**
+ * Compute the coordinate given a bin value.
+ *
+ * @param binValue The bin value.
+ * @param gridSize The grid size.
+ * @return The coordinate value.
+ */
+ public final double computeCoordinate(int binValue, double gridSize) {
+ return (((double) binValue) + 0.5) * gridSize;
+ }
+
+ /**
+ * Generic computation of hit's global position.
+ * Sets the <code>globalPosition</code> array.
+ */
+ protected void computeGlobalPosition() {
+ // Make an id only containing geometric fields and no segmentation fields.
+ IExpandedIdentifier geomIdExp = detector.getDetectorElement().getIdentifierHelper().unpack(new Identifier(this.getDecoder().getID()), geomFields);
+ IIdentifier geomId = detector.getDetectorElement().getIdentifierHelper().pack(geomIdExp);
+
+ // Search for the the DetectorElement associated with the geometry id.
+ List<IDetectorElement> deSearch = detector.getDetectorElement().findDetectorElement(geomId);
+
+ // Check if the DetectorElement lookup failed.
+ if (deSearch == null || deSearch.size() == 0) {
+ throw new RuntimeException("Failed to find DetectorElement with geometry id <" + geomIdExp.toString() + "> !");
+ }
+
+ // Set the DetectorElement to use for the local to global transform.
+ IDetectorElement sensor = deSearch.get(0);
+
+ // Create a vector from the local position array.
+ Hep3Vector posVecLocal = new BasicHep3Vector(localPosition[0], localPosition[1], localPosition[2]);
+
+ // Compute the global position of the hit using the local position and the DetectorElement.
+ Hep3Vector posVecGlobal = sensor.getGeometry().transformLocalToGlobal(posVecLocal);
+
+ // Set the internal global position array.
+ globalPosition[0] = posVecGlobal.x();
+ globalPosition[1] = posVecGlobal.y();
+ globalPosition[2] = posVecGlobal.z();
+ }
+
+ /**
+ * Find the readout cell given a global position.
+ *
+ * @return The cell id for the position.
+ */
+ public long findCellContainingXYZ(double x, double y, double z) {
+ Hep3Vector pos = new BasicHep3Vector(x, y, z);
+ IDetectorElement de =
+ getSubdetector().getDetectorElement().findDetectorElement(pos);
+ if (!de.getGeometry().getPhysicalVolume().isSensitive()) {
+ throw new RuntimeException("The volume " + de.getName() + " is not sensitive.");
+ }
+ Hep3Vector localPositionVec = de.getGeometry().transformGlobalToLocal(pos);
+ ExpandedIdentifier geomId = new ExpandedIdentifier(de.getExpandedIdentifier());
+
+ setSegmentationValues(geomId, localPositionVec);
+
+ return getSubdetector().getDetectorElement().getIdentifierHelper().pack(geomId).getValue();
+ }
+
+ /**
+ * Get the position from the current cell ID. Recomputes the position if necessary.
+ *
+ * @return The position of the current cell.
+ */
+ public final double[] getPosition() {
+ if (needsCompute) {
+ computePosition();
+ needsCompute = false;
+ }
+ return globalPosition;
+ }
+
+ /**
+ * Compute and cache the cell's global position.
+ */
+ protected void computePosition() {
+ computeLocalPosition();
+ computeGlobalPosition();
+ }
+
+ /**
+ * Create an id with geometry fields only given an id including geometry and segmentation fields.
+ *
+ * @param id The cell id.
+ * @return A cell id with values for geometry fields only.
+ */
+ protected final IIdentifier makeGeometryIdentifier(long id) {
+ IExpandedIdentifier geomIdExp = detector.getDetectorElement().getIdentifierHelper().unpack(new Identifier(id), geomFields);
+ return detector.getDetectorElement().getIdentifierHelper().pack(geomIdExp);
+ }
+
+ /**
+ * This method is overridden in order to flag the decoder as dirty
+ * so that internal position data can be recomputed the next time a position
+ * is retrieved by the user.
+ */
+ public final void setID(long id) {
+ super.setID(id);
+ needsCompute = true;
+ }
+
+ /**
+ * We override this method to cache the geometry field information.
+ */
+ public void setIDDescription(IDDescriptor id) {
+ super.setIDDescription(id);
+ setupGeomFields(id);
+ }
+
+ /**
+ * All implementations must support neighbor finding.
+ *
+ * @return True.
+ */
+ public final boolean supportsNeighbours() {
+ return true;
+ }
+
+ /**
+ * Get the X coordinate.
+ *
+ * @return The X coordinate.
+ */
+ public final double getX() {
+ return getPosition()[0];
+ }
+
+ /**
+ * Get the Y coordinate.
+ *
+ * @return The Y coordinate.
+ */
+ public final double getY() {
+ return getPosition()[1];
+ }
+
+ /**
+ * Get the Z coordinate.
+ *
+ * @return The Z coordinate.
+ */
+ public final double getZ() {
+ return getPosition()[2];
+ }
+
+ /**
+ * Utility method for finding neighbors in a 2D readout grid with layers.
+ *
+ * @param layerRange The layer range.
+ * @param uRange The u range.
+ * @param vRange The v range.
+ * @param uIndex The u field index.
+ * @param vIndex The v field index.
+ * @return
+ */
+ protected final long[] getNeighbourIDs(int layerRange, int uRange, int vRange, int uIndex, int vIndex) {
+ if (this.getDecoder().getID() == 0) {
+ throw new RuntimeException("No current ID is set.");
+ }
+ if (sensitiveSlices == null) {
+ initSensitiveSlices();
+ }
IDEncoder gnEncoder = new IDEncoder(descriptor);
BaseIDDecoder gnDecoder = new BaseIDDecoder(descriptor);
gnEncoder.setValues(values);
gnDecoder.setID(gnEncoder.getID());
-
- // Get number of layers.
- int nlayers = this.getNumberOfLayers();
-
- // Set values for current id.
- int currLayer = values[layerIndex];
- int currU = gnDecoder.getValue(uIndex);
- int currV = gnDecoder.getValue(vIndex);
-
- // Create return array.
- List<Long> neighbors = new ArrayList<Long>();
-
- // Loop over layer range.
- for (int ilayer=-layerRange; ilayer<=layerRange; ilayer++)
- {
- // Compute layer value.
- int neighborLayer = currLayer + ilayer;
-
- if (neighborLayer >= 0 && neighborLayer < nlayers)
- {
- gnEncoder.setValue(layerIndex, neighborLayer);
+
+ // Get number of layers.
+ int nlayers = this.getNumberOfLayers();
+
+ // Set values for current id.
+ int currLayer = values[layerIndex];
+ int currU = gnDecoder.getValue(uIndex);
+ int currV = gnDecoder.getValue(vIndex);
+
+ // Create return array.
+ List<Long> neighbors = new ArrayList<Long>();
+
+ // Loop over layer range.
+ for (int ilayer = -layerRange; ilayer <= layerRange; ilayer++)
+ {
+ // Compute layer value.
+ int neighborLayer = currLayer + ilayer;
+
+ if (neighborLayer >= 0 && neighborLayer < nlayers)
+ {
+ gnEncoder.setValue(layerIndex, neighborLayer);
// Loop over X range.
- for (int iu=-uRange; iu<=uRange; iu++)
+ for (int iu = -uRange; iu <= uRange; iu++)
{
- // Compute x value.
- int neighborU = currU + iu;
- gnEncoder.setValue(uIndex, neighborU);
+ // Compute x value.
+ int neighborU = currU + iu;
+ gnEncoder.setValue(uIndex, neighborU);
// Loop over Y range.
- for (int iv=-vRange; iv<=vRange; iv++)
+ for (int iv = -vRange; iv <= vRange; iv++)
{
- // Compute y value.
- int neighborV = currV + iv;
-
- // Set the neighbor fields.
- gnEncoder.setValue(vIndex, neighborV);
-
- // Add the neighbor id to the return array.
- if( this.getDecoder().getID()!= gnEncoder.getID())neighbors.add(gnEncoder.getID());
- }
- }
- }
- }
-
- long result[] = new long[neighbors.size()];
- int i = 0;
- for (Long id : neighbors)
- {
- result[i] = id;
- i++;
- }
- return result;
- }
-
- public double getGridSizeX()
- {
- return gridSizeX;
- }
-
- public double getGridSizeY()
- {
- return gridSizeY;
- }
-
- public double getGridSizeZ()
- {
- return gridSizeZ;
- }
-}
\ No newline at end of file
+ // Compute y value.
+ int neighborV = currV + iv;
+
+ // Set the neighbor fields.
+ gnEncoder.setValue(vIndex, neighborV);
+
+ if(sliceIndex >= 0)
+ {
+ // Loop over sensitive slices
+ for(int is = 0;is < sensitiveSlices[neighborLayer].size();is++)
+ {
+ // Set the slic field.
+ gnEncoder.setValue(sliceIndex, ((Integer) (sensitiveSlices[neighborLayer].get(is))).intValue());;
+
+ // Add the neighbor id to the return array.
+ if (this.getDecoder().getID() != gnEncoder.getID())
+ {
+ neighbors.add(gnEncoder.getID());
+
+ }
+ }
+ }
+ else
+ {
+ // Add the neighbor id to the return array.
+ if (this.getDecoder().getID() != gnEncoder.getID())
+ {
+ neighbors.add(gnEncoder.getID());
+ }
+
+ }
+ }
+ }
+ }
+ }
+
+ long result[] = new long[neighbors.size()];
+ int i = 0;
+ for (Long id : neighbors) {
+ result[i] = id;
+ i++;
+ }
+ return result;
+ }
+
+ public double getGridSizeX() {
+ return gridSizeX;
+ }
+
+ public double getGridSizeY() {
+ return gridSizeY;
+ }
+
+ public double getGridSizeZ() {
+ return gridSizeZ;
+ }
+
+ protected void initSensitiveSlices()
+ {
+ Layering layering = this.getLayering();
+ sensitiveSlices = new List[layering.getNumberOfLayers()];
+ for (int i = 0; i < layering.getNumberOfLayers(); i++) {
+ sensitiveSlices[i] = new ArrayList<Integer>();
+ for (int j = 0; j < layering.getLayer(i).getNumberOfSlices(); j++) {
+ if (layering.getLayer(i).getSlice(j).isSensitive()) {
+ sensitiveSlices[i].add(new Integer(j));
+ }
+ }
+ }
+
+ }
+}
GeomConverter/src/org/lcsim/geometry/segmentation
diff -u -r1.9 -r1.10
--- CartesianGridXY.java 28 Jan 2010 19:46:36 -0000 1.9
+++ CartesianGridXY.java 8 Mar 2010 19:33:28 -0000 1.10
@@ -118,13 +118,21 @@
public void setupGeomFields(IDDescriptor id)
{
- if (geomFields == null)
- {
- geomFields = new ArrayList<Integer>();
+ if (geomFields == null)
+ {
+ geomFields = new ArrayList<Integer>();
- xIndex = id.indexOf("x");
- yIndex = id.indexOf("y");
- layerIndex = id.indexOf("layer");
+ xIndex = id.indexOf("x");
+ yIndex = id.indexOf("y");
+ layerIndex = id.indexOf("layer");
+ try {
+ sliceIndex = id.indexOf("slice");
+ }
+ catch (IllegalArgumentException x)
+ {
+ System.err.println("WARNING: The slice field does not exist in this IDDecoder!");
+ sliceIndex = -1;
+ }
// Set geometry field list.
for (int i=0; i < id.fieldCount(); i++)
CVSspam 0.2.8