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 of inline methods of G4Spher 26 // Implementation of inline methods of G4Sphere 27 // ------------------------------------------- 27 // -------------------------------------------------------------------- 28 28 29 inline 29 inline 30 G4double G4Sphere::GetInnerRadius() const 30 G4double G4Sphere::GetInnerRadius() const 31 { 31 { 32 return fRmin; 32 return fRmin; 33 } 33 } 34 34 35 inline 35 inline 36 G4double G4Sphere::GetOuterRadius() const 36 G4double G4Sphere::GetOuterRadius() const 37 { 37 { 38 return fRmax; 38 return fRmax; 39 } 39 } 40 40 41 inline 41 inline 42 G4double G4Sphere::GetStartPhiAngle() const 42 G4double G4Sphere::GetStartPhiAngle() const 43 { 43 { 44 return fSPhi; 44 return fSPhi; 45 } 45 } 46 46 47 inline 47 inline 48 G4double G4Sphere::GetDeltaPhiAngle() const 48 G4double G4Sphere::GetDeltaPhiAngle() const 49 { 49 { 50 return fDPhi; 50 return fDPhi; 51 } 51 } 52 52 53 inline 53 inline 54 G4double G4Sphere::GetStartThetaAngle() const 54 G4double G4Sphere::GetStartThetaAngle() const 55 { 55 { 56 return fSTheta; 56 return fSTheta; 57 } 57 } 58 58 59 G4double G4Sphere::GetDeltaThetaAngle() const 59 G4double G4Sphere::GetDeltaThetaAngle() const 60 { 60 { 61 return fDTheta; 61 return fDTheta; 62 } 62 } 63 63 64 inline 64 inline 65 G4double G4Sphere::GetSinStartPhi () const 65 G4double G4Sphere::GetSinStartPhi () const 66 { 66 { 67 return sinSPhi; 67 return sinSPhi; 68 } 68 } 69 69 70 inline 70 inline 71 G4double G4Sphere::GetCosStartPhi () const 71 G4double G4Sphere::GetCosStartPhi () const 72 { 72 { 73 return cosSPhi; 73 return cosSPhi; 74 } 74 } 75 75 76 inline 76 inline 77 G4double G4Sphere::GetSinEndPhi () const 77 G4double G4Sphere::GetSinEndPhi () const 78 { 78 { 79 return sinEPhi; 79 return sinEPhi; 80 } 80 } 81 81 82 inline 82 inline 83 G4double G4Sphere::GetCosEndPhi () const 83 G4double G4Sphere::GetCosEndPhi () const 84 { 84 { 85 return cosEPhi; 85 return cosEPhi; 86 } 86 } 87 87 88 inline 88 inline 89 G4double G4Sphere::GetSinStartTheta () const 89 G4double G4Sphere::GetSinStartTheta () const 90 { 90 { 91 return sinSTheta; 91 return sinSTheta; 92 } 92 } 93 93 94 inline 94 inline 95 G4double G4Sphere::GetCosStartTheta () const 95 G4double G4Sphere::GetCosStartTheta () const 96 { 96 { 97 return cosSTheta; 97 return cosSTheta; 98 } 98 } 99 99 100 inline 100 inline 101 G4double G4Sphere::GetSinEndTheta () const 101 G4double G4Sphere::GetSinEndTheta () const 102 { 102 { 103 return sinETheta; 103 return sinETheta; 104 } 104 } 105 105 106 inline 106 inline 107 G4double G4Sphere::GetCosEndTheta () const 107 G4double G4Sphere::GetCosEndTheta () const 108 { 108 { 109 return cosETheta; 109 return cosETheta; 110 } 110 } 111 111 112 inline 112 inline 113 void G4Sphere::Initialize() 113 void G4Sphere::Initialize() 114 { 114 { 115 fCubicVolume = 0.; 115 fCubicVolume = 0.; 116 fSurfaceArea = 0.; 116 fSurfaceArea = 0.; 117 fRebuildPolyhedron = true; 117 fRebuildPolyhedron = true; 118 } 118 } 119 119 120 inline 120 inline 121 void G4Sphere::InitializePhiTrigonometry() 121 void G4Sphere::InitializePhiTrigonometry() 122 { 122 { 123 hDPhi = 0.5*fDPhi; // 123 hDPhi = 0.5*fDPhi; // half delta phi 124 cPhi = fSPhi + hDPhi; 124 cPhi = fSPhi + hDPhi; 125 ePhi = fSPhi + fDPhi; 125 ePhi = fSPhi + fDPhi; 126 126 127 sinCPhi = std::sin(cPhi); 127 sinCPhi = std::sin(cPhi); 128 cosCPhi = std::cos(cPhi); 128 cosCPhi = std::cos(cPhi); 129 cosHDPhi = std::cos(hDPhi); 129 cosHDPhi = std::cos(hDPhi); 130 cosHDPhiIT = std::cos(hDPhi - 0.5*kAngTolera 130 cosHDPhiIT = std::cos(hDPhi - 0.5*kAngTolerance); // inner/outer tol half dphi 131 cosHDPhiOT = std::cos(hDPhi + 0.5*kAngTolera 131 cosHDPhiOT = std::cos(hDPhi + 0.5*kAngTolerance); 132 sinSPhi = std::sin(fSPhi); 132 sinSPhi = std::sin(fSPhi); 133 cosSPhi = std::cos(fSPhi); 133 cosSPhi = std::cos(fSPhi); 134 sinEPhi = std::sin(ePhi); 134 sinEPhi = std::sin(ePhi); 135 cosEPhi = std::cos(ePhi); 135 cosEPhi = std::cos(ePhi); 136 } 136 } 137 137 138 inline 138 inline 139 void G4Sphere::InitializeThetaTrigonometry() 139 void G4Sphere::InitializeThetaTrigonometry() 140 { 140 { 141 eTheta = fSTheta + fDTheta; 141 eTheta = fSTheta + fDTheta; 142 142 143 sinSTheta = std::sin(fSTheta); 143 sinSTheta = std::sin(fSTheta); 144 cosSTheta = std::cos(fSTheta); 144 cosSTheta = std::cos(fSTheta); 145 sinETheta = std::sin(eTheta); 145 sinETheta = std::sin(eTheta); 146 cosETheta = std::cos(eTheta); 146 cosETheta = std::cos(eTheta); 147 147 148 tanSTheta = sinSTheta/cosSTheta; 148 tanSTheta = sinSTheta/cosSTheta; 149 tanSTheta2 = tanSTheta*tanSTheta; 149 tanSTheta2 = tanSTheta*tanSTheta; 150 tanETheta = sinETheta/cosETheta; 150 tanETheta = sinETheta/cosETheta; 151 tanETheta2 = tanETheta*tanETheta; 151 tanETheta2 = tanETheta*tanETheta; 152 } 152 } 153 153 154 inline 154 inline 155 void G4Sphere::CheckThetaAngles(G4double sThet 155 void G4Sphere::CheckThetaAngles(G4double sTheta, G4double dTheta) 156 { 156 { 157 if ( (sTheta<0) || (sTheta>CLHEP::pi) ) 157 if ( (sTheta<0) || (sTheta>CLHEP::pi) ) 158 { 158 { 159 std::ostringstream message; 159 std::ostringstream message; 160 message << "sTheta outside 0-PI range." << 160 message << "sTheta outside 0-PI range." << G4endl 161 << "Invalid starting Theta angle f 161 << "Invalid starting Theta angle for solid: " << GetName(); 162 G4Exception("G4Sphere::CheckThetaAngles()" 162 G4Exception("G4Sphere::CheckThetaAngles()", "GeomSolids0002", 163 FatalException, message); 163 FatalException, message); 164 } 164 } 165 else 165 else 166 { 166 { 167 fSTheta=sTheta; 167 fSTheta=sTheta; 168 } 168 } 169 if ( dTheta+sTheta >= CLHEP::pi ) 169 if ( dTheta+sTheta >= CLHEP::pi ) 170 { 170 { 171 fDTheta=CLHEP::pi-sTheta; 171 fDTheta=CLHEP::pi-sTheta; 172 } 172 } 173 else if ( dTheta > 0 ) 173 else if ( dTheta > 0 ) 174 { 174 { 175 fDTheta=dTheta; 175 fDTheta=dTheta; 176 } 176 } 177 else 177 else 178 { 178 { 179 std::ostringstream message; 179 std::ostringstream message; 180 message << "Invalid dTheta." << G4endl 180 message << "Invalid dTheta." << G4endl 181 << "Negative delta-Theta (" << dTh 181 << "Negative delta-Theta (" << dTheta << "), for solid: " 182 << GetName(); 182 << GetName(); 183 G4Exception("G4Sphere::CheckThetaAngles()" 183 G4Exception("G4Sphere::CheckThetaAngles()", "GeomSolids0002", 184 FatalException, message); 184 FatalException, message); 185 } 185 } 186 fFullThetaSphere = fDTheta-fSTheta >= CLHEP: << 186 if ( fDTheta-fSTheta < CLHEP::pi ) { fFullThetaSphere = false; } >> 187 else { fFullThetaSphere = true ; } 187 fFullSphere = fFullPhiSphere && fFullThetaSp 188 fFullSphere = fFullPhiSphere && fFullThetaSphere; 188 189 189 InitializeThetaTrigonometry(); 190 InitializeThetaTrigonometry(); 190 } 191 } 191 192 192 inline 193 inline 193 void G4Sphere::CheckSPhiAngle(G4double sPhi) 194 void G4Sphere::CheckSPhiAngle(G4double sPhi) 194 { 195 { 195 // Ensure fSphi in 0-2PI or -2PI-0 range if 196 // Ensure fSphi in 0-2PI or -2PI-0 range if shape crosses 0 196 197 197 if ( sPhi < 0 ) 198 if ( sPhi < 0 ) 198 { 199 { 199 fSPhi = CLHEP::twopi - std::fmod(std::fabs 200 fSPhi = CLHEP::twopi - std::fmod(std::fabs(sPhi),CLHEP::twopi); 200 } 201 } 201 else 202 else 202 { 203 { 203 fSPhi = std::fmod(sPhi,CLHEP::twopi) ; 204 fSPhi = std::fmod(sPhi,CLHEP::twopi) ; 204 } 205 } 205 if ( fSPhi+fDPhi > CLHEP::twopi ) 206 if ( fSPhi+fDPhi > CLHEP::twopi ) 206 { 207 { 207 fSPhi -= CLHEP::twopi ; 208 fSPhi -= CLHEP::twopi ; 208 } 209 } 209 } 210 } 210 211 211 inline 212 inline 212 void G4Sphere::CheckDPhiAngle(G4double dPhi) 213 void G4Sphere::CheckDPhiAngle(G4double dPhi) 213 { 214 { 214 fFullPhiSphere = true; 215 fFullPhiSphere = true; 215 if ( dPhi >= CLHEP::twopi-kAngTolerance*0.5 216 if ( dPhi >= CLHEP::twopi-kAngTolerance*0.5 ) 216 { 217 { 217 fDPhi=CLHEP::twopi; 218 fDPhi=CLHEP::twopi; 218 } 219 } 219 else 220 else 220 { 221 { 221 fFullPhiSphere = false; 222 fFullPhiSphere = false; 222 if ( dPhi > 0 ) 223 if ( dPhi > 0 ) 223 { 224 { 224 fDPhi = dPhi; 225 fDPhi = dPhi; 225 } 226 } 226 else 227 else 227 { 228 { 228 std::ostringstream message; 229 std::ostringstream message; 229 message << "Invalid dphi." << G4endl 230 message << "Invalid dphi." << G4endl 230 << "Negative delta-Phi (" << dPh 231 << "Negative delta-Phi (" << dPhi << "), for solid: " 231 << GetName(); 232 << GetName(); 232 G4Exception("G4Sphere::CheckDPhiAngle()" 233 G4Exception("G4Sphere::CheckDPhiAngle()", "GeomSolids0002", 233 FatalException, message); 234 FatalException, message); 234 } 235 } 235 } 236 } 236 } 237 } 237 238 238 inline 239 inline 239 void G4Sphere::CheckPhiAngles(G4double sPhi, G 240 void G4Sphere::CheckPhiAngles(G4double sPhi, G4double dPhi) 240 { 241 { 241 CheckDPhiAngle(dPhi); 242 CheckDPhiAngle(dPhi); 242 if (!fFullPhiSphere && (sPhi != 0.0)) { Chec << 243 if (!fFullPhiSphere && sPhi) { CheckSPhiAngle(sPhi); } 243 fFullSphere = fFullPhiSphere && fFullThetaSp 244 fFullSphere = fFullPhiSphere && fFullThetaSphere; 244 245 245 InitializePhiTrigonometry(); 246 InitializePhiTrigonometry(); 246 } 247 } 247 248 248 inline 249 inline 249 void G4Sphere::SetInnerRadius(G4double newRmin 250 void G4Sphere::SetInnerRadius(G4double newRmin) 250 { 251 { 251 fRmin= newRmin; 252 fRmin= newRmin; 252 fRminTolerance = (fRmin) != 0.0 ? std::max( << 253 fRminTolerance = (fRmin) ? std::max( kRadTolerance, fEpsilon*fRmin ) : 0; 253 Initialize(); 254 Initialize(); 254 } 255 } 255 256 256 inline 257 inline 257 void G4Sphere::SetOuterRadius(G4double newRmax 258 void G4Sphere::SetOuterRadius(G4double newRmax) 258 { 259 { 259 fRmax= newRmax; 260 fRmax= newRmax; 260 fRmaxTolerance = std::max( kRadTolerance, fE 261 fRmaxTolerance = std::max( kRadTolerance, fEpsilon*fRmax ); 261 Initialize(); 262 Initialize(); 262 } 263 } 263 264 264 inline 265 inline 265 void G4Sphere::SetStartPhiAngle(G4double newSP 266 void G4Sphere::SetStartPhiAngle(G4double newSPhi, G4bool compute) 266 { 267 { 267 // Flag 'compute' can be used to explicitely 268 // Flag 'compute' can be used to explicitely avoid recomputation of 268 // trigonometry in case SetDeltaPhiAngle() i 269 // trigonometry in case SetDeltaPhiAngle() is invoked afterwards 269 270 270 CheckSPhiAngle(newSPhi); 271 CheckSPhiAngle(newSPhi); 271 fFullPhiSphere = false; 272 fFullPhiSphere = false; 272 if (compute) { InitializePhiTrigonometry(); 273 if (compute) { InitializePhiTrigonometry(); } 273 Initialize(); 274 Initialize(); 274 } 275 } 275 276 276 inline 277 inline 277 void G4Sphere::SetDeltaPhiAngle(G4double newDP 278 void G4Sphere::SetDeltaPhiAngle(G4double newDPhi) 278 { 279 { 279 CheckPhiAngles(fSPhi, newDPhi); 280 CheckPhiAngles(fSPhi, newDPhi); 280 Initialize(); 281 Initialize(); 281 } 282 } 282 283 283 inline 284 inline 284 void G4Sphere::SetStartThetaAngle(G4double new 285 void G4Sphere::SetStartThetaAngle(G4double newSTheta) 285 { 286 { 286 CheckThetaAngles(newSTheta, fDTheta); 287 CheckThetaAngles(newSTheta, fDTheta); 287 Initialize(); 288 Initialize(); 288 } 289 } 289 290 290 inline 291 inline 291 void G4Sphere::SetDeltaThetaAngle(G4double new 292 void G4Sphere::SetDeltaThetaAngle(G4double newDTheta) 292 { 293 { 293 CheckThetaAngles(fSTheta, newDTheta); 294 CheckThetaAngles(fSTheta, newDTheta); 294 Initialize(); 295 Initialize(); 295 } 296 } 296 297