View Javadoc

1   /*
2    * MakeTracks.java
3    *
4    * Created on February 6, 2008, 11:40 AM
5    *
6    */
7   
8   package org.lcsim.recon.tracking.seedtracker;
9   
10  import java.util.ArrayList;
11  import java.util.List;
12  
13  import org.lcsim.event.EventHeader;
14  import org.lcsim.event.Track;
15  import org.lcsim.event.TrackerHit;
16  import org.lcsim.fit.helicaltrack.HelicalTrackFit;
17  import org.lcsim.fit.helicaltrack.HelicalTrackHit;
18  import org.lcsim.lcio.LCIOConstants;
19  
20  /**
21   * Create a list of SeedTracks from a list of SeedCandidates that have passed
22   * the SeedTracker algorithm and store these tracks back into the event.
23   * @author Richard Partridge
24   * @version 1.0
25   */
26  public class MakeTracks {
27  
28      private String _TrkCollectionName = "Tracks";
29      TrackCheck _trackCheck; // set by SeedTracker
30  
31      /**
32       * Creates a new instance of MakeTracks.
33       */
34      public MakeTracks() {
35      }
36      
37      /**
38       * Process a list of SeedCandidates to make a list of SeedTracks and store
39       * these tracks back into the event.
40       * @param event event header
41       * @param seedlist list of SeedCandidates that are to be turned into tracks
42       * @param bfield magnetic field (used to turn curvature into momentum)
43       */
44      public void Process(EventHeader event, List<SeedCandidate> seedlist, double bfield) {
45          
46          //  Create a the track list
47          List<Track> tracks = new ArrayList<Track>();
48          
49          //  Initialize the reference point to the origin
50          double[] ref = new double[] {0., 0., 0.};
51          
52          //  Loop over the SeedCandidates that have survived
53          for (SeedCandidate trackseed : seedlist) {
54              
55              //  Create a new SeedTrack (SeedTrack extends BaseTrack)
56              SeedTrack trk = new SeedTrack();
57              
58              //  Add the hits to the track
59              for (HelicalTrackHit hit : trackseed.getHits()) {
60                  trk.addHit((TrackerHit) hit);
61              }
62              
63              //  Retrieve the helix and save the relevant bits of helix info
64              HelicalTrackFit helix = trackseed.getHelix();
65              trk.setTrackParameters(helix.parameters(), bfield); // Sets first TrackState.
66              trk.setCovarianceMatrix(helix.covariance()); // Modifies first TrackState.
67              trk.setChisq(helix.chisqtot());
68              trk.setNDF(helix.ndf()[0]+helix.ndf()[1]);
69              
70              //  Flag that the fit was successful and set the reference point
71              trk.setFitSuccess(true);
72              trk.setReferencePoint(ref); // Modifies first TrackState.
73              trk.setRefPointIsDCA(true);
74              
75              //  Set the strategy used to find this track
76              trk.setStratetgy(trackseed.getSeedStrategy());
77              
78              //  Set the SeedCandidate this track is based on
79              trk.setSeedCandidate(trackseed);
80  
81              // Check the track - hook for plugging in external constraint
82              if ((_trackCheck != null) && (! _trackCheck.checkTrack(trk))) continue;
83  
84              //  Add the track to the list of tracks
85              tracks.add((Track) trk);
86          }
87          
88          // Put the tracks back into the event and exit
89          int flag = 1<<LCIOConstants.TRBIT_HITS;
90          event.put(_TrkCollectionName, tracks, Track.class, flag);
91          
92          return;
93      }
94  
95      public void setTrkCollectionName(String name) {
96          _TrkCollectionName = name;
97      }
98      public void setTrackCheck(TrackCheck trackCheck){
99          _trackCheck=trackCheck;
100     }
101 }