lcsim/src/org/lcsim/recon/tracking/seedtracker/analysis
diff -u -r1.3 -r1.4
--- AnalysisUtils.java 16 Sep 2008 01:03:10 -0000 1.3
+++ AnalysisUtils.java 28 Oct 2008 23:48:40 -0000 1.4
@@ -3,8 +3,6 @@
*
* Created on August 4, 2008, 11:00 AM
*
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
*/
package org.lcsim.recon.tracking.seedtracker.analysis;
@@ -25,12 +23,13 @@
import org.lcsim.event.MCParticle;
import org.lcsim.event.RawTrackerHit;
import org.lcsim.event.SimTrackerHit;
+import org.lcsim.event.TrackerHit;
import org.lcsim.fit.helicaltrack.HelicalTrackHit;
/**
* This class contains utilities useful for seedtracker performance studies
- * @authors Richard Partridge,Pelham Keahey
+ * @authors Richard Partridge, Pelham Keahey
* @version 1.0
*/
public class AnalysisUtils {
@@ -38,6 +37,7 @@
private static EventHeader currentEvent=null;
//trkmap returned in the FindTrackMap method
private static Map<MCParticle,Track> trkmap;
+
/** Creates a new instance of AnalysisUtils */
public AnalysisUtils() {
}
@@ -92,52 +92,42 @@
// Done looping over all MCParticle candidates - return the list with any matches that were found
return mcplist;
}
+
/**
* Finds the purity of the given track
* @param trk find purity of this track
* @return a double purity
*/
public static double FindTrackPurity(Track trk){
- double purity=0.;
- //MCParticle and Int map, int will be the number of times this mcparticle shows up in the track
- Map<MCParticle,Integer> occurrences = new HashMap<MCParticle,Integer>();
- double mostoccured;
- int index;
- //creates a seedcandiate for the track
- if (trk instanceof SeedTrack) {
- SeedTrack strk = (SeedTrack) trk;
- for (HelicalTrackHit h : strk.getSeedCandidate().getHits()){
- //Create List of MCParticles in the SeedCandidate
- List<MCParticle> mcpl = h.getMCParticles();
- //loop through these mcparticles and count how many times that particle occurs
- for(MCParticle part : mcpl){
- if(occurrences.containsKey(part)){
- index = occurrences.get(part);
- occurrences.put(part,index+1);
- } else {
- occurrences.put(part, 1);
- }
- }
-
- }
- //If only one MCParticle exsists in the map, then purity if perfect
- if(occurrences.size()==1){
- purity =1;
- }
- //otherwise save the value of the most occuring mcparticle against the total size of the track's hitlist
- else{
- mostoccured = -1;
- for(MCParticle p : occurrences.keySet()){
- int occured = occurrences.get(p);
- if(occured>mostoccured){
- mostoccured = occured;
- }
- }
- purity = mostoccured / strk.getSeedCandidate().getHits().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()) {
+ if (!(hit instanceof HelicalTrackHit)) throw new RuntimeException("AnalysisUtils found track with non-HelicalTrackHits");
+
+ // Loop over the MCParticles for this hit and update their hit count
+ for (MCParticle mcp : ((HelicalTrackHit) hit).getMCParticles()) {
+ Integer mchits = 0;
+ if (mcmap.containsKey(mcp)) mchits = mcmap.get(mcp);
+ mcmap.put(mcp, mchits++);
}
}
+
+ // Find the maximum purity among the MCParticles that contribute to the track
+ double nhits = trk.getTrackerHits().size();
+ double purity = 0;
+ for (Map.Entry entry : mcmap.entrySet()) {
+ int count = (Integer) entry.getValue();
+ purity = Math.max(purity, (double) count / (double) nhits);
+ }
+
return purity;
}
+
+
+
/**
* @param event
* @return a map of MCParticles and Integers. The int is either 1 or 0, 1 being track found 0, track not found