Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // >> 23 // >> 24 // $Id: G4Para.cc,v 1.20 2004/01/26 09:03:19 gcosmo Exp $ >> 25 // GEANT4 tag $Name: geant4-06-00-patch-01 $ >> 26 // >> 27 // class G4Para >> 28 // 26 // Implementation for G4Para class 29 // Implementation for G4Para class 27 // 30 // >> 31 // History: 28 // 21.03.95 P.Kent: Modified for `tolerant' ge 32 // 21.03.95 P.Kent: Modified for `tolerant' geom 29 // 31.10.96 V.Grichine: Modifications accordin 33 // 31.10.96 V.Grichine: Modifications according G4Box/Tubs before to commit 30 // 28.04.05 V.Grichine: new SurfaceNormal acco << 34 // 18.11.99 V.Grichine: kUndef was added to ESide 31 // 29.05.17 E.Tcherniaev: complete revision, s << 35 // 14.02.02 V.Grichine: bug fixed in Inside according to proposal of D.Wright 32 ////////////////////////////////////////////// << 36 // -------------------------------------------------------------------- 33 37 34 #include "G4Para.hh" 38 #include "G4Para.hh" 35 39 36 #if !defined(G4GEOM_USE_UPARA) << 37 << 38 #include "G4VoxelLimits.hh" 40 #include "G4VoxelLimits.hh" 39 #include "G4AffineTransform.hh" 41 #include "G4AffineTransform.hh" 40 #include "G4BoundingEnvelope.hh" << 41 #include "Randomize.hh" << 42 42 43 #include "G4VPVParameterisation.hh" 43 #include "G4VPVParameterisation.hh" 44 44 45 #include "G4VGraphicsScene.hh" 45 #include "G4VGraphicsScene.hh" >> 46 #include "G4Polyhedron.hh" >> 47 #include "G4NURBS.hh" >> 48 #include "G4NURBSbox.hh" 46 49 47 using namespace CLHEP; << 50 // Private enum: Not for external use >> 51 >> 52 enum ESide {kUndef,kPX,kMX,kPY,kMY,kPZ,kMZ}; 48 53 49 ////////////////////////////////////////////// << 54 // used internally for normal routine 50 // << 51 // Constructor - set & check half widths << 52 55 53 G4Para::G4Para(const G4String& pName, << 56 enum ENSide {kNZ,kNX,kNY}; 54 G4double pDx, G4double pD << 55 G4double pAlpha, G4double << 56 : G4CSGSolid(pName), halfCarTolerance(0.5*kC << 57 { << 58 SetAllParameters(pDx, pDy, pDz, pAlpha, pThe << 59 fRebuildPolyhedron = false; // default valu << 60 } << 61 57 62 ////////////////////////////////////////////// << 58 ///////////////////////////////////////////////////////////////////// 63 // 59 // 64 // Constructor - design of trapezoid based on << 60 // Constructor - check and set half-widths 65 61 66 G4Para::G4Para( const G4String& pName, << 62 void G4Para::SetAllParameters( G4double pDx, G4double pDy, G4double pDz, 67 const G4ThreeVector pt[8] ) << 63 G4double pAlpha, G4double pTheta, G4double pPhi ) 68 : G4CSGSolid(pName), halfCarTolerance(0.5*kC << 69 { 64 { 70 // Find dimensions and trigonometric values << 65 if (pDx>0&&pDy>0&&pDz>0) 71 // << 66 { 72 fDx = (pt[3].x() - pt[2].x())*0.5; << 67 fDx=pDx; 73 fDy = (pt[2].y() - pt[1].y())*0.5; << 68 fDy=pDy; 74 fDz = pt[7].z(); << 69 fDz=pDz; 75 CheckParameters(); // check dimensions << 70 fTalpha=tan(pAlpha); 76 << 71 fTthetaCphi=tan(pTheta)*cos(pPhi); 77 fTalpha = (pt[2].x() + pt[3].x() - pt[1].x() << 72 fTthetaSphi=tan(pTheta)*sin(pPhi); 78 fTthetaCphi = (pt[4].x() + fDy*fTalpha + fDx << 73 } 79 fTthetaSphi = (pt[4].y() + fDy)/fDz; << 74 else 80 MakePlanes(); << 75 { 81 << 76 G4cerr << "ERROR - G4Para()::SetAllParameters(): " << GetName() << G4endl 82 // Recompute vertices << 77 << " Invalid dimensions ! - " 83 // << 78 << pDx << ", " << pDy << ", " << pDz << G4endl; 84 G4ThreeVector v[8]; << 79 G4Exception("G4Para::SetAllParameters()", "InvalidSetup", 85 G4double DyTalpha = fDy*fTalpha; << 80 FatalException, "Invalid Length Parameters."); 86 G4double DzTthetaSphi = fDz*fTthetaSphi; << 87 G4double DzTthetaCphi = fDz*fTthetaCphi; << 88 v[0].set(-DzTthetaCphi-DyTalpha-fDx, -DzTthe << 89 v[1].set(-DzTthetaCphi-DyTalpha+fDx, -DzTthe << 90 v[2].set(-DzTthetaCphi+DyTalpha-fDx, -DzTthe << 91 v[3].set(-DzTthetaCphi+DyTalpha+fDx, -DzTthe << 92 v[4].set( DzTthetaCphi-DyTalpha-fDx, DzTthe << 93 v[5].set( DzTthetaCphi-DyTalpha+fDx, DzTthe << 94 v[6].set( DzTthetaCphi+DyTalpha-fDx, DzTthe << 95 v[7].set( DzTthetaCphi+DyTalpha+fDx, DzTthe << 96 << 97 // Compare with original vertices << 98 // << 99 for (G4int i=0; i<8; ++i) << 100 { << 101 G4double delx = std::abs(pt[i].x() - v[i]. << 102 G4double dely = std::abs(pt[i].y() - v[i]. << 103 G4double delz = std::abs(pt[i].z() - v[i]. << 104 G4double discrepancy = std::max(std::max(d << 105 if (discrepancy > 0.1*kCarTolerance) << 106 { << 107 std::ostringstream message; << 108 G4long oldprc = message.precision(16); << 109 message << "Invalid vertice coordinates << 110 << "\nVertix #" << i << ", discr << 111 << "\n original : " << pt[i] << 112 << "\n recomputed : " << v[i]; << 113 G4cout.precision(oldprc); << 114 G4Exception("G4Para::G4Para()", "GeomSol << 115 FatalException, message); << 116 << 117 } << 118 } 81 } 119 } 82 } 120 83 121 ////////////////////////////////////////////// << 84 /////////////////////////////////////////////////////////////////////////// 122 // << 123 // Fake default constructor - sets only member << 124 // for usage restri << 125 << 126 G4Para::G4Para( __void__& a ) << 127 : G4CSGSolid(a), halfCarTolerance(0.5*kCarTo << 128 { << 129 SetAllParameters(1., 1., 1., 0., 0., 0.); << 130 fRebuildPolyhedron = false; // default value << 131 } << 132 << 133 ////////////////////////////////////////////// << 134 // << 135 // Destructor << 136 << 137 G4Para::~G4Para() = default; << 138 << 139 ////////////////////////////////////////////// << 140 // << 141 // Copy constructor << 142 << 143 G4Para::G4Para(const G4Para& rhs) << 144 : G4CSGSolid(rhs), halfCarTolerance(rhs.half << 145 fDx(rhs.fDx), fDy(rhs.fDy), fDz(rhs.fDz), << 146 fTthetaCphi(rhs.fTthetaCphi),fTthetaSphi(r << 147 { << 148 for (G4int i=0; i<4; ++i) { fPlanes[i] = rhs << 149 } << 150 << 151 ////////////////////////////////////////////// << 152 // << 153 // Assignment operator << 154 << 155 G4Para& G4Para::operator = (const G4Para& rhs) << 156 { << 157 // Check assignment to self << 158 // << 159 if (this == &rhs) { return *this; } << 160 << 161 // Copy base class data << 162 // << 163 G4CSGSolid::operator=(rhs); << 164 << 165 // Copy data << 166 // << 167 halfCarTolerance = rhs.halfCarTolerance; << 168 fDx = rhs.fDx; << 169 fDy = rhs.fDy; << 170 fDz = rhs.fDz; << 171 fTalpha = rhs.fTalpha; << 172 fTthetaCphi = rhs.fTthetaCphi; << 173 fTthetaSphi = rhs.fTthetaSphi; << 174 for (G4int i=0; i<4; ++i) { fPlanes[i] = rh << 175 << 176 return *this; << 177 } << 178 << 179 ////////////////////////////////////////////// << 180 // << 181 // Set all parameters, as for constructor - se << 182 << 183 void G4Para::SetAllParameters(G4double pDx, G4 << 184 G4double pAlpha, << 185 { << 186 // Reset data of the base class << 187 fCubicVolume = 0; << 188 fSurfaceArea = 0; << 189 fRebuildPolyhedron = true; << 190 << 191 // Set parameters << 192 fDx = pDx; << 193 fDy = pDy; << 194 fDz = pDz; << 195 fTalpha = std::tan(pAlpha); << 196 fTthetaCphi = std::tan(pTheta)*std::cos(pPhi << 197 fTthetaSphi = std::tan(pTheta)*std::sin(pPhi << 198 << 199 CheckParameters(); << 200 MakePlanes(); << 201 } << 202 << 203 ////////////////////////////////////////////// << 204 // 85 // 205 // Check dimensions << 206 86 207 void G4Para::CheckParameters() << 87 G4Para::G4Para(const G4String& pName, >> 88 G4double pDx, G4double pDy, G4double pDz, >> 89 G4double pAlpha, G4double pTheta, G4double pPhi) >> 90 : G4CSGSolid(pName) 208 { 91 { 209 if (fDx < 2*kCarTolerance || << 92 if (pDx>0&&pDy>0&&pDz>0) 210 fDy < 2*kCarTolerance || << 93 { 211 fDz < 2*kCarTolerance) << 94 SetAllParameters( pDx, pDy, pDz, pAlpha, pTheta, pPhi); 212 { << 95 } 213 std::ostringstream message; << 96 else 214 message << "Invalid (too small or negative << 97 { 215 << GetName() << 98 G4cerr << "ERROR - G4Para()::G4Para(): " << GetName() << G4endl 216 << "\n X - " << fDx << 99 << " Invalid dimensions ! - " 217 << "\n Y - " << fDy << 100 << pDx << ", " << pDy << ", " << pDz << G4endl; 218 << "\n Z - " << fDz; << 101 G4Exception("G4Para::G4Para()", "InvalidSetup", 219 G4Exception("G4Para::CheckParameters()", " << 102 FatalException, "Invalid Length Parameters."); 220 FatalException, message); << 221 } 103 } 222 } 104 } 223 105 224 ////////////////////////////////////////////// << 106 //////////////////////////////////////////////////////////////////////// 225 // 107 // 226 // Set side planes << 108 // Constructor - Design of trapezoid based on 8 G4ThreeVector parameters, >> 109 // which are its vertices. Checking of planarity with preparation of >> 110 // fPlanes[] and than calculation of other members 227 111 228 void G4Para::MakePlanes() << 112 G4Para::G4Para( const G4String& pName, >> 113 const G4ThreeVector pt[8] ) >> 114 : G4CSGSolid(pName) 229 { 115 { 230 G4ThreeVector vx(1, 0, 0); << 116 if ( pt[0].z()<0 && pt[0].z()==pt[1].z() && pt[0].z()==pt[2].z() && 231 G4ThreeVector vy(fTalpha, 1, 0); << 117 pt[0].z()==pt[3].z() && pt[4].z()>0 && pt[4].z()==pt[5].z() && 232 G4ThreeVector vz(fTthetaCphi, fTthetaSphi, 1 << 118 pt[4].z()==pt[6].z() && pt[4].z()==pt[7].z() && 233 << 119 (pt[0].z()+pt[4].z())==0 && 234 // Set -Y & +Y planes << 120 pt[0].y()==pt[1].y() && pt[2].y()==pt[3].y() && 235 // << 121 pt[4].y()==pt[5].y() && pt[6].y()==pt[7].y() && 236 G4ThreeVector ynorm = (vx.cross(vz)).unit(); << 122 (pt[0].y()+pt[2].y()+pt[4].y()+pt[6].y())==0 ) >> 123 { >> 124 fDz = (pt[7]).z() ; >> 125 >> 126 fDy = ((pt[2]).y()-(pt[1]).y())*0.5 ; >> 127 fDx = ((pt[1]).x()-(pt[0]).x())*0.5 ; >> 128 fDx = ((pt[3]).x()-(pt[2]).x())*0.5 ; >> 129 fTalpha = ((pt[2]).x()+(pt[3]).x()-(pt[1]).x()-(pt[0]).x())*0.25/fDy ; >> 130 >> 131 // fDy = ((pt[6]).y()-(pt[5]).y())*0.5 ; >> 132 // fDx = ((pt[5]).x()-(pt[4]).x())*0.5 ; >> 133 // fDx = ((pt[7]).x()-(pt[6]).x())*0.5 ; >> 134 // fTalpha = ((pt[6]).x()+(pt[7]).x()-(pt[5]).x()-(pt[4]).x())*0.25/fDy ; 237 135 238 fPlanes[0].a = 0.; << 136 fTthetaCphi = ((pt[4]).x()+fDy*fTalpha+fDx)/fDz ; 239 fPlanes[0].b = ynorm.y(); << 137 fTthetaSphi = ((pt[4]).y()+fDy)/fDz ; 240 fPlanes[0].c = ynorm.z(); << 241 fPlanes[0].d = fPlanes[0].b*fDy; // point (0 << 242 << 243 fPlanes[1].a = 0.; << 244 fPlanes[1].b = -fPlanes[0].b; << 245 fPlanes[1].c = -fPlanes[0].c; << 246 fPlanes[1].d = fPlanes[0].d; << 247 << 248 // Set -X & +X planes << 249 // << 250 G4ThreeVector xnorm = (vz.cross(vy)).unit(); << 251 << 252 fPlanes[2].a = xnorm.x(); << 253 fPlanes[2].b = xnorm.y(); << 254 fPlanes[2].c = xnorm.z(); << 255 fPlanes[2].d = fPlanes[2].a*fDx; // point (f << 256 << 257 fPlanes[3].a = -fPlanes[2].a; << 258 fPlanes[3].b = -fPlanes[2].b; << 259 fPlanes[3].c = -fPlanes[2].c; << 260 fPlanes[3].d = fPlanes[2].d; << 261 } << 262 << 263 ////////////////////////////////////////////// << 264 // << 265 // Get volume << 266 << 267 G4double G4Para::GetCubicVolume() << 268 { << 269 // It is like G4Box, since para transformati << 270 if (fCubicVolume == 0) << 271 { << 272 fCubicVolume = 8*fDx*fDy*fDz; << 273 } 138 } 274 return fCubicVolume; << 139 else >> 140 { >> 141 G4cerr << "ERROR - G4Para()::G4Para(): " << GetName() << G4endl >> 142 << " Invalid dimensions !" << G4endl; >> 143 G4Exception("G4Para::G4Para()", "InvalidSetup", >> 144 FatalException, "Invalid vertice coordinates."); >> 145 } 275 } 146 } 276 147 277 ////////////////////////////////////////////// 148 ////////////////////////////////////////////////////////////////////////// 278 // 149 // 279 // Get surface area << 280 150 281 G4double G4Para::GetSurfaceArea() << 151 G4Para::~G4Para() 282 { 152 { 283 if(fSurfaceArea == 0) << 284 { << 285 G4ThreeVector vx(fDx, 0, 0); << 286 G4ThreeVector vy(fDy*fTalpha, fDy, 0); << 287 G4ThreeVector vz(fDz*fTthetaCphi, fDz*fTth << 288 << 289 G4double sxy = fDx*fDy; // (vx.cross(vy)). << 290 G4double sxz = (vx.cross(vz)).mag(); << 291 G4double syz = (vy.cross(vz)).mag(); << 292 << 293 fSurfaceArea = 8*(sxy+sxz+syz); << 294 } << 295 return fSurfaceArea; << 296 } 153 } 297 154 298 ////////////////////////////////////////////// 155 ////////////////////////////////////////////////////////////////////////// 299 // 156 // 300 // Dispatch to parameterisation for replicatio 157 // Dispatch to parameterisation for replication mechanism dimension 301 // computation & modification << 158 // computation & modification. 302 159 303 void G4Para::ComputeDimensions( G4VPVPara 160 void G4Para::ComputeDimensions( G4VPVParameterisation* p, 304 const G4int n, 161 const G4int n, 305 const G4VPhysi 162 const G4VPhysicalVolume* pRep ) 306 { 163 { 307 p->ComputeDimensions(*this,n,pRep); 164 p->ComputeDimensions(*this,n,pRep); 308 } 165 } 309 166 310 ////////////////////////////////////////////// << 311 // << 312 // Get bounding box << 313 167 314 void G4Para::BoundingLimits(G4ThreeVector& pMi << 168 ////////////////////////////////////////////////////////////// 315 { << 316 G4double dz = GetZHalfLength(); << 317 G4double dx = GetXHalfLength(); << 318 G4double dy = GetYHalfLength(); << 319 << 320 G4double x0 = dz*fTthetaCphi; << 321 G4double x1 = dy*GetTanAlpha(); << 322 G4double xmin = << 323 std::min( << 324 std::min( << 325 std::min(-x0-x1-dx,-x0+x1-dx),x0-x1-dx),x0 << 326 G4double xmax = << 327 std::max( << 328 std::max( << 329 std::max(-x0-x1+dx,-x0+x1+dx),x0-x1+dx),x0 << 330 << 331 G4double y0 = dz*fTthetaSphi; << 332 G4double ymin = std::min(-y0-dy,y0-dy); << 333 G4double ymax = std::max(-y0+dy,y0+dy); << 334 << 335 pMin.set(xmin,ymin,-dz); << 336 pMax.set(xmax,ymax, dz); << 337 << 338 // Check correctness of the bounding box << 339 // << 340 if (pMin.x() >= pMax.x() || pMin.y() >= pMax << 341 { << 342 std::ostringstream message; << 343 message << "Bad bounding box (min >= max) << 344 << GetName() << " !" << 345 << "\npMin = " << pMin << 346 << "\npMax = " << pMax; << 347 G4Exception("G4Para::BoundingLimits()", "G << 348 JustWarning, message); << 349 DumpInfo(); << 350 } << 351 } << 352 << 353 ////////////////////////////////////////////// << 354 // 169 // 355 // Calculate extent under transform and specif 170 // Calculate extent under transform and specified limit 356 171 357 G4bool G4Para::CalculateExtent( const EAxis pA 172 G4bool G4Para::CalculateExtent( const EAxis pAxis, 358 const G4VoxelL 173 const G4VoxelLimits& pVoxelLimit, 359 const G4Affine 174 const G4AffineTransform& pTransform, 360 G4double& 175 G4double& pMin, G4double& pMax ) const 361 { 176 { 362 G4ThreeVector bmin, bmax; << 177 G4bool flag; 363 G4bool exist; << 364 178 365 // Check bounding box (bbox) << 179 if (!pTransform.IsRotated()) 366 // << 180 { 367 BoundingLimits(bmin,bmax); << 181 // Special case handling for unrotated trapezoids 368 G4BoundingEnvelope bbox(bmin,bmax); << 182 // Compute z/x/y/ mins and maxs respecting limits, with early returns 369 #ifdef G4BBOX_EXTENT << 183 // if outside limits. Then switch() on pAxis 370 return bbox.CalculateExtent(pAxis,pVoxelLimi << 184 371 #endif << 185 G4int i ; 372 if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVox << 186 G4double xoffset,xMin,xMax; 373 { << 187 G4double yoffset,yMin,yMax; 374 return exist = pMin < pMax; << 188 G4double zoffset,zMin,zMax; 375 } << 189 G4double temp[8] ; // some points for intersection with zMin/zMax >> 190 >> 191 xoffset=pTransform.NetTranslation().x(); >> 192 yoffset=pTransform.NetTranslation().y(); >> 193 zoffset=pTransform.NetTranslation().z(); >> 194 >> 195 G4ThreeVector pt[8]; // vertices after translation >> 196 pt[0]=G4ThreeVector(xoffset-fDz*fTthetaCphi-fDy*fTalpha-fDx, >> 197 yoffset-fDz*fTthetaSphi-fDy,zoffset-fDz); >> 198 pt[1]=G4ThreeVector(xoffset-fDz*fTthetaCphi-fDy*fTalpha+fDx, >> 199 yoffset-fDz*fTthetaSphi-fDy,zoffset-fDz); >> 200 pt[2]=G4ThreeVector(xoffset-fDz*fTthetaCphi+fDy*fTalpha-fDx, >> 201 yoffset-fDz*fTthetaSphi+fDy,zoffset-fDz); >> 202 pt[3]=G4ThreeVector(xoffset-fDz*fTthetaCphi+fDy*fTalpha+fDx, >> 203 yoffset-fDz*fTthetaSphi+fDy,zoffset-fDz); >> 204 pt[4]=G4ThreeVector(xoffset+fDz*fTthetaCphi-fDy*fTalpha-fDx, >> 205 yoffset+fDz*fTthetaSphi-fDy,zoffset+fDz); >> 206 pt[5]=G4ThreeVector(xoffset+fDz*fTthetaCphi-fDy*fTalpha+fDx, >> 207 yoffset+fDz*fTthetaSphi-fDy,zoffset+fDz); >> 208 pt[6]=G4ThreeVector(xoffset+fDz*fTthetaCphi+fDy*fTalpha-fDx, >> 209 yoffset+fDz*fTthetaSphi+fDy,zoffset+fDz); >> 210 pt[7]=G4ThreeVector(xoffset+fDz*fTthetaCphi+fDy*fTalpha+fDx, >> 211 yoffset+fDz*fTthetaSphi+fDy,zoffset+fDz); >> 212 zMin=zoffset-fDz; >> 213 zMax=zoffset+fDz; >> 214 if ( pVoxelLimit.IsZLimited() ) >> 215 { >> 216 if ( (zMin>pVoxelLimit.GetMaxZExtent()+kCarTolerance) >> 217 || (zMax<pVoxelLimit.GetMinZExtent()-kCarTolerance) ) >> 218 { >> 219 return false; >> 220 } >> 221 else >> 222 { >> 223 if (zMin<pVoxelLimit.GetMinZExtent()) >> 224 { >> 225 zMin=pVoxelLimit.GetMinZExtent(); >> 226 } >> 227 if (zMax>pVoxelLimit.GetMaxZExtent()) >> 228 { >> 229 zMax=pVoxelLimit.GetMaxZExtent(); >> 230 } >> 231 } >> 232 } 376 233 377 // Set bounding envelope (benv) and calculat << 234 temp[0] = pt[0].y()+(pt[4].y()-pt[0].y()) 378 // << 235 *(zMin-pt[0].z())/(pt[4].z()-pt[0].z()) ; 379 G4double dz = GetZHalfLength(); << 236 temp[1] = pt[0].y()+(pt[4].y()-pt[0].y()) 380 G4double dx = GetXHalfLength(); << 237 *(zMax-pt[0].z())/(pt[4].z()-pt[0].z()) ; 381 G4double dy = GetYHalfLength(); << 238 temp[2] = pt[2].y()+(pt[6].y()-pt[2].y()) >> 239 *(zMin-pt[2].z())/(pt[6].z()-pt[2].z()) ; >> 240 temp[3] = pt[2].y()+(pt[6].y()-pt[2].y()) >> 241 *(zMax-pt[2].z())/(pt[6].z()-pt[2].z()) ; >> 242 yMax = yoffset - fabs(fDz*fTthetaSphi) - fDy - fDy ; >> 243 yMin = -yMax ; >> 244 for(i=0;i<4;i++) >> 245 { >> 246 if(temp[i] > yMax) yMax = temp[i] ; >> 247 if(temp[i] < yMin) yMin = temp[i] ; >> 248 } >> 249 >> 250 if (pVoxelLimit.IsYLimited()) >> 251 { >> 252 if ( (yMin>pVoxelLimit.GetMaxYExtent()+kCarTolerance) >> 253 || (yMax<pVoxelLimit.GetMinYExtent()-kCarTolerance) ) >> 254 { >> 255 return false; >> 256 } >> 257 else >> 258 { >> 259 if (yMin<pVoxelLimit.GetMinYExtent()) >> 260 { >> 261 yMin=pVoxelLimit.GetMinYExtent(); >> 262 } >> 263 if (yMax>pVoxelLimit.GetMaxYExtent()) >> 264 { >> 265 yMax=pVoxelLimit.GetMaxYExtent(); >> 266 } >> 267 } >> 268 } 382 269 383 G4double x0 = dz*fTthetaCphi; << 270 temp[0] = pt[0].x()+(pt[4].x()-pt[0].x()) 384 G4double x1 = dy*GetTanAlpha(); << 271 *(zMin-pt[0].z())/(pt[4].z()-pt[0].z()) ; 385 G4double y0 = dz*fTthetaSphi; << 272 temp[1] = pt[0].x()+(pt[4].x()-pt[0].x()) >> 273 *(zMax-pt[0].z())/(pt[4].z()-pt[0].z()) ; >> 274 temp[2] = pt[2].x()+(pt[6].x()-pt[2].x()) >> 275 *(zMin-pt[2].z())/(pt[6].z()-pt[2].z()) ; >> 276 temp[3] = pt[2].x()+(pt[6].x()-pt[2].x()) >> 277 *(zMax-pt[2].z())/(pt[6].z()-pt[2].z()) ; >> 278 temp[4] = pt[3].x()+(pt[7].x()-pt[3].x()) >> 279 *(zMin-pt[3].z())/(pt[7].z()-pt[3].z()) ; >> 280 temp[5] = pt[3].x()+(pt[7].x()-pt[3].x()) >> 281 *(zMax-pt[3].z())/(pt[7].z()-pt[3].z()) ; >> 282 temp[6] = pt[1].x()+(pt[5].x()-pt[1].x()) >> 283 *(zMin-pt[1].z())/(pt[5].z()-pt[1].z()) ; >> 284 temp[7] = pt[1].x()+(pt[5].x()-pt[1].x()) >> 285 *(zMax-pt[1].z())/(pt[5].z()-pt[1].z()) ; >> 286 >> 287 xMax = xoffset - fabs(fDz*fTthetaCphi) - fDx - fDx -fDx - fDx; >> 288 xMin = -xMax ; >> 289 for(i=0;i<8;i++) >> 290 { >> 291 if(temp[i] > xMax) xMax = temp[i] ; >> 292 if(temp[i] < xMin) xMin = temp[i] ; >> 293 } >> 294 // xMax/Min = f(yMax/Min) ? >> 295 if (pVoxelLimit.IsXLimited()) >> 296 { >> 297 if ( (xMin>pVoxelLimit.GetMaxXExtent()+kCarTolerance) >> 298 || (xMax<pVoxelLimit.GetMinXExtent()-kCarTolerance) ) >> 299 { >> 300 return false; >> 301 } >> 302 else >> 303 { >> 304 if (xMin<pVoxelLimit.GetMinXExtent()) >> 305 { >> 306 xMin=pVoxelLimit.GetMinXExtent(); >> 307 } >> 308 if (xMax>pVoxelLimit.GetMaxXExtent()) >> 309 { >> 310 xMax=pVoxelLimit.GetMaxXExtent(); >> 311 } >> 312 } >> 313 } >> 314 >> 315 switch (pAxis) >> 316 { >> 317 case kXAxis: >> 318 pMin=xMin; >> 319 pMax=xMax; >> 320 break; >> 321 case kYAxis: >> 322 pMin=yMin; >> 323 pMax=yMax; >> 324 break; >> 325 case kZAxis: >> 326 pMin=zMin; >> 327 pMax=zMax; >> 328 break; >> 329 default: >> 330 break; >> 331 } 386 332 387 G4ThreeVectorList baseA(4), baseB(4); << 333 pMin-=kCarTolerance; 388 baseA[0].set(-x0-x1-dx,-y0-dy,-dz); << 334 pMax+=kCarTolerance; 389 baseA[1].set(-x0-x1+dx,-y0-dy,-dz); << 335 flag = true; 390 baseA[2].set(-x0+x1+dx,-y0+dy,-dz); << 336 } 391 baseA[3].set(-x0+x1-dx,-y0+dy,-dz); << 337 else >> 338 { >> 339 // General rotated case - create and clip mesh to boundaries 392 340 393 baseB[0].set(+x0-x1-dx, y0-dy, dz); << 341 G4bool existsAfterClip=false; 394 baseB[1].set(+x0-x1+dx, y0-dy, dz); << 342 G4ThreeVectorList *vertices; 395 baseB[2].set(+x0+x1+dx, y0+dy, dz); << 396 baseB[3].set(+x0+x1-dx, y0+dy, dz); << 397 343 398 std::vector<const G4ThreeVectorList *> polyg << 344 pMin=+kInfinity; 399 polygons[0] = &baseA; << 345 pMax=-kInfinity; 400 polygons[1] = &baseB; << 401 346 402 G4BoundingEnvelope benv(bmin,bmax,polygons); << 347 // Calculate rotated vertex coordinates 403 exist = benv.CalculateExtent(pAxis,pVoxelLim << 348 404 return exist; << 349 vertices=CreateRotatedVertices(pTransform); >> 350 ClipCrossSection(vertices,0,pVoxelLimit,pAxis,pMin,pMax); >> 351 ClipCrossSection(vertices,4,pVoxelLimit,pAxis,pMin,pMax); >> 352 ClipBetweenSections(vertices,0,pVoxelLimit,pAxis,pMin,pMax); >> 353 >> 354 if (pMin!=kInfinity||pMax!=-kInfinity) >> 355 { >> 356 existsAfterClip=true; >> 357 >> 358 // Add 2*tolerance to avoid precision troubles >> 359 // >> 360 pMin-=kCarTolerance; >> 361 pMax+=kCarTolerance; >> 362 } >> 363 else >> 364 { >> 365 // Check for case where completely enveloping clipping volume >> 366 // If point inside then we are confident that the solid completely >> 367 // envelopes the clipping volume. Hence set min/max extents according >> 368 // to clipping volume extents along the specified axis. >> 369 >> 370 G4ThreeVector clipCentre( >> 371 (pVoxelLimit.GetMinXExtent()+pVoxelLimit.GetMaxXExtent())*0.5, >> 372 (pVoxelLimit.GetMinYExtent()+pVoxelLimit.GetMaxYExtent())*0.5, >> 373 (pVoxelLimit.GetMinZExtent()+pVoxelLimit.GetMaxZExtent())*0.5); >> 374 >> 375 if (Inside(pTransform.Inverse().TransformPoint(clipCentre))!=kOutside) >> 376 { >> 377 existsAfterClip=true; >> 378 pMin=pVoxelLimit.GetMinExtent(pAxis); >> 379 pMax=pVoxelLimit.GetMaxExtent(pAxis); >> 380 } >> 381 } >> 382 delete vertices ; // 'new' in the function called >> 383 flag = existsAfterClip ; >> 384 } >> 385 return flag; 405 } 386 } 406 387 407 ////////////////////////////////////////////// << 388 ///////////////////////////////////////////////////////////////////////////// 408 // << 409 // Determine where is point p, inside/on_surfa << 410 // 389 // >> 390 // Check in p is inside/on surface/outside solid 411 391 412 EInside G4Para::Inside( const G4ThreeVector& p 392 EInside G4Para::Inside( const G4ThreeVector& p ) const 413 { 393 { 414 G4double xx = fPlanes[2].a*p.x()+fPlanes[2]. << 394 G4double xt, yt, yt1; 415 G4double dx = std::abs(xx) + fPlanes[2].d; << 395 EInside in = kOutside; >> 396 >> 397 yt1 = p.y() - fTthetaSphi*p.z(); >> 398 yt = fabs(yt1) ; 416 399 417 G4double yy = fPlanes[0].b*p.y()+fPlanes[0]. << 400 // xt = fabs( p.x() - fTthetaCphi*p.z() - fTalpha*yt ); 418 G4double dy = std::abs(yy) + fPlanes[0].d; << 419 G4double dxy = std::max(dx,dy); << 420 401 421 G4double dz = std::abs(p.z())-fDz; << 402 xt = fabs( p.x() - fTthetaCphi*p.z() - fTalpha*yt1 ); 422 G4double dist = std::max(dxy,dz); << 423 403 424 if (dist > halfCarTolerance) return kOutside << 404 if ( fabs( p.z() ) <= fDz - kCarTolerance*0.5) 425 return (dist > -halfCarTolerance) ? kSurface << 405 { >> 406 if (yt <= fDy - kCarTolerance*0.5) >> 407 { >> 408 if ( xt <= fDx - kCarTolerance*0.5 ) in = kInside; >> 409 else if ( xt <= fDx + kCarTolerance*0.5 ) in = kSurface; >> 410 } >> 411 else if ( yt <= fDy + kCarTolerance*0.5) >> 412 { >> 413 if ( xt <= fDx + kCarTolerance*0.5 ) in = kSurface; >> 414 } >> 415 } >> 416 else if ( fabs(p.z()) <= fDz + kCarTolerance*0.5 ) >> 417 { >> 418 if ( yt <= fDy + kCarTolerance*0.5) >> 419 { >> 420 if ( xt <= fDx + kCarTolerance*0.5 ) in = kSurface; >> 421 } >> 422 } >> 423 return in; 426 } 424 } 427 425 428 ////////////////////////////////////////////// << 426 /////////////////////////////////////////////////////////////////////////// 429 // 427 // 430 // Determine side where point is, and return c << 428 // Calculate side nearest to p, and return normal >> 429 // If 2+ sides equidistant, first side's normal returned (arbitrarily) 431 430 432 G4ThreeVector G4Para::SurfaceNormal( const G4T 431 G4ThreeVector G4Para::SurfaceNormal( const G4ThreeVector& p ) const 433 { 432 { 434 G4int nsurf = 0; // number of surfaces where << 433 ENSide side; >> 434 G4ThreeVector norm; >> 435 G4double distx,disty,distz; >> 436 G4double newpx,newpy,xshift; >> 437 G4double calpha,salpha; // Sin/Cos(alpha) - needed to recalc G4Parameter >> 438 G4double tntheta,cosntheta; // tan and cos of normal's theta component >> 439 G4double ycomp; 435 440 436 // Check Z faces << 441 newpx=p.x()-fTthetaCphi*p.z(); 437 // << 442 newpy=p.y()-fTthetaSphi*p.z(); 438 G4double nz = 0; << 439 G4double dz = std::abs(p.z()) - fDz; << 440 if (std::abs(dz) <= halfCarTolerance) << 441 { << 442 nz = (p.z() < 0) ? -1 : 1; << 443 ++nsurf; << 444 } << 445 443 446 // Check Y faces << 444 calpha=1/sqrt(1+fTalpha*fTalpha); 447 // << 445 if (fTalpha) 448 G4double ny = 0; << 449 G4double yy = fPlanes[0].b*p.y()+fPlanes[0]. << 450 if (std::abs(fPlanes[0].d + yy) <= halfCarTo << 451 { 446 { 452 ny = fPlanes[0].b; << 447 salpha=-calpha/fTalpha; // NOTE: actually use MINUS sin(alpha) 453 nz += fPlanes[0].c; << 454 ++nsurf; << 455 } 448 } 456 else if (std::abs(fPlanes[1].d - yy) <= half << 449 else 457 { 450 { 458 ny = fPlanes[1].b; << 451 salpha=0; 459 nz += fPlanes[1].c; << 460 ++nsurf; << 461 } 452 } 462 453 463 // Check X faces << 454 xshift=newpx*calpha+newpy*salpha; 464 // << 455 465 G4double nx = 0; << 456 distx=fabs(fabs(xshift)-fDx*calpha); 466 G4double xx = fPlanes[2].a*p.x()+fPlanes[2]. << 457 disty=fabs(fabs(newpy)-fDy); 467 if (std::abs(fPlanes[2].d + xx) <= halfCarTo << 458 distz=fabs(fabs(p.z())-fDz); 468 { << 459 469 nx = fPlanes[2].a; << 460 if (distx<disty) 470 ny += fPlanes[2].b; << 471 nz += fPlanes[2].c; << 472 ++nsurf; << 473 } << 474 else if (std::abs(fPlanes[3].d - xx) <= half << 475 { 461 { 476 nx = fPlanes[3].a; << 462 if (distx<distz) side=kNX; 477 ny += fPlanes[3].b; << 463 else side=kNZ; 478 nz += fPlanes[3].c; << 479 ++nsurf; << 480 } 464 } 481 << 482 // Return normal << 483 // << 484 if (nsurf == 1) return {nx,ny,nz}; << 485 else if (nsurf != 0) return G4ThreeVector(nx << 486 else 465 else 487 { 466 { 488 // Point is not on the surface << 467 if (disty<distz) side=kNY; 489 // << 468 else side=kNZ; 490 #ifdef G4CSGDEBUG << 491 std::ostringstream message; << 492 G4int oldprc = message.precision(16); << 493 message << "Point p is not on surface (!?) << 494 << GetName() << G4endl; << 495 message << "Position:\n"; << 496 message << " p.x() = " << p.x()/mm << " << 497 message << " p.y() = " << p.y()/mm << " << 498 message << " p.z() = " << p.z()/mm << " << 499 G4cout.precision(oldprc) ; << 500 G4Exception("G4Para::SurfaceNormal(p)", "G << 501 JustWarning, message ); << 502 DumpInfo(); << 503 #endif << 504 return ApproxSurfaceNormal(p); << 505 } 469 } 506 } << 507 470 508 ////////////////////////////////////////////// << 471 switch (side) 509 // << 510 // Algorithm for SurfaceNormal() following the << 511 // for points not on the surface << 512 << 513 G4ThreeVector G4Para::ApproxSurfaceNormal( con << 514 { << 515 G4double dist = -DBL_MAX; << 516 G4int iside = 0; << 517 for (G4int i=0; i<4; ++i) << 518 { 472 { 519 G4double d = fPlanes[i].a*p.x() + << 473 case kNX: 520 fPlanes[i].b*p.y() + << 474 tntheta=fTthetaCphi*calpha+fTthetaSphi*salpha; 521 fPlanes[i].c*p.z() + fPlanes[ << 475 if (xshift<0) 522 if (d > dist) { dist = d; iside = i; } << 476 { >> 477 cosntheta=-1/sqrt(1+tntheta*tntheta); >> 478 } >> 479 else >> 480 { >> 481 cosntheta=1/sqrt(1+tntheta*tntheta); >> 482 } >> 483 norm=G4ThreeVector(calpha*cosntheta,salpha*cosntheta,-tntheta*cosntheta); >> 484 break; >> 485 case kNY: >> 486 if (newpy<0) >> 487 { >> 488 ycomp=-1/sqrt(1+fTthetaSphi*fTthetaSphi); >> 489 } >> 490 else >> 491 { >> 492 ycomp=1/sqrt(1+fTthetaSphi*fTthetaSphi); >> 493 } >> 494 norm=G4ThreeVector(0,ycomp,-fTthetaSphi*ycomp); >> 495 break; >> 496 case kNZ: // Closest to Z >> 497 if (p.z()>=0) >> 498 { >> 499 norm=G4ThreeVector(0,0,1); >> 500 } >> 501 else >> 502 { >> 503 norm=G4ThreeVector(0,0,-1); >> 504 } >> 505 break; 523 } 506 } 524 << 507 return norm; 525 G4double distz = std::abs(p.z()) - fDz; << 526 if (dist > distz) << 527 return { fPlanes[iside].a, fPlanes[iside]. << 528 else << 529 return { 0, 0, (G4double)((p.z() < 0) ? -1 << 530 } 508 } 531 509 532 ////////////////////////////////////////////// << 510 ////////////////////////////////////////////////////////////////////////////// 533 // 511 // 534 // Calculate distance to shape from outside 512 // Calculate distance to shape from outside 535 // - return kInfinity if no intersection << 513 // - return kInfinity if no intersection 536 << 514 // 537 G4double G4Para::DistanceToIn(const G4ThreeVec << 515 // ALGORITHM: 538 const G4ThreeVec << 516 // For each component, calculate pair of minimum and maximum intersection 539 { << 517 // values for which the particle is in the extent of the shape 540 // Z intersections << 518 // - The smallest (MAX minimum) allowed distance of the pairs is intersect >> 519 // - Z plane intersectin uses tolerance >> 520 // - XZ YZ planes use logic & *SLIGHTLY INCORRECT* tolerance >> 521 // (this saves at least 1 sqrt, 1 multiply and 1 divide... in applicable >> 522 // cases) >> 523 // - Note: XZ and YZ planes each divide space into four regions, >> 524 // characterised by ss1 ss2 >> 525 >> 526 G4double G4Para::DistanceToIn( const G4ThreeVector& p, >> 527 const G4ThreeVector& v ) const >> 528 { >> 529 G4double snxt; // snxt = default return value >> 530 G4double smin,smax; >> 531 G4double tmin,tmax; >> 532 G4double yt,vy,xt,vx; >> 533 G4double max; 541 // 534 // 542 if ((std::abs(p.z()) - fDz) >= -halfCarToler << 535 // Z Intersection range 543 return kInfinity; << 544 G4double invz = (-v.z() == 0) ? DBL_MAX : -1 << 545 G4double dz = (invz < 0) ? fDz : -fDz; << 546 G4double tzmin = (p.z() + dz)*invz; << 547 G4double tzmax = (p.z() - dz)*invz; << 548 << 549 // Y intersections << 550 // 536 // 551 G4double tmin0 = tzmin, tmax0 = tzmax; << 537 if (v.z()>0) 552 G4double cos0 = fPlanes[0].b*v.y() + fPlanes << 553 G4double disy = fPlanes[0].b*p.y() + fPlanes << 554 G4double dis0 = fPlanes[0].d + disy; << 555 if (dis0 >= -halfCarTolerance) << 556 { 538 { 557 if (cos0 >= 0) return kInfinity; << 539 max=fDz-p.z(); 558 G4double tmp = -dis0/cos0; << 540 if (max>kCarTolerance*0.5) 559 if (tmin0 < tmp) tmin0 = tmp; << 541 { >> 542 smax=max/v.z(); >> 543 smin=(-fDz-p.z())/v.z(); >> 544 } >> 545 else >> 546 { >> 547 return snxt=kInfinity; >> 548 } >> 549 } >> 550 else if (v.z()<0) >> 551 { >> 552 max=-fDz-p.z(); >> 553 if (max<-kCarTolerance*0.5) >> 554 { >> 555 smax=max/v.z(); >> 556 smin=(fDz-p.z())/v.z(); >> 557 } >> 558 else >> 559 { >> 560 return snxt=kInfinity; >> 561 } 560 } 562 } 561 else if (cos0 > 0) << 563 else 562 { 564 { 563 G4double tmp = -dis0/cos0; << 565 if (fabs(p.z())<=fDz) // Inside 564 if (tmax0 > tmp) tmax0 = tmp; << 566 { >> 567 smin=0; >> 568 smax=kInfinity; >> 569 } >> 570 else >> 571 { >> 572 return snxt=kInfinity; >> 573 } 565 } 574 } >> 575 >> 576 // >> 577 // Y G4Parallel planes intersection >> 578 // >> 579 >> 580 yt=p.y()-fTthetaSphi*p.z(); >> 581 vy=v.y()-fTthetaSphi*v.z(); 566 582 567 G4double tmin1 = tmin0, tmax1 = tmax0; << 583 if (vy>0) 568 G4double cos1 = -cos0; << 569 G4double dis1 = fPlanes[1].d - disy; << 570 if (dis1 >= -halfCarTolerance) << 571 { 584 { 572 if (cos1 >= 0) return kInfinity; << 585 max=fDy-yt; 573 G4double tmp = -dis1/cos1; << 586 if (max>kCarTolerance*0.5) 574 if (tmin1 < tmp) tmin1 = tmp; << 587 { >> 588 tmax=max/vy; >> 589 tmin=(-fDy-yt)/vy; >> 590 } >> 591 else >> 592 { >> 593 return snxt=kInfinity; >> 594 } 575 } 595 } 576 else if (cos1 > 0) << 596 else if (vy<0) 577 { 597 { 578 G4double tmp = -dis1/cos1; << 598 max=-fDy-yt; 579 if (tmax1 > tmp) tmax1 = tmp; << 599 if (max<-kCarTolerance*0.5) >> 600 { >> 601 tmax=max/vy; >> 602 tmin=(fDy-yt)/vy; >> 603 } >> 604 else >> 605 { >> 606 return snxt=kInfinity; >> 607 } >> 608 } >> 609 else >> 610 { >> 611 if (fabs(yt)<=fDy) >> 612 { >> 613 tmin=0; >> 614 tmax=kInfinity; >> 615 } >> 616 else >> 617 { >> 618 return snxt=kInfinity; >> 619 } 580 } 620 } 581 621 582 // X intersections << 622 // Re-Calc valid intersection range 583 // 623 // 584 G4double tmin2 = tmin1, tmax2 = tmax1; << 624 if (tmin>smin) smin=tmin; 585 G4double cos2 = fPlanes[2].a*v.x() + fPlanes << 625 if (tmax<smax) smax=tmax; 586 G4double disx = fPlanes[2].a*p.x() + fPlanes << 626 if (smax<=smin) 587 G4double dis2 = fPlanes[2].d + disx; << 588 if (dis2 >= -halfCarTolerance) << 589 { 627 { 590 if (cos2 >= 0) return kInfinity; << 628 return snxt=kInfinity; 591 G4double tmp = -dis2/cos2; << 592 if (tmin2 < tmp) tmin2 = tmp; << 593 } 629 } 594 else if (cos2 > 0) << 630 else 595 { 631 { 596 G4double tmp = -dis2/cos2; << 632 // 597 if (tmax2 > tmp) tmax2 = tmp; << 633 // X G4Parallel planes intersection >> 634 // >> 635 xt=p.x()-fTthetaCphi*p.z()-fTalpha*yt; >> 636 vx=v.x()-fTthetaCphi*v.z()-fTalpha*vy; >> 637 if (vx>0) >> 638 { >> 639 max=fDx-xt; >> 640 if (max>kCarTolerance*0.5) >> 641 { >> 642 tmax=max/vx; >> 643 tmin=(-fDx-xt)/vx; >> 644 } >> 645 else >> 646 { >> 647 return snxt=kInfinity; >> 648 } >> 649 } >> 650 else if (vx<0) >> 651 { >> 652 max=-fDx-xt; >> 653 if (max<-kCarTolerance*0.5) >> 654 { >> 655 tmax=max/vx; >> 656 tmin=(fDx-xt)/vx; >> 657 } >> 658 else >> 659 { >> 660 return snxt=kInfinity; >> 661 } >> 662 } >> 663 else >> 664 { >> 665 if (fabs(xt)<=fDx) >> 666 { >> 667 tmin=0; >> 668 tmax=kInfinity; >> 669 } >> 670 else >> 671 { >> 672 return snxt=kInfinity; >> 673 } >> 674 } >> 675 if (tmin>smin) smin=tmin; >> 676 if (tmax<smax) smax=tmax; 598 } 677 } 599 678 600 G4double tmin3 = tmin2, tmax3 = tmax2; << 679 if (smax>0&&smin<smax) 601 G4double cos3 = -cos2; << 602 G4double dis3 = fPlanes[3].d - disx; << 603 if (dis3 >= -halfCarTolerance) << 604 { 680 { 605 if (cos3 >= 0) return kInfinity; << 681 if (smin>0) 606 G4double tmp = -dis3/cos3; << 682 { 607 if (tmin3 < tmp) tmin3 = tmp; << 683 snxt=smin; >> 684 } >> 685 else >> 686 { >> 687 snxt=0; >> 688 } 608 } 689 } 609 else if (cos3 > 0) << 690 else 610 { 691 { 611 G4double tmp = -dis3/cos3; << 692 snxt=kInfinity; 612 if (tmax3 > tmp) tmax3 = tmp; << 613 } 693 } 614 << 694 return snxt; 615 // Find distance << 616 // << 617 G4double tmin = tmin3, tmax = tmax3; << 618 if (tmax <= tmin + halfCarTolerance) return << 619 return (tmin < halfCarTolerance ) ? 0. : tmi << 620 } 695 } 621 696 622 ////////////////////////////////////////////// << 697 //////////////////////////////////////////////////////////////////////////// 623 // 698 // 624 // Calculate exact shortest distance to any bo 699 // Calculate exact shortest distance to any boundary from outside 625 // - returns 0 is point inside << 700 // - Returns 0 is point inside 626 701 627 G4double G4Para::DistanceToIn( const G4ThreeVe 702 G4double G4Para::DistanceToIn( const G4ThreeVector& p ) const 628 { 703 { 629 G4double xx = fPlanes[2].a*p.x()+fPlanes[2]. << 704 G4double safe=0.0; 630 G4double dx = std::abs(xx) + fPlanes[2].d; << 705 G4double distz1,distz2,disty1,disty2,distx1,distx2; >> 706 G4double trany,cosy,tranx,cosx; 631 707 632 G4double yy = fPlanes[0].b*p.y()+fPlanes[0]. << 708 // Z planes 633 G4double dy = std::abs(yy) + fPlanes[0].d; << 709 // 634 G4double dxy = std::max(dx,dy); << 710 distz1=p.z()-fDz; >> 711 distz2=-fDz-p.z(); >> 712 if (distz1>distz2) >> 713 { >> 714 safe=distz1; >> 715 } >> 716 else >> 717 { >> 718 safe=distz2; >> 719 } 635 720 636 G4double dz = std::abs(p.z())-fDz; << 721 trany=p.y()-fTthetaSphi*p.z(); // Transformed y into `box' system 637 G4double dist = std::max(dxy,dz); << 638 722 639 return (dist > 0) ? dist : 0.; << 723 // Transformed x into `box' system >> 724 // >> 725 cosy=1.0/sqrt(1.0+fTthetaSphi*fTthetaSphi); >> 726 disty1=(trany-fDy)*cosy; >> 727 disty2=(-fDy-trany)*cosy; >> 728 >> 729 if (disty1>safe) safe=disty1; >> 730 if (disty2>safe) safe=disty2; >> 731 >> 732 tranx=p.x()-fTthetaCphi*p.z()-fTalpha*trany; >> 733 cosx=1.0/sqrt(1.0+fTalpha*fTalpha+fTthetaCphi*fTthetaCphi); >> 734 distx1=(tranx-fDx)*cosx; >> 735 distx2=(-fDx-tranx)*cosx; >> 736 >> 737 if (distx1>safe) safe=distx1; >> 738 if (distx2>safe) safe=distx2; >> 739 >> 740 if (safe<0) safe=0; >> 741 return safe; 640 } 742 } 641 743 642 ////////////////////////////////////////////// 744 ////////////////////////////////////////////////////////////////////////// 643 // 745 // 644 // Calculate distance to surface of shape from << 746 // Calculate distance to surface of shape from inside 645 // find normal at exit point << 747 // Calculate distance to x/y/z planes - smallest is exiting distance 646 // - when leaving the surface, return 0 << 647 748 648 G4double G4Para::DistanceToOut(const G4ThreeVe 749 G4double G4Para::DistanceToOut(const G4ThreeVector& p, const G4ThreeVector& v, 649 const G4bool ca 750 const G4bool calcNorm, 650 G4bool* v << 751 G4bool *validNorm, G4ThreeVector *n) const 651 { 752 { 652 // Z intersections << 753 ESide side = kUndef; >> 754 G4double snxt; // snxt = return value >> 755 G4double max,tmax; >> 756 G4double yt,vy,xt,vx; >> 757 >> 758 G4double ycomp,calpha,salpha,tntheta,cosntheta; >> 759 >> 760 // >> 761 // Z Intersections 653 // 762 // 654 if ((std::abs(p.z()) - fDz) >= -halfCarToler << 763 >> 764 if (v.z()>0) 655 { 765 { 656 if (calcNorm) << 766 max=fDz-p.z(); >> 767 if (max>kCarTolerance*0.5) 657 { 768 { 658 *validNorm = true; << 769 snxt=max/v.z(); 659 n->set(0, 0, (p.z() < 0) ? -1 : 1); << 770 side=kPZ; >> 771 } >> 772 else >> 773 { >> 774 if (calcNorm) >> 775 { >> 776 *validNorm=true; >> 777 *n=G4ThreeVector(0,0,1); >> 778 } >> 779 return snxt=0; 660 } 780 } 661 return 0.; << 662 } 781 } 663 G4double vz = v.z(); << 782 else if (v.z()<0) 664 G4double tmax = (vz == 0) ? DBL_MAX : (std:: << 665 G4int iside = (vz < 0) ? -4 : -2; // little << 666 << 667 // Y intersections << 668 // << 669 G4double cos0 = fPlanes[0].b*v.y() + fPlanes << 670 if (cos0 > 0) << 671 { 783 { 672 G4double dis0 = fPlanes[0].b*p.y() + fPlan << 784 max=-fDz-p.z(); 673 if (dis0 >= -halfCarTolerance) << 785 if (max<-kCarTolerance*0.5) >> 786 { >> 787 snxt=max/v.z(); >> 788 side=kMZ; >> 789 } >> 790 else 674 { 791 { 675 if (calcNorm) 792 if (calcNorm) 676 { 793 { 677 *validNorm = true; << 794 *validNorm=true; 678 n->set(0, fPlanes[0].b, fPlanes[0].c); << 795 *n=G4ThreeVector(0,0,-1); 679 } 796 } 680 return 0.; << 797 return snxt=0; 681 } 798 } 682 G4double tmp = -dis0/cos0; << 683 if (tmax > tmp) { tmax = tmp; iside = 0; } << 684 } 799 } >> 800 else >> 801 { >> 802 snxt=kInfinity; >> 803 } >> 804 >> 805 // >> 806 // Y plane intersection >> 807 // 685 808 686 G4double cos1 = -cos0; << 809 yt=p.y()-fTthetaSphi*p.z(); 687 if (cos1 > 0) << 810 vy=v.y()-fTthetaSphi*v.z(); >> 811 >> 812 if (vy>0) 688 { 813 { 689 G4double dis1 = fPlanes[1].b*p.y() + fPlan << 814 max=fDy-yt; 690 if (dis1 >= -halfCarTolerance) << 815 if (max>kCarTolerance*0.5) >> 816 { >> 817 tmax=max/vy; >> 818 if (tmax<snxt) >> 819 { >> 820 snxt=tmax; >> 821 side=kPY; >> 822 } >> 823 } >> 824 else 691 { 825 { 692 if (calcNorm) 826 if (calcNorm) >> 827 { >> 828 *validNorm=true; // Leaving via plus Y >> 829 ycomp=1/sqrt(1+fTthetaSphi*fTthetaSphi); >> 830 *n=G4ThreeVector(0,ycomp,-fTthetaSphi*ycomp); >> 831 } >> 832 return snxt=0; >> 833 } >> 834 } >> 835 else if (vy<0) >> 836 { >> 837 max=-fDy-yt; >> 838 if (max<-kCarTolerance*0.5) >> 839 { >> 840 tmax=max/vy; >> 841 if (tmax<snxt) 693 { 842 { 694 *validNorm = true; << 843 snxt=tmax; 695 n->set(0, fPlanes[1].b, fPlanes[1].c); << 844 side=kMY; 696 } 845 } 697 return 0.; << 698 } 846 } 699 G4double tmp = -dis1/cos1; << 847 else 700 if (tmax > tmp) { tmax = tmp; iside = 1; } << 848 { >> 849 if (calcNorm) >> 850 { >> 851 *validNorm=true; // Leaving via minus Y >> 852 ycomp=-1/sqrt(1+fTthetaSphi*fTthetaSphi); >> 853 *n=G4ThreeVector(0,ycomp,-fTthetaSphi*ycomp); >> 854 } >> 855 return snxt=0; >> 856 } 701 } 857 } 702 858 703 // X intersections << 704 // 859 // 705 G4double cos2 = fPlanes[2].a*v.x() + fPlanes << 860 // X plane intersection 706 if (cos2 > 0) << 861 // >> 862 >> 863 xt=p.x()-fTthetaCphi*p.z()-fTalpha*yt; >> 864 vx=v.x()-fTthetaCphi*v.z()-fTalpha*vy; >> 865 if (vx>0) 707 { 866 { 708 G4double dis2 = fPlanes[2].a*p.x()+fPlanes << 867 max=fDx-xt; 709 if (dis2 >= -halfCarTolerance) << 868 if (max>kCarTolerance*0.5) >> 869 { >> 870 tmax=max/vx; >> 871 if (tmax<snxt) >> 872 { >> 873 snxt=tmax; >> 874 side=kPX; >> 875 } >> 876 } >> 877 else 710 { 878 { 711 if (calcNorm) 879 if (calcNorm) 712 { 880 { 713 *validNorm = true; << 881 *validNorm=true; // Leaving via plus X 714 n->set(fPlanes[2].a, fPlanes[2].b, fP << 882 calpha=1/sqrt(1+fTalpha*fTalpha); >> 883 if (fTalpha) >> 884 { >> 885 salpha=-calpha/fTalpha; // NOTE: actually use MINUS sin(alpha) >> 886 } >> 887 else >> 888 { >> 889 salpha=0; >> 890 } >> 891 tntheta=fTthetaCphi*calpha+fTthetaSphi*salpha; >> 892 cosntheta=1/sqrt(1+tntheta*tntheta); >> 893 *n=G4ThreeVector(calpha*cosntheta,salpha*cosntheta,-tntheta*cosntheta); 715 } 894 } 716 return 0.; << 895 return snxt=0; 717 } 896 } 718 G4double tmp = -dis2/cos2; << 719 if (tmax > tmp) { tmax = tmp; iside = 2; } << 720 } 897 } 721 << 898 else if (vx<0) 722 G4double cos3 = -cos2; << 723 if (cos3 > 0) << 724 { 899 { 725 G4double dis3 = fPlanes[3].a*p.x()+fPlanes << 900 max=-fDx-xt; 726 if (dis3 >= -halfCarTolerance) << 901 if (max<-kCarTolerance*0.5) >> 902 { >> 903 tmax=max/vx; >> 904 if (tmax<snxt) >> 905 { >> 906 snxt=tmax; >> 907 side=kMX; >> 908 } >> 909 } >> 910 else 727 { 911 { 728 if (calcNorm) 912 if (calcNorm) 729 { 913 { 730 *validNorm = true; << 914 *validNorm=true; // Leaving via minus X 731 n->set(fPlanes[3].a, fPlanes[3].b, fP << 915 calpha=1/sqrt(1+fTalpha*fTalpha); >> 916 if (fTalpha) >> 917 { >> 918 salpha=-calpha/fTalpha; // NOTE: actually use MINUS sin(alpha) >> 919 } >> 920 else >> 921 { >> 922 salpha=0; >> 923 } >> 924 tntheta=fTthetaCphi*calpha+fTthetaSphi*salpha; >> 925 cosntheta=-1/sqrt(1+tntheta*tntheta); >> 926 *n=G4ThreeVector(calpha*cosntheta,salpha*cosntheta,-tntheta*cosntheta); >> 927 return snxt=0; 732 } 928 } 733 return 0.; << 734 } 929 } 735 G4double tmp = -dis3/cos3; << 736 if (tmax > tmp) { tmax = tmp; iside = 3; } << 737 } 930 } 738 931 739 // Set normal, if required, and return dista << 932 if (calcNorm) 740 // << 741 if (calcNorm) << 742 { 933 { 743 *validNorm = true; << 934 *validNorm=true; 744 if (iside < 0) << 935 switch (side) 745 n->set(0, 0, iside + 3); // (-4+3)=-1, ( << 936 { 746 else << 937 case kMZ: 747 n->set(fPlanes[iside].a, fPlanes[iside]. << 938 *n=G4ThreeVector(0,0,-1); >> 939 break; >> 940 case kPZ: >> 941 *n=G4ThreeVector(0,0,1); >> 942 break; >> 943 case kMY: >> 944 ycomp=-1/sqrt(1+fTthetaSphi*fTthetaSphi); >> 945 *n=G4ThreeVector(0,ycomp,-fTthetaSphi*ycomp); >> 946 break; >> 947 case kPY: >> 948 ycomp=1/sqrt(1+fTthetaSphi*fTthetaSphi); >> 949 *n=G4ThreeVector(0,ycomp,-fTthetaSphi*ycomp); >> 950 break; >> 951 case kMX: >> 952 calpha=1/sqrt(1+fTalpha*fTalpha); >> 953 if (fTalpha) >> 954 { >> 955 salpha=-calpha/fTalpha; // NOTE: actually use MINUS sin(alpha) >> 956 } >> 957 else >> 958 { >> 959 salpha=0; >> 960 } >> 961 tntheta=fTthetaCphi*calpha+fTthetaSphi*salpha; >> 962 cosntheta=-1/sqrt(1+tntheta*tntheta); >> 963 *n=G4ThreeVector(calpha*cosntheta,salpha*cosntheta,-tntheta*cosntheta); >> 964 break; >> 965 case kPX: >> 966 calpha=1/sqrt(1+fTalpha*fTalpha); >> 967 if (fTalpha) >> 968 { >> 969 salpha=-calpha/fTalpha; // NOTE: actually use MINUS sin(alpha) >> 970 } >> 971 else >> 972 { >> 973 salpha=0; >> 974 } >> 975 tntheta=fTthetaCphi*calpha+fTthetaSphi*salpha; >> 976 cosntheta=1/sqrt(1+tntheta*tntheta); >> 977 *n=G4ThreeVector(calpha*cosntheta,salpha*cosntheta,-tntheta*cosntheta); >> 978 break; >> 979 default: >> 980 DumpInfo(); >> 981 G4Exception("G4Para::DistanceToOut(p,v,..)","Notification",JustWarning, >> 982 "Undefined side for valid surface normal to solid."); >> 983 break; >> 984 } 748 } 985 } 749 return tmax; << 986 return snxt; 750 } 987 } 751 988 752 ////////////////////////////////////////////// << 989 ///////////////////////////////////////////////////////////////////////////// 753 // 990 // 754 // Calculate exact shortest distance to any bo 991 // Calculate exact shortest distance to any boundary from inside 755 // - returns 0 is point outside << 992 // - Returns 0 is point outside 756 993 757 G4double G4Para::DistanceToOut( const G4ThreeV 994 G4double G4Para::DistanceToOut( const G4ThreeVector& p ) const 758 { 995 { >> 996 G4double safe=0.0; >> 997 G4double distz1,distz2,disty1,disty2,distx1,distx2; >> 998 G4double trany,cosy,tranx,cosx; >> 999 759 #ifdef G4CSGDEBUG 1000 #ifdef G4CSGDEBUG 760 if( Inside(p) == kOutside ) 1001 if( Inside(p) == kOutside ) 761 { 1002 { 762 std::ostringstream message; << 1003 G4cout.precision(16) ; 763 G4int oldprc = message.precision(16); << 1004 G4cout << G4endl ; 764 message << "Point p is outside (!?) of sol << 1005 DumpInfo(); 765 message << "Position:\n"; << 1006 G4cout << "Position:" << G4endl << G4endl ; 766 message << " p.x() = " << p.x()/mm << " << 1007 G4cout << "p.x() = " << p.x()/mm << " mm" << G4endl ; 767 message << " p.y() = " << p.y()/mm << " << 1008 G4cout << "p.y() = " << p.y()/mm << " mm" << G4endl ; 768 message << " p.z() = " << p.z()/mm << " << 1009 G4cout << "p.z() = " << p.z()/mm << " mm" << G4endl << G4endl ; 769 G4cout.precision(oldprc) ; << 1010 G4Exception("G4Para::DistanceToOut(p)", "Notification", 770 G4Exception("G4Para::DistanceToOut(p)", "G << 1011 JustWarning, "Point p is outside !?" ); 771 JustWarning, message ); << 1012 } 772 DumpInfo(); << 773 } << 774 #endif 1013 #endif 775 G4double xx = fPlanes[2].a*p.x()+fPlanes[2]. << 776 G4double dx = std::abs(xx) + fPlanes[2].d; << 777 << 778 G4double yy = fPlanes[0].b*p.y()+fPlanes[0]. << 779 G4double dy = std::abs(yy) + fPlanes[0].d; << 780 G4double dxy = std::max(dx,dy); << 781 1014 782 G4double dz = std::abs(p.z())-fDz; << 1015 // Z planes 783 G4double dist = std::max(dxy,dz); << 1016 // >> 1017 distz1=fDz-p.z(); >> 1018 distz2=fDz+p.z(); >> 1019 if (distz1<distz2) >> 1020 { >> 1021 safe=distz1; >> 1022 } >> 1023 else >> 1024 { >> 1025 safe=distz2; >> 1026 } 784 1027 785 return (dist < 0) ? -dist : 0.; << 1028 trany=p.y()-fTthetaSphi*p.z(); // Transformed y into `box' system 786 } << 787 1029 788 ////////////////////////////////////////////// << 1030 // Transformed x into `box' system 789 // << 1031 // 790 // GetEntityType << 1032 cosy=1.0/sqrt(1.0+fTthetaSphi*fTthetaSphi); >> 1033 disty1=(fDy-trany)*cosy; >> 1034 disty2=(fDy+trany)*cosy; >> 1035 >> 1036 if (disty1<safe) safe=disty1; >> 1037 if (disty2<safe) safe=disty2; 791 1038 792 G4GeometryType G4Para::GetEntityType() const << 1039 tranx=p.x()-fTthetaCphi*p.z()-fTalpha*trany; 793 { << 1040 cosx=1.0/sqrt(1.0+fTalpha*fTalpha+fTthetaCphi*fTthetaCphi); 794 return {"G4Para"}; << 1041 distx1=(fDx-tranx)*cosx; >> 1042 distx2=(fDx+tranx)*cosx; >> 1043 >> 1044 if (distx1<safe) safe=distx1; >> 1045 if (distx2<safe) safe=distx2; >> 1046 >> 1047 if (safe<0) safe=0; >> 1048 return safe; 795 } 1049 } 796 1050 797 ////////////////////////////////////////////// << 1051 //////////////////////////////////////////////////////////////////////////////// 798 // 1052 // 799 // IsFaceted << 1053 // Create a List containing the transformed vertices 800 << 1054 // Ordering [0-3] -fDz cross section 801 G4bool G4Para::IsFaceted() const << 1055 // [4-7] +fDz cross section such that [0] is below [4], 802 { << 1056 // [1] below [5] etc. 803 return true; << 1057 // Note: >> 1058 // Caller has deletion resposibility >> 1059 >> 1060 G4ThreeVectorList* >> 1061 G4Para::CreateRotatedVertices( const G4AffineTransform& pTransform ) const >> 1062 { >> 1063 G4ThreeVectorList *vertices; >> 1064 vertices=new G4ThreeVectorList(); >> 1065 vertices->reserve(8); >> 1066 if (vertices) >> 1067 { >> 1068 G4ThreeVector vertex0(-fDz*fTthetaCphi-fDy*fTalpha-fDx, >> 1069 -fDz*fTthetaSphi-fDy, -fDz); >> 1070 G4ThreeVector vertex1(-fDz*fTthetaCphi-fDy*fTalpha+fDx, >> 1071 -fDz*fTthetaSphi-fDy, -fDz); >> 1072 G4ThreeVector vertex2(-fDz*fTthetaCphi+fDy*fTalpha-fDx, >> 1073 -fDz*fTthetaSphi+fDy, -fDz); >> 1074 G4ThreeVector vertex3(-fDz*fTthetaCphi+fDy*fTalpha+fDx, >> 1075 -fDz*fTthetaSphi+fDy, -fDz); >> 1076 G4ThreeVector vertex4(+fDz*fTthetaCphi-fDy*fTalpha-fDx, >> 1077 +fDz*fTthetaSphi-fDy, +fDz); >> 1078 G4ThreeVector vertex5(+fDz*fTthetaCphi-fDy*fTalpha+fDx, >> 1079 +fDz*fTthetaSphi-fDy, +fDz); >> 1080 G4ThreeVector vertex6(+fDz*fTthetaCphi+fDy*fTalpha-fDx, >> 1081 +fDz*fTthetaSphi+fDy, +fDz); >> 1082 G4ThreeVector vertex7(+fDz*fTthetaCphi+fDy*fTalpha+fDx, >> 1083 +fDz*fTthetaSphi+fDy, +fDz); >> 1084 >> 1085 vertices->push_back(pTransform.TransformPoint(vertex0)); >> 1086 vertices->push_back(pTransform.TransformPoint(vertex1)); >> 1087 vertices->push_back(pTransform.TransformPoint(vertex2)); >> 1088 vertices->push_back(pTransform.TransformPoint(vertex3)); >> 1089 vertices->push_back(pTransform.TransformPoint(vertex4)); >> 1090 vertices->push_back(pTransform.TransformPoint(vertex5)); >> 1091 vertices->push_back(pTransform.TransformPoint(vertex6)); >> 1092 vertices->push_back(pTransform.TransformPoint(vertex7)); >> 1093 } >> 1094 else >> 1095 { >> 1096 DumpInfo(); >> 1097 G4Exception("G4Para::CreateRotatedVertices()", >> 1098 "FatalError", FatalException, >> 1099 "Error in allocation of vertices. Out of memory !"); >> 1100 } >> 1101 return vertices; 804 } 1102 } 805 1103 806 ////////////////////////////////////////////// 1104 ////////////////////////////////////////////////////////////////////////// 807 // 1105 // 808 // Make a clone of the object << 1106 // GetEntityType 809 // << 1107 810 G4VSolid* G4Para::Clone() const << 1108 G4GeometryType G4Para::GetEntityType() const 811 { 1109 { 812 return new G4Para(*this); << 1110 return G4String("G4Para"); 813 } 1111 } 814 1112 815 ////////////////////////////////////////////// 1113 ////////////////////////////////////////////////////////////////////////// 816 // 1114 // 817 // Stream object contents to an output stream 1115 // Stream object contents to an output stream 818 1116 819 std::ostream& G4Para::StreamInfo( std::ostream 1117 std::ostream& G4Para::StreamInfo( std::ostream& os ) const 820 { 1118 { 821 G4double alpha = std::atan(fTalpha); << 822 G4double theta = std::atan(std::sqrt(fTtheta << 823 fTtheta << 824 G4double phi = std::atan2(fTthetaSphi,fTth << 825 << 826 G4long oldprc = os.precision(16); << 827 os << "------------------------------------- 1119 os << "-----------------------------------------------------------\n" 828 << " *** Dump for solid - " << GetName 1120 << " *** Dump for solid - " << GetName() << " ***\n" 829 << " ================================= 1121 << " ===================================================\n" 830 << " Solid type: G4Para\n" 1122 << " Solid type: G4Para\n" 831 << " Parameters:\n" << 1123 << " Parameters: \n" 832 << " half length X: " << fDx/mm << " m << 1124 << " half length X: " << fDx/mm << " mm \n" 833 << " half length Y: " << fDy/mm << " m << 1125 << " half length Y: " << fDy/mm << " mm \n" 834 << " half length Z: " << fDz/mm << " m << 1126 << " half length Z: " << fDz/mm << " mm \n" 835 << " alpha: " << alpha/degree << "degr << 1127 << " tan(alpha) : " << fTalpha/degree << " degrees \n" 836 << " theta: " << theta/degree << "degr << 1128 << " tan(theta)*cos(phi): " << fTthetaCphi/degree << " degrees \n" 837 << " phi: " << phi/degree << "degrees\ << 1129 << " tan(theta)*sin(phi): " << fTthetaSphi/degree << " degrees \n" 838 << "------------------------------------- 1130 << "-----------------------------------------------------------\n"; 839 os.precision(oldprc); << 840 1131 841 return os; 1132 return os; 842 } 1133 } 843 1134 844 ////////////////////////////////////////////// << 1135 //////////////////////////////////////////////////////////////////////////// 845 // << 846 // Return a point randomly and uniformly selec << 847 << 848 G4ThreeVector G4Para::GetPointOnSurface() cons << 849 { << 850 G4double DyTalpha = fDy*fTalpha; << 851 G4double DzTthetaSphi = fDz*fTthetaSphi; << 852 G4double DzTthetaCphi = fDz*fTthetaCphi; << 853 << 854 // Set vertices << 855 // << 856 G4ThreeVector pt[8]; << 857 pt[0].set(-DzTthetaCphi-DyTalpha-fDx, -DzTth << 858 pt[1].set(-DzTthetaCphi-DyTalpha+fDx, -DzTth << 859 pt[2].set(-DzTthetaCphi+DyTalpha-fDx, -DzTth << 860 pt[3].set(-DzTthetaCphi+DyTalpha+fDx, -DzTth << 861 pt[4].set( DzTthetaCphi-DyTalpha-fDx, DzTth << 862 pt[5].set( DzTthetaCphi-DyTalpha+fDx, DzTth << 863 pt[6].set( DzTthetaCphi+DyTalpha-fDx, DzTth << 864 pt[7].set( DzTthetaCphi+DyTalpha+fDx, DzTth << 865 << 866 // Set areas (-Z, -Y, +Y, -X, +X, +Z) << 867 // << 868 G4ThreeVector vx(fDx, 0, 0); << 869 G4ThreeVector vy(DyTalpha, fDy, 0); << 870 G4ThreeVector vz(DzTthetaCphi, DzTthetaSphi, << 871 << 872 G4double sxy = fDx*fDy; // (vx.cross(vy)).ma << 873 G4double sxz = (vx.cross(vz)).mag(); << 874 G4double syz = (vy.cross(vz)).mag(); << 875 << 876 G4double sface[6] = { sxy, syz, syz, sxz, sx << 877 for (G4int i=1; i<6; ++i) { sface[i] += sfac << 878 << 879 // Select face << 880 // << 881 G4double select = sface[5]*G4UniformRand(); << 882 G4int k = 5; << 883 if (select <= sface[4]) k = 4; << 884 if (select <= sface[3]) k = 3; << 885 if (select <= sface[2]) k = 2; << 886 if (select <= sface[1]) k = 1; << 887 if (select <= sface[0]) k = 0; << 888 << 889 // Generate point << 890 // << 891 G4int ip[6][3] = {{0,1,2}, {0,4,1}, {2,3,6}, << 892 G4double u = G4UniformRand(); << 893 G4double v = G4UniformRand(); << 894 return (1.-u-v)*pt[ip[k][0]] + u*pt[ip[k][1] << 895 } << 896 << 897 ////////////////////////////////////////////// << 898 // 1136 // 899 // Methods for visualisation 1137 // Methods for visualisation 900 1138 901 void G4Para::DescribeYourselfTo ( G4VGraphicsS 1139 void G4Para::DescribeYourselfTo ( G4VGraphicsScene& scene ) const 902 { 1140 { 903 scene.AddSolid (*this); << 1141 scene.AddThis (*this); 904 } 1142 } 905 1143 906 G4Polyhedron* G4Para::CreatePolyhedron () cons 1144 G4Polyhedron* G4Para::CreatePolyhedron () const 907 { 1145 { 908 G4double phi = std::atan2(fTthetaSphi, fTthe << 1146 G4double phi = atan2(fTthetaSphi, fTthetaCphi); 909 G4double alpha = std::atan(fTalpha); << 1147 G4double alpha = atan(fTalpha); 910 G4double theta = std::atan(std::sqrt(fTtheta << 1148 G4double theta = atan(sqrt(fTthetaCphi*fTthetaCphi 911 fTtheta << 1149 +fTthetaSphi*fTthetaSphi)); 912 1150 913 return new G4PolyhedronPara(fDx, fDy, fDz, a 1151 return new G4PolyhedronPara(fDx, fDy, fDz, alpha, theta, phi); 914 } 1152 } 915 #endif << 1153 >> 1154 G4NURBS* G4Para::CreateNURBS () const >> 1155 { >> 1156 // return new G4NURBSbox (fDx, fDy, fDz); >> 1157 return 0 ; >> 1158 } >> 1159 >> 1160 // >> 1161 // >> 1162 /////////////////////////// End of G4Para.cc /////////////////////////// 916 1163