Commit in lcsim/src/org/lcsim/contrib/seedtracker on MAIN
SeedTrackerDiagnostics.java+75-211.1 -> 1.2
CD - fixed bug in calculating efficiency + refactoring

lcsim/src/org/lcsim/contrib/seedtracker
SeedTrackerDiagnostics.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- SeedTrackerDiagnostics.java	13 Apr 2008 01:22:45 -0000	1.1
+++ SeedTrackerDiagnostics.java	21 Apr 2008 03:59:28 -0000	1.2
@@ -6,8 +6,12 @@
 package org.lcsim.contrib.seedtracker;
 
 import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
 import org.lcsim.event.EventHeader;
 import org.lcsim.event.MCParticle;
 import org.lcsim.util.aida.AIDA;
@@ -27,35 +31,82 @@
     private double mcth_max=0.9; 
     private double mcth_step = 0.1;
     
+    private double purity_cutoff = 0.0; 
     
     public SeedTrackerDiagnostics(EventHeader event, double b_field){
         this.ev = event;
         this.b_field = b_field; 
     }
     
+    /**
+     * Generates diagnostic plots given a list of seed candidates and a strategy.
+     * @param seedlist
+     * @param strategy
+     */
     public void performDiagnostics(List<SeedCandidate> seedlist, SeedStrategy strategy){
-        
-        List<MCParticle> likelyMCList = makePurityPlots(seedlist);
-        makeEfficiencyPlots(seedlist,likelyMCList,strategy);
+       
+        Map<SeedCandidate,SeedValidator> vmap = generateValidators(seedlist);
+        makePurityPlots(vmap);        
+        Set<MCParticle> likelyMCs = generateLikelyMCSet(vmap);
+        makeEfficiencyPlots(likelyMCs,strategy);
     }
-    
-    public void setMinCosThetaOpts(double min, double max, double step){
+    /**
+     * Multiple efficiency plots are generated for different 
+     * minimum values of cos theta. This is useful because a barrel only 
+     * algorithm would only consider tracks going into the barrel to be findable. 
+     * 
+     * By default, a plot is generated for minCosTheta = 0, 10, 20, 30, 40, 50, 
+     * 60, 70, 80 and 90. That behavior may be changed using this function. 
+     * 
+     * @param min minimum value of minCosTheta to plot
+     * @param max maximum value of minCosTheta to plot
+     * @param step step size in between... 
+     */
+    public void setMinCosThetaOpts(double min, double max, double step) {
         this.mcth_max = max;
         this.mcth_min = min; 
         this.mcth_step = step; 
     }
     
+   /**
+    * Sets the purity cutoff for a track's MC to be considered found when 
+    * calculating efficiency. Default is 0.0. 
+    * @param new_purity_cutoff
+    */
+    public void setPurityCutoff(double new_purity_cutoff){
+        purity_cutoff = new_purity_cutoff; 
+    }
     
-    //makes purity plots and also returns a list of likely MCParticles found 
-    private List<MCParticle> makePurityPlots(List<SeedCandidate> seedlist) {
+    private Map<SeedCandidate,SeedValidator> generateValidators(List<SeedCandidate> seedlist) {
+        
+        Map<SeedCandidate,SeedValidator> ret = new HashMap<SeedCandidate,SeedValidator>(); 
         
-        List<MCParticle> ret = new ArrayList<MCParticle>(); 
         for (SeedCandidate s : seedlist) {
+            ret.put(s, new SeedValidator(s));
+        }
+        
+        return ret;
+    }
+    
+    private Set<MCParticle> generateLikelyMCSet(Map<SeedCandidate, SeedValidator> vmap) {
+        
+        Set<MCParticle> set = new HashSet<MCParticle>(); 
+        
+        for (SeedValidator v : vmap.values()) {
+            if(v.getPurity()<purity_cutoff) continue; 
+            set.add(v.getLikelyMC());
+        }
+        return set; 
+    }
+    
+    
+    //makes purity plots
+    private void makePurityPlots(Map<SeedCandidate, SeedValidator> vmap) {
+        
+        for (SeedCandidate s : vmap.keySet()) {
 
-            SeedValidator v = new SeedValidator(s);
-            
-            ret.add(v.getLikelyMC());
-            
+            SeedValidator v = vmap.get(s);
+   
             if (v.getVerdict().isGoodValue()) {
                 aida.cloud1D("Good seeds chisq").fill(s.getHelix().chisqtot());
                 aida.cloud1D("Good seeds numhits").fill(s.getHits().size());
@@ -65,7 +116,7 @@
                 aida.cloud1D("Bad seeds numhits").fill(s.getHits().size());
                 aida.cloud1D("Bad seeds pt").fill(s.getHelix().pT(5.0));
             }
-
+            
             aida.cloud1D("purity").fill(v.getPurity());
             aida.cloud2D("purity vs. numHits").fill(v.getPurity(), s.getHits().size());
             aida.cloud2D("purity vs. pt").fill(v.getPurity(), s.getHelix().pT(5.0));
@@ -73,10 +124,9 @@
             aida.cloud2D("purity vs. chisq").fill(v.getPurity(), s.getHelix().chisqtot());
             aida.cloud2D("purity cs. dca").fill(v.getPurity(), s.getHelix().dca());
         }
-        return ret; 
     }
     
-    private void makeEfficiencyPlots(List<SeedCandidate> seedlist, List<MCParticle> likelyMCs, SeedStrategy strat){
+    private void makeEfficiencyPlots(Set<MCParticle> likelyMCs, SeedStrategy strat){
         
         FindableTrackParams findable = new FindableTrackParams(strat);
         findable.setBField(b_field);
@@ -99,18 +149,22 @@
                     iter.remove();
             }
 
-            int denom = temp.size(); 
-            aida.cloud1D("Num findable/ minCosTheta = "+String.valueOf(d)).fill(denom);
+            int numFindable = temp.size(); 
+            aida.cloud1D("Num findable/ minCosTheta = "+String.valueOf(d)).fill(numFindable);
 
+            
+            // remove all the MC's we've found... this gives us findable - found
             temp.removeAll(likelyMCs);
 
-            int num =temp.size(); 
-            if(denom>0){
-                double eff = (double) num / (double) denom;
+            int numFound = numFindable - temp.size(); // findable - (findable - found) = found 
+            
+            aida.cloud1D("Num found (purity cutoff="+purity_cutoff+") / minCosTheta = " + String.valueOf(d)).fill(numFound);
+            
+            if(numFindable > 0){
+                double eff = (double) numFound / (double) numFindable;
                 aida.cloud2D("Efficiency vs. minCosTheta").fill(eff, d);
                 aida.cloud1D("Efficiency / minCosTheta = "+String.valueOf(d)).fill(eff);
             }
         }
     }
-    
 }
CVSspam 0.2.8