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-30 08:11:05 UTC (rev 534)
+++ java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalRawConverterDriver.java 2014-04-30 15:22:21 UTC (rev 535)
@@ -9,6 +9,7 @@
import org.hps.conditions.ecal.EcalChannel.GeometryId;
import org.hps.conditions.ecal.EcalChannelConstants;
import org.hps.conditions.ecal.EcalConditions;
+import org.hps.conditions.ecal.EcalConditionsUtil;
import org.lcsim.conditions.ConditionsManager;
import org.lcsim.detector.identifier.IIdentifier;
import org.lcsim.detector.identifier.IIdentifierHelper;
@@ -17,6 +18,7 @@
import org.lcsim.detector.identifier.IIdentifierHelper;
import org.lcsim.event.CalorimeterHit;
import org.lcsim.event.EventHeader;
+import org.lcsim.event.GenericObject;
import org.lcsim.event.RawCalorimeterHit;
import org.lcsim.event.RawTrackerHit;
import org.lcsim.geometry.Detector;
@@ -30,9 +32,9 @@
*/
public class EcalRawConverterDriver extends Driver {
- EcalConditions ecalConditions = null;
- IIdentifierHelper helper = null;
- EcalChannelCollection channels = null;
+ static EcalConditions ecalConditions = null;
+ static IIdentifierHelper helper = null;
+ static EcalChannelCollection channels = null;
EcalRawConverter converter = null;
String rawCollectionName = "EcalReadoutHits";
String ecalReadoutName = "EcalHits";
@@ -43,6 +45,9 @@
boolean applyBadCrystalMap = true;
boolean dropBadFADC = false;
private boolean runBackwards = false;
+ private boolean useTimestamps = false;
+ private boolean useTruthTime = false;
+ private static boolean isBadChannelLoaded = true;
public EcalRawConverterDriver() {
converter = new EcalRawConverter();
@@ -102,18 +107,63 @@
.getCachedConditions(EcalConditions.class, TableConstants.ECAL_CONDITIONS).getCachedData();
// List of channels.
- channels = ecalConditions.getChannelMap();
+ channels = ecalConditions.getChannelCollection();
// ID helper.
helper = detector.getSubdetector("Ecal").getDetectorElement().getIdentifierHelper();
}
-
- public boolean isBadFADC(CalorimeterHit hit) {
+ /**
+ * Returns false if the channel is a good one, true if it is a bad one
+ * argument is CalorimeterHit
+ */
+ public static boolean isBadCrystal(CalorimeterHit hit) {
+
+ // Get the channel data.
+ EcalChannelConstants channelData = findChannel(hit.getCellID());
+
+ return isBadChannelLoaded ? channelData.isBadChannel() : false;
+ }
+
+ /**
+ * Returns false if the FADC is a good one, true if it is a bad one
+ * argument is CalorimeterHit
+ */
+ public boolean isBadFADC(CalorimeterHit hit) {
return (getCrate(hit.getCellID()) == 1 && getSlot(hit.getCellID()) == 3);
}
+
+ private static double getTimestamp(int system, EventHeader event) { //FIXME: copied from org.hps.readout.ecal.ReadoutTimestamp
+ if (event.hasCollection(GenericObject.class, "ReadoutTimestamps")) {
+ List<GenericObject> timestamps = event.get(GenericObject.class, "ReadoutTimestamps");
+ for (GenericObject timestamp : timestamps) {
+ if (timestamp.getIntVal(0) == system) {
+ return timestamp.getDoubleVal(0);
+ }
+ }
+ return 0;
+ } else {
+ return 0;
+ }
+ }
@Override
public void process(EventHeader event) {
+ final int SYSTEM_TRIGGER = 0;
+ final int SYSTEM_TRACKER = 1;
+ final int SYSTEM_ECAL = 2;
+
+ double timeOffset = 0.0;
+ if (useTimestamps) {
+ double t0ECal = getTimestamp(SYSTEM_ECAL, event);
+ double t0Trig = getTimestamp(SYSTEM_TRIGGER, event);
+ timeOffset += (t0ECal - t0Trig);
+ }
+ if (useTruthTime) {
+ double t0ECal = getTimestamp(SYSTEM_ECAL, event);
+ timeOffset += ((t0ECal + 250.0) % 500.0) - 250.0;
+ }
+
+
int flags = 0;
flags += 1 << LCIOConstants.RCHBIT_TIME; //store cell ID
@@ -149,13 +199,10 @@
if (debug) {
System.out.format("old hit energy %d\n", hit.getAmplitude());
}
- CalorimeterHit newHit = converter.HitDtoA(hit, integralWindow);
+ CalorimeterHit newHit = converter.HitDtoA(hit, integralWindow, timeOffset);
- // Get the channel data.
- EcalChannelConstants channelData = findChannel(newHit.getCellID());
-
if (newHit.getRawEnergy() > threshold) {
- if (applyBadCrystalMap && channelData.isBadChannel()) {
+ if (applyBadCrystalMap && isBadCrystal(newHit)) {
continue;
}
if (dropBadFADC && isBadFADC(newHit)) {
@@ -197,60 +244,37 @@
* @param cellID (long)
* @return channel constants (EcalChannelConstants)
*/
- private EcalChannelConstants findChannel(long cellID) {
+ private static 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();
- geometryId.x = x;
- geometryId.y = y;
-
- // Find the ECAL channel.
-// return channels.findChannel(geometryId);
+ GeometryId geometryId = new GeometryId(helper, new int[] { system, x, y });
// Get the channel data.
- return ecalConditions.getChannelConstants(channels.findChannel(geometryId));
+ return ecalConditions.getChannelConstants(channels.findChannel(geometryId));
}
// Return crate number from cellID
- private int getCrate(long cellID) {
- // Make an ID object from hit ID.
- IIdentifier id = new Identifier(cellID);
+ public int getCrate(long 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;
-
+ EcalConditionsUtil util = new EcalConditionsUtil();
+
// Find the ECAL channel and return the crate number.
- return channels.findChannel(geometryId).getCrate();
+ return util.getCrate(helper, cellID);
}
// Return slot number from cellID.
private int getSlot(long cellID) {
- // Make an ID object from 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 and return the slot number.
- return channels.findChannel(geometryId).getSlot();
+ EcalConditionsUtil util = new EcalConditionsUtil();
+
+ // Find the ECAL channel and return the crate number.
+ return util.getSlot(helper, cellID);
}
}