View Javadoc

1   /*
2    * SeedTrackFinder.java
3    *
4    * Created on January 22, 2008, 9:39 AM
5    *
6    */
7   package org.lcsim.recon.tracking.seedtracker;
8   
9   import java.util.ArrayList;
10  import java.util.HashSet;
11  import java.util.List;
12  
13  import java.util.Set;
14  import org.lcsim.event.MCParticle;
15  import org.lcsim.fit.helicaltrack.HelicalTrackHit;
16  import org.lcsim.recon.tracking.seedtracker.diagnostic.ISeedTrackerDiagnostics;
17  
18  /**
19   *
20   * @author Richard Partridge
21   * @version 1.0
22   */
23  public class SeedTrackFinder {
24  
25      private HitManager _hitmanager;
26      private HelixFitter _helixfitter;
27      private ConfirmerExtender _confirmer;
28      private List<SeedCandidate> _trackseeds;
29      private ISeedTrackerDiagnostics _diag = null;
30      private Set<MCParticle> _seededmcp;
31      private Set<MCParticle> _confirmedmcp;
32      TrackCheck _trackCheck; // set by SeedTracker
33      private boolean _debug = false;
34      private boolean _applySectorBinning = false;
35  
36      /**
37       * Creates a new instance of SeedTrackFinder
38       */
39      public SeedTrackFinder(HitManager hitmanager, HelixFitter helixfitter) {
40  
41          //  Save the pointers to the hit manager and helix fitter classes
42          _hitmanager = hitmanager;
43          _helixfitter = helixfitter;
44  
45          //  Instantiate the Confirmer/Extender and Seed Candidate merging classes
46          _confirmer = new ConfirmerExtender(_hitmanager, _helixfitter);
47  
48          //  Create a list of track seeds that have been found
49          _trackseeds = new ArrayList<SeedCandidate>();
50  
51          //  Create a set of MC Particles that have been seeded, confirmed
52          _seededmcp = new HashSet<MCParticle>();
53          _confirmedmcp = new HashSet<MCParticle>();
54  
55      }
56  
57      public void setDiagnostic(ISeedTrackerDiagnostics d) {
58  
59          //  Setup the diagnostics for this class and the classes used by this class
60          _diag = d;
61          _confirmer.setDiagnostics(_diag);
62      }
63  
64      public boolean FindTracks(SeedStrategy strategy, double bfield) {
65  
66          //  Instantiate the fast hit checker
67          FastCheck checker = new FastCheck(strategy, bfield, _diag);
68          if(_applySectorBinning) checker.setDoSectorBinCheck(_hitmanager.getSectorManager());
69          
70          //  Find the valid sector combinations
71          SeedSectoring ss = new SeedSectoring(_hitmanager, strategy, bfield,_applySectorBinning);
72          List<List<Sector>> sslist = ss.SeedSectors();
73  
74          //  Loop over the valid sector combinations
75          for (List<Sector> slist : sslist) {
76  
77              //  Loop over the first seed layer
78              for (HelicalTrackHit hit1 : slist.get(0).Hits()) {
79  
80                  //  Loop over the second seed layer and check that we have a hit pair consistent with our strategy
81                  for (HelicalTrackHit hit2 : slist.get(1).Hits()) {
82                      
83                      //  Call _trackCheck if set
84                      if (_trackCheck != null) {
85                          SeedCandidate tempseed = new SeedCandidate(strategy, bfield);
86                          tempseed.addHit(hit1);
87                          tempseed.addHit(hit2);
88                          if (!_trackCheck.checkSeed(tempseed)) continue;
89                      }
90  
91                      //  Check if the pair of hits is consistent with the current strategy
92                      if (!checker.TwoPointCircleCheck(hit1, hit2, null)) {
93                          if (_diag != null) _diag.fireCheckHitPairFailed(hit1, hit2);
94                          continue;
95                      }
96  
97                      //  Loop over the third seed layer and check that we have a hit triplet consistent with our strategy
98                      for (HelicalTrackHit hit3 : slist.get(2).Hits()) {
99                          
100                         //  Call _trackCheck if set
101                         if (_trackCheck != null) {
102                             SeedCandidate tempseed2 = new SeedCandidate(strategy, bfield);
103                             tempseed2.addHit(hit1);
104                             tempseed2.addHit(hit3);
105                             if (!_trackCheck.checkSeed(tempseed2)) continue;
106 
107                             SeedCandidate tempseed3 = new SeedCandidate(strategy, bfield);
108                             tempseed3.addHit(hit2);
109                             tempseed3.addHit(hit3);
110                             if (!_trackCheck.checkSeed(tempseed3)) continue;
111                         }
112 
113                         //  Form a seed candidate from the seed hits
114                         SeedCandidate seed = new SeedCandidate(strategy, bfield);
115                         seed.addHit(hit1);
116                         seed.addHit(hit2);
117                         seed.addHit(hit3);
118 
119                         //  Check if the triplet of hits is consistent with the current strategy
120                         if (!checker.ThreePointHelixCheck(hit1, hit2, hit3)) {
121 
122                             if (_diag != null) {
123                                 if (seed.isTrueSeed())
124                                 _diag.fireCheckHitTripletFailed(hit1, hit2, hit3);
125                             }
126                             continue;
127                         }
128 
129                         //  Form a seed candidate from the seed hits
130 
131                         //  If it's a true seed, add the MC Particle to those that were seeded
132                         if (_diag != null)
133                             if (seed.isTrueSeed())
134                                 _seededmcp.addAll(seed.getMCParticles());
135 
136                         if(_debug) System.out.println(this.getClass().getSimpleName()+": fit the candidate");
137                         
138                         
139                         //  See if we can fit a helix to this seed candidate
140                         boolean success = _helixfitter.FitCandidate(seed, strategy);
141 
142                         if (!success) continue;
143 
144                         if(_debug) System.out.println(this.getClass().getSimpleName()+": fit success");
145 
146                         //  Save the helix fit
147                         seed.setHelix(_helixfitter.getHelix());
148 
149                         // Check the seed - hook for plugging in external constraint
150                         if (_trackCheck != null) {
151                             if (!_trackCheck.checkSeed(seed)) continue;
152                         }
153 
154                         //  See if we can confirm this seed candidate
155                         success = _confirmer.Confirm(seed, strategy, bfield);
156                         if (!success) continue;
157 
158                         if(_debug) System.out.println(this.getClass().getSimpleName()+": confirmed seed");
159                         
160                         //  Confirmed a seed - if it's a true seed, add the MC Particle to those that were confirmed
161                         if (_diag != null)
162                             if (seed.isTrueSeed())
163                                 _confirmedmcp.addAll(seed.getMCParticles());
164 
165                         if(_debug) System.out.println(this.getClass().getSimpleName()+": try to extend");
166                         
167                         //  Try to extend each confirmed seed candidates to make a track candidate
168                         List<SeedCandidate> confirmedlist = _confirmer.getResult();
169                         for (SeedCandidate confirmedseed : confirmedlist) {
170 
171                             //  See if we can extend this seed candidate
172                             _confirmer.Extend(confirmedseed, strategy, bfield, _trackseeds);
173                         }
174                     }
175                 }
176             }
177         }
178 
179         //  Done with track finding for this strategy
180         if (_diag != null)
181             _diag.fireFinderDone(_trackseeds, _seededmcp);
182 
183         return _trackseeds.size() > 0;
184     }
185 
186     /**
187      * Return the list of track candidates.
188      *
189      * @return track candidates
190      */
191     public List<SeedCandidate> getTrackSeeds() {
192         return _trackseeds;
193     }
194 
195     /**
196      * Clear the list of track candidates accumulated from previous calls to
197      * SeedTrackFinder (typically done before starting a new event).
198      */
199     public void clearTrackSeedList() {
200         _trackseeds.clear();
201         _seededmcp.clear();
202         _confirmedmcp.clear();
203     }
204 
205     /**
206      * Set the maximum number of fits for a given seed in a confirm or extend step.
207      *  
208      * @param maxfits maximum number of fits
209      */
210     public void setMaxFit(int maxfits) {
211         _confirmer.setMaxFit(maxfits);
212     }
213     
214      /**
215      * Set to enable the sectoring to use the sector bins in checking for consistent hits.
216      *
217      * @param applySectorBinning apply sector binning switch
218      */
219     public void setApplySectorBinning(boolean applySectorBinning) {
220         this._applySectorBinning = applySectorBinning;
221     }
222     
223     /**
224      * Return the list of MCParticles that formed valid 3-hit seeds.
225      *
226      * @return list of seeded MCParticles
227      */
228     public Set<MCParticle> getSeededMCParticles() {
229         return _seededmcp;
230     }
231 
232     /**
233      * Return the list of confirmed MCParticles.
234      *
235      * @return confirmed MCParticles
236      */
237     public Set<MCParticle> getConfirmedMCParticles() {
238         return _confirmedmcp;
239     }
240 
241     /**
242      * Return the ConfirmerExtender
243      * 
244      * @return confirmer/extender object
245      * 
246      */
247     public ConfirmerExtender getConfirmer() {
248         return _confirmer;
249     }
250     
251 }