Commit in lcsim/src/org/lcsim/util/hitmap on MAIN
HitMap.java+29added 1.1
HitMapAddDriver.java+59added 1.1
HitMapCloneDriver.java+47added 1.1
HitMapFilter.java+112added 1.1
HitMapFilterDriver.java+57added 1.1
HitMapSubtractDriver.java+69added 1.1
HitMapToClusterListDriver.java+58added 1.1
HitMapToHitListDriver.java+52added 1.1
MapToHitMapDriver.java+48added 1.1
+531
9 added files
Initial commit of HitMap + support classes, for use in the PFA framework

lcsim/src/org/lcsim/util/hitmap
HitMap.java added at 1.1
diff -N HitMap.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ HitMap.java	8 Feb 2006 22:34:12 -0000	1.1
@@ -0,0 +1,29 @@
+package org.lcsim.util.hitmap;
+
+import java.util.Map;
+import java.util.HashMap;
+import org.lcsim.event.CalorimeterHit;
+
+/**
+  * Conventional representation of a collection of CalorimeterHits.
+  * Each entry represents one hit and maps from its CellID
+  * to the hit itself.
+  */
+
+public class HitMap extends HashMap<Long,CalorimeterHit>
+{
+    /** Constructor */
+    public HitMap() {
+	super();
+    }
+
+    /** Copy constructor. The name of the new HitMap is copied from the name of the old HitMap. */
+    public HitMap(HitMap map) {
+	super(map);
+    }
+
+    /** Copy constructor that is backwards-compatible with a generic Map<Long,CalorimeterHit> */
+    public HitMap(Map<Long,CalorimeterHit> map) {
+	super(map);
+    }
+}

lcsim/src/org/lcsim/util/hitmap
HitMapAddDriver.java added at 1.1
diff -N HitMapAddDriver.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ HitMapAddDriver.java	8 Feb 2006 22:34:12 -0000	1.1
@@ -0,0 +1,59 @@
+package org.lcsim.util.hitmap;
+
+import java.util.List;
+import java.util.Vector;
+
+import org.lcsim.event.EventHeader;
+import org.lcsim.util.Driver;
+
+/**
+ * Add a number of named HitMaps together and write the
+ * combined HitMap to the event.
+ */
+
+public class HitMapAddDriver extends Driver
+{
+    /** Simple constructor */
+    public HitMapAddDriver() {
+        super();
+    }
+
+    /**
+      * Constructor with convenience arguments 
+      *
+      * @param inputHitMaps  List of names of input HitMaps in the event
+      * @param outputHitMap  Name to write output HitMap to in the event
+      */
+    public HitMapAddDriver(List<String> inputHitMaps, String outputHitMap) {
+        super();
+        m_inputHitMapNames = new Vector<String> (inputHitMaps);
+        m_outputHitMapName = outputHitMap;
+    }
+
+    /** Process one event, performing conversion. */
+    public void process(EventHeader event) 
+    {
+	HitMap outputHitMap = new HitMap();
+
+	// Read in each input map in turn:
+	for (String name : m_inputHitMapNames) {
+	    HitMap inputHitMap = (HitMap) (event.get(name));
+	    outputHitMap.putAll(inputHitMap);
+	}
+	
+	// Write the output to the event:
+	event.put(m_outputHitMapName, outputHitMap);
+    }
+
+    /** Clear the list of input HitMap names */
+    public void clearInputHitMaps() { m_inputHitMapNames.clear(); }
+
+    /** Add one input HitMap, giving the name under which to read the input HitMap from the event */
+    public void addInputHitMap (String name) { m_inputHitMapNames.add(name); }
+
+    /** Set the name under which to write the output HitMap to the event */
+    public void setOutputHitMap(String name) { m_outputHitMapName= name; }
+
+    protected List<String> m_inputHitMapNames = new Vector<String>();
+    protected String m_outputHitMapName;
+}

lcsim/src/org/lcsim/util/hitmap
HitMapCloneDriver.java added at 1.1
diff -N HitMapCloneDriver.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ HitMapCloneDriver.java	8 Feb 2006 22:34:12 -0000	1.1
@@ -0,0 +1,47 @@
+package org.lcsim.util.hitmap;
+
+import org.lcsim.event.EventHeader;
+import org.lcsim.util.Driver;
+
+/**
+ * Duplicate a named HitMap. This Driver reads in a HitMap
+ * from the event, clones it, then writes the clone out to
+ * the event.
+ */
+
+public class HitMapCloneDriver extends Driver
+{
+    /** Simple constructor */
+    public HitMapCloneDriver() {
+        super();
+    }
+
+    /**
+      * Constructor with convenience arguments 
+      *
+      * @param inputHitMap   Name of input HitMap in the event
+      * @param outputHitMap  Name to write output HitMap to in the event
+      */
+    public HitMapCloneDriver(String inputHitMap, String outputHitMap) {
+        super();
+        m_inputHitMapName = inputHitMap;
+        m_outputHitMapName = outputHitMap;
+    }
+
+    /** Process one event, performing conversion. */
+    public void process(EventHeader event) 
+    {
+	HitMap inputHitMap = (HitMap) (event.get(m_inputHitMapName));
+	HitMap outputHitMap = new HitMap(inputHitMap);
+	event.put(m_outputHitMapName, outputHitMap);
+    }
+
+    /** Set the name under which to read the input HitMap from the event */
+    public void setInputHitMap (String name) { m_inputHitMapName = name; }
+
+    /** Set the name under which to write the output HitMap to the event */
+    public void setOutputHitMap(String name) { m_outputHitMapName= name; }
+
+    protected String m_inputHitMapName;
+    protected String m_outputHitMapName;
+}

lcsim/src/org/lcsim/util/hitmap
HitMapFilter.java added at 1.1
diff -N HitMapFilter.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ HitMapFilter.java	8 Feb 2006 22:34:12 -0000	1.1
@@ -0,0 +1,112 @@
+package org.lcsim.util.hitmap;
+
+import java.util.Set;
+import java.util.Map;
+
+import org.lcsim.event.EventHeader;
+import org.lcsim.util.Driver;
+import org.lcsim.event.Cluster;
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.util.decision.DecisionMakerPair;
+import org.lcsim.util.decision.DecisionMakerSingle;
+
+/**
+ * A filter for HitMaps. Removes or retains hits according to a
+ * user-defined criterion. Examples of use cases: keeping only
+ * hits from the ECAL barrel; keeping only hits with a high local
+ * hit density; removing hits whose energy is below a threshold.
+ *
+ * User-defined decision-makers are supplied in one of three forms:
+ *   (i)   a DecisionMakerSingle<Long> which is applied to each cell id;
+ *   (ii)  a DecisionMakerSingle<CalorimeterHit> which is applied to each hit;
+ *   (iii) a DecisionMakerPair<Long,CalorimeterHit> which is applied to each pairing.
+ * Only one decision-maker is active at a time; setting a new decision-maker
+ * over-writes any previous decision-maker.
+ */
+
+public class HitMapFilter
+{
+    /** Simple constructor */
+    public HitMapFilter() {}
+
+    /** 
+      * Supply a decision-maker which acts on both the CellID and the hit itself
+      * to decide whether to accept or reject a hit. This over-writes any previous
+      * decision-maker.
+      */
+    public void setDecisionOnPair(DecisionMakerPair<Long,CalorimeterHit> decision) { 
+	m_inputDecisionPair = decision;
+	m_inputDecisionLong = null;
+	m_inputDecisionHit = null;
+    }
+
+    /**
+      * Supply a decision-maker which acts on the CellID to decide whether to
+      * accept or reject a hit. This over-writes any previous decision-maker.
+      */
+    public void setDecisionOnID(DecisionMakerSingle<Long> decision) { 
+	m_inputDecisionLong = decision;
+	m_inputDecisionHit = null;
+	m_inputDecisionPair = null;
+    }
+
+    /**
+      * Supply a decision-maker which acts on the hit to decide whether to
+      * accept or reject it. This over-writes any previous decision-maker.
+      */
+    public void setDecisionOnHit(DecisionMakerSingle<CalorimeterHit> decision) { 
+	m_inputDecisionHit = decision;
+	m_inputDecisionLong = null;
+	m_inputDecisionPair = null;
+    }
+
+    /**
+      * Filter the supplied HitMap according to the current decision-maker. 
+      * The original/input HitMap is left unchanged; the return value is
+      * a new, filtered HitMap.
+      */
+    public HitMap filter(HitMap inputHitMap)
+    {
+	// First, verify that we have one and only one decision active.
+	{
+	    int count = 0;
+	    if (m_inputDecisionHit  != null) { count++; }
+	    if (m_inputDecisionLong != null) { count++; }
+	    if (m_inputDecisionPair != null) { count++; }
+	    if (count == 0) {
+		// This can happen if the user hasn't defined a decision
+		// yet (or defined one as null).
+		throw new NullPointerException("Input decision is null");
+	    } else if (count > 1) {
+		// This should never happen
+		throw new AssertionError("Book-keeping error: # decisions defined = "+count+" (should be 1).");
+	    }
+	}
+
+	// Now, apply that decision
+	HitMap outputHitMap = new HitMap();
+	Set<Map.Entry<Long,CalorimeterHit>> entries = inputHitMap.entrySet();
+	for (Map.Entry<Long,CalorimeterHit> pair : entries) {
+	    Long id = pair.getKey();
+	    CalorimeterHit hit = pair.getValue();
+	    boolean passesFilter = false;
+	    if (m_inputDecisionHit != null) {
+		passesFilter = m_inputDecisionHit.valid(hit);
+	    }
+	    if (m_inputDecisionLong != null) {
+		passesFilter = m_inputDecisionLong.valid(id);
+	    }
+	    if (m_inputDecisionPair != null) {
+		passesFilter = m_inputDecisionPair.valid(id,hit);
+	    }
+	    if (passesFilter) {
+		outputHitMap.put(id,hit);
+	    }
+	}
+	return outputHitMap;
+    }
+
+    protected DecisionMakerPair<Long,CalorimeterHit> m_inputDecisionPair = null;
+    protected DecisionMakerSingle<Long> m_inputDecisionLong = null;
+    protected DecisionMakerSingle<CalorimeterHit> m_inputDecisionHit = null;
+}

lcsim/src/org/lcsim/util/hitmap
HitMapFilterDriver.java added at 1.1
diff -N HitMapFilterDriver.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ HitMapFilterDriver.java	8 Feb 2006 22:34:13 -0000	1.1
@@ -0,0 +1,57 @@
+package org.lcsim.util.hitmap;
+
+import org.lcsim.event.EventHeader;
+import org.lcsim.util.Driver;
+import org.lcsim.event.Cluster;
+import org.lcsim.event.CalorimeterHit;
+
+/**
+ * This class is a Driver wrapper around the HitMapFilter class.
+ * It retrieves a named HitMap from the event, filters it
+ * according to the user-defined filter, then writes the filtered
+ * version to the event. The original HitMap is left unchanged
+ * (unless the output identical to the input name).
+ */
+
+public class HitMapFilterDriver extends Driver
+{
+    /** Simple constructor */
+    public HitMapFilterDriver() {
+        super();
+    }
+
+    /**
+      * Constructor with convenience arguments 
+      *
+      * @param inputHitMap   Name of the input HitMap in the event
+      * @param outputHitMap  Name to write the output HitMap to in the event
+      * @param filter        The filter to apply
+      */
+    public HitMapFilterDriver(String inputHitMap, String outputHitMap, HitMapFilter filter) {
+        super();
+        m_filter = filter;
+        m_inputHitMapName = inputHitMap;
+        m_outputHitMapName = outputHitMap;
+    }
+
+    /** Process one event, filtering the hitmap */    
+    public void process(EventHeader event) 
+    {
+	HitMap inputHitMap = (HitMap) (event.get(m_inputHitMapName));
+	HitMap outputHitMap = m_filter.filter(inputHitMap);
+	event.put(m_outputHitMapName, outputHitMap);
+    }
+
+    /** Set the name under which to read the input HitMap from the event */
+    public void setInputHitMap (String name) { m_inputHitMapName = name; }
+
+    /** Set the name under which to write the output HitMap to the event */
+    public void setOutputHitMap(String name) { m_outputHitMapName= name; }
+
+    /** Set the filter */
+    public void setFilter(HitMapFilter filter) { m_filter = filter; }
+
+    protected HitMapFilter m_filter;
+    protected String m_inputHitMapName;
+    protected String m_outputHitMapName;
+}

lcsim/src/org/lcsim/util/hitmap
HitMapSubtractDriver.java added at 1.1
diff -N HitMapSubtractDriver.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ HitMapSubtractDriver.java	8 Feb 2006 22:34:13 -0000	1.1
@@ -0,0 +1,69 @@
+package org.lcsim.util.hitmap;
+
+import org.lcsim.event.EventHeader;
+import org.lcsim.util.Driver;
+
+/**
+ * Driver to subtract two HitMaps. The first and second HitMaps
+ * are read from the event. Any hit in the first HitMap
+ * which is NOT in the second HitMap is put in an output
+ * HitMap and written to the event. Hits which are in
+ * both (or only in the second HitMap) are ignored.
+ *
+ * The input HitMaps are left unaltered (unless the output name is
+ * identical to one of the input names).
+ */
+
+public class HitMapSubtractDriver extends Driver
+{
+    /** Simple constructor */
+    public HitMapSubtractDriver() {
+    }
+
+    /**
+      * Constructor with convenience arguments 
+      *
+      * @param inputHitMap1  Name of first input HitMap in the event
+      * @param inputHitMap2  Name of the second input HitMap, to be subtracted from the first
+      * @param outputHitMap  Name to write output HitMap to in the event
+      */
+    public HitMapSubtractDriver(String inputHitMap1, String inputHitMap2, String outputHitMap) {
+        m_inputHitMapName1 = inputHitMap1;
+        m_inputHitMapName2 = inputHitMap2;
+        m_outputHitMapName = outputHitMap;
+    }
+
+    /**
+      * Process one event, performing subtracting the second HitMap from
+      * first and writing out the remaining hits as the output HitMap.
+      */
+    public void process(EventHeader event) 
+    {
+	// Get the input hit maps:
+	HitMap inputHitMap1 = (HitMap) (event.get(m_inputHitMapName1));
+	HitMap inputHitMap2 = (HitMap) (event.get(m_inputHitMapName2));
+
+	// Prepare the output HitMap. We start with a copy of
+	// the first input map, then remove any hits from the second.
+	HitMap outputHitMap = new HitMap(inputHitMap1);
+	for (Long id : inputHitMap2.keySet()) {
+	    outputHitMap.remove(id);
+	}
+	
+	// Write the output to the event:
+	event.put(m_outputHitMapName, outputHitMap);
+    }
+
+    /** Set the name under which to read the first input HitMap from the event */
+    public void setFirstHitMap (String name) { m_inputHitMapName1 = name; }
+
+    /** Set the name under which to read the second input HitMap from the event */
+    public void setSecondHitMap(String name) { m_inputHitMapName2 = name; }
+
+    /** Set the name under which to write the output HitMap to the event */
+    public void setOutputHitMap(String name) { m_outputHitMapName = name; }
+
+    protected String m_inputHitMapName1;
+    protected String m_inputHitMapName2;
+    protected String m_outputHitMapName;
+}

lcsim/src/org/lcsim/util/hitmap
HitMapToClusterListDriver.java added at 1.1
diff -N HitMapToClusterListDriver.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ HitMapToClusterListDriver.java	8 Feb 2006 22:34:13 -0000	1.1
@@ -0,0 +1,58 @@
+package org.lcsim.util.hitmap;
+
+import java.util.List;
+import java.util.Vector;
+
+import org.lcsim.event.EventHeader;
+import org.lcsim.util.Driver;
+import org.lcsim.event.Cluster;
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.recon.cluster.util.BasicCluster;
+
+ /**
+   * This class takes in a HitMap (i.e. a Map<Long,CalorimeterHit>)
+   * and converts it to a List of one-hit clusters (which can be accessed
+   * by the org.lcsim event browser and WIRED event display in JAS3).
+   */
+
+public class HitMapToClusterListDriver extends Driver
+{
+    /** Simple constructor */
+    public HitMapToClusterListDriver() {
+        super();
+    }
+
+    /**
+      * Constructor with convenience arguments 
+      *
+      * @param inputHitMap  Name of input HitMap in the event
+      * @param outputList   Name to write output List to in the event
+      */
+    public HitMapToClusterListDriver(String inputHitMap, String outputList) {
+        super();
+        m_inputHitMapName = inputHitMap;
+        m_outputListName = outputList;
+    }
+
+    /** Process one event, performing conversion. */
+    public void process(EventHeader event) 
+    {
+	HitMap inputHitMap = (HitMap) (event.get(m_inputHitMapName));
+	List<Cluster> outputClusterList = new Vector<Cluster>();
+	for (CalorimeterHit hit : inputHitMap.values()) {
+	    BasicCluster clus = new BasicCluster();
+	    clus.addHit(hit);
+	    outputClusterList.add(clus);
+	}
+	event.put(m_outputListName, outputClusterList);
+    }
+
+    /** Set the name under which to read the input HitMap from the event */
+    public void setInputHitMap(String name) { m_inputHitMapName = name; }
+
+    /** Set the name under which to write the output List<CalorimeterHit> to the event */
+    public void setOutputList(String name) { m_outputListName = name; }
+
+    protected String m_inputHitMapName;
+    protected String m_outputListName;
+}

lcsim/src/org/lcsim/util/hitmap
HitMapToHitListDriver.java added at 1.1
diff -N HitMapToHitListDriver.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ HitMapToHitListDriver.java	8 Feb 2006 22:34:13 -0000	1.1
@@ -0,0 +1,52 @@
+package org.lcsim.util.hitmap;
+
+import java.util.Map;
+import java.util.List;
+import java.util.Vector;
+
+import org.lcsim.event.EventHeader;
+import org.lcsim.util.Driver;
+import org.lcsim.event.CalorimeterHit;
+
+ /**
+   * This class takes in a HitMap (i.e. a Map<Long,CalorimeterHit>)
+   * and converts it to a List<CalorimeterHit>.
+   */
+
+public class HitMapToHitListDriver extends Driver
+{
+    /** Simple constructor */
+    public HitMapToHitListDriver() {
+        super();
+    }
+
+    /**
+      * Constructor with convenience arguments 
+      *
+      * @param inputHitMap  Name of input HitMap in the event
+      * @param outputList   Name to write output List to in the event
+      */
+    public HitMapToHitListDriver(String inputHitMap, String outputList) {
+        super();
+        m_inputHitMapName = inputHitMap;
+        m_outputListName = outputList;
+    }
+
+     /** Process one event, performing conversion. */
+    public void process(EventHeader event)
+    {
+	HitMap inputHitMap = (HitMap) (event.get(m_inputHitMapName));
+	List<CalorimeterHit> outputList = new Vector<CalorimeterHit> ();
+	outputList.addAll(inputHitMap.values());
+	event.put(m_outputListName, outputList);
+    }
+
+    /** Set the name under which to read the input HitMap from the event */
+    public void setInputHitMap(String name) { m_inputHitMapName = name; }
+
+    /** Set the name under which to write the output List<CalorimeterHit> to the event */
+    public void setOutputList(String name) { m_outputListName = name; }
+    
+    protected String m_inputHitMapName;
+    protected String m_outputListName;
+}

lcsim/src/org/lcsim/util/hitmap
MapToHitMapDriver.java added at 1.1
diff -N MapToHitMapDriver.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ MapToHitMapDriver.java	8 Feb 2006 22:34:13 -0000	1.1
@@ -0,0 +1,48 @@
+package org.lcsim.util.hitmap;
+
+import java.util.Map;
+
+import org.lcsim.event.EventHeader;
+import org.lcsim.util.Driver;
+import org.lcsim.event.CalorimeterHit;
+
+/**
+ * Driver to convert a Map<Long,CalorimeterHit> to a HitMap.
+ */
+
+public class MapToHitMapDriver extends Driver
+{
+    /** Simple constructor */
+    public MapToHitMapDriver() {
+        super();
+    }
+
+    /**
+      * Constructor with convenience arguments 
+      *
+      * @param inputMap      Name of input Map in the event
+      * @param outputHitMap  Name to write HitMap to in the event
+      */
+    public MapToHitMapDriver(String inputMap, String outputHitMap) {
+        super();
+        m_inputHitMapName = inputMap;
+        m_outputHitMapName = outputHitMap;
+    }
+
+    /** Process one event, performing conversion. */
+    public void process(EventHeader event) 
+    {
+	Map<Long,CalorimeterHit> inputMap = (Map<Long,CalorimeterHit>) (event.get(m_inputHitMapName));
+	HitMap outputHitMap = new HitMap(inputMap);
+	event.put(m_outputHitMapName, outputHitMap);
+    }
+
+    /** Set the name under which to read the input Map<Long,CalorimeterHit> from the event */
+    public void setInputMap(String name) { m_inputHitMapName = name; }
+
+    /** Set the name under which to write the output HitMap to the event */
+    public void setOutputHitMap(String name) { m_outputHitMapName = name; }
+
+    protected String m_inputHitMapName;
+    protected String m_outputHitMapName;
+}
CVSspam 0.2.8