Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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// G4TwistedTubs
27//
28// Class description:
29//
30// G4TwistedTubs is a sector of a twisted hollow cylinder.
31// A twisted cylinder which is placed along with z-axis and is
32// separated into phi-segments should become a hyperboloid, and
33// its each segmented piece should be tilted with a stereo angle.
34// G4TwistedTubs is a G4VSolid.
35//
36// Details of the implementation: "Development of a Geant4 solid
37// for stereo mini-jet cells in a cylindrical drift chamber",
38// Computer Physics Communications 153 (2003) pp.373–391
39
40// 01-Aug-2002 - Kotoyo Hoshina ([email protected]), created.
41// 13-Nov-2003 - O.Link ([email protected]), Integration in Geant4
42// from original version in Jupiter-2.5.02 application.
43// --------------------------------------------------------------------
44#ifndef G4TWISTEDTUBS_HH
45#define G4TWISTEDTUBS_HH
46
47#include "G4VSolid.hh"
49#include "G4TwistTubsSide.hh"
51
54
55class G4TwistedTubs : public G4VSolid
56{
57 public: // with description
58
59 G4TwistedTubs(const G4String& pname, // Name of instance
60 G4double twistedangle, // Twisted angle
61 G4double endinnerrad, // Inner radius at endcap
62 G4double endouterrad, // Outer radius at endcap
63 G4double halfzlen, // half z length
64 G4double dphi); // Phi angle of a segment
65
66 G4TwistedTubs(const G4String& pname, // Name of instance
67 G4double twistedangle, // Stereo angle
68 G4double endinnerrad, // Inner radius at endcap
69 G4double endouterrad, // Outer radius at endcap
70 G4double halfzlen, // half z length
71 G4int nseg, // Number of segments in totalPhi
72 G4double totphi); // Total angle of all segments
73
74 G4TwistedTubs(const G4String& pname, // Name of instance
75 G4double twistedangle, // Twisted angle
76 G4double innerrad, // Inner radius at z=0
77 G4double outerrad, // Outer radius at z=0
78 G4double negativeEndz, // -ve z endplate
79 G4double positiveEndz, // +ve z endplate
80 G4double dphi); // Phi angle of a segment
81
82 G4TwistedTubs(const G4String& pname, // Name of instance
83 G4double twistedangle, // Stereo angle
84 G4double innerrad, // Inner radius at z=0
85 G4double outerrad, // Outer radius at z=0
86 G4double negativeEndz, // -ve z endplate
87 G4double positiveEndz, // +ve z endplate
88 G4int nseg, // Number of segments in totalPhi
89 G4double totphi); // Total angle of all segments
90
91 virtual ~G4TwistedTubs();
92
94 const G4int /* n */ ,
95 const G4VPhysicalVolume* /* prep */ );
96
97 void BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const;
98
99 G4bool CalculateExtent(const EAxis pAxis,
100 const G4VoxelLimits& pVoxelLimit,
101 const G4AffineTransform& pTransform,
102 G4double& pMin,
103 G4double& pMax ) const;
104
106 const G4ThreeVector& v ) const;
107
108 G4double DistanceToIn (const G4ThreeVector& p ) const;
109
111 const G4ThreeVector& v,
112 const G4bool calcnorm = false,
113 G4bool* validnorm = nullptr,
114 G4ThreeVector* n = nullptr ) const;
115
116 G4double DistanceToOut(const G4ThreeVector& p) const;
117
118 EInside Inside (const G4ThreeVector& p) const;
119
121
122 void DescribeYourselfTo (G4VGraphicsScene& scene) const;
124 G4Polyhedron* GetPolyhedron () const;
125
126 std::ostream &StreamInfo(std::ostream& os) const;
127
128 // accessors
129
130 inline G4double GetDPhi () const { return fDPhi ; }
131 inline G4double GetPhiTwist () const { return fPhiTwist ; }
132 inline G4double GetInnerRadius () const { return fInnerRadius; }
133 inline G4double GetOuterRadius () const { return fOuterRadius; }
134 inline G4double GetInnerStereo () const { return fInnerStereo; }
135 inline G4double GetOuterStereo () const { return fOuterStereo; }
136 inline G4double GetZHalfLength () const { return fZHalfLength; }
137 inline G4double GetKappa () const { return fKappa ; }
138
139 inline G4double GetTanInnerStereo () const { return fTanInnerStereo ; }
140 inline G4double GetTanInnerStereo2() const { return fTanInnerStereo2 ; }
141 inline G4double GetTanOuterStereo () const { return fTanOuterStereo ; }
142 inline G4double GetTanOuterStereo2() const { return fTanOuterStereo2 ; }
143
144 inline G4double GetEndZ (G4int i) const { return fEndZ[i] ; }
145 inline G4double GetEndPhi (G4int i) const { return fEndPhi[i]; }
147 { return fEndInnerRadius[i]; }
149 { return fEndOuterRadius[i]; }
151 { return (fEndInnerRadius[0] > fEndInnerRadius[1] ?
152 fEndInnerRadius[0] : fEndInnerRadius[1]); }
154 { return (fEndOuterRadius[0] > fEndOuterRadius[1] ?
155 fEndOuterRadius[0] : fEndOuterRadius[1]); }
156
157 G4VisExtent GetExtent () const;
159 G4VSolid* Clone() const;
160
162 // Returns an estimation of the geometrical cubic volume of the
163 // solid. Caches the computed value once computed the first time.
165 // Returns the geometrical surface area of the solid.
166 // Caches the computed value once computed the first time.
167
169
170 public: // without description
171
172 G4TwistedTubs(__void__&);
173 // Fake default constructor for usage restricted to direct object
174 // persistency for clients requiring preallocation of memory for
175 // persistifiable objects.
176
177 G4TwistedTubs(const G4TwistedTubs& rhs);
179 // Copy constructor and assignment operator.
180
181#ifdef G4TWISTDEBUG
182 G4VTwistSurface* GetOuterHype() const { return fOuterHype; }
183#endif
184
185 private:
186
187 inline void SetFields(G4double phitwist, G4double innerrad,
188 G4double outerrad,
189 G4double negativeEndz, G4double positiveEndz);
190 void CreateSurfaces();
191 G4double GetLateralArea(G4double a, G4double r, G4double z) const;
192 G4double GetPhiCutArea(G4double a, G4double r, G4double z) const;
193
194 private:
195
196 G4double fPhiTwist; // Twist angle from -fZHalfLength to fZHalfLength
197 G4double fInnerRadius; // Inner-hype radius at z=0
198 G4double fOuterRadius; // Outer-hype radius at z=0
199 G4double fEndZ[2]; // z at endcaps, [0] = -ve z, [1] = +ve z
200 G4double fDPhi; // Phi-width of a segment fDPhi > 0
201 G4double fZHalfLength; // Half length along z-axis
202
203 G4double fInnerStereo; // Inner-hype stereo angle
204 G4double fOuterStereo; // Outer-hype stereo angle
205 G4double fTanInnerStereo; // std::tan(innerStereoAngle)
206 G4double fTanOuterStereo; // std::tan(outerStereoAngle)
207 G4double fKappa; // std::tan(fPhiTwist/2)/fZHalfLen;
208 G4double fEndInnerRadius[2]; // Inner-hype radii endcaps [0] -ve z, [1] +ve z
209 G4double fEndOuterRadius[2]; // Outer-hype radii endcaps [0] -ve z, [1] +ve z
210 G4double fEndPhi[2]; // Phi endcaps, [0] = -ve z, [1] = +ve z
211
212 G4double fInnerRadius2; // fInnerRadius * fInnerRadius
213 G4double fOuterRadius2; // fOuterRadius * fOuterRadius
214 G4double fTanInnerStereo2; // fInnerRadius * fInnerRadius
215 G4double fTanOuterStereo2; // fInnerRadius * fInnerRadius
216 G4double fEndZ2[2]; // fEndZ * fEndZ
217
218 G4VTwistSurface* fLowerEndcap; // Surface of -ve z
219 G4VTwistSurface* fUpperEndcap; // Surface of +ve z
220 G4VTwistSurface* fLatterTwisted; // Surface of -ve phi
221 G4VTwistSurface* fFormerTwisted; // Surface of +ve phi
222 G4VTwistSurface* fInnerHype; // Surface of -ve r
223 G4VTwistSurface* fOuterHype; // Surface of +ve r
224
225 G4double fCubicVolume = 0.0; // Cached value for cubic volume
226 G4double fSurfaceArea = 0.0; // Cached value for surface area
227
228 mutable G4bool fRebuildPolyhedron = false;
229 mutable G4Polyhedron* fpPolyhedron = nullptr; // polyhedron for vis
230
231 class LastState // last Inside result
232 {
233 public:
234 LastState()
235 {
236 p.set(kInfinity,kInfinity,kInfinity);
237 inside = kOutside;
238 }
239 ~LastState(){}
240 LastState(const LastState& r) : p(r.p), inside(r.inside){}
241 LastState& operator=(const LastState& r)
242 {
243 if (this == &r) { return *this; }
244 p = r.p; inside = r.inside;
245 return *this;
246 }
247 public:
249 EInside inside;
250 };
251
252 class LastVector // last SurfaceNormal result
253 {
254 public:
255 LastVector()
256 {
257 p.set(kInfinity,kInfinity,kInfinity);
258 vec.set(kInfinity,kInfinity,kInfinity);
259 surface = new G4VTwistSurface*[1];
260 }
261 ~LastVector()
262 {
263 delete [] surface;
264 }
265 LastVector(const LastVector& r) : p(r.p), vec(r.vec)
266 {
267 surface = new G4VTwistSurface*[1];
268 surface[0] = r.surface[0];
269 }
270 LastVector& operator=(const LastVector& r)
271 {
272 if (&r == this) { return *this; }
273 p = r.p; vec = r.vec;
274 delete [] surface; surface = new G4VTwistSurface*[1];
275 surface[0] = r.surface[0];
276 return *this;
277 }
278 public:
280 G4ThreeVector vec;
281 G4VTwistSurface **surface;
282 };
283
284 class LastValue // last G4double value
285 {
286 public:
287 LastValue()
288 {
289 p.set(kInfinity,kInfinity,kInfinity);
290 value = DBL_MAX;
291 }
292 ~LastValue(){}
293 LastValue(const LastValue& r) : p(r.p), value(r.value){}
294 LastValue& operator=(const LastValue& r)
295 {
296 if (this == &r) { return *this; }
297 p = r.p; value = r.value;
298 return *this;
299 }
300 public:
302 G4double value;
303 };
304
305 class LastValueWithDoubleVector // last G4double value
306 {
307 public:
308 LastValueWithDoubleVector()
309 {
310 p.set(kInfinity,kInfinity,kInfinity);
311 vec.set(kInfinity,kInfinity,kInfinity);
312 value = DBL_MAX;
313 }
314 ~LastValueWithDoubleVector(){}
315 LastValueWithDoubleVector(const LastValueWithDoubleVector& r)
316 : p(r.p), vec(r.vec), value(r.value){}
317 LastValueWithDoubleVector& operator=(const LastValueWithDoubleVector& r)
318 {
319 if (this == &r) { return *this; }
320 p = r.p; vec = r.vec; value = r.value;
321 return *this;
322 }
323 public:
325 G4ThreeVector vec;
326 G4double value;
327 };
328
329 LastState fLastInside;
330 LastVector fLastNormal;
331 LastValue fLastDistanceToIn;
332 LastValue fLastDistanceToOut;
333 LastValueWithDoubleVector fLastDistanceToInWithV;
334 LastValueWithDoubleVector fLastDistanceToOutWithV;
335
336 };
337
338//=====================================================================
339
340//---------------------
341// inline functions
342//---------------------
343
344inline
345void G4TwistedTubs::SetFields(G4double phitwist, G4double innerrad,
346 G4double outerrad, G4double negativeEndz,
347 G4double positiveEndz)
348{
349 fCubicVolume = 0.;
350 fPhiTwist = phitwist;
351 fEndZ[0] = negativeEndz;
352 fEndZ[1] = positiveEndz;
353 fEndZ2[0] = fEndZ[0] * fEndZ[0];
354 fEndZ2[1] = fEndZ[1] * fEndZ[1];
355 fInnerRadius = innerrad;
356 fOuterRadius = outerrad;
357 fInnerRadius2 = fInnerRadius * fInnerRadius;
358 fOuterRadius2 = fOuterRadius * fOuterRadius;
359
360 if (std::fabs(fEndZ[0]) >= std::fabs(fEndZ[1]))
361 {
362 fZHalfLength = std::fabs(fEndZ[0]);
363 }
364 else
365 {
366 fZHalfLength = std::fabs(fEndZ[1]);
367 }
368
369 G4double parity = (fPhiTwist > 0 ? 1 : -1);
370 G4double tanHalfTwist = std::tan(0.5 * fPhiTwist);
371 G4double innerNumerator = std::fabs(fInnerRadius * tanHalfTwist) * parity;
372 G4double outerNumerator = std::fabs(fOuterRadius * tanHalfTwist) * parity;
373
374 fTanInnerStereo = innerNumerator / fZHalfLength;
375 fTanOuterStereo = outerNumerator / fZHalfLength;
376 fTanInnerStereo2 = fTanInnerStereo * fTanInnerStereo;
377 fTanOuterStereo2 = fTanOuterStereo * fTanOuterStereo;
378 fInnerStereo = std::atan2(innerNumerator, fZHalfLength);
379 fOuterStereo = std::atan2(outerNumerator, fZHalfLength);
380 fEndInnerRadius[0] = std::sqrt(fInnerRadius2 + fEndZ2[0] * fTanInnerStereo2);
381 fEndInnerRadius[1] = std::sqrt(fInnerRadius2 + fEndZ2[1] * fTanInnerStereo2);
382 fEndOuterRadius[0] = std::sqrt(fOuterRadius2 + fEndZ2[0] * fTanOuterStereo2);
383 fEndOuterRadius[1] = std::sqrt(fOuterRadius2 + fEndZ2[1] * fTanOuterStereo2);
384
385 fKappa = tanHalfTwist / fZHalfLength;
386 fEndPhi[0] = std::atan2(fEndZ[0] * tanHalfTwist, fZHalfLength);
387 fEndPhi[1] = std::atan2(fEndZ[1] * tanHalfTwist, fZHalfLength);
388
389#ifdef G4TWISTDEBUG
390 G4cout << "/********* G4TwistedTubs::SetFields() Field Parameters ***************** " << G4endl;
391 G4cout << "/* fPhiTwist : " << fPhiTwist << G4endl;
392 G4cout << "/* fEndZ(0, 1) : " << fEndZ[0] << " , " << fEndZ[1] << G4endl;
393 G4cout << "/* fEndPhi(0, 1) : " << fEndPhi[0] << " , " << fEndPhi[1] << G4endl;
394 G4cout << "/* fInnerRadius, fOuterRadius : " << fInnerRadius << " , " << fOuterRadius << G4endl;
395 G4cout << "/* fEndInnerRadius(0, 1) : " << fEndInnerRadius[0] << " , "
396 << fEndInnerRadius[1] << G4endl;
397 G4cout << "/* fEndOuterRadius(0, 1) : " << fEndOuterRadius[0] << " , "
398 << fEndOuterRadius[1] << G4endl;
399 G4cout << "/* fInnerStereo, fOuterStereo : " << fInnerStereo << " , " << fOuterStereo << G4endl;
400 G4cout << "/* tanHalfTwist, fKappa : " << tanHalfTwist << " , " << fKappa << G4endl;
401 G4cout << "/*********************************************************************** " << G4endl;
402#endif
403}
404
405#endif
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
void set(double x, double y, double z)
G4double GetOuterRadius() const
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const
G4ThreeVector GetPointOnSurface() const
G4double GetZHalfLength() const
G4double GetPhiTwist() const
G4double GetSurfaceArea()
void DescribeYourselfTo(G4VGraphicsScene &scene) const
G4Polyhedron * CreatePolyhedron() const
G4double GetInnerStereo() const
G4double GetTanInnerStereo() const
void ComputeDimensions(G4VPVParameterisation *, const G4int, const G4VPhysicalVolume *)
G4VSolid * Clone() const
G4TwistedTubs & operator=(const G4TwistedTubs &rhs)
G4double GetEndInnerRadius() const
G4double GetEndOuterRadius() const
G4double GetOuterStereo() const
G4double GetCubicVolume()
G4Polyhedron * GetPolyhedron() const
G4GeometryType GetEntityType() const
virtual ~G4TwistedTubs()
G4double GetEndPhi(G4int i) const
G4double GetTanOuterStereo() const
EInside Inside(const G4ThreeVector &p) const
G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcnorm=false, G4bool *validnorm=nullptr, G4ThreeVector *n=nullptr) const
G4VisExtent GetExtent() const
G4double GetTanInnerStereo2() const
G4double GetTanOuterStereo2() const
G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const
G4double GetEndZ(G4int i) const
G4double GetKappa() const
G4double GetEndInnerRadius(G4int i) const
G4double GetInnerRadius() const
void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const
std::ostream & StreamInfo(std::ostream &os) const
G4double GetDPhi() const
G4double GetEndOuterRadius(G4int i) const
EAxis
Definition: geomdefs.hh:54
EInside
Definition: geomdefs.hh:67
@ kOutside
Definition: geomdefs.hh:68
yystype & operator=(const yystype &right)
Definition: G4UItokenNum.hh:78
#define DBL_MAX
Definition: templates.hh:62