hps-java/src/main/java/org/lcsim/hps/recon/tracking
diff -N TrackerHitDriver.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ TrackerHitDriver.java 16 Mar 2012 19:11:11 -0000 1.1
@@ -0,0 +1,320 @@
+package org.lcsim.hps.recon.tracking;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.lcsim.detector.DetectorElementStore;
+import org.lcsim.detector.IDetectorElement;
+import org.lcsim.detector.identifier.IExpandedIdentifier;
+import org.lcsim.detector.identifier.IIdentifier;
+import org.lcsim.detector.identifier.IIdentifierDictionary;
+import org.lcsim.detector.tracker.silicon.SiSensor;
+import org.lcsim.detector.tracker.silicon.SiTrackerModule;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.RawTrackerHit;
+import org.lcsim.event.SimTrackerHit;
+import org.lcsim.geometry.Detector;
+import org.lcsim.recon.tracking.digitization.sisim.BasicReadoutChip;
+import org.lcsim.recon.tracking.digitization.sisim.CDFSiSensorSim;
+import org.lcsim.recon.tracking.digitization.sisim.NearestNeighborRMS;
+import org.lcsim.recon.tracking.digitization.sisim.SiDigitizer;
+import org.lcsim.recon.tracking.digitization.sisim.SiTrackerHit;
+import org.lcsim.recon.tracking.digitization.sisim.SiTrackerHitStrip1D;
+import org.lcsim.recon.tracking.digitization.sisim.StripHitMaker;
+import org.lcsim.recon.tracking.digitization.sisim.config.SimTrackerHitReadoutDriver;
+import org.lcsim.util.Driver;
+
+/**
+ * This Driver runs the tracker digitization to create raw hits and strip hits
+ * from simulated data. The output can be used by a track reconstruction
+ * algorithm like Seed Tracker.
+ *
+ * @author jeremym
+ * @version $Id: TrackerHitDriver.java,v 1.1 2012/03/16 19:11:11 jeremy Exp $
+ */
+public class TrackerHitDriver extends Driver {
+ // Debug switch for development.
+ private static final boolean DEBUG = false;
+
+ // Collection name.
+ private String readoutCollectionName = "TrackerHits";
+
+ // Subdetector name.
+ private String subdetectorName = "Tracker";
+
+ // Name of RawTrackerHit collection to be read from event.
+ private String rawTrackerHitCollectionName = "RawTrackerHitMaker_RawTrackerHits";
+
+ // Name of StripHit1D output collection.
+ private String stripHitOutputCollectionName = "StripClusterer_SiTrackerHitStrip1D";
+
+ // Readout parameters.
+ private double readoutNoiseIntercept = 270.0;
+ private double readoutNoiseSlope = 36.0;
+ private double readoutNoiseThreshold = 4.0;
+ private double readoutNeighborThreshold = 4.0;
+ private int readoutNBits = 10;
+ private int readoutDynamicRange = 40;
+
+ // Clustering parameters.
+ private double clusterSeedThreshold = 4.0;
+ private double clusterNeighborThreshold = 3.0;
+ private double clusterThreshold = 4.0;
+ private int clusterMaxSize = 10;
+ private int clusterCentralStripAveragingThreshold = 4;
+
+ // Clustering errors by number of TrackerHits.
+ private static final double clusterErrorMultiplier = 1.0;
+ private double oneClusterErr = clusterErrorMultiplier / Math.sqrt(12.);
+ private double twoClusterErr = clusterErrorMultiplier / 5.0;
+ private double threeClusterErr = clusterErrorMultiplier / 3.0;
+ private double fourClusterErr = clusterErrorMultiplier / 2.0;
+ private double fiveClusterErr = clusterErrorMultiplier / 1.0;
+
+ // Various data lists required by digitization.
+ private List<String> readouts = new ArrayList<String>();
+ private List<String> processPaths = new ArrayList<String>();
+ private List<IDetectorElement> processDEs = new ArrayList<IDetectorElement>();
+ private Set<SiSensor> processSensors = new HashSet<SiSensor>();
+ private Set<SiTrackerModule> processModules = new HashSet<SiTrackerModule>();
+
+ // Map of SiSensor objects from geometry.
+ private Map<Long, SiSensor> sensorMap = new HashMap<Long, SiSensor>();
+
+ // Digi class objects.
+ private StripHitMaker stripClusterer;
+
+ public void setReadoutCollectionName(String readoutCollectionName) {
+ this.readoutCollectionName = readoutCollectionName;
+ }
+
+ public void setSubdetectorName(String subdetectorName) {
+ this.subdetectorName = subdetectorName;
+ }
+
+ public void setStripHitOutputCollectionName(
+ String stripHitOutputCollectionName) {
+ this.stripHitOutputCollectionName = stripHitOutputCollectionName;
+ }
+
+ public void setReadoutNoiseIntercept(double readoutNoiseIntercept) {
+ this.readoutNoiseIntercept = readoutNoiseIntercept;
+ }
+
+ public void setReadoutNoiseSlope(double readoutNoiseSlope) {
+ this.readoutNoiseSlope = readoutNoiseSlope;
+ }
+
+ public void setReadoutNeighborThreshold(double readoutNeighborThreshold) {
+ this.readoutNeighborThreshold = readoutNeighborThreshold;
+ }
+
+ public void setReadoutNBits(int readoutNBits) {
+ this.readoutNBits = readoutNBits;
+ }
+
+ public void setReadoutDynamicRange(int readoutDynamicRange) {
+ this.readoutDynamicRange = readoutDynamicRange;
+ }
+
+ public void setClusterSeedThreshold(double clusterSeedThreshold) {
+ this.clusterSeedThreshold = clusterSeedThreshold;
+ }
+
+ public void setClusterNeighborThreshold(double clusterNeighborThreshold) {
+ this.clusterNeighborThreshold = clusterNeighborThreshold;
+ }
+
+ public void setClusterThreshold(double clusterThreshold) {
+ this.clusterThreshold = clusterThreshold;
+ }
+
+ public void setClusterMaxSize(int clusterMaxSize) {
+ this.clusterMaxSize = clusterMaxSize;
+ }
+
+ public void setClusterCentralStripAveragingThreshold(
+ int clusterCentralStripAveragingThreshold) {
+ this.clusterCentralStripAveragingThreshold = clusterCentralStripAveragingThreshold;
+ }
+
+ public void setOneClusterErr(double oneClusterErr) {
+ this.oneClusterErr = oneClusterErr;
+ }
+
+ public void setTwoClusterErr(double twoClusterErr) {
+ this.twoClusterErr = twoClusterErr;
+ }
+
+ public void setThreeClusterErr(double threeClusterErr) {
+ this.threeClusterErr = threeClusterErr;
+ }
+
+ public void setFourClusterErr(double fourClusterErr) {
+ this.fourClusterErr = fourClusterErr;
+ }
+
+ public void setFiveClusterErr(double fiveClusterErr) {
+ this.fiveClusterErr = fiveClusterErr;
+ }
+
+ /**
+ * Creates a new instance of TrackerHitDriver.
+ */
+ public TrackerHitDriver() {
+ }
+
+ /**
+ * Initializes this Driver's objects with the job parameters.
+ */
+ private void initialize() {
+
+ // Create the sensor simulation.
+ CDFSiSensorSim stripSim = new CDFSiSensorSim();
+
+ // Create the readout chips and set the noise parameters.
+ BasicReadoutChip stripReadout = new BasicReadoutChip();
+ stripReadout.setNoiseIntercept(readoutNoiseIntercept);
+ stripReadout.setNoiseSlope(readoutNoiseSlope);
+ stripReadout.setNoiseThreshold(readoutNoiseThreshold);
+ stripReadout.setNeighborThreshold(readoutNeighborThreshold);
+ stripReadout.setNbits(readoutNBits);
+ stripReadout.setDynamicRange(readoutDynamicRange);
+
+ // Create Strip clustering algorithm.
+ NearestNeighborRMS stripClusteringAlgo = new NearestNeighborRMS();
+ stripClusteringAlgo.setSeedThreshold(clusterSeedThreshold);
+ stripClusteringAlgo.setNeighborThreshold(clusterNeighborThreshold);
+ stripClusteringAlgo.setClusterThreshold(clusterThreshold);
+
+ // Create the clusterers and set hit-making parameters.
+ stripClusterer = new StripHitMaker(stripSim, stripReadout, stripClusteringAlgo);
+ stripClusterer.setMaxClusterSize(clusterMaxSize);
+ stripClusterer.setCentralStripAveragingThreshold(clusterCentralStripAveragingThreshold);
+
+ // Set the cluster errors.
+ stripClusterer.SetOneClusterErr(oneClusterErr);
+ stripClusterer.SetTwoClusterErr(twoClusterErr);
+ stripClusterer.SetThreeClusterErr(threeClusterErr);
+ stripClusterer.SetFourClusterErr(fourClusterErr);
+ stripClusterer.SetFiveClusterErr(fiveClusterErr);
+
+ // Set the readout to process.
+ readouts.add(readoutCollectionName);
+
+ // Set the detector to process.
+ processPaths.add(subdetectorName);
+ }
+
+ /**
+ * This is executed before detectorChanged and initialization of
+ * digitization objects is done here.
+ */
+ public void startOfData() {
+
+ // At start of job, setup digitization objects needed by this Driver.
+ initialize();
+
+ // If readouts not already set, set them up.
+ if (readouts.size() != 0) {
+ //System.out.println("Adding SimTrackerHitIdentifierReadoutDriver with readouts: " + readouts);
+ super.add(new SimTrackerHitReadoutDriver(readouts));
+ }
+ super.startOfData();
+ readouts.clear(); // FIXME Is this needed?
+ }
+
+ /**
+ * Do initialization once we get a Detector.
+ */
+ public void detectorChanged(Detector detector) {
+
+ // Call sub-Driver's detectorChanged methods.
+ super.detectorChanged(detector);
+
+ // Process detectors specified by path, otherwise process entire detector.
+ IDetectorElement deDetector = detector.getDetectorElement();
+
+ for (String path : processPaths) {
+ processDEs.add(deDetector.findDetectorElement(path));
+ }
+
+ if (processDEs.size() == 0) {
+ processDEs.add(deDetector);
+ }
+
+ for (IDetectorElement detectorElement : processDEs) {
+ processSensors.addAll(detectorElement.findDescendants(SiSensor.class));
+ processModules.addAll(detectorElement.findDescendants(SiTrackerModule.class)); // FIXME Is this redundant?
+ }
+
+ // Make sensor map.
+ for (SiSensor sensor : processSensors) {
+ sensorMap.put(sensor.getIdentifier().getValue(), sensor);
+ }
+ }
+
+ public void setRawTrackerHitCollectionName(
+ String rawTrackerHitCollectionName) {
+ this.rawTrackerHitCollectionName = rawTrackerHitCollectionName;
+ }
+
+ private static IIdentifier makeSensorId(Detector detector, RawTrackerHit hit) {
+
+ IIdentifierDictionary dict = detector.getSubdetector("Tracker").getDetectorElement().getIdentifierHelper().getIdentifierDictionary();
+ int fieldIdx = dict.getFieldIndex("side");
+ int sideIdx = dict.getFieldIndex("strip");
+
+ // The "side" and "strip" fields needs to be taken out of the ID or geometry lookup will fail.
+ IExpandedIdentifier expId = dict.unpack(hit.getIdentifier());
+ expId.setValue(fieldIdx, 0);
+ expId.setValue(sideIdx, 0);
+ IIdentifier strippedId = dict.pack(expId);
+
+ return strippedId;
+ }
+
+ /**
+ * Perform the digitization.
+ */
+ public void process(EventHeader event) {
+
+ // Call sub-Driver processing.
+ super.process(event);
+
+ // Read RawTrackerHits from LCSimEvent.
+ List<RawTrackerHit> rawHits = event.get(RawTrackerHit.class, rawTrackerHitCollectionName);
+
+ // Add hits to sensors.
+ for (RawTrackerHit hit : rawHits) {
+ IIdentifier strippedId = makeSensorId(event.getDetector(), hit);
+ if (!sensorMap.containsKey(strippedId.getValue())) {
+ throw new RuntimeException("Missing SiSensor with id = 0x" + Long.toHexString(strippedId.getValue()));
+ }
+ SiSensor sensor = sensorMap.get(strippedId.getValue());
+ sensor.getReadout().addHit(hit);
+ }
+
+ // Make strip hits.
+ List<SiTrackerHit> stripHits1D = new ArrayList<SiTrackerHit>();
+ for (SiSensor sensor : processSensors) {
+ //System.out.println("making TrackerHits for sensor " + sensor.getName() + " with " + sensor.getReadout().getHits(RawTrackerHit.class).size() + " hits");
+ List<SiTrackerHit> trackerHits = stripClusterer.makeHits(sensor);
+ //System.out.println("made " + trackerHits.size() + " hits on sensor " + sensor.getName());
+ stripHits1D.addAll(trackerHits);
+ }
+
+ // Debug prints.
+ //if (DEBUG) {
+ // System.out.println("TrackerHit collection " + this.stripHitOutputCollectionName + " has " + stripHits1D.size() + " hits.");
+ //}
+
+ // Put output TrackerHits into event.
+ // FIXME Does this collection need a non-zero flag?
+ event.put(this.stripHitOutputCollectionName, stripHits1D, SiTrackerHitStrip1D.class, 0, toString());
+ }
+}
\ No newline at end of file