GeomConverter/src/org/lcsim/geometry/segmentation
diff -u -r1.8 -r1.9
--- GridXYZ.java 12 Jul 2005 18:24:12 -0000 1.8
+++ GridXYZ.java 13 Jul 2005 05:26:44 -0000 1.9
@@ -11,79 +11,61 @@
import static java.lang.Math.atan2;
import org.jdom.DataConversionException;
import org.jdom.Element;
-
+import org.lcsim.geometry.util.IDDescriptor;
/**
* @author jeremym
+ *
+ * Cartesian XYZ grid segmentation, primarily used for readout of planes.
+ * This segmentation is based on a local coordinate system.
+ *
*/
public class GridXYZ extends SegmentationBase
{
- private double gridSizeX;
- private double gridSizeY;
- private double gridSizeZ;
-
- private int xIndex;
- private int yIndex;
- private int zIndex;
+ private double gridSizeX = 0;
+ private double gridSizeY = 0;
+ private double gridSizeZ = 0;
+
+ private int xIndex = -1;
+ private int yIndex = -1;
+ private int zIndex = -1;
+
+ private double[] _localPos = { 0, 0, 0};
+ private double[] _globalPos = { 0, 0, 0};
/** Creates a new instance of GridXYZ */
public GridXYZ(Element node) throws DataConversionException
{
- super(node);
+ super(node);
if ( node.getAttribute("gridSizeX") != null )
{
gridSizeX = node.getAttribute("gridSizeX").getDoubleValue();
}
- else
- {
- gridSizeX = 0;
- }
if ( node.getAttribute("gridSizeY") != null )
{
gridSizeY = node.getAttribute("gridSizeY").getDoubleValue();
}
- else
- {
- gridSizeY = 0;
- }
if ( node.getAttribute("gridSizeZ") != null )
{
gridSizeZ = node.getAttribute("gridSizeZ").getDoubleValue();
- }
- else
- {
- gridSizeZ = 0;
}
}
-
+
public CoordinateSystemType getCoordinateSystemType()
{
return CoordinateSystemType.LOCAL;
- }
-
- public void setGridSizeX(double gsx)
- {
- gridSizeX = gsx;
- }
-
- public void setGridSizeY(double gsy)
- {
- gridSizeY = gsy;
- }
-
- public void setGridSizeZ(double gsz)
- {
- gridSizeZ = gsz;
- }
+ }
+ /* FIXME: How to impl this? It requires specific information about the subdetector topology. */
public long[] getNeighbourIDs(int a, int b, int c)
{
return new long[3];
}
+ /** FIXME: Doesn't belong here, as it is always computable given x and y. */
public double getPhi()
{
double phi = atan2(getX(), getY() );
@@ -96,9 +78,10 @@
return phi;
}
+ /** FIXME: Doesn't belong here, as it is always computable given x and y. */
public double getTheta()
{
- double theta = atan(computeCylindricalRadiusFromPosition() / getZ() );
+ double theta = atan(getCylindricalRadiusFromPosition() / getZ() );
if ( theta < 0 )
{
@@ -106,20 +89,102 @@
}
return theta;
- }
-
+ }
+
public double getX()
- {
- return ((double)getValue(xIndex) + 0.5) * gridSizeX;
+ {
+ return getPosition()[0];
}
public double getY()
{
- return ((double)getValue(yIndex) + 0.5) * gridSizeY;
+ return getPosition()[1];
}
public double getZ()
{
- return ((double)getValue(zIndex) + 0.5) * gridSizeZ;
+ return getPosition()[2];
+ }
+
+ public double[] getPosition()
+ {
+ return _globalPos;
+ }
+
+ private void computePosition()
+ {
+ computeLocalPosition();
+ computeGlobalPosition();
+ }
+
+ private void computeLocalPosition()
+ {
+ computeLocalX();
+ computeLocalY();
+ computeLocalZ();
+ }
+
+ private void computeGlobalPosition()
+ {
+ _globalPos = transformLocalToGlobal(_localPos);
+ }
+
+ private void computeLocalX()
+ {
+ if ( xIndex != -1 )
+ {
+ _localPos[0] = (((double)getValue(xIndex)) + 0.5) * gridSizeX;
+ }
+ }
+
+ private void computeLocalY()
+ {
+ if ( yIndex != -1 )
+ {
+ _localPos[1] = (((double)getValue(yIndex)) + 0.5) * gridSizeY;
+ }
+ }
+
+ private void computeLocalZ()
+ {
+ if ( zIndex != -1 )
+ {
+ _localPos[2] = (((double)getValue(zIndex)) + 0.5) * gridSizeZ;
+ }
+ }
+
+ /** Overridden to cache the global position. */
+ public void setID(long id)
+ {
+ super.setID(id);
+ computePosition();
+ }
+
+ /**
+ * Check for a valid grid size for each of XYZ.
+ * If the grid is not valid, then leave those
+ * indices flagged with invalid values. It
+ * is actually okay to have all 0's, because
+ * this will return the center of the volume,
+ * at least in analogous Geant4 impl of this class.
+ */
+ public void setIDDescription(IDDescriptor id)
+ {
+ super.setIDDescription(id);
+
+ if ( gridSizeX != 0 )
+ {
+ xIndex = id.indexOf("x");
+ }
+
+ if ( gridSizeY != 0 )
+ {
+ yIndex = id.indexOf("y");
+ }
+
+ if ( gridSizeZ != 0 )
+ {
+ zIndex = id.indexOf("z");
+ }
}
-}
+}
\ No newline at end of file