GeomConverter/src/org/lcsim/geometry/subdetector
diff -u -r1.5 -r1.6
--- HPSEcal.java 18 Jul 2011 21:01:53 -0000 1.5
+++ HPSEcal.java 28 Jul 2011 20:20:18 -0000 1.6
@@ -7,6 +7,8 @@
import org.jdom.Element;
import org.jdom.JDOMException;
+import org.lcsim.detector.identifier.IIdentifierHelper;
+import org.lcsim.detector.identifier.Identifier;
import org.lcsim.geometry.IDDecoder;
import org.lcsim.geometry.util.IDEncoder;
@@ -15,7 +17,7 @@
*
* @author Jeremy McCormick <[log in to unmask]>
* @author Timothy Nelson <[log in to unmask]>
- * @version $Id: HPSEcal.java,v 1.5 2011/07/18 21:01:53 jeremy Exp $
+ * @version $Id: HPSEcal.java,v 1.6 2011/07/28 20:20:18 jeremy Exp $
*/
public class HPSEcal extends AbstractSubdetector
{
@@ -26,7 +28,31 @@
private boolean oddX;
public static class NeighborMap extends HashMap<Long,Set<Long>>
- {}
+ {
+ IIdentifierHelper helper;
+ public NeighborMap(IIdentifierHelper helper)
+ {
+ this.helper = helper;
+ }
+
+ public String toString()
+ {
+ System.out.println("NeighborMap has " + this.size() + " entries.");
+ StringBuffer buff = new StringBuffer();
+ for (long id : this.keySet())
+ {
+ buff.append(helper.unpack(new Identifier(id)))
+ .append("\n");
+ Set<Long> nei = this.get(id);
+ for (long nid : nei)
+ {
+ buff.append(" " + helper.unpack(new Identifier(nid)))
+ .append("\n");
+ }
+ }
+ return buff.toString();
+ }
+ }
private NeighborMap neighborMap = null;
@@ -55,8 +81,26 @@
return beamgap;
}
+ /**
+ * The number of crystals in X in one section.
+ * @return
+ */
+ public double nx()
+ {
+ return nx;
+ }
+
+ /**
+ * The number of crystals in y in one section.
+ * @return
+ */
+ public double ny()
+ {
+ return ny;
+ }
+
// Class for storing neighbor incides in XY and side.
- public static class XYSide implements Comparator<XYSide>
+ static class XYSide implements Comparator<XYSide>
{
int x;
int y;
@@ -109,7 +153,7 @@
* @param id The cell ID.
* @return A <code>Set</code> containing the cell's neighbors.
*/
- public Set<Long> getNeighbors(Long id)
+ Set<Long> getNeighbors(Long id)
{
// Get the IDDecoder.
IDDecoder dec = getIDDecoder();
@@ -153,7 +197,7 @@
return ids;
}
- public Set<XYSide> getNeighbors(int ix, int iy, int side)
+ Set<XYSide> getNeighbors(int ix, int iy, int side)
{
Set<Integer> xneighbors = getXNeighbors(ix);
Set<Integer> yneighbors = getYNeighbors(iy);
@@ -177,7 +221,7 @@
return neighbors;
}
- public Set<Integer> getXNeighbors(int ix)
+ Set<Integer> getXNeighbors(int ix)
{
Set<Integer> neighbors = new HashSet<Integer>();
@@ -207,7 +251,7 @@
return neighbors;
}
- public Set<Integer> getYNeighbors(int iy)
+ Set<Integer> getYNeighbors(int iy)
{
Set<Integer> neighbors = new HashSet<Integer>();
@@ -228,13 +272,13 @@
return neighbors;
}
- public boolean isValidY(int iy)
+ boolean isValidY(int iy)
{
// Zero is not valid because ID scheme goes from 1.
return iy > 0 && iy <= ny;
}
- public boolean isValidX(int ix)
+ boolean isValidX(int ix)
{
// Even case.
if (!oddX)
@@ -247,44 +291,20 @@
return ix >= (-nx-1)/2 && ix <= (nx+1)/2;
}
}
-
- /**
- * The number of crystals in X in one section.
- * @return
- */
- public double nx()
- {
- return nx;
- }
-
- /**
- * The number of crystals in y in one section.
- * @return
- */
- public double ny()
- {
- return ny;
- }
-
+
/**
* Create a map of crystal IDs to the <code>Set</code> of neighbor crystal IDs.
* @return A map of neighbors for each crystal ID.
*/
- public NeighborMap makeNeighborMap()
+ public NeighborMap getNeighborMap()
{
if (neighborMap != null)
{
- //System.out.println("Returning existing neighbor map ...");
return neighborMap;
}
-
- //System.out.println(this.getClass().getCanonicalName() + " - makeNeighborsMap");
-
- //System.out.println(" nx = " + nx);
- //System.out.println(" ny = " + ny);
// Setup the private instance of the map.
- neighborMap = new NeighborMap();
+ neighborMap = new NeighborMap(this.getDetectorElement().getIdentifierHelper());
IDDecoder dec = getIDDecoder();
IDEncoder enc = new IDEncoder(dec.getIDDescription());
@@ -314,8 +334,10 @@
{
if (side == 0) continue;
vals[dec.getFieldIndex("side")] = side;
+ // Loop over y.
for (int iy=1; iy<=ny; iy++)
- {
+ {
+ // Loop over x.
for (int ix=0; ix<=hnx; ix++)
{
// Loop for positive and negative x.
@@ -323,27 +345,13 @@
{
if (j == 0)
continue;
-
- //
- //System.out.println("side = " + side);
- //System.out.println("ix = " + ix);
- //System.out.println("iy = " + iy);
- //System.out.println("j = " + j);
-
+
vals[idxx] = ix*j;
vals[idxy] = iy;
-
- //System.out.println(new ExpandedIdentifier(vals));
-
+
Long id = enc.setValues(vals);
Set<Long> neighbors = getNeighbors(id);
-
- // DEBUG
- //for (Long nid : neighbors)
- //{
- // System.out.println(" " + this.getDetectorElement().getIdentifierHelper().unpack(new Identifier(nid)));
- //}
-
+
neighborMap.put(id, neighbors);
}
}
@@ -351,5 +359,5 @@
}
return neighborMap;
- }
-}
+ }
+}
\ No newline at end of file