lcsim/src/org/lcsim/contrib/seedtracker
diff -N SeedValidator.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ SeedValidator.java 1 Apr 2008 22:45:05 -0000 1.1
@@ -0,0 +1,172 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.lcsim.contrib.seedtracker;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.lcsim.event.MCParticle;
+import org.lcsim.fit.helicaltrack.HelicalTrackHit;
+
+/**
+ *
+ * @author cozzy
+ */
+public class SeedValidator {
+
+ private SeedCandidate candidate;
+ private MCParticle likelyMC;
+ private Map<MCParticle,Integer> occurs;
+ private SeedVerdict verdict;
+
+ public enum SeedVerdict{
+ SEED_VALID_BUT_MULTIPLE_MCS_IN_HITS,
+ SEED_VALID,
+ SEED_INVALID,
+ MULTIPLE_POSSIBLE_MCS,
+ GET_MCPARTICLES_FAILED;
+
+ public boolean isGoodValue(){
+ return (this==SEED_VALID || this == SEED_VALID_BUT_MULTIPLE_MCS_IN_HITS);
+ }
+ }
+
+
+ public SeedValidator(SeedCandidate s){
+ candidate = s;
+ occurs = getOccurrences(s);
+ evaluateOccurrences();
+ }
+
+ private void evaluateOccurrences() {
+
+ //this will happen if getMCParticles fails for whatever reason;
+ if(occurs == null) {
+ verdict = SeedVerdict.GET_MCPARTICLES_FAILED;
+ return;
+ }
+
+ //if there's only one MCParticle in the map, then that's the one we want.
+ if(occurs.size()==1) {
+ likelyMC = (MCParticle) occurs.keySet().toArray()[0];
+ verdict = SeedVerdict.SEED_VALID;
+ return;
+ }
+
+
+ //get a list of the MCParticles that appear in all the hits
+ List<MCParticle> mcs_in_all_hits = new ArrayList<MCParticle>();
+ int size = candidate.getHits().size();
+
+ for (MCParticle p : occurs.keySet()){
+ if(occurs.get(p).intValue()==size){
+ mcs_in_all_hits.add(p);
+ }
+ }
+
+ //if no MCParticles meet this criteria, we have a baad seed.
+ if (mcs_in_all_hits.size()==0){
+ verdict = SeedVerdict.SEED_INVALID;
+ return;
+ }
+
+ //if there are multiple MCs meeting this criteria, that's also problematic
+ if (mcs_in_all_hits.size()>1){
+ verdict = SeedVerdict.MULTIPLE_POSSIBLE_MCS;
+ return;
+ }
+
+ verdict = SeedVerdict.SEED_VALID;
+ likelyMC = mcs_in_all_hits.get(0);
+
+ }
+
+
+ public SeedVerdict getVerdict(){
+ return verdict;
+ }
+
+ public MCParticle getLikelyMC(){
+ return likelyMC;
+ }
+
+
+ public enum NewAdditionVerdict{
+ ADDITION_IS_GOOD,
+ ADDITION_IS_GOOD_BUT_MULTIPLE_MCS,
+ ADDITION_IS_BAD,
+ SEED_IS_BAD_OR_CANNOT_DETERMINE;
+
+ public boolean isGoodValue(){
+ return (this==ADDITION_IS_GOOD ||
+ this==ADDITION_IS_GOOD_BUT_MULTIPLE_MCS);
+ }
+ }
+
+
+ /**
+ * Determines whether or not this hit is a good hit to add.
+ *
+ * @param A helical track hit.
+ * @return a NewAdditionVerdict enum
+ */
+
+ public NewAdditionVerdict isGoodAddition(HelicalTrackHit h){
+ if (likelyMC==null)
+ return NewAdditionVerdict.SEED_IS_BAD_OR_CANNOT_DETERMINE;
+
+ List<MCParticle> parts = h.getMCParticles();
+
+ if (parts==null)
+ return NewAdditionVerdict.SEED_IS_BAD_OR_CANNOT_DETERMINE;
+
+ if(!parts.contains(likelyMC))
+ return NewAdditionVerdict.ADDITION_IS_BAD;
+
+ if(parts.size()==1)
+ return NewAdditionVerdict.ADDITION_IS_GOOD;
+
+ return NewAdditionVerdict.ADDITION_IS_GOOD_BUT_MULTIPLE_MCS;
+ }
+
+
+
+ /**
+ * Given a seed candidate, this returns a map of MCParticles to the number
+ * of hits in the seed candidate containing them.
+ *
+ * Returns null if getMCParticles fails on a hit.
+ *
+ * This is static because it might be useful for some other purpose...
+ *
+ * @param s a SeedCandidate
+ * @return a map of MCParticles to number of hits containing that MCParticle,
+ * or null if getMCParticles fails.
+ */
+ public static Map<MCParticle,Integer> getOccurrences(SeedCandidate s){
+
+ Map<MCParticle,Integer> occurrences = new HashMap<MCParticle,Integer>();
+
+ for (HelicalTrackHit h : s.getHits()){
+
+ List<MCParticle> mcs = h.getMCParticles();
+ if (mcs == null) return null;
+
+ for (MCParticle p : mcs) {
+ if(!occurrences.containsKey(p)){
+ occurrences.put(p, 1);
+ }
+ else {
+ int currVal = occurrences.get(p);
+ occurrences.put(p,currVal+1);
+ }
+ }
+ }
+
+ return occurrences;
+ }
+}
lcsim/src/org/lcsim/contrib/seedtracker
diff -u -r1.2 -r1.3
--- MergeSeedLists.java 13 Feb 2008 02:31:33 -0000 1.2
+++ MergeSeedLists.java 1 Apr 2008 22:45:05 -0000 1.3
@@ -7,10 +7,12 @@
package org.lcsim.contrib.seedtracker;
+import hep.physics.vec.Hep3Vector;
import java.util.List;
import java.util.ListIterator;
import org.lcsim.fit.helicaltrack.HelicalTrackHit;
+import org.lcsim.util.aida.AIDA;
/**
*
@@ -19,10 +21,15 @@
*/
public class MergeSeedLists {
+ private AIDA aida = AIDA.defaultInstance();
+ private static final boolean VALIDATE=true;
+
+
/** Creates a new instance of MergeSeedLists */
public MergeSeedLists() {
}
+
public void Merge(List<SeedCandidate> seedlist, List<SeedCandidate> newseedlist, SeedStrategy strategy) {
System.out.println(" Extended seeds before merging"+newseedlist.size());
for (SeedCandidate newseed : newseedlist ) {
@@ -33,6 +40,16 @@
if (isDuplicate(newseed, seed)) {
duplicate = true;
if (isBetter(newseed, seed, strategy)) {
+
+ if(VALIDATE){
+ SeedValidator oldV = new SeedValidator(seed);
+ SeedValidator newV = new SeedValidator(newseed);
+
+ if (oldV.getVerdict().isGoodValue() && !newV.getVerdict().isGoodValue()){
+ makeBadDecisionPlots(newseed,seed, oldV,newV);
+ }
+ }
+
itr.set(newseed);
}
break;
@@ -41,6 +58,24 @@
if (!duplicate) seedlist.add(newseed);
}
System.out.println(" After merging: "+seedlist.size());
+
+ if(VALIDATE) {
+ for (SeedCandidate s : seedlist){
+
+ SeedValidator v = new SeedValidator(s);
+ if (v.getVerdict().isGoodValue()) {
+ aida.cloud1D("Good seeds chisq").fill(s.getHelix().chisqtot());
+ aida.cloud1D("Good seeds numhits").fill(s.getHits().size());
+ aida.cloud1D("Good seeds pt").fill(s.getHelix().pT(5.0));
+ }
+
+ else {
+ aida.cloud1D("Bad seeds chisq").fill(s.getHelix().chisqtot());
+ aida.cloud1D("Bad seeds numhits").fill(s.getHits().size());
+ aida.cloud1D("Bad seeds pt").fill(s.getHelix().pT(5.0));
+ }
+ }
+ }
return;
}
@@ -66,4 +101,21 @@
if (hitdif == -1) return chisqdif < -strategy.getBadHitChisq();
return false;
}
+
+ private void makeBadDecisionPlots(SeedCandidate newseed, SeedCandidate seed, SeedValidator oldV, SeedValidator newV) {
+
+ aida.cloud1D("Bad Decision newseed chisq").fill(newseed.getHelix().chisqtot());
+ aida.cloud1D("Bad Decision oldseed chisq").fill(seed.getHelix().chisqtot());
+ aida.cloud2D("Bad Decision newseed vs. oldseed chisq").fill(newseed.getHelix().chisqtot(), seed.getHelix().chisqtot());
+
+ Hep3Vector p = oldV.getLikelyMC().getMomentum();
+ double pt = Math.sqrt(p.x() * p.x() + p.y() * p.y());
+ aida.cloud1D("Bad Decision real particle transverse momentum").fill(pt);
+
+ Hep3Vector r = oldV.getLikelyMC().getOrigin();
+ double rc = Math.sqrt(r.x()*r.x()+r.y()*r.y());
+ aida.cloud1D("Bad Decision real particle start radius (cylindrical)").fill(rc);
+
+ }
}
+
\ No newline at end of file