// // ******************************************************************** // * 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: G4TwistTrapFlatSide.cc,v 1.6 2007/05/23 09:31:02 gcosmo Exp $ // GEANT4 tag $Name: geant4-09-02-ref-02 $ // // // -------------------------------------------------------------------- // GEANT 4 class source file // // // G4TwistTrapFlatSide.cc // // Author: // 30-Aug-2002 - O.Link (Oliver.Link@cern.ch) // // -------------------------------------------------------------------- #include "G4TwistTrapFlatSide.hh" //===================================================================== //* constructors ------------------------------------------------------ G4TwistTrapFlatSide::G4TwistTrapFlatSide( const G4String &name, G4double PhiTwist, G4double pDx1, G4double pDx2, G4double pDy, G4double pDz, G4double pAlpha, G4double pPhi, G4double pTheta, G4int handedness) : G4VTwistSurface(name) { fHandedness = handedness; // +z = +ve, -z = -ve fDx1 = pDx1 ; fDx2 = pDx2 ; fDy = pDy ; fDz = pDz ; fAlpha = pAlpha ; fTAlph = std::tan(fAlpha) ; fPhi = pPhi ; fTheta = pTheta ; fdeltaX = 2 * fDz * std::tan(fTheta) * std::cos(fPhi) ; // dx in surface equation fdeltaY = 2 * fDz * std::tan(fTheta) * std::sin(fPhi) ; // dy in surface equation fPhiTwist = PhiTwist ; fCurrentNormal.normal.set( 0, 0, (fHandedness < 0 ? -1 : 1)); // Unit vector, in local coordinate system fRot.rotateZ( fHandedness > 0 ? 0.5 * fPhiTwist : -0.5 * fPhiTwist ); fTrans.set( fHandedness > 0 ? 0.5*fdeltaX : -0.5*fdeltaX , fHandedness > 0 ? 0.5*fdeltaY : -0.5*fdeltaY , fHandedness > 0 ? fDz : -fDz ) ; fIsValidNorm = true; fAxis[0] = kXAxis ; fAxis[1] = kYAxis ; fAxisMin[0] = kInfinity ; // x-Axis cannot be fixed, because it fAxisMax[0] = kInfinity ; // depends on y fAxisMin[1] = -fDy ; // y - axis fAxisMax[1] = fDy ; SetCorners(); SetBoundaries(); } //===================================================================== //* Fake default constructor ------------------------------------------ G4TwistTrapFlatSide::G4TwistTrapFlatSide( __void__& a ) : G4VTwistSurface(a) { } //===================================================================== //* destructor -------------------------------------------------------- G4TwistTrapFlatSide::~G4TwistTrapFlatSide() { } //===================================================================== //* GetNormal --------------------------------------------------------- G4ThreeVector G4TwistTrapFlatSide::GetNormal(const G4ThreeVector & /* xx */ , G4bool isGlobal) { if (isGlobal) { return ComputeGlobalDirection(fCurrentNormal.normal); } else { return fCurrentNormal.normal; } } //===================================================================== //* DistanceToSurface(p, v) ------------------------------------------- G4int G4TwistTrapFlatSide::DistanceToSurface(const G4ThreeVector &gp, const G4ThreeVector &gv, G4ThreeVector gxx[], G4double distance[], G4int areacode[], G4bool isvalid[], EValidate validate) { fCurStatWithV.ResetfDone(validate, &gp, &gv); if (fCurStatWithV.IsDone()) { G4int i; for (i=0; i= 0) isvalid[0] = true; } } else if (validate == kValidateWithoutTol) { areacode[0] = GetAreaCode(xx, false); if (IsInside(areacode[0])) { if (distance[0] >= 0) isvalid[0] = true; } } else { // kDontValidate areacode[0] = sInside; if (distance[0] >= 0) isvalid[0] = true; } fCurStatWithV.SetCurrentStatus(0, gxx[0], distance[0], areacode[0], isvalid[0], 1, validate, &gp, &gv); #ifdef G4TWISTDEBUG G4cerr << "ERROR - G4TwistTrapFlatSide::DistanceToSurface(p,v)" << G4endl; G4cerr << " Name : " << GetName() << G4endl; G4cerr << " xx : " << xx << G4endl; G4cerr << " gxx[0] : " << gxx[0] << G4endl; G4cerr << " dist[0] : " << distance[0] << G4endl; G4cerr << " areacode[0] : " << areacode[0] << G4endl; G4cerr << " isvalid[0] : " << isvalid[0] << G4endl; #endif return 1; } //===================================================================== //* DistanceToSurface(p) ---------------------------------------------- G4int G4TwistTrapFlatSide::DistanceToSurface(const G4ThreeVector &gp, G4ThreeVector gxx[], G4double distance[], G4int areacode[]) { // Calculate distance to plane in local coordinate, // then return distance and global intersection points. // fCurStat.ResetfDone(kDontValidate, &gp); if (fCurStat.IsDone()) { G4int i; for (i=0; i wmax - ctol) { areacode |= (sAxis0 & (sAxisX | sAxisMax)) | sBoundary; if (xx.x() >= wmax + ctol) isoutside = true; } // test boundary of y-axis if (xx.y() < fAxisMin[yaxis] + ctol) { areacode |= (sAxis1 & (sAxisY | sAxisMin)); if (areacode & sBoundary) areacode |= sCorner; // xx is on the corner. else areacode |= sBoundary; if (xx.y() <= fAxisMin[yaxis] - ctol) isoutside = true; } else if (xx.y() > fAxisMax[yaxis] - ctol) { areacode |= (sAxis1 & (sAxisY | sAxisMax)); if (areacode & sBoundary) areacode |= sCorner; // xx is on the corner. else areacode |= sBoundary; if (xx.y() >= fAxisMax[yaxis] + ctol) isoutside = true; } // if isoutside = true, clear inside bit. // if not on boundary, add axis information. if (isoutside) { G4int tmpareacode = areacode & (~sInside); areacode = tmpareacode; } else if ((areacode & sBoundary) != sBoundary) { areacode |= (sAxis0 & sAxisX) | (sAxis1 & sAxisY); } } else { // boundary of x-axis if (xx.x() < wmin ) { areacode |= (sAxis0 & (sAxisX | sAxisMin)) | sBoundary; } else if (xx.x() > wmax) { areacode |= (sAxis0 & (sAxisX | sAxisMax)) | sBoundary; } // boundary of y-axis if (xx.y() < fAxisMin[yaxis]) { areacode |= (sAxis1 & (sAxisY | sAxisMin)); if (areacode & sBoundary) areacode |= sCorner; // xx is on the corner. else areacode |= sBoundary; } else if (xx.y() > fAxisMax[yaxis]) { areacode |= (sAxis1 & (sAxisY | sAxisMax)) ; if (areacode & sBoundary) areacode |= sCorner; // xx is on the corner. else areacode |= sBoundary; } if ((areacode & sBoundary) != sBoundary) { areacode |= (sAxis0 & sAxisX) | (sAxis1 & sAxisY); } } return areacode; } else { G4Exception("G4TwistTrapFlatSide::GetAreaCode()", "NotImplemented", FatalException, "Feature NOT implemented !"); } return areacode; } //===================================================================== //* SetCorners -------------------------------------------------------- void G4TwistTrapFlatSide::SetCorners() { // Set Corner points in local coodinate. if (fAxis[0] == kXAxis && fAxis[1] == kYAxis) { G4double x, y, z; // corner of Axis0min and Axis1min x = -fDx1 + fDy * fTAlph ; y = -fDy ; z = 0 ; SetCorner(sC0Min1Min, x, y, z); // corner of Axis0max and Axis1min x = fDx1 + fDy * fTAlph ; y = -fDy ; z = 0 ; SetCorner(sC0Max1Min, x, y, z); // corner of Axis0max and Axis1max x = fDx2 - fDy * fTAlph ; y = fDy ; z = 0 ; SetCorner(sC0Max1Max, x, y, z); // corner of Axis0min and Axis1max x = -fDx2 - fDy * fTAlph ; y = fDy ; z = 0 ; SetCorner(sC0Min1Max, x, y, z); } else { G4cerr << "ERROR - G4TwistTrapFlatSide::SetCorners()" << G4endl << " fAxis[0] = " << fAxis[0] << G4endl << " fAxis[1] = " << fAxis[1] << G4endl; G4Exception("G4TwistTrapFlatSide::SetCorners()", "NotImplemented", FatalException, "Feature NOT implemented !"); } } //===================================================================== //* SetBoundaries() --------------------------------------------------- void G4TwistTrapFlatSide::SetBoundaries() { // Set direction-unit vector of phi-boundary-lines in local coodinate. // Don't call the function twice. G4ThreeVector direction ; if (fAxis[0] == kXAxis && fAxis[1] == kYAxis) { // sAxis0 & sAxisMin direction = - ( GetCorner(sC0Min1Max) - GetCorner(sC0Min1Min) ) ; direction = direction.unit(); SetBoundary(sAxis0 & (sAxisX | sAxisMin), direction, GetCorner(sC0Min1Max), sAxisY) ; // sAxis0 & sAxisMax direction = GetCorner(sC0Max1Max) - GetCorner(sC0Max1Min) ; // inverse direction = direction.unit(); SetBoundary(sAxis0 & (sAxisX | sAxisMax), direction, GetCorner(sC0Max1Min), sAxisY); // sAxis1 & sAxisMin direction = GetCorner(sC0Max1Min) - GetCorner(sC0Min1Min); direction = direction.unit(); SetBoundary(sAxis1 & (sAxisY | sAxisMin), direction, GetCorner(sC0Min1Min), sAxisX); // sAxis1 & sAxisMax direction = - ( GetCorner(sC0Max1Max) - GetCorner(sC0Min1Max) ) ; direction = direction.unit(); SetBoundary(sAxis1 & (sAxisY | sAxisMax), direction, GetCorner(sC0Max1Max), sAxisX); } else { G4cerr << "ERROR - G4TwistTrapFlatSide::SetBoundaries()" << G4endl << " fAxis[0] = " << fAxis[0] << G4endl << " fAxis[1] = " << fAxis[1] << G4endl; G4Exception("G4TwistTrapFlatSide::SetCorners()", "NotImplemented", FatalException, "Feature NOT implemented !"); } } //===================================================================== //* GetFacets() ------------------------------------------------------- void G4TwistTrapFlatSide::GetFacets( G4int m, G4int n, G4double xyz[][3], G4int faces[][4], G4int iside ) { G4double x,y ; // the two parameters for the surface equation G4ThreeVector p ; // a point on the surface, given by (z,u) G4int nnode ; G4int nface ; G4double xmin,xmax ; // calculate the (n-1)*(m-1) vertices G4int i,j ; for ( i = 0 ; i