lcsim/test/org/lcsim
diff -N CalHitStepPosTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ CalHitStepPosTest.java 27 Feb 2012 22:09:23 -0000 1.1
@@ -0,0 +1,65 @@
+package org.lcsim;
+
+import hep.physics.vec.BasicHep3Vector;
+import hep.physics.vec.Hep3Vector;
+import hep.physics.vec.VecOp;
+
+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.event.EventHeader;
+import org.lcsim.event.SimCalorimeterHit;
+import org.lcsim.geometry.IDDecoder;
+import org.lcsim.job.EventMarkerDriver;
+import org.lcsim.util.Driver;
+import org.lcsim.util.cache.FileCache;
+import org.lcsim.util.loop.LCSimLoop;
+
+public class CalHitStepPosTest extends TestCase {
+
+ private static final String fileUrl = "http://www.lcsim.org/test/lcio/muons500_Theta4-176_1-10GeV_SLIC-v2r11p2_geant4-v9r4p2_QGSP_BERT_sidloi3.slcio";
+
+ public void testIt() throws IOException {
+ FileCache cache = new FileCache();
+ cache.setCacheDirectory(new File("."));
+ File file = cache.getCachedFile(new URL(fileUrl));
+ LCSimLoop loop = new LCSimLoop();
+ loop.add(new EventMarkerDriver());
+ loop.add(new CellPosDriver());
+ try {
+ loop.setLCIORecordSource(file);
+ } catch (IOException x) {
+ throw new RuntimeException(x);
+ }
+ try {
+ loop.loop(-1, null);
+ } catch (LoopException x) {
+ throw new RuntimeException(x);
+ } catch (IOException x) {
+ throw new RuntimeException(x);
+ }
+ loop.dispose();
+ }
+
+ static class CellPosDriver extends Driver {
+ public void process(EventHeader event) {
+ List<SimCalorimeterHit> hits = event.get(SimCalorimeterHit.class, "HcalBarrelHits");
+ IDDecoder decoder = event.getMetaData(hits).getIDDecoder();
+ for (SimCalorimeterHit hit : hits) {
+ decoder.setID(hit.getCellID());
+ Hep3Vector cellPos = decoder.getPositionVector();
+ int ncontribs = hit.getMCParticleCount();
+ for (int i = 0; i < ncontribs; i++) {
+ float stepPos[] = hit.getStepPosition(i);
+ Hep3Vector stepVec = new BasicHep3Vector(stepPos[0], stepPos[1], stepPos[2]);
+ System.out.println("cell pos = " + VecOp.sub(stepVec, cellPos)); // Print each step position.
+ }
+ }
+ }
+ }
+}