2 added + 3 modified, total 5 files
GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd
diff -N CartesianGridXY.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ CartesianGridXY.java 15 Sep 2009 00:57:52 -0000 1.1
@@ -0,0 +1,45 @@
+package org.lcsim.geometry.compact.converter.lcdd;
+
+import org.jdom.DataConversionException;
+import org.jdom.Element;
+import org.jdom.Attribute;
+import org.jdom.JDOMException;
+import org.lcsim.geometry.compact.converter.lcdd.util.Calorimeter;
+
+/**
+ *
+ * @author jeremym
+ */
+public class CartesianGridXY extends LCDDSegmentation
+{
+ private double gridSizeX;
+ private double gridSizeY;
+
+ CartesianGridXY(Element node) throws DataConversionException, JDOMException
+ {
+ super(node);
+
+ Attribute attrib = node.getAttribute("gridSizeX");
+ if ( attrib == null )
+ {
+ throw new JDOMException("Required attribute gridSizePhi was not found.");
+ }
+ gridSizeX = attrib.getDoubleValue();
+
+ attrib = node.getAttribute("gridSizeY");
+
+ if ( attrib == null )
+ {
+ throw new JDOMException("Required attribute gridSizeZ was not found.");
+ }
+ gridSizeY = attrib.getDoubleValue();
+ }
+
+ void setSegmentation(Calorimeter cal)
+ {
+ org.lcsim.geometry.compact.converter.lcdd.util.GridXYZ seg = new org.lcsim.geometry.compact.converter.lcdd.util.GridXYZ();
+ seg.setGridSizeX(gridSizeX);
+ seg.setGridSizeY(gridSizeY);
+ cal.setSegmentation(seg);
+ }
+}
\ No newline at end of file
GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd
diff -u -r1.2 -r1.3
--- GridXYZ.java 14 Jun 2005 23:00:56 -0000 1.2
+++ GridXYZ.java 15 Sep 2009 00:57:52 -0000 1.3
@@ -16,70 +16,72 @@
*
* @author jeremym
*/
-public class GridXYZ extends LCDDSegmentation {
+public class GridXYZ extends LCDDSegmentation
+{
- private double gridSizeX;
- private double gridSizeY;
- private double gridSizeZ;
+ private double gridSizeX;
+ private double gridSizeY;
+ private double gridSizeZ;
+
+ /** Creates a new instance of GridXYZ */
+ public GridXYZ(Element node) throws DataConversionException, JDOMException
+ {
+ super(node);
+
+ boolean gotOne = false;
+
+ Attribute attrib = node.getAttribute("gridSizeX");
+
+ if ( attrib != null )
+ {
+ gotOne = true;
+ gridSizeX = attrib.getDoubleValue();
+ }
+ else
+ {
+ gridSizeX = 0;
+ }
+
+ attrib = node.getAttribute("gridSizeY");
+
+ if ( attrib != null )
+ {
+ gotOne = true;
+ gridSizeY = attrib.getDoubleValue();
+ }
+ else
+ {
+ gridSizeY = 0;
+ }
+
+ attrib = node.getAttribute("gridSizeZ");
+
+ if ( attrib != null )
+ {
+ gotOne = true;
+ gridSizeZ = attrib.getDoubleValue();
+ }
+ else
+ {
+ gridSizeZ = 0;
+ }
+
+ if ( !gotOne )
+ {
+ throw new JDOMException("Missing one of required attributes gridSizeX / Y / Z.");
+ }
+ }
+
+ void setSegmentation(Calorimeter cal)
+ {
+ org.lcsim.geometry.compact.converter.lcdd.util.GridXYZ g =
+ new org.lcsim.geometry.compact.converter.lcdd.util.GridXYZ();
+
+ g.setGridSizeX(gridSizeX);
+ g.setGridSizeY(gridSizeY);
+ g.setGridSizeZ(gridSizeZ);
- /** Creates a new instance of GridXYZ */
- public GridXYZ(Element node) throws DataConversionException, JDOMException {
- super(node);
-
- boolean gotOne = false;
-
- Attribute attrib = node.getAttribute("gridSizeX");
-
- if ( attrib != null )
- {
- gotOne = true;
- gridSizeX = attrib.getDoubleValue();
- }
- else
- {
- gridSizeX = 0;
- }
-
- attrib = node.getAttribute("gridSizeY");
-
- if ( attrib != null )
- {
- gotOne = true;
- gridSizeY = attrib.getDoubleValue();
- }
- else
- {
- gridSizeY = 0;
+ cal.setSegmentation(g);
}
- attrib = node.getAttribute("gridSizeZ");
-
- if ( attrib != null )
- {
- gotOne = true;
- gridSizeZ = attrib.getDoubleValue();
- }
- else
- {
- gridSizeZ = 0;
- }
-
- if ( !gotOne )
- {
- throw new JDOMException("Missing one of required attributes gridSizeX / Y / Z.");
- }
- }
-
- void setSegmentation(Calorimeter cal)
- {
- org.lcsim.geometry.compact.converter.lcdd.util.GridXYZ g =
- new org.lcsim.geometry.compact.converter.lcdd.util.GridXYZ();
-
- g.setGridSizeX(gridSizeX);
- g.setGridSizeY(gridSizeY);
- g.setGridSizeZ(gridSizeZ);
-
- cal.setSegmentation(g);
- }
-
}
GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd/util
diff -u -r1.1 -r1.2
--- GridXYZ.java 28 May 2005 00:20:55 -0000 1.1
+++ GridXYZ.java 15 Sep 2009 00:57:52 -0000 1.2
@@ -15,6 +15,9 @@
/** Creates a new instance of GridXYZSegmentation */
public GridXYZ() {
super("grid_xyz");
+ setAttribute("grid_size_x", "0.0");
+ setAttribute("grid_size_y", "0.0");
+ setAttribute("grid_size_z", "0.0");
}
public void setGridSizeX(double gsx) {
@@ -27,6 +30,5 @@
public void setGridSizeZ(double gsz) {
setAttribute("grid_size_z", String.valueOf(gsz));
- }
-
-}
+ }
+}
\ No newline at end of file
GeomConverter/src/org/lcsim/geometry/segmentation
diff -N CartesianGridXY.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ CartesianGridXY.java 15 Sep 2009 00:57:52 -0000 1.1
@@ -0,0 +1,251 @@
+package org.lcsim.geometry.segmentation;
+
+import hep.physics.vec.BasicHep3Vector;
+import hep.physics.vec.Hep3Vector;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jdom.DataConversionException;
+import org.jdom.Element;
+import org.lcsim.detector.IDetectorElement;
+import org.lcsim.detector.identifier.ExpandedIdentifier;
+import org.lcsim.detector.identifier.IExpandedIdentifier;
+import org.lcsim.detector.identifier.IIdentifier;
+import org.lcsim.detector.identifier.IIdentifierHelper;
+import org.lcsim.detector.identifier.Identifier;
+import org.lcsim.geometry.util.IDDescriptor;
+
+/**
+ * Simplified XY grid based on GridXYZ segmentation.
+ *
+ * @author jeremym
+ */
+public class CartesianGridXY extends SegmentationBase
+{
+ private double gridSizeX = 0;
+ private double gridSizeY = 0;
+
+ private int xIndex = -1;
+ private int yIndex = -1;
+ private int layerIndex = -1;
+
+ private double[] localPosition =
+ { 0, 0, 0 };
+
+ private double[] globalPosition =
+ { 0, 0, 0 };
+
+ List<Integer> geomFields;
+
+ public CartesianGridXY(Element node) throws DataConversionException
+ {
+ super(node);
+
+ 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.");
+ }
+ }
+
+ public boolean supportsNeighbours()
+ {
+ return true;
+ }
+
+ // TODO: Bounds check on x and y indices.
+ public long[] getNeighbourIDs(int layerRange, int xRange, int yRange)
+ {
+ // Get the IdentifierHelper.
+ IIdentifierHelper helper = detector.getDetectorElement().getIdentifierHelper();
+
+ // Get number of layers.
+ int nlayers = this.getNumberOfLayers();
+
+ // Current packed id.
+ IIdentifier currId = new Identifier(this.getDecoder().getID());
+
+ // Set values for current id.
+ int currLayer = helper.getValue(currId, layerIndex);
+ int currX = helper.getValue(currId, xIndex);
+ int currY = helper.getValue(currId, yIndex);
+
+ // Create an ExpandedIdentifier for the current id.
+ IExpandedIdentifier thisId = helper.unpack(currId);
+
+ // Compute maximum number of neighbors.
+ //int nMax = (2*layerRange + 1)*(2*xRange + 1)*(2*yRange + 1) - 1;
+
+ // Create return array.
+ List<Long> neighbors = new ArrayList<Long>();
+
+ // Loop over layer range.
+ //int ineighbor = 0;
+ for (int ilayer=-layerRange; ilayer<=layerRange; ilayer++)
+ {
+ // Loop over X range.
+ for (int ix=-xRange; ix<=xRange; ix++)
+ {
+ // Loop over Y range.
+ for (int iy=-yRange; iy<=yRange; iy++)
+ {
+ // Compute layer value.
+ int neighborLayer = currLayer + ilayer;
+
+ if (neighborLayer >= 0 && neighborLayer < nlayers)
+ {
+ // Compute x value.
+ int neighborX = currX + ix;
+
+ // Compute y value.
+ int neighborY = currY + iy;
+
+ // Create a new ExpandedIdenfier from the base Id.
+ ExpandedIdentifier neighborId = new ExpandedIdentifier(thisId);
+
+ // Set the neighbor fields.
+ neighborId.setValue(layerIndex, neighborLayer);
+ neighborId.setValue(xIndex, neighborX);
+ neighborId.setValue(yIndex, neighborY);
+
+ // Add the neighbor id to the return array.
+ neighbors.add(helper.pack(neighborId).getValue());
+ }
+ }
+ }
+ }
+
+ long result[] = new long[neighbors.size()];
+ int i = 0;
+ for (Long id : neighbors)
+ {
+ result[i] = id;
+ i++;
+ }
+ return result;
+ }
+
+ // TODO: Implement this method. Need proper bounds checking first.
+ public long findCellContainingXYZ(double x, double y, double z)
+ {
+ if (true)
+ throw new RuntimeException("Not implemented");
+ return 0;
+ }
+
+ public double[] getPosition()
+ {
+ return globalPosition;
+ }
+
+ private 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 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 local to global transform.
+ IDetectorElement sensor = deSearch.get(0);
+
+ // Create a vector of the local position.
+ Hep3Vector posVecLocal = new BasicHep3Vector(localPosition[0], localPosition[1], localPosition[2]);
+
+ // Compute the global position of the hit using 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();
+ }
+
+ public void setID(long id)
+ {
+ super.setID(id);
+ computePosition();
+ }
+
+ public void setIDDescription(IDDescriptor id)
+ {
+ super.setIDDescription(id);
+
+ if (geomFields == null)
+ {
+ geomFields = new ArrayList<Integer>();
+
+ xIndex = id.indexOf("x");
+ yIndex = id.indexOf("y");
+ layerIndex = id.indexOf("layer");
+
+ // Set geometry field list.
+ for (int i=0; i < id.fieldCount(); i++)
+ {
+ String fname = id.fieldName(i);
+ if (!fname.equals("x") && !fname.equals("y"))
+ {
+ geomFields.add(i);
+ }
+ }
+ }
+ }
+
+ public double getX()
+ {
+ return getPosition()[0];
+ }
+
+ public double getY()
+ {
+ return getPosition()[1];
+ }
+
+ public double getZ()
+ {
+ return getPosition()[2];
+ }
+
+ private void computeLocalX()
+ {
+ localPosition[0] = (((double) getValue(xIndex)) + 0.5) * gridSizeX;
+ }
+
+ private void computeLocalY()
+ {
+ localPosition[1] = (((double) getValue(yIndex)) + 0.5) * gridSizeY;
+ }
+
+ private void computePosition()
+ {
+ computeLocalPosition();
+ computeGlobalPosition();
+ }
+
+ private void computeLocalPosition()
+ {
+ localPosition[0] = localPosition[1] = localPosition[2] = 0.0;
+ computeLocalX();
+ computeLocalY();
+ }
+}
\ No newline at end of file
GeomConverter/src/org/lcsim/geometry/segmentation
diff -u -r1.26 -r1.27
--- GridXYZ.java 10 Sep 2009 01:13:31 -0000 1.26
+++ GridXYZ.java 15 Sep 2009 00:57:52 -0000 1.27
@@ -312,8 +312,9 @@
// DetectorElements. Currently, it has a specific case for PolyhedraBarrel and PolyhedraEndcap.
private void computeGlobalPosition()
{
- globalPosition[0] = globalPosition[1] = globalPosition[2] = 0.0;
-
+ //globalPosition[0] = globalPosition[1] = globalPosition[2] = 0.0;
+
+ /*
// On the first time through, setup list with geometry fields.
// FIXME: How to set this up once at the beginning and not call from here?
if (geomFields == null)
@@ -367,8 +368,9 @@
// Other types, including CylindricalEndcapCalorimeter.
else
{
- globalPosition = transformLocalToGlobal(localPosition);
- }
+ */
+ globalPosition = transformLocalToGlobal(localPosition);
+ //}
}
public void setSubdetector(Subdetector subdet)
CVSspam 0.2.8