1 package org.lcsim.recon.tracking.trfxyp;
2
3 import org.lcsim.recon.tracking.trfutil.Assert;
4 import org.lcsim.recon.tracking.trfutil.TRFMath;
5
6 import org.lcsim.recon.tracking.spacegeom.SpacePoint;
7 import org.lcsim.recon.tracking.spacegeom.SpacePath;
8 import org.lcsim.recon.tracking.spacegeom.CartesianPoint;
9 import org.lcsim.recon.tracking.spacegeom.CartesianPath;
10
11 import org.lcsim.recon.tracking.trfbase.Surface;
12
13 import org.lcsim.recon.tracking.trfbase.VTrack;
14 import org.lcsim.recon.tracking.trfbase.TrackVector;
15 import org.lcsim.recon.tracking.trfbase.CrossStat;
16 import org.lcsim.recon.tracking.trfbase.PureStat;
17 import org.lcsim.recon.tracking.trfbase.TrackSurfaceDirection;
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 public class SurfXYPlane extends Surface
47 {
48
49
50
51
52
53 public static final int NORMPHI = 0;
54 public static final int DISTNORM = 1;
55
56
57 public static final int IV=0;
58 public static final int IZ=1;
59 public static final int IDVDU=2;
60 public static final int IDZDU=3;
61 public static final int IQP=4;
62
63
64
65
66
67
68
69
70
71
72 public static String typeName()
73 { return "SurfXYPlane"; }
74
75
76
77
78
79
80
81 public static String staticType()
82 { return typeName(); }
83
84
85
86 protected double _normphi;
87 protected double _distnorm;
88
89
90
91
92
93 protected boolean safePureEqual( Surface srf)
94 {
95 double s_phi = ((SurfXYPlane ) srf)._normphi;
96 double s_dist= ((SurfXYPlane ) srf)._distnorm;
97 return ( Math.abs(s_phi - _normphi)< 1e-7 && Math.abs(s_dist-_distnorm) < 1e-7);
98 }
99
100
101
102
103 protected boolean safePureLessThan( Surface srf)
104 {
105 double s_phi = (( SurfXYPlane ) srf)._normphi;
106 double s_dist= ((SurfXYPlane )srf)._distnorm;
107 return ( _distnorm < s_dist - 1e-7 ) ||
108 ( Math.abs(_distnorm - s_dist) < 1e-7 && _normphi < s_phi -1e-7 );
109 }
110
111
112
113
114
115
116
117
118
119 public SurfXYPlane(double distnorm, double normphi)
120 {
121
122 Assert.assertTrue( normphi<TRFMath.TWOPI && normphi>=0. );
123 Assert.assertTrue( distnorm >= 0.);
124 _normphi = normphi;
125 _distnorm = distnorm;
126 }
127
128
129
130
131
132 public SurfXYPlane( SurfXYPlane sxyp)
133 {
134 _normphi = sxyp._normphi;
135 _distnorm = sxyp._distnorm;
136 }
137
138
139
140
141
142
143
144 public String pureType()
145 { return staticType(); }
146
147
148
149
150
151
152 public Surface newPureSurface()
153 {
154 return new SurfXYPlane(_distnorm,_normphi);
155 }
156
157
158
159
160
161
162
163 public CrossStat pureStatus(VTrack trv)
164 {
165
166 Surface srf = trv.surface();
167 if ( srf.equals(this) || pureEqual(srf) ) return new CrossStat(PureStat.AT);
168
169 double xtrk = trv.spacePoint().x();
170 double ytrk = trv.spacePoint().y();
171 double cphi = Math.cos(_normphi);
172 double sphi = Math.sin(_normphi);
173 double utrk = xtrk*cphi + ytrk*sphi;
174 double usrf = _distnorm;
175 double prec = CrossStat.staticPrecision();
176 if ( Math.abs(utrk-usrf) < prec ) return new CrossStat(PureStat.ON);
177 if ( utrk > usrf ) return new CrossStat(PureStat.OUTSIDE);
178 return new CrossStat(PureStat.INSIDE);
179 }
180
181
182
183
184
185
186
187
188
189
190
191 public double parameter(int ipar)
192 {
193 if ( ipar == NORMPHI ) return _normphi;
194 if ( ipar == DISTNORM) return _distnorm;
195 return 0.0;
196 }
197
198
199
200
201
202
203
204
205 public TrackVector vecDiff(TrackVector vec1,
206 TrackVector vec2)
207 {
208 TrackVector diff = new TrackVector(vec1);
209 diff = diff.minus(vec2);
210 return diff;
211 }
212
213
214
215
216
217
218
219 public SpacePoint spacePoint(TrackVector vec)
220 {
221 double u = _distnorm;
222 double cphi = Math.cos(_normphi);
223 double sphi = Math.sin(_normphi);
224 double x = u*cphi - vec.get(IV)*sphi;
225 double y = u*sphi + vec.get(IV)*cphi;
226 return new CartesianPoint( x , y, vec.get(IZ) );
227
228 }
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246 public SpacePath spacePath(TrackVector vec,
247 TrackSurfaceDirection dir)
248 {
249 double u = _distnorm;
250 double v = vec.get(IV);
251 double z = vec.get(IZ);
252 double dv_du = vec.get(IDVDU);
253 double dz_du = vec.get(IDZDU);
254
255 double cphi = Math.cos(_normphi);
256 double sphi = Math.sin(_normphi);
257
258 double x = u*cphi - v*sphi;
259 double y = u*sphi + v*cphi;
260
261 double du_ds = 1./Math.sqrt(1.+dv_du*dv_du+dz_du*dz_du);
262 if ( dir.equals(TrackSurfaceDirection.TSD_BACKWARD) ) du_ds *= -1.0;
263 else Assert.assertTrue( dir.equals(TrackSurfaceDirection.TSD_FORWARD) );
264 double dv_ds = dv_du*du_ds;
265
266 double dz_ds = dz_du*du_ds;
267 double dx_ds = du_ds*cphi - dv_ds*sphi;
268 double dy_ds = du_ds*sphi + dv_ds*cphi;
269
270 return new CartesianPath(x, y, z, dx_ds, dy_ds, dz_ds);
271 }
272
273
274
275
276
277
278 public String toString()
279 {
280 return "XY plane at phi = " + _normphi+
281 " and distance = "+ _distnorm;
282 }
283
284 }