hps-java/src/main/java/org/lcsim/hps/recon/ecal
diff -u -r1.5 -r1.6
--- HPSEcal1BitClusterer.java 19 Aug 2011 00:15:14 -0000 1.5
+++ HPSEcal1BitClusterer.java 19 Aug 2011 23:00:10 -0000 1.6
@@ -19,6 +19,7 @@
import org.lcsim.util.Driver;
import org.lcsim.util.lcio.LCIOConstants;
+//import org.lcsim.hps.util.RingBuffer;
/**
* Creates clusters from CalorimeterHits in the HPSEcal detector.
*
@@ -42,6 +43,14 @@
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;
+ //energy deposited in trigger cycle
+ Map<Long, Double> eDepMap = null;
+ //hits in trigger cycle
+ Map<Long, List> hitsMap = null;
public HPSEcal1BitClusterer() {
}
@@ -58,6 +67,10 @@
this.clusterThreshold = clusterThreshold;
}
+ public void setTriggerCycle(int triggerCycle) {
+ this.triggerCycle = triggerCycle;
+ }
+
public void setEcalCollectionName(String ecalCollectionName) {
this.ecalCollectionName = ecalCollectionName;
}
@@ -67,6 +80,7 @@
}
public void startOfData() {
+ clock = 0;
if (ecalCollectionName == null) {
throw new RuntimeException("The parameter ecalCollectionName was not set!");
}
@@ -94,6 +108,12 @@
public void process(EventHeader event) {
//System.out.println(this.getClass().getCanonicalName() + " - process");
+ //if at the beginning of a trigger cycle, reset trigger buffers
+ if (clock % triggerCycle == 0) {
+ eDepMap = new HashMap<Long, Double>();
+ hitsMap = new HashMap<Long, List>();
+ }
+ clock++;
// Get the list of ECal hits.
List<CalorimeterHit> hits = event.get(CalorimeterHit.class, ecalCollectionName);
@@ -101,214 +121,238 @@
throw new RuntimeException("Event is missing ECal hits collection!");
}
- // Get the decoder for the ECal IDs.
- IDDecoder dec = ecal.getIDDecoder();
-
- // Hit map.
- Map<Long, CalorimeterHit> hitMap = new HashMap<Long, CalorimeterHit>();
-
- Map<Long, Integer> hitCounts = new HashMap<Long, Integer>();
-
- // Make a hit map for quick lookup by ID.
+ //fill the trigger buffers
for (CalorimeterHit hit : hits) {
- hitMap.put(hit.getCellID(), hit);
+ Double eDep = eDepMap.get(hit.getCellID());
+ if (eDep == null) {
+ eDepMap.put(hit.getCellID(), hit.getRawEnergy());
+ } else {
+ eDepMap.put(hit.getCellID(), eDep + hit.getRawEnergy());
+ }
+
+ List<CalorimeterHit> hitList = hitsMap.get(hit.getCellID());
+ if (hitList == null) {
+ //can't have more hits than bunches in a cycle
+ hitList = new ArrayList<CalorimeterHit>(triggerCycle);
+ hitsMap.put(hit.getCellID(), hitList);
+ }
+ hitList.add(hit);
}
// New Cluster list to be added to event.
List<Cluster> clusters = new ArrayList<Cluster>();
- // Loop over ECal hits to count hit towers
- for (CalorimeterHit hit : hits) {
- // Cut on min seed E.
- if (hit.getRawEnergy() < hitEMin) {
- continue;
- }
+ //if at the end of a trigger cycle, run clustering
+ if (clock % triggerCycle == 0) {
- // Get neighbor crystal IDs.
- Set<Long> neighbors = neighborMap.get(hit.getCellID());
+ // Get the decoder for the ECal IDs.
+ IDDecoder dec = ecal.getIDDecoder();
- if (neighbors == null) {
- throw new RuntimeException("Oops! Set of neighbors is null!");
- }
+ Map<Long, Integer> hitCounts = new HashMap<Long, Integer>();
+
+
+ // Loop over ECal hits to count hit towers
+ for (Long cellID : eDepMap.keySet()) {
+ // Cut on min seed E.
+ if (eDepMap.get(cellID) < hitEMin) {
+ continue;
+ }
+
+ // Get neighbor crystal IDs.
+ Set<Long> neighbors = neighborMap.get(cellID);
+
+ 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
- hitCount++;
-
- // Loop over neighbors to make hit list for cluster.
- for (Long neighborId : neighbors) {
- hitCount = hitCounts.get(neighborId);
+ Integer hitCount = hitCounts.get(cellID);
if (hitCount == null)
- hitCounts.put(hit.getCellID(), 1);
+ hitCounts.put(cellID, 1);
else
- hitCounts.put(hit.getCellID(), hitCount+1);
- }
- }
+ hitCounts.put(cellID, hitCount + 1);
- //for each crystal with a nonzero hit count, test for cluster
- Iterator<Long> possibleClusters = hitCounts.keySet().iterator();
- while (possibleClusters.hasNext()) {
- Long possibleCluster = possibleClusters.next();
- //System.out.printf("%d, %d hits\n",possibleCluster,hitCounts.get(possibleCluster));
- if (hitCounts.get(possibleCluster) <= clusterThreshold) {
- continue;
+ // 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);
+ }
}
- // Get neighbor crystal IDs.
- Set<Long> neighbors = neighborMap.get(possibleCluster);
+ //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;
+ }
- if (neighbors == null) {
- throw new RuntimeException("Oops! Set of neighbors is null!");
- }
+ // 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");
- 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) {
+ //Apply peak detector scheme.
// Set the ID.
- dec.setID(neighborId);
- Integer neighborHitCount = hitCounts.get(neighborId);
- if (neighborHitCount == null)
- continue;
+ dec.setID(possibleCluster);
// 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;
+ 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;
+ }
} else {
- if (hitCount>neighborHitCount)
- continue;
+ 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)
+ //quadrant 2
+ if (y1 > y2) {
+ if (hitCount >= neighborHitCount)
continue;
} else if (y1 < y2) {
- if (hitCount>=neighborHitCount)
+ if (hitCount > neighborHitCount)
+ continue;
+ } else if (x1 > x2) {
+ if (hitCount >= neighborHitCount)
continue;
} else {
- if (hitCount>neighborHitCount)
+ 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;
+ 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 (hitCount>neighborHitCount)
- continue;
+ 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)
+ //quadrant 4
+ if (y1 < y2) {
+ if (hitCount >= neighborHitCount)
continue;
} else if (y1 > y2) {
- if (hitCount>=neighborHitCount)
+ if (hitCount > neighborHitCount)
+ continue;
+ } else if (x1 < x2) {
+ if (hitCount >= neighborHitCount)
continue;
} else {
- if (hitCount>neighborHitCount)
+ 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;
}
- 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();
- cluster.addHit(hitMap.get(possibleCluster));
- for (Long neighborId : neighbors) {
- // Find the neighbor hit in the event if it exists.
- CalorimeterHit neighborHit = hitMap.get(neighborId);
+ if (isCluster) {
+ //System.out.printf("Cluster: x: %d, y: %d, side:%d, hits: %d\n",x1,y1,side1,hitCount);
+ BasicCluster cluster = new BasicCluster();
+ Double eDep = eDepMap.get(possibleCluster);
+ if (eDep != null && eDep > hitEMin) {
+
+ List<CalorimeterHit> hitList = hitsMap.get(possibleCluster);
+ for (CalorimeterHit hit : hitList) {
+ cluster.addHit(hit);
+ }
+ }
- // Was this neighbor cell hit?
- if (neighborHit != null && neighborHit.getRawEnergy() > hitEMin) {
- cluster.addHit(neighborHit);
+ for (Long neighborId : neighbors) {
+ // Find the neighbor hit in the event if it exists.
+ eDep = eDepMap.get(neighborId);
+
+ // Was this neighbor cell hit?
+ if (eDep != null && eDep > hitEMin) {
+ List<CalorimeterHit> hitList = hitsMap.get(neighborId);
+ for (CalorimeterHit hit : hitList) {
+ 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);