Commit in hps-java/src/main/java/org/lcsim/hps on MAIN | |||
evio/LCSimTestRunEventBuilder.java | +101 | -94 | 1.15 -> 1.16 |
/ECalEvioReader.java | +14 | -8 | 1.11 -> 1.12 |
recon/ecal/HPSEcalConditions.java | +70 | -8 | 1.3 -> 1.4 |
+185 | -110 |
read ECal bad channels file; make EventBuilder stuff friendlier
diff -u -r1.15 -r1.16 --- LCSimTestRunEventBuilder.java 29 Apr 2012 23:05:26 -0000 1.15 +++ LCSimTestRunEventBuilder.java 2 May 2012 20:31:38 -0000 1.16 @@ -21,98 +21,105 @@
*/ public class LCSimTestRunEventBuilder implements LCSimEventBuilder {
- // Names of subdetectors. - private String trackerName; - // Detector conditions object. - private Detector detector; - // Debug flag. - private boolean debug = false; - ECalEvioReader ecalReader = null; - SVTEvioReader svtReader = null; - - public LCSimTestRunEventBuilder() { - LCSimConditionsManagerImplementation.register(); - - ecalReader = new ECalEvioReader(); - svtReader = new SVTEvioReader(); - } - - public void setDetectorName(String detectorName) { - // Make a dummy event to setup the conditions system. - EventHeader dummyEvent = new BaseLCSimEvent(0, 0, detectorName); - detector = dummyEvent.getDetector(); - - // Set default detector names by looking for HPS detector types. - for (Subdetector subdet : detector.getSubdetectorList()) { - if (subdet instanceof HPSTracker) { - trackerName = subdet.getName(); - } else if (subdet instanceof HPSEcal3) { - ecalReader.setEcalName(subdet.getName()); - //System.out.println("calorimeterName = " + calorimeterName); - } - } - } - - public void setDebug(boolean debug) { - this.debug = debug; - ecalReader.setDebug(debug); - } - - public void setEcalHitCollectionName(String ecalHitCollectionName) { - ecalReader.setHitCollectionName(ecalHitCollectionName); - } - - public void setTrackerName(String trackerName) { - this.trackerName = trackerName; - } - - public String getTrackerReadoutName() { - return detector.getSubdetector(trackerName).getReadout().getName(); - } - - public void setEcalName(String ecalName) { - ecalReader.setEcalName(ecalName); - } - - public Detector getDetector() { - return detector; - } - - public EventHeader makeLCSimEvent(EvioEvent evioEvent) throws EvioException { - if (!isPhysicsEvent(evioEvent)) { - throw new EvioException("Not a physics event: event tag " + evioEvent.getHeader().getTag()); - } - - int[] eventID = {0, 0, 0}; - //array of length 3: {event number, trigger code, readout status} - if (evioEvent.getChildCount() > 0) { - for (BaseStructure bank : evioEvent.getChildren()) { - if (bank.getHeader().getTag() == EventConstants.EVENTID_BANK_TAG) { - eventID = bank.getIntData(); - } - } - } - - if (debug) { - System.out.println("Read EVIO event number " + eventID[0]); - } - - - // Create a new LCSimEvent. - EventHeader lcsimEvent = new BaseLCSimEvent(0, eventID[0], detector.getDetectorName()); - - // Make RawCalorimeterHit collection, combining top and bottom section of ECal into one list. - if (!ecalReader.makeHits(evioEvent, lcsimEvent)) - System.out.println(); - - // Make SVT RawTrackerHits - svtReader.makeHits(evioEvent, lcsimEvent); - - return lcsimEvent; - } - - @Override - public boolean isPhysicsEvent(EvioEvent evioEvent) { - return (evioEvent.getHeader().getTag() == EventConstants.PHYSICS_EVENT_TAG); - }
+ // Names of subdetectors. + private String trackerName; + // Detector conditions object. + private Detector detector; + // Debug flag. + private boolean debug = false; + ECalEvioReader ecalReader = null; + SVTEvioReader svtReader = null; + + public LCSimTestRunEventBuilder() { + LCSimConditionsManagerImplementation.register(); + + ecalReader = new ECalEvioReader(); + svtReader = new SVTEvioReader(); + } + + public void setDetectorName(String detectorName) { + // Make a dummy event to setup the conditions system. + EventHeader dummyEvent = new BaseLCSimEvent(0, 0, detectorName); + detector = dummyEvent.getDetector(); + + // Set default detector names by looking for HPS detector types. + for (Subdetector subdet : detector.getSubdetectorList()) { + if (subdet instanceof HPSTracker) { + trackerName = subdet.getName(); + } else if (subdet instanceof HPSEcal3) { + ecalReader.setEcalName(subdet.getName()); + //System.out.println("calorimeterName = " + calorimeterName); + } + } + } + + public void setDebug(boolean debug) { + this.debug = debug; + ecalReader.setDebug(debug); + } + + public void setEcalHitCollectionName(String ecalHitCollectionName) { + ecalReader.setHitCollectionName(ecalHitCollectionName); + } + + public void setTrackerName(String trackerName) { + this.trackerName = trackerName; + } + + public String getTrackerReadoutName() { + return detector.getSubdetector(trackerName).getReadout().getName(); + } + + public void setEcalName(String ecalName) { + ecalReader.setEcalName(ecalName); + } + + public Detector getDetector() { + return detector; + } + + public EventHeader makeLCSimEvent(EvioEvent evioEvent) throws EvioException { + if (!isPhysicsEvent(evioEvent)) { + throw new EvioException("Not a physics event: event tag " + evioEvent.getHeader().getTag()); + } + + int[] eventID = {0, 0, 0}; + //array of length 3: {event number, trigger code, readout status} + if (evioEvent.getChildCount() > 0) { + for (BaseStructure bank : evioEvent.getChildren()) { + if (bank.getHeader().getTag() == EventConstants.EVENTID_BANK_TAG) { + eventID = bank.getIntData(); + } + } + } + + if (debug) { + System.out.println("Read EVIO event number " + eventID[0]); + } + + + // Create a new LCSimEvent. + EventHeader lcsimEvent = new BaseLCSimEvent(0, eventID[0], detector.getDetectorName()); + + // Make RawCalorimeterHit collection, combining top and bottom section of ECal into one list. + try { + ecalReader.makeHits(evioEvent, lcsimEvent); + } catch (Exception e) { + e.printStackTrace(); + } + + // Make SVT RawTrackerHits + try { + svtReader.makeHits(evioEvent, lcsimEvent); + } catch (Exception e) { + e.printStackTrace(); + } + + return lcsimEvent; + } + + @Override + public boolean isPhysicsEvent(EvioEvent evioEvent) { + return (evioEvent.getHeader().getTag() == EventConstants.PHYSICS_EVENT_TAG); + }
}
\ No newline at end of file
diff -u -r1.11 -r1.12 --- ECalEvioReader.java 2 May 2012 16:53:28 -0000 1.11 +++ ECalEvioReader.java 2 May 2012 20:31:38 -0000 1.12 @@ -17,7 +17,7 @@
/** * * @author Sho Uemura <[log in to unmask]>
- * @version $Id: ECalEvioReader.java,v 1.11 2012/05/02 16:53:28 meeg Exp $
+ * @version $Id: ECalEvioReader.java,v 1.12 2012/05/02 20:31:38 meeg Exp $
*/ public class ECalEvioReader extends EvioReader { // Names of subdetectors.
@@ -114,8 +114,10 @@
if (debug) { System.out.println(" channel=" + channel + "; nSamples=" + nSamples); }
- long daqID = HPSEcalConditions.getDaqID(crate, slot, channel); - Long id = HPSEcalConditions.daqToPhysicalID(daqID);
+ Long id = HPSEcalConditions.daqToPhysicalID(crate, slot, channel); + if (id == null) { + System.out.printf("Crate %d, slot %d, channel %d not found in map\n", crate, slot, channel); + }
short[] adcValues = new short[nSamples]; for (int i = 0; i < nSamples; i++) {
@@ -153,8 +155,10 @@
if (debug) { System.out.println(" channel=" + channel + "; npulses=" + npulses); }
- long daqID = HPSEcalConditions.getDaqID(crate, slot, channel); - Long id = HPSEcalConditions.daqToPhysicalID(daqID);
+ Long id = HPSEcalConditions.daqToPhysicalID(crate, slot, channel); + if (id == null) { + System.out.printf("Crate %d, slot %d, channel %d not found in map\n", crate, slot, channel); + }
for (int k = 0; k < npulses; k++) { short pulseNum = cdata.getByte();
@@ -182,7 +186,7 @@
System.out.println("cdata.type[" + i + "]=" + cdata.getTypes().get(i)); } }
- while (cdata.index()+1 < cdata.getItems().size()) { //the +1 is a hack because sometimes an extra byte gets read (padding)
+ while (cdata.index() + 1 < cdata.getItems().size()) { //the +1 is a hack because sometimes an extra byte gets read (padding)
short slot = cdata.getByte(); int trigger = cdata.getInt(); long timestamp = cdata.getLong();
@@ -196,8 +200,10 @@
if (debug) { System.out.println(" channel=" + channel + "; npulses=" + npulses); }
- long daqID = HPSEcalConditions.getDaqID(crate, slot, channel); - Long id = HPSEcalConditions.daqToPhysicalID(daqID);
+ Long id = HPSEcalConditions.daqToPhysicalID(crate, slot, channel); + if (id == null) { + System.out.printf("Crate %d, slot %d, channel %d not found in map\n", crate, slot, channel); + }
for (int k = 0; k < npulses; k++) { short pulseTime = cdata.getShort();
diff -u -r1.3 -r1.4 --- HPSEcalConditions.java 2 May 2012 16:53:29 -0000 1.3 +++ HPSEcalConditions.java 2 May 2012 20:31:38 -0000 1.4 @@ -5,6 +5,7 @@
import java.io.IOException; import java.io.Reader; import java.util.HashMap;
+import java.util.HashSet;
import java.util.StringTokenizer; import org.lcsim.conditions.ConditionsManager; import org.lcsim.detector.identifier.ExpandedIdentifier;
@@ -14,7 +15,7 @@
/** * * @author meeg
- * @version $Id: HPSEcalConditions.java,v 1.3 2012/05/02 16:53:29 meeg Exp $
+ * @version $Id: HPSEcalConditions.java,v 1.4 2012/05/02 20:31:38 meeg Exp $
*/ public class HPSEcalConditions {
@@ -26,6 +27,9 @@
private static HashMap<Long, Integer> daqToPedestalMap = new HashMap<Long, Integer>(); private static HashMap<Long, Double> daqToNoiseMap = new HashMap<Long, Double>(); private static boolean pedestalsLoaded = false;
+ //set of bad channels to ignore + private static HashSet<Long> badChannelsSet = new HashSet<Long>(); + private static boolean badChannelsLoaded = false;
private HPSEcalConditions() { }
@@ -38,6 +42,10 @@
return pedestalsLoaded; }
+ public static boolean badChannelsLoaded() { + return badChannelsLoaded; + } +
public static void loadPedestals() { ConditionsManager conditions = ConditionsManager.defaultInstance(); try {
@@ -51,12 +59,12 @@
pedestalsLoaded = true; }
- public static void loadPedestals(Reader pedestalsReader, int crate) { - BufferedReader bufferedPedestals = new BufferedReader(pedestalsReader);
+ public static void loadPedestals(Reader reader, int crate) { + BufferedReader bufferedReader = new BufferedReader(reader);
String line; while (true) { try {
- line = bufferedPedestals.readLine();
+ line = bufferedReader.readLine();
} catch (IOException e) { throw new RuntimeException("couldn't parse pedestals file", e); }
@@ -85,6 +93,56 @@
} }
+ public static void loadBadChannels(Subdetector ecal) { + + System.out.println("reading ECal bad channels"); + + IIdentifierHelper helper = ecal.getDetectorElement().getIdentifierHelper(); + IExpandedIdentifier expId = new ExpandedIdentifier(helper.getIdentifierDictionary().getNumberOfFields()); + expId.setValue(helper.getFieldIndex("system"), ecal.getSystemID()); + ConditionsManager conditions = ConditionsManager.defaultInstance(); + BufferedReader bufferedReader; + try { + bufferedReader = new BufferedReader(conditions.getRawConditions("daqmap/ecal.badchannels").getReader()); + } catch (IOException e) { + throw new RuntimeException("couldn't get ECal bad channels from conditions manager", e); + } + String line; + while (true) { + try { + line = bufferedReader.readLine(); + } catch (IOException e) { + throw new RuntimeException("couldn't parse ECal bad channels", e); + } + if (line == null) { + break; + } + + if (line.indexOf("#") != -1) { + line = line.substring(0, line.indexOf("#")); + } + + StringTokenizer lineTok = new StringTokenizer(line); + + if (lineTok.countTokens() != 0) { + if (lineTok.countTokens() != 2) { + throw new RuntimeException("Invalid line in ECal bad channels: " + line); + } else { + int x = Integer.valueOf(lineTok.nextToken()); + int y = Integer.valueOf(lineTok.nextToken()); + expId.setValue(helper.getFieldIndex("ix"), x); + expId.setValue(helper.getFieldIndex("iy"), y); + badChannelsSet.add(helper.pack(expId).getValue()); + } + } + } + badChannelsLoaded = true; + } + + public static boolean isBadChannel(long id) { + return badChannelsSet.contains(id); + } +
public static void fillDaqCellMap(Subdetector ecal) { System.out.println("reading DAQ map");
@@ -94,16 +152,16 @@
expId.setValue(helper.getFieldIndex("system"), ecal.getSystemID()); ConditionsManager conditions = ConditionsManager.defaultInstance();
- BufferedReader bufferedPedestals;
+ BufferedReader bufferedReader;
try {
- bufferedPedestals = new BufferedReader(conditions.getRawConditions("daqmap/ecal.txt").getReader());
+ bufferedReader = new BufferedReader(conditions.getRawConditions("daqmap/ecal.txt").getReader());
} catch (IOException e) { throw new RuntimeException("couldn't get DAQ map from conditions manager", e); } String line; while (true) { try {
- line = bufferedPedestals.readLine();
+ line = bufferedReader.readLine();
} catch (IOException e) { throw new RuntimeException("couldn't parse ECal DAQ map", e); }
@@ -143,7 +201,11 @@
public static long getDaqID(int crate, short slot, short channel) { return (((long) crate) << 32) | ((long) slot << 16) | (long) channel; }
-
+ + public static Long daqToPhysicalID(int crate, short slot, short channel) { + return daqToPhysicalMap.get(getDaqID(crate, slot, channel)); + } +
public static int getCrate(long physicalID) { return (int) (physicalID >>> 32); }
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