Print

Print


Commit in hps-java/src/main/java/org/lcsim/hps/recon/ecal on MAIN
HPSEcalFADCReadoutDriver.java+104-471.10 -> 1.11
implemented all FADC readout modes

hps-java/src/main/java/org/lcsim/hps/recon/ecal
HPSEcalFADCReadoutDriver.java 1.10 -> 1.11
diff -u -r1.10 -r1.11
--- HPSEcalFADCReadoutDriver.java	4 Apr 2012 20:43:37 -0000	1.10
+++ HPSEcalFADCReadoutDriver.java	6 Apr 2012 00:53:19 -0000	1.11
@@ -14,6 +14,7 @@
 import org.lcsim.event.RawTrackerHit;
 import org.lcsim.event.base.BaseRawCalorimeterHit;
 import org.lcsim.event.base.BaseRawTrackerHit;
+import org.lcsim.geometry.Detector;
 import org.lcsim.geometry.subdetector.HPSEcal3;
 import org.lcsim.hps.util.ClockSingleton;
 import org.lcsim.hps.util.RingBuffer;
@@ -24,7 +25,7 @@
  * Simulates time evolution of preamp output pulse.
  *
  * @author Sho Uemura <[log in to unmask]>
- * @version $Id: HPSEcalFADCReadoutDriver.java,v 1.10 2012/04/04 20:43:37 meeg Exp $
+ * @version $Id: HPSEcalFADCReadoutDriver.java,v 1.11 2012/04/06 00:53:19 meeg Exp $
  */
 public class HPSEcalFADCReadoutDriver extends HPSEcalReadoutDriver<RawCalorimeterHit> {
 
@@ -48,16 +49,16 @@
 	private int delay0 = 32;
 	//start of readout window relative to trigger time (in readout cycles)
 	//in FADC documentation, "Programmable Latency" or PL
-	private int readoutLatency = 500;
+	private int readoutLatency = 200;
 	//number of ADC samples to read out
 	//in FADC documentation, "Programmable Trigger Window" or PTW
-	private int readoutWindow = 256;
-	//number of ADC samples to read out before each pulse maximum
+	private int readoutWindow = 200;
+	//number of ADC samples to read out before each rising threshold crossing
 	//in FADC documentation, "number of samples before" or NSB
-	private int numSamplesBefore = 5;
-	//number of ADC samples to read out before each pulse maximum
+	private int numSamplesBefore = 10;
+	//number of ADC samples to read out after each rising threshold crossing
 	//in FADC documentation, "number of samples before" or NSA
-	private int numSamplesAfter = 10;
+	private int numSamplesAfter = 50;
 	private HPSEcalConverter converter = null;
 	//output buffer for hits
 	private LinkedList<HPSFADCCalorimeterHit> buffer = new LinkedList<HPSFADCCalorimeterHit>();
@@ -116,14 +117,12 @@
 
 	public void setBufferLength(int bufferLength) {
 		this.bufferLength = bufferLength;
-		eDepMap = new HashMap<Long, RingBuffer>();
-		pipelineMap = new HashMap<Long, FADCPipeline>();
+		resetFADCBuffers();
 	}
 
 	public void setPipelineLength(int pipelineLength) {
 		this.pipelineLength = pipelineLength;
-		eDepMap = new HashMap<Long, RingBuffer>();
-		pipelineMap = new HashMap<Long, FADCPipeline>();
+		resetFADCBuffers();
 	}
 
 	@Override
@@ -133,10 +132,7 @@
 			RingBuffer eDepBuffer = eDepMap.get(cellID);
 
 			FADCPipeline pipeline = pipelineMap.get(cellID);
-			if (pipeline == null) {
-				pipeline = new FADCPipeline(pipelineLength, converter.AtoD(0.0, cellID));
-				pipelineMap.put(cellID, pipeline);
-			}
+			pipeline.step();
 			pipeline.writeValue(converter.AtoD(eDepBuffer.currentValue(), cellID));
 
 			Double sum = sumMap.get(cellID);
@@ -198,49 +194,96 @@
 	@Override
 	protected void processTrigger(EventHeader event) {
 //		event.put(ecalReadoutCollectionName, readWindow(), RawTrackerHit.class, 0, ecalReadoutName);
-		event.put(ecalReadoutCollectionName, readIntegral(), RawCalorimeterHit.class, 0, ecalReadoutName);
+//		event.put(ecalReadoutCollectionName, readPulses(), RawTrackerHit.class, 0, ecalReadoutName);
+		event.put(ecalReadoutCollectionName, readIntegrals(), RawCalorimeterHit.class, 0, ecalReadoutName);
+	}
+
+	protected short[] getWindow(long cellID) {
+		FADCPipeline pipeline = pipelineMap.get(cellID);
+		boolean samplesAboveThreshold = false;
+		short[] adcValues = new short[readoutWindow];
+		for (int i = 0; i < readoutWindow; i++) {
+			adcValues[i] = (short) pipeline.getValue(readoutLatency - i - 1);
+//			if (adcValues[i] != 0) {
+//				System.out.println("getWindow: " + adcValues[i] + " at i = " + i);
+//			}
+			if (adcValues[i] > converter.AtoD(threshold, cellID)) {
+				samplesAboveThreshold = true;
+			}
+		}
+		if (samplesAboveThreshold) {
+			return adcValues;
+		} else {
+			return null;
+		}
 	}
 
 	protected List<RawTrackerHit> readWindow() {
 		System.out.println("Reading FADC data");
 		List<RawTrackerHit> hits = new ArrayList<RawTrackerHit>();
+		for (Long cellID : pipelineMap.keySet()) {
+			short[] adcValues = getWindow(cellID);
+			if (adcValues != null) {
+				hits.add(new BaseRawTrackerHit(cellID, 0, adcValues));
+			}
+		}
+		return hits;
+	}
 
-		Set<Long> cells = ((HPSEcal3) ecal).getNeighborMap().keySet();
-		for (Long cellID : cells) {
-			FADCPipeline pipeline = pipelineMap.get(cellID);
-			short[] adcValues = new short[readoutWindow];
-			if (pipeline == null) {
-				for (int i = 0; i < readoutWindow; i++) {
-					adcValues[i] = (short) converter.AtoD(0.0, cellID);
-				}
-			} else {
+	protected List<RawTrackerHit> readPulses() {
+		System.out.println("Reading FADC data");
+		List<RawTrackerHit> hits = new ArrayList<RawTrackerHit>();
+		for (Long cellID : pipelineMap.keySet()) {
+			short[] window = getWindow(cellID);
+			short[] adcValues = null;
+			int pointerOffset = 0;
+			int numSamplesToRead = 0;
+			int thresholdCrossing = 0;
+			if (window != null) {
 				for (int i = 0; i < readoutWindow; i++) {
-					adcValues[i] = (short) pipeline.getValue(readoutLatency - i);
+					if (numSamplesToRead != 0) {
+						adcValues[adcValues.length-numSamplesToRead] = window[i - pointerOffset];
+						numSamplesToRead--;
+						if (numSamplesToRead == 0) {
+							hits.add(new BaseRawTrackerHit(cellID, thresholdCrossing, adcValues));
+						}
+					} else if ((i == 0 || window[i - 1] <= converter.AtoD(threshold, cellID)) && window[i] > converter.AtoD(threshold, cellID)) {
+						thresholdCrossing = i;
+						pointerOffset = Math.min(numSamplesBefore, i);
+						numSamplesToRead = pointerOffset + Math.min(numSamplesAfter, readoutWindow - i - pointerOffset - 1);
+						adcValues = new short[numSamplesToRead];
+					}
 				}
 			}
-			hits.add(new BaseRawTrackerHit(cellID, 0, adcValues));
 		}
 		return hits;
 	}
 
-	protected List<RawCalorimeterHit> readIntegral() { //TODO: integration algorithm is totally bogus
+	protected List<RawCalorimeterHit> readIntegrals() {
 		System.out.println("Reading FADC data");
 		List<RawCalorimeterHit> hits = new ArrayList<RawCalorimeterHit>();
-
-		Set<Long> cells = ((HPSEcal3) ecal).getNeighborMap().keySet();
-		for (Long cellID : cells) {
-			FADCPipeline pipeline = pipelineMap.get(cellID);
+		for (Long cellID : pipelineMap.keySet()) {
+			short[] window = getWindow(cellID);
 			int adcSum = 0;
-			if (pipeline == null) {
+			int pointerOffset = 0;
+			int numSamplesToRead = 0;
+			int thresholdCrossing = 0;
+			if (window != null) {
 				for (int i = 0; i < readoutWindow; i++) {
-					adcSum += converter.AtoD(0.0, cellID);
-				}
-			} else {
-				for (int i = 0; i < readoutWindow; i++) {
-					adcSum += pipeline.getValue(readoutLatency - i);
+					if (numSamplesToRead != 0) {
+						adcSum += window[i - pointerOffset];
+						numSamplesToRead--;
+						if (numSamplesToRead == 0) {
+							hits.add(new BaseRawCalorimeterHit(cellID, adcSum, thresholdCrossing));
+						}
+					} else if ((i == 0 || window[i - 1] <= converter.AtoD(threshold, cellID)) && window[i] > converter.AtoD(threshold, cellID)) {
+						thresholdCrossing = i;
+						pointerOffset = Math.min(numSamplesBefore, i);
+						numSamplesToRead = pointerOffset + Math.min(numSamplesAfter, readoutWindow - i - pointerOffset - 1);
+						adcSum = 0;
+					}
 				}
 			}
-			hits.add(new BaseRawCalorimeterHit(cellID, adcSum, 0));
 		}
 		return hits;
 	}
@@ -250,11 +293,6 @@
 		//fill the readout buffers
 		for (CalorimeterHit hit : hits) {
 			RingBuffer eDepBuffer = eDepMap.get(hit.getCellID());
-			if (eDepBuffer == null) {
-				eDepBuffer = new RingBuffer(bufferLength);
-				eDepMap.put(hit.getCellID(), eDepBuffer);
-				pipelineMap.put(hit.getCellID(), new FADCPipeline(pipelineLength, converter.AtoD(0.0, hit.getCellID())));
-			}
 			for (int i = 0; i < bufferLength; i++) {
 				eDepBuffer.addToCell(i, hit.getRawEnergy() * pulseAmplitude((i + 1) * readoutPeriod + readoutTime() - (ClockSingleton.getTime() + hit.getTime())));
 			}
@@ -264,12 +302,31 @@
 	@Override
 	protected void initReadout() {
 		//initialize buffers
-		eDepMap = new HashMap<Long, RingBuffer>();
-		pipelineMap = new HashMap<Long, FADCPipeline>();
 		sumMap = new HashMap<Long, Double>();
 		timeMap = new HashMap<Long, Integer>();
 		outputQueue = new PriorityQueue(20, new HPSFADCCalorimeterHit.TimeComparator());
 		pulseIntegral = t0 * Math.E / readoutPeriod;
+		resetFADCBuffers();
+	}
+
+	@Override
+	public void detectorChanged(Detector detector) {
+		super.detectorChanged(detector);
+		resetFADCBuffers();
+	}
+
+	private boolean resetFADCBuffers() {
+		if (ecal == null) {
+			return false;
+		}
+		eDepMap = new HashMap<Long, RingBuffer>();
+		pipelineMap = new HashMap<Long, FADCPipeline>();
+		Set<Long> cells = ((HPSEcal3) ecal).getNeighborMap().keySet();
+		for (Long cellID : cells) {
+			eDepMap.put(cellID, new RingBuffer(bufferLength));
+			pipelineMap.put(cellID, new FADCPipeline(pipelineLength, converter.AtoD(0.0, cellID)));
+		}
+		return true;
 	}
 
 	private double pulseAmplitude(double time) {
@@ -328,7 +385,7 @@
 
 		//return content of specified cell (pos=0 for current cell)
 		public int getValue(int pos) {
-			if (pos > size || pos < 0) {
+			if (pos >= size || pos < 0) {
 				throw new ArrayIndexOutOfBoundsException();
 			}
 			return array[((ptr - pos) % size + size) % size];
CVSspam 0.2.12


Use REPLY-ALL to reply to list

To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1