Skip to content

Commit

Permalink
Fix Example2
Browse files Browse the repository at this point in the history
  • Loading branch information
austinschneider committed Jan 24, 2024
1 parent 3a92c6c commit d0ec2be
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
17 changes: 11 additions & 6 deletions python/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,11 @@ def _get_model_path(model_name, prefix=None):
model_names = [f for f in model_names if f.lower().startswith(model_name)]

if len(model_names) == 0:
raise ValueError("No model found for {}".format(model_name))
raise ValueError("No model folders found for {}\nSearched in ".format(model_name, base_dir))
elif len(model_names) == 1:
model_name = model_names[0]
else:
raise ValueError("Multiple directories found for {}".format(model_name))
raise ValueError("Multiple directories found for {}\nSearched in ".format(model_name, base_dir))

model_files = [
f
Expand All @@ -389,10 +389,15 @@ def _get_model_path(model_name, prefix=None):
for f in model_files:
d = _model_regex.match(f)
if d is not None:
model_versions.append(normalize_version(d.groupdict()["version"]))
if d.groupdict()["version"] is not None:
model_versions.append(normalize_version(d.groupdict()["version"]))
else:
raise ValueError("Input model file has no version: {}\nSearched in ".format(f, os.path.join(base_dir, model_name)))
elif f.lower().startswith(model_name.lower()):
pass
# raise ValueError("Unable to parse version from {}".format(f))
raise ValueError("Unable to parse version from {}\nFound in ".format(f, os.path.join(base_dir, model_name)))

if len(model_versions) == 0:
raise ValueError("No model found for {}\nSearched in ".format(model_name, os.path.join(base_dir, model_name)))

if version is None:
version_idx, version = max(
Expand All @@ -401,7 +406,7 @@ def _get_model_path(model_name, prefix=None):
else:
version = normalize_version(version)
if version not in model_versions:
raise ValueError("No model found for {} {}".format(model_name, version))
raise ValueError("No model found for {}-{}\nSearched in ".format(model_name, version, os.path.join(base_dir, model_name)))
version_idx = model_versions.index(version)

model_file_name = model_files[version_idx]
Expand Down
File renamed without changes.
18 changes: 9 additions & 9 deletions resources/Examples/Example2/DipolePortal_CCM.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import os
import sys
import numpy as np

import leptoninjector as LI
import sys
sys.path.insert(1,'/n/holylfs05/LABS/arguelles_delgado_lab/Everyone/nkamp/LIV2/sources/LeptonInjector/python')
from LIController import LIController

LI_SRC = os.environ.get('LEPTONINJECTOR_SRC')
from leptoninjector import _util
from leptoninjector.LIController import LIController

resources_dir = _util.resource_package_dir()

# Define a DarkNews model
# Define a DarkNews model
model_kwargs = {
'm4': 0.02,
'mu_tr_mu4': 2.5e-6, #1e-6, # GeV^-1
Expand All @@ -35,7 +35,7 @@
primary_type = LI.dataclasses.Particle.ParticleType.NuMu

# Define DarkNews Model
table_dir = LI_SRC+'/resources/CrossSectionTables/DarkNewsTables/Dipole_M%2.2f_mu%2.2e/'%(model_kwargs['m4'],model_kwargs['mu_tr_mu4'])
table_dir = os.path.join(resources_dir, "CrossSections", "DarkNewsTables", "Dipole_M%2.2f_mu%2.2e"%(model_kwargs['m4'],model_kwargs['mu_tr_mu4']))
controller.InputDarkNewsModel(primary_type,
table_dir,
model_kwargs)
Expand All @@ -50,7 +50,7 @@
primary_injection_distributions['energy'] = edist
primary_physical_distributions['energy'] = edist

# Flux normalization:
# Flux normalization:
# using the number quoted in 2105.14020, 4.74e9 nu/m^2/s / (6.2e14 POT/s) * 4*pi*20m^2 to get nu/POT
flux_units = LI.distributions.NormalizationConstant(3.76e-2)
primary_physical_distributions['flux_units'] = flux_units
Expand Down Expand Up @@ -80,4 +80,4 @@

events = controller.GenerateEvents()

controller.SaveEvents('output/CCM_Dipole_M%2.2f_mu%2.2e_example.hdf5'%(model_kwargs['m4'],model_kwargs['mu_tr_mu4']))
controller.SaveEvents('output/CCM_Dipole_M%2.2f_mu%2.2e_example.hdf5'%(model_kwargs['m4'],model_kwargs['mu_tr_mu4']))

0 comments on commit d0ec2be

Please sign in to comment.