Author: [log in to unmask]
Date: Thu Dec 4 17:25:29 2014
New Revision: 1650
Log:
Updates from work on ECAL cosmics analysis.
Added:
java/trunk/users/src/main/java/org/hps/users/jeremym/EcalADCProfilePlotsDriver.java
java/trunk/users/src/main/java/org/hps/users/jeremym/EcalCosmicClusterPlotsDriver.java
java/trunk/users/src/main/java/org/hps/users/jeremym/EcalCosmicHitSelectionDriver.java
Removed:
java/trunk/users/src/main/java/org/hps/users/jeremym/EcalADCSignalPlotsDriver.java
Modified:
java/trunk/users/src/main/java/org/hps/users/jeremym/EcalCosmicClusterDriver.java
Added: java/trunk/users/src/main/java/org/hps/users/jeremym/EcalADCProfilePlotsDriver.java
=============================================================================
--- java/trunk/users/src/main/java/org/hps/users/jeremym/EcalADCProfilePlotsDriver.java (added)
+++ java/trunk/users/src/main/java/org/hps/users/jeremym/EcalADCProfilePlotsDriver.java Thu Dec 4 17:25:29 2014
@@ -0,0 +1,62 @@
+package org.hps.users.jeremym;
+
+import hep.aida.IAnalysisFactory;
+import hep.aida.IProfile1D;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.hps.conditions.database.TableConstants;
+import org.hps.conditions.ecal.EcalChannel;
+import org.hps.conditions.ecal.EcalChannel.EcalChannelCollection;
+import org.hps.conditions.ecal.EcalConditions;
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.RawTrackerHit;
+import org.lcsim.geometry.Detector;
+import org.lcsim.util.Driver;
+import org.lcsim.util.aida.AIDA;
+
+/**
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+public class EcalADCProfilePlotsDriver extends Driver {
+
+ EcalConditions conditions = null;
+ EcalChannelCollection channels = null;
+ Map<EcalChannel, IProfile1D> adcProfiles = new HashMap<EcalChannel, IProfile1D>();
+ AIDA aida = AIDA.defaultInstance();
+ IAnalysisFactory analysisFactory = aida.analysisFactory();
+ String inputHitsCollectionName = "EcalReadoutHits";
+
+ public void setInputHitsCollectionName(String inputHitsCollectionName) {
+ this.inputHitsCollectionName = inputHitsCollectionName;
+ }
+
+ public void detectorChanged(Detector detector) {
+ conditions = ConditionsManager.defaultInstance().getCachedConditions(EcalConditions.class, TableConstants.ECAL_CONDITIONS).getCachedData();
+ channels = conditions.getChannelCollection();
+ for (EcalChannel channel : conditions.getChannelCollection()) {
+ adcProfiles.put(channel, aida.profile1D(inputHitsCollectionName + "/ : ADC Values : " + String.format("%03d", channel.getChannelId()), 100, 0, 100));
+ }
+ }
+
+ public void process(EventHeader event) {
+ if (event.hasCollection(RawTrackerHit.class, inputHitsCollectionName)) {
+ List<RawTrackerHit> hits = event.get(RawTrackerHit.class, inputHitsCollectionName);
+ for (RawTrackerHit hit : hits) {
+ EcalChannel channel = channels.findGeometric(hit.getCellID());
+ if (channel != null) {
+ IProfile1D profile = adcProfiles.get(channel);
+ for (int adcIndex = 0; adcIndex < hit.getADCValues().length; adcIndex++) {
+ // Fill the Profile1D with ADC value.
+ profile.fill(adcIndex, hit.getADCValues()[adcIndex]);
+ }
+ } else {
+ System.err.println("EcalChannel not found for cell ID 0x" + String.format("%08d", Long.toHexString(hit.getCellID())));
+ }
+ }
+ }
+ }
+}
Modified: java/trunk/users/src/main/java/org/hps/users/jeremym/EcalCosmicClusterDriver.java
=============================================================================
--- java/trunk/users/src/main/java/org/hps/users/jeremym/EcalCosmicClusterDriver.java (original)
+++ java/trunk/users/src/main/java/org/hps/users/jeremym/EcalCosmicClusterDriver.java Thu Dec 4 17:25:29 2014
@@ -26,9 +26,10 @@
* @author Jeremy McCormick <[log in to unmask]>
* @author Tim "THammer" Nelson <[log in to unmask]>
*/
+// TODO: Add output collection of RawTrackerHits.
public class EcalCosmicClusterDriver extends Driver {
- String inputHitCollectionName = "SelectedEcalCalHits";
+ String inputHitCollectionName = "EcalCosmicCalHits";
String outputClusterCollectionName = "EcalCosmicClusters";
String ecalName = "Ecal";
HPSEcal3 ecal = null;
@@ -91,7 +92,7 @@
if (clusterCollection.size() > 0) {
int flags = 1 << LCIOConstants.CLBIT_HITS;
event.put(outputClusterCollectionName, clusterCollection, Cluster.class, flags);
- //System.out.println("added cluster to " + outputClusterCollectionName + " with size " + clusterCollection.size());
+ //System.out.println("added " + clusterCollection.size() + " clusters to " + outputClusterCollectionName);
} else {
throw new NextEventException();
}
Added: java/trunk/users/src/main/java/org/hps/users/jeremym/EcalCosmicClusterPlotsDriver.java
=============================================================================
--- java/trunk/users/src/main/java/org/hps/users/jeremym/EcalCosmicClusterPlotsDriver.java (added)
+++ java/trunk/users/src/main/java/org/hps/users/jeremym/EcalCosmicClusterPlotsDriver.java Thu Dec 4 17:25:29 2014
@@ -0,0 +1,87 @@
+package org.hps.users.jeremym;
+
+import hep.aida.IAnalysisFactory;
+import hep.aida.IProfile1D;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.hps.conditions.database.TableConstants;
+import org.hps.conditions.ecal.EcalChannel;
+import org.hps.conditions.ecal.EcalChannel.EcalChannelCollection;
+import org.hps.conditions.ecal.EcalConditions;
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.event.Cluster;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.RawTrackerHit;
+import org.lcsim.geometry.Detector;
+import org.lcsim.util.Driver;
+import org.lcsim.util.aida.AIDA;
+
+/**
+ * Create ADC value plots from the cosmic clusters.
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+public class EcalCosmicClusterPlotsDriver extends Driver {
+
+ EcalConditions conditions = null;
+ EcalChannelCollection channels = null;
+ Map<EcalChannel, IProfile1D> adcProfiles = new HashMap<EcalChannel, IProfile1D>();
+ AIDA aida = AIDA.defaultInstance();
+ IAnalysisFactory analysisFactory = aida.analysisFactory();
+ String inputClusterCollectionName = "EcalCosmicClusters";
+ String rawHitsCollectionName = "EcalCosmicReadoutHits";
+
+ public void setInputHitsCollectionName(String inputClusterCollectionName) {
+ this.inputClusterCollectionName = inputClusterCollectionName;
+ }
+
+ public void setRawHitsCollectionName(String rawHitsCollectionName) {
+ this.rawHitsCollectionName = rawHitsCollectionName;
+ }
+
+ public void detectorChanged(Detector detector) {
+ conditions = ConditionsManager.defaultInstance().getCachedConditions(EcalConditions.class, TableConstants.ECAL_CONDITIONS).getCachedData();
+ channels = conditions.getChannelCollection();
+ for (EcalChannel channel : conditions.getChannelCollection()) {
+ adcProfiles.put(channel, aida.profile1D(inputClusterCollectionName + "/ADC Values : " + String.format("%03d", channel.getChannelId()), 100, 0, 100));
+ }
+ }
+
+ public void process(EventHeader event) {
+ if (event.hasCollection(Cluster.class, inputClusterCollectionName)) {
+ if (event.hasCollection(RawTrackerHit.class, rawHitsCollectionName)) {
+ Map<Long, RawTrackerHit> rawHitMap = createRawHitMap(event.get(RawTrackerHit.class, rawHitsCollectionName));
+ List<Cluster> clusters = event.get(Cluster.class, inputClusterCollectionName);
+ for (Cluster cluster : clusters) {
+ for (CalorimeterHit calHit : cluster.getCalorimeterHits()) {
+ RawTrackerHit rawHit = rawHitMap.get(calHit.getCellID());
+ EcalChannel channel = channels.findGeometric(rawHit.getCellID());
+ if (channel != null) {
+ IProfile1D profile = adcProfiles.get(channel);
+ for (int adcIndex = 0; adcIndex < rawHit.getADCValues().length; adcIndex++) {
+ // Fill the Profile1D with ADC value.
+ profile.fill(adcIndex, rawHit.getADCValues()[adcIndex]);
+ }
+ } else {
+ throw new RuntimeException("EcalChannel not found for cell ID 0x" + String.format("%08d", Long.toHexString(rawHit.getCellID())));
+ }
+ }
+ }
+ } else {
+ throw new RuntimeException("Missing raw hit collection: " + rawHitsCollectionName);
+ }
+ }
+ }
+
+ Map<Long, RawTrackerHit> createRawHitMap(List<RawTrackerHit> rawHits) {
+ Map<Long, RawTrackerHit> rawHitMap = new HashMap<Long, RawTrackerHit>();
+ for (RawTrackerHit hit : rawHits) {
+ rawHitMap.put(hit.getCellID(), hit);
+ }
+ return rawHitMap;
+ }
+
+}
Added: java/trunk/users/src/main/java/org/hps/users/jeremym/EcalCosmicHitSelectionDriver.java
=============================================================================
--- java/trunk/users/src/main/java/org/hps/users/jeremym/EcalCosmicHitSelectionDriver.java (added)
+++ java/trunk/users/src/main/java/org/hps/users/jeremym/EcalCosmicHitSelectionDriver.java Thu Dec 4 17:25:29 2014
@@ -0,0 +1,124 @@
+package org.hps.users.jeremym;
+
+import hep.aida.IAnalysisFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.hps.conditions.database.TableConstants;
+import org.hps.conditions.ecal.EcalChannel;
+import org.hps.conditions.ecal.EcalChannel.EcalChannelCollection;
+import org.hps.conditions.ecal.EcalChannelConstants;
+import org.hps.conditions.ecal.EcalConditions;
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.RawTrackerHit;
+import org.lcsim.geometry.Detector;
+import org.lcsim.geometry.subdetector.HPSEcal3;
+import org.lcsim.util.Driver;
+import org.lcsim.util.aida.AIDA;
+
+/**
+ * This Driver will process ECAL raw mode (window) data and extract hits
+ * that look like signal, by requiring a certain number of ADC samples
+ * in a row that are above a sigma threshold. For events with number
+ * of hits greater than a minimum (5 by default), it will convert
+ * the raw data into CalorimeterHits and write them to an output
+ * collection.
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+public class EcalCosmicHitSelectionDriver extends Driver {
+
+ EcalConditions conditions = null;
+ EcalChannelCollection channels = null;
+
+ AIDA aida = AIDA.defaultInstance();
+ IAnalysisFactory analysisFactory = aida.analysisFactory();
+ double sigmaThreshold = 2.5;
+
+ int minimumSelectedSamples = 3;
+ int minimumNumberOfHits = 3;
+ int minNeighbors = 2;
+ String outputHitsCollectionName = "EcalCosmicReadoutHits";
+ String inputHitsCollectionName = "EcalReadoutHits";
+ HPSEcal3 ecal = null;
+ static String ecalName = "Ecal";
+
+ /**
+ * Set the sigma threshold for an ADC value.
+ * @param sigmaThreshold The sigma threshold.
+ */
+ public void setSigmaThreshold(double sigmaThreshold) {
+ this.sigmaThreshold = sigmaThreshold;
+ }
+
+ /**
+ * Set the number of hits in a row which must be above threshold for the ADC values to be
+ * saved for the event.
+ * @param selectedHits The minimum number of hits above threshold.
+ */
+ public void setMinimumSelectedSamples(int minimumSelectedSamples) {
+ this.minimumSelectedSamples = minimumSelectedSamples;
+ }
+
+ public void setMinimumNumberOfHits(int minimumNumberOfHits) {
+ this.minimumNumberOfHits = minimumNumberOfHits;
+ }
+
+ public void setOutputHitsCollectionName(String outputHitsCollectionName) {
+ this.outputHitsCollectionName = outputHitsCollectionName;
+ }
+
+ public void detectorChanged(Detector detector) {
+ ecal = (HPSEcal3)detector.getSubdetector(ecalName);
+ conditions = ConditionsManager.defaultInstance().getCachedConditions(EcalConditions.class, TableConstants.ECAL_CONDITIONS).getCachedData();
+ channels = conditions.getChannelCollection();
+ }
+
+ public void process(EventHeader event) {
+ if (event.hasCollection(RawTrackerHit.class, inputHitsCollectionName)) {
+ List<RawTrackerHit> hits = event.get(RawTrackerHit.class, inputHitsCollectionName);
+ List<RawTrackerHit> selectedHitsList = new ArrayList<RawTrackerHit>();
+ for (RawTrackerHit hit : hits) {
+ EcalChannel channel = channels.findGeometric(hit.getCellID());
+ if (channel != null) {
+ int nSelectedHits = 0;
+ boolean saveHit = false;
+ EcalChannelConstants channelConstants = conditions.getChannelConstants(channel);
+ double pedestal = channelConstants.getCalibration().getPedestal();
+ double noise = channelConstants.getCalibration().getNoise();
+ double threshold = pedestal + sigmaThreshold * noise;
+ adcThresholdLoop: for (int adcIndex = 0; adcIndex < hit.getADCValues().length; adcIndex++) {
+ short adcValue = hit.getADCValues()[adcIndex];
+ if (adcValue > threshold) {
+ ++nSelectedHits;
+ if (nSelectedHits >= minimumSelectedSamples) {
+ saveHit = true;
+ break adcThresholdLoop;
+ }
+ } else {
+ nSelectedHits = 0;
+ }
+ }
+
+ if (saveHit) {
+ // Add hit to output list.
+ selectedHitsList.add(hit);
+ }
+ } else {
+ System.err.println("EcalChannel not found for cell ID 0x" + String.format("%08d", Long.toHexString(hit.getCellID())));
+ }
+ }
+
+ // Is number of hits above minimum?
+ if (selectedHitsList.size() >= this.minimumNumberOfHits) {
+ // Save selected hits list to event.
+ //getLogger().info("writing " + selectedHitsList.size() + " hits into " + outputHitsCollectionName);
+ event.put(outputHitsCollectionName, selectedHitsList, RawTrackerHit.class, event.getMetaData(hits).getFlags(), ecal.getReadout().getName());
+ } else {
+ // Skip this event so LCIODriver does not write this event.
+ throw new NextEventException();
+ }
+ }
+ }
+}
|