View Javadoc

1   /*
2    * MergeSeedLists.java
3    *
4    * Created on February 6, 2008, 9:54 AM
5    *
6    */
7   package org.lcsim.recon.tracking.seedtracker;
8   
9   import java.util.ArrayList;
10  import java.util.List;
11  
12  import org.lcsim.fit.helicaltrack.HelicalTrackHit;
13  import org.lcsim.recon.tracking.seedtracker.diagnostic.ISeedTrackerDiagnostics;
14  
15  /**
16   *
17   * @author Richard Partridge
18   * @version 1.0
19   */
20  public class MergeSeedLists {
21  
22      private ISeedTrackerDiagnostics _diag = null;
23  
24      /** Creates a new instance of MergeSeedLists */
25      public MergeSeedLists() {
26      }
27  
28      public void setDiagnostic(ISeedTrackerDiagnostics diagnostic) {
29          _diag = diagnostic;
30      }
31  
32      public boolean Merge(List<SeedCandidate> seedlist, SeedCandidate newseed, SeedStrategy strategy) {
33  //        if(diag!=null) diag.fireMergeStartDiagnostics(newseedlist);
34  
35          //  Assume the new seed is better than all duplicates
36          boolean best = true;
37          
38          //  Create a list of duplicates that are inferior
39          List<SeedCandidate> duplist = new ArrayList<SeedCandidate>();
40  
41          //  Loop over all existing seeds
42          for (SeedCandidate seed : seedlist) {
43  
44              //  See if the new seed is considered a duplicate of the current seed
45              boolean dupe = isDuplicate(newseed, seed);
46  
47              if (dupe) {
48  
49                  //  Check if the new seed is better than the existing seed
50                  boolean better = isBetter(newseed, seed, strategy);
51  
52                  if (better) {
53  
54                      //  If the new seed is better, add the existing seed to the list for deletion
55                      duplist.add(seed);
56  
57                  } else {
58  
59                      //  If the new seed is inferior to an existing seed, leave everything unchanged
60                      best = false;
61                      if (_diag != null) _diag.fireMergeKillingNewSeed(seed, newseed);
62                      break;
63                  }
64              }
65          }
66  
67          //  If the new seed is better than all duplicates, add it to the seed list and remove duplicates
68          if (best) {
69              seedlist.add(newseed);
70              for (SeedCandidate seed : duplist) {
71                  seedlist.remove(seed);
72                  if (_diag != null) _diag.fireMergeKillingOldSeed(seed, newseed);
73              }
74          }
75  
76          return best;
77      }
78  
79      public boolean isDuplicate(SeedCandidate seed1, SeedCandidate seed2) {
80          int nduplicate = 0;
81          for (HelicalTrackHit hit1 : seed1.getHits()) {
82              for (HelicalTrackHit hit2 : seed2.getHits()) {
83                  if (hit1 == hit2) {
84                      nduplicate++;
85                      if (nduplicate > 1) {
86                          return true;
87                      }
88                  }
89              }
90          }
91          return false;
92      }
93  
94      public boolean isBetter(SeedCandidate newseed, SeedCandidate oldseed, SeedStrategy strategy) {
95          int hitdif = newseed.getHits().size() - oldseed.getHits().size();
96          double chisqdif = newseed.getHelix().chisqtot() - oldseed.getHelix().chisqtot();
97          if (hitdif > 1) {
98              return true;
99          }
100         if (hitdif == 1) {
101             return chisqdif < strategy.getBadHitChisq();
102         }
103         if (hitdif == 0) {
104             return chisqdif < 0.;
105         }
106         if (hitdif == -1) {
107             return chisqdif < -strategy.getBadHitChisq();
108         }
109         return false;
110     }
111 }