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