View Javadoc

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