1 package org.lcsim.recon.tracking.spacegeom; 2 3 /** 4 * 5 * @author Norman A. Graf 6 * 7 * @version $Id: SpacePointTensor.java,v 1.2 2011/07/06 20:21:01 ngraf Exp $ 8 */ 9 public class SpacePointTensor extends SpacePoint 10 { 11 // The tensor. 12 13 double _txx, _txy, _txz; 14 double _tyx, _tyy, _tyz; 15 double _tzx, _tzy, _tzz; 16 // The rotation from Cartesian to cylindrical: 17 // | cos(phi) sin(phi) 0 | 18 // | -sin(phi) cos(phi) 0 | 19 // | 0 0 1 | 20 // 21 // The rotation from cylindrical to Cartesian: 22 // | cos(phi) -sin(phi) 0 | 23 // | sin(phi) cos(phi) 0 | 24 // | 0 0 1 | 25 // 26 // The rotation from Cartesian to spherical: 27 // | sin(tht)*cos(phi) sin(tht)*sin(phi) cos(tht) | 28 // | cos(tht)*cos(phi) cos(tht)*sin(phi) -sin(tht) | 29 // | -sin(phi) cos(phi) 0 | 30 // 31 // The rotation from spherical to Cartesian: 32 // | sin(tht)*cos(phi) cos(tht)*cos(phi) -sin(phi) | 33 // | sin(tht)*sin(phi) cos(tht)*sin(phi) cos(phi) | 34 // | cos(tht) -sin(tht) 0 | 35 // 36 // 37 // For tensor A and rotation matrix O (above): 38 // A' = OAOt 39 40 // Default constructor. 41 // Initial point is the origin with phi = theta = 0. 42 // Tensor is zero. 43 public SpacePointTensor() 44 { 45 } 46 47 // Constructor from a space point. 48 // Tensor is zero. 49 public SpacePointTensor(SpacePoint spt) 50 { 51 super(spt); 52 } 53 54 // Copy Constructor 55 public SpacePointTensor(SpacePointTensor spt) 56 { 57 super((SpacePoint) spt); 58 _txx = spt._txx; 59 _txy = spt._txy; 60 _txz = spt._txz; 61 _tyx = spt._tyx; 62 _tyy = spt._tyy; 63 _tyz = spt._tyz; 64 _tzx = spt._tzx; 65 _tzy = spt._tzy; 66 _tzz = spt._tzz; 67 } 68 69 // Cartesian components. 70 public double t_x_x() 71 { 72 return _txx; 73 } 74 75 public double t_x_y() 76 { 77 return _txy; 78 } 79 80 public double t_x_z() 81 { 82 return _txz; 83 } 84 85 public double t_y_x() 86 { 87 return _tyx; 88 } 89 90 public double t_y_y() 91 { 92 return _tyy; 93 } 94 95 public double t_y_z() 96 { 97 return _tyz; 98 } 99 100 public double t_z_x() 101 { 102 return _tzx; 103 } 104 105 public double t_z_y() 106 { 107 return _tzy; 108 } 109 110 public double t_z_z() 111 { 112 return _tzz; 113 } 114 115 // Return the rxy, rxy cylindrical component. 116 public double t_rxy_rxy() 117 { 118 double c = cosPhi(); 119 double s = sinPhi(); 120 return _txx * c * c + _tyy * s * s + (_tyx + _txy) * c * s; 121 } 122 //********************************************************************** 123 124 // Return the rxy, phi cylindrical component. 125 public double t_rxy_phi() 126 { 127 double c = cosPhi(); 128 double s = sinPhi(); 129 return (_tyy - _txx) * c * s - _tyx * s * s + _txy * c * c; 130 } 131 132 //********************************************************************** 133 // Return the rxy, z cylindrical component. 134 public double t_rxy_z() 135 { 136 double c = cosPhi(); 137 double s = sinPhi(); 138 return _txz * c + _tyz * s; 139 } 140 141 //********************************************************************** 142 // Return the phi, rxy cylindrical or spherical component. 143 public double t_phi_rxy() 144 { 145 double c = cosPhi(); 146 double s = sinPhi(); 147 return (_tyy - _txx) * c * s + _tyx * c * c - _txy * s * s; 148 } 149 150 //********************************************************************** 151 // Return the phi, phi cylindrical component. 152 public double t_phi_phi() 153 { 154 double c = cosPhi(); 155 double s = sinPhi(); 156 return _txx * s * s + _tyy * c * c - (_tyx + _txy) * c * s; 157 } 158 159 //********************************************************************** 160 // Return the phi, z cylindrical component. 161 public double t_phi_z() 162 { 163 double c = cosPhi(); 164 double s = sinPhi(); 165 return -_txz * s + _tyz * c; 166 } 167 168 //********************************************************************** 169 // Return the z, rxy cylindrical component. 170 public double t_z_rxy() 171 { 172 double c = cosPhi(); 173 double s = sinPhi(); 174 return _tzx * c + _tzy * s; 175 } 176 177 //********************************************************************** 178 // Return the z, phi cylindrical component. 179 public double t_z_phi() 180 { 181 double c = cosPhi(); 182 double s = sinPhi(); 183 return -_tzx * s + _tzy * c; 184 } 185 186 //********************************************************************** 187 // Return the rxyz, rxyz spherical component. 188 public double t_rxyz_rxyz() 189 { 190 double c_phi = cosPhi(); 191 double s_phi = sinPhi(); 192 double c_th = cosTheta(); 193 double s_th = sinTheta(); 194 double arx = _txx * s_th * c_phi + _tyx * s_th * s_phi + _tzx * c_th; 195 double ary = _txy * s_th * c_phi + _tyy * s_th * s_phi + _tzy * c_th; 196 double arz = _txz * s_th * c_phi + _tyz * s_th * s_phi + _tzz * c_th; 197 return arx * s_th * c_phi + ary * s_th * s_phi + arz * c_th; 198 } 199 200 //********************************************************************** 201 // Return the rxyz, theta spherical component. 202 public double t_rxyz_theta() 203 { 204 double c_phi = cosPhi(); 205 double s_phi = sinPhi(); 206 double c_th = cosTheta(); 207 double s_th = sinTheta(); 208 double arx = _txx * s_th * c_phi + _tyx * s_th * s_phi + _tzx * c_th; 209 double ary = _txy * s_th * c_phi + _tyy * s_th * s_phi + _tzy * c_th; 210 double arz = _txz * s_th * c_phi + _tyz * s_th * s_phi + _tzz * c_th; 211 return arx * c_th * c_phi + ary * c_th * s_phi - arz * s_th; 212 } 213 214 //********************************************************************** 215 // Return the rxyz, phi spherical component. 216 public double t_rxyz_phi() 217 { 218 double c_phi = cosPhi(); 219 double s_phi = sinPhi(); 220 double c_th = cosTheta(); 221 double s_th = sinTheta(); 222 double arx = _txx * s_th * c_phi + _tyx * s_th * s_phi + _tzx * c_th; 223 double ary = _txy * s_th * c_phi + _tyy * s_th * s_phi + _tzy * c_th; 224 return -arx * s_phi + ary * c_phi; 225 } 226 227 //********************************************************************** 228 // Return the theta, rxyz spherical component. 229 public double t_theta_rxyz() 230 { 231 double c_phi = cosPhi(); 232 double s_phi = sinPhi(); 233 double c_th = cosTheta(); 234 double s_th = sinTheta(); 235 double atx = _txx * c_th * c_phi + _tyx * c_th * s_phi - _tzx * s_th; 236 double aty = _txy * c_th * c_phi + _tyy * c_th * s_phi - _tzy * s_th; 237 double atz = _txz * c_th * c_phi + _tyz * c_th * s_phi - _tzz * s_th; 238 return atx * s_th * c_phi + aty * s_th * s_phi + atz * c_th; 239 } 240 241 //********************************************************************** 242 // Return the theta, theta spherical component. 243 public double t_theta_theta() 244 { 245 double c_phi = cosPhi(); 246 double s_phi = sinPhi(); 247 double c_th = cosTheta(); 248 double s_th = sinTheta(); 249 double atx = _txx * c_th * c_phi + _tyx * c_th * s_phi - _tzx * s_th; 250 double aty = _txy * c_th * c_phi + _tyy * c_th * s_phi - _tzy * s_th; 251 double atz = _txz * c_th * c_phi + _tyz * c_th * s_phi - _tzz * s_th; 252 return atx * c_th * c_phi + aty * c_th * s_phi - atz * s_th; 253 } 254 255 //********************************************************************** 256 // Return the theta, phi spherical component. 257 public double t_theta_phi() 258 { 259 double c_phi = cosPhi(); 260 double s_phi = sinPhi(); 261 double c_th = cosTheta(); 262 double s_th = sinTheta(); 263 double atx = _txx * c_th * c_phi + _tyx * c_th * s_phi - _tzx * s_th; 264 double aty = _txy * c_th * c_phi + _tyy * c_th * s_phi - _tzy * s_th; 265 return -atx * s_phi + aty * c_phi; 266 } 267 268 //********************************************************************** 269 // Return the phi, rxyz spherical component. 270 public double t_phi_rxyz() 271 { 272 double c_phi = cosPhi(); 273 double s_phi = sinPhi(); 274 double c_th = cosTheta(); 275 double s_th = sinTheta(); 276 double apx = -_txx * s_phi + _tyx * c_phi; 277 double apy = -_txy * s_phi + _tyy * c_phi; 278 double apz = -_txz * s_phi + _tyz * c_phi; 279 return apx * s_th * c_phi + apy * s_th * s_phi + apz * c_th; 280 } 281 282 //********************************************************************** 283 // Return the phi, theta spherical component. 284 public double t_phi_theta() 285 { 286 double c_phi = cosPhi(); 287 double s_phi = sinPhi(); 288 double c_th = cosTheta(); 289 double s_th = sinTheta(); 290 double apx = -_txx * s_phi + _tyx * c_phi; 291 double apy = -_txy * s_phi + _tyy * c_phi; 292 double apz = -_txz * s_phi + _tyz * c_phi; 293 return apx * c_th * c_phi + apy * c_th * s_phi - apz * s_th; 294 } 295 296 public String toString() 297 { 298 StringBuffer sb = new StringBuffer("Point: \n " + super.toString()); 299 sb.append("Tensor:" + "\n"); 300 sb.append(t_x_x() + "\n"); 301 sb.append(t_x_y() + "\n"); 302 sb.append(t_x_z() + "\n"); 303 sb.append("\n"); 304 sb.append(t_y_x() + "\n"); 305 sb.append(t_y_y() + "\n"); 306 sb.append(t_y_z() + "\n"); 307 sb.append("\n"); 308 sb.append(t_z_x() + "\n"); 309 sb.append(t_z_y() + "\n"); 310 sb.append(t_z_z() + "\n"); 311 312 return sb.toString(); 313 314 } 315 316 public boolean equals(SpacePointTensor spt) 317 { 318 319 if (!super.equals(spt)) 320 return false; 321 if (_txx != spt._txx) 322 return false; 323 if (_txy != spt._txy) 324 return false; 325 if (_txz != spt._txz) 326 return false; 327 if (_tyx != spt._tyx) 328 return false; 329 if (_tyy != spt._tyy) 330 return false; 331 if (_tyz != spt._tyz) 332 return false; 333 if (_tzx != spt._tzx) 334 return false; 335 if (_tzy != spt._tzy) 336 return false; 337 if (_tzz != spt._tzz) 338 return false; 339 340 return true; 341 } 342 }