hps-java/src/main/java/org/lcsim/hps/recon/tracking
diff -u -r1.13 -r1.14
--- HPSSVTCalibrationConstants.java 21 Jun 2012 18:47:07 -0000 1.13
+++ HPSSVTCalibrationConstants.java 13 Jul 2012 23:02:57 -0000 1.14
@@ -1,7 +1,3 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
package org.lcsim.hps.recon.tracking;
import java.io.BufferedReader;
@@ -18,36 +14,27 @@
/**
*
- * @author mgraham
+ * @author Mathew Graham <[log in to unmask]>
+ * $Id: HPSSVTCalibrationConstants.java,v 1.14 2012/07/13 23:02:57 omoreno Exp $
*/
public class HPSSVTCalibrationConstants {
- public static Map<Pair<Integer /*
- * Hybrid
- */, Integer /*
- * FPGA
- */>, double[] /*
- * constants
- */> noiseMap = new HashMap<Pair<Integer, Integer>, double[]>();
- public static Map<Pair<Integer /*
- * Hybrid
- */, Integer /*
- * FPGA
- */>, double[] /*
- * constants
- */> pedestalMap = new HashMap<Pair<Integer, Integer>, double[]>();
- public static Map<Pair<Integer /*
- * Hybrid
- */, Integer /*
- * FPGA
- */>, double[] /*
- * constants
- */> tpMap = new HashMap<Pair<Integer, Integer>, double[]>();
+ // TODO: Change all pairs such that FPGA is the fist value
+ // TODO: Change all map keys to type SiSensor?
+
+ public static Map<Pair<Integer /* Hybrid */, Integer /* FPGA */>, double[] /* constants */> noiseMap
+ = new HashMap<Pair<Integer, Integer>, double[]>();
+ public static Map<Pair<Integer /* Hybrid */, Integer /* FPGA */>, double[] /* constants */> pedestalMap
+ = new HashMap<Pair<Integer, Integer>, double[]>();
+ public static Map<Pair<Integer /* Hybrid */, Integer /* FPGA */>, double[] /* constants */> tpMap
+ = new HashMap<Pair<Integer, Integer>, double[]>();
+ public static Map<Pair<Integer /* Hybrid */, Integer /* FPGA */>, Set<Integer> /* Bad channels */> badChannelMap
+ = new HashMap<Pair<Integer, Integer>, Set<Integer>>();
private static boolean pedestalLoaded = false;
private static boolean tpLoaded = false;
/**
- * Default Constructor.
+ * Default Ctor
*/
private HPSSVTCalibrationConstants() {
}
@@ -55,6 +42,11 @@
public static void loadCalibrationConstants() {
loadCalibrationConstants(null);
}
+
+ public static void loadCalibrationConstants(Date date, int runNumber){
+ loadCalibrationConstants(date);
+ loadBadChannels(runNumber);
+ }
public static void loadCalibrationConstants(Date date) {
//write something here to read in constants from calibration file
@@ -126,7 +118,7 @@
double pedestal = Double.valueOf(lineTok.nextToken());
double noise = Double.valueOf(lineTok.nextToken());
- Pair<Integer, Integer> daqPair = new Pair(hybrid, fpga);
+ Pair<Integer, Integer> daqPair = new Pair<Integer, Integer>(hybrid, fpga);
double[] pedestals = pedestalMap.get(daqPair);
if (pedestals == null) {
@@ -182,7 +174,7 @@
double tp = Double.valueOf(lineTok.nextToken()) * 24.0 / 25.0; //FIXME: this is a hack to compensate for the calibrations we have that assumed 25 ns APV clock
double chisq = Double.valueOf(lineTok.nextToken());
- Pair<Integer, Integer> daqPair = new Pair(hybrid, fpga);
+ Pair<Integer, Integer> daqPair = new Pair<Integer, Integer>(hybrid, fpga);
double[] tps = tpMap.get(daqPair);
if (tps == null) {
@@ -199,6 +191,73 @@
public static boolean tpLoaded() {
return tpLoaded;
}
+
+ /**
+ * Load the bad channels for the specified run. If there are no
+ * bad channels specified, just load those found from QA. Channels
+ * found to be bad from QA will always be loaded.
+ *
+ * @param run number
+ */
+ public static void loadBadChannels(int runNumber){
+
+ // Clear the previously loaded bad channels
+ badChannelMap.clear();
+ System.out.println("Loading the SVT bad channels for run " + runNumber);
+
+ ConditionsManager conditions = ConditionsManager.defaultInstance();
+ BufferedReader reader;
+
+ // First load the bad channels found during QA (not run dependent)
+ String filePath = "daqmap/svt_qa.badchannels";
+ try{
+ reader = new BufferedReader(conditions.getRawConditions(filePath).getReader());
+ loadBadChannels(reader);
+ } catch(IOException exception){
+ throw new RuntimeException("Unable to load bad channels for list " + filePath , exception);
+ }
+
+ // Load the bad channels for the specified run number
+ if(runNumber < 0) return;
+ filePath = "daqmap/svt" + runNumber + ".badchannels";
+ try{
+ reader = new BufferedReader(conditions.getRawConditions(filePath).getReader());
+ loadBadChannels(reader);
+ } catch(IOException exception){
+ // If the file isn't found, continue on with just the QA bad channels
+ System.out.println("File " + filePath + " was not found! Continuing with only QA bad channels");
+ }
+ }
+
+ /**
+ * Load the bad channels from a file using the specified character stream.
+ *
+ * @param reader : character stream of type Reader
+ */
+ public static void loadBadChannels(Reader reader){
+ BufferedReader badChannelReader = new BufferedReader(reader);
+
+ String line = null;
+ try{
+ while((line = badChannelReader.readLine()) != null){
+ // If the line is a comment, skip it
+ if(line.indexOf("#") != -1) continue;
+ StringTokenizer stringTok = new StringTokenizer(line);
+ while(stringTok.hasMoreTokens()){
+ int badChannel = Integer.valueOf(stringTok.nextToken());
+ int fpga = Integer.valueOf(stringTok.nextToken());
+ int hybrid = Integer.valueOf(stringTok.nextToken());
+ System.out.println("FPGA: " + fpga + " Hybrid: " + hybrid + " Bad Channel: " + badChannel);
+ Pair<Integer, Integer> daqPair = new Pair<Integer, Integer>(hybrid, fpga);
+ if(!badChannelMap.containsKey(daqPair))
+ badChannelMap.put(daqPair, new HashSet<Integer>());
+ badChannelMap.get(daqPair).add(badChannel);
+ }
+ }
+ } catch(IOException exception){
+ throw new RuntimeException("Unable to parse SVT bad channel list", exception);
+ }
+ }
public static Double getNoise(SiSensor sensor, int channel) {
Pair<Integer, Integer> daqPair = SvtUtils.getInstance().getDaqPair(sensor);
@@ -335,6 +394,20 @@
return constants;
}
+ /**
+ * Checks if a channel has been tagged as bad
+ *
+ * @param daqPair : a Hybrid/FPGA pair defining which sensor the
+ * channels in located on
+ * @param channel : The channel to be checked
+ * @return true if the channel is bad, false otherwise
+ */
+ public static boolean isBadChannel(SiSensor sensor, int channel){
+ Pair<Integer, Integer> daqPair = SvtUtils.getInstance().getDaqPair(sensor);
+ if(badChannelMap.get(daqPair) != null && badChannelMap.get(daqPair).contains(channel)) return true;
+ else return false;
+ }
+
//class to hold calibration constants for a channel; leave fields NaN or null if not known
public static class ChannelConstants {