lcsim/test/org/lcsim
diff -u -r1.2 -r1.3
--- SidloiCalorimeterHitTest.java 18 Sep 2009 21:10:15 -0000 1.2
+++ SidloiCalorimeterHitTest.java 21 Sep 2009 23:05:06 -0000 1.3
@@ -7,23 +7,26 @@
import junit.framework.TestCase;
import org.lcsim.detector.identifier.IIdentifierHelper;
+import org.lcsim.detector.identifier.Identifier;
import org.lcsim.event.EventHeader;
import org.lcsim.event.SimCalorimeterHit;
import org.lcsim.geometry.IDDecoder;
+import org.lcsim.geometry.Subdetector;
+import org.lcsim.geometry.compact.Segmentation;
+import org.lcsim.geometry.segmentation.CartesianGridXY;
+import org.lcsim.geometry.segmentation.CartesianGridXZ;
import org.lcsim.util.Driver;
import org.lcsim.util.cache.FileCache;
import org.lcsim.util.loop.LCSimLoop;
-import org.lcsim.geometry.Detector;
-import org.lcsim.detector.*;
-/**
- * Tests that IDDecoder's computed position matches the position
- * written into the hit by slic. Also checks that the correct
- * number of neighbors are found.
+/*
+ * Tests that the hit position from slic is the same as the computed
+ * position from the decoder. Also checks that the correct
+ * number of neighbors are found and that findCellContainingXYZ
+ * works on cells where the bounds check is successful.
*
* @author jeremym
*/
-// TODO: Add in EcalBarrel once java version is implemented.
public class SidloiCalorimeterHitTest extends TestCase
{
private static final String[] colls =
@@ -31,7 +34,7 @@
public void testHitPosition() throws Exception
{
- runTestFile("http://www.lcsim.org/test/lcio/dev/gamma_Theta1-179_10GeV-0-2000_SLIC-v2r6p1_geant4-v9r2p2_LCPhys_sidloi2.slcio");
+ runTestFile("http://www.lcsim.org/test/lcio/dev/pi_Theta1-179_10GeV-0-2000_SLIC-v2r6p1_geant4-v9r2p2_LCPhys_sidloi2.slcio");
}
private void runTestFile(String s) throws Exception
@@ -43,33 +46,14 @@
LCSimLoop loop = new LCSimLoop();
loop.setLCIORecordSource(file);
loop.add(new HitPositionDriver());
- loop.loop(-1, null);
+ loop.loop(2, null);
loop.dispose();
}
- static final double tolerance = 1.0;
+ static final double tolerance = 0.1;
private class HitPositionDriver extends Driver
- {
- /*
- public void detectorChanged(Detector detector)
- {
- for (IDetectorElement de : DetectorElementStore.getInstance())
- {
- if (de.getName().contains("EcalBarrel"))
- {
- System.out.println(de.getName());
- try
- {
- System.out.println(" " + de.getExpandedIdentifier().toString());
- }
- catch (Exception x)
- {}
- }
- }
- }
- */
-
+ {
public void process(EventHeader event)
{
for (String s : colls)
@@ -80,6 +64,10 @@
IIdentifierHelper helper = decoder.getSubdetector().getDetectorElement().getIdentifierHelper();
int nlayers = decoder.getSubdetector().getLayering().getLayerCount();
+
+ Subdetector subdet = decoder.getSubdetector();
+
+ Segmentation seg = (Segmentation)decoder.getSubdetector().getIDDecoder();
for (SimCalorimeterHit hit : hits)
{
@@ -93,10 +81,18 @@
//System.out.println("hit id: " + hit.getExpandedIdentifier().toString());
//System.out.println("hit pos: " + pos[0] + ", " + pos[1] + ", " + pos[2]);
//System.out.println("decoder pos: " + decoder.getX() + ", " + decoder.getY() + ", " + decoder.getZ());
-
- assertEquals("X coordinate off by > " + tolerance, decoder.getX(), pos[0], tolerance);
- assertEquals("Y coordinate off by > " + tolerance, decoder.getY(), pos[1], tolerance);
- assertEquals("Z coordinate off by > " + tolerance, decoder.getZ(), pos[2], tolerance);
+
+ //
+ // Check position from simulation with computed position from decoder.
+ //
+
+ assertEquals("X coordinate off by > " + tolerance + " in " + decoder.getSubdetector().getName(), decoder.getX(), pos[0], tolerance);
+ assertEquals("Y coordinate off by > " + tolerance + " in " + decoder.getSubdetector().getName(), decoder.getY(), pos[1], tolerance);
+ assertEquals("Z coordinate off by > " + tolerance + " in " + decoder.getSubdetector().getName(), decoder.getZ(), pos[2], tolerance);
+
+ //
+ // Check number of neighbors.
+ //
long neighbors[] = decoder.getNeighbourIDs(1, 1, 1);
@@ -110,6 +106,43 @@
{
assertEquals("Number of neighbors is incorrect.", 18, neighbors.length);
}
+
+ //
+ // Check that cell is bounded by DetectorElement's shape.
+ // Ignore errors because some border cells may seem to be outside.
+ //
+
+ boolean bounds = false;
+ try
+ {
+ if (seg instanceof CartesianGridXY)
+ bounds = ((CartesianGridXY)seg).boundsCheck(id);
+ else if (seg instanceof CartesianGridXZ)
+ bounds = ((CartesianGridXZ)seg).boundsCheck(id);
+ }
+ catch (Exception x)
+ {}
+
+ //
+ // For cells that are in bounds, check that findCellContainingXYZ
+ // returns this ID.
+ //
+
+ if (bounds)
+ {
+ long fndId = 0;
+ try
+ {
+ fndId = seg.findCellContainingXYZ(pos[0], pos[1], pos[2]);
+ }
+ catch (Exception x)
+ {}
+ if (fndId != 0)
+ assertEquals(
+ "Found cell does not match hit's cell in " + subdet.getName() + ".",
+ helper.unpack(new Identifier(fndId)).toString(),
+ helper.unpack(new Identifier(id)).toString());
+ }
//System.out.println("neighbors: " + neighbors.length);
//for (int i=0; i<neighbors.length; i++)