java/branches/ecal-readout-sim_HPSJAVA-93/src/main/java/org/hps/readout/ecal
--- java/branches/ecal-readout-sim_HPSJAVA-93/src/main/java/org/hps/readout/ecal/FADCEcalReadoutDriver.java 2014-06-19 15:09:33 UTC (rev 726)
+++ java/branches/ecal-readout-sim_HPSJAVA-93/src/main/java/org/hps/readout/ecal/FADCEcalReadoutDriver.java 2014-06-19 20:56:41 UTC (rev 727)
@@ -15,17 +15,9 @@
import java.util.PriorityQueue;
import java.util.Set;
-import org.hps.conditions.ConditionsDriver;
-import org.hps.conditions.TableConstants;
-import org.hps.conditions.ecal.EcalChannel.EcalChannelCollection;
-import org.hps.conditions.ecal.EcalChannel.GeometryId;
-import org.hps.conditions.ecal.EcalChannelConstants;
-import org.hps.conditions.ecal.EcalConditions;
-import org.lcsim.conditions.ConditionsManager;
-import org.lcsim.detector.identifier.IIdentifier;
-import org.lcsim.detector.identifier.IIdentifierHelper;
-import org.lcsim.detector.identifier.Identifier;
+import org.hps.conditions.deprecated.EcalConditions;
import org.hps.recon.ecal.ECalUtils;
+import org.hps.recon.ecal.HPSCalorimeterHit;
import org.hps.recon.ecal.HPSRawCalorimeterHit;
import org.lcsim.event.CalorimeterHit;
import org.lcsim.event.EventHeader;
@@ -54,9 +46,6 @@
private static final int ECAL_PULSE_INTEGRAL_MODE = 3;
String ecalName = "Ecal";
Subdetector ecal;
- EcalConditions ecalConditions = null;
- IIdentifierHelper helper = null;
- EcalChannelCollection channels = null;
//buffer for preamp signals (units of volts, no pedestal)
private Map<Long, RingBuffer> signalMap = null;
//ADC pipeline for readout (units of ADC counts)
@@ -241,12 +230,9 @@
FADCPipeline pipeline = pipelineMap.get(cellID);
pipeline.step();
-
- // Get the channel data.
- EcalChannelConstants channelData = findChannel(cellID);
double currentValue = signalBuffer.currentValue() * ((Math.pow(2, nBit) - 1) / maxVolt); //12-bit ADC with maxVolt V range
- int pedestal = (int) Math.round(channelData.getCalibration().getPedestal());
+ int pedestal = (int) Math.round(EcalConditions.physicalToPedestal(cellID));
int digitizedValue = Math.min((int) Math.round(pedestal + currentValue), (int) Math.pow(2, nBit)); //ADC can't return a value larger than 4095; 4096 (overflow) is returned for any input >2V
pipeline.writeValue(digitizedValue);
int pedestalSubtractedValue = digitizedValue - pedestal;
@@ -300,7 +286,7 @@
}
while (outputQueue.peek() != null && outputQueue.peek().getTimeStamp() / 64 <= readoutCounter - delay0) {
if (outputQueue.peek().getTimeStamp() / 64 < readoutCounter - delay0) {
- System.out.println("Stale hit in output queue");
+ System.out.println(this.getName() + ": Stale hit in output queue");
outputQueue.poll();
} else {
buffer.add(outputQueue.poll());
@@ -389,10 +375,6 @@
int pointerOffset = 0;
int numSamplesToRead = 0;
int thresholdCrossing = 0;
-
- // Get the channel data.
- EcalChannelConstants channelData = findChannel(cellID);
-
for (int i = 0; i < readoutWindow; i++) {
if (numSamplesToRead != 0) {
adcValues[adcValues.length - numSamplesToRead] = window[i - pointerOffset];
@@ -400,7 +382,7 @@
if (numSamplesToRead == 0) {
hits.add(new BaseRawTrackerHit(cellID, thresholdCrossing, adcValues));
}
- } else if ((i == 0 || window[i - 1] <= channelData.getCalibration().getPedestal() + readoutThreshold) && window[i] > channelData.getCalibration().getPedestal() + readoutThreshold) {
+ } else if ((i == 0 || window[i - 1] <= EcalConditions.physicalToPedestal(cellID) + readoutThreshold) && window[i] > EcalConditions.physicalToPedestal(cellID) + readoutThreshold) {
thresholdCrossing = i;
pointerOffset = Math.min(numSamplesBefore, i);
numSamplesToRead = pointerOffset + Math.min(numSamplesAfter, readoutWindow - i - pointerOffset - 1);
@@ -420,10 +402,6 @@
int pointerOffset = 0;
int numSamplesToRead = 0;
int thresholdCrossing = 0;
-
- // Get the channel data.
- EcalChannelConstants channelData = findChannel(cellID);
-
if (window != null) {
for (int i = 0; i < readoutWindow; i++) {
if (numSamplesToRead != 0) {
@@ -435,7 +413,7 @@
if (numSamplesToRead == 0) {
hits.add(new BaseRawCalorimeterHit(cellID, adcSum, 64 * thresholdCrossing));
}
- } else if ((i == 0 || window[i - 1] <= channelData.getCalibration().getPedestal() + readoutThreshold) && window[i] > channelData.getCalibration().getPedestal() + readoutThreshold) {
+ } else if ((i == 0 || window[i - 1] <= EcalConditions.physicalToPedestal(cellID) + readoutThreshold) && window[i] > EcalConditions.physicalToPedestal(cellID) + readoutThreshold) {
thresholdCrossing = i;
pointerOffset = Math.min(numSamplesBefore, i);
numSamplesToRead = pointerOffset + Math.min(numSamplesAfter, readoutWindow - i - pointerOffset - 1);
@@ -453,15 +431,13 @@
for (CalorimeterHit hit : hits) {
RingBuffer eDepBuffer = signalMap.get(hit.getCellID());
double energyAmplitude = hit.getRawEnergy();
- // Get the channel data.
- EcalChannelConstants channelData = findChannel(hit.getCellID());
if (addNoise) {
//add preamp noise and photoelectron Poisson noise in quadrature
double noise;
if (use2014Gain) {
- noise = Math.sqrt(Math.pow(channelData.getCalibration().getNoise() * channelData.getGain().getGain() * ECalUtils.gainFactor * ECalUtils.ecalReadoutPeriod, 2) + hit.getRawEnergy() / (ECalUtils.lightYield * ECalUtils.quantumEff * ECalUtils.surfRatio));
+ noise = Math.sqrt(Math.pow(EcalConditions.physicalToNoise(hit.getCellID()) * EcalConditions.physicalToGain(hit.getCellID()) * ECalUtils.gainFactor * ECalUtils.ecalReadoutPeriod, 2) + hit.getRawEnergy() / (ECalUtils.lightYield * ECalUtils.quantumEff * ECalUtils.surfRatio));
} else {
- noise = Math.sqrt(Math.pow(channelData.getCalibration().getNoise() * channelData.getGain().getGain() * ECalUtils.MeV, 2) + hit.getRawEnergy() * ECalUtils.MeV / pePerMeV);
+ noise = Math.sqrt(Math.pow(EcalConditions.physicalToNoise(hit.getCellID()) * EcalConditions.physicalToGain(hit.getCellID()) * ECalUtils.MeV, 2) + hit.getRawEnergy() * ECalUtils.MeV / pePerMeV);
}
energyAmplitude += RandomGaussian.getGaussian(0, noise);
}
@@ -484,17 +460,6 @@
public void detectorChanged(Detector detector) {
// Get the Subdetector.
ecal = detector.getSubdetector(ecalName);
-
- // ECAL combined conditions object.
- ecalConditions = ConditionsManager.defaultInstance()
- .getCachedConditions(EcalConditions.class, TableConstants.ECAL_CONDITIONS).getCachedData();
-
- // List of channels.
- channels = ecalConditions.getChannelCollection();
-
- // ID helper.
- helper = detector.getSubdetector("Ecal").getDetectorElement().getIdentifierHelper();
-
resetFADCBuffers();
}
@@ -506,24 +471,20 @@
pipelineMap = new HashMap<Long, FADCPipeline>();
Set<Long> cells = ((HPSEcal3) ecal).getNeighborMap().keySet();
for (Long cellID : cells) {
- EcalChannelConstants channelData = findChannel(cellID);
signalMap.put(cellID, new RingBuffer(bufferLength));
- pipelineMap.put(cellID, new FADCPipeline(pipelineLength, (int) Math.round(channelData.getCalibration().getPedestal())));
+ pipelineMap.put(cellID, new FADCPipeline(pipelineLength, (int) Math.round(EcalConditions.physicalToPedestal(cellID))));
}
return true;
}
private double pulseAmplitude(double time, long cellID) {
-
- EcalChannelConstants channelData = findChannel(cellID);
-
if (use2014Gain) {
//if fixedGain is set, multiply the default gain by this factor
double corrGain;
if (fixedGain > 0) {
corrGain = fixedGain;
} else {
- corrGain = 1.0 / channelData.getGain().getGain();
+ corrGain = 1.0 / EcalConditions.physicalToGain(cellID);
}
return corrGain * readoutGain * pulseAmplitude(time, pulseShape, tp);
@@ -533,7 +494,7 @@
if (fixedGain > 0) {
gain = readoutPeriod / (fixedGain * ECalUtils.MeV * ((Math.pow(2, nBit) - 1) / maxVolt));
} else {
- gain = readoutPeriod / (channelData.getGain().getGain() * ECalUtils.MeV * ((Math.pow(2, nBit) - 1) / maxVolt));
+ gain = readoutPeriod / (EcalConditions.physicalToGain(cellID) * ECalUtils.MeV * ((Math.pow(2, nBit) - 1) / maxVolt));
}
return gain * pulseAmplitude(time, pulseShape, tp);
@@ -624,26 +585,4 @@
return array[((ptr - pos) % size + size) % size];
}
}
-
- // Convert physical ID to gain value.
- private EcalChannelConstants findChannel(long cellID) {
- // Make an ID object from raw hit ID.
- IIdentifier id = new Identifier(cellID);
-
- // Get physical field values.
- int system = helper.getValue(id, "system");
- int x = helper.getValue(id, "ix");
- int y = helper.getValue(id, "iy");
-
- // Create an ID to search for in channel collection.
- GeometryId geometryId = new GeometryId(helper, new int[] { system, x, y });
-
- // Find the ECAL channel.
-// return channels.findChannel(geometryId);
-
- // Get the channel data.
- return ecalConditions.getChannelConstants(channels.findChannel(geometryId));
- }
-
}
-
java/branches/ecal-readout-sim_HPSJAVA-93/src/main/java/org/hps/readout/ecal
--- java/branches/ecal-readout-sim_HPSJAVA-93/src/main/java/org/hps/readout/ecal/FADCTriggerDriver.java 2014-06-19 15:09:33 UTC (rev 726)
+++ java/branches/ecal-readout-sim_HPSJAVA-93/src/main/java/org/hps/readout/ecal/FADCTriggerDriver.java 2014-06-19 20:56:41 UTC (rev 727)
@@ -2,6 +2,7 @@
import hep.aida.IHistogram1D;
import hep.aida.IHistogram2D;
+import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
@@ -55,6 +56,7 @@
IHistogram2D clusterHitCount2DAll, clusterEnergy2DAll, clusterSumDiff2DAll, energyDistance2DAll, clusterAngles2DAll, clusterCoplanarity2DAll;
IHistogram2D clusterHitCount2D, clusterEnergy2D, clusterSumDiff2D, energyDistance2D, clusterAngles2D, clusterCoplanarity2D;
IHistogram1D triggerBits1D, triggerTimes1D;
+ IHistogram2D clusterSeeds, trigClusterSeeds;
int truthPeriod = 250;
private boolean useQuadrants = false;
protected String clusterCollectionName = "EcalClusters";
@@ -62,6 +64,7 @@
// Each list corresponds to one readout cycle.
private Queue<List<HPSEcalCluster>> topClusterQueue = null;
private Queue<List<HPSEcalCluster>> botClusterQueue = null;
+ PrintWriter pairWriter;
private enum Flag {
@@ -118,7 +121,7 @@
} else if (detector.getName().contains("6pt6")) {
return 6.6;
} else {
- return -1.0;
+ return 2.2;
}
}
@@ -233,6 +236,13 @@
this.energyDistanceThreshold = energyDistanceThreshold;
}
+ public void setPairFile(String pairFile) {
+ try {
+ pairWriter = new PrintWriter(pairFile);
+ } catch (IOException e) {
+ }
+ }
+
@Override
public void detectorChanged(Detector detector) {
if (beamEnergy < 0) {
@@ -258,6 +268,9 @@
triggerBits1D = aida.histogram1D(detector.getDetectorName() + " : " + clusterCollectionName + " : trigger bits", 33, -1.5, 31.5);
triggerTimes1D = aida.histogram1D(detector.getDetectorName() + " : " + clusterCollectionName + " : trigger times", truthPeriod, -0.5, truthPeriod - 0.5);
+
+ clusterSeeds = aida.histogram2D(detector.getDetectorName() + " : " + clusterCollectionName + " : Cluster seeds", 46, -23, 23, 11, -5.5, 5.5);
+ trigClusterSeeds = aida.histogram2D(detector.getDetectorName() + " : " + clusterCollectionName + " : Cluster seeds, with trigger", 46, -23, 23, 11, -5.5, 5.5);
}
@Override
@@ -290,6 +303,25 @@
if (event.hasCollection(HPSEcalCluster.class, clusterCollectionName)) {
// this needs to run every readout cycle whether or not trigger is live
updateClusterQueues(event.get(HPSEcalCluster.class, clusterCollectionName));
+
+ if (pairWriter != null) {
+ List<HPSEcalCluster[]> clusterPairs = getClusterPairsTopBot();
+ for (HPSEcalCluster[] pair : clusterPairs) {
+ pairWriter.format("%d\t", ClockSingleton.getClock());
+ for (HPSEcalCluster cluster : pair) {
+ pairWriter.format("%f\t", cluster.getSeedHit().getTime());
+ pairWriter.format("%f\t", cluster.getSeedHit().getRawEnergy());
+ pairWriter.format("%d\t", cluster.getSeedHit().getIdentifierFieldValue("ix"));
+ pairWriter.format("%d\t", cluster.getSeedHit().getIdentifierFieldValue("iy"));
+ pairWriter.format("%d\t", cluster.getSize());
+ pairWriter.format("%f\t", cluster.getEnergy());
+ pairWriter.format("%f\t", getClusterAngle(cluster));
+ pairWriter.format("%f\t", getClusterDistance(cluster));
+ }
+ pairWriter.println();
+ }
+ pairWriter.flush();
+ }
}
super.process(event);
}
@@ -434,6 +466,12 @@
outputStream.println("Passed all cuts");
}
trigger = true;
+
+ for (HPSEcalCluster cluster : clusterPair) {
+ int ix = cluster.getSeedHit().getIdentifierFieldValue("ix");
+ int iy = cluster.getSeedHit().getIdentifierFieldValue("iy");
+ trigClusterSeeds.fill(ix - 0.5 * Math.signum(ix), iy);
+ }
}
}
if (trigger) {
@@ -449,6 +487,9 @@
printCounts(outputStream);
}
printCounts(new PrintWriter(System.out));
+ if (pairWriter != null) {
+ pairWriter.close();
+ }
super.endOfData();
}
@@ -477,6 +518,10 @@
} else {
botClusterList.add(ecalCluster);
}
+
+ int ix = ecalCluster.getSeedHit().getIdentifierFieldValue("ix");
+ int iy = ecalCluster.getSeedHit().getIdentifierFieldValue("iy");
+ clusterSeeds.fill(ix - 0.5 * Math.signum(ix), iy);
}
topClusterQueue.add(topClusterList);
java/branches/ecal-readout-sim_HPSJAVA-93/src/main/java/org/hps/readout/ecal
--- java/branches/ecal-readout-sim_HPSJAVA-93/src/main/java/org/hps/readout/ecal/SimpleEcalReadoutDriver.java 2014-06-19 15:09:33 UTC (rev 726)
+++ java/branches/ecal-readout-sim_HPSJAVA-93/src/main/java/org/hps/readout/ecal/SimpleEcalReadoutDriver.java 2014-06-19 20:56:41 UTC (rev 727)
@@ -4,8 +4,14 @@
import java.util.List;
import java.util.Map;
+import org.hps.conditions.TableConstants;
+import org.hps.conditions.ecal.EcalConditions;
+import org.hps.conditions.ecal.EcalChannel.EcalChannelCollection;
import org.hps.recon.ecal.HPSCalorimeterHit;
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.detector.identifier.IIdentifierHelper;
import org.lcsim.event.CalorimeterHit;
+import org.lcsim.geometry.Detector;
/**
* Performs readout of ECal hits.
@@ -17,7 +23,32 @@
public class SimpleEcalReadoutDriver extends EcalReadoutDriver<HPSCalorimeterHit> {
//buffer for deposited energy
Map<Long, Double> eDepMap = null;
-
+
+ HPSCalorimeterHit h1 = new HPSCalorimeterHit();
+
+ Detector detector = null;
+ static EcalConditions ecalConditions = null;
+ static IIdentifierHelper helper = null;
+ static EcalChannelCollection channels = null;
+
+ @Override
+ public void detectorChanged(Detector detector) {
+
+ h1.setDetector(detector);
+
+ // ECAL combined conditions object.
+ ecalConditions = ConditionsManager.defaultInstance()
+ .getCachedConditions(EcalConditions.class, TableConstants.ECAL_CONDITIONS).getCachedData();
+
+ // List of channels.
+ channels = ecalConditions.getChannelCollection();
+
+ // ID helper.
+ helper = detector.getSubdetector("Ecal").getDetectorElement().getIdentifierHelper();
+
+ System.out.println("You are now using the database conditions for SimpleEcalReadoutDriver.");
+ }
+
public SimpleEcalReadoutDriver() {
hitClass = HPSCalorimeterHit.class;
}
@@ -32,7 +63,8 @@
// if (iy == 1 && ix*side >= -10 && ix*side <= -2)
// continue;
if (eDepMap.get(cellID) > threshold)
- hits.add(new HPSCalorimeterHit(eDepMap.get(cellID), readoutTime(), cellID, hitType));
+ h1.setParameters(eDepMap.get(cellID), readoutTime(), cellID, hitType);
+ hits.add(h1);
}
//reset hit integration
eDepMap = new HashMap<Long, Double>();
java/branches/ecal-readout-sim_HPSJAVA-93/src/main/java/org/hps/readout/ecal
--- java/branches/ecal-readout-sim_HPSJAVA-93/src/main/java/org/hps/readout/ecal/TimeEvolutionEcalReadoutDriver.java 2014-06-19 15:09:33 UTC (rev 726)
+++ java/branches/ecal-readout-sim_HPSJAVA-93/src/main/java/org/hps/readout/ecal/TimeEvolutionEcalReadoutDriver.java 2014-06-19 20:56:41 UTC (rev 727)
@@ -4,8 +4,14 @@
import java.util.List;
import java.util.Map;
+import org.hps.conditions.TableConstants;
+import org.hps.conditions.ecal.EcalConditions;
+import org.hps.conditions.ecal.EcalChannel.EcalChannelCollection;
import org.hps.recon.ecal.HPSCalorimeterHit;
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.detector.identifier.IIdentifierHelper;
import org.lcsim.event.CalorimeterHit;
+import org.lcsim.geometry.Detector;
/**
* Performs readout of ECal hits.
@@ -15,13 +21,38 @@
* @version $Id: TimeEvolutionEcalReadoutDriver.java,v 1.1 2013/02/25 22:39:26 meeg Exp $
*/
public class TimeEvolutionEcalReadoutDriver extends EcalReadoutDriver<HPSCalorimeterHit> {
-
+
//buffer for deposited energy
Map<Long, RingBuffer> eDepMap = null;
//length of ring buffer (in readout cycles)
int bufferLength = 20;
//shaper time constant in ns; negative values generate square pulses of the given width
double t0 = 18.0;
+
+ HPSCalorimeterHit h1 = new HPSCalorimeterHit();
+
+ Detector detector = null;
+ static EcalConditions ecalConditions = null;
+ static IIdentifierHelper helper = null;
+ static EcalChannelCollection channels = null;
+
+ @Override
+ public void detectorChanged(Detector detector) {
+
+ h1.setDetector(detector);
+
+ // ECAL combined conditions object.
+ ecalConditions = ConditionsManager.defaultInstance()
+ .getCachedConditions(EcalConditions.class, TableConstants.ECAL_CONDITIONS).getCachedData();
+
+ // List of channels.
+ channels = ecalConditions.getChannelCollection();
+
+ // ID helper.
+ helper = detector.getSubdetector("Ecal").getDetectorElement().getIdentifierHelper();
+
+ System.out.println("You are now using the database conditions for TimeEvolutionEcalReadoutDriver.");
+ }
public TimeEvolutionEcalReadoutDriver() {
hitClass = HPSCalorimeterHit.class;
@@ -45,7 +76,8 @@
// int iy = dec.getValue("iy");
// if (iy == 1 && ix == -2)
// System.out.printf("Time %f, output signal %f\n", ClockSingleton.getTime(), eDepBuffer.currentValue());
- hits.add(new HPSCalorimeterHit(eDepBuffer.currentValue(), readoutTime(), cellID, hitType));
+ h1.setParameters(eDepBuffer.currentValue(), readoutTime(), cellID, hitType);
+ hits.add(h1);
}
eDepBuffer.step();
}