2 // ********************************************************************
3 // * License and Disclaimer *
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. *
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. *
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 // ********************************************************************
27 // $Id: G4Tubs.icc 100820 2016-11-02 15:18:48Z gcosmo $
29 // --------------------------------------------------------------------
30 // GEANT 4 inline definitions file
34 // Implementation of inline methods of G4Tubs
35 // --------------------------------------------------------------------
38 G4double G4Tubs::GetInnerRadius () const
44 G4double G4Tubs::GetOuterRadius () const
50 G4double G4Tubs::GetZHalfLength () const
56 G4double G4Tubs::GetStartPhiAngle () const
62 G4double G4Tubs::GetDeltaPhiAngle () const
68 G4double G4Tubs::GetSinStartPhi () const
74 G4double G4Tubs::GetCosStartPhi () const
80 G4double G4Tubs::GetSinEndPhi () const
86 G4double G4Tubs::GetCosEndPhi () const
92 void G4Tubs::Initialize()
96 fRebuildPolyhedron = true;
100 void G4Tubs::InitializeTrigonometry()
102 G4double hDPhi = 0.5*fDPhi; // half delta phi
103 G4double cPhi = fSPhi + hDPhi;
104 G4double ePhi = fSPhi + fDPhi;
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);
116 inline void G4Tubs::CheckSPhiAngle(G4double sPhi)
118 // Ensure fSphi in 0-2PI or -2PI-0 range if shape crosses 0
122 fSPhi = CLHEP::twopi - std::fmod(std::fabs(sPhi),CLHEP::twopi);
126 fSPhi = std::fmod(sPhi,CLHEP::twopi) ;
128 if ( fSPhi+fDPhi > CLHEP::twopi )
130 fSPhi -= CLHEP::twopi ;
134 inline void G4Tubs::CheckDPhiAngle(G4double dPhi)
137 if ( dPhi >= CLHEP::twopi-kAngTolerance*0.5 )
144 fPhiFullTube = false;
151 std::ostringstream message;
152 message << "Invalid dphi." << G4endl
153 << "Negative or zero delta-Phi (" << dPhi << "), for solid: "
155 G4Exception("G4Tubs::CheckDPhiAngle()", "GeomSolids0002",
156 FatalException, message);
161 inline void G4Tubs::CheckPhiAngles(G4double sPhi, G4double dPhi)
163 CheckDPhiAngle(dPhi);
164 if ( (fDPhi<CLHEP::twopi) && (sPhi) ) { CheckSPhiAngle(sPhi); }
165 InitializeTrigonometry();
169 void G4Tubs::SetInnerRadius (G4double newRMin)
171 if ( newRMin < 0 ) // Check radii
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);
187 void G4Tubs::SetOuterRadius (G4double newRMax)
189 if ( newRMax <= 0 ) // Check radii
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);
205 void G4Tubs::SetZHalfLength (G4double newDz)
207 if (newDz<=0) // Check z-len
209 std::ostringstream message;
210 message << "Invalid Z half-length." << G4endl
211 << "Negative Z half-length (" << newDz << "), for solid: "
213 G4Exception("G4Tubs::SetZHalfLength()", "GeomSolids0002",
214 FatalException, message);
221 void G4Tubs::SetStartPhiAngle (G4double newSPhi, G4bool compute)
223 // Flag 'compute' can be used to explicitely avoid recomputation of
224 // trigonometry in case SetDeltaPhiAngle() is invoked afterwards
226 CheckSPhiAngle(newSPhi);
227 fPhiFullTube = false;
228 if (compute) { InitializeTrigonometry(); }
233 void G4Tubs::SetDeltaPhiAngle (G4double newDPhi)
235 CheckPhiAngles(fSPhi, newDPhi);
239 // Older names for access functions
242 G4double G4Tubs::GetRMin () const
244 return GetInnerRadius();
248 G4double G4Tubs::GetRMax () const
250 return GetOuterRadius();
254 G4double G4Tubs::GetDz () const
256 return GetZHalfLength() ;
260 G4double G4Tubs::GetSPhi () const
262 return GetStartPhiAngle();
266 G4double G4Tubs::GetDPhi () const
268 return GetDeltaPhiAngle();
272 G4double G4Tubs::GetCubicVolume()
274 if(fCubicVolume != 0.) {;}
275 else { fCubicVolume = fDPhi*fDz*(fRMax*fRMax-fRMin*fRMin); }
280 G4double G4Tubs::GetSurfaceArea()
282 if(fSurfaceArea != 0.) {;}
285 fSurfaceArea = fDPhi*(fRMin+fRMax)*(2*fDz+fRMax-fRMin);
288 fSurfaceArea = fSurfaceArea + 4*fDz*(fRMax-fRMin);