Commit in hps-java/src/main/java/org/lcsim/hps/evio on MAIN | |||
LCSimTestRunEventBuilder.java | +61 | -224 | 1.6 -> 1.7 |
add proper creation of HPSSVTData collection from EVIO data
diff -u -r1.6 -r1.7 --- LCSimTestRunEventBuilder.java 5 Apr 2012 21:05:52 -0000 1.6 +++ LCSimTestRunEventBuilder.java 5 Apr 2012 23:56:14 -0000 1.7 @@ -6,38 +6,31 @@
import java.util.List; import org.jlab.coda.jevio.BaseStructure;
-import org.jlab.coda.jevio.BaseStructureHeader; -import org.jlab.coda.jevio.CompositeData;
import org.jlab.coda.jevio.EvioEvent;
-import org.jlab.coda.jevio.EvioException;
import org.lcsim.event.EventHeader;
-import org.lcsim.event.RawCalorimeterHit;
import org.lcsim.event.base.BaseLCSimEvent;
-import org.lcsim.event.base.BaseRawCalorimeterHit;
import org.lcsim.geometry.Detector; import org.lcsim.geometry.Subdetector; 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;
-import static org.lcsim.hps.evio.EventConstants.ECAL_LAYER;
/** * 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.6 2012/04/05 21:05:52 meeg Exp $
+ * @version $Id: LCSimTestRunEventBuilder.java,v 1.7 2012/04/05 23:56:14 jeremy 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";
+ + // Names of raw data collections with default settings.
private String rawCalorimeterHitCollectionName = "EcalRawHits";
- //private String svtDataCollectionName;
+ private String svtDataCollectionName = "SVTData"; +
// Detector conditions object. private Detector detector; // Debug flag.
@@ -57,10 +50,10 @@
for (Subdetector subdet : detector.getSubdetectorList()) { if (subdet instanceof HPSTracker) { trackerName = subdet.getName();
- System.out.println("trackerName = " + trackerName);
+ //System.out.println("trackerName = " + trackerName);
} else if (subdet instanceof HPSEcal3) { calorimeterName = subdet.getName();
- System.out.println("calorimeterName = " + calorimeterName);
+ //System.out.println("calorimeterName = " + calorimeterName);
} } }
@@ -70,14 +63,6 @@
ecalReader = null; }
- public String getRawTrackerHitCollectionName() { - return rawTrackerHitCollectionName; - } - - public void setRawTrackerHitCollectionName(String rawTrackerHitCollectionName) { - this.rawTrackerHitCollectionName = rawTrackerHitCollectionName; - } -
public String getRawCalorimeterHitCollectionName() { return rawCalorimeterHitCollectionName; }
@@ -86,6 +71,9 @@
this.rawCalorimeterHitCollectionName = rawCalorimeterHitCollectionName; ecalReader = null; }
+ public void setSvtDataCollectionName(String svtDataCollectionName) { + this.svtDataCollectionName = svtDataCollectionName; + }
public String getTrackerName() { return trackerName;
@@ -120,7 +108,7 @@
// Create a new LCSimEvent. EventHeader lcsimEvent = new BaseLCSimEvent(0, evioEvent.getHeader().getNumber(), detector.getDetectorName());
-
+
if (ecalReader == null) { ecalReader = new ECalEvioReader(); ecalReader.setEcalName(calorimeterName);
@@ -128,215 +116,64 @@
ecalReader.setDebug(debug); }
- // Make RawTrackerHit collection. - //List<RawTrackerHit> rawTrackerHits = makeRawTrackerHits(evioEvent); -
// Make RawCalorimeterHit collection, combining top and bottom section of ECal into one list. ecalReader.makeRawCalorimeterHits(evioEvent, lcsimEvent);
+ // Make SVT data. + List<HPSSVTData> svtData = makeSVTData(evioEvent); + lcsimEvent.put(svtDataCollectionName, svtData, HPSSVTData.class, 0); +
return lcsimEvent; }
-
+
private List<HPSSVTData> makeSVTData(EvioEvent event) {
- List<HPSSVTData> data = new ArrayList<HPSSVTData>();
+ 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) {
- int[] intData = crateBank.getIntData(); - - 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]; - - HPSSVTData svtData = new HPSSVTData(sampleData); - - data.add(svtData); - - /* - int fpga = svtData.getFPGAAddress(); - 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); - } - */ - }
+ if (crateBank.getChildCount() == 0) + throw new RuntimeException("No children found in SVT bank."); + for (BaseStructure frameBank : crateBank.getChildren()) { + + if (frameBank.getHeader().getTag() == 7) { + //System.out.println("skipping FPGA 7 temp bank"); + continue; + } + + int[] intData = frameBank.getIntData(); + //System.out.println("intData.len = " + intData.length); + 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]; + + HPSSVTData svtData = new HPSSVTData(sampleData); + + svtDataCollection.add(svtData); + + /* + int fpga = svtData.getFPGAAddress(); + 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); + } + */ + } + }
}
- } - 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 svtDataCollection;
}
- 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; - } - - 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; - } - */ -// private void makeRawCalorimeterHits(EvioEvent event, EventHeader lcsimEvent) { -// List<RawCalorimeterHit> hits = new ArrayList<RawCalorimeterHit>(); -// for (BaseStructure bank : event.getChildren()) { -// BaseStructureHeader header = bank.getHeader(); -// int bankTag = header.getTag(); -// if (bankTag == MCRawDataToEvio4Converter.ecalBottomBankTag || bankTag == MCRawDataToEvio4Converter.ecalTopBankTag) { -// if (bank.getChildCount() > 0) { -// if (debug) { -// System.out.println("ECal bank tag: " + header.getTag() + "; childCount: " + bank.getChildCount()); -// } -// for (BaseStructure slotBank : bank.getChildren()) { -// CompositeData cdata = null; -// try { -// cdata = slotBank.getCompositeData(); -// } catch (EvioException e) { -// throw new RuntimeException(e); -// } -// List<RawCalorimeterHit> bankHits = makeRawCalorimeterHits(cdata, bankTag); -// hits.addAll(bankHits); -// } -// } -// } -// } -// -// lcsimEvent.put(rawCalorimeterHitCollectionName, hits, RawCalorimeterHit.class, 0, getCalorimeterReadoutName()); -// } -// -// private List<RawCalorimeterHit> makeRawCalorimeterHits(CompositeData cdata, int bankTag) { -// List<RawCalorimeterHit> hits = new ArrayList<RawCalorimeterHit>(); -// if (ecalIDConverter == null) { -// ecalIDConverter = new HPSEcalDaqIDConverter(); -// ecalIDConverter.fillDaqCellMap(detector.getSubdetector(calorimeterName)); -// } -// -// 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); -//// 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(); -// int pulseIntegral = cdata.getInt(); -// if (debug) { -// System.out.println(" pulseTime=" + pulseTime + "; pulseIntegral=" + pulseIntegral); -// } -// hits.add(new BaseRawCalorimeterHit(id, pulseIntegral, pulseTime)); -// } -// } -// return hits; -// }
}
\ No newline at end of file
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