lcsim/src/org/lcsim/recon/pfa/structural
diff -N CheckDisjoint.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ CheckDisjoint.java 22 Oct 2008 17:51:09 -0000 1.1
@@ -0,0 +1,71 @@
+package org.lcsim.recon.pfa.structural;
+
+import java.util.*;
+import org.lcsim.util.Driver;
+import org.lcsim.event.EventHeader;
+import org.lcsim.util.*;
+import org.lcsim.event.*;
+import org.lcsim.recon.cluster.directedtree.*;
+import org.lcsim.util.hitmap.*;
+import org.lcsim.util.decision.*;
+import org.lcsim.contrib.uiowa.MuonFinder.*;
+import org.lcsim.recon.pfa.identifier.*;
+
+/**
+ * Validation driver to check that two collections/hitmaps are disjoint.
+ * Allowed inputs (to read from the event):
+ * 1) A Collection of CalorimeterHit objects
+ * 2) A Collection of Cluster objects
+ * 3) A HitMap
+ *
+ * @version $Id: CheckDisjoint.java,v 1.1 2008/10/22 17:51:09 mcharles Exp $
+ * @author [log in to unmask]
+ */
+
+public class CheckDisjoint extends Driver
+{
+ String m_name1;
+ String m_name2;
+ public CheckDisjoint(String name1, String name2) {
+ m_name1 = name1;
+ m_name2 = name2;
+ }
+
+ public void process(EventHeader event) {
+ Set<Long> set1 = getHits(m_name1, event);
+ Set<Long> set2 = getHits(m_name2, event);
+ for (Long id : set1) {
+ if (set2.contains(id)) {
+ throw new AssertionError("ERROR: Both "+m_name1+" and "+m_name2+" contain hit with ID "+id);
+ }
+ }
+ System.out.println("OK: No overlaps between "+set1.size()+" hits in "+m_name1+" and "+set2.size()+" hits in "+m_name2);
+ }
+
+ private Set<Long> getHits(String name, EventHeader event) {
+ Set<Long> output = new HashSet<Long>();
+ Object o = event.get(name);
+ if (o instanceof HitMap) {
+ HitMap tmpMap = (HitMap)(o);
+ output.addAll(tmpMap.keySet());
+ } else if (o instanceof Collection) {
+ List tmpList = (List)(o);
+ for (Object subObj : tmpList) {
+ if (subObj instanceof CalorimeterHit) {
+ CalorimeterHit hit = (CalorimeterHit)(subObj);
+ output.add(hit.getCellID());
+ } else if (subObj instanceof Cluster) {
+ Cluster clus = (Cluster)(subObj);
+ for (CalorimeterHit hit : clus.getCalorimeterHits()) {
+ output.add(hit.getCellID());
+ }
+ } else {
+ throw new AssertionError("ERROR: Sub-object type "+subObj.getClass().getName()+" not recognized.");
+ }
+ }
+ } else {
+ throw new AssertionError("ERROR: Object type "+o.getClass().getName()+" not recognized.");
+ }
+ return output;
+ }
+}