Commit in hps-java/src on MAIN
main/java/org/lcsim/hps/evio/MCRawDataToEvio4Converter2.java+267added 1.1
main/java/org/lcsim/hps/recon/tracking/HPSDataProcessingModule.java+28-121.5 -> 1.6
                                      /HPSSVTData.java+9-11.1 -> 1.2
test/java/org/lcsim/hps/recon/tracking/SVTDAQIO_Test.java+84added 1.1
+388-13
2 added + 2 modified, total 4 files
work in progress on tracker DAQ data

hps-java/src/main/java/org/lcsim/hps/evio
MCRawDataToEvio4Converter2.java added at 1.1
diff -N MCRawDataToEvio4Converter2.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ MCRawDataToEvio4Converter2.java	28 Mar 2012 00:07:08 -0000	1.1
@@ -0,0 +1,267 @@
+package org.lcsim.hps.evio;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jlab.coda.jevio.CompositeData;
+import org.jlab.coda.jevio.DataType;
+import org.jlab.coda.jevio.EventBuilder;
+import org.jlab.coda.jevio.EventWriter;
+import org.jlab.coda.jevio.EvioBank;
+import org.jlab.coda.jevio.EvioException;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.EventHeader.LCMetaData;
+import org.lcsim.event.RawCalorimeterHit;
+import org.lcsim.event.RawTrackerHit;
+import org.lcsim.geometry.IDDecoder;
+import org.lcsim.hps.recon.tracking.HPSSVTData;
+import org.lcsim.util.Driver;
+
+/**
+ * This Driver creates an EVIO data file using raw data generated from HPS MC data, 
+ * e.g. output from slic simulation in LCIO format.
+ * 
+ * The EVIO event structure is as follows, and subject to change.
+ * 
+ * event
+ *   bank (ecal)
+ *     composite data
+ *   bank (ecal)
+ *     composite data
+ *   bank (svt)
+ *     composite data
+ *     
+ * The tracker data bank has number = 1 and the ecal data bank has number = 2.
+ * 
+ * For now the data formats do not match raw data that would come off the ET ring
+ * but I plan to add this soon.
+ * 
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+public class MCRawDataToEvio4Converter2 extends Driver {
+        
+    // These correspond to ROC (readout crate) IDs from the DAQ system.
+    public static final int ecalTopBankTag = 0x1;
+    public static final int ecalBottomBankTag = 0x2;
+    public static final int trackerBankTag = 0x3;
+        
+    // CompositeData formats.
+    public static final String trackerFormat = "N(L,I,I)";
+    public static final String ecalFormat = "N(L,I,I)";
+    
+    //public static final int ecalBankTag = 0xe103;
+    public static final int trackerBankNumber = 1;
+    public static final int ecalBankNumber = 2;
+    
+    String evioOutputFile = "MCRawData.evio";
+    EventWriter writer;
+    
+    String rawTrackerHitCollectionName = "RawTrackerHitMaker_RawTrackerHits";
+    String rawCalorimeterHitCollectionName = "EcalRawHits";    
+    String svtCollectionName = "SVTData";
+    
+    EventBuilder builder = null;
+
+    private int eventsWritten = 0;
+    
+    public MCRawDataToEvio4Converter2() 
+    {}
+    
+    public void setEvioOutputFile(String evioOutputFile) {
+        this.evioOutputFile = evioOutputFile;
+    }
+    
+    public void setRawTrackerHitCollectionName(String rawTrackerHitCollectionName) {
+        this.rawTrackerHitCollectionName = rawTrackerHitCollectionName;
+    }
+    
+    public void setSVTDataCollectionName(String svtCollectionName) {
+    	this.svtCollectionName = svtCollectionName;
+    }
+    
+    public void setRawCalorimeterHitCollectionName(String rawCalorimeterHitCollectionName) {
+        this.rawCalorimeterHitCollectionName = rawCalorimeterHitCollectionName;
+    }
+    
+    public void startOfData() {
+        try {
+            writer = new EventWriter(evioOutputFile);
+        }
+        catch (EvioException e) {
+            throw new RuntimeException(e);
+        }
+    }
+    
+    public void endOfData() {
+        System.out.println("wrote " + eventsWritten + " events");
+        try {
+            writer.close();
+        } catch (EvioException e) {
+            throw new RuntimeException(e);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+        
+    public void process(EventHeader event) {
+        
+        // Make a new EVIO event.
+        builder = new EventBuilder(0, DataType.BANK, event.getEventNumber());
+        
+        // Write RawTrackerHit collection.
+        // TODO Check for null.
+        //writeRawTrackerHits(event.get(RawTrackerHit.class, rawTrackerHitCollectionName), builder);
+        
+        // Write SVTData.
+        List<List<HPSSVTData>> svtDataList = event.get(HPSSVTData.class);
+        if (svtDataList != null) {
+        	if (svtDataList.size() > 0) {
+        		if (svtDataList.get(0) != null) {
+        			this.writeSVTData(svtDataList.get(0));
+        		} else {
+        			System.out.println("No HPSSVTData in event!");
+        		}
+        	}
+        } else {
+        	System.out.println("No lists with type HPSSVTData.class in event!");
+        }
+        
+        // Write RawCalorimeterHit collection.
+        List<RawCalorimeterHit> rawCalorimeterHits = event.get(RawCalorimeterHit.class, rawCalorimeterHitCollectionName); 
+        LCMetaData meta = event.getMetaData(rawCalorimeterHits);
+        writeRawCalorimeterHits(meta, rawCalorimeterHits, builder);
+        
+        // Write this EVIO event.
+        builder.setAllHeaderLengths();
+        try {
+            writer.writeEvent(builder.getEvent());
+            ++eventsWritten;
+        } catch (EvioException e) {
+            throw new RuntimeException(e);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+    
+    public void writeRawTrackerHits(List<RawTrackerHit> rawTrackerHits, EventBuilder builder) {
+
+        int dataSize = rawTrackerHits.size();
+        
+        //System.out.println("writeRawTrackerHits will write " + dataSize + " hits");
+                                             
+        CompositeData.Data data = new CompositeData.Data();       
+        data.addN(dataSize);     
+        for (RawTrackerHit hit : rawTrackerHits) {
+            data.addLong(hit.getCellID());
+            data.addInt(hit.getTime());
+            data.addInt(hit.getADCValues()[0]);
+        }        
+        CompositeData cdata = null;
+        try {
+            cdata = new CompositeData(trackerFormat, 1, data, 0 ,0);
+        }
+        catch (EvioException e) {
+            throw new RuntimeException(e);
+        }        
+        EvioBank bank = new EvioBank(trackerBankTag, DataType.COMPOSITE, trackerBankNumber);
+        try {
+            bank.appendCompositeData(cdata);
+        } catch (EvioException e) {
+            throw new RuntimeException(e);
+        }
+        bank.setAllHeaderLengths();
+        try {
+            builder.addChild(builder.getEvent(), bank);
+        } catch (EvioException e) {
+            throw new RuntimeException(e);
+        }
+    }
+       
+    public void writeRawCalorimeterHitCollection(List<RawCalorimeterHit> hits, int bankTag, EventBuilder builder) {
+        CompositeData.Data data = new CompositeData.Data();
+        int nTopHits = hits.size();
+        data.addN(nTopHits);
+        for (RawCalorimeterHit hit : hits) {
+            data.addLong(hit.getCellID());
+            data.addInt(hit.getAmplitude());
+            data.addInt(hit.getTimeStamp());
+        }
+        CompositeData cdata = null;
+        try {
+            cdata = new CompositeData(ecalFormat, 1, data, 0, 0);
+        }
+        catch (EvioException e) {
+            throw new RuntimeException(e);
+        }
+        EvioBank bank = new EvioBank(bankTag, DataType.COMPOSITE, ecalBankNumber);
+        try {
+            bank.appendCompositeData(cdata);
+        } catch (EvioException e) {
+            throw new RuntimeException(e);
+        }
+        bank.setAllHeaderLengths();
+        try {
+            builder.addChild(builder.getEvent(), bank);
+        } catch (EvioException e) {
+            throw new RuntimeException(e);
+        }
+    }
+    
+    public void writeRawCalorimeterHits(LCMetaData meta, List<RawCalorimeterHit> rawCalorimeterHits, EventBuilder builder) {
+        
+        // Make two lists containing the hits from top and bottom sections, which go into separate EVIO data banks.
+        IDDecoder dec = meta.getIDDecoder();
+        List<RawCalorimeterHit> topHits = new ArrayList<RawCalorimeterHit>();
+        List<RawCalorimeterHit> bottomHits = new ArrayList<RawCalorimeterHit>();        
+        for (RawCalorimeterHit hit : rawCalorimeterHits) {
+            dec.setID(hit.getCellID());
+            int iy = dec.getValue("iy");
+            // Negative iy should be bottom section.
+            if (iy < 0) {
+                bottomHits.add(hit);
+            }
+            // Positive iy should be top section.
+            else {
+                topHits.add(hit);
+            }
+        }
+        
+        // Write the two collections for top and bottom hits to separate EVIO banks.
+        writeRawCalorimeterHitCollection(topHits, ecalTopBankTag, builder);
+        writeRawCalorimeterHitCollection(bottomHits, ecalBottomBankTag, builder);        
+    }      
+    
+    public void writeSVTData(List<HPSSVTData> data) {
+    	if (data == null) {
+    		throw new RuntimeException("The list points to null.");
+    	}
+    	
+    	int nsamples = data.size();
+    	int evioIntData[] = new int[nsamples*4];
+    	
+    	int i = 0;
+    	for (HPSSVTData sample : data) {
+    		int[] sampleData = sample.getData();
+    		//System.out.println(Integer.toHexString(sampleData[0]) + ":" + Integer.toHexString(sampleData[1])+ ":" + Integer.toHexString(sampleData[2])+ ":" + Integer.toHexString(sampleData[3]));
+    		evioIntData[i] = sampleData[0];
+    		evioIntData[i+1] = sampleData[1];
+    		evioIntData[i+2] = sampleData[2];
+    		evioIntData[i+3] = sampleData[3];
+    		i += 4;    		
+    	}    	
+    	
+    	EvioBank bank = new EvioBank(trackerBankTag, DataType.INT32, trackerBankNumber);
+    	try {
+    		bank.appendIntData(evioIntData);
+    	} catch (EvioException e) {
+    		throw new RuntimeException(e);
+    	}
+    	bank.setAllHeaderLengths();
+        try {
+            builder.addChild(builder.getEvent(), bank);
+        } catch (EvioException e) {
+            throw new RuntimeException(e);
+        }
+    }
+}
\ No newline at end of file

hps-java/src/main/java/org/lcsim/hps/recon/tracking
HPSDataProcessingModule.java 1.5 -> 1.6
diff -u -r1.5 -r1.6
--- HPSDataProcessingModule.java	23 Mar 2012 03:52:14 -0000	1.5
+++ HPSDataProcessingModule.java	28 Mar 2012 00:07:08 -0000	1.6
@@ -27,7 +27,7 @@
 /**
  *
  * @author Omar Moreno <[log in to unmask]>
- * @version $Id: HPSDataProcessingModule.java,v 1.5 2012/03/23 03:52:14 omoreno Exp $
+ * @version $Id: HPSDataProcessingModule.java,v 1.6 2012/03/28 00:07:08 jeremy Exp $
  */
 public class HPSDataProcessingModule extends Driver {
     
@@ -64,7 +64,9 @@
     
     String RawTrackerHitsCollectionName = "RawTrackerHits";
     String RawTrackerHitsCutsCollectionName = "RawTrackerHitsCuts";
-    String dataStreamCollectionName = "dataStream";
+    //String dataStreamCollectionName = "dataStream";
+    
+    String svtCollectionName = "SVTData";
     
     // Histograms
     protected AIDA aida = AIDA.defaultInstance();
@@ -82,6 +84,10 @@
 
     }
     
+    public void setSvtCollectionName(String svtCollectionName) {
+    	this.svtCollectionName = svtCollectionName;
+    }
+    
     /**
      * 
      */
@@ -211,30 +217,36 @@
             
             for(Map.Entry<Integer, List<Double>> block : sensor.getValue().entrySet()){
             
+            	//System.out.println("proc sample");
+            	
                 // Convert ADC value to a short
                 for(int index = 0; index < adc.length; index++){
-                    adc[index] = block.getValue().get(index).shortValue();
+                    adc[index] = block.getValue().get(index).shortValue();                
                 }
                 
+                // Moved list creation above cuts because cuts messed up.  --JM
+                
+                // If all cuts are satisfied, create a RawTrackerHit
+                rawHits.add(makeRawTrackerHit(block.getKey(), sensorMap.get(sensor.getKey()), adc));
+                
+                // Create an svtData packet
+                svtData.add(new HPSSVTData(sensorMap.get(sensor.getKey()), block.getKey(), adc));
+                
                 // Check if a block has the appropriate number of blocks above
                 // threshold
                 if(samplesAboveThreshold(adc) >= nSamplesAboveThresh) continue;
-                
+                                               
                 // Apply the tail cut
                 if(!tailCut(adc)) continue;
                        
                 // Apply noise suppression cut
-                if(!noiseSuppresionCut(adc)) continue;
-                    
-                // If all cuts are satisfied, create a RawTrackerHit
-                rawHits.add(makeRawTrackerHit(block.getKey(), sensorMap.get(sensor.getKey()), adc));
-                
-                // Create an svtData packet
-                svtData.add(new HPSSVTData(sensorMap.get(sensor.getKey()), block.getKey(), adc));
-            
+                if(!noiseSuppresionCut(adc)) continue;                    
+                            
                 block.getValue().clear();
             }
         }
+        
+        System.out.println(this.getClass().getSimpleName() + " created " + rawHits.size());
     }
     
     /**
@@ -323,6 +335,10 @@
             findHits();
             event.put(RawTrackerHitsCollectionName, raw_hits, RawTrackerHit.class, flags);
             
+            // Add SVTData to event.  This collection will not be persisted by LCSim.
+            System.out.println("adding svtCollection " + svtCollectionName + " with " + this.svtData.size() + " samples");
+            event.put(this.svtCollectionName, this.svtData, HPSSVTData.class, 0);
+            
             //
             numberOfSamples = 0;
         }

hps-java/src/main/java/org/lcsim/hps/recon/tracking
HPSSVTData.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- HPSSVTData.java	23 Mar 2012 03:54:36 -0000	1.1
+++ HPSSVTData.java	28 Mar 2012 00:07:08 -0000	1.2
@@ -7,7 +7,7 @@
 /**
  *
  * @author Omar Moreno
- * @version $Id: HPSSVTData.java,v 1.1 2012/03/23 03:54:36 omoreno Exp $
+ * @version $Id: HPSSVTData.java,v 1.2 2012/03/28 00:07:08 jeremy Exp $
  */
 public class HPSSVTData {
     
@@ -30,6 +30,14 @@
         createSVTData();
     }
     
+    /**
+     * Get the packed data for this sample.
+     * @return The packed data as an int array of size 4.
+     */
+    public int[] getData() {
+    	return data;
+    }
+    
     private void createSVTData()
     {
         /*

hps-java/src/test/java/org/lcsim/hps/recon/tracking
SVTDAQIO_Test.java added at 1.1
diff -N SVTDAQIO_Test.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ SVTDAQIO_Test.java	28 Mar 2012 00:07:08 -0000	1.1
@@ -0,0 +1,84 @@
+package org.lcsim.hps.recon.tracking;
+
+import java.io.File;
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.jlab.coda.jevio.BaseStructure;
+import org.jlab.coda.jevio.BaseStructureHeader;
+import org.jlab.coda.jevio.EvioEvent;
+import org.jlab.coda.jevio.EvioReader;
+import org.lcsim.HPSTrackerSample;
+import org.lcsim.hps.evio.MCRawDataToEvio4Converter2;
+import org.lcsim.job.JobControlManager;
+
+public class SVTDAQIO_Test extends TestCase {
+	
+	String lcsimXmlFile = "/u1/hps/trackerTest/HPSTestRunTracking.lcsim";
+	String slicFile = "/u1/hps/trackerTest/ap_75MeV_v4pt0";
+	String evioFile = "TrackerTest.evio";
+	
+	public void testIt() throws Exception {
+		
+		// Create EVIO file.
+		JobControlManager mgr = new JobControlManager();
+		mgr.addVariableDefinition("inputFile", slicFile);
+		mgr.setup(new File(lcsimXmlFile));
+		mgr.run();
+		
+		// Read back EVIO file.
+		EvioReader reader = null;
+		try {
+			reader = new EvioReader(evioFile);
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		}
+		EvioEvent event = null;
+		event = reader.parseNextEvent();
+		while (event != null) {
+			
+			for (BaseStructure bank : event.getChildren()) {
+				BaseStructureHeader header = bank.getHeader();
+				if (header.getTag() == MCRawDataToEvio4Converter2.trackerBankTag) {									
+					int[] intData = bank.getIntData();
+					if (intData.length % 4 != 0) {
+						throw new RuntimeException("Size of int array not divisible by 4!");
+					}
+					int n = intData.length;
+					for (int i=0; i<n; i+=4) {
+
+						int[] sampleData = new int[4];
+						sampleData[0] = intData[i];
+						sampleData[1] = intData[i+1];
+						sampleData[2] = intData[i+2];
+						sampleData[3] = intData[i+3];
+						
+						HPSTrackerSample trackerSample = new HPSTrackerSample();
+						trackerSample.setData(sampleData);
+
+						int fpga = trackerSample.fpgaAddress();
+						int hybrid = trackerSample.hybrid();
+						int channel = trackerSample.channel();
+						int apv = trackerSample.apv();
+
+						System.out.println("fpga=" + fpga + "; hybrid=" + hybrid + "; channel=" + channel + "; apv=" + apv);
+
+						for (int j=0; j<6; j++) {
+							int val = trackerSample.value(j);
+							System.out.println("  val[" + j + "]="+val);
+						}										
+					}
+				}
+			}
+			
+			
+			if (reader.getNumEventsRemaining() == 0) {
+				break;
+			}
+			event = reader.parseNextEvent();
+		}
+		
+	}
+
+}
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