Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/geometry/solids/specific/src/G4PolyconeSide.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/G4PolyconeSide.cc (Version 11.3.0) and /geometry/solids/specific/src/G4PolyconeSide.cc (Version 10.1)


  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 // Implementation of G4PolyconeSide, the face  << 
 27 // one conical side of a polycone              << 
 28 //                                                 26 //
 29 // Author: David C. Williams (davidw@scipp.ucs <<  27 // $Id: G4PolyconeSide.cc 70648 2013-06-03 15:15:16Z gcosmo $
                                                   >>  28 //
                                                   >>  29 // 
                                                   >>  30 // --------------------------------------------------------------------
                                                   >>  31 // GEANT 4 class source file
                                                   >>  32 //
                                                   >>  33 //
                                                   >>  34 // G4PolyconeSide.cc
                                                   >>  35 //
                                                   >>  36 // Implementation of the face representing one conical side of a polycone
                                                   >>  37 //
 30 // -------------------------------------------     38 // --------------------------------------------------------------------
 31                                                    39 
 32 #include "G4PolyconeSide.hh"                       40 #include "G4PolyconeSide.hh"
 33 #include "meshdefs.hh"                             41 #include "meshdefs.hh"
 34 #include "G4PhysicalConstants.hh"                  42 #include "G4PhysicalConstants.hh"
 35 #include "G4IntersectingCone.hh"                   43 #include "G4IntersectingCone.hh"
 36 #include "G4ClippablePolygon.hh"                   44 #include "G4ClippablePolygon.hh"
 37 #include "G4AffineTransform.hh"                    45 #include "G4AffineTransform.hh"
 38 #include "G4SolidExtentList.hh"                    46 #include "G4SolidExtentList.hh"
 39 #include "G4GeometryTolerance.hh"                  47 #include "G4GeometryTolerance.hh"
 40                                                    48 
 41 #include "Randomize.hh"                            49 #include "Randomize.hh"
 42                                                    50 
 43 // This new field helps to use the class G4PlS <<  51 // This static member is thread local. For each thread, it points to the
                                                   >>  52 // array of G4PlSideData instances.
 44 //                                                 53 //
 45 G4PlSideManager G4PolyconeSide::subInstanceMan <<  54 template <class G4PlSideData> G4ThreadLocal
                                                   >>  55          G4PlSideData* G4GeomSplitter<G4PlSideData>::offset = 0;
 46                                                    56 
 47 // This macro changes the references to fields <<  57 // This new field helps to use the class G4PlSideManager.
 48 // in the class G4PlSideData.                  << 
 49 //                                                 58 //
 50 #define G4MT_pcphix ((subInstanceManager.offse <<  59 G4PlSideManager G4PolyconeSide::subInstanceManager;
 51 #define G4MT_pcphiy ((subInstanceManager.offse << 
 52 #define G4MT_pcphiz ((subInstanceManager.offse << 
 53 #define G4MT_pcphik ((subInstanceManager.offse << 
 54                                                    60 
 55 // Returns the private data instance manager.      61 // Returns the private data instance manager.
 56 //                                                 62 //
 57 const G4PlSideManager& G4PolyconeSide::GetSubI     63 const G4PlSideManager& G4PolyconeSide::GetSubInstanceManager()
 58 {                                                  64 {
 59   return subInstanceManager;                       65   return subInstanceManager;
 60 }                                                  66 }
 61                                                    67 
                                                   >>  68 //
 62 // Constructor                                     69 // Constructor
 63 //                                                 70 //
 64 // Values for r1,z1 and r2,z2 should be specif     71 // Values for r1,z1 and r2,z2 should be specified in clockwise
 65 // order in (r,z).                                 72 // order in (r,z).
 66 //                                                 73 //
 67 G4PolyconeSide::G4PolyconeSide( const G4Polyco <<  74 G4PolyconeSide::G4PolyconeSide( const G4PolyconeSideRZ *prevRZ,
 68                                 const G4Polyco <<  75                                 const G4PolyconeSideRZ *tail,
 69                                 const G4Polyco <<  76                                 const G4PolyconeSideRZ *head,
 70                                 const G4Polyco <<  77                                 const G4PolyconeSideRZ *nextRZ,
 71                                       G4double     78                                       G4double thePhiStart, 
 72                                       G4double     79                                       G4double theDeltaPhi, 
 73                                       G4bool t     80                                       G4bool thePhiIsOpen, 
 74                                       G4bool i     81                                       G4bool isAllBehind )
                                                   >>  82   : ncorners(0), corners(0)
 75 {                                                  83 {
                                                   >>  84 
 76   instanceID = subInstanceManager.CreateSubIns     85   instanceID = subInstanceManager.CreateSubInstance();
 77                                                    86 
 78   kCarTolerance = G4GeometryTolerance::GetInst     87   kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
 79   G4MT_pcphix = 0.0; G4MT_pcphiy = 0.0; G4MT_p <<  88   fSurfaceArea = 0.0;
                                                   >>  89   G4MT_pcphi.first = G4ThreeVector(0,0,0);
                                                   >>  90   G4MT_pcphi.second= 0.0;
 80                                                    91 
 81   //                                               92   //
 82   // Record values                                 93   // Record values
 83   //                                               94   //
 84   r[0] = tail->r; z[0] = tail->z;                  95   r[0] = tail->r; z[0] = tail->z;
 85   r[1] = head->r; z[1] = head->z;                  96   r[1] = head->r; z[1] = head->z;
 86                                                    97   
 87   phiIsOpen = thePhiIsOpen;                        98   phiIsOpen = thePhiIsOpen;
 88   if (phiIsOpen)                                   99   if (phiIsOpen)
 89   {                                               100   {
 90     deltaPhi = theDeltaPhi;                       101     deltaPhi = theDeltaPhi;
 91     startPhi = thePhiStart;                       102     startPhi = thePhiStart;
 92                                                   103 
 93     //                                            104     //
 94     // Set phi values to our conventions          105     // Set phi values to our conventions
 95     //                                            106     //
 96     while (deltaPhi < 0.0)    // Loop checking << 107     while (deltaPhi < 0.0) deltaPhi += twopi;
 97      deltaPhi += twopi;                        << 108     while (startPhi < 0.0) startPhi += twopi;
 98     while (startPhi < 0.0)    // Loop checking << 
 99      startPhi += twopi;                        << 
100                                                   109     
101     //                                            110     //
102     // Calculate corner coordinates               111     // Calculate corner coordinates
103     //                                            112     //
104     ncorners = 4;                                 113     ncorners = 4;
105     corners = new G4ThreeVector[ncorners];        114     corners = new G4ThreeVector[ncorners];
106                                                   115     
107     corners[0] = G4ThreeVector( tail->r*std::c    116     corners[0] = G4ThreeVector( tail->r*std::cos(startPhi),
108                                 tail->r*std::s    117                                 tail->r*std::sin(startPhi), tail->z );
109     corners[1] = G4ThreeVector( head->r*std::c    118     corners[1] = G4ThreeVector( head->r*std::cos(startPhi),
110                                 head->r*std::s    119                                 head->r*std::sin(startPhi), head->z );
111     corners[2] = G4ThreeVector( tail->r*std::c    120     corners[2] = G4ThreeVector( tail->r*std::cos(startPhi+deltaPhi),
112                                 tail->r*std::s    121                                 tail->r*std::sin(startPhi+deltaPhi), tail->z );
113     corners[3] = G4ThreeVector( head->r*std::c    122     corners[3] = G4ThreeVector( head->r*std::cos(startPhi+deltaPhi),
114                                 head->r*std::s    123                                 head->r*std::sin(startPhi+deltaPhi), head->z );
115   }                                               124   }
116   else                                            125   else
117   {                                               126   {
118     deltaPhi = twopi;                             127     deltaPhi = twopi;
119     startPhi = 0.0;                               128     startPhi = 0.0;
120   }                                               129   }
121                                                   130   
122   allBehind = isAllBehind;                        131   allBehind = isAllBehind;
123                                                   132     
124   //                                              133   //
125   // Make our intersecting cone                   134   // Make our intersecting cone
126   //                                              135   //
127   cone = new G4IntersectingCone( r, z );          136   cone = new G4IntersectingCone( r, z );
128                                                   137   
129   //                                              138   //
130   // Calculate vectors in r,z space               139   // Calculate vectors in r,z space
131   //                                              140   //
132   rS = r[1]-r[0]; zS = z[1]-z[0];                 141   rS = r[1]-r[0]; zS = z[1]-z[0];
133   length = std::sqrt( rS*rS + zS*zS);             142   length = std::sqrt( rS*rS + zS*zS);
134   rS /= length; zS /= length;                     143   rS /= length; zS /= length;
135                                                   144   
136   rNorm = +zS;                                    145   rNorm = +zS;
137   zNorm = -rS;                                    146   zNorm = -rS;
138                                                   147   
139   G4double lAdj;                                  148   G4double lAdj;
140                                                   149   
141   prevRS = r[0]-prevRZ->r;                        150   prevRS = r[0]-prevRZ->r;
142   prevZS = z[0]-prevRZ->z;                        151   prevZS = z[0]-prevRZ->z;
143   lAdj = std::sqrt( prevRS*prevRS + prevZS*pre    152   lAdj = std::sqrt( prevRS*prevRS + prevZS*prevZS );
144   prevRS /= lAdj;                                 153   prevRS /= lAdj;
145   prevZS /= lAdj;                                 154   prevZS /= lAdj;
146                                                   155 
147   rNormEdge[0] = rNorm + prevZS;                  156   rNormEdge[0] = rNorm + prevZS;
148   zNormEdge[0] = zNorm - prevRS;                  157   zNormEdge[0] = zNorm - prevRS;
149   lAdj = std::sqrt( rNormEdge[0]*rNormEdge[0]     158   lAdj = std::sqrt( rNormEdge[0]*rNormEdge[0] + zNormEdge[0]*zNormEdge[0] );
150   rNormEdge[0] /= lAdj;                           159   rNormEdge[0] /= lAdj;
151   zNormEdge[0] /= lAdj;                           160   zNormEdge[0] /= lAdj;
152                                                   161 
153   nextRS = nextRZ->r-r[1];                        162   nextRS = nextRZ->r-r[1];
154   nextZS = nextRZ->z-z[1];                        163   nextZS = nextRZ->z-z[1];
155   lAdj = std::sqrt( nextRS*nextRS + nextZS*nex    164   lAdj = std::sqrt( nextRS*nextRS + nextZS*nextZS );
156   nextRS /= lAdj;                                 165   nextRS /= lAdj;
157   nextZS /= lAdj;                                 166   nextZS /= lAdj;
158                                                   167 
159   rNormEdge[1] = rNorm + nextZS;                  168   rNormEdge[1] = rNorm + nextZS;
160   zNormEdge[1] = zNorm - nextRS;                  169   zNormEdge[1] = zNorm - nextRS;
161   lAdj = std::sqrt( rNormEdge[1]*rNormEdge[1]     170   lAdj = std::sqrt( rNormEdge[1]*rNormEdge[1] + zNormEdge[1]*zNormEdge[1] );
162   rNormEdge[1] /= lAdj;                           171   rNormEdge[1] /= lAdj;
163   zNormEdge[1] /= lAdj;                           172   zNormEdge[1] /= lAdj;
164 }                                                 173 }
165                                                   174 
                                                   >> 175 
                                                   >> 176 //
166 // Fake default constructor - sets only member    177 // Fake default constructor - sets only member data and allocates memory
167 //                            for usage restri    178 //                            for usage restricted to object persistency.
168 //                                                179 //
169 G4PolyconeSide::G4PolyconeSide( __void__& )       180 G4PolyconeSide::G4PolyconeSide( __void__& )
170   : startPhi(0.), deltaPhi(0.),                << 181   : startPhi(0.), deltaPhi(0.), phiIsOpen(false), allBehind(false),
171     rNorm(0.), zNorm(0.), rS(0.), zS(0.), leng << 182     cone(0), rNorm(0.), zNorm(0.), rS(0.), zS(0.), length(0.),
172     prevRS(0.), prevZS(0.), nextRS(0.), nextZS << 183     prevRS(0.), prevZS(0.), nextRS(0.), nextZS(0.), ncorners(0), corners(0),
173     kCarTolerance(0.), instanceID(0)           << 184     kCarTolerance(0.), fSurfaceArea(0.), instanceID(0)
174 {                                                 185 {
175   r[0] = r[1] = 0.;                               186   r[0] = r[1] = 0.;
176   z[0] = z[1] = 0.;                               187   z[0] = z[1] = 0.;
177   rNormEdge[0]= rNormEdge[1] = 0.;                188   rNormEdge[0]= rNormEdge[1] = 0.;
178   zNormEdge[0]= zNormEdge[1] = 0.;                189   zNormEdge[0]= zNormEdge[1] = 0.;
179 }                                                 190 }
180                                                   191 
                                                   >> 192 
                                                   >> 193 //
181 // Destructor                                     194 // Destructor
182 //                                                195 //  
183 G4PolyconeSide::~G4PolyconeSide()                 196 G4PolyconeSide::~G4PolyconeSide()
184 {                                                 197 {
185   delete cone;                                    198   delete cone;
186   if (phiIsOpen)  { delete [] corners; }          199   if (phiIsOpen)  { delete [] corners; }
187 }                                                 200 }
188                                                   201 
                                                   >> 202 
                                                   >> 203 //
189 // Copy constructor                               204 // Copy constructor
190 //                                                205 //
191 G4PolyconeSide::G4PolyconeSide( const G4Polyco << 206 G4PolyconeSide::G4PolyconeSide( const G4PolyconeSide &source )
                                                   >> 207   : G4VCSGface(), ncorners(0), corners(0)
192 {                                                 208 {
193   instanceID = subInstanceManager.CreateSubIns    209   instanceID = subInstanceManager.CreateSubInstance();
194                                                   210 
195   CopyStuff( source );                            211   CopyStuff( source );
196 }                                                 212 }
197                                                   213 
                                                   >> 214 
                                                   >> 215 //
198 // Assignment operator                            216 // Assignment operator
199 //                                                217 //
200 G4PolyconeSide& G4PolyconeSide::operator=( con << 218 G4PolyconeSide& G4PolyconeSide::operator=( const G4PolyconeSide &source )
201 {                                                 219 {
202   if (this == &source)  { return *this; }         220   if (this == &source)  { return *this; }
203                                                   221 
204   delete cone;                                    222   delete cone;
205   if (phiIsOpen)  { delete [] corners; }          223   if (phiIsOpen)  { delete [] corners; }
206                                                   224   
207   CopyStuff( source );                            225   CopyStuff( source );
208                                                   226   
209   return *this;                                   227   return *this;
210 }                                                 228 }
211                                                   229 
                                                   >> 230 
                                                   >> 231 //
212 // CopyStuff                                      232 // CopyStuff
213 //                                                233 //
214 void G4PolyconeSide::CopyStuff( const G4Polyco << 234 void G4PolyconeSide::CopyStuff( const G4PolyconeSide &source )
215 {                                                 235 {
216   r[0]    = source.r[0];                          236   r[0]    = source.r[0];
217   r[1]    = source.r[1];                          237   r[1]    = source.r[1];
218   z[0]    = source.z[0];                          238   z[0]    = source.z[0];
219   z[1]    = source.z[1];                          239   z[1]    = source.z[1];
220                                                   240   
221   startPhi  = source.startPhi;                    241   startPhi  = source.startPhi;
222   deltaPhi  = source.deltaPhi;                    242   deltaPhi  = source.deltaPhi;
223   phiIsOpen  = source.phiIsOpen;                  243   phiIsOpen  = source.phiIsOpen;
224   allBehind  = source.allBehind;                  244   allBehind  = source.allBehind;
225                                                   245 
226   kCarTolerance = source.kCarTolerance;           246   kCarTolerance = source.kCarTolerance;
227   fSurfaceArea = source.fSurfaceArea;             247   fSurfaceArea = source.fSurfaceArea;
228                                                   248   
229   cone    = new G4IntersectingCone( *source.co    249   cone    = new G4IntersectingCone( *source.cone );
230                                                   250   
231   rNorm    = source.rNorm;                        251   rNorm    = source.rNorm;
232   zNorm    = source.zNorm;                        252   zNorm    = source.zNorm;
233   rS    = source.rS;                              253   rS    = source.rS;
234   zS    = source.zS;                              254   zS    = source.zS;
235   length    = source.length;                      255   length    = source.length;
236   prevRS    = source.prevRS;                      256   prevRS    = source.prevRS;
237   prevZS    = source.prevZS;                      257   prevZS    = source.prevZS;
238   nextRS    = source.nextRS;                      258   nextRS    = source.nextRS;
239   nextZS    = source.nextZS;                      259   nextZS    = source.nextZS;
240                                                   260   
241   rNormEdge[0]   = source.rNormEdge[0];           261   rNormEdge[0]   = source.rNormEdge[0];
242   rNormEdge[1]  = source.rNormEdge[1];            262   rNormEdge[1]  = source.rNormEdge[1];
243   zNormEdge[0]  = source.zNormEdge[0];            263   zNormEdge[0]  = source.zNormEdge[0];
244   zNormEdge[1]  = source.zNormEdge[1];            264   zNormEdge[1]  = source.zNormEdge[1];
245                                                   265   
246   if (phiIsOpen)                                  266   if (phiIsOpen)
247   {                                               267   {
248     ncorners = 4;                                 268     ncorners = 4;
249     corners = new G4ThreeVector[ncorners];        269     corners = new G4ThreeVector[ncorners];
250                                                   270     
251     corners[0] = source.corners[0];               271     corners[0] = source.corners[0];
252     corners[1] = source.corners[1];               272     corners[1] = source.corners[1];
253     corners[2] = source.corners[2];               273     corners[2] = source.corners[2];
254     corners[3] = source.corners[3];               274     corners[3] = source.corners[3];
255   }                                               275   }
256 }                                                 276 }
257                                                   277 
                                                   >> 278 
                                                   >> 279 //
258 // Intersect                                      280 // Intersect
259 //                                                281 //
260 G4bool G4PolyconeSide::Intersect( const G4Thre << 282 G4bool G4PolyconeSide::Intersect( const G4ThreeVector &p,
261                                   const G4Thre << 283                                   const G4ThreeVector &v,  
262                                         G4bool    284                                         G4bool outgoing,
263                                         G4doub    285                                         G4double surfTolerance,
264                                         G4doub << 286                                         G4double &distance,
265                                         G4doub << 287                                         G4double &distFromSurface,
266                                         G4Thre << 288                                         G4ThreeVector &normal,
267                                         G4bool << 289                                         G4bool &isAllBehind )
268 {                                                 290 {
269   G4double s1=0., s2=0.;                       << 291   G4double s1, s2;
270   G4double normSign = outgoing ? +1 : -1;         292   G4double normSign = outgoing ? +1 : -1;
271                                                   293   
272   isAllBehind = allBehind;                        294   isAllBehind = allBehind;
273                                                   295 
274   //                                              296   //
275   // Check for two possible intersections         297   // Check for two possible intersections
276   //                                              298   //
277   G4int nside = cone->LineHitsCone( p, v, &s1,    299   G4int nside = cone->LineHitsCone( p, v, &s1, &s2 );
278   if (nside == 0) return false;                   300   if (nside == 0) return false;
279                                                   301     
280   //                                              302   //
281   // Check the first side first, since it is (    303   // Check the first side first, since it is (supposed to be) closest
282   //                                              304   //
283   G4ThreeVector hit = p + s1*v;                   305   G4ThreeVector hit = p + s1*v;
284                                                   306   
285   if (PointOnCone( hit, normSign, p, v, normal    307   if (PointOnCone( hit, normSign, p, v, normal ))
286   {                                               308   {
287     //                                            309     //
288     // Good intersection! What about the norma    310     // Good intersection! What about the normal? 
289     //                                            311     //
290     if (normSign*v.dot(normal) > 0)               312     if (normSign*v.dot(normal) > 0)
291     {                                             313     {
292       //                                          314       //
293       // We have a valid intersection, but it     315       // We have a valid intersection, but it could very easily
294       // be behind the point. To decide if we     316       // be behind the point. To decide if we tolerate this,
295       // we have to see if the point p is on t    317       // we have to see if the point p is on the surface near
296       // the intersecting point.                  318       // the intersecting point.
297       //                                          319       //
298       // What does it mean exactly for the poi    320       // What does it mean exactly for the point p to be "near"
299       // the intersection? It means that if we    321       // the intersection? It means that if we draw a line from
300       // p to the hit, the line remains entire    322       // p to the hit, the line remains entirely within the
301       // tolerance bounds of the cone. To test    323       // tolerance bounds of the cone. To test this, we can
302       // ask if the normal is correct near p.     324       // ask if the normal is correct near p.
303       //                                          325       //
304       G4double pr = p.perp();                     326       G4double pr = p.perp();
305       if (pr < DBL_MIN) pr = DBL_MIN;             327       if (pr < DBL_MIN) pr = DBL_MIN;
306       G4ThreeVector pNormal( rNorm*p.x()/pr, r    328       G4ThreeVector pNormal( rNorm*p.x()/pr, rNorm*p.y()/pr, zNorm );
307       if (normSign*v.dot(pNormal) > 0)            329       if (normSign*v.dot(pNormal) > 0)
308       {                                           330       {
309         //                                        331         //
310         // p and intersection in same hemisphe    332         // p and intersection in same hemisphere
311         //                                        333         //
312         G4double distOutside2;                    334         G4double distOutside2;
313         distFromSurface = -normSign*DistanceAw    335         distFromSurface = -normSign*DistanceAway( p, false, distOutside2 );
314         if (distOutside2 < surfTolerance*surfT    336         if (distOutside2 < surfTolerance*surfTolerance)
315         {                                         337         {
316           if (distFromSurface > -surfTolerance    338           if (distFromSurface > -surfTolerance)
317           {                                       339           {
318             //                                    340             //
319             // We are just inside or away from    341             // We are just inside or away from the
320             // surface. Accept *any* value of     342             // surface. Accept *any* value of distance.
321             //                                    343             //
322             distance = s1;                        344             distance = s1;
323             return true;                          345             return true;
324           }                                       346           }
325         }                                         347         }
326       }                                           348       }
327       else                                        349       else 
328         distFromSurface = s1;                     350         distFromSurface = s1;
329                                                   351       
330       //                                          352       //
331       // Accept positive distances                353       // Accept positive distances
332       //                                          354       //
333       if (s1 > 0)                                 355       if (s1 > 0)
334       {                                           356       {
335         distance = s1;                            357         distance = s1;
336         return true;                              358         return true;
337       }                                           359       }
338     }                                             360     }
339   }                                               361   }  
340                                                   362   
341   if (nside==1) return false;                     363   if (nside==1) return false;
342                                                   364   
343   //                                              365   //
344   // Well, try the second hit                     366   // Well, try the second hit
345   //                                              367   //  
346   hit = p + s2*v;                                 368   hit = p + s2*v;
347                                                   369   
348   if (PointOnCone( hit, normSign, p, v, normal    370   if (PointOnCone( hit, normSign, p, v, normal ))
349   {                                               371   {
350     //                                            372     //
351     // Good intersection! What about the norma    373     // Good intersection! What about the normal? 
352     //                                            374     //
353     if (normSign*v.dot(normal) > 0)               375     if (normSign*v.dot(normal) > 0)
354     {                                             376     {
355       G4double pr = p.perp();                     377       G4double pr = p.perp();
356       if (pr < DBL_MIN) pr = DBL_MIN;             378       if (pr < DBL_MIN) pr = DBL_MIN;
357       G4ThreeVector pNormal( rNorm*p.x()/pr, r    379       G4ThreeVector pNormal( rNorm*p.x()/pr, rNorm*p.y()/pr, zNorm );
358       if (normSign*v.dot(pNormal) > 0)            380       if (normSign*v.dot(pNormal) > 0)
359       {                                           381       {
360         G4double distOutside2;                    382         G4double distOutside2;
361         distFromSurface = -normSign*DistanceAw    383         distFromSurface = -normSign*DistanceAway( p, false, distOutside2 );
362         if (distOutside2 < surfTolerance*surfT    384         if (distOutside2 < surfTolerance*surfTolerance)
363         {                                         385         {
364           if (distFromSurface > -surfTolerance    386           if (distFromSurface > -surfTolerance)
365           {                                       387           {
366             distance = s2;                        388             distance = s2;
367             return true;                          389             return true;
368           }                                       390           }
369         }                                         391         }
370       }                                           392       }
371       else                                        393       else 
372         distFromSurface = s2;                     394         distFromSurface = s2;
373                                                   395       
374       if (s2 > 0)                                 396       if (s2 > 0)
375       {                                           397       {
376         distance = s2;                            398         distance = s2;
377         return true;                              399         return true;
378       }                                           400       }
379     }                                             401     }
380   }                                               402   }  
381                                                   403 
382   //                                              404   //
383   // Better luck next time                        405   // Better luck next time
384   //                                              406   //
385   return false;                                   407   return false;
386 }                                                 408 }
387                                                   409 
388 // Distance                                    << 410 
389 //                                             << 411 G4double G4PolyconeSide::Distance( const G4ThreeVector &p, G4bool outgoing )
390 G4double G4PolyconeSide::Distance( const G4Thr << 
391 {                                                 412 {
392   G4double normSign = outgoing ? -1 : +1;         413   G4double normSign = outgoing ? -1 : +1;
393   G4double distFrom, distOut2;                    414   G4double distFrom, distOut2;
394                                                   415   
395   //                                              416   //
396   // We have two tries for each hemisphere. Tr    417   // We have two tries for each hemisphere. Try the closest first.
397   //                                              418   //
398   distFrom = normSign*DistanceAway( p, false,     419   distFrom = normSign*DistanceAway( p, false, distOut2 );
399   if (distFrom > -0.5*kCarTolerance )             420   if (distFrom > -0.5*kCarTolerance )
400   {                                               421   {
401     //                                            422     //
402     // Good answer                                423     // Good answer
403     //                                            424     //
404     if (distOut2 > 0)                             425     if (distOut2 > 0) 
405       return std::sqrt( distFrom*distFrom + di    426       return std::sqrt( distFrom*distFrom + distOut2 );
406     else                                          427     else 
407       return std::fabs(distFrom);                 428       return std::fabs(distFrom);
408   }                                               429   }
409                                                   430   
410   //                                              431   //
411   // Try second side.                             432   // Try second side. 
412   //                                              433   //
413   distFrom = normSign*DistanceAway( p,  true,     434   distFrom = normSign*DistanceAway( p,  true, distOut2 );
414   if (distFrom > -0.5*kCarTolerance)              435   if (distFrom > -0.5*kCarTolerance)
415   {                                               436   {
416                                                   437 
417     if (distOut2 > 0)                             438     if (distOut2 > 0) 
418       return std::sqrt( distFrom*distFrom + di    439       return std::sqrt( distFrom*distFrom + distOut2 );
419     else                                          440     else
420       return std::fabs(distFrom);                 441       return std::fabs(distFrom);
421   }                                               442   }
422                                                   443   
423   return kInfinity;                               444   return kInfinity;
424 }                                                 445 }
425                                                   446 
                                                   >> 447 
                                                   >> 448 //
426 // Inside                                         449 // Inside
427 //                                                450 //
428 EInside G4PolyconeSide::Inside( const G4ThreeV << 451 EInside G4PolyconeSide::Inside( const G4ThreeVector &p,
429                                       G4double    452                                       G4double tolerance, 
430                                       G4double << 453                                       G4double *bestDistance )
431 {                                                 454 {
432   G4double distFrom, distOut2, dist2;          << 455   //
433   G4double edgeRZnorm;                         << 456   // Check both sides
                                                   >> 457   //
                                                   >> 458   G4double distFrom[2], distOut2[2], dist2[2];
                                                   >> 459   G4double edgeRZnorm[2];
434                                                   460      
435   distFrom =  DistanceAway( p, distOut2, &edge << 461   distFrom[0] =  DistanceAway( p, false, distOut2[0], edgeRZnorm   );
436   dist2 = distFrom*distFrom + distOut2;        << 462   distFrom[1] =  DistanceAway( p,  true, distOut2[1], edgeRZnorm+1 );
437                                                << 463   
438   *bestDistance = std::sqrt( dist2);           << 464   dist2[0] = distFrom[0]*distFrom[0] + distOut2[0];
                                                   >> 465   dist2[1] = distFrom[1]*distFrom[1] + distOut2[1];
                                                   >> 466   
                                                   >> 467   //
                                                   >> 468   // Who's closest?
                                                   >> 469   //
                                                   >> 470   G4int i = std::fabs(dist2[0]) < std::fabs(dist2[1]) ? 0 : 1;
                                                   >> 471   
                                                   >> 472   *bestDistance = std::sqrt( dist2[i] );
439                                                   473   
                                                   >> 474   //
440   // Okay then, inside or out?                    475   // Okay then, inside or out?
441   //                                              476   //
442   if ( (std::fabs(edgeRZnorm) < tolerance)     << 477   if ( (std::fabs(edgeRZnorm[i]) < tolerance)
443     && (distOut2< tolerance*tolerance) )       << 478     && (distOut2[i] < tolerance*tolerance) )
444     return kSurface;                              479     return kSurface;
445   else if (edgeRZnorm < 0)                     << 480   else if (edgeRZnorm[i] < 0)
446     return kInside;                               481     return kInside;
447   else                                            482   else
448     return kOutside;                              483     return kOutside;
449 }                                                 484 }
450                                                   485 
                                                   >> 486 
                                                   >> 487 //
451 // Normal                                         488 // Normal
452 //                                                489 //
453 G4ThreeVector G4PolyconeSide::Normal( const G4 << 490 G4ThreeVector G4PolyconeSide::Normal( const G4ThreeVector &p,
454                                             G4 << 491                                             G4double *bestDistance )
455 {                                                 492 {
456   if (p == G4ThreeVector(0.,0.,0.))  { return     493   if (p == G4ThreeVector(0.,0.,0.))  { return p; }
457                                                   494 
458   G4double dFrom, dOut2;                          495   G4double dFrom, dOut2;
459                                                   496   
460   dFrom = DistanceAway( p, false, dOut2 );        497   dFrom = DistanceAway( p, false, dOut2 );
461                                                   498   
462   *bestDistance = std::sqrt( dFrom*dFrom + dOu    499   *bestDistance = std::sqrt( dFrom*dFrom + dOut2 );
463                                                   500   
464   G4double rds = p.perp();                        501   G4double rds = p.perp();
465   if (rds!=0.) { return {rNorm*p.x()/rds,rNorm << 502   if (rds!=0.) { return G4ThreeVector(rNorm*p.x()/rds,rNorm*p.y()/rds,zNorm); }
466   return G4ThreeVector( 0.,0., zNorm ).unit();    503   return G4ThreeVector( 0.,0., zNorm ).unit();
467 }                                                 504 }
468                                                   505 
                                                   >> 506 
                                                   >> 507 //
469 // Extent                                         508 // Extent
470 //                                                509 //
471 G4double G4PolyconeSide::Extent( const G4Three    510 G4double G4PolyconeSide::Extent( const G4ThreeVector axis )
472 {                                                 511 {
473   if (axis.perp2() < DBL_MIN)                     512   if (axis.perp2() < DBL_MIN)
474   {                                               513   {
475     //                                            514     //
476     // Special case                               515     // Special case
477     //                                            516     //
478     return axis.z() < 0 ? -cone->ZLo() : cone-    517     return axis.z() < 0 ? -cone->ZLo() : cone->ZHi();
479   }                                               518   }
480                                                   519 
481   //                                              520   //
482   // Is the axis pointing inside our phi gap?     521   // Is the axis pointing inside our phi gap?
483   //                                              522   //
484   if (phiIsOpen)                                  523   if (phiIsOpen)
485   {                                               524   {
486     G4double phi = GetPhi(axis);                  525     G4double phi = GetPhi(axis);
487     while( phi < startPhi )    // Loop checkin << 526     while( phi < startPhi ) phi += twopi;
488       phi += twopi;                            << 
489                                                   527     
490     if (phi > deltaPhi+startPhi)                  528     if (phi > deltaPhi+startPhi)
491     {                                             529     {
492       //                                          530       //
493       // Yeah, looks so. Make four three vecto    531       // Yeah, looks so. Make four three vectors defining the phi
494       // opening                                  532       // opening
495       //                                          533       //
496       G4double cosP = std::cos(startPhi), sinP    534       G4double cosP = std::cos(startPhi), sinP = std::sin(startPhi);
497       G4ThreeVector a( r[0]*cosP, r[0]*sinP, z    535       G4ThreeVector a( r[0]*cosP, r[0]*sinP, z[0] );
498       G4ThreeVector b( r[1]*cosP, r[1]*sinP, z    536       G4ThreeVector b( r[1]*cosP, r[1]*sinP, z[1] );
499       cosP = std::cos(startPhi+deltaPhi); sinP    537       cosP = std::cos(startPhi+deltaPhi); sinP = std::sin(startPhi+deltaPhi);
500       G4ThreeVector c( r[0]*cosP, r[0]*sinP, z    538       G4ThreeVector c( r[0]*cosP, r[0]*sinP, z[0] );
501       G4ThreeVector d( r[1]*cosP, r[1]*sinP, z    539       G4ThreeVector d( r[1]*cosP, r[1]*sinP, z[1] );
502                                                   540       
503       G4double ad = axis.dot(a),                  541       G4double ad = axis.dot(a),
504                bd = axis.dot(b),               << 542          bd = axis.dot(b),
505                cd = axis.dot(c),               << 543          cd = axis.dot(c),
506                dd = axis.dot(d);               << 544          dd = axis.dot(d);
507                                                   545       
508       if (bd > ad) ad = bd;                       546       if (bd > ad) ad = bd;
509       if (cd > ad) ad = cd;                       547       if (cd > ad) ad = cd;
510       if (dd > ad) ad = dd;                       548       if (dd > ad) ad = dd;
511                                                   549       
512       return ad;                                  550       return ad;
513     }                                             551     }
514   }                                               552   }
515                                                   553 
516   //                                              554   //
517   // Check either end                             555   // Check either end
518   //                                              556   //
519   G4double aPerp = axis.perp();                   557   G4double aPerp = axis.perp();
520                                                   558   
521   G4double a = aPerp*r[0] + axis.z()*z[0];        559   G4double a = aPerp*r[0] + axis.z()*z[0];
522   G4double b = aPerp*r[1] + axis.z()*z[1];        560   G4double b = aPerp*r[1] + axis.z()*z[1];
523                                                   561   
524   if (b > a) a = b;                               562   if (b > a) a = b;
525                                                   563   
526   return a;                                       564   return a;
527 }                                                 565 }
528                                                   566 
                                                   >> 567 
                                                   >> 568 
                                                   >> 569 //
529 // CalculateExtent                                570 // CalculateExtent
530 //                                                571 //
531 // See notes in G4VCSGface                        572 // See notes in G4VCSGface
532 //                                                573 //
533 void G4PolyconeSide::CalculateExtent( const EA    574 void G4PolyconeSide::CalculateExtent( const EAxis axis, 
534                                       const G4 << 575                                       const G4VoxelLimits &voxelLimit,
535                                       const G4 << 576                                       const G4AffineTransform &transform,
536                                             G4 << 577                                             G4SolidExtentList &extentList )
537 {                                                 578 {
538   G4ClippablePolygon polygon;                     579   G4ClippablePolygon polygon;
539                                                   580   
540   //                                              581   //
541   // Here we will approximate (ala G4Cons) and    582   // Here we will approximate (ala G4Cons) and divide our conical section
542   // into segments, like G4Polyhedra. When doi    583   // into segments, like G4Polyhedra. When doing so, the radius
543   // is extented far enough such that the segm    584   // is extented far enough such that the segments always lie
544   // just outside the surface of the conical s    585   // just outside the surface of the conical section we are
545   // approximating.                               586   // approximating.
546   //                                              587   //
547                                                   588   
548   //                                              589   //
549   // Choose phi size of our segment(s) based o    590   // Choose phi size of our segment(s) based on constants as
550   // defined in meshdefs.hh                       591   // defined in meshdefs.hh
551   //                                              592   //
552   G4int numPhi = (G4int)(deltaPhi/kMeshAngleDe    593   G4int numPhi = (G4int)(deltaPhi/kMeshAngleDefault) + 1;
553   if (numPhi < kMinMeshSections)                  594   if (numPhi < kMinMeshSections) 
554     numPhi = kMinMeshSections;                    595     numPhi = kMinMeshSections;
555   else if (numPhi > kMaxMeshSections)             596   else if (numPhi > kMaxMeshSections)
556     numPhi = kMaxMeshSections;                    597     numPhi = kMaxMeshSections;
557                                                   598     
558   G4double sigPhi = deltaPhi/numPhi;              599   G4double sigPhi = deltaPhi/numPhi;
559                                                   600   
560   //                                              601   //
561   // Determine radius factor to keep segments     602   // Determine radius factor to keep segments outside
562   //                                              603   //
563   G4double rFudge = 1.0/std::cos(0.5*sigPhi);     604   G4double rFudge = 1.0/std::cos(0.5*sigPhi);
564                                                   605   
565   //                                              606   //
566   // Decide which radius to use on each end of    607   // Decide which radius to use on each end of the side,
567   // and whether a transition mesh is required    608   // and whether a transition mesh is required
568   //                                              609   //
569   // {r0,z0}  - Beginning of this side            610   // {r0,z0}  - Beginning of this side
570   // {r1,z1}  - Ending of this side               611   // {r1,z1}  - Ending of this side
571   // {r2,z0}  - Beginning of transition piece     612   // {r2,z0}  - Beginning of transition piece connecting previous
572   //            side (and ends at beginning of    613   //            side (and ends at beginning of this side)
573   //                                              614   //
574   // So, order is 2 --> 0 --> 1.                  615   // So, order is 2 --> 0 --> 1.
575   //                    -------                   616   //                    -------
576   //                                              617   //
577   // r2 < 0 indicates that no transition piece    618   // r2 < 0 indicates that no transition piece is required
578   //                                              619   //
579   G4double r0, r1, r2, z0, z1;                    620   G4double r0, r1, r2, z0, z1;
580                                                   621   
581   r2 = -1;  // By default: no transition piece    622   r2 = -1;  // By default: no transition piece
582                                                   623   
583   if (rNorm < -DBL_MIN)                           624   if (rNorm < -DBL_MIN)
584   {                                               625   {
585     //                                            626     //
586     // This side faces *inward*, and so our me    627     // This side faces *inward*, and so our mesh has
587     // the same radius                            628     // the same radius
588     //                                            629     //
589     r1 = r[1];                                    630     r1 = r[1];
590     z1 = z[1];                                    631     z1 = z[1];
591     z0 = z[0];                                    632     z0 = z[0];
592     r0 = r[0];                                    633     r0 = r[0];
593                                                   634     
594     r2 = -1;                                      635     r2 = -1;
595                                                   636     
596     if (prevZS > DBL_MIN)                         637     if (prevZS > DBL_MIN)
597     {                                             638     {
598       //                                          639       //
599       // The previous side is facing outwards     640       // The previous side is facing outwards
600       //                                          641       //
601       if ( prevRS*zS - prevZS*rS > 0 )            642       if ( prevRS*zS - prevZS*rS > 0 )
602       {                                           643       {
603         //                                        644         //
604         // Transition was convex: build transi    645         // Transition was convex: build transition piece
605         //                                        646         //
606         if (r[0] > DBL_MIN) r2 = r[0]*rFudge;     647         if (r[0] > DBL_MIN) r2 = r[0]*rFudge;
607       }                                           648       }
608       else                                        649       else
609       {                                           650       {
610         //                                        651         //
611         // Transition was concave: short this     652         // Transition was concave: short this side
612         //                                        653         //
613         FindLineIntersect( z0, r0, zS, rS,        654         FindLineIntersect( z0, r0, zS, rS,
614                            z0, r0*rFudge, prev    655                            z0, r0*rFudge, prevZS, prevRS*rFudge, z0, r0 );
615       }                                           656       }
616     }                                             657     }
617                                                   658     
618     if ( nextZS > DBL_MIN && (rS*nextZS - zS*n    659     if ( nextZS > DBL_MIN && (rS*nextZS - zS*nextRS < 0) )
619     {                                             660     {
620       //                                          661       //
621       // The next side is facing outwards, for    662       // The next side is facing outwards, forming a 
622       // concave transition: short this side      663       // concave transition: short this side
623       //                                          664       //
624       FindLineIntersect( z1, r1, zS, rS,          665       FindLineIntersect( z1, r1, zS, rS,
625                          z1, r1*rFudge, nextZS    666                          z1, r1*rFudge, nextZS, nextRS*rFudge, z1, r1 );
626     }                                             667     }
627   }                                               668   }
628   else if (rNorm > DBL_MIN)                       669   else if (rNorm > DBL_MIN)
629   {                                               670   {
630     //                                            671     //
631     // This side faces *outward* and is given     672     // This side faces *outward* and is given a boost to
632     // it radius                                  673     // it radius
633     //                                            674     //
634     r0 = r[0]*rFudge;                             675     r0 = r[0]*rFudge;
635     z0 = z[0];                                    676     z0 = z[0];
636     r1 = r[1]*rFudge;                             677     r1 = r[1]*rFudge;
637     z1 = z[1];                                    678     z1 = z[1];
638                                                   679     
639     if (prevZS < -DBL_MIN)                        680     if (prevZS < -DBL_MIN)
640     {                                             681     {
641       //                                          682       //
642       // The previous side is facing inwards      683       // The previous side is facing inwards
643       //                                          684       //
644       if ( prevRS*zS - prevZS*rS > 0 )            685       if ( prevRS*zS - prevZS*rS > 0 )
645       {                                           686       {
646         //                                        687         //
647         // Transition was convex: build transi    688         // Transition was convex: build transition piece
648         //                                        689         //
649         if (r[0] > DBL_MIN) r2 = r[0];            690         if (r[0] > DBL_MIN) r2 = r[0];
650       }                                           691       }
651       else                                        692       else
652       {                                           693       {
653         //                                        694         //
654         // Transition was concave: short this     695         // Transition was concave: short this side
655         //                                        696         //
656         FindLineIntersect( z0, r0, zS, rS*rFud    697         FindLineIntersect( z0, r0, zS, rS*rFudge,
657                            z0, r[0], prevZS, p    698                            z0, r[0], prevZS, prevRS, z0, r0 );
658       }                                           699       }
659     }                                             700     }
660                                                   701     
661     if ( nextZS < -DBL_MIN && (rS*nextZS - zS*    702     if ( nextZS < -DBL_MIN && (rS*nextZS - zS*nextRS < 0) )
662     {                                             703     {
663       //                                          704       //
664       // The next side is facing inwards, form    705       // The next side is facing inwards, forming a 
665       // concave transition: short this side      706       // concave transition: short this side
666       //                                          707       //
667       FindLineIntersect( z1, r1, zS, rS*rFudge    708       FindLineIntersect( z1, r1, zS, rS*rFudge,
668                          z1, r[1], nextZS, nex    709                          z1, r[1], nextZS, nextRS, z1, r1 );
669     }                                             710     }
670   }                                               711   }
671   else                                            712   else
672   {                                               713   {
673     //                                            714     //
674     // This side is perpendicular to the z axi    715     // This side is perpendicular to the z axis (is a disk)
675     //                                            716     //
676     // Whether or not r0 needs a rFudge factor    717     // Whether or not r0 needs a rFudge factor depends
677     // on the normal of the previous edge. Sim    718     // on the normal of the previous edge. Similar with r1
678     // and the next edge. No transition piece     719     // and the next edge. No transition piece is required.
679     //                                            720     //
680     r0 = r[0];                                    721     r0 = r[0];
681     r1 = r[1];                                    722     r1 = r[1];
682     z0 = z[0];                                    723     z0 = z[0];
683     z1 = z[1];                                    724     z1 = z[1];
684                                                   725     
685     if (prevZS > DBL_MIN) r0 *= rFudge;           726     if (prevZS > DBL_MIN) r0 *= rFudge;
686     if (nextZS > DBL_MIN) r1 *= rFudge;           727     if (nextZS > DBL_MIN) r1 *= rFudge;
687   }                                               728   }
688                                                   729   
689   //                                              730   //
690   // Loop                                         731   // Loop
691   //                                              732   //
692   G4double phi = startPhi,                        733   G4double phi = startPhi, 
693            cosPhi = std::cos(phi),                734            cosPhi = std::cos(phi), 
694            sinPhi = std::sin(phi);                735            sinPhi = std::sin(phi);
695                                                   736   
696   G4ThreeVector v0( r0*cosPhi, r0*sinPhi, z0 )    737   G4ThreeVector v0( r0*cosPhi, r0*sinPhi, z0 ),
697                     v1( r1*cosPhi, r1*sinPhi,     738                     v1( r1*cosPhi, r1*sinPhi, z1 ),
698   v2, w0, w1, w2;                                 739   v2, w0, w1, w2;
699   transform.ApplyPointTransform( v0 );            740   transform.ApplyPointTransform( v0 );
700   transform.ApplyPointTransform( v1 );            741   transform.ApplyPointTransform( v1 );
701                                                   742   
702   if (r2 >= 0)                                    743   if (r2 >= 0)
703   {                                               744   {
704     v2 = G4ThreeVector( r2*cosPhi, r2*sinPhi,     745     v2 = G4ThreeVector( r2*cosPhi, r2*sinPhi, z0 );
705     transform.ApplyPointTransform( v2 );          746     transform.ApplyPointTransform( v2 );
706   }                                               747   }
707                                                   748 
708   do    // Loop checking, 13.08.2015, G.Cosmo  << 749   do
709   {                                               750   {
710     phi += sigPhi;                                751     phi += sigPhi;
711     if (numPhi == 1) phi = startPhi+deltaPhi;     752     if (numPhi == 1) phi = startPhi+deltaPhi;  // Try to avoid roundoff
712     cosPhi = std::cos(phi),                       753     cosPhi = std::cos(phi), 
713     sinPhi = std::sin(phi);                       754     sinPhi = std::sin(phi);
714                                                   755     
715     w0 = G4ThreeVector( r0*cosPhi, r0*sinPhi,     756     w0 = G4ThreeVector( r0*cosPhi, r0*sinPhi, z0 );
716     w1 = G4ThreeVector( r1*cosPhi, r1*sinPhi,     757     w1 = G4ThreeVector( r1*cosPhi, r1*sinPhi, z1 );
717     transform.ApplyPointTransform( w0 );          758     transform.ApplyPointTransform( w0 );
718     transform.ApplyPointTransform( w1 );          759     transform.ApplyPointTransform( w1 );
719                                                   760     
720     G4ThreeVector deltaV = r0 > r1 ? w0-v0 : w    761     G4ThreeVector deltaV = r0 > r1 ? w0-v0 : w1-v1;
721                                                   762     
722     //                                            763     //
723     // Build polygon, taking special care to k    764     // Build polygon, taking special care to keep the vertices
724     // in order                                   765     // in order
725     //                                            766     //
726     polygon.ClearAllVertices();                   767     polygon.ClearAllVertices();
727                                                   768 
728     polygon.AddVertexInOrder( v0 );               769     polygon.AddVertexInOrder( v0 );
729     polygon.AddVertexInOrder( v1 );               770     polygon.AddVertexInOrder( v1 );
730     polygon.AddVertexInOrder( w1 );               771     polygon.AddVertexInOrder( w1 );
731     polygon.AddVertexInOrder( w0 );               772     polygon.AddVertexInOrder( w0 );
732                                                   773 
733     //                                            774     //
734     // Get extent                                 775     // Get extent
735     //                                            776     //
736     if (polygon.PartialClip( voxelLimit, axis     777     if (polygon.PartialClip( voxelLimit, axis ))
737     {                                             778     {
738       //                                          779       //
739       // Get dot product of normal with target    780       // Get dot product of normal with target axis
740       //                                          781       //
741       polygon.SetNormal( deltaV.cross(v1-v0).u    782       polygon.SetNormal( deltaV.cross(v1-v0).unit() );
742                                                   783       
743       extentList.AddSurface( polygon );           784       extentList.AddSurface( polygon );
744     }                                             785     }
745                                                   786     
746     if (r2 >= 0)                                  787     if (r2 >= 0)
747     {                                             788     {
748       //                                          789       //
749       // Repeat, for transition piece             790       // Repeat, for transition piece
750       //                                          791       //
751       w2 = G4ThreeVector( r2*cosPhi, r2*sinPhi    792       w2 = G4ThreeVector( r2*cosPhi, r2*sinPhi, z0 );
752       transform.ApplyPointTransform( w2 );        793       transform.ApplyPointTransform( w2 );
753                                                   794 
754       polygon.ClearAllVertices();                 795       polygon.ClearAllVertices();
755                                                   796 
756       polygon.AddVertexInOrder( v2 );             797       polygon.AddVertexInOrder( v2 );
757       polygon.AddVertexInOrder( v0 );             798       polygon.AddVertexInOrder( v0 );
758       polygon.AddVertexInOrder( w0 );             799       polygon.AddVertexInOrder( w0 );
759       polygon.AddVertexInOrder( w2 );             800       polygon.AddVertexInOrder( w2 );
760                                                   801 
761       if (polygon.PartialClip( voxelLimit, axi    802       if (polygon.PartialClip( voxelLimit, axis ))
762       {                                           803       {
763         polygon.SetNormal( deltaV.cross(v0-v2)    804         polygon.SetNormal( deltaV.cross(v0-v2).unit() );
764                                                   805         
765         extentList.AddSurface( polygon );         806         extentList.AddSurface( polygon );
766       }                                           807       }
767                                                   808       
768       v2 = w2;                                    809       v2 = w2;
769     }                                             810     }
770                                                   811     
771     //                                            812     //
772     // Next vertex                                813     // Next vertex
773     //                                            814     //    
774     v0 = w0;                                      815     v0 = w0;
775     v1 = w1;                                      816     v1 = w1;
776   } while( --numPhi > 0 );                        817   } while( --numPhi > 0 );
777                                                   818   
778   //                                              819   //
779   // We are almost done. But, it is important     820   // We are almost done. But, it is important that we leave no
780   // gaps in the surface of our solid. By usin    821   // gaps in the surface of our solid. By using rFudge, however,
781   // we've done exactly that, if we have a phi    822   // we've done exactly that, if we have a phi segment. 
782   // Add two additional faces if necessary        823   // Add two additional faces if necessary
783   //                                              824   //
784   if (phiIsOpen && rNorm > DBL_MIN)               825   if (phiIsOpen && rNorm > DBL_MIN)
785   {                                               826   {    
786     cosPhi = std::cos(startPhi);                  827     cosPhi = std::cos(startPhi);
787     sinPhi = std::sin(startPhi);                  828     sinPhi = std::sin(startPhi);
788                                                   829 
789     G4ThreeVector a0( r[0]*cosPhi, r[0]*sinPhi    830     G4ThreeVector a0( r[0]*cosPhi, r[0]*sinPhi, z[0] ),
790                   a1( r[1]*cosPhi, r[1]*sinPhi    831                   a1( r[1]*cosPhi, r[1]*sinPhi, z[1] ),
791                   b0( r0*cosPhi, r0*sinPhi, z[    832                   b0( r0*cosPhi, r0*sinPhi, z[0] ),
792                   b1( r1*cosPhi, r1*sinPhi, z[    833                   b1( r1*cosPhi, r1*sinPhi, z[1] );
793                                                   834   
794     transform.ApplyPointTransform( a0 );          835     transform.ApplyPointTransform( a0 );
795     transform.ApplyPointTransform( a1 );          836     transform.ApplyPointTransform( a1 );
796     transform.ApplyPointTransform( b0 );          837     transform.ApplyPointTransform( b0 );
797     transform.ApplyPointTransform( b1 );          838     transform.ApplyPointTransform( b1 );
798                                                   839 
799     polygon.ClearAllVertices();                   840     polygon.ClearAllVertices();
800                                                   841 
801     polygon.AddVertexInOrder( a0 );               842     polygon.AddVertexInOrder( a0 );
802     polygon.AddVertexInOrder( a1 );               843     polygon.AddVertexInOrder( a1 );
803     polygon.AddVertexInOrder( b0 );               844     polygon.AddVertexInOrder( b0 );
804     polygon.AddVertexInOrder( b1 );               845     polygon.AddVertexInOrder( b1 );
805                                                   846     
806     if (polygon.PartialClip( voxelLimit , axis    847     if (polygon.PartialClip( voxelLimit , axis))
807     {                                             848     {
808       G4ThreeVector normal( sinPhi, -cosPhi, 0    849       G4ThreeVector normal( sinPhi, -cosPhi, 0 );
809       polygon.SetNormal( transform.TransformAx    850       polygon.SetNormal( transform.TransformAxis( normal ) );
810                                                   851         
811       extentList.AddSurface( polygon );           852       extentList.AddSurface( polygon );
812     }                                             853     }
813                                                   854     
814     cosPhi = std::cos(startPhi+deltaPhi);         855     cosPhi = std::cos(startPhi+deltaPhi);
815     sinPhi = std::sin(startPhi+deltaPhi);         856     sinPhi = std::sin(startPhi+deltaPhi);
816                                                   857     
817     a0 = G4ThreeVector( r[0]*cosPhi, r[0]*sinP    858     a0 = G4ThreeVector( r[0]*cosPhi, r[0]*sinPhi, z[0] ),
818     a1 = G4ThreeVector( r[1]*cosPhi, r[1]*sinP    859     a1 = G4ThreeVector( r[1]*cosPhi, r[1]*sinPhi, z[1] ),
819     b0 = G4ThreeVector( r0*cosPhi, r0*sinPhi,     860     b0 = G4ThreeVector( r0*cosPhi, r0*sinPhi, z[0] ),
820     b1 = G4ThreeVector( r1*cosPhi, r1*sinPhi,     861     b1 = G4ThreeVector( r1*cosPhi, r1*sinPhi, z[1] );
821     transform.ApplyPointTransform( a0 );          862     transform.ApplyPointTransform( a0 );
822     transform.ApplyPointTransform( a1 );          863     transform.ApplyPointTransform( a1 );
823     transform.ApplyPointTransform( b0 );          864     transform.ApplyPointTransform( b0 );
824     transform.ApplyPointTransform( b1 );          865     transform.ApplyPointTransform( b1 );
825                                                   866 
826     polygon.ClearAllVertices();                   867     polygon.ClearAllVertices();
827                                                   868 
828     polygon.AddVertexInOrder( a0 );               869     polygon.AddVertexInOrder( a0 );
829     polygon.AddVertexInOrder( a1 );               870     polygon.AddVertexInOrder( a1 );
830     polygon.AddVertexInOrder( b0 );               871     polygon.AddVertexInOrder( b0 );
831     polygon.AddVertexInOrder( b1 );               872     polygon.AddVertexInOrder( b1 );
832                                                   873     
833     if (polygon.PartialClip( voxelLimit, axis     874     if (polygon.PartialClip( voxelLimit, axis ))
834     {                                             875     {
835       G4ThreeVector normal( -sinPhi, cosPhi, 0    876       G4ThreeVector normal( -sinPhi, cosPhi, 0 );
836       polygon.SetNormal( transform.TransformAx    877       polygon.SetNormal( transform.TransformAxis( normal ) );
837                                                   878         
838       extentList.AddSurface( polygon );           879       extentList.AddSurface( polygon );
839     }                                             880     }
840   }                                               881   }
841                                                   882     
842   return;                                         883   return;
843 }                                                 884 }
844                                                   885 
                                                   >> 886 //
845 // GetPhi                                         887 // GetPhi
846 //                                                888 //
847 // Calculate Phi for a given 3-vector (point),    889 // Calculate Phi for a given 3-vector (point), if not already cached for the
848 // same point, in the attempt to avoid consecu    890 // same point, in the attempt to avoid consecutive computation of the same
849 // quantity                                       891 // quantity
850 //                                                892 //
851 G4double G4PolyconeSide::GetPhi( const G4Three    893 G4double G4PolyconeSide::GetPhi( const G4ThreeVector& p )
852 {                                                 894 {
853   G4double val=0.;                                895   G4double val=0.;
854   G4ThreeVector vphi(G4MT_pcphix, G4MT_pcphiy, << 
855                                                   896 
856   if (vphi != p)                               << 897   if (G4MT_pcphi.first != p)
857   {                                               898   {
858     val = p.phi();                                899     val = p.phi();
859     G4MT_pcphix = p.x(); G4MT_pcphiy = p.y();  << 900     G4MT_pcphi.first = p;
860     G4MT_pcphik = val;                         << 901     G4MT_pcphi.second = val;
861   }                                               902   }
862   else                                            903   else
863   {                                               904   {
864     val = G4MT_pcphik;                         << 905     val = G4MT_pcphi.second;
865   }                                               906   }
866   return val;                                     907   return val;
867 }                                                 908 }
868                                                   909 
                                                   >> 910 //
869 // DistanceAway                                   911 // DistanceAway
870 //                                                912 //
871 // Calculate distance of a point from our coni    913 // Calculate distance of a point from our conical surface, including the effect
872 // of any phi segmentation                        914 // of any phi segmentation
873 //                                                915 //
874 // Arguments:                                     916 // Arguments:
875 //  p             - (in) Point to check           917 //  p             - (in) Point to check
876 //  opposite      - (in) If true, check opposi    918 //  opposite      - (in) If true, check opposite hemisphere (see below)
877 //  distOutside   - (out) Additional distance     919 //  distOutside   - (out) Additional distance outside the edges of the surface
878 //  edgeRZnorm    - (out) if negative, point i    920 //  edgeRZnorm    - (out) if negative, point is inside
879 //                                                921 //
880 //  return value = distance from the conical p    922 //  return value = distance from the conical plane, if extrapolated beyond edges,
881 //                 signed by whether the point    923 //                 signed by whether the point is in inside or outside the shape
882 //                                                924 //
883 // Notes:                                         925 // Notes:
884 //  * There are two answers, depending on whic    926 //  * There are two answers, depending on which hemisphere is considered.
885 //                                                927 //
886 G4double G4PolyconeSide::DistanceAway( const G << 928 G4double G4PolyconeSide::DistanceAway( const G4ThreeVector &p,
887                                              G    929                                              G4bool opposite,
888                                              G << 930                                              G4double &distOutside2,
889                                              G << 931                                              G4double *edgeRZnorm  )
890 {                                                 932 {
891   //                                              933   //
892   // Convert our point to r and z                 934   // Convert our point to r and z
893   //                                              935   //
894   G4double rx = p.perp(), zx = p.z();             936   G4double rx = p.perp(), zx = p.z();
895                                                   937   
896   //                                              938   //
897   // Change sign of r if opposite says we shou    939   // Change sign of r if opposite says we should
898   //                                              940   //
899   if (opposite) rx = -rx;                         941   if (opposite) rx = -rx;
900                                                   942   
901   //                                              943   //
902   // Calculate return value                       944   // Calculate return value
903   //                                              945   //
904   G4double deltaR  = rx - r[0], deltaZ = zx -     946   G4double deltaR  = rx - r[0], deltaZ = zx - z[0];
905   G4double answer = deltaR*rNorm + deltaZ*zNor    947   G4double answer = deltaR*rNorm + deltaZ*zNorm;
906                                                   948   
907   //                                              949   //
908   // Are we off the surface in r,z space?         950   // Are we off the surface in r,z space?
909   //                                              951   //
910   G4double q = deltaR*rS + deltaZ*zS;             952   G4double q = deltaR*rS + deltaZ*zS;
911   if (q < 0)                                      953   if (q < 0)
912   {                                               954   {
913     distOutside2 = q*q;                           955     distOutside2 = q*q;
914     if (edgeRZnorm != nullptr)                 << 956     if (edgeRZnorm) *edgeRZnorm = deltaR*rNormEdge[0] + deltaZ*zNormEdge[0];
915       *edgeRZnorm = deltaR*rNormEdge[0] + delt << 
916   }                                               957   }
917   else if (q > length)                            958   else if (q > length)
918   {                                               959   {
919     distOutside2 = sqr( q-length );               960     distOutside2 = sqr( q-length );
920     if (edgeRZnorm != nullptr)                 << 961     if (edgeRZnorm)
921     {                                             962     {
922       deltaR = rx - r[1];                         963       deltaR = rx - r[1];
923       deltaZ = zx - z[1];                         964       deltaZ = zx - z[1];
924       *edgeRZnorm = deltaR*rNormEdge[1] + delt    965       *edgeRZnorm = deltaR*rNormEdge[1] + deltaZ*zNormEdge[1];
925     }                                             966     }
926   }                                               967   }
927   else                                            968   else
928   {                                               969   {
929     distOutside2 = 0.;                         << 970     distOutside2 = 0;
930     if (edgeRZnorm != nullptr) *edgeRZnorm = a << 971     if (edgeRZnorm) *edgeRZnorm = answer;
931   }                                               972   }
932                                                   973 
933   if (phiIsOpen)                                  974   if (phiIsOpen)
934   {                                               975   {
935     //                                            976     //
936     // Finally, check phi                         977     // Finally, check phi
937     //                                            978     //
938     G4double phi = GetPhi(p);                     979     G4double phi = GetPhi(p);
939     while( phi < startPhi )    // Loop checkin << 980     while( phi < startPhi ) phi += twopi;
940       phi += twopi;                            << 
941                                                   981     
942     if (phi > startPhi+deltaPhi)                  982     if (phi > startPhi+deltaPhi)
943     {                                             983     {
944       //                                          984       //
945       // Oops. Are we closer to the start phi     985       // Oops. Are we closer to the start phi or end phi?
946       //                                          986       //
947       G4double d1 = phi-startPhi-deltaPhi;        987       G4double d1 = phi-startPhi-deltaPhi;
948       while( phi > startPhi )    // Loop check << 988       while( phi > startPhi ) phi -= twopi;
949         phi -= twopi;                          << 
950       G4double d2 = startPhi-phi;                 989       G4double d2 = startPhi-phi;
951                                                   990       
952       if (d2 < d1) d1 = d2;                       991       if (d2 < d1) d1 = d2;
953                                                   992       
954       //                                          993       //
955       // Add result to our distance               994       // Add result to our distance
956       //                                          995       //
957       G4double dist = d1*rx;                      996       G4double dist = d1*rx;
958                                                   997       
959       distOutside2 += dist*dist;                  998       distOutside2 += dist*dist;
960       if (edgeRZnorm != nullptr)               << 999       if (edgeRZnorm)
961       {                                           1000       {
962         *edgeRZnorm = std::max(std::fabs(*edge    1001         *edgeRZnorm = std::max(std::fabs(*edgeRZnorm),std::fabs(dist));
963       }                                           1002       }
964     }                                             1003     }
965   }                                               1004   }
966                                                   1005 
967   return answer;                                  1006   return answer;
968 }                                                 1007 }
969                                                   1008 
970 // DistanceAway                                << 
971 //                                             << 
972 // Special version of DistanceAway for Inside. << 
973 // Opposite parameter is not used, instead use << 
974 //                                             << 
975 G4double G4PolyconeSide::DistanceAway( const G << 
976                                              G << 
977                                              G << 
978 {                                              << 
979   //                                           << 
980   // Convert our point to r and z              << 
981   //                                           << 
982   G4double rx = p.perp(), zx = p.z();          << 
983                                                << 
984   //                                           << 
985   // Change sign of r if we should             << 
986   //                                           << 
987   G4int part = 1;                              << 
988   if (rx < 0) part = -1;                       << 
989                                                << 
990   //                                           << 
991   // Calculate return value                    << 
992   //                                           << 
993   G4double deltaR = rx - r[0]*part, deltaZ = z << 
994   G4double answer = deltaR*rNorm*part + deltaZ << 
995                                                << 
996   //                                           << 
997   // Are we off the surface in r,z space?      << 
998   //                                           << 
999   G4double q = deltaR*rS*part + deltaZ*zS;     << 
1000   if (q < 0)                                  << 
1001   {                                           << 
1002     distOutside2 = q*q;                       << 
1003     if (edgeRZnorm != nullptr)                << 
1004     {                                         << 
1005       *edgeRZnorm = deltaR*rNormEdge[0]*part  << 
1006     }                                         << 
1007   }                                           << 
1008   else if (q > length)                        << 
1009   {                                           << 
1010     distOutside2 = sqr( q-length );           << 
1011     if (edgeRZnorm != nullptr)                << 
1012     {                                         << 
1013       deltaR = rx - r[1]*part;                << 
1014       deltaZ = zx - z[1];                     << 
1015       *edgeRZnorm = deltaR*rNormEdge[1]*part  << 
1016     }                                         << 
1017   }                                           << 
1018   else                                        << 
1019   {                                           << 
1020     distOutside2 = 0.;                        << 
1021     if (edgeRZnorm != nullptr) *edgeRZnorm =  << 
1022   }                                           << 
1023                                               << 
1024   if (phiIsOpen)                              << 
1025   {                                           << 
1026     //                                        << 
1027     // Finally, check phi                     << 
1028     //                                        << 
1029     G4double phi = GetPhi(p);                 << 
1030     while( phi < startPhi )    // Loop checki << 
1031       phi += twopi;                           << 
1032                                               << 
1033     if (phi > startPhi+deltaPhi)              << 
1034     {                                         << 
1035       //                                      << 
1036       // Oops. Are we closer to the start phi << 
1037       //                                      << 
1038       G4double d1 = phi-startPhi-deltaPhi;    << 
1039       while( phi > startPhi )    // Loop chec << 
1040         phi -= twopi;                         << 
1041       G4double d2 = startPhi-phi;             << 
1042                                               << 
1043       if (d2 < d1) d1 = d2;                   << 
1044                                               << 
1045       //                                      << 
1046       // Add result to our distance           << 
1047       //                                      << 
1048       G4double dist = d1*rx*part;             << 
1049                                               << 
1050       distOutside2 += dist*dist;              << 
1051       if (edgeRZnorm != nullptr)              << 
1052       {                                       << 
1053         *edgeRZnorm = std::max(std::fabs(*edg << 
1054       }                                       << 
1055     }                                         << 
1056   }                                           << 
1057                                               << 
1058   return answer;                              << 
1059 }                                             << 
1060                                                  1009 
                                                   >> 1010 //
1061 // PointOnCone                                   1011 // PointOnCone
1062 //                                               1012 //
1063 // Decide if a point is on a cone and return     1013 // Decide if a point is on a cone and return normal if it is
1064 //                                               1014 //
1065 G4bool G4PolyconeSide::PointOnCone( const G4T << 1015 G4bool G4PolyconeSide::PointOnCone( const G4ThreeVector &hit,
1066                                           G4d    1016                                           G4double normSign,
1067                                     const G4T << 1017                                     const G4ThreeVector &p,
1068                                     const G4T << 1018                                     const G4ThreeVector &v,
1069                                           G4T << 1019                                           G4ThreeVector &normal )
1070 {                                                1020 {
1071   G4double rx = hit.perp();                      1021   G4double rx = hit.perp();
1072   //                                             1022   //
1073   // Check radial/z extent, as appropriate       1023   // Check radial/z extent, as appropriate
1074   //                                             1024   //
1075   if (!cone->HitOn( rx, hit.z() )) return fal    1025   if (!cone->HitOn( rx, hit.z() )) return false;
1076                                                  1026   
1077   if (phiIsOpen)                                 1027   if (phiIsOpen)
1078   {                                              1028   {
1079     G4double phiTolerant = 2.0*kCarTolerance/    1029     G4double phiTolerant = 2.0*kCarTolerance/(rx+kCarTolerance);
1080     //                                           1030     //
1081     // Check phi segment. Here we have to be     1031     // Check phi segment. Here we have to be careful
1082     // to use the standard method consistent     1032     // to use the standard method consistent with
1083     // PolyPhiFace. See PolyPhiFace::InsideEd    1033     // PolyPhiFace. See PolyPhiFace::InsideEdgesExact
1084     //                                           1034     //
1085     G4double phi = GetPhi(hit);                  1035     G4double phi = GetPhi(hit);
1086     while( phi < startPhi-phiTolerant )   //  << 1036     while( phi < startPhi-phiTolerant ) phi += twopi;
1087       phi += twopi;                           << 
1088                                                  1037     
1089     if (phi > startPhi+deltaPhi+phiTolerant)     1038     if (phi > startPhi+deltaPhi+phiTolerant) return false;
1090                                                  1039     
1091     if (phi > startPhi+deltaPhi-phiTolerant)     1040     if (phi > startPhi+deltaPhi-phiTolerant)
1092     {                                            1041     {
1093       //                                         1042       //
1094       // Exact treatment                         1043       // Exact treatment
1095       //                                         1044       //
1096       G4ThreeVector qx = p + v;                  1045       G4ThreeVector qx = p + v;
1097       G4ThreeVector qa = qx - corners[2],        1046       G4ThreeVector qa = qx - corners[2],
1098               qb = qx - corners[3];              1047               qb = qx - corners[3];
1099       G4ThreeVector qacb = qa.cross(qb);         1048       G4ThreeVector qacb = qa.cross(qb);
1100                                                  1049       
1101       if (normSign*qacb.dot(v) < 0) return fa    1050       if (normSign*qacb.dot(v) < 0) return false;
1102     }                                            1051     }
1103     else if (phi < phiTolerant)                  1052     else if (phi < phiTolerant)
1104     {                                            1053     {
1105       G4ThreeVector qx = p + v;                  1054       G4ThreeVector qx = p + v;
1106       G4ThreeVector qa = qx - corners[1],        1055       G4ThreeVector qa = qx - corners[1],
1107               qb = qx - corners[0];              1056               qb = qx - corners[0];
1108       G4ThreeVector qacb = qa.cross(qb);         1057       G4ThreeVector qacb = qa.cross(qb);
1109                                                  1058       
1110       if (normSign*qacb.dot(v) < 0) return fa    1059       if (normSign*qacb.dot(v) < 0) return false;
1111     }                                            1060     }
1112   }                                              1061   }
1113                                                  1062   
1114   //                                             1063   //
1115   // We have a good hit! Calculate normal        1064   // We have a good hit! Calculate normal
1116   //                                             1065   //
1117   if (rx < DBL_MIN)                              1066   if (rx < DBL_MIN) 
1118     normal = G4ThreeVector( 0, 0, zNorm < 0 ?    1067     normal = G4ThreeVector( 0, 0, zNorm < 0 ? -1 : 1 );
1119   else                                           1068   else
1120     normal = G4ThreeVector( rNorm*hit.x()/rx,    1069     normal = G4ThreeVector( rNorm*hit.x()/rx, rNorm*hit.y()/rx, zNorm );
1121   return true;                                   1070   return true;
1122 }                                                1071 }
1123                                                  1072 
                                                   >> 1073 
                                                   >> 1074 //
1124 // FindLineIntersect                             1075 // FindLineIntersect
1125 //                                               1076 //
1126 // Decide the point at which two 2-dimensiona    1077 // Decide the point at which two 2-dimensional lines intersect
1127 //                                               1078 //
1128 // Equation of line: x = x1 + s*tx1              1079 // Equation of line: x = x1 + s*tx1
1129 //                   y = y1 + s*ty1              1080 //                   y = y1 + s*ty1
1130 //                                               1081 //
1131 // It is assumed that the lines are *not* par    1082 // It is assumed that the lines are *not* parallel
1132 //                                               1083 //
1133 void G4PolyconeSide::FindLineIntersect( G4dou    1084 void G4PolyconeSide::FindLineIntersect( G4double x1,  G4double y1,
1134                                         G4dou    1085                                         G4double tx1, G4double ty1,
1135                                         G4dou    1086                                         G4double x2,  G4double y2,
1136                                         G4dou    1087                                         G4double tx2, G4double ty2,
1137                                         G4dou << 1088                                         G4double &x,  G4double &y )
1138 {                                                1089 {
1139   //                                             1090   //
1140   // The solution is a simple linear equation    1091   // The solution is a simple linear equation
1141   //                                             1092   //
1142   G4double deter = tx1*ty2 - tx2*ty1;            1093   G4double deter = tx1*ty2 - tx2*ty1;
1143                                                  1094   
1144   G4double s1 = ((x2-x1)*ty2 - tx2*(y2-y1))/d    1095   G4double s1 = ((x2-x1)*ty2 - tx2*(y2-y1))/deter;
1145   G4double s2 = ((x2-x1)*ty1 - tx1*(y2-y1))/d    1096   G4double s2 = ((x2-x1)*ty1 - tx1*(y2-y1))/deter;
1146                                                  1097 
1147   //                                             1098   //
1148   // We want the answer to not depend on whic    1099   // We want the answer to not depend on which order the
1149   // lines were specified. Take average.         1100   // lines were specified. Take average.
1150   //                                             1101   //
1151   x = 0.5*( x1+s1*tx1 + x2+s2*tx2 );             1102   x = 0.5*( x1+s1*tx1 + x2+s2*tx2 );
1152   y = 0.5*( y1+s1*ty1 + y2+s2*ty2 );             1103   y = 0.5*( y1+s1*ty1 + y2+s2*ty2 );
1153 }                                                1104 }
1154                                                  1105 
                                                   >> 1106 //
1155 // Calculate surface area for GetPointOnSurfa    1107 // Calculate surface area for GetPointOnSurface()
1156 //                                               1108 //
1157 G4double G4PolyconeSide::SurfaceArea()           1109 G4double G4PolyconeSide::SurfaceArea() 
1158 {                                                1110 { 
1159   if(fSurfaceArea==0.)                        << 1111   if(fSurfaceArea==0)
1160   {                                              1112   {
1161     fSurfaceArea = (r[0]+r[1])* std::sqrt(sqr    1113     fSurfaceArea = (r[0]+r[1])* std::sqrt(sqr(r[0]-r[1])+sqr(z[0]-z[1]));
1162     fSurfaceArea *= 0.5*(deltaPhi);              1114     fSurfaceArea *= 0.5*(deltaPhi);
1163   }                                              1115   }  
1164   return fSurfaceArea;                           1116   return fSurfaceArea;
1165 }                                                1117 }
1166                                                  1118 
                                                   >> 1119 //
1167 // GetPointOnFace                                1120 // GetPointOnFace
1168 //                                               1121 //
1169 G4ThreeVector G4PolyconeSide::GetPointOnFace(    1122 G4ThreeVector G4PolyconeSide::GetPointOnFace()
1170 {                                                1123 {
1171   G4double x,y,zz;                               1124   G4double x,y,zz;
1172   G4double rr,phi,dz,dr;                         1125   G4double rr,phi,dz,dr;
1173   dr=r[1]-r[0];dz=z[1]-z[0];                     1126   dr=r[1]-r[0];dz=z[1]-z[0];
1174   phi=startPhi+deltaPhi*G4UniformRand();         1127   phi=startPhi+deltaPhi*G4UniformRand();
1175   rr=r[0]+dr*G4UniformRand();                    1128   rr=r[0]+dr*G4UniformRand();
1176                                                  1129  
1177   x=rr*std::cos(phi);                            1130   x=rr*std::cos(phi);
1178   y=rr*std::sin(phi);                            1131   y=rr*std::sin(phi);
1179                                                  1132 
1180   // PolyconeSide has a Ring Form                1133   // PolyconeSide has a Ring Form
1181   //                                             1134   //
1182   if (dz==0.)                                    1135   if (dz==0.)
1183   {                                              1136   {
1184     zz=z[0];                                     1137     zz=z[0];
1185   }                                              1138   }
1186   else                                           1139   else
1187   {                                              1140   {
1188     if(dr==0.)  // PolyconeSide has a Tube Fo    1141     if(dr==0.)  // PolyconeSide has a Tube Form
1189     {                                            1142     {
1190       zz = z[0]+dz*G4UniformRand();              1143       zz = z[0]+dz*G4UniformRand();
1191     }                                            1144     }
1192     else                                         1145     else
1193     {                                            1146     {
1194       zz = z[0]+(rr-r[0])*dz/dr;                 1147       zz = z[0]+(rr-r[0])*dz/dr;
1195     }                                            1148     }
1196   }                                              1149   }
1197                                                  1150 
1198   return {x,y,zz};                            << 1151   return G4ThreeVector(x,y,zz);
1199 }                                                1152 }
1200                                                  1153