hps-java/src/main/java/org/lcsim/hps/recon/tracking
diff -u -r1.6 -r1.7
--- SimpleSvtReadout.java 1 Mar 2013 01:15:20 -0000 1.6
+++ SimpleSvtReadout.java 1 Mar 2013 21:24:26 -0000 1.7
@@ -28,26 +28,46 @@
/**
*
* @author Omar Moreno <[log in to unmask]>
- * @version $Id: SimpleSvtReadout.java,v 1.6 2013/03/01 01:15:20 meeg Exp $
+ * @version $Id: SimpleSvtReadout.java,v 1.7 2013/03/01 21:24:26 meeg Exp $
*/
public class SimpleSvtReadout extends Driver {
+ private SimTrackerHitReadoutDriver readoutDriver = new SimTrackerHitReadoutDriver();
private SiSensorSim siSimulation = new CDFSiSensorSim();
private String outputCollection = "SVTRawTrackerHits";
private Map<SiSensor, APV25Pipeline[]> pipelineMap = new HashMap<SiSensor, APV25Pipeline[]>();
//readout period time offset in ns
private double readoutOffset = 0.0;
private String readout = "TrackerHits";
- private SimTrackerHitReadoutDriver readoutDriver = new SimTrackerHitReadoutDriver();
private int readoutCycle = 0;
- private int samplesAboveThreshold = 3;
- private boolean noPileup = false;
private double timeOffset = 30.0;
+ private boolean noPileup = false;
+ //cut settings
+ private boolean enableThresholdCut = true;
+ private int samplesAboveThreshold = 3;
+ private double noiseThreshold = 2.0;
+ private boolean enablePileupCut = true;
public SimpleSvtReadout() {
add(readoutDriver);
}
+ public void setEnablePileupCut(boolean enablePileupCut) {
+ this.enablePileupCut = enablePileupCut;
+ }
+
+ public void setEnableThresholdCut(boolean enableThresholdCut) {
+ this.enableThresholdCut = enableThresholdCut;
+ }
+
+ public void setNoiseThreshold(double noiseThreshold) {
+ this.noiseThreshold = noiseThreshold;
+ }
+
+ public void setSamplesAboveThreshold(int samplesAboveThreshold) {
+ this.samplesAboveThreshold = samplesAboveThreshold;
+ }
+
public void setNoPileup(boolean noPileup) {
this.noPileup = noPileup;
}
@@ -78,50 +98,7 @@
public void process(EventHeader event) {
super.process(event);
- Map<SiSensor, Map<Integer, Double>> hitMap = new HashMap<SiSensor, Map<Integer, Double>>();
- for (SiSensor sensor : SvtUtils.getInstance().getSensors()) {
- Map<Integer, Double> hitsOnSensor = new HashMap<Integer, Double>();
- hitMap.put(sensor, hitsOnSensor);
-
- // Set the sensor to be used in the charge deposition simulation
- siSimulation.setSensor(sensor);
-
- // Perform the charge deposition simulation
- Map<ChargeCarrier, SiElectrodeDataCollection> electrodeDataMap = siSimulation.computeElectrodeData();
-
- for (ChargeCarrier carrier : ChargeCarrier.values()) {
-
- // If the sensor is capable of collecting the given charge carrier
- // then obtain the electrode data for the sensor
- if (sensor.hasElectrodesOnSide(carrier)) {
-
- SiElectrodeDataCollection electrodeDataCol = electrodeDataMap.get(carrier);
-
- // If there is no electrode data available create a new instance of electrode data
- if (electrodeDataCol == null) {
- electrodeDataCol = new SiElectrodeDataCollection();
- }
-
- // Loop over all sensor channels
- for (Integer channel : electrodeDataCol.keySet()) {
-
- // Get the electrode data for this channel
- SiElectrodeData electrodeData = electrodeDataCol.get(channel);
-
- // Get the charge in units of electrons
- double charge = electrodeData.getCharge();
-
- double resistorValue = 100; // Ohms
- double inputStageGain = 1.5;
- double amplitude = (charge / Apv25Constants.MIP) * resistorValue * inputStageGain * Math.pow(2, 14) / 2000;
-
- hitsOnSensor.put(channel, amplitude);
- }
- }
- }
- // Clear the sensors of all deposited charge
- siSimulation.clearReadout();
- }
+ List<StripHit> stripHits = doSiSimulation();
if (!noPileup) {
//if at the end of a readout cycle, step all the pipelines
@@ -136,19 +113,17 @@
}
readoutCycle++;
}
-
- for (SiSensor sensor : hitMap.keySet()) {
- Map<Integer, Double> hitsOnSensor = hitMap.get(sensor);
- for (Integer channel : hitsOnSensor.keySet()) {
- Double amplitude = hitsOnSensor.get(channel);
- APV25Pipeline[] pipelines = pipelineMap.get(sensor);
- if (pipelines[channel] == null) {
- pipelines[channel] = new APV25Pipeline();
- }
- for (int i = 0; i < 20; i++) {
- pipelines[channel].addToCell(i, amplitude * pulseAmplitude((i + 1) * Apv25Constants.SAMPLING_INTERVAL + readoutTime() - ClockSingleton.getTime(), HPSSVTCalibrationConstants.getTShaping(sensor, channel)));
- }
+ for (StripHit stripHit : stripHits) {
+ SiSensor sensor = stripHit.sensor;
+ int channel = stripHit.channel;
+ double amplitude = stripHit.amplitude;
+ APV25Pipeline[] pipelines = pipelineMap.get(sensor);
+ if (pipelines[channel] == null) {
+ pipelines[channel] = new APV25Pipeline();
+ }
+ for (int i = 0; i < 20; i++) {
+ pipelines[channel].addToCell(i, amplitude * pulseAmplitude((i + 1) * Apv25Constants.SAMPLING_INTERVAL + readoutTime() - ClockSingleton.getTime(), HPSSVTCalibrationConstants.getTShaping(sensor, channel)));
}
}
@@ -176,7 +151,7 @@
RawTrackerHit hit = new BaseRawTrackerHit(0, cell_id, samples, null, sensor);
// System.out.println("Making RTH");
- if (samplesAboveThreshold(hit)) {
+ if (readoutCuts(hit)) {
hits.add(hit);
}
}
@@ -190,24 +165,24 @@
} else {
// Create a list to hold the analog data
List<RawTrackerHit> hits = new ArrayList<RawTrackerHit>();
- for (SiSensor sensor : hitMap.keySet()) {
- Map<Integer, Double> hitsOnSensor = hitMap.get(sensor);
- for (Integer channel : hitsOnSensor.keySet()) {
- Double amplitude = hitsOnSensor.get(channel);
- short[] samples = new short[6];
-
- for (int i = 0; i < 6; i++) {
- double time = i * Apv25Constants.SAMPLING_INTERVAL - timeOffset;
- samples[i] = (short) Math.round(amplitude * pulseAmplitude(time, HPSSVTCalibrationConstants.getTShaping(sensor, channel)) + HPSSVTCalibrationConstants.getPedestal(sensor, channel));
- }
- long cell_id = SvtUtils.makeCellID(sensor, channel);
+ for (StripHit stripHit : stripHits) {
+ SiSensor sensor = stripHit.sensor;
+ int channel = stripHit.channel;
+ double amplitude = stripHit.amplitude;
+ short[] samples = new short[6];
+
+ for (int i = 0; i < 6; i++) {
+ double time = i * Apv25Constants.SAMPLING_INTERVAL - timeOffset;
+ samples[i] = (short) Math.round(amplitude * pulseAmplitude(time, HPSSVTCalibrationConstants.getTShaping(sensor, channel)) + HPSSVTCalibrationConstants.getPedestal(sensor, channel));
+ }
+
+ long cell_id = SvtUtils.makeCellID(sensor, channel);
- RawTrackerHit hit = new BaseRawTrackerHit(0, cell_id, samples, null, sensor);
+ RawTrackerHit hit = new BaseRawTrackerHit(0, cell_id, samples, null, sensor);
// System.out.println("Making RTH");
- if (samplesAboveThreshold(hit)) {
- hits.add(hit);
- }
+ if (readoutCuts(hit)) {
+ hits.add(hit);
}
}
@@ -217,6 +192,67 @@
}
}
+ private List<StripHit> doSiSimulation() {
+ List<StripHit> stripHits = new ArrayList<StripHit>();
+ for (SiSensor sensor : SvtUtils.getInstance().getSensors()) {
+
+ // Set the sensor to be used in the charge deposition simulation
+ siSimulation.setSensor(sensor);
+
+ // Perform the charge deposition simulation
+ Map<ChargeCarrier, SiElectrodeDataCollection> electrodeDataMap = siSimulation.computeElectrodeData();
+
+ for (ChargeCarrier carrier : ChargeCarrier.values()) {
+
+ // If the sensor is capable of collecting the given charge carrier
+ // then obtain the electrode data for the sensor
+ if (sensor.hasElectrodesOnSide(carrier)) {
+
+ SiElectrodeDataCollection electrodeDataCol = electrodeDataMap.get(carrier);
+
+ // If there is no electrode data available create a new instance of electrode data
+ if (electrodeDataCol == null) {
+ electrodeDataCol = new SiElectrodeDataCollection();
+ }
+
+ // Loop over all sensor channels
+ for (Integer channel : electrodeDataCol.keySet()) {
+
+ // Get the electrode data for this channel
+ SiElectrodeData electrodeData = electrodeDataCol.get(channel);
+
+ // Get the charge in units of electrons
+ double charge = electrodeData.getCharge();
+
+ double resistorValue = 100; // Ohms
+ double inputStageGain = 1.5;
+ double amplitude = (charge / Apv25Constants.MIP) * resistorValue * inputStageGain * Math.pow(2, 14) / 2000;
+
+ stripHits.add(new StripHit(sensor, channel, amplitude));
+ }
+ }
+ }
+ // Clear the sensors of all deposited charge
+ siSimulation.clearReadout();
+ }
+ return stripHits;
+ }
+
+ private boolean readoutCuts(RawTrackerHit hit) {
+ if (enableThresholdCut && !samplesAboveThreshold(hit)) {
+ return false;
+ }
+ if (enablePileupCut && !pileupCut(hit)) {
+ return false;
+ }
+ return true;
+ }
+
+ private boolean pileupCut(RawTrackerHit hit) {
+ short[] samples = hit.getADCValues();
+ return (samples[2] > samples[1] || samples[3] > samples[2]);
+ }
+
private boolean samplesAboveThreshold(RawTrackerHit hit) {
SiSensor sensor = (SiSensor) hit.getDetectorElement();
int channel = hit.getIdentifierFieldValue("strip");
@@ -227,14 +263,14 @@
short[] samples = hit.getADCValues();
for (int i = 0; i < samples.length; i++) {
// System.out.format("%d, %d\n", samples[i] - pedestal, noise * 3.0);
- if (samples[i] - pedestal > noise * 3.0) {
+ if (samples[i] - pedestal > noise * noiseThreshold) {
count++;
}
}
return count >= samplesAboveThreshold;
}
- public class APV25Pipeline extends RingBuffer {
+ private class APV25Pipeline extends RingBuffer {
private int _trigger_latency = (int) Math.floor(270 / Apv25Constants.SAMPLING_INTERVAL);
@@ -278,6 +314,19 @@
}
}
+ private class StripHit {
+
+ SiSensor sensor;
+ int channel;
+ double amplitude;
+
+ public StripHit(SiSensor sensor, int channel, double amplitude) {
+ this.sensor = sensor;
+ this.channel = channel;
+ this.amplitude = amplitude;
+ }
+ }
+
private double pulseAmplitude(double time, double tp) {
if (time <= 0.0) {
return 0.0;