lcsim/src/org/lcsim/contrib/seedtracker
diff -N FindableTracks.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ FindableTracks.java 21 Apr 2008 09:07:21 -0000 1.1
@@ -0,0 +1,195 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.lcsim.contrib.seedtracker;
+
+import hep.physics.vec.BasicHep3Vector;
+import hep.physics.vec.Hep3Vector;
+import hep.physics.vec.SpacePoint;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.lcsim.event.MCParticle;
+import org.lcsim.fit.helicaltrack.HelicalTrackHit;
+import org.lcsim.util.swim.HelixSwimmer;
+
+/**
+ *
+ * @author cozzy
+ */
+public class FindableTracks {
+
+ private Set<MCParticle> goodMCs;
+ private double minPt;
+ private double maxDCA;
+ private double b_field = 5;
+ private double maxZ0;
+
+ private Hep3Vector ip = new BasicHep3Vector(0,0,0);
+
+ public FindableTracks(SeedStrategy strategy, HitManager hm){
+
+ goodMCs = determineGoodMCs(strategy, hm);
+ minPt = strategy.getMinPT();
+ maxDCA = strategy.getMaxDCA();
+ maxZ0 = strategy.getMaxZ0();
+ }
+ /**
+ * Checks whether the given MCParticle is findable according
+ * to the strategy given to this class. It checks the following:
+ * <ul>
+ * <li>That the particle has hits in all seeed layers
+ * <li>That the particle has sufficient confirm hits
+ * <li>That the particle has sufficient extension hits
+ * <li>That the particle's DCA is not too great
+ * <li>That the particle's Pt is not too small
+ * <li>That the particle's Z0 is not too great
+ * </ul>
+ * @param p MCParticle to check
+ * @return wheter or not the MCParticle is findable
+ */
+ public boolean isFindable(MCParticle p){
+
+ if (!goodMCs.contains(p)) return false;
+
+ double px = p.getMomentum().x();
+ double py = p.getMomentum().y();
+
+ double pt = Math.sqrt(px*px+py*py);
+
+ if (pt < minPt)
+ return false;
+
+ HelixSwimmer h = new HelixSwimmer(b_field);
+
+ h.setTrack(p.getMomentum(), new SpacePoint(p.getOrigin()),(int)p.getCharge());
+
+ double dca = h.getDistanceToPoint(ip);
+ double z0 = h.getPointAtLength(h.getTrackLengthToPoint(ip)).z() - ip.z();
+
+
+ if (Math.abs(z0) > maxZ0 || dca > maxDCA)
+ return false;
+
+ return true;
+
+ }
+
+ public void setBField(double b){
+ this.b_field = b;
+ }
+
+ //this method does the fun job of figuring out if the particle has sufficient hits in each type of layer
+ private Set<MCParticle> determineGoodMCs(SeedStrategy strat, HitManager hm){
+
+ //first, we determine all the MCParticles that go through all the seed layers
+ List<SeedLayer> seedLayers = strat.getLayers(SeedLayer.SeedType.Seed);
+ List<Set<MCParticle>> seedLayerMCs = new ArrayList<Set<MCParticle>>();
+
+ //make a set of MCParticles existing in each seed layer
+ for (SeedLayer sl: seedLayers) {
+ Set<MCParticle> thisLayerMCs = new HashSet<MCParticle>();
+ List<HelicalTrackHit> th = hm.getTrackerHits(sl);
+ for (HelicalTrackHit h : th)
+ thisLayerMCs.addAll(h.getMCParticles());
+ seedLayerMCs.add(thisLayerMCs);
+ }
+
+ if (seedLayerMCs.isEmpty()) return Collections.EMPTY_SET;
+
+ //take the first set of MCs and intersect it with all the sets
+ Set<MCParticle> allSeedMCs = seedLayerMCs.remove(0);
+ for (Set<MCParticle> otherSeedLayerMC : seedLayerMCs)
+ allSeedMCs.retainAll(otherSeedLayerMC);
+
+ if(allSeedMCs.isEmpty()) return Collections.EMPTY_SET; //shortcut out
+
+ //now we ensure we have the minimum number of confirmation hits
+ int minConfirm = strat.getMinConfirm();
+ List<SeedLayer> confirmLayers = strat.getLayers(SeedLayer.SeedType.Confirm);
+ OccurrenceCounter<MCParticle> confirmCounter = getMCCounter(confirmLayers, hm);
+
+ //intersect MCs in all the seeds with MCs that have enough confirm hits
+ allSeedMCs.retainAll(confirmCounter.getAllWithCountGreater(minConfirm));
+
+ if(allSeedMCs.isEmpty()) return Collections.EMPTY_SET; //shortcut out
+
+ //finally, check for enough extension hits...
+ int minExtend = strat.getMinHits() - minConfirm - seedLayers.size();
+ List<SeedLayer> extendLayers = strat.getLayers(SeedLayer.SeedType.Extend);
+ OccurrenceCounter<MCParticle> extendCounter = getMCCounter(extendLayers, hm);
+
+ //intersect MCs with all the seeds with MCs that have enough extend hits
+ allSeedMCs.retainAll(extendCounter.getAllWithCountGreater(minExtend));
+
+ return allSeedMCs;
+ }
+
+ private OccurrenceCounter<MCParticle> getMCCounter(List<SeedLayer> layers, HitManager hm) {
+
+ OccurrenceCounter<MCParticle> MCCounter = new OccurrenceCounter<MCParticle>();
+ for (SeedLayer l : layers) {
+
+ List<HelicalTrackHit> th = hm.getTrackerHits(l.getDetName(), l.getLayer(), l.getBarrelEndcapFlag());
+ for (HelicalTrackHit h : th) {
+ MCCounter.addAll(h.getMCParticles());
+ }
+ }
+
+ return MCCounter;
+ }
+
+ //utility class to count occurrences of stuff... A map of the object to
+ // number of occurrences
+ class OccurrenceCounter<T> {
+
+ Map<T,Integer> map;
+
+ public OccurrenceCounter(){
+ map = new HashMap<T,Integer>();
+ }
+
+ public void add(T obj){
+
+ if(map.containsKey(obj)){
+ int curr = map.get(obj);
+ map.put(obj, curr+1);
+ }
+ else map.put(obj, 1);
+ }
+
+ public void addAll(Collection<T> coll){
+ for (T t : coll)
+ add(t);
+ }
+
+ public int getCount(T obj) {
+
+ if (map.containsKey(obj))
+ return map.get(obj).intValue();
+ else return 0;
+ }
+
+ public Set<T> keySet() {
+ return map.keySet();
+ }
+
+ public Set<T> getAllWithCountGreater(int min) {
+
+ Set<T> ret = new HashSet<T>();
+ for (T t : map.keySet()) {
+ if (map.get(t).intValue() >= min)
+ ret.add(t);
+ }
+ return ret;
+ }
+ }
+
+}
lcsim/src/org/lcsim/contrib/seedtracker
diff -u -r1.2 -r1.3
--- SeedTrackerDiagnostics.java 21 Apr 2008 03:59:28 -0000 1.2
+++ SeedTrackerDiagnostics.java 21 Apr 2008 09:07:21 -0000 1.3
@@ -26,16 +26,14 @@
private double b_field;
private EventHeader ev;
-
- private double mcth_min=0.;
- private double mcth_max=0.9;
- private double mcth_step = 0.1;
-
+ private HitManager hm;
private double purity_cutoff = 0.0;
- public SeedTrackerDiagnostics(EventHeader event, double b_field){
+
+ public SeedTrackerDiagnostics(EventHeader event, double b_field, HitManager hm){
this.ev = event;
this.b_field = b_field;
+ this.hm = hm;
}
/**
@@ -50,23 +48,6 @@
Set<MCParticle> likelyMCs = generateLikelyMCSet(vmap);
makeEfficiencyPlots(likelyMCs,strategy);
}
- /**
- * 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
@@ -128,19 +109,12 @@
private void makeEfficiencyPlots(Set<MCParticle> likelyMCs, SeedStrategy strat){
- FindableTrackParams findable = new FindableTrackParams(strat);
+ FindableTracks findable = new FindableTracks(strat, hm);
findable.setBField(b_field);
List<MCParticle> MCs = ev.getMCParticles();
- //cycle through all the minCosTheta's we're interested in...
- for (double d = mcth_min; d <= mcth_max+0.00001; d+=mcth_step ) {
-
- findable.setMinCosTheta(d);
-
- List<MCParticle> temp = new ArrayList<MCParticle>();
- temp.addAll(MCs);
- Iterator iter = temp.iterator();
+ Iterator iter = MCs.iterator();
//remove all none findable MCs
while(iter.hasNext()){
@@ -149,22 +123,21 @@
iter.remove();
}
- int numFindable = temp.size();
- aida.cloud1D("Num findable/ minCosTheta = "+String.valueOf(d)).fill(numFindable);
+ int numFindable = MCs.size();
+ aida.cloud1D("Number findable").fill(numFindable);
// remove all the MC's we've found... this gives us findable - found
- temp.removeAll(likelyMCs);
+ MCs.removeAll(likelyMCs);
- int numFound = numFindable - temp.size(); // findable - (findable - found) = found
+ int numFound = numFindable - MCs.size(); // findable - (findable - found) = found
- aida.cloud1D("Num found (purity cutoff="+purity_cutoff+") / minCosTheta = " + String.valueOf(d)).fill(numFound);
+ aida.cloud1D("Num found (purity cutoff="+purity_cutoff+") ").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);
+ aida.cloud1D("Efficiency").fill(eff);
}
- }
+
}
}
lcsim/src/org/lcsim/contrib/seedtracker
diff -u -r1.10 -r1.11
--- SeedTracker.java 13 Apr 2008 01:22:45 -0000 1.10
+++ SeedTracker.java 21 Apr 2008 09:07:21 -0000 1.11
@@ -76,7 +76,7 @@
mergeseedlists.makeBadDecisionPlots(PERFORM_DIAGNOSTICS); // make plots if performing diagnostics...
// Instantiate diagnostics
- SeedTrackerDiagnostics diagnostics = new SeedTrackerDiagnostics(event,bfield);
+ SeedTrackerDiagnostics diagnostics = new SeedTrackerDiagnostics(event,bfield,hitmanager);
// Instantiate the Track Maker
MakeTracks maketracks = new MakeTracks();