Commit in lcsim/src/org/lcsim/contrib/onoprien/tracking on MAIN
clustering/ClusteringDriver.java+10-31.6 -> 1.7
mctruth/MCTruth.java+97-21.2 -> 1.3
       /MCTruthDriver.java+2-21.2 -> 1.3
       /SimGroup.java+22-31.2 -> 1.3
tests/HitMakingTest.java+3-21.2 -> 1.3
+134-12
5 modified files


lcsim/src/org/lcsim/contrib/onoprien/tracking/clustering
ClusteringDriver.java 1.6 -> 1.7
diff -u -r1.6 -r1.7
--- ClusteringDriver.java	1 Oct 2007 20:36:25 -0000	1.6
+++ ClusteringDriver.java	19 Oct 2007 19:27:13 -0000	1.7
@@ -11,6 +11,7 @@
 import org.lcsim.contrib.onoprien.tracking.hit.DigiTrackerHit;
 import org.lcsim.contrib.onoprien.tracking.hit.TrackerCluster;
 import org.lcsim.contrib.onoprien.tracking.hit.base.TrackerClusterBasic;
+import org.lcsim.contrib.onoprien.tracking.mctruth.MCTruth;
 
 /**
  * Driver that handles clustering of {@link DigiTrackerHit} objects.
@@ -18,7 +19,7 @@
  * creates a map of clusters. 
  *
  * @author D.Onoprienko
- * @version $Id: ClusteringDriver.java,v 1.6 2007/10/01 20:36:25 onoprien Exp $
+ * @version $Id: ClusteringDriver.java,v 1.7 2007/10/19 19:27:13 onoprien Exp $
  */
 public class ClusteringDriver extends Driver {
 
@@ -67,7 +68,7 @@
 //    System.out.println("Starting clustering");
     
     super.process(event);
-    
+        
     HashMap<Sensor, ArrayList<DigiTrackerHit>> inMap = (HashMap<Sensor, ArrayList<DigiTrackerHit>>) event.get(_inMapName);
     HashMap<Sensor, ArrayList<TrackerCluster>> outMap = new HashMap<Sensor, ArrayList<TrackerCluster>>();
 
@@ -75,7 +76,13 @@
       ArrayList<TrackerCluster> clusterList = _clusterer.findClusters(sensor, inMap.get(sensor));
       if ( ! clusterList.isEmpty()) outMap.put(sensor, clusterList);
     }
-
+    
+    MCTruth mcTruth = null;
+    try {
+      mcTruth = (MCTruth) event.get("MCTruth");
+    } catch (IllegalArgumentException x) {}
+    if (mcTruth != null) mcTruth.setTrackerClusters(outMap);
+    
     event.put(_outMapName, outMap);
   }
 

lcsim/src/org/lcsim/contrib/onoprien/tracking/mctruth
MCTruth.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- MCTruth.java	9 Oct 2007 22:56:15 -0000	1.2
+++ MCTruth.java	19 Oct 2007 19:27:13 -0000	1.3
@@ -2,9 +2,11 @@
 
 import java.util.*;
 
+import org.lcsim.event.EventHeader;
 import org.lcsim.event.MCParticle;
 import org.lcsim.event.SimTrackerHit;
 
+import org.lcsim.contrib.onoprien.tracking.geom.Sensor;
 import org.lcsim.contrib.onoprien.tracking.hit.DigiTrackerHit;
 import org.lcsim.contrib.onoprien.tracking.hit.TrackerCluster;
 import org.lcsim.contrib.onoprien.tracking.hit.TrackerHit;
@@ -16,14 +18,15 @@
  * be added to the processing chain (usually as the first driver).
  *
  * @author D. Onoprienko
- * @version $Id: MCTruth.java,v 1.2 2007/10/09 22:56:15 onoprien Exp $
+ * @version $Id: MCTruth.java,v 1.3 2007/10/19 19:27:13 onoprien Exp $
  */
 public class MCTruth {
   
 // -- Constructors :  ----------------------------------------------------------
   
-  MCTruth(MCTruthDriver mcTruthDriver) {
+  MCTruth(MCTruthDriver mcTruthDriver, EventHeader event) {
     _mcDriver = mcTruthDriver;
+    _event = event;
     _digiToSimGroup = new HashMap<DigiTrackerHit, SimGroup>();
     _missedSimGroups = new ArrayList<SimGroup>();
   }
@@ -161,6 +164,75 @@
     }
   }
   
+// -- Looking up tracking objects by MCParticle :  -----------------------------
+
+  /**
+   * Returns a list of <tt>SimGroups</tt> associated with the given MCParticle, sorted by time.
+   * The list returned by this method belongs to this <tt>MCTruth</tt> object,
+   * clients should not modify it.
+   */
+  public List<SimGroup> getSimGroups(MCParticle mcParticle) {
+    if (_mcToSimGroupList == null) {
+      _mcToSimGroupList = new HashMap<MCParticle, ArrayList<SimGroup>>();
+      for (SimGroup group : _digiToSimGroup.values()) {
+        MCParticle mc = group.getMCParticle();
+        ArrayList<SimGroup> groupList = _mcToSimGroupList.get(mc);
+        if (groupList == null) {
+          groupList = new ArrayList<SimGroup>();
+          _mcToSimGroupList.put(mc, groupList);
+        }
+        groupList.add(group);
+      }
+      for (SimGroup group : _missedSimGroups) {
+        MCParticle mc = group.getMCParticle();
+        ArrayList<SimGroup> groupList = _mcToSimGroupList.get(mc);
+        if (groupList == null) {
+          groupList = new ArrayList<SimGroup>();
+          _mcToSimGroupList.put(mc, groupList);
+        }
+        groupList.add(group);        
+      }
+      for (ArrayList<SimGroup> groupList : _mcToSimGroupList.values()) {
+        Collections.sort(groupList, _compSimGroup);
+        groupList.trimToSize();
+      }
+    }
+    List<SimGroup> out = _mcToSimGroupList.get(mcParticle);
+    if (out == null) out = Collections.emptyList();
+    return out;
+  }
+  
+  /**
+   * Returns a list of <tt>TrackerClusters</tt> associated with the given MCParticle, sorted by time.
+   * The list returned by this method belongs to this <tt>MCTruth</tt> object,
+   * clients should not modify it.
+   */
+  public List<TrackerCluster> getTrackerClusters(MCParticle mcParticle) {
+    if (_mcToTrackerCluster == null) {
+      _mcToTrackerCluster = new HashMap<MCParticle, ArrayList<TrackerCluster>>();
+      for (List<TrackerCluster> clusterList : _trackingClusters.values()) {
+        for (TrackerCluster cluster : clusterList) {
+          List<MCParticle> mcList = getMCParticles(cluster);
+          for (MCParticle mc : mcList) {
+            ArrayList<TrackerCluster> clusters = _mcToTrackerCluster.get(mc);
+            if (clusters == null) {
+              clusters = new ArrayList<TrackerCluster>();
+              _mcToTrackerCluster.put(mc, clusters);
+            }
+            clusters.add(cluster);
+          }
+        }
+      }
+      for (ArrayList<TrackerCluster> clusters : _trackingClusters.values()) {
+        Collections.sort(clusters, _compTrackerCluster);
+        clusters.trimToSize();        
+      }
+    }
+    List<TrackerCluster> out = _mcToTrackerCluster.get(mcParticle);
+    if (out == null) out = Collections.emptyList();
+    return out;
+  }
+  
 // -- Modifiers :  -------------------------------------------------------------
   
   /**
@@ -178,11 +250,34 @@
     }
   }
   
+  /** 
+   * Called by <tt>ClusteringDriver</tt> to store a reference to the <tt>TrackerCluster</tt> map.
+   */
+  public void setTrackerClusters(HashMap<Sensor, ArrayList<TrackerCluster>> clusters) {
+    _trackingClusters = clusters;
+  }
+  
 // -- Private parts :  ---------------------------------------------------------
   
   private MCTruthDriver _mcDriver;
+  private EventHeader _event;
+  private HashMap<Sensor, ArrayList<TrackerCluster>> _trackingClusters;
 
   private HashMap<DigiTrackerHit, SimGroup> _digiToSimGroup;
   private ArrayList<SimGroup> _missedSimGroups;
   
+  private HashMap<MCParticle, ArrayList<SimGroup>> _mcToSimGroupList;
+  private HashMap<MCParticle, ArrayList<TrackerCluster>> _mcToTrackerCluster;
+  
+  private static Comparator<SimGroup> _compSimGroup = new Comparator<SimGroup>() {
+    public int compare(SimGroup s1, SimGroup s2) {
+      return (int)Math.signum(s1.getTime() - s2.getTime());
+    }
+  };
+  private static Comparator<TrackerCluster> _compTrackerCluster = new Comparator<TrackerCluster>() {
+    public int compare(TrackerCluster s1, TrackerCluster s2) {
+      return (int)Math.signum(s1.getTime() - s2.getTime());
+    }
+  };
+  
 }

lcsim/src/org/lcsim/contrib/onoprien/tracking/mctruth
MCTruthDriver.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- MCTruthDriver.java	9 Oct 2007 22:56:15 -0000	1.2
+++ MCTruthDriver.java	19 Oct 2007 19:27:13 -0000	1.3
@@ -18,7 +18,7 @@
  * and objects created by the simulator, like <tt>MCParticles</tt> and <tt>SimTrackerHits</tt>.
  *
  * @author D. Onoprienko
- * @version $Id: MCTruthDriver.java,v 1.2 2007/10/09 22:56:15 onoprien Exp $
+ * @version $Id: MCTruthDriver.java,v 1.3 2007/10/19 19:27:13 onoprien Exp $
  */
 public class MCTruthDriver extends Driver {
   
@@ -36,7 +36,7 @@
     
     // Create MCTruth object and attach it to the event
     
-    MCTruth mcTruth = new MCTruth(this);
+    MCTruth mcTruth = new MCTruth(this, event);
     event.put("MCTruth", mcTruth);
     
   }

lcsim/src/org/lcsim/contrib/onoprien/tracking/mctruth
SimGroup.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- SimGroup.java	9 Oct 2007 22:56:15 -0000	1.2
+++ SimGroup.java	19 Oct 2007 19:27:13 -0000	1.3
@@ -13,7 +13,7 @@
  * Group of {@link SimTrackerHit} objects created in a single sensor-particle crossing.
  *
  * @author D. Onoprienko
- * @version $Id: SimGroup.java,v 1.2 2007/10/09 22:56:15 onoprien Exp $
+ * @version $Id: SimGroup.java,v 1.3 2007/10/19 19:27:13 onoprien Exp $
  */
 public class SimGroup {
   
@@ -22,8 +22,10 @@
   public SimGroup(Collection<SimTrackerHit> simTrackerHits, Collection<DigiTrackerHit> digiTrackerHits) {
     _simList = new ArrayList<SimTrackerHit>(simTrackerHits.size());
     _simList.addAll(simTrackerHits);
+    Collections.sort(_simList, _compSimHit);
     _digiList = new ArrayList<DigiTrackerHit>(digiTrackerHits.size());
     _digiList.addAll(digiTrackerHits);
+    Collections.sort(_digiList);
   }
   
 // -- Getters :  ---------------------------------------------------------------
@@ -38,9 +40,10 @@
   public Hep3Vector getPosition() {
     double[] pos = {0.,0.,0.};
     double sig = 0.;
+    double totalSig = getSignal();
     for (SimTrackerHit hit : _simList) {
       double[] p = hit.getPoint();
-      double s = (hit.getPathLength() > 0.) ? hit.getPathLength()*hit.getdEdx() : hit.getdEdx();
+      double s = (totalSig > Float.MIN_VALUE) ? hit.getdEdx() : 1.;
       for (int i=0; i<3; i++) pos[i] += p[i]*s;
       sig += s;
     }
@@ -51,11 +54,21 @@
   public double getSignal() {
     double sig = 0.;
     for (SimTrackerHit hit : _simList) {
-      sig += (hit.getPathLength() > 0.) ? hit.getPathLength()*hit.getdEdx() : hit.getdEdx();
+      sig += hit.getdEdx();
     }
     return sig;
   }
   
+  /** Returns average time for <tt>SimTrackerHits</tt> in this group. */
+  public double getTime() {
+    double time = 0.;
+    for (SimTrackerHit hit : _simList) {
+      time += hit.getTime();
+    }
+    time /= _simList.size();
+    return time;
+  }
+  
   /** Returns <tt>MCParticle</tt> that produced <tt>SimTrackerHits</tt> in this group. */
   public MCParticle getMCParticle() {
     return _simList.get(0).getMCParticle();
@@ -71,4 +84,10 @@
   
   ArrayList<SimTrackerHit> _simList;
   ArrayList<DigiTrackerHit> _digiList;
+  
+  static Comparator<SimTrackerHit> _compSimHit = new Comparator<SimTrackerHit>() {
+    public int compare(SimTrackerHit s1, SimTrackerHit s2) {
+      return (int)Math.signum(s1.getTime() - s2.getTime());
+    }
+  };
 }

lcsim/src/org/lcsim/contrib/onoprien/tracking/tests
HitMakingTest.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- HitMakingTest.java	12 Oct 2007 21:52:07 -0000	1.2
+++ HitMakingTest.java	19 Oct 2007 19:27:14 -0000	1.3
@@ -37,7 +37,7 @@
  *
  *
  * @author D. Onoprienko
- * @version $Id: HitMakingTest.java,v 1.2 2007/10/12 21:52:07 onoprien Exp $
+ * @version $Id: HitMakingTest.java,v 1.3 2007/10/19 19:27:14 onoprien Exp $
  */
 public class HitMakingTest extends Driver {
   
@@ -60,7 +60,8 @@
     
     // Digitization :
 
-    SimToDigiConverter converter = new ConverterSimple();
+    ConverterSimple converter = new ConverterSimple();
+    converter.set("SIGNAL", "UNIT");
     SimToDigiDriver conversionDriver = new SimToDigiDriver(converter);
     conversionDriver.set("OUTPUT_MAP_NAME", "DigiTrackerHits");
     add(conversionDriver);
CVSspam 0.2.8