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