// // ******************************************************************** // * 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. * // ******************************************************************** // // // $Id: G4VTwistSurface.icc,v 1.3 2006/06/29 18:48:20 gunter Exp $ // GEANT4 tag $Name: geant4-09-03 $ // // // -------------------------------------------------------------------- // G4VTwistSurface class inline methods // // Author: // 01-Aug-2002 - Kotoyo Hoshina (hoshina@hepburn.s.chiba-u.ac.jp) // // History: // 13-Nov-2003 - O.Link (Oliver.Link@cern.ch), Integration in Geant4 // from original version in Jupiter-2.5.02 application. // -------------------------------------------------------------------- //===================================================================== //* DistanceToPlaneWithV ---------------------------------------------- inline G4double G4VTwistSurface::DistanceToPlaneWithV(const G4ThreeVector &p, const G4ThreeVector &v, const G4ThreeVector &x0, const G4ThreeVector &n0, G4ThreeVector &xx) { G4double t = (n0 * (x0 - p)) / (n0 * v); 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::abs(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 { if (areacode & sAxis0) return true; return false; } //===================================================================== //* IsAxis1 ----------------------------------------------------------- inline G4bool G4VTwistSurface::IsAxis1(G4int areacode) const { if (areacode & sAxis1) return true; return false; } //===================================================================== //* IsOutside --------------------------------------------------------- inline G4bool G4VTwistSurface::IsOutside(G4int areacode) const { if (areacode & sInside) return false; return true; } //===================================================================== //* IsInside ---------------------------------------------------------- inline G4bool G4VTwistSurface::IsInside(G4int areacode, G4bool testbitmode) const { if (areacode & sInside) { if (testbitmode) { return true; } else { if (!((areacode & sBoundary) || (areacode & sCorner))) return true; } } return false; } //===================================================================== //* IsBoundary -------------------------------------------------------- inline G4bool G4VTwistSurface::IsBoundary(G4int areacode, G4bool testbitmode) const { if ((areacode & sBoundary) == sBoundary) { if (testbitmode) { return true; } else { 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; } else { 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; } else if (axiscode == (sAxisY & sAxis0) || axiscode == (sAxisY & sAxis1)) { return sAxisY; } else if (axiscode == (sAxisZ & sAxis0) || axiscode == (sAxisZ & sAxis1)) { return sAxisZ; } else if (axiscode == (sAxisRho & sAxis0) || axiscode == (sAxisRho & sAxis1)) { return sAxisRho; } else if (axiscode == (sAxisPhi & sAxis0) || axiscode == (sAxisPhi & sAxis1)) { return sAxisPhi; } else { G4cerr << "ERROR - G4VTwistSurface::GetAxisType()" << G4endl << " areacode = " << areacode << G4endl; G4Exception("G4VTwistSurface::GetAxisType()","NotSupported", FatalException, "Configuration not supported."); } 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* axis0min, G4VTwistSurface* axis1min, G4VTwistSurface* axis0max, G4VTwistSurface* axis1max) { fNeighbours[0] = axis0min; fNeighbours[1] = axis1min; fNeighbours[2] = axis0max; fNeighbours[3] = axis1max; } //===================================================================== //* GetNeighbours ----------------------------------------------------- inline G4int G4VTwistSurface::GetNeighbours(G4int areacode, G4VTwistSurface** surfaces) { int sAxis0Min = sAxis0 & sAxisMin ; int sAxis1Min = sAxis1 & sAxisMin ; int sAxis0Max = sAxis0 & sAxisMax ; int 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)){ G4cerr << "ERROR - G4VTwistSurface::GetCorner()" << G4endl << " areacode = " << areacode << G4endl; G4Exception("G4VTwistSurface::GetCorner()","InvalidSetup", FatalException, "Area code must represent corner."); } if ((areacode & sC0Min1Min) == sC0Min1Min) { return fCorners[0]; } else if ((areacode & sC0Max1Min) == sC0Max1Min) { return fCorners[1]; } else if ((areacode & sC0Max1Max) == sC0Max1Max) { return fCorners[2]; } else if ((areacode & sC0Min1Max) == sC0Min1Max) { return fCorners[3]; } else { G4cerr << "ERROR - G4VTwistSurface::GetCorner()" << G4endl << " areacode = " << areacode << G4endl; G4Exception("G4VTwistSurface::GetCorner()", "NotSupported", FatalException, "Configuration not supported."); } return fCorners[0]; }