Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/geometry/solids/CSG/src/G4Para.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/CSG/src/G4Para.cc (Version 11.3.0) and /geometry/solids/CSG/src/G4Para.cc (Version 9.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 //
                                                   >>  27 // $Id: G4Para.cc,v 1.39 2006/10/19 15:33:37 gcosmo Exp $
                                                   >>  28 // GEANT4 tag $Name: geant4-09-01 $
                                                   >>  29 //
                                                   >>  30 // class G4Para
                                                   >>  31 //
 26 // Implementation for G4Para class                 32 // Implementation for G4Para class
 27 //                                                 33 //
 28 // 21.03.95 P.Kent: Modified for `tolerant' ge <<  34 // History:
                                                   >>  35 //
                                                   >>  36 // 23.10.05 V.Grichine: bug fixed in DistanceToOut(p,v,...) for the v.x()<0 case 
                                                   >>  37 // 28.04.05 V.Grichine: new SurfaceNormal according to J. Apostolakis proposal 
                                                   >>  38 // 30.11.04 V.Grichine: modifications in SurfaceNormal for edges/vertices and
                                                   >>  39 //                      in constructor with vertices
                                                   >>  40 // 14.02.02 V.Grichine: bug fixed in Inside according to proposal of D.Wright
                                                   >>  41 // 18.11.99 V.Grichine: kUndef was added to ESide
 29 // 31.10.96 V.Grichine: Modifications accordin     42 // 31.10.96 V.Grichine: Modifications according G4Box/Tubs before to commit
 30 // 28.04.05 V.Grichine: new SurfaceNormal acco <<  43 // 21.03.95 P.Kent: Modified for `tolerant' geom
 31 // 29.05.17 E.Tcherniaev: complete revision, s <<  44 //
 32 //////////////////////////////////////////////     45 ////////////////////////////////////////////////////////////////////////////
 33                                                    46 
 34 #include "G4Para.hh"                               47 #include "G4Para.hh"
 35                                                    48 
 36 #if !defined(G4GEOM_USE_UPARA)                 << 
 37                                                << 
 38 #include "G4VoxelLimits.hh"                        49 #include "G4VoxelLimits.hh"
 39 #include "G4AffineTransform.hh"                    50 #include "G4AffineTransform.hh"
 40 #include "G4BoundingEnvelope.hh"               << 
 41 #include "Randomize.hh"                            51 #include "Randomize.hh"
 42                                                    52 
 43 #include "G4VPVParameterisation.hh"                53 #include "G4VPVParameterisation.hh"
 44                                                    54 
 45 #include "G4VGraphicsScene.hh"                     55 #include "G4VGraphicsScene.hh"
                                                   >>  56 #include "G4Polyhedron.hh"
                                                   >>  57 #include "G4NURBS.hh"
                                                   >>  58 #include "G4NURBSbox.hh"
 46                                                    59 
 47 using namespace CLHEP;                             60 using namespace CLHEP;
 48                                                    61 
 49 ////////////////////////////////////////////// <<  62 // Private enum: Not for external use 
 50 //                                             <<  63     
 51 //  Constructor - set & check half widths      <<  64 enum ESide {kUndef,kPX,kMX,kPY,kMY,kPZ,kMZ};
 52                                                << 
 53 G4Para::G4Para(const G4String& pName,          << 
 54                      G4double pDx, G4double pD << 
 55                      G4double pAlpha, G4double << 
 56   : G4CSGSolid(pName), halfCarTolerance(0.5*kC << 
 57 {                                              << 
 58   SetAllParameters(pDx, pDy, pDz, pAlpha, pThe << 
 59   fRebuildPolyhedron = false;  // default valu << 
 60 }                                              << 
 61                                                << 
 62 ////////////////////////////////////////////// << 
 63 //                                             << 
 64 // Constructor - design of trapezoid based on  << 
 65                                                << 
 66 G4Para::G4Para( const G4String& pName,         << 
 67                 const G4ThreeVector pt[8] )    << 
 68   : G4CSGSolid(pName), halfCarTolerance(0.5*kC << 
 69 {                                              << 
 70   // Find dimensions and trigonometric values  << 
 71   //                                           << 
 72   fDx = (pt[3].x() - pt[2].x())*0.5;           << 
 73   fDy = (pt[2].y() - pt[1].y())*0.5;           << 
 74   fDz = pt[7].z();                             << 
 75   CheckParameters(); // check dimensions       << 
 76                                                << 
 77   fTalpha = (pt[2].x() + pt[3].x() - pt[1].x() << 
 78   fTthetaCphi = (pt[4].x() + fDy*fTalpha + fDx << 
 79   fTthetaSphi = (pt[4].y() + fDy)/fDz;         << 
 80   MakePlanes();                                << 
 81                                                << 
 82   // Recompute vertices                        << 
 83   //                                           << 
 84   G4ThreeVector v[8];                          << 
 85   G4double DyTalpha = fDy*fTalpha;             << 
 86   G4double DzTthetaSphi = fDz*fTthetaSphi;     << 
 87   G4double DzTthetaCphi = fDz*fTthetaCphi;     << 
 88   v[0].set(-DzTthetaCphi-DyTalpha-fDx, -DzTthe << 
 89   v[1].set(-DzTthetaCphi-DyTalpha+fDx, -DzTthe << 
 90   v[2].set(-DzTthetaCphi+DyTalpha-fDx, -DzTthe << 
 91   v[3].set(-DzTthetaCphi+DyTalpha+fDx, -DzTthe << 
 92   v[4].set( DzTthetaCphi-DyTalpha-fDx,  DzTthe << 
 93   v[5].set( DzTthetaCphi-DyTalpha+fDx,  DzTthe << 
 94   v[6].set( DzTthetaCphi+DyTalpha-fDx,  DzTthe << 
 95   v[7].set( DzTthetaCphi+DyTalpha+fDx,  DzTthe << 
 96                                                << 
 97   // Compare with original vertices            << 
 98   //                                           << 
 99   for (G4int i=0; i<8; ++i)                    << 
100   {                                            << 
101     G4double delx = std::abs(pt[i].x() - v[i]. << 
102     G4double dely = std::abs(pt[i].y() - v[i]. << 
103     G4double delz = std::abs(pt[i].z() - v[i]. << 
104     G4double discrepancy = std::max(std::max(d << 
105     if (discrepancy > 0.1*kCarTolerance)       << 
106     {                                          << 
107       std::ostringstream message;              << 
108       G4long oldprc = message.precision(16);   << 
109       message << "Invalid vertice coordinates  << 
110               << "\nVertix #" << i << ", discr << 
111               << "\n  original   : " << pt[i]  << 
112               << "\n  recomputed : " << v[i];  << 
113       G4cout.precision(oldprc);                << 
114       G4Exception("G4Para::G4Para()", "GeomSol << 
115                   FatalException, message);    << 
116                                                << 
117     }                                          << 
118   }                                            << 
119 }                                              << 
120                                                << 
121 ////////////////////////////////////////////// << 
122 //                                             << 
123 // Fake default constructor - sets only member << 
124 //                            for usage restri << 
125                                                << 
126 G4Para::G4Para( __void__& a )                  << 
127   : G4CSGSolid(a), halfCarTolerance(0.5*kCarTo << 
128 {                                              << 
129   SetAllParameters(1., 1., 1., 0., 0., 0.);    << 
130   fRebuildPolyhedron = false; // default value << 
131 }                                              << 
132                                                    65 
133 ////////////////////////////////////////////// <<  66 // used internally for normal routine
134 //                                             << 
135 // Destructor                                  << 
136                                                    67 
137 G4Para::~G4Para() = default;                   <<  68 enum ENSide {kNZ,kNX,kNY};
138                                                    69 
139 ////////////////////////////////////////////// <<  70 /////////////////////////////////////////////////////////////////////
140 //                                                 71 //
141 // Copy constructor                            <<  72 // Constructor - check and set half-widths
142                                                    73 
143 G4Para::G4Para(const G4Para& rhs)              <<  74 void G4Para::SetAllParameters( G4double pDx, G4double pDy, G4double pDz, 
144   : G4CSGSolid(rhs), halfCarTolerance(rhs.half <<  75                                G4double pAlpha, G4double pTheta, G4double pPhi )
145     fDx(rhs.fDx), fDy(rhs.fDy), fDz(rhs.fDz),  << 
146     fTthetaCphi(rhs.fTthetaCphi),fTthetaSphi(r << 
147 {                                                  76 {
148   for (G4int i=0; i<4; ++i) { fPlanes[i] = rhs <<  77   if ( pDx > 0 && pDy > 0 && pDz > 0 )
                                                   >>  78   {
                                                   >>  79     fDx         = pDx;
                                                   >>  80     fDy         = pDy;
                                                   >>  81     fDz         = pDz;
                                                   >>  82     fTalpha     = std::tan(pAlpha);
                                                   >>  83     fTthetaCphi = std::tan(pTheta)*std::cos(pPhi);
                                                   >>  84     fTthetaSphi = std::tan(pTheta)*std::sin(pPhi);
                                                   >>  85   }
                                                   >>  86   else
                                                   >>  87   {
                                                   >>  88     G4cerr << "ERROR - G4Para()::SetAllParameters(): " << GetName() << G4endl
                                                   >>  89            << "        Invalid dimensions ! - "
                                                   >>  90            << pDx << ", " << pDy << ", " << pDz << G4endl;
                                                   >>  91     G4Exception("G4Para::SetAllParameters()", "InvalidSetup",
                                                   >>  92                 FatalException, "Invalid Length Parameters.");
                                                   >>  93   }
                                                   >>  94   fCubicVolume = 0.;
                                                   >>  95   fSurfaceArea = 0.;
                                                   >>  96   fpPolyhedron = 0;
149 }                                                  97 }
150                                                    98 
151 ////////////////////////////////////////////// <<  99 ///////////////////////////////////////////////////////////////////////////
152 //                                                100 //
153 // Assignment operator                         << 
154                                                   101 
155 G4Para& G4Para::operator = (const G4Para& rhs) << 102 G4Para::G4Para(const G4String& pName,
                                                   >> 103                      G4double pDx, G4double pDy, G4double pDz,
                                                   >> 104                      G4double pAlpha, G4double pTheta, G4double pPhi)
                                                   >> 105   : G4CSGSolid(pName)
156 {                                                 106 {
157    // Check assignment to self                 << 107   if (pDx>0&&pDy>0&&pDz>0)
158    //                                          << 108   {
159    if (this == &rhs)  { return *this; }        << 109     SetAllParameters( pDx, pDy, pDz, pAlpha, pTheta, pPhi);
160                                                << 110   }
161    // Copy base class data                     << 111   else
162    //                                          << 112   {
163    G4CSGSolid::operator=(rhs);                 << 113     G4cerr << "ERROR - G4Para()::G4Para(): " << GetName() << G4endl
164                                                << 114            << "        Invalid dimensions ! - "
165    // Copy data                                << 115            << pDx << ", " << pDy << ", " << pDz << G4endl;
166    //                                          << 116     G4Exception("G4Para::G4Para()", "InvalidSetup",
167    halfCarTolerance = rhs.halfCarTolerance;    << 117                 FatalException, "Invalid Length Parameters.");
168    fDx = rhs.fDx;                              << 118   }
169    fDy = rhs.fDy;                              << 
170    fDz = rhs.fDz;                              << 
171    fTalpha = rhs.fTalpha;                      << 
172    fTthetaCphi = rhs.fTthetaCphi;              << 
173    fTthetaSphi = rhs.fTthetaSphi;              << 
174    for (G4int i=0; i<4; ++i) { fPlanes[i] = rh << 
175                                                << 
176    return *this;                               << 
177 }                                                 119 }
178                                                   120 
179 ////////////////////////////////////////////// << 121 ////////////////////////////////////////////////////////////////////////
180 //                                                122 //
181 // Set all parameters, as for constructor - se << 123 // Constructor - Design of trapezoid based on 8 G4ThreeVector parameters, 
                                                   >> 124 // which are its vertices. Checking of planarity with preparation of 
                                                   >> 125 // fPlanes[] and than calculation of other members
182                                                   126 
183 void G4Para::SetAllParameters(G4double pDx, G4 << 127 G4Para::G4Para( const G4String& pName,
184                               G4double pAlpha, << 128                 const G4ThreeVector pt[8] )
                                                   >> 129   : G4CSGSolid(pName)
185 {                                                 130 {
186   // Reset data of the base class              << 131   if ( pt[0].z()<0 && pt[0].z()==pt[1].z() && pt[0].z()==pt[2].z() &&
187   fCubicVolume = 0;                            << 132        pt[0].z()==pt[3].z() && pt[4].z()>0 && pt[4].z()==pt[5].z() &&
188   fSurfaceArea = 0;                            << 133        pt[4].z()==pt[6].z() && pt[4].z()==pt[7].z()           &&
189   fRebuildPolyhedron = true;                   << 134        (pt[0].z()+pt[4].z())==0                               &&
190                                                << 135        pt[0].y()==pt[1].y() && pt[2].y()==pt[3].y()           &&
191   // Set parameters                            << 136        pt[4].y()==pt[5].y() && pt[6].y()==pt[7].y()           &&
192   fDx = pDx;                                   << 137        ( pt[0].y() + pt[2].y() + pt[4].y() + pt[6].y() ) == 0 && 
193   fDy = pDy;                                   << 138        ( pt[0].x() + pt[1].x() + pt[4].x() + pt[5].x() ) == 0)
194   fDz = pDz;                                   << 139   {
195   fTalpha = std::tan(pAlpha);                  << 140     fDz = (pt[7]).z() ;
196   fTthetaCphi = std::tan(pTheta)*std::cos(pPhi << 141 
197   fTthetaSphi = std::tan(pTheta)*std::sin(pPhi << 142     fDy = ((pt[2]).y()-(pt[1]).y())*0.5 ;
198                                                << 143     fDx = ((pt[1]).x()-(pt[0]).x())*0.5 ;
199   CheckParameters();                           << 144     fDx = ((pt[3]).x()-(pt[2]).x())*0.5 ;
200   MakePlanes();                                << 145     fTalpha = ((pt[2]).x()+(pt[3]).x()-(pt[1]).x()-(pt[0]).x())*0.25/fDy ;
201 }                                              << 146 
                                                   >> 147     // fDy = ((pt[6]).y()-(pt[5]).y())*0.5 ;
                                                   >> 148     // fDx = ((pt[5]).x()-(pt[4]).x())*0.5 ;
                                                   >> 149     // fDx = ((pt[7]).x()-(pt[6]).x())*0.5 ;
                                                   >> 150     // fTalpha = ((pt[6]).x()+(pt[7]).x()-(pt[5]).x()-(pt[4]).x())*0.25/fDy ;
202                                                   151 
203 ////////////////////////////////////////////// << 152     fTthetaCphi = ((pt[4]).x()+fDy*fTalpha+fDx)/fDz ;
204 //                                             << 153     fTthetaSphi = ((pt[4]).y()+fDy)/fDz ;
205 // Check dimensions                            << 
206                                                << 
207 void G4Para::CheckParameters()                 << 
208 {                                              << 
209   if (fDx < 2*kCarTolerance ||                 << 
210       fDy < 2*kCarTolerance ||                 << 
211       fDz < 2*kCarTolerance)                   << 
212   {                                            << 
213     std::ostringstream message;                << 
214     message << "Invalid (too small or negative << 
215             << GetName()                       << 
216             << "\n  X - " << fDx               << 
217             << "\n  Y - " << fDy               << 
218             << "\n  Z - " << fDz;              << 
219     G4Exception("G4Para::CheckParameters()", " << 
220                 FatalException, message);      << 
221   }                                               154   }
                                                   >> 155   else
                                                   >> 156   {
                                                   >> 157     G4cerr << "ERROR - G4Para()::G4Para(): " << GetName() << G4endl
                                                   >> 158            << "        Invalid dimensions !" << G4endl;
                                                   >> 159     G4Exception("G4Para::G4Para()", "InvalidSetup",
                                                   >> 160                 FatalException, "Invalid vertice coordinates.");
                                                   >> 161   }    
222 }                                                 162 }
223                                                   163 
224 ////////////////////////////////////////////// << 164 ///////////////////////////////////////////////////////////////////////
225 //                                                165 //
226 // Set side planes                             << 166 // Fake default constructor - sets only member data and allocates memory
227                                                << 167 //                            for usage restricted to object persistency.
228 void G4Para::MakePlanes()                      << 
229 {                                              << 
230   G4ThreeVector vx(1, 0, 0);                   << 
231   G4ThreeVector vy(fTalpha, 1, 0);             << 
232   G4ThreeVector vz(fTthetaCphi, fTthetaSphi, 1 << 
233                                                << 
234   // Set -Y & +Y planes                        << 
235   //                                           << 
236   G4ThreeVector ynorm = (vx.cross(vz)).unit(); << 
237                                                << 
238   fPlanes[0].a = 0.;                           << 
239   fPlanes[0].b = ynorm.y();                    << 
240   fPlanes[0].c = ynorm.z();                    << 
241   fPlanes[0].d = fPlanes[0].b*fDy; // point (0 << 
242                                                << 
243   fPlanes[1].a =  0.;                          << 
244   fPlanes[1].b = -fPlanes[0].b;                << 
245   fPlanes[1].c = -fPlanes[0].c;                << 
246   fPlanes[1].d =  fPlanes[0].d;                << 
247                                                << 
248   // Set -X & +X planes                        << 
249   //                                           << 
250   G4ThreeVector xnorm = (vz.cross(vy)).unit(); << 
251                                                << 
252   fPlanes[2].a = xnorm.x();                    << 
253   fPlanes[2].b = xnorm.y();                    << 
254   fPlanes[2].c = xnorm.z();                    << 
255   fPlanes[2].d = fPlanes[2].a*fDx; // point (f << 
256                                                << 
257   fPlanes[3].a = -fPlanes[2].a;                << 
258   fPlanes[3].b = -fPlanes[2].b;                << 
259   fPlanes[3].c = -fPlanes[2].c;                << 
260   fPlanes[3].d =  fPlanes[2].d;                << 
261 }                                              << 
262                                                << 
263 ////////////////////////////////////////////// << 
264 //                                                168 //
265 // Get volume                                  << 169 G4Para::G4Para( __void__& a )
266                                                << 170   : G4CSGSolid(a)
267 G4double G4Para::GetCubicVolume()              << 
268 {                                                 171 {
269   // It is like G4Box, since para transformati << 
270   if (fCubicVolume == 0)                       << 
271   {                                            << 
272     fCubicVolume = 8*fDx*fDy*fDz;              << 
273   }                                            << 
274   return fCubicVolume;                         << 
275 }                                                 172 }
276                                                   173 
277 //////////////////////////////////////////////    174 //////////////////////////////////////////////////////////////////////////
278 //                                                175 //
279 // Get surface area                            << 
280                                                   176 
281 G4double G4Para::GetSurfaceArea()              << 177 G4Para::~G4Para()
282 {                                                 178 {
283   if(fSurfaceArea == 0)                        << 
284   {                                            << 
285     G4ThreeVector vx(fDx, 0, 0);               << 
286     G4ThreeVector vy(fDy*fTalpha, fDy, 0);     << 
287     G4ThreeVector vz(fDz*fTthetaCphi, fDz*fTth << 
288                                                << 
289     G4double sxy = fDx*fDy; // (vx.cross(vy)). << 
290     G4double sxz = (vx.cross(vz)).mag();       << 
291     G4double syz = (vy.cross(vz)).mag();       << 
292                                                << 
293     fSurfaceArea = 8*(sxy+sxz+syz);            << 
294   }                                            << 
295   return fSurfaceArea;                         << 
296 }                                                 179 }
297                                                   180 
298 //////////////////////////////////////////////    181 //////////////////////////////////////////////////////////////////////////
299 //                                                182 //
300 // Dispatch to parameterisation for replicatio    183 // Dispatch to parameterisation for replication mechanism dimension
301 // computation & modification                  << 184 // computation & modification.
302                                                   185 
303 void G4Para::ComputeDimensions(      G4VPVPara    186 void G4Para::ComputeDimensions(      G4VPVParameterisation* p,
304                                 const G4int n,    187                                 const G4int n,
305                                 const G4VPhysi    188                                 const G4VPhysicalVolume* pRep )
306 {                                                 189 {
307   p->ComputeDimensions(*this,n,pRep);             190   p->ComputeDimensions(*this,n,pRep);
308 }                                                 191 }
309                                                   192 
310 ////////////////////////////////////////////// << 
311 //                                             << 
312 // Get bounding box                            << 
313                                                   193 
314 void G4Para::BoundingLimits(G4ThreeVector& pMi << 194 //////////////////////////////////////////////////////////////
315 {                                              << 
316   G4double dz = GetZHalfLength();              << 
317   G4double dx = GetXHalfLength();              << 
318   G4double dy = GetYHalfLength();              << 
319                                                << 
320   G4double x0 = dz*fTthetaCphi;                << 
321   G4double x1 = dy*GetTanAlpha();              << 
322   G4double xmin =                              << 
323     std::min(                                  << 
324     std::min(                                  << 
325     std::min(-x0-x1-dx,-x0+x1-dx),x0-x1-dx),x0 << 
326   G4double xmax =                              << 
327     std::max(                                  << 
328     std::max(                                  << 
329     std::max(-x0-x1+dx,-x0+x1+dx),x0-x1+dx),x0 << 
330                                                << 
331   G4double y0 = dz*fTthetaSphi;                << 
332   G4double ymin = std::min(-y0-dy,y0-dy);      << 
333   G4double ymax = std::max(-y0+dy,y0+dy);      << 
334                                                << 
335   pMin.set(xmin,ymin,-dz);                     << 
336   pMax.set(xmax,ymax, dz);                     << 
337                                                << 
338   // Check correctness of the bounding box     << 
339   //                                           << 
340   if (pMin.x() >= pMax.x() || pMin.y() >= pMax << 
341   {                                            << 
342     std::ostringstream message;                << 
343     message << "Bad bounding box (min >= max)  << 
344             << GetName() << " !"               << 
345             << "\npMin = " << pMin             << 
346             << "\npMax = " << pMax;            << 
347     G4Exception("G4Para::BoundingLimits()", "G << 
348                 JustWarning, message);         << 
349     DumpInfo();                                << 
350   }                                            << 
351 }                                              << 
352                                                << 
353 ////////////////////////////////////////////// << 
354 //                                                195 //
355 // Calculate extent under transform and specif    196 // Calculate extent under transform and specified limit
356                                                   197 
357 G4bool G4Para::CalculateExtent( const EAxis pA    198 G4bool G4Para::CalculateExtent( const EAxis pAxis,
358                                 const G4VoxelL    199                                 const G4VoxelLimits& pVoxelLimit,
359                                 const G4Affine    200                                 const G4AffineTransform& pTransform,
360                                      G4double&    201                                      G4double& pMin, G4double& pMax ) const
361 {                                                 202 {
362   G4ThreeVector bmin, bmax;                    << 203   G4bool flag;
363   G4bool exist;                                << 
364                                                   204 
365   // Check bounding box (bbox)                 << 205   if (!pTransform.IsRotated())
366   //                                           << 206   {  
367   BoundingLimits(bmin,bmax);                   << 207     // Special case handling for unrotated trapezoids
368   G4BoundingEnvelope bbox(bmin,bmax);          << 208     // Compute z/x/y/ mins and maxs respecting limits, with early returns
369 #ifdef G4BBOX_EXTENT                           << 209     // if outside limits. Then switch() on pAxis
370   return bbox.CalculateExtent(pAxis,pVoxelLimi << 210 
371 #endif                                         << 211     G4int i ; 
372   if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVox << 212     G4double xoffset,xMin,xMax;
373   {                                            << 213     G4double yoffset,yMin,yMax;
374     return exist = pMin < pMax;                << 214     G4double zoffset,zMin,zMax;
375   }                                            << 215     G4double temp[8] ;       // some points for intersection with zMin/zMax
                                                   >> 216     
                                                   >> 217     xoffset=pTransform.NetTranslation().x();      
                                                   >> 218     yoffset=pTransform.NetTranslation().y();
                                                   >> 219     zoffset=pTransform.NetTranslation().z();
                                                   >> 220  
                                                   >> 221     G4ThreeVector pt[8];   // vertices after translation
                                                   >> 222     pt[0]=G4ThreeVector(xoffset-fDz*fTthetaCphi-fDy*fTalpha-fDx,
                                                   >> 223                         yoffset-fDz*fTthetaSphi-fDy,zoffset-fDz);
                                                   >> 224     pt[1]=G4ThreeVector(xoffset-fDz*fTthetaCphi-fDy*fTalpha+fDx,
                                                   >> 225                         yoffset-fDz*fTthetaSphi-fDy,zoffset-fDz);
                                                   >> 226     pt[2]=G4ThreeVector(xoffset-fDz*fTthetaCphi+fDy*fTalpha-fDx,
                                                   >> 227                         yoffset-fDz*fTthetaSphi+fDy,zoffset-fDz);
                                                   >> 228     pt[3]=G4ThreeVector(xoffset-fDz*fTthetaCphi+fDy*fTalpha+fDx,
                                                   >> 229                         yoffset-fDz*fTthetaSphi+fDy,zoffset-fDz);
                                                   >> 230     pt[4]=G4ThreeVector(xoffset+fDz*fTthetaCphi-fDy*fTalpha-fDx,
                                                   >> 231                         yoffset+fDz*fTthetaSphi-fDy,zoffset+fDz);
                                                   >> 232     pt[5]=G4ThreeVector(xoffset+fDz*fTthetaCphi-fDy*fTalpha+fDx,
                                                   >> 233                         yoffset+fDz*fTthetaSphi-fDy,zoffset+fDz);
                                                   >> 234     pt[6]=G4ThreeVector(xoffset+fDz*fTthetaCphi+fDy*fTalpha-fDx,
                                                   >> 235                         yoffset+fDz*fTthetaSphi+fDy,zoffset+fDz);
                                                   >> 236     pt[7]=G4ThreeVector(xoffset+fDz*fTthetaCphi+fDy*fTalpha+fDx,
                                                   >> 237                         yoffset+fDz*fTthetaSphi+fDy,zoffset+fDz);
                                                   >> 238     zMin=zoffset-fDz;
                                                   >> 239     zMax=zoffset+fDz;
                                                   >> 240     if ( pVoxelLimit.IsZLimited() )
                                                   >> 241     {
                                                   >> 242       if   ( (zMin>pVoxelLimit.GetMaxZExtent()+kCarTolerance)
                                                   >> 243           || (zMax<pVoxelLimit.GetMinZExtent()-kCarTolerance) )
                                                   >> 244       {
                                                   >> 245         return false;
                                                   >> 246       }
                                                   >> 247       else
                                                   >> 248       {
                                                   >> 249         if (zMin<pVoxelLimit.GetMinZExtent())
                                                   >> 250         {
                                                   >> 251           zMin=pVoxelLimit.GetMinZExtent();
                                                   >> 252         }
                                                   >> 253         if (zMax>pVoxelLimit.GetMaxZExtent())
                                                   >> 254         {
                                                   >> 255           zMax=pVoxelLimit.GetMaxZExtent();
                                                   >> 256         }
                                                   >> 257       }
                                                   >> 258     }
376                                                   259 
377   // Set bounding envelope (benv) and calculat << 260     temp[0] = pt[0].y()+(pt[4].y()-pt[0].y())
378   //                                           << 261                        *(zMin-pt[0].z())/(pt[4].z()-pt[0].z()) ;
379   G4double dz = GetZHalfLength();              << 262     temp[1] = pt[0].y()+(pt[4].y()-pt[0].y())
380   G4double dx = GetXHalfLength();              << 263                        *(zMax-pt[0].z())/(pt[4].z()-pt[0].z()) ;
381   G4double dy = GetYHalfLength();              << 264     temp[2] = pt[2].y()+(pt[6].y()-pt[2].y())
                                                   >> 265                        *(zMin-pt[2].z())/(pt[6].z()-pt[2].z()) ;
                                                   >> 266     temp[3] = pt[2].y()+(pt[6].y()-pt[2].y())
                                                   >> 267                        *(zMax-pt[2].z())/(pt[6].z()-pt[2].z()) ;        
                                                   >> 268     yMax = yoffset - std::fabs(fDz*fTthetaSphi) - fDy - fDy ;
                                                   >> 269     yMin = -yMax ;
                                                   >> 270     for(i=0;i<4;i++)
                                                   >> 271     {
                                                   >> 272       if(temp[i] > yMax) yMax = temp[i] ;
                                                   >> 273       if(temp[i] < yMin) yMin = temp[i] ;
                                                   >> 274     }
                                                   >> 275       
                                                   >> 276     if (pVoxelLimit.IsYLimited())
                                                   >> 277     {
                                                   >> 278       if ( (yMin>pVoxelLimit.GetMaxYExtent()+kCarTolerance)
                                                   >> 279         || (yMax<pVoxelLimit.GetMinYExtent()-kCarTolerance) )
                                                   >> 280       {
                                                   >> 281         return false;
                                                   >> 282       }
                                                   >> 283       else
                                                   >> 284       {
                                                   >> 285         if (yMin<pVoxelLimit.GetMinYExtent())
                                                   >> 286         {
                                                   >> 287           yMin=pVoxelLimit.GetMinYExtent();
                                                   >> 288         }
                                                   >> 289         if (yMax>pVoxelLimit.GetMaxYExtent())
                                                   >> 290         {
                                                   >> 291           yMax=pVoxelLimit.GetMaxYExtent();
                                                   >> 292         }
                                                   >> 293       }
                                                   >> 294     }
382                                                   295 
383   G4double x0 = dz*fTthetaCphi;                << 296     temp[0] = pt[0].x()+(pt[4].x()-pt[0].x())
384   G4double x1 = dy*GetTanAlpha();              << 297                        *(zMin-pt[0].z())/(pt[4].z()-pt[0].z()) ;
385   G4double y0 = dz*fTthetaSphi;                << 298     temp[1] = pt[0].x()+(pt[4].x()-pt[0].x())
                                                   >> 299                        *(zMax-pt[0].z())/(pt[4].z()-pt[0].z()) ;
                                                   >> 300     temp[2] = pt[2].x()+(pt[6].x()-pt[2].x())
                                                   >> 301                        *(zMin-pt[2].z())/(pt[6].z()-pt[2].z()) ;
                                                   >> 302     temp[3] = pt[2].x()+(pt[6].x()-pt[2].x())
                                                   >> 303                        *(zMax-pt[2].z())/(pt[6].z()-pt[2].z()) ;
                                                   >> 304     temp[4] = pt[3].x()+(pt[7].x()-pt[3].x())
                                                   >> 305                        *(zMin-pt[3].z())/(pt[7].z()-pt[3].z()) ;
                                                   >> 306     temp[5] = pt[3].x()+(pt[7].x()-pt[3].x())
                                                   >> 307                        *(zMax-pt[3].z())/(pt[7].z()-pt[3].z()) ;
                                                   >> 308     temp[6] = pt[1].x()+(pt[5].x()-pt[1].x())
                                                   >> 309                        *(zMin-pt[1].z())/(pt[5].z()-pt[1].z()) ;
                                                   >> 310     temp[7] = pt[1].x()+(pt[5].x()-pt[1].x())
                                                   >> 311                        *(zMax-pt[1].z())/(pt[5].z()-pt[1].z()) ;
                                                   >> 312 
                                                   >> 313     xMax = xoffset - std::fabs(fDz*fTthetaCphi) - fDx - fDx -fDx - fDx;
                                                   >> 314     xMin = -xMax ;
                                                   >> 315     for(i=0;i<8;i++)
                                                   >> 316     {
                                                   >> 317       if(temp[i] > xMax) xMax = temp[i] ;
                                                   >> 318       if(temp[i] < xMin) xMin = temp[i] ;
                                                   >> 319     }
                                                   >> 320       // xMax/Min = f(yMax/Min) ?
                                                   >> 321     if (pVoxelLimit.IsXLimited())
                                                   >> 322     {
                                                   >> 323       if ( (xMin>pVoxelLimit.GetMaxXExtent()+kCarTolerance)
                                                   >> 324         || (xMax<pVoxelLimit.GetMinXExtent()-kCarTolerance) )
                                                   >> 325       {
                                                   >> 326         return false;
                                                   >> 327       }
                                                   >> 328       else
                                                   >> 329       {
                                                   >> 330         if (xMin<pVoxelLimit.GetMinXExtent())
                                                   >> 331         {
                                                   >> 332           xMin=pVoxelLimit.GetMinXExtent();
                                                   >> 333         }
                                                   >> 334         if (xMax>pVoxelLimit.GetMaxXExtent())
                                                   >> 335         {
                                                   >> 336           xMax=pVoxelLimit.GetMaxXExtent();
                                                   >> 337         }
                                                   >> 338       }
                                                   >> 339     }
386                                                   340 
387   G4ThreeVectorList baseA(4), baseB(4);        << 341     switch (pAxis)
388   baseA[0].set(-x0-x1-dx,-y0-dy,-dz);          << 342     {
389   baseA[1].set(-x0-x1+dx,-y0-dy,-dz);          << 343       case kXAxis:
390   baseA[2].set(-x0+x1+dx,-y0+dy,-dz);          << 344         pMin=xMin;
391   baseA[3].set(-x0+x1-dx,-y0+dy,-dz);          << 345         pMax=xMax;
                                                   >> 346         break;
                                                   >> 347       case kYAxis:
                                                   >> 348         pMin=yMin;
                                                   >> 349         pMax=yMax;
                                                   >> 350         break;
                                                   >> 351       case kZAxis:
                                                   >> 352         pMin=zMin;
                                                   >> 353         pMax=zMax;
                                                   >> 354         break;
                                                   >> 355       default:
                                                   >> 356         break;
                                                   >> 357     }
392                                                   358 
393   baseB[0].set(+x0-x1-dx, y0-dy, dz);          << 359     pMin-=kCarTolerance;
394   baseB[1].set(+x0-x1+dx, y0-dy, dz);          << 360     pMax+=kCarTolerance;
395   baseB[2].set(+x0+x1+dx, y0+dy, dz);          << 361     flag = true;
396   baseB[3].set(+x0+x1-dx, y0+dy, dz);          << 362   }
                                                   >> 363   else
                                                   >> 364   {
                                                   >> 365     // General rotated case - create and clip mesh to boundaries
                                                   >> 366 
                                                   >> 367     G4bool existsAfterClip=false;
                                                   >> 368     G4ThreeVectorList *vertices;
397                                                   369 
398   std::vector<const G4ThreeVectorList *> polyg << 370     pMin=+kInfinity;
399   polygons[0] = &baseA;                        << 371     pMax=-kInfinity;
400   polygons[1] = &baseB;                        << 
401                                                   372 
402   G4BoundingEnvelope benv(bmin,bmax,polygons); << 373     // Calculate rotated vertex coordinates
403   exist = benv.CalculateExtent(pAxis,pVoxelLim << 374 
404   return exist;                                << 375     vertices=CreateRotatedVertices(pTransform);
                                                   >> 376     ClipCrossSection(vertices,0,pVoxelLimit,pAxis,pMin,pMax);
                                                   >> 377     ClipCrossSection(vertices,4,pVoxelLimit,pAxis,pMin,pMax);
                                                   >> 378     ClipBetweenSections(vertices,0,pVoxelLimit,pAxis,pMin,pMax);
                                                   >> 379       
                                                   >> 380     if (pMin!=kInfinity||pMax!=-kInfinity)
                                                   >> 381     {
                                                   >> 382       existsAfterClip=true;
                                                   >> 383         
                                                   >> 384       // Add 2*tolerance to avoid precision troubles
                                                   >> 385       //
                                                   >> 386       pMin-=kCarTolerance;
                                                   >> 387       pMax+=kCarTolerance;
                                                   >> 388     }
                                                   >> 389     else
                                                   >> 390     {
                                                   >> 391       // Check for case where completely enveloping clipping volume
                                                   >> 392       // If point inside then we are confident that the solid completely
                                                   >> 393       // envelopes the clipping volume. Hence set min/max extents according
                                                   >> 394       // to clipping volume extents along the specified axis.
                                                   >> 395        
                                                   >> 396       G4ThreeVector clipCentre(
                                                   >> 397         (pVoxelLimit.GetMinXExtent()+pVoxelLimit.GetMaxXExtent())*0.5,
                                                   >> 398         (pVoxelLimit.GetMinYExtent()+pVoxelLimit.GetMaxYExtent())*0.5,
                                                   >> 399         (pVoxelLimit.GetMinZExtent()+pVoxelLimit.GetMaxZExtent())*0.5);
                                                   >> 400         
                                                   >> 401       if (Inside(pTransform.Inverse().TransformPoint(clipCentre))!=kOutside)
                                                   >> 402       {
                                                   >> 403         existsAfterClip=true;
                                                   >> 404         pMin=pVoxelLimit.GetMinExtent(pAxis);
                                                   >> 405         pMax=pVoxelLimit.GetMaxExtent(pAxis);
                                                   >> 406       }
                                                   >> 407     }
                                                   >> 408     delete vertices ;          //  'new' in the function called
                                                   >> 409     flag = existsAfterClip ;
                                                   >> 410   }
                                                   >> 411   return flag;
405 }                                                 412 }
406                                                   413 
407 ////////////////////////////////////////////// << 414 /////////////////////////////////////////////////////////////////////////////
408 //                                             << 
409 // Determine where is point p, inside/on_surfa << 
410 //                                                415 //
                                                   >> 416 // Check in p is inside/on surface/outside solid
411                                                   417 
412 EInside G4Para::Inside( const G4ThreeVector& p    418 EInside G4Para::Inside( const G4ThreeVector& p ) const
413 {                                                 419 {
414   G4double xx = fPlanes[2].a*p.x()+fPlanes[2]. << 420   G4double xt, yt, yt1;
415   G4double dx = std::abs(xx) + fPlanes[2].d;   << 421   EInside  in = kOutside;
                                                   >> 422 
                                                   >> 423   yt1 = p.y() - fTthetaSphi*p.z();
                                                   >> 424   yt  = std::fabs(yt1) ;
416                                                   425 
417   G4double yy = fPlanes[0].b*p.y()+fPlanes[0]. << 426   // xt = std::fabs( p.x() - fTthetaCphi*p.z() - fTalpha*yt );
418   G4double dy = std::abs(yy) + fPlanes[0].d;   << 
419   G4double dxy = std::max(dx,dy);              << 
420                                                   427 
421   G4double dz = std::abs(p.z())-fDz;           << 428   xt = std::fabs( p.x() - fTthetaCphi*p.z() - fTalpha*yt1 );
422   G4double dist = std::max(dxy,dz);            << 
423                                                   429 
424   if (dist > halfCarTolerance) return kOutside << 430   if ( std::fabs( p.z() ) <= fDz - kCarTolerance*0.5)
425   return (dist > -halfCarTolerance) ? kSurface << 431   {
                                                   >> 432     if (yt <= fDy - kCarTolerance*0.5)
                                                   >> 433     {
                                                   >> 434       if      ( xt <= fDx - kCarTolerance*0.5 ) in = kInside;
                                                   >> 435       else if ( xt <= fDx + kCarTolerance*0.5 ) in = kSurface;
                                                   >> 436     }
                                                   >> 437     else if ( yt <= fDy + kCarTolerance*0.5)
                                                   >> 438     {
                                                   >> 439       if ( xt <= fDx + kCarTolerance*0.5 ) in = kSurface;  
                                                   >> 440     }
                                                   >> 441   }
                                                   >> 442   else  if ( std::fabs(p.z()) <= fDz + kCarTolerance*0.5 )
                                                   >> 443   {
                                                   >> 444     if ( yt <= fDy + kCarTolerance*0.5)
                                                   >> 445     {
                                                   >> 446       if ( xt <= fDx + kCarTolerance*0.5 ) in = kSurface;  
                                                   >> 447     }
                                                   >> 448   }
                                                   >> 449   return in;
426 }                                                 450 }
427                                                   451 
428 ////////////////////////////////////////////// << 452 ///////////////////////////////////////////////////////////////////////////
429 //                                                453 //
430 // Determine side where point is, and return c << 454 // Calculate side nearest to p, and return normal
                                                   >> 455 // If 2+ sides equidistant, first side's normal returned (arbitrarily)
431                                                   456 
432 G4ThreeVector G4Para::SurfaceNormal( const G4T    457 G4ThreeVector G4Para::SurfaceNormal( const G4ThreeVector& p ) const
433 {                                                 458 {
434   G4int nsurf = 0; // number of surfaces where << 459   G4ThreeVector norm, sumnorm(0.,0.,0.);
                                                   >> 460   G4int noSurfaces = 0; 
                                                   >> 461   G4double distx,disty,distz;
                                                   >> 462   G4double newpx,newpy,xshift;
                                                   >> 463   G4double calpha,salpha;      // Sin/Cos(alpha) - needed to recalc G4Parameter
                                                   >> 464   G4double tntheta,cosntheta;  // tan and cos of normal's theta component
                                                   >> 465   G4double ycomp;
                                                   >> 466   G4double delta = 0.5*kCarTolerance;
                                                   >> 467 
                                                   >> 468   newpx  = p.x()-fTthetaCphi*p.z();
                                                   >> 469   newpy  = p.y()-fTthetaSphi*p.z();
                                                   >> 470 
                                                   >> 471   calpha = 1/std::sqrt(1+fTalpha*fTalpha);
                                                   >> 472   if (fTalpha) {salpha = -calpha/fTalpha;} // NOTE: using MINUS std::sin(alpha)
                                                   >> 473   else         {salpha = 0.;}
                                                   >> 474   
                                                   >> 475   //  xshift = newpx*calpha+newpy*salpha;
                                                   >> 476   xshift = newpx - newpy*fTalpha;
435                                                   477 
436   // Check Z faces                             << 478   //  distx  = std::fabs(std::fabs(xshift)-fDx*calpha);
437   //                                           << 479   distx  = std::fabs(std::fabs(xshift)-fDx);
438   G4double nz = 0;                             << 480   disty  = std::fabs(std::fabs(newpy)-fDy);
439   G4double dz = std::abs(p.z()) - fDz;         << 481   distz  = std::fabs(std::fabs(p.z())-fDz);
440   if (std::abs(dz) <= halfCarTolerance)        << 
441   {                                            << 
442     nz = (p.z() < 0) ? -1 : 1;                 << 
443     ++nsurf;                                   << 
444   }                                            << 
445                                                   482 
446   // Check Y faces                             << 483   tntheta   = fTthetaCphi*calpha + fTthetaSphi*salpha;
447   //                                           << 484   cosntheta = 1/std::sqrt(1+tntheta*tntheta);
448   G4double ny = 0;                             << 485   ycomp     = 1/std::sqrt(1+fTthetaSphi*fTthetaSphi);
449   G4double yy = fPlanes[0].b*p.y()+fPlanes[0]. << 486 
450   if (std::abs(fPlanes[0].d + yy) <= halfCarTo << 487   G4ThreeVector nX  = G4ThreeVector( calpha*cosntheta,
451   {                                            << 488                                      salpha*cosntheta,
452     ny  = fPlanes[0].b;                        << 489                                     -tntheta*cosntheta);
453     nz += fPlanes[0].c;                        << 490   G4ThreeVector nY  = G4ThreeVector( 0, ycomp,-fTthetaSphi*ycomp);
454     ++nsurf;                                   << 491   G4ThreeVector nZ  = G4ThreeVector( 0, 0,  1.0);
455   }                                            << 492 
456   else if (std::abs(fPlanes[1].d - yy) <= half << 493   if (distx <= delta)      
457   {                                               494   {
458     ny  = fPlanes[1].b;                        << 495     noSurfaces ++;
459     nz += fPlanes[1].c;                        << 496     if ( xshift >= 0.) {sumnorm += nX;}
460     ++nsurf;                                   << 497     else               {sumnorm -= nX;}
461   }                                               498   }
462                                                << 499   if (disty <= delta)
463   // Check X faces                             << 
464   //                                           << 
465   G4double nx = 0;                             << 
466   G4double xx = fPlanes[2].a*p.x()+fPlanes[2]. << 
467   if (std::abs(fPlanes[2].d + xx) <= halfCarTo << 
468   {                                               500   {
469     nx  = fPlanes[2].a;                        << 501     noSurfaces ++;
470     ny += fPlanes[2].b;                        << 502     if ( newpy >= 0.)  {sumnorm += nY;}
471     nz += fPlanes[2].c;                        << 503     else               {sumnorm -= nY;}
472     ++nsurf;                                   << 
473   }                                               504   }
474   else if (std::abs(fPlanes[3].d - xx) <= half << 505   if (distz <= delta)  
475   {                                               506   {
476     nx  = fPlanes[3].a;                        << 507     noSurfaces ++;
477     ny += fPlanes[3].b;                        << 508     if ( p.z() >= 0.)  {sumnorm += nZ;}
478     nz += fPlanes[3].c;                        << 509     else               {sumnorm -= nZ;}
479     ++nsurf;                                   << 
480   }                                               510   }
481                                                << 511   if ( noSurfaces == 0 )
482   // Return normal                             << 
483   //                                           << 
484   if (nsurf == 1)      return {nx,ny,nz};      << 
485   else if (nsurf != 0) return G4ThreeVector(nx << 
486   else                                         << 
487   {                                               512   {
488     // Point is not on the surface             << 
489     //                                         << 
490 #ifdef G4CSGDEBUG                                 513 #ifdef G4CSGDEBUG
491     std::ostringstream message;                << 514     G4Exception("G4Para::SurfaceNormal(p)", "Notification", JustWarning, 
492     G4int oldprc = message.precision(16);      << 515                 "Point p is not on surface !?" );
493     message << "Point p is not on surface (!?) << 516 #endif 
494             << GetName() << G4endl;            << 517      norm = ApproxSurfaceNormal(p);
495     message << "Position:\n";                  << 
496     message << "   p.x() = " << p.x()/mm << "  << 
497     message << "   p.y() = " << p.y()/mm << "  << 
498     message << "   p.z() = " << p.z()/mm << "  << 
499     G4cout.precision(oldprc) ;                 << 
500     G4Exception("G4Para::SurfaceNormal(p)", "G << 
501                 JustWarning, message );        << 
502     DumpInfo();                                << 
503 #endif                                         << 
504     return ApproxSurfaceNormal(p);             << 
505   }                                               518   }
                                                   >> 519   else if ( noSurfaces == 1 ) {norm = sumnorm;}
                                                   >> 520   else                        {norm = sumnorm.unit();}
                                                   >> 521 
                                                   >> 522   return norm;
506 }                                                 523 }
507                                                   524 
508 ////////////////////////////////////////////// << 525 
                                                   >> 526 ////////////////////////////////////////////////////////////////////////
509 //                                                527 //
510 // Algorithm for SurfaceNormal() following the    528 // Algorithm for SurfaceNormal() following the original specification
511 // for points not on the surface                  529 // for points not on the surface
512                                                   530 
513 G4ThreeVector G4Para::ApproxSurfaceNormal( con    531 G4ThreeVector G4Para::ApproxSurfaceNormal( const G4ThreeVector& p ) const
514 {                                                 532 {
515   G4double dist = -DBL_MAX;                    << 533   ENSide  side;
516   G4int iside = 0;                             << 534   G4ThreeVector norm;
517   for (G4int i=0; i<4; ++i)                    << 535   G4double distx,disty,distz;
                                                   >> 536   G4double newpx,newpy,xshift;
                                                   >> 537   G4double calpha,salpha;  // Sin/Cos(alpha) - needed to recalc G4Parameter 
                                                   >> 538   G4double tntheta,cosntheta;  // tan and cos of normal's theta component
                                                   >> 539   G4double ycomp;
                                                   >> 540 
                                                   >> 541   newpx=p.x()-fTthetaCphi*p.z();
                                                   >> 542   newpy=p.y()-fTthetaSphi*p.z();
                                                   >> 543 
                                                   >> 544   calpha=1/std::sqrt(1+fTalpha*fTalpha);
                                                   >> 545   if (fTalpha)
                                                   >> 546   {
                                                   >> 547     salpha=-calpha/fTalpha;  // NOTE: actually use MINUS std::sin(alpha)
                                                   >> 548   }
                                                   >> 549   else
518   {                                               550   {
519     G4double d = fPlanes[i].a*p.x() +          << 551     salpha=0;
520                  fPlanes[i].b*p.y() +          << 
521                  fPlanes[i].c*p.z() + fPlanes[ << 
522     if (d > dist) { dist = d; iside = i; }     << 
523   }                                               552   }
524                                                   553 
525   G4double distz = std::abs(p.z()) - fDz;      << 554   xshift=newpx*calpha+newpy*salpha;
526   if (dist > distz)                            << 555 
527     return { fPlanes[iside].a, fPlanes[iside]. << 556   distx=std::fabs(std::fabs(xshift)-fDx*calpha);
                                                   >> 557   disty=std::fabs(std::fabs(newpy)-fDy);
                                                   >> 558   distz=std::fabs(std::fabs(p.z())-fDz);
                                                   >> 559     
                                                   >> 560   if (distx<disty)
                                                   >> 561   {
                                                   >> 562     if (distx<distz) {side=kNX;}
                                                   >> 563     else {side=kNZ;}
                                                   >> 564   }
528   else                                            565   else
529     return { 0, 0, (G4double)((p.z() < 0) ? -1 << 566   {
                                                   >> 567     if (disty<distz) {side=kNY;}
                                                   >> 568     else {side=kNZ;}
                                                   >> 569   }
                                                   >> 570 
                                                   >> 571   switch (side)
                                                   >> 572   {
                                                   >> 573     case kNX:
                                                   >> 574       tntheta=fTthetaCphi*calpha+fTthetaSphi*salpha;
                                                   >> 575       if (xshift<0)
                                                   >> 576       {
                                                   >> 577         cosntheta=-1/std::sqrt(1+tntheta*tntheta);
                                                   >> 578       }
                                                   >> 579       else
                                                   >> 580       {
                                                   >> 581         cosntheta=1/std::sqrt(1+tntheta*tntheta);
                                                   >> 582       }
                                                   >> 583       norm=G4ThreeVector(calpha*cosntheta,salpha*cosntheta,-tntheta*cosntheta);
                                                   >> 584       break;
                                                   >> 585     case kNY:
                                                   >> 586       if (newpy<0)
                                                   >> 587       {
                                                   >> 588         ycomp=-1/std::sqrt(1+fTthetaSphi*fTthetaSphi);
                                                   >> 589       }
                                                   >> 590       else
                                                   >> 591       {
                                                   >> 592         ycomp=1/std::sqrt(1+fTthetaSphi*fTthetaSphi);
                                                   >> 593       }
                                                   >> 594       norm=G4ThreeVector(0,ycomp,-fTthetaSphi*ycomp);
                                                   >> 595       break;
                                                   >> 596     case kNZ:           // Closest to Z
                                                   >> 597       if (p.z()>=0)
                                                   >> 598       {
                                                   >> 599         norm=G4ThreeVector(0,0,1);
                                                   >> 600       }
                                                   >> 601       else
                                                   >> 602       {
                                                   >> 603         norm=G4ThreeVector(0,0,-1);
                                                   >> 604       }
                                                   >> 605       break;
                                                   >> 606   }
                                                   >> 607   return norm;
530 }                                                 608 }
531                                                   609 
532 ////////////////////////////////////////////// << 610 //////////////////////////////////////////////////////////////////////////////
533 //                                                611 //
534 // Calculate distance to shape from outside       612 // Calculate distance to shape from outside
535 //  - return kInfinity if no intersection      << 613 // - return kInfinity if no intersection
536                                                << 614 //
537 G4double G4Para::DistanceToIn(const G4ThreeVec << 615 // ALGORITHM:
538                               const G4ThreeVec << 616 // For each component, calculate pair of minimum and maximum intersection
539 {                                              << 617 // values for which the particle is in the extent of the shape
540   // Z intersections                           << 618 // - The smallest (MAX minimum) allowed distance of the pairs is intersect
                                                   >> 619 // - Z plane intersectin uses tolerance
                                                   >> 620 // - XZ YZ planes use logic & *SLIGHTLY INCORRECT* tolerance
                                                   >> 621 //   (this saves at least 1 sqrt, 1 multiply and 1 divide... in applicable
                                                   >> 622 //    cases)
                                                   >> 623 // - Note: XZ and YZ planes each divide space into four regions,
                                                   >> 624 //   characterised by ss1 ss2
                                                   >> 625 
                                                   >> 626 G4double G4Para::DistanceToIn( const G4ThreeVector& p,
                                                   >> 627                                const G4ThreeVector& v ) const
                                                   >> 628 {
                                                   >> 629   G4double snxt;    // snxt = default return value
                                                   >> 630   G4double smin,smax;
                                                   >> 631   G4double tmin,tmax;
                                                   >> 632   G4double yt,vy,xt,vx;
                                                   >> 633   G4double max;
541   //                                              634   //
542   if ((std::abs(p.z()) - fDz) >= -halfCarToler << 635   // Z Intersection range
543     return kInfinity;                          << 
544   G4double invz = (-v.z() == 0) ? DBL_MAX : -1 << 
545   G4double dz = (invz < 0) ? fDz : -fDz;       << 
546   G4double tzmin = (p.z() + dz)*invz;          << 
547   G4double tzmax = (p.z() - dz)*invz;          << 
548                                                << 
549   // Y intersections                           << 
550   //                                              636   //
551   G4double tmin0 = tzmin, tmax0 = tzmax;       << 637   if (v.z()>0)
552   G4double cos0 = fPlanes[0].b*v.y() + fPlanes << 
553   G4double disy = fPlanes[0].b*p.y() + fPlanes << 
554   G4double dis0 = fPlanes[0].d + disy;         << 
555   if (dis0 >= -halfCarTolerance)               << 
556   {                                               638   {
557     if (cos0 >= 0) return kInfinity;           << 639     max=fDz-p.z();
558     G4double tmp  = -dis0/cos0;                << 640     if (max>kCarTolerance*0.5)
559     if (tmin0 < tmp) tmin0 = tmp;              << 641     {
                                                   >> 642       smax=max/v.z();
                                                   >> 643       smin=(-fDz-p.z())/v.z();
                                                   >> 644     }
                                                   >> 645     else
                                                   >> 646     {
                                                   >> 647       return snxt=kInfinity;
                                                   >> 648     }
560   }                                               649   }
561   else if (cos0 > 0)                           << 650   else if (v.z()<0)
                                                   >> 651   {
                                                   >> 652     max=-fDz-p.z();
                                                   >> 653     if (max<-kCarTolerance*0.5)
                                                   >> 654     {
                                                   >> 655       smax=max/v.z();
                                                   >> 656       smin=(fDz-p.z())/v.z();
                                                   >> 657     }
                                                   >> 658     else
                                                   >> 659     {
                                                   >> 660       return snxt=kInfinity;
                                                   >> 661     }
                                                   >> 662   }
                                                   >> 663   else
562   {                                               664   {
563     G4double tmp  = -dis0/cos0;                << 665     if (std::fabs(p.z())<=fDz) // Inside
564     if (tmax0 > tmp) tmax0 = tmp;              << 666     {
                                                   >> 667       smin=0;
                                                   >> 668       smax=kInfinity;
                                                   >> 669     }
                                                   >> 670     else
                                                   >> 671     {
                                                   >> 672       return snxt=kInfinity;
                                                   >> 673     }
565   }                                               674   }
                                                   >> 675     
                                                   >> 676   //
                                                   >> 677   // Y G4Parallel planes intersection
                                                   >> 678   //
                                                   >> 679 
                                                   >> 680   yt=p.y()-fTthetaSphi*p.z();
                                                   >> 681   vy=v.y()-fTthetaSphi*v.z();
566                                                   682 
567   G4double tmin1 = tmin0, tmax1 = tmax0;       << 683   if (vy>0)
568   G4double cos1 = -cos0;                       << 
569   G4double dis1 = fPlanes[1].d - disy;         << 
570   if (dis1 >= -halfCarTolerance)               << 
571   {                                               684   {
572     if (cos1 >= 0) return kInfinity;           << 685     max=fDy-yt;
573     G4double tmp  = -dis1/cos1;                << 686     if (max>kCarTolerance*0.5)
574     if (tmin1 < tmp) tmin1 = tmp;              << 687     {
                                                   >> 688       tmax=max/vy;
                                                   >> 689       tmin=(-fDy-yt)/vy;
                                                   >> 690     }
                                                   >> 691     else
                                                   >> 692     {
                                                   >> 693       return snxt=kInfinity;
                                                   >> 694     }
575   }                                               695   }
576   else if (cos1 > 0)                           << 696   else if (vy<0)
577   {                                               697   {
578     G4double tmp  = -dis1/cos1;                << 698     max=-fDy-yt;
579     if (tmax1 > tmp) tmax1 = tmp;              << 699     if (max<-kCarTolerance*0.5)
                                                   >> 700     {
                                                   >> 701       tmax=max/vy;
                                                   >> 702       tmin=(fDy-yt)/vy;
                                                   >> 703     }
                                                   >> 704     else
                                                   >> 705     {
                                                   >> 706       return snxt=kInfinity;
                                                   >> 707     }
                                                   >> 708   }
                                                   >> 709   else
                                                   >> 710   {
                                                   >> 711     if (std::fabs(yt)<=fDy)
                                                   >> 712     {
                                                   >> 713       tmin=0;
                                                   >> 714       tmax=kInfinity;
                                                   >> 715     }
                                                   >> 716     else
                                                   >> 717     {
                                                   >> 718       return snxt=kInfinity;
                                                   >> 719     }
580   }                                               720   }
581                                                   721 
582   // X intersections                           << 722   // Re-Calc valid intersection range
583   //                                              723   //
584   G4double tmin2 = tmin1, tmax2 = tmax1;       << 724   if (tmin>smin) smin=tmin;
585   G4double cos2 = fPlanes[2].a*v.x() + fPlanes << 725   if (tmax<smax) smax=tmax;
586   G4double disx = fPlanes[2].a*p.x() + fPlanes << 726   if (smax<=smin)
587   G4double dis2 = fPlanes[2].d + disx;         << 
588   if (dis2 >= -halfCarTolerance)               << 
589   {                                               727   {
590     if (cos2 >= 0) return kInfinity;           << 728     return snxt=kInfinity;
591     G4double tmp  = -dis2/cos2;                << 
592     if (tmin2 < tmp) tmin2 = tmp;              << 
593   }                                               729   }
594   else if (cos2 > 0)                           << 730   else
595   {                                               731   {
596     G4double tmp  = -dis2/cos2;                << 732     //
597     if (tmax2 > tmp) tmax2 = tmp;              << 733     // X G4Parallel planes intersection
                                                   >> 734     //
                                                   >> 735     xt=p.x()-fTthetaCphi*p.z()-fTalpha*yt;
                                                   >> 736     vx=v.x()-fTthetaCphi*v.z()-fTalpha*vy;
                                                   >> 737     if (vx>0)
                                                   >> 738     {
                                                   >> 739       max=fDx-xt;
                                                   >> 740       if (max>kCarTolerance*0.5)
                                                   >> 741       {
                                                   >> 742         tmax=max/vx;
                                                   >> 743         tmin=(-fDx-xt)/vx;
                                                   >> 744       }
                                                   >> 745       else
                                                   >> 746       {
                                                   >> 747         return snxt=kInfinity;
                                                   >> 748       }
                                                   >> 749     }
                                                   >> 750     else if (vx<0)
                                                   >> 751     {
                                                   >> 752       max=-fDx-xt;
                                                   >> 753       if (max<-kCarTolerance*0.5)
                                                   >> 754       {
                                                   >> 755         tmax=max/vx;
                                                   >> 756         tmin=(fDx-xt)/vx;
                                                   >> 757       }
                                                   >> 758       else
                                                   >> 759       {
                                                   >> 760         return snxt=kInfinity;
                                                   >> 761       }
                                                   >> 762     }
                                                   >> 763     else
                                                   >> 764     {
                                                   >> 765       if (std::fabs(xt)<=fDx)
                                                   >> 766       {
                                                   >> 767         tmin=0;
                                                   >> 768         tmax=kInfinity;
                                                   >> 769       }
                                                   >> 770       else
                                                   >> 771       {
                                                   >> 772         return snxt=kInfinity;
                                                   >> 773       }
                                                   >> 774     }
                                                   >> 775     if (tmin>smin) smin=tmin;
                                                   >> 776     if (tmax<smax) smax=tmax;
598   }                                               777   }
599                                                   778 
600   G4double tmin3 = tmin2, tmax3 = tmax2;       << 779   if (smax>0&&smin<smax)
601   G4double cos3 = -cos2;                       << 
602   G4double dis3 = fPlanes[3].d - disx;         << 
603   if (dis3 >= -halfCarTolerance)               << 
604   {                                               780   {
605     if (cos3 >= 0) return kInfinity;           << 781     if (smin>0)
606     G4double tmp  = -dis3/cos3;                << 782     {
607     if (tmin3 < tmp) tmin3 = tmp;              << 783       snxt=smin;
                                                   >> 784     }
                                                   >> 785     else
                                                   >> 786     {
                                                   >> 787       snxt=0;
                                                   >> 788     }
608   }                                               789   }
609   else if (cos3 > 0)                           << 790   else
610   {                                               791   {
611     G4double tmp  = -dis3/cos3;                << 792     snxt=kInfinity;
612     if (tmax3 > tmp) tmax3 = tmp;              << 
613   }                                               793   }
614                                                << 794   return snxt;
615   // Find distance                             << 
616   //                                           << 
617   G4double tmin = tmin3, tmax = tmax3;         << 
618   if (tmax <= tmin + halfCarTolerance) return  << 
619   return (tmin < halfCarTolerance ) ? 0. : tmi << 
620 }                                                 795 }
621                                                   796 
622 ////////////////////////////////////////////// << 797 ////////////////////////////////////////////////////////////////////////////
623 //                                                798 //
624 // Calculate exact shortest distance to any bo    799 // Calculate exact shortest distance to any boundary from outside
625 // - returns 0 is point inside                 << 800 // - Returns 0 is point inside
626                                                   801 
627 G4double G4Para::DistanceToIn( const G4ThreeVe    802 G4double G4Para::DistanceToIn( const G4ThreeVector& p ) const
628 {                                                 803 {
629   G4double xx = fPlanes[2].a*p.x()+fPlanes[2]. << 804   G4double safe=0.0;
630   G4double dx = std::abs(xx) + fPlanes[2].d;   << 805   G4double distz1,distz2,disty1,disty2,distx1,distx2;
                                                   >> 806   G4double trany,cosy,tranx,cosx;
                                                   >> 807 
                                                   >> 808   // Z planes
                                                   >> 809   //
                                                   >> 810   distz1=p.z()-fDz;
                                                   >> 811   distz2=-fDz-p.z();
                                                   >> 812   if (distz1>distz2)
                                                   >> 813   {
                                                   >> 814     safe=distz1;
                                                   >> 815   }
                                                   >> 816   else
                                                   >> 817   {
                                                   >> 818     safe=distz2;
                                                   >> 819   }
631                                                   820 
632   G4double yy = fPlanes[0].b*p.y()+fPlanes[0]. << 821   trany=p.y()-fTthetaSphi*p.z(); // Transformed y into `box' system
633   G4double dy = std::abs(yy) + fPlanes[0].d;   << 
634   G4double dxy = std::max(dx,dy);              << 
635                                                   822 
636   G4double dz = std::abs(p.z())-fDz;           << 823   // Transformed x into `box' system
637   G4double dist = std::max(dxy,dz);            << 824   //
                                                   >> 825   cosy=1.0/std::sqrt(1.0+fTthetaSphi*fTthetaSphi);
                                                   >> 826   disty1=(trany-fDy)*cosy;
                                                   >> 827   disty2=(-fDy-trany)*cosy;
                                                   >> 828     
                                                   >> 829   if (disty1>safe) safe=disty1;
                                                   >> 830   if (disty2>safe) safe=disty2;
638                                                   831 
639   return (dist > 0) ? dist : 0.;               << 832   tranx=p.x()-fTthetaCphi*p.z()-fTalpha*trany;
                                                   >> 833   cosx=1.0/std::sqrt(1.0+fTalpha*fTalpha+fTthetaCphi*fTthetaCphi);
                                                   >> 834   distx1=(tranx-fDx)*cosx;
                                                   >> 835   distx2=(-fDx-tranx)*cosx;
                                                   >> 836     
                                                   >> 837   if (distx1>safe) safe=distx1;
                                                   >> 838   if (distx2>safe) safe=distx2;
                                                   >> 839     
                                                   >> 840   if (safe<0) safe=0;
                                                   >> 841   return safe;  
640 }                                                 842 }
641                                                   843 
642 //////////////////////////////////////////////    844 //////////////////////////////////////////////////////////////////////////
643 //                                                845 //
644 // Calculate distance to surface of shape from << 846 // Calculate distance to surface of shape from inside
645 // find normal at exit point                   << 847 // Calculate distance to x/y/z planes - smallest is exiting distance
646 // - when leaving the surface, return 0        << 
647                                                   848 
648 G4double G4Para::DistanceToOut(const G4ThreeVe    849 G4double G4Para::DistanceToOut(const G4ThreeVector& p, const G4ThreeVector& v,
649                                const G4bool ca    850                                const G4bool calcNorm,
650                                      G4bool* v << 851                                G4bool *validNorm, G4ThreeVector *n) const
651 {                                                 852 {
652   // Z intersections                           << 853   ESide side = kUndef;
                                                   >> 854   G4double snxt;    // snxt = return value
                                                   >> 855   G4double max,tmax;
                                                   >> 856   G4double yt,vy,xt,vx;
                                                   >> 857 
                                                   >> 858   G4double ycomp,calpha,salpha,tntheta,cosntheta;
                                                   >> 859 
                                                   >> 860   //
                                                   >> 861   // Z Intersections
653   //                                              862   //
654   if ((std::abs(p.z()) - fDz) >= -halfCarToler << 863 
                                                   >> 864   if (v.z()>0)
655   {                                               865   {
656     if (calcNorm)                              << 866     max=fDz-p.z();
                                                   >> 867     if (max>kCarTolerance*0.5)
657     {                                             868     {
658       *validNorm = true;                       << 869       snxt=max/v.z();
659       n->set(0, 0, (p.z() < 0) ? -1 : 1);      << 870       side=kPZ;
                                                   >> 871     }
                                                   >> 872     else
                                                   >> 873     {
                                                   >> 874       if (calcNorm)
                                                   >> 875       {
                                                   >> 876         *validNorm=true;
                                                   >> 877         *n=G4ThreeVector(0,0,1);
                                                   >> 878       }
                                                   >> 879       return snxt=0;
660     }                                             880     }
661     return 0.;                                 << 
662   }                                               881   }
663   G4double vz = v.z();                         << 882   else if (v.z()<0)
664   G4double tmax = (vz == 0) ? DBL_MAX : (std:: << 
665   G4int iside = (vz < 0) ? -4 : -2; // little  << 
666                                                << 
667   // Y intersections                           << 
668   //                                           << 
669   G4double cos0 = fPlanes[0].b*v.y() + fPlanes << 
670   if (cos0 > 0)                                << 
671   {                                               883   {
672     G4double dis0 = fPlanes[0].b*p.y() + fPlan << 884     max=-fDz-p.z();
673     if (dis0 >= -halfCarTolerance)             << 885     if (max<-kCarTolerance*0.5)
                                                   >> 886     {
                                                   >> 887       snxt=max/v.z();
                                                   >> 888       side=kMZ;
                                                   >> 889     }
                                                   >> 890     else
674     {                                             891     {
675       if (calcNorm)                               892       if (calcNorm)
676       {                                           893       {
677         *validNorm = true;                     << 894         *validNorm=true;
678         n->set(0, fPlanes[0].b, fPlanes[0].c); << 895         *n=G4ThreeVector(0,0,-1);
679       }                                           896       }
680       return 0.;                               << 897       return snxt=0;
681     }                                             898     }
682     G4double tmp = -dis0/cos0;                 << 
683     if (tmax > tmp) { tmax = tmp; iside = 0; } << 
684   }                                               899   }
                                                   >> 900   else
                                                   >> 901   {
                                                   >> 902     snxt=kInfinity;
                                                   >> 903   }
                                                   >> 904     
                                                   >> 905   //
                                                   >> 906   // Y plane intersection
                                                   >> 907   //
                                                   >> 908 
                                                   >> 909   yt=p.y()-fTthetaSphi*p.z();
                                                   >> 910   vy=v.y()-fTthetaSphi*v.z();
685                                                   911 
686   G4double cos1 = -cos0;                       << 912   if (vy>0)
687   if (cos1 > 0)                                << 913   {
                                                   >> 914     max=fDy-yt;
                                                   >> 915     if (max>kCarTolerance*0.5)
                                                   >> 916     {
                                                   >> 917       tmax=max/vy;
                                                   >> 918       if (tmax<snxt)
                                                   >> 919       {
                                                   >> 920         snxt=tmax;
                                                   >> 921         side=kPY;
                                                   >> 922       }
                                                   >> 923     }
                                                   >> 924     else
                                                   >> 925     {
                                                   >> 926       if (calcNorm)
                                                   >> 927       {      
                                                   >> 928         *validNorm=true; // Leaving via plus Y
                                                   >> 929         ycomp=1/std::sqrt(1+fTthetaSphi*fTthetaSphi);
                                                   >> 930         *n=G4ThreeVector(0,ycomp,-fTthetaSphi*ycomp);
                                                   >> 931       }
                                                   >> 932       return snxt=0;
                                                   >> 933     }
                                                   >> 934   }
                                                   >> 935   else if (vy<0)
688   {                                               936   {
689     G4double dis1 = fPlanes[1].b*p.y() + fPlan << 937     max=-fDy-yt;
690     if (dis1 >= -halfCarTolerance)             << 938     if (max<-kCarTolerance*0.5)
                                                   >> 939     {
                                                   >> 940       tmax=max/vy;
                                                   >> 941       if (tmax<snxt)
                                                   >> 942       {
                                                   >> 943         snxt=tmax;
                                                   >> 944         side=kMY;
                                                   >> 945       }
                                                   >> 946     }
                                                   >> 947     else
691     {                                             948     {
692       if (calcNorm)                               949       if (calcNorm)
693       {                                           950       {
694         *validNorm = true;                     << 951         *validNorm=true; // Leaving via minus Y
695         n->set(0, fPlanes[1].b, fPlanes[1].c); << 952         ycomp=-1/std::sqrt(1+fTthetaSphi*fTthetaSphi);
                                                   >> 953         *n=G4ThreeVector(0,ycomp,-fTthetaSphi*ycomp);
696       }                                           954       }
697       return 0.;                               << 955       return snxt=0;
698     }                                             956     }
699     G4double tmp = -dis1/cos1;                 << 
700     if (tmax > tmp) { tmax = tmp; iside = 1; } << 
701   }                                               957   }
702                                                   958 
703   // X intersections                           << 
704   //                                              959   //
705   G4double cos2 = fPlanes[2].a*v.x() + fPlanes << 960   // X plane intersection
706   if (cos2 > 0)                                << 961   //
                                                   >> 962 
                                                   >> 963   xt=p.x()-fTthetaCphi*p.z()-fTalpha*yt;
                                                   >> 964   vx=v.x()-fTthetaCphi*v.z()-fTalpha*vy;
                                                   >> 965   if (vx>0)
707   {                                               966   {
708     G4double dis2 = fPlanes[2].a*p.x()+fPlanes << 967     max=fDx-xt;
709     if (dis2 >= -halfCarTolerance)             << 968     if (max>kCarTolerance*0.5)
                                                   >> 969     {
                                                   >> 970       tmax=max/vx;
                                                   >> 971       if (tmax<snxt)
                                                   >> 972       {
                                                   >> 973         snxt=tmax;
                                                   >> 974         side=kPX;
                                                   >> 975       }
                                                   >> 976     }
                                                   >> 977     else
710     {                                             978     {
711       if (calcNorm)                               979       if (calcNorm)
712       {                                           980       {
713          *validNorm = true;                    << 981         *validNorm=true; // Leaving via plus X
714          n->set(fPlanes[2].a, fPlanes[2].b, fP << 982         calpha=1/std::sqrt(1+fTalpha*fTalpha);
                                                   >> 983         if (fTalpha)
                                                   >> 984         {
                                                   >> 985           salpha=-calpha/fTalpha;  // NOTE: actually use MINUS std::sin(alpha)
                                                   >> 986         }
                                                   >> 987         else
                                                   >> 988         {
                                                   >> 989           salpha=0;
                                                   >> 990         }
                                                   >> 991         tntheta=fTthetaCphi*calpha+fTthetaSphi*salpha;
                                                   >> 992         cosntheta=1/std::sqrt(1+tntheta*tntheta);
                                                   >> 993         *n=G4ThreeVector(calpha*cosntheta,salpha*cosntheta,-tntheta*cosntheta);
715       }                                           994       }
716       return 0.;                               << 995       return snxt=0;
717     }                                             996     }
718     G4double tmp = -dis2/cos2;                 << 
719     if (tmax > tmp) { tmax = tmp; iside = 2; } << 
720   }                                               997   }
721                                                << 998   else if (vx<0)
722   G4double cos3 = -cos2;                       << 
723   if (cos3 > 0)                                << 
724   {                                               999   {
725     G4double dis3 = fPlanes[3].a*p.x()+fPlanes << 1000     max=-fDx-xt;
726     if (dis3 >= -halfCarTolerance)             << 1001     if (max<-kCarTolerance*0.5)
                                                   >> 1002     {
                                                   >> 1003       tmax=max/vx;
                                                   >> 1004       if (tmax<snxt)
                                                   >> 1005       {
                                                   >> 1006         snxt=tmax;
                                                   >> 1007         side=kMX;
                                                   >> 1008       }
                                                   >> 1009     }
                                                   >> 1010     else
727     {                                             1011     {
728       if (calcNorm)                               1012       if (calcNorm)
729       {                                           1013       {
730          *validNorm = true;                    << 1014         *validNorm=true; // Leaving via minus X
731          n->set(fPlanes[3].a, fPlanes[3].b, fP << 1015         calpha=1/std::sqrt(1+fTalpha*fTalpha);
                                                   >> 1016         if (fTalpha)
                                                   >> 1017         {
                                                   >> 1018           salpha=-calpha/fTalpha;  // NOTE: actually use MINUS std::sin(alpha)
                                                   >> 1019         }
                                                   >> 1020         else
                                                   >> 1021         {
                                                   >> 1022           salpha=0;
                                                   >> 1023         }
                                                   >> 1024         tntheta=fTthetaCphi*calpha+fTthetaSphi*salpha;
                                                   >> 1025         cosntheta=-1/std::sqrt(1+tntheta*tntheta);
                                                   >> 1026         *n=G4ThreeVector(calpha*cosntheta,salpha*cosntheta,-tntheta*cosntheta);
732       }                                           1027       }
733       return 0.;                               << 1028       return snxt=0;
734     }                                             1029     }
735     G4double tmp = -dis3/cos3;                 << 
736     if (tmax > tmp) { tmax = tmp; iside = 3; } << 
737   }                                               1030   }
738                                                   1031 
739   // Set normal, if required, and return dista << 1032   if (calcNorm)
740   //                                           << 
741   if (calcNorm)                                << 
742   {                                               1033   {
743     *validNorm = true;                         << 1034     *validNorm=true;
744     if (iside < 0)                             << 1035     switch (side)
745       n->set(0, 0, iside + 3); // (-4+3)=-1, ( << 1036     {
746     else                                       << 1037       case kMZ:
747       n->set(fPlanes[iside].a, fPlanes[iside]. << 1038         *n=G4ThreeVector(0,0,-1);
                                                   >> 1039         break;
                                                   >> 1040       case kPZ:
                                                   >> 1041         *n=G4ThreeVector(0,0,1);
                                                   >> 1042         break;
                                                   >> 1043       case kMY:
                                                   >> 1044         ycomp=-1/std::sqrt(1+fTthetaSphi*fTthetaSphi);
                                                   >> 1045         *n=G4ThreeVector(0,ycomp,-fTthetaSphi*ycomp);
                                                   >> 1046         break;        
                                                   >> 1047       case kPY:
                                                   >> 1048         ycomp=1/std::sqrt(1+fTthetaSphi*fTthetaSphi);
                                                   >> 1049         *n=G4ThreeVector(0,ycomp,-fTthetaSphi*ycomp);
                                                   >> 1050         break;        
                                                   >> 1051       case kMX:
                                                   >> 1052         calpha=1/std::sqrt(1+fTalpha*fTalpha);
                                                   >> 1053         if (fTalpha)
                                                   >> 1054         {
                                                   >> 1055           salpha=-calpha/fTalpha;  // NOTE: actually use MINUS std::sin(alpha)
                                                   >> 1056         }
                                                   >> 1057         else
                                                   >> 1058         {
                                                   >> 1059           salpha=0;
                                                   >> 1060         }
                                                   >> 1061         tntheta=fTthetaCphi*calpha+fTthetaSphi*salpha;
                                                   >> 1062         cosntheta=-1/std::sqrt(1+tntheta*tntheta);
                                                   >> 1063         *n=G4ThreeVector(calpha*cosntheta,salpha*cosntheta,-tntheta*cosntheta);
                                                   >> 1064         break;
                                                   >> 1065       case kPX:
                                                   >> 1066         calpha=1/std::sqrt(1+fTalpha*fTalpha);
                                                   >> 1067         if (fTalpha)
                                                   >> 1068         {
                                                   >> 1069           salpha=-calpha/fTalpha;  // NOTE: actually use MINUS std::sin(alpha)
                                                   >> 1070         }
                                                   >> 1071         else
                                                   >> 1072         {
                                                   >> 1073           salpha=0;
                                                   >> 1074         }
                                                   >> 1075         tntheta=fTthetaCphi*calpha+fTthetaSphi*salpha;
                                                   >> 1076         cosntheta=1/std::sqrt(1+tntheta*tntheta);
                                                   >> 1077         *n=G4ThreeVector(calpha*cosntheta,salpha*cosntheta,-tntheta*cosntheta);
                                                   >> 1078         break;
                                                   >> 1079       default:
                                                   >> 1080         DumpInfo();
                                                   >> 1081         G4Exception("G4Para::DistanceToOut(p,v,..)","Notification",JustWarning,
                                                   >> 1082                     "Undefined side for valid surface normal to solid.");
                                                   >> 1083         break;
                                                   >> 1084     }
748   }                                               1085   }
749   return tmax;                                 << 1086   return snxt;
750 }                                                 1087 }
751                                                   1088 
752 ////////////////////////////////////////////// << 1089 /////////////////////////////////////////////////////////////////////////////
753 //                                                1090 //
754 // Calculate exact shortest distance to any bo    1091 // Calculate exact shortest distance to any boundary from inside
755 // - returns 0 is point outside                << 1092 // - Returns 0 is point outside
756                                                   1093 
757 G4double G4Para::DistanceToOut( const G4ThreeV    1094 G4double G4Para::DistanceToOut( const G4ThreeVector& p ) const
758 {                                                 1095 {
                                                   >> 1096   G4double safe=0.0;
                                                   >> 1097   G4double distz1,distz2,disty1,disty2,distx1,distx2;
                                                   >> 1098   G4double trany,cosy,tranx,cosx;
                                                   >> 1099 
759 #ifdef G4CSGDEBUG                                 1100 #ifdef G4CSGDEBUG
760   if( Inside(p) == kOutside )                     1101   if( Inside(p) == kOutside )
761   {                                               1102   {
762     std::ostringstream message;                << 1103      G4cout.precision(16) ;
763     G4int oldprc = message.precision(16);      << 1104      G4cout << G4endl ;
764     message << "Point p is outside (!?) of sol << 1105      DumpInfo();
765     message << "Position:\n";                  << 1106      G4cout << "Position:"  << G4endl << G4endl ;
766     message << "   p.x() = " << p.x()/mm << "  << 1107      G4cout << "p.x() = "   << p.x()/mm << " mm" << G4endl ;
767     message << "   p.y() = " << p.y()/mm << "  << 1108      G4cout << "p.y() = "   << p.y()/mm << " mm" << G4endl ;
768     message << "   p.z() = " << p.z()/mm << "  << 1109      G4cout << "p.z() = "   << p.z()/mm << " mm" << G4endl << G4endl ;
769     G4cout.precision(oldprc) ;                 << 1110      G4Exception("G4Para::DistanceToOut(p)", "Notification",
770     G4Exception("G4Para::DistanceToOut(p)", "G << 1111                  JustWarning, "Point p is outside !?" );
771                 JustWarning, message );        << 1112   }
772     DumpInfo();                                << 
773     }                                          << 
774 #endif                                            1113 #endif
775   G4double xx = fPlanes[2].a*p.x()+fPlanes[2]. << 
776   G4double dx = std::abs(xx) + fPlanes[2].d;   << 
777                                                   1114 
778   G4double yy = fPlanes[0].b*p.y()+fPlanes[0]. << 1115   // Z planes
779   G4double dy = std::abs(yy) + fPlanes[0].d;   << 1116   //
780   G4double dxy = std::max(dx,dy);              << 1117   distz1=fDz-p.z();
781                                                << 1118   distz2=fDz+p.z();
782   G4double dz = std::abs(p.z())-fDz;           << 1119   if (distz1<distz2)
783   G4double dist = std::max(dxy,dz);            << 1120   {
                                                   >> 1121     safe=distz1;
                                                   >> 1122   }
                                                   >> 1123   else
                                                   >> 1124   {
                                                   >> 1125     safe=distz2;
                                                   >> 1126   }
784                                                   1127 
785   return (dist < 0) ? -dist : 0.;              << 1128   trany=p.y()-fTthetaSphi*p.z(); // Transformed y into `box' system
786 }                                              << 
787                                                   1129 
788 ////////////////////////////////////////////// << 1130   // Transformed x into `box' system
789 //                                             << 1131   //
790 // GetEntityType                               << 1132   cosy=1.0/std::sqrt(1.0+fTthetaSphi*fTthetaSphi);
                                                   >> 1133   disty1=(fDy-trany)*cosy;
                                                   >> 1134   disty2=(fDy+trany)*cosy;
                                                   >> 1135     
                                                   >> 1136   if (disty1<safe) safe=disty1;
                                                   >> 1137   if (disty2<safe) safe=disty2;
791                                                   1138 
792 G4GeometryType G4Para::GetEntityType() const   << 1139   tranx=p.x()-fTthetaCphi*p.z()-fTalpha*trany;
793 {                                              << 1140   cosx=1.0/std::sqrt(1.0+fTalpha*fTalpha+fTthetaCphi*fTthetaCphi);
794   return {"G4Para"};                           << 1141   distx1=(fDx-tranx)*cosx;
                                                   >> 1142   distx2=(fDx+tranx)*cosx;
                                                   >> 1143     
                                                   >> 1144   if (distx1<safe) safe=distx1;
                                                   >> 1145   if (distx2<safe) safe=distx2;
                                                   >> 1146     
                                                   >> 1147   if (safe<0) safe=0;
                                                   >> 1148   return safe;  
795 }                                                 1149 }
796                                                   1150 
797 ////////////////////////////////////////////// << 1151 ////////////////////////////////////////////////////////////////////////////////
798 //                                                1152 //
799 // IsFaceted                                   << 1153 // Create a List containing the transformed vertices
800                                                << 1154 // Ordering [0-3] -fDz cross section
801 G4bool G4Para::IsFaceted() const               << 1155 //          [4-7] +fDz cross section such that [0] is below [4],
802 {                                              << 1156 //                                             [1] below [5] etc.
803   return true;                                 << 1157 // Note:
                                                   >> 1158 //  Caller has deletion resposibility
                                                   >> 1159 
                                                   >> 1160 G4ThreeVectorList*
                                                   >> 1161 G4Para::CreateRotatedVertices( const G4AffineTransform& pTransform ) const
                                                   >> 1162 {
                                                   >> 1163   G4ThreeVectorList *vertices;
                                                   >> 1164   vertices=new G4ThreeVectorList();
                                                   >> 1165   vertices->reserve(8);
                                                   >> 1166   if (vertices)
                                                   >> 1167   {
                                                   >> 1168     G4ThreeVector vertex0(-fDz*fTthetaCphi-fDy*fTalpha-fDx,
                                                   >> 1169                           -fDz*fTthetaSphi-fDy, -fDz);
                                                   >> 1170     G4ThreeVector vertex1(-fDz*fTthetaCphi-fDy*fTalpha+fDx,
                                                   >> 1171                           -fDz*fTthetaSphi-fDy, -fDz);
                                                   >> 1172     G4ThreeVector vertex2(-fDz*fTthetaCphi+fDy*fTalpha-fDx,
                                                   >> 1173                           -fDz*fTthetaSphi+fDy, -fDz);
                                                   >> 1174     G4ThreeVector vertex3(-fDz*fTthetaCphi+fDy*fTalpha+fDx,
                                                   >> 1175                           -fDz*fTthetaSphi+fDy, -fDz);
                                                   >> 1176     G4ThreeVector vertex4(+fDz*fTthetaCphi-fDy*fTalpha-fDx,
                                                   >> 1177                           +fDz*fTthetaSphi-fDy, +fDz);
                                                   >> 1178     G4ThreeVector vertex5(+fDz*fTthetaCphi-fDy*fTalpha+fDx,
                                                   >> 1179                           +fDz*fTthetaSphi-fDy, +fDz);
                                                   >> 1180     G4ThreeVector vertex6(+fDz*fTthetaCphi+fDy*fTalpha-fDx,
                                                   >> 1181                           +fDz*fTthetaSphi+fDy, +fDz);
                                                   >> 1182     G4ThreeVector vertex7(+fDz*fTthetaCphi+fDy*fTalpha+fDx,
                                                   >> 1183                           +fDz*fTthetaSphi+fDy, +fDz);
                                                   >> 1184 
                                                   >> 1185     vertices->push_back(pTransform.TransformPoint(vertex0));
                                                   >> 1186     vertices->push_back(pTransform.TransformPoint(vertex1));
                                                   >> 1187     vertices->push_back(pTransform.TransformPoint(vertex2));
                                                   >> 1188     vertices->push_back(pTransform.TransformPoint(vertex3));
                                                   >> 1189     vertices->push_back(pTransform.TransformPoint(vertex4));
                                                   >> 1190     vertices->push_back(pTransform.TransformPoint(vertex5));
                                                   >> 1191     vertices->push_back(pTransform.TransformPoint(vertex6));
                                                   >> 1192     vertices->push_back(pTransform.TransformPoint(vertex7));
                                                   >> 1193   }
                                                   >> 1194   else
                                                   >> 1195   {
                                                   >> 1196     DumpInfo();
                                                   >> 1197     G4Exception("G4Para::CreateRotatedVertices()",
                                                   >> 1198                 "FatalError", FatalException,
                                                   >> 1199                 "Error in allocation of vertices. Out of memory !");
                                                   >> 1200   }
                                                   >> 1201   return vertices;
804 }                                                 1202 }
805                                                   1203 
806 //////////////////////////////////////////////    1204 //////////////////////////////////////////////////////////////////////////
807 //                                                1205 //
808 // Make a clone of the object                  << 1206 // GetEntityType
809 //                                             << 1207 
810 G4VSolid* G4Para::Clone() const                << 1208 G4GeometryType G4Para::GetEntityType() const
811 {                                                 1209 {
812   return new G4Para(*this);                    << 1210   return G4String("G4Para");
813 }                                                 1211 }
814                                                   1212 
815 //////////////////////////////////////////////    1213 //////////////////////////////////////////////////////////////////////////
816 //                                                1214 //
817 // Stream object contents to an output stream     1215 // Stream object contents to an output stream
818                                                   1216 
819 std::ostream& G4Para::StreamInfo( std::ostream    1217 std::ostream& G4Para::StreamInfo( std::ostream& os ) const
820 {                                                 1218 {
821   G4double alpha = std::atan(fTalpha);         << 
822   G4double theta = std::atan(std::sqrt(fTtheta << 
823                                        fTtheta << 
824   G4double phi   = std::atan2(fTthetaSphi,fTth << 
825                                                << 
826   G4long oldprc = os.precision(16);            << 
827   os << "-------------------------------------    1219   os << "-----------------------------------------------------------\n"
828      << "    *** Dump for solid - " << GetName    1220      << "    *** Dump for solid - " << GetName() << " ***\n"
829      << "    =================================    1221      << "    ===================================================\n"
830      << " Solid type: G4Para\n"                   1222      << " Solid type: G4Para\n"
831      << " Parameters:\n"                       << 1223      << " Parameters: \n"
832      << "    half length X: " << fDx/mm << " m << 1224      << "    half length X: " << fDx/mm << " mm \n"
833      << "    half length Y: " << fDy/mm << " m << 1225      << "    half length Y: " << fDy/mm << " mm \n"
834      << "    half length Z: " << fDz/mm << " m << 1226      << "    half length Z: " << fDz/mm << " mm \n"
835      << "    alpha: " << alpha/degree << "degr << 1227      << "    std::tan(alpha)         : " << fTalpha/degree << " degrees \n"
836      << "    theta: " << theta/degree << "degr << 1228      << "    std::tan(theta)*std::cos(phi): " << fTthetaCphi/degree
837      << "    phi: " << phi/degree << "degrees\ << 1229      << " degrees \n"
                                                   >> 1230      << "    std::tan(theta)*std::sin(phi): " << fTthetaSphi/degree
                                                   >> 1231      << " degrees \n"
838      << "-------------------------------------    1232      << "-----------------------------------------------------------\n";
839   os.precision(oldprc);                        << 
840                                                   1233 
841   return os;                                      1234   return os;
842 }                                                 1235 }
843                                                   1236 
844 ////////////////////////////////////////////// << 1237 //////////////////////////////////////////////////////////////////////////////
                                                   >> 1238 //
                                                   >> 1239 // GetPointOnPlane
                                                   >> 1240 // Auxiliary method for Get Point on Surface
845 //                                                1241 //
846 // Return a point randomly and uniformly selec << 
847                                                   1242 
848 G4ThreeVector G4Para::GetPointOnSurface() cons << 1243 G4ThreeVector G4Para::GetPointOnPlane(G4ThreeVector p0, G4ThreeVector p1, 
                                                   >> 1244                                       G4ThreeVector p2, G4ThreeVector p3, 
                                                   >> 1245                                       G4double& area) const
849 {                                                 1246 {
850   G4double DyTalpha = fDy*fTalpha;             << 1247   G4double lambda1, lambda2, chose, aOne, aTwo;
851   G4double DzTthetaSphi = fDz*fTthetaSphi;     << 1248   G4ThreeVector t, u, v, w, Area, normal;
852   G4double DzTthetaCphi = fDz*fTthetaCphi;     << 
853                                                << 
854   // Set vertices                              << 
855   //                                           << 
856   G4ThreeVector pt[8];                         << 
857   pt[0].set(-DzTthetaCphi-DyTalpha-fDx, -DzTth << 
858   pt[1].set(-DzTthetaCphi-DyTalpha+fDx, -DzTth << 
859   pt[2].set(-DzTthetaCphi+DyTalpha-fDx, -DzTth << 
860   pt[3].set(-DzTthetaCphi+DyTalpha+fDx, -DzTth << 
861   pt[4].set( DzTthetaCphi-DyTalpha-fDx,  DzTth << 
862   pt[5].set( DzTthetaCphi-DyTalpha+fDx,  DzTth << 
863   pt[6].set( DzTthetaCphi+DyTalpha-fDx,  DzTth << 
864   pt[7].set( DzTthetaCphi+DyTalpha+fDx,  DzTth << 
865                                                << 
866   // Set areas (-Z, -Y, +Y, -X, +X, +Z)        << 
867   //                                           << 
868   G4ThreeVector vx(fDx, 0, 0);                 << 
869   G4ThreeVector vy(DyTalpha, fDy, 0);          << 
870   G4ThreeVector vz(DzTthetaCphi, DzTthetaSphi, << 
871                                                << 
872   G4double sxy = fDx*fDy; // (vx.cross(vy)).ma << 
873   G4double sxz = (vx.cross(vz)).mag();         << 
874   G4double syz = (vy.cross(vz)).mag();         << 
875                                                   1249   
876   G4double sface[6] = { sxy, syz, syz, sxz, sx << 1250   t = p1 - p0;
877   for (G4int i=1; i<6; ++i) { sface[i] += sfac << 1251   u = p2 - p1;
                                                   >> 1252   v = p3 - p2;
                                                   >> 1253   w = p0 - p3;
                                                   >> 1254 
                                                   >> 1255   Area = G4ThreeVector(w.y()*v.z() - w.z()*v.y(),
                                                   >> 1256                        w.z()*v.x() - w.x()*v.z(),
                                                   >> 1257                        w.x()*v.y() - w.y()*v.x());
                                                   >> 1258   
                                                   >> 1259   aOne = 0.5*Area.mag();
                                                   >> 1260   
                                                   >> 1261   Area = G4ThreeVector(t.y()*u.z() - t.z()*u.y(),
                                                   >> 1262                        t.z()*u.x() - t.x()*u.z(),
                                                   >> 1263                        t.x()*u.y() - t.y()*u.x());
                                                   >> 1264   
                                                   >> 1265   aTwo = 0.5*Area.mag();
                                                   >> 1266   
                                                   >> 1267   area = aOne + aTwo;
                                                   >> 1268   
                                                   >> 1269   chose = RandFlat::shoot(0.,aOne+aTwo);
878                                                   1270 
879   // Select face                               << 1271   if( (chose>=0.) && (chose < aOne) )
880   //                                           << 1272   {
881   G4double select = sface[5]*G4UniformRand();  << 1273     lambda1 = RandFlat::shoot(0.,1.);
882   G4int k = 5;                                 << 1274     lambda2 = RandFlat::shoot(0.,lambda1);
883   if (select <= sface[4]) k = 4;               << 1275     return (p2+lambda1*v+lambda2*w);    
884   if (select <= sface[3]) k = 3;               << 1276   }
885   if (select <= sface[2]) k = 2;               << 1277 
886   if (select <= sface[1]) k = 1;               << 1278   // else
887   if (select <= sface[0]) k = 0;               << 1279 
888                                                << 1280   lambda1 = RandFlat::shoot(0.,1.);
889   // Generate point                            << 1281   lambda2 = RandFlat::shoot(0.,lambda1);
890   //                                           << 1282   return (p0+lambda1*t+lambda2*u);    
891   G4int ip[6][3] = {{0,1,2}, {0,4,1}, {2,3,6}, << 
892   G4double u = G4UniformRand();                << 
893   G4double v = G4UniformRand();                << 
894   return (1.-u-v)*pt[ip[k][0]] + u*pt[ip[k][1] << 
895 }                                                 1283 }
896                                                   1284 
897 ////////////////////////////////////////////// << 1285 /////////////////////////////////////////////////////////////////////////
                                                   >> 1286 //
                                                   >> 1287 // GetPointOnSurface
                                                   >> 1288 //
                                                   >> 1289 // Return a point (G4ThreeVector) randomly and uniformly
                                                   >> 1290 // selected on the solid surface
                                                   >> 1291 
                                                   >> 1292 G4ThreeVector G4Para::GetPointOnSurface() const
                                                   >> 1293 {
                                                   >> 1294   G4ThreeVector One, Two, Three, Four, Five, Six;
                                                   >> 1295   G4ThreeVector pt[8] ;
                                                   >> 1296   G4double chose, aOne, aTwo, aThree, aFour, aFive, aSix;
                                                   >> 1297 
                                                   >> 1298   pt[0] = G4ThreeVector(-fDz*fTthetaCphi-fDy*fTalpha-fDx,
                                                   >> 1299                         -fDz*fTthetaSphi-fDy, -fDz);
                                                   >> 1300   pt[1] = G4ThreeVector(-fDz*fTthetaCphi-fDy*fTalpha+fDx,
                                                   >> 1301                         -fDz*fTthetaSphi-fDy, -fDz);
                                                   >> 1302   pt[2] = G4ThreeVector(-fDz*fTthetaCphi+fDy*fTalpha-fDx,
                                                   >> 1303                         -fDz*fTthetaSphi+fDy, -fDz);
                                                   >> 1304   pt[3] = G4ThreeVector(-fDz*fTthetaCphi+fDy*fTalpha+fDx,
                                                   >> 1305                         -fDz*fTthetaSphi+fDy, -fDz);
                                                   >> 1306   pt[4] = G4ThreeVector(+fDz*fTthetaCphi-fDy*fTalpha-fDx,
                                                   >> 1307                         +fDz*fTthetaSphi-fDy, +fDz);
                                                   >> 1308   pt[5] = G4ThreeVector(+fDz*fTthetaCphi-fDy*fTalpha+fDx,
                                                   >> 1309                         +fDz*fTthetaSphi-fDy, +fDz);
                                                   >> 1310   pt[6] = G4ThreeVector(+fDz*fTthetaCphi+fDy*fTalpha-fDx,
                                                   >> 1311                         +fDz*fTthetaSphi+fDy, +fDz);
                                                   >> 1312   pt[7] = G4ThreeVector(+fDz*fTthetaCphi+fDy*fTalpha+fDx,
                                                   >> 1313                         +fDz*fTthetaSphi+fDy, +fDz);
                                                   >> 1314 
                                                   >> 1315   // make sure we provide the points in a clockwise fashion
                                                   >> 1316 
                                                   >> 1317   One   = GetPointOnPlane(pt[0],pt[1],pt[3],pt[2], aOne);
                                                   >> 1318   Two   = GetPointOnPlane(pt[4],pt[5],pt[7],pt[6], aTwo);
                                                   >> 1319   Three = GetPointOnPlane(pt[6],pt[7],pt[3],pt[2], aThree);
                                                   >> 1320   Four  = GetPointOnPlane(pt[4],pt[5],pt[1],pt[0], aFour); 
                                                   >> 1321   Five  = GetPointOnPlane(pt[0],pt[2],pt[6],pt[4], aFive);
                                                   >> 1322   Six   = GetPointOnPlane(pt[1],pt[3],pt[7],pt[5], aSix);
                                                   >> 1323 
                                                   >> 1324   chose = RandFlat::shoot(0.,aOne+aTwo+aThree+aFour+aFive+aSix);
                                                   >> 1325   
                                                   >> 1326   if( (chose>=0.) && (chose<aOne) )                    
                                                   >> 1327     { return One; }
                                                   >> 1328   else if(chose>=aOne && chose<aOne+aTwo)  
                                                   >> 1329     { return Two; }
                                                   >> 1330   else if(chose>=aOne+aTwo && chose<aOne+aTwo+aThree)
                                                   >> 1331     { return Three; }
                                                   >> 1332   else if(chose>=aOne+aTwo+aThree && chose<aOne+aTwo+aThree+aFour)
                                                   >> 1333     { return Four; }
                                                   >> 1334   else if(chose>=aOne+aTwo+aThree+aFour && chose<aOne+aTwo+aThree+aFour+aFive)
                                                   >> 1335     { return Five; }
                                                   >> 1336   return Six;
                                                   >> 1337 }
                                                   >> 1338 
                                                   >> 1339 ////////////////////////////////////////////////////////////////////////////
898 //                                                1340 //
899 // Methods for visualisation                      1341 // Methods for visualisation
900                                                   1342 
901 void G4Para::DescribeYourselfTo ( G4VGraphicsS    1343 void G4Para::DescribeYourselfTo ( G4VGraphicsScene& scene ) const
902 {                                                 1344 {
903   scene.AddSolid (*this);                         1345   scene.AddSolid (*this);
904 }                                                 1346 }
905                                                   1347 
906 G4Polyhedron* G4Para::CreatePolyhedron () cons    1348 G4Polyhedron* G4Para::CreatePolyhedron () const
907 {                                                 1349 {
908   G4double phi = std::atan2(fTthetaSphi, fTthe    1350   G4double phi = std::atan2(fTthetaSphi, fTthetaCphi);
909   G4double alpha = std::atan(fTalpha);            1351   G4double alpha = std::atan(fTalpha);
910   G4double theta = std::atan(std::sqrt(fTtheta << 1352   G4double theta = std::atan(std::sqrt(fTthetaCphi*fTthetaCphi
911                                        fTtheta << 1353                             +fTthetaSphi*fTthetaSphi));
912                                                   1354     
913   return new G4PolyhedronPara(fDx, fDy, fDz, a    1355   return new G4PolyhedronPara(fDx, fDy, fDz, alpha, theta, phi);
914 }                                                 1356 }
915 #endif                                         << 1357 
                                                   >> 1358 G4NURBS* G4Para::CreateNURBS () const
                                                   >> 1359 {
                                                   >> 1360   // return new G4NURBSbox (fDx, fDy, fDz);
                                                   >> 1361   return 0 ;
                                                   >> 1362 }
916                                                   1363