lcsim/test/org/lcsim
diff -u -r1.3 -r1.4
--- SidloiCalorimeterHitTest.java 21 Sep 2009 23:05:06 -0000 1.3
+++ SidloiCalorimeterHitTest.java 8 Oct 2009 18:54:52 -0000 1.4
@@ -29,12 +29,26 @@
*/
public class SidloiCalorimeterHitTest extends TestCase
{
+ private static final boolean debug = false;
+ private static final boolean boundsCheck = true;
+
+ static final double tolerance = 0.1;
+
private static final String[] colls =
{ "EcalBarrelHits", "HcalEndcapHits", "EcalEndcapHits", "HcalBarrelHits" };
public void testHitPosition() throws Exception
{
- runTestFile("http://www.lcsim.org/test/lcio/dev/pi_Theta1-179_10GeV-0-2000_SLIC-v2r6p1_geant4-v9r2p2_LCPhys_sidloi2.slcio");
+ runTestFile("http://www.lcsim.org/test/lcio/dev/muons10_Theta4-176_1-10GeV_SLIC-v2r6p3_geant4-v9r2p0_LCPhys_sidloi2.slcio");
+ }
+
+ private void runTestFile(File f) throws Exception
+ {
+ LCSimLoop loop = new LCSimLoop();
+ loop.setLCIORecordSource(f);
+ loop.add(new HitPositionDriver());
+ loop.loop(1, null);
+ loop.dispose();
}
private void runTestFile(String s) throws Exception
@@ -46,11 +60,9 @@
LCSimLoop loop = new LCSimLoop();
loop.setLCIORecordSource(file);
loop.add(new HitPositionDriver());
- loop.loop(2, null);
+ loop.loop(1, null);
loop.dispose();
}
-
- static final double tolerance = 0.1;
private class HitPositionDriver extends Driver
{
@@ -58,6 +70,12 @@
{
for (String s : colls)
{
+ if (debug)
+ {
+ System.out.println("-----------------------------");
+ System.out.println("collection: " + s);
+ }
+
List<SimCalorimeterHit> hits = event.get(SimCalorimeterHit.class, s);
IDDecoder decoder = event.getMetaData(hits).getIDDecoder();
@@ -69,6 +87,10 @@
Segmentation seg = (Segmentation)decoder.getSubdetector().getIDDecoder();
+ int findCellCount = 0;
+ int neighborCheckCount = 0;
+ int outOfBoundsCount = 0;
+
for (SimCalorimeterHit hit : hits)
{
long id = hit.getCellID();
@@ -77,10 +99,13 @@
double[] pos = hit.getPosition();
// Debug stuff for testing new detector components.
- //System.out.println("-------------------------------");
- //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());
+ if (debug)
+ {
+ System.out.println("-------------------------------");
+ 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());
+ }
//
// Check position from simulation with computed position from decoder.
@@ -101,54 +126,75 @@
if (layern != 0 && layern != (nlayers - 1))
{
assertEquals("Number of neighbors is incorrect.", 27, neighbors.length);
+ ++neighborCheckCount;
}
else
{
assertEquals("Number of neighbors is incorrect.", 18, neighbors.length);
+ ++neighborCheckCount;
}
- //
- // 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)
+ if (boundsCheck)
{
- long fndId = 0;
+ //
+ // Check that cell is bounded by DetectorElement's shape.
+ //
+
+ boolean bounds = false;
try
- {
- fndId = seg.findCellContainingXYZ(pos[0], pos[1], pos[2]);
+ {
+ if (seg instanceof CartesianGridXY)
+ bounds = ((CartesianGridXY)seg).boundsCheck(id);
+ else if (seg instanceof CartesianGridXZ)
+ bounds = ((CartesianGridXZ)seg).boundsCheck(id);
}
catch (Exception x)
- {}
- if (fndId != 0)
+ {
+ throw new RuntimeException("Cell " + helper.unpack(new Identifier(id)).toString() + " is out of bounds.");
+ }
+
+ //
+ // Check that findCellContainingXYZ returns this ID for cells that are in bounds.
+ //
+
+ if (bounds)
+ {
+ long fndId = 0;
+ try
+ {
+ fndId = seg.findCellContainingXYZ(pos[0], pos[1], pos[2]);
+ }
+ catch (Exception x)
+ {
+ throw new RuntimeException("Error running findCell for id " + helper.unpack(new Identifier(id)).toString());
+ }
assertEquals(
"Found cell does not match hit's cell in " + subdet.getName() + ".",
helper.unpack(new Identifier(fndId)).toString(),
helper.unpack(new Identifier(id)).toString());
+ ++findCellCount;
+ }
+ else
+ {
+ ++outOfBoundsCount;
+ }
+
+ if (debug)
+ {
+ System.out.println("neighbors: " + neighbors.length);
+ for (int i=0; i<neighbors.length; i++)
+ {
+ System.out.println(" " + helper.unpack(new Identifier(neighbors[i])));
+ }
+ }
}
-
- //System.out.println("neighbors: " + neighbors.length);
- //for (int i=0; i<neighbors.length; i++)
- //{
- // System.out.println(" " + helper.unpack(new Identifier(neighbors[i])));
- //}
+ }
+
+ if (debug)
+ {
+ System.out.println("findCellContainingXYZ ran OK for " + findCellCount + " cells");
+ System.out.println("neighbors checked OK for " + neighborCheckCount + " cells");
+ System.out.println("found " + outOfBoundsCount + " cells that were out of bounds");
}
}
}