Geant4 Cross Reference

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

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

Diff markup

Differences between /geometry/solids/specific/src/G4VTwistSurface.cc (Version 11.3.0) and /geometry/solids/specific/src/G4VTwistSurface.cc (Version 8.0.p1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                    <<   3 // * DISCLAIMER                                                       *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th <<   5 // * The following disclaimer summarizes all the specific disclaimers *
  6 // * the Geant4 Collaboration.  It is provided <<   6 // * of contributors to this software. The specific disclaimers,which *
  7 // * conditions of the Geant4 Software License <<   7 // * govern, are listed with their locations in:                      *
  8 // * LICENSE and available at  http://cern.ch/ <<   8 // *   http://cern.ch/geant4/license                                  *
  9 // * include a list of copyright holders.      << 
 10 // *                                                9 // *                                                                  *
 11 // * Neither the authors of this software syst     10 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     11 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     12 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     13 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  <<  14 // * use.                                                             *
 16 // * for the full disclaimer and the limitatio << 
 17 // *                                               15 // *                                                                  *
 18 // * This  code  implementation is the result  <<  16 // * This  code  implementation is the  intellectual property  of the *
 19 // * technical work of the GEANT4 collaboratio <<  17 // * GEANT4 collaboration.                                            *
 20 // * By using,  copying,  modifying or  distri <<  18 // * By copying,  distributing  or modifying the Program (or any work *
 21 // * any work based  on the software)  you  ag <<  19 // * based  on  the Program)  you indicate  your  acceptance of  this *
 22 // * use  in  resulting  scientific  publicati <<  20 // * statement, and all its terms.                                    *
 23 // * acceptance of all terms of the Geant4 Sof << 
 24 // *******************************************     21 // ********************************************************************
 25 //                                                 22 //
 26 // G4VTwistSurface implementation              << 
 27 //                                                 23 //
 28 // 01-Aug-2002 - Kotoyo Hoshina (hoshina@hepbu <<  24 // $Id: G4VTwistSurface.cc,v 1.4 2005/12/09 13:38:15 link Exp $
 29 // 13-Nov-2003 - O.Link (Oliver.Link@cern.ch), <<  25 // GEANT4 tag $Name: geant4-08-00-patch-01 $
 30 //               from original version in Jupi <<  26 //
                                                   >>  27 // 
                                                   >>  28 // --------------------------------------------------------------------
                                                   >>  29 // GEANT 4 class source file
                                                   >>  30 //
                                                   >>  31 //
                                                   >>  32 // G4VTwistSurface.cc
                                                   >>  33 //
                                                   >>  34 // Author: 
                                                   >>  35 //   01-Aug-2002 - Kotoyo Hoshina (hoshina@hepburn.s.chiba-u.ac.jp)
                                                   >>  36 //
                                                   >>  37 // History:
                                                   >>  38 //   13-Nov-2003 - O.Link (Oliver.Link@cern.ch), Integration in Geant4
                                                   >>  39 //                 from original version in Jupiter-2.5.02 application.
 31 // -------------------------------------------     40 // --------------------------------------------------------------------
 32                                                << 
 33 #include <iomanip>                             << 
 34                                                    41 
 35 #include "G4VTwistSurface.hh"                      42 #include "G4VTwistSurface.hh"
 36 #include "G4GeometryTolerance.hh"              <<  43 #include <iomanip>
 37                                                    44 
 38 const G4int  G4VTwistSurface::sOutside             45 const G4int  G4VTwistSurface::sOutside        = 0x00000000;
 39 const G4int  G4VTwistSurface::sInside              46 const G4int  G4VTwistSurface::sInside         = 0x10000000;
 40 const G4int  G4VTwistSurface::sBoundary            47 const G4int  G4VTwistSurface::sBoundary       = 0x20000000;
 41 const G4int  G4VTwistSurface::sCorner              48 const G4int  G4VTwistSurface::sCorner         = 0x40000000;
 42 const G4int  G4VTwistSurface::sC0Min1Min           49 const G4int  G4VTwistSurface::sC0Min1Min      = 0x40000101; 
 43 const G4int  G4VTwistSurface::sC0Max1Min           50 const G4int  G4VTwistSurface::sC0Max1Min      = 0x40000201;
 44 const G4int  G4VTwistSurface::sC0Max1Max           51 const G4int  G4VTwistSurface::sC0Max1Max      = 0x40000202; 
 45 const G4int  G4VTwistSurface::sC0Min1Max           52 const G4int  G4VTwistSurface::sC0Min1Max      = 0x40000102; 
 46 const G4int  G4VTwistSurface::sAxisMin             53 const G4int  G4VTwistSurface::sAxisMin        = 0x00000101; 
 47 const G4int  G4VTwistSurface::sAxisMax             54 const G4int  G4VTwistSurface::sAxisMax        = 0x00000202; 
 48 const G4int  G4VTwistSurface::sAxisX               55 const G4int  G4VTwistSurface::sAxisX          = 0x00000404;
 49 const G4int  G4VTwistSurface::sAxisY               56 const G4int  G4VTwistSurface::sAxisY          = 0x00000808;
 50 const G4int  G4VTwistSurface::sAxisZ               57 const G4int  G4VTwistSurface::sAxisZ          = 0x00000C0C;
 51 const G4int  G4VTwistSurface::sAxisRho             58 const G4int  G4VTwistSurface::sAxisRho        = 0x00001010;
 52 const G4int  G4VTwistSurface::sAxisPhi             59 const G4int  G4VTwistSurface::sAxisPhi        = 0x00001414;
 53                                                    60 
 54 // mask                                            61 // mask
 55 const G4int  G4VTwistSurface::sAxis0               62 const G4int  G4VTwistSurface::sAxis0          = 0x0000FF00;
 56 const G4int  G4VTwistSurface::sAxis1               63 const G4int  G4VTwistSurface::sAxis1          = 0x000000FF;
 57 const G4int  G4VTwistSurface::sSizeMask            64 const G4int  G4VTwistSurface::sSizeMask       = 0x00000303;
 58 const G4int  G4VTwistSurface::sAxisMask            65 const G4int  G4VTwistSurface::sAxisMask       = 0x0000FCFC;
 59 const G4int  G4VTwistSurface::sAreaMask            66 const G4int  G4VTwistSurface::sAreaMask       = 0XF0000000;
 60                                                    67 
 61 //============================================     68 //=====================================================================
 62 //* constructors -----------------------------     69 //* constructors ------------------------------------------------------
 63                                                    70 
 64 G4VTwistSurface::G4VTwistSurface(const G4Strin     71 G4VTwistSurface::G4VTwistSurface(const G4String &name)
 65   : fIsValidNorm(false), fName(name)           <<  72   : fName(name)
 66 {                                                  73 {
 67                                                    74 
 68    fAxis[0]    = kUndefined;                       75    fAxis[0]    = kUndefined;
 69    fAxis[1]    = kUndefined;                       76    fAxis[1]    = kUndefined;
 70    fAxisMin[0] = kInfinity;                        77    fAxisMin[0] = kInfinity;
 71    fAxisMin[1] = kInfinity;                        78    fAxisMin[1] = kInfinity;
 72    fAxisMax[0] = kInfinity;                        79    fAxisMax[0] = kInfinity;
 73    fAxisMax[1] = kInfinity;                        80    fAxisMax[1] = kInfinity;
 74    fHandedness = 1;                                81    fHandedness = 1;
 75                                                    82 
 76    for (auto i=0; i<4; ++i)                    <<  83    G4int i;
 77    {                                           <<  84    for (i=0; i<4; i++) {
 78       fCorners[i].set(kInfinity, kInfinity, kI     85       fCorners[i].set(kInfinity, kInfinity, kInfinity);
 79       fNeighbours[i] = nullptr;                <<  86       fNeighbours[i] = 0;
 80    }                                               87    }
 81                                                    88 
 82    fCurrentNormal.p.set(kInfinity, kInfinity,      89    fCurrentNormal.p.set(kInfinity, kInfinity, kInfinity);
 83                                                    90    
 84    fAmIOnLeftSide.me.set(kInfinity, kInfinity,     91    fAmIOnLeftSide.me.set(kInfinity, kInfinity, kInfinity);
 85    fAmIOnLeftSide.vec.set(kInfinity, kInfinity     92    fAmIOnLeftSide.vec.set(kInfinity, kInfinity, kInfinity);
 86    kCarTolerance = G4GeometryTolerance::GetIns << 
 87 }                                                  93 }
 88                                                    94 
 89 G4VTwistSurface::G4VTwistSurface(const G4Strin <<  95 G4VTwistSurface::G4VTwistSurface(const G4String         &name,
 90                        const G4RotationMatrix& <<  96                        const G4RotationMatrix &rot,
 91                        const G4ThreeVector&    <<  97                        const G4ThreeVector    &tlate,
 92                              G4int                 98                              G4int             handedness,
 93                        const EAxis                 99                        const EAxis             axis0 ,
 94                        const EAxis                100                        const EAxis             axis1 ,
 95                              G4double             101                              G4double          axis0min,
 96                              G4double             102                              G4double          axis1min,
 97                              G4double             103                              G4double          axis0max,
 98                              G4double             104                              G4double          axis1max )
 99    : fIsValidNorm(false), fName(name)          << 105    : fName(name)
100 {                                                 106 {
101    fAxis[0]    = axis0;                           107    fAxis[0]    = axis0;
102    fAxis[1]    = axis1;                           108    fAxis[1]    = axis1;
103    fAxisMin[0] = axis0min;                        109    fAxisMin[0] = axis0min;
104    fAxisMin[1] = axis1min;                        110    fAxisMin[1] = axis1min;
105    fAxisMax[0] = axis0max;                        111    fAxisMax[0] = axis0max;
106    fAxisMax[1] = axis1max;                        112    fAxisMax[1] = axis1max;
107    fHandedness = handedness;                      113    fHandedness = handedness;
108    fRot        = rot;                             114    fRot        = rot;
109    fTrans      = tlate;                           115    fTrans      = tlate;
110                                                   116 
111    for (auto i=0; i<4; ++i)                    << 117    G4int i;
112    {                                           << 118    for (i=0; i<4; i++) {
113       fCorners[i].set(kInfinity, kInfinity, kI    119       fCorners[i].set(kInfinity, kInfinity, kInfinity);
114       fNeighbours[i] = nullptr;                << 120       fNeighbours[i] = 0;
115    }                                              121    }
116                                                   122 
117    fCurrentNormal.p.set(kInfinity, kInfinity,     123    fCurrentNormal.p.set(kInfinity, kInfinity, kInfinity);
118                                                   124    
119    fAmIOnLeftSide.me.set(kInfinity, kInfinity,    125    fAmIOnLeftSide.me.set(kInfinity, kInfinity, kInfinity);
120    fAmIOnLeftSide.vec.set(kInfinity, kInfinity    126    fAmIOnLeftSide.vec.set(kInfinity, kInfinity, kInfinity);
121    kCarTolerance = G4GeometryTolerance::GetIns << 
122 }                                                 127 }
123                                                   128 
124 //============================================    129 //=====================================================================
125 //* Fake default constructor -----------------    130 //* Fake default constructor ------------------------------------------
126                                                   131 
127 G4VTwistSurface::G4VTwistSurface( __void__& )     132 G4VTwistSurface::G4VTwistSurface( __void__& )
128   : fHandedness(0), fIsValidNorm(false), kCarT << 133   : fName("")
129     fName("")                                  << 134 {
                                                   >> 135 }
                                                   >> 136 
                                                   >> 137 //=====================================================================
                                                   >> 138 //* destructor --------------------------------------------------------
                                                   >> 139 
                                                   >> 140 G4VTwistSurface::~G4VTwistSurface()
130 {                                                 141 {
131    fAxis[0] = fAxis[1] = kXAxis;               << 
132    fAxisMin[0] = fAxisMin[1] = 0.;             << 
133    fAxisMax[0] = fAxisMax[1] = 0.;             << 
134    fNeighbours[0] = fNeighbours[1] = fNeighbou << 
135 }                                                 142 }
136                                                   143 
137 //============================================    144 //=====================================================================
138 //* AmIOnLeftSide ----------------------------    145 //* AmIOnLeftSide -----------------------------------------------------
139                                                   146 
140 G4int G4VTwistSurface::AmIOnLeftSide(const G4T << 147 G4int G4VTwistSurface::AmIOnLeftSide(const G4ThreeVector &me, 
141                                      const G4T << 148                                 const G4ThreeVector &vec,
142                                            G4b << 149                                       G4bool        withtol) 
143 {                                                 150 {
144    // AmIOnLeftSide returns phi-location of "m    151    // AmIOnLeftSide returns phi-location of "me"
145    // (phi relation between me and vec project    152    // (phi relation between me and vec projected on z=0 plane).
146    // If "me" is on -ve-phi-side of "vec", it     153    // If "me" is on -ve-phi-side of "vec", it returns 1.
147    // On the other hand, if "me" is on +ve-phi    154    // On the other hand, if "me" is on +ve-phi-side of "vec",
148    // it returns -1.                              155    // it returns -1.
149    // (The return value represents z-coordinat    156    // (The return value represents z-coordinate of normal vector
150    //  of me.cross(vec).)                         157    //  of me.cross(vec).)
151    // If me is on boundary of vec, return 0.      158    // If me is on boundary of vec, return 0.
152                                                   159 
153    const G4double kAngTolerance                << 160    static G4RotationMatrix unitrot;  // unit matrix
154      = G4GeometryTolerance::GetInstance()->Get << 161    static const G4RotationMatrix rottol    = unitrot.rotateZ(0.5*kAngTolerance);
155                                                << 162    static const G4RotationMatrix invrottol = unitrot.rotateZ(-1.*kAngTolerance);
156    G4RotationMatrix unitrot;                   << 
157    const G4RotationMatrix rottol    = unitrot. << 
158    const G4RotationMatrix invrottol = unitrot. << 
159                                                   163 
160    if (fAmIOnLeftSide.me == me                    164    if (fAmIOnLeftSide.me == me 
161        && fAmIOnLeftSide.vec == vec               165        && fAmIOnLeftSide.vec == vec
162        && fAmIOnLeftSide.withTol == withtol)   << 166        && fAmIOnLeftSide.withTol == withtol) {
163    {                                           << 
164       return fAmIOnLeftSide.amIOnLeftSide;        167       return fAmIOnLeftSide.amIOnLeftSide;
165    }                                              168    }
166                                                   169    
167    fAmIOnLeftSide.me      = me;                   170    fAmIOnLeftSide.me      = me;
168    fAmIOnLeftSide.vec     = vec;                  171    fAmIOnLeftSide.vec     = vec;
169    fAmIOnLeftSide.withTol = withtol;              172    fAmIOnLeftSide.withTol = withtol;
170                                                   173    
171    G4ThreeVector met   = (G4ThreeVector(me.x()    174    G4ThreeVector met   = (G4ThreeVector(me.x(), me.y(), 0.)).unit();
172    G4ThreeVector vect  = (G4ThreeVector(vec.x(    175    G4ThreeVector vect  = (G4ThreeVector(vec.x(), vec.y(), 0.)).unit();
173                                                   176    
174    G4ThreeVector ivect = invrottol * vect;        177    G4ThreeVector ivect = invrottol * vect;
175    G4ThreeVector rvect = rottol * vect;           178    G4ThreeVector rvect = rottol * vect;
176                                                   179 
177    G4double metcrossvect = met.x() * vect.y()     180    G4double metcrossvect = met.x() * vect.y() - met.y() * vect.x();
178                                                   181    
179    if (withtol)                                << 182    if (withtol) {
180    {                                           << 
181       if (met.x() * ivect.y() - met.y() * ivec    183       if (met.x() * ivect.y() - met.y() * ivect.x() > 0 && 
182           metcrossvect >= 0)  {                   184           metcrossvect >= 0)  {
183          fAmIOnLeftSide.amIOnLeftSide = 1;        185          fAmIOnLeftSide.amIOnLeftSide = 1;
184       } else if (met.x() * rvect.y() - met.y()    186       } else if (met.x() * rvect.y() - met.y() * rvect.x() < 0 &&
185                  metcrossvect <= 0)  {            187                  metcrossvect <= 0)  {
186          fAmIOnLeftSide.amIOnLeftSide = -1;       188          fAmIOnLeftSide.amIOnLeftSide = -1;
187       } else {                                    189       } else {
188          fAmIOnLeftSide.amIOnLeftSide = 0;        190          fAmIOnLeftSide.amIOnLeftSide = 0;
189       }                                           191       }
190    }                                           << 192    } else {
191    else                                        << 
192    {                                           << 
193       if (metcrossvect > 0) {                     193       if (metcrossvect > 0) {    
194          fAmIOnLeftSide.amIOnLeftSide = 1;        194          fAmIOnLeftSide.amIOnLeftSide = 1;
195       } else if (metcrossvect < 0 ) {             195       } else if (metcrossvect < 0 ) {
196          fAmIOnLeftSide.amIOnLeftSide = -1;       196          fAmIOnLeftSide.amIOnLeftSide = -1;
197       } else {                                    197       } else {       
198          fAmIOnLeftSide.amIOnLeftSide = 0;        198          fAmIOnLeftSide.amIOnLeftSide = 0;
199       }                                           199       }
200    }                                              200    }
201                                                   201 
202 #ifdef G4TWISTDEBUG                            << 202 #ifdef G4SPECSDEBUG
203    G4cout << "         === G4VTwistSurface::Am    203    G4cout << "         === G4VTwistSurface::AmIOnLeftSide() =============="
204           << G4endl;                              204           << G4endl;
205    G4cout << "             Name , returncode      205    G4cout << "             Name , returncode  : " << fName << " " 
206                        << fAmIOnLeftSide.amIOn    206                        << fAmIOnLeftSide.amIOnLeftSide <<  G4endl;
207    G4cout << "             me, vec    : " << s    207    G4cout << "             me, vec    : " << std::setprecision(14) << me 
208                                           << "    208                                           << " " << vec  << G4endl;
209    G4cout << "             met, vect  : " << m    209    G4cout << "             met, vect  : " << met << " " << vect  << G4endl;
210    G4cout << "             ivec, rvec : " << i    210    G4cout << "             ivec, rvec : " << ivect << " " << rvect << G4endl;
211    G4cout << "             met x vect : " << m    211    G4cout << "             met x vect : " << metcrossvect << G4endl;
212    G4cout << "             met x ivec : " << m    212    G4cout << "             met x ivec : " << met.cross(ivect) << G4endl;
213    G4cout << "             met x rvec : " << m    213    G4cout << "             met x rvec : " << met.cross(rvect) << G4endl;
214    G4cout << "         =======================    214    G4cout << "         =============================================="
215           << G4endl;                              215           << G4endl;
216 #endif                                            216 #endif
217                                                   217 
218    return fAmIOnLeftSide.amIOnLeftSide;           218    return fAmIOnLeftSide.amIOnLeftSide;
219 }                                                 219 }
220                                                   220 
221 //============================================    221 //=====================================================================
222 //* DistanceToBoundary -----------------------    222 //* DistanceToBoundary ------------------------------------------------
223                                                   223 
224 G4double G4VTwistSurface::DistanceToBoundary(G    224 G4double G4VTwistSurface::DistanceToBoundary(G4int areacode,
225                                              G << 225                                         G4ThreeVector &xx,
226                                        const G << 226                                         const G4ThreeVector &p) 
227 {                                                 227 {
228    // DistanceToBoundary                          228    // DistanceToBoundary 
229    //                                             229    //
230    // return distance to nearest boundary from    230    // return distance to nearest boundary from arbitrary point p 
231    // in local coodinate.                         231    // in local coodinate.
232    // Argument areacode must be one of them:      232    // Argument areacode must be one of them:
233    // sAxis0 & sAxisMin, sAxis0 & sAxisMax,       233    // sAxis0 & sAxisMin, sAxis0 & sAxisMax,
234    // sAxis1 & sAxisMin, sAxis1 & sAxisMax.       234    // sAxis1 & sAxisMin, sAxis1 & sAxisMax.
235    //                                             235    //
236                                                   236 
237    G4ThreeVector d;    // direction vector of     237    G4ThreeVector d;    // direction vector of the boundary
238    G4ThreeVector x0;   // reference point of t    238    G4ThreeVector x0;   // reference point of the boundary
239    G4double      dist = kInfinity;                239    G4double      dist = kInfinity;
240    G4int         boundarytype;                    240    G4int         boundarytype;
241                                                   241 
242    if (IsAxis0(areacode) && IsAxis1(areacode)) << 242    if (IsAxis0(areacode) && IsAxis1(areacode)) {
243    {                                           << 243       G4cerr << "ERROR - G4VTwistSurface::DistanceToBoundary()" << G4endl
244       std::ostringstream message;              << 244              << "        Point is in the corner area. This function returns"
245       message << "Point is in the corner area. << 245              << G4endl
246               << "        Point is in the corn << 246              << "        a direction vector of a boundary line." << G4endl
247               << G4endl                        << 247              << "        areacode = " << areacode << G4endl;
248               << "        a direction vector o << 248       G4Exception("G4VTwistSurface::DistanceToBoundary()", "InvalidSetup",
249               << "        areacode = " << area << 249                   FatalException, "Point is in the corner area.");
250       G4Exception("G4VTwistSurface::DistanceTo << 250    } else if (IsAxis0(areacode) || IsAxis1(areacode)) {
251                   FatalException, message);    << 
252    }                                           << 
253    else if (IsAxis0(areacode) || IsAxis1(areac << 
254    {                                           << 
255       GetBoundaryParameters(areacode, d, x0, b    251       GetBoundaryParameters(areacode, d, x0, boundarytype);
256       if (boundarytype == sAxisPhi)            << 252       if (boundarytype == sAxisPhi) {
257       {                                        << 
258          G4double t = x0.getRho() / p.getRho()    253          G4double t = x0.getRho() / p.getRho();
259          xx.set(t*p.x(), t*p.y(), x0.z());        254          xx.set(t*p.x(), t*p.y(), x0.z());
260          dist = (xx - p).mag();                   255          dist = (xx - p).mag();
261       }                                        << 256       } else { 
262       else                                     << 
263       {                                        << 
264          // linear boundary                       257          // linear boundary
265          // sAxisX, sAxisY, sAxisZ, sAxisRho      258          // sAxisX, sAxisY, sAxisZ, sAxisRho
266          dist = DistanceToLine(p, x0, d, xx);     259          dist = DistanceToLine(p, x0, d, xx);
267       }                                           260       }
268    }                                           << 261    } else {
269    else                                        << 262       G4cerr << "ERROR - G4VTwistSurface::DistanceToBoundary()" << G4endl
270    {                                           << 263              << "        areacode = " << areacode << G4endl;
271       std::ostringstream message;              << 264       G4Exception("G4VTwistSurface::DistanceToBoundary()", "InvalidSetup",
272       message << "Bad areacode of boundary." < << 265                   FatalException, "Bad areacode of boundary.");
273               << "        areacode = " << area << 
274       G4Exception("G4VTwistSurface::DistanceTo << 
275                   FatalException, message);    << 
276    }                                              266    }
277    return dist;                                   267    return dist;
278 }                                                 268 }
279                                                   269 
280 //============================================    270 //=====================================================================
281 //* DistanceToIn -----------------------------    271 //* DistanceToIn ------------------------------------------------------
282                                                   272 
283 G4double G4VTwistSurface::DistanceToIn(const G << 273 G4double G4VTwistSurface::DistanceToIn(const G4ThreeVector &gp,
284                                        const G << 274                                   const G4ThreeVector &gv,
285                                              G << 275                                         G4ThreeVector &gxxbest)
286 {                                                 276 {
287 #ifdef G4TWISTDEBUG                            << 277 #ifdef G4SPECSDEBUG
288    G4cout << " ~~~~ G4VTwistSurface::DistanceT << 278    G4cout << " ~~~~~ G4VTwistSurface::DistanceToIn(p,v) - Start ~~~~~" << G4endl;
289    G4cout << "      Name : " << fName << G4end    279    G4cout << "      Name : " << fName << G4endl;
290    G4cout << "      gp   : " << gp << G4endl;     280    G4cout << "      gp   : " << gp << G4endl;
291    G4cout << "      gv   : " <<  gv << G4endl;    281    G4cout << "      gv   : " <<  gv << G4endl;
292    G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    282    G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << G4endl;
293 #endif                                            283 #endif
294                                                   284    
295    G4ThreeVector gxx[G4VSURFACENXX];              285    G4ThreeVector gxx[G4VSURFACENXX];
296    G4double      distance[G4VSURFACENXX]  ;       286    G4double      distance[G4VSURFACENXX]  ; 
297    G4int         areacode[G4VSURFACENXX]  ;       287    G4int         areacode[G4VSURFACENXX]  ;
298    G4bool        isvalid[G4VSURFACENXX]   ;       288    G4bool        isvalid[G4VSURFACENXX]   ; 
299                                                   289    
300    for (G4int i = 0 ; i<G4VSURFACENXX ; ++i )  << 290    for (G4int i = 0 ; i<G4VSURFACENXX ; i++ ) {
301    {                                           << 
302      distance[i] = kInfinity ;                    291      distance[i] = kInfinity ;
303      areacode[i] = sOutside ;                     292      areacode[i] = sOutside ;
304      isvalid[i] = false ;                         293      isvalid[i] = false ;
305    }                                              294    }
306                                                   295 
307    G4double      bestdistance   = kInfinity;      296    G4double      bestdistance   = kInfinity;
308 #ifdef G4TWISTDEBUG                            << 
309    G4int         besti          = -1;             297    G4int         besti          = -1;  
310 #endif                                         << 
311    G4ThreeVector bestgxx(kInfinity, kInfinity,    298    G4ThreeVector bestgxx(kInfinity, kInfinity, kInfinity);
312                                                   299 
313    G4int         nxx = DistanceToSurface(gp, g    300    G4int         nxx = DistanceToSurface(gp, gv, gxx, distance, areacode, 
314                                          isval    301                                          isvalid, kValidateWithTol);
315                                                   302 
316    for (G4int i=0; i<nxx; ++i)                 << 303    for (G4int i=0; i< nxx; i++) {
317    {                                           << 
318                                                   304 
319       // skip this intersection if:               305       // skip this intersection if:
320       //   - invalid intersection                 306       //   - invalid intersection
321       //   - particle goes outword the surface    307       //   - particle goes outword the surface
322                                                   308 
323       if (!isvalid[i])                         << 309       if (!isvalid[i]) {
324       {                                        << 
325          // xx[i] is sOutside or distance[i] <    310          // xx[i] is sOutside or distance[i] < 0
326          continue;                                311          continue;      
327       }                                           312       }
328                                                   313 
329       G4ThreeVector normal = GetNormal(gxx[i],    314       G4ThreeVector normal = GetNormal(gxx[i], true);
330                                                   315 
331       if ((normal * gv) >= 0)                  << 316       if ((normal * gv) >= 0) {
332       {                                        << 
333                                                   317 
334 #ifdef G4TWISTDEBUG                            << 318 #ifdef G4SPECSDEBUG
335          G4cout << "   G4VTwistSurface::Distan    319          G4cout << "   G4VTwistSurface::DistanceToIn(p,v): "
336                 << "particle goes outword the     320                 << "particle goes outword the surface." << G4endl;
337 #endif                                            321 #endif 
338          continue;                                322          continue; 
339       }                                           323       }
340                                                   324       
341       //                                          325       //
342       // accept this intersection if the inter    326       // accept this intersection if the intersection is inside.
343       //                                          327       //
344                                                   328 
345       if (IsInside(areacode[i]))               << 329       if (IsInside(areacode[i])) {
346       {                                        << 330          if (distance[i] < bestdistance) {
347          if (distance[i] < bestdistance)       << 
348          {                                     << 
349             bestdistance = distance[i];           331             bestdistance = distance[i];
350             bestgxx = gxx[i];                     332             bestgxx = gxx[i];
351 #ifdef G4TWISTDEBUG                            << 
352             besti   = i;                          333             besti   = i;
                                                   >> 334 
                                                   >> 335 #ifdef G4SPECSDEBUG
353             G4cout << "   G4VTwistSurface::Dis    336             G4cout << "   G4VTwistSurface::DistanceToIn(p,v): "
354                    << " areacode sInside name,    337                    << " areacode sInside name, distance = "
355                    << fName <<  " "<< bestdist    338                    << fName <<  " "<< bestdistance << G4endl;
356 #endif                                            339 #endif 
357          }                                        340          }
358                                                   341 
359       //                                          342       //
360       // else, the intersection is on boundary    343       // else, the intersection is on boundary or corner.
361       //                                          344       //
362                                                   345 
363       }                                        << 346       } else {
364       else                                     << 347 
365       {                                        << 348          G4VTwistSurface *neighbours[2];
366          G4VTwistSurface* neighbours[2];       << 
367          G4bool      isaccepted[2] = {false, f    349          G4bool      isaccepted[2] = {false, false};
368          G4int       nneighbours   = GetNeighb    350          G4int       nneighbours   = GetNeighbours(areacode[i], neighbours);
369                                                   351             
370          for (G4int j=0; j<nneighbours; ++j)   << 352          for (G4int j=0; j< nneighbours; j++) {
371          {                                     << 
372             // if on corner, nneighbours = 2.     353             // if on corner, nneighbours = 2.
373             // if on boundary, nneighbours = 1    354             // if on boundary, nneighbours = 1.
374                                                   355 
375             G4ThreeVector tmpgxx[G4VSURFACENXX    356             G4ThreeVector tmpgxx[G4VSURFACENXX];
376             G4double      tmpdist[G4VSURFACENX    357             G4double      tmpdist[G4VSURFACENXX] ;
377             G4int         tmpareacode[G4VSURFA    358             G4int         tmpareacode[G4VSURFACENXX] ;
378             G4bool        tmpisvalid[G4VSURFAC    359             G4bool        tmpisvalid[G4VSURFACENXX] ;
379                                                   360 
380             for (G4int l = 0 ; l<G4VSURFACENXX << 361             for (G4int l = 0 ; l<G4VSURFACENXX ; l++ ) {
381             {                                  << 
382               tmpdist[l] = kInfinity ;            362               tmpdist[l] = kInfinity ;
383               tmpareacode[l] = sOutside ;         363               tmpareacode[l] = sOutside ;
384               tmpisvalid[l] = false ;             364               tmpisvalid[l] = false ;
385             }                                     365             }
386                                                   366 
387             G4int tmpnxx = neighbours[j]->Dist    367             G4int tmpnxx = neighbours[j]->DistanceToSurface(
388                                           gp,     368                                           gp, gv, tmpgxx, tmpdist,
389                                           tmpa    369                                           tmpareacode, tmpisvalid,
390                                           kVal    370                                           kValidateWithTol);
391             G4ThreeVector neighbournormal;        371             G4ThreeVector neighbournormal;
392                                                   372 
393             for (G4int k=0; k< tmpnxx; ++k)    << 373             for (G4int k=0; k< tmpnxx; k++) {
394             {                                  << 374 
395                //                                 375                //  
396                // if tmpxx[k] is valid && sIns    376                // if tmpxx[k] is valid && sInside, the final winner must
397                // be neighbour surface. return    377                // be neighbour surface. return kInfinity. 
398                // else , choose tmpxx on same     378                // else , choose tmpxx on same boundary of xx, then check normal 
399                //                                 379                //  
400                                                   380 
401                if (IsInside(tmpareacode[k]))   << 381                if (IsInside(tmpareacode[k])) {
402                {                               << 382 
403 #ifdef G4TWISTDEBUG                            << 383 #ifdef G4SPECSDEBUG
404                   G4cout << "   G4VTwistSurfac    384                   G4cout << "   G4VTwistSurface:DistanceToIn(p,v): "
405                          << " intersection "<<    385                          << " intersection "<< tmpgxx[k] << G4endl
406                          << "   is inside of n    386                          << "   is inside of neighbour surface of " << fName 
407                          << " . returning kInf    387                          << " . returning kInfinity." << G4endl;
408                   G4cout << "~~ G4VTwistSurfac << 388                   G4cout << "~~~~~ G4VTwistSurface::DistanceToIn(p,v) - return ~~~~"
409                          << G4endl;               389                          << G4endl;
410                   G4cout << "      No intersec    390                   G4cout << "      No intersections " << G4endl; 
411                   G4cout << "      Name : " <<    391                   G4cout << "      Name : " << fName << G4endl; 
412                   G4cout << "~~~~~~~~~~~~~~~~~    392                   G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
413                          << G4endl;               393                          << G4endl;
414 #endif                                            394 #endif 
415                   if (tmpisvalid[k])  return k    395                   if (tmpisvalid[k])  return kInfinity;
416                   continue;                       396                   continue;
417                                                   397 
418                //                                 398                //  
419                // if tmpxx[k] is valid && sIns    399                // if tmpxx[k] is valid && sInside, the final winner must
420                // be neighbour surface. return    400                // be neighbour surface. return .  
421                //                                 401                //
422                                                   402 
423                }                               << 403                } else if (IsSameBoundary(this,areacode[i],
424                else if (IsSameBoundary(this,ar << 404                                          neighbours[j], tmpareacode[k])) { 
425                                        neighbo << 
426                {                               << 
427                   // tmpxx[k] is same boundary    405                   // tmpxx[k] is same boundary (or corner) of xx.
428                                                   406                  
429                   neighbournormal = neighbours    407                   neighbournormal = neighbours[j]->GetNormal(tmpgxx[k], true);
430                   if (neighbournormal * gv < 0    408                   if (neighbournormal * gv < 0) isaccepted[j] = true;
431                }                                  409                }
432             }                                     410             } 
433                                                   411 
434             // if nneighbours = 1, chabge isac    412             // if nneighbours = 1, chabge isaccepted[1] before
435             // exiting neighboursurface loop.     413             // exiting neighboursurface loop.  
436                                                   414 
437             if (nneighbours == 1) isaccepted[1    415             if (nneighbours == 1) isaccepted[1] = true;
438                                                   416 
439          } // neighboursurface loop end           417          } // neighboursurface loop end
440                                                   418 
441          // now, we can accept xx intersection    419          // now, we can accept xx intersection
442                                                   420 
443          if (isaccepted[0] && isaccepted[1])   << 421          if (isaccepted[0] == true && isaccepted[1] == true) {
444          {                                     << 422             if (distance[i] < bestdistance) {
445             if (distance[i] < bestdistance)    << 423                 bestdistance = distance[i];
446             {                                  << 424                 gxxbest = gxx[i];
447                bestdistance = distance[i];     << 425                 besti   = i;
448                gxxbest = gxx[i];               << 426 #ifdef G4SPECSDEBUG
449 #ifdef G4TWISTDEBUG                            << 
450                besti = i;                      << 
451                G4cout << "   G4VTwistSurface::    427                G4cout << "   G4VTwistSurface::DistanceToIn(p,v): "
452                       << " areacode sBoundary     428                       << " areacode sBoundary & sBoundary distance = "
453                       << fName  << " " << dist    429                       << fName  << " " << distance[i] << G4endl;
454 #endif                                            430 #endif 
455             }                                     431             }
456          }                                        432          }
                                                   >> 433 
457       } // else end                               434       } // else end
458    } // intersection loop end                     435    } // intersection loop end
459                                                   436 
460    gxxbest = bestgxx;                             437    gxxbest = bestgxx;
461                                                   438 
462 #ifdef G4TWISTDEBUG                            << 439 #ifdef G4SPECSDEBUG
463    if (besti < 0)                              << 440    if (besti < 0) {
464    {                                           << 441       G4cout << "~~~~~ G4VTwistSurface::DistanceToIn(p,v) - return ~~~~" << G4endl;
465       G4cout << "~~~ G4VTwistSurface::Distance << 
466       G4cout << "      No intersections " << G    442       G4cout << "      No intersections " << G4endl; 
467       G4cout << "      Name : " << fName << G4    443       G4cout << "      Name : " << fName << G4endl; 
468       G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    444       G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << G4endl;
469    }                                           << 445    } else {
470    else                                        << 446       G4cout << "~~~~~ G4VTwistSurface::DistanceToIn(p,v) : return ~~~~" << G4endl;
471    {                                           << 
472       G4cout << "~~~ G4VTwistSurface::Distance << 
473       G4cout << "      Name, i  : " << fName <    447       G4cout << "      Name, i  : " << fName << " , " << besti << G4endl; 
474       G4cout << "      gxx[i]   : " << gxxbest    448       G4cout << "      gxx[i]   : " << gxxbest << G4endl; 
475       G4cout << "      bestdist : " << bestdis    449       G4cout << "      bestdist : " << bestdistance << G4endl;
476       G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    450       G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << G4endl;
477    }                                              451    } 
478                                                   452 
479 #endif                                            453 #endif
480                                                   454 
481    return bestdistance;                           455    return bestdistance;
482 }                                                 456 }
483                                                   457 
484 //============================================    458 //=====================================================================
485 //* DistanceToOut(p, v) ----------------------    459 //* DistanceToOut(p, v) -----------------------------------------------
486                                                   460 
487 G4double G4VTwistSurface::DistanceToOut(const  << 461 G4double G4VTwistSurface::DistanceToOut(const G4ThreeVector &gp,
488                                         const  << 462                                    const G4ThreeVector &gv,
489                                                << 463                                          G4ThreeVector &gxxbest)
490 {                                                 464 {
491 #ifdef G4TWISTDEBUG                            << 465 #ifdef G4SPECSDEBUG
492    G4cout << "~~~~~ G4VTwistSurface::DistanceT    466    G4cout << "~~~~~ G4VTwistSurface::DistanceToOut(p,v) - Start ~~~~" << G4endl;
493    G4cout << "      Name : " << fName << G4end    467    G4cout << "      Name : " << fName << G4endl;
494    G4cout << "      gp   : " << gp << G4endl;     468    G4cout << "      gp   : " << gp << G4endl;
495    G4cout << "      gv   : " <<  gv << G4endl;    469    G4cout << "      gv   : " <<  gv << G4endl;
496    G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    470    G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << G4endl;
497 #endif                                            471 #endif
498                                                   472 
499    G4ThreeVector gxx[G4VSURFACENXX];              473    G4ThreeVector gxx[G4VSURFACENXX];
500    G4double      distance[G4VSURFACENXX];      << 474    G4double      distance[G4VSURFACENXX]  ; 
501    G4int         areacode[G4VSURFACENXX];      << 475    G4int         areacode[G4VSURFACENXX]  ;
502    G4bool        isvalid[G4VSURFACENXX];       << 476    G4bool        isvalid[G4VSURFACENXX]   ; 
                                                   >> 477    G4int         i;
503                                                   478    
504    for ( G4int i = 0 ; i<G4VSURFACENXX ; ++i ) << 479    for ( i = 0 ; i<G4VSURFACENXX ; i++ )
505    {                                              480    {
506      distance[i] = kInfinity ;                    481      distance[i] = kInfinity ;
507      areacode[i] = sOutside ;                     482      areacode[i] = sOutside ;
508      isvalid[i] = false ;                         483      isvalid[i] = false ;
509    }                                              484    }
510                                                   485 
511    G4int         nxx;                             486    G4int         nxx;
512    G4double      bestdistance   = kInfinity;      487    G4double      bestdistance   = kInfinity;
                                                   >> 488    G4int         besti          = -1;
513                                                   489 
514    nxx = DistanceToSurface(gp, gv, gxx, distan    490    nxx = DistanceToSurface(gp, gv, gxx, distance, areacode,
515                            isvalid, kValidateW    491                            isvalid, kValidateWithTol);
516                                                   492 
517    for (G4int i=0; i<nxx; ++i)                 << 493    for (i=0; i<nxx; i++) {
518    {                                           << 494       if (!(isvalid[i])) {
519       if (!(isvalid[i]))                       << 
520       {                                        << 
521          continue;                                495          continue;
522       }                                           496       }
523                                                   497 
524       G4ThreeVector normal = GetNormal(gxx[i],    498       G4ThreeVector normal = GetNormal(gxx[i], true);
525       if (normal * gv <= 0)                    << 499       if (normal * gv <= 0) {
526       {                                        << 
527          // particle goes toword inside of sol    500          // particle goes toword inside of solid, return kInfinity
528 #ifdef G4TWISTDEBUG                            << 501 #ifdef G4SPECSDEBUG
529           G4cout << "   G4VTwistSurface::Dista << 502           G4cout << "   G4VTwistSurface::DistanceToOut(p,v): normal*gv < 0, normal " 
530                  << fName << " " << normal        503                  << fName << " " << normal 
531                  << G4endl;                       504                  << G4endl;
532 #endif                                            505 #endif 
533       }                                        << 506       } else {
534       else                                     << 
535       {                                        << 
536          // gxx[i] is accepted.                   507          // gxx[i] is accepted.
537          if (distance[i] < bestdistance)       << 508          if (distance[i] < bestdistance) {
538          {                                     << 
539             bestdistance = distance[i];           509             bestdistance = distance[i];
540             gxxbest = gxx[i];                     510             gxxbest = gxx[i];
                                                   >> 511             besti   = i;
541          }                                        512          }
542       }                                           513       } 
543    }                                              514    }
544                                                   515 
545 #ifdef G4TWISTDEBUG                            << 516 #ifdef G4SPECSDEBUG
546    if (besti < 0)                              << 517    if (besti < 0) {
547    {                                           << 518       G4cout << "~~~~~ G4VTwistSurface::DistanceToOut(p,v) - return ~~~" << G4endl;
548       G4cout << "~~ G4VTwistSurface::DistanceT << 
549       G4cout << "      No intersections   " <<    519       G4cout << "      No intersections   " << G4endl; 
550       G4cout << "      Name     : " << fName <    520       G4cout << "      Name     : " << fName << G4endl; 
551       G4cout << "      bestdist : " << bestdis    521       G4cout << "      bestdist : " << bestdistance << G4endl;
552       G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    522       G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << G4endl;
553    }                                           << 523    } else {
554    else                                        << 524       G4cout << "~~~~~ G4VTwistSurface::DistanceToOut(p,v) : return ~~~" << G4endl;
555    {                                           << 
556       G4cout << "~~ G4VTwistSurface::DistanceT << 
557       G4cout << "      Name, i  : " << fName <    525       G4cout << "      Name, i  : " << fName << " , " << i << G4endl; 
558       G4cout << "      gxx[i]   : " << gxxbest    526       G4cout << "      gxx[i]   : " << gxxbest << G4endl; 
559       G4cout << "      bestdist : " << bestdis    527       G4cout << "      bestdist : " << bestdistance << G4endl;
560       G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    528       G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << G4endl;
561    }                                              529    } 
562 #endif                                            530 #endif
563                                                   531 
564    return bestdistance;                           532    return bestdistance;
565 }                                                 533 }
566                                                   534 
567 //============================================    535 //=====================================================================
568 //* DistanceTo(p) ----------------------------    536 //* DistanceTo(p) -----------------------------------------------------
569                                                   537 
570 G4double G4VTwistSurface::DistanceTo(const G4T << 538 G4double G4VTwistSurface::DistanceTo(const G4ThreeVector &gp,
571                                            G4T << 539                                       G4ThreeVector &gxxbest)
572 {                                                 540 {
573 #ifdef G4TWISTDEBUG                            << 541 #ifdef G4SPECSDEBUG
574    G4cout << "~~~~~ G4VTwistSurface::DistanceT    542    G4cout << "~~~~~ G4VTwistSurface::DistanceTo(p) - Start ~~~~~~~~~" << G4endl;
575    G4cout << "      Name : " << fName << G4end    543    G4cout << "      Name : " << fName << G4endl;
576    G4cout << "      gp   : " << gp << G4endl;     544    G4cout << "      gp   : " << gp << G4endl;
577    G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    545    G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << G4endl;
578 #endif                                            546 #endif
579                                                   547 
580                                                   548 
581    G4ThreeVector gxx[G4VSURFACENXX];              549    G4ThreeVector gxx[G4VSURFACENXX];
582    G4double      distance[G4VSURFACENXX]  ;       550    G4double      distance[G4VSURFACENXX]  ; 
583    G4int         areacode[G4VSURFACENXX]  ;       551    G4int         areacode[G4VSURFACENXX]  ;
584                                                   552    
585    for (G4int i = 0 ; i<G4VSURFACENXX ; ++i )  << 553    for (G4int i = 0 ; i<G4VSURFACENXX ; i++ ) {
586    {                                           << 
587      distance[i] = kInfinity ;                    554      distance[i] = kInfinity ;
588      areacode[i] = sOutside ;                     555      areacode[i] = sOutside ;
589    }                                              556    }
590                                                   557 
591    DistanceToSurface(gp, gxx, distance, areaco << 558    G4int nxx;
                                                   >> 559 
                                                   >> 560    nxx = DistanceToSurface(gp, gxx, distance, areacode);
592    gxxbest = gxx[0];                              561    gxxbest = gxx[0];
593                                                   562 
594 #ifdef G4TWISTDEBUG                            << 563 #ifdef G4SPECSDEBUG
595    G4cout << "~~~~~ G4VTwistSurface::DistanceT    564    G4cout << "~~~~~ G4VTwistSurface::DistanceTo(p) - return ~~~~~~~~" << G4endl;
596    G4cout << "      Name     : " << fName << G    565    G4cout << "      Name     : " << fName << G4endl; 
597    G4cout << "      gxx      : " << gxxbest <<    566    G4cout << "      gxx      : " << gxxbest << G4endl; 
598    G4cout << "      bestdist : " << distance[0    567    G4cout << "      bestdist : " << distance[0] << G4endl;
599    G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    568    G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << G4endl;
600 #endif                                            569 #endif
601                                                   570 
602    return distance[0];                            571    return distance[0];
603 }                                                 572 }
604                                                   573 
605 //============================================    574 //=====================================================================
606 //* IsSameBoundary ---------------------------    575 //* IsSameBoundary ----------------------------------------------------
607                                                   576 
608 G4bool                                         << 577 G4bool G4VTwistSurface::IsSameBoundary(G4VTwistSurface *surface1, G4int areacode1,
609 G4VTwistSurface::IsSameBoundary(G4VTwistSurfac << 578                                   G4VTwistSurface *surface2, G4int areacode2 ) const
610                                 G4VTwistSurfac << 
611 {                                                 579 {
612    //                                             580    //
613    // IsSameBoundary                              581    // IsSameBoundary
614    //                                             582    //
615    // checking tool whether two boundaries on     583    // checking tool whether two boundaries on different surfaces are same or not.
616    //                                             584    //
617                                                   585 
618    G4bool testbitmode = true;                     586    G4bool testbitmode = true;
619    G4bool iscorner[2] = {IsCorner(areacode1, t    587    G4bool iscorner[2] = {IsCorner(areacode1, testbitmode), 
620                          IsCorner(areacode2, t    588                          IsCorner(areacode2, testbitmode)};
621                                                   589 
622    if (iscorner[0] && iscorner[1])             << 590    if (iscorner[0] && iscorner[1]) {
623    {                                           << 
624       // on corner                                591       // on corner 
625       G4ThreeVector corner1 =                     592       G4ThreeVector corner1 = 
626            surf1->ComputeGlobalPoint(surf1->Ge << 593            surface1->ComputeGlobalPoint(surface1->GetCorner(areacode1));
627       G4ThreeVector corner2 =                     594       G4ThreeVector corner2 = 
628            surf2->ComputeGlobalPoint(surf2->Ge << 595            surface2->ComputeGlobalPoint(surface2->GetCorner(areacode2));
629                                                   596 
630       return (corner1 - corner2).mag() < kCarT << 597       if ((corner1 - corner2).mag() < kCarTolerance) {
631    }                                           << 598          return true;
632    else if ((IsBoundary(areacode1, testbitmode << 599       } else {
633             (IsBoundary(areacode2, testbitmode << 600          return false;
634    {                                           << 601       }
                                                   >> 602     
                                                   >> 603    } else if ((IsBoundary(areacode1, testbitmode) && (!iscorner[0])) &&
                                                   >> 604               (IsBoundary(areacode2, testbitmode) && (!iscorner[1]))) {
635       // on boundary                              605       // on boundary  
636       G4ThreeVector d1, d2, ld1, ld2;             606       G4ThreeVector d1, d2, ld1, ld2;
637       G4ThreeVector x01, x02, lx01, lx02;         607       G4ThreeVector x01, x02, lx01, lx02;
638       G4int         type1, type2;                 608       G4int         type1, type2;
639       surf1->GetBoundaryParameters(areacode1,  << 609       surface1->GetBoundaryParameters(areacode1, ld1, lx01, type1);
640       surf2->GetBoundaryParameters(areacode2,  << 610       surface2->GetBoundaryParameters(areacode2, ld2, lx02, type2);
641                                                   611 
642       x01 = surf1->ComputeGlobalPoint(lx01);   << 612       x01 = surface1->ComputeGlobalPoint(lx01);
643       x02 = surf2->ComputeGlobalPoint(lx02);   << 613       x02 = surface2->ComputeGlobalPoint(lx02);
644       d1  = surf1->ComputeGlobalDirection(ld1) << 614       d1  = surface1->ComputeGlobalDirection(ld1);
645       d2  = surf2->ComputeGlobalDirection(ld2) << 615       d2  = surface2->ComputeGlobalDirection(ld2);
                                                   >> 616 
                                                   >> 617       if ((x01 - x02).mag() < kCarTolerance &&
                                                   >> 618           (d1 - d2).mag() < kCarTolerance) {
                                                   >> 619         return true;
                                                   >> 620       } else {
                                                   >> 621         return false;
                                                   >> 622       }
646                                                   623 
647       return (x01 - x02).mag() < kCarTolerance << 624    } else {
648             && (d1 - d2).mag() < kCarTolerance << 
649    }                                           << 
650    else                                        << 
651    {                                           << 
652       return false;                               625       return false;
653    }                                              626    }
654 }                                                 627 }
655                                                   628 
656 //============================================    629 //=====================================================================
657 //* GetBoundaryParameters --------------------    630 //* GetBoundaryParameters ---------------------------------------------
658                                                   631 
659 void G4VTwistSurface::GetBoundaryParameters(co << 632 void G4VTwistSurface::GetBoundaryParameters(const G4int         &areacode,
660                                              G << 633                                              G4ThreeVector &d,
661                                              G << 634                                              G4ThreeVector &x0,
662                                              G << 635                                              G4int         &boundarytype) const
663 {                                                 636 {
664    // areacode must be one of them:               637    // areacode must be one of them:
665    // sAxis0 & sAxisMin, sAxis0 & sAxisMax,       638    // sAxis0 & sAxisMin, sAxis0 & sAxisMax,
666    // sAxis1 & sAxisMin, sAxis1 & sAxisMax.       639    // sAxis1 & sAxisMin, sAxis1 & sAxisMax.
667                                                   640    
668    for (const auto & boundary : fBoundaries)   << 641    G4int i;
669    {                                           << 642    for (i=0; i<4; i++) {
670       if (boundary.GetBoundaryParameters(areac << 643       if (fBoundaries[i].GetBoundaryParameters(areacode, d, x0,
671       {                                        << 644                                                boundarytype)) {
672          return;                                  645          return;
673       }                                           646       }
674    }                                              647    }
675                                                   648 
676    std::ostringstream message;                 << 649    G4cerr << "ERROR - G4VTwistSurface::GetBoundaryParameters()" << G4endl
677    message << "Not registered boundary." << G4 << 650           << "        Boundary at areacode " << std::hex << areacode
678            << "        Boundary at areacode "  << 651           << std::dec << G4endl
679            << std::dec << G4endl               << 652           << "        is not be registered." << G4endl;
680            << "        is not registered.";    << 653    G4Exception("G4VTwistSurface::GetBoundaryParameters()", "InvalidSetup",
681    G4Exception("G4VTwistSurface::GetBoundaryPa << 654                FatalException, "Not registered boundary.");
682                FatalException, message);       << 
683 }                                                 655 }
684                                                   656 
685 //============================================    657 //=====================================================================
686 //* GetBoundaryAtPZ --------------------------    658 //* GetBoundaryAtPZ ---------------------------------------------------
687                                                   659 
688 G4ThreeVector G4VTwistSurface::GetBoundaryAtPZ    660 G4ThreeVector G4VTwistSurface::GetBoundaryAtPZ(G4int areacode,
689                                                << 661                                           const G4ThreeVector &p) const
690 {                                                 662 {
691    // areacode must be one of them:               663    // areacode must be one of them:
692    // sAxis0 & sAxisMin, sAxis0 & sAxisMax,       664    // sAxis0 & sAxisMin, sAxis0 & sAxisMax,
693    // sAxis1 & sAxisMin, sAxis1 & sAxisMax.       665    // sAxis1 & sAxisMin, sAxis1 & sAxisMax.
694                                                   666 
695    if (((areacode & sAxis0) != 0) && ((areacod << 667    if (areacode & sAxis0 && areacode & sAxis1) {
696    {                                           << 668      G4cerr << "ERROR - G4VTwistSurface::GetBoundaryAtPZ()" << G4endl
697      std::ostringstream message;               << 669             << "        Point is in the corner area. This function returns"
698      message << "Point is in the corner area." << 670             << G4endl
699              << "        This function returns << 671             << "        a direction vector of a boundary line." << G4endl
700              << "a direction vector of a bound << 672             << "        areacode = " << areacode << G4endl;
701              << "        areacode = " << areac << 673      G4Exception("G4VTwistSurface::GetBoundaryAtPZ()", "InvalidCondition",
702      G4Exception("G4VTwistSurface::GetBoundary << 674                  FatalException, "Point is in the corner area.");
703                  FatalException, message);     << 
704    }                                              675    }
705                                                   676 
706    G4ThreeVector d;                               677    G4ThreeVector d;
707    G4ThreeVector x0;                              678    G4ThreeVector x0;
708    G4int         boundarytype = 0;             << 679    G4int         boundarytype;
709    G4bool        found = false;                   680    G4bool        found = false;
710                                                   681    
711    for (const auto & boundary : fBoundaries)   << 682    for (G4int i=0; i<4; i++) {
712    {                                           << 683       if (fBoundaries[i].GetBoundaryParameters(areacode, d, x0, 
713       if (boundary.GetBoundaryParameters(areac << 684                                                 boundarytype)){
714       {                                        << 
715          found = true;                            685          found = true;
716          continue;                                686          continue;
717       }                                           687       }
718    }                                              688    }
719                                                   689 
720    if (!found)                                 << 690    if (!found) {
721    {                                           << 691      G4cerr << "ERROR - G4VTwistSurface::GetBoundaryAtPZ()" << G4endl
722      std::ostringstream message;               << 692             << "        Boundary at areacode " << areacode << G4endl
723      message << "Not registered boundary." <<  << 693             << "        is not be registered." << G4endl;
724              << "        Boundary at areacode  << 694      G4Exception("G4VTwistSurface::GetBoundaryAtPZ()", "InvalidSetup",
725              << "        is not registered.";  << 695                  FatalException, "Not registered boundary.");
726      G4Exception("G4VTwistSurface::GetBoundary << 
727                  FatalException, message);     << 
728    }                                              696    }
729                                                   697 
730    if (((boundarytype & sAxisPhi) == sAxisPhi)    698    if (((boundarytype & sAxisPhi) == sAxisPhi) ||
731        ((boundarytype & sAxisRho) == sAxisRho) << 699        ((boundarytype & sAxisRho) == sAxisRho)) {
732    {                                           << 700      G4cerr << "ERROR - G4VTwistSurface::GetBoundaryAtPZ()" << G4endl
733      std::ostringstream message;               << 701             << "        Boundary at areacode " << areacode << G4endl
734      message << "Not a z-depended line boundar << 702             << "        is not a z-depended line." << G4endl;
735              << "        Boundary at areacode  << 703      G4Exception("G4VTwistSurface::GetBoundaryAtPZ()", "InvalidSetup",
736              << "        is not a z-depended l << 704                  FatalException, "Not a z-depended line boundary.");
737      G4Exception("G4VTwistSurface::GetBoundary << 
738                  FatalException, message);     << 
739    }                                              705    }
740    return ((p.z() - x0.z()) / d.z()) * d + x0;    706    return ((p.z() - x0.z()) / d.z()) * d + x0;
741 }                                                 707 }
742                                                   708 
743 //============================================    709 //=====================================================================
744 //* SetCorner --------------------------------    710 //* SetCorner ---------------------------------------------------------
745                                                   711 
746 void G4VTwistSurface::SetCorner(G4int areacode << 712 void G4VTwistSurface::SetCorner(G4int areacode, G4double x, G4double y, G4double z)
747                                 G4double x, G4 << 
748 {                                                 713 {
749    if ((areacode & sCorner) != sCorner)        << 714    if ((areacode & sCorner) != sCorner){
750    {                                           << 715      G4cerr << "ERROR - G4VTwistSurface::SetCorner()" << G4endl
751      std::ostringstream message;               << 716             << "        areacode " << areacode << G4endl;
752      message << "Area code must represents cor << 717      G4Exception("G4VTwistSurface::SetCorner()", "InvalidSetup",
753              << "        areacode " << areacod << 718                  FatalException, "Area code must represents corner.");
754      G4Exception("G4VTwistSurface::SetCorner() << 
755                  FatalException, message);     << 
756    }                                              719    }
757                                                   720 
758    if ((areacode & sC0Min1Min) == sC0Min1Min)     721    if ((areacode & sC0Min1Min) == sC0Min1Min) {
759       fCorners[0].set(x, y, z);                   722       fCorners[0].set(x, y, z);
760    } else if ((areacode & sC0Max1Min) == sC0Ma    723    } else if ((areacode & sC0Max1Min) == sC0Max1Min) {
761       fCorners[1].set(x, y, z);                   724       fCorners[1].set(x, y, z);
762    } else if ((areacode & sC0Max1Max) == sC0Ma    725    } else if ((areacode & sC0Max1Max) == sC0Max1Max) {
763       fCorners[2].set(x, y, z);                   726       fCorners[2].set(x, y, z);
764    } else if ((areacode & sC0Min1Max) == sC0Mi    727    } else if ((areacode & sC0Min1Max) == sC0Min1Max) {
765       fCorners[3].set(x, y, z);                   728       fCorners[3].set(x, y, z);
766    }                                              729    }
767 }                                                 730 }
768                                                   731 
769 //============================================    732 //=====================================================================
770 //* SetBoundaryAxis --------------------------    733 //* SetBoundaryAxis ---------------------------------------------------
771                                                   734 
772 void G4VTwistSurface::GetBoundaryAxis(G4int ar    735 void G4VTwistSurface::GetBoundaryAxis(G4int areacode, EAxis axis[]) const
773 {                                                 736 {
774    if ((areacode & sBoundary) != sBoundary) {     737    if ((areacode & sBoundary) != sBoundary) {
775      G4Exception("G4VTwistSurface::GetBoundary << 738      G4Exception("G4VTwistSurface::GetBoundaryAxis()", "InvalidCondition",
776                  FatalException, "Not located     739                  FatalException, "Not located on a boundary!");
777    }                                              740    }
778    for (G4int i=0; i<2; ++i)                   << 741    G4int i;
779    {                                           << 742    for (i=0; i<2; i++) {
                                                   >> 743 
780       G4int whichaxis = 0 ;                       744       G4int whichaxis = 0 ;
781       if (i == 0) {                               745       if (i == 0) {
782          whichaxis = sAxis0;                      746          whichaxis = sAxis0;
783       } else if (i == 1) {                        747       } else if (i == 1) {
784          whichaxis = sAxis1;                      748          whichaxis = sAxis1;
785       }                                           749       }
786                                                   750       
787       // extracted axiscode of whichaxis          751       // extracted axiscode of whichaxis
788       G4int axiscode = whichaxis & sAxisMask &    752       G4int axiscode = whichaxis & sAxisMask & areacode ; 
789       if (axiscode != 0) {                     << 753       if (axiscode) {
790          if (axiscode == (whichaxis & sAxisX))    754          if (axiscode == (whichaxis & sAxisX)) {
791             axis[i] = kXAxis;                     755             axis[i] = kXAxis;
792          } else if (axiscode == (whichaxis & s    756          } else if (axiscode == (whichaxis & sAxisY)) {
793             axis[i] = kYAxis;                     757             axis[i] = kYAxis;
794          } else if (axiscode == (whichaxis & s    758          } else if (axiscode == (whichaxis & sAxisZ)) {
795             axis[i] = kZAxis;                     759             axis[i] = kZAxis;
796          } else if (axiscode == (whichaxis & s    760          } else if (axiscode == (whichaxis & sAxisRho)) {
797             axis[i] = kRho;                       761             axis[i] = kRho;
798          } else if (axiscode == (whichaxis & s    762          } else if (axiscode == (whichaxis & sAxisPhi)) {
799             axis[i] = kPhi;                       763             axis[i] = kPhi;
800          } else {                                 764          } else {
801            std::ostringstream message;         << 765            G4cerr << "ERROR - G4VTwistSurface::GetBoundaryAxis()" << G4endl
802            message << "Not supported areacode. << 766                   << "        areacode " << areacode << G4endl;
803                    << "        areacode " << a << 767            G4Exception("G4VTwistSurface::GetBoundaryAxis()", "InvalidSetup",
804            G4Exception("G4VTwistSurface::GetBo << 768                        FatalException, "Not supported areacode.");
805                        FatalException, message << 
806          }                                        769          }
807       }                                           770       }
808    }                                              771    }
809 }                                                 772 }
810                                                   773 
811 //============================================    774 //=====================================================================
812 //* SetBoundaryLimit -------------------------    775 //* SetBoundaryLimit --------------------------------------------------
813                                                   776 
814 void G4VTwistSurface::GetBoundaryLimit(G4int a    777 void G4VTwistSurface::GetBoundaryLimit(G4int areacode, G4double limit[]) const
815 {                                                 778 {
816    if ((areacode & sCorner) != 0) {            << 779    if (areacode & sCorner) {
817       if ((areacode & sC0Min1Min) != 0) {      << 780       if (areacode & sC0Min1Max) {
818          limit[0] = fAxisMin[0];                  781          limit[0] = fAxisMin[0];
819          limit[1] = fAxisMin[1];                  782          limit[1] = fAxisMin[1];
820       } else if ((areacode & sC0Max1Min) != 0) << 783       } else if (areacode & sC0Max1Min) {
821          limit[0] = fAxisMax[0];                  784          limit[0] = fAxisMax[0];
822          limit[1] = fAxisMin[1];                  785          limit[1] = fAxisMin[1];
823       } else if ((areacode & sC0Max1Max) != 0) << 786       } else if (areacode & sC0Max1Max) {
824          limit[0] = fAxisMax[0];                  787          limit[0] = fAxisMax[0];
825          limit[1] = fAxisMax[1];                  788          limit[1] = fAxisMax[1];
826       } else if ((areacode & sC0Min1Max) != 0) << 789       } else if (areacode & sC0Min1Max) {
827          limit[0] = fAxisMin[0];                  790          limit[0] = fAxisMin[0];
828          limit[1] = fAxisMax[1];                  791          limit[1] = fAxisMax[1];
829       }                                           792       }
830    } else if ((areacode & sBoundary) != 0) {   << 793    } else if (areacode & sBoundary) {
831       if ((areacode & (sAxis0 | sAxisMin)) !=  << 794       if (areacode & (sAxis0 | sAxisMin)) {
832          limit[0] = fAxisMin[0];                  795          limit[0] = fAxisMin[0];
833       } else if ((areacode & (sAxis1 | sAxisMi << 796       } else if (areacode & (sAxis1 | sAxisMin)) {
834          limit[0] = fAxisMin[1];                  797          limit[0] = fAxisMin[1];
835       } else if ((areacode & (sAxis0 | sAxisMa << 798       } else if (areacode & (sAxis0 | sAxisMax)) {
836          limit[0] = fAxisMax[0];                  799          limit[0] = fAxisMax[0];
837       } else if ((areacode & (sAxis1 | sAxisMa << 800       } else if (areacode & (sAxis1 | sAxisMax)) {
838          limit[0] = fAxisMax[1];                  801          limit[0] = fAxisMax[1];
839       }                                           802       }
840    } else {                                       803    } else {
841      std::ostringstream message;               << 804      G4cerr << "WARNING - G4VTwistSurface::GetBoundaryAxis()" << G4endl
842      message << "Not located on a boundary!" < << 805             << "          areacode " << areacode << G4endl;
843              << "          areacode " << areac << 806      G4Exception("G4VTwistSurface::GetBoundaryLimit()", "InvalidCondition",
844      G4Exception("G4VTwistSurface::GetBoundary << 807                  JustWarning, "Not located on a boundary!");
845                  JustWarning, message);        << 
846    }                                              808    }
847 }                                                 809 }
848                                                   810 
849 //============================================    811 //=====================================================================
850 //* SetBoundary ------------------------------    812 //* SetBoundary -------------------------------------------------------
851                                                   813 
852 void G4VTwistSurface::SetBoundary(const G4int& << 814 void G4VTwistSurface::SetBoundary(const G4int         &axiscode,
853                                   const G4Thre << 815                              const G4ThreeVector &direction,
854                                   const G4Thre << 816                              const G4ThreeVector &x0,
855                                   const G4int& << 817                              const G4int         &boundarytype)
856 {                                                 818 {
857    G4int code = (~sAxisMask) & axiscode;          819    G4int code = (~sAxisMask) & axiscode;
858    if ((code == (sAxis0 & sAxisMin)) ||           820    if ((code == (sAxis0 & sAxisMin)) ||
859        (code == (sAxis0 & sAxisMax)) ||           821        (code == (sAxis0 & sAxisMax)) ||
860        (code == (sAxis1 & sAxisMin)) ||           822        (code == (sAxis1 & sAxisMin)) ||
861        (code == (sAxis1 & sAxisMax)))          << 823        (code == (sAxis1 & sAxisMax))) {
862    {                                           << 824 
                                                   >> 825       G4int i;
863       G4bool done = false;                        826       G4bool done = false;
864       for (auto & boundary : fBoundaries)      << 827       for (i=0; i<4; i++) {
865       {                                        << 828          if (fBoundaries[i].IsEmpty()) {
866          if (boundary.IsEmpty())               << 829             fBoundaries[i].SetFields(axiscode, direction,
867          {                                     << 830                                      x0, boundarytype);
868             boundary.SetFields(axiscode, direc << 
869             done = true;                          831             done = true;
870             break;                                832             break;
871          }                                        833          }
872       }                                           834       }
873                                                   835 
874       if (!done)                               << 836       if (!done) {
875       {                                        << 837          G4Exception("G4VTwistSurface::SetBoundary()", "InvalidCondition",
876          G4Exception("G4VTwistSurface::SetBoun << 
877                       FatalException, "Number     838                       FatalException, "Number of boundary exceeding 4!");
878       }                                           839       }
879    }                                           << 840    } else {
880    else                                        << 841       G4cerr << "ERROR - G4VTwistSurface::SetBoundary()" << G4endl
881    {                                           << 842              << "        invalid axiscode. axiscode = "
882       std::ostringstream message;              << 843              << std::hex << axiscode << std::dec << G4endl;
883       message << "Invalid axis-code." << G4end << 844       G4Exception("G4VTwistSurface::SetBoundary()", "InvalidCondition",
884               << "        axiscode = "         << 845                   FatalException, "Invalid axis-code.");
885               << std::hex << axiscode << std:: << 
886       G4Exception("G4VTwistSurface::SetBoundar << 
887                   FatalException, message);    << 
888    }                                              846    }
889 }                                                 847 }
890                                                   848 
891 //============================================    849 //=====================================================================
892 //* GetFace ----------------------------------    850 //* GetFace -----------------------------------------------------------
893                                                   851 
894 G4int G4VTwistSurface::GetFace( G4int i, G4int << 852 G4int G4VTwistSurface::GetFace( G4int i, G4int j, G4int m,
895                                 G4int n, G4int    853                                 G4int n, G4int iside ) 
896 {                                                 854 {
897   // this is the face mapping function            855   // this is the face mapping function
898   // (i,j) -> face number                         856   // (i,j) -> face number
899                                                   857 
900   if ( iside == 0 ) {                             858   if ( iside == 0 ) {
901     return i * ( k - 1 ) + j ;                 << 859     return i * ( m - 1 ) + j ;
902   }                                               860   }
903                                                   861 
904   else if ( iside == 1 ) {                        862   else if ( iside == 1 ) {
905     return (k-1)*(k-1) + i*(k-1) + j ;         << 863     return (m-1)*(m-1) + i*(m-1) + j ;
906   }                                               864   }
907                                                   865 
908   else if ( iside == 2 ) {                        866   else if ( iside == 2 ) {
909     return 2*(k-1)*(k-1) + i*(k-1) + j ;       << 867     return 2*(m-1)*(m-1) + i*(m-1) + j ;
910   }                                               868   }
911                                                   869 
912   else if ( iside == 3 ) {                        870   else if ( iside == 3 ) {
913     return 2*(k-1)*(k-1) + (n-1)*(k-1) + i*(k- << 871     return 2*(m-1)*(m-1) + (n-1)*(m-1) + i*(m-1) + j ;
914   }                                               872   }
915                                                   873   
916   else if ( iside == 4 ) {                        874   else if ( iside == 4 ) {
917     return 2*(k-1)*(k-1) + 2*(n-1)*(k-1) + i*( << 875     return 2*(m-1)*(m-1) + 2*(n-1)*(m-1) + i*(m-1) + j ;
918   }                                               876   }
919                                                   877   
920   else if ( iside == 5 ) {                        878   else if ( iside == 5 ) {
921     return 2*(k-1)*(k-1) + 3*(n-1)*(k-1) + i*( << 879     return 2*(m-1)*(m-1) + 3*(n-1)*(m-1) + i*(m-1) + j ;
922   }                                               880   }
923                                                   881 
924   else {                                          882   else {
925     std::ostringstream message;                << 883 
926     message << "Not correct side number: "     << 884    G4cerr << "ERROR - G4VTwistSurface::GetFace(): "
927             << GetName() << G4endl             << 885            << GetName() << G4endl
928             << "iside is " << iside << " but s << 886            << "        Not correct side number! - " << G4endl 
929             << "0,1,2,3,4 or 5" << ".";        << 887            << "iside is " << iside << " but should be "
930     G4Exception("G4TwistSurface::G4GetFace()", << 888            << "0,1,2,3,4 or 5" << "." << G4endl ;
931                 FatalException, message);      << 889     G4Exception("G4TwistSurface::G4GetFace()", "InvalidSetup",
                                                   >> 890                 FatalException, "Not correct side number.");
                                                   >> 891 
                                                   >> 892 
932   }                                               893   }
933                                                   894 
934   return -1 ;  // wrong face                      895   return -1 ;  // wrong face
935 }                                                 896 }
936                                                   897 
937 //============================================    898 //=====================================================================
938 //* GetNode ----------------------------------    899 //* GetNode -----------------------------------------------------------
939                                                   900 
940 G4int G4VTwistSurface::GetNode( G4int i, G4int << 901 G4int G4VTwistSurface::GetNode( G4int i, G4int j, G4int m,
941                                 G4int n, G4int    902                                 G4int n, G4int iside ) 
942 {                                                 903 {
943   // this is the node mapping function            904   // this is the node mapping function
944   // (i,j) -> node number                         905   // (i,j) -> node number
945   // Depends on the side iside and the used me    906   // Depends on the side iside and the used meshing of the surface
946                                                   907 
947   if ( iside == 0 )                            << 908   if ( iside == 0 ) {
948   {                                            << 909     // lower endcap is mxm squared. 
949     // lower endcap is kxk squared.            << 910     // n = m 
950     // n = k                                   << 911     return i * m + j ;
951     return i * k + j ;                         << 
952   }                                               912   }
953                                                   913 
954   if ( iside == 1 )                            << 914   if ( iside == 1 ) {
955   {                                            << 915     // upper endcap is mxm squared. Shift by m*m
956     // upper endcap is kxk squared. Shift by k << 916     // n = m 
957     // n = k                                   << 917     return  m*m + i*m + j ;
958     return  k*k + i*k + j ;                    << 
959   }                                               918   }
960                                                   919 
961   else if ( iside == 2 )                       << 920   else if ( iside == 2 ) {
962   {                                            << 
963     // front side.                                921     // front side.
964     if      ( i == 0 )   { return       j ;  } << 922     if      ( i == 0 )     {   return       j ;  }
965     else if ( i == n-1 ) { return k*k + j ;  } << 923     else if ( i == n-1 )   {   return m*m + j ;  } 
966     else                 { return 2*k*k + 4*(i << 924     else                   {   return 2*m*m + 4*(i-1)*(m-1) + j ; }
967   }                                               925   }
968                                                   926 
969   else if ( iside == 3 )                       << 927   else if ( iside == 3 ) {
970   {                                            << 
971     // right side                                 928     // right side
972     if      ( i == 0 )   { return       (j+1)* << 929     if      ( i == 0 )     {   return       (j+1)*m - 1 ; } 
973     else if ( i == n-1 ) { return k*k + (j+1)* << 930     else if ( i == n-1 )   {   return m*m + (j+1)*m - 1 ; }
974     else                                       << 931     else                   {   return 2*m*m + 4*(i-1)*(m-1) + (m-1) + j ; }
975     {                                          << 
976       return 2*k*k + 4*(i-1)*(k-1) + (k-1) + j << 
977     }                                          << 
978   }                                               932   }
979   else if ( iside == 4 )                       << 933   else if ( iside == 4 ) {
980   {                                            << 934     // back side.
981     // back side                               << 935     if      ( i == 0 )     {   return   m*m - 1 - j ; }               // reversed order
982     if      ( i == 0 )   { return   k*k - 1 -  << 936     else if ( i == n-1 )   {   return 2*m*m - 1 - j ; }               // reversed order 
983     else if ( i == n-1 ) { return 2*k*k - 1 -  << 937     else                   {   return 2*m*m + 4*(i-1)*(m-1) + 2*(m-1) + j ; // normal order
984     else                                       << 
985     {                                          << 
986       return 2*k*k + 4*(i-1)*(k-1) + 2*(k-1) + << 
987     }                                             938     }
988   }                                               939   }
989   else if ( iside == 5 )                       << 940   else if ( iside == 5 ) {
990   {                                            << 
991     // left side                                  941     // left side 
992     if      ( i == 0 )   { return k*k   - (j+1 << 942     if      ( i == 0 )     {   return m*m   - (j+1)*m ; }             // reversed order
993     else if ( i == n-1)  { return 2*k*k - (j+1 << 943     else if ( i == n-1)    {   return 2*m*m - (j+1)*m ; }             // reverded order
994     else                                       << 944     else {
995     {                                          << 945       if ( j == m-1 )      {   return 2*m*m + 4*(i-1)*(m-1) ; }       // special case
996       if ( j == k-1 ) { return 2*k*k + 4*(i-1) << 946       else                 {   return 2*m*m + 4*(i-1)*(m-1) + 3*(m-1) + j ; }  // normal order
997       else                                     << 947     }  
998       {                                        << 
999         return 2*k*k + 4*(i-1)*(k-1) + 3*(k-1) << 
1000       }                                       << 
1001     }                                         << 
1002   }                                              948   }
1003   else                                        << 949 
1004   {                                           << 950   else {
1005     std::ostringstream message;               << 951 
1006     message << "Not correct side number: "    << 952     G4cerr << "ERROR - G4VTwistSurface::GetNode(): "
1007             << GetName() << G4endl            << 953            << GetName() << G4endl
1008             << "iside is " << iside << " but  << 954            << "        Not correct side number! - " << G4endl 
1009             << "0,1,2,3,4 or 5" << ".";       << 955            << "iside is " << iside << " but should be "
1010     G4Exception("G4TwistSurface::G4GetNode()" << 956            << "0,1,2,3,4 or 5" << "." << G4endl ;
1011                 FatalException, message);     << 957     G4Exception("G4TwistSurface::G4GetNode()", "InvalidSetup",
                                                   >> 958                 FatalException, "Not correct side number.");
1012   }                                              959   } 
1013   return -1 ;  // wrong node                     960   return -1 ;  // wrong node 
1014 }                                                961 } 
1015                                                  962 
1016 //===========================================    963 //=====================================================================
1017 //* GetEdgeVisiblility ----------------------    964 //* GetEdgeVisiblility ------------------------------------------------
1018                                                  965 
1019 G4int G4VTwistSurface::GetEdgeVisibility( G4i << 966 G4int G4VTwistSurface::GetEdgeVisibility( G4int i, G4int j, G4int m, G4int n, G4int number, G4int orientation) 
1020                                           G4i << 
1021 {                                                967 {
                                                   >> 968 
1022   // clockwise filling         -> positive or    969   // clockwise filling         -> positive orientation
1023   // counter clockwise filling -> negative or    970   // counter clockwise filling -> negative orientation 
1024                                                  971 
1025   //                                             972   //
1026   //   d    C    c                               973   //   d    C    c
1027   //     +------+                                974   //     +------+ 
1028   //     |      |                                975   //     |      |
1029   //     |      |                                976   //     |      |
1030   //     |      |                                977   //     |      |
1031   //   D |      |B                               978   //   D |      |B
1032   //     |      |                                979   //     |      |
1033   //     |      |                                980   //     |      |
1034   //     |      |                                981   //     |      |
1035   //     +------+                                982   //     +------+
1036   //    a   A    b                               983   //    a   A    b
1037   //                                             984   //    
1038   //  a = +--+    A = ---+                       985   //  a = +--+    A = ---+
1039   //  b = --++    B = --+-                       986   //  b = --++    B = --+-
1040   //  c = -++-    C = -+--                       987   //  c = -++-    C = -+--
1041   //  d = ++--    D = +---                       988   //  d = ++--    D = +---
1042                                                  989 
1043                                                  990 
1044   // check first invisible faces                 991   // check first invisible faces
1045                                                  992 
1046   if ( ( i>0 && i<n-2 ) && ( j>0 && j<k-2 ) ) << 993   if ( ( i>0 && i<n-2 ) && ( j>0 && j<m-2 ) ) {
1047   {                                           << 
1048     return -1 ;   // always invisible, signs:    994     return -1 ;   // always invisible, signs:   ----
1049   }                                              995   }
1050                                                  996   
1051   // change first the vertex number (depends     997   // change first the vertex number (depends on the orientation)
1052   // 0,1,2,3  -> 3,2,1,0                         998   // 0,1,2,3  -> 3,2,1,0
1053   if ( orientation < 0 ) { number = ( 3 - num    999   if ( orientation < 0 ) { number = ( 3 - number ) ;  }
1054                                                  1000   
1055   // check true edges                            1001   // check true edges
1056   if ( ( j>=1 && j<=k-3 ) )                   << 1002   if ( ( j>=1 && j<=m-3 ) ) {
1057   {                                           << 1003 
1058     if ( i == 0 )  {        // signs (A):  --    1004     if ( i == 0 )  {        // signs (A):  ---+  
1059       return ( number == 3 ) ? 1 : -1 ;          1005       return ( number == 3 ) ? 1 : -1 ;
1060     }                                            1006     }
1061                                                  1007     
1062     else if ( i == n-2 ) {  // signs (C):  -+    1008     else if ( i == n-2 ) {  // signs (C):  -+--
1063       return  ( number == 1 ) ? 1 : -1 ;         1009       return  ( number == 1 ) ? 1 : -1 ; 
1064     }                                            1010     }
1065                                                  1011     
1066     else                                      << 1012     else {
1067     {                                         << 1013       G4cerr << "ERROR - G4VTwistSurface::GetEdgeVisibliity(): "
1068       std::ostringstream message;             << 1014        << GetName() << G4endl
1069       message << "Not correct face number: "  << 1015        << "        Not correct face number! - " << G4endl ;
1070       G4Exception("G4TwistSurface::G4GetEdgeV << 1016   G4Exception("G4TwistSurface::G4GetEdgeVisibility()", "InvalidSetup",
1071                   "GeomSolids0003", FatalExce << 1017         FatalException, "Not correct face number.");
1072     }                                            1018     }
1073   }                                              1019   }
1074                                                  1020   
1075   if ( ( i>=1 && i<=n-3 ) )                   << 1021   if ( ( i>=1 && i<=n-3 ) ) {
1076   {                                           << 1022 
1077     if ( j == 0 )  {        // signs (D):  +-    1023     if ( j == 0 )  {        // signs (D):  +---
1078       return ( number == 0 ) ? 1 : -1 ;          1024       return ( number == 0 ) ? 1 : -1 ;
1079     }                                            1025     }
1080                                                  1026 
1081     else if ( j == k-2 ) {  // signs (B):  -- << 1027     else if ( j == m-2 ) {  // signs (B):  --+-
1082       return  ( number == 2 ) ? 1 : -1 ;         1028       return  ( number == 2 ) ? 1 : -1 ; 
1083     }                                            1029     }
1084                                                  1030 
1085     else                                      << 1031     else {
1086     {                                         << 1032       G4cerr << "ERROR - G4VTwistSurface::GetEdgeVisibliity(): "
1087       std::ostringstream message;             << 1033        << GetName() << G4endl
1088       message << "Not correct face number: "  << 1034        << "        Not correct face number! - " << G4endl ;
1089       G4Exception("G4TwistSurface::G4GetEdgeV << 1035   G4Exception("G4TwistSurface::G4GetEdgeVisibility()", "InvalidSetup",
1090                   "GeomSolids0003", FatalExce << 1036         FatalException, "Not correct face number.");
1091     }                                            1037     }
1092   }                                              1038   }
1093                                                  1039   
1094   // now the corners                             1040   // now the corners
1095   if ( i == 0 && j == 0 ) {          // signs    1041   if ( i == 0 && j == 0 ) {          // signs (a) : +--+
1096     return ( number == 0 || number == 3 ) ? 1    1042     return ( number == 0 || number == 3 ) ? 1 : -1 ;
1097   }                                              1043   }
1098   else if ( i == 0 && j == k-2 ) {   // signs << 1044   else if ( i == 0 && j == m-2 ) {   // signs (b) : --++
1099     return ( number == 2 || number == 3 ) ? 1    1045     return ( number == 2 || number == 3 ) ? 1 : -1 ;
1100   }                                              1046   }
1101   else if ( i == n-2 && j == k-2 ) { // signs << 1047   else if ( i == n-2 && j == m-2 ) { // signs (c) : -++-
1102     return ( number == 1 || number == 2 ) ? 1    1048     return ( number == 1 || number == 2 ) ? 1 : -1 ;
1103   }                                              1049   }
1104   else if ( i == n-2 && j == 0 ) {   // signs << 1050   else if ( i == n-2 && j == j ) {   // signs (d) : ++--
1105     return ( number == 0 || number == 1 ) ? 1    1051     return ( number == 0 || number == 1 ) ? 1 : -1 ;
1106   }                                              1052   }
1107   else                                        << 1053   else {
1108   {                                           << 1054     G4cerr << "ERROR - G4VTwistSurface::GetEdgeVisibliity(): "
1109     std::ostringstream message;               << 1055            << GetName() << G4endl
1110     message << "Not correct face number: " << << 1056            << "        Not correct face number! - " << G4endl ;
1111     G4Exception("G4TwistSurface::G4GetEdgeVis << 1057       G4Exception("G4TwistSurface::G4GetEdgeVisibility()", "InvalidSetup",
1112                 "GeomSolids0003", FatalExcept << 1058       FatalException, "Not correct face number.");
1113   }                                              1059   }
1114                                                  1060 
1115   std::ostringstream message;                 << 1061   G4cerr << "ERROR - G4VTwistSurface::GetEdgeVisibliity(): "
1116   message << "Not correct face number: " << G << 1062    << GetName() << G4endl
1117   G4Exception("G4TwistSurface::G4GetEdgeVisib << 1063    << "        Not correct face number! - " << G4endl ;
1118               FatalException, message);       << 1064     G4Exception("G4TwistSurface::G4GetEdgeVisibility()", "InvalidSetup",
1119                                               << 1065     FatalException, "Not correct face number.");
                                                   >> 1066   
1120   return 0 ;                                     1067   return 0 ;
                                                   >> 1068 
1121 }                                                1069 }
1122                                                  1070 
1123                                                  1071 
1124 //===========================================    1072 //=====================================================================
1125 //* DebugPrint ------------------------------    1073 //* DebugPrint --------------------------------------------------------
1126                                                  1074 
1127 void G4VTwistSurface::DebugPrint() const         1075 void G4VTwistSurface::DebugPrint() const
1128 {                                                1076 {
1129    G4ThreeVector A = fRot * GetCorner(sC0Min1    1077    G4ThreeVector A = fRot * GetCorner(sC0Min1Min) + fTrans;
1130    G4ThreeVector B = fRot * GetCorner(sC0Max1    1078    G4ThreeVector B = fRot * GetCorner(sC0Max1Min) + fTrans;
1131    G4ThreeVector C = fRot * GetCorner(sC0Max1    1079    G4ThreeVector C = fRot * GetCorner(sC0Max1Max) + fTrans;
1132    G4ThreeVector D = fRot * GetCorner(sC0Min1    1080    G4ThreeVector D = fRot * GetCorner(sC0Min1Max) + fTrans;
1133                                                  1081   
1134    G4cout << "/* G4VTwistSurface::DebugPrint( << 1082    G4cout << "/* G4VTwistSurface::DebugPrint():-------------------------------"
1135           << G4endl;                             1083           << G4endl;
1136    G4cout << "/* Name = " << fName << G4endl;    1084    G4cout << "/* Name = " << fName << G4endl;
1137    G4cout << "/* Axis = " << std::hex << fAxi    1085    G4cout << "/* Axis = " << std::hex << fAxis[0] << " "
1138           << std::hex << fAxis[1]                1086           << std::hex << fAxis[1] 
1139           << " (0,1,2,3,5 = kXAxis,kYAxis,kZA    1087           << " (0,1,2,3,5 = kXAxis,kYAxis,kZAxis,kRho,kPhi)"
1140           << std::dec << G4endl;                 1088           << std::dec << G4endl;
1141    G4cout << "/* BoundaryLimit(in local) fAxi    1089    G4cout << "/* BoundaryLimit(in local) fAxis0(min, max) = ("<<fAxisMin[0] 
1142           << ", " << fAxisMax[0] << ")" << G4    1090           << ", " << fAxisMax[0] << ")" << G4endl;
1143    G4cout << "/* BoundaryLimit(in local) fAxi    1091    G4cout << "/* BoundaryLimit(in local) fAxis1(min, max) = ("<<fAxisMin[1] 
1144           << ", " << fAxisMax[1] << ")" << G4    1092           << ", " << fAxisMax[1] << ")" << G4endl;
1145    G4cout << "/* Cornar point sC0Min1Min = "     1093    G4cout << "/* Cornar point sC0Min1Min = " << A << G4endl;
1146    G4cout << "/* Cornar point sC0Max1Min = "     1094    G4cout << "/* Cornar point sC0Max1Min = " << B << G4endl;
1147    G4cout << "/* Cornar point sC0Max1Max = "     1095    G4cout << "/* Cornar point sC0Max1Max = " << C << G4endl;
1148    G4cout << "/* Cornar point sC0Min1Max = "     1096    G4cout << "/* Cornar point sC0Min1Max = " << D << G4endl;
1149    G4cout << "/*-----------------------------    1097    G4cout << "/*---------------------------------------------------------"
1150           << G4endl;                             1098           << G4endl;
1151 }                                                1099 }
1152                                                  1100 
1153 //===========================================    1101 //=====================================================================
1154 // G4VTwistSurface::CurrentStatus class          1102 // G4VTwistSurface::CurrentStatus class
1155 //===========================================    1103 //=====================================================================
1156                                                  1104 
1157 //===========================================    1105 //=====================================================================
1158 //* CurrentStatus::CurrentStatus ------------    1106 //* CurrentStatus::CurrentStatus --------------------------------------
1159                                                  1107 
1160 G4VTwistSurface::CurrentStatus::CurrentStatus    1108 G4VTwistSurface::CurrentStatus::CurrentStatus() 
1161 {                                                1109 {
1162   for (size_t i=0; i<G4VSURFACENXX; ++i)      << 1110   for (size_t i=0; i<G4VSURFACENXX; i++)
1163   {                                              1111   {
1164     fDistance[i] = kInfinity;                    1112     fDistance[i] = kInfinity;
1165     fAreacode[i] = sOutside;                     1113     fAreacode[i] = sOutside;
1166     fIsValid[i]  = false;                        1114     fIsValid[i]  = false;
1167     fXX[i].set(kInfinity, kInfinity, kInfinit    1115     fXX[i].set(kInfinity, kInfinity, kInfinity);
1168   }                                              1116   }
1169   fNXX   = 0;                                    1117   fNXX   = 0;
1170   fLastp.set(kInfinity, kInfinity, kInfinity)    1118   fLastp.set(kInfinity, kInfinity, kInfinity);
1171   fLastv.set(kInfinity, kInfinity, kInfinity)    1119   fLastv.set(kInfinity, kInfinity, kInfinity);
1172   fLastValidate = kUninitialized;                1120   fLastValidate = kUninitialized;
1173   fDone = false;                                 1121   fDone = false;
1174 }                                                1122 }
1175                                                  1123 
1176 //===========================================    1124 //=====================================================================
1177 //* CurrentStatus::~CurrentStatus -----------    1125 //* CurrentStatus::~CurrentStatus -------------------------------------
1178                                                  1126 
1179 G4VTwistSurface::CurrentStatus::~CurrentStatu    1127 G4VTwistSurface::CurrentStatus::~CurrentStatus() 
1180 = default;                                    << 1128 {
                                                   >> 1129 }
1181                                                  1130 
1182 //===========================================    1131 //=====================================================================
1183 //* CurrentStatus::SetCurrentStatus ---------    1132 //* CurrentStatus::SetCurrentStatus -----------------------------------
1184                                                  1133 
1185 void                                             1134 void
1186 G4VTwistSurface::CurrentStatus::SetCurrentSta << 1135 G4VTwistSurface::CurrentStatus::SetCurrentStatus(G4int                i, 
1187                                               << 1136                                             G4ThreeVector       &xx, 
1188                                               << 1137                                             G4double            &dist, 
1189                                               << 1138                                             G4int               &areacode, 
1190                                               << 1139                                             G4bool              &isvalid,
1191                                               << 1140                                             G4int                nxx,
1192                                               << 1141                                             EValidate            validate,
1193                                            co << 1142                                       const G4ThreeVector *p, 
1194                                            co << 1143                                       const G4ThreeVector *v)
1195 {                                                1144 {
1196   fDistance[i]  = dist;                          1145   fDistance[i]  = dist;
1197   fAreacode[i]  = areacode;                      1146   fAreacode[i]  = areacode;
1198   fIsValid[i]   = isvalid;                       1147   fIsValid[i]   = isvalid;
1199   fXX[i]        = xx;                            1148   fXX[i]        = xx;
1200   fNXX          = nxx;                           1149   fNXX          = nxx;
1201   fLastValidate = validate;                      1150   fLastValidate = validate;
1202   if (p != nullptr)                           << 1151   if (p)
1203   {                                              1152   {
1204     fLastp = *p;                                 1153     fLastp = *p;
1205   }                                              1154   }
1206   else                                           1155   else
1207   {                                              1156   {
1208     G4Exception("G4VTwistSurface::CurrentStat << 1157     G4Exception("G4VTwistSurface::CurrentStatus::CurrentStatus()",
1209                 "GeomSolids0003", FatalExcept << 1158                 "InvalidCondition", FatalException,
                                                   >> 1159                 "SetCurrentStatus: p = 0!");
1210   }                                              1160   }
1211   if (v != nullptr)                           << 1161   if (v) 
1212   {                                              1162   {
1213     fLastv = *v;                                 1163     fLastv = *v;
1214   }                                              1164   }
1215   else                                           1165   else
1216   {                                              1166   {
1217     fLastv.set(kInfinity, kInfinity, kInfinit    1167     fLastv.set(kInfinity, kInfinity, kInfinity);
1218   }                                              1168   }
1219   fDone = true;                                  1169   fDone = true;
1220 }                                                1170 }
1221                                                  1171 
1222 //===========================================    1172 //=====================================================================
1223 //* CurrentStatus::ResetfDone ---------------    1173 //* CurrentStatus::ResetfDone -----------------------------------------
1224                                                  1174 
1225 void                                             1175 void
1226 G4VTwistSurface::CurrentStatus::ResetfDone(EV << 1176 G4VTwistSurface::CurrentStatus::ResetfDone(EValidate     validate,
1227                                      const G4 << 1177                                 const G4ThreeVector *p, 
1228                                      const G4 << 1178                                 const G4ThreeVector *v)
1229                                                  1179 
1230 {                                                1180 {
1231   if (validate == fLastValidate && p != nullp << 1181   if (validate == fLastValidate && p && *p == fLastp)
1232   {                                              1182   {
1233      if (v == nullptr || (*v == fLastv)) retu << 1183      if (!v || (v && *v == fLastv)) return;
1234   }                                              1184   }         
1235   G4ThreeVector xx(kInfinity, kInfinity, kInf    1185   G4ThreeVector xx(kInfinity, kInfinity, kInfinity);
1236   for (size_t i=0; i<G4VSURFACENXX; ++i)      << 1186   for (size_t i=0; i<G4VSURFACENXX; i++)
1237   {                                              1187   {
1238     fDistance[i] = kInfinity;                    1188     fDistance[i] = kInfinity;
1239     fAreacode[i] = sOutside;                     1189     fAreacode[i] = sOutside;
1240     fIsValid[i]  = false;                        1190     fIsValid[i]  = false;
1241     fXX[i] = xx;   // bug in old code ( was f    1191     fXX[i] = xx;   // bug in old code ( was fXX[i] =  xx[i]  )
1242   }                                              1192   }
1243   fNXX = 0;                                   << 1193   fNXX   = 0;
1244   fLastp.set(kInfinity, kInfinity, kInfinity)    1194   fLastp.set(kInfinity, kInfinity, kInfinity);
1245   fLastv.set(kInfinity, kInfinity, kInfinity)    1195   fLastv.set(kInfinity, kInfinity, kInfinity);
1246   fLastValidate = kUninitialized;                1196   fLastValidate = kUninitialized;
1247   fDone = false;                                 1197   fDone = false;
1248 }                                                1198 }
1249                                                  1199 
1250 //===========================================    1200 //=====================================================================
1251 //* CurrentStatus::DebugPrint ---------------    1201 //* CurrentStatus::DebugPrint -----------------------------------------
1252                                                  1202 
1253 void                                             1203 void
1254 G4VTwistSurface::CurrentStatus::DebugPrint()     1204 G4VTwistSurface::CurrentStatus::DebugPrint() const
1255 {                                                1205 {
1256   G4cout << "CurrentStatus::Dist0,1= " << fDi    1206   G4cout << "CurrentStatus::Dist0,1= " << fDistance[0] 
1257          << " " << fDistance[1] << " areacode    1207          << " " << fDistance[1] << " areacode = " << fAreacode[0] 
1258          << " " << fAreacode[1] << G4endl;       1208          << " " << fAreacode[1] << G4endl;
1259 }                                                1209 }
1260                                                  1210 
1261 //===========================================    1211 //=====================================================================
1262 // G4VTwistSurface::Boundary class               1212 // G4VTwistSurface::Boundary class
1263 //===========================================    1213 //=====================================================================
1264                                                  1214 
1265 //===========================================    1215 //=====================================================================
                                                   >> 1216 //* Boundary::Boundary ------------------------------------------------
                                                   >> 1217 
                                                   >> 1218 G4VTwistSurface::Boundary::Boundary()
                                                   >> 1219  : fBoundaryAcode(-1), fBoundaryType(0)
                                                   >> 1220 {
                                                   >> 1221 }
                                                   >> 1222 
                                                   >> 1223 //=====================================================================
                                                   >> 1224 //* Boundary::~Boundary -----------------------------------------------
                                                   >> 1225 
                                                   >> 1226 G4VTwistSurface::Boundary::~Boundary()
                                                   >> 1227 {
                                                   >> 1228 }
                                                   >> 1229 
                                                   >> 1230 //=====================================================================
1266 //* Boundary::SetFields ---------------------    1231 //* Boundary::SetFields -----------------------------------------------
1267                                                  1232 
1268 void                                             1233 void
1269 G4VTwistSurface::Boundary::SetFields(const G4 << 1234 G4VTwistSurface::Boundary::SetFields(const G4int         &areacode, 
1270                                 const G4Three << 1235                                 const G4ThreeVector &d, 
1271                                 const G4Three << 1236                                 const G4ThreeVector &x0, 
1272                                 const G4int&  << 1237                                 const G4int         &boundarytype)
1273 {                                                1238 {
1274   fBoundaryAcode     = areacode;                 1239   fBoundaryAcode     = areacode;
1275   fBoundaryDirection = d;                        1240   fBoundaryDirection = d;
1276   fBoundaryX0        = x0;                       1241   fBoundaryX0        = x0;
1277   fBoundaryType      = boundarytype;             1242   fBoundaryType      = boundarytype;
1278 }                                                1243 }
1279                                                  1244 
1280 //===========================================    1245 //=====================================================================
1281 //* Boundary::IsEmpty -----------------------    1246 //* Boundary::IsEmpty -------------------------------------------------
1282                                                  1247 
1283 G4bool G4VTwistSurface::Boundary::IsEmpty() c    1248 G4bool G4VTwistSurface::Boundary::IsEmpty() const 
1284 {                                                1249 {
1285   return fBoundaryAcode == -1;                << 1250   if (fBoundaryAcode == -1) return true;
                                                   >> 1251   return false;
1286 }                                                1252 }
1287                                                  1253 
1288 //===========================================    1254 //=====================================================================
1289 //* Boundary::GetBoundaryParameters ---------    1255 //* Boundary::GetBoundaryParameters -----------------------------------
1290                                                  1256 
1291 G4bool                                           1257 G4bool
1292 G4VTwistSurface::Boundary::GetBoundaryParamet << 1258 G4VTwistSurface::Boundary::GetBoundaryParameters(const G4int         &areacode, 
1293                                               << 1259                                                   G4ThreeVector &d,
1294                                               << 1260                                                   G4ThreeVector &x0, 
1295                                               << 1261                                                   G4int  &boundarytype) const 
1296 {                                                1262 {  
1297   // areacode must be one of them:               1263   // areacode must be one of them:
1298   // sAxis0 & sAxisMin, sAxis0 & sAxisMax,       1264   // sAxis0 & sAxisMin, sAxis0 & sAxisMax,
1299   // sAxis1 & sAxisMin, sAxis1 & sAxisMax        1265   // sAxis1 & sAxisMin, sAxis1 & sAxisMax
1300   //                                          << 1266   if ((areacode & sAxis0) && (areacode & sAxis1))
1301   if (((areacode & sAxis0) != 0) && ((areacod << 
1302   {                                              1267   {
1303     std::ostringstream message;               << 1268     G4cerr << "ERROR - G4VTwistSurface::Boundary::GetBoundaryParameters()"
1304     message << "Located in the corner area."  << 1269            << G4endl
1305             << "        This function returns << 1270            << "        Located in the corner area. This function"
1306             << "a boundary line." << G4endl   << 1271            << "        returns a direction vector of a boundary line."
1307             << "        areacode = " << areac << 1272            << "        areacode = " << areacode << G4endl;
1308     G4Exception("G4VTwistSurface::Boundary::G    1273     G4Exception("G4VTwistSurface::Boundary::GetBoundaryParameters()",
1309                 "GeomSolids0003", FatalExcept << 1274                 "InvalidCondition", FatalException,
                                                   >> 1275                 "Located in the corner area.");
1310   }                                              1276   } 
1311   if ((areacode & sSizeMask) != (fBoundaryAco    1277   if ((areacode & sSizeMask) != (fBoundaryAcode & sSizeMask))
1312   {                                              1278   {
1313     return false;                                1279     return false;
1314   }                                              1280   }
1315   d  = fBoundaryDirection;                       1281   d  = fBoundaryDirection;
1316   x0 = fBoundaryX0;                              1282   x0 = fBoundaryX0;
1317   boundarytype = fBoundaryType;                  1283   boundarytype = fBoundaryType;
1318   return true;                                   1284   return true;
1319 }                                                1285 }
1320                                                  1286