lcsim/test/org/lcsim
diff -u -r1.3 -r1.4
--- CalHitStepPosTest.java 13 Jul 2012 18:59:20 -0000 1.3
+++ CalHitStepPosTest.java 18 Jul 2012 23:42:20 -0000 1.4
@@ -12,6 +12,7 @@
import junit.framework.TestCase;
import org.lcsim.event.EventHeader;
+import org.lcsim.event.EventHeader.LCMetaData;
import org.lcsim.event.SimCalorimeterHit;
import org.lcsim.geometry.IDDecoder;
import org.lcsim.job.EventMarkerDriver;
@@ -21,12 +22,11 @@
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";
- private static final String fileUrl = "http://www.lcsim.org/test/lcio/muon_Theta90_10GeV_SLIC-v3r0p0_geant4-v9r5p1_QGSP_BERT_sidloi3.slcio";
-
+ private static final String fileUrl = "ftp://ftp-lcd.slac.stanford.edu/lcd/jeremym/mu_Theta4-176_10GeV_SLIC-v3r0p1_geant4-v9r5p1_QGSP_BERT_sidloi3.slcio";
+
public void testIt() throws IOException {
FileCache cache = new FileCache();
- cache.setCacheDirectory(new File("."));
+ cache.setCacheDirectory(new File(".testdata"));
File file = cache.getCachedFile(new URL(fileUrl));
LCSimLoop loop = new LCSimLoop();
loop.add(new EventMarkerDriver());
@@ -45,19 +45,51 @@
}
static class CellPosDriver extends Driver {
- public void process(EventHeader event) {
- List<SimCalorimeterHit> hits = event.get(SimCalorimeterHit.class, "HcalBarrelHits");
- IDDecoder decoder = event.getMetaData(hits).getIDDecoder();
+
+ public void process(EventHeader event) {
+ for (List<SimCalorimeterHit> collection : event.get(SimCalorimeterHit.class)) {
+ procHits(collection, event);
+ }
+ System.out.println();
+ }
+
+ private void procHits(List<SimCalorimeterHit> hits, EventHeader event) {
+ LCMetaData meta = event.getMetaData(hits);
+ IDDecoder decoder = meta.getIDDecoder();
+ String name = meta.getName();
+ if (hits.size() > 0) {
+ System.out.println();
+ System.out.println(hits.size() + " hits in " + name);
+ } else {
+ return;
+ }
+ int nhits = 0;
for (SimCalorimeterHit hit : hits) {
decoder.setID(hit.getCellID());
Hep3Vector cellPos = decoder.getPositionVector();
+ System.out.printf(" %.5f %.5f %.5f", cellPos.x(), cellPos.y(), cellPos.z());
int ncontribs = hit.getMCParticleCount();
+ System.out.println(" " + ncontribs + " steps");
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.
+ double stepX = stepPos[0];
+ double stepY = stepPos[1];
+ double stepZ = stepPos[2];
+ Hep3Vector stepVec = new BasicHep3Vector(stepX, stepY, stepZ);
+
+ Hep3Vector localPos = VecOp.sub(stepVec, cellPos);
+ double localX = localPos.x();
+ double localY = localPos.y();
+ double localZ = localPos.z();
+
+ double mag = localPos.magnitude();
+
+ System.out.printf(" %.5f %.5f %.5f ; %.5f %.5f %.5f ; %.5f%n", stepX, stepY, stepZ, localX, localY, localZ, mag);
}
+ ++nhits;
}
+ System.out.println();
}
- }
-}
+ }
+}
\ No newline at end of file