View Javadoc

1   package org.lcsim.recon.tracking.trffit;
2   import java.util.List;
3   import java.util.ArrayList;
4   import java.util.Iterator;
5   
6   import org.lcsim.recon.tracking.trfutil.RandomGenerator;
7   
8   import org.lcsim.recon.tracking.trfbase.Surface;
9   import org.lcsim.recon.tracking.trfbase.Cluster;
10  import org.lcsim.recon.tracking.trfbase.Hit;
11  import org.lcsim.recon.tracking.trfbase.Propagator;
12  import org.lcsim.recon.tracking.trfbase.PropStat;
13  import org.lcsim.recon.tracking.trfbase.TrackVector;
14  import org.lcsim.recon.tracking.trfbase.HitGenerator;
15  import org.lcsim.recon.tracking.trfbase.VTrack;
16  import org.lcsim.recon.tracking.trfbase.ETrack;
17  import org.lcsim.recon.tracking.trfbase.TrackError;
18  
19  /**
20   * Generates an HTrack from a VTrack using its track error matrix
21   * and a list of hit generators.  The VTrack is propagated to each
22   * of the hit generator surfaces and used to generate a cluster which
23   * is in turn used to generate a hit.  This is repeated until a hit is
24   * succesfully produced at each surface.  The first hit from each
25   * surface is assigned to the HTrack.
26   *
27   *@author Norman A. Graf
28   *@version 1.0
29   *
30   */
31  
32  
33  public class HTrackGenerator extends RandomGenerator
34  {
35      
36      // The Hit generators.
37      private List _hgens;
38      
39      // The starting surface.
40      private Surface _srf;
41      
42      // The track error matrix.
43      private TrackError _terr;
44      
45      // Propagator.
46      private Propagator _prop;
47      
48      /**
49       *Construct an instance from a list of HitGenerators, a Propagator,
50       * a starting Surface and a track error.
51       *
52       * @param   hgens The list of HitGenerators.
53       * @param   prop  The Propagator for propagating the track.
54       * @param   srf   The Surface at which to start the track.
55       * @param   terr  The starting TrackError.
56       */
57      public HTrackGenerator(  List hgens,   Propagator prop,
58              Surface srf,   TrackError terr)
59      {
60          _hgens = hgens;
61          _terr = new TrackError(terr);
62          _prop = prop.newPropagator();
63          _srf = srf.newPureSurface();
64      }
65      
66      //
67      
68      /**
69       *Return a new HTrack.
70       * Return null for failure.
71       *
72       * @param   trv The starting VTrack.
73       * @return  The HTrack containing hits.
74       */
75      public HTrack newTrack(  VTrack trv)
76      {
77          HTrack trh = null;
78          VTrack newtrv = new VTrack(trv);
79          // Create new list of hits.
80          List track_hits = new ArrayList();
81          // Loop over hit surfaces.
82          
83          for ( Iterator ihgen=_hgens.iterator(); ihgen.hasNext(); )
84          {
85              HitGenerator hgen = (HitGenerator) ihgen.next();
86              // Propagate to the surface.
87              PropStat pstat = _prop.vecProp(newtrv,hgen.surface());
88              if ( ! pstat.success() ) break;
89              // Generate a cluster.
90              Cluster clu = hgen.newCluster(newtrv,0);
91              if ( clu == null ) break;
92              // Generate a hit.
93              List hits = clu.predict( new ETrack(newtrv,_terr), clu );
94              if ( hits.size() == 0 ) break;
95              track_hits.add( hits.get(0) );
96          }
97          // If the number of assigned does not equal the number of hit
98          // generators, all hits were not found.  Exit with error.
99          if ( track_hits.size() != _hgens.size() ) return trh;
100         // Propagate to the surface.
101         VTrack starttrv = new VTrack(trv);
102         PropStat pstat = _prop.vecProp(starttrv,_srf);
103         if ( ! pstat.success() ) return trh;
104         ETrack tre = new ETrack(starttrv,_terr);
105         trh = new HTrack(tre);
106         
107         for ( Iterator ihit=track_hits.iterator(); ihit.hasNext(); )
108             trh.addHit((Hit) ihit.next());
109         return trh;
110     }
111     
112     
113     /**
114      * Output stream
115      *
116      * @return String representation of the class
117      */
118     public String toString()
119     {
120         return getClass().getName();
121     }
122     
123 }