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