forked from micro-uhecr/him_crpropa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesting_script_hadrmod.py
201 lines (151 loc) · 6.01 KB
/
testing_script_hadrmod.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
from crpropa import *
from him_crpropa.hadronic_module import *
import sys
def TestRun1D(N=100, filename='Test1.txt', density=1e13, seed=None):
"""Testing function for hadronic module in 1D
Primary protons of 1 EeV, one directionalin 1 pc spherical volume.
Cutoff energy is 1 TeV, only hadronic interactions for protons with
Cross section 10mb
"""
#specifying the output
particle_positions = TextOutput(filename, Output.Event1D)
# Detection grid
sim = ModuleList()
det = Observer()
det.add(ObserverSurface(Sphere(Vector3d(0,0,0), 1 * pc)))
det.onDetection(particle_positions)
sim.add(det)
module1 = SimplePropagation(0.01*pc, 0.5*pc)
module3 = HadronicInteractions(matter_density=density, seed=seed)
sim.add(module1)
sim.add(module3)
sim.add(SphericalBoundary(Vector3d(0, 0, 0), 1.01 * pc))
sim.add( MinimumEnergy( 100 * TeV) )
# Specifying the source
source = Source()
source.add(SourceParticleType(nucleusId(1, 1)))
source.add(SourceDirection(Vector3d(0, 0, 1)))
source.add(SourcePosition(0))
source.add(SourceEnergy(1 * EeV))
# Run particle
sim.setShowProgress(True)
sim.run(source, N)
def TestRun1D_tracks(N=100, filename='Test1.txt', density=1e13, seed=None):
"""Testing function for hadronic module in 1D
Primary protons of 1 EeV, one directionalin 1 pc spherical volume.
Cutoff energy is 1 TeV, only hadronic interactions for protons with
Cross section 10mb
"""
#specifying the output
particle_positions = TextOutput(filename, Output.Trajectory3D)
# Detection grid
sim = ModuleList()
det = Observer()
# det.add(ObserverTracking(Vector3d(0,0,0), pc, 0.01*pc))
det.add(ObserverSurface(Sphere(Vector3d(0,0,0), 1 * pc)))
det.onDetection(particle_positions)
sim.add(det)
module1 = SimplePropagation(0.3*pc, 1.5*pc)
if seed == None:
module3 = HadronicInteractions(matter_density=density)
else:
module3 = HadronicInteractions(matter_density=density, seed=seed)
sim.add(module1)
sim.add(module3)
sim.add(SphericalBoundary(Vector3d(0, 0, 0), 1.01 * pc))
sim.add( MinimumEnergy( 10 * TeV) )
# Specifying the source
source = Source()
source.add(SourceParticleType(nucleusId(1, 1)))
source.add(SourceDirection(Vector3d(0, 0, 1)))
source.add(SourcePosition(0))
source.add(SourceEnergy(1 * EeV))
# Run particle
sim.setShowProgress(True)
sim.run(source, N)
def TestReproducibility(N=100, filename='Test1.txt', density=1e13):
"""Testing that the same seeds yield unchanged results
"""
# Fixing CRPropa seed
Random_seedThreads(1987)
# Fixing HM seed
#specifying the output
particle_positions = TextOutput(filename, Output.Trajectory3D)
# Detection grid
sim = ModuleList()
det = Observer()
det.add(ObserverSurface(Sphere(Vector3d(0,0,0), 1 * pc)))
det.onDetection(particle_positions)
sim.add(det)
module1 = SimplePropagation(0.3*pc, 1.5*pc)
module3 = HadronicInteractions(matter_density=density, seed=1298)
sim.add(module1)
sim.add(module3)
sim.add(SphericalBoundary(Vector3d(0, 0, 0), 1.01 * pc))
sim.add( MinimumEnergy( 1 * PeV) )
# Specifying the source
source = Source()
source.add(SourceParticleType(nucleusId(1, 1)))
source.add(SourceDirection(Vector3d(0, 0, 1)))
source.add(SourcePosition(0))
source.add(SourceEnergy(50 * TeV))
# Run particle
sim.setShowProgress(True)
sim.run(source, N)
def TestOneInteractionLength(N=100, filename='Test1.txt', energy=1, seed=None):
"""Testing function for hadronic module isotropic source.
Primary protons of given energy (EeV), isotropic source, in spherical volume
of 1 pc and density such that the radius equals one interaction length.
No cutoff energy, only hadronic interactions for protons with cross section
given by PDG model.
"""
def sigma_pp(plab):
"""Cross section for proton-proton interactions based on the PDG fit, as
a function of the laboratory momentum plab in GeV.
Reference: C. Patrignani 2016 Chinese Phys. C 40 100001
"""
mp = 0.938272 # GeV
M = 2.1206 # GeV
H = 0.272 # mb
P, R1, R2 = 34.41, 13.07, 7.394 # in mb
eta1, eta2 = 0.4473, 0.5486 # dimenssionless
ecm2 = 2*(mp**2 + mp*sqrt(plab**2 + mp**2)) # GeV
sab = (2*mp + M)**2 # GeV
xsec = H * log(ecm2/sab)**2 + P + R1*(ecm2/sab)**-eta1 - R2*(ecm2/sab)**-eta2
return xsec
density = 1 / sigma_pp(energy * 1e9) / 1e-31 / pc # m^-3
#specifying the output
particle_positions = TextOutput(filename, Output.Event1D)
# Detection grid
sim = ModuleList()
det = Observer()
det.add(ObserverSurface(Sphere(Vector3d(0,0,0), 1 * pc)))
det.onDetection(particle_positions)
sim.add(det)
module1 = SimplePropagation(0.01*pc, 0.5*pc)
module3 = HadronicInteractions(matter_density=density, seed=seed)
sim.add(module1)
sim.add(module3)
sim.add(SphericalBoundary(Vector3d(0, 0, 0), 1.01 * pc))
# Specifying the source
source = Source()
source.add(SourceParticleType(nucleusId(1, 1)))
source.add(SourceIsotropicEmission())
source.add(SourceEnergy(1 * EeV))
# Run particle
sim.setShowProgress(True)
sim.run(source, N)
if __name__ == "__main__":
# TestRun1D(100000, 'output.txt')
Nprimaries = 100
output_filename = 'output.txt'
if len(sys.argv) > 2:
Nprimaries = int(sys.argv[1])
if len(sys.argv) == 3:
output_filename = sys.argv[2]
Random_seedThreads(1987)
# TestRun1D(Nprimaries, output_filename, seed=1967)
# TestRun1D_tracks(Nprimaries, output_filename, seed=1967, density=1e22)
# TestReproducibility(Nprimaries, output_filename, density=1e19)
# print(Random_seedThreads.getSeed())
TestOneInteractionLength(Nprimaries, output_filename)