Geant4  10.03
G4Tubs.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: G4Tubs.icc 100820 2016-11-02 15:18:48Z gcosmo $
28 //
29 // --------------------------------------------------------------------
30 // GEANT 4 inline definitions file
31 //
32 // G4Tubs.icc
33 //
34 // Implementation of inline methods of G4Tubs
35 // --------------------------------------------------------------------
36 
37 inline
38 G4double G4Tubs::GetInnerRadius () const
39 {
40  return fRMin;
41 }
42 
43 inline
44 G4double G4Tubs::GetOuterRadius () const
45 {
46  return fRMax;
47 }
48 
49 inline
50 G4double G4Tubs::GetZHalfLength () const
51 {
52  return fDz;
53 }
54 
55 inline
56 G4double G4Tubs::GetStartPhiAngle () const
57 {
58  return fSPhi;
59 }
60 
61 inline
62 G4double G4Tubs::GetDeltaPhiAngle () const
63 {
64  return fDPhi;
65 }
66 
67 inline
68 G4double G4Tubs::GetSinStartPhi () const
69 {
70  return sinSPhi;
71 }
72 
73 inline
74 G4double G4Tubs::GetCosStartPhi () const
75 {
76  return cosSPhi;
77 }
78 
79 inline
80 G4double G4Tubs::GetSinEndPhi () const
81 {
82  return sinEPhi;
83 }
84 
85 inline
86 G4double G4Tubs::GetCosEndPhi () const
87 {
88  return cosEPhi;
89 }
90 
91 inline
92 void G4Tubs::Initialize()
93 {
94  fCubicVolume = 0.;
95  fSurfaceArea = 0.;
96  fRebuildPolyhedron = true;
97 }
98 
99 inline
100 void G4Tubs::InitializeTrigonometry()
101 {
102  G4double hDPhi = 0.5*fDPhi; // half delta phi
103  G4double cPhi = fSPhi + hDPhi;
104  G4double ePhi = fSPhi + fDPhi;
105 
106  sinCPhi = std::sin(cPhi);
107  cosCPhi = std::cos(cPhi);
108  cosHDPhiIT = std::cos(hDPhi - 0.5*kAngTolerance); // inner/outer tol half dphi
109  cosHDPhiOT = std::cos(hDPhi + 0.5*kAngTolerance);
110  sinSPhi = std::sin(fSPhi);
111  cosSPhi = std::cos(fSPhi);
112  sinEPhi = std::sin(ePhi);
113  cosEPhi = std::cos(ePhi);
114 }
115 
116 inline void G4Tubs::CheckSPhiAngle(G4double sPhi)
117 {
118  // Ensure fSphi in 0-2PI or -2PI-0 range if shape crosses 0
119 
120  if ( sPhi < 0 )
121  {
122  fSPhi = CLHEP::twopi - std::fmod(std::fabs(sPhi),CLHEP::twopi);
123  }
124  else
125  {
126  fSPhi = std::fmod(sPhi,CLHEP::twopi) ;
127  }
128  if ( fSPhi+fDPhi > CLHEP::twopi )
129  {
130  fSPhi -= CLHEP::twopi ;
131  }
132 }
133 
134 inline void G4Tubs::CheckDPhiAngle(G4double dPhi)
135 {
136  fPhiFullTube = true;
137  if ( dPhi >= CLHEP::twopi-kAngTolerance*0.5 )
138  {
139  fDPhi=CLHEP::twopi;
140  fSPhi=0;
141  }
142  else
143  {
144  fPhiFullTube = false;
145  if ( dPhi > 0 )
146  {
147  fDPhi = dPhi;
148  }
149  else
150  {
151  std::ostringstream message;
152  message << "Invalid dphi." << G4endl
153  << "Negative or zero delta-Phi (" << dPhi << "), for solid: "
154  << GetName();
155  G4Exception("G4Tubs::CheckDPhiAngle()", "GeomSolids0002",
156  FatalException, message);
157  }
158  }
159 }
160 
161 inline void G4Tubs::CheckPhiAngles(G4double sPhi, G4double dPhi)
162 {
163  CheckDPhiAngle(dPhi);
164  if ( (fDPhi<CLHEP::twopi) && (sPhi) ) { CheckSPhiAngle(sPhi); }
165  InitializeTrigonometry();
166 }
167 
168 inline
169 void G4Tubs::SetInnerRadius (G4double newRMin)
170 {
171  if ( newRMin < 0 ) // Check radii
172  {
173  std::ostringstream message;
174  message << "Invalid radii." << G4endl
175  << "Invalid values for radii in solid " << GetName() << G4endl
176  << " newRMin = " << newRMin
177  << ", fRMax = " << fRMax << G4endl
178  << " Negative inner radius!";
179  G4Exception("G4Tubs::SetInnerRadius()", "GeomSolids0002",
180  FatalException, message);
181  }
182  fRMin= newRMin;
183  Initialize();
184 }
185 
186 inline
187 void G4Tubs::SetOuterRadius (G4double newRMax)
188 {
189  if ( newRMax <= 0 ) // Check radii
190  {
191  std::ostringstream message;
192  message << "Invalid radii." << G4endl
193  << "Invalid values for radii in solid " << GetName() << G4endl
194  << " fRMin = " << fRMin
195  << ", newRMax = " << newRMax << G4endl
196  << " Invalid outer radius!";
197  G4Exception("G4Tubs::SetOuterRadius()", "GeomSolids0002",
198  FatalException, message);
199  }
200  fRMax= newRMax;
201  Initialize();
202 }
203 
204 inline
205 void G4Tubs::SetZHalfLength (G4double newDz)
206 {
207  if (newDz<=0) // Check z-len
208  {
209  std::ostringstream message;
210  message << "Invalid Z half-length." << G4endl
211  << "Negative Z half-length (" << newDz << "), for solid: "
212  << GetName();
213  G4Exception("G4Tubs::SetZHalfLength()", "GeomSolids0002",
214  FatalException, message);
215  }
216  fDz= newDz;
217  Initialize();
218 }
219 
220 inline
221 void G4Tubs::SetStartPhiAngle (G4double newSPhi, G4bool compute)
222 {
223  // Flag 'compute' can be used to explicitely avoid recomputation of
224  // trigonometry in case SetDeltaPhiAngle() is invoked afterwards
225 
226  CheckSPhiAngle(newSPhi);
227  fPhiFullTube = false;
228  if (compute) { InitializeTrigonometry(); }
229  Initialize();
230 }
231 
232 inline
233 void G4Tubs::SetDeltaPhiAngle (G4double newDPhi)
234 {
235  CheckPhiAngles(fSPhi, newDPhi);
236  Initialize();
237 }
238 
239 // Older names for access functions
240 
241 inline
242 G4double G4Tubs::GetRMin () const
243 {
244  return GetInnerRadius();
245 }
246 
247 inline
248 G4double G4Tubs::GetRMax () const
249 {
250  return GetOuterRadius();
251 }
252 
253 inline
254 G4double G4Tubs::GetDz () const
255 {
256  return GetZHalfLength() ;
257 }
258 
259 inline
260 G4double G4Tubs::GetSPhi () const
261 {
262  return GetStartPhiAngle();
263 }
264 
265 inline
266 G4double G4Tubs::GetDPhi () const
267 {
268  return GetDeltaPhiAngle();
269 }
270 
271 inline
272 G4double G4Tubs::GetCubicVolume()
273 {
274  if(fCubicVolume != 0.) {;}
275  else { fCubicVolume = fDPhi*fDz*(fRMax*fRMax-fRMin*fRMin); }
276  return fCubicVolume;
277 }
278 
279 inline
280 G4double G4Tubs::GetSurfaceArea()
281 {
282  if(fSurfaceArea != 0.) {;}
283  else
284  {
285  fSurfaceArea = fDPhi*(fRMin+fRMax)*(2*fDz+fRMax-fRMin);
286  if (!fPhiFullTube)
287  {
288  fSurfaceArea = fSurfaceArea + 4*fDz*(fRMax-fRMin);
289  }
290  }
291  return fSurfaceArea;
292 }