View Javadoc

1   package org.lcsim.recon.tracking.trfcyl;
2   
3   import org.lcsim.recon.tracking.trfutil.Assert;
4   
5   import org.lcsim.recon.tracking.trfbase.HitGenerator;
6   import org.lcsim.recon.tracking.trfbase.Surface;
7   import org.lcsim.recon.tracking.trfbase.Cluster;
8   import org.lcsim.recon.tracking.trfbase.VTrack;
9   import org.lcsim.recon.tracking.trfbase.CrossStat;
10  
11  /**
12   * Generates HitCylPhi hits on a cylindrical surface with a gaussian spread in the measurement.
13   *
14   *@author Norman A. Graf
15   *@version 1.0
16   *
17   */
18  public class HitCylPhiGenerator extends HitGenerator
19  {
20      
21      // attributes
22      
23      // the surface
24      private  Surface  _srf;
25      
26      // Error (standard deviation) for the measurement.
27      private double _dphi;
28      
29      //
30      private boolean debug;
31      
32      /**
33       *Construct an instance from a cylinder surface and the measurement uncertainty as a gaussian sigma.
34       * The cylinder is cloned so user can pass subclass.
35       *
36       * @param   srf The cylindrical surface.
37       * @param   dphi The gaussian sigma for the phi measurement uncertainty.
38       */
39      public HitCylPhiGenerator(  SurfCylinder srf, double dphi)
40      {
41          super();
42          _srf = srf.newSurface();
43          //_srf = new SurfCylinder(srf);
44          _dphi =dphi;
45          Assert.assertTrue( _dphi >= 0.0 );
46      }
47      
48      //
49      
50      /**
51       *Construct an instance from a cylinder surface, the measurement uncertainty
52       *and a random number seed.
53       * The cylinder is cloned so user can pass subclass.
54       *
55       * @param   srf The cylindrical surface.
56       * @param   dphi The gaussian sigma for the phi measurement uncertainty.
57       * @param   seed The seed for the random number used by the HitGenerator.
58       */
59      public HitCylPhiGenerator(  SurfCylinder srf, double dphi, long seed)
60      {
61          super(seed);
62          _srf = srf.newSurface();
63          // _srf = new SurfCylinder(srf);
64          _dphi =dphi;
65          Assert.assertTrue( _dphi >= 0.0 );
66          
67      }
68      
69      //
70      
71      /**
72        *Construct an instance replicating the HitCylPhiGenerator ( copy constructor ).
73       *
74       * @param   hgen The HitCylPhiGenerator to replicate.
75       */
76      public HitCylPhiGenerator(  HitCylPhiGenerator hgen)
77      {
78          super(hgen);
79          _srf = hgen._srf;
80          _dphi = hgen._dphi;
81          Assert.assertTrue( _dphi >= 0.0 );
82          
83      }
84      
85      //
86      
87      /**
88       *Return the surface associated with this HitCylPhiGenerator.
89       *
90       * @return The surface associated with this HitCylPhiGenerator.
91       */
92      public Surface surface()
93      { return _srf; }
94      
95      //
96      
97      
98      /**
99       *Generate a new cluster.
100      * Return null for failure.
101      *
102      * @param   trv The VTrack for which to generate a cluster at this surface.
103      * @return   The cluster for this track at this surface, null for failure.
104      */
105     public Cluster newCluster( VTrack trv )
106     {
107         return newCluster( trv, 0 );
108     }
109     
110     
111     /**
112      *Generate a new cluster with the specified Monte Carlo track ID.
113      * Return null for failure.
114      *
115     * @param   trv The VTrack for which to generate a cluster at this surface.
116      * @param   mcid The MC ID to associate with this cluster.
117      * @return   The cluster for this track at this surface, null for failure.
118      */
119     public Cluster newCluster( VTrack trv, int mcid )
120     {
121         
122         // Create null cluster.
123         Cluster clu = null;
124         
125         // Check track has been propagated to the surface.
126         Assert.assertTrue( _srf.pureEqual( trv.surface() ) );
127         if ( ! _srf.pureEqual( trv.surface() ) ) return clu;
128         
129         // Require that track is in bounds if surface is bounded.
130         CrossStat xstat =_srf.status(trv);
131         if(debug) System.out.println("Surface: "+_srf + "\n Status: "+xstat);
132         if ( (! _srf.isPure()) && (! xstat.inBounds()) ) return clu;
133         
134         // calculate phi.
135         double phi = trv.vector().get(0) + _dphi*gauss();
136         
137         // construct cluster
138         double radius = _srf.parameter(SurfCylinder.RADIUS);
139         clu = new ClusCylPhi( radius, phi, _dphi, mcid );
140         return clu;
141         
142     }
143     
144     
145     /**
146      *output stream
147      *
148      * @return A String representation of this instance.
149      */
150     public String toString()
151     {
152         StringBuffer sb = new StringBuffer("HitCylPhi Generator at \n" + surface()
153         + "\nMeasurement error (dphi): " + _dphi);
154         sb.append(super.toString());
155         return sb.toString();
156         
157     }
158 }