Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change internal looping in NuRadioMC #208

Merged
merged 223 commits into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
223 commits
Select commit Hold shift + click to select a range
c9c56fe
remove print statements
cg-laser Nov 13, 2019
6a39b7a
change label
cg-laser Dec 10, 2019
7d02b6b
add TA combined fit results
cg-laser Dec 19, 2019
666b5c0
plot errorband of Auger best fit
cg-laser Feb 7, 2020
bc58859
update plot
cg-laser Feb 10, 2020
efd95bc
rename AUGER->Auger
cg-laser Feb 11, 2020
47bb060
add RNO-G and icecube gen2 flux predictions
cg-laser Apr 1, 2020
dcaece0
remove outdated tau second band simulations. This is replaced by prop…
cg-laser May 19, 2020
7a3e785
if proposal is not activated, fiducial volume equals full volume
cg-laser May 19, 2020
95e2f34
remove command line arguments to match changes in generator.py
cg-laser May 20, 2020
1c161cc
add a separte entry for each shower
cg-laser May 20, 2020
9d1474b
remove unused code
cg-laser May 20, 2020
94e9ad6
fix setting total number of events
cg-laser May 20, 2020
5d63273
rename energies_shower to shower_energies
cg-laser May 20, 2020
b21576c
improve output
cg-laser May 20, 2020
37f8589
add tests for event generation
cg-laser May 20, 2020
cd208e1
rename "event_ids" to "event_group_ids"
cg-laser May 20, 2020
031360d
fix encoding of string data sets so that they are unicode strings in p3
cg-laser May 20, 2020
d5082c1
change that allows to retrive a specific random realization of a show…
cg-laser May 20, 2020
cb34e3c
rename variable
cg-laser May 20, 2020
bb973de
work in progress,
cg-laser Jun 2, 2020
1674051
fix use of global variable
cg-laser Jun 5, 2020
6bba681
next step in modifying main simulation routine
cg-laser Jun 5, 2020
4b9db9b
refactor internal looping to iterate over showers. Refractor specific…
cg-laser Jun 9, 2020
42a4e2c
increase major version of input file format
cg-laser Jun 9, 2020
d5b4cdc
adjust Veff test
cg-laser Jun 9, 2020
91dbe5b
change NuRadioReco branch temporarily
cg-laser Jun 9, 2020
99ec5be
allow for custom detector simulation
cg-laser Jun 10, 2020
a6dd69f
save sim showers to event
cg-laser Jun 10, 2020
318b8cb
adapt hdf5 files to new structure, save all relevant quantities
cg-laser Jun 10, 2020
620c6f8
remove pritns
cg-laser Jun 10, 2020
cc85837
fix calculation of Veff
cg-laser Jun 10, 2020
7d7d88a
fix Veff calculation in main simulation script
cg-laser Jun 11, 2020
6fb2f85
fix Alvarez2009 model
cg-laser Jun 11, 2020
0e7e0f6
rename self._iE to self._iSh to reflect that this index loops over al…
cg-laser Jun 11, 2020
296b8f8
remove matplotib import
cg-laser Jun 11, 2020
34e7dc3
pass additional argumentss to Alvarez2009 model
cg-laser Jun 11, 2020
a997a95
adjust comparision script to new hdf5 structure
cg-laser Jun 11, 2020
3795c48
save ARZ and Alvarez2009 shower realizations in separate fields
cg-laser Jun 12, 2020
68b3075
set only those showers to triggered that contributed to an event that…
cg-laser Jun 12, 2020
9dab0ef
assign every shower a unique shower id
cg-laser Jun 12, 2020
e54841f
use shower_ids and indexes properly, save maximum amplitude and signa…
cg-laser Jun 12, 2020
329d1bd
sim shower must be a radio shower
cg-laser Jun 16, 2020
55b6cdf
cosmetic
cg-laser Jun 17, 2020
508763d
fix tests part 1
cg-laser Jun 17, 2020
6142cda
fix MB test
cg-laser Jun 17, 2020
8d6cbd0
Merge branch 'master' into internal-looping
cg-laser Jun 17, 2020
577d93d
trigger build
cg-laser Jun 17, 2020
2645ef3
add more output to test
cg-laser Jun 17, 2020
1bc5168
add hdf5 dump if comparison fails
cg-laser Jun 18, 2020
8299281
update reference
cg-laser Jun 18, 2020
10dcd07
add max amplitude per ray and shower to comparision
cg-laser Jun 18, 2020
7545bef
add printout of event group if events disagree
cg-laser Jun 18, 2020
ddcc672
select correct gid
cg-laser Jun 18, 2020
77c3a2a
better output
cg-laser Jun 18, 2020
4c12547
improve output
cg-laser Jun 18, 2020
152c4ea
update
cg-laser Jun 18, 2020
6e17902
allow for input file having more stations than output file
cg-laser Jun 18, 2020
fd27a67
improve dump script
cg-laser Jun 18, 2020
ba20b5d
fix dump script
cg-laser Jun 18, 2020
52d8767
make time resolution in efieldToVoltageConverter configurable, update…
cg-laser Jun 18, 2020
b2d4582
add output time to time output
cg-laser Jun 19, 2020
bdc4391
change log level from warning to info to not confuse users
cg-laser Jun 19, 2020
20bdf5d
activate event splitting with 1mus separation for MB to speed up comp…
cg-laser Jun 19, 2020
41a0f95
change precision of maximum_amplitude test to 1% (only this field)
cg-laser Jun 19, 2020
644806a
add ARZ test
cg-laser Jun 19, 2020
0a32c78
add ARZ config
cg-laser Jun 19, 2020
ab38c8c
temporarily disable DnR example
cg-laser Jun 19, 2020
f1ef99d
add saveguard against divide by zero in debug output
cg-laser Jun 19, 2020
7464fc8
move effective volume calculation back into a try,except block
cg-laser Jun 19, 2020
be4add4
fix examples
cg-laser Jun 19, 2020
0edec72
delete the correct files
cg-laser Jun 19, 2020
aebd2c5
Merge branch 'master' into internal-looping
cg-laser Jun 24, 2020
d04d8ff
adapt Aeff function and test
cg-laser Jun 24, 2020
2bbd005
add distance cut
cg-laser Jun 24, 2020
f278258
make script more modular
cg-laser Jun 24, 2020
21b2c40
fix calculation of aeff in utlitiy script
cg-laser Jun 24, 2020
99e01e5
move distance cut from test. Concept of distance cut needs to be reth…
cg-laser Jun 24, 2020
b79123f
bugfix to get correct distance distrubution if rmin is > 0
cg-laser Jun 30, 2020
0cefd69
cleanup code, allow volume to be a cube
cg-laser Jun 30, 2020
dba5fd8
also remove geometry cut for Volume generator
cg-laser Jun 30, 2020
71eb11c
implement a speed up cut that removes skips all trajectories that don…
cg-laser Jun 30, 2020
835134a
add comment
cg-laser Jun 30, 2020
7572c8f
fix tests
cg-laser Jun 30, 2020
d7d8c10
improve logging, add back fiducial volume cut
cg-laser Jun 30, 2020
e5b6298
make deleting files more robust
cg-laser Jun 30, 2020
98541e9
sufrace muons should also start at the surface...
cg-laser Jun 30, 2020
47ac5cd
fix geometry cut. Change order of generating data sets. Now first is …
cg-laser Jul 1, 2020
fec51da
change Veff reference value to different random realization of input …
cg-laser Jul 1, 2020
19b42fa
fix Veff script to directly use the "area" and "volume" attributes, a…
cg-laser Jul 1, 2020
07ca0fe
substantial speedup in saving events function, change vertex generati…
cg-laser Jul 1, 2020
6ee02b0
reduce testing precision a little bit from 7 decimals to 3 decimals
cg-laser Jul 1, 2020
d410a10
do not increase z volume automatically
cg-laser Jul 2, 2020
4623c96
add scripts to calculate distance cut
cg-laser Jul 2, 2020
95dec6f
add better distance cut
cg-laser Jul 2, 2020
11cbe62
add 100m safety margin to account for distances of antennas
cg-laser Jul 2, 2020
506df11
make memory management more efficient.
cg-laser Jul 2, 2020
532668c
bugfix, index global array correctly
cg-laser Jul 2, 2020
699b7e2
set triggers correctly
cg-laser Jul 3, 2020
17a1e7c
fix index function
cg-laser Jul 3, 2020
a952878
remove "save_all" option
cg-laser Jul 3, 2020
0413c45
fix case of no triggered event
cg-laser Jul 3, 2020
69843b7
additional saveguard against no triggered events
cg-laser Jul 3, 2020
e2107df
fix typo
cg-laser Jul 6, 2020
bdeccbc
save shower id per station group to be able to reference back to the …
cg-laser Jul 6, 2020
0897ce0
remeove check for same station keys in all files
cg-laser Jul 6, 2020
f04457a
adjust merging to new file structure and enable multi processing
cg-laser Jul 6, 2020
a51002d
forgot one dtype
cg-laser Jul 6, 2020
feae7ab
fix single core processing
cg-laser Jul 6, 2020
a73b7d1
update changelog
cg-laser Jul 6, 2020
ef0c4d5
make Veff script robust against hdf5 file not having trigger_names at…
cg-laser Jul 6, 2020
44cafc6
add output
cg-laser Jul 6, 2020
eefbe8d
Merge branch 'add-TA-GZKflux' into memory-management
cg-laser Jul 7, 2020
1516f8d
remove print out
cg-laser Jul 7, 2020
52f38c2
add multithreading option to Veff utility
cg-laser Jul 7, 2020
a38cdf8
make it work...
cg-laser Jul 7, 2020
1971d8c
speed improvement
cg-laser Jul 7, 2020
4cd2a8f
Merge pull request #221 from nu-radio/memory-management
cg-laser Jul 22, 2020
4ba063c
Merge pull request #220 from nu-radio/speedup-distance-cut
cg-laser Jul 22, 2020
b345f42
Merge pull request #219 from nu-radio/evt-gen-volume
cg-laser Jul 22, 2020
2359a1e
Merge branch 'master' into internal-looping
cg-laser Jul 22, 2020
575451f
add functionality for different bandwidth per station and channel
cg-laser Jul 28, 2020
bad7e24
update travis to use NuRadioREco branch
cg-laser Jul 28, 2020
224fa00
bugfixes
cg-laser Jul 28, 2020
8132eed
Update .travis.yml
cg-laser Jul 29, 2020
82d8074
distance cut can now sum over all surrounding shower energies
cg-laser Jul 29, 2020
8496083
increase default integration steps
cg-laser Jul 29, 2020
6a33fe8
bugfix
cg-laser Jul 29, 2020
a334825
Merge branch 'bandwidth-per-channel' into distance-cut
cg-laser Jul 29, 2020
c64d9d3
speedup weight calculation, time distance cut
cg-laser Jul 29, 2020
c52121a
test
cg-laser Jul 29, 2020
dd39655
test
cg-laser Jul 29, 2020
ccd4fa4
speed up weight calculation
cg-laser Jul 29, 2020
a40e99d
Merge pull request #226 from nu-radio/bandwidth-per-channel
cg-laser Jul 30, 2020
54a3171
add docu and debug output
cg-laser Jul 30, 2020
495597d
Merge pull request #227 from nu-radio/distance-cut
cg-laser Jul 30, 2020
11bf0f8
Merge remote-tracking branch 'origin/fix-Veff-secondaries' into inter…
cg-laser Jul 30, 2020
daa9cee
remove unused function
cg-laser Jul 30, 2020
85d51d4
improve plotting
cg-laser Jul 30, 2020
ed8504a
remove unused function
cg-laser Jul 30, 2020
8b6f325
add timing to evt gen
cg-laser Jul 30, 2020
9b6f8fb
fix variable name
cg-laser Jul 30, 2020
754c564
increase default log level
cg-laser Jul 30, 2020
b5e1271
update logger
cg-laser Jul 30, 2020
0d26302
change test
cg-laser Jul 30, 2020
276577f
improve plot
cg-laser Jul 30, 2020
b88f414
clean up proposal
cg-laser Jul 30, 2020
9baa399
bugfix
cg-laser Jul 30, 2020
b469f28
make proposal setting configurable
cg-laser Jul 30, 2020
459561d
remove doublicated import
cg-laser Jul 30, 2020
6bf3651
restrict distance cut to a minimum of 100m
cg-laser Jul 30, 2020
4110bf9
fix tests
cg-laser Jul 30, 2020
4c0467a
add limitation of event numbers from automatic event number increase
cg-laser Jul 30, 2020
3a8d52b
number of events must be integer
cg-laser Jul 30, 2020
c58c95d
also limit number of events for cube simulation volume
cg-laser Jul 30, 2020
ba8e7e2
Merge pull request #228 from nu-radio/proposal-ecut
cg-laser Jul 31, 2020
000ea78
add efficiency cut to veff function
cg-laser Jul 31, 2020
0a84e7f
check for empty stations
cg-laser Jul 31, 2020
a91cb34
typo
cg-laser Jul 31, 2020
a3542f0
correct indexing
cg-laser Jul 31, 2020
91e11ff
fix
cg-laser Jul 31, 2020
b305ea8
fix efficiency calculation
cg-laser Jul 31, 2020
1d9acc8
skip non-triggered trigger combinations
cg-laser Jul 31, 2020
a085af0
optimize calculation
cg-laser Jul 31, 2020
be3792e
convert nans to 0
cg-laser Jul 31, 2020
432c0d3
save Vrms and bandwidth per station and channel
cg-laser Jul 31, 2020
bc9f5ee
make showing auger configurable, save Vrms/bandwidth as list
cg-laser Jul 31, 2020
eae7868
add log levelx
cg-laser Aug 3, 2020
28c28ec
generate events in batches
cg-laser Aug 3, 2020
346ea4b
improve logging
cg-laser Aug 4, 2020
1797542
fix output
cg-laser Aug 4, 2020
48e86e0
improve output
cg-laser Aug 4, 2020
e1979b7
slight memory improvement
cg-laser Aug 4, 2020
48a06e9
reduce default batch size to 1e5
cg-laser Aug 4, 2020
de55601
use xx field to count number of events
cg-laser Aug 6, 2020
54e1e6b
extent volume better (restrict it to maximum horizontal distance for …
cg-laser Aug 7, 2020
0e98495
improve printout and timing
cg-laser Aug 7, 2020
a3b5c77
check for uniqueness of gids
cg-laser Aug 7, 2020
da7b33b
update nur reference file (required because file format changed)
cg-laser Aug 11, 2020
33d7f08
merge file with hdf5.part???? and hdf5.part?????? automatically
cg-laser Aug 12, 2020
199d010
fix
cg-laser Aug 12, 2020
5c8b0d6
assign new gids if they are not unique
cg-laser Aug 12, 2020
3dcb17b
more output
cg-laser Aug 12, 2020
48870b9
update logging
cg-laser Aug 12, 2020
255611c
Merge pull request #229 from nu-radio/evt-gen-memory
cg-laser Aug 12, 2020
852ef04
add option to read noise temperature per station and channel from det…
cg-laser Aug 12, 2020
21db4a8
update chnagelog
cg-laser Aug 12, 2020
503f8af
update default config
cg-laser Aug 12, 2020
6788811
improve memory usage
cg-laser Aug 13, 2020
cd66b08
bugfix
cg-laser Aug 13, 2020
eacb085
Merge pull request #232 from nu-radio/memory-optimization-proposal
cg-laser Aug 24, 2020
3a21523
rename noise temperature variables to comply with coding conventions
cg-laser Aug 24, 2020
2918b23
Merge pull request #230 from nu-radio/noise-temperature
cg-laser Aug 24, 2020
f474521
Merge branch 'master' into internal-looping
cg-laser Aug 24, 2020
1fe4df3
initialize noise adder module with seed from config file
cg-laser Aug 24, 2020
70b5a47
change to NuRadioReco master branch
cg-laser Aug 25, 2020
8913943
add noise at the correct place (after the antenna but before the filter)
cg-laser Aug 27, 2020
306b6f3
update noise reference. Required because order when noise is being ad…
cg-laser Aug 31, 2020
ef2d0c6
add documentation, change default parameter
cg-laser Sep 1, 2020
afce539
combine Aeff and Veff functions
cg-laser Sep 2, 2020
00e362d
fixes
cg-laser Sep 2, 2020
e76d2f4
fix examples to use new funtions
cg-laser Sep 3, 2020
476575b
fixes to new methods
cg-laser Sep 3, 2020
5e6d4f6
save parent muon to hdf5 file if any shower is in fiducial volume
cg-laser Sep 3, 2020
414ed87
fix key
cg-laser Sep 3, 2020
685dd09
remove non-existent argument
cg-laser Sep 3, 2020
a4c6df5
add debug output
cg-laser Sep 3, 2020
50f1d58
dabug outupt
cg-laser Sep 3, 2020
84c6ab1
more debug output
cg-laser Sep 3, 2020
1138ae0
fix in debug output
cg-laser Sep 3, 2020
a29064f
remove debug output
cg-laser Sep 4, 2020
e5e9d62
fix
cg-laser Sep 4, 2020
3600f1c
make nur output mode configurable
cg-laser Sep 6, 2020
bb64a83
remove comma from yaml file
cg-laser Sep 6, 2020
80be808
remove DnR example. It needs to be reimplemented using the new structure
cg-laser Sep 7, 2020
665675b
add more printout to dump script
cg-laser Sep 7, 2020
a124e89
remove unused function
cg-laser Sep 7, 2020
e2ebf8f
change type to int
cg-laser Sep 7, 2020
e794d50
update changelog
cg-laser Sep 7, 2020
f5d2b50
improve output
cg-laser Sep 7, 2020
037c99f
correctly save phi parameters
cg-laser Sep 7, 2020
55b10f2
Merge pull request #235 from nu-radio/refactor-veff
cg-laser Sep 7, 2020
ed9a7f0
change output
cg-laser Sep 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ jobs:
script: NuRadioMC/test/SingleEvents/test_build.sh
- script: NuRadioMC/test/SingleEvents/validate_MB.sh
name: "Single event test (Moore's Bay)"
- script: NuRadioMC/test/SingleEvents/validate_ARZ.sh
name: "Single event test (ARZ)"
- stage: "Test individual components"
name: "Signal generation test"
script: NuRadioMC/test/SignalGen/test_build.sh
Expand Down
175 changes: 60 additions & 115 deletions NuRadioMC/EvtGen/NuRadioProposal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import six
import json
import logging

"""
This module takes care of the PROPOSAL implementation. Some important things
Expand Down Expand Up @@ -225,6 +226,7 @@ def is_shower_primary(particle):
else:
return False


def check_path_to_tables(config_file_path):
"""
Checks if the paths for the PROPOSAL tables in the input config file are
Expand All @@ -240,18 +242,19 @@ def check_path_to_tables(config_file_path):

if not os.path.isdir(path_to_tables):

error_msg = "'path_to_tables' in {} points to {}, which is a non-existing directory. ".format(config_file_path,
error_msg = "'path_to_tables' in {} points to {}, which is a non-existing directory. ".format(config_file_path,
path_to_tables)
error_msg += "Please choose a valid path for the PROPOSAL config file in {}.".format(config_file_path)
raise ValueError(error_msg)

if not os.path.isdir(path_to_tables_readonly):

error_msg = "'path_to_tables_readonly' in {} points to {}, which is a non-existing directory. ".format(config_file_path,
error_msg = "'path_to_tables_readonly' in {} points to {}, which is a non-existing directory. ".format(config_file_path,
path_to_tables_readonly)
error_msg += "Please choose a valid path for the PROPOSAL config file in {}.".format(config_file_path)
raise ValueError(error_msg)


@six.add_metaclass(Singleton)
class ProposalFunctions(object):
"""
Expand All @@ -260,7 +263,7 @@ class ProposalFunctions(object):
not be used from the outside to avoid mismatching units.
"""

def __init__(self, config_file='SouthPole', low_nu=1 * units.PeV):
def __init__(self, config_file='SouthPole', log_level=logging.INFO):
"""
Parameters
----------
Expand All @@ -274,33 +277,21 @@ def __init__(self, config_file='SouthPole', low_nu=1 * units.PeV):
IMPORTANT: If these options are used, the code is more efficient if the
user requests their own "path_to_tables" and "path_to_tables_readonly",
pointing them to a writable directory
low_nu: float
Low energy limit for the propagating particle in NuRadioMC units (eV)
"""
print("initializing proposal interface class", flush=True)
self.propagators = {}
low = low_nu * pp_eV
for lepton_code in [13, -13, 15, -15]:
self.propagators[lepton_code] = self.__create_propagator(low=low, particle_code=lepton_code,
config_file=config_file)

self.mu_propagators = {}
for lepton_code in [13, -13]:
self.mu_propagators[lepton_code] = self.__create_propagator(low=low, particle_code=lepton_code,
config_file=config_file)

def __create_propagator(self,
low=0.1 * pp_PeV,
particle_code=13,
config_file='SouthPole'):
self.__logger = logging.getLogger("proposal")
self.__logger.setLevel(log_level)
self.__logger.info("initializing proposal interface class")

self.__propagators = {}
self.__config_file = config_file

def __get_propagator(self,
particle_code=13):
"""
Creates a PROPOSAL propagator for muons or taus
Returns a PROPOSAL propagator for muons or taus. If it does not exist yet it is being generated.

Parameters
----------
low: float
Minimum energy that a particle can have. If this energy is attained,
propagation stops. In PROPOSAL units (MeV)
particle_code: integer
Particle code for the muon- (13), muon+ (-13), tau- (15), or tau+ (-15)
config_file: string or path
Expand All @@ -323,90 +314,49 @@ def __create_propagator(self,
propagator: PROPOSAL propagator
Propagator that can be used to calculate the interactions of a muon or tau
"""
mu_def_builder = pp.particle.ParticleDefBuilder()
if (particle_code == 13):
mu_def_builder.SetParticleDef(pp.particle.MuMinusDef())
elif (particle_code == -13):
mu_def_builder.SetParticleDef(pp.particle.MuPlusDef())
elif (particle_code == 15):
mu_def_builder.SetParticleDef(pp.particle.TauMinusDef())
elif (particle_code == -15):
mu_def_builder.SetParticleDef(pp.particle.TauPlusDef())
else:
error_str = "The propagation of this particle via PROPOSAL is not currently supported.\n"
error_str += "Please choose between -/+muon (13/-13) and -/+tau (15/-15)"
raise NotImplementedError(error_str)

mu_def = mu_def_builder.build()

if (config_file == 'SouthPole'):
config_file_full_path = os.path.join(os.path.dirname(__file__), 'config_PROPOSAL.json')
elif (config_file == 'MooresBay'):
config_file_full_path = os.path.join(os.path.dirname(__file__), 'config_PROPOSAL_mooresbay.json')
elif (config_file == 'InfIce'):
config_file_full_path = os.path.join(os.path.dirname(__file__), 'config_PROPOSAL_infice.json')
elif (config_file == 'Greenland'):
config_file_full_path = os.path.join(os.path.dirname(__file__), 'config_PROPOSAL_greenland.json')
elif (os.path.exists(config_file)):
config_file_full_path = config_file
else:
raise ValueError("Proposal config file is not valid. Please provide a valid option.")

if not os.path.exists(config_file_full_path):
error_message = "Proposal config file does not exist.\n"
error_message += "Please provide valid paths for the interpolation tables "
error_message += "in file {}.sample ".format(config_file_full_path)
error_message += "and copy the file to {}.".format(os.path.basename(config_file_full_path))
raise ValueError(error_message)

check_path_to_tables(config_file_full_path)

propagator = pp.Propagator(particle_def=mu_def, config_file=config_file_full_path)

return propagator
if(particle_code not in self.__propagators):
self.__logger.info(f"initializing propagator for particle code {particle_code}")
mu_def_builder = pp.particle.ParticleDefBuilder()
if (particle_code == 13):
mu_def_builder.SetParticleDef(pp.particle.MuMinusDef())
elif (particle_code == -13):
mu_def_builder.SetParticleDef(pp.particle.MuPlusDef())
elif (particle_code == 15):
mu_def_builder.SetParticleDef(pp.particle.TauMinusDef())
elif (particle_code == -15):
mu_def_builder.SetParticleDef(pp.particle.TauPlusDef())
else:
error_str = "The propagation of this particle via PROPOSAL is not currently supported.\n"
error_str += "Please choose between -/+muon (13/-13) and -/+tau (15/-15)"
raise NotImplementedError(error_str)

mu_def = mu_def_builder.build()

if (self.__config_file == 'SouthPole'):
config_file_full_path = os.path.join(os.path.dirname(__file__), 'config_PROPOSAL.json')
elif (self.__config_file == 'MooresBay'):
config_file_full_path = os.path.join(os.path.dirname(__file__), 'config_PROPOSAL_mooresbay.json')
elif (self.__config_file == 'InfIce'):
config_file_full_path = os.path.join(os.path.dirname(__file__), 'config_PROPOSAL_infice.json')
elif (self.__config_file == 'Greenland'):
config_file_full_path = os.path.join(os.path.dirname(__file__), 'config_PROPOSAL_greenland.json')
elif (os.path.exists(self.__config_file)):
config_file_full_path = self.__config_file
else:
raise ValueError("Proposal config file is not valid. Please provide a valid option.")

def __get_compact_sub_pev_losses(self,
energy_arr,
distance_arr,
compact_dist,
min_energy_loss):
r""" return biggest compact loss if above min_energy_cut
if not os.path.exists(config_file_full_path):
error_message = "Proposal config file does not exist.\n"
error_message += "Please provide valid paths for the interpolation tables "
error_message += "in file {}.sample ".format(config_file_full_path)
error_message += "and copy the file to {}.".format(os.path.basename(config_file_full_path))
raise ValueError(error_message)

This function groups energy losses along a path and groups them into a
single shower. The effect is only seen for < 10 PeV energy bins and it's
at least one order of magnitude lower than non-grouped losses, so it does
not influence that much.
check_path_to_tables(config_file_full_path)

Parameters
----------
energy_arr: array-like
energy of the energy losses below min_energy_loss, in PROPOSAL units (MeV)
distance_arr: array_like
distances of the energy losses below min_energy_loss, in PROPOSAL units (cm)
compact_dist: float
distance in centimeters (PROPOSAL units): how compact the energy losses should be
min_energy_loss: float
min energy for the sensitivity (here a PeV), in PROPOSAL units (MeV)
"""
len_bins = np.arange(distance_arr[0], distance_arr[-1] + 1e-3, 100)
# We have used 100 to create a bin length of 1 m
len_indices = np.digitize(distance_arr, len_bins)
bincount = np.bincount(len_indices, energy_arr)

if len(bincount) <= compact_dist:
sum_bins = np.sum(bincount)
if sum_bins > min_energy_loss:
return [sum_bins]
else:
return []
self.__propagators[particle_code] = pp.Propagator(particle_def=mu_def, config_file=config_file_full_path)

# We transform the compact_dist into meters, since the above histogram
# has a bin length of 1 m
convolved_comp_arr = np.convolve(np.ones(int(compact_dist / pp_m)), bincount, mode='valid')
if np.any(convolved_comp_arr > min_energy_loss):
return [np.max(convolved_10m_arr)]
else:
return []
return self.__propagators[particle_code]

def __produces_shower(self,
particle,
Expand Down Expand Up @@ -499,8 +449,7 @@ def __propagate_particle(self,
lepton_position,
lepton_direction,
propagation_length,
low=1 * pp_PeV,
decay_muon=False):
low=1 * pp_PeV):
"""
Calculates secondary particles using a PROPOSAL propagator. It needs to
be given a propagators dictionary with particle codes as key
Expand Down Expand Up @@ -543,15 +492,9 @@ def __propagate_particle(self,
initial_condition.energy = energy_lepton
initial_condition.propagated_distance = 0

if not decay_muon:
secondaries = self.propagators[lepton_code].propagate(initial_condition,
secondaries = self.__get_propagator(lepton_code).propagate(initial_condition,
propagation_length,
minimal_energy=low).particles
else:
secondaries = self.mu_propagators[lepton_code].propagate(initial_condition,
propagation_length,
minimal_energy=low).particles

return secondaries

def __filter_secondaries(self,
Expand Down Expand Up @@ -624,10 +567,12 @@ def get_secondaries_array(self,
Array containing the lepton directions, normalised to 1
low_nu: float
Low energy limit for the propagating particle in NuRadioMC units (eV)
controls the minimum energy of the particle. Below this energy, the propagated particle will be discarded
propagation_length_nu: float
Maximum propagation length in NuRadioMC units (m)
min_energy_loss_nu: float
Minimum energy for a selected secondary-induced shower (eV)
controls the minimum energy a secondary shower must have to be returned and saved in an event file
propagate_decay_muons: bool
If True, muons created by tau decay are propagated and their induced
showers are stored
Expand Down Expand Up @@ -722,7 +667,7 @@ def get_secondaries_array(self,
continue
mu_energy, mu_code, mu_position, mu_direction = decay_muon
mu_secondaries = self.__propagate_particle(mu_energy, mu_code, mu_position, mu_direction,
propagation_length, low=low, decay_muon=True)
propagation_length, low=low)

mu_shower_inducing_prods = self.__filter_secondaries(mu_secondaries, min_energy_loss, lepton_position)

Expand Down
15 changes: 5 additions & 10 deletions NuRadioMC/EvtGen/generate_cylinder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from NuRadioMC.EvtGen.generator import generate_eventlist_cylinder
from NuRadioReco.utilities import units
import argparse
import logging
logger = logging.getLogger("EventGen")
logging.basicConfig()
logger.setLevel(logging.INFO)

if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Generate input data files using forced event generator for cylinder geometry')
Expand Down Expand Up @@ -57,13 +61,9 @@
* 'GZK-1': GZK neutrino flux model from van Vliet et al., 2019, https://arxiv.org/abs/1901.01899v1 for
10 percent proton fraction (see get_GZK_1 function for details)
* 'GZK-1+IceCube-nu-2017': a combination of the cosmogenic (GZK-1) and astrophysical (IceCube nu 2017) flux""")
parser.add_argument('--add_tau_second_bang', type=bool, default=False,
help='if True simulate second vertices from tau decays')
parser.add_argument('--tabulated_taus', type=bool, default=True,
help='if True the tau decay properties are taken from a table')
parser.add_argument('--deposited', type=bool, default=False,
help='if True, generate deposited energies instead of primary neutrino energies')
parser.add_argument('--proposal', type=bool, default=False,
parser.add_argument('--proposal', default=False, action='store_true',
help='if integer, PROPOSAL generates a number of propagations equal to resample and then reuses them. Only to be used with a single kind of lepton (muon or tau)')
parser.add_argument('--proposal_config', type=str, default="SouthPole",
help="""The user can specify the path to their own config file or choose among
Expand All @@ -82,8 +82,6 @@
If one of these three options is chosen, the user is supposed to edit
the corresponding config_PROPOSAL_xxx.json.sample file to include valid
table paths and then copy this file to config_PROPOSAL_xxx.json.""")
parser.add_argument('--resample', type=int, default=None,
help='if True the tau decay properties are taken from a table')
parser.add_argument('--start_file_id', type=int, default=0,
help="in case the data set is distributed over several files, this number specifies the id of the first file (useful if an existing data set is extended)")
args = parser.parse_args()
Expand All @@ -97,10 +95,7 @@
args.flavor,
args.n_events_per_file,
args.spectrum,
args.add_tau_second_bang,
args.tabulated_taus,
args.deposited,
args.proposal,
args.proposal_config,
args.resample,
args.start_file_id)