hps-java/src/main/java/org/lcsim/hps/recon/tracking
diff -u -r1.11 -r1.12
--- HPSDataProcessingModule.java 10 Apr 2012 01:00:13 -0000 1.11
+++ HPSDataProcessingModule.java 21 Apr 2012 07:32:25 -0000 1.12
@@ -10,7 +10,6 @@
//--- org.lcsim ---//
import java.util.Set;
-import org.lcsim.detector.IDetectorElement;
import org.lcsim.detector.IReadout;
import org.lcsim.detector.tracker.silicon.SiSensor;
import org.lcsim.event.EventHeader;
@@ -20,39 +19,55 @@
import org.lcsim.geometry.Detector;
import org.lcsim.util.Driver;
+//--- Constants ---//
+import static org.lcsim.hps.recon.tracking.HPSSVTConstants.SVT_TOTAL_FPGAS;
+import static org.lcsim.hps.recon.tracking.HPSSVTConstants.TOTAL_APV25_CHANNELS;
+import static org.lcsim.hps.recon.tracking.HPSSVTConstants.TOTAL_APV25_PER_HYBRID;
+import static org.lcsim.hps.recon.tracking.HPSSVTConstants.TOTAL_HYBRIDS_PER_FPGA;
+
/**
*
* @author Omar Moreno <[log in to unmask]>
- * @version $Id: HPSDataProcessingModule.java,v 1.11 2012/04/10 01:00:13 meeg Exp $
+ * @version $Id: HPSDataProcessingModule.java,v 1.12 2012/04/21 07:32:25 omoreno Exp $
*/
public class HPSDataProcessingModule extends Driver {
+
+ // A map relating a sensor to all sample blocks collected from that sensor
+ Map<SiSensor, Map<Integer, List<Double>>> sensorToSamplesMap;
- Map<Long, Map<Integer, List<Double>>> sensorToBlocksMap;
// Relate a channel to its six samples
Map<Integer, List<Double>> channelToBlock;
+
// Relate a sensor Identifier to the actual sensor
Map<Long, SiSensor> sensorMap = new HashMap<Long, SiSensor>();
+
// Collection of all sensors
Set<SiSensor> sensorSet = new HashSet<SiSensor>();
+
// Collections of RawTrackerHits
List<RawTrackerHit> rawHits; // Cuts are applied
- List<RawTrackerHit> rawHitsNoCuts; // No cuts are applied to samples
+ List<RawTrackerHit> rawHitsNoCuts; // No cuts are applied to samples
+
// Collection of all SVT data
List<HPSSVTData> svtData;
List<HPSSVTData> svtFpgaData;
- // 1-5 rms noise [ADC Counts] <--- This is going to change
-// int[] noiseThreshold = {1657, 1675, 1692, 1709, 1728};
+ List<Double> samples;
+
int numberOfSamples = 0; // Total number of APV25 samples
int nSamplesAboveThresh = 3; // Number of samples above noise threshold
int pedestal = 1638; // [ADC counts] For now, all channels have the same pedestal
int flags = 0; //
int noise = 18; // [ADC Counts] RMS noise
int noiseThreshold = 3; // Units of RMS noise
+ int physicalChannel;
+
private boolean thresholdCut = false; // Apply threshold cut?
private boolean tailCut = false; // Apply tail cut?
- private boolean noiseSuppression = false; // Apply noise supression?
+ private boolean noiseSuppression = false; // Apply noise suppression?
+ boolean debug = true;
+
double[] apv25DataStream;
- List<Double> samples;
+
String RawTrackerHitsCollectionName = "RawTrackerHits";
String RawTrackerHitsNoCutsCollectionName = "RawTrackerHitsNoCuts";
String svtCollectionName = "SVTData";
@@ -62,7 +77,7 @@
*/
public HPSDataProcessingModule() {
channelToBlock = new HashMap<Integer, List<Double>>();
- sensorToBlocksMap = new HashMap<Long, Map<Integer, List<Double>>>();
+ sensorToSamplesMap = new HashMap<SiSensor, Map<Integer, List<Double>>>();
rawHits = new ArrayList<RawTrackerHit>();
rawHitsNoCuts = new ArrayList<RawTrackerHit>();
svtData = new ArrayList<HPSSVTData>();
@@ -75,20 +90,9 @@
@Override
public void detectorChanged(Detector detector) {
- // Get the tracker
- IDetectorElement tracker = detector.getDetectorElement().findDetectorElement("Tracker");
-
- // Fill the collection of sensors
- sensorSet.addAll(tracker.findDescendants(SiSensor.class));
-
- for (SiSensor sensor : sensorSet) {
-
- // Map a sensor to its identifier
- sensorMap.put(sensor.getIdentifier().getValue(), sensor);
-
+ for (SiSensor sensor : HPSSVTDAQMaps.sensors) {
// Map a sensor to its corresponding samples
- sensorToBlocksMap.put(sensor.getIdentifier().getValue(),
- new HashMap<Integer, List<Double>>());
+ sensorToSamplesMap.put(sensor, new HashMap<Integer, List<Double>>());
}
}
@@ -159,43 +163,37 @@
* A map relating a sensor to the digital samples readout from the
* sensor
*/
- public void addSample(Map<Long, Map<Integer, double[]>> sensorToDigitalMap) {
+ public void addSample(Map<SiSensor, Map<Integer, double[]>> sensorToDigitalMap) {
/*
- * Long: Sensor Identifier
* Integer: Chip Number
- * double[]: APV25 Data Stream
+ * double[]: APV25 Data Analog Data
*/
- int channelN = 0;
+ int physicalChannel;
// Loop through the list of all sensors
- for (Map.Entry<Long, Map<Integer, double[]>> sensor : sensorToDigitalMap.entrySet()) {
+ for (Map.Entry<SiSensor, Map<Integer, double[]>> sensor : sensorToDigitalMap.entrySet()) {
// Loop through all APV25s
- for (Map.Entry<Integer, double[]> sample : sensor.getValue().entrySet()) {
+ for (Map.Entry<Integer, double[]> chipData : sensor.getValue().entrySet()) {
// Copy the sample to avoid concurrent modification
- apv25DataStream = sample.getValue();
+ apv25DataStream = chipData.getValue();
// Strip the APV25 data stream of all header information
- // This needs to change so that the real chip address can be
- // extracted ...
apv25DataStream = Arrays.copyOfRange(apv25DataStream, 12, apv25DataStream.length - 1);
// Loop through all channels
for (int channel = 0; channel < apv25DataStream.length; channel++) {
- channelN = channel + sample.getKey() * 128;
+ physicalChannel = channel + chipData.getKey() * 128;
- // Check if a block has been created for this channel. If
- // not create it
- if (!sensorToBlocksMap.get(sensor.getKey()).containsKey(channelN)) {
- sensorToBlocksMap.get(sensor.getKey()).put(channelN, new ArrayList<Double>(6));
+ // Check if a block has been created for this channel. If not create it
+ if (!sensorToSamplesMap.get(sensor.getKey()).containsKey(physicalChannel)) {
+ sensorToSamplesMap.get(sensor.getKey()).put(physicalChannel, new ArrayList<Double>(6));
}
-
- sensorToBlocksMap.get(sensor.getKey()).get(channelN).add(apv25DataStream[channel]);
-
+ sensorToSamplesMap.get(sensor.getKey()).get(physicalChannel).add(apv25DataStream[channel]);
}
}
}
@@ -208,76 +206,89 @@
*/
public void findHits() {
- int fpgaAddress = 0;
- int hybridNumber = 0;
- int apvNumber = 0;
-
+ int fpgaNumber, hybridNumber, apvNumber, rawChannel;
+
// Clear the list of raw tracker hits
rawHits.clear();
rawHitsNoCuts.clear();
svtData.clear();
// Loop through all sensors and the corresponding blocks
- for (Map.Entry<Long, Map<Integer, List<Double>>> sensor : sensorToBlocksMap.entrySet()) {
-
- // Get the FPGA address
- fpgaAddress = HPSSVTDAQMaps.sensorToDAQPair.get(sensorMap.get(sensor.getKey())).getSecondElement();
+ for (Map.Entry<SiSensor, Map<Integer, List<Double>>> sensor : sensorToSamplesMap.entrySet()) {
- for (Map.Entry<Integer, List<Double>> block : sensor.getValue().entrySet()) {
+ // Get the FPGA number
+ fpgaNumber = HPSSVTDAQMaps.sensorToDAQPair.get(sensor.getKey()).getSecondElement();
+ if(fpgaNumber > SVT_TOTAL_FPGAS || fpgaNumber < 0)
+ throw new RuntimeException("FPGA Number out of range!");
+ if(debug) System.out.println(this.getClass().getSimpleName() + ": FPGA Number: " + fpgaNumber);
+
+ for (Map.Entry<Integer, List<Double>> samples : sensor.getValue().entrySet()) {
short[] adc = new short[6];
// Convert ADC value to a short
- for (int index = 0; index < adc.length; index++) {
- adc[index] = block.getValue().get(index).shortValue();
- }
+ for (int index = 0; index < adc.length; index++)
+ adc[index] = samples.getValue().get(index).shortValue();
- // Create RawTrackerHits from all hits before applying cuts
- RawTrackerHit newHit = makeRawTrackerHit(block.getKey(), sensorMap.get(sensor.getKey()), adc);
- rawHitsNoCuts.add(newHit);
-
- // Check if a block has the appropriate number of blocks above
- // threshold
+ // If a strip had any charge deposited on it, create a RawTrackerHit
+ if(!(samplesAboveThreshold(adc) >= 1)){
+ samples.getValue().clear();
+ continue;
+ }
+
+ RawTrackerHit rawHit = makeRawTrackerHit(samples.getKey(), sensor.getKey(), adc);
+ rawHitsNoCuts.add(rawHit);
+
+ // Check if a block has the appropriate number of blocks above threshold
if (thresholdCut && !(samplesAboveThreshold(adc) >= nSamplesAboveThresh)) {
- block.getValue().clear();
+ samples.getValue().clear();
continue;
}
// Apply the tail cut
if (tailCut && !tailCut(adc)) {
- block.getValue().clear();
+ samples.getValue().clear();
continue;
}
// Apply noise suppression cut
if (noiseSuppression && !noiseSuppressionCut(adc)) {
- block.getValue().clear();
+ samples.getValue().clear();
continue;
}
// If all cuts are satisfied, add the hit to the list of hits to be saved
- rawHits.add(newHit);
+ rawHits.add(rawHit);
// Get the hybrid number
- hybridNumber = HPSSVTDAQMaps.sensorToDAQPair.get(sensorMap.get(sensor.getKey())).getFirstElement();
-
- // Find the APV number
- apvNumber = (int) Math.floor(block.getKey() / 128);
-
+ hybridNumber = HPSSVTDAQMaps.sensorToDAQPair.get(sensor.getKey()).getFirstElement();
+ if(hybridNumber > TOTAL_HYBRIDS_PER_FPGA || hybridNumber < 0)
+ throw new RuntimeException("Hybrid number is out of range!");
+ if(debug) System.out.println(this.getClass().getSimpleName() + ": Hybrid Number: " + hybridNumber);
+
+ // Find the APV number. Note that strip numbering is from 639 to 0
+ apvNumber = (TOTAL_APV25_PER_HYBRID - 1) - (int) Math.floor(samples.getKey()/128);
+ if(apvNumber > TOTAL_APV25_PER_HYBRID || apvNumber < 0)
+ throw new RuntimeException("APV25 Number out of range!");
+ if(debug) System.out.println(this.getClass().getSimpleName() + ": APV Number: " + apvNumber);
+
+ // Find the raw channel number from the physical channel
+ rawChannel = samples.getKey() - (TOTAL_APV25_CHANNELS*TOTAL_APV25_PER_HYBRID - 1)
+ + apvNumber*TOTAL_APV25_CHANNELS + (TOTAL_APV25_CHANNELS - 1);
+ if(rawChannel > TOTAL_APV25_CHANNELS || rawChannel < 0)
+ throw new RuntimeException("APV25 Channel " + rawChannel + " out of range!");
+ if(debug) System.out.println(this.getClass().getSimpleName() + ": Raw Channel Number: " + rawChannel);
+
// Create an svtData packet
- svtData.add(new HPSSVTData(hybridNumber, apvNumber, block.getKey() % 128, fpgaAddress, adc));
- svtFpgaData.add(new HPSSVTData(hybridNumber, apvNumber, block.getKey() % 128, fpgaAddress, adc));
-
- block.getValue().clear();
+ svtData.add(new HPSSVTData(hybridNumber, apvNumber, rawChannel , fpgaNumber, adc));
+
+ samples.getValue().clear();
}
- HPSSVTDataBuffer.addToBuffer(svtFpgaData, fpgaAddress);
-
- // Clear data buffer.
- svtFpgaData.clear();
+ HPSSVTDataBuffer.addToBuffer(svtData, fpgaNumber);
}
- System.out.println(this.getClass().getName() + ": Total RawTrackerHits before cuts: " + rawHitsNoCuts.size());
- System.out.println(this.getClass().getName() + ": Total RawTrackerHits: " + rawHits.size());
- System.out.println(this.getClass().getName() + ": Total SVTData: " + svtData.size());
+ if(debug) System.out.println(this.getClass().getName() + ": Total RawTrackerHits before cuts: " + rawHitsNoCuts.size());
+ if(debug) System.out.println(this.getClass().getName() + ": Total RawTrackerHits: " + rawHits.size());
+ if(debug) System.out.println(this.getClass().getName() + ": Total SVTData: " + svtData.size());
}
/**