Commit in hps-java/src/main/java/org/lcsim/hps/recon/tracking on MAIN
TrackerReconDriver.java+68-631.3 -> 1.4
TrackerDigiDriver.java+106-671.4 -> 1.5
+174-130
2 modified files
code cleanup and some additional comments

hps-java/src/main/java/org/lcsim/hps/recon/tracking
TrackerReconDriver.java 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- TrackerReconDriver.java	19 Jan 2012 01:30:24 -0000	1.3
+++ TrackerReconDriver.java	19 Jan 2012 22:48:34 -0000	1.4
@@ -3,6 +3,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.lcsim.detector.tracker.silicon.SiTrackerModule;
 import org.lcsim.event.EventHeader;
 import org.lcsim.event.Track;
 import org.lcsim.event.TrackerHit;
@@ -20,43 +21,50 @@
  * It is intended to work with the {@link TrackerDigiDriver} digitization Driver.
  * 
  * @author jeremym
- * @version $Id: TrackerReconDriver.java,v 1.3 2012/01/19 01:30:24 jeremy Exp $
+ * @version $Id: TrackerReconDriver.java,v 1.4 2012/01/19 22:48:34 jeremy Exp $
  */
 public final class TrackerReconDriver extends Driver 
 {
 	// Debug flag
 	private final static boolean DEBUG = true;
 	
+	// Tracks found across all events.
+	int ntracks = 0;
+	
+	// Number of events processed.
+	int nevents = 0;
+	
+	// Cache detector object.
+	Detector detector = null;
+	
     // FIXME Hard-coded B-field value.  Get this from the Detector?
     private double bfield = 0.5;
     
     // Name of the SVT subdetector.
     private String subdetectorName = "Tracker";
             
-    // SimTrackerHit input collection.
+    // SimTrackerHit input collection for readout cleanup.
     private String simTrackerHitCollectionName = "TrackerHits";
     
-    // Tracking strategy path. 
+    // Tracking strategies resource path. 
     private String strategyResource = "HPS-Test-1pt3.xml";
         
-    // Seedtracker's output track collection.
+    // Output track collection.
     private String trackCollectionName = "MatchedTracks";
     
-    // Seedtracker's HelicalTrackHit input collection.
+    // HelicalTrackHit input collection.
     private String stInputCollectionName = "RotatedHelicalTrackHits";
     
-    // HelicalTrackHitDriver's output hit collection.
+    // Output hit collection for HelicalTrackHits.
     private String hthOutputCollectionName = "HelicalTrackHits";
     
-    // Name of strip hits collection.
-    // FIXME This currently depends on name of strip clusterer from in another Driver.  
-    //       Can we change to something generic like "SiStripHits" instead?
+    // Input strip hits collection from digi.
     private String stripHitsCollectionName = "StripClusterer_SiTrackerHitStrip1D";
     
-    // Hit relations.
+    // Hit relations output collection.
 	private String helicalTrackHitRelationsCollectionName = "HelicalTrackHitRelations";
 	
-	// Track to MC relations.
+	// Track to MC relations output collection.
 	private String helicalTrackMCRelationsCollectionName = "HelicalTrackMCRelations";
 	
     public TrackerReconDriver()
@@ -126,31 +134,37 @@
      */
     public void detectorChanged(Detector detector)
     {
-        setup();
+    	this.detector = detector;
+    	//System.out.println("detector bfield @ 0,0,0 = " + detector.getFieldMap().getField(new BasicHep3Vector(0,0,0)));
+        initialize();
         super.detectorChanged(detector);        
     }
         
     /** 
      * Setup all the child Drivers necessary for track reconstruction.
      */
-    private void setup()
+    private void initialize()
     {                
+    	//
         // 1) Driver to create HelicalTrackHits expected by Seedtracker.
+    	//
+    	// TODO Make this its own separate Driver??? (Matt)
+        
+        // Setup default stereo pairings which should work for even number of modules.
+    	List<SiTrackerModule> modules = detector.getDetectorElement().findDescendants(SiTrackerModule.class);
+    	if (modules.size() == 0)
+    		throw new RuntimeException("No SiTrackerModules found in detector.");
+    	int nmodules = modules.size();
+    	if (nmodules % 2 != 0)
+    		throw new RuntimeException("Don't know how to do stereo pairing for odd number of modules.");        
+    	List<int[]> pairs = new ArrayList<int[]>();
+        for (int i=1; i<=(nmodules/2)-1; i+=2)
+        {
+        	int[] pair = {i, i+1};
+        	System.out.println("Adding stereo pair: " + pair[0] + ", " + pair[1]);
+        	pairs.add(pair);
+        }
         
-        // Setup adjacent layer pairings.
-    	// TODO Provide a default implementation here that is smart enough to pair adjacent modules by number.
-        List<int[]> pairs = new ArrayList<int[]>();
-        int[] p1 = {1, 2};
-        int[] p2 = {3, 4};
-        int[] p3 = {5, 6};
-        int[] p4 = {7, 8};
-        int[] p5 = {9, 10};
-        pairs.add(p1);
-        pairs.add(p2);
-        pairs.add(p3);
-        pairs.add(p4);
-        pairs.add(p5);
-
         // Create the Driver.
         HPSHelicalTrackHitDriver hthdriver = new HPSHelicalTrackHitDriver();
         hthdriver.addCollection(stripHitsCollectionName);
@@ -161,12 +175,14 @@
         {
             hthdriver.setStereoPair(subdetectorName, pair[0], pair[1]);
         }       
-        hthdriver.setMaxSeperation(10.01);  
-        hthdriver.setTolerance(0.01); 
+        hthdriver.setMaxSeperation(10.01); // user parameter?
+        hthdriver.setTolerance(0.01); // user parameter?        
         hthdriver.setTransformToTracking(true);
         add(hthdriver);
         
-        // 2) Driver to run Seedtracker.
+        //
+        // 2) Driver to run Seed Tracker.
+        //
 
         if (!strategyResource.startsWith("/"))
             strategyResource = "/" + strategyResource; 
@@ -181,9 +197,9 @@
         stFinal.setSectorParams(false);
         add(stFinal);
         
+        //
         // 3) Cleanup the readouts for next event.
-        // TODO Check if this driver is duplicated elsewhere (in digi?).
-        
+        //               
         List<String> readoutCleanup = new ArrayList<String>();
         readoutCleanup.add(this.simTrackerHitCollectionName);
         add(new ReadoutCleanupDriver(readoutCleanup));
@@ -201,49 +217,38 @@
      * This method is used to run the reconstruction and print debug information.
      */
     public void process(EventHeader event)
-    {
-        // This runs the track reconstruction using the sub-Drivers.
+    {    	
+        // This call runs the track reconstruction using the sub-Drivers.
         super.process(event);
-        
-        // Check for digi hits and print debug output.
+                
+        // Debug prints.
         if (DEBUG)
         {
-        	List<TrackerHit> digi = event.get(TrackerHit.class, "TrackerHits");
-        	if (digi.size() == 0)
-        	{
-        		System.out.println("WARNING: The sisim TrackerHit collection is empty!");
-        	}
-        	else
-        	{
-        		System.out.println("The sisim TrackerHit collection has " + digi.size() + " hits.");
-        	}
-
         	// Check for HelicalTrackHits.
         	List<TrackerHit> hth = event.get(TrackerHit.class, hthOutputCollectionName);
-        	if (hth.size() == 0)
-        	{
-        		System.out.println("WARNING: The HelicalTrackHit collection " + hthOutputCollectionName + " is empty!");
-        	}
-        	else
-        	{
-        		System.out.println("The HelicalTrackHit collection " + hthOutputCollectionName + " has " + hth.size() + " hits.");
-        	}       
-
+        	System.out.println("The HelicalTrackHit collection " + hthOutputCollectionName + " has " + hth.size() + " hits.");
+        	       
         	// Check for Tracks.
         	List<Track> tracks = event.get(Track.class, trackCollectionName);        
-        	if (tracks.size() == 0)
-        	{
-        		System.out.println("WARNING: The Track collection " + trackCollectionName + " is empty!");
-        	}
-        	else
-        	{
-        		System.out.println("The Track collection " + trackCollectionName + " has " + tracks.size() + " tracks.");
-        	}        
+        	System.out.println("The Track collection " + trackCollectionName + " has " + tracks.size() + " tracks.");
+        	        
         	// Print out track info.
         	for (Track track : tracks)
         	{
         		System.out.println(track.toString());
         	}
         }
+        
+    	// Increment number of events.
+    	++nevents;
+        
+        // Add to tracks found.
+        ntracks += event.get(Track.class, trackCollectionName).size();
     }   
+    
+    public void endOfData()
+    {
+    	System.out.println("-------------------------------------------");
+    	System.out.println(this.getName() + " found " + ntracks + " tracks in " + nevents + " events which is " + ((double)ntracks/(double)nevents) + " efficiency.");
+    }
 }
\ No newline at end of file

hps-java/src/main/java/org/lcsim/hps/recon/tracking
TrackerDigiDriver.java 1.4 -> 1.5
diff -u -r1.4 -r1.5
--- TrackerDigiDriver.java	19 Jan 2012 01:22:15 -0000	1.4
+++ TrackerDigiDriver.java	19 Jan 2012 22:48:34 -0000	1.5
@@ -10,6 +10,7 @@
 import org.lcsim.detector.tracker.silicon.SiTrackerModule;
 import org.lcsim.event.EventHeader;
 import org.lcsim.event.RawTrackerHit;
+import org.lcsim.event.SimTrackerHit;
 import org.lcsim.geometry.Detector;
 import org.lcsim.recon.tracking.digitization.sisim.BasicReadoutChip;
 import org.lcsim.recon.tracking.digitization.sisim.CDFSiSensorSim;
@@ -23,34 +24,29 @@
 import org.lcsim.util.Driver;
 
 /**
- * This Driver runs the Tracker Digitization, from simulated Test Proposal data,
- * to produce RawTrackerHits and TrackerHits that can then be used by SeedTracker.
+ * This Driver runs the tracker digitization to create raw hits and strip hits from simulated data.
+ * The output can be used by a track reconstruction algorithm like Seed Tracker.
  * 
  * @author jeremym
+ * @version $Id: TrackerDigiDriver.java,v 1.5 2012/01/19 22:48:34 jeremy Exp $
  */
 public class TrackerDigiDriver extends Driver 
 {
-    // Debug switch for development.
+    // Debug switch for development.  
     private static final boolean DEBUG = true; 
-    
-    // Collections required by digi algo.   
-    private List<String> readouts = new ArrayList<String>();
-    private List<String> processPaths = new ArrayList<String>();
-    private List<IDetectorElement> processDEs = new ArrayList<IDetectorElement>();    
-    private Set<SiSensor> processSensors = new HashSet<SiSensor>();
-    private Set<SiTrackerModule> processModules = new HashSet<SiTrackerModule>();
-    
-    // Digi class objects.
-    private SiDigitizer stripDigitizer;
-    private StripHitMaker stripClusterer;
-    private String digitizerName;
-    
-    // Collection name parameter.
+        
+    // Collection name.
     private String readoutCollectionName = "TrackerHits";
     
-    // Subdetector name parameter.
+    // Subdetector name.
     private String subdetectorName = "Tracker";
     
+    // Name of RawTrackerHit output collection.
+    private String rawTrackerHitOutputCollectionName = "RawTrackerHitMaker_RawTrackerHits";
+    
+    // Name of StripHit1D output collection.
+    private String stripHitOutputCollectionName = "StripClusterer_SiTrackerHitStrip1D";
+    
     // Readout parameters.
     private double readoutNoiseIntercept = 270.0;
     private double readoutNoiseSlope = 36.0;
@@ -66,7 +62,7 @@
     private int clusterMaxSize = 10;
     private int clusterCentralStripAveragingThreshold = 4;
     
-    // Clustering error parameters.
+    // Clustering errors by number of TrackerHits.
     private static final double clusterErrorMultiplier = 1.0;
     private double oneClusterErr = clusterErrorMultiplier / Math.sqrt(12.);
     private double twoClusterErr = clusterErrorMultiplier / 5.0;
@@ -74,8 +70,17 @@
     private double fourClusterErr = clusterErrorMultiplier / 2.0;
     private double fiveClusterErr = clusterErrorMultiplier / 1.0;
     
-    // TODO: All parameters with default arguments above should have setters.
-
+    // Various data lists required by digitization.   
+    private List<String> readouts = new ArrayList<String>();
+    private List<String> processPaths = new ArrayList<String>();
+    private List<IDetectorElement> processDEs = new ArrayList<IDetectorElement>();    
+    private Set<SiSensor> processSensors = new HashSet<SiSensor>();
+    private Set<SiTrackerModule> processModules = new HashSet<SiTrackerModule>();
+    
+    // Digi class objects.
+    private SiDigitizer stripDigitizer;
+    private StripHitMaker stripClusterer;
+    
     public void setReadoutCollectionName(String readoutCollectionName)
     {
         this.readoutCollectionName = readoutCollectionName;
@@ -86,6 +91,16 @@
         this.subdetectorName = subdetectorName;
     }
     
+    public void setRawTrackerHitOutputCollectionName(String rawTrackerHitOutputCollectionName)
+    {
+    	this.rawTrackerHitOutputCollectionName = rawTrackerHitOutputCollectionName;
+    }
+    
+    public void setStripHitOutputCollectionName(String stripHitOutputCollectionName)
+    {
+    	this.stripHitOutputCollectionName = stripHitOutputCollectionName;
+    }
+    
     public void setReadoutNoiseIntercept(double readoutNoiseIntercept)
     {
         this.readoutNoiseIntercept = readoutNoiseIntercept;
@@ -162,12 +177,19 @@
     }
     
     /**
-     * Creates a new instance of TrackerHitDriver
+     * Creates a new instance of TrackerHitDriver.
      */
     public TrackerDigiDriver() 
-    {
-        // TODO: Move all of this constructor code to startOfData().
-        
+    {}
+
+    /** 
+     * Initializes this Driver's objects with the job parameters.
+     */
+	private void initialize() 
+	{
+		if (DEBUG)
+			System.out.println(this.getClass() + " - initialize");
+		        
         // Create the sensor simulation.
         CDFSiSensorSim stripSim = new CDFSiSensorSim();
 
@@ -182,7 +204,6 @@
         
         // Create the digitizer that produces the raw hits
         stripDigitizer = new RawTrackerHitMaker(stripSim, stripReadout);
-        digitizerName = stripDigitizer.getName();
 
         // Create Strip clustering algorithm.
         NearestNeighborRMS stripClusteringAlgo = new NearestNeighborRMS(); 
@@ -207,25 +228,55 @@
 
         // Set the detector to process.
         processPaths.add(subdetectorName);
+	}
+	
+	/**
+	 * This is executed before detectorChanged and initialization of digitization objects is done here.
+	 */
+    public void startOfData() 
+    {
+    	if (DEBUG)
+    		System.out.println(this.getClass().getSimpleName() + ".startOfData");
+    	
+    	// At start of job, setup digitization objects needed by this Driver.
+    	initialize();
+    	    	    	
+        // If readouts not already set, set them up.
+        if (readouts.size() != 0) 
+        {
+            System.out.println("Adding SimTrackerHitIdentifierReadoutDriver with readouts: " + readouts);
+            super.add(new SimTrackerHitReadoutDriver(readouts));
+        }
+        super.startOfData();
+        readouts.clear(); // FIXME Is this needed?
     }
 
+    /**
+     * Do initialization once we get a Detector.
+     */
     public void detectorChanged(Detector detector) 
     {
-        System.out.println(detector.getName());
+    	if (DEBUG)
+    		System.out.println(this.getClass().getSimpleName() + ".detectorChanged");
+    	
+    	// Call sub-Driver's detectorChanged methods.
         super.detectorChanged(detector);
-
+        
         // Process detectors specified by path, otherwise process entire detector
         IDetectorElement deDetector = detector.getDetectorElement();
         
-        for (String path : processPaths) {
+        for (String path : processPaths) 
+        {
             processDEs.add(deDetector.findDetectorElement(path));
         }
 
-        if (processDEs.size() == 0) {
+        if (processDEs.size() == 0) 
+        {
             processDEs.add(deDetector);
         }
 
-        for (IDetectorElement detectorElement : processDEs) {
+        for (IDetectorElement detectorElement : processDEs) 
+        {
             processSensors.addAll(detectorElement.findDescendants(SiSensor.class));
             if (DEBUG)
                 System.out.println("added " + processSensors.size() + " sensors");
@@ -235,54 +286,42 @@
         }
     }
 
-    public void startOfData() 
-    {
-        // If readouts not already set, set them up.
-        if (readouts.size() != 0) {
-            System.out.println("Adding SimTrackerHitIdentifierReadoutDriver with readouts: " + readouts);
-            super.add(new SimTrackerHitReadoutDriver(readouts));
-        }
-        super.startOfData();
-        readouts.clear();
-    }
-
+    /**
+     * Perform the digitization.
+     */
     public void process(EventHeader event) 
-    {
+    {    	
+    	// Call sub-Driver processing.
         super.process(event);
 
+        // Make new lists for output.
         List<RawTrackerHit> rawHits = new ArrayList<RawTrackerHit>();                       
         List<SiTrackerHit> stripHits1D = new ArrayList<SiTrackerHit>();
 
-        for (SiSensor sensor : processSensors) {
+        // Make raw hits.
+        for (SiSensor sensor : processSensors) 
+        {
             rawHits.addAll(stripDigitizer.makeHits(sensor));
         }
-        
-        if (DEBUG)
-            System.out.println(this.getClass().getSimpleName() + " got " + rawHits.size() + " raw hits in coll " + getRawHitsName());
-
-        for (SiSensor sensor : processSensors) {
+                 
+        // Make strip hits.
+        for (SiSensor sensor : processSensors) 
+        {
             stripHits1D.addAll(stripClusterer.makeHits(sensor));
         }        
         
-        // DEBUG
+        // Debug prints.
         if (DEBUG)
-            System.out.println(this.getClass().getSimpleName() + " got " + stripHits1D.size() + " strip hits in coll " + getStripHits1DName());
+        {
+    		List<SimTrackerHit> simHits = event.get(SimTrackerHit.class, this.readoutCollectionName);
+    		System.out.println("SimTrackerHit collection " + this.readoutCollectionName + " has " + simHits.size() + " hits.");
+    		System.out.println("RawTrackerHit collection " + this.rawTrackerHitOutputCollectionName + " has " + rawHits.size() + " hits.");
+            System.out.println("TrackerHit collection " + this.stripHitOutputCollectionName + " has " + stripHits1D.size() + " hits.");
+        }
              
-        // Put hits into collection.
+        // Put output hits into collection.
         int flag = 0;        
-        event.put(getRawHitsName(), rawHits, RawTrackerHit.class, flag, toString()); 
-        event.put(getStripHits1DName(), stripHits1D, SiTrackerHitStrip1D.class, 0, toString());
-    }
-
-    // TODO: Make this a user parameter.
-    public String getRawHitsName() 
-    {
-        return digitizerName + "_RawTrackerHits";
-    }
-
-    // TODO: Make this a user parameter.
-    public String getStripHits1DName() 
-    {
-        return stripClusterer.getName() + "_SiTrackerHitStrip1D";
+        event.put(this.rawTrackerHitOutputCollectionName, rawHits, RawTrackerHit.class, flag, toString()); 
+        event.put(this.stripHitOutputCollectionName, stripHits1D, SiTrackerHitStrip1D.class, 0, toString());
     }
-}
+}
\ No newline at end of file
CVSspam 0.2.12


Use REPLY-ALL to reply to list

To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1