Commit in lcsim-contrib/src/main/java/org/lcsim/contrib/onoprien/vsegment/mctruth on MAIN
MCTruthVS.java+83-61.2 -> 1.3
Enable use of arbitrary collections of ITrackerHits in reconstructable particle definition.

lcsim-contrib/src/main/java/org/lcsim/contrib/onoprien/vsegment/mctruth
MCTruthVS.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- MCTruthVS.java	24 Jan 2009 05:11:49 -0000	1.2
+++ MCTruthVS.java	24 Jan 2009 22:38:37 -0000	1.3
@@ -14,9 +14,6 @@
 import org.lcsim.contrib.onoprien.vsegment.hit.ITrackerPulse;
 import org.lcsim.contrib.onoprien.vsegment.hit.ITrackerHit;
 import org.lcsim.contrib.onoprien.util.ListMap;
-import org.lcsim.contrib.onoprien.vsegment.hit.VSRawTrackerData;
-import org.lcsim.contrib.onoprien.vsegment.hit.VSRawTrackerHit;
-import org.lcsim.contrib.onoprien.vsegment.hit.VSTrackerPulse;
 import org.lcsim.contrib.onoprien.vsegment.hit.VSTrackerHit;
 
 /**
@@ -25,7 +22,7 @@
  * be added to the processing chain (usually as the first driver).
  * 
  * @author D. Onoprienko
- * @version $Id: MCTruthVS.java,v 1.2 2009/01/24 05:11:49 onoprien Exp $
+ * @version $Id: MCTruthVS.java,v 1.3 2009/01/24 22:38:37 onoprien Exp $
  */
 public class MCTruthVS {
   
@@ -107,7 +104,35 @@
 // -- Looking up tracking objects by MCParticle :  -----------------------------
 
   /**
-   * Returns a list of tracker clusters to which the specified <tt>MCParticle</tt> has contributed.
+   * Returns a list of <tt>SimTrackerHits</tt> produced by the specified <tt>MCParticle</tt>, sorted by time.
+   */
+  public List<SimTrackerHit> getSimTrackerHits(MCParticle mcParticle) {
+    if (_mc2sth == null) {
+      List<List<SimTrackerHit>> hitLists = _event.get(SimTrackerHit.class);
+      _mc2sth = new HashMap<MCParticle, List<SimTrackerHit>>();
+      for (List<SimTrackerHit> hitList : hitLists) {
+        for (SimTrackerHit hit : hitList) {
+          MCParticle mc = hit.getMCParticle();
+          List<SimTrackerHit> partList = _mc2sth.get(mc);
+          if (partList == null) {
+            partList = new ArrayList<SimTrackerHit>(15);
+            _mc2sth.put(mc, partList);
+          }
+          partList.add(hit);
+        }
+      }
+      for (List<SimTrackerHit> hitList : _mc2sth.values()) {
+        Collections.sort(hitList, _tCompSimTrHit);
+        ((ArrayList<SimTrackerHit>) hitList).trimToSize();
+      }
+    }
+    List<SimTrackerHit> out = _mc2sth.get(mcParticle);
+    return (out == null) ? Collections.<SimTrackerHit>emptyList() : out ;
+  }
+
+  /**
+   * Returns a list of tracker clusters to which the specified <tt>MCParticle</tt> 
+   * has contributed, sorted by time.
    */
   public List<VSTrackerHit> getTrackerClusters(MCParticle mcParticle) {
     if (_mc2tc == null) {
@@ -128,7 +153,42 @@
         }
       }
     }
-    return new ArrayList(_mc2tc.allFrom(mcParticle));
+    ArrayList<VSTrackerHit> out = new ArrayList(_mc2tc.allFrom(mcParticle));
+    Collections.sort(out, _tCompITrHit);
+    return out;
+  }
+
+  /**
+   * Returns a map from MCParticles to lists of hits from the specified collections.
+   * Each MCParticle is mapped to a time-ordered list of hits to which it has contributed.
+   *
+   * @param collectionName  One ore more names of  <tt>ITrackerHit</tt> collections.
+   */
+  public HashMap<MCParticle, List<ITrackerHit>> mapByMCParticle(String... collectionName) {
+    HashMap<MCParticle, HashSet<ITrackerHit>> map = new HashMap<MCParticle, HashSet<ITrackerHit>>();
+    for (String name : collectionName) {
+      try {
+        Collection<ITrackerHit> col = (Collection<ITrackerHit>) _event.get(name);
+        for (ITrackerHit hit : col) {
+          List<MCParticle> mcList = getMCParticles(hit);
+          for (MCParticle mc : mcList) {
+            HashSet<ITrackerHit> hitSet = map.get(mc);
+            if (hitSet == null) {
+              hitSet = new HashSet<ITrackerHit>();
+              map.put(mc, hitSet);
+            }
+            hitSet.add(hit);
+          }
+        }
+      } catch (IllegalArgumentException x) {}
+    }
+    HashMap<MCParticle, List<ITrackerHit>> outMap = new HashMap<MCParticle, List<ITrackerHit>>((int) (map.size()*1.5+1));
+    for (Map.Entry<MCParticle,HashSet<ITrackerHit>> entry : map.entrySet()) {
+      ArrayList<ITrackerHit> out = new ArrayList<ITrackerHit>(entry.getValue());
+      Collections.sort(out, _tCompITrHit);
+      outMap.put(entry.getKey(), out);
+    }
+    return outMap;
   }
 
   
@@ -142,4 +202,21 @@
   private RelationalTable<ITrackerHit, SimTrackerHit> _th2sth;
   
   private RelationalTable<MCParticle, VSTrackerHit> _mc2tc;
+
+  private HashMap<MCParticle, List<SimTrackerHit>> _mc2sth;
+
+// -- Comparators :  -----------------------------------------------------------
+
+  private Comparator<SimTrackerHit> _tCompSimTrHit = new Comparator<SimTrackerHit>() {
+    public int compare(SimTrackerHit hit1, SimTrackerHit hit2) {
+      return Double.compare(hit1.getTime(), hit2.getTime());
+    }
+  };
+
+  private Comparator<ITrackerHit> _tCompITrHit = new Comparator<ITrackerHit>() {
+    public int compare(ITrackerHit hit1, ITrackerHit hit2) {
+      return Double.compare(hit1.getTime(), hit2.getTime());
+    }
+  };
+
 }
CVSspam 0.2.8