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/EcalRawConverterDriver.java 2014-04-24 13:04:56 UTC (rev 510)
+++ java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalRawConverterDriver.java 2014-04-24 13:10:04 UTC (rev 511)
@@ -3,7 +3,18 @@
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.conditions.ecal.EcalChannel.EcalChannelCollection;
+import org.lcsim.detector.identifier.IIdentifierHelper;
import org.lcsim.event.CalorimeterHit;
import org.lcsim.event.EventHeader;
import org.lcsim.event.RawCalorimeterHit;
@@ -19,6 +30,9 @@
*/
public class EcalRawConverterDriver extends Driver {
+ EcalConditions ecalConditions = null;
+ IIdentifierHelper helper = null;
+ EcalChannelCollection channels = null;
EcalRawConverter converter = null;
String rawCollectionName = "EcalReadoutHits";
String ecalReadoutName = "EcalHits";
@@ -83,17 +97,25 @@
@Override
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 static boolean isBadCrystal(CalorimeterHit hit) {
- return EcalConditions.badChannelsLoaded() ? EcalConditions.isBadChannel(hit.getCellID()) : false;
+ public boolean isBadFADC(CalorimeterHit hit) {
+
+ // Get the channel data.
+ EcalChannelConstants channelData = findChannel(hit.getCellID());
+
+ return (channelData.getCrate() == 1 && channelData.getSlot() == 3);
}
- public static boolean isBadFADC(CalorimeterHit hit) {
- long daqID = EcalConditions.physicalToDaqID(hit.getCellID());
- return (EcalConditions.getCrate(daqID) == 1 && EcalConditions.getSlot(daqID) == 3);
- }
-
@Override
public void process(EventHeader event) {
int flags = 0;
@@ -108,7 +130,11 @@
for (RawTrackerHit hit : hits) {
CalorimeterHit newHit = converter.HitDtoA(hit);
- if (applyBadCrystalMap && isBadCrystal(newHit)) {
+
+ // Get the channel data.
+ EcalChannelConstants channelData = findChannel(newHit.getCellID());
+
+ if (applyBadCrystalMap && channelData.isBadChannel()) {
continue;
}
if (dropBadFADC && isBadFADC(newHit)) {
@@ -128,8 +154,12 @@
System.out.format("old hit energy %d\n", hit.getAmplitude());
}
CalorimeterHit newHit = converter.HitDtoA(hit, integralWindow);
+
+ // Get the channel data.
+ EcalChannelConstants channelData = findChannel(newHit.getCellID());
+
if (newHit.getRawEnergy() > threshold) {
- if (applyBadCrystalMap && isBadCrystal(newHit)) {
+ if (applyBadCrystalMap && channelData.isBadChannel()) {
continue;
}
if (dropBadFADC && isBadFADC(newHit)) {
@@ -164,4 +194,30 @@
}
}
}
+
+
+ /**
+ * 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));
+ }
}