Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/geometry/solids/specific/src/G4EllipticalCone.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /geometry/solids/specific/src/G4EllipticalCone.cc (Version 11.3.0) and /geometry/solids/specific/src/G4EllipticalCone.cc (Version 9.3.p2)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
                                                   >>  26 // $Id: G4EllipticalCone.cc,v 1.16.4.1 2010/09/08 15:54:58 gcosmo Exp $
                                                   >>  27 // GEANT4 tag $Name: geant4-09-03-patch-02 $
                                                   >>  28 //
 26 // Implementation of G4EllipticalCone class        29 // Implementation of G4EllipticalCone class
 27 //                                                 30 //
 28 // This code implements an Elliptical Cone giv     31 // This code implements an Elliptical Cone given explicitly by the
 29 // equation:                                       32 // equation:
 30 //   x^2/a^2 + y^2/b^2 = (z-h)^2                   33 //   x^2/a^2 + y^2/b^2 = (z-h)^2
 31 // and specified by the parameters (a,b,h) and     34 // and specified by the parameters (a,b,h) and a cut parallel to the
 32 // xy plane above z = 0.                           35 // xy plane above z = 0.
 33 //                                                 36 //
 34 // Author: Dionysios Anninos                       37 // Author: Dionysios Anninos
 35 // Revised: Evgueni Tcherniaev                 <<  38 //
 36 // -------------------------------------------     39 // --------------------------------------------------------------------
 37                                                    40 
 38 #if !(defined(G4GEOM_USE_UELLIPTICALCONE) && d << 
 39                                                << 
 40 #include "globals.hh"                              41 #include "globals.hh"
 41                                                    42 
 42 #include "G4EllipticalCone.hh"                     43 #include "G4EllipticalCone.hh"
 43                                                    44 
 44 #include "G4RandomTools.hh"                    << 
 45 #include "G4GeomTools.hh"                      << 
 46 #include "G4ClippablePolygon.hh"                   45 #include "G4ClippablePolygon.hh"
                                                   >>  46 #include "G4SolidExtentList.hh"
 47 #include "G4VoxelLimits.hh"                        47 #include "G4VoxelLimits.hh"
 48 #include "G4AffineTransform.hh"                    48 #include "G4AffineTransform.hh"
 49 #include "G4BoundingEnvelope.hh"               << 
 50 #include "G4GeometryTolerance.hh"                  49 #include "G4GeometryTolerance.hh"
 51                                                    50 
 52 #include "meshdefs.hh"                             51 #include "meshdefs.hh"
 53                                                    52 
 54 #include "Randomize.hh"                            53 #include "Randomize.hh"
 55                                                    54 
 56 #include "G4VGraphicsScene.hh"                     55 #include "G4VGraphicsScene.hh"
                                                   >>  56 #include "G4Polyhedron.hh"
                                                   >>  57 #include "G4NURBS.hh"
                                                   >>  58 #include "G4NURBSbox.hh"
 57 #include "G4VisExtent.hh"                          59 #include "G4VisExtent.hh"
 58                                                    60 
 59 #include "G4AutoLock.hh"                       <<  61 //#define G4SPECSDEBUG 1    
 60                                                << 
 61 namespace                                      << 
 62 {                                              << 
 63   G4Mutex polyhedronMutex = G4MUTEX_INITIALIZE << 
 64 }                                              << 
 65                                                    62 
 66 using namespace CLHEP;                             63 using namespace CLHEP;
 67                                                    64 
 68 ////////////////////////////////////////////// <<  65 //////////////////////////////////////////////////////////////////////
 69 //                                                 66 //
 70 // Constructor - check parameters                  67 // Constructor - check parameters
 71                                                <<  68 //
 72 G4EllipticalCone::G4EllipticalCone(const G4Str     69 G4EllipticalCone::G4EllipticalCone(const G4String& pName,
 73                                          G4dou     70                                          G4double  pxSemiAxis,
 74                                          G4dou     71                                          G4double  pySemiAxis,
 75                                          G4dou     72                                          G4double  pzMax,
 76                                          G4dou     73                                          G4double  pzTopCut)
 77   : G4VSolid(pName), zTopCut(0.)               <<  74   : G4VSolid(pName), fpPolyhedron(0), fCubicVolume(0.), fSurfaceArea(0.),
                                                   >>  75     zTopCut(0.)
 78 {                                                  76 {
 79   halfCarTol = 0.5*kCarTolerance;              <<  77 
                                                   >>  78   kRadTolerance = G4GeometryTolerance::GetInstance()->GetRadialTolerance();
 80                                                    79 
 81   // Check Semi-Axis & Z-cut                       80   // Check Semi-Axis & Z-cut
 82   //                                               81   //
 83   if ( (pxSemiAxis <= 0.) || (pySemiAxis <= 0.     82   if ( (pxSemiAxis <= 0.) || (pySemiAxis <= 0.) || (pzMax <= 0.) )
 84   {                                                83   {
 85      std::ostringstream message;               <<  84      G4cerr << "ERROR - G4EllipticalCone::G4EllipticalCone(): "
 86      message << "Invalid semi-axis or height f <<  85             << GetName() << G4endl
 87              << "\n   X semi-axis, Y semi-axis <<  86             << "        Invalid semi-axis or height!" << G4endl;
 88              << pxSemiAxis << ", " << pySemiAx <<  87      G4Exception("G4EllipticalCone::G4EllipticalCone()", "InvalidSetup",
 89      G4Exception("G4EllipticalCone::G4Elliptic <<  88                  FatalException, "Invalid semi-axis or height.");
 90                  FatalErrorInArgument, message <<  89   }
 91    }                                           << 
 92                                                << 
 93   if ( pzTopCut <= 0 )                             90   if ( pzTopCut <= 0 )
 94   {                                                91   {
 95      std::ostringstream message;               <<  92      G4cerr << "ERROR - G4EllipticalCone::G4EllipticalCone(): "
 96      message << "Invalid z-coordinate for cutt <<  93             << GetName() << G4endl
 97              << "\n   Z top cut = " << pzTopCu <<  94             << "        Invalid z-coordinate for cutting plane !" << G4endl;
 98      G4Exception("G4EllipticalCone::G4Elliptic <<  95      G4Exception("G4EllipticalCone::G4EllipticalCone()", "InvalidSetup",
 99                  FatalErrorInArgument, message <<  96                  FatalException, "Invalid z-coordinate for cutting plane.");
100   }                                                97   }
101                                                    98 
102   SetSemiAxis( pxSemiAxis, pySemiAxis, pzMax )     99   SetSemiAxis( pxSemiAxis, pySemiAxis, pzMax );
103   SetZCut(pzTopCut);                              100   SetZCut(pzTopCut);
104 }                                                 101 }
105                                                   102 
106 ////////////////////////////////////////////// << 103 ///////////////////////////////////////////////////////////////////////////////
107 //                                                104 //
108 // Fake default constructor - sets only member    105 // Fake default constructor - sets only member data and allocates memory
109 //                            for usage restri    106 //                            for usage restricted to object persistency.
110                                                << 107 //
111 G4EllipticalCone::G4EllipticalCone( __void__&     108 G4EllipticalCone::G4EllipticalCone( __void__& a )
112   : G4VSolid(a), halfCarTol(0.),               << 109   : G4VSolid(a), fpPolyhedron(0), kRadTolerance(0.), fCubicVolume(0.),
113     xSemiAxis(0.), ySemiAxis(0.), zheight(0.), << 110     fSurfaceArea(0.), xSemiAxis(0.), ySemiAxis(0.), zheight(0.),
114     cosAxisMin(0.), invXX(0.), invYY(0.)       << 111     semiAxisMax(0.), zTopCut(0.)
115 {                                                 112 {
116 }                                                 113 }
117                                                   114 
118 ////////////////////////////////////////////// << 115 ///////////////////////////////////////////////////////////////////////////////
119 //                                                116 //
120 // Destructor                                     117 // Destructor
121                                                << 118 //
122 G4EllipticalCone::~G4EllipticalCone()             119 G4EllipticalCone::~G4EllipticalCone()
123 {                                                 120 {
124   delete fpPolyhedron; fpPolyhedron = nullptr; << 
125 }                                                 121 }
126                                                   122 
127 ////////////////////////////////////////////// << 123 ///////////////////////////////////////////////////////////////////////////////
128 //                                                124 //
129 // Copy constructor                            << 125 // Calculate extent under transform and specified limit
130                                                << 
131 G4EllipticalCone::G4EllipticalCone(const G4Ell << 
132   : G4VSolid(rhs), halfCarTol(rhs.halfCarTol), << 
133     fCubicVolume(rhs.fCubicVolume), fSurfaceAr << 
134     xSemiAxis(rhs.xSemiAxis), ySemiAxis(rhs.yS << 
135     zheight(rhs.zheight), zTopCut(rhs.zTopCut) << 
136     cosAxisMin(rhs.cosAxisMin), invXX(rhs.invX << 
137 {                                              << 
138 }                                              << 
139                                                << 
140 ////////////////////////////////////////////// << 
141 //                                                126 //
142 // Assignment operator                         << 127 G4bool
143                                                << 128 G4EllipticalCone::CalculateExtent( const EAxis axis,
144 G4EllipticalCone& G4EllipticalCone::operator = << 129                                    const G4VoxelLimits &voxelLimit,
                                                   >> 130                                    const G4AffineTransform &transform,
                                                   >> 131                                          G4double &min, G4double &max ) const
145 {                                                 132 {
146    // Check assignment to self                 << 133   G4SolidExtentList  extentList( axis, voxelLimit );
147    //                                          << 134   
148    if (this == &rhs)  { return *this; }        << 135   //
149                                                << 136   // We are going to divide up our elliptical face into small pieces
150    // Copy base class data                     << 137   //
151    //                                          << 138   
152    G4VSolid::operator=(rhs);                   << 139   //
153                                                << 140   // Choose phi size of our segment(s) based on constants as
154    // Copy data                                << 141   // defined in meshdefs.hh
155    //                                          << 142   //
156    halfCarTol = rhs.halfCarTol;                << 143   G4int numPhi = kMaxMeshSections;
157    fCubicVolume = rhs.fCubicVolume; fSurfaceAr << 144   G4double sigPhi = twopi/numPhi;
158    xSemiAxis = rhs.xSemiAxis; ySemiAxis = rhs. << 145   
159    zheight = rhs.zheight; zTopCut = rhs.zTopCu << 146   //
160    cosAxisMin = rhs.cosAxisMin; invXX = rhs.in << 147   // We have to be careful to keep our segments completely outside
                                                   >> 148   // of the elliptical surface. To do so we imagine we have
                                                   >> 149   // a simple (unit radius) circular cross section (as in G4Tubs) 
                                                   >> 150   // and then "stretch" the dimensions as necessary to fit the ellipse.
                                                   >> 151   //
                                                   >> 152   G4double rFudge = 1.0/std::cos(0.5*sigPhi);
                                                   >> 153   G4double dxFudgeBot = xSemiAxis*2.*zheight*rFudge,
                                                   >> 154            dyFudgeBot = ySemiAxis*2.*zheight*rFudge;
                                                   >> 155   G4double dxFudgeTop = xSemiAxis*(zheight-zTopCut)*rFudge,
                                                   >> 156            dyFudgeTop = ySemiAxis*(zheight-zTopCut)*rFudge;
                                                   >> 157   
                                                   >> 158   //
                                                   >> 159   // As we work around the elliptical surface, we build
                                                   >> 160   // a "phi" segment on the way, and keep track of two
                                                   >> 161   // additional polygons for the two ends.
                                                   >> 162   //
                                                   >> 163   G4ClippablePolygon endPoly1, endPoly2, phiPoly;
                                                   >> 164   
                                                   >> 165   G4double phi = 0, 
                                                   >> 166            cosPhi = std::cos(phi),
                                                   >> 167            sinPhi = std::sin(phi);
                                                   >> 168   G4ThreeVector v0( dxFudgeTop*cosPhi, dyFudgeTop*sinPhi, +zTopCut ),
                                                   >> 169                 v1( dxFudgeBot*cosPhi, dyFudgeBot*sinPhi, -zTopCut ),
                                                   >> 170                 w0, w1;
                                                   >> 171   transform.ApplyPointTransform( v0 );
                                                   >> 172   transform.ApplyPointTransform( v1 );
                                                   >> 173   do
                                                   >> 174   {
                                                   >> 175     phi += sigPhi;
                                                   >> 176     if (numPhi == 1) phi = 0;  // Try to avoid roundoff
                                                   >> 177     cosPhi = std::cos(phi), 
                                                   >> 178     sinPhi = std::sin(phi);
                                                   >> 179     
                                                   >> 180     w0 = G4ThreeVector( dxFudgeTop*cosPhi, dyFudgeTop*sinPhi, +zTopCut );
                                                   >> 181     w1 = G4ThreeVector( dxFudgeBot*cosPhi, dyFudgeBot*sinPhi, -zTopCut );
                                                   >> 182     transform.ApplyPointTransform( w0 );
                                                   >> 183     transform.ApplyPointTransform( w1 );
                                                   >> 184     
                                                   >> 185     //
                                                   >> 186     // Add a point to our z ends
                                                   >> 187     //
                                                   >> 188     endPoly1.AddVertexInOrder( v0 );
                                                   >> 189     endPoly2.AddVertexInOrder( v1 );
                                                   >> 190     
                                                   >> 191     //
                                                   >> 192     // Build phi polygon
                                                   >> 193     //
                                                   >> 194     phiPoly.ClearAllVertices();
                                                   >> 195     
                                                   >> 196     phiPoly.AddVertexInOrder( v0 );
                                                   >> 197     phiPoly.AddVertexInOrder( v1 );
                                                   >> 198     phiPoly.AddVertexInOrder( w1 );
                                                   >> 199     phiPoly.AddVertexInOrder( w0 );
                                                   >> 200     
                                                   >> 201     if (phiPoly.PartialClip( voxelLimit, axis ))
                                                   >> 202     {
                                                   >> 203       //
                                                   >> 204       // Get unit normal
                                                   >> 205       //
                                                   >> 206       phiPoly.SetNormal( (v1-v0).cross(w0-v0).unit() );
                                                   >> 207       
                                                   >> 208       extentList.AddSurface( phiPoly );
                                                   >> 209     }
161                                                   210 
162    fRebuildPolyhedron = false;                 << 211     //
163    delete fpPolyhedron; fpPolyhedron = nullptr << 212     // Next vertex
                                                   >> 213     //    
                                                   >> 214     v0 = w0;
                                                   >> 215     v1 = w1;
                                                   >> 216   } while( --numPhi > 0 );
164                                                   217 
165    return *this;                               << 218   //
                                                   >> 219   // Process the end pieces
                                                   >> 220   //
                                                   >> 221   if (endPoly1.PartialClip( voxelLimit, axis ))
                                                   >> 222   {
                                                   >> 223     static const G4ThreeVector normal(0,0,+1);
                                                   >> 224     endPoly1.SetNormal( transform.TransformAxis(normal) );
                                                   >> 225     extentList.AddSurface( endPoly1 );
                                                   >> 226   }
                                                   >> 227   
                                                   >> 228   if (endPoly2.PartialClip( voxelLimit, axis ))
                                                   >> 229   {
                                                   >> 230     static const G4ThreeVector normal(0,0,-1);
                                                   >> 231     endPoly2.SetNormal( transform.TransformAxis(normal) );
                                                   >> 232     extentList.AddSurface( endPoly2 );
                                                   >> 233   }
                                                   >> 234   
                                                   >> 235   //
                                                   >> 236   // Return min/max value
                                                   >> 237   //
                                                   >> 238   return extentList.GetExtent( min, max );
166 }                                                 239 }
167                                                   240 
168 ////////////////////////////////////////////// << 241 ////////////////////////////////////////////////////////////////////////
169 //                                                242 //
170 // Get bounding box                            << 243 // Return whether point inside/outside/on surface
171                                                << 244 // Split into radius, phi, theta checks
172 void G4EllipticalCone::BoundingLimits(G4ThreeV << 245 // Each check modifies `in', or returns as approprate
173                                       G4ThreeV << 246 //
                                                   >> 247 EInside G4EllipticalCone::Inside(const G4ThreeVector& p) const
174 {                                                 248 {
175   G4double zcut   = GetZTopCut();              << 249   G4double rad2oo,  // outside surface outer tolerance
176   G4double height = GetZMax();                 << 250            rad2oi;  // outside surface inner tolerance
177   G4double xmax   = GetSemiAxisX()*(height+zcu << 251   
178   G4double ymax   = GetSemiAxisY()*(height+zcu << 252   EInside in;
179   pMin.set(-xmax,-ymax,-zcut);                 << 
180   pMax.set( xmax, ymax, zcut);                 << 
181                                                << 
182   // Check correctness of the bounding box     << 
183   //                                           << 
184   if (pMin.x() >= pMax.x() || pMin.y() >= pMax << 
185   {                                            << 
186     std::ostringstream message;                << 
187     message << "Bad bounding box (min >= max)  << 
188             << GetName() << " !"               << 
189             << "\npMin = " << pMin             << 
190             << "\npMax = " << pMax;            << 
191     G4Exception("G4EllipticalCone::BoundingLim << 
192                 JustWarning, message);         << 
193     DumpInfo();                                << 
194   }                                            << 
195 }                                              << 
196                                                   253 
197 ////////////////////////////////////////////// << 254   static const G4double halfRadTol = 0.5*kRadTolerance;
198 //                                             << 255   static const G4double halfCarTol = 0.5*kCarTolerance;
199 // Calculate extent under transform and specif << 
200                                                   256 
201 G4bool                                         << 257   // check this side of z cut first, because that's fast
202 G4EllipticalCone::CalculateExtent(const EAxis  << 258   //
203                                   const G4Voxe << 259 
204                                   const G4Affi << 260   if ( (p.z() < -zTopCut - halfCarTol)
205                                         G4doub << 261     || (p.z() > zTopCut + halfCarTol ) )
206 {                                              << 
207   G4ThreeVector bmin,bmax;                     << 
208   G4bool exist;                                << 
209                                                << 
210   // Check bounding box (bbox)                 << 
211   //                                           << 
212   BoundingLimits(bmin,bmax);                   << 
213   G4BoundingEnvelope bbox(bmin,bmax);          << 
214 #ifdef G4BBOX_EXTENT                           << 
215   return bbox.CalculateExtent(pAxis,pVoxelLimi << 
216 #endif                                         << 
217   if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVox << 
218   {                                               262   {
219     return exist = pMin < pMax;                << 263     return in = kOutside; 
220   }                                               264   }
221                                                   265 
222   // Set bounding envelope (benv) and calculat << 266   rad2oo= sqr(p.x()/( xSemiAxis + halfRadTol ))
223   //                                           << 267         + sqr(p.y()/( ySemiAxis + halfRadTol ));
224   static const G4int NSTEPS = 48; // number of << 
225   static const G4double ang = twopi/NSTEPS;    << 
226   static const G4double sinHalf = std::sin(0.5 << 
227   static const G4double cosHalf = std::cos(0.5 << 
228   static const G4double sinStep = 2.*sinHalf*c << 
229   static const G4double cosStep = 1. - 2.*sinH << 
230   G4double zcut   = bmax.z();                  << 
231   G4double height = GetZMax();                 << 
232   G4double sxmin  = GetSemiAxisX()*(height-zcu << 
233   G4double symin  = GetSemiAxisY()*(height-zcu << 
234   G4double sxmax  = bmax.x()/cosHalf;          << 
235   G4double symax  = bmax.y()/cosHalf;          << 
236                                                << 
237   G4double sinCur = sinHalf;                   << 
238   G4double cosCur = cosHalf;                   << 
239   G4ThreeVectorList baseA(NSTEPS),baseB(NSTEPS << 
240   for (G4int k=0; k<NSTEPS; ++k)               << 
241   {                                            << 
242     baseA[k].set(sxmax*cosCur,symax*sinCur,-zc << 
243     baseB[k].set(sxmin*cosCur,symin*sinCur, zc << 
244                                                << 
245     G4double sinTmp = sinCur;                  << 
246     sinCur = sinCur*cosStep + cosCur*sinStep;  << 
247     cosCur = cosCur*cosStep - sinTmp*sinStep;  << 
248   }                                            << 
249                                                << 
250   std::vector<const G4ThreeVectorList *> polyg << 
251   polygons[0] = &baseA;                        << 
252   polygons[1] = &baseB;                        << 
253   G4BoundingEnvelope benv(bmin,bmax,polygons); << 
254   exist = benv.CalculateExtent(pAxis,pVoxelLim << 
255   return exist;                                << 
256 }                                              << 
257                                                   268 
258 ////////////////////////////////////////////// << 269   if ( rad2oo > sqr( zheight-p.z() ) )
259 //                                             << 270   {
260 // Determine where is point: inside, outside o << 271     return in = kOutside; 
                                                   >> 272   }
261                                                   273 
262 EInside G4EllipticalCone::Inside(const G4Three << 274   //  rad2oi= sqr( p.x()*(1.0 + 0.5*kRadTolerance/(xSemiAxis*xSemiAxis)) )
263 {                                              << 275   //      + sqr( p.y()*(1.0 + 0.5*kRadTolerance/(ySemiAxis*ySemiAxis)) );
264   G4double hp = std::sqrt(p.x()*p.x()*invXX +  << 276   rad2oi = sqr(p.x()/( xSemiAxis - halfRadTol ))
265   G4double ds = (hp - zheight)*cosAxisMin;     << 277         + sqr(p.y()/( ySemiAxis - halfRadTol ));
266   G4double dz = std::abs(p.z()) - zTopCut;     << 278      
267   G4double dist = std::max(ds,dz);             << 279   if (rad2oi < sqr( zheight-p.z() ) )
                                                   >> 280   {
                                                   >> 281     in = ( ( p.z() < -zTopCut + halfRadTol )
                                                   >> 282         || ( p.z() >  zTopCut - halfRadTol ) ) ? kSurface : kInside;
                                                   >> 283   }
                                                   >> 284   else 
                                                   >> 285   {
                                                   >> 286     in = kSurface;
                                                   >> 287   }
268                                                   288 
269   if (dist > halfCarTol) return kOutside;      << 289   return in;
270   return (dist > -halfCarTol) ? kSurface : kIn << 
271 }                                                 290 }
272                                                   291 
273 //////////////////////////////////////////////    292 /////////////////////////////////////////////////////////////////////////
274 //                                                293 //
275 // Return unit normal at surface closest to p  << 294 // Return unit normal of surface closest to p not protected against p=0
276                                                << 295 //
277 G4ThreeVector G4EllipticalCone::SurfaceNormal(    296 G4ThreeVector G4EllipticalCone::SurfaceNormal( const G4ThreeVector& p) const
278 {                                                 297 {
279   G4ThreeVector norm(0,0,0);                   << 
280   G4int nsurf = 0;  // number of surfaces wher << 
281                                                   298 
282   G4double hp = std::sqrt(p.x()*p.x()*invXX +  << 299   G4double rx = sqr(p.x()/xSemiAxis), 
283   G4double ds = (hp - zheight)*cosAxisMin;     << 300            ry = sqr(p.y()/ySemiAxis);
284   if (std::abs(ds) <= halfCarTol)              << 301 
                                                   >> 302   G4double rad = std::sqrt(rx + ry); 
                                                   >> 303 
                                                   >> 304   G4ThreeVector norm;
                                                   >> 305 
                                                   >> 306   if( (p.z() < -zTopCut) && ((rx+ry) < sqr(zTopCut + zheight)) )
285   {                                               307   {
286     norm = G4ThreeVector(p.x()*invXX, p.y()*in << 308     return G4ThreeVector( 0., 0., -1. ); 
287     G4double mag = norm.mag();                 << 
288     if (mag == 0) return {0,0,1}; // apex      << 
289     norm *= (1/mag);                           << 
290     ++nsurf;                                   << 
291   }                                               309   }
292   G4double dz = std::abs(p.z()) - zTopCut;     << 310 
293   if (std::abs(dz) <= halfCarTol)              << 311   if( (p.z() > (zheight > zTopCut ? zheight : zTopCut)) &&
                                                   >> 312       ((rx+ry) < sqr(zheight-zTopCut)) )
294   {                                               313   {
295     norm += G4ThreeVector(0., 0.,(p.z() < 0) ? << 314     return G4ThreeVector( 0., 0., 1. );
296     ++nsurf;                                   << 
297   }                                               315   }
298                                                   316 
299   if      (nsurf == 1) return norm;            << 317   if( p.z() > rad + 2.*zTopCut - zheight ) 
300   else if (nsurf >  1) return norm.unit(); //  << 
301   else                                         << 
302   {                                               318   {
303     // Point is not on the surface             << 319     if ( p.z() > zTopCut )
304     //                                         << 320     {
305 #ifdef G4CSGDEBUG                              << 321       if( p.x() == 0. ) 
306     std::ostringstream message;                << 322       {
307     G4long oldprc = message.precision(16);     << 323         norm = G4ThreeVector( 0., p.y() < 0. ? -1. : 1., 1. ); 
308     message << "Point p is not on surface (!?) << 324         return norm /= norm.mag();
309             << GetName() << G4endl;            << 325       } 
310     message << "Position:\n";                  << 326       if( p.y() == 0. )
311     message << "   p.x() = " << p.x()/mm << "  << 327       {
312     message << "   p.y() = " << p.y()/mm << "  << 328         norm = G4ThreeVector( p.x() < 0. ? -1. : 1., 0., 1. ); 
313     message << "   p.z() = " << p.z()/mm << "  << 329         return norm /= norm.mag();
314     G4cout.precision(oldprc);                  << 330       } 
315     G4Exception("G4EllipticalCone::SurfaceNorm << 331       
316                 JustWarning, message );        << 332       G4double m =  std::fabs(p.x()/p.y());
317     DumpInfo();                                << 333       G4double c2 = sqr(zheight-zTopCut)/(1./sqr(xSemiAxis)+sqr(m/ySemiAxis));
318 #endif                                         << 334       G4double x  = std::sqrt(c2);
319     return ApproxSurfaceNormal(p);             << 335       G4double y  = m*x;
                                                   >> 336         
                                                   >> 337       x /= sqr(xSemiAxis);
                                                   >> 338       y /= sqr(ySemiAxis);
                                                   >> 339       
                                                   >> 340       norm = G4ThreeVector( p.x() < 0. ? -x : x, 
                                                   >> 341                             p.y() < 0. ? -y : y,
                                                   >> 342                             zheight - zTopCut );
                                                   >> 343       norm /= norm.mag();
                                                   >> 344       norm += G4ThreeVector( 0., 0., 1. );
                                                   >> 345       return norm /= norm.mag();      
                                                   >> 346     }
                                                   >> 347     
                                                   >> 348     return G4ThreeVector( 0., 0., 1. );    
320   }                                               349   }
321 }                                              << 350   
                                                   >> 351   if( p.z() < rad - 2.*zTopCut - zheight )
                                                   >> 352   {
                                                   >> 353     if( p.x() == 0. ) 
                                                   >> 354     {
                                                   >> 355       norm = G4ThreeVector( 0., p.y() < 0. ? -1. : 1., -1. ); 
                                                   >> 356       return norm /= norm.mag();
                                                   >> 357     } 
                                                   >> 358     if( p.y() == 0. )
                                                   >> 359     {
                                                   >> 360       norm = G4ThreeVector( p.x() < 0. ? -1. : 1., 0., -1. ); 
                                                   >> 361       return norm /= norm.mag();
                                                   >> 362     } 
                                                   >> 363     
                                                   >> 364     G4double m =  std::fabs(p.x()/p.y());
                                                   >> 365     G4double c2 = sqr(zheight+zTopCut)/(1./sqr(xSemiAxis)+sqr(m/ySemiAxis));
                                                   >> 366     G4double x  = std::sqrt(c2);
                                                   >> 367     G4double y  = m*x;
                                                   >> 368     
                                                   >> 369     x /= sqr(xSemiAxis);
                                                   >> 370     y /= sqr(ySemiAxis);
                                                   >> 371     
                                                   >> 372     norm = G4ThreeVector( p.x() < 0. ? -x : x, 
                                                   >> 373                           p.y() < 0. ? -y : y,
                                                   >> 374                           zheight - zTopCut );
                                                   >> 375     norm /= norm.mag();
                                                   >> 376     norm += G4ThreeVector( 0., 0., -1. );
                                                   >> 377     return norm /= norm.mag();      
                                                   >> 378   }
                                                   >> 379     
                                                   >> 380   norm  = G4ThreeVector(p.x()/sqr(xSemiAxis), p.y()/sqr(ySemiAxis), rad);
                                                   >> 381    
                                                   >> 382   G4double m = std::tan(pi/8.);
                                                   >> 383   G4double c = -zTopCut - m*(zTopCut + zheight);
322                                                   384 
323 ////////////////////////////////////////////// << 385   if( p.z() < -m*rad + c )
324 //                                             << 386     return G4ThreeVector (0.,0.,-1.);
325 // Find surface nearest to point and return co << 387 
326 // The algorithm is similar to the algorithm u << 388   return norm /= norm.mag();
327 // This method normally should not be called.  << 
328                                                << 
329 G4ThreeVector                                  << 
330 G4EllipticalCone::ApproxSurfaceNormal(const G4 << 
331 {                                              << 
332   G4double hp = std::sqrt(p.x()*p.x()*invXX +  << 
333   G4double ds = (hp - zheight)*cosAxisMin;     << 
334   G4double dz = std::abs(p.z()) - zTopCut;     << 
335   if (ds > dz && std::abs(hp - p.z()) > halfCa << 
336     return G4ThreeVector(p.x()*invXX, p.y()*in << 
337   else                                         << 
338     return { 0., 0., (G4double)((p.z() < 0) ?  << 
339 }                                                 389 }
340                                                   390 
341 ////////////////////////////////////////////// << 391 //////////////////////////////////////////////////////////////////////////
342 //                                                392 //
343 // Calculate distance to shape from outside, a    393 // Calculate distance to shape from outside, along normalised vector
344 // return kInfinity if no intersection, or int    394 // return kInfinity if no intersection, or intersection distance <= tolerance
345                                                << 395 //
346 G4double G4EllipticalCone::DistanceToIn( const    396 G4double G4EllipticalCone::DistanceToIn( const G4ThreeVector& p,
347                                          const    397                                          const G4ThreeVector& v  ) const
348 {                                                 398 {
                                                   >> 399 
                                                   >> 400   static const G4double halfTol = 0.5*kCarTolerance;
                                                   >> 401 
349   G4double distMin = kInfinity;                   402   G4double distMin = kInfinity;
350                                                   403 
351   // code from EllipticalTube                     404   // code from EllipticalTube
352                                                   405 
353   G4double sigz = p.z()+zTopCut;                  406   G4double sigz = p.z()+zTopCut;
354                                                   407 
355   //                                              408   //
356   // Check z = -dz planer surface                 409   // Check z = -dz planer surface
357   //                                              410   //
358                                                   411 
359   if (sigz < halfCarTol)                       << 412   if (sigz < halfTol)
360   {                                               413   {
361     //                                            414     //
362     // We are "behind" the shape in z, and so     415     // We are "behind" the shape in z, and so can
363     // potentially hit the rear face. Correct     416     // potentially hit the rear face. Correct direction?
364     //                                            417     //
365     if (v.z() <= 0)                               418     if (v.z() <= 0)
366     {                                             419     {
367       //                                          420       //
368       // As long as we are far enough away, we    421       // As long as we are far enough away, we know we
369       // can't intersect                          422       // can't intersect
370       //                                          423       //
371       if (sigz < 0) return kInfinity;             424       if (sigz < 0) return kInfinity;
372                                                   425       
373       //                                          426       //
374       // Otherwise, we don't intersect unless     427       // Otherwise, we don't intersect unless we are
375       // on the surface of the ellipse            428       // on the surface of the ellipse
376       //                                          429       //
377                                                   430 
378       if ( sqr(p.x()/( xSemiAxis - halfCarTol  << 431       if ( sqr(p.x()/( xSemiAxis - halfTol ))
379          + sqr(p.y()/( ySemiAxis - halfCarTol  << 432          + sqr(p.y()/( ySemiAxis - halfTol )) <= sqr( zheight+zTopCut ) )
380         return kInfinity;                         433         return kInfinity;
381                                                   434 
382     }                                             435     }
383     else                                          436     else
384     {                                             437     {
385       //                                          438       //
386       // How far?                                 439       // How far?
387       //                                          440       //
388       G4double q = -sigz/v.z();                << 441       G4double s = -sigz/v.z();
389                                                   442       
390       //                                          443       //
391       // Where does that place us?                444       // Where does that place us?
392       //                                          445       //
393       G4double xi = p.x() + q*v.x(),           << 446       G4double xi = p.x() + s*v.x(),
394                yi = p.y() + q*v.y();           << 447                yi = p.y() + s*v.y();
395                                                   448       
396       //                                          449       //
397       // Is this on the surface (within ellips    450       // Is this on the surface (within ellipse)?
398       //                                          451       //
399       if ( sqr(xi/xSemiAxis) + sqr(yi/ySemiAxi    452       if ( sqr(xi/xSemiAxis) + sqr(yi/ySemiAxis) <= sqr( zheight + zTopCut ) )
400       {                                           453       {
401         //                                        454         //
402         // Yup. Return q, unless we are on the << 455         // Yup. Return s, unless we are on the surface
403         //                                        456         //
404         return (sigz < -halfCarTol) ? q : 0;   << 457         return (sigz < -halfTol) ? s : 0;
405       }                                           458       }
406       else if (xi/(xSemiAxis*xSemiAxis)*v.x()     459       else if (xi/(xSemiAxis*xSemiAxis)*v.x()
407              + yi/(ySemiAxis*ySemiAxis)*v.y()     460              + yi/(ySemiAxis*ySemiAxis)*v.y() >= 0)
408       {                                           461       {
409         //                                        462         //
410         // Else, if we are traveling outwards,    463         // Else, if we are traveling outwards, we know
411         // we must miss                           464         // we must miss
412         //                                        465         //
413         //        return kInfinity;               466         //        return kInfinity;
414       }                                           467       }
415     }                                             468     }
416   }                                               469   }
417                                                   470 
418   //                                              471   //
419   // Check z = +dz planer surface                 472   // Check z = +dz planer surface
420   //                                              473   //
                                                   >> 474 
421   sigz = p.z() - zTopCut;                         475   sigz = p.z() - zTopCut;
422                                                   476   
423   if (sigz > -halfCarTol)                      << 477   if (sigz > -halfTol)
424   {                                               478   {
425     if (v.z() >= 0)                               479     if (v.z() >= 0)
426     {                                             480     {
427                                                   481 
428       if (sigz > 0) return kInfinity;             482       if (sigz > 0) return kInfinity;
429                                                   483 
430       if ( sqr(p.x()/( xSemiAxis - halfCarTol  << 484       if ( sqr(p.x()/( xSemiAxis - halfTol ))
431          + sqr(p.y()/( ySemiAxis - halfCarTol  << 485          + sqr(p.y()/( ySemiAxis - halfTol )) <= sqr( zheight-zTopCut ) )
432         return kInfinity;                         486         return kInfinity;
433                                                   487 
434     }                                             488     }
435     else {                                        489     else {
436       G4double q = -sigz/v.z();                << 490       G4double s = -sigz/v.z();
437                                                   491 
438       G4double xi = p.x() + q*v.x(),           << 492       G4double xi = p.x() + s*v.x(),
439                yi = p.y() + q*v.y();           << 493                yi = p.y() + s*v.y();
440                                                   494 
441       if ( sqr(xi/xSemiAxis) + sqr(yi/ySemiAxi    495       if ( sqr(xi/xSemiAxis) + sqr(yi/ySemiAxis) <= sqr( zheight - zTopCut ) )
442       {                                           496       {
443         return (sigz > -halfCarTol) ? q : 0;   << 497         return (sigz > -halfTol) ? s : 0;
444       }                                           498       }
445       else if (xi/(xSemiAxis*xSemiAxis)*v.x()     499       else if (xi/(xSemiAxis*xSemiAxis)*v.x()
446              + yi/(ySemiAxis*ySemiAxis)*v.y()     500              + yi/(ySemiAxis*ySemiAxis)*v.y() >= 0)
447       {                                           501       {
448         //        return kInfinity;               502         //        return kInfinity;
449       }                                           503       }
450     }                                             504     }
451   }                                               505   }
452                                                   506 
453                                                   507 
454 #if 0                                             508 #if 0
455                                                   509 
456   // check to see if Z plane is relevant          510   // check to see if Z plane is relevant
457   //                                              511   //
458   if (p.z() < -zTopCut - halfCarTol)           << 512   if (p.z() < -zTopCut - 0.5*kCarTolerance)
459   {                                               513   {
460     if (v.z() <= 0.0)                             514     if (v.z() <= 0.0)
461       return distMin;                             515       return distMin; 
462                                                   516 
463     G4double lambda = (-zTopCut - p.z())/v.z()    517     G4double lambda = (-zTopCut - p.z())/v.z();
464                                                   518     
465     if ( sqr((lambda*v.x()+p.x())/xSemiAxis) +    519     if ( sqr((lambda*v.x()+p.x())/xSemiAxis) + 
466          sqr((lambda*v.y()+p.y())/ySemiAxis) <    520          sqr((lambda*v.y()+p.y())/ySemiAxis) <=
467          sqr(zTopCut + zheight + halfCarTol) ) << 521          sqr(zTopCut + zheight + 0.5*kRadTolerance) ) 
468     {                                             522     { 
469       return distMin = std::fabs(lambda);         523       return distMin = std::fabs(lambda);    
470     }                                             524     }
471   }                                               525   }
472                                                   526 
473   if (p.z() > zTopCut + halfCarTol)            << 527   if (p.z() > zTopCut+0.5*kCarTolerance) 
474   {                                               528   {
475     if (v.z() >= 0.0)                             529     if (v.z() >= 0.0)
476       { return distMin; }                         530       { return distMin; }
477                                                   531 
478     G4double lambda  = (zTopCut - p.z()) / v.z    532     G4double lambda  = (zTopCut - p.z()) / v.z();
479                                                   533 
480     if ( sqr((lambda*v.x() + p.x())/xSemiAxis)    534     if ( sqr((lambda*v.x() + p.x())/xSemiAxis) + 
481          sqr((lambda*v.y() + p.y())/ySemiAxis)    535          sqr((lambda*v.y() + p.y())/ySemiAxis) <=
482          sqr(zheight - zTopCut + halfCarTol) ) << 536          sqr(zheight - zTopCut + 0.5*kRadTolerance) )
483       {                                           537       {
484         return distMin = std::fabs(lambda);       538         return distMin = std::fabs(lambda);
485       }                                           539       }
486   }                                               540   }
487                                                   541   
488   if (p.z() > zTopCut - halfCarTol             << 542   if (p.z() > zTopCut - halfTol
489    && p.z() < zTopCut + halfCarTol )           << 543    && p.z() < zTopCut + halfTol )
490   {                                               544   {
491     if (v.z() > 0.)                               545     if (v.z() > 0.) 
492       { return kInfinity; }                       546       { return kInfinity; }
493                                                   547 
494     return distMin = 0.;                          548     return distMin = 0.;
495   }                                               549   }
496                                                   550   
497   if (p.z() < -zTopCut + halfCarTol            << 551   if (p.z() < -zTopCut + halfTol
498    && p.z() > -zTopCut - halfCarTol)           << 552    && p.z() > -zTopCut - halfTol)
499   {                                               553   {
500     if (v.z() < 0.)                               554     if (v.z() < 0.)
501       { return distMin = kInfinity; }             555       { return distMin = kInfinity; }
502                                                   556     
503     return distMin = 0.;                          557     return distMin = 0.;
504   }                                               558   }
505                                                   559   
506 #endif                                            560 #endif
507                                                   561 
508   // if we are here then it either intersects     562   // if we are here then it either intersects or grazes the curved surface 
509   // or it does not intersect at all              563   // or it does not intersect at all
510   //                                              564   //
                                                   >> 565 
511   G4double A = sqr(v.x()/xSemiAxis) + sqr(v.y(    566   G4double A = sqr(v.x()/xSemiAxis) + sqr(v.y()/ySemiAxis) - sqr(v.z());
512   G4double B = 2*(v.x()*p.x()/sqr(xSemiAxis) +    567   G4double B = 2*(v.x()*p.x()/sqr(xSemiAxis) + 
513                   v.y()*p.y()/sqr(ySemiAxis) +    568                   v.y()*p.y()/sqr(ySemiAxis) + v.z()*(zheight-p.z()));
514   G4double C = sqr(p.x()/xSemiAxis) + sqr(p.y(    569   G4double C = sqr(p.x()/xSemiAxis) + sqr(p.y()/ySemiAxis) - 
515                sqr(zheight - p.z());              570                sqr(zheight - p.z());
516                                                   571  
517   G4double discr = B*B - 4.*A*C;                  572   G4double discr = B*B - 4.*A*C;
518                                                   573    
519   // if the discriminant is negative it never     574   // if the discriminant is negative it never hits the curved object
520   //                                              575   //
521   if ( discr < -halfCarTol )                   << 576   if ( discr < -halfTol )
522     { return distMin; }                           577     { return distMin; }
523                                                   578   
524   // case below is when it hits or grazes the  << 579   //case below is when it hits or grazes the surface
525   //                                              580   //
526   if ( (discr >= -halfCarTol ) && (discr < hal << 581   if ( (discr >= - halfTol ) && (discr < halfTol ) )
527   {                                               582   {
528     return distMin = std::fabs(-B/(2.*A));        583     return distMin = std::fabs(-B/(2.*A)); 
529   }                                               584   }
530                                                   585   
531   G4double plus  = (-B+std::sqrt(discr))/(2.*A    586   G4double plus  = (-B+std::sqrt(discr))/(2.*A);
532   G4double minus = (-B-std::sqrt(discr))/(2.*A    587   G4double minus = (-B-std::sqrt(discr))/(2.*A);
533                                                << 588   //  G4double lambda   = std::fabs(plus) < std::fabs(minus) ? plus : minus;
534   // Special case::Point on Surface, Check nor << 
535                                                   589 
536   if ( ( std::fabs(plus) < halfCarTol )||( std << 
537   {                                            << 
538     G4ThreeVector truenorm(p.x()/(xSemiAxis*xS << 
539                            p.y()/(ySemiAxis*yS << 
540                            -( p.z() - zheight  << 
541     if ( truenorm*v >= 0)  //  going outside t << 
542     {                                          << 
543       return kInfinity;                        << 
544     }                                          << 
545     else                                       << 
546     {                                          << 
547       return 0;                                << 
548     }                                          << 
549   }                                            << 
550                                                << 
551   // G4double lambda = std::fabs(plus) < std:: << 
552   G4double lambda = 0;                            590   G4double lambda = 0;
553                                                   591 
554   if ( minus > halfCarTol && minus < distMin ) << 592   if ( minus > halfTol && minus < distMin ) 
555   {                                               593   {
556     lambda = minus ;                              594     lambda = minus ;
557     // check normal vector   n * v < 0            595     // check normal vector   n * v < 0
558     G4ThreeVector pin = p + lambda*v;             596     G4ThreeVector pin = p + lambda*v;
559     if(std::fabs(pin.z())< zTopCut + halfCarTo << 597 
560     {                                          << 598     G4ThreeVector truenorm(pin.x()/(xSemiAxis*xSemiAxis),
561       G4ThreeVector truenorm(pin.x()/(xSemiAxi << 599                            pin.y()/(ySemiAxis*ySemiAxis),
562                              pin.y()/(ySemiAxi << 600                            - ( pin.z() - zheight ));
563                              - ( pin.z() - zhe << 601     if ( truenorm*v < 0)
564       if ( truenorm*v < 0)                     << 602     {   // yes, going inside the solid
565       {   // yes, going inside the solid       << 603       distMin = lambda;
566         distMin = lambda;                      << 
567       }                                        << 
568     }                                             604     }
569   }                                               605   }
570   if ( plus > halfCarTol  && plus < distMin )  << 606     
                                                   >> 607   if ( plus > halfTol  && plus < distMin )
571   {                                               608   {
572     lambda = plus ;                               609     lambda = plus ;
573     // check normal vector   n * v < 0            610     // check normal vector   n * v < 0
574     G4ThreeVector pin = p + lambda*v;             611     G4ThreeVector pin = p + lambda*v;
575     if(std::fabs(pin.z()) < zTopCut + halfCarT << 612 
576     {                                          << 613     G4ThreeVector truenorm(pin.x()/(xSemiAxis*xSemiAxis),
577       G4ThreeVector truenorm(pin.x()/(xSemiAxi << 614                            pin.y()/(ySemiAxis*ySemiAxis),
578                              pin.y()/(ySemiAxi << 615                            - ( pin.z() - zheight ) );
579                              - ( pin.z() - zhe << 616     if ( truenorm*v < 0)
580       if ( truenorm*v < 0)                     << 617     {   // yes, going inside the solid
581       {   // yes, going inside the solid       << 618       distMin = lambda;
582         distMin = lambda;                      << 
583       }                                        << 
584     }                                             619     }
585   }                                               620   }
586   if (distMin < halfCarTol) distMin=0.;        << 621 
587   return distMin ;                                622   return distMin ;
588 }                                                 623 }
589                                                   624 
590 ////////////////////////////////////////////// << 625 //////////////////////////////////////////////////////////////////////////
591 //                                                626 //
592 // Calculate distance (<= actual) to closest s    627 // Calculate distance (<= actual) to closest surface of shape from outside
593 // Return 0 if point inside                       628 // Return 0 if point inside
594                                                << 629 //
595 G4double G4EllipticalCone::DistanceToIn(const     630 G4double G4EllipticalCone::DistanceToIn(const G4ThreeVector& p) const
596 {                                                 631 {
597   G4double hp = std::sqrt(p.x()*p.x()*invXX +  << 632   G4double distR, distR2, distZ, maxDim;
598   G4double ds = (hp - zheight)*cosAxisMin;     << 633   G4double distRad;  
599   G4double dz = std::abs(p.z()) - zTopCut;     << 634 
600   G4double dist = std::max(ds,dz);             << 635   // check if the point lies either below z=-zTopCut in bottom elliptical
601   return (dist > 0) ? dist : 0.;               << 636   // region or on top within cut elliptical region
                                                   >> 637   //
                                                   >> 638   if( (p.z() <= -zTopCut) && (sqr(p.x()/xSemiAxis) + sqr(p.y()/ySemiAxis)
                                                   >> 639                            <= sqr(zTopCut + zheight + 0.5*kCarTolerance )) )
                                                   >> 640   {  
                                                   >> 641     //return distZ = std::fabs(zTopCut - p.z());
                                                   >> 642      return distZ = std::fabs(zTopCut + p.z());
                                                   >> 643   } 
                                                   >> 644   
                                                   >> 645   if( (p.z() >= zTopCut) && (sqr(p.x()/xSemiAxis)+sqr(p.y()/ySemiAxis)
                                                   >> 646                           <= sqr(zheight - zTopCut + kCarTolerance/2.0 )) )
                                                   >> 647   {
                                                   >> 648     return distZ = std::fabs(p.z() - zTopCut);
                                                   >> 649   } 
                                                   >> 650   
                                                   >> 651   // below we use the following approximation: we take the largest of the
                                                   >> 652   // axes and find the shortest distance to the circular (cut) cone of that
                                                   >> 653   // radius.  
                                                   >> 654   //
                                                   >> 655   maxDim = xSemiAxis >= ySemiAxis ? xSemiAxis:ySemiAxis;
                                                   >> 656   distRad = std::sqrt(p.x()*p.x()+p.y()*p.y());
                                                   >> 657 
                                                   >> 658   if( p.z() > maxDim*distRad + zTopCut*(1.+maxDim)-sqr(maxDim)*zheight )
                                                   >> 659   {
                                                   >> 660     distR2 = sqr(p.z() - zTopCut) + sqr(distRad - maxDim*(zheight - zTopCut));
                                                   >> 661     return std::sqrt( distR2 );
                                                   >> 662   } 
                                                   >> 663 
                                                   >> 664   if( distRad > maxDim*( zheight - p.z() ) )
                                                   >> 665   {
                                                   >> 666     if( p.z() > maxDim*distRad - (zTopCut*(1.+maxDim)+sqr(maxDim)*zheight) )
                                                   >> 667     {
                                                   >> 668       G4double zVal = (p.z()-maxDim*(distRad-maxDim*zheight))/(1.+sqr(maxDim));
                                                   >> 669       G4double rVal = maxDim*(zheight - zVal);
                                                   >> 670       return distR  = std::sqrt(sqr(p.z() - zVal) + sqr(distRad - rVal));
                                                   >> 671     }
                                                   >> 672   }
                                                   >> 673 
                                                   >> 674   if( distRad <= maxDim*(zheight - p.z()) )
                                                   >> 675   {
                                                   >> 676     distR2 = sqr(distRad - maxDim*(zheight + zTopCut)) + sqr(p.z() + zTopCut);
                                                   >> 677     return std::sqrt( distR2 );    
                                                   >> 678   }   
                                                   >> 679   
                                                   >> 680   return distR = 0;
602 }                                                 681 }
603                                                   682 
604 ////////////////////////////////////////////// << 683 /////////////////////////////////////////////////////////////////////////
605 //                                                684 //
606 // Calculate distance to surface of shape from    685 // Calculate distance to surface of shape from `inside',
607 // allowing for tolerance                         686 // allowing for tolerance
608                                                << 687 //
609 G4double G4EllipticalCone::DistanceToOut(const    688 G4double G4EllipticalCone::DistanceToOut(const G4ThreeVector& p,
610                                          const    689                                          const G4ThreeVector& v,
611                                          const    690                                          const G4bool calcNorm,
612                                                << 691                                                G4bool *validNorm,
613                                                << 692                                                G4ThreeVector *n  ) const
614 {                                                 693 {
615   G4double distMin, lambda;                       694   G4double distMin, lambda;
616   enum surface_e {kPlaneSurf, kCurvedSurf, kNo    695   enum surface_e {kPlaneSurf, kCurvedSurf, kNoSurf} surface;
617                                                   696   
618   distMin = kInfinity;                            697   distMin = kInfinity;
619   surface = kNoSurf;                              698   surface = kNoSurf;
620                                                   699 
621   if (v.z() < 0.0)                                700   if (v.z() < 0.0)
622   {                                               701   {
623     lambda = (-p.z() - zTopCut)/v.z();            702     lambda = (-p.z() - zTopCut)/v.z();
624                                                   703 
625     if ( (sqr((p.x() + lambda*v.x())/xSemiAxis    704     if ( (sqr((p.x() + lambda*v.x())/xSemiAxis) + 
626           sqr((p.y() + lambda*v.y())/ySemiAxis    705           sqr((p.y() + lambda*v.y())/ySemiAxis)) < 
627           sqr(zheight + zTopCut + halfCarTol)  << 706           sqr(zheight + zTopCut + 0.5*kCarTolerance) )
628     {                                             707     {
629       distMin = std::fabs(lambda);                708       distMin = std::fabs(lambda);
630                                                   709 
631       if (!calcNorm) { return distMin; }          710       if (!calcNorm) { return distMin; }
632     }                                             711     } 
633     distMin = std::fabs(lambda);                  712     distMin = std::fabs(lambda);
634     surface = kPlaneSurf;                         713     surface = kPlaneSurf;
635   }                                               714   }
636                                                   715 
637   if (v.z() > 0.0)                                716   if (v.z() > 0.0)
638   {                                               717   {
639     lambda = (zTopCut - p.z()) / v.z();           718     lambda = (zTopCut - p.z()) / v.z();
640                                                   719 
641     if ( (sqr((p.x() + lambda*v.x())/xSemiAxis    720     if ( (sqr((p.x() + lambda*v.x())/xSemiAxis)
642         + sqr((p.y() + lambda*v.y())/ySemiAxis    721         + sqr((p.y() + lambda*v.y())/ySemiAxis) )
643        < (sqr(zheight - zTopCut + halfCarTol)) << 722        < (sqr(zheight - zTopCut + 0.5*kCarTolerance)) )
644     {                                             723     {
645       distMin = std::fabs(lambda);                724       distMin = std::fabs(lambda);
646       if (!calcNorm) { return distMin; }          725       if (!calcNorm) { return distMin; }
647     }                                             726     }
648     distMin = std::fabs(lambda);                  727     distMin = std::fabs(lambda);
649     surface = kPlaneSurf;                         728     surface = kPlaneSurf;
650   }                                               729   }
651                                                   730   
652   // if we are here then it either intersects     731   // if we are here then it either intersects or grazes the 
653   // curved surface...                            732   // curved surface...
654   //                                              733   //
655   G4double A = sqr(v.x()/xSemiAxis) + sqr(v.y(    734   G4double A = sqr(v.x()/xSemiAxis) + sqr(v.y()/ySemiAxis) - sqr(v.z());
656   G4double B = 2.*(v.x()*p.x()/sqr(xSemiAxis)     735   G4double B = 2.*(v.x()*p.x()/sqr(xSemiAxis) +  
657                    v.y()*p.y()/sqr(ySemiAxis)     736                    v.y()*p.y()/sqr(ySemiAxis) + v.z()*(zheight-p.z()));
658   G4double C = sqr(p.x()/xSemiAxis) + sqr(p.y(    737   G4double C = sqr(p.x()/xSemiAxis) + sqr(p.y()/ySemiAxis)
659              - sqr(zheight - p.z());              738              - sqr(zheight - p.z());
660                                                   739  
661   G4double discr = B*B - 4.*A*C;                  740   G4double discr = B*B - 4.*A*C;
662                                                   741   
663   if ( discr >= - halfCarTol && discr < halfCa << 742   if ( discr >= - 0.5*kCarTolerance && discr < 0.5*kCarTolerance )
664   {                                               743   { 
665     if(!calcNorm) { return distMin = std::fabs    744     if(!calcNorm) { return distMin = std::fabs(-B/(2.*A)); }
666   }                                               745   }
667                                                   746 
668   else if ( discr > halfCarTol )               << 747   else if ( discr > 0.5*kCarTolerance )
669   {                                               748   {
670     G4double plus  = (-B+std::sqrt(discr))/(2.    749     G4double plus  = (-B+std::sqrt(discr))/(2.*A);
671     G4double minus = (-B-std::sqrt(discr))/(2.    750     G4double minus = (-B-std::sqrt(discr))/(2.*A);
672                                                   751 
673     if ( plus > halfCarTol && minus > halfCarT << 752     if ( plus > 0.5*kCarTolerance && minus > 0.5*kCarTolerance )
674     {                                             753     {
675       // take the shorter distance                754       // take the shorter distance
676       //                                          755       //
677       lambda   = std::fabs(plus) < std::fabs(m    756       lambda   = std::fabs(plus) < std::fabs(minus) ? plus : minus;
678     }                                             757     }
679     else                                          758     else
680     {                                             759     {
681       // at least one solution is close to zer    760       // at least one solution is close to zero or negative
682       // so, take small positive solution or z    761       // so, take small positive solution or zero 
683       //                                          762       //
684       lambda   = plus > -halfCarTol ? plus : 0 << 763       lambda   = plus > -0.5*kCarTolerance ? plus : 0;
685     }                                             764     }
686                                                   765 
687     if ( std::fabs(lambda) < distMin )            766     if ( std::fabs(lambda) < distMin )
688     {                                             767     {
689       if( std::fabs(lambda) > halfCarTol)      << 768       distMin  = std::fabs(lambda);
690       {                                        << 769       surface  = kCurvedSurf;
691         distMin  = std::fabs(lambda);          << 
692         surface  = kCurvedSurf;                << 
693       }                                        << 
694       else  // Point is On the Surface, Check  << 
695       {                                        << 
696         G4ThreeVector truenorm(p.x()/(xSemiAxi << 
697                                p.y()/(ySemiAxi << 
698                                -( p.z() - zhei << 
699         if( truenorm.dot(v) > 0 )              << 
700         {                                      << 
701           distMin  = 0.0;                      << 
702           surface  = kCurvedSurf;              << 
703         }                                      << 
704       }                                        << 
705     }                                             770     }
706   }                                               771   }
707                                                   772 
708   // set normal if requested                      773   // set normal if requested
709   //                                              774   //
710   if (calcNorm)                                   775   if (calcNorm)
711   {                                               776   {
712     if (surface == kNoSurf)                       777     if (surface == kNoSurf)
713     {                                             778     {
714       *validNorm = false;                         779       *validNorm = false;
715     }                                             780     }
716     else                                          781     else
717     {                                             782     {
718       *validNorm = true;                          783       *validNorm = true;
719       switch (surface)                            784       switch (surface)
720       {                                           785       {
721         case kPlaneSurf:                          786         case kPlaneSurf:
722         {                                         787         {
723           *n = G4ThreeVector(0.,0.,(v.z() > 0.    788           *n = G4ThreeVector(0.,0.,(v.z() > 0.0 ? 1. : -1.));
724         }                                         789         }
725         break;                                    790         break;
726                                                   791 
727         case kCurvedSurf:                         792         case kCurvedSurf:
728         {                                         793         {
729           G4ThreeVector pexit = p + distMin*v;    794           G4ThreeVector pexit = p + distMin*v;
730           G4ThreeVector truenorm( pexit.x()/(x << 795           G4ThreeVector truenorm(pexit.x()/(xSemiAxis*xSemiAxis),
731                                   pexit.y()/(y << 796                                  pexit.y()/(ySemiAxis*ySemiAxis),
732                                   -( pexit.z() << 797                                  pexit.z() - zheight );
733           truenorm /= truenorm.mag();             798           truenorm /= truenorm.mag();
734           *n= truenorm;                           799           *n= truenorm;
735         }                                         800         } 
736         break;                                    801         break;
737                                                   802 
738         default:            // Should never re    803         default:            // Should never reach this case ...
                                                   >> 804           G4int oldprc = G4cout.precision(16);
                                                   >> 805           G4cout << G4endl;
739           DumpInfo();                             806           DumpInfo();
740           std::ostringstream message;          << 807           G4cout << "Position:"  << G4endl << G4endl;
741           G4long oldprc = message.precision(16 << 808           G4cout << "p.x() = "   << p.x()/mm << " mm" << G4endl;
742           message << "Undefined side for valid << 809           G4cout << "p.y() = "   << p.y()/mm << " mm" << G4endl;
743                   << G4endl                    << 810           G4cout << "p.z() = "   << p.z()/mm << " mm" << G4endl << G4endl;
744                   << "Position:"  << G4endl    << 811           G4cout << "Direction:" << G4endl << G4endl;
745                   << "   p.x() = "   << p.x()/ << 812           G4cout << "v.x() = "   << v.x() << G4endl;
746                   << "   p.y() = "   << p.y()/ << 813           G4cout << "v.y() = "   << v.y() << G4endl;
747                   << "   p.z() = "   << p.z()/ << 814           G4cout << "v.z() = "   << v.z() << G4endl << G4endl;
748                   << "Direction:" << G4endl    << 815           G4cout << "Proposed distance :" << G4endl << G4endl;
749                   << "   v.x() = "   << v.x()  << 816           G4cout << "distMin = "    << distMin/mm << " mm" << G4endl << G4endl;
750                   << "   v.y() = "   << v.y()  << 817           G4cout.precision(oldprc);
751                   << "   v.z() = "   << v.z()  << 
752                   << "Proposed distance :" <<  << 
753                   << "   distMin = "    << dis << 
754           message.precision(oldprc);           << 
755           G4Exception("G4EllipticalCone::Dista    818           G4Exception("G4EllipticalCone::DistanceToOut(p,v,..)",
756                       "GeomSolids1002", JustWa << 819                       "Notification", JustWarning,
                                                   >> 820                       "Undefined side for valid surface normal to solid.");
757           break;                                  821           break;
758       }                                           822       }
759     }                                             823     }
760   }                                               824   }
761                                                   825 
762   if (distMin < halfCarTol) { distMin=0; }     << 
763                                                << 
764   return distMin;                                 826   return distMin;
765 }                                                 827 }
766                                                   828 
767 //////////////////////////////////////////////    829 /////////////////////////////////////////////////////////////////////////
768 //                                                830 //
769 // Calculate distance (<=actual) to closest su    831 // Calculate distance (<=actual) to closest surface of shape from inside
770                                                << 832 //
771 G4double G4EllipticalCone::DistanceToOut(const    833 G4double G4EllipticalCone::DistanceToOut(const G4ThreeVector& p) const
772 {                                                 834 {
                                                   >> 835   G4double rad,roo,roo1, distR, distZ, distMin=0.;
                                                   >> 836   G4double minAxis = xSemiAxis < ySemiAxis ? xSemiAxis : ySemiAxis;
                                                   >> 837 
773 #ifdef G4SPECSDEBUG                               838 #ifdef G4SPECSDEBUG
774   if( Inside(p) == kOutside )                     839   if( Inside(p) == kOutside )
775   {                                               840   {
776      std::ostringstream message;               << 841      G4cout.precision(16) ;
777      G4long oldprc = message.precision(16);    << 842      G4cout << G4endl ;
778      message << "Point p is outside (!?) of so << 
779              << "Position:\n"                  << 
780              << "   p.x() = "  << p.x()/mm <<  << 
781              << "   p.y() = "  << p.y()/mm <<  << 
782              << "   p.z() = "  << p.z()/mm <<  << 
783      message.precision(oldprc) ;               << 
784      G4Exception("G4Ellipsoid::DistanceToOut(p << 
785                  JustWarning, message);        << 
786      DumpInfo();                                  843      DumpInfo();
                                                   >> 844      G4cout << "Position:"  << G4endl << G4endl ;
                                                   >> 845      G4cout << "p.x() = "   << p.x()/mm << " mm" << G4endl ;
                                                   >> 846      G4cout << "p.y() = "   << p.y()/mm << " mm" << G4endl ;
                                                   >> 847      G4cout << "p.z() = "   << p.z()/mm << " mm" << G4endl << G4endl ;
                                                   >> 848      G4cout.precision(6) ;
                                                   >> 849      G4Exception("G4Ellipsoid::DistanceToOut(p)", "Notification", JustWarning, 
                                                   >> 850                  "Point p is outside !?" );
787   }                                               851   }
788 #endif                                            852 #endif
789   G4double hp = std::sqrt(p.x()*p.x()*invXX +  << 853     
790   G4double ds = (zheight - hp)*cosAxisMin;     << 854   // since we have made the above warning, below we are working assuming p
791   G4double dz = zTopCut - std::abs(p.z());     << 855   // is inside check how close it is to the circular cone with radius equal
792   G4double dist = std::min(ds,dz);             << 856   // to the smaller of the axes
793   return (dist > 0) ? dist : 0.;               << 857   //
794 }                                              << 858   if( sqr(p.x()/minAxis)+sqr(p.y()/minAxis) < sqr(zheight - p.z()) )
                                                   >> 859   {
                                                   >> 860     rad     = std::sqrt(sqr(p.x()) + sqr(p.y()));
                                                   >> 861     roo     = minAxis*(zheight-p.z()); // radius of cone at z= p.z()
                                                   >> 862     roo1    = minAxis*(zheight-zTopCut); // radius of cone at z=+zTopCut
795                                                   863 
796 ////////////////////////////////////////////// << 864     distZ=zTopCut - std::fabs(p.z()) ;
797 //                                             << 865     distR=(roo-rad)/(std::sqrt(1+sqr(minAxis)));
798 // GetEntityType                               << 
799                                                   866 
800 G4GeometryType G4EllipticalCone::GetEntityType << 867     if(rad>roo1)
801 {                                              << 868     {
802   return {"G4EllipticalCone"};                 << 869       distMin=(zTopCut-p.z())*(roo-rad)/(roo-roo1);
                                                   >> 870       distMin=std::min(distMin,distR);
                                                   >> 871     }      
                                                   >> 872     distMin=std::min(distR,distZ);
                                                   >> 873   }
                                                   >> 874 
                                                   >> 875   return distMin;
803 }                                                 876 }
804                                                   877 
805 ////////////////////////////////////////////// << 878 //////////////////////////////////////////////////////////////////////////
806 //                                                879 //
807 // Make a clone of the object                  << 880 // GetEntityType
808                                                << 881 //
809 G4VSolid* G4EllipticalCone::Clone() const      << 882 G4GeometryType G4EllipticalCone::GetEntityType() const
810 {                                                 883 {
811   return new G4EllipticalCone(*this);          << 884   return G4String("G4EllipticalCone");
812 }                                                 885 }
813                                                   886 
814 ////////////////////////////////////////////// << 887 //////////////////////////////////////////////////////////////////////////
815 //                                                888 //
816 // Stream object contents to an output stream     889 // Stream object contents to an output stream
817                                                << 890 //
818 std::ostream& G4EllipticalCone::StreamInfo( st    891 std::ostream& G4EllipticalCone::StreamInfo( std::ostream& os ) const
819 {                                                 892 {
820   G4long oldprc = os.precision(16);            << 
821   os << "-------------------------------------    893   os << "-----------------------------------------------------------\n"
822      << "    *** Dump for solid - " << GetName    894      << "    *** Dump for solid - " << GetName() << " ***\n"
823      << "    =================================    895      << "    ===================================================\n"
824      << " Solid type: G4EllipticalCone\n"         896      << " Solid type: G4EllipticalCone\n"
825      << " Parameters: \n"                         897      << " Parameters: \n"
826                                                   898 
827      << "    semi-axis x: " << xSemiAxis/mm <<    899      << "    semi-axis x: " << xSemiAxis/mm << " mm \n"
828      << "    semi-axis y: " << ySemiAxis/mm <<    900      << "    semi-axis y: " << ySemiAxis/mm << " mm \n"
829      << "    height    z: " << zheight/mm << "    901      << "    height    z: " << zheight/mm << " mm \n"
830      << "    half length in  z: " << zTopCut/m    902      << "    half length in  z: " << zTopCut/mm << " mm \n"
831      << "-------------------------------------    903      << "-----------------------------------------------------------\n";
832   os.precision(oldprc);                        << 
833                                                   904 
834   return os;                                      905   return os;
835 }                                                 906 }
836                                                   907 
837 //////////////////////////////////////////////    908 /////////////////////////////////////////////////////////////////////////
838 //                                                909 //
839 // Return random point on the surface of the s << 910 // GetPointOnSurface
840                                                << 911 //
                                                   >> 912 // returns quasi-uniformly distributed point on surface of elliptical cone
                                                   >> 913 //
841 G4ThreeVector G4EllipticalCone::GetPointOnSurf    914 G4ThreeVector G4EllipticalCone::GetPointOnSurface() const
842 {                                                 915 {
843   G4double x0 = xSemiAxis*zheight; // x semi a << 
844   G4double y0 = ySemiAxis*zheight; // y semi a << 
845   G4double s0 = G4GeomTools::EllipticConeLater << 
846   G4double kmin = (zTopCut >= zheight ) ? 0. : << 
847   G4double kmax = (zTopCut >= zheight ) ? 2. : << 
848                                                   916 
849   // Set areas (base at -Z, side surface, base << 917   G4double phi, sinphi, cosphi, aOne, aTwo, aThree,
850   //                                           << 918            chose, zRand, rRand1, rRand2;
851   G4double szmin =  pi*x0*y0*kmax*kmax;        << 919   
852   G4double szmax =  pi*x0*y0*kmin*kmin;        << 920   G4double rOne = std::sqrt(sqr(xSemiAxis)
853   G4double sside =  s0*(kmax*kmax - kmin*kmin) << 921                 + sqr(ySemiAxis))*(zheight - zTopCut);
854   G4double ssurf[3] = { szmin, sside, szmax }; << 922   G4double rTwo = std::sqrt(sqr(xSemiAxis)
855   for (auto i=1; i<3; ++i) { ssurf[i] += ssurf << 923                 + sqr(ySemiAxis))*(zheight + zTopCut);
856                                                << 924   
857   // Select surface                            << 925   aOne   = pi*(rOne + rTwo)*std::sqrt(sqr(rOne - rTwo)+sqr(2.*zTopCut));
858   //                                           << 926   aTwo   = pi*xSemiAxis*ySemiAxis*sqr(zheight+zTopCut);
859   G4double select = ssurf[2]*G4UniformRand();  << 927   aThree = pi*xSemiAxis*ySemiAxis*sqr(zheight-zTopCut);  
860   G4int k = 2;                                 << 928 
861   if (select <= ssurf[1]) k = 1;               << 929   phi = RandFlat::shoot(0.,twopi);
862   if (select <= ssurf[0]) k = 0;               << 930   cosphi = std::cos(phi);
                                                   >> 931   sinphi = std::sin(phi);
                                                   >> 932   
                                                   >> 933   if(zTopCut >= zheight) aThree = 0.;
863                                                   934 
864   // Pick random point on selected surface     << 935   chose = RandFlat::shoot(0.,aOne+aTwo+aThree);
865   //                                           << 936   if((chose>=0.) && (chose<aOne))
866   G4ThreeVector p;                             << 
867   switch(k)                                    << 
868   {                                               937   {
869     case 0: // base at -Z, uniform distributio << 938     zRand = RandFlat::shoot(-zTopCut,zTopCut);
870     {                                          << 939     return G4ThreeVector(xSemiAxis*(zheight-zRand)*cosphi,
871       G4double zh = zheight + zTopCut;         << 940                          ySemiAxis*(zheight-zRand)*sinphi,zRand);    
872       G4TwoVector rho = G4RandomPointInEllipse << 941   }
873       p.set(rho.x(),rho.y(),-zTopCut);         << 942   else if((chose>=aOne) && (chose<aOne+aTwo))
874       break;                                   << 943   {
875     }                                          << 944     do
876     case 1: // side surface, uniform distribut << 
877     {                                             945     {
878       G4double zh = G4RandomRadiusInRing(zheig << 946       rRand1 = RandFlat::shoot(0.,1.) ;
879       G4double a = x0;                         << 947       rRand2 = RandFlat::shoot(0.,1.) ;
880       G4double b = y0;                         << 948     } while ( rRand2 >= rRand1  ) ;
881                                                   949 
882       G4double hh = zheight*zheight;           << 950     //    rRand2 = RandFlat::shoot(0.,std::sqrt(1.-sqr(rRand1)));
883       G4double aa = a*a;                       << 951     return G4ThreeVector(rRand1*xSemiAxis*(zheight+zTopCut)*cosphi,
884       G4double bb = b*b;                       << 952                          rRand1*ySemiAxis*(zheight+zTopCut)*sinphi, -zTopCut);
885       G4double R  = std::max(a,b);             << 
886       G4double mu_max = R*std::sqrt(hh + R*R); << 
887                                                   953 
888       G4double x,y;                            << 
889       for (auto i=0; i<1000; ++i)              << 
890       {                                        << 
891   G4double phi = CLHEP::twopi*G4UniformRand(); << 
892         x = std::cos(phi);                     << 
893         y = std::sin(phi);                     << 
894         G4double xx = x*x;                     << 
895         G4double yy = y*y;                     << 
896         G4double E = hh + aa*xx + bb*yy;       << 
897         G4double F = (aa-bb)*x*y;              << 
898         G4double G = aa*yy + bb*xx;            << 
899         G4double mu = std::sqrt(E*G - F*F);    << 
900         if (mu_max*G4UniformRand() <= mu) brea << 
901       }                                        << 
902       p.set(zh*xSemiAxis*x,zh*ySemiAxis*y,zhei << 
903       break;                                   << 
904     }                                          << 
905     case 2: // base at +Z, uniform distributio << 
906     {                                          << 
907       G4double zh = zheight - zTopCut;         << 
908       G4TwoVector rho = G4RandomPointInEllipse << 
909       p.set(rho.x(),rho.y(),zTopCut);          << 
910       break;                                   << 
911     }                                          << 
912   }                                               954   }
913   return p;                                    << 955   // else
914 }                                              << 956   //
915                                                << 
916 ////////////////////////////////////////////// << 
917 //                                             << 
918 // Get cubic volume                            << 
919                                                   957 
920 G4double G4EllipticalCone::GetCubicVolume()    << 958   do
921 {                                              << 
922   if (fCubicVolume == 0.0)                     << 
923   {                                               959   {
924     G4double x0 = xSemiAxis*zheight; // x semi << 960     rRand1 = RandFlat::shoot(0.,1.) ;
925     G4double y0 = ySemiAxis*zheight; // y semi << 961     rRand2 = RandFlat::shoot(0.,1.) ;
926     G4double v0 = CLHEP::pi*x0*y0*zheight/3.;  << 962   } while ( rRand2 >= rRand1  ) ;
927     G4double kmin = (zTopCut >= zheight ) ? 0. << 
928     G4double kmax = (zTopCut >= zheight ) ? 2. << 
929     fCubicVolume = (kmax - kmin)*(kmax*kmax +  << 
930   }                                            << 
931   return fCubicVolume;                         << 
932 }                                              << 
933                                                << 
934 ////////////////////////////////////////////// << 
935 //                                             << 
936 // Get surface area                            << 
937                                                   963 
938 G4double G4EllipticalCone::GetSurfaceArea()    << 964   return G4ThreeVector(rRand1*xSemiAxis*(zheight-zTopCut)*cosphi,
939 {                                              << 965                        rRand1*ySemiAxis*(zheight-zTopCut)*sinphi, zTopCut);
940   if (fSurfaceArea == 0.0)                     << 
941   {                                            << 
942     G4double x0 = xSemiAxis*zheight; // x semi << 
943     G4double y0 = ySemiAxis*zheight; // y semi << 
944     G4double s0 = G4GeomTools::EllipticConeLat << 
945     G4double kmin = (zTopCut >= zheight ) ? 0. << 
946     G4double kmax = (zTopCut >= zheight ) ? 2. << 
947     fSurfaceArea = (kmax - kmin)*(kmax + kmin) << 
948                  + CLHEP::pi*x0*y0*(kmin*kmin  << 
949   }                                            << 
950   return fSurfaceArea;                         << 
951 }                                                 966 }
952                                                   967 
953 ////////////////////////////////////////////// << 
954 //                                                968 //
955 // Methods for visualisation                      969 // Methods for visualisation
                                                   >> 970 //
956                                                   971 
957 void G4EllipticalCone::DescribeYourselfTo (G4V    972 void G4EllipticalCone::DescribeYourselfTo (G4VGraphicsScene& scene) const
958 {                                                 973 {
959   scene.AddSolid(*this);                          974   scene.AddSolid(*this);
960 }                                                 975 }
961                                                   976 
962 G4VisExtent G4EllipticalCone::GetExtent() cons    977 G4VisExtent G4EllipticalCone::GetExtent() const
963 {                                                 978 {
964   // Define the sides of the box into which th    979   // Define the sides of the box into which the solid instance would fit.
965   //                                              980   //
966   G4ThreeVector pmin,pmax;                     << 981   G4double maxDim;
967   BoundingLimits(pmin,pmax);                   << 982   maxDim = xSemiAxis > ySemiAxis ? xSemiAxis : ySemiAxis;
968   return { pmin.x(), pmax.x(), pmin.y(), pmax. << 983   maxDim = maxDim > zTopCut ? maxDim : zTopCut;
                                                   >> 984   
                                                   >> 985   return G4VisExtent (-maxDim, maxDim,
                                                   >> 986                       -maxDim, maxDim,
                                                   >> 987                       -maxDim, maxDim);
                                                   >> 988 }
                                                   >> 989 
                                                   >> 990 G4NURBS* G4EllipticalCone::CreateNURBS () const
                                                   >> 991 {
                                                   >> 992   // Box for now!!!
                                                   >> 993   //
                                                   >> 994   return new G4NURBSbox(xSemiAxis, ySemiAxis,zheight);
969 }                                                 995 }
970                                                   996 
971 G4Polyhedron* G4EllipticalCone::CreatePolyhedr    997 G4Polyhedron* G4EllipticalCone::CreatePolyhedron () const
972 {                                                 998 {
973   return new G4PolyhedronEllipticalCone(xSemiA    999   return new G4PolyhedronEllipticalCone(xSemiAxis, ySemiAxis, zheight, zTopCut);
974 }                                                 1000 }
975                                                   1001 
976 G4Polyhedron* G4EllipticalCone::GetPolyhedron     1002 G4Polyhedron* G4EllipticalCone::GetPolyhedron () const
977 {                                                 1003 {
978   if ( (fpPolyhedron == nullptr)               << 1004   if ( (!fpPolyhedron)
979     || fRebuildPolyhedron                      << 
980     || (fpPolyhedron->GetNumberOfRotationSteps    1005     || (fpPolyhedron->GetNumberOfRotationStepsAtTimeOfCreation() !=
981         fpPolyhedron->GetNumberOfRotationSteps    1006         fpPolyhedron->GetNumberOfRotationSteps()) )
982     {                                             1007     {
983       G4AutoLock l(&polyhedronMutex);          << 
984       delete fpPolyhedron;                        1008       delete fpPolyhedron;
985       fpPolyhedron = CreatePolyhedron();          1009       fpPolyhedron = CreatePolyhedron();
986       fRebuildPolyhedron = false;              << 
987       l.unlock();                              << 
988     }                                             1010     }
989   return fpPolyhedron;                            1011   return fpPolyhedron;
990 }                                                 1012 }
991                                                << 
992 #endif // !defined(G4GEOM_USE_UELLIPTICALCONE) << 
993                                                   1013