File indexing completed on 2026-04-09 07:49:14
0001 #pragma once
0002
0003 #include "G4ThreeVector.hh"
0004
0005 struct S4OpBoundaryProcess
0006 {
0007 static G4ThreeVector SmearNormal_SigmaAlpha(const G4ThreeVector& Momentum, const G4ThreeVector& Normal, G4double sigma_alpha );
0008 static G4ThreeVector SmearNormal_Polish( const G4ThreeVector& Momentum, const G4ThreeVector& Normal, G4double polish );
0009 };
0010
0011
0012 #include "Randomize.hh"
0013 #include <CLHEP/Units/PhysicalConstants.h>
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080 inline G4ThreeVector S4OpBoundaryProcess::SmearNormal_SigmaAlpha(const G4ThreeVector& Momentum, const G4ThreeVector& Normal, G4double sigma_alpha )
0081 {
0082 if (sigma_alpha == 0.0) return Normal;
0083 G4ThreeVector FacetNormal ;
0084
0085 G4double alpha;
0086 G4double f_max = std::min(1.0,4.*sigma_alpha);
0087
0088 G4double phi, SinAlpha, CosAlpha, SinPhi, CosPhi, unit_x, unit_y, unit_z;
0089 G4ThreeVector tmpNormal;
0090
0091 do {
0092 do {
0093 alpha = G4RandGauss::shoot(0.0,sigma_alpha);
0094
0095 } while (G4UniformRand()*f_max > std::sin(alpha) || alpha >= CLHEP::halfpi );
0096
0097 phi = G4UniformRand()*CLHEP::twopi;
0098
0099 SinAlpha = std::sin(alpha);
0100 CosAlpha = std::cos(alpha);
0101 SinPhi = std::sin(phi);
0102 CosPhi = std::cos(phi);
0103
0104 unit_x = SinAlpha * CosPhi;
0105 unit_y = SinAlpha * SinPhi;
0106 unit_z = CosAlpha;
0107
0108 FacetNormal.setX(unit_x);
0109 FacetNormal.setY(unit_y);
0110 FacetNormal.setZ(unit_z);
0111
0112 tmpNormal = Normal;
0113
0114
0115
0116 FacetNormal.rotateUz(tmpNormal);
0117
0118 } while (Momentum * FacetNormal >= 0.0);
0119 return FacetNormal ;
0120 }
0121
0122 inline G4ThreeVector S4OpBoundaryProcess::SmearNormal_Polish( const G4ThreeVector& Momentum, const G4ThreeVector& Normal, G4double polish )
0123 {
0124 if (polish == 1.0) return Normal;
0125 G4ThreeVector FacetNormal ;
0126
0127 do {
0128 G4ThreeVector smear;
0129 do {
0130 smear.setX(2.*G4UniformRand()-1.0);
0131 smear.setY(2.*G4UniformRand()-1.0);
0132 smear.setZ(2.*G4UniformRand()-1.0);
0133
0134 } while (smear.mag()>1.0);
0135 smear = (1.-polish) * smear;
0136 FacetNormal = Normal + smear;
0137
0138 } while (Momentum * FacetNormal >= 0.0);
0139 FacetNormal = FacetNormal.unit();
0140 return FacetNormal ;
0141 }
0142