Import Geant4 0.0.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-01 15:25:35 +02:00
parent 54d6b71f95
commit b97f8d0df7
3237 changed files with 807095 additions and 0 deletions
@@ -0,0 +1,304 @@
// This code implementation is the intellectual property of
// the RD44 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: G4FPlane.cc,v 2.30 1998/12/11 08:29:07 broglia Exp $
// GEANT4 tag $Name: geant4-00 $
//
#include "G4FPlane.hh"
#include "G4CompositeCurve.hh"
G4FPlane::G4FPlane( const G4Vector3D& direction,
const G4Vector3D& axis ,
const G4Point3D& Pt0 ):pplace(direction, axis, Pt0)
{
G4Point3D Pt1 = Pt0 + direction;
// The plane include direction and axis is the normal,
// so axis^direction is included in the plane
G4Point3D Pt2 = Pt0 + axis.cross(direction);
G4Ray::CalcPlane3Pts( Pl, Pt0, Pt1, Pt2 );
active = 1;
CalcNormal();
distance = kInfinity;
Type = 1;
}
G4FPlane::G4FPlane(const G4Point3DVector* pVec, const G4Point3DVector* iVec)
: pplace( (*pVec)[0]-(*pVec)[1], // direction
((*pVec)[pVec->length()-1]-(*pVec)[0])
.cross((*pVec)[0]-(*pVec)[1]), // axis
(*pVec)[0] ) // location
{
G4Ray::CalcPlane3Pts( Pl, (*pVec)[0], (*pVec)[1], (*pVec)[2] );
G4CurveVector bounds;
G4CompositeCurve* polygon;
projectedBoundary = new G4SurfaceBoundary;
polygon= new G4CompositeCurve(*pVec);
bounds.insert(polygon);
if (iVec)
{
polygon= new G4CompositeCurve(*iVec);
bounds.insert(polygon);
}
SetBoundaries(&bounds);
CalcNormal();
IsConvex();
distance = kInfinity;
Type=1;
}
void G4FPlane::CalcBBox()
{
// This is needed since the bounds are used for the Solid
// bbox calculation. The bbox test is NOT performed for
// planar surfaces.
// Finds the bounds of the G4Plane surface iow
// calculates the bounds for a bounding box
// to the surface. The bounding box is used
// for a preliminary check of intersection.
bbox= new G4BoundingBox3D(surfaceBoundary.BBox().GetBoxMin(),
surfaceBoundary.BBox().GetBoxMax());
}
void G4FPlane::CalcNormal()
{
/*
// Calc Normal for surface which is used for the projection
// Make planes
G4Vector3D norm;
G4Vector3D RefDirection = pplace.GetRefDirection();
G4Vector3D Axis = pplace.GetAxis();
// L. Broglia : before in G4Placement
if( RefDirection == Axis )
norm = RefDirection;
else
{
// L. Broglia : error on setY, and it`s better to use cross function
// norm.setX( RefDirection.y() * Axis.z() - RefDirection.z() * Axis.y() );
// norm.setY( RefDirection.x() * Axis.z() - RefDirection.z() * Axis.x() );
// norm.setZ( RefDirection.x() * Axis.y() - RefDirection.y() * Axis.x() );
norm = RefDirection.cross(Axis);
}
// const G4Point3D& tmp = pplace.GetSrfPoint();
const G4Point3D tmp = pplace.GetLocation();
*/
// L. Broglia
// The direction of the normal is the axis of his location
// Its sense depend on the orientation of the bounded curve
const G4Point3D tmp = pplace.GetLocation();
G4Vector3D norm;
G4int sense = GetSameSense();
if (sense)
norm = pplace.GetAxis();
else
norm = - pplace.GetAxis();
NormalX = new G4Ray(tmp, norm);
NormalX->RayCheck();
NormalX->CreatePlanes();
}
void G4FPlane::Project()
{
// Project
const G4Plane& Plane1 = NormalX->GetPlane(1);
const G4Plane& Plane2 = NormalX->GetPlane(2);
// probably not necessary
// projections of the boundary should be handled by the intersection
// OuterBoundary->ProjectBoundaryTo2D(Plane1, Plane2, 0);
}
int G4FPlane::IsConvex()
{
return -1;
}
int G4FPlane::Intersect(const G4Ray& rayref)
{
Intersected =1;
// closest_hit = pplace.EvaluateIntersection(rayref);
// L. Broglia : before in G4Placement
// s is solution, line is p + tq, n is G4Plane Normal, r is point on G4Plane
// all parameters are pointers to arrays of three elements
hitpoint = PINFINITY;
register G4double a, b, t;
register const G4Vector3D& RayDir = rayref.GetDir();
register const G4Point3D& RayStart = rayref.GetStart();
G4double dirx = RayDir.x();
G4double diry = RayDir.y();
G4double dirz = RayDir.z();
G4Vector3D norm = (*NormalX).GetDir();
G4Point3D srf_point = pplace.GetLocation();
b = norm.x() * dirx + norm.y() * diry + norm.z() * dirz;
if ( fabs(b) < 0.001 )
{
// G4cout << "\nLine is parallel to G4Plane.No Hit.";
}
else
{
G4double startx = RayStart.x();
G4double starty = RayStart.y();
G4double startz = RayStart.z();
a = norm.x() * (srf_point.x() - startx) +
norm.y() * (srf_point.y() - starty) +
norm.z() * (srf_point.z() - startz) ;
t = a/b;
// substitute t into line equation
// to calculate final solution
G4double solx,soly,solz;
solx = startx + t * dirx;
soly = starty + t * diry;
solz = startz + t * dirz;
if(((dirx < 0 && solx < startx)||(dirx >= 0 && solx >= startx))&&
((diry < 0 && soly < starty)||(diry >= 0 && soly >= starty))&&
((dirz < 0 && solz < startz)||(dirz >= 0 && solz >= startz)))
hitpoint= G4Point3D(solx,soly, solz);
}
// closest_hit is a public Point3D in G4Surface
closest_hit = hitpoint;
if(closest_hit.x() == kInfinity)
{
active=0;
Distance(kInfinity);
return 0;
}
else
{
Distance( RayStart.distance2(closest_hit) );
if(distance < kCarTolerance*0.5)
{
// the point is on the surface
active=1; //active=0;
Distance(0); //Distance(kInfinity);
return 1; //return 0;
}
G4Point3D hit = closest_hit;
// project the hit to the xy plane,
// with the same projection that took the boundary
// into projectedBoundary
G4Point3D projectedHit= pplace.GetToPlacementCoordinates() * hit;
// test ray from the hit on the xy plane
// check if it intersects the boundary
G4Ray testRay(projectedHit, G4Vector3D(1, 0, 0));
G4CurveRayIntersection is;
projectedBoundary->IntersectRay2D(testRay, is);
// if not, we are outside
if ( is.GetDistance() >= kInfinity )
{
active=0;
Distance(kInfinity);
return 0;
}
// if yes, we have to check on which side of the intersected
// curve the hit lies
G4Vector3D tangent;
projectedBoundary->Tangent(is, tangent);
// L. Broglia
// Now replace tangent into the pplace
tangent = pplace.GetFromPlacementCoordinates() * tangent;
// (let's assume that the tangent is defined)
// criterion for outside: (d x t).z() < 0
// d = hit - is & t = tangent
G4Point3D Is = pplace.GetFromPlacementCoordinates() * (is.GetPoint());
G4Vector3D d = hit - Is;
if ( (d.cross(tangent)).z() < 0 )
{
active=0;
Distance(kInfinity);
return 0;
}
// a real intersection point
return 1;
}
}
G4double G4FPlane::ClosestDistanceToPoint(const G4Point3D& Pt)
{
// Calculates signed distance of point Pt to G4Plane Pl
// Be careful, the equation of the plane is :
// ax + by + cz = d
return ( Pt.x()*Pl.a + Pt.y()*Pl.b + Pt.z()*Pl.c - Pl.d);
}
void G4FPlane::InitBounded()
{
// L. Broglia
projectedBoundary =
surfaceBoundary.Project( pplace.GetToPlacementCoordinates() );
}
G4double G4FPlane::HowNear( const G4Vector3D& x ) const
{
const G4Point3D Pt = x;
//G4double d = ClosestDistanceToPoint(Pt);
//return d;
return ( Pt.x()*Pl.a + Pt.y()*Pl.b + Pt.z()*Pl.c - Pl.d);
}