hps-java/src/main/java/org/lcsim/hps/recon/tracking
diff -u -r1.5 -r1.6
--- HPSSVTCalibrationConstants.java 28 Apr 2012 19:35:09 -0000 1.5
+++ HPSSVTCalibrationConstants.java 30 Apr 2012 16:13:30 -0000 1.6
@@ -4,10 +4,12 @@
*/
package org.lcsim.hps.recon.tracking;
+import java.io.BufferedReader;
import java.io.IOException;
-import java.io.StreamTokenizer;
+import java.io.Reader;
import java.util.HashMap;
import java.util.Map;
+import java.util.StringTokenizer;
import org.lcsim.conditions.ConditionsManager;
import org.lcsim.detector.tracker.silicon.SiSensor;
import org.lcsim.hps.util.Pair;
@@ -18,152 +20,175 @@
*/
public class HPSSVTCalibrationConstants {
- // Map from Sensor to Hybrid/FPGA pair
- public static Map<Pair<SiSensor /*
- * Sensor
- */, Integer> /*
- * Channel Number
- */, Double /*
- * constant
- */> noise;
- public static Map<Pair<SiSensor /*
- * Sensor
- */, Integer> /*
- * Channel Number
- */, Double /*
- * constant
- */> pedestal;
- public static Map<Pair<SiSensor /*
- * Sensor
- */, Integer> /*
- * Channel Number
- */, Double /*
- * constant
- */> tShaping;
-
- /**
- * Default Constructor.
- */
- public HPSSVTCalibrationConstants() {
- pedestal = new HashMap<Pair<SiSensor, Integer>, Double>();
- noise = new HashMap<Pair<SiSensor, Integer>, Double>();
- tShaping = new HashMap<Pair<SiSensor, Integer>, Double>();
-
- }
-
- public void loadCalibrationConstants(String calibFile) {
- //write something here to read in constants from calibration fiel
-/*
- * ConditionsManager conditions =
- * ConditionsManager.defaultInstance(); StreamTokenizer tok =
- * null; try { tok = new
- * StreamTokenizer(conditions.getRawConditions(calibFile).getReader());
- * } catch (IOException e) { throw new
- * RuntimeException("couldn't get DAQ map from conditions
- * manager", e); } tok.commentChar('#');
- * tok.eolIsSignificant(false); tok.parseNumbers(); try { while
- * (tok.nextToken() != StreamTokenizer.TT_EOF) { tok.pushBack();
- * int x = (int) getNumber(tok); int y = (int) getNumber(tok);
- * int crate = (int) getNumber(tok); short slot = (short)
- * getNumber(tok); short channel = (short) getNumber(tok);
- * addMapEntry(enc.getID(), getDaqID(crate, slot, channel));
- * pedestal.put(sensorChannel, physicalID);
- * noise.put(sensorChannel, daqID); // 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 static double getNoise(SiSensor sensor, int channel) {
- Pair<SiSensor, Integer> sensorChannel = new Pair(sensor, channel);
- return noise.get(sensorChannel);
- }
-
- public static double getPedestal(SiSensor sensor, int channel) {
- Pair<SiSensor, Integer> sensorChannel = new Pair(sensor, channel);
- return pedestal.get(sensorChannel);
- }
-
- public static double getTShaping(SiSensor sensor, int channel) {
- Pair<SiSensor, Integer> sensorChannel = new Pair(sensor, channel);
- return tShaping.get(sensorChannel);
- }
-
- private 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);
- }
- }
-
- public static ChannelConstants getChannelConstants(SiSensor sensor, int channel) {
- Pair<SiSensor, Integer> sensorChannel = new Pair(sensor, channel);
- ChannelConstants constants = new ChannelConstants();
-// ...don't have a constants file yet!
- noise.put(sensorChannel,20.0);
- pedestal.put(sensorChannel,1638.0);
- tShaping.put(sensorChannel,35.0);
-////
- Double value;
- value = noise.get(sensorChannel);
- if (value != null) {
- constants.setNoise(value);
- }
- value = pedestal.get(sensorChannel);
- if (value != null) {
- constants.setPedestal(value);
- }
- value = tShaping.get(sensorChannel);
- if (value != null) {
- constants.setTp(value);
- }
-
- return constants;
- }
-
- //class to hold calibration constants for a channel; leave fields NaN or null if not known
- public static class ChannelConstants {
-
- private double pedestal = Double.NaN;
- private double tp = Double.NaN;
- private double noise = Double.NaN;
- private double[][] pulseShape = null;
-
- public double getNoise() {
- return noise;
- }
-
- public void setNoise(double noise) {
- this.noise = noise;
- }
-
- public double getPedestal() {
- return pedestal;
- }
-
- public void setPedestal(double pedestal) {
- this.pedestal = pedestal;
- }
-
- public double[][] getPulseShape() {
- return pulseShape;
- }
-
- public void setPulseShape(double[][] pulseShape) {
- this.pulseShape = pulseShape;
- }
-
- public double getTp() {
- return tp;
- }
-
- public void setTp(double tp) {
- this.tp = tp;
- }
- }
+ // Map from Sensor to Hybrid/FPGA pair
+ private static Map<Pair<SiSensor /*
+ * Sensor
+ */, Integer> /*
+ * Channel Number
+ */, Double /*
+ * constant
+ */> noiseMap = new HashMap<Pair<SiSensor, Integer>, Double>();
+ private static Map<Pair<SiSensor /*
+ * Sensor
+ */, Integer> /*
+ * Channel Number
+ */, Double /*
+ * constant
+ */> pedestalMap = new HashMap<Pair<SiSensor, Integer>, Double>();
+ private static Map<Pair<SiSensor /*
+ * Sensor
+ */, Integer> /*
+ * Channel Number
+ */, Double /*
+ * constant
+ */> tpMap = new HashMap<Pair<SiSensor, Integer>, Double>();
+ private static boolean calibrationLoaded = false;
+
+ /**
+ * Default Constructor.
+ */
+ private HPSSVTCalibrationConstants() {
+ }
+
+ public static void loadCalibrationConstants() {
+ //write something here to read in constants from calibration fiel
+ ConditionsManager conditions = ConditionsManager.defaultInstance();
+ try {
+ Reader baselineReader = conditions.getRawConditions("calibSVT/default.base").getReader();
+ loadBaseline(baselineReader);
+ } catch (IOException e) {
+ throw new RuntimeException("couldn't get baseline file", e);
+ }
+ }
+
+ public static void loadBaseline(Reader baselineReader) {
+ BufferedReader bufferedBaseline = new BufferedReader(baselineReader);
+ String line;
+ while (true) {
+ try {
+ line = bufferedBaseline.readLine();
+ } catch (IOException e) {
+ throw new RuntimeException("couldn't parse baseline file", 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() != 5) {
+ throw new RuntimeException("Invalid line in baseline file: " + line);
+ } else {
+ int fpga = Integer.valueOf(lineTok.nextToken());
+ int hybrid = Integer.valueOf(lineTok.nextToken());
+ int channel = Integer.valueOf(lineTok.nextToken());
+ double pedestal = Double.valueOf(lineTok.nextToken());
+ double noise = Double.valueOf(lineTok.nextToken());
+ SiSensor sensor = HPSSVTDAQMaps.daqPairToSensor.get(new Pair(hybrid, fpga));
+ if (sensor == null) {
+ throw new RuntimeException("invalid DAQ ID: FPGA " + fpga + ", hybrid " + hybrid);
+ }
+ Pair<SiSensor, Integer> sensorChannel = new Pair(sensor, channel);
+ pedestalMap.put(sensorChannel, pedestal);
+ noiseMap.put(sensorChannel, noise);
+ }
+ }
+ }
+ calibrationLoaded = true;
+ }
+
+ public static boolean calibrationLoaded() {
+ return calibrationLoaded;
+ }
+
+ public static double getNoise(SiSensor sensor, int channel) {
+ Pair<SiSensor, Integer> sensorChannel = new Pair(sensor, channel);
+ return noiseMap.get(sensorChannel);
+ }
+
+ public static double getPedestal(SiSensor sensor, int channel) {
+ Pair<SiSensor, Integer> sensorChannel = new Pair(sensor, channel);
+ return pedestalMap.get(sensorChannel);
+ }
+
+ public static double getTShaping(SiSensor sensor, int channel) {
+ Pair<SiSensor, Integer> sensorChannel = new Pair(sensor, channel);
+ return tpMap.get(sensorChannel);
+ }
+
+ public static ChannelConstants getChannelConstants(SiSensor sensor, int channel) {
+ Pair<SiSensor, Integer> sensorChannel = new Pair(sensor, channel);
+ ChannelConstants constants = new ChannelConstants();
+
+ Double value;
+ value = noiseMap.get(sensorChannel);
+ if (value != null) {
+ constants.setNoise(value);
+ } else {
+ System.out.println("Couldn't get noise for sensor " + sensor.getName() + ", channel " + channel);
+ constants.setNoise(20.0);
+ }
+ value = pedestalMap.get(sensorChannel);
+ if (value != null) {
+ constants.setPedestal(value);
+ } else {
+ System.out.println("Couldn't get pedestal for sensor " + sensor.getName() + ", channel " + channel);
+ constants.setPedestal(1638.0);
+ }
+ value = tpMap.get(sensorChannel);
+ if (value != null) {
+ constants.setTp(value);
+ } else {
+// System.out.println("Couldn't get Tp for sensor " + sensor.getName() + ", channel " + channel);
+ constants.setTp(35.0);
+ }
+
+ return constants;
+ }
+
+ //class to hold calibration constants for a channel; leave fields NaN or null if not known
+ public static class ChannelConstants {
+
+ private double pedestal = Double.NaN;
+ private double tp = Double.NaN;
+ private double noise = Double.NaN;
+ private double[][] pulseShape = null;
+
+ public double getNoise() {
+ return noise;
+ }
+
+ public void setNoise(double noise) {
+ this.noise = noise;
+ }
+
+ public double getPedestal() {
+ return pedestal;
+ }
+
+ public void setPedestal(double pedestal) {
+ this.pedestal = pedestal;
+ }
+
+ public double[][] getPulseShape() {
+ return pulseShape;
+ }
+
+ public void setPulseShape(double[][] pulseShape) {
+ this.pulseShape = pulseShape;
+ }
+
+ public double getTp() {
+ return tp;
+ }
+
+ public void setTp(double tp) {
+ this.tp = tp;
+ }
+ }
}
hps-java/src/main/java/org/lcsim/hps/recon/tracking
diff -u -r1.8 -r1.9
--- HPSRawTrackerHitFitterDriver.java 28 Apr 2012 21:03:47 -0000 1.8
+++ HPSRawTrackerHitFitterDriver.java 30 Apr 2012 16:13:30 -0000 1.9
@@ -52,12 +52,13 @@
if (rawHitCollectionName == null) {
throw new RuntimeException("The parameter ecalCollectionName was not set!");
}
- HPSSVTCalibrationConstants calibConstants = new HPSSVTCalibrationConstants();
- calibConstants.loadCalibrationConstants("Foobar");
}
@Override
public void process(EventHeader event) {
+ if (!HPSSVTCalibrationConstants.calibrationLoaded()) {
+ HPSSVTCalibrationConstants.loadCalibrationConstants();
+ }
List<RawTrackerHit> rawHits = event.get(RawTrackerHit.class, rawHitCollectionName);
if (rawHits == null) {
throw new RuntimeException("Event is missing SVT hits collection!");