lcsim/test/org/lcsim/detector/driver
diff -N DetectorIdentifierHelperTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ DetectorIdentifierHelperTest.java 6 Nov 2007 20:51:41 -0000 1.1
@@ -0,0 +1,273 @@
+package org.lcsim.detector.driver;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.freehep.record.loop.LoopException;
+import org.lcsim.detector.identifier.IIdentifier;
+import org.lcsim.detector.identifier.Identifier;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.SimCalorimeterHit;
+import org.lcsim.event.SimTrackerHit;
+import org.lcsim.event.EventHeader.LCMetaData;
+import org.lcsim.geometry.Subdetector;
+import org.lcsim.util.Driver;
+import org.lcsim.util.cache.FileCache;
+import org.lcsim.util.loop.LCSimLoop;
+import org.lcsim.detector.IDetectorElement;
+import org.lcsim.detector.DetectorIdHelper;
+
+/**
+ * Tests the functionality of {@link org.lcsim.detector.DetectorIdHelper}
+ * on an sid01 LCIO file.
+ *
+ * @author Jeremy McCormick <[log in to unmask]>
+ * @version $Id: DetectorIdentifierHelperTest.java,v 1.1 2007/11/06 20:51:41 jeremy Exp $
+ */
+
+public class DetectorIdentifierHelperTest extends TestCase
+{
+ public void testDetectorIdHelper()
+ {
+ File file = null;
+ try
+ {
+ FileCache cache = new FileCache();
+ file = cache.getCachedFile(new URL("http://www.lcsim.org/test/lcio/pythiaZPoleuds-0-1000_SLIC-v2r3p7_geant4-v9r0p1_LCPhys_sid01.slcio"));
+ LCSimLoop loop = new LCSimLoop();
+ loop.setLCIORecordSource(file);
+ loop.add(new TrackerDriver());
+ loop.add(new CalorimeterDriver());
+ loop.loop(1,null);
+ loop.dispose();
+ }
+ catch (IOException x)
+ {
+ throw new RuntimeException(x);
+ }
+ catch (LoopException x)
+ {
+ throw new RuntimeException(x);
+ }
+ }
+
+ class CalorimeterDriver extends Driver
+ {
+ protected void process(EventHeader event)
+ {
+ int ecalBarrel, ecalEndcap, hcalBarrel, hcalEndcap, forwardEcal, lumi, muonBarrel, muonEndcap;
+ ecalBarrel = ecalEndcap = hcalBarrel = hcalEndcap = forwardEcal = lumi = muonBarrel = muonEndcap = 0;
+ List<List<SimCalorimeterHit>> collections = event.get(SimCalorimeterHit.class);
+ for (List<SimCalorimeterHit> collection: collections)
+ {
+ LCMetaData meta = event.getMetaData(collection);
+ String collectionName = meta.getName();
+ Subdetector subdet = meta.getIDDecoder().getSubdetector();
+ IDetectorElement deSubdet = subdet.getDetectorElement();
+ DetectorIdHelper idHelper = (DetectorIdHelper)deSubdet.getIdentifierHelper();
+
+ for (SimCalorimeterHit hit : collection)
+ {
+ IIdentifier hitId = new Identifier(hit.getCellID());
+
+ assertTrue(idHelper.isCalorimeter(hitId));
+
+ if (subdet.isBarrel())
+ {
+ assertTrue(idHelper.isBarrel(hitId));
+ assertTrue(idHelper.isCalorimeterBarrel(hitId));
+ }
+
+ if (subdet.isEndcap())
+ {
+ assertTrue(idHelper.isEndcap(hitId));
+ assertTrue(idHelper.isCalorimeterEndcap(hitId));
+
+ if (hit.getPosition()[2] > 0)
+ {
+ assertTrue(idHelper.isCalorimeterEndcapPositive(hitId));
+ }
+ else
+ {
+ assertTrue(idHelper.isCalorimeterEndcapNegative(hitId));
+ }
+ }
+
+ if (collectionName.equals("EcalBarrHits"))
+ {
+ assertTrue(idHelper.isEcal(hitId));
+ assertTrue(idHelper.isBarrel(hitId));
+ }
+
+ if (collectionName.equals("EcalEndcapHits"))
+ {
+ assertTrue(idHelper.isEcal(hitId));
+ assertTrue(idHelper.isEcalEndcap(hitId));
+ if (hit.getPosition()[2] > 0)
+ {
+ assertTrue(idHelper.isEcalEndcapPositive(hitId));
+ }
+ else
+ {
+ assertTrue(idHelper.isEcalEndcapNegative(hitId));
+ }
+ }
+
+ if (collectionName.equals("HcalBarrHits"))
+ {
+ assertTrue(idHelper.isHcal(hitId));
+ assertTrue(idHelper.isHcalBarrel(hitId));
+ }
+
+ if (collectionName.equals("HcalEndcapHits"))
+ {
+ assertTrue(idHelper.isHcal(hitId));
+ assertTrue(idHelper.isHcalEndcap(hitId));
+ if (hit.getPosition()[2] > 0)
+ {
+ assertTrue(idHelper.isHcalEndcapPositive(hitId));
+ }
+ else
+ {
+ assertTrue(idHelper.isHcalEndcapNegative(hitId));
+ }
+ }
+
+ if (collectionName.equals("MuonBarrHits"))
+ {
+ assertTrue(idHelper.isMuon(hitId));
+ assertTrue(idHelper.isMuonBarrel(hitId));
+ }
+
+ if (collectionName.equals("MuonEndcapHits"))
+ {
+ assertTrue(idHelper.isMuon(hitId));
+ assertTrue(idHelper.isMuonEndcap(hitId));
+ if (hit.getPosition()[2] > 0)
+ {
+ assertTrue(idHelper.isMuonEndcapPositive(hitId));
+ }
+ else
+ {
+ assertTrue(idHelper.isMuonEndcapNegative(hitId));
+ }
+ }
+
+ if (collectionName.equals("LuminosityMonitorHits"))
+ {
+ assertTrue(idHelper.isLumi(hitId));
+
+ if (hit.getPosition()[2] > 0)
+ {
+ assertTrue(idHelper.isLumiEndcapPositive(hitId));
+ }
+ else
+ {
+ assertTrue(idHelper.isLumiEndcapNegative(hitId));
+ }
+ }
+
+ if (collectionName.equals("ForwardEcalEndcapHits"))
+ {
+ assertTrue(idHelper.isEcalForward(hitId));
+
+ if (hit.getPosition()[2] > 0)
+ {
+ assertTrue(idHelper.isEcalForwardEndcapPositive(hitId));
+ }
+ else
+ {
+ assertTrue(idHelper.isEcalForwardEndcapNegative(hitId));
+ }
+ }
+ }
+ }
+ }
+ }
+
+ class TrackerDriver extends Driver
+ {
+ protected void process(EventHeader event)
+ {
+ event.getDetector();
+ int sitBarrel, sitEndcap, vtxBarrel, vtxEndcap;
+ sitBarrel = sitEndcap = vtxBarrel = vtxEndcap = 0;
+ List<List<SimTrackerHit>> collections = event.get(SimTrackerHit.class);
+ for (List<SimTrackerHit> collection : collections)
+ {
+ LCMetaData meta = event.getMetaData(collection);
+ String collectionName = meta.getName();
+ Subdetector subdet = meta.getIDDecoder().getSubdetector();
+ if (subdet == null)
+ throw new RuntimeException("Oops! Subdetector for collection " + meta.getName() + " is null!");
+ IDetectorElement deSubdet = subdet.getDetectorElement();
+ DetectorIdHelper idHelper = (DetectorIdHelper)deSubdet.getIdentifierHelper();
+
+ IIdentifier subdetId = deSubdet.getIdentifier();
+
+ for (SimTrackerHit hit : collection)
+ {
+ IIdentifier hitId = new Identifier(hit.getCellID());
+
+ assertTrue(idHelper.isTracker(hitId));
+
+ if (subdet.isBarrel())
+ {
+ assertTrue(idHelper.isBarrel(hitId));
+ assertTrue(idHelper.isTrackerBarrel(hitId));
+ }
+
+ if (subdet.isEndcap())
+ {
+ assertTrue(idHelper.isEndcap(hitId));
+ assertTrue(idHelper.isTrackerEndcap(hitId));
+ }
+
+ if (collectionName.equals("TkrBarrHits"))
+ {
+ assertTrue(idHelper.isSit(hitId));
+ assertTrue(idHelper.isSitBarrel(hitId));
+ }
+
+ if (collectionName.equals("TkrEndcapHits"))
+ {
+ assertTrue(idHelper.isSit(hitId));
+ assertTrue(idHelper.isSitEndcap(hitId));
+ if (hit.getPoint()[2] > 0)
+ {
+ assertTrue(idHelper.isSitEndcapPositive(hitId));
+ }
+ else
+ {
+ assertTrue(idHelper.isSitEndcapNegative(hitId));
+ }
+ }
+
+ if (collectionName.equals("VtxBarrHits"))
+ {
+ assertTrue(idHelper.isVtx(hitId));
+ assertTrue(idHelper.isVtxBarrel(hitId));
+ }
+
+ if (collectionName.equals("VtxEndcapHits"))
+ {
+ assertTrue(idHelper.isVtx(hitId));
+ assertTrue(idHelper.isVtxEndcap(hitId));
+ if (hit.getPoint()[2] > 0)
+ {
+ assertTrue(idHelper.isVtxEndcapPositive(hitId));
+ }
+ else
+ {
+ assertTrue(idHelper.isVtxEndcapNegative(hitId));
+ }
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
lcsim/test/org/lcsim/detector/driver
diff -N DetectorIdHelperTest.java
--- DetectorIdHelperTest.java 11 Sep 2007 00:21:01 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,300 +0,0 @@
-package org.lcsim.detector.driver;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URL;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.freehep.record.loop.LoopException;
-import org.lcsim.detector.identifier.IIdentifier;
-import org.lcsim.detector.identifier.Identifier;
-import org.lcsim.event.EventHeader;
-import org.lcsim.event.SimCalorimeterHit;
-import org.lcsim.event.SimTrackerHit;
-import org.lcsim.event.EventHeader.LCMetaData;
-import org.lcsim.geometry.Subdetector;
-import org.lcsim.util.Driver;
-import org.lcsim.util.cache.FileCache;
-import org.lcsim.util.loop.LCSimLoop;
-import org.lcsim.detector.IDetectorElement;
-import org.lcsim.detector.DetectorIdHelper;
-
-/**
- * Tests the functionality of {@link org.lcsim.detector.DetectorIdHelper}
- * on an sid01 LCIO file.
- *
- * @author Jeremy McCormick <[log in to unmask]>
- * @version $Id: DetectorIdHelperTest.java,v 1.2 2007/09/11 00:21:01 tonyj Exp $
- */
-
-public class DetectorIdHelperTest extends TestCase
-{
- public void testDetectorIdHelper()
- {
- File file = null;
- try
- {
- FileCache cache = new FileCache();
- file = cache.getCachedFile(new URL("http://www.lcsim.org/test/lcio/muons10_Theta4-176_1-10GeV_SLIC_v2r2p1_sid01.slcio"));
- LCSimLoop loop = new LCSimLoop();
- loop.setLCIORecordSource(file);
- loop.add(new TrackerDriver());
- loop.add(new CalorimeterDriver());
- loop.loop(1,null);
- loop.dispose();
- }
- catch (IOException x)
- {
- throw new RuntimeException(x);
- }
- catch (LoopException x)
- {
- throw new RuntimeException(x);
- }
- }
-
- class CalorimeterDriver extends Driver
- {
- protected void process(EventHeader event)
- {
- int ecalBarrel, ecalEndcap, hcalBarrel, hcalEndcap, forwardEcal, lumi, muonBarrel, muonEndcap;
- ecalBarrel = ecalEndcap = hcalBarrel = hcalEndcap = forwardEcal = lumi = muonBarrel = muonEndcap = 0;
- List<List<SimCalorimeterHit>> collections = event.get(SimCalorimeterHit.class);
- for (List<SimCalorimeterHit> collection: collections)
- {
- LCMetaData meta = event.getMetaData(collection);
- String collectionName = meta.getName();
- Subdetector subdet = meta.getIDDecoder().getSubdetector();
- IDetectorElement deSubdet = subdet.getDetectorElement();
- DetectorIdHelper idHelper = (DetectorIdHelper)deSubdet.getIdentifierHelper();
-
- for (SimCalorimeterHit hit : collection)
- {
- IIdentifier hitId = new Identifier(hit.getCellID());
-
- assertTrue(idHelper.isCalorimeter(hitId));
-
- if (subdet.isBarrel())
- {
- assertTrue(idHelper.isBarrel(hitId));
- assertTrue(idHelper.isCalorimeterBarrel(hitId));
- }
-
- if (subdet.isEndcap())
- {
- assertTrue(idHelper.isEndcap(hitId));
- assertTrue(idHelper.isCalorimeterEndcap(hitId));
-
- if (hit.getPosition()[2] > 0)
- {
- assertTrue(idHelper.isCalorimeterEndcapPositive(hitId));
- }
- else
- {
- assertTrue(idHelper.isCalorimeterEndcapNegative(hitId));
- }
- }
-
- if (collectionName.equals("EcalBarrHits"))
- {
- assertTrue(idHelper.isEcal(hitId));
- assertTrue(idHelper.isBarrel(hitId));
- ++ecalBarrel;
- }
-
- if (collectionName.equals("EcalEndcapHits"))
- {
- assertTrue(idHelper.isEcal(hitId));
- assertTrue(idHelper.isEcalEndcap(hitId));
- if (hit.getPosition()[2] > 0)
- {
- assertTrue(idHelper.isEcalEndcapPositive(hitId));
- }
- else
- {
- assertTrue(idHelper.isEcalEndcapNegative(hitId));
- }
- ++ecalEndcap;
- }
-
- if (collectionName.equals("HcalBarrHits"))
- {
- assertTrue(idHelper.isHcal(hitId));
- assertTrue(idHelper.isHcalBarrel(hitId));
- ++hcalBarrel;
- }
-
- if (collectionName.equals("HcalEndcapHits"))
- {
- assertTrue(idHelper.isHcal(hitId));
- assertTrue(idHelper.isHcalEndcap(hitId));
- if (hit.getPosition()[2] > 0)
- {
- assertTrue(idHelper.isHcalEndcapPositive(hitId));
- }
- else
- {
- assertTrue(idHelper.isHcalEndcapNegative(hitId));
- }
- ++hcalEndcap;
- }
-
- if (collectionName.equals("MuonBarrHits"))
- {
- assertTrue(idHelper.isMuon(hitId));
- assertTrue(idHelper.isMuonBarrel(hitId));
- ++muonBarrel;
- }
-
- if (collectionName.equals("MuonEndcapHits"))
- {
- assertTrue(idHelper.isMuon(hitId));
- assertTrue(idHelper.isMuonEndcap(hitId));
- if (hit.getPosition()[2] > 0)
- {
- assertTrue(idHelper.isMuonEndcapPositive(hitId));
- }
- else
- {
- assertTrue(idHelper.isMuonEndcapNegative(hitId));
- }
- ++muonEndcap;
- }
-
- // FIXME: This event does not have Lumi hits!
- if (collectionName.equals("LuminosityMonitorHits"))
- {
- assertTrue(idHelper.isLumi(hitId));
-
- if (hit.getPosition()[2] > 0)
- {
- assertTrue(idHelper.isLumiEndcapPositive(hitId));
- }
- else
- {
- assertTrue(idHelper.isLumiEndcapNegative(hitId));
- }
- ++lumi;
- }
-
- if (collectionName.equals("ForwardEcalEndcapHits"))
- {
- assertTrue(idHelper.isEcalForward(hitId));
-
- if (hit.getPosition()[2] > 0)
- {
- assertTrue(idHelper.isEcalForwardEndcapPositive(hitId));
- }
- else
- {
- assertTrue(idHelper.isEcalForwardEndcapNegative(hitId));
- }
- ++forwardEcal;
- }
- }
- }
- assertEquals(ecalBarrel,173);
- assertEquals(ecalEndcap,139);
- assertEquals(hcalBarrel,209);
- assertEquals(hcalEndcap,108);
- assertEquals(muonBarrel,73);
- assertEquals(muonEndcap,81);
- assertEquals(lumi,0);
- assertEquals(forwardEcal,30);
- }
- }
-
- class TrackerDriver extends Driver
- {
- protected void process(EventHeader event)
- {
- event.getDetector();
- int sitBarrel, sitEndcap, vtxBarrel, vtxEndcap;
- sitBarrel = sitEndcap = vtxBarrel = vtxEndcap = 0;
- List<List<SimTrackerHit>> collections = event.get(SimTrackerHit.class);
- for (List<SimTrackerHit> collection : collections)
- {
- LCMetaData meta = event.getMetaData(collection);
- String collectionName = meta.getName();
- Subdetector subdet = meta.getIDDecoder().getSubdetector();
- if (subdet == null)
- throw new RuntimeException("Oops! Subdetector for collection " + meta.getName() + " is null!");
- IDetectorElement deSubdet = subdet.getDetectorElement();
- DetectorIdHelper idHelper = (DetectorIdHelper)deSubdet.getIdentifierHelper();
-
- IIdentifier subdetId = deSubdet.getIdentifier();
-
- for (SimTrackerHit hit : collection)
- {
- IIdentifier hitId = new Identifier(hit.getCellID());
-
- assertTrue(idHelper.isTracker(hitId));
-
- if (subdet.isBarrel())
- {
- assertTrue(idHelper.isBarrel(hitId));
- assertTrue(idHelper.isTrackerBarrel(hitId));
- }
-
- if (subdet.isEndcap())
- {
- assertTrue(idHelper.isEndcap(hitId));
- assertTrue(idHelper.isTrackerEndcap(hitId));
- }
-
- if (collectionName.equals("TkrBarrHits"))
- {
- assertTrue(idHelper.isSit(hitId));
- assertTrue(idHelper.isSitBarrel(hitId));
- ++sitBarrel;
- }
-
- if (collectionName.equals("TkrEndcapHits"))
- {
- assertTrue(idHelper.isSit(hitId));
- assertTrue(idHelper.isSitEndcap(hitId));
- if (hit.getPoint()[2] > 0)
- {
- assertTrue(idHelper.isSitEndcapPositive(hitId));
- }
- else
- {
- assertTrue(idHelper.isSitEndcapNegative(hitId));
- }
- ++sitEndcap;
- }
-
- if (collectionName.equals("VtxBarrHits"))
- {
- assertTrue(idHelper.isVtx(hitId));
- assertTrue(idHelper.isVtxBarrel(hitId));
- ++vtxBarrel;
- }
-
- if (collectionName.equals("VtxEndcapHits"))
- {
- assertTrue(idHelper.isVtx(hitId));
- assertTrue(idHelper.isVtxEndcap(hitId));
- if (hit.getPoint()[2] > 0)
- {
- assertTrue(idHelper.isVtxEndcapPositive(hitId));
- }
- else
- {
- assertTrue(idHelper.isVtxEndcapNegative(hitId));
- }
- ++vtxEndcap;
- }
- }
- }
-
- // Check that the correct number of SimTrackerHits were processed.
- assertEquals(sitBarrel,33);
- assertEquals(sitEndcap, 26);
- assertEquals(vtxBarrel,35);
- assertEquals(vtxEndcap,12);
- }
- }
-}
\ No newline at end of file