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 8.1.p2)


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