Import Geant4 0.1.0 source tree
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
// 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: BuildBoxWorld.hh,v 1.1 1999/01/08 16:31:32 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-00-01 $
|
||||
//
|
||||
#ifndef BUILDBOXWORLD_HH
|
||||
#define BUILDBOXWORLD_HH
|
||||
|
||||
#include "G4PVPlacement.hh"
|
||||
#include "G4LogicalVolume.hh"
|
||||
#include "G4Box.hh"
|
||||
#include "G4Material.hh"
|
||||
|
||||
G4VPhysicalVolume* BuildBoxWorld()
|
||||
{
|
||||
G4double z = 13.;
|
||||
G4double a = 26.98*g/mole;
|
||||
G4double density = 2.7*g/cm3;
|
||||
|
||||
G4Box *myWorldBox= new G4Box ("WBox",10000,10000,10000);
|
||||
G4Box *myTargetBox = new G4Box ("TBox",100,200,400);
|
||||
|
||||
G4LogicalVolume *myWorldLog=new G4LogicalVolume(myWorldBox,0,
|
||||
"WLog",0,0,0);
|
||||
G4LogicalVolume *myTargetLog=new G4LogicalVolume(myTargetBox,0,
|
||||
"YLog",0,0,0);
|
||||
G4PVPlacement *myWorldPhys=new G4PVPlacement(0,G4ThreeVector(),
|
||||
"WPhys",
|
||||
myWorldLog,
|
||||
0,false,0);
|
||||
G4PVPlacement *myTargetPhys=new G4PVPlacement(0,G4ThreeVector(),
|
||||
"TPhys",
|
||||
myTargetLog,
|
||||
myWorldPhys,false,0);
|
||||
|
||||
return myWorldPhys;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,91 @@
|
||||
// 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: BuildCalorimeter.hh,v 1.1 1999/01/08 16:31:32 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-00-01 $
|
||||
//
|
||||
#ifndef BUILDCALORIMETER_HH
|
||||
#define BUILDCALORIMETER_HH
|
||||
|
||||
#include "G4PVPlacement.hh"
|
||||
#include "G4LogicalVolume.hh"
|
||||
#include "G4Box.hh"
|
||||
#include "G4Tubs.hh"
|
||||
|
||||
G4VPhysicalVolume* BuildCalorimeter()
|
||||
{
|
||||
G4double offset=22.5,xTlate,yTlate;
|
||||
G4int i,j,copyNo;
|
||||
G4double z = 13.;
|
||||
G4double a = 26.98*g/mole;
|
||||
G4double density = 2.7*g/cm3;
|
||||
|
||||
G4Box *myWorldBox= new G4Box ("WBox",10000,10000,10000);
|
||||
G4Box *myCalBox = new G4Box ("CBox",1500,1500,1000);
|
||||
G4Tubs *myTargetTube = new G4Tubs ("TTube",0,22.5,1000,0,360);
|
||||
|
||||
G4LogicalVolume *myWorldLog=new G4LogicalVolume(myWorldBox,0,
|
||||
"WLog",0,0,0);
|
||||
G4LogicalVolume *myCalLog=new G4LogicalVolume(myCalBox,0,
|
||||
"CLog",0,0,0);
|
||||
G4LogicalVolume *myTargetLog=new G4LogicalVolume(myTargetTube,0,
|
||||
"TLog",0,0,0);
|
||||
|
||||
G4PVPlacement *myWorldPhys=new G4PVPlacement(0,G4ThreeVector(),
|
||||
"WPhys",
|
||||
myWorldLog,
|
||||
0,false,0);
|
||||
G4PVPlacement *myCalPhys=new G4PVPlacement(0,G4ThreeVector(),
|
||||
"CalPhys",
|
||||
myCalLog,
|
||||
myWorldPhys,false,0);
|
||||
|
||||
G4String tName1("TPhys1"); // Allow all target physicals to share
|
||||
// same name (delayed copy)
|
||||
copyNo=0;
|
||||
for (j=1;j<=25;j++)
|
||||
{
|
||||
yTlate=-1000.0-40.0+j*80.0;
|
||||
|
||||
for (i=1;i<=50;i++)
|
||||
{
|
||||
copyNo++;
|
||||
xTlate=-1000.0-20.0+i*45.0-offset;
|
||||
G4PVPlacement *myTargetPhys=new G4PVPlacement(0,G4ThreeVector(xTlate,yTlate,0),
|
||||
tName1,
|
||||
myTargetLog,
|
||||
myCalPhys,
|
||||
false,
|
||||
copyNo);
|
||||
}
|
||||
}
|
||||
|
||||
G4String tName2("TPhys2"); // Allow all target physicals to share
|
||||
// same name (delayed copy)
|
||||
copyNo=0;
|
||||
for (j=1;j<=26;j++)
|
||||
{
|
||||
yTlate=-1000.0-80.0+j*80.0;
|
||||
for (i=1;i<=50;i++)
|
||||
{
|
||||
copyNo++;
|
||||
xTlate=-1000.0-20.0+i*45.0;
|
||||
G4PVPlacement *myTargetPhys=new G4PVPlacement(0,G4ThreeVector(xTlate,yTlate,0),
|
||||
tName2,
|
||||
myTargetLog,
|
||||
myCalPhys,
|
||||
false,
|
||||
copyNo);
|
||||
}
|
||||
}
|
||||
|
||||
return myWorldPhys;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
# $Id: GNUmakefile,v 1.1 1999/01/08 16:31:32 gunter Exp $
|
||||
# ----------------------------------------------------------------
|
||||
# Makes test program in environment variable G4TARGET.
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
ifndef G4TARGET
|
||||
G4TARGET := $(TESTTARGET)
|
||||
endif
|
||||
|
||||
ifndef G4INSTALL
|
||||
G4INSTALL = ../../..
|
||||
endif
|
||||
|
||||
G4EXEC_BUILD = true
|
||||
|
||||
include $(G4INSTALL)/config/architecture.gmk
|
||||
|
||||
# Override some variables for binmake.gmk.
|
||||
#
|
||||
INCFLAGS := -I$(G4BASE)/geometry/management/include \
|
||||
-I$(G4BASE)/geometry/volumes/include \
|
||||
-I$(G4BASE)/geometry/solids/CSG/include \
|
||||
-I$(G4BASE)/global/management/include \
|
||||
-I$(G4BASE)/global/HEPRandom/include \
|
||||
-I$(G4BASE)/global/HEPGeometry/include \
|
||||
-I$(G4BASE)/materials/include \
|
||||
-I$(G4BASE)/graphics_reps/include
|
||||
|
||||
LDLIBS := -lG4materials \
|
||||
-lG4geometry \
|
||||
-lG4global \
|
||||
-lG4graphics_reps
|
||||
|
||||
include $(G4INSTALL)/config/binmake.gmk
|
||||
@@ -0,0 +1,84 @@
|
||||
// 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: Shoot.hh,v 1.1 1999/01/08 16:31:32 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-00-01 $
|
||||
//
|
||||
#ifndef SHOOT_HH
|
||||
#define SHOOT_HH
|
||||
|
||||
#include "G4VPhysicalVolume.hh"
|
||||
#include "G4Navigator.hh"
|
||||
#include "G4ThreeVector.hh"
|
||||
#include "G4Timer.hh"
|
||||
#include "G4ios.hh"
|
||||
|
||||
void Shoot(const G4int numShoot,
|
||||
G4VPhysicalVolume *pTopNode,
|
||||
const G4ThreeVector& pSource,
|
||||
const G4ThreeVector& pVec)
|
||||
{
|
||||
const G4double physStep=kInfinity;
|
||||
G4int i;
|
||||
G4double safety,Step;
|
||||
G4Navigator myNav;
|
||||
G4Timer timer;
|
||||
G4ThreeVector partLoc;
|
||||
G4VPhysicalVolume *located;
|
||||
|
||||
myNav.SetWorldVolume(pTopNode);
|
||||
|
||||
timer.Start();
|
||||
|
||||
for (i=numShoot;i>0;i--)
|
||||
{
|
||||
|
||||
partLoc=pSource;
|
||||
located=myNav.LocateGlobalPointAndSetup(partLoc,false);
|
||||
while (located)
|
||||
{
|
||||
Step=myNav.ComputeStep(partLoc,pVec,physStep,safety);
|
||||
partLoc+=Step*pVec;
|
||||
myNav.SetGeometricallyLimitedStep();
|
||||
located=myNav.LocateGlobalPointAndSetup(partLoc);
|
||||
};
|
||||
}
|
||||
timer.Stop();
|
||||
G4cout << "Shots = " << numShoot << " " << timer << endl;
|
||||
}
|
||||
|
||||
void ShootVerbose(G4VPhysicalVolume *pTopNode,
|
||||
const G4ThreeVector& pSource,
|
||||
const G4ThreeVector& pVec)
|
||||
{
|
||||
const G4double physStep=kInfinity;
|
||||
G4double safety,Step;
|
||||
G4Navigator myNav;
|
||||
G4ThreeVector partLoc;
|
||||
G4VPhysicalVolume *located;
|
||||
|
||||
myNav.SetWorldVolume(pTopNode);
|
||||
|
||||
partLoc=pSource;
|
||||
// located=myNav.LocateGlobalPointAndSetup(partLoc,false);
|
||||
located=myNav.LocateGlobalPointAndSetup(partLoc,true);
|
||||
while (located)
|
||||
{
|
||||
Step=myNav.ComputeStep(partLoc,pVec,physStep,safety);
|
||||
G4cout << "Physical Location=" << located->GetName()
|
||||
<< " #" << located->GetCopyNo() << endl
|
||||
<< " Step=" << Step << " Safety=" << safety
|
||||
<< " ---->" << endl;
|
||||
|
||||
partLoc+=Step*pVec;
|
||||
myNav.SetGeometricallyLimitedStep();
|
||||
located=myNav.LocateGlobalPointAndSetup(partLoc);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,102 @@
|
||||
// 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: calorimeter.cc,v 1.1 1999/01/08 16:31:32 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-00-01 $
|
||||
//
|
||||
// calorimeter
|
||||
//
|
||||
// World consisting of CSoC '95 tube calorimeter
|
||||
// For comparison against F77 case. Toggle optimisation with 0/1
|
||||
// on command line. Default - optimisation ON
|
||||
|
||||
#include "G4ios.hh"
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "G4GeometryManager.hh"
|
||||
#include "BuildCalorimeter.hh"
|
||||
#include "Shoot.hh"
|
||||
#include "G4Timer.hh"
|
||||
#include "globals.hh"
|
||||
#include "geomdefs.hh"
|
||||
|
||||
const G4int numShoot = 10000;
|
||||
const G4bool optimise= true;
|
||||
|
||||
int main()
|
||||
{
|
||||
G4ThreeVector origin(0,0,0),pMX(-500,0,0);
|
||||
G4ThreeVector vx(1,0,0);
|
||||
G4ThreeVector vy(0,1,0);
|
||||
G4ThreeVector vxy(1/sqrt(2.0),1/sqrt(2.0),0);
|
||||
G4VPhysicalVolume *myTopNode;
|
||||
G4Timer timer;
|
||||
|
||||
G4cout << " Calorimeter Performance Test - P.Kent 21.08.95" << endl
|
||||
<< "Using calorimeter from CERN School of Computing '95" << endl;
|
||||
#ifndef NDEBUG
|
||||
G4cout << "WARNING: *** ASSERTs are compiled IN ***" << endl;
|
||||
#endif
|
||||
|
||||
myTopNode=BuildCalorimeter(); // Build the geometry
|
||||
timer.Start();
|
||||
G4GeometryManager::GetInstance()->CloseGeometry(optimise);
|
||||
timer.Stop();
|
||||
|
||||
if (optimise)
|
||||
{
|
||||
G4cout << "Optimisation ON";
|
||||
}
|
||||
else
|
||||
{
|
||||
G4cout << "Optimisation OFF";
|
||||
}
|
||||
G4cout << " Geometry close took " << timer << endl;
|
||||
|
||||
#ifdef G4GEOMETRY_VERBOSE
|
||||
G4cout << endl << "Voxels for:"
|
||||
<< G4LogicalVolumeStore::GetInstance()->at(1)->GetName() << endl
|
||||
<< *G4LogicalVolumeStore::GetInstance()->at(1)->GetVoxelHeader()
|
||||
<< endl;
|
||||
#endif
|
||||
G4SmartVoxelHeader* top=G4LogicalVolumeStore::GetInstance()
|
||||
->at(1)->GetVoxelHeader();
|
||||
if (top)
|
||||
{
|
||||
G4cout << "1st level voxels along ";
|
||||
switch (top->GetAxis())
|
||||
{
|
||||
case kXAxis:
|
||||
G4cout << "X" << endl;
|
||||
break;
|
||||
case kYAxis:
|
||||
G4cout << "Y" << endl;
|
||||
break;
|
||||
case kZAxis:
|
||||
G4cout << "Z" << endl;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
G4cout << endl << "Shooting from " << origin << " along " << vx << endl;
|
||||
ShootVerbose(myTopNode,origin,vx);
|
||||
Shoot(numShoot,myTopNode,origin,vx);
|
||||
|
||||
G4cout << endl << "Shooting from " << origin << " along " << vy << endl;
|
||||
ShootVerbose(myTopNode,origin,vy);
|
||||
Shoot(numShoot,myTopNode,origin,vy);
|
||||
|
||||
G4cout << endl << "Shooting from " << origin << " along " << vxy << endl;
|
||||
ShootVerbose(myTopNode,origin,vxy);
|
||||
Shoot(numShoot,myTopNode,origin,vxy);
|
||||
|
||||
G4GeometryManager::GetInstance()->OpenGeometry();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,439 @@
|
||||
// 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: G4Box.cc,v 1.1 1999/01/08 16:31:33 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-00-01 $
|
||||
//
|
||||
//
|
||||
// Implementation for G4Box class
|
||||
//
|
||||
|
||||
#include "G4Box.hh"
|
||||
|
||||
//#include "G4VoxelLimits.hh"
|
||||
//#include "G4Transform.hh"
|
||||
|
||||
//#ifdef G4VISUALIZE
|
||||
//#include "G4VWindow.hh"
|
||||
//#include "G4Polyline.hh"
|
||||
//#endif
|
||||
|
||||
#include <math.h>
|
||||
// Private (implementation) enum: Not for external use
|
||||
// Codes for faces (kPX=plus x face,kMY= minus y face etc)
|
||||
enum ESide {kPX,kMX,kPY,kMY,kPZ,kMZ};
|
||||
|
||||
// Constructor - check & set half widths
|
||||
G4Box::G4Box(const G4double pX,
|
||||
const G4double pY,
|
||||
const G4double pZ)
|
||||
{
|
||||
fDx=pX; fDy=pY; fDz=pZ;
|
||||
}
|
||||
|
||||
|
||||
// Return whether point inside/outside/on surface, using tolerance
|
||||
EInside G4Box::Inside(const G4ThreeVector& p) const
|
||||
{
|
||||
EInside in=kOutside;
|
||||
|
||||
if (fabs(p.x())<=fDx-kCarTolerance*0.5)
|
||||
{
|
||||
if (fabs(p.y())<=fDy-kCarTolerance*0.5)
|
||||
{
|
||||
if (fabs(p.z())<=fDz-kCarTolerance*0.5)
|
||||
{
|
||||
in=kInside;
|
||||
}
|
||||
else if (fabs(p.z())<=fDz+kCarTolerance*0.5)
|
||||
{
|
||||
in=kSurface;
|
||||
}
|
||||
}
|
||||
else if (fabs(p.y())<=fDy+kCarTolerance*0.5)
|
||||
{
|
||||
if (fabs(p.z())<=fDz+kCarTolerance*0.5)
|
||||
{
|
||||
in=kSurface;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (fabs(p.x())<=fDx+kCarTolerance*0.5)
|
||||
{
|
||||
if (fabs(p.y())<=fDy+kCarTolerance*0.5)
|
||||
{
|
||||
if (fabs(p.z())<=fDz+kCarTolerance*0.5)
|
||||
{
|
||||
in=kSurface;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
// Calculate side nearest to p, and return normal
|
||||
// If two sides are equidistant, normal of first side (x/y/z)
|
||||
// encountered returned
|
||||
G4ThreeVector G4Box::SurfaceNormal( const G4ThreeVector& p) const
|
||||
{
|
||||
G4double distx,disty,distz;
|
||||
G4ThreeVector norm;
|
||||
// Calculate distances as if in 1st octant
|
||||
distx=fabs(fabs(p.x())-fDx);
|
||||
disty=fabs(fabs(p.y())-fDy);
|
||||
distz=fabs(fabs(p.z())-fDz);
|
||||
|
||||
if (distx<=disty)
|
||||
{
|
||||
if (distx<=distz)
|
||||
{
|
||||
// Closest to X
|
||||
if (p.x()<0) norm=G4ThreeVector(-1.0,0,0);
|
||||
else norm=G4ThreeVector(1.0,0,0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Closest to Z
|
||||
if (p.z()<0) norm=G4ThreeVector(0,0,-1.0);
|
||||
else norm=G4ThreeVector(0,0,1.0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (disty<=distz)
|
||||
{
|
||||
// Closest to Y
|
||||
if (p.y()<0) norm=G4ThreeVector(0,-1.0,0);
|
||||
else norm=G4ThreeVector(0,1.0,0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Closest to Z
|
||||
if (p.z()<0) norm=G4ThreeVector(0,0,-1.0);
|
||||
else norm=G4ThreeVector(0,0,1.0);
|
||||
}
|
||||
}
|
||||
|
||||
return norm;
|
||||
}
|
||||
|
||||
// Calculate distance to box from an outside point
|
||||
// - return kInfinity if no intersection.
|
||||
//
|
||||
// ALGORITHM:
|
||||
//
|
||||
// Check that if point lies outside x/y/z extent of box, travel is towards
|
||||
// the box (ie. there is a possiblity of an intersection)
|
||||
//
|
||||
// Calculate pairs of minimum and maximum distances for x/y/z travel for
|
||||
// intersection with the box's x/y/z extent.
|
||||
// If there is a valid intersection, it is given by the maximum min distance
|
||||
// (ie. distance to satisfy x/y/z intersections) *if* <= minimum max distance
|
||||
// (ie. distance after which 1+ of x/y/z intersections not satisfied)
|
||||
//
|
||||
// NOTE:
|
||||
//
|
||||
// `Inside' safe - meaningful answers given if point is inside the exact
|
||||
// shape.
|
||||
|
||||
G4double G4Box::DistanceToIn(const G4ThreeVector& p,const G4ThreeVector& v) const
|
||||
{
|
||||
G4double safx,safy,safz;
|
||||
G4double smin,sminy,sminz;
|
||||
G4double smax,smaxy,smaxz;
|
||||
G4double stmp;
|
||||
|
||||
safx=fabs(p.x())-fDx; // minimum distance to x surface of shape
|
||||
safy=fabs(p.y())-fDy;
|
||||
safz=fabs(p.z())-fDz;
|
||||
|
||||
// Will we intersect?
|
||||
// If safx/y/z is >-tol/2 the point is outside/on the box's x/y/z extent.
|
||||
// If both p.x/y/z and v.x/y/z repectively are both positive/negative,
|
||||
// travel is in a direction away from the shape.
|
||||
|
||||
if ( ((p.x()*v.x()>=0.0) && safx>-kCarTolerance*0.5)
|
||||
|| ((p.y()*v.y()>=0.0) && safy>-kCarTolerance*0.5)
|
||||
|| ((p.z()*v.z()>=0.0) && safz>-kCarTolerance*0.5)) return kInfinity;
|
||||
|
||||
// Compute min / max distances for x/y/z travel:
|
||||
// X Planes
|
||||
if (v.x())
|
||||
{
|
||||
stmp=1.0/fabs(v.x());
|
||||
smin=safx*stmp;
|
||||
smax=(fDx+fabs(p.x()))*stmp;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (safx<=0.0)
|
||||
{
|
||||
smin=0.0;
|
||||
smax=kInfinity;
|
||||
}
|
||||
else
|
||||
{
|
||||
return kInfinity; // Travel parallel
|
||||
}
|
||||
}
|
||||
|
||||
// Y Planes
|
||||
if (v.y())
|
||||
{
|
||||
stmp=1.0/fabs(v.y());
|
||||
sminy=safy*stmp;
|
||||
smaxy=(fDy+fabs(p.y()))*stmp;
|
||||
if (sminy>smin) smin=sminy;
|
||||
if (smaxy<smax) smax=smaxy;
|
||||
if (smin>smax) return kInfinity;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (safy>0.0)
|
||||
{
|
||||
return kInfinity; // Travel parallel
|
||||
}
|
||||
}
|
||||
|
||||
// Z planes
|
||||
if (v.z())
|
||||
{
|
||||
stmp=1.0/fabs(v.z());
|
||||
sminz=safz*stmp;
|
||||
smaxz=(fDz+fabs(p.z()))*stmp;
|
||||
if (sminz>smin) smin=sminz;
|
||||
if (smaxz<smax) smax=smaxz;
|
||||
if (smin>smax) return kInfinity;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (safz>0.0)
|
||||
{
|
||||
return kInfinity; // Travel parallel
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (smin<0)
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
return smin;
|
||||
}
|
||||
|
||||
// Appoximate distance to box.
|
||||
// Returns largest perpendicular distance to the closest x/y/z sides of
|
||||
// the box.
|
||||
// - If inside return 0
|
||||
G4double G4Box::DistanceToIn(const G4ThreeVector& p) const
|
||||
{
|
||||
G4double safex,safey,safez,safe=0.0;
|
||||
safex=fabs(p.x())-fDx;
|
||||
safey=fabs(p.y())-fDy;
|
||||
safez=fabs(p.z())-fDz;
|
||||
|
||||
if (safex>safe) safe=safex;
|
||||
if (safey>safe) safe=safey;
|
||||
if (safez>safe) safe=safez;
|
||||
return safe;
|
||||
}
|
||||
|
||||
// Calcluate distance to surface of box from inside
|
||||
// by calculating distances to box's x/y/z planes.
|
||||
// Smallest distance is exact distance to exiting.
|
||||
// - Eliminate one side of each pair by considering direction of v
|
||||
// - when leaving a surface & v.close, return 0
|
||||
G4double G4Box::DistanceToOut(const G4ThreeVector& p,const G4ThreeVector& v,
|
||||
const G4bool calcNorm,
|
||||
G4bool *validNorm,G4ThreeVector *n) const
|
||||
{
|
||||
ESide side;
|
||||
G4double pdist,stmp,snxt;
|
||||
|
||||
if (calcNorm) *validNorm=true; // All normals are valid
|
||||
|
||||
if (v.x()>0)
|
||||
{
|
||||
pdist=fDx-p.x();
|
||||
if (pdist>kCarTolerance*0.5)
|
||||
{
|
||||
snxt=pdist/v.x();
|
||||
side=kPX;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (calcNorm)
|
||||
{
|
||||
*n=G4ThreeVector(1,0,0);
|
||||
}
|
||||
return snxt=0;
|
||||
}
|
||||
}
|
||||
else if (v.x()<0)
|
||||
{
|
||||
pdist=fDx+p.x();
|
||||
if (pdist>kCarTolerance*0.5)
|
||||
{
|
||||
snxt=-pdist/v.x();
|
||||
side=kMX;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (calcNorm)
|
||||
{
|
||||
*n=G4ThreeVector(-1,0,0);
|
||||
}
|
||||
return snxt=0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
snxt=kInfinity;
|
||||
}
|
||||
|
||||
if (v.y()>0)
|
||||
{
|
||||
pdist=fDy-p.y();
|
||||
if (pdist>kCarTolerance*0.5)
|
||||
{
|
||||
stmp=pdist/v.y();
|
||||
if (stmp<snxt)
|
||||
{
|
||||
snxt=stmp;
|
||||
side=kPY;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (calcNorm)
|
||||
{
|
||||
*n=G4ThreeVector(0,1,0);
|
||||
}
|
||||
return snxt=0;
|
||||
}
|
||||
}
|
||||
else if (v.y()<0)
|
||||
{
|
||||
pdist=fDy+p.y();
|
||||
if (pdist>kCarTolerance*0.5)
|
||||
{
|
||||
stmp=-pdist/v.y();
|
||||
if (stmp<snxt)
|
||||
{
|
||||
snxt=stmp;
|
||||
side=kMY;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (calcNorm)
|
||||
{
|
||||
*n=G4ThreeVector(0,-1,0);
|
||||
}
|
||||
return snxt=0;
|
||||
}
|
||||
}
|
||||
|
||||
if (v.z()>0)
|
||||
{
|
||||
pdist=fDz-p.z();
|
||||
if (pdist>kCarTolerance*0.5)
|
||||
{
|
||||
stmp=pdist/v.z();
|
||||
if (stmp<snxt)
|
||||
{
|
||||
snxt=stmp;
|
||||
side=kPZ;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (calcNorm)
|
||||
{
|
||||
*n=G4ThreeVector(0,0,1);
|
||||
}
|
||||
return snxt=0;
|
||||
}
|
||||
}
|
||||
else if (v.z()<0)
|
||||
{
|
||||
pdist=fDz+p.z();
|
||||
if (pdist>kCarTolerance*0.5)
|
||||
{
|
||||
stmp=-pdist/v.z();
|
||||
if (stmp<snxt)
|
||||
{
|
||||
snxt=stmp;
|
||||
side=kMZ;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (calcNorm)
|
||||
{
|
||||
*n=G4ThreeVector(0,0,-1);
|
||||
}
|
||||
return snxt=0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (calcNorm)
|
||||
{
|
||||
|
||||
switch (side)
|
||||
{
|
||||
case kPX:
|
||||
*n=G4ThreeVector(1,0,0);
|
||||
break;
|
||||
case kMX:
|
||||
*n=G4ThreeVector(-1,0,0);
|
||||
break;
|
||||
case kPY:
|
||||
*n=G4ThreeVector(0,1,0);
|
||||
break;
|
||||
case kMY:
|
||||
*n=G4ThreeVector(0,-1,0);
|
||||
break;
|
||||
case kPZ:
|
||||
*n=G4ThreeVector(0,0,1);
|
||||
break;
|
||||
case kMZ:
|
||||
*n=G4ThreeVector(0,0,-1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return snxt;
|
||||
}
|
||||
|
||||
// Calculate exact shortest distance to any boundary from inside
|
||||
// - If outside return 0
|
||||
G4double G4Box::DistanceToOut(const G4ThreeVector& p) const
|
||||
{
|
||||
G4double safx1,safx2,safy1,safy2,safz1,safz2,safe;
|
||||
|
||||
safx1=fDx-p.x();
|
||||
safx2=fDx+p.x();
|
||||
safy1=fDy-p.y();
|
||||
safy2=fDy+p.y();
|
||||
safz1=fDz-p.z();
|
||||
safz2=fDz+p.z();
|
||||
|
||||
// shortest Dist to any boundary now MIN(safx1,safx2,safy1..)
|
||||
if (safx2<safx1) safe=safx2;
|
||||
else safe=safx1;
|
||||
if (safy1<safe) safe=safy1;
|
||||
if (safy2<safe) safe=safy2;
|
||||
if (safz1<safe) safe=safz1;
|
||||
if (safz2<safe) safe=safz2;
|
||||
|
||||
if (safe<0) safe=0;
|
||||
return safe;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
// 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: G4Box.hh,v 1.1 1999/01/08 16:31:33 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-00-01 $
|
||||
//
|
||||
// class G4Box
|
||||
//
|
||||
// A Box is a cuboid of given half lengths dx,dy,dz. The Box is
|
||||
// centred on the origin with sides parallel to the x/y/z axes.
|
||||
//
|
||||
// Member functions:
|
||||
//
|
||||
// As inherited from G4VSolid +
|
||||
//
|
||||
// G4Box(const G4String& pName,const G4double pX,
|
||||
// const G4double pY,const G4double pZ)
|
||||
// Construct a box with name, and half lengths pX,pY,pZ
|
||||
//
|
||||
// G4double GetXHalfLength() const
|
||||
// G4double GetYHalfLength() const
|
||||
// G4double GetZHalfLength() const
|
||||
//
|
||||
// Return the respective parameter
|
||||
//
|
||||
// Protected:
|
||||
//
|
||||
// G4ThreeVectorList*
|
||||
// CreateRotatedVertices(const G4Transform& pTransform) const
|
||||
//
|
||||
// Create the List of transformed vertices in the format required
|
||||
// for G4VSolid:: ClipCrossSection and ClipBetweenSections.
|
||||
//
|
||||
// Member Data:
|
||||
//
|
||||
// fDx,fDy,fDz - The box's half-widths
|
||||
//
|
||||
// History:
|
||||
// 30.06.95 P.Kent Converted from source code developed end 94
|
||||
// 18.07.95 J.Allison Added virtual function Wireframe.
|
||||
// 31.07.95 J.Allison Added virtual function DispatchWireframe.
|
||||
|
||||
#ifndef G4BOX_HH
|
||||
#define G4BOX_HH
|
||||
|
||||
#include "G4ThreeVector.hh"
|
||||
|
||||
class G4Box
|
||||
{
|
||||
public:
|
||||
G4Box(const G4double pX,
|
||||
const G4double pY,const G4double pZ);
|
||||
|
||||
// Access functions
|
||||
G4double GetXHalfLength() const
|
||||
{
|
||||
return fDx;
|
||||
}
|
||||
|
||||
G4double GetYHalfLength() const
|
||||
{
|
||||
return fDy;
|
||||
}
|
||||
|
||||
G4double GetZHalfLength() const
|
||||
{
|
||||
return fDz;
|
||||
}
|
||||
|
||||
EInside Inside(const G4ThreeVector& p) const;
|
||||
|
||||
G4ThreeVector SurfaceNormal( const G4ThreeVector& p) 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=false,
|
||||
G4bool *validNorm=0,G4ThreeVector *n=0) const;
|
||||
G4double DistanceToOut(const G4ThreeVector& p) const;
|
||||
|
||||
protected:
|
||||
G4double fDx,fDy,fDz;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,445 @@
|
||||
// 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: G4Box_fastfabs.cc,v 1.1 1999/01/08 16:31:33 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-00-01 $
|
||||
//
|
||||
//
|
||||
// Implementation for G4Box class
|
||||
//
|
||||
|
||||
#include "G4Box.hh"
|
||||
|
||||
//#include "G4VoxelLimits.hh"
|
||||
//#include "G4Transform.hh"
|
||||
|
||||
//#ifdef G4VISUALIZE
|
||||
//#include "G4VWindow.hh"
|
||||
//#include "G4Polyline.hh"
|
||||
//#endif
|
||||
|
||||
//#include <math.h>
|
||||
|
||||
inline G4double fastfabs(const G4double p)
|
||||
{
|
||||
return (p>=0) ? p : -p ;
|
||||
}
|
||||
|
||||
// Private (implementation) enum: Not for external use
|
||||
// Codes for faces (kPX=plus x face,kMY= minus y face etc)
|
||||
enum ESide {kPX,kMX,kPY,kMY,kPZ,kMZ};
|
||||
|
||||
// Constructor - check & set half widths
|
||||
G4Box::G4Box(const G4double pX,
|
||||
const G4double pY,
|
||||
const G4double pZ)
|
||||
{
|
||||
fDx=pX; fDy=pY; fDz=pZ;
|
||||
}
|
||||
|
||||
|
||||
// Return whether point inside/outside/on surface, using tolerance
|
||||
EInside G4Box::Inside(const G4ThreeVector& p) const
|
||||
{
|
||||
EInside in=kOutside;
|
||||
|
||||
if (fastfabs(p.x())<=fDx-kCarTolerance*0.5)
|
||||
{
|
||||
if (fastfabs(p.y())<=fDy-kCarTolerance*0.5)
|
||||
{
|
||||
if (fastfabs(p.z())<=fDz-kCarTolerance*0.5)
|
||||
{
|
||||
in=kInside;
|
||||
}
|
||||
else if (fastfabs(p.z())<=fDz+kCarTolerance*0.5)
|
||||
{
|
||||
in=kSurface;
|
||||
}
|
||||
}
|
||||
else if (fastfabs(p.y())<=fDy+kCarTolerance*0.5)
|
||||
{
|
||||
if (fastfabs(p.z())<=fDz+kCarTolerance*0.5)
|
||||
{
|
||||
in=kSurface;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (fastfabs(p.x())<=fDx+kCarTolerance*0.5)
|
||||
{
|
||||
if (fastfabs(p.y())<=fDy+kCarTolerance*0.5)
|
||||
{
|
||||
if (fastfabs(p.z())<=fDz+kCarTolerance*0.5)
|
||||
{
|
||||
in=kSurface;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
// Calculate side nearest to p, and return normal
|
||||
// If two sides are equidistant, normal of first side (x/y/z)
|
||||
// encountered returned
|
||||
G4ThreeVector G4Box::SurfaceNormal( const G4ThreeVector& p) const
|
||||
{
|
||||
G4double distx,disty,distz;
|
||||
G4ThreeVector norm;
|
||||
// Calculate distances as if in 1st octant
|
||||
distx=fastfabs(fastfabs(p.x())-fDx);
|
||||
disty=fastfabs(fastfabs(p.y())-fDy);
|
||||
distz=fastfabs(fastfabs(p.z())-fDz);
|
||||
|
||||
if (distx<=disty)
|
||||
{
|
||||
if (distx<=distz)
|
||||
{
|
||||
// Closest to X
|
||||
if (p.x()<0) norm=G4ThreeVector(-1.0,0,0);
|
||||
else norm=G4ThreeVector(1.0,0,0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Closest to Z
|
||||
if (p.z()<0) norm=G4ThreeVector(0,0,-1.0);
|
||||
else norm=G4ThreeVector(0,0,1.0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (disty<=distz)
|
||||
{
|
||||
// Closest to Y
|
||||
if (p.y()<0) norm=G4ThreeVector(0,-1.0,0);
|
||||
else norm=G4ThreeVector(0,1.0,0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Closest to Z
|
||||
if (p.z()<0) norm=G4ThreeVector(0,0,-1.0);
|
||||
else norm=G4ThreeVector(0,0,1.0);
|
||||
}
|
||||
}
|
||||
|
||||
return norm;
|
||||
}
|
||||
|
||||
// Calculate distance to box from an outside point
|
||||
// - return kInfinity if no intersection.
|
||||
//
|
||||
// ALGORITHM:
|
||||
//
|
||||
// Check that if point lies outside x/y/z extent of box, travel is towards
|
||||
// the box (ie. there is a possiblity of an intersection)
|
||||
//
|
||||
// Calculate pairs of minimum and maximum distances for x/y/z travel for
|
||||
// intersection with the box's x/y/z extent.
|
||||
// If there is a valid intersection, it is given by the maximum min distance
|
||||
// (ie. distance to satisfy x/y/z intersections) *if* <= minimum max distance
|
||||
// (ie. distance after which 1+ of x/y/z intersections not satisfied)
|
||||
//
|
||||
// NOTE:
|
||||
//
|
||||
// `Inside' safe - meaningful answers given if point is inside the exact
|
||||
// shape.
|
||||
|
||||
G4double G4Box::DistanceToIn(const G4ThreeVector& p,const G4ThreeVector& v) const
|
||||
{
|
||||
G4double safx,safy,safz;
|
||||
G4double smin,sminy,sminz;
|
||||
G4double smax,smaxy,smaxz;
|
||||
G4double stmp;
|
||||
|
||||
safx=fastfabs(p.x())-fDx; // minimum distance to x surface of shape
|
||||
safy=fastfabs(p.y())-fDy;
|
||||
safz=fastfabs(p.z())-fDz;
|
||||
|
||||
// Will we intersect?
|
||||
// If safx/y/z is >-tol/2 the point is outside/on the box's x/y/z extent.
|
||||
// If both p.x/y/z and v.x/y/z repectively are both positive/negative,
|
||||
// travel is in a direction away from the shape.
|
||||
|
||||
if ( ((p.x()*v.x()>=0.0) && safx>-kCarTolerance*0.5)
|
||||
|| ((p.y()*v.y()>=0.0) && safy>-kCarTolerance*0.5)
|
||||
|| ((p.z()*v.z()>=0.0) && safz>-kCarTolerance*0.5)) return kInfinity;
|
||||
|
||||
// Compute min / max distances for x/y/z travel:
|
||||
// X Planes
|
||||
if (v.x())
|
||||
{
|
||||
stmp=1.0/fastfabs(v.x());
|
||||
smin=safx*stmp;
|
||||
smax=(fDx+fastfabs(p.x()))*stmp;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (safx<=0.0)
|
||||
{
|
||||
smin=0.0;
|
||||
smax=kInfinity;
|
||||
}
|
||||
else
|
||||
{
|
||||
return kInfinity; // Travel parallel
|
||||
}
|
||||
}
|
||||
|
||||
// Y Planes
|
||||
if (v.y())
|
||||
{
|
||||
stmp=1.0/fastfabs(v.y());
|
||||
sminy=safy*stmp;
|
||||
smaxy=(fDy+fastfabs(p.y()))*stmp;
|
||||
if (sminy>smin) smin=sminy;
|
||||
if (smaxy<smax) smax=smaxy;
|
||||
if (smin>smax) return kInfinity;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (safy>0.0)
|
||||
{
|
||||
return kInfinity; // Travel parallel
|
||||
}
|
||||
}
|
||||
|
||||
// Z planes
|
||||
if (v.z())
|
||||
{
|
||||
stmp=1.0/fastfabs(v.z());
|
||||
sminz=safz*stmp;
|
||||
smaxz=(fDz+fastfabs(p.z()))*stmp;
|
||||
if (sminz>smin) smin=sminz;
|
||||
if (smaxz<smax) smax=smaxz;
|
||||
if (smin>smax) return kInfinity;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (safz>0.0)
|
||||
{
|
||||
return kInfinity; // Travel parallel
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (smin<0)
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
return smin;
|
||||
}
|
||||
|
||||
// Appoximate distance to box.
|
||||
// Returns largest perpendicular distance to the closest x/y/z sides of
|
||||
// the box.
|
||||
// - If inside return 0
|
||||
G4double G4Box::DistanceToIn(const G4ThreeVector& p) const
|
||||
{
|
||||
G4double safex,safey,safez,safe=0.0;
|
||||
safex=fastfabs(p.x())-fDx;
|
||||
safey=fastfabs(p.y())-fDy;
|
||||
safez=fastfabs(p.z())-fDz;
|
||||
|
||||
if (safex>safe) safe=safex;
|
||||
if (safey>safe) safe=safey;
|
||||
if (safez>safe) safe=safez;
|
||||
return safe;
|
||||
}
|
||||
|
||||
// Calcluate distance to surface of box from inside
|
||||
// by calculating distances to box's x/y/z planes.
|
||||
// Smallest distance is exact distance to exiting.
|
||||
// - Eliminate one side of each pair by considering direction of v
|
||||
// - when leaving a surface & v.close, return 0
|
||||
G4double G4Box::DistanceToOut(const G4ThreeVector& p,const G4ThreeVector& v,
|
||||
const G4bool calcNorm,
|
||||
G4bool *validNorm,G4ThreeVector *n) const
|
||||
{
|
||||
ESide side;
|
||||
G4double pdist,stmp,snxt;
|
||||
|
||||
if (calcNorm) *validNorm=true; // All normals are valid
|
||||
|
||||
if (v.x()>0)
|
||||
{
|
||||
pdist=fDx-p.x();
|
||||
if (pdist>kCarTolerance*0.5)
|
||||
{
|
||||
snxt=pdist/v.x();
|
||||
side=kPX;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (calcNorm)
|
||||
{
|
||||
*n=G4ThreeVector(1,0,0);
|
||||
}
|
||||
return snxt=0;
|
||||
}
|
||||
}
|
||||
else if (v.x()<0)
|
||||
{
|
||||
pdist=fDx+p.x();
|
||||
if (pdist>kCarTolerance*0.5)
|
||||
{
|
||||
snxt=-pdist/v.x();
|
||||
side=kMX;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (calcNorm)
|
||||
{
|
||||
*n=G4ThreeVector(-1,0,0);
|
||||
}
|
||||
return snxt=0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
snxt=kInfinity;
|
||||
}
|
||||
|
||||
if (v.y()>0)
|
||||
{
|
||||
pdist=fDy-p.y();
|
||||
if (pdist>kCarTolerance*0.5)
|
||||
{
|
||||
stmp=pdist/v.y();
|
||||
if (stmp<snxt)
|
||||
{
|
||||
snxt=stmp;
|
||||
side=kPY;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (calcNorm)
|
||||
{
|
||||
*n=G4ThreeVector(0,1,0);
|
||||
}
|
||||
return snxt=0;
|
||||
}
|
||||
}
|
||||
else if (v.y()<0)
|
||||
{
|
||||
pdist=fDy+p.y();
|
||||
if (pdist>kCarTolerance*0.5)
|
||||
{
|
||||
stmp=-pdist/v.y();
|
||||
if (stmp<snxt)
|
||||
{
|
||||
snxt=stmp;
|
||||
side=kMY;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (calcNorm)
|
||||
{
|
||||
*n=G4ThreeVector(0,-1,0);
|
||||
}
|
||||
return snxt=0;
|
||||
}
|
||||
}
|
||||
|
||||
if (v.z()>0)
|
||||
{
|
||||
pdist=fDz-p.z();
|
||||
if (pdist>kCarTolerance*0.5)
|
||||
{
|
||||
stmp=pdist/v.z();
|
||||
if (stmp<snxt)
|
||||
{
|
||||
snxt=stmp;
|
||||
side=kPZ;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (calcNorm)
|
||||
{
|
||||
*n=G4ThreeVector(0,0,1);
|
||||
}
|
||||
return snxt=0;
|
||||
}
|
||||
}
|
||||
else if (v.z()<0)
|
||||
{
|
||||
pdist=fDz+p.z();
|
||||
if (pdist>kCarTolerance*0.5)
|
||||
{
|
||||
stmp=-pdist/v.z();
|
||||
if (stmp<snxt)
|
||||
{
|
||||
snxt=stmp;
|
||||
side=kMZ;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (calcNorm)
|
||||
{
|
||||
*n=G4ThreeVector(0,0,-1);
|
||||
}
|
||||
return snxt=0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (calcNorm)
|
||||
{
|
||||
|
||||
switch (side)
|
||||
{
|
||||
case kPX:
|
||||
*n=G4ThreeVector(1,0,0);
|
||||
break;
|
||||
case kMX:
|
||||
*n=G4ThreeVector(-1,0,0);
|
||||
break;
|
||||
case kPY:
|
||||
*n=G4ThreeVector(0,1,0);
|
||||
break;
|
||||
case kMY:
|
||||
*n=G4ThreeVector(0,-1,0);
|
||||
break;
|
||||
case kPZ:
|
||||
*n=G4ThreeVector(0,0,1);
|
||||
break;
|
||||
case kMZ:
|
||||
*n=G4ThreeVector(0,0,-1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return snxt;
|
||||
}
|
||||
|
||||
// Calculate exact shortest distance to any boundary from inside
|
||||
// - If outside return 0
|
||||
G4double G4Box::DistanceToOut(const G4ThreeVector& p) const
|
||||
{
|
||||
G4double safx1,safx2,safy1,safy2,safz1,safz2,safe;
|
||||
|
||||
safx1=fDx-p.x();
|
||||
safx2=fDx+p.x();
|
||||
safy1=fDy-p.y();
|
||||
safy2=fDy+p.y();
|
||||
safz1=fDz-p.z();
|
||||
safz2=fDz+p.z();
|
||||
|
||||
// shortest Dist to any boundary now MIN(safx1,safx2,safy1..)
|
||||
if (safx2<safx1) safe=safx2;
|
||||
else safe=safx1;
|
||||
if (safy1<safe) safe=safy1;
|
||||
if (safy2<safe) safe=safy2;
|
||||
if (safz1<safe) safe=safz1;
|
||||
if (safz2<safe) safe=safz2;
|
||||
|
||||
if (safe<0) safe=0;
|
||||
return safe;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
// 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: G4RotationMatrix.hh,v 1.1 1999/01/08 16:31:34 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-00-01 $
|
||||
//
|
||||
//
|
||||
// Rotation Matrix class, converted from CLHEP:
|
||||
// Author: Leif Lonnblad
|
||||
|
||||
// History:
|
||||
// 30.11.94 P.Kent: Added phiX/thetaX (etc) + IsIdentity functions
|
||||
|
||||
#ifndef G4ROTATIONMATRIX_HH
|
||||
#define G4ROTATIONMATRIX_HH
|
||||
|
||||
#include "globals.hh"
|
||||
|
||||
//#include "G4ThreeVector.hh"
|
||||
class G4ThreeVector;
|
||||
|
||||
class G4RotationMatrix {
|
||||
|
||||
public:
|
||||
|
||||
// Default constructor. Gives a unit matrix.
|
||||
inline G4RotationMatrix()
|
||||
: xx(1.0), xy(0.0), xz(0.0),
|
||||
yx(0.0), yy(1.0), yz(0.0),
|
||||
zx(0.0), zy(0.0), zz(1.0)
|
||||
{;}
|
||||
|
||||
// Copy constructor.
|
||||
inline G4RotationMatrix(const G4RotationMatrix & m)
|
||||
: xx(m.xx), xy(m.xy), xz(m.xz),
|
||||
yx(m.yx), yy(m.yy), yz(m.yz),
|
||||
zx(m.zx), zy(m.zy), zz(m.zz)
|
||||
{;}
|
||||
|
||||
|
||||
inline G4RotationMatrix & operator = (const G4RotationMatrix & m);
|
||||
// Assignment.
|
||||
|
||||
inline G4bool operator == (const G4RotationMatrix &m) const;
|
||||
// Comparison
|
||||
|
||||
inline G4ThreeVector operator * (const G4ThreeVector &) const;
|
||||
// Multiplication with a d3Vector
|
||||
|
||||
G4RotationMatrix operator * (const G4RotationMatrix &) const;
|
||||
inline G4RotationMatrix & operator *= (const G4RotationMatrix &);
|
||||
inline G4RotationMatrix & transform(const G4RotationMatrix &);
|
||||
// Matrix multiplication.
|
||||
// Note a *= b; <=> a = a * b; while a.transform(b); <=> a = b * a;
|
||||
|
||||
inline G4RotationMatrix inverse() const;
|
||||
// Returns the inverse.
|
||||
|
||||
inline G4RotationMatrix & invert();
|
||||
// Inverts the Rotation matrix
|
||||
|
||||
G4RotationMatrix & rotateX(double);
|
||||
// Rotation around the x-axis.
|
||||
|
||||
G4RotationMatrix & rotateY(double);
|
||||
// Rotation around the y-axis.
|
||||
|
||||
G4RotationMatrix & rotateZ(double);
|
||||
// Rotation around the z-axis.
|
||||
|
||||
G4RotationMatrix & rotate(double angle, const G4ThreeVector & axis);
|
||||
inline G4RotationMatrix & rotate(double angle, const G4ThreeVector * axis);
|
||||
// Rotation around a specified vector.
|
||||
|
||||
// Function to return angles (RADS) made by rotated axes against original axes
|
||||
inline double phiX() const;
|
||||
inline double phiY() const;
|
||||
inline double phiZ() const;
|
||||
|
||||
inline double thetaX() const;
|
||||
inline double thetaY() const;
|
||||
inline double thetaZ() const;
|
||||
|
||||
inline G4bool isIdentity() const;
|
||||
// IsIdentity function returns true if identity matrix
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
inline G4RotationMatrix(double, double, double, double, double,
|
||||
double, double, double, double);
|
||||
// Protected constructor;.
|
||||
|
||||
G4double xx, xy, xz, yx, yy, yz, zx, zy, zz;
|
||||
// The matrix elements.
|
||||
|
||||
};
|
||||
|
||||
#include "G4ThreeVector.hh"
|
||||
|
||||
#include "G4RotationMatrix.icc"
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
// 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: G4RotationMatrix.icc,v 1.1 1999/01/08 16:31:34 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-00-01 $
|
||||
//
|
||||
// Inline functions for class G4RotationMatrix
|
||||
// Converted from CLHEP:
|
||||
// Author: Leif Lonnblad
|
||||
//
|
||||
// History:
|
||||
// 30.11.94 P.Kent
|
||||
|
||||
inline G4RotationMatrix & G4RotationMatrix::operator = (const G4RotationMatrix & m) {
|
||||
xx = m.xx;
|
||||
xy = m.xy;
|
||||
xz = m.xz;
|
||||
yx = m.yx;
|
||||
yy = m.yy;
|
||||
yz = m.yz;
|
||||
zx = m.zx;
|
||||
zy = m.zy;
|
||||
zz = m.zz;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline G4bool G4RotationMatrix::operator == (const G4RotationMatrix& m) const
|
||||
{
|
||||
return ( (xx == m.xx)
|
||||
&&(xy == m.xy)
|
||||
&&(xz == m.xz)
|
||||
&&(yx == m.yx)
|
||||
&&(yy == m.yy)
|
||||
&&(yz == m.yz)
|
||||
&&(zx == m.zx)
|
||||
&&(zy == m.zy)
|
||||
&&(zz == m.zz) ) ? true : false;
|
||||
}
|
||||
|
||||
inline G4ThreeVector G4RotationMatrix::operator * (const G4ThreeVector & p) const {
|
||||
return G4ThreeVector(xx*p.x() + xy*p.y() + xz*p.z(),
|
||||
yx*p.x() + yy*p.y() + yz*p.z(),
|
||||
zx*p.x() + zy*p.y() + zz*p.z());
|
||||
}
|
||||
|
||||
inline G4RotationMatrix & G4RotationMatrix::operator *= (const G4RotationMatrix & m) {
|
||||
return *this = operator * (m);
|
||||
}
|
||||
|
||||
inline G4RotationMatrix & G4RotationMatrix::transform(const G4RotationMatrix & m) {
|
||||
return *this = m.operator * (*this);
|
||||
}
|
||||
|
||||
inline G4RotationMatrix G4RotationMatrix::inverse() const {
|
||||
G4RotationMatrix m(xx, yx, zx, xy, yy, zy, xz, yz, zz);
|
||||
return m;
|
||||
}
|
||||
|
||||
inline G4RotationMatrix & G4RotationMatrix::invert() {
|
||||
return *this=inverse();
|
||||
}
|
||||
|
||||
inline G4RotationMatrix & G4RotationMatrix::rotate(double psi, const G4ThreeVector * p) {
|
||||
return rotate(psi, *p);
|
||||
}
|
||||
|
||||
inline G4RotationMatrix::G4RotationMatrix(double mxx, double mxy, double mxz,
|
||||
double myx, double myy, double myz,
|
||||
double mzx, double mzy, double mzz)
|
||||
: xx(mxx), xy(mxy), xz(mxz), yx(myx), yy(myy), yz(myz),
|
||||
zx(mzx), zy(mzy), zz(mzz) {}
|
||||
|
||||
inline double G4RotationMatrix::phiX() const
|
||||
{
|
||||
double radang;
|
||||
if (yx) radang=atan2(yx,xx);
|
||||
else radang=0.0;
|
||||
return radang;
|
||||
}
|
||||
|
||||
inline double G4RotationMatrix::phiY() const
|
||||
{
|
||||
double radang;
|
||||
if (yy) radang=atan2(yy,xy);
|
||||
else radang=0.0;
|
||||
return radang;
|
||||
}
|
||||
|
||||
inline double G4RotationMatrix::phiZ() const
|
||||
{
|
||||
double radang;
|
||||
if (yz) radang=atan2(yz,xz);
|
||||
else radang=0.0;
|
||||
return radang;
|
||||
}
|
||||
|
||||
inline double G4RotationMatrix::thetaX() const
|
||||
{
|
||||
// double zang=xz;
|
||||
// if (zang>=1.0) return 0;
|
||||
// else if (zang <=1.0) return 180.0;
|
||||
// else return acos(zang);
|
||||
return acos(xz);
|
||||
}
|
||||
inline double G4RotationMatrix::thetaY() const
|
||||
|
||||
{
|
||||
//Angs should always be <1.0 && >-1.0
|
||||
// double zang=yz;
|
||||
// if (zang>=1.0) return 0;
|
||||
// else if (zang <=1.0) return 180.0;
|
||||
// else return acos(zang);
|
||||
return acos(yz);
|
||||
}
|
||||
|
||||
inline double G4RotationMatrix::thetaZ() const
|
||||
{
|
||||
//Angs should always be <1.0 && >-1.0
|
||||
// double zang=zz;
|
||||
// if (zang>=1.0) return 0;
|
||||
// else if (zang <=1.0) return 180.0;
|
||||
// else return acos(zang);
|
||||
return acos(zz);
|
||||
}
|
||||
|
||||
// Return zero if identity, else non-zero
|
||||
// Does not use `fuzzy' check - must be exactly identity
|
||||
inline G4bool G4RotationMatrix::isIdentity() const
|
||||
{
|
||||
return (xx==1.0 && xy==0.0 && xz==0.0 &&
|
||||
yx==0.0 && yy==1.0 && yz==0.0 &&
|
||||
zx==0.0 && zy==0.0 && zz==1.0 ) ? true : false;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
// 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: G4ThreeVector.hh,v 1.1 1999/01/08 16:31:34 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-00-01 $
|
||||
//
|
||||
//
|
||||
// ThreeVector class, converted from CLHEP:
|
||||
// Authors: Leif Lonnblad and Anders Nilsson.
|
||||
//
|
||||
// History:
|
||||
// 30.06.95 P.Kent
|
||||
|
||||
#ifndef G4THREEVECTOR_HH
|
||||
#define G4THREEVECTOR_HH
|
||||
|
||||
#include "globals.hh"
|
||||
#include "geomdefs.hh"
|
||||
|
||||
class ostream;
|
||||
|
||||
class G4ThreeVector {
|
||||
|
||||
friend class G4RotationMatrix;
|
||||
|
||||
public:
|
||||
|
||||
// The Constructors
|
||||
inline G4ThreeVector(G4double x = 0.0, G4double y = 0.0, G4double z = 0.0)
|
||||
: dx(x), dy(y), dz(z)
|
||||
{;}
|
||||
|
||||
inline G4ThreeVector(const G4ThreeVector & p)
|
||||
: dx(p.dx), dy(p.dy), dz(p.dz)
|
||||
{;}
|
||||
|
||||
// the x, y and z components.
|
||||
inline G4double x() const
|
||||
{
|
||||
return dx;
|
||||
}
|
||||
|
||||
inline G4double y() const
|
||||
{
|
||||
return dy;
|
||||
}
|
||||
|
||||
inline G4double z() const
|
||||
{
|
||||
return dz;
|
||||
}
|
||||
|
||||
// Assignment.
|
||||
inline G4ThreeVector & operator = (const G4ThreeVector & p)
|
||||
{
|
||||
dx = p.x();
|
||||
dy = p.y();
|
||||
dz = p.z();
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline G4bool operator==(const G4ThreeVector& v) const;
|
||||
// Test for equality
|
||||
|
||||
inline G4ThreeVector & operator += (const G4ThreeVector &);
|
||||
// Addition.
|
||||
|
||||
inline G4ThreeVector & operator -= (const G4ThreeVector &);
|
||||
// Subtraction operator.
|
||||
|
||||
inline G4ThreeVector operator - () const;
|
||||
// Unary minus.
|
||||
|
||||
inline G4ThreeVector & operator *= (G4double);
|
||||
// Operators for scaling with real numbers.
|
||||
|
||||
inline G4double dot(const G4ThreeVector &) const;
|
||||
// Scalar product.
|
||||
|
||||
inline G4ThreeVector cross(const G4ThreeVector &) const;
|
||||
// Cross product.
|
||||
|
||||
inline G4double operator () (const EAxis) const;
|
||||
// Component access
|
||||
|
||||
|
||||
inline G4ThreeVector unit() const;
|
||||
// the unit vector parallel to this
|
||||
|
||||
inline G4double mag2() const;
|
||||
// the Magnitude squared.
|
||||
|
||||
inline G4double mag() const;
|
||||
// the magnutude.
|
||||
|
||||
inline G4double perp2() const;
|
||||
// The transverse component squared.
|
||||
|
||||
inline G4double perp() const;
|
||||
// The transverse component.
|
||||
|
||||
inline G4double perp2(const G4ThreeVector &) const;
|
||||
// The transverse component wrt. given axis squared.
|
||||
|
||||
inline G4double perp(const G4ThreeVector &) const;
|
||||
// The transverse component wrt. given axis.
|
||||
|
||||
inline G4double phi() const;
|
||||
// The azimuth angle.
|
||||
|
||||
inline G4double theta() const;
|
||||
// The polar angle.
|
||||
|
||||
inline G4double cosTheta() const;
|
||||
// Cosine of the polar angle.
|
||||
|
||||
inline G4double angle(const G4ThreeVector &) const;
|
||||
// The angle w.r.t. another 3-vector.
|
||||
|
||||
inline G4ThreeVector & operator *= (const G4RotationMatrix &);
|
||||
inline G4ThreeVector & transform(const G4RotationMatrix &);
|
||||
// Transformation with a Rotation matrix.
|
||||
|
||||
void rotateX(G4double);
|
||||
// Rotates the G4ThreeVector around the x-axis.
|
||||
|
||||
void rotateY(G4double);
|
||||
// Rotates the G4ThreeVector around the y-axis.
|
||||
|
||||
void rotateZ(G4double);
|
||||
// Rotates the G4ThreeVector around the z-axis.
|
||||
|
||||
void rotate(G4double, const G4ThreeVector &);
|
||||
// Rotates around the axis specified by another G4ThreeVector.
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
inline void setX(G4double);
|
||||
inline void setY(G4double);
|
||||
inline void setZ(G4double);
|
||||
// Set the x, y and z components.
|
||||
|
||||
private:
|
||||
|
||||
G4double dx, dy, dz;
|
||||
// The components.
|
||||
|
||||
};
|
||||
|
||||
ostream & operator << (ostream &, const G4ThreeVector &);
|
||||
// output to a stream
|
||||
|
||||
|
||||
#include "G4ThreeVector.icc"
|
||||
// Inline functions
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,177 @@
|
||||
// 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: G4ThreeVector.icc,v 1.1 1999/01/08 16:31:34 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-00-01 $
|
||||
//
|
||||
//
|
||||
// Inline functions for class G4ThreeVector
|
||||
// Converted from CLHEP:
|
||||
// Authors: Leif Lonnblad and Anders Nilsson.
|
||||
//
|
||||
// History:
|
||||
// 30.06.95 P.Kent
|
||||
|
||||
#include <math.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "G4RotationMatrix.hh"
|
||||
|
||||
inline G4bool G4ThreeVector::operator == (const G4ThreeVector& v) const
|
||||
{
|
||||
return (v.x()==x()&&v.y()==y()&&v.z()==z()) ? true : false;
|
||||
}
|
||||
|
||||
inline G4ThreeVector& G4ThreeVector::operator += (const G4ThreeVector & p) {
|
||||
dx += p.x();
|
||||
dy += p.y();
|
||||
dz += p.z();
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline G4ThreeVector& G4ThreeVector::operator -= (const G4ThreeVector & p) {
|
||||
dx -= p.x();
|
||||
dy -= p.y();
|
||||
dz -= p.z();
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline G4ThreeVector G4ThreeVector::operator - () const {
|
||||
G4ThreeVector q(-dx, -dy, -dz);
|
||||
return q;
|
||||
}
|
||||
|
||||
inline G4ThreeVector& G4ThreeVector::operator *= (G4double a) {
|
||||
dx *= a;
|
||||
dy *= a;
|
||||
dz *= a;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline G4ThreeVector & G4ThreeVector::operator *= (const G4RotationMatrix & m){
|
||||
*this = m * (*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline G4ThreeVector & G4ThreeVector::transform(const G4RotationMatrix & m) {
|
||||
*this = m * (*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline G4double G4ThreeVector::dot(const G4ThreeVector & p) const {
|
||||
return dx*p.x() + dy*p.y() + dz*p.z();
|
||||
}
|
||||
|
||||
inline G4ThreeVector G4ThreeVector::cross(const G4ThreeVector & p) const {
|
||||
G4ThreeVector q(dy*p.z() - p.y()*dz, dz*p.x() - p.z()*dx, dx*p.y() - p.x()*dy);
|
||||
return q;
|
||||
}
|
||||
|
||||
inline G4double G4ThreeVector::operator () (const EAxis p) const
|
||||
{
|
||||
if (p==kXAxis)
|
||||
{
|
||||
return dx;
|
||||
}
|
||||
else if (p==kYAxis)
|
||||
{
|
||||
return dy;
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(p==kZAxis);
|
||||
return dz;
|
||||
}
|
||||
}
|
||||
|
||||
inline G4double G4ThreeVector::mag2() const {
|
||||
return dx*dx + dy*dy + dz*dz;
|
||||
}
|
||||
|
||||
inline G4double G4ThreeVector::mag() const {
|
||||
return sqrt(mag2());
|
||||
}
|
||||
|
||||
inline G4ThreeVector G4ThreeVector::unit() const {
|
||||
G4double tot = dx*dx+dy*dy+dz*dz;
|
||||
G4ThreeVector p(*this);
|
||||
// If 0 Magnitude, return same vector (null)
|
||||
return tot >0.0 ? p*=(1.0/sqrt(tot)) : p;
|
||||
}
|
||||
|
||||
inline G4double G4ThreeVector::perp2() const {
|
||||
return dx*dx + dy*dy;
|
||||
}
|
||||
|
||||
inline G4double G4ThreeVector::perp() const {
|
||||
return sqrt(perp2());
|
||||
}
|
||||
|
||||
inline G4double G4ThreeVector::perp2(const G4ThreeVector & p) const {
|
||||
G4double tot = p.mag2();
|
||||
// return tot > 0.0 ? mag2()-sqr(dot(p))/tot : mag2();
|
||||
return tot > 0.0 ? mag2()-(dot(p))*(dot(p))/tot : mag2();
|
||||
}
|
||||
|
||||
inline G4double G4ThreeVector::perp(const G4ThreeVector & p) const {
|
||||
return sqrt(perp2(p));
|
||||
}
|
||||
|
||||
inline G4double G4ThreeVector::phi() const {
|
||||
return dx == 0.0 && dy == 0.0 ? 0.0 : atan2(dy,dx);
|
||||
}
|
||||
|
||||
inline G4double G4ThreeVector::theta() const {
|
||||
return dx == 0.0 && dy == 0.0 && dz == 0.0 ? 0.0 : atan2(perp(),dz);
|
||||
}
|
||||
|
||||
inline G4double G4ThreeVector::cosTheta() const {
|
||||
G4double ptot = mag();
|
||||
return ptot == 0.0 ? 1.0 : dz/ptot;
|
||||
}
|
||||
|
||||
inline G4double G4ThreeVector::angle(const G4ThreeVector & q) const {
|
||||
G4double ptot2 = mag2()*q.mag2();
|
||||
return ptot2 <= 0.0 ? 0.0 : acos(dot(q)/sqrt(ptot2));
|
||||
}
|
||||
|
||||
inline void G4ThreeVector::setX(G4double x) {
|
||||
dx = x;
|
||||
}
|
||||
|
||||
inline void G4ThreeVector::setY(G4double y) {
|
||||
dy = y;
|
||||
}
|
||||
|
||||
inline void G4ThreeVector::setZ(G4double z) {
|
||||
dz = z;
|
||||
}
|
||||
|
||||
inline G4ThreeVector operator + (const G4ThreeVector & a, const G4ThreeVector & b) {
|
||||
G4ThreeVector p(a.x() + b.x(), a.y() + b.y(), a.z() + b.z());
|
||||
return p;
|
||||
}
|
||||
|
||||
inline G4ThreeVector operator - (const G4ThreeVector & a, const G4ThreeVector & b) {
|
||||
G4ThreeVector p(a.x() - b.x(), a.y() - b.y(), a.z() - b.z());
|
||||
return p;
|
||||
}
|
||||
|
||||
inline G4ThreeVector operator * (const G4ThreeVector & p, G4double a) {
|
||||
G4ThreeVector q(a*p.x(), a*p.y(), a*p.z());
|
||||
return q;
|
||||
}
|
||||
|
||||
inline G4ThreeVector operator * (G4double a, const G4ThreeVector & p) {
|
||||
G4ThreeVector q(a*p.x(), a*p.y(), a*p.z());
|
||||
return q;
|
||||
}
|
||||
|
||||
inline G4double operator * (const G4ThreeVector & a, const G4ThreeVector & b) {
|
||||
return a.dot(b);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
#
|
||||
# Build stand-alone DistanceToIn tests for AIX
|
||||
#
|
||||
# boxtoinf77.aix - gnobox.f test
|
||||
# boxtoincpp.aix - DistanceToIn test [note: calls not virtual - modified
|
||||
# G4Box.hh/.cc]
|
||||
# boxtoincpp.aix_fastfabs - DistanceToIn test, with `custom' inline fabs
|
||||
# [actually slower than boxtoincpp.aix on SP2]
|
||||
|
||||
all: boxtoinf77.aix boxtoincpp.aix boxtoincpp.aix_fastfabs
|
||||
|
||||
boxtoinf77.aix: boxtoinf77.o gnobox.o
|
||||
xlf -O3 -o boxtoinf77.aix boxtoinf77.o gnobox.o
|
||||
|
||||
boxtoinf77.o: boxtoinf77.f
|
||||
xlf -c -O3 boxtoinf77.f
|
||||
|
||||
gnobox.o: gnobox.f
|
||||
xlf -c -O3 gnobox.f
|
||||
|
||||
boxtoincpp.aix: boxtoincpp.o G4Box.o
|
||||
xlC -+ -O3 -o boxtoincpp.aix boxtoincpp.o G4Box.o -lm
|
||||
|
||||
boxtoincpp.aix_fastfabs: boxtoincpp.o G4Box_fastfabs.o
|
||||
xlC -+ -O3 -o boxtoincpp.aix_fastfabs boxtoincpp.o G4Box_fastfabs.o -lm
|
||||
|
||||
boxtoincpp.o: boxtoincpp.cc
|
||||
xlC -+ -O3 -c boxtoincpp.cc
|
||||
|
||||
G4Box.o: G4Box.cc
|
||||
xlC -+ -O3 -c G4Box.cc
|
||||
|
||||
G4Box_fastfabs.o: G4Box_fastfabs.cc
|
||||
xlC -+ -O3 -c G4Box_fastfabs.cc
|
||||
|
||||
clean:
|
||||
rm -f *.o boxtoinf77.aix boxtoincpp.aix boxtoincpp.aix_fastfabs
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
#
|
||||
# Build stand-alone DistanceToIn tests for HP
|
||||
#
|
||||
# boxtoinf77.hp - gnobox.f test
|
||||
# boxtoincpp.hp - DistanceToIn test [note: calls not virtual - modified
|
||||
# G4Box.hh/.cc]
|
||||
# boxtoincpp.hp_fastfabs - DistanceToIn test, with `custom' inline fabs
|
||||
#
|
||||
|
||||
all: boxtoinf77.hp boxtoincpp.hp boxtoincpp.hp_fastfabs
|
||||
|
||||
boxtoinf77.hp: boxtoinf77.o gnobox.o
|
||||
f77 +O3 -o boxtoinf77.hp boxtoinf77.o gnobox.o
|
||||
|
||||
boxtoinf77.o: boxtoinf77.f
|
||||
f77 -c +O3 boxtoinf77.f
|
||||
|
||||
gnobox.o: gnobox.f
|
||||
f77 -c +O3 gnobox.f
|
||||
|
||||
boxtoincpp.hp: boxtoincpp.o G4Box.o
|
||||
CC +O3 -o boxtoincpp.hp boxtoincpp.o G4Box.o -Wl,-a,archive -DNDEBUG -lm
|
||||
boxtoincpp.hp_fastfabs: boxtoincpp.o G4Box_fastfabs.o
|
||||
CC +O3 -o boxtoincpp.hp_fastfabs boxtoincpp.o G4Box_fastfabs.o -Wl,-a,archive -DNDEBUG -lm
|
||||
|
||||
boxtoincpp.o: boxtoincpp.cc
|
||||
CC +O3 -c boxtoincpp.cc
|
||||
|
||||
G4Box.o: G4Box.cc
|
||||
CC +O3 -c G4Box.cc
|
||||
|
||||
G4Box_fastfabs.o: G4Box_fastfabs.cc
|
||||
CC +O3 -c G4Box_fastfabs.cc
|
||||
|
||||
clean:
|
||||
rm -f *.o boxtoinf77.hp boxtoincpp.hp boxtoincpp.hp_fastfabs
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
// 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: boxtoincpp.cc,v 1.1 1999/01/08 16:31:35 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-00-01 $
|
||||
//
|
||||
|
||||
#include "G4ios.hh"
|
||||
#include "G4Box.hh"
|
||||
#include "G4ThreeVector.hh"
|
||||
|
||||
const G4int norept=1000000;
|
||||
|
||||
void main()
|
||||
{
|
||||
G4int i;
|
||||
G4double snxt,total=0;
|
||||
G4ThreeVector endpt,startpt(-500,0,0),dir(1,0,0);
|
||||
|
||||
G4Box testbox(100,200,400);
|
||||
|
||||
for (i=1;i<=norept;i++)
|
||||
{
|
||||
snxt=testbox.DistanceToIn(startpt,dir);
|
||||
endpt=G4ThreeVector(startpt.x()+snxt*dir.x(),
|
||||
startpt.y()+snxt*dir.y(),
|
||||
startpt.z()+snxt*dir.z());
|
||||
total=total+endpt.x()+endpt.y()+endpt.z();
|
||||
}
|
||||
if ((!total)&&(!endpt.x())&&(!endpt.y())&&(!endpt.z()))
|
||||
{
|
||||
G4cout << "total=0";
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// 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: geomdefs.hh,v 1.1 1999/01/08 16:31:35 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-00-01 $
|
||||
//
|
||||
|
||||
// Constants, typedefs, enums for Geometry Section
|
||||
//
|
||||
// History:
|
||||
// 30.06.95 P.Kent
|
||||
|
||||
#ifndef GEOMDEFS_HH
|
||||
#define GEOMDEFS_HH
|
||||
|
||||
#include "globals.hh"
|
||||
|
||||
// `Infinity' - Distance returned for no intersection etc.
|
||||
const G4double kInfinity = 9E99;
|
||||
|
||||
// Thickness of shapes for Inside function / tracking.
|
||||
// Should be greater than largest math error from the shape
|
||||
// distance calculation routines.
|
||||
// Tolerance is centred on surface: Inside routine uses a
|
||||
// tolerance dx +/- kTol/2
|
||||
// Note: values not `tuned', and because of approximations kRadtolerance and
|
||||
// kAngTolerance may not always be used as an exact radius
|
||||
const G4double kCarTolerance = 1E-9;
|
||||
const G4double kRadTolerance = 1E-9;
|
||||
const G4double kAngTolerance = 1E-9;
|
||||
|
||||
// Define axes for function params etc.
|
||||
// X/Y/ZAxis = Normal Catesian axes
|
||||
// Radial2D = Radial axis in cylindrical polar
|
||||
// Radial3D = Radial axis in spherical polar
|
||||
enum EAxis {kXAxis,kYAxis,kZAxis,kRadial2D,kRadial3D};
|
||||
|
||||
// VShape::Inside routine return codes
|
||||
// kSurface => within tolerance of exact surface
|
||||
enum EInside {kOutside,kSurface,kInside};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
// 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: globals.hh,v 1.1 1999/01/08 16:31:35 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-00-01 $
|
||||
//
|
||||
|
||||
// Global Constants and typedefs
|
||||
//
|
||||
// History:
|
||||
// 30.06.95 P.Kent
|
||||
|
||||
#ifndef GLOBALS_HH
|
||||
#define GLOBALS_HH
|
||||
|
||||
// Typedefs for numeric types
|
||||
// [NOTE: Will in future need to be made more sophisticated]
|
||||
typedef double G4double;
|
||||
typedef float G4float;
|
||||
typedef long G4long;
|
||||
typedef int G4int;
|
||||
|
||||
// Typedefs to decouple from library classes
|
||||
//#include <rw/cstring.h>
|
||||
//typedef RWCString G4String;
|
||||
|
||||
// Boolean - define G4_HAVE_BOOL if bool type available
|
||||
#ifdef G4_HAVE_BOOL
|
||||
typedef bool G4bool;
|
||||
#else
|
||||
typedef int G4bool;
|
||||
const int false = 0;
|
||||
const int true = 1;
|
||||
//enum G4bool {false = 0, true = 1};
|
||||
#endif
|
||||
|
||||
// Global error function
|
||||
//void G4Exception(const char* s=0);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
// 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: replicaCal.cc,v 1.1 1999/01/08 16:31:32 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-00-01 $
|
||||
//
|
||||
//
|
||||
//
|
||||
// Replicated geometry performance test - ~calorimeter with end caps. Main
|
||||
// calorimeter block is replicated (divided) in r & z.
|
||||
// Toggle optimisation with 0/1 on command line. Default - optimisation ON
|
||||
|
||||
#include "G4ios.hh"
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "G4GeometryManager.hh"
|
||||
#include "Shoot.hh"
|
||||
#include "G4Timer.hh"
|
||||
|
||||
#include "G4PVPlacement.hh"
|
||||
#include "G4PVReplica.hh"
|
||||
#include "G4LogicalVolume.hh"
|
||||
#include "G4Tubs.hh"
|
||||
|
||||
const G4int numShoot = 10000;
|
||||
const G4bool optimise= true;
|
||||
const G4double x0=1.12343*cm;
|
||||
|
||||
G4VPhysicalVolume* BuildReplicaCal(G4Material* Air)
|
||||
{
|
||||
G4double xr=x0/4;
|
||||
G4int nr=20;
|
||||
G4int nl=20;
|
||||
|
||||
G4double r1=20*xr,r2=21*xr,z1=10*x0,z2=11*x0;
|
||||
// Container
|
||||
G4Tubs *ecalTube=new G4Tubs("ECAL",0,r2,z2,0,360*deg);
|
||||
// End cap
|
||||
G4Tubs *leakTube=new G4Tubs("LEAK",0,r2,0.5*x0,0,360*deg);
|
||||
// Wrapper
|
||||
G4Tubs *latrTube=new G4Tubs("LATR",r1,r2,z1,0,360*deg);
|
||||
// Main calorimeter block
|
||||
G4Tubs *blocTube=new G4Tubs("BLOC",0,r1,z1,0,360*deg);
|
||||
G4Tubs *blocTubeR=new G4Tubs("BLOCR",0,r1/nr,z1,0,360*deg);
|
||||
G4Tubs *blocTubeRZ=new G4Tubs("BLOCRZ",0,r1/nr,z1/nl,0,360*deg);
|
||||
|
||||
G4double zc=0.5*(z1+z2);
|
||||
|
||||
G4LogicalVolume *ecalLog=new G4LogicalVolume(ecalTube,Air,
|
||||
"ecalLog",0,0,0);
|
||||
G4LogicalVolume *leakLog=new G4LogicalVolume(leakTube,Air,
|
||||
"leakLog",0,0,0);
|
||||
G4LogicalVolume *latrLog=new G4LogicalVolume(latrTube,Air,
|
||||
"latrLog",0,0,0);
|
||||
G4LogicalVolume *blocLog=new G4LogicalVolume(blocTube,Air,
|
||||
"blocLog",0,0,0);
|
||||
G4LogicalVolume *blocRLog=new G4LogicalVolume(blocTubeR,Air,
|
||||
"blocRLog",0,0,0);
|
||||
G4LogicalVolume *blocRZLog=new G4LogicalVolume(blocTubeRZ,Air,
|
||||
"blocRZLog",0,0,0);
|
||||
|
||||
|
||||
G4PVPlacement *ecalPhys=new G4PVPlacement(0,G4ThreeVector(),
|
||||
"ecalPhys",
|
||||
ecalLog,
|
||||
0,false,0);
|
||||
// Position end caps, wrapper and calorimeter bloc within ecal
|
||||
G4PVPlacement *leakPhys=new G4PVPlacement(0,G4ThreeVector(0,0,-zc),
|
||||
"leakPhys",
|
||||
leakLog,
|
||||
ecalPhys,false,0);
|
||||
G4PVPlacement *leakPhys2=new G4PVPlacement(0,G4ThreeVector(0,0,zc),
|
||||
"leakPhys",
|
||||
leakLog,
|
||||
ecalPhys,false,1);
|
||||
G4PVPlacement *latrPhys=new G4PVPlacement(0,G4ThreeVector(),
|
||||
"latrPhys",
|
||||
latrLog,
|
||||
ecalPhys,false,0);
|
||||
G4PVPlacement *blocPhys=new G4PVPlacement(0,G4ThreeVector(),
|
||||
"blocPhys",
|
||||
blocLog,
|
||||
ecalPhys,false,0);
|
||||
|
||||
// Create replicas
|
||||
G4PVReplica *blocPhysR=new G4PVReplica("blocRepR",
|
||||
blocRLog,blocPhys,
|
||||
kRho,nr,r1/nr,0);
|
||||
G4PVReplica *blocPhysRZ=new G4PVReplica("blocRepRZ",
|
||||
blocRZLog,blocPhysR,
|
||||
kZAxis,nl,2*z1/nl);
|
||||
|
||||
return ecalPhys;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
G4ThreeVector pos(0,0,-10*x0+0.01*cm);
|
||||
G4double phi=M_PI*0.5,theta=15*deg;
|
||||
G4ThreeVector dir(cos(phi)*sin(theta),sin(phi)*sin(theta),cos(theta));
|
||||
G4VPhysicalVolume *myTopNode;
|
||||
G4Timer timer;
|
||||
|
||||
G4cout << " Replication Performance Test - P.Kent 26.09.96" << endl;
|
||||
#ifndef NDEBUG
|
||||
G4cout << "WARNING: *** ASSERTs are compiled IN ***" << endl;
|
||||
#endif
|
||||
|
||||
myTopNode=BuildReplicaCal(NULL); // Build the geometry
|
||||
timer.Start();
|
||||
G4GeometryManager::GetInstance()->CloseGeometry(optimise);
|
||||
timer.Stop();
|
||||
|
||||
if (optimise)
|
||||
{
|
||||
G4cout << "Optimisation ON";
|
||||
}
|
||||
else
|
||||
{
|
||||
G4cout << "Optimisation OFF";
|
||||
}
|
||||
G4cout << " Geometry close took " << timer << endl;
|
||||
|
||||
G4cout << endl << "Shooting from " << pos << " along " << dir << endl;
|
||||
ShootVerbose(myTopNode,pos,dir);
|
||||
Shoot(numShoot,myTopNode,pos,dir);
|
||||
|
||||
G4GeometryManager::GetInstance()->OpenGeometry();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
// 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: shooter.cc,v 1.1 1999/01/08 16:31:33 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-00-01 $
|
||||
//
|
||||
// shooter - perform test shots through simple box world.
|
||||
//
|
||||
// World consisting of single box positioned inside large box world
|
||||
// For comparison against F77 case. No voxels involved
|
||||
|
||||
#include "G4ios.hh"
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "G4GeometryManager.hh"
|
||||
#include "BuildBoxWorld.hh"
|
||||
#include "Shoot.hh"
|
||||
|
||||
const G4int numShoot = 10000;
|
||||
|
||||
int main()
|
||||
{
|
||||
G4ThreeVector origin(0,0,0),pMX(-500,0,0);
|
||||
G4ThreeVector vx(1,0,0);
|
||||
G4ThreeVector vy(0,1,0);
|
||||
G4VPhysicalVolume *myTopNode;
|
||||
|
||||
G4cout << "Simple BoxWorld Performance Test - P.Kent 21.08.95" << endl;
|
||||
#ifndef NDEBUG
|
||||
G4cout << "WARNING: *** ASSERTs are compiled IN ***" << endl;
|
||||
#endif
|
||||
|
||||
myTopNode=BuildBoxWorld(); // Build the geometry
|
||||
G4GeometryManager::GetInstance()->CloseGeometry();
|
||||
|
||||
G4cout << endl << "Shooting from " << origin << " along " << vx << endl;
|
||||
ShootVerbose(myTopNode,origin,vx);
|
||||
Shoot(numShoot,myTopNode,origin,vx);
|
||||
|
||||
G4cout << endl << "Shooting from " << origin << " along " << vy << endl;
|
||||
ShootVerbose(myTopNode,origin,vy);
|
||||
Shoot(numShoot,myTopNode,origin,vy);
|
||||
|
||||
G4cout << endl << "Shooting from " << pMX << " along " << vx << endl;
|
||||
ShootVerbose(myTopNode,pMX,vx);
|
||||
Shoot(numShoot,myTopNode,pMX,vx);
|
||||
|
||||
G4GeometryManager::GetInstance()->OpenGeometry();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user