lcsim/src/org/lcsim/recon/tracking/seedtracker/example
diff -u -r1.1 -r1.2
--- MCTrackStateDriver.java 18 Mar 2010 20:58:58 -0000 1.1
+++ MCTrackStateDriver.java 19 Mar 2010 22:03:25 -0000 1.2
@@ -1,4 +1,4 @@
-// $Id: MCTrackStateDriver.java,v 1.1 2010/03/18 20:58:58 jeremy Exp $
+// $Id: MCTrackStateDriver.java,v 1.2 2010/03/19 22:03:25 jeremy Exp $
package org.lcsim.recon.tracking.seedtracker.example;
import java.util.ArrayList;
@@ -14,16 +14,26 @@
import org.lcsim.util.Driver;
/**
- * Adds dummy TrackState information to the event for testing slicPandora.
+ * This Driver adds the three TrackState collections expected by slicPandora.
+ * It calculates them from Monte Carlo information in the event associated with
+ * the Tracks found by SeedTracker.
+ *
+ * Since the relationship between the three types of TrackStates and Tracks
+ * is one-to-one, it is not necessary to use LCRelations. The order of the
+ * TrackStates should match that of the Tracks, so the corresponding TrackStates
+ * are accessible via the same index number into the collection.
+ *
* @author jeremym
*/
public class MCTrackStateDriver extends Driver
{
/**
- * Dummy implementation of TrackState for Pandora PFA New input.
+ * Simple implementation of TrackState as an LCIO GenericObject containing 6 floats
+ * corresponding to position (x,y,z) and momentum (px,py,pz).
+ *
* @author jeremym
*/
- class MyTrackState implements GenericObject
+ public static class TrackState implements GenericObject
{
List<Float> vals = new ArrayList<Float>();
@@ -36,7 +46,7 @@
* @param py
* @param pz
*/
- MyTrackState(float x, float y, float z, float px, float py, float pz)
+ public TrackState(float x, float y, float z, float px, float py, float pz)
{
vals.add(x);
vals.add(y);
@@ -55,7 +65,7 @@
* @param py
* @param pz
*/
- MyTrackState(double x, double y, double z, double px, double py, double pz)
+ public TrackState(double x, double y, double z, double px, double py, double pz)
{
vals.add((float)x);
vals.add((float)y);
@@ -103,27 +113,31 @@
public MCTrackStateDriver()
{}
-
+
/**
- * Make collections of GenericObjects containing dummy TrackStates for testing slicPandora.
+ * Creates three TrackState collections for the event's Tracks.
*/
public void process(EventHeader event)
{
+ // Get the Tracks from the event. Collection name is SeedTracker's default.
List<Track> tracks = event.get(Track.class, "Tracks");
- // Setup start lists.
+ // Start TrackState list.
List<GenericObject> startObjs = new ArrayList<GenericObject>();
- // Setup end lists.
+ // End TrackState list.
List<GenericObject> endObjs = new ArrayList<GenericObject>();
- // Setup ECal lists.
+ // ECal TrackState list.
List<GenericObject> ecalObjs = new ArrayList<GenericObject>();
+ // Loop over all the Tracks in the collection.
for (Track track : tracks)
{
// Get hits contributing to this track.
List<TrackerHit> trackerHits = track.getTrackerHits();
+
+ // Find the outermost hit.
double tmax = 0;
SimTrackerHit outermostHit = null;
for (TrackerHit trackerHit : trackerHits)
@@ -131,12 +145,15 @@
//System.out.println(trackerHit.getClass().getName());
//System.out.println("TrackerHit.getTime = " + trackerHit.getTime());
- BaseRawTrackerHit rawHit = (BaseRawTrackerHit)trackerHit.getRawHits().get(0);
+ // Get the first RawTrackerHit from the TrackerHit.
+ BaseRawTrackerHit rawHit = (BaseRawTrackerHit)trackerHit.getRawHits().get(0);
+
+ // Get the first SimTrackerHit from the RawTrackerHit.
SimTrackerHit simHit = rawHit.getSimTrackerHits().get(0);
//System.out.println("simHit.getTime = " + simHit.getTime());
- // Find outtermost hit.
+ // Find the outermost hit by looking for the largest time.
if (simHit.getTime() > tmax)
{
tmax = simHit.getTime();
@@ -145,31 +162,26 @@
}
//System.out.println("tmax = " + tmax);
-
+
+ // Set both the End and ECal TrackStates from the outermost hit on the track.
double[] pos = outermostHit.getPosition();
- double[] momentum = outermostHit.getMomentum();
-
- MyTrackState ecalState = new MyTrackState(pos[0], pos[1], pos[2], momentum[0], momentum[1], momentum[2]);
- ecalObjs.add(ecalState);
-
- MyTrackState endState = new MyTrackState(pos[0], pos[1], pos[2], momentum[0], momentum[1], momentum[2]);
+ double[] momentum = outermostHit.getMomentum();
+ TrackState ecalState = new TrackState(pos[0], pos[1], pos[2], momentum[0], momentum[1], momentum[2]);
+ ecalObjs.add(ecalState);
+ TrackState endState = new TrackState(pos[0], pos[1], pos[2], momentum[0], momentum[1], momentum[2]);
endObjs.add(endState);
+ // Get the start TrackState from the Monte Carlo information.
MCParticle particle = outermostHit.getMCParticle();
double[] ppos = particle.getOrigin().v();
- double[] pmom = particle.getMomentum().v();
-
- MyTrackState startState = new MyTrackState(ppos[0], ppos[1], ppos[2], pmom[0], pmom[1], pmom[2]);
+ double[] pmom = particle.getMomentum().v();
+ TrackState startState = new TrackState(ppos[0], ppos[1], ppos[2], pmom[0], pmom[1], pmom[2]);
startObjs.add(startState);
}
- // Write out start states.
+ // Add the lists to the event.
event.put("StateAtStart", startObjs, GenericObject.class, 0);
-
- // Write out ecal states.
event.put("StateAtECal", ecalObjs, GenericObject.class, 0);
-
- // Write out end states.
event.put("StateAtEnd", endObjs, GenericObject.class, 0);
}
}
\ No newline at end of file