3 added + 5 modified, total 8 files
GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd
diff -N GlobalGridXY.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ GlobalGridXY.java 2 Nov 2009 19:35:13 -0000 1.1
@@ -0,0 +1,56 @@
+package org.lcsim.geometry.compact.converter.lcdd;
+
+import org.jdom.Attribute;
+import org.jdom.DataConversionException;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.lcsim.geometry.compact.converter.lcdd.util.Calorimeter;
+
+/**
+ *
+ * @author jeremym
+ */
+public class GlobalGridXY extends LCDDSegmentation
+{
+ private double gridSizeX;
+ private double gridSizeY;
+
+ /** Creates a new instance of GridXYZ */
+ public GlobalGridXY(Element node) throws DataConversionException, JDOMException
+ {
+ super(node);
+
+ Attribute attrib = node.getAttribute("gridSizeX");
+
+ if ( attrib != null )
+ {
+ gridSizeX = attrib.getDoubleValue();
+ }
+ else
+ {
+ throw new RuntimeException("Missing gridSizeX parameter.");
+ }
+
+ attrib = node.getAttribute("gridSizeY");
+
+ if ( attrib != null )
+ {
+ gridSizeY = attrib.getDoubleValue();
+ }
+ else
+ {
+ throw new RuntimeException("Missing gridSizeY parameter.");
+ }
+ }
+
+ void setSegmentation(Calorimeter cal)
+ {
+ org.lcsim.geometry.compact.converter.lcdd.util.GlobalGridXY g =
+ new org.lcsim.geometry.compact.converter.lcdd.util.GlobalGridXY();
+
+ g.setGridSizeX(gridSizeX);
+ g.setGridSizeY(gridSizeY);
+
+ cal.setSegmentation(g);
+ }
+}
GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd
diff -u -r1.3 -r1.4
--- GridXYZ.java 15 Sep 2009 00:57:52 -0000 1.3
+++ GridXYZ.java 2 Nov 2009 19:35:13 -0000 1.4
@@ -18,7 +18,6 @@
*/
public class GridXYZ extends LCDDSegmentation
{
-
private double gridSizeX;
private double gridSizeY;
private double gridSizeZ;
GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd
diff -u -r1.3 -r1.4
--- NonprojectiveCylinder.java 14 Jun 2005 23:04:45 -0000 1.3
+++ NonprojectiveCylinder.java 2 Nov 2009 19:35:13 -0000 1.4
@@ -12,35 +12,35 @@
*/
public class NonprojectiveCylinder extends LCDDSegmentation
{
- private double gridSizePhi;
- private double gridSizeZ;
+ private double gridSizePhi;
+ private double gridSizeZ;
NonprojectiveCylinder(Element node) throws DataConversionException, JDOMException
{
- super(node);
- //System.out.println("NonprojectiveCylinder ctor");
+ super(node);
- Attribute attrib = node.getAttribute("gridSizePhi");
- if ( attrib == null )
- {
- throw new JDOMException("Required attribute gridSizePhi was not found.");
- }
- gridSizePhi = attrib.getDoubleValue();
-
- attrib = node.getAttribute("gridSizeZ");
-
- if ( attrib == null )
- {
- throw new JDOMException("Required attribute gridSizeZ was not found.");
- }
-
- gridSizeZ = attrib.getDoubleValue();
- }
- void setSegmentation(Calorimeter cal)
- {
- org.lcsim.geometry.compact.converter.lcdd.util.NonprojectiveCylinder npcyl = new org.lcsim.geometry.compact.converter.lcdd.util.NonprojectiveCylinder();
- npcyl.setGridSizePhi(gridSizePhi);
- npcyl.setGridSizeZ(gridSizeZ);
- cal.setSegmentation(npcyl);
- }
+ Attribute attrib = node.getAttribute("gridSizePhi");
+ if ( attrib == null )
+ {
+ throw new JDOMException("Required attribute gridSizePhi was not found.");
+ }
+ gridSizePhi = attrib.getDoubleValue();
+
+ attrib = node.getAttribute("gridSizeZ");
+
+ if ( attrib == null )
+ {
+ throw new JDOMException("Required attribute gridSizeZ was not found.");
+ }
+
+ gridSizeZ = attrib.getDoubleValue();
+ }
+
+ void setSegmentation(Calorimeter cal)
+ {
+ org.lcsim.geometry.compact.converter.lcdd.util.NonprojectiveCylinder npcyl = new org.lcsim.geometry.compact.converter.lcdd.util.NonprojectiveCylinder();
+ npcyl.setGridSizePhi(gridSizePhi);
+ npcyl.setGridSizeZ(gridSizeZ);
+ cal.setSegmentation(npcyl);
+ }
}
GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd/util
diff -N GlobalGridXY.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ GlobalGridXY.java 2 Nov 2009 19:35:14 -0000 1.1
@@ -0,0 +1,25 @@
+package org.lcsim.geometry.compact.converter.lcdd.util;
+
+/**
+ *
+ * @author jeremym
+ */
+public class GlobalGridXY extends Segmentation
+{
+ public GlobalGridXY()
+ {
+ super("global_grid_xy");
+ setAttribute("grid_size_x", "0.0");
+ setAttribute("grid_size_y", "0.0");
+ }
+
+ public void setGridSizeX(double gsx)
+ {
+ setAttribute("grid_size_x", String.valueOf(gsx));
+ }
+
+ public void setGridSizeY(double gsy)
+ {
+ setAttribute("grid_size_y", String.valueOf(gsy));
+ }
+}
GeomConverter/src/org/lcsim/geometry/segmentation
diff -N GlobalGridXY.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ GlobalGridXY.java 2 Nov 2009 19:35:14 -0000 1.1
@@ -0,0 +1,151 @@
+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.Identifier;
+import org.lcsim.geometry.util.IDDescriptor;
+
+/**
+ * Global XY Cartesian grid segmentation.
+ *
+ * @author jeremym
+ */
+public class GlobalGridXY extends AbstractCartesianGrid
+{
+ private double gridSizeX = 0;
+ private double gridSizeY = 0;
+
+ private int xIndex = -1;
+ private int yIndex = -1;
+
+ public GlobalGridXY(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.");
+ }
+ }
+
+ protected void computePosition()
+ {
+ computeGlobalX();
+ computeGlobalY();
+ computeGlobalZ();
+ }
+
+ protected void setSegmentationValues(IExpandedIdentifier geomId, Hep3Vector positionVec)
+ {
+ geomId.setValue(xIndex, getXBin(positionVec.x()));
+ geomId.setValue(yIndex, getYBin(positionVec.y()));
+ }
+
+ protected void setupGeomFields(IDDescriptor id)
+ {
+ if (geomFields == null)
+ {
+ geomFields = new ArrayList<Integer>();
+
+ xIndex = id.indexOf("x");
+ yIndex = id.indexOf("y");
+ layerIndex = id.indexOf("layer");
+
+ // Exclude "x" and "y" fields in 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 long[] getNeighbourIDs(int layerRange, int xRange, int yRange)
+ {
+ return getNeighbourIDs(layerRange, xRange, yRange, xIndex, yIndex);
+ }
+
+ public int getXBin(double x)
+ {
+ return getBin(x, gridSizeX);
+ }
+
+ public int getYBin(double y)
+ {
+ return getBin(y, gridSizeY);
+ }
+
+ private void computeGlobalX()
+ {
+ globalPosition[0] = (((double) getValue(xIndex)) + 0.5) * gridSizeX;
+ }
+
+ private void computeGlobalY()
+ {
+ globalPosition[1] = (((double) getValue(yIndex)) + 0.5) * gridSizeY;
+ }
+
+ private void computeGlobalZ()
+ {
+ // 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);
+
+ globalPosition[2] = sensor.getGeometry().getPosition().z();
+ }
+
+
+ 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.");
+ }
+
+ ExpandedIdentifier geomId = new ExpandedIdentifier(de.getExpandedIdentifier());
+
+ setSegmentationValues(geomId, pos);
+
+ return getSubdetector().getDetectorElement().getIdentifierHelper().pack(geomId).getValue();
+ }
+}
\ No newline at end of file
GeomConverter/src/org/lcsim/geometry/segmentation
diff -u -r1.2 -r1.3
--- AbstractCartesianGrid.java 8 Oct 2009 21:31:58 -0000 1.2
+++ AbstractCartesianGrid.java 2 Nov 2009 19:35:14 -0000 1.3
@@ -28,7 +28,7 @@
{
double[] localPosition = {0, 0, 0};
double[] globalPosition = {0, 0, 0};
- boolean needsCompute = true;
+ boolean needsCompute = true;
List<Integer> geomFields;
/**
@@ -41,40 +41,41 @@
{
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();
+ 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);
+ protected void setupGeomFields(IDDescriptor id)
+ {}
/**
* Check if the id is valid. It must be in bounds of the readout volume it points to.
* @param rawId
* @return True if id is valid for this segmentation type; False if not.
*/
- abstract public boolean boundsCheck(long rawId);
+ public boolean boundsCheck(long rawId)
+ {
+ return false;
+ }
/**
* Set the segmentation field values on the given <code>IExpandedIdentifier</code>.
* @param geomId The expanded id.
* @param localPositionVec The local position of the hit.
*/
- abstract protected void setSegmentationValues(IExpandedIdentifier geomId, Hep3Vector localPositionVec);
+ protected void setSegmentationValues(IExpandedIdentifier geomId, Hep3Vector localPositionVec)
+ {}
/**
- * Create the neighbor ids list with the given parameters for layer and the two fields.
- */
- abstract public long[] getNeighbourIDs(int layerRange, int uRange, int vRange);
-
- /**
* Compute the integer bin given a coordinate value and a grid size.
* @param u The coordinate value.
* @param gridSize The grid size.
@@ -101,7 +102,7 @@
/**
* Generic computation of hit's global position. Sets the <code>globalPosition</code> array.
*/
- protected final void computeGlobalPosition()
+ 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);
@@ -169,7 +170,7 @@
/**
* Compute and cache the cell's global position.
*/
- protected final void computePosition()
+ protected void computePosition()
{
computeLocalPosition();
computeGlobalPosition();
GeomConverter/src/org/lcsim/geometry/segmentation
diff -u -r1.6 -r1.7
--- CartesianGridXY.java 8 Oct 2009 18:52:22 -0000 1.6
+++ CartesianGridXY.java 2 Nov 2009 19:35:14 -0000 1.7
@@ -108,14 +108,7 @@
throw new RuntimeException("Don't know how to bounds check solid " + de.getGeometry().getLogicalVolume().getSolid().getName() + ".");
}
}
-
-
- public void setIDDescription(IDDescriptor id)
- {
- super.setIDDescription(id);
- setupGeomFields(id);
- }
-
+
public void setupGeomFields(IDDescriptor id)
{
if (geomFields == null)
GeomConverter/src/org/lcsim/geometry/segmentation
diff -u -r1.28 -r1.29
--- GridXYZ.java 21 Sep 2009 21:12:35 -0000 1.28
+++ GridXYZ.java 2 Nov 2009 19:35:14 -0000 1.29
@@ -22,8 +22,7 @@
* @author jeremym Cartesian XYZ grid segmentation, primarily used for readout
* of planes. This segmentation is based on a local coordinate system.
*/
-// FIXME: This class needs to be refactored. It is doing way to much and has too
-// many extra methods.
+// FIXME: This class needs to be refactored.
public class GridXYZ extends SegmentationBase
{
private double gridSizeX = 0;
@@ -293,70 +292,9 @@
IIdentifierHelper helper;
IIdentifierDictionary iddict;
- // FIXME: This method needs to be generalized to all calorimeters, including the old endcaps.
- // For the general computation to work, they will need to have properly defined sensor
- // DetectorElements. Currently, it has a specific case for PolyhedraBarrel and PolyhedraEndcap.
private void computeGlobalPosition()
- {
- //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)
- {
- geomFields = new ArrayList<Integer>();
-
- helper = detector.getDetectorElement().getIdentifierHelper();
- iddict = helper.getIdentifierDictionary();
-
- for (Entry<Integer,IIdentifierField> field : iddict.getFieldIndexMap().entrySet())
- {
- String label = field.getValue().getLabel();
- if (!label.equals("x") && !label.equals("y") && !label.equals("z"))
- {
- geomFields.add(field.getKey());
- }
- }
- }
-
- // Compute for PolyhedraBarrel and PolyhedraEndcap.
- if (detector instanceof PolyhedraBarrelCalorimeter
- || detector instanceof PolyhedraEndcapCalorimeter)
- {
- // Make an id only containing geometric fields and no segmentation fields.
- IExpandedIdentifier geomIdExp = helper.unpack(new Identifier(this.getDecoder().getID()), geomFields);
- IIdentifier geomId = helper.pack(geomIdExp);
-
- // Find the DetectorElement associated with the geometry id.
- List<IDetectorElement> deSearch = detector.getDetectorElement().findDetectorElement(geomId);
-
- // Check if lookup failed.
- if (deSearch == null || deSearch.size() == 0)
- {
- throw new RuntimeException("Failed to find DetectorElement with geometry id <" + geomIdExp.toString() + ">!");
- }
-
- // Set the DetectorElement associated to the hit.
- 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 global position array.
- globalPosition[0] = posVecGlobal.x();
- globalPosition[1] = posVecGlobal.y();
- globalPosition[2] = posVecGlobal.z();
- }
- // Other types, including CylindricalEndcapCalorimeter.
- else
- {
- */
+ {
globalPosition = transformLocalToGlobal(localPosition);
- //}
}
public void setSubdetector(Subdetector subdet)
@@ -541,7 +479,7 @@
public int getBin(double u, double gridSizeU)
{
- int numBins = (int) Math.floor(2 * getRMax() / gridSizeU);
+ //int numBins = (int) Math.floor(2 * getRMax() / gridSizeU);
double u0 = gridSizeU / 2;
int iu = (int) Math.floor((u - u0) / gridSizeU + 0.5);
return iu;
CVSspam 0.2.8