lcsim-contrib/src/main/java/org/lcsim/contrib/sATLAS
diff -N TrackAnalysis.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ TrackAnalysis.java 20 Aug 2009 17:22:04 -0000 1.1
@@ -0,0 +1,87 @@
+/*
+ * TrackAnalysis.java
+ *
+ * Created on October 16, 2008, 6:09 PM
+ *
+ */
+
+package org.lcsim.contrib.sATLAS;
+
+import org.lcsim.contrib.mgraham.sATLASDigi.*;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.lcsim.event.MCParticle;
+import org.lcsim.event.RelationalTable;
+import org.lcsim.event.Track;
+import org.lcsim.event.TrackerHit;
+
+/**
+ *
+ * @author Richard Partridge
+ */
+public class TrackAnalysis {
+ private enum HelixPar {Curvature, Phi0, DCA, Z0, Slope};
+ private MCParticle _mcp = null;
+ private int _nhits;
+ private int _nbadhits;
+ private double _purity;
+
+ /** Creates a new instance of TrackAnalysis */
+ public TrackAnalysis(Track trk, RelationalTable hittomc) {
+
+ // Get the number of hits on the track
+ _nhits = trk.getTrackerHits().size();
+
+ // Create a map containing the number of hits for each MCParticle associated with the track
+ Map<MCParticle,Integer> mcmap = new HashMap<MCParticle,Integer>();
+
+ // Loop over the hits on the track and make sure we have HelicalTrackHits (which contain the MC particle)
+ for (TrackerHit hit : trk.getTrackerHits()) {
+
+ // get the set of MCParticles associated with this hit and update the hit count for each MCParticle
+ Set<MCParticle> mclist = hittomc.allFrom(hit);
+ for (MCParticle mcp : mclist) {
+ Integer mchits = 0;
+ if (mcmap.containsKey(mcp)) mchits = mcmap.get(mcp);
+ mchits++;
+ mcmap.put(mcp, mchits);
+ }
+ }
+
+ // Find the MCParticle that has the most hits on the track
+
+ int nbest = 0;
+ MCParticle mcbest = null;
+ for (MCParticle mcp : mcmap.keySet()) {
+ int count = mcmap.get(mcp);
+ if (count > nbest) {
+ nbest = count;
+ mcbest = mcp;
+ }
+ }
+
+ if (nbest > 0) _mcp = mcbest;
+ _purity = (double) nbest / (double) _nhits;
+ _nbadhits = _nhits - nbest;
+
+ }
+
+ public MCParticle getMCParticle() {
+ return _mcp;
+ }
+
+ public int getNHits() {
+ return _nhits;
+ }
+
+ public int getNBadHits() {
+ return _nbadhits;
+ }
+
+ public double getPurity() {
+ return _purity;
+ }
+
+}