@ -1,5 +1,6 @@
using MetagraphOptimization
using QEDbase
using QEDcore
using QEDprocesses
using StatsBase # for countmap
using Random
@ -9,8 +10,6 @@ import MetagraphOptimization.caninteract
import MetagraphOptimization . issame
import MetagraphOptimization . interaction_result
import MetagraphOptimization . propagation_result
import MetagraphOptimization . direction
import MetagraphOptimization . spin_or_pol
import MetagraphOptimization . QED_vertex
def_momentum = SFourMomentum ( 1.0 , 0.0 , 0.0 , 0.0 )
@ -18,32 +17,32 @@ def_momentum = SFourMomentum(1.0, 0.0, 0.0, 0.0)
RNG = Random . MersenneTwister ( 0 )
testparticleTypes = [
Photon Stateful { Incoming , PolX } ,
Photon Stateful { Outgoing , PolX } ,
Fermion Stateful{ Incoming , SpinUp } ,
Fermion Stateful{ Outgoing , SpinUp } ,
AntiFermion Stateful{ Incoming , SpinUp } ,
AntiFermion Stateful{ Outgoing , SpinUp } ,
Particle Stateful { Incoming , Photon , SFourMomentum } ,
Particle Stateful { Outgoing , Photon , SFourMomentum } ,
Particle Stateful{ Incoming , Electron , SFourMomentum } ,
Particle Stateful{ Outgoing , Electron , SFourMomentum } ,
Particle Stateful{ Incoming , Positron , SFourMomentum } ,
Particle Stateful{ Outgoing , Positron , SFourMomentum } ,
]
testparticleTypesPropagated = [
Photon Stateful { Outgoing , PolX } ,
Photon Stateful { Incoming , PolX } ,
Fermion Stateful{ Outgoing , SpinUp } ,
Fermion Stateful{ Incoming , SpinUp } ,
AntiFermion Stateful{ Outgoing , SpinUp } ,
AntiFermion Stateful{ Incoming , SpinUp } ,
Particle Stateful { Outgoing , Photon , SFourMomentum } ,
Particle Stateful { Incoming , Photon , SFourMomentum } ,
Particle Stateful{ Outgoing , Electron , SFourMomentum } ,
Particle Stateful{ Incoming , Electron , SFourMomentum } ,
Particle Stateful{ Outgoing , Positron , SFourMomentum } ,
Particle Stateful{ Incoming , Positron , SFourMomentum } ,
]
function compton_groundtruth ( input :: QEDProcessInpu t)
function compton_groundtruth ( input :: PhaseSpacePoin t)
# p1k1 -> p2k2
# formula: − (ie)^2 (u(p2) slashed(ε1) S(p2 − k1) slashed(ε2) u(p1) + u(p2) slashed(ε2) S(p1 + k1) slashed(ε1) u(p1))
p1 = input . inFerms [ 1 ]
p2 = input . outFerms [ 1 ]
p1 = momentum ( psp , Incoming ( ) , 2 )
p2 = momentum ( psp , Outgoing ( ) , 2 )
k1 = input . inPhotons [ 1 ]
k2 = input . outPhotons [ 1 ]
k1 = momentum ( psp , Incoming ( ) , 1 )
k2 = momentum ( psp , Outgoing ( ) , 1 )
u_p1 = base_state ( Electron ( ) , Incoming ( ) , p1 . momentum , spin_or_pol ( p1 ) )
u_p2 = base_state ( Electron ( ) , Outgoing ( ) , p2 . momentum , spin_or_pol ( p2 ) )
@ -88,8 +87,8 @@ end
@test issame ( typeof ( resultParticle ) , interaction_result ( p1 , p2 ) )
totalMom = zero ( SFourMomentum )
for ( p , mom ) in [ ( p1 , testParticle1 . momentum ) , ( p2 , testParticle2 . momentum ) , ( p3 , resultParticle . momentum ) ]
if ( typeof ( direction ( p ) ) <: Incoming )
for ( p , mom ) in [ ( p1 , momentum ( testParticle1) ) , ( p2 , momentum ( testParticle2) ) , ( p3 , momentum ( resultParticle) ) ]
if ( typeof ( particle_ direction( p ) ) <: Incoming )
totalMom += mom
else
totalMom -= mom
@ -103,7 +102,7 @@ end
@testset " Propagation Result " begin
for ( p , propResult ) in zip ( testparticleTypes , testparticleTypesPropagated )
@test issame ( propagation_result ( p ) , propResult )
@test direction ( propagation_result ( p ) ( def_momentum ) ) != direction ( p ( def_momentum ) )
@test particle_ direction( propagation_result ( p ) ( def_momentum ) ) != particle_ direction( p ( def_momentum ) )
end
end
@ -117,38 +116,23 @@ end
end
@testset " Known processes " begin
compton_process = QEDProcessDescription (
Dict { Type , Int } ( PhotonStateful { Incoming , PolX } => 1 , FermionStateful { Incoming , SpinUp } => 1 ) ,
Dict { Type , Int } ( PhotonStateful { Outgoing , PolX } => 1 , FermionStateful { Outgoing , SpinUp } => 1 ) ,
)
compton_process = Generic QEDProcess(1 , 1 , 1 , 1 , 0 , 0 )
@test parse_process ( " ke->ke " , QEDModel ( ) ) == compton_process
positron_compton_process = QEDProcessDescription (
Dict { Type , Int } ( PhotonStateful { Incoming , PolX } => 1 , AntiFermionStateful { Incoming , SpinUp } => 1 ) ,
Dict { Type , Int } ( PhotonStateful { Outgoing , PolX } => 1 , AntiFermionStateful { Outgoing , SpinUp } => 1 ) ,
)
positron_compton_process = Generic QEDProcess(1 , 1 , 0 , 0 , 1 , 1 )
@test parse_process ( " kp->kp " , QEDModel ( ) ) == positron_compton_process
trident_process = QEDProcessDescription (
Dict { Type , Int } ( PhotonStateful { Incoming , PolX } => 1 , FermionStateful { Incoming , SpinUp } => 1 ) ,
Dict { Type , Int } ( FermionStateful { Outgoing , SpinUp } => 2 , AntiFermionStateful { Outgoing , SpinUp } => 1 ) ,
)
trident_process = Generic QEDProcess(1 , 0 , 1 , 2 , 0 , 1 )
@test parse_process ( " ke->eep " , QEDModel ( ) ) == trident_process
pair_production_process = QEDProcessDescription (
Dict { Type , Int } ( PhotonStateful { Incoming , PolX } => 2 ) ,
Dict { Type , Int } ( FermionStateful { Outgoing , SpinUp } => 1 , AntiFermionStateful { Outgoing , SpinUp } => 1 ) ,
)
pair_production_process = Generic QEDProcess(2 , 0 , 0 , 1 , 0 , 1 )
@test parse_process ( " kk->pe " , QEDModel ( ) ) == pair_production_process
pair_annihilation_process = QEDProcessDescription (
Dict { Type , Int } ( FermionStateful { Incoming , SpinUp } => 1 , AntiFermionStateful { Incoming , SpinUp } => 1 ) ,
Dict { Type , Int } ( PhotonStateful { Outgoing , PolX } => 2 ) ,
)
pair_annihilation_process = Generic QEDProcess(0 , 2 , 1 , 0 , 1 , 0 )
@test parse_process ( " pe->kk " , QEDModel ( ) ) == pair_annihilation_process
end
@ -161,12 +145,18 @@ end
for i in 1 : 100
input = gen_process_input ( process )
@test length ( input . inFerms ) == get ( process . inParticles , FermionStateful { Incoming , SpinUp } , 0 )
@test length ( input . inAntiferms ) == get ( process . inParticles , AntiFermion Stateful{ Incoming , SpinUp } , 0 )
@test length ( input . inPhoton s ) == get ( process . inParticles , PhotonStateful { Incoming , PolX } , 0 )
@test length ( input . outFerms ) == get ( process . out Particles, Fermion Stateful{ Outgo ing, SpinUp } , 0 )
@test length ( input . outAntiferms ) == get ( process . outParticles , AntiFermionStateful { Outgoing , SpinUp } , 0 )
@test length ( input . outPhotons ) == get ( process . out Particles, Photon Stateful { Outgo ing, PolX } , 0 )
@test length ( input . inFerms ) ==
get ( process . inParticles , Particle Stateful{ Incoming , Electron , SFourMomentum } , 0 )
@test length ( input . inAntiferm s ) ==
get ( process . in Particles, Particle Stateful{ Incom ing, Positron , SFourMomentum } , 0 )
@test length ( input . inPhotons ) ==
get ( process . in Particles, Particle Stateful { Incom ing, Photon , SFourMomentum } , 0 )
@test length ( input . outFerms ) ==
get ( process . outParticles , ParticleStateful { Outgoing , Electron , SFourMomentum } , 0 )
@test length ( input . outAntiferms ) ==
get ( process . outParticles , ParticleStateful { Outgoing , Positron , SFourMomentum } , 0 )
@test length ( input . outPhotons ) ==
get ( process . outParticles , ParticleStateful { Outgoing , Photon , SFourMomentum } , 0 )
@test isapprox (
sum ( [
@ -185,6 +175,7 @@ end
end
end
#=
@ t e s t s e t " C o m p t o n " b e g i n
i m p o r t M e t a g r a p h O p t i m i z a t i o n . i n s e r t _ n o d e !
i m p o r t M e t a g r a p h O p t i m i z a t i o n . i n s e r t _ e d g e !
@ -347,3 +338,4 @@ end
@ t e s t i s a p p r o x ( c o m p u t e _ f u n c t i o n . ( i n p u t ) , r e d u c e d _ c o m p u t e _ f u n c t i o n . ( i n p u t ) )
e n d
e n d
=#