hps-java/src/main/java/org/lcsim/hps/recon/ecal
diff -N HPSEcal1BitClusterVetoClusterer.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ HPSEcal1BitClusterVetoClusterer.java 13 Oct 2011 19:59:40 -0000 1.1
@@ -0,0 +1,292 @@
+package org.lcsim.hps.recon.ecal;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.event.Cluster;
+import org.lcsim.event.EventHeader;
+import org.lcsim.geometry.IDDecoder;
+import org.lcsim.util.lcio.LCIOConstants;
+
+/**
+ * Creates clusters from CalorimeterHits in the HPSEcal detector.
+ *
+ * A veto hit vetoes clusters in the crystal with the veto hit and all its neighbors.
+ *
+ * The clustering algorithm is from JLab Hall B 6 GeV DVCS Trigger Design doc.
+ *
+ * @author Sho Uemura <[log in to unmask]>
+ * @version $Id: HPSEcal1BitClusterVetoClusterer.java,v 1.1 2011/10/13 19:59:40 meeg Exp $
+ */
+public class HPSEcal1BitClusterVetoClusterer extends HPSEcal1BitClusterer {
+
+ String vetoCollectionName;
+
+ public HPSEcal1BitClusterVetoClusterer() {
+ }
+
+ public void setVetoCollectionName(String vetoCollectionName) {
+ this.vetoCollectionName = vetoCollectionName;
+ }
+
+ public void startOfData() {
+ if (ecalCollectionName == null) {
+ throw new RuntimeException("The parameter ecalCollectionName was not set!");
+ }
+
+ if (vetoCollectionName == null) {
+ throw new RuntimeException("The parameter vetoCollectionName was not set!");
+ }
+
+ if (ecalName == null) {
+ throw new RuntimeException("The parameter ecalName was not set!");
+ }
+ }
+
+ public void process(EventHeader event) {
+ //System.out.println(this.getClass().getCanonicalName() + " - process");
+
+ // Get the list of raw ECal hits.
+ List<CalorimeterHit> hits = event.get(CalorimeterHit.class, ecalCollectionName);
+ if (hits == null)
+ throw new RuntimeException("Event is missing ECal raw hits collection!");
+
+ List<CalorimeterHit> vetoHits = event.get(CalorimeterHit.class, vetoCollectionName);
+ if (vetoHits == null)
+ throw new RuntimeException("Event is missing ECal veto hits collection!");
+
+ // Put Cluster collection into event.
+ int flag = 1 << LCIOConstants.CLBIT_HITS;
+ event.put(clusterCollectionName, createVetoedClusters(hits, vetoHits), Cluster.class, flag);
+ }
+
+ public List<Cluster> createVetoedClusters(List<CalorimeterHit> hits, List<CalorimeterHit> vetoHits) {
+ // Hit map.
+ Map<Long, CalorimeterHit> map = new HashMap<Long, CalorimeterHit>();
+
+ // Make a hit map for quick lookup by ID.
+ for (CalorimeterHit hit : hits) {
+ map.put(hit.getCellID(), hit);
+ }
+
+ // New Cluster list to be added to event.
+ List<Cluster> clusters = new ArrayList<Cluster>();
+
+ // Get the decoder for the ECal IDs.
+ IDDecoder dec = ecal.getIDDecoder();
+
+ Map<Long, Integer> hitCounts = new HashMap<Long, Integer>();
+
+ // Loop over ECal hits to count hit towers
+ for (CalorimeterHit hit : hits) {
+ // Cut on seed E.
+ if (hit.getRawEnergy() < hitEMin || hit.getRawEnergy() > hitEMax) {
+ continue;
+ }
+
+ // Get neighbor crystal IDs.
+ Set<Long> neighbors = neighborMap.get(hit.getCellID());
+
+ if (neighbors == null) {
+ throw new RuntimeException("Oops! Set of neighbors is null!");
+ }
+
+ Integer hitCount = hitCounts.get(hit.getCellID());
+ if (hitCount == null)
+ hitCounts.put(hit.getCellID(), 1);
+ else
+ hitCounts.put(hit.getCellID(), hitCount + 1);
+
+ // Loop over neighbors to make hit list for cluster.
+ for (Long neighborId : neighbors) {
+ hitCount = hitCounts.get(neighborId);
+ if (hitCount == null)
+ hitCounts.put(neighborId, 1);
+ else
+ hitCounts.put(neighborId, hitCount + 1);
+ }
+ }
+
+ // Loop over veto hits to veto clusters
+ for (CalorimeterHit hit : vetoHits) {
+ // Get neighbor crystal IDs.
+ Set<Long> neighbors = neighborMap.get(hit.getCellID());
+
+ if (neighbors == null) {
+ throw new RuntimeException("Oops! Set of neighbors is null!");
+ }
+
+ // Veto the hit towers for the vetoed crystal and all neighbors.
+ hitCounts.remove(hit.getCellID());
+ for (Long neighborId : neighbors) {
+ hitCounts.remove(neighborId);
+ }
+ }
+
+ //for each crystal with a nonzero hit count, test for cluster
+ for (Long possibleCluster : hitCounts.keySet()) {
+ //System.out.printf("%d, %d hits\n",possibleCluster,hitCounts.get(possibleCluster));
+ if (hitCounts.get(possibleCluster) <= clusterThreshold) {
+ continue;
+ }
+
+ // Get neighbor crystal IDs.
+ Set<Long> neighbors = neighborMap.get(possibleCluster);
+
+ if (neighbors == null) {
+ throw new RuntimeException("Oops! Set of neighbors is null!");
+ }
+
+ //Apply peak detector scheme.
+ // Set the ID.
+ dec.setID(possibleCluster);
+ // Get ID field values.
+ int x1 = dec.getValue("ix");
+ int y1 = dec.getValue("iy");
+ Integer hitCount = hitCounts.get(possibleCluster);
+
+ //System.out.printf("Possible cluster: x: %d, y: %d, hits: %d\n",x1,y1,hitCount);
+ boolean isCluster = true;
+ for (Long neighborId : neighbors) {
+ // Set the ID.
+ dec.setID(neighborId);
+ Integer neighborHitCount = hitCounts.get(neighborId);
+ if (neighborHitCount == null)
+ continue;
+ // Get ID field values.
+ int x2 = dec.getValue("ix");
+ int y2 = dec.getValue("iy");
+ if (y1 > 0) {
+ if (x1 > 0) {
+ //quadrant 1
+ if (x1 == 1) {
+ //special case: left edge of quadrant
+ if (x1 > x2 && y1 < y2) {
+ if (hitCount > neighborHitCount)
+ continue;
+ } else if (x1 > x2) {
+ if (hitCount >= neighborHitCount)
+ continue;
+ } else if (x1 < x2) {
+ if (hitCount > neighborHitCount)
+ continue;
+ } else if (y1 < y2) {
+ if (hitCount >= neighborHitCount)
+ continue;
+ } else {
+ if (hitCount > neighborHitCount)
+ continue;
+ }
+ } else {
+ if (x1 > x2) {
+ if (hitCount >= neighborHitCount)
+ continue;
+ } else if (x1 < x2) {
+ if (hitCount > neighborHitCount)
+ continue;
+ } else if (y1 < y2) {
+ if (hitCount >= neighborHitCount)
+ continue;
+ } else {
+ if (hitCount > neighborHitCount)
+ continue;
+ }
+ }
+ } else {
+ //quadrant 2
+ if (y1 > y2) {
+ if (hitCount >= neighborHitCount)
+ continue;
+ } else if (y1 < y2) {
+ if (hitCount > neighborHitCount)
+ continue;
+ } else if (x1 > x2) {
+ if (hitCount >= neighborHitCount)
+ continue;
+ } else {
+ if (hitCount > neighborHitCount)
+ continue;
+ }
+ }
+ } else {
+ if (x1 < 0) {
+ //quadrant 3
+ if (x1 == 1) {
+ //special case: left edge of quadrant
+ if (x1 < x2 && y1 > y2) {
+ if (hitCount > neighborHitCount)
+ continue;
+ } else if (x1 < x2) {
+ if (hitCount >= neighborHitCount)
+ continue;
+ } else if (x1 > x2) {
+ if (hitCount > neighborHitCount)
+ continue;
+ } else if (y1 > y2) {
+ if (hitCount >= neighborHitCount)
+ continue;
+ } else {
+ if (hitCount > neighborHitCount)
+ continue;
+ }
+ } else {
+ if (x1 < x2) {
+ if (hitCount >= neighborHitCount)
+ continue;
+ } else if (x1 > x2) {
+ if (hitCount > neighborHitCount)
+ continue;
+ } else if (y1 > y2) {
+ if (hitCount >= neighborHitCount)
+ continue;
+ } else {
+ if (hitCount > neighborHitCount)
+ continue;
+ }
+ }
+ } else {
+ //quadrant 4
+ if (y1 < y2) {
+ if (hitCount >= neighborHitCount)
+ continue;
+ } else if (y1 > y2) {
+ if (hitCount > neighborHitCount)
+ continue;
+ } else if (x1 < x2) {
+ if (hitCount >= neighborHitCount)
+ continue;
+ } else {
+ if (hitCount > neighborHitCount)
+ continue;
+ }
+ }
+ }
+ isCluster = false;
+ break;
+ }
+
+ if (isCluster) {
+ //System.out.printf("Cluster: x: %d, y: %d, side:%d, hits: %d\n",x1,y1,side1,hitCount);
+ HPSEcalCluster cluster = new HPSEcalCluster(possibleCluster);
+ CalorimeterHit hit = map.get(possibleCluster);
+ if (hit != null && hit.getRawEnergy() > hitEMin && hit.getRawEnergy() < hitEMax) {
+ cluster.addHit(hit);
+ }
+
+ for (Long neighborId : neighbors) {
+ // Find the neighbor hit in the event if it exists.
+ hit = map.get(neighborId);
+ if (hit != null && hit.getRawEnergy() > hitEMin && hit.getRawEnergy() < hitEMax) {
+ cluster.addHit(hit);
+ }
+ }
+ clusters.add(cluster);
+ }
+ }
+ return clusters;
+ }
+}
\ No newline at end of file
hps-java/src/main/java/org/lcsim/hps/recon/ecal
diff -N HPSEcal1BitEventVetoClusterer.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ HPSEcal1BitEventVetoClusterer.java 13 Oct 2011 19:59:40 -0000 1.1
@@ -0,0 +1,65 @@
+package org.lcsim.hps.recon.ecal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.event.Cluster;
+import org.lcsim.event.EventHeader;
+import org.lcsim.util.lcio.LCIOConstants;
+
+/**
+ * Creates clusters from CalorimeterHits in the HPSEcal detector.
+ *
+ * A veto hit vetoes all clusters in the event.
+ *
+ * The clustering algorithm is from JLab Hall B 6 GeV DVCS Trigger Design doc.
+ *
+ * @author Sho Uemura <[log in to unmask]>
+ * @version $Id: HPSEcal1BitEventVetoClusterer.java,v 1.1 2011/10/13 19:59:40 meeg Exp $
+ */
+public class HPSEcal1BitEventVetoClusterer extends HPSEcal1BitClusterer {
+
+ String vetoCollectionName;
+
+ public HPSEcal1BitEventVetoClusterer() {
+ }
+
+ public void setVetoCollectionName(String vetoCollectionName) {
+ this.vetoCollectionName = vetoCollectionName;
+ }
+
+ public void startOfData() {
+ if (ecalCollectionName == null) {
+ throw new RuntimeException("The parameter ecalCollectionName was not set!");
+ }
+
+ if (vetoCollectionName == null) {
+ throw new RuntimeException("The parameter vetoCollectionName was not set!");
+ }
+
+ if (ecalName == null) {
+ throw new RuntimeException("The parameter ecalName was not set!");
+ }
+ }
+
+ public void process(EventHeader event) {
+ //System.out.println(this.getClass().getCanonicalName() + " - process");
+
+ // Get the list of raw ECal hits.
+ List<CalorimeterHit> hits = event.get(CalorimeterHit.class, ecalCollectionName);
+ if (hits == null)
+ throw new RuntimeException("Event is missing ECal raw hits collection!");
+
+ List<CalorimeterHit> vetoHits = event.get(CalorimeterHit.class, vetoCollectionName);
+ if (vetoHits == null)
+ throw new RuntimeException("Event is missing ECal veto hits collection!");
+
+ // Put Cluster collection into event.
+ int flag = 1 << LCIOConstants.CLBIT_HITS;
+ if (vetoHits.isEmpty())
+ event.put(clusterCollectionName, createClusters(hits), Cluster.class, flag);
+ else
+ event.put(clusterCollectionName, new ArrayList<Cluster>(), Cluster.class, flag);
+ }
+}
\ No newline at end of file