Commit in hps-java/src/main/java/org/lcsim/hps/recon/tracking on MAIN | |||
HPSDataProcessingModule.java | +197 | -94 | 1.1 -> 1.2 |
Improved sample blocking; Now creates RawTrackerHits
diff -u -r1.1 -r1.2 --- HPSDataProcessingModule.java 12 Jan 2012 22:41:29 -0000 1.1 +++ HPSDataProcessingModule.java 30 Jan 2012 00:36:06 -0000 1.2 @@ -1,135 +1,134 @@
package org.lcsim.hps.recon.tracking;
+//--- Java ---// +import java.lang.Integer;
import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List; import java.util.Map;
+import java.util.Queue; + +//--- org.lcsim ---// +import java.util.Set;
import java.util.SortedMap; import java.util.TreeMap;
+import org.lcsim.detector.IDetectorElement; +import org.lcsim.detector.tracker.silicon.SiSensor;
import org.lcsim.event.EventHeader;
+import org.lcsim.event.RawTrackerHit; +import org.lcsim.event.SimTrackerHit; +import org.lcsim.event.base.BaseRawTrackerHit; +import org.lcsim.geometry.Detector;
import org.lcsim.util.Driver;
+import org.lcsim.util.aida.AIDA;
/** * * @author Omar Moreno <[log in to unmask]>
- * @version $Id: HPSDataProcessingModule.java,v 1.1 2012/01/12 22:41:29 omoreno Exp $
+ * @version $Id: HPSDataProcessingModule.java,v 1.2 2012/01/30 00:36:06 omoreno Exp $
*/ public class HPSDataProcessingModule extends Driver {
- - SortedMap<Integer, Map<Integer, double[]>> samples;
Map<Integer, List<Double>> blocks;
- Integer sampleNumber = 1; - int numberOfSamples = 6;
+ Set<SiSensor> sensorSet = new HashSet<SiSensor>(); + SortedMap<Integer, SiSensor> sensorMap = new TreeMap<Integer, SiSensor>(); + + // List of HPSRawTrackerHits + // List<HPSSVTRawTrackerHit> rawHits; + List<RawTrackerHit> rawHits; + + int numberOfSamples = 0; + int noiseThreshold = 1716; // ADC counts + int flags = 0; + + String RawTrackerHitsCollectionName = "RawTrackerHits"; + + // Histograms + protected AIDA aida = AIDA.defaultInstance();
/**
- * Constructor
+ * Default Constructor
*/ public HPSDataProcessingModule() {
- // ... // - blocks = new HashMap<Integer, List<Double>>(); - samples = new TreeMap<Integer, Map<Integer, double[]>>();
+ blocks = new HashMap<Integer, List<Double>>(); + + rawHits = new ArrayList<RawTrackerHit>();
}
- /** - * - */ - public void addSample( Map<Integer, double[]> sample ) - { - samples.put(sampleNumber, sample); - - //---> - System.out.println(this.getClass().getName() + ": Sample # " + sampleNumber + " added!"); - //--->
+ @Override + public void detectorChanged(Detector detector){ + + IDetectorElement tracker + = detector.getDetectorElement().findDetectorElement("Tracker"); + sensorSet.addAll(tracker.findDescendants(SiSensor.class));
- sampleNumber++; -
+ // Sort the sensors by sensor ID + for(SiSensor sensor : sensorSet){ + sensorMap.put(sensor.getSensorID(), sensor); + }
} /** *
- */ - - - /**
* */
- public void createBlocks() - {
+ public void addSample( Map<Integer, double[]> sample ) + { + // Loop through the avp25 digital sample and group all channel data + // into blocks of 6 samples + for(Map.Entry<Integer, double[]> digitalData : sample.entrySet()){
- // First iterate through all samples - Iterator sampleIterator = samples.keySet().iterator(); - while(sampleIterator.hasNext()){ - - // Get a single sample of the APV25 output - Map<Integer, double[]> sample - = samples.get((Integer) sampleIterator.next());
+ // Get the chip number + Integer chipN = digitalData.getKey();
+ // Get the AVP25 data stream + double[] apv25DataStream = digitalData.getValue(); + + // Strip the APV25 data stream of all header information + apv25DataStream = Arrays.copyOfRange(apv25DataStream, 12, apv25DataStream.length-1); +
//--->
- System.out.println(this.getClass().getName() + ": Sample size:" + sample.size());
+// System.out.println(this.getClass().getName() + ": Data Size: " + digitalDatum.length);
//--->
- // Loop through the avp25 digital sample - for(Map.Entry<Integer, double[]> entries : sample.entrySet()){
+ // Loop through all channels + for(int index = 1; index <= apv25DataStream.length; index++){ + + // get the channel number + int channelN = index+(chipN-1)*128;
- // Get the chip number minus 1 - Integer chipN = entries.getKey(); -
//--->
-// System.out.println(this.getClass().getName() + ": Chip Number: " + chipN);
+ // System.out.println(this.getClass().getName() + ": Channel Number: " + channelN );
//--->
+ + // Check if map "blocks" contains the channel. If not add it. + if(!blocks.containsKey(channelN)) + blocks.put(channelN, new ArrayList<Double>(6));
- double[] digitalData = entries.getValue(); - - // Strip the digital sample of all header information - digitalData = Arrays.copyOfRange(digitalData, 12, digitalData.length-1);
+ List<Double> signal = blocks.get(channelN);
//--->
-// System.out.println(this.getClass().getName() + ": Data Size: " + digitalData.length);
+// if(channelN == 675) System.out.println(this.getClass().getName() + ": " + signal.toString());
//--->
- // Loop through all channels and add to blocks - for(int index = 1; index <= digitalData.length; index++){ - - int channelN = index+(chipN-1)*128; - - //---> -// System.out.println(this.getClass().getName() + ": Channel Number: " + channelN ); - //---> - - // Check if map blocks has the channel - if(!blocks.containsKey(channelN)) - blocks.put(channelN, new ArrayList<Double>(6)); - - List<Double> signal = blocks.get(channelN); - - signal.add(digitalData[index-1]); - - blocks.put(channelN, signal); - }
+ //===> + aida.histogram1D(this.getClass().getName() + "ADC Count from all Channels", 1000, 0, 16384).fill(apv25DataStream[index-1]); + //===> + + // Add the sample to the channel + signal.add(apv25DataStream[index-1]); + + // add the block back into the block map + blocks.put(channelN, signal);
} }
- - //---> -// System.out.println(this.getClass().getName() + ": Number of blocks: " + blocks.size()); - //---> - - //---> -// for(Map.Entry<Integer, List<Double>> entries : blocks.entrySet()){ -// System.out.println(this.getClass().getName() + entries.getValue().toString()); -// } - //---> - - // CLear all samples - samples.clear(); - - // Reset the sample number - sampleNumber = 1; -
+ numberOfSamples++;
} /**
@@ -137,17 +136,118 @@
*/ public void findHits() {
- int nHits = 0;
+ // Clear the list of raw hits + rawHits.clear();
- // Loop through all blocks - for(Map.Entry<Integer, List<Double>> entries : blocks.entrySet()){
+ // Loop through all the blocks + for(Iterator blockIterator = blocks.entrySet().iterator(); + blockIterator.hasNext(); ){ + + Map.Entry entry = (Map.Entry) blockIterator.next(); + List<Double> samples = (List<Double>) entry.getValue(); + + if(samplesAboveThreshold(samples) < 3 ){ + + blockIterator.remove(); + continue; + } + + if(!(samples.get(3) > samples.get(2) + || samples.get(4) > samples.get(3))){ + blockIterator.remove(); + continue; + } + + // Create a raw hit if all cuts are passed + // rawHits.add( new HPSSVTRawTrackerHit((Integer) entry.getKey(), samples, 0));
- if(entries.getValue().get(3) >= 1640 ){ - ++nHits; - System.out.println("Found a hit! There are now a total of " + nHits);
+// System.out.println(samples.toString()); + //===> + for(Double sample : samples){ + aida.histogram1D(this.getClass().getName() + ": ADC values from all samples", 1000, 1500, 17000).fill(sample);
}
+ //===>
}
+ +// System.out.println(this.getClass().getName() + ": There are a total of " + nHitsNoCuts + " when no cuts are applied"); + System.out.println(this.getClass().getName() + ": There are a total of " + blocks.size() + " when threshold cut is applied"); + //===> + aida.histogram1D(this.getClass().getName() + ": Hits per trigger event", 20, 0, 100).fill(blocks.size()); + //===> + + } + + /** + * + */ + private void makeRawTrackerHits() + { + // Loop through all the blocks + for(Iterator blockIterator = blocks.entrySet().iterator(); + blockIterator.hasNext(); ){ + + Map.Entry entry = (Map.Entry) blockIterator.next(); + List<Double> adcSamples = (List<Double>) entry.getValue(); + int channelN = (Integer) entry.getKey(); + + // Extract the chip number + int chipN = (int) Math.floor(channelN/128); + + // Extract the sensor number + int sensorId = (int) Math.ceil(chipN/5); + + // Extract the channel number + int channel = channelN%128 + 1; + + // Fill the list of ADC values + short[] adcValues = new short[adcSamples.size()]; + for(int index = 0; index < adcValues.length; index++){ + adcValues[index] = adcSamples.get(index).shortValue(); + } + + SiSensor sensor = sensorMap.get((Integer) sensorId); + long cellId = sensor.makeStripId(channel, 1).getValue(); + + RawTrackerHit rawHit + = new BaseRawTrackerHit(0, cellId, adcValues, null, sensor); + + rawHits.add(rawHit); + } +// +// for(Iterator sensorIt = sensorMap.entrySet().iterator(); +// sensorIt.hasNext(); ){ +// Map.Entry sense = (Map.Entry) sensorIt.next(); +// SiSensor sensor = (SiSensor) sense.getValue(); +// System.out.println("Sensor ID: " + (Integer) sense.getKey() + "Actual Sensor ID: " + sensor.getSensorID()); +// } + } + + + /** + * + * @param samples + * @return + */ + private int samplesAboveThreshold(List<Double> samples) + { + // Number of samples above threshold + int nSamplesAboveThreshold = 0; + + for(Double sample : samples ){ + + if(sample > noiseThreshold) nSamplesAboveThreshold++; + } + + return nSamplesAboveThreshold; + } + + /** + * + */ + public void setNoiseThreshold( int threshold ) + { + noiseThreshold = threshold;
} /**
@@ -160,17 +260,20 @@
// If 6 samples have been collected, block the samples together // by channel
- if(samples.size() == 6 ){
+ if(numberOfSamples == 6){
- // - createBlocks(); - - // Once blocks are created, find which blocks have a hit above - // threshold
+ // find which blocks have a hit above threshold
findHits();
+ // Create Raw Tracker hits + makeRawTrackerHits(); +
// Once cuts have been applied, clear the blocks blocks.clear();
+ numberOfSamples = 0; + + // Store the raw hits in the event + event.put(RawTrackerHitsCollectionName, rawHits, RawTrackerHit.class, flags);
} }
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