Import Geant4 6.2.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-09 10:56:29 +02:00
parent 1d812b78b1
commit e083ffb441
1415 changed files with 111223 additions and 21207 deletions
+2 -1
View File
@@ -1,4 +1,4 @@
# $Id: GNUmakefile,v 1.3 2003/11/14 14:46:15 gcosmo Exp $
# $Id: GNUmakefile,v 1.4 2004/06/11 14:17:18 gcosmo Exp $
# ----------------------------------------------------------------------------
# GNUmakefile for geometry/solids/specific library. Gabriele Cosmo, 05/04/00.
# ----------------------------------------------------------------------------
@@ -11,6 +11,7 @@ endif
include $(G4INSTALL)/config/architecture.gmk
CPPFLAGS += -DG4GEOM_ALLOC_EXPORT
CPPFLAGS += -I$(G4BASE)/intercoms/include \
-I$(G4BASE)/graphics_reps/include \
-I$(G4BASE)/global/management/include \
+32 -1
View File
@@ -1,4 +1,4 @@
$Id: History,v 1.34 2004/01/12 10:30:31 gcosmo Exp $
$Id: History,v 1.39 2004/06/07 08:46:53 gcosmo Exp $
-------------------------------------------------------------------
=========================================================
@@ -17,6 +17,37 @@ committal in the CVS repository !
* Reverse chronological order (last date on top), please *
----------------------------------------------------------
07-Jun-2004, G.Cosmo (geom-specific-V06-01-04)
- Fixed compilation problem in G4TwistedSurface.cc on WIN32-VC.
28-May-2004, G.Cosmo (geom-specific-V06-01-03)
- Fixed archiving problem on WIN32-VC7: replaced structs with classes
in G4VSurface.
- Replaced misleading names for masks in G4VSurface and moved inlined
methods of nested classes to .cc.
25-May-2004, G.Cosmo (geom-specific-V06-01-02)
- Fixed compilation problem on SUN-CC. Made EValidate enum public in
G4VSurface.hh.
24-May-2004, G.Cosmo (geom-specific-V06-01-01)
- Removed compilation warnings and minor cleanup...
19-May-2004, O.Link (geom-specific-V06-01-00)
- First implementation of a framework for twisted surfaces, integrated from
the original version of Kotoyo Hoshina (hoshina@hepburn.s.chiba-u.ac.jp)
implemented in the 'Jupiter' application.
o Includes new specific twisted shape: G4TwistedTubs.
o New classes: G4VSurface, G4TwistedSurface, G4HyperbolicSurface,
G4FlatSurface, G4TwistedTubs.
o Cleanup of original code (debugging messages, compiler errors, migration
of g4std to new convention...)
o New organisation of class G4TwistedTubs: now independent of XXXSurface;
removed backpointer 'fSolid' from XXXSurface to G4TwistedTubs.
o New form of constructors in G4TwistedSurface, G4HyperbolicSurface and
G4FlatSurface.
o Change in G4TwistedSurface::DistanceToIn(p,v,...): roundoff correction.
12-Jan-2004, G.Cosmo (geom-specific-V06-00-00)
- G4PolyhedraSide.cc: fixed bug in which particles could "leak" out the
center of a face if inner radius = 0.
@@ -0,0 +1,103 @@
//
// ********************************************************************
// * DISCLAIMER *
// * *
// * The following disclaimer summarizes all the specific disclaimers *
// * of contributors to this software. The specific disclaimers,which *
// * govern, are listed with their locations in: *
// * http://cern.ch/geant4/license *
// * *
// * 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. *
// * *
// * This code implementation is the intellectual property of the *
// * GEANT4 collaboration. *
// * By copying, distributing or modifying the Program (or any work *
// * based on the Program) you indicate your acceptance of this *
// * statement, and all its terms. *
// ********************************************************************
//
//
// $Id: G4FlatSurface.hh,v 1.4 2004/05/24 12:09:46 gcosmo Exp $
// GEANT4 tag $Name: geant4-06-02 $
//
//
// --------------------------------------------------------------------
// GEANT 4 class header file
//
//
// G4FlatSurface
//
// Class description:
//
// Class describing a flat boundary surface for G4VSolid.
// 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.
// --------------------------------------------------------------------
#ifndef __G4FLATSURFACE__
#define __G4FLATSURFACE__
#include "G4VSurface.hh"
// class G4TwistedTubs;
class G4FlatSurface : public G4VSurface
{
public: // with description
G4FlatSurface(const G4String &name,
const G4RotationMatrix &rot,
const G4ThreeVector &tlate,
const G4ThreeVector &n,
const EAxis axis1 = kRho, // RHO axis !
const EAxis axis2 = kPhi, // PHI axis !
G4double axis0min = -kInfinity,
G4double axis1min = -kInfinity,
G4double axis0max = kInfinity,
G4double axis1max = kInfinity );
G4FlatSurface( const G4String &name,
G4double EndInnerRadius[2],
G4double EndOuterRadius[2],
G4double DPhi,
G4double EndPhi[2],
G4double EndZ[2],
G4int handedness ) ;
virtual ~G4FlatSurface();
virtual G4ThreeVector GetNormal(const G4ThreeVector & /* xx */ ,
G4bool isGlobal = false);
virtual G4int DistanceToSurface(const G4ThreeVector &gp,
const G4ThreeVector &gv,
G4ThreeVector gxx[],
G4double distance[],
G4int areacode[],
G4bool isvalid[],
EValidate validate = kValidateWithTol);
virtual G4int DistanceToSurface(const G4ThreeVector &gp,
G4ThreeVector gxx[],
G4double distance[],
G4int areacode[]);
protected: // with description
virtual G4int GetAreaCode(const G4ThreeVector &xx,
G4bool withTol = true) ;
private:
virtual void SetCorners();
virtual void SetBoundaries();
};
#endif
@@ -0,0 +1,152 @@
//
// ********************************************************************
// * DISCLAIMER *
// * *
// * The following disclaimer summarizes all the specific disclaimers *
// * of contributors to this software. The specific disclaimers,which *
// * govern, are listed with their locations in: *
// * http://cern.ch/geant4/license *
// * *
// * 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. *
// * *
// * This code implementation is the intellectual property of the *
// * GEANT4 collaboration. *
// * By copying, distributing or modifying the Program (or any work *
// * based on the Program) you indicate your acceptance of this *
// * statement, and all its terms. *
// ********************************************************************
//
//
// $Id: G4HyperbolicSurface.hh,v 1.4 2004/05/24 12:09:47 gcosmo Exp $
// GEANT4 tag $Name: geant4-06-02 $
//
//
// --------------------------------------------------------------------
// GEANT 4 class header file
//
//
// G4HyperbolicSurface
//
// Class description:
//
// Class describing a hyperbolic boundary surface for G4VSolid.
// 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.
// --------------------------------------------------------------------
#ifndef __G4HYPERBOLICSURFACE__
#define __G4HYPERBOLICSURFACE__
#include "G4VSurface.hh"
class G4HyperbolicSurface : public G4VSurface
{
public: // with description
G4HyperbolicSurface(const G4String &name,
const G4RotationMatrix &rot, // 0.5*(phi-width segment)
const G4ThreeVector &tlate,
const G4int handedness,// R-hand = 1, L-hand = -1
const G4double kappa, // tan(TwistAngle/2)/fZHalfLen
const G4double tanstereo, // tan(stereo angle)
const G4double r0, // radius at z = 0
const EAxis axis0 = kPhi,
const EAxis axis1 = kZAxis,
G4double axis0min = -kInfinity,
G4double axis1min = -kInfinity,
G4double axis0max = kInfinity,
G4double axis1max = kInfinity);
G4HyperbolicSurface(const G4String &name,
G4double EndInnerRadius[2],
G4double EndOuterRadius[2],
G4double DPhi,
G4double EndPhi[2],
G4double EndZ[2],
G4double InnerRadius,
G4double OuterRadius,
G4double Kappa,
G4double TanInnerStereo,
G4double TanOuterStereo,
G4int handedness) ;
virtual ~G4HyperbolicSurface();
virtual G4int DistanceToSurface(const G4ThreeVector &gp,
const G4ThreeVector &gv,
G4ThreeVector gxx[],
G4double distance[],
G4int areacode[],
G4bool isvalid[],
EValidate validate = kValidateWithTol);
virtual G4int DistanceToSurface(const G4ThreeVector &gp,
G4ThreeVector gxx[],
G4double distance[],
G4int areacode[]);
virtual G4ThreeVector GetNormal(const G4ThreeVector &xx,
G4bool isGlobal = false) ;
virtual EInside Inside(const G4ThreeVector &gp) ;
inline virtual G4double GetRhoAtPZ(const G4ThreeVector &p,
G4bool isglobal = false) const ;
private:
virtual G4int GetAreaCode(const G4ThreeVector &xx,
G4bool withTol = true);
virtual G4int GetAreaCodeInPhi(const G4ThreeVector &xx,
G4bool withTol = true);
virtual void SetCorners();
virtual void SetCorners(G4double EndInnerRadius[2],
G4double EndOuterRadius[2],
G4double DPhi,
G4double EndPhi[2],
G4double EndZ[2]);
virtual void SetBoundaries();
private:
G4double fKappa; // tan(TwistedAngle/2)/HalfLenZ;
G4double fTanStereo; // tan(StereoAngle)
G4double fTan2Stereo; // tan(StereoAngle)**2
G4double fR0; // radius at z = 0
G4double fR02; // radius**2 at z = 0
class Insidetype
{
public:
G4ThreeVector gp;
EInside inside;
};
Insidetype fInside;
};
//========================================================
// inline functions
//========================================================
inline
G4double G4HyperbolicSurface::GetRhoAtPZ(const G4ThreeVector &p,
G4bool isglobal) const
{
// Get Rho at p.z() on Hyperbolic Surface.
G4ThreeVector tmpp;
if (isglobal) {
tmpp = fRot.inverse()*p - fTrans;
} else {
tmpp = p;
}
return sqrt(fR02 + tmpp.z() * tmpp.z() * fTan2Stereo);
}
#endif
@@ -0,0 +1,150 @@
//
// ********************************************************************
// * DISCLAIMER *
// * *
// * The following disclaimer summarizes all the specific disclaimers *
// * of contributors to this software. The specific disclaimers,which *
// * govern, are listed with their locations in: *
// * http://cern.ch/geant4/license *
// * *
// * 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. *
// * *
// * This code implementation is the intellectual property of the *
// * GEANT4 collaboration. *
// * By copying, distributing or modifying the Program (or any work *
// * based on the Program) you indicate your acceptance of this *
// * statement, and all its terms. *
// ********************************************************************
//
//
// $Id: G4TwistedSurface.hh,v 1.4 2004/05/24 12:09:47 gcosmo Exp $
// GEANT4 tag $Name: geant4-06-02 $
//
//
// --------------------------------------------------------------------
// GEANT 4 class header file
//
//
// G4TwistedSurface
//
// Class description:
//
// Class describing a twisted boundary surface for G4VSolid.
// 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.
// --------------------------------------------------------------------
#ifndef __G4TWISTEDSURFACE__
#define __G4TWISTEDSURFACE__
#include "G4VSurface.hh"
class G4TwistedSurface : public G4VSurface
{
public: // with description
G4TwistedSurface(const G4String &name,
const G4RotationMatrix &rot, // 0.5*(phi-width segment)
const G4ThreeVector &tlate,
G4int handedness, // R-hand = 1, L-hand = -1
const G4double kappa, // tan(TwistAngle/2)/fZHalfLen
const EAxis axis0 = kXAxis,
const EAxis axis1 = kZAxis,
G4double axis0min = -kInfinity,
G4double axis1min = -kInfinity,
G4double axis0max = kInfinity,
G4double axis1max = kInfinity );
G4TwistedSurface(const G4String &name,
G4double EndInnerRadius[2],
G4double EndOuterRadius[2],
G4double DPhi,
G4double EndPhi[2],
G4double EndZ[2],
G4double InnerRadius,
G4double OuterRadius,
G4double Kappa,
G4int handedness);
virtual ~G4TwistedSurface();
virtual G4ThreeVector GetNormal(const G4ThreeVector &xx,
G4bool isGlobal = false) ;
virtual G4int DistanceToSurface(const G4ThreeVector &gp,
const G4ThreeVector &gv,
G4ThreeVector gxx[],
G4double distance[],
G4int areacode[],
G4bool isvalid[],
EValidate validate = kValidateWithTol);
virtual G4int DistanceToSurface(const G4ThreeVector &gp,
G4ThreeVector gxx[],
G4double distance[],
G4int areacode[]);
inline G4ThreeVector ProjectAtPXPZ(const G4ThreeVector &p,
G4bool isglobal = false) const ;
private:
virtual G4double DistanceToPlane(const G4ThreeVector &p,
const G4ThreeVector &A,
const G4ThreeVector &B,
const G4ThreeVector &C,
const G4ThreeVector &D,
const G4int parity,
G4ThreeVector &xx,
G4ThreeVector &n);
virtual G4int GetAreaCode(const G4ThreeVector &xx,
G4bool withTol = true);
virtual void SetCorners();
virtual void SetCorners( G4double endInnerRad[2],
G4double endOuterRad[2],
G4double endPhi[2],
G4double endZ[2] ) ;
virtual void SetBoundaries();
private:
G4double fKappa; // tan(TwistedAngle/2)/HalfLenZ;
};
//========================================================
// inline functions
//========================================================
inline
G4ThreeVector G4TwistedSurface::ProjectAtPXPZ(const G4ThreeVector &p,
G4bool isglobal) const
{
// Get Rho at p.z() on Hyperbolic Surface.
G4ThreeVector tmpp;
if (isglobal) {
tmpp = fRot.inverse()*p - fTrans;
} else {
tmpp = p;
}
G4ThreeVector xx(p.x(), p.x() * fKappa * p.z(), p.z());
if (isglobal) {
return (fRot * xx + fTrans);
} else {
return xx;
}
}
#endif
@@ -0,0 +1,356 @@
//
// ********************************************************************
// * DISCLAIMER *
// * *
// * The following disclaimer summarizes all the specific disclaimers *
// * of contributors to this software. The specific disclaimers,which *
// * govern, are listed with their locations in: *
// * http://cern.ch/geant4/license *
// * *
// * 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. *
// * *
// * This code implementation is the intellectual property of the *
// * GEANT4 collaboration. *
// * By copying, distributing or modifying the Program (or any work *
// * based on the Program) you indicate your acceptance of this *
// * statement, and all its terms. *
// ********************************************************************
//
//
// $Id: G4TwistedTubs.hh,v 1.3 2004/05/24 12:09:47 gcosmo Exp $
// GEANT4 tag $Name: geant4-06-02 $
//
//
// --------------------------------------------------------------------
// GEANT 4 class header file
//
//
// G4TwistedTubs
//
// Class description:
//
// G4TwistedTubs is a sort of twisted cylinder.
// A twisted cylinder which is placed along with z-axis and is
// separated into phi-segments should become a hyperboloid, and
// its each segmented piece should be tilted with a stereo angle.
// G4TwistedTubs is a G4VSolid.
// It can have inner & outer surfaces as well as G4TwistedTubs,
// but cannot has different stereo angles between the inner surface
// and outer surface.
// 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.
// --------------------------------------------------------------------
#ifndef __G4TWISTEDTUBS__
#define __G4TWISTEDTUBS__
#include "G4VSolid.hh"
#include "G4FlatSurface.hh"
#include "G4TwistedSurface.hh"
#include "G4HyperbolicSurface.hh"
class G4SolidExtentList;
class G4ClippablePolygon;
class G4TwistedTubs : public G4VSolid
{
public: // with description
G4TwistedTubs(const G4String &pname, // Name of instance
G4double twistedangle, // Twisted angle
G4double endinnerrad, // Inner radius at endcap
G4double endouterrad, // Outer radius at endcap
G4double halfzlen, // half z length
G4double dphi); // Phi angle of a segment
G4TwistedTubs(const G4String &pname, // Name of instance
G4double twistedangle, // Stereo angle
G4double endinnerrad, // Inner radius at endcap
G4double endouterrad, // Outer radius at endcap
G4double halfzlen, // half z length
G4int nseg, // Number of segments in totalPhi
G4double totphi); // Total angle of all segments
G4TwistedTubs(const G4String &pname, // Name of instance
G4double twistedangle, // Twisted angle
G4double innerrad, // Inner radius at z=0
G4double outerrad, // Outer radius at z=0
G4double negativeEndz, // -ve z endplate
G4double positiveEndz, // +ve z endplate
G4double dphi); // Phi angle of a segment
G4TwistedTubs(const G4String &pname, // Name of instance
G4double twistedangle, // Stereo angle
G4double innerrad, // Inner radius at z=0
G4double outerrad, // Outer radius at z=0
G4double negativeEndz, // -ve z endplate
G4double positiveEndz, // +ve z endplate
G4int nseg, // Number of segments in totalPhi
G4double totphi); // Total angle of all segments
virtual ~G4TwistedTubs();
void ComputeDimensions(G4VPVParameterisation * /* p */ ,
const G4int /* n */ ,
const G4VPhysicalVolume * /* prep */ );
G4bool CalculateExtent(const EAxis paxis,
const G4VoxelLimits &pvoxellimit,
const G4AffineTransform &ptransform,
G4double &pmin,
G4double &pmax ) const;
G4double DistanceToIn (const G4ThreeVector &p,
const G4ThreeVector &v ) const;
G4double DistanceToIn (const G4ThreeVector &p ) const;
G4double DistanceToOut(const G4ThreeVector &p,
const G4ThreeVector &v,
const G4bool calcnorm=G4bool(false),
G4bool *validnorm=0,
G4ThreeVector *n=0 ) const;
G4double DistanceToOut(const G4ThreeVector &p) const;
EInside Inside (const G4ThreeVector &p) const;
G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const;
void DescribeYourselfTo (G4VGraphicsScene &scene) const;
G4Polyhedron *CreatePolyhedron () const;
G4NURBS *CreateNURBS () const;
std::ostream &StreamInfo(std::ostream& os) const;
// accessors
inline G4double GetDPhi () const { return fDPhi ; }
inline G4double GetPhiTwist () const { return fPhiTwist ; }
inline G4double GetInnerRadius () const { return fInnerRadius; }
inline G4double GetOuterRadius () const { return fOuterRadius; }
inline G4double GetInnerStereo () const { return fInnerStereo; }
inline G4double GetOuterStereo () const { return fOuterStereo; }
inline G4double GetZHalfLength () const { return fZHalfLength; }
inline G4double GetKappa () const { return fKappa ; }
inline G4double GetTanInnerStereo () const { return fTanInnerStereo ; }
inline G4double GetTanInnerStereo2() const { return fTanInnerStereo2 ; }
inline G4double GetTanOuterStereo () const { return fTanOuterStereo ; }
inline G4double GetTanOuterStereo2() const { return fTanOuterStereo2 ; }
inline G4double GetEndZ (G4int i) const { return fEndZ[i] ; }
inline G4double GetEndPhi (G4int i) const { return fEndPhi[i]; }
inline G4double GetEndInnerRadius (G4int i) const
{ return fEndInnerRadius[i]; }
inline G4double GetEndOuterRadius (G4int i) const
{ return fEndOuterRadius[i]; }
inline G4double GetEndInnerRadius () const
{ return (fEndInnerRadius[0] > fEndInnerRadius[1] ?
fEndInnerRadius[0] : fEndInnerRadius[1]); }
inline G4double GetEndOuterRadius () const
{ return (fEndOuterRadius[0] > fEndOuterRadius[1] ?
fEndOuterRadius[0] : fEndOuterRadius[1]); }
G4VisExtent GetExtent () const;
G4GeometryType GetEntityType() const;
public: // without description
#ifdef G4SPECSDEBUG
G4VSurface * GetOuterHype() const { return fOuterHype; }
#endif
private:
inline void SetFields(G4double phitwist, G4double innerrad,
G4double outerrad,
G4double negativeEndz, G4double positiveEndz);
void CreateSurfaces();
static void AddPolyToExtent( const G4ThreeVector &v0,
const G4ThreeVector &v1,
const G4ThreeVector &w1,
const G4ThreeVector &w0,
const G4VoxelLimits &voxellimit,
const EAxis axis,
G4SolidExtentList &extentlist );
private:
G4double fPhiTwist; // Twist angle from -fZHalfLength to fZHalfLength
G4double fInnerRadius; // Inner-hype radius at z=0
G4double fOuterRadius; // Outer-hype radius at z=0
G4double fEndZ[2]; // z at endcaps, [0] = -ve z, [1] = +ve z
G4double fDPhi; // Phi-width of a segment fDPhi > 0
G4double fZHalfLength; // Half length along z-axis
G4double fInnerStereo; // Inner-hype stereo angle
G4double fOuterStereo; // Outer-hype stereo angle
G4double fTanInnerStereo; // tan(innerStereoAngle)
G4double fTanOuterStereo; // tan(outerStereoAngle)
G4double fKappa; // tan(fPhiTwist/2)/fZHalfLen;
G4double fEndInnerRadius[2]; // Inner-hype radii endcaps [0] -ve z, [1] +ve z
G4double fEndOuterRadius[2]; // Outer-hype radii endcaps [0] -ve z, [1] +ve z
G4double fEndPhi[2]; // Phi endcaps, [0] = -ve z, [1] = +ve z
G4double fInnerRadius2; // fInnerRadius * fInnerRadius
G4double fOuterRadius2; // fOuterRadius * fOuterRadius
G4double fTanInnerStereo2; // fInnerRadius * fInnerRadius
G4double fTanOuterStereo2; // fInnerRadius * fInnerRadius
G4double fEndZ2[2]; // fEndZ * fEndZ
G4VSurface *fLowerEndcap; // Surface of -ve z
G4VSurface *fUpperEndcap; // Surface of +ve z
G4VSurface *fLatterTwisted; // Surface of -ve phi
G4VSurface *fFormerTwisted; // Surface of +ve phi
G4VSurface *fInnerHype; // Surface of -ve r
G4VSurface *fOuterHype; // Surface of +ve r
class LastState // last Inside result
{
public:
LastState()
{
p.set(kInfinity,kInfinity,kInfinity);
inside = kOutside;
}
~LastState(){}
public:
G4ThreeVector p;
EInside inside;
};
class LastVector // last SurfaceNormal result
{
public:
LastVector()
{
p.set(kInfinity,kInfinity,kInfinity);
vec.set(kInfinity,kInfinity,kInfinity);
surface = new G4VSurface*[1];
}
~LastVector()
{
delete [] surface;
}
public:
G4ThreeVector p;
G4ThreeVector vec;
G4VSurface **surface;
};
class LastValue // last G4double value
{
public:
LastValue()
{
p.set(kInfinity,kInfinity,kInfinity);
value = DBL_MAX;
}
~LastValue(){}
public:
G4ThreeVector p;
G4double value;
};
class LastValueWithDoubleVector // last G4double value
{
public:
LastValueWithDoubleVector()
{
p.set(kInfinity,kInfinity,kInfinity);
vec.set(kInfinity,kInfinity,kInfinity);
value = DBL_MAX;
}
~LastValueWithDoubleVector(){}
public:
G4ThreeVector p;
G4ThreeVector vec;
G4double value;
};
LastState fLastInside;
LastVector fLastNormal;
LastValue fLastDistanceToIn;
LastValue fLastDistanceToOut;
LastValueWithDoubleVector fLastDistanceToInWithV;
LastValueWithDoubleVector fLastDistanceToOutWithV;
};
//=====================================================================
//---------------------
// inline functions
//---------------------
inline
void G4TwistedTubs::SetFields(G4double phitwist, G4double innerrad,
G4double outerrad, G4double negativeEndz,
G4double positiveEndz)
{
fPhiTwist = phitwist;
fEndZ[0] = negativeEndz;
fEndZ[1] = positiveEndz;
fEndZ2[0] = fEndZ[0] * fEndZ[0];
fEndZ2[1] = fEndZ[1] * fEndZ[1];
fInnerRadius = innerrad;
fOuterRadius = outerrad;
fInnerRadius2 = fInnerRadius * fInnerRadius;
fOuterRadius2 = fOuterRadius * fOuterRadius;
G4int maxi;
if (fabs(fEndZ[0]) >= fabs(fEndZ[1])) {
fZHalfLength = fabs(fEndZ[0]);
maxi = 0;
} else {
fZHalfLength = fabs(fEndZ[1]);
maxi = 1;
}
G4double parity = (fPhiTwist > 0 ? 1 : -1);
G4double tanHalfTwist = tan(0.5 * fPhiTwist);
G4double innerNumerator = fabs(fInnerRadius * tanHalfTwist) * parity;
G4double outerNumerator = fabs(fOuterRadius * tanHalfTwist) * parity;
fTanInnerStereo = innerNumerator / fZHalfLength;
fTanOuterStereo = outerNumerator / fZHalfLength;
fTanInnerStereo2 = fTanInnerStereo * fTanInnerStereo;
fTanOuterStereo2 = fTanOuterStereo * fTanOuterStereo;
fInnerStereo = atan2(innerNumerator, fZHalfLength);
fOuterStereo = atan2(outerNumerator, fZHalfLength);
fEndInnerRadius[0] = sqrt(fInnerRadius2 + fEndZ2[0] * fTanInnerStereo2);
fEndInnerRadius[1] = sqrt(fInnerRadius2 + fEndZ2[1] * fTanInnerStereo2);
fEndOuterRadius[0] = sqrt(fOuterRadius2 + fEndZ2[0] * fTanOuterStereo2);
fEndOuterRadius[1] = sqrt(fOuterRadius2 + fEndZ2[1] * fTanOuterStereo2);
fKappa = tanHalfTwist / fZHalfLength;
fEndPhi[0] = atan2(fEndZ[0] * tanHalfTwist, fZHalfLength);
fEndPhi[1] = atan2(fEndZ[1] * tanHalfTwist, fZHalfLength);
#ifdef G4SPECSDEBUG
G4cout << "/********* G4TwistedTubs::SetFields() Field Parameters ***************** " << G4endl;
G4cout << "/* fPhiTwist : " << fPhiTwist << G4endl;
G4cout << "/* fEndZ(0, 1) : " << fEndZ[0] << " , " << fEndZ[1] << G4endl;
G4cout << "/* fEndPhi(0, 1) : " << fEndPhi[0] << " , " << fEndPhi[1] << G4endl;
G4cout << "/* fInnerRadius, fOuterRadius : " << fInnerRadius << " , " << fOuterRadius << G4endl;
G4cout << "/* fEndInnerRadius(0, 1) : " << fEndInnerRadius[0] << " , "
<< fEndInnerRadius[1] << G4endl;
G4cout << "/* fEndOuterRadius(0, 1) : " << fEndOuterRadius[0] << " , "
<< fEndOuterRadius[1] << G4endl;
G4cout << "/* fInnerStereo, fOuterStereo : " << fInnerStereo << " , " << fOuterStereo << G4endl;
G4cout << "/* tanHalfTwist, fKappa : " << tanHalfTwist << " , " << fKappa << G4endl;
G4cout << "/*********************************************************************** " << G4endl;
#endif
}
#endif
@@ -0,0 +1,337 @@
//
// ********************************************************************
// * DISCLAIMER *
// * *
// * The following disclaimer summarizes all the specific disclaimers *
// * of contributors to this software. The specific disclaimers,which *
// * govern, are listed with their locations in: *
// * http://cern.ch/geant4/license *
// * *
// * 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. *
// * *
// * This code implementation is the intellectual property of the *
// * GEANT4 collaboration. *
// * By copying, distributing or modifying the Program (or any work *
// * based on the Program) you indicate your acceptance of this *
// * statement, and all its terms. *
// ********************************************************************
//
//
// $Id: G4VSurface.hh,v 1.8 2004/05/28 18:19:05 gcosmo Exp $
// GEANT4 tag $Name: geant4-06-02 $
//
//
// --------------------------------------------------------------------
// GEANT 4 class header file
//
//
// G4VSurface
//
// Class description:
//
// Abstract base class for boundary surface of G4VSolid.
// 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.
// --------------------------------------------------------------------
#ifndef __G4VSURFACE__
#define __G4VSURFACE__
#include "G4VSolid.hh"
#include "geomdefs.hh"
#include "G4RotationMatrix.hh"
class G4VSurface
{
public: // without description
enum EValidate {kDontValidate = 0, kValidateWithTol = 1,
kValidateWithoutTol = 2, kUninitialized = 3};
public: // with description
G4VSurface (const G4String &name);
G4VSurface (const G4String &name,
const G4RotationMatrix &rot,
const G4ThreeVector &tlate,
G4int handedness,
const EAxis axis1,
const EAxis axis2,
G4double axis0min = -kInfinity,
G4double axis1min = -kInfinity,
G4double axis0max = kInfinity,
G4double axis1max = kInfinity);
virtual ~G4VSurface();
virtual G4int AmIOnLeftSide(const G4ThreeVector &me,
const G4ThreeVector &vec,
G4bool withTol = true);
virtual G4double DistanceToBoundary( G4int areacode,
G4ThreeVector &xx,
const G4ThreeVector &p) ;
virtual G4double DistanceToIn(const G4ThreeVector &gp,
const G4ThreeVector &gv,
G4ThreeVector &gxxbest);
virtual G4double DistanceToOut(const G4ThreeVector &gp,
const G4ThreeVector &gv,
G4ThreeVector &gxxbest);
virtual G4double DistanceTo(const G4ThreeVector &gp,
G4ThreeVector &gxx);
virtual G4int DistanceToSurface(const G4ThreeVector &gp,
const G4ThreeVector &gv,
G4ThreeVector gxx[],
G4double distance[],
G4int areacode[],
G4bool isvalid[],
EValidate validate=kValidateWithTol) = 0;
virtual G4int DistanceToSurface(const G4ThreeVector &gp,
G4ThreeVector gxx[],
G4double distance[],
G4int areacode[]) = 0;
void DebugPrint() const;
// get methods
virtual G4ThreeVector GetNormal(const G4ThreeVector &xx,G4bool isGlobal) = 0;
virtual G4String GetName() const { return fName; }
virtual void GetBoundaryParameters(const G4int &areacode,
G4ThreeVector &d,
G4ThreeVector &x0,
G4int &boundarytype) const;
virtual G4ThreeVector GetBoundaryAtPZ(G4int areacode,
const G4ThreeVector &p) const;
inline G4double DistanceToPlaneWithV(const G4ThreeVector &p,
const G4ThreeVector &v,
const G4ThreeVector &x0,
const G4ThreeVector &n0,
G4ThreeVector &xx);
inline G4double DistanceToPlane(const G4ThreeVector &p,
const G4ThreeVector &x0,
const G4ThreeVector &n0,
G4ThreeVector &xx);
inline G4double DistanceToPlane(const G4ThreeVector &p,
const G4ThreeVector &x0,
const G4ThreeVector &t1,
const G4ThreeVector &t2,
G4ThreeVector &xx,
G4ThreeVector &n);
inline G4double DistanceToLine (const G4ThreeVector &p,
const G4ThreeVector &x0,
const G4ThreeVector &d,
G4ThreeVector &xx);
inline G4bool IsAxis0 (G4int areacode) const;
inline G4bool IsAxis1 (G4int areacode) const;
inline G4bool IsOutside (G4int areacode) const;
inline G4bool IsInside (G4int areacode, G4bool testbitmode = false) const;
inline G4bool IsBoundary (G4int areacode, G4bool testbitmode = false) const;
inline G4bool IsCorner (G4int areacode, G4bool testbitmode = false) const;
inline G4bool IsValidNorm() const { return fIsValidNorm; }
G4bool IsSameBoundary (G4VSurface *surface1, G4int areacode1,
G4VSurface *surface2, G4int areacode2 ) const;
inline G4int GetAxisType(G4int areacode, G4int whichaxis) const;
inline G4ThreeVector ComputeGlobalPoint (const G4ThreeVector &lp) const;
inline G4ThreeVector ComputeLocalPoint (const G4ThreeVector &gp) const;
inline G4ThreeVector ComputeGlobalDirection (const G4ThreeVector &lp) const;
inline G4ThreeVector ComputeLocalDirection (const G4ThreeVector &gp) const;
// set methods
inline void SetAxis(G4int i, const EAxis axis) { fAxis[i] = axis; }
inline void SetNeighbours(G4VSurface* axis0min, G4VSurface* axis1min,
G4VSurface* axis0max, G4VSurface* axis1max);
protected: // with description
// get methods
inline G4VSurface** GetNeighbours() { return fNeighbours; }
inline G4int GetNeighbours(G4int areacode, G4VSurface* surfaces[]);
inline G4ThreeVector GetCorner(G4int areacode) const;
void GetBoundaryAxis(G4int areacode, EAxis axis[]) const;
void GetBoundaryLimit(G4int areacode, G4double limit[]) const;
virtual G4int GetAreaCode(const G4ThreeVector &xx, G4bool withtol=true) = 0;
// set methods
virtual void SetBoundary(const G4int &axiscode,
const G4ThreeVector &direction,
const G4ThreeVector &x0,
const G4int &boundarytype);
// areacode must be one of them:
// sAxis0 & sAxisMin, sAxis0 & sAxisMax,
// sAxis1 & sAxisMin, sAxis1 & sAxisMax.
// boundarytype represents the shape of locus
// from the start point to end point of boundary.
// ex.
// sAxisRho = linear line which start point is fixed at origin.
// sAxisPhi = part of circle which center placed at the origin.
void SetCorner(G4int areacode, G4double x, G4double y, G4double z);
private:
virtual void SetBoundaries() = 0;
virtual void SetCorners() = 0;
// data members ---------------------------------------------------------
public:
static const G4int sOutside ;
static const G4int sInside ;
static const G4int sBoundary;
static const G4int sCorner;
static const G4int sCMin1Min;
static const G4int sCMax1Min;
static const G4int sCMax1Max;
static const G4int sCMin1Max;
static const G4int sAxisMin;
static const G4int sAxisMax;
static const G4int sAxisX;
static const G4int sAxisY;
static const G4int sAxisZ;
static const G4int sAxisRho;
static const G4int sAxisPhi;
static const G4int sAxis0;
static const G4int sAxis1;
static const G4int sSizeMask;
static const G4int sAxisMask;
static const G4int sAreaMask;
protected:
class CurrentStatus
{
public:
CurrentStatus();
virtual ~CurrentStatus();
inline G4ThreeVector GetXX(G4int i) const { return fXX[i]; }
inline G4double GetDistance(G4int i) const { return fDistance[i]; }
inline G4int GetAreacode(G4int i) const { return fAreacode[i]; }
inline G4int GetNXX() const { return fNXX; }
inline G4bool IsDone() const { return fDone; }
inline G4bool IsValid(G4int i) const { return fIsValid[i]; }
void SetCurrentStatus(G4int i,
G4ThreeVector &xx,
G4double &dist,
G4int &areacode,
G4bool &isvalid,
G4int nxx,
EValidate validate,
const G4ThreeVector *p,
const G4ThreeVector *v = 0);
void ResetfDone(EValidate validate,
const G4ThreeVector *p,
const G4ThreeVector *v = 0);
void DebugPrint() const;
private:
G4double fDistance[2];
G4ThreeVector fXX[2];
G4int fAreacode[2];
G4bool fIsValid[2];
G4int fNXX;
G4ThreeVector fLastp;
G4ThreeVector fLastv;
EValidate fLastValidate;
G4bool fDone;
};
class Boundary
{
public:
Boundary();
virtual ~Boundary();
void SetFields(const G4int &areacode,
const G4ThreeVector &d,
const G4ThreeVector &x0,
const G4int &boundarytype);
G4bool IsEmpty() const;
G4bool GetBoundaryParameters(const G4int &areacode,
G4ThreeVector &d,
G4ThreeVector &x0,
G4int &boundarytype) const;
private:
G4int fBoundaryAcode;
G4ThreeVector fBoundaryDirection;
G4ThreeVector fBoundaryX0;
G4int fBoundaryType;
};
EAxis fAxis[2];
G4double fAxisMin[2];
G4double fAxisMax[2];
CurrentStatus fCurStatWithV;
CurrentStatus fCurStat;
G4RotationMatrix fRot;
G4ThreeVector fTrans;
G4int fHandedness;
class G4SurfCurNormal
{
public:
G4ThreeVector p;
G4ThreeVector normal;
};
G4SurfCurNormal fCurrentNormal;
G4bool fIsValidNorm;
private:
G4VSurface *fNeighbours[4]; // {0,1,2,3} = sAxis0min, sAxis1min,
// sAxis0max, sAxis1max
G4ThreeVector fCorners[4]; // corners of the surface in local coordinate
Boundary fBoundaries[4]; // boundaries of the surface.
G4String fName;
class G4SurfSideQuery
{
public:
G4ThreeVector me;
G4ThreeVector vec;
G4bool withTol;
G4int amIOnLeftSide;
};
G4SurfSideQuery fAmIOnLeftSide;
};
//========================================================
// inline functions
//========================================================
#include "G4VSurface.icc"
#endif
@@ -0,0 +1,369 @@
//
// ********************************************************************
// * DISCLAIMER *
// * *
// * The following disclaimer summarizes all the specific disclaimers *
// * of contributors to this software. The specific disclaimers,which *
// * govern, are listed with their locations in: *
// * http://cern.ch/geant4/license *
// * *
// * 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. *
// * *
// * This code implementation is the intellectual property of the *
// * GEANT4 collaboration. *
// * By copying, distributing or modifying the Program (or any work *
// * based on the Program) you indicate your acceptance of this *
// * statement, and all its terms. *
// ********************************************************************
//
//
// $Id: G4VSurface.icc,v 1.2 2004/05/28 13:13:35 gcosmo Exp $
// GEANT4 tag $Name: geant4-06-02 $
//
//
// --------------------------------------------------------------------
// G4VSurface 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 G4VSurface::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 G4VSurface::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) / abs(n)
//
G4double t;
G4ThreeVector n = n0.unit();
t = n * (p - x0);
xx = p - t * n;
return t;
}
//=====================================================================
//* DistanceToPlane ---------------------------------------------------
inline
G4double G4VSurface::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 G4VSurface::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 G4VSurface::IsAxis0(G4int areacode) const
{
if (areacode & sAxis0) return true;
return false;
}
//=====================================================================
//* IsAxis1 -----------------------------------------------------------
inline
G4bool G4VSurface::IsAxis1(G4int areacode) const
{
if (areacode & sAxis1) return true;
return false;
}
//=====================================================================
//* IsOutside ---------------------------------------------------------
inline
G4bool G4VSurface::IsOutside(G4int areacode) const
{
if (areacode & sInside) return false;
return true;
}
//=====================================================================
//* IsInside ----------------------------------------------------------
inline
G4bool G4VSurface::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 G4VSurface::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 G4VSurface::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 G4VSurface::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 - G4VSurface::GetAxisType()" << G4endl
<< " areacode = " << areacode << G4endl;
G4Exception("G4VSurface::GetAxisType()","NotSupported",
FatalException, "Configuration not supported.");
}
return 1;
}
//=====================================================================
//* ComputeGlobalPoint ------------------------------------------------
inline
G4ThreeVector G4VSurface::ComputeGlobalPoint(const G4ThreeVector &lp) const
{
return fRot * G4ThreeVector(lp) + fTrans;
}
//=====================================================================
//* ComputeGlobalPoint ------------------------------------------------
inline
G4ThreeVector G4VSurface::ComputeLocalPoint(const G4ThreeVector &gp) const
{
return fRot.inverse() * G4ThreeVector(gp) - fTrans;
}
//=====================================================================
//* ComputeGlobalDirection --------------------------------------------
inline
G4ThreeVector G4VSurface::ComputeGlobalDirection(const G4ThreeVector &lp) const
{
return fRot * G4ThreeVector(lp);
}
//=====================================================================
//* ComputeLocalDirection ---------------------------------------------
inline
G4ThreeVector G4VSurface::ComputeLocalDirection(const G4ThreeVector &gp) const
{
return fRot.inverse() * G4ThreeVector(gp);
}
//=====================================================================
//* SetNeighbours -----------------------------------------------------
inline
void G4VSurface::SetNeighbours(G4VSurface* axis0min, G4VSurface* axis1min,
G4VSurface* axis0max, G4VSurface* axis1max)
{
fNeighbours[0] = axis0min;
fNeighbours[1] = axis1min;
fNeighbours[2] = axis0max;
fNeighbours[4] = axis1max;
}
//=====================================================================
//* GetNeighbours -----------------------------------------------------
inline
G4int G4VSurface::GetNeighbours(G4int areacode, G4VSurface** surfaces)
{
G4int i = 0;
if (areacode & (sAxis0 | sAxisMin)) {
surfaces[i] = fNeighbours[0];
i++;
}
if (areacode & (sAxis1 | sAxisMin)) {
surfaces[i] = fNeighbours[1];
i++;
if (i == 2) return i;
}
if (areacode & (sAxis0 | sAxisMax)) {
surfaces[i] = fNeighbours[2];
i++;
if (i == 2) return i;
}
if (areacode & (sAxis1 | sAxisMax)) {
surfaces[i] = fNeighbours[3];
i++;
if (i == 2) return i;
}
return i;
}
//=====================================================================
//* GetCorner ---------------------------------------------------------
inline
G4ThreeVector G4VSurface::GetCorner(G4int areacode) const
{
if (!(areacode & sCorner)){
G4cerr << "ERROR - G4VSurface::GetCorner()" << G4endl
<< " areacode = " << areacode << G4endl;
G4Exception("G4VSurface::GetCorner()","InvalidSetup",
FatalException, "Area code must represent corner.");
}
if ((areacode & sCMin1Min) == sCMin1Min) {
return fCorners[0];
} else if ((areacode & sCMax1Min) == sCMax1Min) {
return fCorners[1];
} else if ((areacode & sCMax1Max) == sCMax1Max) {
return fCorners[2];
} else if ((areacode & sCMin1Max) == sCMin1Max) {
return fCorners[3];
} else {
G4cerr << "ERROR - G4VSurface::GetCorner()" << G4endl
<< " areacode = " << areacode << G4endl;
G4Exception("G4VSurface::GetCorner()", "NotSupported",
FatalException, "Configuration not supported.");
}
return fCorners[0];
}
@@ -0,0 +1,482 @@
//
// ********************************************************************
// * DISCLAIMER *
// * *
// * The following disclaimer summarizes all the specific disclaimers *
// * of contributors to this software. The specific disclaimers,which *
// * govern, are listed with their locations in: *
// * http://cern.ch/geant4/license *
// * *
// * 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. *
// * *
// * This code implementation is the intellectual property of the *
// * GEANT4 collaboration. *
// * By copying, distributing or modifying the Program (or any work *
// * based on the Program) you indicate your acceptance of this *
// * statement, and all its terms. *
// ********************************************************************
//
//
// $Id: G4FlatSurface.cc,v 1.5 2004/05/28 13:13:36 gcosmo Exp $
// GEANT4 tag $Name: geant4-06-02 $
//
//
// --------------------------------------------------------------------
// GEANT 4 class source file
//
//
// G4FlatSurface.cc
//
// 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.
// --------------------------------------------------------------------
#include "G4FlatSurface.hh"
//=====================================================================
//* constructors ------------------------------------------------------
G4FlatSurface::G4FlatSurface(const G4String &name,
const G4RotationMatrix &rot,
const G4ThreeVector &tlate,
const G4ThreeVector &n,
const EAxis axis0 ,
const EAxis axis1 ,
G4double axis0min,
G4double axis1min,
G4double axis0max,
G4double axis1max )
: G4VSurface(name, rot, tlate, 0, axis0, axis1,
axis0min, axis1min, axis0max, axis1max)
{
if (axis0 == kPhi && axis1 == kRho) {
G4Exception("G4FlatSurface::G4FlatSurface()", "InvalidSetup",
FatalException, "Should swap axis0 and axis1!");
}
G4ThreeVector normal = rot.inverse()*n;
fCurrentNormal.normal = normal.unit(); // in local coordinate system
fIsValidNorm = true;
SetCorners();
SetBoundaries();
}
G4FlatSurface::G4FlatSurface( const G4String &name,
G4double EndInnerRadius[2],
G4double EndOuterRadius[2],
G4double DPhi,
G4double EndPhi[2],
G4double EndZ[2],
G4int handedness )
: G4VSurface(name)
{
fHandedness = handedness; // +z = +ve, -z = -ve
fAxis[0] = kRho; // in local coordinate system
fAxis[1] = kPhi;
G4int i = (handedness < 0 ? 0 : 1);
fAxisMin[0] = EndInnerRadius[i]; // Inner-hype radius at z=0
fAxisMax[0] = EndOuterRadius[i]; // Outer-hype radius at z=0
fAxisMin[1] = -0.5*DPhi;
fAxisMax[1] = -fAxisMin[1];
fCurrentNormal.normal.set(0, 0, (fHandedness < 0 ? -1 : 1));
// Unit vector, in local coordinate system
fRot.rotateZ(EndPhi[i]);
fTrans.set(0, 0, EndZ[i]);
fIsValidNorm = true;
SetCorners();
SetBoundaries();
}
//=====================================================================
//* destructor --------------------------------------------------------
G4FlatSurface::~G4FlatSurface()
{
}
//=====================================================================
//* GetNormal ---------------------------------------------------------
G4ThreeVector G4FlatSurface::GetNormal(const G4ThreeVector & /* xx */ ,
G4bool isGlobal)
{
if (isGlobal) {
return ComputeGlobalDirection(fCurrentNormal.normal);
} else {
return fCurrentNormal.normal;
}
}
//=====================================================================
//* DistanceToSurface(p, v) -------------------------------------------
G4int G4FlatSurface::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<fCurStatWithV.GetNXX(); i++) {
gxx[i] = fCurStatWithV.GetXX(i);
distance[i] = fCurStatWithV.GetDistance(i);
areacode[i] = fCurStatWithV.GetAreacode(i);
isvalid[i] = fCurStatWithV.IsValid(i);
}
return fCurStatWithV.GetNXX();
} else {
// initialize
G4int i;
for (i=0; i<2; i++) {
distance[i] = kInfinity;
areacode[i] = sOutside;
isvalid[i] = false;
gxx[i].set(kInfinity, kInfinity, kInfinity);
}
}
G4ThreeVector p = ComputeLocalPoint(gp);
G4ThreeVector v = ComputeLocalDirection(gv);
//
// special case!
// if p is on surface, distance = 0.
//
if (fabs(p.z()) == 0.) { // if p is on the plane
distance[0] = 0;
G4ThreeVector xx = p;
gxx[0] = ComputeGlobalPoint(xx);
if (validate == kValidateWithTol) {
areacode[0] = GetAreaCode(xx);
if (!IsOutside(areacode[0])) {
isvalid[0] = true;
}
} else if (validate == kValidateWithoutTol) {
areacode[0] = GetAreaCode(xx, false);
if (IsInside(areacode[0])) {
isvalid[0] = true;
}
} else { // kDontValidate
areacode[0] = sInside;
isvalid[0] = true;
}
return 1;
}
//
// special case end
//
if (v.z() == 0) {
fCurStatWithV.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
isvalid[0], 0, validate, &gp, &gv);
return 0;
}
distance[0] = - (p.z() / v.z());
G4ThreeVector xx = p + distance[0]*v;
gxx[0] = ComputeGlobalPoint(xx);
if (validate == kValidateWithTol) {
areacode[0] = GetAreaCode(xx);
if (!IsOutside(areacode[0])) {
if (distance[0] >= 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 G4SPECSDEBUG
G4cerr << "ERROR - G4FlatSurface::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 G4FlatSurface::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<fCurStat.GetNXX(); i++) {
gxx[i] = fCurStat.GetXX(i);
distance[i] = fCurStat.GetDistance(i);
areacode[i] = fCurStat.GetAreacode(i);
}
return fCurStat.GetNXX();
} else {
// initialize
G4int i;
for (i=0; i<2; i++) {
distance[i] = kInfinity;
areacode[i] = sOutside;
gxx[i].set(kInfinity, kInfinity, kInfinity);
}
}
G4ThreeVector p = ComputeLocalPoint(gp);
G4ThreeVector xx;
// The plane is placed on origin with making its normal
// parallel to z-axis.
if (fabs(p.z()) <= 0.5 * kCarTolerance) { // if p is on the plane, return 1
distance[0] = 0;
xx = p;
} else {
distance[0] = fabs(p.z());
xx.set(p.x(), p.y(), 0);
}
gxx[0] = ComputeGlobalPoint(xx);
areacode[0] = sInside;
G4bool isvalid = true;
fCurStat.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
isvalid, 1, kDontValidate, &gp);
return 1;
}
//=====================================================================
//* GetAreaCode -------------------------------------------------------
G4int G4FlatSurface::GetAreaCode(const G4ThreeVector &xx,
G4bool withTol)
{
static const G4double rtol = 0.5*kRadTolerance;
G4int areacode = sInside;
if (fAxis[0] == kRho && fAxis[1] == kPhi) {
G4int rhoaxis = 0;
// G4int phiaxis = 0;
G4ThreeVector dphimin; // direction of phi-minimum boundary
G4ThreeVector dphimax; // direction of phi-maximum boundary
dphimin = GetCorner(sCMax1Min);
dphimax = GetCorner(sCMax1Max);
if (withTol) {
G4bool isoutside = false;
// test boundary of rho-axis
if (xx.getRho() <= fAxisMin[rhoaxis] + rtol) {
areacode |= (sAxis0 & (sAxisRho | sAxisMin)) | sBoundary; // rho-min
if (xx.getRho() < fAxisMin[rhoaxis] - rtol) isoutside = true;
} else if (xx.getRho() >= fAxisMax[rhoaxis] - rtol) {
areacode |= (sAxis0 & (sAxisRho | sAxisMax)) | sBoundary; // rho-max
if (xx.getRho() > fAxisMax[rhoaxis] + rtol) isoutside = true;
}
// test boundary of phi-axis
if (AmIOnLeftSide(xx, dphimin) >= 0) { // xx is on dphimin
areacode |= (sAxis1 & (sAxisPhi | sAxisMin));
if (areacode & sBoundary) areacode |= sCorner; // xx is on the corner.
else areacode |= sBoundary;
if (AmIOnLeftSide(xx, dphimin) > 0) isoutside = true;
} else if (AmIOnLeftSide(xx, dphimax) <= 0) { // xx is on dphimax
areacode |= (sAxis1 & (sAxisPhi | sAxisMax));
if (areacode & sBoundary) areacode |= sCorner; // xx is on the corner.
else areacode |= sBoundary;
if (AmIOnLeftSide(xx, dphimax) < 0) 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 & sAxisRho) | (sAxis1 & sAxisPhi);
}
} else {
// out of boundary of rho-axis
if (xx.getRho() < fAxisMin[rhoaxis]) {
areacode |= (sAxis0 & (sAxisRho | sAxisMin)) | sBoundary;
} else if (xx.getRho() > fAxisMax[rhoaxis]) {
areacode |= (sAxis0 & (sAxisRho | sAxisMax)) | sBoundary;
}
// out of boundary of phi-axis
if (AmIOnLeftSide(xx, dphimin, false) >= 0) { // xx is leftside or
areacode |= (sAxis1 & (sAxisPhi | sAxisMin)) ; // boundary of dphimin
if (areacode & sBoundary) areacode |= sCorner; // xx is on the corner.
else areacode |= sBoundary;
} else if (AmIOnLeftSide(xx, dphimax, false) <= 0) { // xx is rightside or
areacode |= (sAxis1 & (sAxisPhi | sAxisMax)) ; // boundary of dphimax
if (areacode & sBoundary) areacode |= sCorner; // xx is on the corner.
else areacode |= sBoundary;
}
if ((areacode & sBoundary) != sBoundary) {
areacode |= (sAxis0 & sAxisRho) | (sAxis1 & sAxisPhi);
}
}
return areacode;
} else {
G4cerr << "ERROR - G4FlatSurface::GetAreaCode()" << G4endl
<< " fAxis[0] = " << fAxis[0] << G4endl
<< " fAxis[1] = " << fAxis[1] << G4endl;
G4Exception("G4FlatSurface::GetAreaCode()", "NotImplemented",
FatalException, "Feature NOT implemented !");
}
return areacode;
}
//=====================================================================
//* SetCorners --------------------------------------------------------
void G4FlatSurface::SetCorners()
{
// Set Corner points in local coodinate.
if (fAxis[0] == kRho && fAxis[1] == kPhi) {
G4int rhoaxis = 0; // kRho
G4int phiaxis = 1; // kPhi
G4double x, y, z;
// corner of Axis0min and Axis1min
x = fAxisMin[rhoaxis]*cos(fAxisMin[phiaxis]);
y = fAxisMin[rhoaxis]*sin(fAxisMin[phiaxis]);
z = 0;
SetCorner(sCMin1Min, x, y, z);
// corner of Axis0max and Axis1min
x = fAxisMax[rhoaxis]*cos(fAxisMin[phiaxis]);
y = fAxisMax[rhoaxis]*sin(fAxisMin[phiaxis]);
z = 0;
SetCorner(sCMax1Min, x, y, z);
// corner of Axis0max and Axis1max
x = fAxisMax[rhoaxis]*cos(fAxisMax[phiaxis]);
y = fAxisMax[rhoaxis]*sin(fAxisMax[phiaxis]);
z = 0;
SetCorner(sCMax1Max, x, y, z);
// corner of Axis0min and Axis1max
x = fAxisMin[rhoaxis]*cos(fAxisMax[phiaxis]);
y = fAxisMin[rhoaxis]*sin(fAxisMax[phiaxis]);
z = 0;
SetCorner(sCMin1Max, x, y, z);
} else {
G4cerr << "ERROR - G4FlatSurface::SetCorners()" << G4endl
<< " fAxis[0] = " << fAxis[0] << G4endl
<< " fAxis[1] = " << fAxis[1] << G4endl;
G4Exception("G4FlatSurface::SetCorners()", "NotImplemented",
FatalException, "Feature NOT implemented !");
}
}
//=====================================================================
//* SetBoundaries() ---------------------------------------------------
void G4FlatSurface::SetBoundaries()
{
// Set direction-unit vector of phi-boundary-lines in local coodinate.
// Don't call the function twice.
if (fAxis[0] == kRho && fAxis[1] == kPhi) {
G4ThreeVector direction;
// sAxis0 & sAxisMin
direction = GetCorner(sCMin1Max) - GetCorner(sCMin1Min);
direction = direction.unit();
SetBoundary(sAxis0 & (sAxisPhi | sAxisMin), direction,
GetCorner(sCMin1Min), sAxisPhi);
// sAxis0 & sAxisMax
direction = GetCorner(sCMax1Max) - GetCorner(sCMax1Min);
direction = direction.unit();
SetBoundary(sAxis0 & (sAxisPhi | sAxisMax), direction,
GetCorner(sCMax1Min), sAxisPhi);
// sAxis1 & sAxisMin
direction = GetCorner(sCMax1Min) - GetCorner(sCMin1Min);
direction = direction.unit();
SetBoundary(sAxis1 & (sAxisRho | sAxisMin), direction,
GetCorner(sCMin1Min), sAxisRho);
// sAxis1 & sAxisMax
direction = GetCorner(sCMax1Max) - GetCorner(sCMin1Max);
direction = direction.unit();
SetBoundary(sAxis1 & (sAxisRho | sAxisMax), direction,
GetCorner(sCMin1Max), sAxisPhi);
} else {
G4cerr << "ERROR - G4FlatSurface::SetBoundaries()" << G4endl
<< " fAxis[0] = " << fAxis[0] << G4endl
<< " fAxis[1] = " << fAxis[1] << G4endl;
G4Exception("G4FlatSurface::SetBoundaries()", "NotImplemented",
FatalException, "Feature NOT implemented !");
}
}
@@ -0,0 +1,912 @@
//
// ********************************************************************
// * DISCLAIMER *
// * *
// * The following disclaimer summarizes all the specific disclaimers *
// * of contributors to this software. The specific disclaimers,which *
// * govern, are listed with their locations in: *
// * http://cern.ch/geant4/license *
// * *
// * 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. *
// * *
// * This code implementation is the intellectual property of the *
// * GEANT4 collaboration. *
// * By copying, distributing or modifying the Program (or any work *
// * based on the Program) you indicate your acceptance of this *
// * statement, and all its terms. *
// ********************************************************************
//
//
// $Id: G4HyperbolicSurface.cc,v 1.5 2004/05/28 13:13:36 gcosmo Exp $
// GEANT4 tag $Name: geant4-06-02 $
//
//
// --------------------------------------------------------------------
// GEANT 4 class source file
//
//
// G4HyperbolicSurface.cc
//
// 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.
// --------------------------------------------------------------------
#include "G4HyperbolicSurface.hh"
//=====================================================================
//* constructors ------------------------------------------------------
G4HyperbolicSurface::G4HyperbolicSurface(const G4String &name,
const G4RotationMatrix &rot,
const G4ThreeVector &tlate,
const G4int handedness,
const G4double kappa,
const G4double tanstereo,
const G4double r0,
const EAxis axis0,
const EAxis axis1,
G4double axis0min,
G4double axis1min,
G4double axis0max,
G4double axis1max )
: G4VSurface(name, rot, tlate, handedness, axis0, axis1,
axis0min, axis1min, axis0max, axis1max),
fKappa(kappa), fTanStereo(tanstereo),
fTan2Stereo(tanstereo*tanstereo), fR0(r0), fR02(r0*r0)
{
if (axis0 == kZAxis && axis1 == kPhi) {
G4Exception("G4HyperbolicSurface::G4HyperbolicSurface()", "InvalidSetup",
FatalException, "Should swap axis0 and axis1!");
}
fInside.gp.set(kInfinity, kInfinity, kInfinity);
fInside.inside = kOutside;
fIsValidNorm = false;
SetCorners();
SetBoundaries();
}
G4HyperbolicSurface::G4HyperbolicSurface(const G4String &name,
G4double EndInnerRadius[2],
G4double EndOuterRadius[2],
G4double DPhi,
G4double EndPhi[2],
G4double EndZ[2],
G4double InnerRadius,
G4double OuterRadius,
G4double Kappa,
G4double TanInnerStereo,
G4double TanOuterStereo,
G4int handedness)
: G4VSurface(name)
{
fHandedness = handedness; // +z = +ve, -z = -ve
fAxis[0] = kPhi;
fAxis[1] = kZAxis;
fAxisMin[0] = kInfinity; // we cannot fix boundary min of Phi,
fAxisMax[0] = kInfinity; // because it depends on z.
fAxisMin[1] = EndZ[0];
fAxisMax[1] = EndZ[1];
fKappa = Kappa;
if (handedness < 0) { // inner hyperbolic surface
fTanStereo = TanInnerStereo;
fR0 = InnerRadius;
} else { // outer hyperbolic surface
fTanStereo = TanOuterStereo;
fR0 = OuterRadius;
}
fTan2Stereo = fTanStereo * fTanStereo;
fR02 = fR0 * fR0;
fTrans.set(0, 0, 0);
fIsValidNorm = false;
fInside.gp.set(kInfinity, kInfinity, kInfinity);
fInside.inside = kOutside;
SetCorners(EndInnerRadius, EndOuterRadius, DPhi, EndPhi, EndZ) ;
SetBoundaries();
}
//=====================================================================
//* destructor --------------------------------------------------------
G4HyperbolicSurface::~G4HyperbolicSurface()
{
}
//=====================================================================
//* GetNormal ---------------------------------------------------------
G4ThreeVector G4HyperbolicSurface::GetNormal(const G4ThreeVector &tmpxx,
G4bool isGlobal)
{
// GetNormal returns a normal vector at a surface (or very close
// to surface) point at tmpxx.
// If isGlobal=true, it returns the normal in global coordinate.
//
G4ThreeVector xx;
if (isGlobal) {
xx = ComputeLocalPoint(tmpxx);
if ((xx - fCurrentNormal.p).mag() < 0.5 * kCarTolerance) {
return ComputeGlobalDirection(fCurrentNormal.normal);
}
} else {
xx = tmpxx;
if (xx == fCurrentNormal.p) {
return fCurrentNormal.normal;
}
}
fCurrentNormal.p = xx;
G4ThreeVector normal( xx.x(), xx.y(), -xx.z() * fTan2Stereo);
normal *= fHandedness;
normal = normal.unit();
if (isGlobal) {
fCurrentNormal.normal = ComputeLocalDirection(normal);
} else {
fCurrentNormal.normal = normal;
}
return fCurrentNormal.normal;
}
//=====================================================================
//* Inside() ----------------------------------------------------------
EInside G4HyperbolicSurface::Inside(const G4ThreeVector &gp)
{
// Inside returns
static const G4double halftol = 0.5 * kRadTolerance;
if (fInside.gp == gp) {
return fInside.inside;
}
fInside.gp = gp;
G4ThreeVector p = ComputeLocalPoint(gp);
if (p.mag() < DBL_MIN) {
fInside.inside = kOutside;
return fInside.inside;
}
G4double rhohype = GetRhoAtPZ(p);
G4double distanceToOut = fHandedness * (rhohype - p.getRho());
// +ve : inside
if (distanceToOut < -halftol) {
fInside.inside = kOutside;
} else {
G4int areacode = GetAreaCode(p);
if (IsOutside(areacode)) {
fInside.inside = kOutside;
} else if (IsBoundary(areacode)) {
fInside.inside = kSurface;
} else if (IsInside(areacode)) {
if (distanceToOut <= halftol) {
fInside.inside = kSurface;
} else {
fInside.inside = kInside;
}
} else {
G4cout << "WARNING - G4HyperbolicSurface::Inside()" << G4endl
<< " Invalid option !" << G4endl
<< " name, areacode, distanceToOut = "
<< GetName() << ", " << std::hex << areacode << std::dec << ", "
<< distanceToOut << G4endl;
}
}
return fInside.inside;
}
//=====================================================================
//* DistanceToSurface -------------------------------------------------
G4int G4HyperbolicSurface::DistanceToSurface(const G4ThreeVector &gp,
const G4ThreeVector &gv,
G4ThreeVector gxx[],
G4double distance[],
G4int areacode[],
G4bool isvalid[],
EValidate validate)
{
//
// Decide if and where a line intersects with a hyperbolic
// surface (of infinite extent)
//
// Arguments:
// p - (in) Point on trajectory
// v - (in) Vector along trajectory
// r2 - (in) Square of radius at z = 0
// tan2phi - (in) tan(stereo)**2
// s - (out) Up to two points of intersection, where the
// intersection point is p + s*v, and if there are
// two intersections, s[0] < s[1]. May be negative.
// Returns:
// The number of intersections. If 0, the trajectory misses.
//
//
// Equation of a line:
//
// x = x0 + s*tx y = y0 + s*ty z = z0 + s*tz
//
// Equation of a hyperbolic surface:
//
// x**2 + y**2 = r**2 + (z*tanPhi)**2
//
// Solution is quadratic:
//
// a*s**2 + b*s + c = 0
//
// where:
//
// a = tx**2 + ty**2 - (tz*tanPhi)**2
//
// b = 2*( x0*tx + y0*ty - z0*tz*tanPhi**2 )
//
// c = x0**2 + y0**2 - r**2 - (z0*tanPhi)**2
//
fCurStatWithV.ResetfDone(validate, &gp, &gv);
if (fCurStatWithV.IsDone()) {
G4int i;
for (i=0; i<fCurStatWithV.GetNXX(); i++) {
gxx[i] = fCurStatWithV.GetXX(i);
distance[i] = fCurStatWithV.GetDistance(i);
areacode[i] = fCurStatWithV.GetAreacode(i);
isvalid[i] = fCurStatWithV.IsValid(i);
}
return fCurStatWithV.GetNXX();
} else {
// initialize
G4int i;
for (i=0; i<2; i++) {
distance[i] = kInfinity;
areacode[i] = sOutside;
isvalid[i] = false;
gxx[i].set(kInfinity, kInfinity, kInfinity);
}
}
G4ThreeVector p = ComputeLocalPoint(gp);
G4ThreeVector v = ComputeLocalDirection(gv);
G4ThreeVector xx[2];
//
// special case! p is on origin.
//
if (p.mag() == 0) {
// p is origin.
// unique solution of 2-dimension question in r-z plane
// Equations:
// r^2 = fR02 + z^2*fTan2Stere0
// r = beta*z
// where
// beta = vrho / vz
// Solution (z value of intersection point):
// xxz = +- sqrt (fR02 / (beta^2 - fTan2Stereo))
//
G4double vz = v.z();
G4double absvz = abs(vz);
G4double vrho = v.getRho();
G4double vslope = vrho/vz;
G4double vslope2 = vslope * vslope;
if (vrho == 0 || (vrho/absvz) <= (absvz*fabs(fTanStereo)/absvz)) {
// vz/vrho is bigger than slope of asymptonic line
distance[0] = kInfinity;
fCurStatWithV.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
isvalid[0], 0, validate, &gp, &gv);
return 0;
}
if (vz) {
G4double xxz = sqrt(fR02 / (vslope2 - fTan2Stereo))
* (vz / fabs(vz)) ;
G4double t = xxz / vz;
xx[0].set(t*v.x(), t*v.y(), xxz);
} else {
// p.z = 0 && v.z =0
xx[0].set(v.x()*fR0, v.y()*fR0, 0); // v is a unit vector.
}
distance[0] = xx[0].mag();
gxx[0] = ComputeGlobalPoint(xx[0]);
if (validate == kValidateWithTol) {
areacode[0] = GetAreaCode(xx[0]);
if (!IsOutside(areacode[0])) {
if (distance[0] >= 0) isvalid[0] = true;
}
} else if (validate == kValidateWithoutTol) {
areacode[0] = GetAreaCode(xx[0], 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);
return 1;
}
//
// special case end.
//
G4double a = v.x()*v.x() + v.y()*v.y() - v.z()*v.z()*fTan2Stereo;
G4double b = 2.0 * ( p.x() * v.x() + p.y() * v.y() - p.z() * v.z() * fTan2Stereo );
G4double c = p.x()*p.x() + p.y()*p.y() - fR02 - p.z()*p.z()*fTan2Stereo;
G4double D = b*b - 4*a*c; //discriminant
if (fabs(a) < DBL_MIN) {
if (fabs(b) > DBL_MIN) { // single solution
distance[0] = -c/b;
xx[0] = p + distance[0]*v;
gxx[0] = ComputeGlobalPoint(xx[0]);
if (validate == kValidateWithTol) {
areacode[0] = GetAreaCode(xx[0]);
if (!IsOutside(areacode[0])) {
if (distance[0] >= 0) isvalid[0] = true;
}
} else if (validate == kValidateWithoutTol) {
areacode[0] = GetAreaCode(xx[0], 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);
return 1;
} else {
// if a=b=0 and c != 0, p is origin and v is parallel to asymptotic line.
// if a=b=c=0, p is on surface and v is paralell to stereo wire.
// return distance = infinity.
fCurStatWithV.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
isvalid[0], 0, validate, &gp, &gv);
return 0;
}
} else if (D > DBL_MIN) { // double solutions
D = sqrt(D);
G4double factor = 0.5/a;
G4double tmpdist[2] = {kInfinity, kInfinity};
G4ThreeVector tmpxx[2] ;
G4int tmpareacode[2] = {sOutside, sOutside};
G4bool tmpisvalid[2] = {false, false};
G4int i;
for (i=0; i<2; i++) {
tmpdist[i] = factor*(-b - D);
D = -D;
tmpxx[i] = p + tmpdist[i]*v;
if (validate == kValidateWithTol) {
tmpareacode[i] = GetAreaCode(tmpxx[i]);
if (!IsOutside(tmpareacode[i])) {
if (tmpdist[i] >= 0) tmpisvalid[i] = true;
continue;
}
} else if (validate == kValidateWithoutTol) {
tmpareacode[i] = GetAreaCode(tmpxx[i], false);
if (IsInside(tmpareacode[i])) {
if (tmpdist[i] >= 0) tmpisvalid[i] = true;
continue;
}
} else { // kDontValidate
tmpareacode[i] = sInside;
if (tmpdist[i] >= 0) tmpisvalid[i] = true;
continue;
}
}
if (tmpdist[0] <= tmpdist[1]) {
distance[0] = tmpdist[0];
distance[1] = tmpdist[1];
xx[0] = tmpxx[0];
xx[1] = tmpxx[1];
gxx[0] = ComputeGlobalPoint(tmpxx[0]);
gxx[1] = ComputeGlobalPoint(tmpxx[1]);
areacode[0] = tmpareacode[0];
areacode[1] = tmpareacode[1];
isvalid[0] = tmpisvalid[0];
isvalid[1] = tmpisvalid[1];
} else {
distance[0] = tmpdist[1];
distance[1] = tmpdist[0];
xx[0] = tmpxx[1];
xx[1] = tmpxx[0];
gxx[0] = ComputeGlobalPoint(tmpxx[1]);
gxx[1] = ComputeGlobalPoint(tmpxx[0]);
areacode[0] = tmpareacode[1];
areacode[1] = tmpareacode[0];
isvalid[0] = tmpisvalid[1];
isvalid[1] = tmpisvalid[0];
}
fCurStatWithV.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
isvalid[0], 2, validate, &gp, &gv);
fCurStatWithV.SetCurrentStatus(1, gxx[1], distance[1], areacode[1],
isvalid[1], 2, validate, &gp, &gv);
return 2;
} else {
// if D<0, no solution
// if D=0, just grazing the surfaces, return kInfinity
fCurStatWithV.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
isvalid[0], 0, validate, &gp, &gv);
return 0;
}
G4Exception("G4HyperbolicSurface::DistanceToSurface(p,v)",
"InvalidCondition", FatalException, "Illegal operation !");
return 1;
}
//=====================================================================
//* DistanceToSurface -------------------------------------------------
G4int G4HyperbolicSurface::DistanceToSurface(const G4ThreeVector &gp,
G4ThreeVector gxx[],
G4double distance[],
G4int areacode[])
{
// Find the approximate distance of a point of a hyperbolic surface.
// The distance must be an underestimate.
// It will also be nice (although not necessary) that the estimate is
// always finite no matter how close the point is.
//
// We arranged G4Hype::ApproxDistOutside and G4Hype::ApproxDistInside
// for this function. See these discriptions.
static const G4double halftol = 0.5 * kRadTolerance;
fCurStat.ResetfDone(kDontValidate, &gp);
if (fCurStat.IsDone()) {
for (G4int i=0; i<fCurStat.GetNXX(); i++) {
gxx[i] = fCurStat.GetXX(i);
distance[i] = fCurStat.GetDistance(i);
areacode[i] = fCurStat.GetAreacode(i);
}
return fCurStat.GetNXX();
} else {
// initialize
for (G4int i=0; i<2; i++) {
distance[i] = kInfinity;
areacode[i] = sOutside;
gxx[i].set(kInfinity, kInfinity, kInfinity);
}
}
G4ThreeVector p = ComputeLocalPoint(gp);
G4ThreeVector xx;
//
// special case!
// If p is on surface, return distance = 0 immediatery .
//
G4ThreeVector lastgxx[2];
G4double distfromlast[2];
for (G4int i=0; i<2; i++) {
lastgxx[i] = fCurStatWithV.GetXX(i);
distfromlast[i] = (gp - lastgxx[i]).mag();
}
if ((gp - lastgxx[0]).mag() < halftol || (gp - lastgxx[1]).mag() < halftol) {
// last winner, or last poststep point is on the surface.
xx = p;
gxx[0] = gp;
distance[0] = 0;
G4bool isvalid = true;
fCurStat.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
isvalid, 1, kDontValidate, &gp);
return 1;
}
//
// special case end
//
G4double prho = p.getRho();
G4double pz = fabs(p.z()); // use symmetry
G4double r1 = sqrt(fR02 + pz * pz * fTan2Stereo);
G4ThreeVector pabsz(p.x(), p.y(), pz);
if (prho > r1 + halftol) { // p is outside of Hyperbolic surface
// First point xx1
G4double t = r1 / prho;
G4ThreeVector xx1(t * pabsz.x(), t * pabsz.y() , pz);
// Second point xx2
G4double z2 = (prho * fTanStereo + pz) / (1 + fTan2Stereo);
G4double r2 = sqrt(fR02 + z2 * z2 * fTan2Stereo);
t = r2 / prho;
G4ThreeVector xx2(t * pabsz.x(), t * pabsz.y() , z2);
G4double len = (xx2 - xx1).mag();
if (len < DBL_MIN) {
// xx2 = xx1?? I guess we
// must have really bracketed the normal
distance[0] = (pabsz - xx1).mag();
xx = xx1;
} else {
distance[0] = DistanceToLine(pabsz, xx1, (xx2 - xx1) , xx);
}
} else if (prho < r1 - halftol) { // p is inside of Hyperbolic surface.
// First point xx1
G4double t;
G4ThreeVector xx1;
if (prho < DBL_MIN) {
xx1.set(r1, 0. , pz);
} else {
t = r1 / prho;
xx1.set(t * pabsz.x(), t * pabsz.y() , pz);
}
// dr, dz is tangential vector of Hyparbolic surface at xx1
// dr = r, dz = z*tan2stereo
G4double dr = pz * fTan2Stereo;
G4double dz = r1;
G4double tanbeta = dr / dz;
G4double pztanbeta = pz * tanbeta;
// Second point xx2
// xx2 is intersection between x-axis and tangential vector
G4double r2 = r1 - pztanbeta;
G4ThreeVector xx2;
if (prho < DBL_MIN) {
xx2.set(r2, 0. , 0.);
} else {
t = r2 / prho;
xx2.set(t * pabsz.x(), t * pabsz.y() , 0.);
}
G4ThreeVector d = xx2 - xx1;
distance[0] = DistanceToLine(pabsz, xx1, d, xx);
} else { // p is on Hyperbolic surface.
distance[0] = 0;
xx.set(p.x(), p.y(), pz);
}
if (p.z() < 0) {
G4ThreeVector tmpxx(xx.x(), xx.y(), -xx.z());
xx = tmpxx;
}
gxx[0] = ComputeGlobalPoint(xx);
areacode[0] = sInside;
G4bool isvalid = true;
fCurStat.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
isvalid, 1, kDontValidate, &gp);
return 1;
}
//=====================================================================
//* GetAreaCode -------------------------------------------------------
G4int G4HyperbolicSurface::GetAreaCode(const G4ThreeVector &xx,
G4bool withTol)
{
static const G4double ctol = 0.5 * kCarTolerance;
G4int areacode = sInside;
if ((fAxis[0] == kPhi && fAxis[1] == kZAxis)) {
//G4int phiaxis = 0;
G4int zaxis = 1;
if (withTol) {
G4bool isoutside = false;
G4int phiareacode = GetAreaCodeInPhi(xx);
G4bool isoutsideinphi = IsOutside(phiareacode);
// test boundary of phiaxis
if ((phiareacode & sAxisMin) == sAxisMin) {
areacode |= (sAxis0 & (sAxisPhi | sAxisMin)) | sBoundary;
if (isoutsideinphi) isoutside = true;
} else if ((phiareacode & sAxisMax) == sAxisMax) {
areacode |= (sAxis0 & (sAxisPhi | sAxisMax)) | sBoundary;
if (isoutsideinphi) isoutside = true;
}
// test boundary of zaxis
if (xx.z() < fAxisMin[zaxis] + ctol) {
areacode |= (sAxis1 & (sAxisZ | sAxisMin));
if (areacode & sBoundary) areacode |= sCorner; // xx is on the corner.
else areacode |= sBoundary;
if (xx.z() <= fAxisMin[zaxis] - ctol) isoutside = true;
} else if (xx.z() > fAxisMax[zaxis] - ctol) {
areacode |= (sAxis1 & (sAxisZ | sAxisMax));
if (areacode & sBoundary) areacode |= sCorner; // xx is on the corner.
else areacode |= sBoundary;
if (xx.z() >= fAxisMax[zaxis] + ctol) isoutside = true;
}
// if isoutside = true, clear sInside bit.
// if not on boundary, add boundary information.
if (isoutside) {
G4int tmpareacode = areacode & (~sInside);
areacode = tmpareacode;
} else if ((areacode & sBoundary) != sBoundary) {
areacode |= (sAxis0 & sAxisPhi) | (sAxis1 & sAxisZ);
}
return areacode;
} else {
G4int phiareacode = GetAreaCodeInPhi(xx, false);
// test boundary of z-axis
if (xx.z() < fAxisMin[zaxis]) {
areacode |= (sAxis1 & (sAxisZ | sAxisMin)) | sBoundary;
} else if (xx.z() > fAxisMax[zaxis]) {
areacode |= (sAxis1 & (sAxisZ | sAxisMax)) | sBoundary;
}
// boundary of phi-axis
if (phiareacode == sAxisMin) {
areacode |= (sAxis0 & (sAxisPhi | sAxisMin));
if (areacode & sBoundary) areacode |= sCorner; // xx is on the corner.
else areacode |= sBoundary;
} else if (phiareacode == sAxisMax) {
areacode |= (sAxis0 & (sAxisPhi | sAxisMax));
if (areacode & sBoundary) areacode |= sCorner; // xx is on the corner.
else areacode |= sBoundary;
}
// if not on boundary, add boundary information.
if ((areacode & sBoundary) != sBoundary) {
areacode |= (sAxis0 & sAxisPhi) | (sAxis1 & sAxisZ);
}
return areacode;
}
} else {
G4cerr << "ERROR - G4HyperbolicSurface::GetAreaCode()" << G4endl
<< " fAxis[0] = " << fAxis[0] << G4endl
<< " fAxis[1] = " << fAxis[1] << G4endl;
G4Exception("G4HyperbolicSurface::GetAreaCode()",
"NotImplemented", FatalException,
"Feature NOT implemented !");
}
return areacode;
}
//=====================================================================
//* GetAreaCodeInPhi --------------------------------------------------
G4int G4HyperbolicSurface::GetAreaCodeInPhi(const G4ThreeVector &xx,
G4bool withTol)
{
G4ThreeVector lowerlimit; // lower phi-boundary limit at z = xx.z()
G4ThreeVector upperlimit; // upper phi-boundary limit at z = xx.z()
lowerlimit = GetBoundaryAtPZ(sAxis0 & sAxisMin, xx);
upperlimit = GetBoundaryAtPZ(sAxis0 & sAxisMax, xx);
G4int areacode = sInside;
G4bool isoutside = false;
if (withTol) {
if (AmIOnLeftSide(xx, lowerlimit) >= 0) { // xx is on lowerlimit
areacode |= (sAxisMin | sBoundary);
if (AmIOnLeftSide(xx, lowerlimit) > 0) isoutside = true;
} else if (AmIOnLeftSide(xx, upperlimit) <= 0) { // xx is on upperlimit
areacode |= (sAxisMax | sBoundary);
if (AmIOnLeftSide(xx, upperlimit) < 0) isoutside = true;
}
// if isoutside = true, clear inside bit.
if (isoutside) {
G4int tmpareacode = areacode & (~sInside);
areacode = tmpareacode;
}
} else {
if (AmIOnLeftSide(xx, lowerlimit, false) >= 0) {
areacode |= (sAxisMin | sBoundary);
} else if (AmIOnLeftSide(xx, upperlimit, false) <= 0) {
areacode |= (sAxisMax | sBoundary);
}
}
return areacode;
}
//=====================================================================
//* SetCorners(EndInnerRadius, EndOuterRadius,DPhi,EndPhi,EndZ) -------
void G4HyperbolicSurface::SetCorners(
G4double EndInnerRadius[2],
G4double EndOuterRadius[2],
G4double DPhi,
G4double endPhi[2],
G4double endZ[2]
)
{
// Set Corner points in local coodinate.
if (fAxis[0] == kPhi && fAxis[1] == kZAxis) {
G4int i;
G4double endRad[2];
G4double halfdphi = 0.5*DPhi;
for (i=0; i<2; i++) { // i=0,1 : -ve z, +ve z
endRad[i] = (fHandedness == 1 ? EndOuterRadius[i]
: EndInnerRadius[i]);
}
G4int zmin = 0 ; // at -ve z
G4int zmax = 1 ; // at +ve z
G4double x, y, z;
// corner of Axis0min and Axis1min
x = endRad[zmin]*cos(endPhi[zmin] - halfdphi);
y = endRad[zmin]*sin(endPhi[zmin] - halfdphi);
z = endZ[zmin];
SetCorner(sCMin1Min, x, y, z);
// corner of Axis0max and Axis1min
x = endRad[zmin]*cos(endPhi[zmin] + halfdphi);
y = endRad[zmin]*sin(endPhi[zmin] + halfdphi);
z = endZ[zmin];
SetCorner(sCMax1Min, x, y, z);
// corner of Axis0max and Axis1max
x = endRad[zmax]*cos(endPhi[zmax] + halfdphi);
y = endRad[zmax]*sin(endPhi[zmax] + halfdphi);
z = endZ[zmax];
SetCorner(sCMax1Max, x, y, z);
// corner of Axis0min and Axis1max
x = endRad[zmax]*cos(endPhi[zmax] - halfdphi);
y = endRad[zmax]*sin(endPhi[zmax] - halfdphi);
z = endZ[zmax];
SetCorner(sCMin1Max, x, y, z);
} else {
G4cerr << "ERROR - G4FlatSurface::SetCorners()" << G4endl
<< " fAxis[0] = " << fAxis[0] << G4endl
<< " fAxis[1] = " << fAxis[1] << G4endl;
G4Exception("G4HyperbolicSurface::SetCorners()",
"NotImplemented", FatalException,
"Feature NOT implemented !");
}
}
//=====================================================================
//* SetCorners() ------------------------------------------------------
void G4HyperbolicSurface::SetCorners()
{
G4Exception("G4HyperbolicSurface::SetCorners()",
"NotImplemented", FatalException,
"Method NOT implemented !");
}
//=====================================================================
//* SetBoundaries() ---------------------------------------------------
void G4HyperbolicSurface::SetBoundaries()
{
// Set direction-unit vector of phi-boundary-lines in local coodinate.
// sAxis0 must be kPhi.
// This fanction set lower phi-boundary and upper phi-boundary.
if (fAxis[0] == kPhi && fAxis[1] == kZAxis) {
G4ThreeVector direction;
// sAxis0 & sAxisMin
direction = GetCorner(sCMin1Max) - GetCorner(sCMin1Min);
direction = direction.unit();
SetBoundary(sAxis0 & (sAxisPhi | sAxisMin), direction,
GetCorner(sCMin1Min), sAxisZ);
// sAxis0 & sAxisMax
direction = GetCorner(sCMax1Max) - GetCorner(sCMax1Min);
direction = direction.unit();
SetBoundary(sAxis0 & (sAxisPhi | sAxisMax), direction,
GetCorner(sCMax1Min), sAxisZ);
// sAxis1 & sAxisMin
direction = GetCorner(sCMax1Min) - GetCorner(sCMin1Min);
direction = direction.unit();
SetBoundary(sAxis1 & (sAxisZ | sAxisMin), direction,
GetCorner(sCMin1Min), sAxisPhi);
// sAxis1 & sAxisMax
direction = GetCorner(sCMax1Max) - GetCorner(sCMin1Max);
direction = direction.unit();
SetBoundary(sAxis1 & (sAxisZ | sAxisMax), direction,
GetCorner(sCMin1Max), sAxisPhi);
} else {
G4cerr << "ERROR - G4HyperbolicSurface::SetBoundaries()" << G4endl
<< " fAxis[0] = " << fAxis[0] << G4endl
<< " fAxis[1] = " << fAxis[1] << G4endl;
G4Exception("G4HyperbolicSurface::SetBoundaries()",
"NotImplemented", FatalException,
"Feature NOT implemented !");
}
}
@@ -0,0 +1,949 @@
//
// ********************************************************************
// * DISCLAIMER *
// * *
// * The following disclaimer summarizes all the specific disclaimers *
// * of contributors to this software. The specific disclaimers,which *
// * govern, are listed with their locations in: *
// * http://cern.ch/geant4/license *
// * *
// * 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. *
// * *
// * This code implementation is the intellectual property of the *
// * GEANT4 collaboration. *
// * By copying, distributing or modifying the Program (or any work *
// * based on the Program) you indicate your acceptance of this *
// * statement, and all its terms. *
// ********************************************************************
//
//
// $Id: G4TwistedSurface.cc,v 1.6 2004/06/07 08:46:38 gcosmo Exp $
// GEANT4 tag $Name: geant4-06-02 $
//
//
// --------------------------------------------------------------------
// GEANT 4 class source file
//
//
// G4TwistedSurface.cc
//
// 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.
// --------------------------------------------------------------------
#include "G4TwistedSurface.hh"
//=====================================================================
//* constructors ------------------------------------------------------
G4TwistedSurface::G4TwistedSurface(const G4String &name,
const G4RotationMatrix &rot,
const G4ThreeVector &tlate,
G4int handedness,
const G4double kappa,
const EAxis axis0,
const EAxis axis1,
G4double axis0min,
G4double axis1min,
G4double axis0max,
G4double axis1max)
: G4VSurface(name, rot, tlate, handedness, axis0, axis1,
axis0min, axis1min, axis0max, axis1max),
fKappa(kappa)
{
if (axis0 == kZAxis && axis1 == kXAxis) {
G4Exception("G4TwistedSurface::G4TwistedSurface()", "InvalidSetup",
FatalException, "Should swap axis0 and axis1!");
}
fIsValidNorm = false;
SetCorners();
SetBoundaries();
}
G4TwistedSurface::G4TwistedSurface(const G4String &name,
G4double EndInnerRadius[2],
G4double EndOuterRadius[2],
G4double DPhi,
G4double EndPhi[2],
G4double EndZ[2],
G4double InnerRadius,
G4double OuterRadius,
G4double Kappa,
G4int handedness)
: G4VSurface(name)
{
fHandedness = handedness; // +z = +ve, -z = -ve
fAxis[0] = kXAxis; // in local coordinate system
fAxis[1] = kZAxis;
fAxisMin[0] = InnerRadius; // Inner-hype radius at z=0
fAxisMax[0] = OuterRadius; // Outer-hype radius at z=0
fAxisMin[1] = EndZ[0];
fAxisMax[1] = EndZ[1];
fKappa = Kappa;
fRot.rotateZ( fHandedness > 0
? -0.5*DPhi
: 0.5*DPhi );
fTrans.set(0, 0, 0);
fIsValidNorm = false;
SetCorners( EndInnerRadius, EndOuterRadius, EndPhi, EndZ) ;
SetBoundaries();
}
//=====================================================================
//* destructor --------------------------------------------------------
G4TwistedSurface::~G4TwistedSurface()
{
}
//=====================================================================
//* GetNormal ---------------------------------------------------------
G4ThreeVector G4TwistedSurface::GetNormal(const G4ThreeVector &tmpxx,
G4bool isGlobal)
{
// GetNormal returns a normal vector at a surface (or very close
// to surface) point at tmpxx.
// If isGlobal=true, it returns the normal in global coordinate.
//
G4ThreeVector xx;
if (isGlobal) {
xx = ComputeLocalPoint(tmpxx);
if ((xx - fCurrentNormal.p).mag() < 0.5 * kCarTolerance) {
return ComputeGlobalDirection(fCurrentNormal.normal);
}
} else {
xx = tmpxx;
if (xx == fCurrentNormal.p) {
return fCurrentNormal.normal;
}
}
G4ThreeVector er(1, fKappa * xx.z(), 0);
G4ThreeVector ez(0, fKappa * xx.x(), 1);
G4ThreeVector normal = fHandedness*(er.cross(ez));
if (isGlobal) {
fCurrentNormal.normal = ComputeGlobalDirection(normal.unit());
} else {
fCurrentNormal.normal = normal.unit();
}
return fCurrentNormal.normal;
}
//=====================================================================
//* DistanceToSurface -------------------------------------------------
G4int G4TwistedSurface::DistanceToSurface(const G4ThreeVector &gp,
const G4ThreeVector &gv,
G4ThreeVector gxx[],
G4double distance[],
G4int areacode[],
G4bool isvalid[],
EValidate validate)
{
// Coordinate system:
//
// The coordinate system is so chosen that the intersection of
// the twisted surface with the z=0 plane coincides with the
// x-axis.
// Rotation matrix from this coordinate system (local system)
// to global system is saved in fRot field.
// So the (global) particle position and (global) velocity vectors,
// p and v, should be rotated fRot.inverse() in order to convert
// to local vectors.
//
// Equation of a twisted surface:
//
// x(rho(z=0), z) = rho(z=0)
// y(rho(z=0), z) = rho(z=0)*K*z
// z(rho(z=0), z) = z
// with
// K = tan(fPhiTwist/2)/fZHalfLen
//
// Equation of a line:
//
// gxx = p + t*v
// with
// p = fRot.inverse()*gp
// v = fRot.inverse()*gv
//
// Solution for intersection:
//
// Required time for crossing is given by solving the
// following quadratic equation:
//
// a*t^2 + b*t + c = 0
//
// where
//
// a = K*v_x*v_z
// b = K*(v_x*p_z + v_z*p_x) - v_y
// c = K*p_x*p_z - p_y
//
// Out of the possible two solutions you must choose
// the one that gives a positive rho(z=0).
//
//
fCurStatWithV.ResetfDone(validate, &gp, &gv);
if (fCurStatWithV.IsDone()) {
G4int i;
for (i=0; i<fCurStatWithV.GetNXX(); i++) {
gxx[i] = fCurStatWithV.GetXX(i);
distance[i] = fCurStatWithV.GetDistance(i);
areacode[i] = fCurStatWithV.GetAreacode(i);
isvalid[i] = fCurStatWithV.IsValid(i);
}
return fCurStatWithV.GetNXX();
} else {
// initialize
G4int i;
for (i=0; i<2; i++) {
distance[i] = kInfinity;
areacode[i] = sOutside;
isvalid[i] = false;
gxx[i].set(kInfinity, kInfinity, kInfinity);
}
}
G4ThreeVector p = ComputeLocalPoint(gp);
G4ThreeVector v = ComputeLocalDirection(gv);
G4ThreeVector xx[2];
//
// special case!
// p is origin or
//
G4double absvz = fabs(v.z());
if ((absvz < DBL_MIN) && (fabs(p.x() * v.y() - p.y() * v.x()) < DBL_MIN)) {
// no intersection
isvalid[0] = false;
fCurStat.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
isvalid[0], 0, validate, &gp, &gv);
return 0;
}
//
// special case end
//
G4double a = fKappa * v.x() * v.z();
G4double b = fKappa * (v.x() * p.z() + v.z() * p.x()) - v.y();
G4double c = fKappa * p.x() * p.z() - p.y();
G4double D = b * b - 4 * a * c; // discriminant
if (fabs(a) < DBL_MIN) {
if (fabs(b) > DBL_MIN) {
// single solution
distance[0] = - c / b;
xx[0] = p + distance[0]*v;
gxx[0] = ComputeGlobalPoint(xx[0]);
if (validate == kValidateWithTol) {
areacode[0] = GetAreaCode(xx[0]);
if (!IsOutside(areacode[0])) {
if (distance[0] >= 0) isvalid[0] = true;
}
} else if (validate == kValidateWithoutTol) {
areacode[0] = GetAreaCode(xx[0], false);
if (IsInside(areacode[0])) {
if (distance[0] >= 0) isvalid[0] = true;
}
} else { // kDontValidate
// we must omit x(rho,z) = rho(z=0) < 0
if (xx[0].x() > 0) {
areacode[0] = sInside;
if (distance[0] >= 0) isvalid[0] = true;
} else {
distance[0] = kInfinity;
fCurStatWithV.SetCurrentStatus(0, gxx[0], distance[0],
areacode[0], isvalid[0],
0, validate, &gp, &gv);
return 0;
}
}
fCurStatWithV.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
isvalid[0], 1, validate, &gp, &gv);
return 1;
} else {
// if a=b=0 , v.y=0 and (v.x=0 && p.x=0) or (v.z=0 && p.z=0) .
// if v.x=0 && p.x=0, no intersection unless p is on z-axis
// (in that case, v is paralell to surface).
// if v.z=0 && p.z=0, no intersection unless p is on x-axis
// (in that case, v is paralell to surface).
// return distance = infinity.
fCurStatWithV.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
isvalid[0], 0, validate, &gp, &gv);
return 0;
}
} else if (D > DBL_MIN) {
// double solutions
D = sqrt(D);
G4double factor = 0.5/a;
G4double tmpdist[2] = {kInfinity, kInfinity};
G4ThreeVector tmpxx[2];
G4int tmpareacode[2] = {sOutside, sOutside};
G4bool tmpisvalid[2] = {false, false};
G4int i;
for (i=0; i<2; i++) {
G4double bminusD = - b - D;
// protection against round off error
//G4double protection = 1.0e-6;
G4double protection = 0;
if ( b * D < 0 && fabs(bminusD / D) < protection ) {
G4double acovbb = (a*c)/(b*b);
tmpdist[i] = - c/b * ( 1 - acovbb * (1 + 2*acovbb));
} else {
tmpdist[i] = factor * bminusD;
}
D = -D;
tmpxx[i] = p + tmpdist[i]*v;
if (validate == kValidateWithTol) {
tmpareacode[i] = GetAreaCode(tmpxx[i]);
if (!IsOutside(tmpareacode[i])) {
if (tmpdist[i] >= 0) tmpisvalid[i] = true;
continue;
}
} else if (validate == kValidateWithoutTol) {
tmpareacode[i] = GetAreaCode(tmpxx[i], false);
if (IsInside(tmpareacode[i])) {
if (tmpdist[i] >= 0) tmpisvalid[i] = true;
continue;
}
} else { // kDontValidate
// we must choose x(rho,z) = rho(z=0) > 0
if (tmpxx[i].x() > 0) {
tmpareacode[i] = sInside;
if (tmpdist[i] >= 0) tmpisvalid[i] = true;
continue;
} else {
tmpdist[i] = kInfinity;
continue;
}
}
}
if (tmpdist[0] <= tmpdist[1]) {
distance[0] = tmpdist[0];
distance[1] = tmpdist[1];
xx[0] = tmpxx[0];
xx[1] = tmpxx[1];
gxx[0] = ComputeGlobalPoint(tmpxx[0]);
gxx[1] = ComputeGlobalPoint(tmpxx[1]);
areacode[0] = tmpareacode[0];
areacode[1] = tmpareacode[1];
isvalid[0] = tmpisvalid[0];
isvalid[1] = tmpisvalid[1];
} else {
distance[0] = tmpdist[1];
distance[1] = tmpdist[0];
xx[0] = tmpxx[1];
xx[1] = tmpxx[0];
gxx[0] = ComputeGlobalPoint(tmpxx[1]);
gxx[1] = ComputeGlobalPoint(tmpxx[0]);
areacode[0] = tmpareacode[1];
areacode[1] = tmpareacode[0];
isvalid[0] = tmpisvalid[1];
isvalid[1] = tmpisvalid[0];
}
fCurStatWithV.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
isvalid[0], 2, validate, &gp, &gv);
fCurStatWithV.SetCurrentStatus(1, gxx[1], distance[1], areacode[1],
isvalid[1], 2, validate, &gp, &gv);
// protection against roundoff error
for (G4int k=0; k<2; k++) {
if (!isvalid[k]) continue;
G4ThreeVector xxonsurface(xx[k].x(), fKappa * fabs(xx[k].x())
* xx[k].z() , xx[k].z());
G4double deltaY = (xx[k] - xxonsurface).mag();
if ( deltaY > 0.5*kCarTolerance ) {
G4int maxcount = 10;
G4int l;
G4double lastdeltaY = deltaY;
G4ThreeVector last = deltaY;
for (l=0; l<maxcount; l++) {
G4ThreeVector surfacenormal = GetNormal(xxonsurface);
distance[k] = DistanceToPlaneWithV(p, v, xxonsurface,
surfacenormal, xx[k]);
deltaY = (xx[k] - xxonsurface).mag();
if (deltaY > lastdeltaY) {
}
gxx[k] = ComputeGlobalPoint(xx[k]);
if (deltaY <= 0.5*kCarTolerance) {
break;
}
xxonsurface.set(xx[k].x(),
fKappa * fabs(xx[k].x()) * xx[k].z(),
xx[k].z());
}
if (l == maxcount) {
G4cerr << "ERROR - G4TwistedSurface::DistanceToSurface(p,v)"
<< G4endl
<< " maxloop count " << maxcount << G4endl;
G4Exception("G4FlatSurface::DistanceToSurface(p,v)",
"InvalidSetup", FatalException,
"Exceeded maxloop count!");
}
}
}
return 2;
} else {
// if D<0, no solution
// if D=0, just grazing the surfaces, return kInfinity
fCurStatWithV.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
isvalid[0], 0, validate, &gp, &gv);
return 0;
}
G4Exception("G4TwistedSurface::DistanceToSurface(p,v)",
"InvalidCondition", FatalException, "Illegal operation !");
return 1;
}
//=====================================================================
//* DistanceToSurface -------------------------------------------------
G4int G4TwistedSurface::DistanceToSurface(const G4ThreeVector &gp,
G4ThreeVector gxx[],
G4double distance[],
G4int areacode[])
{
fCurStat.ResetfDone(kDontValidate, &gp);
G4int i = 0;
if (fCurStat.IsDone()) {
for (i=0; i<fCurStat.GetNXX(); i++) {
gxx[i] = fCurStat.GetXX(i);
distance[i] = fCurStat.GetDistance(i);
areacode[i] = fCurStat.GetAreacode(i);
}
return fCurStat.GetNXX();
} else {
// initialize
for (i=0; i<2; i++) {
distance[i] = kInfinity;
areacode[i] = sOutside;
gxx[i].set(kInfinity, kInfinity, kInfinity);
}
}
static const G4double halftol = 0.5 * kCarTolerance;
G4ThreeVector p = ComputeLocalPoint(gp);
G4ThreeVector xx;
G4int parity = (fKappa >= 0 ? 1 : -1);
//
// special case!
// If p is on surface, or
// p is on z-axis,
// return here immediatery.
//
G4ThreeVector lastgxx[2];
G4double distfromlast[2];
for (i=0; i<2; i++) {
lastgxx[i] = fCurStatWithV.GetXX(i);
distfromlast[i] = (gp - lastgxx[i]).mag();
}
if ((gp - lastgxx[0]).mag() < halftol
|| (gp - lastgxx[1]).mag() < halftol) {
// last winner, or last poststep point is on the surface.
xx = p;
distance[0] = 0;
gxx[0] = gp;
G4bool isvalid = true;
fCurStat.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
isvalid, 1, kDontValidate, &gp);
return 1;
}
if (p.getRho() == 0) {
// p is on z-axis. Namely, p is on twisted surface (invalid area).
// We must return here, however, returning distance to x-minimum
// boundary is better than return 0-distance.
//
G4bool isvalid = true;
if (fAxis[0] == kXAxis && fAxis[1] == kZAxis) {
distance[0] = DistanceToBoundary(sAxis0 & sAxisMin, xx, p);
areacode[0] = sInside;
} else {
distance[0] = 0;
xx.set(0., 0., 0.);
}
gxx[0] = ComputeGlobalPoint(xx);
fCurStat.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
isvalid, 0, kDontValidate, &gp);
return 1;
}
//
// special case end
//
// set corner points of quadrangle try area ...
G4ThreeVector A; // foot of normal from p to boundary of sAxis0 & sAxisMin
G4ThreeVector C; // foot of normal from p to boundary of sAxis0 & sAxisMax
G4ThreeVector B; // point on boundary sAxis0 & sAxisMax at z = A.z()
G4ThreeVector D; // point on boundary sAxis0 & sAxisMin at z = C.z()
G4double distToA; // distance from p to A
G4double distToC; // distance from p to C
distToA = DistanceToBoundary(sAxis0 & sAxisMin, A, p);
distToC = DistanceToBoundary(sAxis0 & sAxisMax, C, p);
// is p.z between a.z and c.z?
// p.z must be bracketed a.z and c.z.
if (A.z() > C.z()) {
if (p.z() > A.z()) {
A = GetBoundaryAtPZ(sAxis0 & sAxisMin, p);
} else if (p.z() < C.z()) {
C = GetBoundaryAtPZ(sAxis0 & sAxisMax, p);
}
} else {
if (p.z() > C.z()) {
C = GetBoundaryAtPZ(sAxis0 & sAxisMax, p);
} else if (p.z() < A.z()) {
A = GetBoundaryAtPZ(sAxis0 & sAxisMin, p);
}
}
G4ThreeVector d[2]; // direction vectors of boundary
G4ThreeVector x0[2]; // foot of normal from line to p
G4int btype[2]; // boundary type
for (i=0; i<2; i++) {
if (i == 0) {
GetBoundaryParameters((sAxis0 & sAxisMax), d[i], x0[i], btype[i]);
B = x0[i] + ((A.z() - x0[i].z()) / d[i].z()) * d[i];
// x0 + t*d , d is direction unit vector.
} else {
GetBoundaryParameters((sAxis0 & sAxisMin), d[i], x0[i], btype[i]);
D = x0[i] + ((C.z() - x0[i].z()) / d[i].z()) * d[i];
}
}
// In order to set correct diagonal, swap A and D, C and B if needed.
G4ThreeVector pt(p.x(), p.y(), 0.);
G4double rc = fabs(p.x());
G4ThreeVector surfacevector(rc, rc * fKappa * p.z(), 0.);
G4int pside = AmIOnLeftSide(pt, surfacevector);
G4double test = (A.z() - C.z()) * parity * pside;
if (test == 0) {
if (pside == 0) {
// p is on surface.
xx = p;
distance[0] = 0;
gxx[0] = gp;
G4bool isvalid = true;
fCurStat.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
isvalid, 1, kDontValidate, &gp);
return 1;
} else {
// A.z = C.z(). return distance to line.
d[0] = C - A;
distance[0] = DistanceToLine(p, A, d[0], xx);
areacode[0] = sInside;
gxx[0] = ComputeGlobalPoint(xx);
G4bool isvalid = true;
fCurStat.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
isvalid, 1, kDontValidate, &gp);
return 1;
}
} else if (test < 0) {
// wrong diagonal. vector AC is crossing the surface!
// swap A and D, C and B
G4ThreeVector tmp;
tmp = A;
A = D;
D = tmp;
tmp = C;
C = B;
B = tmp;
} else {
// correct diagonal. nothing to do.
}
// Now, we chose correct diaglnal.
// First try. divide quadrangle into double triangle by diagonal and
// calculate distance to both surfaces.
G4ThreeVector xxacb; // foot of normal from plane ACB to p
G4ThreeVector nacb; // normal of plane ACD
G4ThreeVector xxcad; // foot of normal from plane CAD to p
G4ThreeVector ncad; // normal of plane CAD
G4ThreeVector AB(A.x(), A.y(), 0);
G4ThreeVector DC(C.x(), C.y(), 0);
G4double distToACB = G4VSurface::DistanceToPlane(p, A, C-A, AB, xxacb, nacb) * parity;
G4double distToCAD = G4VSurface::DistanceToPlane(p, C, C-A, DC, xxcad, ncad) * parity;
// if calculated distance = 0, return
if (fabs(distToACB) <= halftol || fabs(distToCAD) <= halftol) {
xx = (fabs(distToACB) < fabs(distToCAD) ? xxacb : xxcad);
areacode[0] = sInside;
gxx[0] = ComputeGlobalPoint(xx);
distance[0] = 0;
G4bool isvalid = true;
fCurStat.SetCurrentStatus(0, gxx[0], distance[0] , areacode[0],
isvalid, 1, kDontValidate, &gp);
return 1;
}
if (distToACB * distToCAD > 0 && distToACB < 0) {
// both distToACB and distToCAD are negative.
// divide quadrangle into double triangle by diagonal
G4ThreeVector normal;
distance[0] = DistanceToPlane(p, A, B, C, D, parity, xx, normal);
} else {
if (distToACB * distToCAD > 0) {
// both distToACB and distToCAD are positive.
// Take smaller one.
if (distToACB <= distToCAD) {
distance[0] = distToACB;
xx = xxacb;
} else {
distance[0] = distToCAD;
xx = xxcad;
}
} else {
// distToACB * distToCAD is negative.
// take positive one
if (distToACB > 0) {
distance[0] = distToACB;
xx = xxacb;
} else {
distance[0] = distToCAD;
xx = xxcad;
}
}
}
areacode[0] = sInside;
gxx[0] = ComputeGlobalPoint(xx);
G4bool isvalid = true;
fCurStat.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
isvalid, 1, kDontValidate, &gp);
return 1;
}
//=====================================================================
//* DistanceToPlane ---------------------------------------------------
G4double G4TwistedSurface::DistanceToPlane(const G4ThreeVector &p,
const G4ThreeVector &A,
const G4ThreeVector &B,
const G4ThreeVector &C,
const G4ThreeVector &D,
const G4int parity,
G4ThreeVector &xx,
G4ThreeVector &n)
{
static const G4double halftol = 0.5 * kCarTolerance;
G4ThreeVector M = 0.5*(A + B);
G4ThreeVector N = 0.5*(C + D);
G4ThreeVector xxanm; // foot of normal from p to plane ANM
G4ThreeVector nanm; // normal of plane ANM
G4ThreeVector xxcmn; // foot of normal from p to plane CMN
G4ThreeVector ncmn; // normal of plane CMN
G4double distToanm = G4VSurface::DistanceToPlane(p, A, (N - A), (M - A), xxanm, nanm) * parity;
G4double distTocmn = G4VSurface::DistanceToPlane(p, C, (M - C), (N - C), xxcmn, ncmn) * parity;
// if p is behind of both surfaces, abort.
if (distToanm * distTocmn > 0 && distToanm < 0) {
G4Exception("G4TwistedSurface::DistanceToPlane()",
"InvalidCondition", FatalException,
"Point p is behind the surfaces.");
}
// if p is on surface, return 0.
if (fabs(distToanm) <= halftol) {
xx = xxanm;
n = nanm * parity;
return 0;
} else if (fabs(distTocmn) <= halftol) {
xx = xxcmn;
n = ncmn * parity;
return 0;
}
if (distToanm <= distTocmn) {
if (distToanm > 0) {
// both distanses are positive. take smaller one.
xx = xxanm;
n = nanm * parity;
return distToanm;
} else {
// take -ve distance and call the function recursively.
return DistanceToPlane(p, A, M, N, D, parity, xx, n);
}
} else {
if (distTocmn > 0) {
// both distanses are positive. take smaller one.
xx = xxcmn;
n = ncmn * parity;
return distTocmn;
} else {
// take -ve distance and call the function recursively.
return DistanceToPlane(p, C, N, M, B, parity, xx, n);
}
}
}
//=====================================================================
//* GetAreaCode -------------------------------------------------------
G4int G4TwistedSurface::GetAreaCode(const G4ThreeVector &xx,
G4bool withTol)
{
// We must use the function in local coordinate system.
// See the description of DistanceToSurface(p,v).
static const G4double ctol = 0.5 * kCarTolerance;
G4int areacode = sInside;
if (fAxis[0] == kXAxis && fAxis[1] == kZAxis) {
G4int xaxis = 0;
G4int zaxis = 1;
if (withTol) {
G4bool isoutside = false;
// test boundary of xaxis
if (xx.x() < fAxisMin[xaxis] + ctol) {
areacode |= (sAxis0 & (sAxisX | sAxisMin)) | sBoundary;
if (xx.x() <= fAxisMin[xaxis] - ctol) isoutside = true;
} else if (xx.x() > fAxisMax[xaxis] - ctol) {
areacode |= (sAxis0 & (sAxisX | sAxisMax)) | sBoundary;
if (xx.x() >= fAxisMin[xaxis] + ctol) isoutside = true;
}
// test boundary of z-axis
if (xx.z() < fAxisMin[zaxis] + ctol) {
areacode |= (sAxis1 & (sAxisZ | sAxisMin));
if (areacode & sBoundary) areacode |= sCorner; // xx is on the corner.
else areacode |= sBoundary;
if (xx.z() <= fAxisMin[zaxis] - ctol) isoutside = true;
} else if (xx.z() > fAxisMax[zaxis] - ctol) {
areacode |= (sAxis1 & (sAxisZ | sAxisMax));
if (areacode & sBoundary) areacode |= sCorner; // xx is on the corner.
else areacode |= sBoundary;
if (xx.z() >= fAxisMax[zaxis] + 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 & sAxisZ);
}
} else {
// boundary of x-axis
if (xx.x() < fAxisMin[xaxis] ) {
areacode |= (sAxis0 & (sAxisX | sAxisMin)) | sBoundary;
} else if (xx.x() > fAxisMax[xaxis]) {
areacode |= (sAxis0 & (sAxisX | sAxisMax)) | sBoundary;
}
// boundary of z-axis
if (xx.z() < fAxisMin[zaxis]) {
areacode |= (sAxis1 & (sAxisZ | sAxisMin));
if (areacode & sBoundary) areacode |= sCorner; // xx is on the corner.
else areacode |= sBoundary;
} else if (xx.z() > fAxisMax[zaxis]) {
areacode |= (sAxis1 & (sAxisZ | sAxisMax)) ;
if (areacode & sBoundary) areacode |= sCorner; // xx is on the corner.
else areacode |= sBoundary;
}
if ((areacode & sBoundary) != sBoundary) {
areacode |= (sAxis0 & sAxisX) | (sAxis1 & sAxisZ);
}
}
return areacode;
} else {
G4Exception("G4TwistedSurface::GetAreaCode()",
"NotImplemented", FatalException,
"Feature NOT implemented !");
}
return areacode;
}
//=====================================================================
//* SetCorners( arglist ) -------------------------------------------------
void G4TwistedSurface::SetCorners(
G4double endInnerRad[2],
G4double endOuterRad[2],
G4double endPhi[2],
G4double endZ[2])
{
// Set Corner points in local coodinate.
if (fAxis[0] == kXAxis && fAxis[1] == kZAxis) {
G4int zmin = 0 ; // at -ve z
G4int zmax = 1 ; // at +ve z
G4double x, y, z;
// corner of Axis0min and Axis1min
x = endInnerRad[zmin]*cos(endPhi[zmin]);
y = endInnerRad[zmin]*sin(endPhi[zmin]);
z = endZ[zmin];
SetCorner(sCMin1Min, x, y, z);
// corner of Axis0max and Axis1min
x = endOuterRad[zmin]*cos(endPhi[zmin]);
y = endOuterRad[zmin]*sin(endPhi[zmin]);
z = endZ[zmin];
SetCorner(sCMax1Min, x, y, z);
// corner of Axis0max and Axis1max
x = endOuterRad[zmax]*cos(endPhi[zmax]);
y = endOuterRad[zmax]*sin(endPhi[zmax]);
z = endZ[zmax];
SetCorner(sCMax1Max, x, y, z);
// corner of Axis0min and Axis1max
x = endInnerRad[zmax]*cos(endPhi[zmax]);
y = endInnerRad[zmax]*sin(endPhi[zmax]);
z = endZ[zmax];
SetCorner(sCMin1Max, x, y, z);
} else {
G4cerr << "ERROR - G4FlatSurface::SetCorners()" << G4endl
<< " fAxis[0] = " << fAxis[0] << G4endl
<< " fAxis[1] = " << fAxis[1] << G4endl;
G4Exception("G4TwistedSurface::SetCorners()",
"NotImplemented", FatalException,
"Feature NOT implemented !");
}
}
//=====================================================================
//* SetCorners() ------------------------------------------------------
void G4TwistedSurface::SetCorners()
{
G4Exception("G4TwistedSurface::SetCorners()",
"NotImplemented", FatalException,
"Method NOT implemented !");
}
//=====================================================================
//* SetBoundaries() ---------------------------------------------------
void G4TwistedSurface::SetBoundaries()
{
// Set direction-unit vector of boundary-lines in local coodinate.
//
G4ThreeVector direction;
if (fAxis[0] == kXAxis && fAxis[1] == kZAxis) {
// sAxis0 & sAxisMin
direction = GetCorner(sCMin1Max) - GetCorner(sCMin1Min);
direction = direction.unit();
SetBoundary(sAxis0 & (sAxisX | sAxisMin), direction,
GetCorner(sCMin1Min), sAxisZ) ;
// sAxis0 & sAxisMax
direction = GetCorner(sCMax1Max) - GetCorner(sCMax1Min);
direction = direction.unit();
SetBoundary(sAxis0 & (sAxisX | sAxisMax), direction,
GetCorner(sCMax1Min), sAxisZ);
// sAxis1 & sAxisMin
direction = GetCorner(sCMax1Min) - GetCorner(sCMin1Min);
direction = direction.unit();
SetBoundary(sAxis1 & (sAxisZ | sAxisMin), direction,
GetCorner(sCMin1Min), sAxisX);
// sAxis1 & sAxisMax
direction = GetCorner(sCMax1Max) - GetCorner(sCMin1Max);
direction = direction.unit();
SetBoundary(sAxis1 & (sAxisZ | sAxisMax), direction,
GetCorner(sCMin1Max), sAxisX);
} else {
G4cerr << "ERROR - G4FlatSurface::SetBoundaries()" << G4endl
<< " fAxis[0] = " << fAxis[0] << G4endl
<< " fAxis[1] = " << fAxis[1] << G4endl;
G4Exception("G4TwistedSurface::SetCorners()",
"NotImplemented", FatalException,
"Feature NOT implemented !");
}
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff