1 added + 12 modified, total 13 files
hps-java/src/main/java/org/lcsim/hps/evio
diff -u -r1.1 -r1.2
--- ECalEvioWriter.java 5 Apr 2012 20:20:28 -0000 1.1
+++ ECalEvioWriter.java 7 Apr 2012 00:07:24 -0000 1.2
@@ -4,6 +4,7 @@
*/
package org.lcsim.hps.evio;
+import org.lcsim.event.RawTrackerHit;
import org.jlab.coda.jevio.CompositeData;
import java.util.ArrayList;
import java.util.HashMap;
@@ -28,13 +29,14 @@
/**
*
* @author Sho Uemura <[log in to unmask]>
- * @version $Id: ECalEvioWriter.java,v 1.1 2012/04/05 20:20:28 meeg Exp $
+ * @version $Id: ECalEvioWriter.java,v 1.2 2012/04/07 00:07:24 meeg Exp $
*/
public class ECalEvioWriter implements EvioWriter {
- private String rawCalorimeterHitCollectionName = "EcalReadoutHits";
+ private String hitCollectionName = "EcalReadoutHits";
private String ecalName = "Ecal";
private HPSEcalDaqIDConverter ecalIDConverter = null;
+ private int mode = EventConstants.ECAL_PULSE_INTEGRAL_MODE;
public ECalEvioWriter() {
}
@@ -43,12 +45,28 @@
this.ecalName = ecalName;
}
- public void setRawCalorimeterHitCollectionName(String rawCalorimeterHitCollectionName) {
- this.rawCalorimeterHitCollectionName = rawCalorimeterHitCollectionName;
+ public void setHitCollectionName(String hitCollectionName) {
+ this.hitCollectionName = hitCollectionName;
+ }
+
+ public void setMode(int mode) {
+ this.mode = mode;
+ if (mode != EventConstants.ECAL_WINDOW_MODE && mode != EventConstants.ECAL_PULSE_MODE && mode != EventConstants.ECAL_PULSE_INTEGRAL_MODE) {
+ throw new IllegalArgumentException("invalid mode " + mode);
+ }
}
public boolean hasData(EventHeader event) {
- return event.hasCollection(RawCalorimeterHit.class, rawCalorimeterHitCollectionName);
+ switch (mode) {
+ case EventConstants.ECAL_WINDOW_MODE:
+ return event.hasCollection(RawTrackerHit.class, hitCollectionName);
+ case EventConstants.ECAL_PULSE_MODE:
+ return event.hasCollection(RawTrackerHit.class, hitCollectionName);
+ case EventConstants.ECAL_PULSE_INTEGRAL_MODE:
+ return event.hasCollection(RawCalorimeterHit.class, hitCollectionName);
+ default:
+ return false;
+ }
}
public void writeData(EventHeader event, EventBuilder builder) {
@@ -56,13 +74,52 @@
ecalIDConverter = new HPSEcalDaqIDConverter();
ecalIDConverter.fillDaqCellMap(event.getDetector().getSubdetector(ecalName));
}
- List<RawCalorimeterHit> rawCalorimeterHits = event.get(RawCalorimeterHit.class, rawCalorimeterHitCollectionName);
- LCMetaData meta = event.getMetaData(rawCalorimeterHits);
- writeRawCalorimeterHits(meta, rawCalorimeterHits, builder);
- System.out.println("Writing ECal data, event " + event.getEventNumber());
+ LCMetaData meta;
+ List<RawCalorimeterHit> rawCalorimeterHits;
+ List<RawTrackerHit> rawTrackerHits;
+ switch (mode) {
+ case EventConstants.ECAL_WINDOW_MODE:
+ rawTrackerHits = event.get(RawTrackerHit.class, hitCollectionName);
+ meta = event.getMetaData(rawTrackerHits);
+ writeWindowHits(meta, rawTrackerHits, builder);
+ break;
+ case EventConstants.ECAL_PULSE_MODE:
+ rawTrackerHits = event.get(RawTrackerHit.class, hitCollectionName);
+ meta = event.getMetaData(rawTrackerHits);
+ writePulseHits(meta, rawTrackerHits, builder);
+ break;
+ case EventConstants.ECAL_PULSE_INTEGRAL_MODE:
+ rawCalorimeterHits = event.get(RawCalorimeterHit.class, hitCollectionName);
+ meta = event.getMetaData(rawCalorimeterHits);
+ writeIntegralHits(meta, rawCalorimeterHits, builder);
+ break;
+ default:
+ break;
+ }
+ }
+
+ private void writeIntegralHits(LCMetaData meta, List<RawCalorimeterHit> rawCalorimeterHits, EventBuilder builder) {
+ System.out.println("Writing " + rawCalorimeterHits.size() + " ECal hits in integral format");
+
+ // Make two lists containing the hits from top and bottom sections, which go into separate EVIO data banks.
+ List<RawCalorimeterHit> topHits = new ArrayList<RawCalorimeterHit>();
+ List<RawCalorimeterHit> bottomHits = new ArrayList<RawCalorimeterHit>();
+ for (RawCalorimeterHit hit : rawCalorimeterHits) {
+ Long daqID = ecalIDConverter.physicalToDaqID(hit.getCellID());
+ int crate = HPSEcalDaqIDConverter.getCrate(daqID);
+ if (crate == ECAL_BOTTOM_BANK_TAG) {
+ bottomHits.add(hit);
+ } else {
+ topHits.add(hit);
+ }
+ }
+
+ // Write the two collections for top and bottom hits to separate EVIO banks.
+ writeIntegralHitCollection(topHits, meta, ECAL_TOP_BANK_TAG, builder);
+ writeIntegralHitCollection(bottomHits, meta, ECAL_BOTTOM_BANK_TAG, builder);
}
- private void writeRawCalorimeterHitCollection(List<RawCalorimeterHit> hits, LCMetaData meta, int bankTag, EventBuilder builder) {
+ private void writeIntegralHitCollection(List<RawCalorimeterHit> hits, LCMetaData meta, int bankTag, EventBuilder builder) {
// Get the ID decoder.
IDDecoder dec = meta.getIDDecoder();
@@ -146,27 +203,211 @@
}
}
- private void writeRawCalorimeterHits(LCMetaData meta, List<RawCalorimeterHit> rawCalorimeterHits, EventBuilder builder) {
- System.out.println("Writing " + rawCalorimeterHits.size() + " ECal hits");
+ private void writePulseHits(LCMetaData meta, List<RawTrackerHit> rawCalorimeterHits, EventBuilder builder) {
+ System.out.println("Writing " + rawCalorimeterHits.size() + " ECal hits in pulse format");
// Make two lists containing the hits from top and bottom sections, which go into separate EVIO data banks.
+ List<RawTrackerHit> topHits = new ArrayList<RawTrackerHit>();
+ List<RawTrackerHit> bottomHits = new ArrayList<RawTrackerHit>();
+ for (RawTrackerHit hit : rawCalorimeterHits) {
+ Long daqID = ecalIDConverter.physicalToDaqID(hit.getCellID());
+ int crate = HPSEcalDaqIDConverter.getCrate(daqID);
+ if (crate == ECAL_BOTTOM_BANK_TAG) {
+ bottomHits.add(hit);
+ } else {
+ topHits.add(hit);
+ }
+ }
+
+ // Write the two collections for top and bottom hits to separate EVIO banks.
+ writePulseHitCollection(topHits, meta, ECAL_TOP_BANK_TAG, builder);
+ writePulseHitCollection(bottomHits, meta, ECAL_BOTTOM_BANK_TAG, builder);
+ }
+
+ private void writePulseHitCollection(List<RawTrackerHit> hits, LCMetaData meta, int bankTag, EventBuilder builder) {
+ // Get the ID decoder.
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) {
+
+ // Make a hit map; allow for multiple hits in a crystal.
+ Map<Long, List<RawTrackerHit>> hitMap = new HashMap<Long, List<RawTrackerHit>>();
+ for (RawTrackerHit hit : hits) {
+ if (hitMap.get(hit.getCellID()) == null) {
+ hitMap.put(hit.getCellID(), new ArrayList<RawTrackerHit>());
+ }
+ List<RawTrackerHit> channelHits = hitMap.get(hit.getCellID());
+ channelHits.add(hit);
+ }
+
+ // Make map of slot number to hit IDs.
+ Map<Integer, List<Long>> slotMap = new HashMap<Integer, List<Long>>();
+ for (Long id : hitMap.keySet()) {
+ dec.setID(id);
+// System.out.println(dec.getIDDescription());
+// System.out.printf("ix = %d, iy = %d\n", dec.getValue("ix"), dec.getValue("iy"));
+ Long daqID = ecalIDConverter.physicalToDaqID(id);
+// System.out.printf("physicalID %d, daqID %d\n", id, daqID);
+ int slot = HPSEcalDaqIDConverter.getSlot(daqID);
+ if (slotMap.get(slot) == null) {
+ slotMap.put(slot, new ArrayList<Long>());
+ }
+ List<Long> slots = slotMap.get(slot);
+ slots.add(id);
+ }
+
+ // Make a new bank for this crate.
+ EvioBank crateBank = new EvioBank(bankTag, DataType.BANK, ECAL_BANK_NUMBER);
+
+ // Loop over the slots in the map.
+ for (int slot : slotMap.keySet()) {
+
+ // New bank for this slot.
+ EvioBank slotBank = new EvioBank(EventConstants.ECAL_PULSE_BANK_TAG, DataType.COMPOSITE, slot);
+
+ // Create composite data for this slot and its channels.
+ CompositeData.Data data = new CompositeData.Data();
+ data.addUchar((byte) slot); // slot #
+ data.addUint(0); // trigger #
+ data.addUlong(0); // timestamp
+ List<Long> hitIDs = slotMap.get(slot);
+ int nhits = hitIDs.size();
+ data.addN(nhits); // number of channels
+ for (Long id : hitIDs) {
+ dec.setID(id);
+ int channel = HPSEcalDaqIDConverter.getChannel(ecalIDConverter.physicalToDaqID(id));
+ data.addUchar((byte) channel); // channel #
+ List<RawTrackerHit> channelHits = hitMap.get(id);
+ data.addN(channelHits.size()); // number of pulses
+ for (RawTrackerHit hit : channelHits) {
+ data.addUchar((byte) channelHits.indexOf(hit)); // pulse number
+ data.addN(hit.getADCValues().length); // number of samples
+ for (short val : hit.getADCValues()) {
+ data.addUshort(val); // sample
+ }
+ }
+ }
+
+ // Add CompositeData to bank.
+ CompositeData cdata = null;
+ try {
+ cdata = new CompositeData(EventConstants.ECAL_PULSE_FORMAT, 1, data, EventConstants.ECAL_PULSE_BANK_TAG, slot);
+ slotBank.appendCompositeData(cdata);
+ } catch (EvioException e) {
+ throw new RuntimeException(e);
+ }
+
+ // Add slot bank to crate bank.
+ slotBank.setAllHeaderLengths();
+ try {
+ builder.addChild(crateBank, slotBank);
+ } catch (EvioException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ try {
+ crateBank.setAllHeaderLengths();
+ builder.addChild(builder.getEvent(), crateBank);
+ } catch (EvioException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private void writeWindowHits(LCMetaData meta, List<RawTrackerHit> rawCalorimeterHits, EventBuilder builder) {
+ System.out.println("Writing " + rawCalorimeterHits.size() + " ECal hits in window format");
+
+ // Make two lists containing the hits from top and bottom sections, which go into separate EVIO data banks.
+ List<RawTrackerHit> topHits = new ArrayList<RawTrackerHit>();
+ List<RawTrackerHit> bottomHits = new ArrayList<RawTrackerHit>();
+ for (RawTrackerHit hit : rawCalorimeterHits) {
+ Long daqID = ecalIDConverter.physicalToDaqID(hit.getCellID());
+ int crate = HPSEcalDaqIDConverter.getCrate(daqID);
+ if (crate == ECAL_BOTTOM_BANK_TAG) {
bottomHits.add(hit);
- } // Positive iy should be top section.
- else {
+ } else {
topHits.add(hit);
}
}
// Write the two collections for top and bottom hits to separate EVIO banks.
- writeRawCalorimeterHitCollection(topHits, meta, ECAL_TOP_BANK_TAG, builder);
- writeRawCalorimeterHitCollection(bottomHits, meta, ECAL_BOTTOM_BANK_TAG, builder);
+ writeWindowHitCollection(topHits, meta, ECAL_TOP_BANK_TAG, builder);
+ writeWindowHitCollection(bottomHits, meta, ECAL_BOTTOM_BANK_TAG, builder);
+ }
+
+ private void writeWindowHitCollection(List<RawTrackerHit> hits, LCMetaData meta, int bankTag, EventBuilder builder) {
+ // Get the ID decoder.
+ IDDecoder dec = meta.getIDDecoder();
+
+ // Make a hit map; allow for multiple hits in a crystal.
+ Map<Long, RawTrackerHit> hitMap = new HashMap<Long, RawTrackerHit>();
+ for (RawTrackerHit hit : hits) {
+ hitMap.put(hit.getCellID(), hit);
+ }
+
+ // Make map of slot number to hit IDs.
+ Map<Integer, List<Long>> slotMap = new HashMap<Integer, List<Long>>();
+ for (Long id : hitMap.keySet()) {
+ dec.setID(id);
+// System.out.println(dec.getIDDescription());
+// System.out.printf("ix = %d, iy = %d\n", dec.getValue("ix"), dec.getValue("iy"));
+ Long daqID = ecalIDConverter.physicalToDaqID(id);
+// System.out.printf("physicalID %d, daqID %d\n", id, daqID);
+ int slot = HPSEcalDaqIDConverter.getSlot(daqID);
+ if (slotMap.get(slot) == null) {
+ slotMap.put(slot, new ArrayList<Long>());
+ }
+ List<Long> slots = slotMap.get(slot);
+ slots.add(id);
+ }
+
+ // Make a new bank for this crate.
+ EvioBank crateBank = new EvioBank(bankTag, DataType.BANK, ECAL_BANK_NUMBER);
+
+ // Loop over the slots in the map.
+ for (int slot : slotMap.keySet()) {
+
+ // New bank for this slot.
+ EvioBank slotBank = new EvioBank(EventConstants.ECAL_WINDOW_BANK_TAG, DataType.COMPOSITE, slot);
+
+ // Create composite data for this slot and its channels.
+ CompositeData.Data data = new CompositeData.Data();
+ data.addUchar((byte) slot); // slot #
+ data.addUint(0); // trigger #
+ data.addUlong(0); // timestamp
+ List<Long> hitIDs = slotMap.get(slot);
+ int nhits = hitIDs.size();
+ data.addN(nhits); // number of channels
+ for (Long id : hitIDs) {
+ dec.setID(id);
+ int channel = HPSEcalDaqIDConverter.getChannel(ecalIDConverter.physicalToDaqID(id));
+ data.addUchar((byte) channel); // channel #
+ RawTrackerHit hit = hitMap.get(id);
+ data.addN(hit.getADCValues().length); // number of samples
+ for (short val : hit.getADCValues()) {
+ data.addUshort(val); // sample
+ }
+ }
+
+ // Add CompositeData to bank.
+ CompositeData cdata = null;
+ try {
+ cdata = new CompositeData(EventConstants.ECAL_WINDOW_FORMAT, 1, data, EventConstants.ECAL_WINDOW_BANK_TAG, slot);
+ slotBank.appendCompositeData(cdata);
+ } catch (EvioException e) {
+ throw new RuntimeException(e);
+ }
+
+ // Add slot bank to crate bank.
+ slotBank.setAllHeaderLengths();
+ try {
+ builder.addChild(crateBank, slotBank);
+ } catch (EvioException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ try {
+ crateBank.setAllHeaderLengths();
+ builder.addChild(builder.getEvent(), crateBank);
+ } catch (EvioException e) {
+ throw new RuntimeException(e);
+ }
}
}
hps-java/src/main/java/org/lcsim/hps/evio
diff -u -r1.1 -r1.2
--- ECalEvioReader.java 5 Apr 2012 21:05:52 -0000 1.1
+++ ECalEvioReader.java 7 Apr 2012 00:07:24 -0000 1.2
@@ -14,12 +14,14 @@
import org.jlab.coda.jevio.EvioException;
import org.lcsim.event.EventHeader;
import org.lcsim.event.RawCalorimeterHit;
+import org.lcsim.event.RawTrackerHit;
+import org.lcsim.event.base.BaseRawTrackerHit;
import org.lcsim.hps.recon.ecal.HPSEcalDaqIDConverter;
/**
*
* @author Sho Uemura <[log in to unmask]>
- * @version $Id: ECalEvioReader.java,v 1.1 2012/04/05 21:05:52 meeg Exp $
+ * @version $Id: ECalEvioReader.java,v 1.2 2012/04/07 00:07:24 meeg Exp $
*/
public class ECalEvioReader {
// Names of subdetectors.
@@ -29,6 +31,9 @@
private String rawCalorimeterHitCollectionName = "EcalReadoutHits";
private String ecalName = "Ecal";
private HPSEcalDaqIDConverter ecalIDConverter = null;
+ private int mode = EventConstants.ECAL_PULSE_INTEGRAL_MODE;
+ private int bankTag = EventConstants.ECAL_PULSE_INTEGRAL_BANK_TAG;
+ private Class hitClass = RawCalorimeterHit.class;
public ECalEvioReader() {
}
@@ -45,16 +50,37 @@
this.debug = debug;
}
+ public void setMode(int mode) {
+ this.mode = mode;
+ if (mode != EventConstants.ECAL_WINDOW_MODE && mode != EventConstants.ECAL_PULSE_MODE && mode != EventConstants.ECAL_PULSE_INTEGRAL_MODE) {
+ throw new IllegalArgumentException("invalid mode " + mode);
+ }
+ switch (mode) {
+ case EventConstants.ECAL_WINDOW_MODE:
+ bankTag = EventConstants.ECAL_WINDOW_BANK_TAG;
+ hitClass = RawTrackerHit.class;
+ break;
+ case EventConstants.ECAL_PULSE_MODE:
+ bankTag = EventConstants.ECAL_PULSE_BANK_TAG;
+ hitClass = RawTrackerHit.class;
+ break;
+ case EventConstants.ECAL_PULSE_INTEGRAL_MODE:
+ bankTag = EventConstants.ECAL_PULSE_INTEGRAL_BANK_TAG;
+ hitClass = RawCalorimeterHit.class;
+ break;
+ }
+ }
+
public void makeRawCalorimeterHits(EvioEvent event, EventHeader lcsimEvent) {
if (ecalIDConverter == null) {
ecalIDConverter = new HPSEcalDaqIDConverter();
ecalIDConverter.fillDaqCellMap(lcsimEvent.getDetector().getSubdetector(ecalName));
}
- List<RawCalorimeterHit> hits = new ArrayList<RawCalorimeterHit>();
+ List<Object> hits = new ArrayList<Object>();
for (BaseStructure bank : event.getChildren()) {
BaseStructureHeader header = bank.getHeader();
- int bankTag = header.getTag();
- if (bankTag == MCRawDataToEvio4Converter.ecalBottomBankTag || bankTag == MCRawDataToEvio4Converter.ecalTopBankTag) {
+ int crateBankTag = header.getTag();
+ if (crateBankTag == EventConstants.ECAL_TOP_BANK_TAG || crateBankTag == EventConstants.ECAL_BOTTOM_BANK_TAG) {
if (bank.getChildCount() > 0) {
if (debug) {
System.out.println("ECal bank tag: " + header.getTag() + "; childCount: " + bank.getChildCount());
@@ -66,17 +92,117 @@
} catch (EvioException e) {
throw new RuntimeException(e);
}
- List<RawCalorimeterHit> bankHits = makeRawCalorimeterHits(cdata, bankTag);
- hits.addAll(bankHits);
+ if (slotBank.getHeader().getTag() != bankTag) {
+ throw new RuntimeException("Unsupported ECal format - bank tag " + slotBank.getHeader().getTag());
+ }
+ switch (mode) {
+ case EventConstants.ECAL_WINDOW_MODE:
+ hits.addAll(makeWindowHits(cdata, crateBankTag));
+ break;
+ case EventConstants.ECAL_PULSE_MODE:
+ hits.addAll(makePulseHits(cdata, crateBankTag));
+ break;
+ case EventConstants.ECAL_PULSE_INTEGRAL_MODE:
+ hits.addAll(makeIntegralHits(cdata, crateBankTag));
+ break;
+ }
}
}
}
}
String readoutName = lcsimEvent.getDetector().getSubdetector(ecalName).getReadout().getName();
- lcsimEvent.put(rawCalorimeterHitCollectionName, hits, RawCalorimeterHit.class, 0, readoutName);
+ lcsimEvent.put(rawCalorimeterHitCollectionName, hits, hitClass, 0, readoutName);
+ }
+
+ private List<BaseRawTrackerHit> makeWindowHits(CompositeData cdata, int bankTag) {
+ List<BaseRawTrackerHit> hits = new ArrayList<BaseRawTrackerHit>();
+ if (debug) {
+ int n = cdata.getNValues().size();
+ for (int i = 0; i < n; i++) {
+ System.out.println("cdata.N[" + i + "]=" + cdata.getNValues().get(i));
+ }
+ int ni = cdata.getItems().size();
+ for (int i = 0; i < ni; i++) {
+ System.out.println("cdata.type[" + i + "]=" + cdata.getTypes().get(i));
+ }
+ }
+
+ int crate = bankTag;
+ short slot = cdata.getByte();
+ int trigger = cdata.getInt();
+ long timestamp = cdata.getLong();
+ int nchannels = cdata.getNValue();
+ if (debug) {
+ System.out.println("slot#=" + slot + "; trigger=" + trigger + "; timestamp=" + timestamp + "; nchannels=" + nchannels);
+ }
+ for (int j = 0; j < nchannels; j++) {
+ short channel = cdata.getByte();
+ int nSamples = cdata.getNValue();
+ if (debug) {
+ System.out.println(" channel=" + channel + "; nSamples=" + nSamples);
+ }
+ long daqID = HPSEcalDaqIDConverter.getDaqID(crate, slot, channel);
+ Long id = ecalIDConverter.daqToPhysicalID(daqID);
+
+ short[] adcValues = new short[nSamples];
+ for (int i = 0; i < nSamples; i++) {
+ adcValues[i] = cdata.getShort();
+ }
+// if (debug) {
+// System.out.println(" pulseTime=" + pulseTime + "; pulseIntegral=" + pulseIntegral);
+// }
+ hits.add(new BaseRawTrackerHit(id, 0, adcValues));
+ }
+ return hits;
+ }
+
+ private List<BaseRawTrackerHit> makePulseHits(CompositeData cdata, int bankTag) {
+ List<BaseRawTrackerHit> hits = new ArrayList<BaseRawTrackerHit>();
+ if (debug) {
+ int n = cdata.getNValues().size();
+ for (int i = 0; i < n; i++) {
+ System.out.println("cdata.N[" + i + "]=" + cdata.getNValues().get(i));
+ }
+ int ni = cdata.getItems().size();
+ for (int i = 0; i < ni; i++) {
+ System.out.println("cdata.type[" + i + "]=" + cdata.getTypes().get(i));
+ }
+ }
+
+ int crate = bankTag;
+ short slot = cdata.getByte();
+ int trigger = cdata.getInt();
+ long timestamp = cdata.getLong();
+ int nchannels = cdata.getNValue();
+ if (debug) {
+ System.out.println("slot#=" + slot + "; trigger=" + trigger + "; timestamp=" + timestamp + "; nchannels=" + nchannels);
+ }
+ for (int j = 0; j < nchannels; j++) {
+ short channel = cdata.getByte();
+ int npulses = cdata.getNValue();
+ if (debug) {
+ System.out.println(" channel=" + channel + "; npulses=" + npulses);
+ }
+ long daqID = HPSEcalDaqIDConverter.getDaqID(crate, slot, channel);
+ Long id = ecalIDConverter.daqToPhysicalID(daqID);
+
+ for (int k = 0; k < npulses; k++) {
+ short pulseNum = cdata.getByte();
+ int sampleCount = cdata.getNValue();
+ short[] adcValues = new short[sampleCount];
+ for (int i = 0; i < sampleCount; i++) {
+ adcValues[i] = cdata.getShort();
+ }
+// if (debug) {
+// System.out.println(" pulseTime=" + pulseTime + "; pulseIntegral=" + pulseIntegral);
+// }
+ hits.add(new BaseRawTrackerHit(id, pulseNum, adcValues));
+ }
+ }
+ return hits;
}
- private List<RawCalorimeterHit> makeRawCalorimeterHits(CompositeData cdata, int bankTag) {
+ private List<RawCalorimeterHit> makeIntegralHits(CompositeData cdata, int bankTag) {
List<RawCalorimeterHit> hits = new ArrayList<RawCalorimeterHit>();
if (debug) {
int n = cdata.getNValues().size();
@@ -105,8 +231,6 @@
}
long daqID = HPSEcalDaqIDConverter.getDaqID(crate, slot, channel);
Long id = ecalIDConverter.daqToPhysicalID(daqID);
-// System.out.printf("crate = %d, slot = %d, channel = %d\n", crate, slot, channel);
-// System.out.printf("physicalID %d, daqID %d\n", id, daqID);
for (int k = 0; k < npulses; k++) {
short pulseTime = cdata.getShort();
hps-java/src/main/java/org/lcsim/hps/evio
diff -u -r1.1 -r1.2
--- SVTEvioWriter.java 5 Apr 2012 20:20:28 -0000 1.1
+++ SVTEvioWriter.java 7 Apr 2012 00:07:24 -0000 1.2
@@ -15,11 +15,12 @@
import org.jlab.coda.jevio.EvioException;
import org.lcsim.event.EventHeader;
import org.lcsim.hps.recon.tracking.HPSSVTData;
+import org.lcsim.hps.recon.tracking.HPSSVTDataBuffer;
/**
*
* @author Sho Uemura <[log in to unmask]>
- * @version $Id: SVTEvioWriter.java,v 1.1 2012/04/05 20:20:28 meeg Exp $
+ * @version $Id: SVTEvioWriter.java,v 1.2 2012/04/07 00:07:24 meeg Exp $
*/
public class SVTEvioWriter implements EvioWriter {
@@ -32,46 +33,34 @@
}
public void writeData(EventHeader event, EventBuilder builder) {
- 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), builder);
- System.out.println("Writing SVT data, event " + event.getEventNumber());
- }
+
+ // SVT container bank.
+ EvioBank svtBank = new EvioBank(SVT_BANK_TAG, DataType.BANK, SVT_BANK_NUMBER);
+
+ int nfpgas = 8;
+ for (int i=0; i<nfpgas; i++) {
+
+ // Get the raw int data buffer for this FPGA.
+ int[] dataBuffer = HPSSVTDataBuffer.readoutBuffer(i);
+
+ System.out.println("FPGA["+i+"] has data of size " + dataBuffer.length);
+
+ // Bank for this FPGA's frame data.
+ // FIXME: Need actual FPGA numbers.
+ EvioBank frameBank = new EvioBank(i, DataType.UINT32, i);
+ try {
+ frameBank.appendIntData(dataBuffer);
+ builder.addChild(svtBank, frameBank);
+ } catch (EvioException e) {
+ throw new RuntimeException(e);
}
}
- }
-
- private void writeSVTData(List<HPSSVTData> data, EventBuilder builder) {
- 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(SVT_BANK_TAG, DataType.UINT32, SVT_BANK_NUMBER);
- try {
- bank.appendIntData(evioIntData);
- } catch (EvioException e) {
- throw new RuntimeException(e);
- }
- bank.setAllHeaderLengths();
+
+ // Add top bank to event.
try {
- builder.addChild(builder.getEvent(), bank);
+ builder.addChild(builder.getEvent(), svtBank);
} catch (EvioException e) {
throw new RuntimeException(e);
- }
+ }
}
}
hps-java/src/main/java/org/lcsim/hps/evio
diff -u -r1.5 -r1.6
--- TestRunReconToEvio.java 5 Apr 2012 23:56:37 -0000 1.5
+++ TestRunReconToEvio.java 7 Apr 2012 00:07:24 -0000 1.6
@@ -1,32 +1,12 @@
package org.lcsim.hps.evio;
-import static org.lcsim.hps.evio.EventConstants.ECAL_BANK_NUMBER;
-import static org.lcsim.hps.evio.EventConstants.ECAL_BOTTOM_BANK_TAG;
-import static org.lcsim.hps.evio.EventConstants.ECAL_CHANNEL_OFFSET;
-import static org.lcsim.hps.evio.EventConstants.ECAL_PULSE_INTEGRAL_BANK_TAG;
-import static org.lcsim.hps.evio.EventConstants.ECAL_PULSE_INTEGRAL_FORMAT;
-import static org.lcsim.hps.evio.EventConstants.ECAL_TOP_BANK_TAG;
-import static org.lcsim.hps.evio.EventConstants.SVT_BANK_NUMBER;
-import static org.lcsim.hps.evio.EventConstants.SVT_BANK_TAG;
-
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-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.geometry.IDDecoder;
-import org.lcsim.hps.recon.tracking.HPSSVTData;
-import org.lcsim.hps.recon.tracking.HPSSVTDataBuffer;
import org.lcsim.util.Driver;
/**
@@ -40,11 +20,13 @@
public class TestRunReconToEvio extends Driver {
EventWriter writer;
+ String ecalName = "Ecal";
String rawCalorimeterHitCollectionName = "EcalDigitizedHits";
- String svtCollectionName = "SVTData";
String evioOutputFile = "TestRunData.evio";
EventBuilder builder = null;
private int eventsWritten = 0;
+ ECalEvioWriter ecalWriter = null;
+ SVTEvioWriter svtWriter = null;
public TestRunReconToEvio() {
}
@@ -53,12 +35,18 @@
this.evioOutputFile = evioOutputFile;
}
- public void setSVTDataCollectionName(String svtCollectionName) {
- this.svtCollectionName = svtCollectionName;
+ public void setEcalName(String ecalName) {
+ this.ecalName = ecalName;
+ if (ecalWriter != null) {
+ ecalWriter.setEcalName(ecalName);
+ }
}
public void setRawCalorimeterHitCollectionName(String rawCalorimeterHitCollectionName) {
this.rawCalorimeterHitCollectionName = rawCalorimeterHitCollectionName;
+ if (ecalWriter != null) {
+ ecalWriter.setHitCollectionName(rawCalorimeterHitCollectionName);
+ }
}
protected void startOfData() {
@@ -67,6 +55,12 @@
} catch (EvioException e) {
throw new RuntimeException(e);
}
+
+ ecalWriter = new ECalEvioWriter();
+ ecalWriter.setEcalName(ecalName);
+ ecalWriter.setHitCollectionName(rawCalorimeterHitCollectionName);
+
+ svtWriter = new SVTEvioWriter();
}
protected void endOfData() {
@@ -81,17 +75,8 @@
}
protected void process(EventHeader event) {
-
- // Skip if no SVT data in event.
- List<HPSSVTData> svtData = null;
- try {
- svtData = event.get(HPSSVTData.class, svtCollectionName);
- } catch (IllegalArgumentException e) {
- //System.out.println(svtCollectionName + " does not exit; skipping event");
- return;
- }
- if (svtData.size() == 0) {
- //System.out.println(svtCollectionName + " is empty; skipping event");
+
+ if (!svtWriter.hasData(event)) {
return;
}
@@ -99,10 +84,11 @@
builder = new EventBuilder(0, DataType.BANK, event.getEventNumber());
// Write SVTData.
- writeSVTData(event);
+ svtWriter.writeData(event, builder);
// Write RawCalorimeterHit collection.
- writeRawCalorimeterHits(event);
+ ecalWriter.writeData(event, builder);
+// writeRawCalorimeterHits(event);
// Write this EVIO event.
writeEvioEvent();
@@ -119,148 +105,4 @@
throw new RuntimeException(e);
}
}
-
- private void writeRawCalorimeterHits(EventHeader event) {
- List<RawCalorimeterHit> rawCalorimeterHits = event.get(RawCalorimeterHit.class, rawCalorimeterHitCollectionName);
- LCMetaData meta = event.getMetaData(rawCalorimeterHits);
- writeRawCalorimeterHits(meta, rawCalorimeterHits, builder);
- }
-
- private void writeSVTData(EventHeader event) {
-
- // SVT container bank.
- EvioBank svtBank = new EvioBank(SVT_BANK_TAG, DataType.BANK, SVT_BANK_NUMBER);
-
- int nfpgas = 8;
- for (int i=0; i<nfpgas; i++) {
-
- // Get the raw int data buffer for this FPGA.
- int[] dataBuffer = HPSSVTDataBuffer.readoutBuffer(i);
-
- System.out.println("FPGA["+i+"] has data of size " + dataBuffer.length);
-
- // Bank for this FPGA's frame data.
- // FIXME: Need actual FPGA numbers.
- EvioBank frameBank = new EvioBank(i, DataType.UINT32, i);
- try {
- frameBank.appendIntData(dataBuffer);
- builder.addChild(svtBank, frameBank);
- } catch (EvioException e) {
- throw new RuntimeException(e);
- }
- }
-
- // Add top bank to event.
- try {
- builder.addChild(builder.getEvent(), svtBank);
- } catch (EvioException e) {
- throw new RuntimeException(e);
- }
- }
-
- private void writeRawCalorimeterHitCollection(List<RawCalorimeterHit> hits, LCMetaData meta, int bankTag, EventBuilder builder) {
-
- // Get the ID decoder.
- IDDecoder dec = meta.getIDDecoder();
-
- // Make a hit map; allow for multiple hits in a crystal.
- Map<Long, List<RawCalorimeterHit>> hitMap = new HashMap<Long, List<RawCalorimeterHit>>();
- for (RawCalorimeterHit hit : hits) {
- if (hitMap.get(hit.getCellID()) == null) {
- hitMap.put(hit.getCellID(), new ArrayList<RawCalorimeterHit>());
- }
- List<RawCalorimeterHit> channelHits = hitMap.get(hit.getCellID());
- channelHits.add(hit);
- }
-
- // Make map of slot number to hit IDs.
- Map<Integer, List<Long>> slotMap = new HashMap<Integer, List<Long>>();
- for (Long id : hitMap.keySet()) {
- dec.setID(id);
- int iy = dec.getValue("iy"); // treating as slot number
- int slot = Math.abs(iy);
- if (slotMap.get(slot) == null) {
- slotMap.put(slot, new ArrayList<Long>());
- }
- List<Long> slots = slotMap.get(slot);
- slots.add(id);
- }
-
- // Make a new bank for this crate.
- EvioBank crateBank = new EvioBank(bankTag, DataType.BANK, ECAL_BANK_NUMBER);
-
- // Loop over the slots in the map.
- for (int slot : slotMap.keySet()) {
-
- // New bank for this slot.
- EvioBank slotBank = new EvioBank(ECAL_PULSE_INTEGRAL_BANK_TAG, DataType.COMPOSITE, slot);
-
- // Create composite data for this slot and its channels.
- CompositeData.Data data = new CompositeData.Data();
- data.addUchar((byte) slot); // slot #
- data.addUint(0); // trigger #
- data.addUlong(0); // timestamp
- List<Long> hitIDs = slotMap.get(slot);
- int nhits = hitIDs.size();
- data.addN(nhits); // number of channels
- for (Long id : hitIDs) {
- dec.setID(id);
- int ix = dec.getValue("ix");
- int channel = ix + ECAL_CHANNEL_OFFSET;
- data.addUchar((byte) channel); // channel #
- List<RawCalorimeterHit> channelHits = hitMap.get(id);
- data.addN(channelHits.size()); // number of pulses
- for (RawCalorimeterHit hit : channelHits) {
- data.addUshort((short) hit.getTimeStamp()); // pulse time
- data.addUint((int) hit.getAmplitude()); // pulse integral
- }
- }
-
- // Add CompositeData to bank.
- CompositeData cdata = null;
- try {
- cdata = new CompositeData(ECAL_PULSE_INTEGRAL_FORMAT, 1, data, ECAL_PULSE_INTEGRAL_BANK_TAG, slot);
- slotBank.appendCompositeData(cdata);
- } catch (EvioException e) {
- throw new RuntimeException(e);
- }
-
- // Add slot bank to crate bank.
- slotBank.setAllHeaderLengths();
- try {
- builder.addChild(crateBank, slotBank);
- } catch (EvioException e) {
- throw new RuntimeException(e);
- }
- }
- try {
- crateBank.setAllHeaderLengths();
- builder.addChild(builder.getEvent(), crateBank);
- } catch (EvioException e) {
- throw new RuntimeException(e);
- }
- }
-
- private 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, meta, ECAL_TOP_BANK_TAG, builder);
- writeRawCalorimeterHitCollection(bottomHits, meta, ECAL_BOTTOM_BANK_TAG, builder);
- }
}
\ No newline at end of file
hps-java/src/main/java/org/lcsim/hps/evio
diff -u -r1.7 -r1.8
--- LCSimTestRunEventBuilder.java 5 Apr 2012 23:56:14 -0000 1.7
+++ LCSimTestRunEventBuilder.java 7 Apr 2012 00:07:24 -0000 1.8
@@ -19,27 +19,36 @@
* Build LCSim events from EVIO data.
* @author Sho Uemura <[log in to unmask]>
* @author Jeremy McCormick <[log in to unmask]>
- * @version $Id: LCSimTestRunEventBuilder.java,v 1.7 2012/04/05 23:56:14 jeremy Exp $
+ * @version $Id: LCSimTestRunEventBuilder.java,v 1.8 2012/04/07 00:07:24 meeg Exp $
*/
public class LCSimTestRunEventBuilder implements LCSimEventBuilder {
// Names of subdetectors.
private String trackerName;
private String calorimeterName;
-
- // Names of raw data collections with default settings.
+ // Names of raw data collections with default settings.
private String rawCalorimeterHitCollectionName = "EcalRawHits";
private String svtDataCollectionName = "SVTData";
-
// Detector conditions object.
private Detector detector;
// Debug flag.
private boolean debug = false;
ECalEvioReader ecalReader = null;
+ private int ecalMode = EventConstants.ECAL_PULSE_INTEGRAL_MODE;
public LCSimTestRunEventBuilder() {
}
+ public void setEcalMode(int ecalMode) {
+ this.ecalMode = ecalMode;
+ if (ecalMode != EventConstants.ECAL_WINDOW_MODE && ecalMode != EventConstants.ECAL_PULSE_MODE && ecalMode != EventConstants.ECAL_PULSE_INTEGRAL_MODE) {
+ throw new IllegalArgumentException("invalid mode " + ecalMode);
+ }
+ if (ecalReader != null) {
+ ecalReader.setMode(ecalMode);
+ }
+ }
+
public void setDetectorName(String detectorName) {
// Make a dummy event to setup the conditions system.
@@ -71,6 +80,7 @@
this.rawCalorimeterHitCollectionName = rawCalorimeterHitCollectionName;
ecalReader = null;
}
+
public void setSvtDataCollectionName(String svtDataCollectionName) {
this.svtDataCollectionName = svtDataCollectionName;
}
@@ -105,14 +115,17 @@
}
public EventHeader makeLCSimEvent(EvioEvent evioEvent) {
-
+// if (debug) {
+ System.out.println("Read EVIO event number " + evioEvent.getHeader().getNumber());
+// }
// Create a new LCSimEvent.
EventHeader lcsimEvent = new BaseLCSimEvent(0, evioEvent.getHeader().getNumber(), detector.getDetectorName());
-
+
if (ecalReader == null) {
ecalReader = new ECalEvioReader();
ecalReader.setEcalName(calorimeterName);
ecalReader.setRawCalorimeterHitCollectionName(rawCalorimeterHitCollectionName);
+ ecalReader.setMode(ecalMode);
ecalReader.setDebug(debug);
}
@@ -125,14 +138,15 @@
return lcsimEvent;
}
-
+
private List<HPSSVTData> makeSVTData(EvioEvent event) {
List<HPSSVTData> svtDataCollection = new ArrayList<HPSSVTData>();
for (BaseStructure crateBank : event.getChildren()) {
- int crateTag = crateBank.getHeader().getTag();
+ int crateTag = crateBank.getHeader().getTag();
if (crateTag == SVT_BANK_TAG) {
- if (crateBank.getChildCount() == 0)
+ if (crateBank.getChildCount() == 0) {
throw new RuntimeException("No children found in SVT bank.");
+ }
for (BaseStructure frameBank : crateBank.getChildren()) {
if (frameBank.getHeader().getTag() == 7) {
@@ -146,16 +160,16 @@
throw new RuntimeException("Size of int array not divisible by 4!");
}
int n = intData.length;
- for (int i=0; i<n; i+=4) {
+ 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];
+ sampleData[1] = intData[i + 1];
+ sampleData[2] = intData[i + 2];
+ sampleData[3] = intData[i + 3];
HPSSVTData svtData = new HPSSVTData(sampleData);
-
+
svtDataCollection.add(svtData);
/*
@@ -163,17 +177,17 @@
int hybrid = svtData.getHybridNumber();
int channel = svtData.getChannelNumber();
int apv = svtData.getAPVNumber();
-
+
System.out.println("fpga=" + fpga + "; hybrid=" + hybrid + "; channel=" + channel + "; apv=" + apv);
for (int j=0; j<6; j++) {
- int val = svtData.getSample(j);
- System.out.println(" sample[" + j + "]="+val);
+ int val = svtData.getSample(j);
+ System.out.println(" sample[" + j + "]="+val);
}
- */
+ */
}
- }
+ }
}
- }
+ }
return svtDataCollection;
}
}
\ No newline at end of file
hps-java/src/main/java/org/lcsim/hps/evio
diff -u -r1.4 -r1.5
--- TestRunTriggeredReconToEvio.java 5 Apr 2012 20:20:28 -0000 1.4
+++ TestRunTriggeredReconToEvio.java 7 Apr 2012 00:07:24 -0000 1.5
@@ -26,27 +26,46 @@
EventWriter writer;
String rawCalorimeterHitCollectionName = "EcalReadoutHits";
-// String svtCollectionName = "SVTData";
String evioOutputFile = "TestRunData.evio";
String ecalName = "Ecal";
Queue<QueuedEtEvent> builderQueue = null;
private int eventsWritten = 0;
public static boolean triggerBit = false;
HPSEcalDaqIDConverter ecalIDConverter = null;
+ ECalEvioWriter ecalWriter = null;
+ SVTEvioWriter svtWriter = null;
List<EvioWriter> writers = null;
+ private int ecalMode = EventConstants.ECAL_PULSE_INTEGRAL_MODE;
public TestRunTriggeredReconToEvio() {
}
+ public void setEcalMode(int ecalMode) {
+ this.ecalMode = ecalMode;
+ if (ecalMode != EventConstants.ECAL_WINDOW_MODE && ecalMode != EventConstants.ECAL_PULSE_MODE && ecalMode != EventConstants.ECAL_PULSE_INTEGRAL_MODE) {
+ throw new IllegalArgumentException("invalid mode " + ecalMode);
+ }
+ if (ecalWriter != null) {
+ ecalWriter.setMode(ecalMode);
+ }
+ }
+
public void setEvioOutputFile(String evioOutputFile) {
this.evioOutputFile = evioOutputFile;
}
-// public void setSVTDataCollectionName(String svtCollectionName) {
-// this.svtCollectionName = svtCollectionName;
-// }
+ public void setEcalName(String ecalName) {
+ this.ecalName = ecalName;
+ if (ecalWriter != null) {
+ ecalWriter.setEcalName(ecalName);
+ }
+ }
+
public void setRawCalorimeterHitCollectionName(String rawCalorimeterHitCollectionName) {
this.rawCalorimeterHitCollectionName = rawCalorimeterHitCollectionName;
+ if (ecalWriter != null) {
+ ecalWriter.setHitCollectionName(rawCalorimeterHitCollectionName);
+ }
}
protected void startOfData() {
@@ -58,12 +77,13 @@
writers = new ArrayList<EvioWriter>();
- ECalEvioWriter ecalWriter = new ECalEvioWriter();
+ ecalWriter = new ECalEvioWriter();
+ ecalWriter.setMode(ecalMode);
ecalWriter.setEcalName(ecalName);
- ecalWriter.setRawCalorimeterHitCollectionName(rawCalorimeterHitCollectionName);
+ ecalWriter.setHitCollectionName(rawCalorimeterHitCollectionName);
writers.add(ecalWriter);
- SVTEvioWriter svtWriter = new SVTEvioWriter();
+ svtWriter = new SVTEvioWriter();
writers.add(svtWriter);
builderQueue = new LinkedList<QueuedEtEvent>();
@@ -91,7 +111,7 @@
for (int i = 0; i < writers.size(); i++) {
EvioWriter evioWriter = writers.get(i);
if (evioWriter.hasData(event)) {
- System.out.println("try to write SVT data, event " + event.getEventNumber());
+ System.out.println(evioWriter.getClass().getSimpleName() + ": writing data, event " + event.getEventNumber());
EventBuilder builder = null;
for (QueuedEtEvent queuedEvent : builderQueue) {
@@ -102,7 +122,7 @@
}
}
if (builder == null) {
- throw new RuntimeException("no queued ET events waiting for an SVT bank");
+ throw new RuntimeException("no queued ET events waiting for an " + evioWriter.getClass().getSimpleName() + " bank");
}
// Write data.
evioWriter.writeData(event, builder);
hps-java/src/main/java/org/lcsim/hps/evio
diff -u -r1.3 -r1.4
--- EventConstants.java 5 Apr 2012 19:05:23 -0000 1.3
+++ EventConstants.java 7 Apr 2012 00:07:24 -0000 1.4
@@ -13,16 +13,24 @@
public static final int SVT_BANK_NUMBER = 1;
public static final int ECAL_BANK_NUMBER = 2;
+ public static final int ECAL_WINDOW_MODE = 1;
+ public static final int ECAL_PULSE_MODE = 2;
+ public static final int ECAL_PULSE_INTEGRAL_MODE = 3;
+
+ // The composite data format for window ecal data.
+ public static final String ECAL_WINDOW_FORMAT = "c,i,l,N(c,Ns)";
+ // The composite data format for pulse ecal data.
+ public static final String ECAL_PULSE_FORMAT = "c,i,l,N(c,N(c,Ns))";
// The composite data format for pulse integral ecal data.
public static final String ECAL_PULSE_INTEGRAL_FORMAT = "c,i,l,N(c,N(s,i))";
+ // The tag for ECal window data.
+ public static final int ECAL_WINDOW_BANK_TAG = 0xe101;
+ // The tag for ECal pulse data.
+ public static final int ECAL_PULSE_BANK_TAG = 0xe102;
// The tag for ECal pulse integral data.
public static final int ECAL_PULSE_INTEGRAL_BANK_TAG = 0xe103;
- // Offset applied to ecal channels, as we are temporarily using some negative values.
- // This will eventually go away.
- public static final int ECAL_CHANNEL_OFFSET = 23;
-
// layer ID used for encoding of physical ID
public static final int ECAL_LAYER = 0;
}
hps-java/src/main/java/org/lcsim/hps/users/meeg
diff -N HPSEcalRawTrackerHitPrintDriver.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ HPSEcalRawTrackerHitPrintDriver.java 7 Apr 2012 00:07:25 -0000 1.1
@@ -0,0 +1,93 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.lcsim.hps.users.meeg;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.List;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.RawTrackerHit;
+import org.lcsim.geometry.Detector;
+import org.lcsim.geometry.IDDecoder;
+import org.lcsim.geometry.Subdetector;
+import org.lcsim.util.Driver;
+
+/**
+ *
+ * @author Sho Uemura <[log in to unmask]>
+ * @version $Id: HPSEcalRawTrackerHitPrintDriver.java,v 1.1 2012/04/07 00:07:25 meeg Exp $
+ */
+public class HPSEcalRawTrackerHitPrintDriver extends Driver {
+
+ Subdetector ecal;
+ IDDecoder dec;
+ String ecalName = "Ecal";
+ String ecalReadoutName = "EcalHits";
+ String ecalCollectionName = "EcalRawHits";
+ String outputFileName;
+ PrintWriter outputStream = null;
+ int flags;
+
+ public HPSEcalRawTrackerHitPrintDriver() {
+ }
+
+ public void setEcalCollectionName(String ecalCollectionName) {
+ this.ecalCollectionName = ecalCollectionName;
+ }
+
+ public void setEcalName(String ecalName) {
+ this.ecalName = ecalName;
+ }
+
+ public void setOutputFileName(String outputFileName) {
+ this.outputFileName = outputFileName;
+ }
+
+ public void startOfData() {
+ if (ecalCollectionName == null) {
+ throw new RuntimeException("The parameter ecalCollectionName was not set!");
+ }
+
+ if (ecalName == null) {
+ throw new RuntimeException("The parameter ecalName was not set!");
+ }
+
+ if (outputFileName != null) {
+ try {
+ outputStream = new PrintWriter(outputFileName);
+ } catch (IOException ex) {
+ throw new RuntimeException("Invalid outputFilePath!");
+ }
+ } else {
+ outputStream = new PrintWriter(System.out);
+ }
+ }
+
+ public void detectorChanged(Detector detector) {
+ // Get the Subdetector.
+ ecal = (Subdetector) detector.getSubdetector(ecalName);
+ dec = ecal.getIDDecoder();
+ }
+
+ public void process(EventHeader event) {
+ // Get the list of ECal hits.
+ if (event.hasCollection(RawTrackerHit.class, ecalCollectionName)) {
+ outputStream.println("Reading RawTrackerHits from event " + event.getEventNumber());
+ List<RawTrackerHit> hits = event.get(RawTrackerHit.class, ecalCollectionName);
+
+ //FIXME: this check is necessary because hasCollection(type, name) doesn't seem to actually check type!
+ if (!hits.isEmpty() && !RawTrackerHit.class.isInstance(hits.get(0))) {
+ return;
+ }
+ for (RawTrackerHit hit : hits) {
+ dec.setID(hit.getCellID());
+ outputStream.printf("%d\t%d\t%d\t%d\n", dec.getValue("ix"), dec.getValue("iy"), hit.getTime(), hit.getADCValues().length);
+ for (int i = 0; i < hit.getADCValues().length; i++) {
+ outputStream.printf("%d\n", hit.getADCValues()[i]);
+ }
+ }
+ }
+ }
+}
hps-java/src/main/java/org/lcsim/hps/users/meeg
diff -u -r1.4 -r1.5
--- EvioFileReader.java 4 Apr 2012 20:43:37 -0000 1.4
+++ EvioFileReader.java 7 Apr 2012 00:07:25 -0000 1.5
@@ -6,7 +6,7 @@
import org.jlab.coda.jevio.EvioEvent;
import org.jlab.coda.jevio.EvioReader;
import org.lcsim.event.EventHeader;
-import org.lcsim.hps.evio.LCSimEventBuilder;
+import org.lcsim.hps.evio.EventConstants;
import org.lcsim.hps.evio.LCSimTestRunEventBuilder;
import org.lcsim.job.JobControlManager;
import org.lcsim.util.DriverAdapter;
@@ -24,6 +24,7 @@
String detectorName = defaultDetectorName;
private JobControlManager jobMgr;
boolean debug = false;
+ int ecalMode = EventConstants.ECAL_PULSE_INTEGRAL_MODE;
EvioFileReader() {
}
@@ -31,6 +32,7 @@
private static void usage() {
System.out.println("\nUsage: java Producer -e <evio file> [-s <steering file>] [-d <detector>]\n\n"
+ " -s steering file\n"
+ + " -m ECal mode\n"
+ " -d detector name\n");
System.exit(1);
}
@@ -50,6 +52,8 @@
steeringFile = new String(args[++i]);
} else if (args[i].equalsIgnoreCase("-d")) {
detectorName = new String(args[++i]);
+ } else if (args[i].equalsIgnoreCase("-m")) {
+ ecalMode = Integer.parseInt(args[++i]);
} else {
usage();
return;
@@ -74,9 +78,10 @@
driverAdapter.configure(null);
// Setup the event builder.
- LCSimEventBuilder eventBuilder = new LCSimTestRunEventBuilder();
+ LCSimTestRunEventBuilder eventBuilder = new LCSimTestRunEventBuilder();
eventBuilder.setDetectorName(detectorName);
eventBuilder.setDebug(debug);
+ eventBuilder.setEcalMode(ecalMode);
// Open EVIO reader.
reader = new EvioReader(evioFileName);
@@ -93,80 +98,6 @@
// Supply record to Driver Adapter.
driverAdapter.recordSupplied(new RecordSuppliedEvent(new Object(), lcsimEvent));
-
-
-
-// if (event.getChildren() != null) {
-// for (BaseStructure crateBank : event.getChildren()) {
-// int crateTag = crateBank.getHeader().getTag();
-// if (crateTag == SVT_BANK_TAG) {
-// int[] intData = crateBank.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(" sample[" + j + "]=" + val);
-// }
-// }
-// } else if (crateTag == ECAL_TOP_BANK_TAG || crateTag == ECAL_BOTTOM_BANK_TAG) {
-// if (crateBank.getChildCount() > 0) {
-// for (BaseStructure slotBank : crateBank.getChildren()) {
-// CompositeData cdata = slotBank.getCompositeData();
-// System.out.println("ecal.tag=" + Integer.toHexString(slotBank.getHeader().getTag()));
-// System.out.println("cdata has " + cdata.getItems().size() + " items");
-// System.out.println("cdata has " + cdata.getTypes().size() + " types");
-// System.out.println("cdata has " + cdata.getNValues().size() + " N values");
-// int n = cdata.getNValues().size();
-// for (int i = 0; i < n; i++) {
-// System.out.println("cdata.N[" + i + "]=" + cdata.getNValues().get(i));
-// }
-// int ni = cdata.getItems().size();
-// for (int i = 0; i < ni; i++) {
-// System.out.println("cdata.type[" + i + "]=" + cdata.getTypes().get(i));
-// }
-// int slot = cdata.getByte();
-// int trigger = cdata.getInt();
-// long timestamp = cdata.getLong();
-// int nchannels = cdata.getNValue();
-// System.out.println("slot#=" + slot + "; trigger=" + trigger + "; timestamp=" + timestamp + "; nchannels=" + nchannels);
-// for (int i = 0; i < nchannels; i++) {
-// int channelNumber = cdata.getByte();
-// int npulses = cdata.getNValue();
-// System.out.println(" channel=" + channelNumber + "; npulses=" + npulses);
-// for (int j = 0; j < npulses; j++) {
-// short pulseTime = cdata.getShort();
-// int pulseIntegral = cdata.getInt();
-// System.out.println(" pulseTime=" + pulseTime + "; pulseIntegral=" + pulseIntegral);
-// }
-// }
-// }
-// }
-// }
-// }
-//
-// if (reader.getNumEventsRemaining() == 0) {
-// break;
-// }
-// }
event = reader.parseNextEvent();
}
// Cleanup.
hps-java/src/main/java/org/lcsim/hps/users/meeg
diff -u -r1.2 -r1.3
--- HPSEcalDigitalPrintDriver.java 3 Apr 2012 18:28:10 -0000 1.2
+++ HPSEcalDigitalPrintDriver.java 7 Apr 2012 00:07:25 -0000 1.3
@@ -17,7 +17,7 @@
/**
*
* @author Sho Uemura <[log in to unmask]>
- * @version $Id: HPSEcalDigitalPrintDriver.java,v 1.2 2012/04/03 18:28:10 jeremy Exp $
+ * @version $Id: HPSEcalDigitalPrintDriver.java,v 1.3 2012/04/07 00:07:25 meeg Exp $
*/
public class HPSEcalDigitalPrintDriver extends Driver {
@@ -65,6 +65,8 @@
} catch (IOException ex) {
throw new RuntimeException("Invalid outputFilePath!");
}
+ } else {
+ outputStream = new PrintWriter(System.out);
}
}
@@ -76,17 +78,19 @@
public void process(EventHeader event) {
// Get the list of ECal hits.
- List<RawCalorimeterHit> hits = event.get(RawCalorimeterHit.class, ecalCollectionName);
- if (hits == null) {
- throw new RuntimeException("Event is missing ECal hits collection!");
- }
- for (RawCalorimeterHit hit : hits) {
- dec.setID(hit.getCellID());
- if (outputStream != null) {
- outputStream.printf("%d\t%d\t%d\t%d\n", dec.getValue("ix"), dec.getValue("iy"), hit.getTimeStamp()*timeScale, hit.getAmplitude());
- } else {
- System.out.printf("%d\t%d\t%d\t%d\n", dec.getValue("ix"), dec.getValue("iy"), hit.getTimeStamp()*timeScale, hit.getAmplitude());
+ if (event.hasCollection(RawCalorimeterHit.class, ecalCollectionName)) {
+ List<RawCalorimeterHit> hits = event.get(RawCalorimeterHit.class, ecalCollectionName);
+
+ //FIXME: this check is necessary because hasCollection(type, name) doesn't seem to actually check type!
+ if (!hits.isEmpty() && !RawCalorimeterHit.class.isInstance(hits.get(0))) {
+ return;
+ }
+
+ outputStream.println("Reading RawCalorimeterHit from event " + event.getEventNumber());
+ for (RawCalorimeterHit hit : hits) {
+ dec.setID(hit.getCellID());
+ outputStream.printf("%d\t%d\t%d\t%d\n", dec.getValue("ix"), dec.getValue("iy"), hit.getTimeStamp() * timeScale, hit.getAmplitude());
}
}
}
-}
+}
\ No newline at end of file
hps-java/src/main/java/org/lcsim/hps/recon/ecal
diff -u -r1.11 -r1.12
--- HPSEcalFADCReadoutDriver.java 6 Apr 2012 00:53:19 -0000 1.11
+++ HPSEcalFADCReadoutDriver.java 7 Apr 2012 00:07:25 -0000 1.12
@@ -16,6 +16,7 @@
import org.lcsim.event.base.BaseRawTrackerHit;
import org.lcsim.geometry.Detector;
import org.lcsim.geometry.subdetector.HPSEcal3;
+import org.lcsim.hps.evio.EventConstants;
import org.lcsim.hps.util.ClockSingleton;
import org.lcsim.hps.util.RingBuffer;
import org.lcsim.util.lcio.LCIOConstants;
@@ -25,7 +26,7 @@
* Simulates time evolution of preamp output pulse.
*
* @author Sho Uemura <[log in to unmask]>
- * @version $Id: HPSEcalFADCReadoutDriver.java,v 1.11 2012/04/06 00:53:19 meeg Exp $
+ * @version $Id: HPSEcalFADCReadoutDriver.java,v 1.12 2012/04/07 00:07:25 meeg Exp $
*/
public class HPSEcalFADCReadoutDriver extends HPSEcalReadoutDriver<RawCalorimeterHit> {
@@ -67,6 +68,7 @@
private double pulseIntegral;
//output collection name for hits read out from trigger
private String ecalReadoutCollectionName = "EcalReadoutHits";
+ private int mode = EventConstants.ECAL_PULSE_INTEGRAL_MODE;
public HPSEcalFADCReadoutDriver() {
flags = 0;
@@ -125,6 +127,13 @@
resetFADCBuffers();
}
+ public void setMode(int mode) {
+ this.mode = mode;
+ if (mode != EventConstants.ECAL_WINDOW_MODE && mode != EventConstants.ECAL_PULSE_MODE && mode != EventConstants.ECAL_PULSE_INTEGRAL_MODE) {
+ throw new IllegalArgumentException("invalid mode " + mode);
+ }
+ }
+
@Override
protected void readHits(List<RawCalorimeterHit> hits) {
@@ -178,24 +187,21 @@
}
@Override
- public void process(EventHeader event) {
- super.process(event);
- //System.out.println(this.getClass().getCanonicalName() + " - process");
- // Get the list of ECal hits.
- List<CalorimeterHit> hits = event.get(CalorimeterHit.class, ecalCollectionName);
- if (hits == null) {
- throw new RuntimeException("Event is missing ECal hits collection!");
- }
-
- if (ClockSingleton.triggered()) {
- }
- }
-
- @Override
protected void processTrigger(EventHeader event) {
-// event.put(ecalReadoutCollectionName, readWindow(), RawTrackerHit.class, 0, ecalReadoutName);
-// event.put(ecalReadoutCollectionName, readPulses(), RawTrackerHit.class, 0, ecalReadoutName);
- event.put(ecalReadoutCollectionName, readIntegrals(), RawCalorimeterHit.class, 0, ecalReadoutName);
+ switch (mode) {
+ case EventConstants.ECAL_WINDOW_MODE:
+ System.out.println("Reading out ECal in window mode");
+ event.put(ecalReadoutCollectionName, readWindow(), RawTrackerHit.class, 0, ecalReadoutName);
+ break;
+ case EventConstants.ECAL_PULSE_MODE:
+ System.out.println("Reading out ECal in pulse mode");
+ event.put(ecalReadoutCollectionName, readPulses(), RawTrackerHit.class, 0, ecalReadoutName);
+ break;
+ case EventConstants.ECAL_PULSE_INTEGRAL_MODE:
+ System.out.println("Reading out ECal in integral mode");
+ event.put(ecalReadoutCollectionName, readIntegrals(), RawCalorimeterHit.class, 0, ecalReadoutName);
+ break;
+ }
}
protected short[] getWindow(long cellID) {
@@ -219,7 +225,7 @@
}
protected List<RawTrackerHit> readWindow() {
- System.out.println("Reading FADC data");
+// System.out.println("Reading FADC data");
List<RawTrackerHit> hits = new ArrayList<RawTrackerHit>();
for (Long cellID : pipelineMap.keySet()) {
short[] adcValues = getWindow(cellID);
@@ -231,7 +237,7 @@
}
protected List<RawTrackerHit> readPulses() {
- System.out.println("Reading FADC data");
+// System.out.println("Reading FADC data");
List<RawTrackerHit> hits = new ArrayList<RawTrackerHit>();
for (Long cellID : pipelineMap.keySet()) {
short[] window = getWindow(cellID);
@@ -242,7 +248,7 @@
if (window != null) {
for (int i = 0; i < readoutWindow; i++) {
if (numSamplesToRead != 0) {
- adcValues[adcValues.length-numSamplesToRead] = window[i - pointerOffset];
+ adcValues[adcValues.length - numSamplesToRead] = window[i - pointerOffset];
numSamplesToRead--;
if (numSamplesToRead == 0) {
hits.add(new BaseRawTrackerHit(cellID, thresholdCrossing, adcValues));
@@ -260,7 +266,7 @@
}
protected List<RawCalorimeterHit> readIntegrals() {
- System.out.println("Reading FADC data");
+// System.out.println("Reading FADC data");
List<RawCalorimeterHit> hits = new ArrayList<RawCalorimeterHit>();
for (Long cellID : pipelineMap.keySet()) {
short[] window = getWindow(cellID);
hps-java/src/main/resources/org/lcsim/hps/steering
diff -u -r1.1 -r1.2
--- ecal_print.lcsim 4 Apr 2012 20:43:37 -0000 1.1
+++ ecal_print.lcsim 7 Apr 2012 00:07:25 -0000 1.2
@@ -12,6 +12,7 @@
<execute>
<driver name="EventMarkerDriver"/>
<driver name="EcalPrint"/>
+ <driver name="EcalTPrint"/>
</execute>
<drivers>
<driver name="EventMarkerDriver" type="org.lcsim.job.EventMarkerDriver">
@@ -19,6 +20,9 @@
</driver>
<driver name="EcalPrint" type="org.lcsim.hps.users.meeg.HPSEcalDigitalPrintDriver">
<ecalCollectionName>EcalRawHits</ecalCollectionName>
+ </driver>
+ <driver name="EcalTPrint" type="org.lcsim.hps.users.meeg.HPSEcalRawTrackerHitPrintDriver">
+ <ecalCollectionName>EcalRawHits</ecalCollectionName>
</driver>
</drivers>
</lcsim>
hps-java/src/main/resources/org/lcsim/hps/steering
diff -u -r1.3 -r1.4
--- HPSTestRunReconToEvio.lcsim 5 Apr 2012 23:59:49 -0000 1.3
+++ HPSTestRunReconToEvio.lcsim 7 Apr 2012 00:07:25 -0000 1.4
@@ -8,16 +8,15 @@
<lcsim xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:noNamespaceSchemaLocation="http://www.lcsim.org/schemas/lcsim/1.0/lcsim.xsd">
- <inputFiles>
- <file>${inputFile}</file>
- </inputFiles>
+ <inputFiles>
+ <file>${inputFile}</file>
+ </inputFiles>
- <control>
- <numberOfEvents>-1</numberOfEvents>
- </control>
+ <control>
+ <numberOfEvents>-1</numberOfEvents>
+ </control>
<execute>
- <driver name="HPSEcalConverterAtoDDriver"/>
<driver name="EcalReadout"/>
<driver name="EcalConverter"/>
<driver name="EcalClusterer"/>
@@ -30,47 +29,40 @@
</execute>
<drivers>
-
- <driver name="HPSEcalConverterAtoDDriver" type="org.lcsim.hps.recon.ecal.HPSEcalConverterAtoDDriver">
- <scale>0.0001</scale>
- <ecalCollectionName>EcalHits</ecalCollectionName>
- <ecalName>Ecal</ecalName>
- </driver>
-
- <driver name="TestRunReconToEvio" type="org.lcsim.hps.evio.TestRunReconToEvio">
- <evioOutputFile>${evioFile}</evioOutputFile>
- </driver>
+ <driver name="TestRunReconToEvio" type="org.lcsim.hps.evio.TestRunTriggeredReconToEvio">
+ <evioOutputFile>${evioFile}</evioOutputFile>
+ </driver>
<driver name="EcalReadout"
type="org.lcsim.hps.recon.ecal.HPSEcalFADCReadoutDriver">
- <readoutPeriod>4.0</readoutPeriod>
- <coincidenceWindow>2</coincidenceWindow>
- <ecalName>Ecal</ecalName>
- <ecalCollectionName>EcalHits</ecalCollectionName>
- <ecalRawCollectionName>EcalRawHits</ecalRawCollectionName>
- <threshold>0.05</threshold>
- <scale>0.08</scale>
+ <readoutPeriod>4.0</readoutPeriod>
+ <coincidenceWindow>2</coincidenceWindow>
+ <ecalName>Ecal</ecalName>
+ <ecalCollectionName>EcalHits</ecalCollectionName>
+ <ecalRawCollectionName>EcalRawHits</ecalRawCollectionName>
+ <threshold>0.05</threshold>
+ <scale>0.08</scale>
</driver>
<driver name="EcalConverter"
type="org.lcsim.hps.recon.ecal.HPSEcalConverterDriver">
- <ecalName>Ecal</ecalName>
- <rawCollectionName>EcalRawHits</rawCollectionName>
- <ecalCollectionName>EcalCorrectedHits</ecalCollectionName>
- <scale>0.08</scale>
+ <ecalName>Ecal</ecalName>
+ <rawCollectionName>EcalRawHits</rawCollectionName>
+ <ecalCollectionName>EcalCorrectedHits</ecalCollectionName>
+ <scale>0.08</scale>
</driver>
<driver name="EcalClusterer"
type="org.lcsim.hps.recon.ecal.HPSEcalCTPClusterer">
- <ecalName>Ecal</ecalName>
- <ecalCollectionName>EcalCorrectedHits</ecalCollectionName>
+ <ecalName>Ecal</ecalName>
+ <ecalCollectionName>EcalCorrectedHits</ecalCollectionName>
</driver>
<driver name="EcalTrigger"
type="org.lcsim.hps.recon.ecal.HPSFADCTriggerDriver">
- <clusterCollectionName>EcalClusters</clusterCollectionName>
- <ecalName>Ecal</ecalName>
- <deadTime>10</deadTime>
+ <clusterCollectionName>EcalClusters</clusterCollectionName>
+ <ecalName>Ecal</ecalName>
+ <deadTime>10</deadTime>
</driver>
<driver name="SVTSensorSetup"
@@ -85,7 +77,7 @@
type="org.lcsim.hps.recon.tracking.apv25.HPSSiSensorReadout">
</driver>
- <driver name="ClockDriver"
+ <driver name="ClockDriver"
type="org.lcsim.hps.util.ClockDriver">
</driver>
CVSspam 0.2.12