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