Print

Print


Commit in lcsim/src/org/lcsim/contrib/uiowa/template on MAIN
BasicReconstructedParticle.java+94added 1.1
HitMapDriver.java+44added 1.1
PerfectClusterer.java+120added 1.1
PerfectIdentifier.java+72added 1.1
TrivialPFA.java+43added 1.1
+373
5 added files
Very trivial PFA template

lcsim/src/org/lcsim/contrib/uiowa/template
BasicReconstructedParticle.java added at 1.1
diff -N BasicReconstructedParticle.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ BasicReconstructedParticle.java	11 Jan 2006 21:26:50 -0000	1.1
@@ -0,0 +1,94 @@
+// WARNING! Doesn't do anything
+
+package devel;
+
+import hep.physics.vec.*;
+import java.util.*;
+import org.lcsim.event.*;
+
+public class BasicReconstructedParticle implements ReconstructedParticle
+{
+
+  // Interface:
+
+  public int getType() {
+    return m_type;
+  }
+  public Hep3Vector getMomentum() {
+    return m_threeMomentum;
+  }
+  public double getEnergy() {
+    return m_energy;
+  }
+  public double[] getCovMatrix() {
+    return m_covMatrix;
+  }
+  public double getMass() {
+    return m_mass;
+  }
+  public double getCharge() {
+    return m_charge;
+  }
+  public Hep3Vector getReferencePoint() {
+    return m_referencePoint;
+  }
+  public List<ParticleID> getParticleIDs() {
+    return m_PIDList;
+  }
+  public ParticleID getParticleIDUsed() {
+    return m_usedPID;
+  }
+  public double getGoodnessOfPID() {
+    return m_goodnessOfPID;
+  }
+  public List<ReconstructedParticle> getParticles() {
+    return m_particleList;
+  }
+  public List<Cluster> getClusters() {
+    return m_clusterList;
+  }
+  public List<Track> getTracks() {
+    return m_trackList;
+  }
+  public void addParticleID(ParticleID pid) {
+    m_PIDList.add(pid);
+  }
+  public void addParticle(ReconstructedParticle part) {
+    // Propagate effects?
+    m_particleList.add(part);
+  }
+  public void addCluster(Cluster clus) {
+    // Propagage effects?
+    m_clusterList.add(clus);
+  }
+  public void addTrack(Track track) {
+    // Propagate effects?
+    m_trackList.add(track);
+  }
+  public HepLorentzVector asFourVector() {
+    return m_fourMomentum;
+  }
+
+  // New methods:
+
+  public BasicReconstructedParticle() {
+    // empty
+  }
+
+  // Data:
+
+  int m_type;
+  Hep3Vector m_threeMomentum;
+  HepLorentzVector m_fourMomentum;
+  double m_energy;
+  double[] m_covMatrix;
+  double m_mass;
+  double m_charge;
+  Hep3Vector m_referencePoint;
+  List<ParticleID> m_PIDList;
+  ParticleID m_usedPID;
+  double m_goodnessOfPID;
+  List<ReconstructedParticle> m_particleList = new Vector<ReconstructedParticle> ();
+  List<Cluster> m_clusterList = new Vector<Cluster>();
+  List<Track> m_trackList = new Vector<Track>();
+}

lcsim/src/org/lcsim/contrib/uiowa/template
HitMapDriver.java added at 1.1
diff -N HitMapDriver.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ HitMapDriver.java	11 Jan 2006 21:26:50 -0000	1.1
@@ -0,0 +1,44 @@
+package devel;
+
+import java.util.*;
+import org.lcsim.util.*;
+import org.lcsim.event.*;
+
+public class HitMapDriver extends Driver
+{
+  public HitMapDriver()
+  {
+    m_inputLists = new Vector<String>();
+  }
+
+  public void process(EventHeader event)
+  {
+    // Here is the hitmap we'll write out to the event:
+    Map<Long, CalorimeterHit> hitMap = new HashMap<Long, CalorimeterHit> ();
+
+    // Fill the hitmap with each input list in turn:
+    for (String inputName : m_inputLists) {
+      List<CalorimeterHit> inputList = event.get(CalorimeterHit.class, inputName);
+      for (CalorimeterHit hit : inputList) {
+        // Put this hit in the hitmap:
+        Long cellID = hit.getCellID();
+        // Should check return value here:
+        hitMap.put(cellID, hit);
+      }
+    }
+
+    // All hits added; upload the hitmap to the event:
+    event.put(m_outputName, hitMap);
+  }
+
+  public void addInputList(String name) {
+    m_inputLists.add(name);
+  }
+
+  public void setOutput(String name) {
+    m_outputName = name;
+  }
+
+  protected List<String> m_inputLists;
+  protected String m_outputName;
+}

lcsim/src/org/lcsim/contrib/uiowa/template
PerfectClusterer.java added at 1.1
diff -N PerfectClusterer.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ PerfectClusterer.java	11 Jan 2006 21:26:50 -0000	1.1
@@ -0,0 +1,120 @@
+package devel;
+
+import java.util.*;
+
+import org.lcsim.event.EventHeader;
+import org.lcsim.util.Driver;
+import org.lcsim.event.Cluster;
+import org.lcsim.event.MCParticle;
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.event.SimCalorimeterHit;
+import org.lcsim.recon.cluster.util.BasicCluster;
+
+/**
+ * A clusterer with perfect pattern recognition
+ */
+
+public class PerfectClusterer extends Driver
+{
+  public PerfectClusterer() {
+  }
+
+  public void process(EventHeader event) 
+  {
+    List<MCParticle> mcList = event.get(MCParticle.class, m_mcName);
+    Map<Long, CalorimeterHit> inputHitMap = (Map<Long, CalorimeterHit>) (event.get(m_inputHitMapName));
+
+    Map<Long, CalorimeterHit> outputHitMap = new HashMap<Long, CalorimeterHit>(inputHitMap); // initially cloned
+    Collection<CalorimeterHit> hits = inputHitMap.values(); // initially full
+    Map<MCParticle, BasicCluster> particleToClusterMap = new HashMap<MCParticle, BasicCluster>(); // initially empty
+
+    for (CalorimeterHit hit : hits) {
+      // Find the particles that contributed to the hit.
+      // There can be more than one if:
+      //   (1) More than one particle deposits energy in the cell
+      //   (2) The list of MC particles is ambiguous
+      Set<MCParticle> truthParticles = findMCParticles(hit, mcList);
+      for (MCParticle part : truthParticles) {
+        BasicCluster clus = particleToClusterMap.get(part);
+        if (clus == null) {
+          // Haven't yet made a cluster for this particle -- make one now
+          clus = new BasicCluster();
+          particleToClusterMap.put(part, clus);
+        }
+        clus.addHit(hit);
+      }
+    }
+
+    // Finished assembling the clusters. Do book-keeping:
+    //   (1) Build the output list of clusters
+    //   (2) Build the output hitmap
+    Collection<BasicCluster> clusters = particleToClusterMap.values();
+    List<Cluster> outputClusterList = new Vector<Cluster>();
+    for (BasicCluster clus : clusters) {
+      outputClusterList.add(clus);
+      for (CalorimeterHit hit : clus.getCalorimeterHits()) {
+        outputHitMap.remove(hit.getCellID());
+      }
+    }
+
+    // Write out:
+    event.put(m_outputClusterListName, outputClusterList);
+    event.put(m_outputHitMapName, outputHitMap);
+  }
+
+  static protected Set<MCParticle> findMCParticles(CalorimeterHit hit, List<MCParticle> mcList)
+  {
+    if ( ! (hit instanceof SimCalorimeterHit) ) {
+      throw new AssertionError("Non-simulated hit!");
+    } else {
+      SimCalorimeterHit simHit = (SimCalorimeterHit) (hit);
+      Set<MCParticle> contributingParticlesFromList = new HashSet<MCParticle>();
+      int nContributingParticles = simHit.getMCParticleCount();
+      for (int i=0; i<nContributingParticles; i++) {
+        MCParticle part = simHit.getMCParticle(i);
+        List<MCParticle> parentsInList = findParentsInList(part, mcList);
+        contributingParticlesFromList.addAll(parentsInList);
+      }
+      return contributingParticlesFromList;
+    }
+  }      
+
+  static List<MCParticle> findParentsInList(MCParticle part, List<MCParticle> mcList) 
+  {
+    List<MCParticle> outputList = new Vector<MCParticle>();
+    if (mcList.contains(part)) {
+      // Already in there
+      outputList.add(part);
+    } else {
+      // Not in there -- recurse up through parents
+      List<MCParticle> parents = part.getParents();
+      if (parents.size()==0) {
+        // Ran out of options -- add nothing and return below
+      } else {
+        for (MCParticle parent : parents) {
+          List<MCParticle> ancestorsInList = findParentsInList(parent, mcList);
+          outputList.addAll(ancestorsInList);
+        }
+      }
+    }
+    return outputList;
+  }   
+
+  public void setInputHitMap(String name) {
+    m_inputHitMapName = name;
+  }
+  public void setOutputHitMap(String name) {
+    m_outputHitMapName = name;
+  }
+  public void setOutputClusterList(String name) {
+    m_outputClusterListName = name;
+  }
+  public void setMCParticleList(String name) {
+    m_mcName = name;
+  }
+
+  String m_inputHitMapName;
+  String m_outputHitMapName;
+  String m_outputClusterListName;
+  String m_mcName;
+}

lcsim/src/org/lcsim/contrib/uiowa/template
PerfectIdentifier.java added at 1.1
diff -N PerfectIdentifier.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ PerfectIdentifier.java	11 Jan 2006 21:26:51 -0000	1.1
@@ -0,0 +1,72 @@
+package devel;
+
+import java.util.*;
+import org.lcsim.util.*;
+import org.lcsim.event.*;
+
+public class PerfectIdentifier extends Driver
+{
+  public PerfectIdentifier() {
+  }
+
+  public void process(EventHeader event)
+  {
+    List<Cluster> inputClusterList = event.get(Cluster.class, m_inputClusterListName);
+    List<ReconstructedParticle> outputParticleList = new Vector<ReconstructedParticle>();
+    List<MCParticle> mcList = event.get(MCParticle.class, m_mcName);
+
+    for (Cluster clus : inputClusterList) {
+      // Identify
+      MCParticle truthID = findTruthID(clus, mcList);
+      // Add to output list
+      ReconstructedParticle part = new BasicReconstructedParticle();
+      part.addCluster(clus);
+      // [... do more to fix up particle...]
+      outputParticleList.add(part);
+    }
+    event.put(m_outputParticleListName, outputParticleList);
+  }
+
+  MCParticle findTruthID(Cluster clus, List<MCParticle> mcList) {
+    // Find the dominant MC particle in some way.
+    // For now, do something ugly
+    Map<MCParticle, Integer> tmpMap = new HashMap<MCParticle, Integer> ();
+    for (CalorimeterHit hit : clus.getCalorimeterHits()) {
+      Set<MCParticle> particles = PerfectClusterer.findMCParticles(hit, mcList);
+      for (MCParticle part : particles) {
+        Integer oldValue = tmpMap.get(part);
+        if (oldValue==null) {
+          oldValue = new Integer(0);
+        }
+        Integer newValue = new Integer(oldValue + 1);
+        tmpMap.put(part, newValue);
+      }
+    }
+
+    // Which particle contributed the most?
+    int max = 0;
+    MCParticle best = null;
+    for (MCParticle part : tmpMap.keySet()) {
+      int numHits = tmpMap.get(part).intValue();
+      if (numHits > max || best==null) {
+        max = numHits;
+        best = part;
+      }
+    }
+    return best;
+  }
+
+  public void setInputClusterList(String name) {
+    m_inputClusterListName = name;
+  }
+  public void setOutputParticleList(String name) {
+    m_outputParticleListName = name;
+  }
+  public void setMCParticleList(String name) {
+    m_mcName = name;
+  }
+
+  String m_inputClusterListName;
+  String m_outputParticleListName;
+  String m_mcName;
+}

lcsim/src/org/lcsim/contrib/uiowa/template
TrivialPFA.java added at 1.1
diff -N TrivialPFA.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ TrivialPFA.java	11 Jan 2006 21:26:51 -0000	1.1
@@ -0,0 +1,43 @@
+package devel;
+
+import org.lcsim.util.*;
+import org.lcsim.event.*;
+import org.lcsim.event.util.*;
+
+public class TrivialPFA extends Driver
+{
+  public TrivialPFA()
+  {
+    // You might run digisim here
+    // [digisim]
+
+    // Set up the hitmaps.
+    HitMapDriver hitmaps = new HitMapDriver();
+    hitmaps.addInputList("EcalBarrHits");
+    hitmaps.addInputList("EcalEndcapHits");
+    hitmaps.addInputList("HcalBarrHits");
+    hitmaps.addInputList("HcalEndcapHits");
+    hitmaps.setOutput("hits");
+    add(hitmaps);
+    
+    // Set up the MC list
+    CreateFinalStateMCParticleList mcListMaker = new CreateFinalStateMCParticleList("Gen");
+    add(mcListMaker);
+
+    // Cluster the hits (perfect pattern recognition)
+    PerfectClusterer clusterer = new PerfectClusterer();
+    clusterer.setInputHitMap("hits");
+    clusterer.setOutputHitMap("leftover hits");
+    clusterer.setOutputClusterList("perfect clusters");
+    clusterer.setMCParticleList("GenFinalStateParticles");
+    add(clusterer);
+
+    // ID the clusters and create reconstructed particles
+    PerfectIdentifier id = new PerfectIdentifier();
+    id.setInputClusterList("perfect clusters");
+    id.setOutputParticleList("perfect particles");
+    id.setMCParticleList("GenFinalStateParticles");
+    add(id);
+
+  }
+}
CVSspam 0.2.8