// // ******************************************************************** // * License and Disclaimer * // * * // * The Geant4 software is copyright of the Copyright Holders of * // * the Geant4 Collaboration. It is provided under the terms and * // * conditions of the Geant4 Software License, included in the file * // * LICENSE and available at http://cern.ch/geant4/license . These * // * include a list of copyright holders. * // * * // * Neither the authors of this software system, nor their employing * // * institutes,nor the agencies providing financial support for this * // * work make any representation or warranty, express or implied, * // * regarding this software system or assume any liability for its * // * use. Please see the license in the file LICENSE and URL above * // * for the full disclaimer and the limitation of liability. * // * * // * This code implementation is the result of the scientific and * // * technical work of the GEANT4 collaboration. * // * By using, copying, modifying or distributing the software (or * // * any work based on the software) you agree to acknowledge its * // * use in resulting scientific publications, and indicate your * // * acceptance of all terms of the Geant4 Software license. * // ******************************************************************** // // G4VTwistSurface class inline methods // // Author: Kotoyo Hoshina (Chiba University), 01.08.2002 - Created. // Oliver Link (CERN), 13.11.2003 - Integration in Geant4 // from original version in Jupiter-2.5.02 application. // -------------------------------------------------------------------- struct Intersection { G4double phi ; // parameter phi G4double u ; // parameter u G4ThreeVector xx ; // intersection point in cartesian G4double distance ; // distance to intersection G4int areacode ; // the areacode of the intersection G4bool isvalid ; // valid intersection ?? }; inline G4bool DistanceSort( const Intersection& a, const Intersection& b) { return a.distance < b.distance ; } inline G4bool EqualIntersection( const Intersection& a, const Intersection& b) { return ( ( a.xx - b.xx ).mag() < 1E-9*CLHEP::mm ) ; } //===================================================================== //* DistanceToPlaneWithV ---------------------------------------------- inline G4double G4VTwistSurface::DistanceToPlaneWithV(const G4ThreeVector& p, const G4ThreeVector& v, const G4ThreeVector& x0, const G4ThreeVector& n0, G4ThreeVector& xx) { G4double q = n0 * v; G4double t = kInfinity; if (q != 0.0) { t = (n0 * (x0 - p)) / q; } xx = p + t * v; return t; } //===================================================================== //* DistanceToPlane --------------------------------------------------- inline G4double G4VTwistSurface::DistanceToPlane(const G4ThreeVector& p, const G4ThreeVector& x0, const G4ThreeVector& n0, G4ThreeVector& xx) { // DistanceToPlane : // Calculate distance to plane in local coordinate, // then return distance and global intersection points. // // p - location of flying particle // x0 - reference point of surface // xx - a foot of perpendicular line from p to the plane // t - distance from xx to p // n - a unit normal of this plane from plane to p. // // equation of plane: // n*(x - x0) = 0; // // vector to xx: // xx = p - t*n // // where // t = n * (p - x0) / std::fabs(n) // G4double t; G4ThreeVector n = n0.unit(); t = n * (p - x0); xx = p - t * n; return t; } //===================================================================== //* DistanceToPlane --------------------------------------------------- inline G4double G4VTwistSurface::DistanceToPlane(const G4ThreeVector& p, const G4ThreeVector& x0, const G4ThreeVector& t1, const G4ThreeVector& t2, G4ThreeVector& xx, G4ThreeVector& n) { // DistanceToPlane : // Calculate distance to plane in local coordinate, // then return distance and global intersection points. // t1 - 1st. vector lying on the plane // t2 - 2nd. vector lying on the plane n = (t1.cross(t2)).unit(); return DistanceToPlane(p, x0, n, xx); } //===================================================================== //* DistanceToLine ---------------------------------------------------- inline G4double G4VTwistSurface::DistanceToLine(const G4ThreeVector& p, const G4ThreeVector& x0, const G4ThreeVector& d, G4ThreeVector& xx) { // DistanceToLine : // Calculate distance to line, // then return distance and global intersection points. // // p - location of flying particle // x0 - reference point of line // d - direction vector of line // xx - a foot of perpendicular line from p to the plane // t - distance from xx to p // // Equation // // distance^2 = |(xx - p)|^2 // with // xx = x0 + t*d // // (d/dt)distance^2 = (d/dt)|((x0 + t*d) - p)|^2 // = 2*t*|d|^2 + 2*d*(x0 - p) // = 0 // smallest distance // then // t = - d*(x0 - p) / |d|^2 // G4double t; G4ThreeVector dir = d.unit(); t = - dir * (x0 - p); // |dir|^2 = 1. xx = x0 + t * dir; G4ThreeVector dist = xx - p; return dist.mag(); } //===================================================================== //* IsAxis0 ----------------------------------------------------------- inline G4bool G4VTwistSurface::IsAxis0(G4int areacode) const { return (areacode & sAxis0) != 0; } //===================================================================== //* IsAxis1 ----------------------------------------------------------- inline G4bool G4VTwistSurface::IsAxis1(G4int areacode) const { return (areacode & sAxis1) != 0; } //===================================================================== //* IsOutside --------------------------------------------------------- inline G4bool G4VTwistSurface::IsOutside(G4int areacode) const { return (areacode & sInside) == 0; } //===================================================================== //* IsInside ---------------------------------------------------------- inline G4bool G4VTwistSurface::IsInside(G4int areacode, G4bool testbitmode) const { if ((areacode & sInside) != 0) { if (testbitmode) { return true; } if (((areacode & sBoundary) == 0) && ((areacode & sCorner) == 0)) { return true; } } return false; } //===================================================================== //* IsBoundary -------------------------------------------------------- inline G4bool G4VTwistSurface::IsBoundary(G4int areacode, G4bool testbitmode) const { if ((areacode & sBoundary) == sBoundary) { if (testbitmode) { return true; } if ((areacode & sInside) == sInside) { return true; } } return false; } //===================================================================== //* IsCorner ---------------------------------------------------------- inline G4bool G4VTwistSurface::IsCorner(G4int areacode, G4bool testbitmode) const { if ((areacode & sCorner) == sCorner) { if (testbitmode) { return true; } if ((areacode & sInside) == sInside) { return true; } } return false; } //===================================================================== //* GetAxisType ------------------------------------------------------- inline G4int G4VTwistSurface::GetAxisType(G4int areacode, G4int whichaxis) const { G4int axiscode = areacode & sAxisMask & whichaxis; if (axiscode == (sAxisX & sAxis0) || axiscode == (sAxisX & sAxis1)) { return sAxisX; } if (axiscode == (sAxisY & sAxis0) || axiscode == (sAxisY & sAxis1)) { return sAxisY; } if (axiscode == (sAxisZ & sAxis0) || axiscode == (sAxisZ & sAxis1)) { return sAxisZ; } if (axiscode == (sAxisRho & sAxis0) || axiscode == (sAxisRho & sAxis1)) { return sAxisRho; } if (axiscode == (sAxisPhi & sAxis0) || axiscode == (sAxisPhi & sAxis1)) { return sAxisPhi; } std::ostringstream message; message << "Configuration not supported." << G4endl << " areacode = " << areacode; G4Exception("G4VTwistSurface::GetAxisType()","GeomSolids0001", FatalException, message); return 1; } //===================================================================== //* ComputeGlobalPoint ------------------------------------------------ inline G4ThreeVector G4VTwistSurface::ComputeGlobalPoint(const G4ThreeVector& lp) const { return fRot * G4ThreeVector(lp) + fTrans; } //===================================================================== //* ComputeGlobalPoint ------------------------------------------------ inline G4ThreeVector G4VTwistSurface::ComputeLocalPoint(const G4ThreeVector& gp) const { return fRot.inverse() * ( G4ThreeVector(gp) - fTrans ) ; } //===================================================================== //* ComputeGlobalDirection -------------------------------------------- inline G4ThreeVector G4VTwistSurface::ComputeGlobalDirection(const G4ThreeVector& lp) const { return fRot * G4ThreeVector(lp); } //===================================================================== //* ComputeLocalDirection --------------------------------------------- inline G4ThreeVector G4VTwistSurface::ComputeLocalDirection(const G4ThreeVector& gp) const { return fRot.inverse() * G4ThreeVector(gp); } //===================================================================== //* SetNeighbours ----------------------------------------------------- inline void G4VTwistSurface::SetNeighbours(G4VTwistSurface* ax0min, G4VTwistSurface* ax1min, G4VTwistSurface* ax0max, G4VTwistSurface* ax1max) { fNeighbours[0] = ax0min; fNeighbours[1] = ax1min; fNeighbours[2] = ax0max; fNeighbours[3] = ax1max; } //===================================================================== //* GetNeighbours ----------------------------------------------------- inline G4int G4VTwistSurface::GetNeighbours(G4int areacode, G4VTwistSurface** surfaces) { G4int sAxis0Min = sAxis0 & sAxisMin ; G4int sAxis1Min = sAxis1 & sAxisMin ; G4int sAxis0Max = sAxis0 & sAxisMax ; G4int sAxis1Max = sAxis1 & sAxisMax ; G4int i = 0; if ( (areacode & sAxis0Min ) == sAxis0Min ) { surfaces[i] = fNeighbours[0] ; ++i ; } if ( ( areacode & sAxis1Min ) == sAxis1Min ) { surfaces[i] = fNeighbours[1] ; ++i ; if ( i == 2 ) { return i ; } } if ( ( areacode & sAxis0Max ) == sAxis0Max ) { surfaces[i] = fNeighbours[2] ; ++i ; if ( i == 2 ) { return i ; } } if ( ( areacode & sAxis1Max ) == sAxis1Max ) { surfaces[i] = fNeighbours[3] ; ++i ; if ( i == 2 ) { return i ; } } return i ; } //===================================================================== //* GetCorner --------------------------------------------------------- inline G4ThreeVector G4VTwistSurface::GetCorner(G4int areacode) const { if ((areacode & sCorner) == 0) { std::ostringstream message; message << "Area code must represent corner." << G4endl << " areacode = " << areacode; G4Exception("G4VTwistSurface::GetCorner()","GeomSolids0002", FatalException, message); } if ((areacode & sC0Min1Min) == sC0Min1Min) { return fCorners[0]; } if ((areacode & sC0Max1Min) == sC0Max1Min) { return fCorners[1]; } if ((areacode & sC0Max1Max) == sC0Max1Max) { return fCorners[2]; } if ((areacode & sC0Min1Max) == sC0Min1Max) { return fCorners[3]; } std::ostringstream message; message << "Configuration not supported." << G4endl << " areacode = " << areacode; G4Exception("G4VTwistSurface::GetCorner()", "GeomSolids0001", FatalException, message); return fCorners[0]; }