Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions ext/Geant4/g4jl_application.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function _processHits(step::G4Step, ::G4TouchableHistory, data::SDData{T})::Bool
# detno
detno = Int32(1), #step |> GetPostStepPoint |> GetPhysicalVolume, # get ID?
# thit
thit = T(0)*u"s", #step |> GetPostStepPoint |> GetGlobalTime,
thit = (step |> GetPostStepPoint |> GetGlobalTime) / Geant4.SystemOfUnits.nanosecond * u"ns",
# edep
edep = T(edep * 1000u"keV"),
# pos
Expand All @@ -53,7 +53,7 @@ end


@with_kw mutable struct GeneratorData <: G4JLGeneratorData
gun::Union{Nothing, CxxPtr{G4ParticleGun}} = nothing
gun::Union{Nothing, CxxPtr{G4ParticleGun}, CxxPtr{G4SingleParticleSource}} = nothing
particle::Union{Nothing, CxxPtr{G4ParticleDefinition}} = nothing
position::G4ThreeVector = G4ThreeVector(0, 0, 0)
direction::G4ThreeVector = G4ThreeVector(0, 0, 0)
Expand All @@ -79,9 +79,7 @@ function SSDGenerator(source::SolidStateDetectors.MonoenergeticSource; kwargs..
SetParticleEnergy(gun, ustrip(u"MeV", source.energy))
SetParticleDefinition(gun, particle)
end



function _gen(evt::G4Event, data::GeneratorData)::Nothing
if !iszero(source.opening_angle)
d::CartesianVector = normalize(source.direction)
Expand All @@ -105,15 +103,16 @@ function SSDGenerator(source::SolidStateDetectors.IsotopeSource; kwargs...)

data = GeneratorData(;kwargs...)
function _init(data::GeneratorData, ::Any)
gun = data.gun = move!(G4ParticleGun())
gun = data.gun = move!(G4SingleParticleSource())
data.position = G4ThreeVector(
source.position.x * Geant4.SystemOfUnits.meter,
source.position.y * Geant4.SystemOfUnits.meter,
source.position.z * Geant4.SystemOfUnits.meter
)
SetParticlePosition(gun, data.position)
data.direction = G4ThreeVector(source.direction.x, source.direction.y, source.direction.z)
SetParticleMomentumDirection(gun, data.direction)
SetParticleMomentumDirection(GetAngDist(gun), data.direction)
SetMonoEnergy(gun |> GetEneDist, 0.0 * Geant4.SystemOfUnits.MeV)
end

function _gen(evt::G4Event, data::GeneratorData)::Nothing
Expand All @@ -130,10 +129,10 @@ function SSDGenerator(source::SolidStateDetectors.IsotopeSource; kwargs...)
θ = acos(1 - (1 - cos(source.opening_angle))*rand())
v = (cos(θ) * d + sin(θ) * (cos(ϕ) * a + sin(ϕ) * b))
direction = G4ThreeVector(v.x, v.y, v.z)
SetParticleMomentumDirection(data.gun, direction)
SetParticleMomentumDirection(GetAngDist(data.gun), direction)
end
GeneratePrimaryVertex(data.gun, CxxPtr(evt))
end

G4JLPrimaryGenerator("SSDGenerator", data; init_method=_init, generate_method=_gen)
end
end
Loading