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