Commit in hps-java/src/main/java/org/lcsim/hps on MAIN | |||
evio/LCSimTestRunEventBuilder.java | +113 | -118 | 1.3 -> 1.4 |
/TestRunTriggeredReconToEvio.java | +21 | -6 | 1.1 -> 1.2 |
/EventConstants.java | +4 | -1 | 1.1 -> 1.2 |
recon/ecal/HPSEcalDaqIDConverter.java | +43 | -63 | 1.1 -> 1.2 |
+181 | -188 |
ECal ID conversion now uses longs instead of objects; integrated with EVIO<->LCIO
diff -u -r1.3 -r1.4 --- LCSimTestRunEventBuilder.java 3 Apr 2012 18:36:48 -0000 1.3 +++ LCSimTestRunEventBuilder.java 5 Apr 2012 17:01:08 -0000 1.4 @@ -19,34 +19,33 @@
import org.lcsim.geometry.subdetector.HPSEcal3; import org.lcsim.geometry.subdetector.HPSTracker; import org.lcsim.geometry.util.IDEncoder;
+import org.lcsim.hps.recon.ecal.HPSEcalDaqIDConverter;
import org.lcsim.hps.recon.tracking.HPSSVTData; /** * 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.3 2012/04/03 18:36:48 jeremy Exp $
+ * @version $Id: LCSimTestRunEventBuilder.java,v 1.4 2012/04/05 17:01:08 meeg Exp $
*/ public class LCSimTestRunEventBuilder implements LCSimEventBuilder { // Names of subdetectors. private String trackerName; private String calorimeterName;
-
// Names of raw data collections with default settings. private String rawTrackerHitCollectionName = "RawTrackerHitMaker_RawTrackerHits"; private String rawCalorimeterHitCollectionName = "EcalRawHits";
-
//private String svtDataCollectionName;
-
// Detector conditions object. private Detector detector;
-
// Debug flag. private boolean debug = false;
+ private HPSEcalDaqIDConverter ecalIDConverter; + + public LCSimTestRunEventBuilder() { + }
- public LCSimTestRunEventBuilder() {} -
public void setDetectorName(String detectorName) { // Make a dummy event to setup the conditions system.
@@ -130,25 +129,25 @@
return lcsimEvent; }
-
+
private List<HPSSVTData> makeSVTData(EvioEvent event) { List<HPSSVTData> data = new ArrayList<HPSSVTData>(); for (BaseStructure crateBank : event.getChildren()) {
- int crateTag = crateBank.getHeader().getTag(); - if (crateTag == SVT_BANK_TAG) {
+ int crateTag = crateBank.getHeader().getTag(); + if (crateTag == SVT_BANK_TAG) {
int[] intData = crateBank.getIntData();
-
+
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);
-
+
data.add(svtData); /*
@@ -156,109 +155,108 @@
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 data; } /* private List<RawTrackerHit> makeRawTrackerHits(EvioEvent event) {
- List<RawTrackerHit> rawTrackerHits = new ArrayList<RawTrackerHit>(); - for (BaseStructure bank : event.getChildren()) { - if (bank.getHeader().getTag() == MCRawDataToEvio4Converter.trackerBankTag) { - //System.out.println("found SVT bank; tag = " + MCRawDataToEvio4Converter.trackerBankTag); - CompositeData cdata = null; - try { - cdata = bank.getCompositeData(); - } catch (EvioException e) { - throw new RuntimeException(e); - } - rawTrackerHits.addAll(makeRawTrackerHits(cdata)); - } - } - return rawTrackerHits;
+ List<RawTrackerHit> rawTrackerHits = new ArrayList<RawTrackerHit>(); + for (BaseStructure bank : event.getChildren()) { + if (bank.getHeader().getTag() == MCRawDataToEvio4Converter.trackerBankTag) { + //System.out.println("found SVT bank; tag = " + MCRawDataToEvio4Converter.trackerBankTag); + CompositeData cdata = null; + try { + cdata = bank.getCompositeData(); + } catch (EvioException e) { + throw new RuntimeException(e);
}
- -
+ rawTrackerHits.addAll(makeRawTrackerHits(cdata)); + } + } + return rawTrackerHits; + } + +
private List<RawTrackerHit> makeRawTrackerHits(CompositeData cdata) {
- - // Get some ID info before looping in order to strip out irrelevant fields. - // TODO Next three should be cached so as to avoid calling every event. - IIdentifierDictionary dict = detector.getSubdetector(trackerName).getDetectorElement().getIdentifierHelper().getIdentifierDictionary(); - int fieldIdx = dict.getFieldIndex("side"); - int sideIdx = dict.getFieldIndex("strip"); - - // List of hits to return. - List<RawTrackerHit> hits = new ArrayList<RawTrackerHit>(); - - // Loop over the items in the CompositeData. - int n = cdata.getNValue(); - if (debug) { - System.out.println("RawTrackerHit.N = " + n); - } - for (int i = 0; i < n; i++) { - - // Get values for hit from composite data. - Long id = cdata.getLong(); - int time = cdata.getInt(); - int adcValue = cdata.getInt(); - - // Make the new hit. - RawTrackerHit hit = new BaseRawTrackerHit(id, time, new short[]{(short) adcValue}); - - // The "side" and "strip" fields needs to be stripped from the ID for sensor lookup. - IExpandedIdentifier expId = dict.unpack(hit.getIdentifier()); - expId.setValue(fieldIdx, 0); - expId.setValue(sideIdx, 0); - IIdentifier strippedId = dict.pack(expId); - - // Find the sensor for this hit using the stripped ID. - SiSensor sensor = findSensor(strippedId); - - // Assign sensor to hit. - hit.setDetectorElement(sensor); - - // Add this hit to the list. - hits.add(hit); - } - - if (debug) { - System.out.println("makeRawTrackerHits created " + hits.size() + " hits"); - } - - return hits;
+ + // Get some ID info before looping in order to strip out irrelevant fields. + // TODO Next three should be cached so as to avoid calling every event. + IIdentifierDictionary dict = detector.getSubdetector(trackerName).getDetectorElement().getIdentifierHelper().getIdentifierDictionary(); + int fieldIdx = dict.getFieldIndex("side"); + int sideIdx = dict.getFieldIndex("strip"); + + // List of hits to return. + List<RawTrackerHit> hits = new ArrayList<RawTrackerHit>(); + + // Loop over the items in the CompositeData. + int n = cdata.getNValue(); + if (debug) { + System.out.println("RawTrackerHit.N = " + n);
}
-
+ for (int i = 0; i < n; i++) { + + // Get values for hit from composite data. + Long id = cdata.getLong(); + int time = cdata.getInt(); + int adcValue = cdata.getInt(); + + // Make the new hit. + RawTrackerHit hit = new BaseRawTrackerHit(id, time, new short[]{(short) adcValue}); + + // The "side" and "strip" fields needs to be stripped from the ID for sensor lookup. + IExpandedIdentifier expId = dict.unpack(hit.getIdentifier()); + expId.setValue(fieldIdx, 0); + expId.setValue(sideIdx, 0); + IIdentifier strippedId = dict.pack(expId); + + // Find the sensor for this hit using the stripped ID. + SiSensor sensor = findSensor(strippedId); + + // Assign sensor to hit. + hit.setDetectorElement(sensor); + + // Add this hit to the list. + hits.add(hit); + } + + if (debug) { + System.out.println("makeRawTrackerHits created " + hits.size() + " hits"); + } + + return hits; + } +
private SiSensor findSensor(IIdentifier id) {
- List<IDetectorElement> des = DetectorElementStore.getInstance().find(id); - SiSensor sensor = null; - if (des == null || des.isEmpty()) { - throw new RuntimeException("Failed to find any DetectorElements with ID <0x" + Long.toHexString(id.getValue()) + ">."); - } else if (des.size() == 1) { - sensor = (SiSensor) des.get(0); - } else { - for (IDetectorElement de : des) { - if (de instanceof SiSensor) { - sensor = (SiSensor) de; - break; - } - } - } - if (sensor == null) { - throw new RuntimeException("No sensor was found with ID <0x" + Long.toHexString(id.getValue()) + ">."); - } - return sensor;
+ List<IDetectorElement> des = DetectorElementStore.getInstance().find(id); + SiSensor sensor = null; + if (des == null || des.isEmpty()) { + throw new RuntimeException("Failed to find any DetectorElements with ID <0x" + Long.toHexString(id.getValue()) + ">."); + } else if (des.size() == 1) { + sensor = (SiSensor) des.get(0); + } else { + for (IDetectorElement de : des) { + if (de instanceof SiSensor) { + sensor = (SiSensor) de; + break;
}
- */ -
+ } + } + if (sensor == null) { + throw new RuntimeException("No sensor was found with ID <0x" + Long.toHexString(id.getValue()) + ">."); + } + return sensor; + } + */
private List<RawCalorimeterHit> makeRawCalorimeterHits(EvioEvent event) { List<RawCalorimeterHit> hits = new ArrayList<RawCalorimeterHit>(); for (BaseStructure bank : event.getChildren()) {
@@ -287,7 +285,11 @@
private List<RawCalorimeterHit> makeRawCalorimeterHits(CompositeData cdata, int bankTag) { List<RawCalorimeterHit> hits = new ArrayList<RawCalorimeterHit>();
- IDEncoder enc = new IDEncoder(detector.getSubdetector(calorimeterName).getIDDecoder().getIDDescription());
+ if (ecalIDConverter == null) { + ecalIDConverter = new HPSEcalDaqIDConverter(); + ecalIDConverter.fillDaqCellMap(new IDEncoder(detector.getSubdetector(calorimeterName).getIDDecoder().getIDDescription())); + } +
if (debug) { int n = cdata.getNValues().size();
@@ -300,7 +302,8 @@
} }
- int slot = cdata.getByte();
+ int crate = bankTag; + short slot = cdata.getByte();
int trigger = cdata.getInt(); long timestamp = cdata.getLong(); int nchannels = cdata.getNValue();
@@ -308,27 +311,19 @@
System.out.println("slot#=" + slot + "; trigger=" + trigger + "; timestamp=" + timestamp + "; nchannels=" + nchannels); } for (int j = 0; j < nchannels; j++) {
- int channelNumber = cdata.getByte();
+ short channel = cdata.getByte();
int npulses = cdata.getNValue(); if (debug) {
- System.out.println(" channel=" + channelNumber + "; npulses=" + npulses);
+ System.out.println(" channel=" + channel + "; npulses=" + npulses);
}
+ long id = ecalIDConverter.physicalToDaqID(HPSEcalDaqIDConverter.getDaqID(crate, slot, channel));
for (int k = 0; k < npulses; k++) { short pulseTime = cdata.getShort(); int pulseIntegral = cdata.getInt(); if (debug) { System.out.println(" pulseTime=" + pulseTime + "; pulseIntegral=" + pulseIntegral); }
- - //TODO: replace this with the real ID translation scheme - if (bankTag == MCRawDataToEvio4Converter.ecalTopBankTag) { - enc.setValue("iy", slot); - } else { - enc.setValue("iy", -1 * slot); - } - enc.setValue("ix", channelNumber - EventConstants.ECAL_CHANNEL_OFFSET); - - hits.add(new BaseRawCalorimeterHit(enc.getID(), pulseIntegral, pulseTime));
+ hits.add(new BaseRawCalorimeterHit(id, pulseIntegral, pulseTime));
} } return hits;
diff -u -r1.1 -r1.2 --- TestRunTriggeredReconToEvio.java 4 Apr 2012 20:43:37 -0000 1.1 +++ TestRunTriggeredReconToEvio.java 5 Apr 2012 17:01:08 -0000 1.2 @@ -2,12 +2,13 @@
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_FORMAT; import static org.lcsim.hps.evio.EventConstants.ECAL_PULSE_INTEGRAL_BANK_TAG; 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 static org.lcsim.hps.evio.EventConstants.ECAL_SYSTEM; +import static org.lcsim.hps.evio.EventConstants.ECAL_LAYER;
import java.io.IOException; import java.util.ArrayList;
@@ -27,6 +28,8 @@
import org.lcsim.event.EventHeader.LCMetaData; import org.lcsim.event.RawCalorimeterHit; import org.lcsim.geometry.IDDecoder;
+import org.lcsim.geometry.util.IDEncoder; +import org.lcsim.hps.recon.ecal.HPSEcalDaqIDConverter;
import org.lcsim.hps.recon.tracking.HPSSVTData; import org.lcsim.util.Driver;
@@ -44,9 +47,11 @@
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;
public TestRunTriggeredReconToEvio() { }
@@ -109,7 +114,7 @@
// Write SVTData. writeSVTData(event, builder); }
-
+
if (event.hasCollection(RawCalorimeterHit.class, rawCalorimeterHitCollectionName)) { System.out.println("try to write ECal data, event " + event.getEventNumber()); EventBuilder builder = null;
@@ -148,6 +153,14 @@
} private void writeRawCalorimeterHits(EventHeader event, EventBuilder builder) {
+ if (ecalIDConverter == null) { + ecalIDConverter = new HPSEcalDaqIDConverter(); + System.out.println(event.getDetector().getSubdetector(ecalName).getIDDecoder().getIDDescription()); + IDEncoder enc = new IDEncoder(event.getDetector().getSubdetector(ecalName).getIDDecoder().getIDDescription()); + enc.setValue("system", ECAL_SYSTEM); + enc.setValue("layer", ECAL_LAYER); + ecalIDConverter.fillDaqCellMap(enc); + }
List<RawCalorimeterHit> rawCalorimeterHits = event.get(RawCalorimeterHit.class, rawCalorimeterHitCollectionName); LCMetaData meta = event.getMetaData(rawCalorimeterHits); writeRawCalorimeterHits(meta, rawCalorimeterHits, builder);
@@ -216,8 +229,11 @@
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);
+// 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>()); }
@@ -244,8 +260,7 @@
data.addN(nhits); // number of channels for (Long id : hitIDs) { dec.setID(id);
- int ix = dec.getValue("ix"); - int channel = ix + ECAL_CHANNEL_OFFSET;
+ int channel = HPSEcalDaqIDConverter.getChannel(ecalIDConverter.physicalToDaqID(id));
data.addUchar((byte) channel); // channel # List<RawCalorimeterHit> channelHits = hitMap.get(id); data.addN(channelHits.size()); // number of pulses
diff -u -r1.1 -r1.2 --- EventConstants.java 29 Mar 2012 04:14:14 -0000 1.1 +++ EventConstants.java 5 Apr 2012 17:01:08 -0000 1.2 @@ -18,8 +18,11 @@
// 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;
+ + public static final int ECAL_SYSTEM = 13; + public static final int ECAL_LAYER = 0;
}
diff -u -r1.1 -r1.2 --- HPSEcalDaqIDConverter.java 4 Apr 2012 23:34:51 -0000 1.1 +++ HPSEcalDaqIDConverter.java 5 Apr 2012 17:01:08 -0000 1.2 @@ -8,23 +8,24 @@
import java.io.StreamTokenizer; import java.util.HashMap; import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.geometry.util.IDEncoder;
/** * * @author meeg
- * @version $Id: HPSEcalDaqIDConverter.java,v 1.1 2012/04/04 23:34:51 meeg Exp $
+ * @version $Id: HPSEcalDaqIDConverter.java,v 1.2 2012/04/05 17:01:08 meeg Exp $
*/ public class HPSEcalDaqIDConverter {
- private HashMap<DaqID, PhysicalID> daqToPhysicalMap; - private HashMap<PhysicalID, DaqID> physicalToDaqMap;
+ private HashMap<Long, Long> daqToPhysicalMap; + private HashMap<Long, Long> physicalToDaqMap;
public HPSEcalDaqIDConverter() {
- daqToPhysicalMap = new HashMap<DaqID, PhysicalID>(); - physicalToDaqMap = new HashMap<PhysicalID, DaqID>();
+ daqToPhysicalMap = new HashMap<Long, Long>(); + physicalToDaqMap = new HashMap<Long, Long>();
}
- public void fillDaqCellMap() {
+ public void fillDaqCellMap(IDEncoder enc) {
System.out.println("reading DAQ map"); ConditionsManager conditions = ConditionsManager.defaultInstance(); StreamTokenizer tok = null;
@@ -37,79 +38,58 @@
tok.eolIsSignificant(false); tok.parseNumbers(); try {
- int[] ids = new int[5]; - do { - for (int i = 0; i < 5; i++) { - if (tok.nextToken() == StreamTokenizer.TT_NUMBER) { - ids[i] = (int) tok.nval; - } else { - throw new IOException("expected an int from DAQ map, instead got " + tok); - } - } - addMapEntry(ids[0], ids[1], ids[2], ids[3], ids[4]); - System.out.printf("x = %d, y = %d, crate = %d, slot = %d, channel = %d\n", ids[0], ids[1], ids[2], ids[3], ids[4]); - } while (tok.nextToken() != StreamTokenizer.TT_EOF);
+ while (tok.nextToken() != StreamTokenizer.TT_EOF) { + tok.pushBack(); + int x = (int) getNumber(tok); + int y = (int) getNumber(tok); + enc.setValue("ix", x); + enc.setValue("iy", y); + int crate = (int) getNumber(tok); + short slot = (short) getNumber(tok); + short channel = (short) getNumber(tok); + addMapEntry(enc.getID(), getDaqID(crate, slot, channel)); +// System.out.printf("x = %d, y = %d, crate = %d, slot = %d, channel = %d\n", x, y, crate, slot, channel); +// System.out.printf("physicalID = %d, daqID = %d\n",enc.getID(), getDaqID(crate, slot, channel)); + }
} catch (IOException e) { throw new RuntimeException("couldn't parse DAQ map", e); } }
- public DaqID physicalToDaqID(PhysicalID physicalID) { - return physicalToDaqMap.get(physicalID); - } - - public PhysicalID daqToPhysicalID(DaqID daqID) { - return daqToPhysicalMap.get(daqID);
+ private static double getNumber(StreamTokenizer tok) throws IOException { + if (tok.nextToken() == StreamTokenizer.TT_NUMBER) { + return tok.nval; + } else { + throw new IOException("expected an int from DAQ map, instead got " + tok); + }
}
- private void addMapEntry(int x, int y, int crate, int slot, int channel) { - DaqID daqID = new DaqID(crate, slot, channel); - PhysicalID physicalID = new PhysicalID(x, y);
+ private void addMapEntry(long physicalID, long daqID) {
daqToPhysicalMap.put(daqID, physicalID); physicalToDaqMap.put(physicalID, daqID); }
- public class DaqID { - - private int crate; - private int slot; - private int channel; - - public DaqID(int crate, int slot, int channel) { - this.crate = crate; - this.slot = slot; - this.channel = channel; - } - - public int getChannel() { - return channel; - } - - public int getCrate() { - return crate; - } - - public int getSlot() { - return slot; - }
+ public static long getDaqID(int crate, short slot, short channel) { + return (((long) crate) << 32) | ((long) slot << 16) | (long) channel;
}
- public class PhysicalID {
+ public static int getCrate(long physicalID) { + return (int) (physicalID >>> 32); + }
- private int x; - private int y;
+ public static short getSlot(long physicalID) { + return (short) ((physicalID >>> 16) & 0xFFFF); + }
- public PhysicalID(int x, int y) { - this.x = x; - this.y = y; - }
+ public static short getChannel(long physicalID) { + return (short) (physicalID & 0xFFFF); + }
- public int getX() { - return x; - }
+ public Long physicalToDaqID(long physicalID) { + return physicalToDaqMap.get(physicalID); + }
- public int getY() { - return y; - }
+ public Long daqToPhysicalID(long daqID) { + return daqToPhysicalMap.get(daqID);
} }
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