2 // ********************************************************************
3 // * License and Disclaimer *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
27 // $Id: G4Sphere.icc 100820 2016-11-02 15:18:48Z gcosmo $
29 // --------------------------------------------------------------------
30 // GEANT 4 inline definitions file
34 // Implementation of inline methods of G4Sphere
35 // --------------------------------------------------------------------
38 G4double G4Sphere::GetInsideRadius() const
44 G4double G4Sphere::GetInnerRadius() const
50 G4double G4Sphere::GetOuterRadius() const
56 G4double G4Sphere::GetStartPhiAngle() const
62 G4double G4Sphere::GetDeltaPhiAngle() const
68 G4double G4Sphere::GetStartThetaAngle() const
73 G4double G4Sphere::GetDeltaThetaAngle() const
79 G4double G4Sphere::GetSinStartPhi () const
85 G4double G4Sphere::GetCosStartPhi () const
91 G4double G4Sphere::GetSinEndPhi () const
97 G4double G4Sphere::GetCosEndPhi () const
103 G4double G4Sphere::GetSinStartTheta () const
109 G4double G4Sphere::GetCosStartTheta () const
115 G4double G4Sphere::GetSinEndTheta () const
121 G4double G4Sphere::GetCosEndTheta () const
127 void G4Sphere::Initialize()
131 fRebuildPolyhedron = true;
135 void G4Sphere::InitializePhiTrigonometry()
137 hDPhi = 0.5*fDPhi; // half delta phi
138 cPhi = fSPhi + hDPhi;
139 ePhi = fSPhi + fDPhi;
141 sinCPhi = std::sin(cPhi);
142 cosCPhi = std::cos(cPhi);
143 cosHDPhiIT = std::cos(hDPhi - 0.5*kAngTolerance); // inner/outer tol half dphi
144 cosHDPhiOT = std::cos(hDPhi + 0.5*kAngTolerance);
145 sinSPhi = std::sin(fSPhi);
146 cosSPhi = std::cos(fSPhi);
147 sinEPhi = std::sin(ePhi);
148 cosEPhi = std::cos(ePhi);
152 void G4Sphere::InitializeThetaTrigonometry()
154 eTheta = fSTheta + fDTheta;
156 sinSTheta = std::sin(fSTheta);
157 cosSTheta = std::cos(fSTheta);
158 sinETheta = std::sin(eTheta);
159 cosETheta = std::cos(eTheta);
161 tanSTheta = std::tan(fSTheta);
162 tanSTheta2 = tanSTheta*tanSTheta;
163 tanETheta = std::tan(eTheta);
164 tanETheta2 = tanETheta*tanETheta;
168 void G4Sphere::CheckThetaAngles(G4double sTheta, G4double dTheta)
170 if ( (sTheta<0) || (sTheta>CLHEP::pi) )
172 std::ostringstream message;
173 message << "sTheta outside 0-PI range." << G4endl
174 << "Invalid starting Theta angle for solid: " << GetName();
175 G4Exception("G4Sphere::CheckThetaAngles()", "GeomSolids0002",
176 FatalException, message);
182 if ( dTheta+sTheta >= CLHEP::pi )
184 fDTheta=CLHEP::pi-sTheta;
186 else if ( dTheta > 0 )
192 std::ostringstream message;
193 message << "Invalid dTheta." << G4endl
194 << "Negative delta-Theta (" << dTheta << "), for solid: "
196 G4Exception("G4Sphere::CheckThetaAngles()", "GeomSolids0002",
197 FatalException, message);
199 if ( fDTheta-fSTheta < CLHEP::pi ) { fFullThetaSphere = false; }
200 else { fFullThetaSphere = true ; }
201 fFullSphere = fFullPhiSphere && fFullThetaSphere;
203 InitializeThetaTrigonometry();
207 void G4Sphere::CheckSPhiAngle(G4double sPhi)
209 // Ensure fSphi in 0-2PI or -2PI-0 range if shape crosses 0
213 fSPhi = CLHEP::twopi - std::fmod(std::fabs(sPhi),CLHEP::twopi);
217 fSPhi = std::fmod(sPhi,CLHEP::twopi) ;
219 if ( fSPhi+fDPhi > CLHEP::twopi )
221 fSPhi -= CLHEP::twopi ;
226 void G4Sphere::CheckDPhiAngle(G4double dPhi)
228 fFullPhiSphere = true;
229 if ( dPhi >= CLHEP::twopi-kAngTolerance*0.5 )
235 fFullPhiSphere = false;
242 std::ostringstream message;
243 message << "Invalid dphi." << G4endl
244 << "Negative delta-Phi (" << dPhi << "), for solid: "
246 G4Exception("G4Sphere::CheckDPhiAngle()", "GeomSolids0002",
247 FatalException, message);
253 void G4Sphere::CheckPhiAngles(G4double sPhi, G4double dPhi)
255 CheckDPhiAngle(dPhi);
256 if (!fFullPhiSphere && sPhi) { CheckSPhiAngle(sPhi); }
257 fFullSphere = fFullPhiSphere && fFullThetaSphere;
259 InitializePhiTrigonometry();
263 void G4Sphere::SetInsideRadius(G4double newRmin)
266 fRminTolerance = (fRmin) ? std::max( kRadTolerance, fEpsilon*fRmin ) : 0;
271 void G4Sphere::SetInnerRadius(G4double newRmin)
273 SetInsideRadius(newRmin);
277 void G4Sphere::SetOuterRadius(G4double newRmax)
280 fRmaxTolerance = std::max( kRadTolerance, fEpsilon*fRmax );
285 void G4Sphere::SetStartPhiAngle(G4double newSPhi, G4bool compute)
287 // Flag 'compute' can be used to explicitely avoid recomputation of
288 // trigonometry in case SetDeltaPhiAngle() is invoked afterwards
290 CheckSPhiAngle(newSPhi);
291 fFullPhiSphere = false;
292 if (compute) { InitializePhiTrigonometry(); }
297 void G4Sphere::SetDeltaPhiAngle(G4double newDPhi)
299 CheckPhiAngles(fSPhi, newDPhi);
304 void G4Sphere::SetStartThetaAngle(G4double newSTheta)
306 CheckThetaAngles(newSTheta, fDTheta);
311 void G4Sphere::SetDeltaThetaAngle(G4double newDTheta)
313 CheckThetaAngles(fSTheta, newDTheta);
317 // Old access functions
320 G4double G4Sphere::GetRmin() const
322 return GetInsideRadius();
326 G4double G4Sphere::GetRmax() const
328 return GetOuterRadius();
332 G4double G4Sphere::GetSPhi() const
334 return GetStartPhiAngle();
338 G4double G4Sphere::GetDPhi() const
340 return GetDeltaPhiAngle();
344 G4double G4Sphere::GetSTheta() const
346 return GetStartThetaAngle();
350 G4double G4Sphere::GetDTheta() const
352 return GetDeltaThetaAngle();
356 G4double G4Sphere::GetCubicVolume()
358 if(fCubicVolume != 0.) {;}
359 else { fCubicVolume = fDPhi*(std::cos(fSTheta)-std::cos(fSTheta+fDTheta))*
360 (fRmax*fRmax*fRmax-fRmin*fRmin*fRmin)/3.; }