hps-java/src/main/java/org/lcsim/hps/recon/ecal
diff -N HPSEcalRawConverter.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ HPSEcalRawConverter.java 3 May 2012 00:14:54 -0000 1.1
@@ -0,0 +1,153 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.lcsim.hps.recon.ecal;
+
+import hep.physics.vec.Hep3Vector;
+import org.lcsim.detector.IDetectorElement;
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.event.RawTrackerHit;
+import org.lcsim.geometry.IDDecoder;
+import org.lcsim.geometry.Subdetector;
+
+
+public class HPSEcalRawConverter {
+
+ boolean debug = false;
+ double scale = 0.01;
+ double pedestal = 0.0;
+ double period = 4.0;
+ double dt = 0.0;
+ IDDecoder dec;
+ Subdetector ecal;
+
+
+
+ public HPSEcalRawConverter(Subdetector ecal) {
+ this.ecal = ecal;
+ //this.dec = ecal.getIDDecoder();
+ }
+
+ public double getPedestal() {
+ return pedestal;
+ }
+
+ public void setPedestal(double pedestal) {
+ this.pedestal = pedestal;
+ }
+
+ public double getScale() {
+ return scale;
+ }
+
+ public void setScale(double scale) {
+ this.scale = scale;
+ }
+
+ public IDDecoder getIDDecoder() {
+ return dec;
+ }
+
+ public void setIDDecoder(IDDecoder dec) {
+ this.dec = dec;
+ }
+
+ public void setSubDetector(Subdetector d) {
+ this.ecal = d;
+ }
+
+ public int AtoD(double amplitude, long cellID) {
+ return (int) Math.floor((amplitude + pedestal) / scale);
+ }
+
+ public double DtoA(int amplitude, long cellID) {
+ return scale * (amplitude + 0.5) + pedestal;
+ }
+
+ public int getPedestal(RawTrackerHit hit) {
+ //HPSEcalConditions cond = new HPSEcalConditions();
+ if (!HPSEcalConditions.pedestalsLoaded()) {
+ HPSEcalConditions.loadPedestals();
+ }
+ return HPSEcalConditions.physicalToPedestal(hit.getCellID());
+
+ }
+
+
+ //public short sumADC(RawTrackerHit hit, double scale, double pedestal) {
+ public short sumADC(RawTrackerHit hit) {
+ //Sum all pedestal subtracted ADC values
+ //return scale * (amplitude + 0.5) + pedestal;
+ if ( debug ) {
+ System.out.println("Summing ADC for hit: " + hit.toString());
+ }
+ int pedestal = getPedestal(hit);
+ short sum = 0;
+ short samples[] = hit.getADCValues();
+ for ( int isample=0; isample<6; ++isample) {
+ sum += (samples[isample] - pedestal);
+ if ( debug ) {
+ System.out.println("Sample " + isample + " " + samples[isample] + " pedestal " + pedestal + " (" + sum + ")");
+ }
+ }
+ return sum;
+
+ }
+
+// public IExpandedIdentifier getIdentifier(short x, short y) {
+//
+// IIdentifierHelper helper = ecal.getDetectorElement().getIdentifierHelper();
+// IExpandedIdentifier expId = new ExpandedIdentifier(helper.getIdentifierDictionary().getNumberOfFields());
+// expId.setValue(helper.getFieldIndex("system"), ecal.getSystemID());
+//
+// expId.setValue(helper.getFieldIndex("ix"), x);
+// expId.setValue(helper.getFieldIndex("iy"), y);
+// return expId;
+//
+// }
+
+ public CalorimeterHit HitDtoA(RawTrackerHit hit) {
+ //dec.setID(hit.getCellID());
+ //return new HPSRawCalorimeterHit(DtoA(hit.getAmplitude(), hit.getCellID()), dec.getPosition(), period * hit.getTimeStamp() + dt, hit.getCellID(), 0);
+ double time = 0.0;
+ long id = hit.getCellID();
+ int type = 0;
+ //System.out.println("id " + id);
+
+ double rawEnergy = (double) sumADC(hit);
+ //IExpandedIdentifier expId = getIdentifier();
+// IDetectorElement detElem;
+// try {
+// detElem = hit.getDetectorElement();
+// }
+// catch (NullPointerException exc) {
+//
+// }
+//
+
+
+
+ //System.out.println(hit.getDetectorElement().getName());
+ //System.out.println(hit.getDetectorElement().getGeometry().getPosition().toString());
+
+ Hep3Vector pvec = hit.getDetectorElement().getGeometry().getPosition();
+ double [] pos = new double[3];
+ pos[0] = pvec.x();
+ pos[1] = pvec.y();
+ pos[2] = pvec.z();
+ CalorimeterHit h = new HPSRawCalorimeterHit(rawEnergy+0.0000001, null, time, id, 0);
+ //System.out.println(" raw energy " + rawEnergy);
+ return h;
+ }
+
+// public CalorimeterHit HitDtoA(RawCalorimeterHit hit) {
+// dec.setID(hit.getCellID());
+// return new HPSRawCalorimeterHit(DtoA(hit.getAmplitude(), hit.getCellID()), dec.getPosition(), period * hit.getTimeStamp() + dt, hit.getCellID(), 0);
+// }
+
+// public RawCalorimeterHit HitAtoD(CalorimeterHit hit) {
+// dec.setID(hit.getCellID());
+// return new HPSFADCCalorimeterHit(hit.getCellID(), AtoD(hit.getRawEnergy(), hit.getCellID()), (int) Math.round(hit.getTime() / period), 0);
+// }
+}
hps-java/src/main/java/org/lcsim/hps/recon/ecal
diff -N HPSEcalRawConverterDriver.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ HPSEcalRawConverterDriver.java 3 May 2012 00:14:54 -0000 1.1
@@ -0,0 +1,109 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+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.RawTrackerHit;
+import org.lcsim.geometry.Detector;
+import org.lcsim.geometry.Subdetector;
+import org.lcsim.util.Driver;
+
+/**
+ *
+ * @author Sho Uemura <[log in to unmask]>
+ * @version $Id: HPSEcalRawConverterDriver.java,v 1.1 2012/05/03 00:14:54 phansson Exp $
+ */
+public class HPSEcalRawConverterDriver extends Driver {
+
+ HPSEcalRawConverter converter = null;
+ Subdetector ecal;
+ String rawCollectionName = "EcalReadoutHits";
+ String ecalName;
+ String ecalReadoutName = "EcalHits";
+ String ecalCollectionName = "EcalCalHits";
+ boolean debug = false;
+
+
+ public HPSEcalRawConverterDriver() {
+ converter = new HPSEcalRawConverter(null);
+
+ }
+
+ public void setPedestal(double pedestal) {
+ converter.setPedestal(pedestal);
+ }
+
+ public void setScale(double scale) {
+ converter.setScale(scale);
+ }
+
+ public void setEcalCollectionName(String ecalCollectionName) {
+ this.ecalCollectionName = ecalCollectionName;
+ }
+
+ public void setEcalName(String ecalName) {
+ this.ecalName = ecalName;
+ }
+
+ public void setRawCollectionName(String rawCollectionName) {
+ this.rawCollectionName = rawCollectionName;
+ }
+
+
+
+
+ @Override
+ 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!");
+ }
+ }
+
+ @Override
+ public void detectorChanged(Detector detector) {
+ // Get the Subdetector.
+ ecal = (Subdetector) detector.getSubdetector(ecalName);
+ //converter.setIDDecoder(ecal.getIDDecoder());
+ converter.setSubDetector(ecal);
+ }
+
+ @Override
+ public void process(EventHeader event) {
+ // Get the list of ECal hits.
+ List<RawTrackerHit> hits = event.get(RawTrackerHit.class, rawCollectionName);
+ if (hits == null) {
+ throw new RuntimeException("Event is missing ECal \"tracker hits\" collection!");
+ }
+
+ ArrayList<CalorimeterHit> newHits = new ArrayList<CalorimeterHit>();
+
+ for (RawTrackerHit hit : hits) {
+ //if (debug) System.out.println("Try to convert hit: " + hit.toString());
+ //newHits.add(converter.HitDtoA(hit));
+ //if (debug) System.out.println("Added hit (rawEnergy "+ newHits.get(newHits.size()-1).getRawEnergy() + "): " + newHits.get(newHits.size()-1).toString());
+ }
+ int flags = 0;
+ event.put(ecalCollectionName, newHits, CalorimeterHit.class, flags, ecalReadoutName);
+ String s = ecalCollectionName; //"EcalCalHits";
+
+ System.out.println(" char: " + event.hasCollection(CalorimeterHit.class, "EcalCalHits"));
+ System.out.println(" str: " + event.hasCollection(CalorimeterHit.class, ecalCollectionName));
+
+ List<CalorimeterHit> ll = event.get(CalorimeterHit.class,s);
+
+ System.out.println("ll size " + ll.size());
+ List<List<CalorimeterHit>> lll = event.get(CalorimeterHit.class);
+ System.out.println("lll size " + lll.size());
+
+
+ }
+}