Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // Implementation for G4UCutTubs wrapper class 26 // Implementation for G4UCutTubs wrapper class 27 // 27 // 28 // 07.07.17 G.Cosmo, CERN/PH 28 // 07.07.17 G.Cosmo, CERN/PH 29 // ------------------------------------------- 29 // -------------------------------------------------------------------- 30 30 31 #include "G4CutTubs.hh" 31 #include "G4CutTubs.hh" 32 #include "G4UCutTubs.hh" 32 #include "G4UCutTubs.hh" 33 33 34 #if ( defined(G4GEOM_USE_USOLIDS) || defined(G 34 #if ( defined(G4GEOM_USE_USOLIDS) || defined(G4GEOM_USE_PARTIAL_USOLIDS) ) 35 35 36 #include "G4GeomTools.hh" 36 #include "G4GeomTools.hh" 37 #include "G4AffineTransform.hh" 37 #include "G4AffineTransform.hh" 38 #include "G4VPVParameterisation.hh" 38 #include "G4VPVParameterisation.hh" 39 #include "G4BoundingEnvelope.hh" 39 #include "G4BoundingEnvelope.hh" 40 40 41 using namespace CLHEP; 41 using namespace CLHEP; 42 42 43 ////////////////////////////////////////////// 43 ///////////////////////////////////////////////////////////////////////// 44 // 44 // 45 // Constructor - check parameters, convert ang 45 // Constructor - check parameters, convert angles so 0<sphi+dpshi<=2_PI 46 // - note if pdphi>2PI then reset 46 // - note if pdphi>2PI then reset to 2PI 47 47 48 G4UCutTubs::G4UCutTubs( const G4String& pName, 48 G4UCutTubs::G4UCutTubs( const G4String& pName, 49 G4double pRMin, 49 G4double pRMin, G4double pRMax, 50 G4double pDz, 50 G4double pDz, 51 G4double pSPhi, 51 G4double pSPhi, G4double pDPhi, 52 const G4ThreeVec << 52 G4ThreeVector pLowNorm, 53 const G4ThreeVec << 53 G4ThreeVector pHighNorm ) 54 : Base_t(pName, pRMin, pRMax, pDz, pSPhi, pD 54 : Base_t(pName, pRMin, pRMax, pDz, pSPhi, pDPhi, 55 pLowNorm.x(), pLowNorm.y(), pLowNor 55 pLowNorm.x(), pLowNorm.y(), pLowNorm.z(), 56 pHighNorm.x(), pHighNorm.y(), pHigh 56 pHighNorm.x(), pHighNorm.y(), pHighNorm.z()) 57 { 57 { 58 } 58 } 59 59 60 ////////////////////////////////////////////// 60 /////////////////////////////////////////////////////////////////////// 61 // 61 // 62 // Fake default constructor - sets only member 62 // Fake default constructor - sets only member data and allocates memory 63 // for usage restri 63 // for usage restricted to object persistency. 64 // 64 // 65 G4UCutTubs::G4UCutTubs( __void__& a ) 65 G4UCutTubs::G4UCutTubs( __void__& a ) 66 : Base_t(a) 66 : Base_t(a) 67 { 67 { 68 } 68 } 69 69 70 ////////////////////////////////////////////// 70 ////////////////////////////////////////////////////////////////////////// 71 // 71 // 72 // Destructor 72 // Destructor 73 73 74 G4UCutTubs::~G4UCutTubs() = default; << 74 G4UCutTubs::~G4UCutTubs() >> 75 { >> 76 } 75 77 76 ////////////////////////////////////////////// 78 ////////////////////////////////////////////////////////////////////////// 77 // 79 // 78 // Copy constructor 80 // Copy constructor 79 81 80 G4UCutTubs::G4UCutTubs(const G4UCutTubs& rhs) 82 G4UCutTubs::G4UCutTubs(const G4UCutTubs& rhs) 81 : Base_t(rhs) 83 : Base_t(rhs) 82 { 84 { 83 } 85 } 84 86 85 ////////////////////////////////////////////// 87 ////////////////////////////////////////////////////////////////////////// 86 // 88 // 87 // Assignment operator 89 // Assignment operator 88 90 89 G4UCutTubs& G4UCutTubs::operator = (const G4UC 91 G4UCutTubs& G4UCutTubs::operator = (const G4UCutTubs& rhs) 90 { 92 { 91 // Check assignment to self 93 // Check assignment to self 92 // 94 // 93 if (this == &rhs) { return *this; } 95 if (this == &rhs) { return *this; } 94 96 95 // Copy base class data 97 // Copy base class data 96 // 98 // 97 Base_t::operator=(rhs); 99 Base_t::operator=(rhs); 98 100 99 return *this; 101 return *this; 100 } 102 } 101 103 102 ////////////////////////////////////////////// 104 ///////////////////////////////////////////////////////////////////////// 103 // 105 // 104 // Accessors and modifiers 106 // Accessors and modifiers 105 107 106 G4double G4UCutTubs::GetInnerRadius() const 108 G4double G4UCutTubs::GetInnerRadius() const 107 { 109 { 108 return rmin(); 110 return rmin(); 109 } 111 } 110 G4double G4UCutTubs::GetOuterRadius() const 112 G4double G4UCutTubs::GetOuterRadius() const 111 { 113 { 112 return rmax(); 114 return rmax(); 113 } 115 } 114 G4double G4UCutTubs::GetZHalfLength() const 116 G4double G4UCutTubs::GetZHalfLength() const 115 { 117 { 116 return z(); 118 return z(); 117 } 119 } 118 G4double G4UCutTubs::GetStartPhiAngle() const 120 G4double G4UCutTubs::GetStartPhiAngle() const 119 { 121 { 120 return sphi(); 122 return sphi(); 121 } 123 } 122 G4double G4UCutTubs::GetDeltaPhiAngle() const 124 G4double G4UCutTubs::GetDeltaPhiAngle() const 123 { 125 { 124 return dphi(); 126 return dphi(); 125 } 127 } 126 G4double G4UCutTubs::GetSinStartPhi() const 128 G4double G4UCutTubs::GetSinStartPhi() const 127 { 129 { 128 return std::sin(GetStartPhiAngle()); 130 return std::sin(GetStartPhiAngle()); 129 } 131 } 130 G4double G4UCutTubs::GetCosStartPhi() const 132 G4double G4UCutTubs::GetCosStartPhi() const 131 { 133 { 132 return std::cos(GetStartPhiAngle()); 134 return std::cos(GetStartPhiAngle()); 133 } 135 } 134 G4double G4UCutTubs::GetSinEndPhi() const 136 G4double G4UCutTubs::GetSinEndPhi() const 135 { 137 { 136 return std::sin(GetStartPhiAngle()+GetDeltaP 138 return std::sin(GetStartPhiAngle()+GetDeltaPhiAngle()); 137 } 139 } 138 G4double G4UCutTubs::GetCosEndPhi() const 140 G4double G4UCutTubs::GetCosEndPhi() const 139 { 141 { 140 return std::cos(GetStartPhiAngle()+GetDeltaP 142 return std::cos(GetStartPhiAngle()+GetDeltaPhiAngle()); 141 } 143 } 142 G4ThreeVector G4UCutTubs::GetLowNorm () const 144 G4ThreeVector G4UCutTubs::GetLowNorm () const 143 { 145 { 144 U3Vector lc = BottomNormal(); 146 U3Vector lc = BottomNormal(); 145 return {lc.x(), lc.y(), lc.z()}; << 147 return G4ThreeVector(lc.x(), lc.y(), lc.z()); 146 } 148 } 147 G4ThreeVector G4UCutTubs::GetHighNorm () const 149 G4ThreeVector G4UCutTubs::GetHighNorm () const 148 { 150 { 149 U3Vector hc = TopNormal(); 151 U3Vector hc = TopNormal(); 150 return {hc.x(), hc.y(), hc.z()}; << 152 return G4ThreeVector(hc.x(), hc.y(), hc.z()); 151 } 153 } 152 154 153 void G4UCutTubs::SetInnerRadius(G4double newRM 155 void G4UCutTubs::SetInnerRadius(G4double newRMin) 154 { 156 { 155 SetRMin(newRMin); 157 SetRMin(newRMin); 156 fRebuildPolyhedron = true; 158 fRebuildPolyhedron = true; 157 } 159 } 158 void G4UCutTubs::SetOuterRadius(G4double newRM 160 void G4UCutTubs::SetOuterRadius(G4double newRMax) 159 { 161 { 160 SetRMax(newRMax); 162 SetRMax(newRMax); 161 fRebuildPolyhedron = true; 163 fRebuildPolyhedron = true; 162 } 164 } 163 void G4UCutTubs::SetZHalfLength(G4double newDz 165 void G4UCutTubs::SetZHalfLength(G4double newDz) 164 { 166 { 165 SetDz(newDz); 167 SetDz(newDz); 166 fRebuildPolyhedron = true; 168 fRebuildPolyhedron = true; 167 } 169 } 168 void G4UCutTubs::SetStartPhiAngle(G4double new 170 void G4UCutTubs::SetStartPhiAngle(G4double newSPhi, G4bool) 169 { 171 { 170 SetSPhi(newSPhi); 172 SetSPhi(newSPhi); 171 fRebuildPolyhedron = true; 173 fRebuildPolyhedron = true; 172 } 174 } 173 void G4UCutTubs::SetDeltaPhiAngle(G4double new 175 void G4UCutTubs::SetDeltaPhiAngle(G4double newDPhi) 174 { 176 { 175 SetDPhi(newDPhi); 177 SetDPhi(newDPhi); 176 fRebuildPolyhedron = true; 178 fRebuildPolyhedron = true; 177 } 179 } 178 180 179 ////////////////////////////////////////////// 181 ///////////////////////////////////////////////////////////////////////// 180 // 182 // 181 // Make a clone of the object 183 // Make a clone of the object 182 184 183 G4VSolid* G4UCutTubs::Clone() const 185 G4VSolid* G4UCutTubs::Clone() const 184 { 186 { 185 return new G4UCutTubs(*this); 187 return new G4UCutTubs(*this); 186 } 188 } 187 189 188 ////////////////////////////////////////////// 190 ////////////////////////////////////////////////////////////////////////// 189 // 191 // 190 // Get bounding box 192 // Get bounding box 191 193 192 void G4UCutTubs::BoundingLimits(G4ThreeVector& 194 void G4UCutTubs::BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const 193 { 195 { 194 static G4bool checkBBox = true; 196 static G4bool checkBBox = true; 195 197 196 G4double rmin = GetInnerRadius(); 198 G4double rmin = GetInnerRadius(); 197 G4double rmax = GetOuterRadius(); 199 G4double rmax = GetOuterRadius(); 198 G4double dz = GetZHalfLength(); 200 G4double dz = GetZHalfLength(); 199 G4double dphi = GetDeltaPhiAngle(); 201 G4double dphi = GetDeltaPhiAngle(); 200 202 201 G4double sinSphi = GetSinStartPhi(); 203 G4double sinSphi = GetSinStartPhi(); 202 G4double cosSphi = GetCosStartPhi(); 204 G4double cosSphi = GetCosStartPhi(); 203 G4double sinEphi = GetSinEndPhi(); 205 G4double sinEphi = GetSinEndPhi(); 204 G4double cosEphi = GetCosEndPhi(); 206 G4double cosEphi = GetCosEndPhi(); 205 207 206 G4ThreeVector norm; 208 G4ThreeVector norm; 207 G4double mag, topx, topy, dists, diste; 209 G4double mag, topx, topy, dists, diste; 208 G4bool iftop; 210 G4bool iftop; 209 211 210 // Find Zmin 212 // Find Zmin 211 // 213 // 212 G4double zmin; 214 G4double zmin; 213 norm = GetLowNorm(); 215 norm = GetLowNorm(); 214 mag = std::sqrt(norm.x()*norm.x() + norm.y( 216 mag = std::sqrt(norm.x()*norm.x() + norm.y()*norm.y()); 215 topx = (mag == 0) ? 0 : -rmax*norm.x()/mag; 217 topx = (mag == 0) ? 0 : -rmax*norm.x()/mag; 216 topy = (mag == 0) ? 0 : -rmax*norm.y()/mag; 218 topy = (mag == 0) ? 0 : -rmax*norm.y()/mag; 217 dists = sinSphi*topx - cosSphi*topy; 219 dists = sinSphi*topx - cosSphi*topy; 218 diste = -sinEphi*topx + cosEphi*topy; 220 diste = -sinEphi*topx + cosEphi*topy; 219 if (dphi > pi) 221 if (dphi > pi) 220 { 222 { 221 iftop = true; 223 iftop = true; 222 if (dists > 0 && diste > 0)iftop = false; 224 if (dists > 0 && diste > 0)iftop = false; 223 } 225 } 224 else 226 else 225 { 227 { 226 iftop = false; 228 iftop = false; 227 if (dists <= 0 && diste <= 0) iftop = true 229 if (dists <= 0 && diste <= 0) iftop = true; 228 } 230 } 229 if (iftop) 231 if (iftop) 230 { 232 { 231 zmin = -(norm.x()*topx + norm.y()*topy)/no 233 zmin = -(norm.x()*topx + norm.y()*topy)/norm.z() - dz; 232 } 234 } 233 else 235 else 234 { 236 { 235 G4double z1 = -rmin*(norm.x()*cosSphi + no 237 G4double z1 = -rmin*(norm.x()*cosSphi + norm.y()*sinSphi)/norm.z() - dz; 236 G4double z2 = -rmin*(norm.x()*cosEphi + no 238 G4double z2 = -rmin*(norm.x()*cosEphi + norm.y()*sinEphi)/norm.z() - dz; 237 G4double z3 = -rmax*(norm.x()*cosSphi + no 239 G4double z3 = -rmax*(norm.x()*cosSphi + norm.y()*sinSphi)/norm.z() - dz; 238 G4double z4 = -rmax*(norm.x()*cosEphi + no 240 G4double z4 = -rmax*(norm.x()*cosEphi + norm.y()*sinEphi)/norm.z() - dz; 239 zmin = std::min(std::min(std::min(z1,z2),z 241 zmin = std::min(std::min(std::min(z1,z2),z3),z4); 240 } 242 } 241 243 242 // Find Zmax 244 // Find Zmax 243 // 245 // 244 G4double zmax; 246 G4double zmax; 245 norm = GetHighNorm(); 247 norm = GetHighNorm(); 246 mag = std::sqrt(norm.x()*norm.x() + norm.y( 248 mag = std::sqrt(norm.x()*norm.x() + norm.y()*norm.y()); 247 topx = (mag == 0) ? 0 : -rmax*norm.x()/mag; 249 topx = (mag == 0) ? 0 : -rmax*norm.x()/mag; 248 topy = (mag == 0) ? 0 : -rmax*norm.y()/mag; 250 topy = (mag == 0) ? 0 : -rmax*norm.y()/mag; 249 dists = sinSphi*topx - cosSphi*topy; 251 dists = sinSphi*topx - cosSphi*topy; 250 diste = -sinEphi*topx + cosEphi*topy; 252 diste = -sinEphi*topx + cosEphi*topy; 251 if (dphi > pi) 253 if (dphi > pi) 252 { 254 { 253 iftop = true; 255 iftop = true; 254 if (dists > 0 && diste > 0) iftop = false; 256 if (dists > 0 && diste > 0) iftop = false; 255 } 257 } 256 else 258 else 257 { 259 { 258 iftop = false; 260 iftop = false; 259 if (dists <= 0 && diste <= 0) iftop = true 261 if (dists <= 0 && diste <= 0) iftop = true; 260 } 262 } 261 if (iftop) 263 if (iftop) 262 { 264 { 263 zmax = -(norm.x()*topx + norm.y()*topy)/no 265 zmax = -(norm.x()*topx + norm.y()*topy)/norm.z() + dz; 264 } 266 } 265 else 267 else 266 { 268 { 267 G4double z1 = -rmin*(norm.x()*cosSphi + no 269 G4double z1 = -rmin*(norm.x()*cosSphi + norm.y()*sinSphi)/norm.z() + dz; 268 G4double z2 = -rmin*(norm.x()*cosEphi + no 270 G4double z2 = -rmin*(norm.x()*cosEphi + norm.y()*sinEphi)/norm.z() + dz; 269 G4double z3 = -rmax*(norm.x()*cosSphi + no 271 G4double z3 = -rmax*(norm.x()*cosSphi + norm.y()*sinSphi)/norm.z() + dz; 270 G4double z4 = -rmax*(norm.x()*cosEphi + no 272 G4double z4 = -rmax*(norm.x()*cosEphi + norm.y()*sinEphi)/norm.z() + dz; 271 zmax = std::max(std::max(std::max(z1,z2),z 273 zmax = std::max(std::max(std::max(z1,z2),z3),z4); 272 } 274 } 273 275 274 // Find bounding box 276 // Find bounding box 275 // 277 // 276 if (GetDeltaPhiAngle() < twopi) 278 if (GetDeltaPhiAngle() < twopi) 277 { 279 { 278 G4TwoVector vmin,vmax; 280 G4TwoVector vmin,vmax; 279 G4GeomTools::DiskExtent(rmin,rmax, 281 G4GeomTools::DiskExtent(rmin,rmax, 280 GetSinStartPhi(),G 282 GetSinStartPhi(),GetCosStartPhi(), 281 GetSinEndPhi(),Get 283 GetSinEndPhi(),GetCosEndPhi(), 282 vmin,vmax); 284 vmin,vmax); 283 pMin.set(vmin.x(),vmin.y(), zmin); 285 pMin.set(vmin.x(),vmin.y(), zmin); 284 pMax.set(vmax.x(),vmax.y(), zmax); 286 pMax.set(vmax.x(),vmax.y(), zmax); 285 } 287 } 286 else 288 else 287 { 289 { 288 pMin.set(-rmax,-rmax, zmin); 290 pMin.set(-rmax,-rmax, zmin); 289 pMax.set( rmax, rmax, zmax); 291 pMax.set( rmax, rmax, zmax); 290 } 292 } 291 293 292 // Check correctness of the bounding box 294 // Check correctness of the bounding box 293 // 295 // 294 if (pMin.x() >= pMax.x() || pMin.y() >= pMax 296 if (pMin.x() >= pMax.x() || pMin.y() >= pMax.y() || pMin.z() >= pMax.z()) 295 { 297 { 296 std::ostringstream message; 298 std::ostringstream message; 297 message << "Bad bounding box (min >= max) 299 message << "Bad bounding box (min >= max) for solid: " 298 << GetName() << " !" 300 << GetName() << " !" 299 << "\npMin = " << pMin 301 << "\npMin = " << pMin 300 << "\npMax = " << pMax; 302 << "\npMax = " << pMax; 301 G4Exception("G4CUutTubs::BoundingLimits()" 303 G4Exception("G4CUutTubs::BoundingLimits()", "GeomMgt0001", 302 JustWarning, message); 304 JustWarning, message); 303 StreamInfo(G4cout); 305 StreamInfo(G4cout); 304 } 306 } 305 307 306 // Check consistency of bounding boxes 308 // Check consistency of bounding boxes 307 // 309 // 308 if (checkBBox) 310 if (checkBBox) 309 { 311 { 310 U3Vector vmin, vmax; 312 U3Vector vmin, vmax; 311 Extent(vmin,vmax); 313 Extent(vmin,vmax); 312 if (std::abs(pMin.x()-vmin.x()) > kCarTole 314 if (std::abs(pMin.x()-vmin.x()) > kCarTolerance || 313 std::abs(pMin.y()-vmin.y()) > kCarTole 315 std::abs(pMin.y()-vmin.y()) > kCarTolerance || 314 std::abs(pMin.z()-vmin.z()) > kCarTole 316 std::abs(pMin.z()-vmin.z()) > kCarTolerance || 315 std::abs(pMax.x()-vmax.x()) > kCarTole 317 std::abs(pMax.x()-vmax.x()) > kCarTolerance || 316 std::abs(pMax.y()-vmax.y()) > kCarTole 318 std::abs(pMax.y()-vmax.y()) > kCarTolerance || 317 std::abs(pMax.z()-vmax.z()) > kCarTole 319 std::abs(pMax.z()-vmax.z()) > kCarTolerance) 318 { 320 { 319 std::ostringstream message; 321 std::ostringstream message; 320 message << "Inconsistency in bounding bo 322 message << "Inconsistency in bounding boxes for solid: " 321 << GetName() << " !" 323 << GetName() << " !" 322 << "\nBBox min: wrapper = " << p 324 << "\nBBox min: wrapper = " << pMin << " solid = " << vmin 323 << "\nBBox max: wrapper = " << p 325 << "\nBBox max: wrapper = " << pMax << " solid = " << vmax; 324 G4Exception("G4UCutTubs::BoundingLimits( 326 G4Exception("G4UCutTubs::BoundingLimits()", "GeomMgt0001", 325 JustWarning, message); 327 JustWarning, message); 326 checkBBox = false; 328 checkBBox = false; 327 } 329 } 328 } 330 } 329 } 331 } 330 332 331 ////////////////////////////////////////////// 333 ////////////////////////////////////////////////////////////////////////// 332 // 334 // 333 // Calculate extent under transform and specif 335 // Calculate extent under transform and specified limit 334 336 335 G4bool 337 G4bool 336 G4UCutTubs::CalculateExtent(const EAxis pAxis, 338 G4UCutTubs::CalculateExtent(const EAxis pAxis, 337 const G4VoxelLimit 339 const G4VoxelLimits& pVoxelLimit, 338 const G4AffineTran 340 const G4AffineTransform& pTransform, 339 G4double& pM 341 G4double& pMin, G4double& pMax) const 340 { 342 { 341 G4ThreeVector bmin, bmax; 343 G4ThreeVector bmin, bmax; 342 G4bool exist; 344 G4bool exist; 343 345 344 // Get bounding box 346 // Get bounding box 345 BoundingLimits(bmin,bmax); 347 BoundingLimits(bmin,bmax); 346 348 347 // Check bounding box 349 // Check bounding box 348 G4BoundingEnvelope bbox(bmin,bmax); 350 G4BoundingEnvelope bbox(bmin,bmax); 349 #ifdef G4BBOX_EXTENT 351 #ifdef G4BBOX_EXTENT 350 if (true) return bbox.CalculateExtent(pAxis, 352 if (true) return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax); 351 #endif 353 #endif 352 if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVox 354 if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax)) 353 { 355 { 354 return exist = pMin < pMax; << 356 return exist = (pMin < pMax) ? true : false; 355 } 357 } 356 358 357 // Get parameters of the solid 359 // Get parameters of the solid 358 G4double rmin = GetInnerRadius(); 360 G4double rmin = GetInnerRadius(); 359 G4double rmax = GetOuterRadius(); 361 G4double rmax = GetOuterRadius(); 360 G4double dphi = GetDeltaPhiAngle(); 362 G4double dphi = GetDeltaPhiAngle(); 361 G4double zmin = bmin.z(); 363 G4double zmin = bmin.z(); 362 G4double zmax = bmax.z(); 364 G4double zmax = bmax.z(); 363 365 364 // Find bounding envelope and calculate exte 366 // Find bounding envelope and calculate extent 365 // 367 // 366 const G4int NSTEPS = 24; // numbe 368 const G4int NSTEPS = 24; // number of steps for whole circle 367 G4double astep = twopi/NSTEPS; // max a 369 G4double astep = twopi/NSTEPS; // max angle for one step 368 G4int ksteps = (dphi <= astep) ? 1 : (G4i 370 G4int ksteps = (dphi <= astep) ? 1 : (G4int)((dphi-deg)/astep) + 1; 369 G4double ang = dphi/ksteps; 371 G4double ang = dphi/ksteps; 370 372 371 G4double sinHalf = std::sin(0.5*ang); 373 G4double sinHalf = std::sin(0.5*ang); 372 G4double cosHalf = std::cos(0.5*ang); 374 G4double cosHalf = std::cos(0.5*ang); 373 G4double sinStep = 2.*sinHalf*cosHalf; 375 G4double sinStep = 2.*sinHalf*cosHalf; 374 G4double cosStep = 1. - 2.*sinHalf*sinHalf; 376 G4double cosStep = 1. - 2.*sinHalf*sinHalf; 375 G4double rext = rmax/cosHalf; 377 G4double rext = rmax/cosHalf; 376 378 377 // bounding envelope for full cylinder consi 379 // bounding envelope for full cylinder consists of two polygons, 378 // in other cases it is a sequence of quadri 380 // in other cases it is a sequence of quadrilaterals 379 if (rmin == 0 && dphi == twopi) 381 if (rmin == 0 && dphi == twopi) 380 { 382 { 381 G4double sinCur = sinHalf; 383 G4double sinCur = sinHalf; 382 G4double cosCur = cosHalf; 384 G4double cosCur = cosHalf; 383 385 384 G4ThreeVectorList baseA(NSTEPS),baseB(NSTE 386 G4ThreeVectorList baseA(NSTEPS),baseB(NSTEPS); 385 for (G4int k=0; k<NSTEPS; ++k) 387 for (G4int k=0; k<NSTEPS; ++k) 386 { 388 { 387 baseA[k].set(rext*cosCur,rext*sinCur,zmi 389 baseA[k].set(rext*cosCur,rext*sinCur,zmin); 388 baseB[k].set(rext*cosCur,rext*sinCur,zma 390 baseB[k].set(rext*cosCur,rext*sinCur,zmax); 389 391 390 G4double sinTmp = sinCur; 392 G4double sinTmp = sinCur; 391 sinCur = sinCur*cosStep + cosCur*sinStep 393 sinCur = sinCur*cosStep + cosCur*sinStep; 392 cosCur = cosCur*cosStep - sinTmp*sinStep 394 cosCur = cosCur*cosStep - sinTmp*sinStep; 393 } 395 } 394 std::vector<const G4ThreeVectorList *> pol 396 std::vector<const G4ThreeVectorList *> polygons(2); 395 polygons[0] = &baseA; 397 polygons[0] = &baseA; 396 polygons[1] = &baseB; 398 polygons[1] = &baseB; 397 G4BoundingEnvelope benv(bmin,bmax,polygons 399 G4BoundingEnvelope benv(bmin,bmax,polygons); 398 exist = benv.CalculateExtent(pAxis,pVoxelL 400 exist = benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax); 399 } 401 } 400 else 402 else 401 { 403 { 402 G4double sinStart = GetSinStartPhi(); 404 G4double sinStart = GetSinStartPhi(); 403 G4double cosStart = GetCosStartPhi(); 405 G4double cosStart = GetCosStartPhi(); 404 G4double sinEnd = GetSinEndPhi(); 406 G4double sinEnd = GetSinEndPhi(); 405 G4double cosEnd = GetCosEndPhi(); 407 G4double cosEnd = GetCosEndPhi(); 406 G4double sinCur = sinStart*cosHalf + cos 408 G4double sinCur = sinStart*cosHalf + cosStart*sinHalf; 407 G4double cosCur = cosStart*cosHalf - sin 409 G4double cosCur = cosStart*cosHalf - sinStart*sinHalf; 408 410 409 // set quadrilaterals 411 // set quadrilaterals 410 G4ThreeVectorList pols[NSTEPS+2]; 412 G4ThreeVectorList pols[NSTEPS+2]; 411 for (G4int k=0; k<ksteps+2; ++k) pols[k].r 413 for (G4int k=0; k<ksteps+2; ++k) pols[k].resize(4); 412 pols[0][0].set(rmin*cosStart,rmin*sinStart 414 pols[0][0].set(rmin*cosStart,rmin*sinStart,zmax); 413 pols[0][1].set(rmin*cosStart,rmin*sinStart 415 pols[0][1].set(rmin*cosStart,rmin*sinStart,zmin); 414 pols[0][2].set(rmax*cosStart,rmax*sinStart 416 pols[0][2].set(rmax*cosStart,rmax*sinStart,zmin); 415 pols[0][3].set(rmax*cosStart,rmax*sinStart 417 pols[0][3].set(rmax*cosStart,rmax*sinStart,zmax); 416 for (G4int k=1; k<ksteps+1; ++k) 418 for (G4int k=1; k<ksteps+1; ++k) 417 { 419 { 418 pols[k][0].set(rmin*cosCur,rmin*sinCur,z 420 pols[k][0].set(rmin*cosCur,rmin*sinCur,zmax); 419 pols[k][1].set(rmin*cosCur,rmin*sinCur,z 421 pols[k][1].set(rmin*cosCur,rmin*sinCur,zmin); 420 pols[k][2].set(rext*cosCur,rext*sinCur,z 422 pols[k][2].set(rext*cosCur,rext*sinCur,zmin); 421 pols[k][3].set(rext*cosCur,rext*sinCur,z 423 pols[k][3].set(rext*cosCur,rext*sinCur,zmax); 422 424 423 G4double sinTmp = sinCur; 425 G4double sinTmp = sinCur; 424 sinCur = sinCur*cosStep + cosCur*sinStep 426 sinCur = sinCur*cosStep + cosCur*sinStep; 425 cosCur = cosCur*cosStep - sinTmp*sinStep 427 cosCur = cosCur*cosStep - sinTmp*sinStep; 426 } 428 } 427 pols[ksteps+1][0].set(rmin*cosEnd,rmin*sin 429 pols[ksteps+1][0].set(rmin*cosEnd,rmin*sinEnd,zmax); 428 pols[ksteps+1][1].set(rmin*cosEnd,rmin*sin 430 pols[ksteps+1][1].set(rmin*cosEnd,rmin*sinEnd,zmin); 429 pols[ksteps+1][2].set(rmax*cosEnd,rmax*sin 431 pols[ksteps+1][2].set(rmax*cosEnd,rmax*sinEnd,zmin); 430 pols[ksteps+1][3].set(rmax*cosEnd,rmax*sin 432 pols[ksteps+1][3].set(rmax*cosEnd,rmax*sinEnd,zmax); 431 433 432 // set envelope and calculate extent 434 // set envelope and calculate extent 433 std::vector<const G4ThreeVectorList *> pol 435 std::vector<const G4ThreeVectorList *> polygons; 434 polygons.resize(ksteps+2); 436 polygons.resize(ksteps+2); 435 for (G4int k=0; k<ksteps+2; ++k) polygons[ 437 for (G4int k=0; k<ksteps+2; ++k) polygons[k] = &pols[k]; 436 G4BoundingEnvelope benv(bmin,bmax,polygons 438 G4BoundingEnvelope benv(bmin,bmax,polygons); 437 exist = benv.CalculateExtent(pAxis,pVoxelL 439 exist = benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax); 438 } 440 } 439 return exist; 441 return exist; 440 } 442 } 441 443 442 ////////////////////////////////////////////// 444 /////////////////////////////////////////////////////////////////////////// 443 // 445 // 444 // Return real Z coordinate of point on Cutted 446 // Return real Z coordinate of point on Cutted +/- fDZ plane 445 447 446 G4double G4UCutTubs::GetCutZ(const G4ThreeVect 448 G4double G4UCutTubs::GetCutZ(const G4ThreeVector& p) const 447 { 449 { 448 G4double newz = p.z(); // p.z() should be e 450 G4double newz = p.z(); // p.z() should be either +fDz or -fDz 449 G4ThreeVector fLowNorm = GetLowNorm(); 451 G4ThreeVector fLowNorm = GetLowNorm(); 450 G4ThreeVector fHighNorm = GetHighNorm(); 452 G4ThreeVector fHighNorm = GetHighNorm(); 451 453 452 if (p.z()<0) 454 if (p.z()<0) 453 { 455 { 454 if(fLowNorm.z()!=0.) 456 if(fLowNorm.z()!=0.) 455 { 457 { 456 newz = -GetZHalfLength() 458 newz = -GetZHalfLength() 457 - (p.x()*fLowNorm.x()+p.y()*fLowNo 459 - (p.x()*fLowNorm.x()+p.y()*fLowNorm.y())/fLowNorm.z(); 458 } 460 } 459 } 461 } 460 else 462 else 461 { 463 { 462 if(fHighNorm.z()!=0.) 464 if(fHighNorm.z()!=0.) 463 { 465 { 464 newz = GetZHalfLength() 466 newz = GetZHalfLength() 465 - (p.x()*fHighNorm.x()+p.y()*fHigh 467 - (p.x()*fHighNorm.x()+p.y()*fHighNorm.y())/fHighNorm.z(); 466 } 468 } 467 } 469 } 468 return newz; 470 return newz; 469 } 471 } 470 472 471 ////////////////////////////////////////////// 473 ////////////////////////////////////////////////////////////////////////// 472 // 474 // 473 // Create polyhedron for visualization 475 // Create polyhedron for visualization 474 // 476 // 475 G4Polyhedron* G4UCutTubs::CreatePolyhedron() c 477 G4Polyhedron* G4UCutTubs::CreatePolyhedron() const 476 { 478 { 477 typedef G4double G4double3[3]; 479 typedef G4double G4double3[3]; 478 typedef G4int G4int4[4]; 480 typedef G4int G4int4[4]; 479 481 480 auto ph = new G4Polyhedron; << 482 G4Polyhedron *ph = new G4Polyhedron; 481 G4Polyhedron *ph1 = new G4PolyhedronTubs(Get 483 G4Polyhedron *ph1 = new G4PolyhedronTubs(GetInnerRadius(), 482 Get 484 GetOuterRadius(), 483 Get 485 GetZHalfLength(), 484 Get 486 GetStartPhiAngle(), 485 Get 487 GetDeltaPhiAngle()); 486 G4int nn=ph1->GetNoVertices(); 488 G4int nn=ph1->GetNoVertices(); 487 G4int nf=ph1->GetNoFacets(); 489 G4int nf=ph1->GetNoFacets(); 488 auto xyz = new G4double3[nn]; // number of << 490 G4double3* xyz = new G4double3[nn]; // number of nodes 489 auto faces = new G4int4[nf] ; // number of << 491 G4int4* faces = new G4int4[nf] ; // number of faces 490 G4double fDz = GetZHalfLength(); 492 G4double fDz = GetZHalfLength(); 491 493 492 for(G4int i=0; i<nn; ++i) 494 for(G4int i=0; i<nn; ++i) 493 { 495 { 494 xyz[i][0]=ph1->GetVertex(i+1).x(); 496 xyz[i][0]=ph1->GetVertex(i+1).x(); 495 xyz[i][1]=ph1->GetVertex(i+1).y(); 497 xyz[i][1]=ph1->GetVertex(i+1).y(); 496 G4double tmpZ=ph1->GetVertex(i+1).z(); 498 G4double tmpZ=ph1->GetVertex(i+1).z(); 497 if (tmpZ>=fDz-kCarTolerance) 499 if (tmpZ>=fDz-kCarTolerance) 498 { 500 { 499 xyz[i][2]=GetCutZ(G4ThreeVector(xyz[i][0 501 xyz[i][2]=GetCutZ(G4ThreeVector(xyz[i][0],xyz[i][1],fDz)); 500 } 502 } 501 else if(tmpZ<=-fDz+kCarTolerance) 503 else if(tmpZ<=-fDz+kCarTolerance) 502 { 504 { 503 xyz[i][2]=GetCutZ(G4ThreeVector(xyz[i][0 505 xyz[i][2]=GetCutZ(G4ThreeVector(xyz[i][0],xyz[i][1],-fDz)); 504 } 506 } 505 else 507 else 506 { 508 { 507 xyz[i][2]=tmpZ; 509 xyz[i][2]=tmpZ; 508 } 510 } 509 } 511 } 510 G4int iNodes[4]; 512 G4int iNodes[4]; 511 G4int* iEdge=nullptr; << 513 G4int *iEdge=0; 512 G4int n; 514 G4int n; 513 for(G4int i=0; i<nf; ++i) 515 for(G4int i=0; i<nf; ++i) 514 { 516 { 515 ph1->GetFacet(i+1,n,iNodes,iEdge); 517 ph1->GetFacet(i+1,n,iNodes,iEdge); 516 for(G4int k=0; k<n; ++k) 518 for(G4int k=0; k<n; ++k) 517 { 519 { 518 faces[i][k]=iNodes[k]; 520 faces[i][k]=iNodes[k]; 519 } 521 } 520 for(G4int k=n; k<4; ++k) 522 for(G4int k=n; k<4; ++k) 521 { 523 { 522 faces[i][k]=0; 524 faces[i][k]=0; 523 } 525 } 524 } 526 } 525 ph->createPolyhedron(nn,nf,xyz,faces); 527 ph->createPolyhedron(nn,nf,xyz,faces); 526 528 527 delete [] xyz; 529 delete [] xyz; 528 delete [] faces; 530 delete [] faces; 529 delete ph1; 531 delete ph1; 530 532 531 return ph; 533 return ph; 532 } 534 } 533 535 534 #endif // G4GEOM_USE_USOLIDS 536 #endif // G4GEOM_USE_USOLIDS 535 537