Print

Print


Commit in hps-java/src/main/java/org/lcsim/hps/recon/tracking on MAIN
HPSDataProcessingModule.java+167-1421.2 -> 1.3
Changed to make use of sensor identifier; Creates RawTrackerHits

hps-java/src/main/java/org/lcsim/hps/recon/tracking
HPSDataProcessingModule.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- HPSDataProcessingModule.java	30 Jan 2012 00:36:06 -0000	1.2
+++ HPSDataProcessingModule.java	12 Mar 2012 23:04:24 -0000	1.3
@@ -17,6 +17,7 @@
 import java.util.SortedMap;
 import java.util.TreeMap;
 import org.lcsim.detector.IDetectorElement;
+import org.lcsim.detector.IReadout;
 import org.lcsim.detector.tracker.silicon.SiSensor;
 import org.lcsim.event.EventHeader;
 import org.lcsim.event.RawTrackerHit;
@@ -29,23 +30,30 @@
 /**
  *
  * @author Omar Moreno <[log in to unmask]>
- * @version $Id: HPSDataProcessingModule.java,v 1.2 2012/01/30 00:36:06 omoreno Exp $
+ * @version $Id: HPSDataProcessingModule.java,v 1.3 2012/03/12 23:04:24 omoreno Exp $
  */
 public class HPSDataProcessingModule extends Driver {
     
+    
+    boolean debug = false;
+    
+    Map<Long, Map<Integer, List<Double>>> sensorToBlocksMap;
+    
     Map<Integer, List<Double>> blocks;
     
     Set<SiSensor> sensorSet = new HashSet<SiSensor>();
-    SortedMap<Integer, SiSensor> sensorMap = new TreeMap<Integer, SiSensor>();
+    Map<Long, SiSensor> sensorMap = new HashMap<Long, SiSensor>();
     
-    // List of HPSRawTrackerHits
- //   List<HPSSVTRawTrackerHit> rawHits;
-    List<RawTrackerHit> rawHits;
+    // 1-5 rms noise [ADC Counts]
+    int[] noiseThreshold = {1657, 1675, 1692, 1709, 1728}; 
     
     int numberOfSamples = 0;
-    int noiseThreshold = 1716; // ADC counts
     int flags = 0;
     
+    double[] apv25DataStream;
+    
+    List<Double> samples;
+    
     String RawTrackerHitsCollectionName = "RawTrackerHits";
     
     // Histograms
@@ -58,7 +66,7 @@
     {
         blocks  = new HashMap<Integer, List<Double>>();
         
-        rawHits = new ArrayList<RawTrackerHit>();
+        sensorToBlocksMap = new HashMap<Long, Map<Integer, List<Double>>>();
     }
     
     @Override
@@ -70,161 +78,188 @@
         
         // Sort the sensors by sensor ID
         for(SiSensor sensor : sensorSet){
-            sensorMap.put(sensor.getSensorID(), sensor);
+            sensorMap.put(sensor.getIdentifier().getValue(), sensor);
+            
+            sensorToBlocksMap.put(sensor.getIdentifier().getValue(),
+               new HashMap<Integer, List<Double>>());
         }
     }
     
+    
     /**
      * 
      * 
      */
-    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()){
+    public void addSample(Map<Long, Map<Integer, double[]>> sensorToDigitalMap)
+    {
+     
+        int channelN = 0;
         
-            // Get the chip number
-            Integer chipN = digitalData.getKey();    
+        // Loop through all channels and group all channel data into blocks of
+        // 6 samples
+        for(Map.Entry<Long, Map<Integer, double[]>> sensor : sensorToDigitalMap.entrySet()){
             
-            // 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() + ": Data Size: " + digitalDatum.length);
-            //--->
+            boolean flag = false;
             
-            // Loop through all channels
-            for(int index = 1; index <= apv25DataStream.length; index++){
-
-                // get the channel number
-                int channelN = index+(chipN-1)*128;
-
-                //--->
- //               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));             
+            if(debug && flag) System.out.println(this.getClass().getName() + ": Sensor: " + sensor.getKey());
+            
+            for(Map.Entry<Integer, double[]> sample : sensor.getValue().entrySet()){
+                
                 
-                List<Double> signal = blocks.get(channelN);
+                // Copy the sample to avoid concurrent modification
+                apv25DataStream = sample.getValue();
                 
-                //--->
-//                if(channelN == 675) System.out.println(this.getClass().getName() + ": " + signal.toString());
-                //--->
+                // Strip the APV25 data stream of all header information
+                apv25DataStream 
+                   = Arrays.copyOfRange(apv25DataStream, 12, apv25DataStream.length-1);
                 
-                //===>
-                aida.histogram1D(this.getClass().getName() + "ADC Count from all Channels", 1000, 0, 16384).fill(apv25DataStream[index-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++){
+                    
+                    channelN = channel + sample.getKey()*128;
+
+                    // 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());
+                    }
+                }
                 
-                // Add the sample to the channel
-                signal.add(apv25DataStream[index-1]);
+                if(debug) flag = false;
                 
-                // add the block back into the block map
-                blocks.put(channelN, signal);
             }
         }
+        
         numberOfSamples++;
+        
+        if(debug) System.out.println(this.getClass().getName() + ": Number of samples " + numberOfSamples);
     }
     
     /**
      * 
      */
-    public void findHits()
+    public List<RawTrackerHit> findHits()
     {
-        // Clear the list of raw hits
-        rawHits.clear();
-        
+        int nThresholdHits_2over=0;
+        int nSampleCuts_2over=0;
+        int nRawHits = 0;
+
+        List<RawTrackerHit> rawHits = new ArrayList<RawTrackerHit>();
+
         // 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 ){
+        for(Map.Entry<Long, Map<Integer, List<Double>>> sensor : sensorToBlocksMap.entrySet()){
+            for(Map.Entry<Integer, List<Double>> block : sensor.getValue().entrySet()){
+ 
+
                 
-                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(block.getValue().get(0) > 1638 || block.getValue().get(1) > 1638){
+                    nRawHits++;
+                }
+                
+                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++;
+                    
+                    }
+                    
+                }
             
-//            System.out.println(samples.toString());
-            //===>
-            for(Double sample : samples){
-                aida.histogram1D(this.getClass().getName() + ": ADC values from all samples", 1000, 1500, 17000).fill(sample);
+                block.getValue().clear();
             }
-            //===>
-            
         }
-            
-//        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());
-        //===>
-
+        
+        
+        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;
     }
     
     /**
      * 
      */
-    private void makeRawTrackerHits()
+    public void clearBlocks()
     {
-        // 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();
+        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;
+                }
             }
-            
-            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());
-//        }
+        }        
+    }
+        
+    /**
+     * 
+     */
+    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;
+        
     }
     
     
     /**
+     * Finds how many samples are above a given threshold
      * 
      * @param samples
      * @return 
@@ -236,19 +271,11 @@
         
         for(Double sample : samples ){
             
-            if(sample > noiseThreshold) nSamplesAboveThreshold++;
+            if(sample > noiseThreshold[2]) nSamplesAboveThreshold++;
         }
-        
         return nSamplesAboveThreshold;
     }
     
-    /**
-     * 
-     */
-    public void setNoiseThreshold( int threshold )
-    {
-        noiseThreshold = threshold;
-    }
     
     /**
      * 
@@ -257,24 +284,22 @@
     public void process(EventHeader event)
     {
         super.process(event);
+        
+        List<RawTrackerHit> raw_hits = new ArrayList<RawTrackerHit>();
 
-        // If 6 samples have been collected, block the samples together
-        // by channel
+        // If six samples have been collected process the data
         if(numberOfSamples == 6){
             
             // find which blocks have a hit above threshold
-            findHits();
+            raw_hits.addAll(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);
-            
         }
+        
+        // Store the raw tracker hits in the event
+        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