Geant4_10
UCons.hh
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * This Software is part of the AIDA Unified Solids Library package *
4 // * See: https://aidasoft.web.cern.ch/USolids *
5 // ********************************************************************
6 //
7 // $Id:$
8 //
9 // --------------------------------------------------------------------
10 //
11 // UCons
12 //
13 // Class description:
14 //
15 // A UCons is, in the general case, a Phi segment of a cone, with
16 // half-length fDz, inner and outer radii specified at -fDz and +fDz.
17 // The Phi segment is described by a starting fSPhi angle, and the
18 // +fDPhi delta angle for the shape.
19 // If the delta angle is >=2*UUtils::kPi, the shape is treated as
20 // continuous in Phi
21 //
22 // Member Data:
23 //
24 // fRmin1 inside radius at -fDz
25 // fRmin2 inside radius at +fDz
26 // fRmax1 outside radius at -fDz
27 // fRmax2 outside radius at +fDz
28 // fDz half length in z
29 //
30 // fSPhi starting angle of the segment in radians
31 // fDPhi delta angle of the segment in radians
32 //
33 // fPhiFullCone Boolean variable used for indicate the Phi Section
34 //
35 // Note:
36 // Internally fSPhi & fDPhi are adjusted so that fDPhi<=2PI,
37 // and fDPhi+fSPhi<=2PI. This enables simpler comparisons to be
38 // made with (say) Phi of a point.
39 //
40 // 19.10.12 Marek Gayer
41 // Created from original implementation in Geant4
42 // --------------------------------------------------------------------
43 
44 #ifndef UCons_HH
45 #define UCons_HH
46 
47 #include "VUSolid.hh"
48 
49 class UCons : public VUSolid
50 {
51  public: // with description
52 
53  UCons(const std::string& pName,
54  double pRmin1, double pRmax1,
55  double pRmin2, double pRmax2,
56  double pDz,
57  double pSPhi, double pDPhi);
58  //
59  // Constructs a cone with the given name and dimensions
60 
61  ~UCons() ;
62  //
63  // Destructor
64 
65  // Accessors
66 
67  inline double GetInnerRadiusMinusZ() const;
68  inline double GetOuterRadiusMinusZ() const;
69  inline double GetInnerRadiusPlusZ() const;
70  inline double GetOuterRadiusPlusZ() const;
71  inline double GetZHalfLength() const;
72  inline double GetStartPhiAngle() const;
73  inline double GetDeltaPhiAngle() const;
74 
75  // Modifiers
76 
77  inline void SetInnerRadiusMinusZ(double Rmin1);
78  inline void SetOuterRadiusMinusZ(double Rmax1);
79  inline void SetInnerRadiusPlusZ(double Rmin2);
80  inline void SetOuterRadiusPlusZ(double Rmax2);
81  inline void SetZHalfLength(double newDz);
82  inline void SetStartPhiAngle(double newSPhi, bool trig = true);
83  inline void SetDeltaPhiAngle(double newDPhi);
84 
85  // Other methods for solid
86 
87  inline double GetCubicVolume();
88  inline double GetSurfaceArea();
89 
90 
91 // inline VUSolid::EnumInside Inside( const UVector3& p ) const;
92 
93  bool Normal(const UVector3& p, UVector3& n) const;
94 
95  double DistanceToIn(const UVector3& p, const UVector3& v, double aPstep = UUtils::kInfinity) const;
96 
97  double SafetyFromOutside(const UVector3& p, bool precise) const;
98 
99 
100 
101  double DistanceToOut(const UVector3& aPoint,
102  const UVector3& aDirection,
103  UVector3& aNormalVector,
104  bool& aConvex,
105  double aPstep = UUtils::kInfinity) const;
106 
107  double SafetyFromInside(const UVector3& p, bool precise) const;
108 
110 
111  UVector3 GetPointOnSurface() const;
112 
113  VUSolid* Clone() const;
114 
115  std::ostream& StreamInfo(std::ostream& os) const;
116 
117 // void Extent (EAxisType aAxis, double &aMin, double &aMax) const;
118  void Extent(UVector3& aMin, UVector3& aMax) const;
119 
120  virtual void GetParametersList(int /*aNumber*/, double* /*aArray*/) const;
121 
122  virtual void ComputeBBox(UBBox* /*aBox*/, bool /*aStore = false*/) {}
123 
124  // Visualisation functions
125 
126 
127  inline VUSolid::EnumInside Inside(const UVector3& p) const
128  {
129  double r2, rl, rh, pPhi, tolRMin, tolRMax; // rh2, rl2;
131  static const double halfCarTolerance = VUSolid::Tolerance() * 0.5;
132  static const double halfRadTolerance = kRadTolerance * 0.5;
133  static const double halfAngTolerance = kAngTolerance * 0.5;
134 
135  if (std::fabs(p.z) > fDz + halfCarTolerance)
136  {
137  return in = eOutside;
138  }
139  else if (std::fabs(p.z) >= fDz - halfCarTolerance)
140  {
141  in = eSurface;
142  }
143  else
144  {
145  in = eInside;
146  }
147 
148  r2 = p.x * p.x + p.y * p.y;
149  rl = 0.5 * (fRmin2 * (p.z + fDz) + fRmin1 * (fDz - p.z)) / fDz;
150  rh = 0.5 * (fRmax2 * (p.z + fDz) + fRmax1 * (fDz - p.z)) / fDz;
151 
152  // rh2 = rh*rh;
153 
154  tolRMin = rl - halfRadTolerance;
155  if (tolRMin < 0)
156  {
157  tolRMin = 0;
158  }
159  tolRMax = rh + halfRadTolerance;
160 
161  if ((r2 < tolRMin * tolRMin) || (r2 > tolRMax * tolRMax))
162  {
163  return in = eOutside;
164  }
165 
166  if (rl)
167  {
168  tolRMin = rl + halfRadTolerance;
169  }
170  else
171  {
172  tolRMin = 0.0;
173  }
174  tolRMax = rh - halfRadTolerance;
175 
176  if (in == eInside) // else it's eSurface already
177  {
178  if ((r2 < tolRMin * tolRMin) || (r2 >= tolRMax * tolRMax))
179  {
180  in = eSurface;
181  }
182  }
183  if (!fPhiFullCone && ((p.x != 0.0) || (p.y != 0.0)))
184  {
185  pPhi = std::atan2(p.y, p.x);
186 
187  if (pPhi < fSPhi - halfAngTolerance)
188  {
189  pPhi += 2 * UUtils::kPi;
190  }
191  else if (pPhi > fSPhi + fDPhi + halfAngTolerance)
192  {
193  pPhi -= 2 * UUtils::kPi;
194  }
195 
196  if ((pPhi < fSPhi - halfAngTolerance) ||
197  (pPhi > fSPhi + fDPhi + halfAngTolerance))
198  {
199  return in = eOutside;
200  }
201 
202  else if (in == eInside) // else it's eSurface anyway already
203  {
204  if ((pPhi < fSPhi + halfAngTolerance) ||
205  (pPhi > fSPhi + fDPhi - halfAngTolerance))
206  {
207  in = eSurface;
208  }
209  }
210  }
211  else if (!fPhiFullCone)
212  {
213  in = eSurface;
214  }
215 
216  return in;
217  }
218 
219  public: // without description
220 
221  UCons();
222  //
223  // Fake default constructor for usage restricted to direct object
224  // persistency for clients requiring preallocation of memory for
225  // persistifiable objects.
226 
227  UCons(const UCons& rhs);
228  UCons& operator=(const UCons& rhs);
229  // Copy constructor and assignment operator.
230 
231  // Old access functions
232 
233  inline double GetRmin1() const;
234  inline double GetRmax1() const;
235  inline double GetRmin2() const;
236  inline double GetRmax2() const;
237  inline double GetDz() const;
238  inline double GetSPhi() const;
239  inline double GetDPhi() const;
240 
241  private:
242 
243  double fCubicVolume, fSurfaceArea;
244 
245  inline double Capacity();
246  inline double SurfaceArea();
247 
248  inline void Initialize();
249  //
250  // Reset relevant values to zero
251 
252  inline void CheckSPhiAngle(double sPhi);
253  inline void CheckDPhiAngle(double dPhi);
254  inline void CheckPhiAngles(double sPhi, double dPhi);
255  //
256  // Reset relevant flags and angle values
257 
258  inline void InitializeTrigonometry();
259  //
260  // Recompute relevant trigonometric values and cache them
261 
262  UVector3 ApproxSurfaceNormal(const UVector3& p) const;
263  //
264  // Algorithm for SurfaceNormal() following the original
265  // specification for points not on the surface
266 
267  private:
268 
269  // Used by distanceToOut
270  //
271  enum ESide {kNull, kRMin, kRMax, kSPhi, kEPhi, kPZ, kMZ};
272 
273  // used by normal
274  //
275  enum ENorm {kNRMin, kNRMax, kNSPhi, kNEPhi, kNZ};
276 
277  double kRadTolerance, kAngTolerance;
278  //
279  // Radial and angular tolerances
280 
281  double fRmin1, fRmin2, fRmax1, fRmax2, fDz, fSPhi, fDPhi;
282  //
283  // Radial and angular dimensions
284 
285  double sinCPhi, cosCPhi, cosHDPhiOT, cosHDPhiIT,
286  sinSPhi, cosSPhi, sinEPhi, cosEPhi;
287  //
288  // Cached trigonometric values
289 
290  bool fPhiFullCone;
291 
292  double secRMin, tanRMin, tanRMax, secRMax;
293 
294 // double fSinPhi;
295 
296  //
297  // Flag for identification of section or full cone
298 };
299 
300 #include "UCons.icc"
301 
302 #endif
void SetZHalfLength(double newDz)
double GetRmin1() const
double GetDPhi() const
double SafetyFromOutside(const UVector3 &p, bool precise) const
Definition: UCons.cc:1261
virtual void ComputeBBox(UBBox *, bool)
Definition: UCons.hh:122
VUSolid::EnumInside Inside(const UVector3 &p) const
Definition: UCons.hh:127
double GetRmax2() const
void SetOuterRadiusMinusZ(double Rmax1)
UGeometryType GetEntityType() const
Definition: UCons.cc:2070
std::ostream & StreamInfo(std::ostream &os) const
Definition: UCons.cc:2089
double DistanceToIn(const UVector3 &p, const UVector3 &v, double aPstep=UUtils::kInfinity) const
Definition: UCons.cc:442
UCons & operator=(const UCons &rhs)
Definition: UCons.cc:132
ifstream in
Definition: comparison.C:7
const char * p
Definition: xmltok.h:285
~UCons()
Definition: UCons.cc:108
double SafetyFromInside(const UVector3 &p, bool precise) const
Definition: UCons.cc:1980
double GetOuterRadiusPlusZ() const
double GetSPhi() const
VUSolid * Clone() const
Definition: UCons.cc:2079
static double Tolerance()
Definition: VUSolid.hh:127
double x
Definition: UVector3.hh:136
ENorm
Definition: G4Cons.cc:72
Definition: UCons.hh:49
void SetDeltaPhiAngle(double newDPhi)
Char_t n[5]
double GetDz() const
double GetStartPhiAngle() const
bool Normal(const UVector3 &p, UVector3 &n) const
Definition: UCons.cc:176
double GetZHalfLength() const
EnumInside
Definition: VUSolid.hh:23
tuple v
Definition: test.py:18
double GetInnerRadiusPlusZ() const
double GetOuterRadiusMinusZ() const
void Extent(UVector3 &aMin, UVector3 &aMax) const
Definition: UCons.cc:2211
virtual void GetParametersList(int, double *) const
Definition: UCons.cc:2218
double GetRmax1() const
double GetSurfaceArea()
void SetInnerRadiusPlusZ(double Rmin2)
double GetDeltaPhiAngle() const
std::string UGeometryType
Definition: UTypes.hh:70
double GetInnerRadiusMinusZ() const
void SetOuterRadiusPlusZ(double Rmax2)
UCons()
Definition: UCons.cc:94
UVector3 GetPointOnSurface() const
Definition: UCons.cc:2116
ESide
Definition: G4Cons.cc:68
void SetInnerRadiusMinusZ(double Rmin1)
double z
Definition: UVector3.hh:138
double y
Definition: UVector3.hh:137
double GetRmin2() const
void SetStartPhiAngle(double newSPhi, bool trig=true)
double DistanceToOut(const UVector3 &aPoint, const UVector3 &aDirection, UVector3 &aNormalVector, bool &aConvex, double aPstep=UUtils::kInfinity) const
Definition: UCons.cc:1336
double GetCubicVolume()