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