lcsim/sandbox/RobKutschke/TKNHits
diff -N ReadTKNRawHitsDriverV1.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ReadTKNRawHitsDriverV1.java 1 Nov 2007 22:55:19 -0000 1.1
@@ -0,0 +1,167 @@
+
+import org.lcsim.util.aida.AIDA;
+import java.util.List;
+import org.lcsim.util.Driver;
+
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.MCParticle;
+import org.lcsim.event.SimTrackerHit;
+import org.lcsim.event.RawTrackerHit;
+import org.lcsim.event.base.BaseRawTrackerHit;
+
+import org.lcsim.geometry.Detector;
+import org.lcsim.detector.IDetectorElement;
+import org.lcsim.detector.IGeometryInfo;
+import org.lcsim.detector.identifier.IExpandedIdentifier;
+
+import hep.physics.vec.Hep3Vector;
+import hep.physics.vec.BasicHep3Vector;
+
+import org.lcsim.detector.driver.SimTrackerHitIdentifierReadoutDriver;
+import org.lcsim.contrib.RobKutschke.TKNHits.TKNRawHitsDriverV1;
+import org.lcsim.contrib.RobKutschke.TKNHits.TrackerIdentifierIndexCache;
+
+/**
+ *
+ * Driver to illustrate use of the RawTrackerHits created by Tim's code.
+ * In this version, all of the hits are returned as a single unsorted vector
+ * per system.
+ *
+ *@author $Author: kutschke $
+ *@version $Id: ReadTKNRawHitsDriverV1.java,v 1.1 2007/11/01 22:55:19 kutschke Exp $
+ *
+ * Date $Date: 2007/11/01 22:55:19 $
+ *
+ */
+
+
+public class ReadTKNRawHitsDriverV1 extends Driver
+{
+ private AIDA aida = AIDA.defaultInstance();
+
+ // Cache of index values that are expensive to look up.
+ private TrackerIdentifierIndexCache index = null;
+
+ // Names of collections on which to work.
+ // As of 11/01/07 the example only works with the tracker barrel but, in the future
+ // it will work with all Tracker, Vertex Detector and forward tracker hits.
+ private String[] sim = {"SiTrackerBarrel_RO"};
+ private String[] raw = {"RawBarrelTrackerHits"};
+
+ // Printout limit control.
+ private int nprint = 0;
+
+ /**
+ * Constructor:
+ * Add the necessary drivers using super.
+ *
+ */
+ public ReadTKNRawHitsDriverV1(){
+
+ // Attach SimTrackerHits to the detector.
+ super.add( new SimTrackerHitIdentifierReadoutDriver( sim ) );
+
+ // Create Raw Trackerhits and put them in the event.
+ super.add( new TKNRawHitsDriverV1( sim, raw) );
+ }
+
+ /**
+ * Update any geometry related information when the detector changes.
+ *
+ */
+ public void detectorChanged( Detector detector) {
+
+ // Invalidate the cached indices when the detector changes.
+ index = null;
+ }
+
+ /**
+ * This does the main work of the class.
+ *
+ */
+ public void process(EventHeader header)
+ {
+ // Create the list of RawTrackerHits in the event.
+ super.process(header);
+
+ // Get the list of RawTrackerHits from the event.
+ List<RawTrackerHit> rawhits = header.get(RawTrackerHit.class, raw[0] );
+ aida.cloud1D("Number of RawTrackerHits per event").fill(rawhits.size());
+
+ // Make sure cached indices are valid.
+ if ( index == null ){
+ if ( rawhits.size() > 0 ){
+ index = new TrackerIdentifierIndexCache( rawhits.get(0), true );
+ } else{
+ return;
+ }
+ }
+
+ // Header for the tabluar printout.
+ if ( ++nprint == 1 ){
+ System.out.printf ( "Event System Layer Module Sensor Side Strip Time ADC NSim");
+ System.out.printf ( " ( Local Origin )\n");
+ }
+
+ // Loop over the raw hits.
+ for ( RawTrackerHit raw : rawhits ){
+
+ // Need concrete type to access some methods.
+ // At present, this will not survive persistency.
+ BaseRawTrackerHit base = (BaseRawTrackerHit) raw;
+
+ // For hits of this type, the adc array will always be of length 1, exactly.
+ short adc = raw.getADCValues()[0];
+
+ // Position in detector heirarchy.
+ IExpandedIdentifier id = base.getExpandedIdentifier();
+
+ // Information about the wafer on which this hit lives.
+ IDetectorElement de = base.getDetectorElement();
+ IGeometryInfo geom = de.getGeometry();
+
+ // Coordinates of wafer center in global system.
+ Hep3Vector center = geom.getPosition();
+
+ // Links back to the SimTrackerHits that contributed to this hit.
+ // As of 11/01/07 this returns a corrupt list.
+ List<SimTrackerHit> sims = raw.getSimTrackerHit();
+
+ // Coming soon: convert the strip number to a local position.
+
+ // Some printout.
+ if ( nprint < 6 ){
+ System.out.printf ( "%5d %6d %5d %6d %6d %4d %5d %4d %5d %4d (%9.3f %9.3f %9.3f)\n",
+ header.getEventNumber(),
+ id.getValue(index.getSystem()),
+ id.getValue(index.getLayer()),
+ id.getValue(index.getModule()),
+ id.getValue(index.getSensor()),
+ id.getValue(index.getSide()),
+ id.getValue(index.getStrip()),
+ raw.getTime(),
+ adc,
+ sims.size(),
+ center.x(),
+ center.y(),
+ center.z()
+ );
+
+ // Uncomment this block to inspect the corrupted list of SimTrackerHits.
+ /*
+ for ( SimTrackerHit sim : sims ){
+ double[] pos = sim.getPoint();
+ System.out.printf ( "SimTrackerHit: %9.3f %9.3f %9.3f | %20.10f | ",
+ pos[0], pos[1], pos[2], sim.getTime() );
+ System.out.println (sim);
+ }
+ */
+
+ }
+
+ // And some histograms.
+ aida.cloud1D("Raw ADC spectrum").fill(adc);
+
+ }
+ } // process(EventHeader)
+}