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
+25
View File
@@ -0,0 +1,25 @@
# $Id: GNUmakefile,v 2.0 1998/07/02 16:41:02 gunter Exp $
# ------------------------------------------------------------
# GNUmakefile for optical photons library. G.Folger 10-Dec-97.
# ------------------------------------------------------------
name := G4optical
ifndef G4INSTALL
G4INSTALL = ../../..
endif
include $(G4INSTALL)/config/architecture.gmk
CPPFLAGS += -I$(G4BASE)/global/management/include \
-I$(G4BASE)/global/HEPRandom/include \
-I$(G4BASE)/global/HEPGeometry/include \
-I$(G4BASE)/geometry/management/include \
-I$(G4BASE)/geometry/volumes/include \
-I$(G4BASE)/track/include \
-I$(G4BASE)/processes/management/include \
-I$(G4BASE)/particles/management/include \
-I$(G4BASE)/particles/bosons/include \
-I$(G4BASE)/materials/include
include $(G4INSTALL)/config/common.gmk
@@ -0,0 +1,97 @@
// 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: G4OpAbsorption.hh,v 2.3.2.2 1998/09/03 21:27:27 gum Exp $
// GEANT4 tag $Name: geant4-00 $
//
////////////////////////////////////////////////////////////////////////
// Optical Photon Absorption Class Definition
////////////////////////////////////////////////////////////////////////
//
// File: G4OpAbsorption.hh
// Description: Discrete Process -- Absorption of Optical Photons
// Version: 1.0
// Created: 1996-05-21
// Author: Juliet Armstrong
// Updated: 1997-04-09 by Peter Gumplinger
// > new physics/tracking scheme
// 1998-08-25 by Stefano Magni
// > Change process to use G4MaterialPropertiesTables
// mail: gum@triumf.ca
// magni@mi.infn.it
//
////////////////////////////////////////////////////////////////////////
#ifndef G4OpAbsorption_h
#define G4OpAbsorption_h 1
/////////////
// Includes
/////////////
#include "globals.hh"
#include "templates.hh"
#include "Randomize.hh"
#include "G4Step.hh"
#include "G4VDiscreteProcess.hh"
#include "G4DynamicParticle.hh"
#include "G4Material.hh"
#include "G4OpticalPhoton.hh"
/////////////////////
// Class Definition
/////////////////////
class G4OpAbsorption : public G4VDiscreteProcess
{
private:
//////////////
// Operators
//////////////
// G4OpAbsorption& operator=(const G4OpAbsorption &right);
public:
////////////////////////////////
// Constructors and Destructor
////////////////////////////////
G4OpAbsorption(const G4String& processName = "Absorption");
// G4OpAbsorption(const G4OpAbsorption &right);
~G4OpAbsorption();
////////////
// Methods
////////////
G4bool IsApplicable(const G4ParticleDefinition& aParticleType);
G4double GetMeanFreePath(const G4Track& aTrack,
G4double ,
G4ForceCondition* );
G4VParticleChange* PostStepDoIt(const G4Track& aTrack,
const G4Step& aStep);
};
////////////////////
// Inline methods
////////////////////
inline
G4bool G4OpAbsorption::IsApplicable(const G4ParticleDefinition& aParticleType)
{
return ( &aParticleType == G4OpticalPhoton::OpticalPhoton() );
}
#endif /* G4OpAbsorption_h */
@@ -0,0 +1,358 @@
// 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: G4OpBoundaryProcess.hh,v 2.1 1998/08/25 22:04:25 gum Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
////////////////////////////////////////////////////////////////////////
// Optical Photon Boundary Process Class Definition
////////////////////////////////////////////////////////////////////////
//
// File: G4OpBoundaryProcess.hh
// Description: Discrete Process -- reflection/refraction at
// optical interfaces
// Version: 1.1
// Created: 1997-06-18
// Author: Peter Gumplinger
// adopted from work by Werner Keil - April 2/96
// mail: gum@triumf.ca
//
// CVS version tag:
////////////////////////////////////////////////////////////////////////
#ifndef G4OpBoundaryProcess_h
#define G4OpBoundaryProcess_h 1
/////////////
// Includes
/////////////
#include "globals.hh"
#include "templates.hh"
#include "geomdefs.hh"
#include "Randomize.hh"
#include "G4Step.hh"
#include "G4VDiscreteProcess.hh"
#include "G4DynamicParticle.hh"
#include "G4Material.hh"
#include "G4LogicalBorderSurface.hh"
#include "G4LogicalSkinSurface.hh"
#include "G4OpticalSurface.hh"
#include "G4OpticalPhoton.hh"
#include "G4TransportationManager.hh"
/////////////////////
// Class Definition
/////////////////////
class G4OpBoundaryProcess : public G4VDiscreteProcess
{
enum G4OpBoundaryProcessStatus { Undefined,
FresnelRefraction, FresnelReflection,
TotalInternalReflection,
LambertianReflection, LobeReflection,
SpikeReflection, BackScattering,
Absorption, Detection };
private:
//////////////
// Operators
//////////////
// G4OpBoundaryProcess& operator=(const G4OpBoundaryProcess &right);
// G4OpBoundaryProcess(const G4OpBoundaryProcess &right);
public:
////////////////////////////////
// Constructors and Destructor
////////////////////////////////
G4OpBoundaryProcess(const G4String& processName = "Boundary");
~G4OpBoundaryProcess();
////////////
// Methods
////////////
G4bool IsApplicable(const G4ParticleDefinition& aParticleType);
G4double GetMeanFreePath(const G4Track& ,
G4double ,
G4ForceCondition* condition);
G4VParticleChange* PostStepDoIt(const G4Track& aTrack,
const G4Step& aStep);
G4OpticalSurfaceModel GetModel() const;
void SetModel(G4OpticalSurfaceModel model);
// set/get the optical surface model to be followed (glisur || unified)
private:
void G4Swap(G4double* a, G4double* b) const;
void G4Swap(G4Material* a, G4Material* b) const;
void G4VectorSwap(G4ThreeVector* vec1, G4ThreeVector* vec2) const;
G4bool G4BooleanRand(const G4double prob) const;
G4ThreeVector G4IsotropicRand() const;
G4ThreeVector G4LambertianRand(const G4ThreeVector& normal);
G4ThreeVector G4PlaneVectorRand(const G4ThreeVector& normal) const;
G4ThreeVector GetFacetNormal(const G4ThreeVector& Momentum,
const G4ThreeVector& Normal) const;
void DielectricMetal();
void DielectricDielectric();
void ChooseReflection();
void DoAbsorption();
void DoReflection();
private:
G4double thePhotonMomentum;
G4ThreeVector OldMomentum;
G4ThreeVector OldPolarization;
G4ThreeVector NewMomentum;
G4ThreeVector NewPolarization;
G4ThreeVector theGlobalNormal;
G4ThreeVector theFacetNormal;
G4Material* Material1;
G4Material* Material2;
G4OpticalSurface* OpticalSurface;
G4double Rindex1;
G4double Rindex2;
G4double cost1, cost2, sint1, sint2;
G4OpBoundaryProcessStatus theStatus;
G4OpticalSurfaceModel theModel;
G4OpticalSurfaceFinish theFinish;
G4double theReflectivity;
G4double theEfficiency;
G4double prob_sl, prob_ss, prob_bs;
};
////////////////////
// Inline methods
////////////////////
inline
void G4OpBoundaryProcess::G4Swap(G4double* a, G4double* b) const
{
// swaps the contents of the objects pointed
// to by 'a' and 'b'!
G4double temp;
temp = *a;
*a = *b;
*b = temp;
}
inline
void G4OpBoundaryProcess::G4Swap(G4Material* a, G4Material* b) const
{
// ONLY swaps the pointers; i.e. what used to be pointed
// to by 'a' is now pointed to by 'b' and vice versa!
G4Material* temp = a;
a = b;
b = temp;
}
inline
void G4OpBoundaryProcess::G4VectorSwap(G4ThreeVector* vec1,
G4ThreeVector* vec2) const
{
// swaps the contents of the objects pointed
// to by 'vec1' and 'vec2'!
G4ThreeVector temp;
temp = *vec1;
*vec1 = *vec2;
*vec2 = temp;
}
inline
G4bool G4OpBoundaryProcess::G4BooleanRand(const G4double prob) const
{
/* Returns a random boolean variable with the specified probability */
return (G4UniformRand() < prob);
}
inline
G4ThreeVector G4OpBoundaryProcess::G4IsotropicRand() const
{
/* Returns a random isotropic unit vector. */
G4ThreeVector vect;
G4double len2;
do {
vect.setX(G4UniformRand() - 0.5);
vect.setY(G4UniformRand() - 0.5);
vect.setZ(G4UniformRand() - 0.5);
len2 = vect.mag2();
} while (len2 < 0.01 || len2 > 0.25);
return vect.unit();
}
inline
G4ThreeVector G4OpBoundaryProcess::
G4LambertianRand(const G4ThreeVector& normal)
{
/* Returns a random lambertian unit vector. */
G4ThreeVector vect;
G4double ndotv;
do {
vect = G4IsotropicRand();
ndotv = normal * vect;
if (ndotv < 0.0) {
vect = -vect;
ndotv = -ndotv;
}
} while (!G4BooleanRand(ndotv));
return vect;
}
inline
G4ThreeVector G4OpBoundaryProcess::
G4PlaneVectorRand(const G4ThreeVector& normal) const
/* This function chooses a random vector within a plane given
by the unit normal */
{
G4ThreeVector vec1 = normal.orthogonal();
G4ThreeVector vec2 = vec1.cross(normal);
G4double cost = 2.*G4UniformRand() - 1.0;
G4double sint = sqrt(1.0 - cost * cost);
return cost * vec1 + sint * vec2;
}
inline
G4bool G4OpBoundaryProcess::IsApplicable(const G4ParticleDefinition&
aParticleType)
{
return ( &aParticleType == G4OpticalPhoton::OpticalPhoton() );
}
inline
G4OpticalSurfaceModel G4OpBoundaryProcess::GetModel() const
{
return theModel;
}
inline
void G4OpBoundaryProcess::SetModel(G4OpticalSurfaceModel model)
{
theModel = model;
}
inline
void G4OpBoundaryProcess::ChooseReflection()
{
G4double rand = G4UniformRand();
if ( rand >= 0.0 && rand < prob_ss ) {
theStatus = SpikeReflection;
theFacetNormal = theGlobalNormal;
}
else if ( rand >= prob_ss &&
rand <= prob_ss+prob_sl) {
theStatus = LobeReflection;
}
else if ( rand > prob_ss+prob_sl &&
rand < prob_ss+prob_sl+prob_bs ) {
theStatus = BackScattering;
}
else {
theStatus = LambertianReflection;
}
}
inline
void G4OpBoundaryProcess::DoAbsorption()
{
theStatus = Absorption;
if ( G4BooleanRand(theEfficiency) ) {
// EnergyDeposited =/= 0 means: photon has been detected
theStatus = Detection;
aParticleChange.SetLocalEnergyDeposit(thePhotonMomentum);
}
else {
aParticleChange.SetLocalEnergyDeposit(0.0);
}
// aParticleChange.SetEnergyChange(0.0);
aParticleChange.SetStatusChange(fStopAndKill);
}
inline
void G4OpBoundaryProcess::DoReflection()
{
if ( theStatus == LambertianReflection ) {
NewMomentum = G4LambertianRand(theGlobalNormal);
theFacetNormal = (NewMomentum - OldMomentum).unit();
}
else if ( theFinish == ground ) {
theStatus = LobeReflection;
theFacetNormal = GetFacetNormal(OldMomentum,theGlobalNormal);
G4double PdotN = OldMomentum * theFacetNormal;
NewMomentum = OldMomentum - (2.*PdotN)*theFacetNormal;
}
else {
theStatus = SpikeReflection;
theFacetNormal = theGlobalNormal;
G4double PdotN = OldMomentum * theFacetNormal;
NewMomentum = OldMomentum - (2.*PdotN)*theFacetNormal;
}
G4double EdotN = OldPolarization * theFacetNormal;
NewPolarization = -OldPolarization + (2.*EdotN)*theFacetNormal;
}
#endif /* G4OpBoundaryProcess_h */
@@ -0,0 +1,146 @@
// 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: G4OpRayleigh.hh,v 2.2 1998/08/25 22:03:54 gum Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
////////////////////////////////////////////////////////////////////////
// Optical Photon Rayleigh Scattering Class Definition
////////////////////////////////////////////////////////////////////////
//
// File: G4OpRayleigh.hh
// Description: Discrete Process -- Rayleigh scattering of optical photons
// Version: 1.0
// Created: 1996-05-31
// Author: Juliet Armstrong
// Updated: 1997-04-09 by Peter Gumplinger
// > new physics/tracking scheme
// mail: gum@triumf.ca
//
////////////////////////////////////////////////////////////////////////
#ifndef G4OpRayleigh_h
#define G4OpRayleigh_h 1
/////////////
// Includes
/////////////
#include "globals.hh"
#include "templates.hh"
#include "Randomize.hh"
#include "G4ThreeVector.hh"
#include "G4ParticleMomentum.hh"
#include "G4Step.hh"
#include "G4VDiscreteProcess.hh"
#include "G4DynamicParticle.hh"
#include "G4Material.hh"
#include "G4OpticalPhoton.hh"
#include "G4PhysicsTable.hh"
#include "G4PhysicsOrderedFreeVector.hh"
/////////////////////
// Class Definition
/////////////////////
class G4OpRayleigh : public G4VDiscreteProcess
{
private:
//////////////
// Operators
//////////////
// G4OpRayleigh& operator=(const G4OpRayleigh &right);
public:
////////////////////////////////
// Constructors and Destructor
////////////////////////////////
G4OpRayleigh(const G4String& processName = "Rayleigh Scattering");
// G4OpRayleigh(const G4OpRayleigh &right);
~G4OpRayleigh();
////////////
// Methods
////////////
G4bool IsApplicable(const G4ParticleDefinition& aParticleType);
G4double GetMeanFreePath(const G4Track& aTrack,
G4double ,
G4ForceCondition* );
G4VParticleChange* PostStepDoIt(const G4Track& aTrack,
const G4Step& aStep);
G4PhysicsTable* GetPhysicsTable() const;
// Returns the address of the physics table.
void DumpPhysicsTable() const;
private:
void BuildThePhysicsTable();
/////////////////////
// Helper Functions
/////////////////////
G4PhysicsOrderedFreeVector* RayleighAttenuationLengthGenerator(
G4MaterialPropertiesTable *aMPT);
///////////////////////
// Class Data Members
///////////////////////
protected:
G4PhysicsTable* thePhysicsTable;
// A Physics Table can be either a cross-sections table or
// an energy table (or can be used for other specific
// purposes).
};
////////////////////
// Inline methods
////////////////////
inline
G4bool G4OpRayleigh::IsApplicable(const G4ParticleDefinition& aParticleType)
{
return ( &aParticleType == G4OpticalPhoton::OpticalPhoton() );
}
inline
void G4OpRayleigh::DumpPhysicsTable() const
{
G4int PhysicsTableSize = thePhysicsTable->entries();
G4PhysicsOrderedFreeVector *v;
for (G4int i = 0 ; i < PhysicsTableSize ; i++ )
{
v = (G4PhysicsOrderedFreeVector*)(*thePhysicsTable)[i];
v->DumpValues();
}
}
inline G4PhysicsTable* G4OpRayleigh::GetPhysicsTable() const
{
return thePhysicsTable;
}
#endif /* G4OpRayleigh_h */
@@ -0,0 +1,124 @@
// 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: G4OpAbsorption.cc,v 2.6 1998/09/03 21:31:01 gum Exp $
// GEANT4 tag $Name: geant4-00 $
//
////////////////////////////////////////////////////////////////////////
// Optical Photon Absorption Class Implementation
////////////////////////////////////////////////////////////////////////
//
// File: G4OpAbsorption.cc
// Description: Discrete Process -- Absorption of Optical Photons
// Version: 1.0
// Created: 1996-05-21
// Author: Juliet Armstrong
// Updated: 1997-04-09 by Peter Gumplinger
// > new physics/tracking scheme
// 1998-08-25 by Stefano Magni
// > Change process to use G4MaterialPropertiesTables
// 1998-09-03 by Peter Gumplinger
// > Protect G4MaterialPropertyVector* AttenuationLengthVector
// mail: gum@triumf.ca
// magni@mi.infn.it
//
////////////////////////////////////////////////////////////////////////
#include "G4ios.hh"
#include "G4OpAbsorption.hh"
/////////////////////////
// Class Implementation
/////////////////////////
//////////////
// Operators
//////////////
// G4OpAbsorption::operator=(const G4OpAbsorption &right)
// {
// }
/////////////////
// Constructors
/////////////////
G4OpAbsorption::G4OpAbsorption(const G4String& processName)
: G4VDiscreteProcess(processName)
{
if (verboseLevel>0) {
G4cout << GetProcessName() << " is created " << endl;
}
}
// G4OpAbsorption::G4OpAbsorption(const G4OpAbsorpton &right)
// {
// }
////////////////
// Destructors
////////////////
G4OpAbsorption::~G4OpAbsorption(){}
////////////
// Methods
////////////
// PostStepDoIt
// -------------
//
G4VParticleChange*
G4OpAbsorption::PostStepDoIt(const G4Track& aTrack, const G4Step& aStep)
{
aParticleChange.Initialize(aTrack);
aParticleChange.SetStatusChange(fStopAndKill);
if (verboseLevel>0) {
G4cout << "\n** Photon Absorbed! **" << endl;
}
return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
}
// GetMeanFreePath
// ---------------
//
G4double G4OpAbsorption::GetMeanFreePath(const G4Track& aTrack,
G4double ,
G4ForceCondition* )
{
const G4DynamicParticle* aParticle = aTrack.GetDynamicParticle();
const G4Material* aMaterial = aTrack.GetMaterial();
G4double thePhotonMomentum = aParticle->GetTotalMomentum();
G4MaterialPropertiesTable* aMaterialPropertyTable;
G4MaterialPropertyVector* AttenuationLengthVector;
G4double AttenuationLength = DBL_MAX;
aMaterialPropertyTable = aMaterial->GetMaterialPropertiesTable();
if ( aMaterialPropertyTable ) {
AttenuationLengthVector = aMaterialPropertyTable->
GetProperty("ABSLENGTH");
if ( AttenuationLengthVector ){
AttenuationLength = AttenuationLengthVector->
GetProperty (thePhotonMomentum);
}
else {
G4cout << "No Absorbtion length specified" << endl;
}
}
else {
G4cout << "No Absorbtion length specified" << endl;
}
return AttenuationLength;
}
@@ -0,0 +1,635 @@
////////////////////////////////////////////////////////////////////////
// Optical Photon Boundary Process Class Implementation
////////////////////////////////////////////////////////////////////////
//
// File: G4OpBoundaryProcess.cc
// Description: Discrete Process -- reflection/refraction at
// optical interfaces
// Version: 1.1
// Created: 1997-06-18
// Modified: 1998-05-25 - Correct parallel component of polarization
// (thanks to: Stefano Magni + Giovanni Pieri)
// 1998-05-28 - NULL Rindex pointer before reuse
// (thanks to: Stefano Magni)
// 1998-06-11 - delete *sint1 in oblique reflection
// (thanks to: Giovanni Pieri)
// 1998-06-19 - move from GetLocalExitNormal() to the new
// method: GetLocalExitNormal(&valid) to get
// the surface normal in all cases
// 1998-11-07 - NULL OpticalSurface pointer before use
// comparison not sharp for: abs(cost1) < 1.0
// remove sin1, sin2 in lines 556,567
// (thanks to Stefano Magni)
//
// Author: Peter Gumplinger
// adopted from work by Werner Keil - April 2/96
// mail: gum@triumf.ca
//
////////////////////////////////////////////////////////////////////////
#include "G4ios.hh"
#include "G4OpBoundaryProcess.hh"
/////////////////////////
// Class Implementation
/////////////////////////
//////////////
// Operators
//////////////
// G4OpBoundaryProcess::operator=(const G4OpBoundaryProcess &right)
// {
// }
/////////////////
// Constructors
/////////////////
G4OpBoundaryProcess::G4OpBoundaryProcess(const G4String& processName)
: G4VDiscreteProcess(processName)
{
if ( verboseLevel > 0) {
G4cout << GetProcessName() << " is created " << endl;
}
theStatus = Undefined;
theModel = glisur;
theFinish = polished;
}
// G4OpBoundaryProcess::G4OpBoundaryProcess(const G4OpBoundaryProcess &right)
// {
// }
////////////////
// Destructors
////////////////
G4OpBoundaryProcess::~G4OpBoundaryProcess(){}
////////////
// Methods
////////////
// PostStepDoIt
// ------------
//
G4VParticleChange*
G4OpBoundaryProcess::PostStepDoIt(const G4Track& aTrack, const G4Step& aStep)
{
aParticleChange.Initialize(aTrack);
G4StepPoint* pPreStepPoint = aStep.GetPreStepPoint();
G4StepPoint* pPostStepPoint = aStep.GetPostStepPoint();
if (pPostStepPoint->GetStepStatus() != fGeomBoundary)
return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
if (aTrack.GetStepLength()<=kCarTolerance/2)
return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
Material1 = pPreStepPoint ->GetPhysicalVolume()->
GetLogicalVolume()->GetMaterial();
Material2 = pPostStepPoint->GetPhysicalVolume()->
GetLogicalVolume()->GetMaterial();
if (Material1 == Material2)
return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
const G4DynamicParticle* aParticle = aTrack.GetDynamicParticle();
thePhotonMomentum = aParticle->GetTotalMomentum();
OldMomentum = aParticle->GetMomentumDirection();
OldPolarization = aParticle->GetPolarization();
if ( verboseLevel > 0 ) {
G4cout << " Photon at Boundary! " << endl;
G4cout << " Old Momentum Direction: " << OldMomentum << endl;
G4cout << " Old Polarization: " << OldPolarization << endl;
}
G4MaterialPropertiesTable* aMaterialPropertiesTable;
G4MaterialPropertyVector* Rindex;
aMaterialPropertiesTable = Material1->GetMaterialPropertiesTable();
if (aMaterialPropertiesTable) {
Rindex = aMaterialPropertiesTable->GetProperty("RINDEX");
}
else {
aParticleChange.SetStatusChange(fStopAndKill);
return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
}
if (Rindex) {
Rindex1 = Rindex->GetProperty(thePhotonMomentum);
}
else {
aParticleChange.SetStatusChange(fStopAndKill);
return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
}
Rindex = NULL;
OpticalSurface = NULL;
aMaterialPropertiesTable = Material2->GetMaterialPropertiesTable();
if (aMaterialPropertiesTable)
Rindex = aMaterialPropertiesTable->GetProperty("RINDEX");
G4LogicalSurface* Surface = G4LogicalBorderSurface::GetSurface
(pPreStepPoint ->GetPhysicalVolume(),
pPostStepPoint->GetPhysicalVolume());
if (Surface == NULL) Surface = G4LogicalSkinSurface::GetSurface
(pPreStepPoint->GetPhysicalVolume()->
GetLogicalVolume());
if (Surface != NULL) OpticalSurface = Surface->GetOpticalSurface();
theModel = glisur;
theFinish = polished;
G4OpticalSurfaceType type;
if (Rindex) {
type = dielectric_dielectric;
// if (OpticalSurface) type = OpticalSurface->GetType();
Rindex2 = Rindex->GetProperty(thePhotonMomentum);
}
else if (OpticalSurface) {
type = OpticalSurface->GetType();
}
else {
aParticleChange.SetStatusChange(fStopAndKill);
return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
}
if (OpticalSurface) {
theModel = OpticalSurface->GetModel();
theFinish = OpticalSurface->GetFinish();
aMaterialPropertiesTable = OpticalSurface->
GetMaterialPropertiesTable();
if (aMaterialPropertiesTable) {
G4MaterialPropertyVector* PropertyPointer;
if(!Rindex) {
PropertyPointer =
aMaterialPropertiesTable->GetProperty("RINDEX");
if (PropertyPointer) Rindex2 =
PropertyPointer->GetProperty(thePhotonMomentum);
}
PropertyPointer =
aMaterialPropertiesTable->GetProperty("REFLECTIVITY");
if (PropertyPointer) theReflectivity =
PropertyPointer->GetProperty(thePhotonMomentum);
PropertyPointer =
aMaterialPropertiesTable->GetProperty("EFFICIENCY");
if (PropertyPointer) theEfficiency =
PropertyPointer->GetProperty(thePhotonMomentum);
if ( theModel == unified ) {
PropertyPointer =
aMaterialPropertiesTable->GetProperty("SPECULARLOBECONSTANT");
if (PropertyPointer) prob_sl =
PropertyPointer->GetProperty(thePhotonMomentum);
PropertyPointer =
aMaterialPropertiesTable->GetProperty("SPECULARSPIKECONSTANT");
if (PropertyPointer) prob_ss =
PropertyPointer->GetProperty(thePhotonMomentum);
PropertyPointer =
aMaterialPropertiesTable->GetProperty("BACKSCATTERCONSTANT");
if (PropertyPointer) prob_bs =
PropertyPointer->GetProperty(thePhotonMomentum);
}
}
}
G4ThreeVector theGlobalPoint = pPostStepPoint->GetPosition();
G4Navigator* theNavigator =
G4TransportationManager::GetTransportationManager()->
GetNavigatorForTracking();
G4ThreeVector theLocalPoint = theNavigator->
GetGlobalToLocalTransform().
TransformPoint(theGlobalPoint);
G4ThreeVector theLocalNormal; // Normal points back into volume
G4bool valid;
theLocalNormal = theNavigator->GetLocalExitNormal(&valid);
if (valid) {
theLocalNormal = -theLocalNormal;
}
else {
G4cerr << " G4OpBoundaryProcess/PostStepDoIt(): "
<< " The Navigator reports that it returned an invalid normal"
<< endl;
}
theGlobalNormal = theNavigator->GetLocalToGlobalTransform().
TransformAxis(theLocalNormal);
theStatus = Undefined;
if (type == dielectric_metal) {
DielectricMetal();
}
else if (type == dielectric_dielectric) {
if ( theFinish == polishedfrontpainted ||
theFinish == groundfrontpainted ) {
if( !G4BooleanRand(theReflectivity) ) {
DoAbsorption();
}
else {
if ( theFinish == groundfrontpainted )
theStatus = LambertianReflection;
DoReflection();
}
}
else {
DielectricDielectric();
}
}
else {
G4cout << " Error: G4BoundaryProcess: illegal boundary type " << endl;
return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
}
NewMomentum = NewMomentum.unit();
NewPolarization = NewPolarization.unit();
if ( verboseLevel > 0) {
G4cout << " New Momentum Direction: " << NewMomentum << endl;
G4cout << " New Polarization: " << NewPolarization << endl;
if ( theStatus == Undefined )
G4cout << " *** Undefined *** " << endl;
if ( theStatus == FresnelRefraction )
G4cout << " *** FresnelRefraction *** " << endl;
if ( theStatus == FresnelReflection )
G4cout << " *** FresnelReflection *** " << endl;
if ( theStatus == TotalInternalReflection )
G4cout << " *** TotalInternalReflection *** " << endl;
if ( theStatus == LambertianReflection )
G4cout << " *** LambertianReflection *** " << endl;
if ( theStatus == LobeReflection )
G4cout << " *** LobeReflection *** " << endl;
if ( theStatus == SpikeReflection )
G4cout << " *** SpikeReflection *** " << endl;
if ( theStatus == BackScattering )
G4cout << " *** BackScattering *** " << endl;
if ( theStatus == Absorption )
G4cout << " *** Absorption *** " << endl;
if ( theStatus == Detection )
G4cout << " *** Detection *** " << endl;
}
aParticleChange.SetMomentumChange(NewMomentum);
aParticleChange.SetPolarizationChange(NewPolarization);
return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
}
G4ThreeVector
G4OpBoundaryProcess::GetFacetNormal(const G4ThreeVector& Momentum,
const G4ThreeVector& Normal ) const
{
G4ThreeVector FacetNormal;
if (theModel == unified) {
/* This function code alpha to a random value taken from the
distribution p(alpha) = g(alpha; 0, sigma_alpha)*sin(alpha),
for alpha > 0 and alpha < 90, where g(alpha; 0, sigma_alpha)
is a gaussian distribution with mean 0 and standard deviation
sigma_alpha. */
G4double alpha;
G4double sigma_alpha = 0.0;
if (OpticalSurface) sigma_alpha = OpticalSurface->GetSigmaAlpha();
G4double f_max = min(1.0,4.*sigma_alpha);
do {
do {
alpha = RandGauss::shoot(0.0,sigma_alpha);
} while (G4UniformRand()*f_max > sin(alpha) || alpha >= halfpi );
G4double phi = G4UniformRand()*twopi;
G4double SinAlpha = sin(alpha);
G4double CosAlpha = cos(alpha);
G4double SinPhi = sin(phi);
G4double CosPhi = cos(phi);
G4double unit_x = SinAlpha * CosPhi;
G4double unit_y = SinAlpha * SinPhi;
G4double unit_z = CosAlpha;
FacetNormal.setX(unit_x);
FacetNormal.setY(unit_y);
FacetNormal.setZ(unit_z);
G4ThreeVector tmpNormal = Normal;
FacetNormal.rotateUz(tmpNormal);
} while (Momentum * FacetNormal >= 0.0);
}
else {
G4double polish = 1.0;
if (OpticalSurface) polish = OpticalSurface->GetPolish();
if (polish < 1.0) {
do {
G4ThreeVector smear;
do {
smear.setX(2.*G4UniformRand()-1.0);
smear.setY(2.*G4UniformRand()-1.0);
smear.setZ(2.*G4UniformRand()-1.0);
} while (smear.mag()>1.0);
smear = (1.-polish) * smear;
FacetNormal = Normal + smear;
} while (Momentum * FacetNormal >= 0.0);
FacetNormal = FacetNormal.unit();
}
else {
FacetNormal = Normal;
}
}
return FacetNormal;
}
void G4OpBoundaryProcess::DielectricMetal()
{
do {
if( !G4BooleanRand(theReflectivity) ) {
DoAbsorption();
}
else {
DoReflection();
}
OldMomentum = NewMomentum;
OldPolarization = NewPolarization;
} while (NewMomentum * theGlobalNormal < 0.0);
}
void G4OpBoundaryProcess::DielectricDielectric()
{
G4bool Inside = false;
G4bool Swap = false;
leap:
G4bool Through = false;
G4bool Done = false;
do {
if (Through) {
Swap = !Swap;
Through = false;
theGlobalNormal = -theGlobalNormal;
G4Swap(Material1,Material2);
G4Swap(&Rindex1,&Rindex2);
}
if ( theFinish == ground || theFinish == groundbackpainted ) {
theFacetNormal =
GetFacetNormal(OldMomentum,theGlobalNormal);
}
else {
theFacetNormal = theGlobalNormal;
}
G4double PdotN = OldMomentum * theFacetNormal;
G4double EdotN = OldPolarization * theFacetNormal;
cost1 = - PdotN;
if (abs(cost1) < 1.0-kCarTolerance){
sint1 = sqrt(1-cost1*cost1);
sint2 = sint1*Rindex1/Rindex2; // *** Snell's Law ***
}
else {
sint1 = 0.0;
sint2 = 0.0;
}
if (sint2 >= 1.0) {
// Simulate total internal reflection
if (Swap) Swap = !Swap;
theStatus = TotalInternalReflection;
if ( theModel == unified && theFinish != polished )
ChooseReflection();
if ( theStatus == LambertianReflection ) {
DoReflection();
}
else if ( theStatus == BackScattering ) {
NewMomentum = -OldMomentum;
NewPolarization = -OldPolarization;
}
else {
PdotN = OldMomentum * theFacetNormal;
NewMomentum = OldMomentum - (2.*PdotN)*theFacetNormal;
EdotN = OldPolarization * theFacetNormal;
NewPolarization = -OldPolarization + (2.*EdotN)*theFacetNormal;
}
}
else if (sint2 < 1.0) {
// Calculate amplitude for transmission (Q = P x N)
if (cost1 > 0.0) {
cost2 = sqrt(1-sint2*sint2);
}
else {
cost2 = -sqrt(1-sint2*sint2);
}
G4ThreeVector A_trans, Atrans, E1pp, E1pl;
G4double E1_perp, E1_parl;
if (sint1 > 0.0) {
A_trans = OldMomentum.cross(theFacetNormal);
Atrans = A_trans.unit();
E1_perp = OldPolarization * Atrans;
E1pp = E1_perp * Atrans;
E1pl = OldPolarization - E1pp;
E1_parl = E1pl.mag();
}
else {
A_trans = OldPolarization;
// Here we Follow Jackson's conventions and we set the
// parallel component = 1 in case of a ray perpendicular
// to the surface
E1_perp = 0.0;
E1_parl = 1.0;
}
G4double E2_perp, E2_parl, E2_total, TransCoeff;
if (cost1 != 0.0) {
G4double s1 = Rindex1*cost1;
E2_perp = 2.*s1*E1_perp/(Rindex1*cost1+Rindex2*cost2);
E2_parl = 2.*s1*E1_parl/(Rindex2*cost1+Rindex1*cost2);
E2_total = E2_perp*E2_perp + E2_parl*E2_parl;
G4double s2 = Rindex2*cost2*E2_total;
TransCoeff = s2/s1;
}
else {
TransCoeff = 0.0;
}
G4ThreeVector Refracted, Deflected;
G4double E2_abs, C_parl, C_perp;
if ( !G4BooleanRand(TransCoeff) ) {
// Simulate reflection
if (Swap) Swap = !Swap;
theStatus = FresnelReflection;
if ( theModel == unified && theFinish != polished )
ChooseReflection();
if ( theStatus == LambertianReflection ) {
DoReflection();
}
else if ( theStatus == BackScattering ) {
NewMomentum = -OldMomentum;
NewPolarization = -OldPolarization;
}
else {
PdotN = OldMomentum * theFacetNormal;
NewMomentum = OldMomentum - (2.*PdotN)*theFacetNormal;
if (sint1 > 0.0) { // incident ray oblique
E2_parl = Rindex2*E2_parl/Rindex1 - E1_parl;
E2_perp = E2_perp - E1_perp;
E2_total = E2_perp*E2_perp + E2_parl*E2_parl;
Refracted = theFacetNormal + PdotN * NewMomentum;
E2_abs = sqrt(E2_total);
C_parl = E2_parl/E2_abs;
C_perp = E2_perp/E2_abs;
NewPolarization = C_parl*Refracted - C_perp*A_trans;
}
else if (Rindex2 > Rindex1) { // incident ray perpendicular
NewPolarization = - OldPolarization;
}
}
}
else { // photon gets transmitted
// Simulate transmission/refraction
Inside = !Inside;
Through = true;
theStatus = FresnelRefraction;
if (sint1 > 0.0) { // incident ray oblique
G4double alpha = cost1 - cost2*(Rindex2/Rindex1);
Deflected = OldMomentum + alpha*theFacetNormal;
NewMomentum = Deflected.unit();
PdotN = -cost2;
Refracted = theFacetNormal - PdotN*NewMomentum;
E2_abs = sqrt(E2_total);
C_parl = E2_parl/E2_abs;
C_perp = E2_perp/E2_abs;
NewPolarization = C_parl*Refracted + C_perp*A_trans;
}
else { // incident ray perpendicular
NewMomentum = OldMomentum;
NewPolarization = OldPolarization;
}
}
}
OldMomentum = NewMomentum;
OldPolarization = NewPolarization;
if (theStatus == FresnelRefraction) {
Done = (NewMomentum * theGlobalNormal <= 0.0);
}
else {
Done = (NewMomentum * theGlobalNormal >= 0.0);
}
} while (!Done);
if (Inside && !Swap) {
if( theFinish == polishedbackpainted ||
theFinish == groundbackpainted ) {
if( !G4BooleanRand(theReflectivity) ) {
DoAbsorption();
}
else {
if (theStatus != FresnelRefraction ) {
theGlobalNormal = -theGlobalNormal;
}
else {
Swap = !Swap;
G4Swap(Material1,Material2);
G4Swap(&Rindex1,&Rindex2);
}
if ( theFinish == groundbackpainted )
theStatus = LambertianReflection;
DoReflection();
theGlobalNormal = -theGlobalNormal;
OldMomentum = NewMomentum;
goto leap;
}
}
}
}
// GetMeanFreePath
// ---------------
//
G4double G4OpBoundaryProcess::GetMeanFreePath(const G4Track& ,
G4double ,
G4ForceCondition* condition)
{
*condition = Forced;
return DBL_MAX;
}
@@ -0,0 +1,295 @@
// 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: G4OpRayleigh.cc,v 2.4 1998/08/25 22:05:13 gum Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
////////////////////////////////////////////////////////////////////////
// Optical Photon Rayleigh Scattering Class Implementation
////////////////////////////////////////////////////////////////////////
//
// File: G4OpRayleigh.cc
// Description: Discrete Process -- Rayleigh scattering of optical
// photons
// Version: 1.0
// Created: 1996-05-31
// Author: Juliet Armstrong
// Updated: 1997-04-09 by Peter Gumplinger
// > new physics/tracking scheme
// mail: gum@triumf.ca
//
////////////////////////////////////////////////////////////////////////
#include "G4ios.hh"
#include "G4OpRayleigh.hh"
/////////////////////////
// Class Implementation
/////////////////////////
//////////////
// Operators
//////////////
// G4OpRayleigh::operator=(const G4OpRayleigh &right)
// {
// }
/////////////////
// Constructors
/////////////////
G4OpRayleigh::G4OpRayleigh(const G4String& processName)
: G4VDiscreteProcess(processName)
{
thePhysicsTable = NULL;
if (verboseLevel>0) {
G4cout << GetProcessName() << " is created " << endl;
}
BuildThePhysicsTable();
}
// G4OpRayleigh::G4OpRayleigh(const G4OpRayleigh &right)
// {
// }
////////////////
// Destructors
////////////////
G4OpRayleigh::~G4OpRayleigh()
{
if (thePhysicsTable!= NULL) {
thePhysicsTable->clearAndDestroy();
delete thePhysicsTable;
}
}
////////////
// Methods
////////////
// PostStepDoIt
// -------------
//
G4VParticleChange*
G4OpRayleigh::PostStepDoIt(const G4Track& aTrack, const G4Step& aStep)
{
aParticleChange.Initialize(aTrack);
const G4DynamicParticle* aParticle = aTrack.GetDynamicParticle();
const G4Material* aMaterial = aTrack.GetMaterial();
if (verboseLevel>0) {
G4cout << "Scattering Photon!" << endl;
G4cout << "Old Momentum Direction: "
<< aParticle->GetMomentumDirection() << endl;
G4cout << "Old Polarization: "
<< aParticle->GetPolarization() << endl;
}
// find polar angle w.r.t. old polarization vector
G4double rand = G4UniformRand();
G4double CosTheta = pow(rand, 1./3.);
G4double SinTheta = 1.-CosTheta*CosTheta;
// find azimuthal angle w.r.t old polarization vector
rand = G4UniformRand();
G4double Phi = twopi*rand;
G4double SinPhi = sin(Phi);
G4double CosPhi = cos(Phi);
G4double unit_x = SinTheta * CosPhi;
G4double unit_y = SinTheta * SinPhi;
G4double unit_z = CosTheta;
G4ThreeVector NewPolarization (unit_x,unit_y,unit_z);
// Rotate new polarization direction into global reference system
G4ThreeVector OldPolarization = aParticle->GetPolarization();
NewPolarization.rotateUz(OldPolarization);
// -- new momentum direction is normal to the new polarization
// vector (components below expressed in reference system where
// new polarization vector is aligned with the z axis)
SinTheta = 1.0;
CosTheta = 0.0;
rand = G4UniformRand();
Phi = twopi * rand;
SinPhi = sin(Phi);
CosPhi = cos(Phi);
unit_x = SinTheta*CosPhi;
unit_y = SinTheta*SinPhi;
unit_z = CosTheta;
G4ThreeVector NewMomentumDirection(unit_x,unit_y,unit_z);
// Rotate New momentum direction vector into global reference system
NewMomentumDirection.rotateUz(NewPolarization);
aParticleChange.SetPolarizationChange(NewPolarization.unit());
aParticleChange.SetMomentumChange(NewMomentumDirection.unit());
if (verboseLevel>0) {
G4cout << "New Polarization: "
<< NewPolarization << endl;
G4cout << "Polarization Change: "
<< *(aParticleChange.GetPolarizationChange()) << endl;
G4cout << "New Momentum Direction: "
<< NewMomentumDirection << endl;
G4cout << "Momentum Change: "
<< *(aParticleChange.GetMomentumChange()) << endl;
}
return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
}
// BuildThePhysicsTable for the Rayleigh Scattering process
// --------------------------------------------------------
//
void G4OpRayleigh::BuildThePhysicsTable()
{
// Builds a table of scattering lengths for each material
if (thePhysicsTable) return;
const G4MaterialTable* theMaterialTable=
G4Material::GetMaterialTable();
G4int numOfMaterials = theMaterialTable->length();
// create a new physics table
thePhysicsTable = new G4PhysicsTable(numOfMaterials);
// loop for materials
for (G4int i=0 ; i < numOfMaterials; i++)
{
G4PhysicsOrderedFreeVector* ScatteringLengths =
new G4PhysicsOrderedFreeVector();
if ((*theMaterialTable)[i]->GetName() == "Water")
{
G4MaterialPropertiesTable *MaterialPT =
(*theMaterialTable)[i]->GetMaterialPropertiesTable();
// Call utility routine to Generate
// Rayleigh Scattering Lengths
ScatteringLengths =
RayleighAttenuationLengthGenerator(MaterialPT);
}
thePhysicsTable->insertAt(i,ScatteringLengths);
}
}
// GetMeanFreePath()
// -----------------
//
G4double G4OpRayleigh::GetMeanFreePath(const G4Track& aTrack,
G4double ,
G4ForceCondition* )
{
const G4DynamicParticle* aParticle = aTrack.GetDynamicParticle();
const G4Material* aMaterial = aTrack.GetMaterial();
G4double thePhotonMomentum = aParticle->GetTotalMomentum();
G4double AttenuationLength = DBL_MAX;
G4bool isOutRange;
if (aMaterial->GetName() == "Water")
{
AttenuationLength =
(*thePhysicsTable)(aMaterial->GetIndex())->
GetValue(thePhotonMomentum, isOutRange);
}
return AttenuationLength;
}
// RayleighAttenuationLengthGenerator()
// ------------------------------------
// Private method to compute Rayleigh Scattering Lengths (for water)
//
G4PhysicsOrderedFreeVector*
G4OpRayleigh::RayleighAttenuationLengthGenerator(G4MaterialPropertiesTable *aMPT)
{
// Physical Constants
// isothermal compressibility of water
G4double betat = 7.658e-23*m3/MeV;
// K Boltzman
G4double kboltz = 8.61739e-11*MeV/kelvin;
// Temperature of water is 10 degrees celsius
// conversion to kelvin:
// TCelsius = TKelvin - 273.15 => 273.15 + 10 = 283.15
G4double temp = 283.15*kelvin;
// Retrieve vectors for refraction index
// and photon momentum from the material properties table
G4MaterialPropertyVector* Rindex = aMPT->GetProperty("RINDEX");
G4double refsq;
G4double e;
G4double xlambda;
G4double c1, c2, c3, c4;
G4double Dist;
G4double refraction_index;
G4double no_unit = 1.0;
G4PhysicsOrderedFreeVector *RayleighScatteringLengths =
new G4PhysicsOrderedFreeVector();
Rindex->ResetIterator();
while (++(*Rindex)) {
e = (Rindex->GetPhotonMomentum());
refraction_index = Rindex->GetProperty();
refsq = refraction_index*refraction_index;
xlambda = h_Planck*c_light/e;
if (verboseLevel>0) {
G4cout << Rindex->GetPhotonMomentum() << " MeV\t";
G4cout << xlambda << " mm\t";
}
c1 = 1 / (6.0 * pi);
c2 = pow((2.0 * pi / xlambda), 4);
c3 = pow( ( (refsq - 1.0) * (refsq + 2.0) / 3.0 ), 2);
c4 = betat * temp * kboltz;
Dist = 1.0 / (c1*c2*c3*c4);
if (verboseLevel>0) {
G4cout << Dist << " mm" << endl;
}
RayleighScatteringLengths->
InsertValues(Rindex->GetPhotonMomentum(), Dist);
}
return RayleighScatteringLengths;
}