Commit in lcsim-contrib/src/main/java/org/lcsim/contrib/onoprien/crux on MAIN
diagnostics/ClusteringTest.java+3-31.3 -> 1.4
infrastructure/ICluster.java+13added 1.1
              /CatSeed.java+96-121.1 -> 1.2
              /CruxCluster.java+3-31.1.1.1 -> 1.2
              /ITrack.java+2-21.2 -> 1.3
mctruth/MCTruthCrux.java+161-671.2 -> 1.3
+278-87
1 added + 5 modified, total 6 files
Generalized seed class and related changes in MCTruth

lcsim-contrib/src/main/java/org/lcsim/contrib/onoprien/crux/diagnostics
ClusteringTest.java 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- ClusteringTest.java	9 Feb 2009 03:57:38 -0000	1.3
+++ ClusteringTest.java	11 Feb 2009 23:31:40 -0000	1.4
@@ -26,7 +26,7 @@
  *
  *
  * @author D. Onoprienko
- * @version $Id: ClusteringTest.java,v 1.3 2009/02/09 03:57:38 onoprien Exp $
+ * @version $Id: ClusteringTest.java,v 1.4 2009/02/11 23:31:40 onoprien Exp $
  */
 public class ClusteringTest extends Driver implements JobEventListener {
   
@@ -170,7 +170,7 @@
     MCTruthCrux mcTruth = (MCTruthCrux) _event.get(MCTruthCrux.KEY);
     
     for (CruxCluster cluster : _inClusterList) {
-      List<MCParticle> mcList = mcTruth.getMCParticles(cluster);
+      List<MCParticle> mcList = mcTruth.getMCParticles(MCTruthCrux.Rec.CLUSTER, cluster);
       CalModule module = cluster.getModule();
       String name = (module == null) ? "Multiple modules" : module.getName();
       _aida.cloud1D("MCParticles per cluster").fill(mcList.size());
@@ -179,7 +179,7 @@
     
     // Cluster multiplicity:
     
-    WeightedTable<MCParticle, Cluster> mcToClusterMap = mcTruth.<Cluster>getMCParticleMap(MCTruthCrux.Rec.CLUSTER, _inClusterList);
+    WeightedTable<MCParticle, Cluster> mcToClusterMap = mcTruth.<Cluster>getMCParticleTable(MCTruthCrux.Rec.CLUSTER, _inClusterList);
     for (MCParticle mc : mcToClusterMap.fromSet()) {
       int nClusters = mcToClusterMap.allFrom(mc).size();
       _aida.cloud1D("Clusters per MCParticle").fill(nClusters);

lcsim-contrib/src/main/java/org/lcsim/contrib/onoprien/crux/infrastructure
ICluster.java added at 1.1
diff -N ICluster.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ICluster.java	11 Feb 2009 23:31:40 -0000	1.1
@@ -0,0 +1,13 @@
+package org.lcsim.contrib.onoprien.crux.infrastructure;
+
+import org.lcsim.event.Cluster;
+
+/**
+ * Calorimeter cluster.
+ *
+ * @author onoprien
+ * @version $Id: ICluster.java,v 1.1 2009/02/11 23:31:40 onoprien Exp $
+ */
+public interface ICluster extends Cluster {
+
+}

lcsim-contrib/src/main/java/org/lcsim/contrib/onoprien/crux/infrastructure
CatSeed.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- CatSeed.java	9 Feb 2009 04:15:24 -0000	1.1
+++ CatSeed.java	11 Feb 2009 23:31:40 -0000	1.2
@@ -2,37 +2,121 @@
 
 import java.util.*;
 
+import hep.physics.vec.Hep3Vector;
 import org.lcsim.event.CalorimeterHit;
-import org.lcsim.event.MCParticle;
+import org.lcsim.event.Cluster;
+
+import org.lcsim.contrib.onoprien.util.job.JobManager;
+import org.lcsim.contrib.onoprien.util.swim.BField;
+import org.lcsim.contrib.onoprien.util.swim.ParCovMatrix;
+import org.lcsim.contrib.onoprien.util.swim.Helix;
 
 /**
  * Stub to prevent build from failing.
  *
  * @author D. Onoprienko
- * @version $Id: CatSeed.java,v 1.1 2009/02/09 04:15:24 onoprien Exp $
+ * @version $Id: CatSeed.java,v 1.2 2009/02/11 23:31:40 onoprien Exp $
  */
-public class CatSeed {
+public class CatSeed implements ICluster {
 
 // -- Private parts :  ---------------------------------------------------------
 
-  ArrayList<MCParticle> _mcList = new ArrayList<MCParticle>(1);
+  private Helix _helix;
+  private ICluster _mipStub;
+  private ArrayList<ICluster> _clusters;
+
+  private BField _bField;
   
 // -- Constructors :  ----------------------------------------------------------
   
   public CatSeed() {
+    _bField = JobManager.defaultInstance().get(BField.class);
   }
 
-// -- Getters :  ---------------------------------------------------------------
-
-  /**
-   * Returns a list of <tt>MCParticles</tt> that contributed to this seed.
-   */
-  public ArrayList<MCParticle> getMCParticles() {
-    return _mcList;
+  public CatSeed(Helix helix, ICluster mipStub, List<? extends ICluster> clusters) {
+    this();
+    _helix = helix;
+    _mipStub = mipStub;
+    _clusters = new ArrayList<ICluster>(clusters);
   }
 
+
+// -- Implementing ICluster :  -------------------------------------------------
+
   public List<CalorimeterHit> getCalorimeterHits() {
-    return null;
+    LinkedHashSet<CalorimeterHit> hitSet = new LinkedHashSet<CalorimeterHit>();
+    for (ICluster cluster : _clusters) {
+      hitSet.addAll(cluster.getCalorimeterHits());
+    }
+    return new ArrayList<CalorimeterHit>(hitSet);
+  }
+
+  public int getType() {
+    return 0;
+  }
+
+  public double getEnergy() {
+    return _bField.getP(_helix);
+  }
+
+  public double[] getPosition() {
+    return _helix.getPosition().v();
+  }
+
+  public double[] getPositionError() {
+    ParCovMatrix<Helix.VRep> cov = _helix.getCovMatrix(Helix.VRep.class);
+    return new double[] {Math.sqrt(cov.get(Helix.VRep.X)), Math.sqrt(cov.get(Helix.VRep.Y)), Math.sqrt(cov.get(Helix.VRep.Z))};
+  }
+
+  public double getITheta() {
+    return Math.acos(_helix.getDirection().z());
+  }
+
+  public double getIPhi() {
+    Hep3Vector dir = _helix.getDirection();
+    return Math.atan2(dir.y(), dir.x());
+  }
+
+  public int getSize() {
+    return getCalorimeterHits().size();
+  }
+
+  public double[] getDirectionError() {
+    ParCovMatrix<Helix.VRep> cov = _helix.getCovMatrix(Helix.VRep.class);
+    return new double[] {Math.sqrt(cov.get(Helix.VRep.DX)), Math.sqrt(cov.get(Helix.VRep.DY)), Math.sqrt(cov.get(Helix.VRep.DZ))};
+  }
+
+  public double[] getShape() {
+    throw new UnsupportedOperationException();
+  }
+
+  public List<Cluster> getClusters() {
+    return Collections.<Cluster>unmodifiableList(_clusters);
+  }
+
+  @Deprecated
+  public double[] getHitContributions() {
+    List<CalorimeterHit> hitList = getCalorimeterHits();
+    double[] out = new double[hitList.size()];
+    int i=0;
+    for (CalorimeterHit hit : hitList) {
+      out[i++] = hit.getCorrectedEnergy();
+    }
+    return out;
+  }
+
+  public double[] getSubdetectorEnergies() {
+    throw new UnsupportedOperationException();
+  }
+
+// -- Additional getters :  ----------------------------------------------------
+
+  /**
+   * Returns cluster of calorimeter hits that belong to the MIP-like portion of this <tt>CatSeed</tt>.
+   * Hits are ordered in increasing layer number.
+   */
+  public ICluster getMipStup() {
+    return _mipStub;
   }
   
 }

lcsim-contrib/src/main/java/org/lcsim/contrib/onoprien/crux/infrastructure
CruxCluster.java 1.1.1.1 -> 1.2
diff -u -r1.1.1.1 -r1.2
--- CruxCluster.java	10 Dec 2008 22:03:06 -0000	1.1.1.1
+++ CruxCluster.java	11 Feb 2009 23:31:40 -0000	1.2
@@ -12,12 +12,12 @@
 import org.lcsim.geometry.Subdetector;
 
 /**
- * Class representing a cluster of calorimeter hits.
+ * Crux package specific implementation of {@link ICluster}.
  *
  * @author D. Onoprienko
- * @version $Id: CruxCluster.java,v 1.1.1.1 2008/12/10 22:03:06 jeremy Exp $
+ * @version $Id: CruxCluster.java,v 1.2 2009/02/11 23:31:40 onoprien Exp $
  */
-public class CruxCluster implements Cluster {
+public class CruxCluster implements ICluster {
   
 // -- Constructors :  ----------------------------------------------------------
   

lcsim-contrib/src/main/java/org/lcsim/contrib/onoprien/crux/infrastructure
ITrack.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- ITrack.java	22 Jan 2009 21:01:56 -0000	1.2
+++ ITrack.java	11 Feb 2009 23:31:40 -0000	1.3
@@ -9,10 +9,10 @@
 import org.lcsim.contrib.onoprien.vsegment.hit.ITrackerHit;
 
 /**
- * Generic interface to be implemented by classes that represent found tracks.
+ * Reconstructed track.
  *
  * @author D. Onoprienko
- * @version $Id: ITrack.java,v 1.2 2009/01/22 21:01:56 onoprien Exp $
+ * @version $Id: ITrack.java,v 1.3 2009/02/11 23:31:40 onoprien Exp $
  */
 public interface ITrack {
   

lcsim-contrib/src/main/java/org/lcsim/contrib/onoprien/crux/mctruth
MCTruthCrux.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- MCTruthCrux.java	9 Feb 2009 03:57:38 -0000	1.2
+++ MCTruthCrux.java	11 Feb 2009 23:31:40 -0000	1.3
@@ -1,6 +1,7 @@
 package org.lcsim.contrib.onoprien.crux.mctruth;
 
 import java.util.*;
+import java.util.logging.Level;
 
 import org.lcsim.event.CalorimeterHit;
 import org.lcsim.event.Cluster;
@@ -19,23 +20,48 @@
 
 /**
  * Provides access to Monte Carlo truth information for reconstructed
- * objects created with crux package.
+ * objects created with crux package. Relations between <tt>MCParticles</tt> and
+ * reconstructed objects are weighted - See {@link Rec} for a description of how
+ * weights are calculated for each type of reconstructed object.
  *
  * @author D. Onoprienko
- * @version $Id: MCTruthCrux.java,v 1.2 2009/02/09 03:57:38 onoprien Exp $
+ * @version $Id: MCTruthCrux.java,v 1.3 2009/02/11 23:31:40 onoprien Exp $
  */
 public class MCTruthCrux {
   
   /** Name under which this object is saved in the event record: "MCTruthCrux". */
   static public final String KEY = "MCTruthCrux";
 
+  /**
+   * Enumeration of types of reconstructed objects for which Monte Carlo truth information
+   * can be accessed through a {@link MCTruthCrux} object.
+   */
   public enum Rec {
+    /**
+     * Reconstructed track. The <tt>MCParticle</tt> weight is equal to the number of hits
+     * on the track to which that <tt>MCParticle</tt> has contributed.
+     */
     TRACK(ITrack.class),
+    /**
+     * Calorimeter hit. The <tt>MCParticle</tt> weight is equal to the energy
+     * contributed by that <tt>MCParticle</tt>.
+     */
     CAL_HIT(CalorimeterHit.class),
+    /**
+     * Calorimeter cluster. The <tt>MCParticle</tt> weight is equal to the energy
+     * contributed by that <tt>MCParticle</tt>.
+     */
     CLUSTER(Cluster.class),
+    /**
+     * Calorimeter assisted tracking seed. The <tt>MCParticle</tt> weight is equal to the
+     * energy contributed by the <tt>MCParticle</tt> to the MIP stub portion of the seed cluster.
+     */
     CAT_SEED(CatSeed.class);
+
     Class _type;
     Rec(Class type) {_type = type;}
+
+    /** Returns a common superclass of reconstructed objects of this type. */
     public Class type() {return _type;}
   }
 
@@ -51,56 +77,93 @@
   
 // -- Constructors :  ----------------------------------------------------------
   
-  public MCTruthCrux(MCTruthDriverCrux driver, EventHeader event) {
+  MCTruthCrux(MCTruthDriverCrux driver, EventHeader event) {
     _driver = driver;
     _event = event;
-    try {
-      _mcTruthVS = (MCTruthVS) event.get(MCTruthVS.KEY);
-    } catch (IllegalArgumentException x) {}
   }
 
 
 // -- Set default maps :  ------------------------------------------------------
 
-  public <T> void setMCParticleMap(Rec type, WeightedTable<MCParticle,T> map) {
+  /**
+   * Sets the default relational table between <tt>MCParticles</tt> and reconstructed objects of the specified type.
+   * Subsequent calls to
+   * {@link #getMCParticleTable(Rec, Collection) getMCParticleTable(type)},
+   * {@link #get(Rec, MCParticle) get(type, mcParticle)},
+   * {@link #getMCParticles(Rec, Object) getMCParticles(type, reconstructedObject)}, and
+   * {@link #getMCParticles(Object) getMCParticles(reconstructedObject)}
+   * will use this map. If the map is set to <tt>null</tt>, the next call to one of these
+   * methods will re-create the map by calling <tt>getMCParticleTable(type)</tt>, and set it as a default.
+   */
+  public <T> void setMCParticleTable(Rec type, WeightedTable<MCParticle,T> map) {
     _defMaps.put(type, map);
   }
 
 
 // -- Names of collections of reco objects to RelationalTable methods :  -------
 
-  public <T> WeightedTable<MCParticle,T> getMCParticleMap(Rec type, String... collectionNames) {
-    List<Collection<T>> colList;
-    if (collectionNames.length == 0) {
-      colList = _event.get(type.type());
-    } else {
+  /**
+   * Returns a relational table between <tt>MCParticles</tt> and reconstructed objects of the
+   * requested type from the specified collections in the event record. If no collection names
+   * are specified, the default names set through the {@link MCTruthDriverCrux#set(String, Object...)}
+   * method are used, and the created table is set as the default. If the default names have not been
+   * set, all lists with compatible element types are used
+   * (as returned by {@link EventHeader#get(Class) EventHeader.get(type.type())}.
+   */
+  public <T> WeightedTable<MCParticle,T> getMCParticleTable(Rec type, String... collectionNames) {
+
+    WeightedTable<MCParticle,T> out = null;
+    boolean needToSet = false;
+    List<Collection<T>> colList = null;
+
+    if (collectionNames.length == 0) {                   // called with no names
+      out = _defMaps.get(type);
+      if (out == null) {
+        collectionNames = _driver._defaultNames.get(type);
+        if (collectionNames == null || collectionNames.length == 0) {
+          colList = _event.get(type.type());
+        } else {
+          out = getMCParticleTable(type, collectionNames);
+        }
+        needToSet = true;
+      }
+    } else {                                                // called with names
       colList = new ArrayList<Collection<T>>();
       for (String name : collectionNames) {
         try {
           colList.add((Collection<T>) (_event.get(name)));
-        } catch (IllegalArgumentException x) {
-        }
+        } catch (IllegalArgumentException x) {}
       }
     }
-    if (colList.size() == 1) {
-      return getMCParticleMap(type, colList.get(0));
-    } else {
-      ArrayList<T> lst = new ArrayList<T>(100);
-      for (Collection<T> col : colList) {
-        lst.addAll(col);
+
+    if (out == null) {
+      if (colList.size() == 1) {
+        out = getMCParticleTable(type, colList.get(0));
+      } else {
+        ArrayList<T> lst = new ArrayList<T>(100);
+        for (Collection<T> col : colList) {
+          lst.addAll(col);
+        }
+        out = getMCParticleTable(type, lst);
       }
-      return getMCParticleMap(type, lst);
     }
+
+    if (needToSet) setMCParticleTable(type, out);
+    return out;
   }
 
 
 // -- Collection of reco objects to RelationalTable methods :  -----------------
 
-  public <T> WeightedTable<MCParticle,T> getMCParticleMap(Rec type, Collection<? extends T> collection) {
+  /**
+   * Returns a relational table between <tt>MCParticles</tt> and reconstructed objects of the
+   * requested type from the specified collection.
+   */
+  public <T> WeightedTable<MCParticle,T> getMCParticleTable(Rec type, Collection<? extends T> collection) {
     WeightedTable<MCParticle,T> table = new WeightedTable<MCParticle,T>();
     LinkedHashSet<T> set = new LinkedHashSet<T>(collection);
     for (T e : set) {
-      WeightedList<MCParticle> mcList = findMCParticles(e);
+      WeightedList<MCParticle> mcList = findMCParticles(type, e);
       for (int i=0; i<mcList.size(); i++) {
         table.add(mcList.get(i), e, mcList.getWeight(i));
       }
@@ -111,71 +174,84 @@
 
 // -- MCParticle to Reco Objects methods :  ------------------------------------
 
+  /**
+   * Returns a weighted list of reconstructed objects of the specified type to which the specified
+   * <tt>MCParticle</tt> has contributed. The method uses default relational table,
+   * creating it if it does not already exist.
+   */
   public <T> WeightedList<T> get(Rec type, MCParticle mcParticle) {
     WeightedTable<MCParticle,T> map = _defMaps.get(type);
-    if (map == null) {
-      String[] names = _driver._defaultNames.get(type);
-      if (names == null) {
-        List<List<T>> colList = _event.get(type.type());
-        ArrayList<T> col = new ArrayList<T>(100);
-        for (List<T> lst : colList) col.addAll(lst);
-        map = getMCParticleMap(type, col);
-      } else {
-        map = getMCParticleMap(type, names);
-      }
-      _defMaps.put(type, map);
-    }
+    if (map == null) map = getMCParticleTable(type);
     return map.listFrom(mcParticle);
   }
 
 
 // -- Reco object to MCParticles methods (lookup in tables) :  -----------------
 
-  public WeightedList<MCParticle> getMCParticles(Object reconstructedObject) {
-    Rec type;
-    if (reconstructedObject instanceof ITrack) {
-      type = Rec.TRACK;
-    } else if (reconstructedObject instanceof CalorimeterHit) {
-      type = Rec.CAL_HIT;
-    } else if (reconstructedObject instanceof Cluster) {
-      type = Rec.CLUSTER;
-    } else if (reconstructedObject instanceof CatSeed) {
-      type = Rec.CAT_SEED;
-    } else {
-      throw new IllegalArgumentException("No idea how to find MCParticles for "+ reconstructedObject.getClass());
-    }
-    return getMCParticles(type, reconstructedObject);
-  }
-
+//  public WeightedList<MCParticle> getMCParticles(Object reconstructedObject) {
+//    Rec type;
+//    if (reconstructedObject instanceof ITrack) {
+//      type = Rec.TRACK;
+//    } else if (reconstructedObject instanceof CalorimeterHit) {
+//      type = Rec.CAL_HIT;
+//    } else if (reconstructedObject instanceof Cluster) {
+//      type = Rec.CLUSTER;
+//    } else if (reconstructedObject instanceof CatSeed) {
+//      type = Rec.CAT_SEED;
+//    } else {
+//      throw new IllegalArgumentException("No idea how to find MCParticles for "+ reconstructedObject.getClass());
+//    }
+//    return getMCParticles(type, reconstructedObject);
+//  }
+
+  /**
+   * Returns a weighted list of <tt>MCParticles</tt> that contributed to the specified
+   * reconstructed object. The method uses default relational table,
+   * creating it if it does not already exist.
+   */
   public WeightedList<MCParticle> getMCParticles(Rec type, Object reconstructedObject) {
     WeightedTable map = _defMaps.get(type);
-    if (map == null) {
-      map = getMCParticleMap(type);
-      setMCParticleMap(type, map);
-    }
+    if (map == null) map = getMCParticleTable(type);
     return map.listTo(reconstructedObject);
   }
 
 
 // -- Reco object to MCParticles methods :  ------------------------------------
 
-  private WeightedList<MCParticle> findMCParticles(Object reconstructedObject) {
-    if (reconstructedObject instanceof ITrack) {
-      return findMCParticles((ITrack)reconstructedObject);
-    } else if (reconstructedObject instanceof CalorimeterHit) {
-      return findMCParticles((CalorimeterHit)reconstructedObject);
-    } else if (reconstructedObject instanceof Cluster) {
-      return findMCParticles((Cluster)reconstructedObject);
-    } else if (reconstructedObject instanceof CatSeed) {
-      return findMCParticles((CatSeed)reconstructedObject);
-    } else {
-      throw new IllegalArgumentException("No idea how to find MCParticles for "+ reconstructedObject.getClass());
+  /**
+   * Compiles and returns a weighted list of <tt>MCParticles</tt> that contributed to the
+   * specified reconstructed object. The method neither uses nor creates the default relational table.
+   * The returned list is in decreasing weight order.
+   * <p>
+   * See {@link Rec} for a description of how weights are calculated for
+   * each type of reconstructed object.
+   */
+  private WeightedList<MCParticle> findMCParticles(Rec type, Object reconstructedObject) {
+    switch (type) {
+      case TRACK : return findMCParticles((ITrack)reconstructedObject);
+      case CAL_HIT : return findMCParticles((CalorimeterHit)reconstructedObject);
+      case CLUSTER : return findMCParticles((Cluster)reconstructedObject);
+      case CAT_SEED : return findMCParticles((CatSeed)reconstructedObject);
+      default: throw new IllegalArgumentException();
     }
   }
 
+  /**
+   * Compiles and returns a weighted list of <tt>MCParticles</tt> that contributed to the
+   * specified track. The method neither uses nor creates the default relational table. The
+   * weight is equal to the number of hits on the track to which the <tt>MCParticle</tt>
+   * has contributed. The returned list is in decreasing weight order.
+   */
   public WeightedList<MCParticle> findMCParticles(ITrack track) {
     List<? extends ITrackerHit> hits = track.getAnchorHits();
     WeightedList<MCParticle> out = new WeightedList<MCParticle>(1);
+    if (_mcTruthVS == null) {
+      try {
+        _mcTruthVS = (MCTruthVS) _event.get(MCTruthVS.KEY);
+      } catch (IllegalArgumentException x) {
+        _driver.log("Failed to fetch MCTruthVS from the event record", Level.SEVERE);
+      }
+    }
     for (ITrackerHit hit : hits) {
       List<MCParticle> mcList = _mcTruthVS.getMCParticles(hit);
       for (MCParticle mc : mcList) {
@@ -186,6 +262,12 @@
     return out;
   }
 
+  /**
+   * Compiles and returns a weighted list of <tt>MCParticles</tt> that contributed to the
+   * specified hit. The method neither uses nor creates the default relational table. The
+   * weight is equal to the energy contributed by the <tt>MCParticle</tt>.
+   * The returned list is in decreasing weight order.
+   */
   public WeightedList<MCParticle> findMCParticles(CalorimeterHit hit) {
     SimCalorimeterHit sHit = (SimCalorimeterHit) hit;
     int n = sHit.getMCParticleCount();
@@ -197,6 +279,12 @@
     return out;
   }
 
+  /**
+   * Compiles and returns a weighted list of <tt>MCParticles</tt> that contributed to the
+   * specified cluster. The method neither uses nor creates the default relational table. The
+   * weight is equal to the energy contributed by the <tt>MCParticle</tt>.
+   * The returned list is in decreasing weight order.
+   */
   public WeightedList<MCParticle> findMCParticles(Cluster cluster) {
     WeightedList<MCParticle> out = new WeightedList<MCParticle>();
     List<CalorimeterHit> hitList = cluster.getCalorimeterHits();
@@ -210,8 +298,14 @@
     return out;
   }
 
+  /**
+   * Compiles and returns a weighted list of <tt>MCParticles</tt> that contributed to the
+   * specified CAT seed. The method neither uses nor creates the default relational table. The
+   * weight is equal to the energy contributed by the <tt>MCParticle</tt> to the MIP stub
+   * portion of the seed cluster. The returned list is in decreasing weight order.
+   */
   public WeightedList<MCParticle> findMCParticles(CatSeed seed) {
-    throw new UnsupportedOperationException();  //FIXME
+    return findMCParticles(seed.getMipStup());
   }
   
 }
CVSspam 0.2.8