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