51 #include "art/Framework/Services/Registry/ServiceHandle.h"
53 #include "Geant4/G4GeometryTolerance.hh"
54 #include "Geant4/G4Navigator.hh"
55 #include "Geant4/G4OpProcessSubType.hh"
56 #include "Geant4/G4RandomTools.hh"
57 #include "Geant4/G4TransportationManager.hh"
58 #include "Geant4/G4ios.hh"
68 : G4VDiscreteProcess(processName, type)
70 G4cout << GetProcessName() <<
" is created " << G4endl;
72 SetProcessSubType(fOpBoundary);
76 fCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
91 aParticleChange.Initialize(aTrack);
93 G4StepPoint* pPreStepPoint = aStep.GetPreStepPoint();
94 G4StepPoint* pPostStepPoint = aStep.GetPostStepPoint();
96 if (pPostStepPoint->GetStepStatus() != fGeomBoundary) {
98 return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
102 return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
105 G4Material* Material1 = pPreStepPoint->GetMaterial();
106 G4Material* Material2 = pPostStepPoint->GetMaterial();
108 if (Material1 != Material2) {
110 art::ServiceHandle<sim::LArG4Parameters const> lgp;
114 G4ThreeVector NewMomentum;
115 G4ThreeVector NewPolarization;
117 G4ThreeVector theGlobalNormal;
118 G4ThreeVector theFacetNormal;
120 std::string Material1Name = Material1->GetName();
121 std::string Material2Name = Material2->GetName();
123 const G4DynamicParticle* aParticle = aTrack.GetDynamicParticle();
124 G4double thePhotonMomentum = aParticle->GetTotalMomentum();
125 G4ThreeVector OldMomentum = aParticle->GetMomentumDirection();
126 G4ThreeVector OldPolarization = aParticle->GetPolarization();
129 std::cout <<
"OpBoundaryProcessSimple Debug: Photon " << aTrack.GetTrackID() <<
" momentum "
130 << thePhotonMomentum <<
" Material1 " << Material1Name.c_str() <<
" Material 2 "
131 << Material2Name.c_str() << std::endl;
133 G4ThreeVector theGlobalPoint = pPostStepPoint->GetPosition();
135 G4Navigator* theNavigator =
136 G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking();
138 G4ThreeVector theLocalPoint =
139 theNavigator->GetGlobalToLocalTransform().TransformPoint(theGlobalPoint);
143 G4ThreeVector theLocalNormal = theNavigator->GetLocalExitNormal(&valid);
145 if (valid) { theLocalNormal = -theLocalNormal; }
147 G4cerr <<
" OpBoundaryProcessSimple/PostStepDoIt(): "
148 <<
" The Navigator reports that it returned an invalid normal" << G4endl;
151 theGlobalNormal = theNavigator->GetLocalToGlobalTransform().TransformAxis(theLocalNormal);
153 if (OldMomentum * theGlobalNormal > 0.0) {
154 #ifdef G4DEBUG_OPTICAL
155 G4cerr <<
" OpBoundaryProcessSimple/PostStepDoIt(): "
156 <<
" theGlobalNormal points the wrong direction " << G4endl;
158 theGlobalNormal = -theGlobalNormal;
161 G4MaterialPropertiesTable* aMaterialPropertiesTable;
162 G4MaterialPropertyVector* Reflectance;
163 G4MaterialPropertyVector* DiffuseReflectanceFraction;
165 aMaterialPropertiesTable = Material1->GetMaterialPropertiesTable();
167 if (aMaterialPropertiesTable) {
169 std::stringstream PropertyName;
170 PropertyName <<
"REFLECTANCE_" << Material2Name.c_str();
171 Reflectance = aMaterialPropertiesTable->GetProperty(PropertyName.str().c_str());
173 PropertyName.str(
"");
174 PropertyName <<
"DIFFUSE_REFLECTANCE_FRACTION_" << Material2Name.c_str();
175 DiffuseReflectanceFraction =
176 aMaterialPropertiesTable->GetProperty(PropertyName.str().c_str());
179 double theReflectance = Reflectance->Value(thePhotonMomentum);
181 if (DiffuseReflectanceFraction) {
182 double theDiffuseReflectanceFraction =
183 DiffuseReflectanceFraction->Value(thePhotonMomentum);
205 NewMomentum = G4LambertianRand(theGlobalNormal);
206 theFacetNormal = (NewMomentum - OldMomentum).unit();
210 theFacetNormal = theGlobalNormal;
211 G4double PdotN = OldMomentum * theFacetNormal;
212 NewMomentum = OldMomentum - (2. * PdotN) * theFacetNormal;
216 aParticleChange.ProposeTrackStatus(fStopAndKill);
220 NewMomentum = OldMomentum;
223 aParticleChange.ProposeTrackStatus(fStopAndKill);
225 NewMomentum = NewMomentum.unit();
226 aParticleChange.ProposeMomentumDirection(NewMomentum);
228 return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
Store parameters for running LArG4.
G4VParticleChange * PostStepDoIt(const G4Track &aTrack, const G4Step &aStep)
OpBoundaryProcessSimpleStatus fTheStatus
G4bool G4BooleanRand(const G4double prob) const
G4double GetMeanFreePath(const G4Track &, G4double, G4ForceCondition *condition)
BEGIN_PROLOG could also be cout
OpBoundaryProcessSimple(const G4String &processName="OpBoundary", G4ProcessType type=fOptical)