java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal
--- java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalEdepToTriggerConverterDriver.java 2014-04-24 01:33:39 UTC (rev 508)
+++ java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalEdepToTriggerConverterDriver.java 2014-04-24 12:08:22 UTC (rev 509)
@@ -3,7 +3,16 @@
import java.util.ArrayList;
import java.util.List;
-import org.hps.conditions.deprecated.EcalConditions;
+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.util.RandomGaussian;
import org.lcsim.event.CalorimeterHit;
import org.lcsim.event.EventHeader;
@@ -17,6 +26,9 @@
*/
public class EcalEdepToTriggerConverterDriver extends Driver {
+ EcalConditions ecalConditions = null;
+ IIdentifierHelper helper = null;
+ EcalChannelCollection channels = null;
private String ecalReadoutName = "EcalHits";
private String inputCollection = "EcalHits";
private String readoutCollection = "EcalCalHits";
@@ -76,13 +88,18 @@
}
@Override
- public void detectorChanged(Detector detector) {
+ public void detectorChanged(Detector detector) {
+ // ECAL combined conditions object.
+ ecalConditions = ConditionsManager.defaultInstance()
+ .getCachedConditions(EcalConditions.class, TableConstants.ECAL_CONDITIONS).getCachedData();
+
+ // List of channels.
+ channels = ecalConditions.getChannelMap();
+
+ // ID helper.
+ helper = detector.getSubdetector("Ecal").getDetectorElement().getIdentifierHelper();
}
- public boolean isBadCrystal(CalorimeterHit hit) {
- return EcalConditions.badChannelsLoaded() ? EcalConditions.isBadChannel(hit.getCellID()) : false;
- }
-
@Override
public void process(EventHeader event) {
ArrayList<CalorimeterHit> triggerHits = new ArrayList<CalorimeterHit>();
@@ -92,7 +109,11 @@
List<CalorimeterHit> hits = event.get(CalorimeterHit.class, inputCollection);
for (CalorimeterHit hit : hits) {
- if (applyBadCrystalMap && isBadCrystal(hit)) {
+
+ // Get the channel data.
+ EcalChannelConstants channelData = findChannel(hit.getCellID());
+
+ if (applyBadCrystalMap && channelData.isBadChannel()) {
continue;
}
double amplitude = hitAmplitude(hit);
@@ -151,8 +172,11 @@
return null;
}
+ // Get the channel data.
+ EcalChannelConstants channelData = findChannel(hit.getCellID());
+
// double integral = hit.getRawEnergy()/ECalUtils.GeV * gainScale;
- double gain = _gain > 0 ? _gain : EcalConditions.physicalToGain(hit.getCellID());
+ double gain = _gain > 0 ? _gain : channelData.getGain().getGain();
double integral = amplitude * gain * pulseIntegral * gainScale * ECalUtils.MeV / ECalUtils.GeV;
// double thresholdCrossingTime = 0 - hit.getTime();
@@ -182,13 +206,17 @@
private double hitAmplitude(CalorimeterHit hit) {
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 = Math.sqrt(Math.pow(EcalConditions.physicalToNoise(hit.getCellID()) * EcalConditions.physicalToGain(hit.getCellID()) * ECalUtils.MeV, 2) + hit.getRawEnergy() * ECalUtils.MeV / pePerMeV);
+ double noise = Math.sqrt(Math.pow(channelData.getCalibration().getNoise() * channelData.getGain().getGain() * ECalUtils.MeV, 2) + hit.getRawEnergy() * ECalUtils.MeV / pePerMeV);
energyAmplitude += RandomGaussian.getGaussian(0, noise);
}
- double gain = _gain > 0 ? _gain : EcalConditions.physicalToGain(hit.getCellID());
+ double gain = _gain > 0 ? _gain : channelData.getGain().getGain();
// System.out.format("amplitude: %f %f %f %f\n", hit.getRawEnergy(), energyAmplitude, gain, (energyAmplitude / ECalUtils.MeV) / (gain * pulseIntegral));
return (energyAmplitude / ECalUtils.MeV) / (gain * pulseIntegral);
}
@@ -207,4 +235,31 @@
}
}
}
+
+ /**
+ * Convert physical ID to gain value.
+ * @param cellID (long)
+ * @return channel constants (EcalChannelConstants)
+ */
+ private EcalChannelConstants findChannel(long cellID) {
+ // Make an ID object from raw hit ID.
+ IIdentifier id = new Identifier(cellID);
+
+ // Get physical field values.
+ 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();
+ geometryId.x = x;
+ geometryId.y = y;
+
+ // Find the ECAL channel.
+// return channels.findChannel(geometryId);
+
+ // Get the channel data.
+ return ecalConditions.getChannelConstants(channels.findChannel(geometryId));
+ }
+
}
+