12 added files
java/trunk/conditions/src/main/java/org/hps/conditions/deprecated
--- java/trunk/conditions/src/main/java/org/hps/conditions/deprecated/BeamSpot.java (rev 0)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/deprecated/BeamSpot.java 2014-03-26 00:23:18 UTC (rev 349)
@@ -0,0 +1,81 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.hps.conditions.deprecated;
+
+import hep.physics.matrix.SymmetricMatrix;
+
+/**
+ * Class describing the HPS beamspot at the target (Z=0)
+ * @author mgraham
+ * created on 6/27/2011
+ */
+public class BeamSpot {
+
+ private static double[] _position;
+ private static double[] _angle;
+ private static SymmetricMatrix _beamcov;
+
+ public BeamSpot() {
+ }
+
+ public BeamSpot(double[] pos, SymmetricMatrix cov, double[] angle) {
+ _position = pos;
+ _beamcov = cov;
+ _angle = angle;
+ }
+
+ public BeamSpot(double sigX, double sigY) {
+ // default beamspot position
+ _position[0] = 0;
+ _position[1] = 0;
+ _angle[0] = 0;
+ _angle[1] = 0;
+ _beamcov = new SymmetricMatrix(2);
+ _beamcov.setElement(0, 0, sigX * sigX);
+ _beamcov.setElement(1, 1, sigY * sigY);
+ }
+
+ public BeamSpot(double posX, double sigX, double posY, double sigY) {
+ _position[0] = posX;
+ _position[1] = posY;
+ _angle[0] = 0;
+ _angle[1] = 0;
+ _beamcov = new SymmetricMatrix(2);
+ _beamcov.setElement(0, 0, sigX * sigX);
+ _beamcov.setElement(1, 1, sigY * sigY);
+ }
+
+ public double getBeamSigmaX() {
+ return Math.sqrt(_beamcov.e(0, 0));
+ }
+
+ public double getBeamSigmaY() {
+ return Math.sqrt(_beamcov.e(1, 1));
+ }
+
+ public double[] getBeamPosition() {
+ return _position;
+ }
+
+ public double[] getBeamAngle() {
+ return _angle;
+ }
+
+ public SymmetricMatrix getBeamCovariance() {
+ return _beamcov;
+ }
+
+ public void setBeamPosition(double[] pos) {
+ _position = pos;
+ }
+
+ public void setBeamAngle(double[] ang) {
+ _angle = ang;
+ }
+
+ public void setBeamCovariance(SymmetricMatrix cov) {
+ _beamcov = cov;
+ }
+}
java/trunk/conditions/src/main/java/org/hps/conditions/deprecated
--- java/trunk/conditions/src/main/java/org/hps/conditions/deprecated/BeamlineConstants.java (rev 0)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/deprecated/BeamlineConstants.java 2014-03-26 00:23:18 UTC (rev 349)
@@ -0,0 +1,12 @@
+package org.hps.conditions.deprecated;
+
+public final class BeamlineConstants {
+
+ private BeamlineConstants() {}
+
+ public static final double ECAL_FACE_TESTRUN = 1524; // mm
+ public static final double DIPOLE_EDGE_TESTRUN = 457.2 + 457.2; // 452.2 + 462.2; //914; // mm
+ public static final double DIPOLE_EDGELOW_TESTRUN = 0.; //452.2 - 462.2; // mm
+ public static final double HARP_POSITION_TESTRUN = -674.062; // mm
+
+}
java/trunk/conditions/src/main/java/org/hps/conditions/deprecated
--- java/trunk/conditions/src/main/java/org/hps/conditions/deprecated/CalibrationDriver.java (rev 0)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/deprecated/CalibrationDriver.java 2014-03-26 00:23:18 UTC (rev 349)
@@ -0,0 +1,107 @@
+package org.hps.conditions.deprecated;
+
+import org.lcsim.conditions.ConditionsEvent;
+import org.lcsim.conditions.ConditionsListener;
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.conditions.ConditionsSet;
+import org.lcsim.event.EventHeader;
+import org.lcsim.geometry.Detector;
+import org.lcsim.util.Driver;
+
+/**
+ *
+ * @author Sho Uemura <[log in to unmask]>
+ * @version $Id: CalibrationDriver.java,v 1.1 2013/10/25 19:39:46 jeremy Exp $
+ */
+public class CalibrationDriver extends Driver implements ConditionsListener {
+
+ // The test run number of interest. If it equals -1, the default calibrations
+ // are loaded
+ private static int runNumber = -1;
+ private boolean fixRunNumber = false;
+ private String gainFilename = "default.gain";
+
+ public CalibrationDriver() {
+ add(new EcalConditions());
+ add(new HPSSVTSensorSetup());
+ }
+
+ public void setRunNumber(int runNumber) {
+ CalibrationDriver.runNumber = runNumber;
+ fixRunNumber = true;
+ }
+
+ public void setGainFilename(String gainFileName) {
+ this.gainFilename = gainFileName;
+ }
+
+ public static int runNumber() {
+ return runNumber;
+ }
+
+ @Override
+ protected void process(EventHeader event) {
+ super.process(event);
+ if (!fixRunNumber && runNumber != event.getRunNumber()) {
+ runNumber = event.getRunNumber();
+ }
+ }
+
+ @Override
+ protected void detectorChanged(Detector detector) {
+ super.detectorChanged(detector);
+
+ if (!EcalConditions.calibrationLoaded()) {
+ EcalConditions.setGainFilename(gainFilename);
+ EcalConditions.loadCalibration();
+ }
+ if (fixRunNumber && (!HPSSVTCalibrationConstants.pedestalLoaded() || !HPSSVTCalibrationConstants.tpLoaded())) {
+ System.out.println("Loading calibration for set run: " + runNumber);
+ loadCalibsByRun(runNumber);
+ }
+ }
+
+ @Override
+ protected void startOfData() {
+ ConditionsManager.defaultInstance().addConditionsListener(this);
+ }
+
+ @Override
+ public void conditionsChanged(ConditionsEvent ce) {
+ if (!fixRunNumber) {
+ System.out.println("Got ConditionsEvent with run: " + ce.getConditionsManager().getRun());
+ runNumber = ce.getConditionsManager().getRun();
+ loadCalibsByRun(runNumber);
+ }
+ }
+
+ private void loadCalibsByRun(int run) {
+ HPSSVTCalibrationConstants.loadCalibration(run);
+ FieldMap.loadFieldMap(run);
+ }
+
+ /**
+ * get specified conditions list, parse as a map of run numbers to calibration file paths; get the appropriate file
+ * @param calibName
+ * @param run
+ * @return
+ */
+ public static String getCalibForRun(String calibName, int run) {
+ System.out.println("Reading calibrations " + calibName + " for run: " + run);
+
+ ConditionsSet calibSet = ConditionsManager.defaultInstance().getConditions(calibName);
+
+ int mostRecentValid = Integer.MIN_VALUE;
+ String filePath = null;
+ for (Object key : calibSet.keySet()) {
+ int keyRun = Integer.parseInt((String) key);
+// System.out.println("Available calibration for run: " + keyRun);
+ if (keyRun > mostRecentValid && keyRun <= run) {
+ mostRecentValid = keyRun;
+ filePath = calibSet.getString((String) key);
+ }
+ }
+ System.out.println("Use this calibration from run " + mostRecentValid + ": " + filePath);
+ return filePath;
+ }
+}
java/trunk/conditions/src/main/java/org/hps/conditions/deprecated
--- java/trunk/conditions/src/main/java/org/hps/conditions/deprecated/EcalConditions.java (rev 0)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/deprecated/EcalConditions.java 2014-03-26 00:23:18 UTC (rev 349)
@@ -0,0 +1,351 @@
+package org.hps.conditions.deprecated;
+
+import java.io.BufferedReader;
+import org.lcsim.geometry.compact.Subdetector;
+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;
+import org.lcsim.detector.identifier.IExpandedIdentifier;
+import org.lcsim.detector.identifier.IIdentifierHelper;
+import org.lcsim.geometry.Detector;
+import org.lcsim.util.Driver;
+
+/**
+ *
+ * @author meeg
+ * @version $Id: EcalConditions.java,v 1.2 2013/10/24 20:01:54 meeg Exp $
+ */
+public class EcalConditions extends Driver {
+
+ //DAQ channel map
+ private static HashMap<Long, Long> daqToPhysicalMap = new HashMap<Long, Long>();
+ private static HashMap<Long, Long> physicalToDaqMap = new HashMap<Long, Long>();
+ //pedestals
+ private static HashMap<Long, Double> daqToPedestalMap = new HashMap<Long, Double>();
+ private static HashMap<Long, Double> daqToNoiseMap = new HashMap<Long, Double>();
+ //set of bad channels to ignore
+ private static HashSet<Long> badChannelsSet = new HashSet<Long>();
+ private static boolean badChannelsLoaded = false;
+ private static IIdentifierHelper helper = null;
+ //gain
+ private static HashMap<Long, Double> physicalToGainMap = new HashMap<Long, Double>();
+ //subdetector name (for when this is used as a driver)
+ private String subdetectorName = "Ecal";
+ private static Subdetector subdetector;
+ private static boolean debug = false;
+ private static boolean calibrationLoaded = false;
+ private static String gainFilename = "default.gain";
+
+ public EcalConditions() {
+ }
+
+ @Override
+ public void detectorChanged(Detector detector) {
+ detectorChanged(detector, subdetectorName);
+ }
+
+ public static void detectorChanged(Detector detector, String ecalName) {
+ subdetector = detector.getSubdetector(ecalName);
+ if (subdetector == null) {
+ throw new RuntimeException("Subdetector " + ecalName + " not found");
+ }
+ helper = subdetector.getDetectorElement().getIdentifierHelper();
+ }
+
+ public static boolean calibrationLoaded() {
+ return calibrationLoaded;
+ }
+
+ public static void loadDaqMap(Detector detector, String ecalName) {
+ detectorChanged(detector, ecalName);
+ fillDaqCellMap(subdetector);
+ }
+
+ public static void loadCalibration() {
+ fillDaqCellMap(subdetector);
+ loadBadChannels(subdetector);
+ loadGains();
+ loadPedestals();
+ calibrationLoaded = true;
+ }
+
+ public static void setGainFilename(String name) {
+ gainFilename = name;
+ }
+
+ public void setSubdetectorName(String subdetectorName) {
+ this.subdetectorName = subdetectorName;
+ }
+
+ public static IIdentifierHelper getHelper() {
+ return helper;
+ }
+
+ public static Subdetector getSubdetector() {
+ return subdetector;
+ }
+
+ public static boolean badChannelsLoaded() {
+ return badChannelsLoaded;
+ }
+
+ public static void loadPedestals() {
+ ConditionsManager conditions = ConditionsManager.defaultInstance();
+ try {
+ Reader pedestalsReader = conditions.getRawConditions("calibECal/default01.ped").getReader();
+ loadPedestals(pedestalsReader, 1);
+ pedestalsReader = conditions.getRawConditions("calibECal/default02.ped").getReader();
+ loadPedestals(pedestalsReader, 2);
+ } catch (IOException e) {
+ throw new RuntimeException("couldn't get pedestals file", e);
+ }
+ }
+
+ public static void loadPedestals(Reader reader, int crate) {
+
+ System.out.println("reading pedestals for ECal");
+
+ BufferedReader bufferedReader = new BufferedReader(reader);
+ String line;
+ while (true) {
+ try {
+ line = bufferedReader.readLine();
+ } catch (IOException e) {
+ throw new RuntimeException("couldn't parse pedestals 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() != 4) {
+ throw new RuntimeException("Invalid line in pedestals file: " + line);
+ } else {
+ short slot = Short.valueOf(lineTok.nextToken());
+ short channel = Short.valueOf(lineTok.nextToken());
+ double pedestal = Double.valueOf(lineTok.nextToken());
+ double noise = Double.valueOf(lineTok.nextToken());
+ long daqid = getDaqID(crate, slot, channel);
+ daqToPedestalMap.put(daqid, pedestal);
+ daqToNoiseMap.put(daqid, noise);
+ if (debug) {
+ System.out.printf("Channel %d: pede %.2f noise %.2f (crate %d slot %d channel %d)\n", daqid,pedestal,noise,crate,slot,channel);
+ }
+ }
+ }
+ }
+ }
+
+ private static void loadBadChannels(Subdetector ecal) {
+
+ System.out.println("reading ECal bad channels");
+
+ 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());
+ if (debug) {
+ System.out.printf("Channel %d is bad (x=%d y=%d)\n", helper.pack(expId).getValue(),x,y);
+ }
+ }
+ }
+ }
+ badChannelsLoaded = true;
+ }
+
+ public static void loadGains() {
+ if (debug) {
+ System.out.println("Loading gains");
+ }
+ BufferedReader bufferedReader;
+ ConditionsManager conditions = ConditionsManager.defaultInstance();
+ try {
+ bufferedReader = new BufferedReader(conditions.getRawConditions("calibECal/"+EcalConditions.gainFilename).getReader());
+ } catch (IOException e) {
+ throw new RuntimeException("couldn't get gain file("+gainFilename+") ", e);
+ }
+
+ String line;
+ while (true) {
+ try {
+ line = bufferedReader.readLine();
+ } catch (IOException e) {
+ throw new RuntimeException("couldn't parse gain 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() != 3) {
+ throw new RuntimeException("Invalid line in gain file: " + line);
+ } else {
+ int x = Integer.valueOf(lineTok.nextToken());
+ int y = Integer.valueOf(lineTok.nextToken());
+ double gain = Double.valueOf(lineTok.nextToken());
+ physicalToGainMap.put(makePhysicalID(x, y), gain);
+ if (debug) {
+ System.out.printf("Channel %d: gain %.2f (x=%d y=%d)\n", makePhysicalID(x, y),gain,x,y);
+ }
+ }
+ }
+ }
+ }
+
+ public static boolean isBadChannel(long id) {
+ return badChannelsSet.contains(id);
+ }
+
+ private static void fillDaqCellMap(Subdetector ecal) {
+
+ System.out.println("reading ECal DAQ map");
+
+ 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.txt").getReader());
+ } catch (IOException e) {
+ throw new RuntimeException("couldn't get DAQ map from conditions manager", e);
+ }
+ String line;
+ while (true) {
+ try {
+ line = bufferedReader.readLine();
+ } catch (IOException e) {
+ throw new RuntimeException("couldn't parse ECal DAQ map", 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 ECal DAQ map: " + line);
+ } else {
+ int x = Integer.valueOf(lineTok.nextToken());
+ int y = Integer.valueOf(lineTok.nextToken());
+// if (x>0 && y>0) x = 24-x;
+ expId.setValue(helper.getFieldIndex("ix"), x);
+ expId.setValue(helper.getFieldIndex("iy"), y);
+ int crate = Integer.valueOf(lineTok.nextToken());
+ short slot = Short.valueOf(lineTok.nextToken());
+ short channel = Short.valueOf(lineTok.nextToken());
+ addMapEntry(helper.pack(expId).getValue(), getDaqID(crate, slot, channel));
+ }
+ }
+ }
+ }
+
+ public static long makePhysicalID(int ix, int iy) {
+ IExpandedIdentifier expId = new ExpandedIdentifier(helper.getIdentifierDictionary().getNumberOfFields());
+ expId.setValue(helper.getFieldIndex("system"), subdetector.getSystemID());
+ expId.setValue(helper.getFieldIndex("ix"), ix);
+ expId.setValue(helper.getFieldIndex("iy"), iy);
+ return helper.pack(expId).getValue();
+ }
+
+ private static void addMapEntry(long physicalID, long daqID) {
+ daqToPhysicalMap.put(daqID, physicalID);
+ physicalToDaqMap.put(physicalID, daqID);
+ }
+
+ 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 daqID) {
+ return (int) (daqID >>> 32);
+ }
+
+ public static short getSlot(long daqID) {
+ return (short) ((daqID >>> 16) & 0xFFFF);
+ }
+
+ public static short getChannel(long daqID) {
+ return (short) (daqID & 0xFFFF);
+ }
+
+ public static Long physicalToDaqID(long physicalID) {
+ return physicalToDaqMap.get(physicalID);
+ }
+
+ public static Long daqToPhysicalID(long daqID) {
+ return daqToPhysicalMap.get(daqID);
+ }
+
+ public static Double daqToPedestal(long daqID) {
+ return daqToPedestalMap.get(daqID);
+ }
+
+ public static Double physicalToPedestal(long physicalID) {
+ return daqToPedestalMap.get(physicalToDaqMap.get(physicalID));
+ }
+
+ public static Double physicalToNoise(long physicalID) {
+ return daqToNoiseMap.get(physicalToDaqMap.get(physicalID));
+ }
+
+ public static Double physicalToGain(long physicalID) {
+ return physicalToGainMap.get(physicalID);
+ }
+}
java/trunk/conditions/src/main/java/org/hps/conditions/deprecated
--- java/trunk/conditions/src/main/java/org/hps/conditions/deprecated/FieldMap.java (rev 0)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/deprecated/FieldMap.java 2014-03-26 00:23:18 UTC (rev 349)
@@ -0,0 +1,193 @@
+package org.hps.conditions.deprecated;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.hps.util.Pair;
+
+/**
+
+@author Mathew Graham <[log in to unmask]> $Id: FieldMap.java,v 1.14
+2012/07/23 23:02:57 mgraham Exp $
+ */
+public class FieldMap {
+
+ // TODO: Change all pairs such that FPGA is the fist value
+ // TODO: Change all map keys to type SiSensor?
+
+ public static Map<Pair<Integer/*
+ zbin
+ */, Integer/*
+ xbin
+ */>, Double/*
+ b_y
+ */> fieldMap = new HashMap<Pair<Integer, Integer>, Double>();
+ ;
+ public static Map<Pair<Integer/*
+ zbin
+ */, Integer/*
+ zbin
+ */>, Pair<Double/*
+ zpos
+ */, Double/*
+ xpos
+ */>> fieldBins = new HashMap<Pair<Integer, Integer>, Pair<Double, Double>>();
+ ;
+ private static boolean fieldMapLoaded = false;
+ private static boolean debug = false;
+
+ /**
+ Default Ctor
+ */
+ private FieldMap() {
+ }
+
+ public static void loadFieldMap() {
+ loadFieldMap(-1);
+ }
+
+ public static void loadFieldMap(int run) {
+ System.out.println("Loading fieldmap for run " + run);
+ //write something here to read in constants from calibration file
+ ConditionsManager conditions = ConditionsManager.defaultInstance();
+
+ String filePath = null;
+
+ //TODO: if we ever have more than one field map, make a list and uncomment this
+// filePath = HPSCalibrationListener.getCalibForRun("FieldMap/bfieldmap", run);
+
+ if (filePath == null) {
+ filePath = "FieldMap/bfieldmap.dat";
+ }
+
+ try {
+ Reader baselineReader = conditions.getRawConditions(filePath).getReader();
+ loadBField(baselineReader);
+ } catch (IOException e) {
+ throw new RuntimeException("couldn't get baseline file", e);
+ }
+
+
+
+
+ }
+
+ private static void loadBField(Reader baselineReader) throws IOException {
+
+ BufferedReader bufferedBaseline = new BufferedReader(baselineReader);
+ String line;
+ Double xval = 0.0, zval = 0.0, bY;
+ Integer iz = -1, ix = 0;
+ 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 tok = new StringTokenizer(line);
+ if (debug) {
+ System.out.println(line.toString());
+ }
+ List<Double> vals = new ArrayList<Double>();
+
+ while ((vals = getNumbersInLine(tok)).size() > 0) {
+ if (debug) {
+ System.out.println(getNumbersInLine(tok).size());
+ }
+ for (int i = 0; i < vals.size(); i++) {
+ double val = vals.get(i);
+ if (i == 0 && val >= 0) {
+ xval = 0.0;
+ zval = val * 10.0;//convert from cm to mm
+ ix = 0;
+ iz++;
+ } else {
+ bY = val / 10000.0 * 0.491 / 0.5;//gauss-->tesla and normalize by our nominal bfield (file is for 0.5T)
+ bY = Math.abs(bY);
+ Pair zx = new Pair(zval, xval);
+ Pair izix = new Pair(iz, ix);
+// System.out.println("Putting B = "+bY+" & (Z,X) = "+zval+","+xval+")");
+ fieldMap.put(izix, bY);
+// System.out.println("Making _fieldBins pair = ("+iz+","+ix+")");
+ fieldBins.put(izix, zx);
+ xval += 10.0;
+ ix++;
+ }
+ }
+ }
+ }
+ fieldMapLoaded = true;
+
+ }
+
+ public static boolean fieldMapLoaded() {
+ return fieldMapLoaded;
+ }
+
+ private static List<Double> getNumbersInLine(StringTokenizer tok) throws IOException {
+ List<Double> nums = new ArrayList<Double>();
+ while (tok.hasMoreTokens()) {
+ String tokVal = tok.nextToken();
+// System.out.println(tokVal);
+ nums.add(Double.valueOf(tokVal).doubleValue());
+ }
+// System.out.println("Returning list");
+ return nums;
+ }
+
+ public static double getFieldFromMap(double zval, double xval) {
+ Pair<Integer, Integer> bin = getFieldBin(zval, xval);
+ return fieldMap.get(bin);
+ }
+
+ private static Pair<Integer, Integer> getFieldBin(double zval, double xval) {
+ Integer iz, ix;
+ int nZ = 150;
+ int nX = 25;
+ double zNew = Math.abs(zval - BeamlineConstants.DIPOLE_EDGE_TESTRUN / 2);
+ double xNew = Math.abs(xval);
+ for (iz = 0; iz < nZ; iz++) {
+ Pair tmp = fieldBins.get(new Pair(iz, 0));
+ Double zpair = (Double) tmp.getFirstElement();
+ if (zpair > zNew) {
+ break;
+ }
+ }
+ for (ix = 0; ix < nX; ix++) {
+ Pair tmp = fieldBins.get(new Pair(1, ix));
+ Double xpair = (Double) tmp.getSecondElement();
+ if (xpair > xNew) {
+ break;
+ }
+ }
+ Pair izix = new Pair(iz, ix);
+ return izix;
+
+ }
+
+ public static void printFieldMap() {
+ int xval = 0;
+ System.out.printf("---- B-field ----\n");
+ System.out.printf("%5s %5s %10s\n", "z","x","B");
+ for(int zval=-100;zval< 1400;++zval) {
+ double bfield = FieldMap.getFieldFromMap((double)zval, (double)xval);
+ System.out.printf("%5d %5d %10.3f\n", zval,xval,bfield);
+ }
+ }
+
+}
java/trunk/conditions/src/main/java/org/hps/conditions/deprecated
--- java/trunk/conditions/src/main/java/org/hps/conditions/deprecated/HPSSVTCalibrationConstants.java (rev 0)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/deprecated/HPSSVTCalibrationConstants.java 2014-03-26 00:23:18 UTC (rev 349)
@@ -0,0 +1,537 @@
+package org.hps.conditions.deprecated;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import org.hps.conditions.deprecated.CalibrationDriver;
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.detector.identifier.IIdentifier;
+import org.lcsim.detector.tracker.silicon.SiSensor;
+import org.lcsim.detector.tracker.silicon.SiTrackerIdentifierHelper;
+import org.lcsim.hps.util.Pair;
+
+/**
+ *
+ * @author Mathew Graham <[log in to unmask]> $Id:
+ * HPSSVTCalibrationConstants.java,v 1.23 2013/02/25 22:39:26 meeg Exp $
+ */
+public class HPSSVTCalibrationConstants {
+
+ // TODO: Change all map keys to type SiSensor?
+ // TODO: Update everything to make it compatible new version of SVT Utils
+ private static Map<Pair<Integer /*
+ * FPGA
+ */, Integer /*
+ * Hybrid
+ */>, double[] /*
+ * constants
+ */> noiseMap = new HashMap<Pair<Integer, Integer>, double[]>();
+ private static Map<Pair<Integer /*
+ * FPGA
+ */, Integer /*
+ * Hybrid
+ */>, double[] /*
+ * constants
+ */> pedestalMap = new HashMap<Pair<Integer, Integer>, double[]>();
+ private static Map<Pair<Integer /*
+ * FPGA
+ */, Integer /*
+ * Hybrid
+ */>, double[] /*
+ * constants
+ */> tpMap = new HashMap<Pair<Integer, Integer>, double[]>();
+ private static Map<Pair<Integer /*
+ * FPGA
+ */, Integer /*
+ * Hybrid
+ */>, Set<Integer> /*
+ * Bad channels
+ */> badChannelMap = new HashMap<Pair<Integer, Integer>, Set<Integer>>();
+ private static Map<Pair<Integer /*
+ * FPGA
+ */, Integer /*
+ * Hybrid
+ */>, List<Double> /*
+ * channels
+ */> gainMap = new HashMap<Pair<Integer, Integer>, List<Double>>();
+ private static Map<Pair<Integer /*
+ * FPGA
+ */, Integer /*
+ * Hybrid
+ */>, List<Double> /*
+ * channels
+ */> offsetMap = new HashMap<Pair<Integer, Integer>, List<Double>>();
+ private static Map<Pair<Integer, Integer>, Double> t0ShiftMap = new HashMap<Pair<Integer, Integer>, Double>();
+ private static boolean pedestalLoaded = false;
+ private static boolean tpLoaded = false;
+ private static int totalBadChannels = 0;
+
+ /**
+ * Default Ctor
+ */
+ private HPSSVTCalibrationConstants() {
+ }
+
+ public static void loadCalibration(int runNumber) {
+ loadCalibrationConstants(runNumber);
+ loadBadChannels(runNumber);
+ loadGain();
+ loadT0Shifts();
+ }
+
+ public static void loadCalibrationConstants(int run) {
+ //write something here to read in constants from calibration file
+ ConditionsManager conditions = ConditionsManager.defaultInstance();
+ String filePath = null;
+
+ filePath = CalibrationDriver.getCalibForRun("calibSVT/base", run);
+
+ if (filePath == null) {
+ filePath = "calibSVT/default.base";
+ }
+
+ try {
+ Reader baselineReader = conditions.getRawConditions(filePath).getReader();
+ loadBaseline(baselineReader);
+ } catch (IOException e) {
+ throw new RuntimeException("couldn't get baseline file", e);
+ }
+
+
+ filePath = CalibrationDriver.getCalibForRun("calibSVT/tp", run);
+
+ if (filePath == null) {
+ filePath = "calibSVT/default.tp";
+ }
+
+ try {
+ Reader tpReader = conditions.getRawConditions(filePath).getReader();
+ loadTp(tpReader);
+ } catch (IOException e) {
+ throw new RuntimeException("couldn't get Tp file", e);
+ }
+
+ }
+
+ private 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());
+
+ Pair<Integer, Integer> daqPair = new Pair<Integer, Integer>(fpga, hybrid);
+
+ double[] pedestals = pedestalMap.get(daqPair);
+ if (pedestals == null) {
+ pedestals = new double[HPSSVTConstants.TOTAL_APV25_CHANNELS * HPSSVTConstants.TOTAL_APV25_PER_HYBRID];
+ pedestalMap.put(daqPair, pedestals);
+ }
+ pedestals[channel] = pedestal;
+
+ double[] noises = noiseMap.get(daqPair);
+ if (noises == null) {
+ noises = new double[HPSSVTConstants.TOTAL_APV25_CHANNELS * HPSSVTConstants.TOTAL_APV25_PER_HYBRID];
+ noiseMap.put(daqPair, noises);
+ }
+ noises[channel] = noise;
+ }
+ }
+ }
+ pedestalLoaded = true;
+ }
+
+ public static boolean pedestalLoaded() {
+ return pedestalLoaded;
+ }
+
+ private static void loadTp(Reader baselineReader) {
+ BufferedReader bufferedTp = new BufferedReader(baselineReader);
+ String line;
+ while (true) {
+ try {
+ line = bufferedTp.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() != 7) {
+ 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 amplitude = Double.valueOf(lineTok.nextToken());
+ double t0 = Double.valueOf(lineTok.nextToken());
+ 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<Integer, Integer>(fpga, hybrid);
+
+ double[] tps = tpMap.get(daqPair);
+ if (tps == null) {
+ tps = new double[HPSSVTConstants.TOTAL_APV25_CHANNELS * HPSSVTConstants.TOTAL_APV25_PER_HYBRID];
+ tpMap.put(daqPair, tps);
+ }
+ tps[channel] = tp;
+ }
+ }
+ }
+ tpLoaded = true;
+ }
+
+ 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);
+
+ // If the calibrations are ideal (run < 0) don't load any bad channels
+ if (runNumber < 0) {
+ System.out.println("Running using ideal SVT calibrations. Bad channels will not be loaded.");
+ return;
+ }
+
+ 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
+ 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
+ */
+ private 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;
+ }
+ totalBadChannels++;
+ 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());
+ Pair<Integer, Integer> daqPair = new Pair<Integer, Integer>(fpga, hybrid);
+ 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);
+ }
+ }
+
+ /**
+ *
+ */
+ private static void loadGain() {
+
+ System.out.println("Loading SVT gains ...");
+
+ ConditionsManager conditions = ConditionsManager.defaultInstance();
+ BufferedReader gainReader;
+
+ String filePath = "calibSVT/svt_default.gain";
+ String line = null;
+ try {
+ gainReader = new BufferedReader(conditions.getRawConditions(filePath).getReader());
+ while ((line = gainReader.readLine()) != null) {
+ // If the line is a comment, skip it
+ if (line.indexOf("#") != -1) {
+ continue;
+ }
+ StringTokenizer stringTok = new StringTokenizer(line);
+ while (stringTok.hasMoreTokens()) {
+ int fpga = Integer.valueOf(stringTok.nextToken());
+ int hybrid = Integer.valueOf(stringTok.nextToken());
+ int channel = Integer.valueOf(stringTok.nextToken());
+ double gain = Double.valueOf(stringTok.nextToken());
+ double offset = Double.valueOf(stringTok.nextToken());
+ Pair<Integer, Integer> daqPair = new Pair<Integer, Integer>(fpga, hybrid);
+ if (!gainMap.containsKey(daqPair)) {
+ gainMap.put(daqPair, new ArrayList<Double>());
+ }
+ gainMap.get(daqPair).add(channel, gain);
+ if (!offsetMap.containsKey(daqPair)) {
+ offsetMap.put(daqPair, new ArrayList<Double>());
+ }
+ offsetMap.get(daqPair).add(channel, offset);
+ }
+ }
+ } catch (IOException exception) {
+ throw new RuntimeException("Unable to load gains!", exception);
+ }
+ }
+
+ private static void loadT0Shifts() {
+ System.out.println("Loading SVT t0 shifts ...");
+
+ ConditionsManager conditions = ConditionsManager.defaultInstance();
+ BufferedReader reader;
+
+ String filePath = "calibSVT/default.t0shift";
+ String line;
+ try {
+ reader = new BufferedReader(conditions.getRawConditions(filePath).getReader());
+ while ((line = reader.readLine()) != null) {
+ // If the line is a comment, skip it
+ if (line.indexOf("#") != -1) {
+ line = line.substring(0, line.indexOf("#"));
+ }
+ StringTokenizer lineTok = new StringTokenizer(line);
+ if (lineTok.countTokens() == 0) {
+ continue;
+ }
+ if (lineTok.countTokens() != 3) {
+ throw new RuntimeException("Invalid line in t0shift file: " + line);
+ }
+ int layer = Integer.valueOf(lineTok.nextToken());
+ int module = Integer.valueOf(lineTok.nextToken());
+ double t0shift = Double.valueOf(lineTok.nextToken());
+
+ t0ShiftMap.put(new Pair(layer, module), t0shift);
+ }
+ } catch (IOException exception) {
+ throw new RuntimeException("Unable to load t0 shifts!", exception);
+ }
+ }
+
+ public static Double getNoise(SiSensor sensor, int channel) {
+ Pair<Integer, Integer> daqPair = SvtUtils.getInstance().getDaqPair(sensor);
+ double[] noises = noiseMap.get(daqPair);
+ if (noises == null) {
+ return null;
+ } else {
+ return noises[channel];
+ }
+ }
+
+ public static Double getPedestal(SiSensor sensor, int channel) {
+ Pair<Integer, Integer> daqPair = SvtUtils.getInstance().getDaqPair(sensor);
+ double[] pedestals = pedestalMap.get(daqPair);
+ if (pedestals == null) {
+ return null;
+ } else {
+ return pedestals[channel];
+ }
+ }
+
+ public static Double getTShaping(SiSensor sensor, int channel) {
+ Pair<Integer, Integer> daqPair = SvtUtils.getInstance().getDaqPair(sensor);
+ double[] tps = tpMap.get(daqPair);
+ if (tps == null) {
+ return null;
+ } else {
+ return tps[channel];
+ }
+ }
+
+ public static Double getGain(SiSensor sensor, int channel) {
+ Pair<Integer, Integer> daqPair = SvtUtils.getInstance().getDaqPair(sensor);
+ List<Double> gain = gainMap.get(daqPair);
+ if (gain == null) {
+ return null;
+ } else {
+ return gain.get(channel);
+ }
+ }
+
+ public static Double getOffset(SiSensor sensor, int channel) {
+ Pair<Integer, Integer> daqPair = SvtUtils.getInstance().getDaqPair(sensor);
+ List<Double> offset = offsetMap.get(daqPair);
+ if (offset == null) {
+ return null;
+ } else {
+ return offset.get(channel);
+ }
+ }
+
+ public static ChannelConstants getChannelConstants(SiSensor sensor, int channel) {
+ ChannelConstants constants = new ChannelConstants();
+
+ Double value;
+ value = getNoise(sensor, channel);
+ 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 = getPedestal(sensor, channel);
+ 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 = getTShaping(sensor, channel);
+ if (value != null) {
+ constants.setTp(value);
+ } else {
+ System.out.println("Couldn't get Tp for sensor " + sensor.getName() + ", channel " + channel);
+ constants.setTp(53.0);
+ }
+
+ value = lookupT0Shift(sensor);
+ constants.setT0Shift(value);
+
+ return constants;
+ }
+
+ /**
+ * Checks if a channel has been tagged as bad
+ *
+ * @param daqPair : a FPGA/Hybrid 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;
+ }
+ }
+
+ public static int getTotalBadChannels() {
+ return totalBadChannels;
+ }
+
+ //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 t0Shift = 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;
+ }
+
+ public double getT0Shift() {
+ return t0Shift;
+ }
+
+ public void setT0Shift(double t0Shift) {
+ this.t0Shift = t0Shift;
+ }
+ }
+
+ static private double lookupT0Shift(SiSensor sensor) {
+ SiTrackerIdentifierHelper helper = (SiTrackerIdentifierHelper) sensor.getIdentifierHelper();
+ IIdentifier id = sensor.getIdentifier();
+ int layer = helper.getLayerValue(id);
+ int module = helper.getModuleValue(id);
+ return t0ShiftMap.get(new Pair(layer, module));
+ }
+}
java/trunk/conditions/src/main/java/org/hps/conditions/deprecated
--- java/trunk/conditions/src/main/java/org/hps/conditions/deprecated/HPSSVTConstants.java (rev 0)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/deprecated/HPSSVTConstants.java 2014-03-26 00:23:18 UTC (rev 349)
@@ -0,0 +1,61 @@
+package org.hps.conditions.deprecated;
+
+/**
+ *
+ * @author Omar Moreno <[log in to unmask]>
+ * @version $Id: HPSSVTConstants.java,v 1.7 2013/04/25 22:11:14 meeg Exp $
+ *
+ */
+
+public class HPSSVTConstants {
+
+ public static final int SVT_TOTAL_FPGAS = 7;
+ public static final int TOTAL_APV25_PER_HYBRID = 5;
+ public static final int TOTAL_APV25_CHANNELS = 128;
+ public static final int TOTAL_HYBRIDS_PER_FPGA = 3;
+ public static final int TOTAL_TEMPS_PER_HYBRID = 4;
+
+ // The Rear Transition Module gain
+ public static final double RTM_GAIN = 1.5;
+
+ // Total number of strips per sensor
+ public static final int TOTAL_STRIPS_PER_SENSOR = 639;
+
+ // Total number of shaper signal samples obtained
+ public static final int TOTAL_NUMBER_OF_SAMPLES = 6;
+
+ // MASKs used to encode and decode the SVT data
+ public static final int TEMP_MASK = 0xFFFF;
+ public static final int HYBRID_MASK = 0x3;
+ public static final int APV_MASK = 0x7;
+ public static final int CHANNEL_MASK = 0x7F;
+ public static final int FPGA_MASK = 0xFFFF;
+ public static final int SAMPLE_MASK = 0x3FFF;
+
+ // Temperature constants
+ public static final double MIN_TEMP = -50;
+ public static final double MAX_TEMP = 150;
+ public static final int ADC_TEMP_COUNT = 4096;
+ public static final double TEMP_K0 = 273.15;
+ public static final double CONST_A = 0.03448533;
+ public static final double BETA = 3750.;
+ public static final double V_MAX = 2.5;
+ public static final double V_REF = 2.5;
+ public static final double R_DIV = 10000.;
+ public static final double TEMP_INC = 0.01;
+
+ // Length of the APV25 analog pipeline
+ public static final int ANALOG_PIPELINE_LENGTH = 192;
+ // Total number of channels an APV25 ASIC contains
+ public static final int CHANNELS = 128;
+ // Number of electron-hole pairs created by a min. ionizing particle
+ // in 300 micrometers of Si
+ public static final int MIP = 25000; // electrons
+ // Time intervals at which an APV25 shaper signal is sampled at
+ public static final double SAMPLING_INTERVAL = 24.0; // [ns]
+ // The APV25 gain after multiplexing
+ public static final double MULTIPLEXER_GAIN = 1;
+ // The APV25 front end gain
+ public static final double FRONT_END_GAIN = 100.0; //
+
+}
java/trunk/conditions/src/main/java/org/hps/conditions/deprecated
--- java/trunk/conditions/src/main/java/org/hps/conditions/deprecated/HPSSVTSensorSetup.java (rev 0)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/deprecated/HPSSVTSensorSetup.java 2014-03-26 00:23:18 UTC (rev 349)
@@ -0,0 +1,235 @@
+package org.hps.conditions.deprecated;
+
+import hep.physics.matrix.BasicMatrix;
+import hep.physics.vec.BasicHep3Vector;
+import hep.physics.vec.VecOp;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import org.lcsim.detector.*;
+import org.lcsim.detector.solids.Box;
+import org.lcsim.detector.solids.LineSegment3D;
+import org.lcsim.detector.solids.Polygon3D;
+import org.lcsim.detector.tracker.silicon.ChargeCarrier;
+import org.lcsim.detector.tracker.silicon.SiSensor;
+import org.lcsim.detector.tracker.silicon.SiStrips;
+import org.lcsim.geometry.Detector;
+import org.lcsim.util.Driver;
+
+/**
+ * Setup driver for the HPSTracker subdetector.
+ *
+ * @author Mathew Graham <[log in to unmask]>
+ * @author Omar Moreno <[log in to unmask]>
+ * @author Jeremy McCormick <[log in to unmask]>
+ * @version $Id: HPSSVTSensorSetup.java,v 1.13 2013/10/29 23:28:53 jeremy Exp $
+ */
+public class HPSSVTSensorSetup extends Driver {
+
+ boolean debug = false;
+ String subdetectorName = "Tracker";
+ // Sensor Characteristics
+ private double readoutStripPitch = 0.060; // mm
+ private double senseStripPitch = 0.030; // mm
+ private double readoutStripCapacitanceIntercept = 0;
+ private double readoutStripCapacitanceSlope = 0.16; // pf/mm
+ private double senseStripCapacitanceIntercept = 0;
+ private double senseStripCapacitanceSlope = 0.16; // pf/mm
+ private double readoutTransferEfficiency = 0.986;
+ private double senseTransferEfficiency = 0.419;
+ /*
+ * Adding separate strip capacitance for long detectors following
+ * S/N = mip_charge/(270e- + 36*C[pf/cm]*L[cm]
+ * e.g. for expected S/N=16 and L=20cm -> C=0.1708pf/mm
+ * e.g. for expected S/N=8 and L=20cm -> C=0.39pf/mm
+ * This should be taken into account by the noise model -> FIX THIS.
+ */
+ private double longSensorLengthThreshold = 190.0; //mm
+ private double readoutLongStripCapacitanceSlope = 0.39; // pf/mm
+ private double senseLongStripCapacitanceSlope = 0.39; // pf/mm
+
+
+ // Set of sensors
+ Set<SiSensor> sensors = new HashSet<SiSensor>();
+
+ public HPSSVTSensorSetup() {
+ }
+
+ public HPSSVTSensorSetup(String subdetectorName) {
+ this.subdetectorName = subdetectorName;
+ }
+
+ @Override
+ public void detectorChanged(Detector detector) {
+ if (subdetectorName == null) {
+ throw new RuntimeException("The subdetector name was not set!");
+ }
+
+ // Get the SVT
+ IDetectorElement detectorElement = detector.getDetectorElement().findDetectorElement(subdetectorName);
+
+ // Get all SVT sensors
+ sensors.addAll(detectorElement.findDescendants(SiSensor.class));
+ if (debug) {
+ System.err.println(this.getClass().getName() + ": Added " + sensors.size() + " sensors");
+ }
+
+ // Configure the sensors
+ configureSensors(sensors);
+
+ // Create DAQ Maps
+ //if (!SvtUtils.getInstance().isSetup()) {
+ SvtUtils.getInstance().reset(); // Hard reset of SvtUtils to clear previous detector state.
+ SvtUtils.getInstance().setup(detector);
+ //}
+ }
+
+ /**
+ * Configure the SVT sensors
+ *
+ * @param subdetector
+ */
+ private void configureSensors(Set<SiSensor> sensors) {
+ // Loop through all the sensors in the set.
+ for (SiSensor sensor : sensors) {
+
+ if (debug) {
+ System.out.println(this.getClass().getSimpleName() + " - setting up sensor " + sensor.getName());
+ }
+
+ Box sensorSolid = (Box) sensor.getGeometry().getLogicalVolume().getSolid();
+
+ Polygon3D pSide = sensorSolid.getFacesNormalTo(new BasicHep3Vector(0, 0, 1)).get(0);
+ Polygon3D nSide = sensorSolid.getFacesNormalTo(new BasicHep3Vector(0, 0, -1)).get(0);
+
+ // P side collects holes.
+ sensor.setBiasSurface(ChargeCarrier.HOLE, pSide);
+ // N side collects electrons.
+ sensor.setBiasSurface(ChargeCarrier.ELECTRON, nSide);
+
+ // Translate to the outside of the box in order to setup electrodes.
+ ITranslation3D electrodesPosition = new Translation3D(VecOp.mult(-pSide.getDistance(), pSide.getNormal()));
+
+ // Align the strips with the edge of the sensor.
+ IRotation3D electrodesRotation = new RotationPassiveXYZ(0, 0, 0);
+ Transform3D electrodesTransform = new Transform3D(electrodesPosition, electrodesRotation);
+
+ // Set the number of readout and sense electrodes.
+ SiStrips readoutElectrodes = new SiStrips(ChargeCarrier.HOLE, readoutStripPitch, sensor, electrodesTransform);
+ SiStrips senseElectrodes = new SiStrips(ChargeCarrier.HOLE, senseStripPitch, (readoutElectrodes.getNCells() * 2 - 1), sensor, electrodesTransform);
+
+ if (debug) {
+ System.out.println("The number of readout strips is " + readoutElectrodes.getNCells());
+ System.out.println("The number of sense strips is " + senseElectrodes.getNCells());
+ }
+
+ double roCap = this.getStripLength(sensor) > longSensorLengthThreshold ? readoutLongStripCapacitanceSlope : readoutStripCapacitanceSlope;
+ double senseCap = this.getStripLength(sensor) > longSensorLengthThreshold ? senseLongStripCapacitanceSlope : senseStripCapacitanceSlope;
+
+ // Set the strip capacitance.
+ readoutElectrodes.setCapacitanceIntercept(readoutStripCapacitanceIntercept);
+ readoutElectrodes.setCapacitanceSlope(roCap);
+ senseElectrodes.setCapacitanceIntercept(senseStripCapacitanceIntercept);
+ senseElectrodes.setCapacitanceSlope(senseCap);
+
+ if(debug) {
+ System.out.printf("%s: Sensor %s has strip length %.3f\n",this.getClass().getSimpleName(),sensor.getName(),this.getStripLength(sensor));
+ System.out.printf("%s: ro electrodes capacitance %.3f (cell0 %.3f)\n",this.getClass().getSimpleName(),readoutElectrodes.getCapacitance(),readoutElectrodes.getCapacitance(0));
+ System.out.printf("%s: ro sense capacitance %.3f (cell0 %.3f)\n",this.getClass().getSimpleName(),senseElectrodes.getCapacitance(),senseElectrodes.getCapacitance(0));
+ }
+
+ // Set sense and readout electrodes.
+ sensor.setSenseElectrodes(senseElectrodes);
+ sensor.setReadoutElectrodes(readoutElectrodes);
+
+ // Set the charge transfer efficiency.
+ double[][] transferEfficiencies = {{readoutTransferEfficiency, senseTransferEfficiency}};
+ sensor.setTransferEfficiencies(ChargeCarrier.HOLE, new BasicMatrix(transferEfficiencies));
+
+ if (debug) {
+ System.out.println("----------------------------");
+ }
+ }
+ }
+
+ double getStripLength(SiSensor sensor) {
+ /*
+ * Returns the length of the strip
+ * This is getting the face of the sensor and then getting the longest edge
+ * VERY DANGEROUS -> FIX THIS!
+ */
+ double length = 0;
+ List<Polygon3D> faces = ((Box) sensor.getGeometry().getLogicalVolume().getSolid()).getFacesNormalTo(new BasicHep3Vector(0,0,1));
+ for(Polygon3D face : faces) {
+ //System.out.printf("%s: Sensor %s polygon3D %s\n",this.getClass().getSimpleName(),sensor.getName(),face.toString());
+ List<LineSegment3D> edges = face.getEdges();
+ for(LineSegment3D edge : edges) {
+ double l = edge.getLength();
+ if(l>length) {
+ length = l;
+ }
+ //System.out.printf("%s: edge %.3f \n",this.getClass().getSimpleName(),edge.getLength());
+ }
+ }
+
+ return length;
+ }
+
+ /**
+ * Set the readout strip capacitance
+ *
+ * @param intercept
+ * @param slope
+ */
+ public void setReadoutStripCapacitance(double intercept, double slope) {
+ readoutStripCapacitanceIntercept = intercept;
+ readoutStripCapacitanceSlope = slope;
+ }
+
+ /**
+ * Set the sense strip capacitance
+ *
+ * @param intercept
+ * @param slope
+ */
+ public void setSenseStripCapacitance(double intercept, double slope) {
+ senseStripCapacitanceIntercept = intercept;
+ senseStripCapacitanceSlope = slope;
+ }
+
+ /**
+ * Set readout strip pitch
+ *
+ * @param strip pitch
+ */
+ public void setReadoutStripPitch(double pitch) {
+ readoutStripPitch = pitch;
+ }
+
+ /**
+ * Set sense strip pitch
+ *
+ * @param strip pitch
+ */
+ public void setSenseStripPitch(double pitch) {
+ senseStripPitch = pitch;
+ }
+
+ /**
+ * Set readout strip transfer efficiency
+ *
+ * @param efficiency
+ */
+ public void setReadoutTransferEfficiency(double efficiency) {
+ readoutTransferEfficiency = efficiency;
+ }
+
+ /**
+ * Set sense strip transfer efficiency
+ *
+ * @param efficiency
+ */
+ public void setSenseTransferEfficiency(double efficiency) {
+ senseTransferEfficiency = efficiency;
+ }
+}
java/trunk/conditions/src/main/java/org/hps/conditions/deprecated
--- java/trunk/conditions/src/main/java/org/hps/conditions/deprecated/HpsConditionsReader.java (rev 0)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/deprecated/HpsConditionsReader.java 2014-03-26 00:23:18 UTC (rev 349)
@@ -0,0 +1,45 @@
+package org.hps.conditions.deprecated;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.conditions.ConditionsReader;
+
+/**
+ *
+ * @author Sho Uemura <[log in to unmask]>
+ * @version $Id: HpsConditionsReader.java,v 1.3 2012/11/20 19:56:40 meeg Exp $
+ */
+public class HpsConditionsReader extends ConditionsReader {
+
+ private String detectorName = null;
+ private int run;
+
+ public HpsConditionsReader(ConditionsReader reader) {
+ }
+
+ @Override
+ public InputStream open(String name, String type) throws IOException {
+ InputStream in = getClass().getResourceAsStream("/" + detectorName + "/" + name + "." + type);
+ if (in == null) {
+ in = getClass().getResourceAsStream("/org/lcsim/hps/calib/proposal2014/" + name + "." + type);
+ if (in == null) {
+ throw new IOException("Conditions " + name + " for " + detectorName + " with type " + type + " were not found");
+ }
+ }
+ return in;
+ }
+
+ @Override
+ public void close() throws IOException {
+ }
+
+ @Override
+ protected boolean update(ConditionsManager manager, String detectorName, int run) throws IOException {
+ this.detectorName = detectorName;
+ this.run = run;
+
+ return true;
+ }
+}
java/trunk/conditions/src/main/java/org/hps/conditions/deprecated
--- java/trunk/conditions/src/main/java/org/hps/conditions/deprecated/QuietBaseLCSimEvent.java (rev 0)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/deprecated/QuietBaseLCSimEvent.java 2014-03-26 00:23:18 UTC (rev 349)
@@ -0,0 +1,392 @@
+package org.hps.conditions.deprecated;
+import hep.physics.event.BaseEvent;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.IdentityHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.lcsim.conditions.ConditionsManager;
+//import org.lcsim.conditions.ConditionsManager.ConditionsNotFoundException;
+import org.lcsim.event.Cluster;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.HasMetaData;
+import org.lcsim.event.MCParticle;
+import org.lcsim.event.SimCalorimeterHit;
+import org.lcsim.event.SimTrackerHit;
+import org.lcsim.event.Track;
+import org.lcsim.geometry.Detector;
+import org.lcsim.geometry.IDDecoder;
+import org.lcsim.geometry.util.BaseIDDecoder;
+import org.lcsim.geometry.util.IDDescriptor;
+import org.lcsim.lcio.LCIOConstants;
+import org.lcsim.lcio.LCIOUtil;
+
+/**
+ * Duplicates BaseLCSimEvent but doesn't call conditionsManager.setDetector in its constructor.
+ * Used in TestRunTriggeredReconToLcio to avoid causing spurious detectorChanged events.
+ * TODO: really should find a better way to do this, this is awful, but I don't see a clean way to do this by just extending BaseLCSimEvent.
+ * @author Sho Uemura
+ */
+public class QuietBaseLCSimEvent extends BaseEvent implements EventHeader
+{
+ private String detectorName;
+ private final Map<List,LCMetaData> metaDataMap = new IdentityHashMap<List,LCMetaData>();
+ private ConditionsManager conditionsManager = ConditionsManager.defaultInstance();
+ private static final int NANO_SECONDS = 1000000;
+ public static final String READOUT_NAME = "ReadoutName";
+
+ /** Creates a new instance of BaseLCSimEvent */
+ public QuietBaseLCSimEvent(int run, int event, String detectorName)
+ {
+ this(run,event,detectorName,System.currentTimeMillis()*NANO_SECONDS);
+ }
+
+ public QuietBaseLCSimEvent(int run, int event, String detectorName, long timeStamp)
+ {
+ super(run,event,timeStamp);
+ this.detectorName = detectorName;
+// try
+// {
+// conditionsManager.setDetector(detectorName,run);
+// }
+// catch (ConditionsNotFoundException x)
+// {
+// throw new RuntimeException("Please see http://confluence.slac.stanford.edu/display/ilc/Conditions+database",x);
+// }
+ }
+
+ //public String getInputFile()
+ //{
+ // return (String)get("INPUT_FILE");
+ //}
+
+ public String toString()
+ {
+ return "Run "+getRunNumber()+" Event "+getEventNumber()+" ("+new Date(getTimeStamp()/NANO_SECONDS)+") Detector: "+detectorName;
+ }
+
+ public Detector getDetector()
+ {
+ return conditionsManager.getCachedConditions(Detector.class,"compact.xml").getCachedData();
+ }
+
+ public List<MCParticle> getMCParticles()
+ {
+ return get(MCParticle.class,MC_PARTICLES);
+ }
+
+ public List<Track> getTracks()
+ {
+ return get(Track.class,TRACKS);
+ }
+
+ public List<Cluster> getClusters()
+ {
+ return get(Cluster.class,CLUSTERS);
+ }
+
+ public List<SimCalorimeterHit> getSimCalorimeterHits(String name)
+ {
+ return get(SimCalorimeterHit.class,name);
+ }
+
+ public List<SimTrackerHit> getSimTrackerHits(String name)
+ {
+ return get(SimTrackerHit.class,name);
+ }
+
+ public <T> List<T> get(Class<T> type, String name)
+ {
+ return (List<T>) get(name);
+ }
+
+ public <T> List<List<T>> get(Class<T> type)
+ {
+ List<List<T>> result = new ArrayList<List<T>>();
+ for (Map.Entry<List,LCMetaData> entry : metaDataMap.entrySet())
+ {
+ if (type.isAssignableFrom(entry.getValue().getType()))
+ {
+ result.add(entry.getKey());
+ }
+ }
+ return result;
+ }
+
+ public Collection<LCMetaData> getMetaData()
+ {
+ return metaDataMap.values();
+ }
+
+ public Set<List> getLists()
+ {
+ return metaDataMap.keySet();
+ }
+
+ public LCMetaData getMetaData(List x)
+ {
+ return metaDataMap.get(x);
+ }
+
+ public void put(String name, Object component)
+ {
+ super.put(name, component);
+ if (component instanceof List)
+ {
+ List list = (List) component;
+ Class type = list.isEmpty() ? Object.class : list.get(0).getClass();
+ for (Object o : list)
+ {
+ if (!type.isAssignableFrom(o.getClass())) type = Object.class;
+ }
+ metaDataMap.put(list,new MetaData(name,type,0,null));
+ }
+ }
+
+ public void put(String name, List collection, Class type, int flags)
+ {
+ put(name,collection,type,flags,null);
+ }
+
+ public void put(String name, List collection, Class type, int flags, String readoutName)
+ {
+ super.put(name,collection);
+
+ LCMetaData meta = new MetaData(name, type, flags, readoutName);
+ metaDataMap.put(collection,meta);
+
+ setCollectionMetaData(collection, type, meta);
+ }
+
+ private void setCollectionMetaData(List collection, Class type, LCMetaData meta) {
+ //System.out.println("setCollectionMetaData");
+ // Set MetaData on collection objects.
+ if (HasMetaData.class.isAssignableFrom(type)) {
+ for (Object o : collection) {
+ if (o instanceof HasMetaData) {
+ ((HasMetaData)o).setMetaData(meta);
+ }
+ }
+ }
+ }
+
+ protected void put(String name, List collection, Class type, int flags, Map intMap, Map floatMap, Map stringMap)
+ {
+ super.put(name,collection);
+ LCMetaData meta = new MetaData(name, type, flags, intMap, floatMap, stringMap);
+ metaDataMap.put(collection,meta);
+ }
+
+ /**
+ * Removes a collection from the event.
+ */
+ public void remove(String name)
+ {
+ Object collection = get(name);
+ if (collection instanceof List) metaDataMap.remove((List) collection);
+ super.keys().remove(name);
+ }
+
+ public String getDetectorName()
+ {
+ return detectorName;
+ }
+
+ public boolean hasCollection(Class type, String name)
+ {
+ if (!hasItem(name)) return false;
+ Object collection = get(name);
+ if (!(collection instanceof List)) return false;
+ return type.isAssignableFrom(metaDataMap.get(collection).getType());
+ }
+
+ public boolean hasCollection(Class type)
+ {
+ for (LCMetaData meta : metaDataMap.values())
+ {
+ if (type.isAssignableFrom(meta.getType()))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public boolean hasItem(String name)
+ {
+ return super.keys().contains(name);
+ }
+
+ public Map<String, int[]> getIntegerParameters()
+ {
+ return Collections.<String, int[]>emptyMap();
+
+ }
+
+ public Map<String, float[]> getFloatParameters()
+ {
+ return Collections.<String, float[]>emptyMap();
+
+ }
+
+ public Map<String, String[]> getStringParameters()
+ {
+ return Collections.<String, String[]>emptyMap();
+ }
+
+ public float getWeight()
+ {
+ return 1.0f;
+ }
+
+ private class MetaData implements LCMetaData
+ {
+ private int flags;
+ private final String name;
+ private final Class type;
+ private Map<String, int[]> intMap;
+ private Map<String, float[]> floatMap;
+ private Map<String, String[]> stringMap;
+ private transient IDDecoder dec;
+
+ MetaData(String name, Class type, int flags, String readoutName)
+ {
+ this.name = name;
+ this.type = type;
+ this.flags = flags;
+ if (readoutName != null) getStringParameters().put(READOUT_NAME,new String[]{ readoutName });
+ }
+ MetaData(String name, Class type, int flags, Map intMap, Map floatMap, Map stringMap)
+ {
+ this.name = name;
+ this.type = type;
+ this.flags = flags;
+ this.intMap = intMap;
+ this.floatMap = floatMap;
+ this.stringMap = stringMap;
+ }
+
+ public int getFlags()
+ {
+ return flags;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public Class getType()
+ {
+ return type;
+ }
+
+ public org.lcsim.geometry.IDDecoder getIDDecoder()
+ {
+ if (dec == null) dec = findIDDecoder();
+ return dec;
+ }
+
+ public org.lcsim.geometry.IDDecoder findIDDecoder()
+ {
+ // If the IDDecoder name is explicitly set then use it, otherwise
+ // use the name of the collection itself.
+ String readoutName = name;
+ if (stringMap != null)
+ {
+ String[] names = stringMap.get(READOUT_NAME);
+ if (names != null && names.length >= 1) readoutName = names[0];
+ }
+
+ // Find the IDDecoder using the Detector.
+ org.lcsim.geometry.IDDecoder result=null;
+ try {
+ result = getDetector().getDecoder(readoutName);
+ }
+ catch (RuntimeException x)
+ {}
+
+ // Detector lookup failed. Attempt to use the CellIDEncoding collection parameter.
+ if (result == null)
+ result = createIDDecoderFromCellIDEncoding();
+
+ // If both methods failed, then there is a problem.
+ if (result == null)
+ throw new RuntimeException("Could not find or create an IDDecoder for the collection: "+name+", readout: "+readoutName);
+
+ return result;
+ }
+
+ /**
+ * Make an IDDecoder for this MetaData using the CellIDEncoding parameter.
+ * @return An IDDecoder made built from the CellIDEncoding.
+ */
+ private IDDecoder createIDDecoderFromCellIDEncoding()
+ {
+ String[] cellIdEncoding = getStringParameters().get("CellIDEncoding");
+ IDDecoder result = null;
+ if (cellIdEncoding != null)
+ {
+ result = new BaseIDDecoder();
+ try {
+ IDDescriptor desc = new IDDescriptor(cellIdEncoding[0]);
+ result.setIDDescription(desc);
+ }
+ catch (IDDescriptor.IDException x)
+ {
+ throw new RuntimeException(x);
+ }
+ }
+ return result;
+ }
+
+ public Map<String, int[]> getIntegerParameters()
+ {
+ if (intMap == null) intMap = new HashMap<String, int[]>();
+ return intMap;
+ }
+
+ public Map<String, float[]> getFloatParameters()
+ {
+ if (floatMap == null) floatMap = new HashMap<String, float[]>();
+ return floatMap;
+ }
+
+ public Map<String, String[]> getStringParameters()
+ {
+ if (stringMap == null) stringMap = new HashMap<String, String[]>();
+ return stringMap;
+ }
+
+ public EventHeader getEvent()
+ {
+ return QuietBaseLCSimEvent.this;
+ }
+
+ public void setSubset(boolean isSubset)
+ {
+ flags = LCIOUtil.bitSet(flags,LCIOConstants.BITSubset,isSubset);
+ }
+
+ public boolean isSubset()
+ {
+ return LCIOUtil.bitTest(flags,LCIOConstants.BITSubset);
+ }
+
+ public void setTransient(boolean isTransient)
+ {
+ flags = LCIOUtil.bitSet(flags,LCIOConstants.BITTransient,isTransient);
+ }
+
+ public boolean isTransient()
+ {
+ return LCIOUtil.bitTest(flags,LCIOConstants.BITTransient);
+ }
+ }
+}
java/trunk/conditions/src/main/java/org/hps/conditions/deprecated
--- java/trunk/conditions/src/main/java/org/hps/conditions/deprecated/StereoPair.java (rev 0)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/deprecated/StereoPair.java 2014-03-26 00:23:18 UTC (rev 349)
@@ -0,0 +1,130 @@
+package org.hps.conditions.deprecated;
+
+import org.lcsim.detector.tracker.silicon.SiSensor;
+
+/**
+ * A class describing an SVT stereo pair.
+ *
+ * @author Per Hansson <[log in to unmask]>
+ * @author Omar Moreno <[log in to unmask]>
+ * @version $Id: StereoPair.java,v 1.3 2013/07/30 00:53:07 omoreno Exp $
+ */
+public class StereoPair {
+
+
+ // Layer number to which the stereo pair belongs to
+ private int layerNumber = -1;
+
+ // The axial and stereo sensors
+ private SiSensor axialSensor = null;
+ private SiSensor stereoSensor = null;
+
+ // The detector volume in which the stereo pair resides
+ public enum detectorVolume{ Top, Bottom };
+ private detectorVolume volume = detectorVolume.Top;
+
+ /**
+ * Default Ctor
+ *
+ * @param layerNumber : Layer number to which the stereo pair belongs to
+ */
+ public StereoPair(int layerNumber){
+ this.layerNumber = layerNumber;
+ }
+
+ /**
+ * Ctor
+ *
+ * @param layerNumber : Layer number to which the stereo pair belongs to
+ * @param volume : detector volume (detectorVolume.Top or detector Volume.Bottom) in
+ * which the stereo pair resides
+ * @param axialSensor
+ * @param stereoSensor
+ */
+ public StereoPair(int layerNumber, detectorVolume volume, SiSensor axialSensor, SiSensor stereoSensor){
+ this.layerNumber = layerNumber;
+ this.volume = volume;
+ this.axialSensor = axialSensor;
+ this.stereoSensor = stereoSensor;
+ }
+
+ /**
+ * Set the axial sensor of stereo pair
+ *
+ * @param axialSensor
+ */
+ public void setAxialSensor(SiSensor axialSensor){
+ this.axialSensor = axialSensor;
+ }
+
+ /**
+ * Set the stereo sensor of the stereo pair
+ *
+ * @param stereoSensor
+ */
+ public void setStereoSensor(SiSensor stereoSensor){
+ this.stereoSensor = stereoSensor;
+ }
+
+ /**
+ * Set the SVT volume in which the stereo pair resides
+ *
+ * @param volume : detectorVolume.Top or detectorVolume.Bottom
+ */
+ public void setDetectorVolume(detectorVolume volume){
+ this.volume = volume;
+ }
+
+ /**
+ * Get the axial sensor of the stereo pair
+ *
+ * @return Axial sensor. Returns null if it hasn't been set yet.
+ */
+ public SiSensor getAxialSensor(){
+ return axialSensor;
+ }
+
+ /**
+ * Get the stereo sensor of the stereo pair
+ *
+ * @return Stereo sensor. Returns null if it hasn't been set yet.
+ */
+ public SiSensor getStereoSensor(){
+ return stereoSensor;
+ }
+
+ /**
+ * Get the layer number to which the stereo pair belongs to
+ *
+ * @return layer number
+ */
+ public int getLayerNumber(){
+ return layerNumber;
+ }
+
+ /**
+ * Get the SVT volume in which the stereo pair resides
+ *
+ * @return volume : detectorVolume.Top or detectorVolume.Bottom
+ */
+ public detectorVolume getDetectorVolume(){
+ return volume;
+ }
+
+ /**
+ * Return a string describing the stereo pair
+ *
+ * @return stereo pair description
+ */
+ @Override
+ public String toString(){
+ String axialName = axialSensor == null ? "None" : axialSensor.getName();
+ String stereoName = stereoSensor == null ? "None" : stereoSensor.getName();
+ String description = "Stereo Pair:\n";
+ description += "\tLayer Number: " + this.getLayerNumber();
+ description += "\t\tAxial Sensor: " + axialName;
+ description += "\t\tStereo Sensor: " + stereoName;
+ return description;
+
+ }
+}
java/trunk/conditions/src/main/java/org/hps/conditions/deprecated
--- java/trunk/conditions/src/main/java/org/hps/conditions/deprecated/SvtUtils.java (rev 0)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/deprecated/SvtUtils.java 2014-03-26 00:23:18 UTC (rev 349)
@@ -0,0 +1,526 @@
+package org.hps.conditions.deprecated;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.detector.IDetectorElement;
+import org.lcsim.detector.identifier.IIdentifier;
+import org.lcsim.detector.identifier.IIdentifierHelper;
+import org.lcsim.detector.tracker.silicon.ChargeCarrier;
+import org.lcsim.detector.tracker.silicon.SiSensor;
+import org.lcsim.detector.tracker.silicon.SiTrackerIdentifierHelper;
+import org.lcsim.geometry.Detector;
+import org.lcsim.hps.util.Pair;
+
+import static org.hps.conditions.deprecated.StereoPair.detectorVolume;
+
+/**
+ * A class providing various utilities related to the HPS SVT.
+ *
+ * @author Omar Moreno <[log in to unmask]>
+ * @version $Id: SvtUtils.java,v 1.19 2013/11/06 20:25:37 omoreno Exp $
+ */
+public class SvtUtils {
+
+ private static SvtUtils INSTANCE = null;
+ // Set of sensors
+ private Set<SiSensor> sensors = new HashSet<SiSensor>();
+ // Set of stereo pairs
+ private Set<StereoPair> stereoPairs = new HashSet<StereoPair>();
+ // Map from Sensor to Hybrid/FPGA pair
+ private Map<SiSensor /* sensor */, Pair<Integer /* FPGA */, Integer /* Hybrid */>> sensorToDaqPair = new HashMap<SiSensor, Pair<Integer, Integer>>();
+ // Map from Hybrid/FPGA pair
+ private Map<Pair<Integer /* FPGA */, Integer /* Hybrid */>, SiSensor /* Sensor*/> daqPairToSensor = new HashMap<Pair<Integer, Integer>, SiSensor>();
+ // Map from SVT top layer to Hybrid/FPGA pair
+ private Map<Integer /* Layer */, List<Pair<Integer /* FPGA */, Integer /* Hybrid */>>> topLayerDaqMap = new HashMap<Integer, List<Pair<Integer, Integer>>>();
+ // Map from SVT bottom layer to Hybrid/FPGA pair
+ private Map<Integer /* Layer # */, List<Pair<Integer /* FPGA */, Integer /* Hybrid */>>> bottomLayerDaqMap = new HashMap<Integer, List<Pair<Integer, Integer>>>();
+ // Map sensor to an SVT top layer
+ private Map<SiSensor /* Sensor */, Integer /* Layer */> sensorToTopLayer = new HashMap<SiSensor, Integer>();
+ // Map sensor to an SVT bottom layer
+ private Map<SiSensor /* Sensor */, Integer /* Layer */> sensorToBottomLayer = new HashMap<SiSensor, Integer>();
+ // Map sensor to descriptor
+ private Map<SiSensor /* Sensor */, String /* Description */> sensorToDescriptor = new HashMap<SiSensor, String>();
+ // Map layer to top SVT sensor
+ private Map<Integer /* Layer */, List<SiSensor> /* Sensor */> topLayerToSensor = new HashMap<Integer, List<SiSensor>>();
+ // Map layer to bottom SVT sensor
+ private Map<Integer /* Layer */, List<SiSensor> /* Sensor */> bottomLayerToSensor = new HashMap<Integer, List<SiSensor>>();
+ private SiSensor[][] sensorArray;
+ private IIdentifierHelper helper;
+ String subdetectorName = "Tracker";
+ ConditionsManager manager = ConditionsManager.defaultInstance();
+ int maxModuleNumber = 0;
+ int maxLayerNumber = 0;
+ private Set<Integer> fpgaNumbers = new HashSet<Integer>();
+ private boolean isSetup = false;
+ boolean debug = false;
+
+ /*
+ * Private ctor to keep user from instantiating
+ */
+ private SvtUtils() {
+ }
+
+ /**
+ *
+ */
+ public static SvtUtils getInstance() {
+
+ // Use lazy instantiation
+ if (INSTANCE == null) {
+ INSTANCE = new SvtUtils();
+ }
+ return INSTANCE;
+ }
+
+ /**
+ * @return true if all maps have been loaded, false otherwise
+ */
+ public boolean isSetup() {
+ return isSetup;
+ }
+
+ /**
+ * Get the plane number to which the sensor belongs to. This is does not
+ * return the SVT layer number.
+ *
+ * @param sensor
+ * @return The layer number
+ */
+ // TODO: Change the name to clarify that what is being returned is the plane number
+ public int getLayerNumber(SiSensor sensor) {
+ if (sensorToTopLayer.containsKey(sensor)) {
+ return sensorToTopLayer.get(sensor);
+ } else if (sensorToBottomLayer.containsKey(sensor)) {
+ return sensorToBottomLayer.get(sensor);
+ } else {
+ throw new RuntimeException("The sensor " + sensor.getName()
+ + " does not have an associated plane number");
+ }
+ }
+
+ /**
+ * Checks if a sensor is part of the top SVT volume.
+ *
+ * @return true if it is, false if it belongs to the bottom volume
+ */
+ public boolean isTopLayer(SiSensor sensor) {
+ if (sensorToTopLayer.containsKey(sensor)) {
+ return true;
+ } else if (sensorToBottomLayer.containsKey(sensor)) {
+ return false;
+ } else {
+ throw new RuntimeException("There is no layer associated with sensor " + sensor.getName());
+ }
+ }
+
+ /**
+ * Checks if the orientation of the sensor is axial.
+ *
+ * @return true if it is, false if it is a stereo sensor
+ */
+ public boolean isAxial(SiSensor sensor) {
+ if (this.isTopLayer(sensor) && this.getLayerNumber(sensor) % 2 == 1) {
+ return true;
+ } else if (!this.isTopLayer(sensor) && this.getLayerNumber(sensor) % 2 == 0) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Get a sensor by its plane and module id. Both are zero-indexed.
+ *
+ * @param moduleNumber : module id
+ * @param planeNumber : plane id (typically 1 less than the layer id)
+ * @return sensor
+ */
+ public SiSensor getSensor(int moduleNumber, int planeNumber) {
+ if (moduleNumber < 0 || moduleNumber > maxModuleNumber) {
+ throw new RuntimeException("Module number " + moduleNumber + " is out of range!");
+ } else if (planeNumber < 0 || planeNumber >= maxLayerNumber) {
+ throw new RuntimeException("Plane number " + planeNumber + " is out of range!");
+ }
+ return sensorArray[moduleNumber][planeNumber];
+ }
+
+ /**
+ * Get a sensor by its FPGA and hybrid number.
+ *
+ * @param daqPair : a Pair of the form Pair<FPGA number, hybrid number>
+ * @return sensor
+ */
+ public SiSensor getSensor(Pair<Integer, Integer> daqPair) {
+ return daqPairToSensor.get(daqPair);
+ }
+
+ /**
+ * Get a sensor from the top SVT volume by its plane number and sensor
+ * position within a plane.
+ *
+ * @param planeNumber
+ * @param sensorNumber : position within a plane
+ * @return sensor or null if the sensor doesn't exist in that position
+ */
+ public SiSensor getTopSensor(int planeNumber, int sensorNumber) {
+ if(topLayerToSensor.get(planeNumber).size() <= sensorNumber) return null;
+ return topLayerToSensor.get(planeNumber).get(sensorNumber);
+ }
+
+ /**
+ * Get a sensor from the bottom SVT volume by its plane number and sensor
+ * position within a plane.
+ *
+ * @param planeNumber
+ * @param sensorNumber : position within a plane
+ * @return sensor or null if the sensor doesn't exist in that position
+ */
+ public SiSensor getBottomSensor(int layer, int sensorNumber) {
+ if(bottomLayerToSensor.get(layer).size() <= sensorNumber) return null;
+ return bottomLayerToSensor.get(layer).get(sensorNumber);
+ }
+
+ /**
+ * Get the Set of all sensors which compose the SVT.
+ *
+ * @return set of sensors
+ */
+ public Set<SiSensor> getSensors() {
+ return sensors;
+ }
+
+ /**
+ * Get the Set of all FPGA numbers.
+ *
+ * @return set of FPGA numbers
+ */
+ public Set<Integer> getFpgaNumbers() {
+ return fpgaNumbers;
+ }
+
+ /**
+ * Get the FPGA number associated with a sensor.
+ *
+ * @return FPGA number
+ */
+ public int getFPGA(SiSensor sensor) {
+ return sensorToDaqPair.get(sensor).getFirstElement();
+ }
+
+ /**
+ * Get the hybrid number associated with a sensor.
+ *
+ * @return hybrid number
+ */
+ public int getHybrid(SiSensor sensor) {
+ return sensorToDaqPair.get(sensor).getSecondElement();
+ }
+
+ public int getFPGACount() {
+ return 0;
+ }
+
+ /**
+ * Get the FPGA and hybrid number associated with a sensor as a pair of
+ * values.
+ *
+ * @param sensor
+ * @return pair of the form Pair<FPGA, hybrid>
+ */
+ public Pair<Integer, Integer> getDaqPair(SiSensor sensor) {
+ return sensorToDaqPair.get(sensor);
+ }
+
+ /**
+ * Get the IIdentifierHelper associated with the SVT.
+ *
+ * @return helper
+ */
+ public IIdentifierHelper getHelper() {
+ return helper;
+ }
+
+ /**
+ * Get a string describing a sensor.
+ *
+ * @param sensor
+ * @return String describing a sensor
+ */
+ public String getDescription(SiSensor sensor) {
+ return this.sensorToDescriptor.get(sensor);
+ }
+
+ /**
+ * Make the cell ID for any channel on a sensor.
+ *
+ * @param sensor
+ * @param channel : Physical channel number
+ * @return cell ID
+ */
+ public static long makeCellID(SiSensor sensor, int channel) {
+ int sideNumber;
+ if (sensor.hasElectrodesOnSide(ChargeCarrier.HOLE)) {
+ sideNumber = ChargeCarrier.HOLE.charge();
+ } else {
+ sideNumber = ChargeCarrier.ELECTRON.charge();
+ }
+ return sensor.makeStripId(channel, sideNumber).getValue();
+ }
+
+ /**
+ * Get the set of all stereo pairs which compose the SVT.
+ *
+ * @return Set of stereo pairs
+ */
+ public Set<StereoPair> getStereoPairs(){
+ return stereoPairs;
+ }
+
+ /**
+ * Creates and fill the various utility maps.
+ *
+ * @param detector : The SVT detector being used
+ */
+ public void setup(Detector detector) {
+
+ this.printDebug("Method: setupMaps: \n\tDetector: " + detector.getDetectorName());
+
+ // Load the DAQ Map from the conditions database
+ this.loadSvtDaqMap();
+
+ // Instantiate 'sensorArray' which allows for retrieval of a SiSensor
+ // by module and layer id
+ sensorArray = new SiSensor[maxModuleNumber + 1][maxLayerNumber];
+
+ // Get all of the sensors composing the SVT and add them to the set of all sensors
+ IDetectorElement detectorElement = detector.getDetectorElement().findDetectorElement(subdetectorName);
+ helper = detectorElement.getIdentifierHelper();
+ sensors.addAll(detectorElement.findDescendants(SiSensor.class));
+ this.printDebug("\tTotal number of sensors: " + sensors.size());
+
+ IIdentifier sensorIdent;
+ SiTrackerIdentifierHelper sensorHelper;
+ String description;
+ // Loop through all of the sensors and fill the maps
+ for (SiSensor sensor : sensors) {
+
+ // Get the sensor identifier
+ sensorIdent = sensor.getIdentifier();
+
+ // Get the sensor identifier helper in order to decode the id fields
+ sensorHelper = (SiTrackerIdentifierHelper) sensor.getIdentifierHelper();
+
+ // Get the sensor layer and module id
+ int layerNumber = sensorHelper.getLayerValue(sensorIdent);
+ int moduleNumber = sensorHelper.getModuleValue(sensorIdent);
+ sensorArray[moduleNumber][layerNumber - 1] = sensor;
+ int listPosition = 0;
+ switch (moduleNumber % 2) {
+ // Top Layer
+ case 0:
+
+ listPosition = moduleNumber / 2;
+ sensorToTopLayer.put(sensor, layerNumber);
+ sensorToDaqPair.put( sensor, topLayerDaqMap.get(layerNumber).get(listPosition));
+ topLayerToSensor.get(layerNumber).set(listPosition, sensor);
+ daqPairToSensor.put(topLayerDaqMap.get(layerNumber).get(listPosition), sensor);
+ description = "Top Layer " + layerNumber + " - Sensor " + listPosition;
+ this.printDebug("\tDescription: " + description);
+ sensorToDescriptor.put(sensor, description);
+ break;
+ // Bottom Layer
+ case 1:
+
+ listPosition = (moduleNumber - 1) / 2;
+ sensorToBottomLayer.put(sensor, layerNumber);
+ sensorToDaqPair.put(sensor, bottomLayerDaqMap.get(layerNumber).get(listPosition));
+ bottomLayerToSensor.get(layerNumber).set(listPosition, sensor);
+ daqPairToSensor.put(bottomLayerDaqMap.get(layerNumber).get(listPosition), sensor);
+ description = "Bottom Layer " + layerNumber + " - Sensor " + listPosition;
+ this.printDebug("\tDescription: " + description);
+ sensorToDescriptor.put(sensor, description);
+ break;
+ default:
+ throw new RuntimeException("Invalid module number: " + moduleNumber);
+ }
+ }
+
+ // Create stereo pairs
+ this.createStereoPairs();
+
+ isSetup = true;
+ }
+
+ /**
+ * Load the SVT DAQ Map from the conditions database
+ *
+ */
+ private void loadSvtDaqMap(){
+
+ // Path to file in conditions database
+ String filePath = "daqmap/svt_default.daqmap";
+ BufferedReader daqMapReader = null;
+ String currentLine = null;
+ try {
+ daqMapReader = new BufferedReader(manager.getRawConditions(filePath).getReader());
+
+ // Continue to read lines for the DAQ map until the end of file is
+ // reached. The DAQ map is has the following format
+ //
+ // layer module fpga hybrid
+ // ---------------------------------
+ while ((currentLine = daqMapReader.readLine()) != null) {
+
+ // If the line is a comment,skip it
+ if (currentLine.indexOf("#") != -1) continue;
+
+ // Split the line into tokens by whitespace
+ StringTokenizer stringTok = new StringTokenizer(currentLine);
+ int listPosition = 0;
+ while (stringTok.hasMoreTokens()) {
+
+ // Parse the line
+ int layer = Integer.valueOf(stringTok.nextToken());
+ int module = Integer.valueOf(stringTok.nextToken());
+ int fpga = Integer.valueOf(stringTok.nextToken());
+ int hybrid = Integer.valueOf(stringTok.nextToken());
+
+ // Find the maximum layer number and module number. This
+ // is used when instantiating 'sensorArray' and when creating
+ // stereo pairs.
+ maxModuleNumber = Math.max(maxModuleNumber, module);
+ maxLayerNumber = Math.max(maxLayerNumber, layer);
+
+ // A pair is used to relate an FPGA value to a hybrid number
+ Pair<Integer, Integer> daqPair = new Pair<Integer, Integer>(fpga, hybrid);
+ fpgaNumbers.add(fpga);
+
+ // Load the maps based on module number.
+ //
+ // Module 0 & 2 correspond to sensors which lie in the top SVT volume
+ // Module 1 & 3 correspond to sensors which lie in the bottom SVT volume
+ //
+ // A module number > 1 indicate that the sensor is part of a double layer.
+ // For the test run detector, all module numbers are either 0 or 1.
+ switch (module % 2) {
+ case 0:
+ listPosition = module / 2;
+ // If the top layer DAQ map doesn't contain the layer, add it
+ if (!topLayerDaqMap.containsKey(layer)) {
+ topLayerDaqMap.put(layer, new ArrayList<Pair<Integer, Integer>>());
+ }
+ this.printDebug("\tAdding FPGA: " + daqPair.getFirstElement() + ", Hybrid: " + daqPair.getSecondElement() + " to position: " + listPosition);
+ // Add the DAQ pair to the corresponding layer
+ topLayerDaqMap.get(layer).add(listPosition, daqPair);
+
+ // If the top layer sensor map doesn't contain the layer, add it
+ if (!topLayerToSensor.containsKey(layer)) {
+ topLayerToSensor.put(layer, new ArrayList<SiSensor>());
+ }
+ // Create room within the sensor map for the sensor
+ topLayerToSensor.get(layer).add(null);
+ break;
+ case 1:
+ listPosition = (module - 1) / 2;
+ if (!bottomLayerDaqMap.containsKey(layer)) {
+ bottomLayerDaqMap.put(layer, new ArrayList<Pair<Integer, Integer>>());
+ }
+ this.printDebug("\tAdding FPGA: " + daqPair.getFirstElement() + ", Hybrid: " + daqPair.getSecondElement() + " to position: " + listPosition);
+ bottomLayerDaqMap.get(layer).add(listPosition, daqPair);
+ if (!bottomLayerToSensor.containsKey(layer)) {
+ bottomLayerToSensor.put(layer, new ArrayList<SiSensor>());
+ }
+ bottomLayerToSensor.get(layer).add(null);
+ break;
+ default:
+ throw new RuntimeException("Invalid module number: " + module);
+ }
+ }
+ }
+
+ } catch (IOException exception) {
+ throw new RuntimeException("Unable to load DAQ Map from " + filePath, exception);
+ }
+ }
+
+ /**
+ *
+ */
+ private void createStereoPairs(){
+
+ // Loop through all the sensors in both top and bottom layers and
+ // create stereo pairs.
+ SiSensor firstSensor = null;
+ SiSensor secondSensor = null;
+ int trackerLayer = 0;
+
+ //
+ for(int layerNumber = 1; layerNumber <= maxLayerNumber; layerNumber+=2 ){
+ for(int sensorNumber = 0; sensorNumber < (maxModuleNumber+1)/2; sensorNumber++){
+
+ firstSensor = this.getTopSensor(layerNumber, sensorNumber);
+ secondSensor = this.getTopSensor(layerNumber+1, sensorNumber);
+
+ if(firstSensor == null || secondSensor == null) continue;
+
+ trackerLayer = (layerNumber + 1)/2;
+ if(this.isAxial(firstSensor)){
+ stereoPairs.add(new StereoPair(trackerLayer, detectorVolume.Top, firstSensor, secondSensor));
+ } else {
+ stereoPairs.add(new StereoPair(trackerLayer, detectorVolume.Top, secondSensor, firstSensor));
+ }
+
+ firstSensor = this.getBottomSensor(layerNumber, sensorNumber);
+ secondSensor = this.getBottomSensor(layerNumber+1, sensorNumber);
+
+ if(firstSensor == null || secondSensor == null) continue;
+
+ if(this.isAxial(firstSensor)){
+ stereoPairs.add(new StereoPair(trackerLayer, detectorVolume.Bottom, firstSensor, secondSensor));
+ } else {
+ stereoPairs.add(new StereoPair(trackerLayer, detectorVolume.Bottom, secondSensor, firstSensor));
+ }
+ }
+ }
+
+ this.printDebug("Total number of stereo pairs created: " + stereoPairs.size());
+ for(StereoPair stereoPair : stereoPairs){
+ this.printDebug(stereoPair.toString());
+ }
+ }
+
+ /**
+ * Print a debug message
+ *
+ * @param debugMessage : message to be printed
+ */
+ private void printDebug(String debugMessage) {
+ if (debug) {
+ System.out.println(this.getClass().getSimpleName() + ": " + debugMessage);
+ }
+ }
+
+ public void reset() {
+ sensors = new HashSet<SiSensor>();
+ stereoPairs = new HashSet<StereoPair>();
+ sensorToDaqPair = new HashMap<SiSensor, Pair<Integer, Integer>>();
+ daqPairToSensor = new HashMap<Pair<Integer, Integer>, SiSensor>();
+ topLayerDaqMap = new HashMap<Integer, List<Pair<Integer, Integer>>>();
+ bottomLayerDaqMap = new HashMap<Integer, List<Pair<Integer, Integer>>>();
+ sensorToTopLayer = new HashMap<SiSensor, Integer>();
+ sensorToBottomLayer = new HashMap<SiSensor, Integer>();
+ sensorToDescriptor = new HashMap<SiSensor, String>();
+ topLayerToSensor = new HashMap<Integer, List<SiSensor>>();
+ bottomLayerToSensor = new HashMap<Integer, List<SiSensor>>();
+ sensorArray= null;
+ fpgaNumbers = new HashSet<Integer>();
+ }
+}
SVNspam 0.1