Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4TwistedTubs.hh
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: G4TwistedTubs.hh 67011 2013-01-29 16:17:41Z gcosmo $
28 //
29 //
30 // --------------------------------------------------------------------
31 // GEANT 4 class header file
32 //
33 //
34 // G4TwistedTubs
35 //
36 // Class description:
37 //
38 // G4TwistedTubs is a sort of twisted cylinder.
39 // A twisted cylinder which is placed along with z-axis and is
40 // separated into phi-segments should become a hyperboloid, and
41 // its each segmented piece should be tilted with a stereo angle.
42 // G4TwistedTubs is a G4VSolid.
43 // It can have inner & outer surfaces as well as G4TwistedTubs,
44 // but cannot has different stereo angles between the inner surface
45 // and outer surface.
46 
47 // Author:
48 // 01-Aug-2002 - Kotoyo Hoshina (hoshina@hepburn.s.chiba-u.ac.jp)
49 //
50 // History:
51 // 13-Nov-2003 - O.Link (Oliver.Link@cern.ch), Integration in Geant4
52 // from original version in Jupiter-2.5.02 application.
53 // --------------------------------------------------------------------
54 #ifndef __G4TWISTEDTUBS__
55 #define __G4TWISTEDTUBS__
56 
57 #include "G4VSolid.hh"
58 #include "G4TwistTubsFlatSide.hh"
59 #include "G4TwistTubsSide.hh"
60 #include "G4TwistTubsHypeSide.hh"
61 
62 class G4SolidExtentList;
63 class G4ClippablePolygon;
64 
65 class G4TwistedTubs : public G4VSolid
66 {
67  public: // with description
68 
69  G4TwistedTubs(const G4String &pname, // Name of instance
70  G4double twistedangle, // Twisted angle
71  G4double endinnerrad, // Inner radius at endcap
72  G4double endouterrad, // Outer radius at endcap
73  G4double halfzlen, // half z length
74  G4double dphi); // Phi angle of a segment
75 
76  G4TwistedTubs(const G4String &pname, // Name of instance
77  G4double twistedangle, // Stereo angle
78  G4double endinnerrad, // Inner radius at endcap
79  G4double endouterrad, // Outer radius at endcap
80  G4double halfzlen, // half z length
81  G4int nseg, // Number of segments in totalPhi
82  G4double totphi); // Total angle of all segments
83 
84  G4TwistedTubs(const G4String &pname, // Name of instance
85  G4double twistedangle, // Twisted angle
86  G4double innerrad, // Inner radius at z=0
87  G4double outerrad, // Outer radius at z=0
88  G4double negativeEndz, // -ve z endplate
89  G4double positiveEndz, // +ve z endplate
90  G4double dphi); // Phi angle of a segment
91 
92  G4TwistedTubs(const G4String &pname, // Name of instance
93  G4double twistedangle, // Stereo angle
94  G4double innerrad, // Inner radius at z=0
95  G4double outerrad, // Outer radius at z=0
96  G4double negativeEndz, // -ve z endplate
97  G4double positiveEndz, // +ve z endplate
98  G4int nseg, // Number of segments in totalPhi
99  G4double totphi); // Total angle of all segments
100 
101  virtual ~G4TwistedTubs();
102 
104  const G4int /* n */ ,
105  const G4VPhysicalVolume * /* prep */ );
106 
107  G4bool CalculateExtent(const EAxis paxis,
108  const G4VoxelLimits &pvoxellimit,
109  const G4AffineTransform &ptransform,
110  G4double &pmin,
111  G4double &pmax ) const;
112 
114  const G4ThreeVector &v ) const;
115 
116  G4double DistanceToIn (const G4ThreeVector &p ) const;
117 
119  const G4ThreeVector &v,
120  const G4bool calcnorm=G4bool(false),
121  G4bool *validnorm=0,
122  G4ThreeVector *n=0 ) const;
123 
124  G4double DistanceToOut(const G4ThreeVector &p) const;
125 
126  EInside Inside (const G4ThreeVector &p) const;
127 
128  G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const;
129 
130  void DescribeYourselfTo (G4VGraphicsScene &scene) const;
131  G4Polyhedron *CreatePolyhedron () const;
132  G4NURBS *CreateNURBS () const;
133  G4Polyhedron *GetPolyhedron () const;
134 
135  std::ostream &StreamInfo(std::ostream& os) const;
136 
137  // accessors
138 
139  inline G4double GetDPhi () const { return fDPhi ; }
140  inline G4double GetPhiTwist () const { return fPhiTwist ; }
141  inline G4double GetInnerRadius () const { return fInnerRadius; }
142  inline G4double GetOuterRadius () const { return fOuterRadius; }
143  inline G4double GetInnerStereo () const { return fInnerStereo; }
144  inline G4double GetOuterStereo () const { return fOuterStereo; }
145  inline G4double GetZHalfLength () const { return fZHalfLength; }
146  inline G4double GetKappa () const { return fKappa ; }
147 
148  inline G4double GetTanInnerStereo () const { return fTanInnerStereo ; }
149  inline G4double GetTanInnerStereo2() const { return fTanInnerStereo2 ; }
150  inline G4double GetTanOuterStereo () const { return fTanOuterStereo ; }
151  inline G4double GetTanOuterStereo2() const { return fTanOuterStereo2 ; }
152 
153  inline G4double GetEndZ (G4int i) const { return fEndZ[i] ; }
154  inline G4double GetEndPhi (G4int i) const { return fEndPhi[i]; }
156  { return fEndInnerRadius[i]; }
158  { return fEndOuterRadius[i]; }
159  inline G4double GetEndInnerRadius () const
160  { return (fEndInnerRadius[0] > fEndInnerRadius[1] ?
161  fEndInnerRadius[0] : fEndInnerRadius[1]); }
162  inline G4double GetEndOuterRadius () const
163  { return (fEndOuterRadius[0] > fEndOuterRadius[1] ?
164  fEndOuterRadius[0] : fEndOuterRadius[1]); }
165 
166  G4VisExtent GetExtent () const;
168  G4VSolid* Clone() const;
169 
171  // Returns an estimation of the geometrical cubic volume of the
172  // solid. Caches the computed value once computed the first time.
174  // Returns an estimation of the geometrical surface area of the
175  // solid. Caches the computed value once computed the first time.
176 
178 
179  public: // without description
180 
181  G4TwistedTubs(__void__&);
182  // Fake default constructor for usage restricted to direct object
183  // persistency for clients requiring preallocation of memory for
184  // persistifiable objects.
185 
186  G4TwistedTubs(const G4TwistedTubs& rhs);
187  G4TwistedTubs& operator=(const G4TwistedTubs& rhs);
188  // Copy constructor and assignment operator.
189 
190 #ifdef G4TWISTDEBUG
191  G4VTwistSurface * GetOuterHype() const { return fOuterHype; }
192 #endif
193 
194  private:
195 
196  inline void SetFields(G4double phitwist, G4double innerrad,
197  G4double outerrad,
198  G4double negativeEndz, G4double positiveEndz);
199 
200  void CreateSurfaces();
201 
202  static void AddPolyToExtent( const G4ThreeVector &v0,
203  const G4ThreeVector &v1,
204  const G4ThreeVector &w1,
205  const G4ThreeVector &w0,
206  const G4VoxelLimits &voxellimit,
207  const EAxis axis,
208  G4SolidExtentList &extentlist );
209  private:
210 
211  G4double fPhiTwist; // Twist angle from -fZHalfLength to fZHalfLength
212  G4double fInnerRadius; // Inner-hype radius at z=0
213  G4double fOuterRadius; // Outer-hype radius at z=0
214  G4double fEndZ[2]; // z at endcaps, [0] = -ve z, [1] = +ve z
215  G4double fDPhi; // Phi-width of a segment fDPhi > 0
216  G4double fZHalfLength; // Half length along z-axis
217 
218  G4double fInnerStereo; // Inner-hype stereo angle
219  G4double fOuterStereo; // Outer-hype stereo angle
220  G4double fTanInnerStereo; // std::tan(innerStereoAngle)
221  G4double fTanOuterStereo; // std::tan(outerStereoAngle)
222  G4double fKappa; // std::tan(fPhiTwist/2)/fZHalfLen;
223  G4double fEndInnerRadius[2]; // Inner-hype radii endcaps [0] -ve z, [1] +ve z
224  G4double fEndOuterRadius[2]; // Outer-hype radii endcaps [0] -ve z, [1] +ve z
225  G4double fEndPhi[2]; // Phi endcaps, [0] = -ve z, [1] = +ve z
226 
227  G4double fInnerRadius2; // fInnerRadius * fInnerRadius
228  G4double fOuterRadius2; // fOuterRadius * fOuterRadius
229  G4double fTanInnerStereo2; // fInnerRadius * fInnerRadius
230  G4double fTanOuterStereo2; // fInnerRadius * fInnerRadius
231  G4double fEndZ2[2]; // fEndZ * fEndZ
232 
233  G4VTwistSurface *fLowerEndcap; // Surface of -ve z
234  G4VTwistSurface *fUpperEndcap; // Surface of +ve z
235  G4VTwistSurface *fLatterTwisted; // Surface of -ve phi
236  G4VTwistSurface *fFormerTwisted; // Surface of +ve phi
237  G4VTwistSurface *fInnerHype; // Surface of -ve r
238  G4VTwistSurface *fOuterHype; // Surface of +ve r
239 
240  G4double fCubicVolume; // Cached value for cubic volume
241  G4double fSurfaceArea; // Cached value for surface area
242 
243  mutable G4Polyhedron* fpPolyhedron; // pointer to polyhedron for vis
244 
245  class LastState // last Inside result
246  {
247  public:
248  LastState()
249  {
250  p.set(kInfinity,kInfinity,kInfinity);
251  inside = kOutside;
252  }
253  ~LastState(){}
254  LastState(const LastState& r) : p(r.p), inside(r.inside){}
255  LastState& operator=(const LastState& r)
256  {
257  if (this == &r) { return *this; }
258  p = r.p; inside = r.inside;
259  return *this;
260  }
261  public:
263  EInside inside;
264  };
265 
266  class LastVector // last SurfaceNormal result
267  {
268  public:
269  LastVector()
270  {
271  p.set(kInfinity,kInfinity,kInfinity);
272  vec.set(kInfinity,kInfinity,kInfinity);
273  surface = new G4VTwistSurface*[1];
274  }
275  ~LastVector()
276  {
277  delete [] surface;
278  }
279  LastVector(const LastVector& r) : p(r.p), vec(r.vec)
280  {
281  surface = new G4VTwistSurface*[1];
282  surface[0] = r.surface[0];
283  }
284  LastVector& operator=(const LastVector& r)
285  {
286  if (&r == this) { return *this; }
287  p = r.p; vec = r.vec;
288  delete [] surface; surface = new G4VTwistSurface*[1];
289  surface[0] = r.surface[0];
290  return *this;
291  }
292  public:
294  G4ThreeVector vec;
295  G4VTwistSurface **surface;
296  };
297 
298  class LastValue // last G4double value
299  {
300  public:
301  LastValue()
302  {
303  p.set(kInfinity,kInfinity,kInfinity);
304  value = DBL_MAX;
305  }
306  ~LastValue(){}
307  LastValue(const LastValue& r) : p(r.p), value(r.value){}
308  LastValue& operator=(const LastValue& r)
309  {
310  if (this == &r) { return *this; }
311  p = r.p; value = r.value;
312  return *this;
313  }
314  public:
316  G4double value;
317  };
318 
319  class LastValueWithDoubleVector // last G4double value
320  {
321  public:
322  LastValueWithDoubleVector()
323  {
324  p.set(kInfinity,kInfinity,kInfinity);
325  vec.set(kInfinity,kInfinity,kInfinity);
326  value = DBL_MAX;
327  }
328  ~LastValueWithDoubleVector(){}
329  LastValueWithDoubleVector(const LastValueWithDoubleVector& r)
330  : p(r.p), vec(r.vec), value(r.value){}
331  LastValueWithDoubleVector& operator=(const LastValueWithDoubleVector& r)
332  {
333  if (this == &r) { return *this; }
334  p = r.p; vec = r.vec; value = r.value;
335  return *this;
336  }
337  public:
339  G4ThreeVector vec;
340  G4double value;
341  };
342 
343  LastState fLastInside;
344  LastVector fLastNormal;
345  LastValue fLastDistanceToIn;
346  LastValue fLastDistanceToOut;
347  LastValueWithDoubleVector fLastDistanceToInWithV;
348  LastValueWithDoubleVector fLastDistanceToOutWithV;
349 
350  };
351 
352 //=====================================================================
353 
354 //---------------------
355 // inline functions
356 //---------------------
357 
358 inline
359 void G4TwistedTubs::SetFields(G4double phitwist, G4double innerrad,
360  G4double outerrad, G4double negativeEndz,
361  G4double positiveEndz)
362 {
363  fCubicVolume = 0.;
364  fPhiTwist = phitwist;
365  fEndZ[0] = negativeEndz;
366  fEndZ[1] = positiveEndz;
367  fEndZ2[0] = fEndZ[0] * fEndZ[0];
368  fEndZ2[1] = fEndZ[1] * fEndZ[1];
369  fInnerRadius = innerrad;
370  fOuterRadius = outerrad;
371  fInnerRadius2 = fInnerRadius * fInnerRadius;
372  fOuterRadius2 = fOuterRadius * fOuterRadius;
373 
374  if (std::fabs(fEndZ[0]) >= std::fabs(fEndZ[1])) {
375  fZHalfLength = std::fabs(fEndZ[0]);
376  } else {
377  fZHalfLength = std::fabs(fEndZ[1]);
378  }
379 
380  G4double parity = (fPhiTwist > 0 ? 1 : -1);
381  G4double tanHalfTwist = std::tan(0.5 * fPhiTwist);
382  G4double innerNumerator = std::fabs(fInnerRadius * tanHalfTwist) * parity;
383  G4double outerNumerator = std::fabs(fOuterRadius * tanHalfTwist) * parity;
384 
385  fTanInnerStereo = innerNumerator / fZHalfLength;
386  fTanOuterStereo = outerNumerator / fZHalfLength;
387  fTanInnerStereo2 = fTanInnerStereo * fTanInnerStereo;
388  fTanOuterStereo2 = fTanOuterStereo * fTanOuterStereo;
389  fInnerStereo = std::atan2(innerNumerator, fZHalfLength);
390  fOuterStereo = std::atan2(outerNumerator, fZHalfLength);
391  fEndInnerRadius[0] = std::sqrt(fInnerRadius2 + fEndZ2[0] * fTanInnerStereo2);
392  fEndInnerRadius[1] = std::sqrt(fInnerRadius2 + fEndZ2[1] * fTanInnerStereo2);
393  fEndOuterRadius[0] = std::sqrt(fOuterRadius2 + fEndZ2[0] * fTanOuterStereo2);
394  fEndOuterRadius[1] = std::sqrt(fOuterRadius2 + fEndZ2[1] * fTanOuterStereo2);
395 
396  fKappa = tanHalfTwist / fZHalfLength;
397  fEndPhi[0] = std::atan2(fEndZ[0] * tanHalfTwist, fZHalfLength);
398  fEndPhi[1] = std::atan2(fEndZ[1] * tanHalfTwist, fZHalfLength);
399 
400 #ifdef G4TWISTDEBUG
401  G4cout << "/********* G4TwistedTubs::SetFields() Field Parameters ***************** " << G4endl;
402  G4cout << "/* fPhiTwist : " << fPhiTwist << G4endl;
403  G4cout << "/* fEndZ(0, 1) : " << fEndZ[0] << " , " << fEndZ[1] << G4endl;
404  G4cout << "/* fEndPhi(0, 1) : " << fEndPhi[0] << " , " << fEndPhi[1] << G4endl;
405  G4cout << "/* fInnerRadius, fOuterRadius : " << fInnerRadius << " , " << fOuterRadius << G4endl;
406  G4cout << "/* fEndInnerRadius(0, 1) : " << fEndInnerRadius[0] << " , "
407  << fEndInnerRadius[1] << G4endl;
408  G4cout << "/* fEndOuterRadius(0, 1) : " << fEndOuterRadius[0] << " , "
409  << fEndOuterRadius[1] << G4endl;
410  G4cout << "/* fInnerStereo, fOuterStereo : " << fInnerStereo << " , " << fOuterStereo << G4endl;
411  G4cout << "/* tanHalfTwist, fKappa : " << tanHalfTwist << " , " << fKappa << G4endl;
412  G4cout << "/*********************************************************************** " << G4endl;
413 #endif
414 }
415 
416 #endif