lcsim/src/org/lcsim/contrib/uiowa
diff -N CheckDisjoint.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ CheckDisjoint.java 13 Oct 2008 07:15:51 -0000 1.1
@@ -0,0 +1,60 @@
+package org.lcsim.contrib.uiowa;
+
+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.*;
+
+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;
+ }
+}