lcsim/src/org/lcsim/recon/cluster/mipfinder
diff -N ShowerPointFinderDriver.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ShowerPointFinderDriver.java 22 Oct 2008 17:47:51 -0000 1.1
@@ -0,0 +1,134 @@
+package org.lcsim.recon.cluster.mipfinder;
+
+import java.util.*;
+import org.lcsim.util.*;
+import org.lcsim.event.util.*;
+import org.lcsim.event.*;
+import org.lcsim.recon.pfa.identifier.*;
+import org.lcsim.util.hitmap.*;
+import org.lcsim.recon.cluster.util.*;
+import org.lcsim.util.decision.*;
+
+/**
+ * Wrapper class for ShowerPointFinder, allowing it to be
+ * run as a Driver. Outputs are written to the event.
+ *
+ * @version $Id: ShowerPointFinderDriver.java,v 1.1 2008/10/22 17:47:51 mcharles Exp $
+ * @author [log in to unmask]
+ */
+
+public class ShowerPointFinderDriver extends Driver {
+
+ protected HelixExtrapolator m_findCluster;
+ protected String m_inputHitMap;
+ protected String m_inputTrackList;
+ protected String m_outputTrackMap;
+ protected String m_outputHitMap;
+ protected String m_outputMipClusterList;
+ protected TrackClusterMatcher m_trackClusterMatcher;
+ protected boolean m_debug = false;
+
+ /**
+ * Constructor. Quite a few inputs needed:
+ *
+ * @param findCluster Extrapolator object that should be used to propagate tracks.
+ * @param inputHitMap Name of the input hitmap. Tracks will be matched to MIPs in these hits.
+ * @param inputTrackList Name of the input track list.
+ * @param outputTrackMap Name to write an output Map<Track,BasicCluster> out as, connecting tracks to their MIP stubs.
+ * @param outputHitMap Name to write the remaining, unused hits out as.
+ * @param outputMipClusterList Name to write the MIP stub clusters out as.
+ */
+ public ShowerPointFinderDriver(HelixExtrapolator findCluster, String inputHitMap, String inputTrackList, String outputTrackMap, String outputHitMap, String outputMipClusterList) {
+ m_findCluster = findCluster;
+ m_inputHitMap = inputHitMap;
+ m_inputTrackList = inputTrackList;
+ m_outputTrackMap = outputTrackMap;
+ m_outputHitMap = outputHitMap;
+ m_outputMipClusterList = outputMipClusterList;
+ LocalHelixExtrapolationTrackClusterMatcher genMatch = new LocalHelixExtrapolationTrackClusterMatcher(m_findCluster);
+ add(genMatch);
+ m_trackClusterMatcher = genMatch;
+ }
+ public void process(EventHeader event) {
+ super.process(event);
+
+ // Read in & set up
+ HitMap inputHitMap = (HitMap)(event.get(m_inputHitMap));
+ List<Track> inputTrackList = event.get(Track.class, m_inputTrackList);
+ Set<CalorimeterHit> allHits = new HashSet<CalorimeterHit>();
+ allHits.addAll(inputHitMap.values());
+
+ // Start by finding all ECAL hits:
+ ListFilter<CalorimeterHit> findEcalHits = new ListFilter<CalorimeterHit>(new HitInECALDecision());
+ List<CalorimeterHit> hitsEcal = findEcalHits.filterList(allHits);
+ // Wrap them individually as clusters:
+ List<Cluster> clustersEcal = new Vector<Cluster>();
+ for (CalorimeterHit hit : hitsEcal) {
+ BasicCluster clus = new BasicCluster();
+ clus.addHit(hit);
+ clustersEcal.add(clus);
+ }
+
+ // Do track -> hit matching:
+ Map<Track,Cluster> tracksMatchedToClusters = new HashMap<Track,Cluster>();
+ for (Track tr : inputTrackList) {
+ Cluster matchedCluster = m_trackClusterMatcher.matchTrackToCluster(tr, clustersEcal);
+ if (matchedCluster != null) {
+ tracksMatchedToClusters.put(tr, matchedCluster);
+ }
+ }
+
+ // Find showering point for each track given first hit:
+ ShowerPointFinder showerFinder = new ShowerPointFinder(m_findCluster, allHits, tracksMatchedToClusters);
+ Map<Track,BasicCluster> mapTrkToMIP = showerFinder.findMips();
+
+ // Remaining, unused hits
+ HitMap outputHitMap = new HitMap(inputHitMap);
+ for (BasicCluster clus : mapTrkToMIP.values()) {
+ for (CalorimeterHit hit : clus.getCalorimeterHits()) {
+ long id = hit.getCellID();
+ outputHitMap.remove(id);
+ if (m_debug) { System.out.println("DEBUG: Removed cell ID "+id+" from "+m_outputHitMap); }
+ }
+ }
+
+ // Write main output
+ event.put(m_outputTrackMap, mapTrkToMIP);
+ event.put(m_outputHitMap, outputHitMap);
+
+ // Additional list of MIP clusters used to identify MIP hits for dE/dx etc:
+ List<Cluster> preShowerMips = new Vector<Cluster>();
+ preShowerMips.addAll(mapTrkToMIP.values());
+ event.put(m_outputMipClusterList, preShowerMips);
+ event.getMetaData(preShowerMips).setTransient(true);
+
+ // Some debug
+ if (m_debug) {
+ System.out.println("DEBUG: Printing hit cell IDs for "+preShowerMips.size()+" pre-shower MIPs...");
+ for (Cluster clus : preShowerMips) {
+ for (CalorimeterHit hit : clus.getCalorimeterHits()) {
+ System.out.println("DEBUG: ID "+hit.getCellID()+" in "+hit.getSubdetector().getName());
+ }
+ }
+ System.out.println("DEBUG: Checking for overlaps among "+preShowerMips.size()+" pre-shower MIPs...");
+ for (int i=0; i<preShowerMips.size(); i++) {
+ Cluster clus1 = preShowerMips.get(i);
+ for (int j=i+1; j<preShowerMips.size(); j++) {
+ Cluster clus2 = preShowerMips.get(j);
+ // Now check for overlaps
+ int countOverlaps = 0;
+ for (CalorimeterHit hit1 : clus1.getCalorimeterHits()) {
+ for (CalorimeterHit hit2 : clus2.getCalorimeterHits()) {
+ if (hit1.getCellID() == hit2.getCellID()) {
+ countOverlaps++;
+ }
+ }
+ }
+ if (countOverlaps != 0) {
+ System.out.println("DEBUG: Found "+countOverlaps+" overlaps when comparing a MIP with "+clus1.getCalorimeterHits().size()+" with another MIP with "+clus2.getCalorimeterHits().size()+" hits.");
+ }
+ }
+ }
+ }
+ }
+}