Geant4  10.01.p03
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 83572 2014-09-01 15:23:27Z 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 void G4Sphere::Initialize()
80 {
81  fCubicVolume = 0.;
82  fSurfaceArea = 0.;
83  fRebuildPolyhedron = true;
84 }
85 
86 inline
87 void G4Sphere::InitializePhiTrigonometry()
88 {
89  hDPhi = 0.5*fDPhi; // half delta phi
90  cPhi = fSPhi + hDPhi;
91  ePhi = fSPhi + fDPhi;
92 
93  sinCPhi = std::sin(cPhi);
94  cosCPhi = std::cos(cPhi);
95  cosHDPhiIT = std::cos(hDPhi - 0.5*kAngTolerance); // inner/outer tol half dphi
96  cosHDPhiOT = std::cos(hDPhi + 0.5*kAngTolerance);
97  sinSPhi = std::sin(fSPhi);
98  cosSPhi = std::cos(fSPhi);
99  sinEPhi = std::sin(ePhi);
100  cosEPhi = std::cos(ePhi);
101 }
102 
103 inline
104 void G4Sphere::InitializeThetaTrigonometry()
105 {
106  eTheta = fSTheta + fDTheta;
107 
108  sinSTheta = std::sin(fSTheta);
109  cosSTheta = std::cos(fSTheta);
110  sinETheta = std::sin(eTheta);
111  cosETheta = std::cos(eTheta);
112 
113  tanSTheta = std::tan(fSTheta);
114  tanSTheta2 = tanSTheta*tanSTheta;
115  tanETheta = std::tan(eTheta);
116  tanETheta2 = tanETheta*tanETheta;
117 }
118 
119 inline
120 void G4Sphere::CheckThetaAngles(G4double sTheta, G4double dTheta)
121 {
122  if ( (sTheta<0) || (sTheta>CLHEP::pi) )
123  {
124  std::ostringstream message;
125  message << "sTheta outside 0-PI range." << G4endl
126  << "Invalid starting Theta angle for solid: " << GetName();
127  G4Exception("G4Sphere::CheckThetaAngles()", "GeomSolids0002",
128  FatalException, message);
129  }
130  else
131  {
132  fSTheta=sTheta;
133  }
134  if ( dTheta+sTheta >= CLHEP::pi )
135  {
136  fDTheta=CLHEP::pi-sTheta;
137  }
138  else if ( dTheta > 0 )
139  {
140  fDTheta=dTheta;
141  }
142  else
143  {
144  std::ostringstream message;
145  message << "Invalid dTheta." << G4endl
146  << "Negative delta-Theta (" << dTheta << "), for solid: "
147  << GetName();
148  G4Exception("G4Sphere::CheckThetaAngles()", "GeomSolids0002",
149  FatalException, message);
150  }
151  if ( fDTheta-fSTheta < CLHEP::pi ) { fFullThetaSphere = false; }
152  else { fFullThetaSphere = true ; }
153  fFullSphere = fFullPhiSphere && fFullThetaSphere;
154 
155  InitializeThetaTrigonometry();
156 }
157 
158 inline
159 void G4Sphere::CheckSPhiAngle(G4double sPhi)
160 {
161  // Ensure fSphi in 0-2PI or -2PI-0 range if shape crosses 0
162 
163  if ( sPhi < 0 )
164  {
165  fSPhi = CLHEP::twopi - std::fmod(std::fabs(sPhi),CLHEP::twopi);
166  }
167  else
168  {
169  fSPhi = std::fmod(sPhi,CLHEP::twopi) ;
170  }
171  if ( fSPhi+fDPhi > CLHEP::twopi )
172  {
173  fSPhi -= CLHEP::twopi ;
174  }
175 }
176 
177 inline
178 void G4Sphere::CheckDPhiAngle(G4double dPhi)
179 {
180  fFullPhiSphere = true;
181  if ( dPhi >= CLHEP::twopi-kAngTolerance*0.5 )
182  {
183  fDPhi=CLHEP::twopi;
184  }
185  else
186  {
187  fFullPhiSphere = false;
188  if ( dPhi > 0 )
189  {
190  fDPhi = dPhi;
191  }
192  else
193  {
194  std::ostringstream message;
195  message << "Invalid dphi." << G4endl
196  << "Negative delta-Phi (" << dPhi << "), for solid: "
197  << GetName();
198  G4Exception("G4Sphere::CheckDPhiAngle()", "GeomSolids0002",
199  FatalException, message);
200  }
201  }
202 }
203 
204 inline
205 void G4Sphere::CheckPhiAngles(G4double sPhi, G4double dPhi)
206 {
207  CheckDPhiAngle(dPhi);
208  if (!fFullPhiSphere && sPhi) { CheckSPhiAngle(sPhi); }
209  fFullSphere = fFullPhiSphere && fFullThetaSphere;
210 
211  InitializePhiTrigonometry();
212 }
213 
214 inline
215 void G4Sphere::SetInsideRadius(G4double newRmin)
216 {
217  fRmin= newRmin;
218  fRminTolerance = (fRmin) ? std::max( kRadTolerance, fEpsilon*fRmin ) : 0;
219  Initialize();
220 }
221 
222 inline
223 void G4Sphere::SetInnerRadius(G4double newRmin)
224 {
225  SetInsideRadius(newRmin);
226 }
227 
228 inline
229 void G4Sphere::SetOuterRadius(G4double newRmax)
230 {
231  fRmax= newRmax;
232  fRmaxTolerance = std::max( kRadTolerance, fEpsilon*fRmax );
233  Initialize();
234 }
235 
236 inline
237 void G4Sphere::SetStartPhiAngle(G4double newSPhi, G4bool compute)
238 {
239  // Flag 'compute' can be used to explicitely avoid recomputation of
240  // trigonometry in case SetDeltaPhiAngle() is invoked afterwards
241 
242  CheckSPhiAngle(newSPhi);
243  fFullPhiSphere = false;
244  if (compute) { InitializePhiTrigonometry(); }
245  Initialize();
246 }
247 
248 inline
249 void G4Sphere::SetDeltaPhiAngle(G4double newDPhi)
250 {
251  CheckPhiAngles(fSPhi, newDPhi);
252  Initialize();
253 }
254 
255 inline
256 void G4Sphere::SetStartThetaAngle(G4double newSTheta)
257 {
258  CheckThetaAngles(newSTheta, fDTheta);
259  Initialize();
260 }
261 
262 inline
263 void G4Sphere::SetDeltaThetaAngle(G4double newDTheta)
264 {
265  CheckThetaAngles(fSTheta, newDTheta);
266  Initialize();
267 }
268 
269 // Old access functions
270 
271 inline
272 G4double G4Sphere::GetRmin() const
273 {
274  return GetInsideRadius();
275 }
276 
277 inline
278 G4double G4Sphere::GetRmax() const
279 {
280  return GetOuterRadius();
281 }
282 
283 inline
284 G4double G4Sphere::GetSPhi() const
285 {
286  return GetStartPhiAngle();
287 }
288 
289 inline
290 G4double G4Sphere::GetDPhi() const
291 {
292  return GetDeltaPhiAngle();
293 }
294 
295 inline
296 G4double G4Sphere::GetSTheta() const
297 {
298  return GetStartThetaAngle();
299 }
300 
301 inline
302 G4double G4Sphere::GetDTheta() const
303 {
304  return GetDeltaThetaAngle();
305 }
306 
307 inline
308 G4double G4Sphere::GetCubicVolume()
309 {
310  if(fCubicVolume != 0.) {;}
311  else { fCubicVolume = fDPhi*(std::cos(fSTheta)-std::cos(fSTheta+fDTheta))*
312  (fRmax*fRmax*fRmax-fRmin*fRmin*fRmin)/3.; }
313  return fCubicVolume;
314 }