hps-java/src/main/java/org/lcsim/hps/recon/ecal
diff -u -r1.9 -r1.10
--- HPSEcal1BitClusterer.java 23 Aug 2011 17:29:59 -0000 1.9
+++ HPSEcal1BitClusterer.java 23 Aug 2011 22:08:29 -0000 1.10
@@ -1,6 +1,7 @@
package org.lcsim.hps.recon.ecal;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -17,6 +18,7 @@
import org.lcsim.recon.cluster.util.BasicCluster;
import org.lcsim.util.Driver;
import org.lcsim.util.lcio.LCIOConstants;
+import org.lcsim.recon.cluster.util.Clusterer;
/**
* Creates clusters from CalorimeterHits in the HPSEcal detector.
@@ -27,25 +29,17 @@
* @author Tim Nelson <[log in to unmask]>
* @author Sho Uemura <[log in to unmask]>
*/
-public class HPSEcal1BitClusterer extends Driver {
-
+public class HPSEcal1BitClusterer extends Driver implements Clusterer {
HPSEcal ecal;
- String ecalCollectionName;
String ecalName;
- String rawCollectionName = "EcalRawHits";
+ String ecalCollectionName;
String clusterCollectionName = "EcalClusters";
// Threshold E for discriminator.
double hitEMin = .05;
// Threshold hit count for cluster. Cluster must have more than this many hits.
int clusterThreshold = 5;
- // Odd or even number of crystals in X.
- boolean oddX;
// Map of crystals to their neighbors.
NeighborMap neighborMap = null;
- //counts bunches for trigger clock
- int clock;
- //number of bunches in trigger cycle
- int triggerCycle = 4;
public HPSEcal1BitClusterer() {
}
@@ -54,8 +48,8 @@
this.clusterCollectionName = clusterCollectionName;
}
- public void setRawCollectionName(String rawCollectionName) {
- this.rawCollectionName = rawCollectionName;
+ public void setEcalCollectionName(String ecalCollectionName) {
+ this.ecalCollectionName = ecalCollectionName;
}
public void setHitEMin(double hitEMin) {
@@ -66,20 +60,11 @@
this.clusterThreshold = clusterThreshold;
}
- public void setTriggerCycle(int triggerCycle) {
- this.triggerCycle = triggerCycle;
- }
-
- public void setEcalCollectionName(String ecalCollectionName) {
- this.ecalCollectionName = ecalCollectionName;
- }
-
public void setEcalName(String ecalName) {
this.ecalName = ecalName;
}
public void startOfData() {
- clock = 0;
if (ecalCollectionName == null) {
throw new RuntimeException("The parameter ecalCollectionName was not set!");
}
@@ -109,136 +94,131 @@
//System.out.println(this.getClass().getCanonicalName() + " - process");
// Get the list of raw ECal hits.
- List<CalorimeterHit> hits = event.get(CalorimeterHit.class, rawCollectionName);
-
- // New Cluster list to be added to event.
- List<Cluster> clusters = new ArrayList<Cluster>();
+ List<CalorimeterHit> hits = event.get(CalorimeterHit.class, ecalCollectionName);
//if there are raw hits, run clustering
if (hits != null) {
- // Hit map.
- Map<Long, CalorimeterHit> hitMap = new HashMap<Long, CalorimeterHit>();
+ // Put Cluster collection into event.
+ int flag = 1 << LCIOConstants.CLBIT_HITS;
+ event.put(clusterCollectionName, createClusters(hits), Cluster.class, flag);
+ }
+ }
- // Make a hit map for quick lookup by ID.
- for (CalorimeterHit hit : hits) {
- hitMap.put(hit.getCellID(), hit);
- }
+ public List<Cluster> createClusters(List<CalorimeterHit> hits) {
+ // Hit map.
+ Map<Long, CalorimeterHit> hitMap = new HashMap<Long, CalorimeterHit>();
+
+ // Make a hit map for quick lookup by ID.
+ for (CalorimeterHit hit : hits) {
+ hitMap.put(hit.getCellID(), hit);
+ }
- // Get the decoder for the ECal IDs.
- IDDecoder dec = ecal.getIDDecoder();
+ return createClusters(hitMap);
+ }
- Map<Long, Integer> hitCounts = new HashMap<Long, Integer>();
+ public List<Cluster> createClusters(Map<Long, CalorimeterHit> map) {
+ // 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();
- // Loop over ECal hits to count hit towers
- for (CalorimeterHit hit : hits) {
- // Cut on min seed E.
- if (hit.getCorrectedEnergy() < hitEMin) {
- continue;
- }
+ Map<Long, Integer> hitCounts = new HashMap<Long, Integer>();
- // Get neighbor crystal IDs.
- Set<Long> neighbors = neighborMap.get(hit.getCellID());
+ Collection<CalorimeterHit> hitCollection = map.values();
+ // Loop over ECal hits to count hit towers
+ for (CalorimeterHit hit : hitCollection) {
+ // Cut on min seed E.
+ if (hit.getRawEnergy() < hitEMin) {
+ continue;
+ }
- if (neighbors == null) {
- throw new RuntimeException("Oops! Set of neighbors is null!");
- }
+ // Get neighbor crystal IDs.
+ Set<Long> neighbors = neighborMap.get(hit.getCellID());
- Integer hitCount = hitCounts.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(hit.getCellID(), 1);
+ hitCounts.put(neighborId, 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);
- }
+ hitCounts.put(neighborId, hitCount + 1);
}
+ }
- //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;
- }
+ //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);
+ // Get neighbor crystal IDs.
+ Set<Long> neighbors = neighborMap.get(possibleCluster);
- if (neighbors == null) {
- throw new RuntimeException("Oops! Set of neighbors is null!");
- }
+ if (neighbors == null) {
+ throw new RuntimeException("Oops! Set of neighbors is null!");
+ }
- //Apply peak detector scheme.
+ //Apply peak detector scheme.
+ // Set the ID.
+ dec.setID(possibleCluster);
+ // Get ID field values.
+ int x1 = dec.getValue("ix");
+ int y1 = dec.getValue("iy");
+ int side1 = dec.getValue("side");
+ Integer hitCount = hitCounts.get(possibleCluster);
+
+ //System.out.printf("Possible cluster: x: %d, y: %d, side:%d, hits: %d\n",x1,y1,side1,hitCount);
+ boolean isCluster = true;
+ for (Long neighborId : neighbors) {
// Set the ID.
- dec.setID(possibleCluster);
+ dec.setID(neighborId);
+ Integer neighborHitCount = hitCounts.get(neighborId);
+ if (neighborHitCount == null)
+ continue;
// Get ID field values.
- int x1 = dec.getValue("ix");
- int y1 = dec.getValue("iy");
- int side1 = dec.getValue("side");
- Integer hitCount = hitCounts.get(possibleCluster);
-
- //System.out.printf("Possible cluster: x: %d, y: %d, side:%d, hits: %d\n",x1,y1,side1,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 (side1 == 1) {
- 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;
- }
+ int x2 = dec.getValue("ix");
+ int y2 = dec.getValue("iy");
+ if (side1 == 1) {
+ 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 (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;
- }
+ if (hitCount > neighborHitCount)
+ continue;
}
} else {
- //quadrant 2
- if (y1 > y2) {
+ if (x1 > x2) {
if (hitCount >= neighborHitCount)
continue;
- } else if (y1 < y2) {
+ } else if (x1 < x2) {
if (hitCount > neighborHitCount)
continue;
- } else if (x1 > x2) {
+ } else if (y1 < y2) {
if (hitCount >= neighborHitCount)
continue;
} else {
@@ -247,50 +227,50 @@
}
}
} 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;
- }
+ //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 (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;
- }
+ if (hitCount > neighborHitCount)
+ continue;
}
} else {
- //quadrant 4
- if (y1 < y2) {
+ if (x1 < x2) {
if (hitCount >= neighborHitCount)
continue;
- } else if (y1 > y2) {
+ } else if (x1 > x2) {
if (hitCount > neighborHitCount)
continue;
- } else if (x1 < x2) {
+ } else if (y1 > y2) {
if (hitCount >= neighborHitCount)
continue;
} else {
@@ -298,33 +278,45 @@
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;
}
+ isCluster = false;
+ break;
+ }
- if (isCluster) {
- //System.out.printf("Cluster: x: %d, y: %d, side:%d, hits: %d\n",x1,y1,side1,hitCount);
- BasicCluster cluster = new BasicCluster();
- CalorimeterHit hit = hitMap.get(possibleCluster);
- if (hit != null && hit.getCorrectedEnergy() > hitEMin) {
- cluster.addHit(hit);
- }
+ if (isCluster) {
+ //System.out.printf("Cluster: x: %d, y: %d, side:%d, hits: %d\n",x1,y1,side1,hitCount);
+ BasicCluster cluster = new BasicCluster();
+ CalorimeterHit hit = map.get(possibleCluster);
+ if (hit != null && hit.getRawEnergy() > hitEMin) {
+ cluster.addHit(hit);
+ }
- for (Long neighborId : neighbors) {
- // Find the neighbor hit in the event if it exists.
- hit = hitMap.get(neighborId);
- if (hit != null && hit.getCorrectedEnergy() > hitEMin) {
- 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) {
+ cluster.addHit(hit);
}
- clusters.add(cluster);
}
+ clusters.add(cluster);
}
-
}
- // Put Cluster collection into event.
- int flag = 1 << LCIOConstants.CLBIT_HITS;
- event.put(clusterCollectionName, clusters, Cluster.class, flag);
+ return clusters;
}
}
\ No newline at end of file