Commit in hps-java/src/main/java/org/lcsim/hps/recon/ecal on MAIN | |||
ECalSimpleReadout.java | +69 | added 1.1 | |
ECalReadout.java | +27 | added 1.1 | |
HPSEcalReadoutDriver.java | +105 | added 1.1 | |
RawCalorimeterHit.java | +37 | added 1.1 | |
HPSEcal1BitClusterer.java | +31 | -57 | 1.6 -> 1.7 |
+269 | -57 |
breaking out readout into separate classes/drivers in preparation for time evolution
diff -N ECalSimpleReadout.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ECalSimpleReadout.java 23 Aug 2011 17:08:10 -0000 1.1 @@ -0,0 +1,69 @@
+/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.lcsim.hps.recon.ecal; + +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; + +import org.lcsim.event.CalorimeterHit; +import org.lcsim.geometry.Subdetector; +import org.lcsim.geometry.IDDecoder; +import org.lcsim.hps.recon.ecal.RawCalorimeterHit; + +/** + * Minimal ECal readout - just integrates energies of all hits, + * no time evolution + * @author meeg + */ +public class ECalSimpleReadout implements ECalReadout { + + private static String _NAME = "ECalSimpleDigitizer"; + Subdetector ecal; + Map<Long, Double> eDepMap = null; + int hitType = 11; + + public String getName() { + return _NAME; + } + + public ECalSimpleReadout(Subdetector ecal) { + this.ecal = ecal; + eDepMap = new HashMap<Long, Double>(); + } + + public void setEcal(Subdetector ecal) { + this.ecal = ecal; + } + + public void setHitType(int hitType) { + this.hitType = hitType; + } + + public List<CalorimeterHit> readHits() { + IDDecoder dec = ecal.getIDDecoder(); + List<CalorimeterHit> hitList = new ArrayList<CalorimeterHit>(); + for (Long cellID : eDepMap.keySet()) { + dec.setID(cellID); + hitList.add(new RawCalorimeterHit(eDepMap.get(cellID), dec.getPosition(), 0.0, cellID, hitType, dec)); + } + //reset hit integration + eDepMap = new HashMap<Long, Double>(); + return hitList; + } + + public void putHits(List<CalorimeterHit> hits) { + //fill the trigger buffers + for (CalorimeterHit hit : hits) { + Double eDep = eDepMap.get(hit.getCellID()); + if (eDep == null) { + eDepMap.put(hit.getCellID(), hit.getRawEnergy()); + } else { + eDepMap.put(hit.getCellID(), eDep + hit.getRawEnergy()); + } + } + } +}
diff -N ECalReadout.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ECalReadout.java 23 Aug 2011 17:08:10 -0000 1.1 @@ -0,0 +1,27 @@
+/* + * SiDigitizer.java + * + * Created on August 22, 2011, 9:20 AM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package org.lcsim.hps.recon.ecal; + +import java.util.List; +import org.lcsim.event.CalorimeterHit; + + +/** + * converts energy deposition from MC to raw hits + * @author meeg + */ +public interface ECalReadout +{ + public String getName(); + + public List<CalorimeterHit> readHits(); + + public void putHits(List<CalorimeterHit> hits); +}
diff -N HPSEcalReadoutDriver.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ HPSEcalReadoutDriver.java 23 Aug 2011 17:08:10 -0000 1.1 @@ -0,0 +1,105 @@
+package org.lcsim.hps.recon.ecal; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.lcsim.event.CalorimeterHit; +import org.lcsim.event.EventHeader; +import org.lcsim.geometry.Detector; +import org.lcsim.geometry.IDDecoder; +import org.lcsim.geometry.subdetector.HPSEcal; +import org.lcsim.geometry.subdetector.HPSEcal2; +import org.lcsim.util.Driver; + +/** + * Performs readout of ECal hits. + * + * @author Sho Uemura <[log in to unmask]> + */ +public class HPSEcalReadoutDriver extends Driver { + + HPSEcal ecal; + String ecalCollectionName; + String ecalName; + String digitizedCollectionName = "EcalDigitizedHits"; + Map<Long, Double> eDepMap = null; + int hitType = 11; + //counts bunches for trigger clock + int clock; + //number of bunches in trigger cycle + int triggerCycle = 4; + + public HPSEcalReadoutDriver() { + } + + public void setDigitizedCollectionName(String digitizedCollectionName) { + this.digitizedCollectionName = digitizedCollectionName; + } + + public void setEcalCollectionName(String ecalCollectionName) { + this.ecalCollectionName = ecalCollectionName; + } + + public void setEcalName(String ecalName) { + this.ecalName = ecalName; + } + + public void setTriggerCycle(int triggerCycle) { + this.triggerCycle = triggerCycle; + } + + public void startOfData() { + if (ecalCollectionName == null) + throw new RuntimeException("The parameter ecalCollectionName was not set!"); + + if (ecalName == null) + throw new RuntimeException("The parameter ecalName was not set!"); + + //initialize clock + clock = 0; + } + + public void detectorChanged(Detector detector) { + // Get the Subdetector. + ecal = (HPSEcal2) detector.getSubdetector(ecalName); + } + + public void process(EventHeader event) { + //System.out.println(this.getClass().getCanonicalName() + " - process"); + //if at the beginning of a readout cycle, reset readout buffers + if (clock % triggerCycle == 0) { + eDepMap = new HashMap<Long, Double>(); + } + + clock++; + // Get the list of ECal hits. + List<CalorimeterHit> hits = event.get(CalorimeterHit.class, ecalCollectionName); + if (hits == null) + throw new RuntimeException("Event is missing ECal hits collection!"); + + //fill trigger buffers + for (CalorimeterHit hit : hits) { + Double eDep = eDepMap.get(hit.getCellID()); + if (eDep == null) { + eDepMap.put(hit.getCellID(), hit.getRawEnergy()); + } else { + eDepMap.put(hit.getCellID(), eDep + hit.getRawEnergy()); + } + } + + //if at the end of a readout cycle, write buffers to hits + if (clock % triggerCycle == 0) { + IDDecoder dec = ecal.getIDDecoder(); + // New CalorimeterHit list to be added to event. + List<CalorimeterHit> digitizedHits = new ArrayList<CalorimeterHit>(); + for (Long cellID : eDepMap.keySet()) { + dec.setID(cellID); + digitizedHits.add(new RawCalorimeterHit(eDepMap.get(cellID), dec.getPosition(), 0.0, cellID, hitType, dec)); + } + + event.put(digitizedCollectionName, digitizedHits, CalorimeterHit.class, 0); + } + } +}
\ No newline at end of file
diff -N RawCalorimeterHit.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ RawCalorimeterHit.java 23 Aug 2011 17:08:10 -0000 1.1 @@ -0,0 +1,37 @@
+package org.lcsim.hps.recon.ecal; + +import org.lcsim.event.base.BaseCalorimeterHit; +import org.lcsim.geometry.IDDecoder; + +/** + * An implementation of CalorimeterHit, with a constructor that sets rawEnergy + * for use in ECalReadout + * + * @author Sho Uemura + */ +public class RawCalorimeterHit extends BaseCalorimeterHit { + + IDDecoder idDecoder; + + /** + * Fully qualified constructor that sets rawEnergy + * + * @param energy Raw energy for this cell + * @param position Global Cartesian coordinate for this cell + * @param time Time of energy deposition + * @param id Cell ID + * @param type Type + */ + public RawCalorimeterHit(double energy, double[] position, double time, long id, int type, IDDecoder idDecoder) { + this.rawEnergy = energy; + this.position = position; + this.time = time; + this.id = id; + this.type = type; + this.idDecoder = idDecoder; + } + + public IDDecoder getIDDecoder() { + return idDecoder; + } +}
\ No newline at end of file
diff -u -r1.6 -r1.7 --- HPSEcal1BitClusterer.java 19 Aug 2011 23:00:10 -0000 1.6 +++ HPSEcal1BitClusterer.java 23 Aug 2011 17:08:10 -0000 1.7 @@ -5,7 +5,6 @@
import java.util.List; import java.util.Map; import java.util.Set;
-import java.util.Iterator;
import org.lcsim.event.CalorimeterHit; import org.lcsim.event.Cluster;
@@ -34,6 +33,7 @@
HPSEcal ecal; String ecalCollectionName; String ecalName;
+ String digitizedCollectionName = "EcalDigitizedHits";
String clusterCollectionName = "EcalClusters"; // Threshold E for discriminator. double hitEMin = .05;
@@ -47,10 +47,7 @@
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;
+ ECalSimpleReadout digitizer = null;
public HPSEcal1BitClusterer() { }
@@ -59,6 +56,10 @@
this.clusterCollectionName = clusterCollectionName; }
+ public void setDigitizedCollectionName(String digitizedCollectionName) { + this.digitizedCollectionName = digitizedCollectionName; + } +
public void setHitEMin(double hitEMin) { this.hitEMin = hitEMin; }
@@ -81,6 +82,7 @@
public void startOfData() { clock = 0;
+ digitizer = new ECalSimpleReadout(ecal);
if (ecalCollectionName == null) { throw new RuntimeException("The parameter ecalCollectionName was not set!"); }
@@ -93,6 +95,7 @@
public void detectorChanged(Detector detector) { // Get the Subdetector. ecal = (HPSEcal2) detector.getSubdetector(ecalName);
+ digitizer.setEcal(ecal);
// Cache ref to neighbor map. neighborMap = ecal.getNeighborMap();
@@ -108,42 +111,22 @@
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); - if (hits == null) { - throw new RuntimeException("Event is missing ECal hits collection!"); - } - - //fill the trigger buffers - for (CalorimeterHit hit : hits) { - 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); - }
+ // Get the list of digitized ECal hits. + List<CalorimeterHit> hits = event.get(CalorimeterHit.class, digitizedCollectionName);
// New Cluster list to be added to event. List<Cluster> clusters = new ArrayList<Cluster>();
- //if at the end of a trigger cycle, run clustering - if (clock % triggerCycle == 0) {
+ //if there are digitized hits, run clustering + if (hits != null) { + // 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();
@@ -152,24 +135,24 @@
// Loop over ECal hits to count hit towers
- for (Long cellID : eDepMap.keySet()) {
+ for (CalorimeterHit hit : hits) {
// Cut on min seed E.
- if (eDepMap.get(cellID) < hitEMin) {
+ if (hit.getCorrectedEnergy() < hitEMin) {
continue; } // Get neighbor crystal IDs.
- Set<Long> neighbors = neighborMap.get(cellID);
+ Set<Long> neighbors = neighborMap.get(hit.getCellID());
if (neighbors == null) { throw new RuntimeException("Oops! Set of neighbors is null!"); }
- Integer hitCount = hitCounts.get(cellID);
+ Integer hitCount = hitCounts.get(hit.getCellID());
if (hitCount == null)
- hitCounts.put(cellID, 1);
+ hitCounts.put(hit.getCellID(), 1);
else
- hitCounts.put(cellID, hitCount + 1);
+ hitCounts.put(hit.getCellID(), hitCount + 1);
// Loop over neighbors to make hit list for cluster. for (Long neighborId : neighbors) {
@@ -327,25 +310,16 @@
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); - }
+ CalorimeterHit hit = hitMap.get(possibleCluster); + if (hit != null && hit.getCorrectedEnergy() > hitEMin) { + cluster.addHit(hit);
} 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); - }
+ hit = hitMap.get(neighborId); + if (hit != null && hit.getCorrectedEnergy() > hitEMin) { + cluster.addHit(hit);
} } clusters.add(cluster);