lcsim/test/org/lcsim/calorimeter
diff -N CalorimeterHitDetectorElementTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ CalorimeterHitDetectorElementTest.java 18 Mar 2009 03:43:13 -0000 1.1
@@ -0,0 +1,100 @@
+package org.lcsim.calorimeter;
+
+import java.io.File;
+import java.net.URL;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.lcsim.detector.identifier.IIdentifierHelper;
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.event.EventHeader;
+import org.lcsim.util.Driver;
+import org.lcsim.util.cache.FileCache;
+import org.lcsim.util.loop.LCSimLoop;
+
+/**
+ * Tests that the CalorimeterHitDetectorElementDriver sets up DetectorElements
+ * for all CalorimeterHits.
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+public class CalorimeterHitDetectorElementTest extends TestCase
+{
+ private static final boolean DEBUG = false;
+
+ public void testHits() throws Exception
+ {
+ URL url = new URL("http://www.lcsim.org/test/lcio/panpyWW-0-500_SLIC-v2r5p4_geant4-v9r2p0_LCPhys_sid02.slcio");
+ FileCache cache = new FileCache();
+ File testFile = cache.getCachedFile(url);
+ LCSimLoop loop = new LCSimLoop();
+ loop.setLCIORecordSource(testFile);
+ loop.add(new CalorimeterTestDriver());
+ loop.loop(-1,null);
+ loop.dispose();
+ }
+
+ class CalorimeterTestDriver extends Driver
+ {
+ CalorimeterTestDriver()
+ {}
+
+ public void process(EventHeader event)
+ {
+ // First time how long it takes to setup DetectorElements
+ // for the curious and/or skeptical.
+ long start = System.currentTimeMillis();
+ int nhits = 0;
+ for (List<CalorimeterHit> coll : event.get(CalorimeterHit.class))
+ {
+ for (CalorimeterHit hit : coll)
+ {
+ hit.getDetectorElement();
+ ++nhits;
+ }
+ }
+ long elapsed = System.currentTimeMillis() - start;
+ System.out.println("Took " + elapsed + " ms to find DetectorElements for " + nhits + " hits.");
+ System.out.println("ms / hit = " + ((double)elapsed)/((double)nhits));
+
+ // Now process the collections again and perform some assertions to
+ // check the validity of the DetectorElement association.
+ int checkedHits=0;
+ for (List<CalorimeterHit> coll : event.get(CalorimeterHit.class))
+ {
+ for (CalorimeterHit hit : coll)
+ {
+ hit.getDetectorElement();
+
+ // Hit must have a DetectorElement.
+ assertTrue(hit.getDetectorElement() != null);
+
+ IIdentifierHelper helper = hit.getIdentifierHelper();
+
+ // Verbose debug print of DetectorElement name and hit's expanded identifier.
+ if (DEBUG)
+ System.out.println(hit.getDetectorElement().getName() + " - " + hit.getIdentifierHelper().unpack(hit.getIdentifier()));
+
+ // CalorimeterHits are currently linked to their layer,
+ // so layer number should match the DetectorElement's.
+ int layern = helper.getValue(hit.getIdentifier(), "layer");
+
+ // TODO: Replace with comparison against DetectorElement's identifier
+ // once CylindricalCalorimeter sensors have them.
+ if (!hit.getDetectorElement().getName().contains("layer"+layern))
+ {
+ throw new RuntimeException(
+ "The layer number <" + layern + "> of the hit and does not match DetectorElement <" + hit.getDetectorElement().getName() + ">.");
+ }
+
+ ++checkedHits;
+ }
+ }
+ assertEquals(
+ "The number of hits that were setup and those that were checked do not match.",
+ nhits,
+ checkedHits);
+ System.out.println("Checked " + checkedHits + " for valid DetectorElement setting.");
+ }
+ }
+}
\ No newline at end of file
lcsim/test/org/lcsim/calorimeter
diff -N CalorimeterHitDetectorElementDriverTest.java
--- CalorimeterHitDetectorElementDriverTest.java 18 Mar 2009 03:24:44 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,81 +0,0 @@
-package org.lcsim.calorimeter;
-
-import java.io.File;
-import java.net.URL;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.lcsim.detector.identifier.IIdentifierHelper;
-import org.lcsim.event.CalorimeterHit;
-import org.lcsim.event.EventHeader;
-import org.lcsim.util.Driver;
-import org.lcsim.util.cache.FileCache;
-import org.lcsim.util.loop.LCSimLoop;
-
-/**
- * Tests that the CalorimeterHitDetectorElementDriver sets up DetectorElements
- * for all CalorimeterHits.
- * @author Jeremy McCormick <[log in to unmask]>
- */
-public class CalorimeterHitDetectorElementDriverTest extends TestCase
-{
- private static final boolean DEBUG = false;
-
- public void testHits() throws Exception
- {
- URL url = new URL("http://www.lcsim.org/test/lcio/panpyWW-0-500_SLIC-v2r5p4_geant4-v9r2p0_LCPhys_sid02.slcio");
- FileCache cache = new FileCache();
- File testFile = cache.getCachedFile(url);
- LCSimLoop loop = new LCSimLoop();
- loop.setLCIORecordSource(testFile);
- loop.add(new CalorimeterTestDriver());
- loop.loop(-1);
- loop.dispose();
- }
-
- class CalorimeterTestDriver extends Driver
- {
- CalorimeterTestDriver()
- {
- add(new CalorimeterHitDetectorElementDriver());
- }
-
- public void process(EventHeader event)
- {
- long start = System.currentTimeMillis();
- super.process(event);
- long elapsed = System.currentTimeMillis() - start;
- int nhits = 0;
- for (List<CalorimeterHit> coll : event.get(CalorimeterHit.class))
- {
- for (CalorimeterHit hit : coll)
- {
- // Hit must have a DetectorElement.
- assert(hit.getDetectorElement() != null);
- IIdentifierHelper helper = hit.getIdentifierHelper();
-
- // Verbose debug print of DetectorElement name and hit's expanded identifier.
- if (DEBUG)
- System.out.println(hit.getDetectorElement().getName() + " - " + hit.getIdentifierHelper().unpack(hit.getIdentifier()));
-
- // CalorimeterHits are currently linked to their layer,
- // so layer number should match the DetectorElement's.
- int layern = helper.getValue(hit.getIdentifier(), "layer");
-
- // TODO: Replace with comparison against DetectorElement's identifier
- // once CylindricalCalorimeter sensors have them.
- if (!hit.getDetectorElement().getName().contains("layer"+layern))
- {
- throw new RuntimeException(
- "The layer number <" + layern + "> of the hit and does not match DetectorElement <" + hit.getDetectorElement().getName() + ">.");
- }
-
- ++nhits;
- }
- }
- System.out.println("Took " + elapsed + " ms on " + nhits + " hits.");
- System.out.println("ms / hit = " + ((double)elapsed)/((double)nhits));
- }
- }
-}
\ No newline at end of file