Commit in hps-java/src/main/java/org/lcsim/hps/recon/tracking on MAIN
HPSDataProcessingModule.java+106-991.3 -> 1.4
Added Cuts

hps-java/src/main/java/org/lcsim/hps/recon/tracking
HPSDataProcessingModule.java 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- HPSDataProcessingModule.java	12 Mar 2012 23:04:24 -0000	1.3
+++ HPSDataProcessingModule.java	22 Mar 2012 20:02:42 -0000	1.4
@@ -6,19 +6,16 @@
 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.IReadout;
+import org.lcsim.detector.identifier.IIdentifier;
 import org.lcsim.detector.tracker.silicon.SiSensor;
+import org.lcsim.detector.tracker.silicon.SiTrackerIdentifierHelper;
 import org.lcsim.event.EventHeader;
 import org.lcsim.event.RawTrackerHit;
 import org.lcsim.event.SimTrackerHit;
@@ -30,24 +27,26 @@
 /**
  *
  * @author Omar Moreno <[log in to unmask]>
- * @version $Id: HPSDataProcessingModule.java,v 1.3 2012/03/12 23:04:24 omoreno Exp $
+ * @version $Id: HPSDataProcessingModule.java,v 1.4 2012/03/22 20:02:42 omoreno Exp $
  */
 public class HPSDataProcessingModule extends Driver {
     
-    
-    boolean debug = false;
-    
     Map<Long, Map<Integer, List<Double>>> sensorToBlocksMap;
     
-    Map<Integer, List<Double>> blocks;
+    // Relate a channel to its six samples
+    Map<Integer, List<Double>> channelToBlock;
     
-    Set<SiSensor> sensorSet = new HashSet<SiSensor>();
+    // Relate a sensor Identifier to the actual sensor
     Map<Long, SiSensor> sensorMap = new HashMap<Long, SiSensor>();
     
-    // 1-5 rms noise [ADC Counts]
+    // Set of all sensors
+    Set<SiSensor> sensorSet = new HashSet<SiSensor>();
+    
+    // 1-5 rms noise [ADC Counts] <--- This is going to change
     int[] noiseThreshold = {1657, 1675, 1692, 1709, 1728}; 
     
     int numberOfSamples = 0;
+    int nSamplesAboveThresh = 0;
     int flags = 0;
     
     double[] apv25DataStream;
@@ -64,27 +63,53 @@
      */
     public HPSDataProcessingModule()
     {
-        blocks  = new HashMap<Integer, List<Double>>();
-        
+        channelToBlock  = new HashMap<Integer, List<Double>>();
         sensorToBlocksMap = new HashMap<Long, Map<Integer, List<Double>>>();
     }
     
+    /**
+     * 
+     */
     @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));
         
-        // Sort the sensors by sensor ID
+
+// -----> This needs to be changed        
+//        tracker.getIdentifierHelper().getIdentifierDictionary().getFieldNames().toString();
+//        
+//        IIdentifier ident = tracker.getIdentifier();
+//          IIdentifier ident_sen = sensor.getIdentifier();  
+//        SiTrackerIdentifierHelper helper =  (SiTrackerIdentifierHelper) sensor.getIdentifierHelper();
+//
+//        
+//           System.out.println("Layer:" + " " + helper.getLayerValue(ident_sen));
+//          System.out.println("Module:" + " " + helper.getModuleValue(ident_sen));
+        
         for(SiSensor sensor : sensorSet){
+        
+            // Map a sensor to its identifier
             sensorMap.put(sensor.getIdentifier().getValue(), sensor);
             
-            sensorToBlocksMap.put(sensor.getIdentifier().getValue(),
-               new HashMap<Integer, List<Double>>());
+            // Map a sensor to its corresponding samples
+            sensorToBlocksMap.put(sensor.getIdentifier().getValue(), 
+                                    new HashMap<Integer, List<Double>>());
         }
     }
     
+    /**
+     * 
+     */
+    public void SetSamplesAboveThresh(int nSamplesAboveThresh)
+    {
+        this.nSamplesAboveThresh = nSamplesAboveThresh;
+    }
     
     /**
      * 
@@ -93,32 +118,30 @@
     public void addSample(Map<Long, Map<Integer, double[]>> sensorToDigitalMap)
     {
      
+        /*
+         * Long:     Sensor Identifier
+         * Integer:  Chip Number
+         * double[]: APV25 Data Stream 
+         * 
+         */
+        
         int channelN = 0;
         
-        // Loop through all channels and group all channel data into blocks of
-        // 6 samples
+        // Loop through the list of all sensors
         for(Map.Entry<Long, Map<Integer, double[]>> sensor : sensorToDigitalMap.entrySet()){
             
-            boolean flag = false;
-            
-            if(debug && flag) System.out.println(this.getClass().getName() + ": Sensor: " + sensor.getKey());
-            
+            // Loop through all APV25s
             for(Map.Entry<Integer, double[]> sample : sensor.getValue().entrySet()){
                 
-                
                 // Copy the sample to avoid concurrent modification
                 apv25DataStream = sample.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);
                 
-            
-                if(debug && flag){
-                    System.out.println(this.getClass().getName() + ": APV25 data stream size: " + apv25DataStream.length);
-                    System.out.println(this.getClass().getName() + ": Chip number: " + sample.getKey());
-                }
-                
                 // Loop through all channels
                 for(int channel = 0; channel < apv25DataStream.length; channel++){
                     
@@ -127,87 +150,57 @@
                     // Check if a block has been created for this channel. If
                     // not create it
                     if(!sensorToBlocksMap.get(sensor.getKey()).containsKey(channelN)){
-                        if(debug && flag){
-                            System.out.println(this.getClass().getName() + ": Sensor: " + sensor.getKey() + ": Creating List for channel " + channelN);
-                        }
                         sensorToBlocksMap.get(sensor.getKey()).put(channelN, new ArrayList<Double>(6));
                     }
                     
                     sensorToBlocksMap.get(sensor.getKey()).get(channelN).add(apv25DataStream[channel]);
                     
-                    if(debug && flag){
-                        System.out.println(this.getClass().getName() + ": List Size: " + sensorToBlocksMap.get(sensor.getKey()).get(channelN).size());
-                    }
                 }
-                
-                if(debug) flag = false;
-                
             }
         }
         
+        // ---> Possibly change ...
         numberOfSamples++;
-        
-        if(debug) System.out.println(this.getClass().getName() + ": Number of samples " + numberOfSamples);
     }
     
     /**
      * 
      */
-    public List<RawTrackerHit> findHits()
+    public List<RawTrackerHit> findHits(int eventN)
     {
-        int nThresholdHits_2over=0;
-        int nSampleCuts_2over=0;
-        int nRawHits = 0;
+
+        short[] adc;
 
         List<RawTrackerHit> rawHits = new ArrayList<RawTrackerHit>();
 
-        // Loop through all the blocks
+        // Loop through all sensors and the corresponding blocks
         for(Map.Entry<Long, Map<Integer, List<Double>>> sensor : sensorToBlocksMap.entrySet()){
+            
             for(Map.Entry<Integer, List<Double>> block : sensor.getValue().entrySet()){
- 
-
-                
-                if(block.getValue().get(0) > 1638 || block.getValue().get(1) > 1638){
-                    nRawHits++;
+            
+                // Convert ADC value to a short
+                adc = new short[block.getValue().size()];
+                for(int index = 0; index < block.getValue().size(); index++){
+                    adc[index] = block.getValue().get(index).shortValue();
                 }
                 
-                if(samplesAboveThreshold(block.getValue()) >= 2){
-
-                    nThresholdHits_2over++;
-
-                    aida.histogram1D(this.getClass().getName() + ": ADC values - Sample 1", 500, 1630, 1800).fill(block.getValue().get(0));
-                    aida.histogram1D(this.getClass().getName() + ": ADC values - Sample 2", 500, 1630, 1800).fill(block.getValue().get(1));
-                    aida.histogram1D(this.getClass().getName() + ": ADC values - Sample 3", 500, 1630, 1800).fill(block.getValue().get(2));
-                    aida.histogram1D(this.getClass().getName() + ": ADC values - Sample 4", 500, 1630, 1800).fill(block.getValue().get(3));
-                    aida.histogram1D(this.getClass().getName() + ": ADC values - Sample 5", 500, 1630, 1800).fill(block.getValue().get(4));
-                    aida.histogram1D(this.getClass().getName() + ": ADC values - Sample 6", 500, 1630, 1800).fill(block.getValue().get(5));
-                    
-                    
-                    short[] adcValues = new short[block.getValue().size()];
-                    for(int index = 0; index < block.getValue().size(); index++){
-                        adcValues[index] = block.getValue().get(index).shortValue();
-                    }
-                        
-                    rawHits.add(makeRawTrackerHit(block.getKey(), sensorMap.get(sensor.getKey()), adcValues));
-                    
-                    if(block.getValue().get(2) > noiseThreshold[3] || block.getValue().get(1) > noiseThreshold[3] ){
-                            
-                        nSampleCuts_2over++;
-                    
-                    }
+                // Check if a block has the appropriate number of blocks above
+                // threshold
+                if(samplesAboveThreshold(block.getValue()) >= nSamplesAboveThresh) continue;
+                
+                // Apply the tail cut
+                if(!(adc[3] > adc[2] || adc[4] > adc[3])) continue;
+                       
+                // Apply noise suppression cut
+                if(adc[3] > noiseThreshold[3] || adc[4] > noiseThreshold[3]) continue;
                     
-                }
+                // If all cuts are satisfied, create a RawTrackerHit
+                rawHits.add(makeRawTrackerHit(block.getKey(), sensorMap.get(sensor.getKey()), adc));
             
                 block.getValue().clear();
             }
         }
         
-        
-        System.out.println(this.getClass().getName() + ": Number of Raw Hits: " + nRawHits);
-        System.out.println(this.getClass().getName() + ": Number of hits that pass 2 threshold cut: " + nThresholdHits_2over);
-        System.out.println(this.getClass().getName() + ": Number of hits that pass 2 over sample cut: " + nSampleCuts_2over);
-        nRawHits = 0;
-    
         return rawHits;
     }
     
@@ -217,20 +210,10 @@
     public void clearBlocks()
     {
         for(Map.Entry<Long, Map<Integer, List<Double>>> sensor : sensorToBlocksMap.entrySet()){
-            boolean flag = false;
             for(Map.Entry<Integer, List<Double>> block : sensor.getValue().entrySet()){
                 
-                if(debug && flag){
-                    System.out.println(this.getClass().getName() + ": Block size before clearing " + block.getValue().size());
-                }
-                
                 block.getValue().clear();
 
-                           
-                if(debug && flag){
-                    System.out.println(this.getClass().getName() + ": Block size after clearing " + block.getValue().size());
-                    flag = false;
-                }
             }
         }        
     }
@@ -240,21 +223,17 @@
      */
     private RawTrackerHit makeRawTrackerHit( Integer channelNumber, SiSensor sensor, short[] adcValues)
     {
-        
         IReadout ro = sensor.getReadout();
         
-        
         // No time yet
         int time = 0;
         long cell_id = sensor.makeStripId(channelNumber, 1).getValue();
         
-        
         RawTrackerHit rawHit = new BaseRawTrackerHit(time, cell_id, adcValues, new ArrayList<SimTrackerHit>(), sensor);
-        
+
         ro.addHit(rawHit);
         
         return rawHit;
-        
     }
     
     
@@ -271,11 +250,37 @@
         
         for(Double sample : samples ){
             
-            if(sample > noiseThreshold[2]) nSamplesAboveThreshold++;
+            if(sample >= noiseThreshold[2]) nSamplesAboveThreshold++;
         }
         return nSamplesAboveThreshold;
     }
     
+    /**
+     * 
+     */
+    private int[] createDataStream(short[] samples, short channel)
+    {
+        int[] data = new int[4];
+        short fpga = 0;  // This will be extracted from the sensor number
+        
+        
+        /*
+         * Sample Data consists of the following: Z[xx:xx] = Zeros, O[xx:xx] = Ones
+         * Sample[0] = O[0], Z[0], Hybrid[1:0], Z[0], ApvChip[2:0], Z[0], Channel[6:0], FpgaAddress[15:0]
+         * Sample[1] = Z[1:0], Sample1[13:0]], Z[1:0], Sample0[13:0]
+         * Sample[2] = Z[1:0], Sample3[13:0]], Z[1:0], Sample2[13:0]
+         * Sample[3] = Z[1:0], Sample5[13:0]], Z[1:0], Sample4[13:0]
+         */
+        
+        // Add the channel number 
+        data[0] = ( ~(0xFFFF << 16) & data[0] ) | ( ( fpga & 0x7F ) << 16);
+        data[0] = ( ~(0x7F << 23) & data[0] ) | ( ( channel & 0x7F ) << 23);
+//        data[0] = ( ~(0x1 << 24) & data[0] ) | (( 0 & 0x1 ) << 24 ); 
+        
+        
+        return data;
+    }
+    
     
     /**
      * 
@@ -291,7 +296,7 @@
         if(numberOfSamples == 6){
             
             // find which blocks have a hit above threshold
-            raw_hits.addAll(findHits());
+            raw_hits.addAll(findHits(event.getEventNumber()));
             
             //
             numberOfSamples = 0;
@@ -299,6 +304,8 @@
         }
         
         // Store the raw tracker hits in the event
+        if(raw_hits.size() > 0)
+        System.out.println(this.getClass().getName() + ": The number of raw hits found: " + raw_hits.size());
         event.put(RawTrackerHitsCollectionName, raw_hits, RawTrackerHit.class, flags);
     
     }
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