hps-java/src/main/java/org/lcsim/hps/recon/ecal
diff -N HPSEcalConverterDriver.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ HPSEcalConverterDriver.java 21 Nov 2012 00:29:53 -0000 1.6
@@ -0,0 +1,86 @@
+package org.lcsim.hps.recon.ecal;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.RawCalorimeterHit;
+import org.lcsim.util.Driver;
+import org.lcsim.util.lcio.LCIOConstants;
+
+/**
+ *
+ * @author Sho Uemura <[log in to unmask]>
+ * @version $Id: HPSEcalConverterDriver.java,v 1.6 2012/11/21 00:29:53 meeg Exp $
+ */
+public class HPSEcalConverterDriver extends Driver {
+
+ String rawCollectionName;
+ String ecalReadoutName = "EcalHits";
+ String ecalCollectionName = "EcalCorrectedHits";
+ int flags;
+ double scale = 1.0;
+// double pedestal = 0.0;
+ double period = 4.0;
+ double dt = 0.0;
+
+ public HPSEcalConverterDriver() {
+ flags = 0;
+ flags += 1 << LCIOConstants.CHBIT_LONG; //store position
+ flags += 1 << LCIOConstants.RCHBIT_ID1; //store cell ID
+ }
+
+// public void setPedestal(double pedestal) {
+// this.pedestal = pedestal;
+// }
+ public void setScale(double scale) {
+ this.scale = scale;
+ }
+
+ public void setEcalCollectionName(String ecalCollectionName) {
+ this.ecalCollectionName = ecalCollectionName;
+ }
+
+ public void setRawCollectionName(String rawCollectionName) {
+ this.rawCollectionName = rawCollectionName;
+ }
+
+ @Override
+ public void startOfData() {
+ if (ecalCollectionName == null) {
+ throw new RuntimeException("The parameter ecalCollectionName was not set!");
+ }
+ }
+
+ @Override
+ public void process(EventHeader event) {
+ if (event.hasCollection(HPSFADCCalorimeterHit.class, rawCollectionName)) {
+ // Get the list of ECal hits.
+ List<HPSFADCCalorimeterHit> hits = event.get(HPSFADCCalorimeterHit.class, rawCollectionName);
+
+ ArrayList<CalorimeterHit> newHits = new ArrayList<CalorimeterHit>();
+
+ for (HPSFADCCalorimeterHit hit : hits) {
+ newHits.add(HitDtoA(hit));
+ }
+
+ event.put(ecalCollectionName, newHits, CalorimeterHit.class, flags, ecalReadoutName);
+ }
+ }
+
+// private int AtoD(double amplitude, long cellID) {
+// return (int) Math.round(amplitude / scale);
+// }
+
+ private double DtoA(int amplitude, long cellID) {
+ return scale * amplitude;
+ }
+
+ private CalorimeterHit HitDtoA(RawCalorimeterHit hit) {
+ return new HPSRawCalorimeterHit(DtoA(hit.getAmplitude(), hit.getCellID()), period * hit.getTimeStamp() + dt, hit.getCellID(), 0);
+ }
+
+// private RawCalorimeterHit HitAtoD(CalorimeterHit hit) {
+// return new HPSFADCCalorimeterHit(hit.getCellID(), AtoD(hit.getRawEnergy(), hit.getCellID()), (int) Math.round(hit.getTime() / period), 0);
+// }
+}