View Javadoc

1   package  org.lcsim.recon.tracking.trfzp;
2   
3   // Generator for ClusZPlane2 objects.
4   
5   import org.lcsim.recon.tracking.trfutil.Assert;
6   
7   import org.lcsim.recon.tracking.trfbase.HitGenerator;
8   import org.lcsim.recon.tracking.trfbase.VTrack;
9   import org.lcsim.recon.tracking.trfbase.Surface;
10  import org.lcsim.recon.tracking.trfbase.Cluster;
11  import org.lcsim.recon.tracking.trfbase.HitError;
12  /**
13   * Generates two dimensional (x,y) hits on a z plane with a gaussian spread
14   * in the measurements correlated according to
15   * the covariance matrix.
16   *
17   *
18   *@author Norman A. Graf
19   *@version 1.0
20   *
21   */
22  public class HitZPlane2Generator extends HitGenerator
23  {
24      
25      // attributes
26      private static final int IX = ClusZPlane2.IX;
27      private static final int IY = ClusZPlane2.IY;
28      
29      // the surface
30      private SurfZPlane _szp;
31      
32      // the error matrix for the measurement (x,y)
33      private HitError _dhm;
34      
35      
36      
37      //
38      
39      /**
40       *Construct an instance  from the z plane position and measurement 
41       * position uncertainty.
42       *
43       * @param   zpos The z position of the plane.
44       * @param   dhm  The hit error covariance matrix.
45       */
46      public HitZPlane2Generator(double zpos, HitError dhm)
47      {
48          super();
49          _szp = new SurfZPlane(zpos);
50          _dhm = dhm;
51          Assert.assertTrue( _dhm.get(IX,IX) >= 0.0 && _dhm.get(IY,IY) >= 0.0);
52          
53          // check that determinant of _dhm is positive
54          Assert.assertTrue( _dhm.get(IX,IX)*_dhm.get(IY,IY) - _dhm.get(IX,IY)*_dhm.get(IX,IY) >= 0.0);
55          
56          Assert.assertTrue( _dhm.size() == 2);
57      }
58      
59      //
60      
61      /**
62       *Construct an instance from the z plane position the measurement position uncertainty
63       * and random number seed.
64       *
65       * @param   zpos The z position of the plane.
66       * @param   dhm  The hit error covariance matrix.
67       * @param   iseed The seed for the random number used by the HitGenerator.
68       */
69      public HitZPlane2Generator(double zpos, HitError dhm, long iseed)
70      {
71          super(iseed);
72          _szp = new SurfZPlane(zpos);
73          _dhm = dhm;
74          Assert.assertTrue( _dhm.get(IX,IX) >= 0.0 && _dhm.get(IY,IY) >= 0.0);
75          
76          // check that determinant of _dhm is positive
77          Assert.assertTrue( _dhm.get(IX,IX)*_dhm.get(IY,IY) - _dhm.get(IX,IY)*_dhm.get(IX,IY) >= 0.0);
78          
79          Assert.assertTrue( _dhm.size() == 2);  }
80      
81      //
82      
83     /**
84       *Construct an instance replicating the HitZPlane2Generator ( copy constructor ).
85       *
86       * @param  gen The HitZPlane2Generator to replicate.
87       */
88      public HitZPlane2Generator( HitZPlane2Generator gen)
89      {
90          super(gen);
91          _szp = new SurfZPlane(gen._szp);
92          _dhm = (gen._dhm);
93          Assert.assertTrue( _dhm.get(IX,IX) >= 0.0 && _dhm.get(IY,IY) >= 0.0 );
94          
95          // check that determinant of _dhm is positive
96          Assert.assertTrue( _dhm.get(IX,IX)*_dhm.get(IY,IY) - _dhm.get(IX,IY)*_dhm.get(IX,IY) >= 0.0);
97          
98          Assert.assertTrue( _dhm.size() == 2 );
99      }
100     
101     //
102     
103     /**
104      *Return the surface associated with this HitZPlane2Generator.
105      *
106      * @return The surface associated with this HitZPlane2Generator.
107      */
108     public  Surface surface()
109     { return _szp; }
110     
111     //
112     
113     /**
114      *Generate a new cluster.
115      * Return null for failure.
116      *
117      * @param   trv The VTrack for which to generate a cluster at this surface.
118      * @return   The cluster for this track at this surface, null for failure.
119      */
120     public Cluster newCluster( VTrack trv )
121     {
122         return newCluster(trv, 0);
123     }
124     
125     /**
126      *Generate a new cluster with the specified Monte Carlo track ID.
127      * Return null for failure.
128      *
129     * @param   trv The VTrack for which to generate a cluster at this surface.
130      * @param   mcid The MC ID to associate with this cluster.
131      * @return   The cluster for this track at this surface, null for failure.
132      */
133     public Cluster newCluster( VTrack trv, int mcid)
134     {
135         // Check track has been propagated to the surface.
136         Assert.assertTrue( _szp.pureEqual( trv.surface() ) );
137         if ( ! _szp.pureEqual( trv.surface() ) ) return null;
138         
139         // calculate axy.
140         double x_track = trv.vector().get(SurfZPlane.IX);
141         double y_track = trv.vector().get(SurfZPlane.IY);
142         double a1  = _dhm.get(IX,IX);
143         double a2  = _dhm.get(IY,IY);
144         double a12 = _dhm.get(IX,IY);
145         double phi;
146         if(a12 == 0.)
147         {
148             phi = 0.;
149         }
150         else
151         {
152             if(a1 == a2 )
153             {
154                 phi = Math.PI/4.;
155             }
156             else
157             {
158                 phi = 0.5*Math.atan(2*a12/(a1-a2));
159             }
160         }
161         double cphi= Math.cos(phi);
162         double sphi= Math.sin(phi);
163         double xx = cphi*cphi*a1 + sphi*sphi*a2 + 2*cphi*sphi*a12;
164         double yy = cphi*cphi*a2 + sphi*sphi*a1 - 2*cphi*sphi*a12;
165         
166         // simple check. To be removed later
167         
168         Assert.assertTrue( Math.abs(cphi*cphi*a12 - sphi*sphi*a12 + cphi*sphi*(a2-a1)) < 1.e-10);
169         Assert.assertTrue( Math.abs(xx*yy - (a1*a2 - a12*a12)) < 1.e-10 );
170         
171         // Very important test
172         
173         Assert.assertTrue( xx > 0.);
174         Assert.assertTrue( yy > 0.);
175         
176         double dxx = gauss()/Math.sqrt(xx);
177         double dyy = gauss()/Math.sqrt(yy);
178         double b1 = cphi*dxx - sphi*dyy;
179         double b2 = cphi*dyy + sphi*dxx;
180         
181         double ax  = x_track + (a1*b1+a12*b2);
182         double ay  = y_track + (a2*b2+a12*b1);
183         
184         // construct cluster
185         double zpos = _szp.parameter(SurfZPlane.ZPOS);
186         return new ClusZPlane2(zpos,ax,ay,_dhm.get(IX,IX), _dhm.get(IY,IY), _dhm.get(IX,IY), mcid );
187     }
188     
189     
190     /**
191      *output stream
192      *
193      * @return A String representation of this instance.
194      */
195     public String toString()
196     {
197         return  "Surface: " + _szp
198         + "\n Measurement error (dhm): " + _dhm ;
199     }
200 }
201