hps-java/src/main/java/org/lcsim/hps/evio
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
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
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()
{
/*