From d0ec2be2b676eef829ab337c52eb593bf3faddd2 Mon Sep 17 00:00:00 2001 From: Austin Schneider Date: Tue, 23 Jan 2024 18:59:09 -0700 Subject: [PATCH] Fix Example2 --- python/_util.py | 17 +++++++++++------ .../materials/CCM/{CCM.dat => CCM-v1.dat} | 0 .../Examples/Example2/DipolePortal_CCM.py | 18 +++++++++--------- 3 files changed, 20 insertions(+), 15 deletions(-) rename resources/Detectors/materials/CCM/{CCM.dat => CCM-v1.dat} (100%) diff --git a/python/_util.py b/python/_util.py index d3daea3a..015db0cf 100644 --- a/python/_util.py +++ b/python/_util.py @@ -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 @@ -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( @@ -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] diff --git a/resources/Detectors/materials/CCM/CCM.dat b/resources/Detectors/materials/CCM/CCM-v1.dat similarity index 100% rename from resources/Detectors/materials/CCM/CCM.dat rename to resources/Detectors/materials/CCM/CCM-v1.dat diff --git a/resources/Examples/Example2/DipolePortal_CCM.py b/resources/Examples/Example2/DipolePortal_CCM.py index 0702c219..889371f4 100644 --- a/resources/Examples/Example2/DipolePortal_CCM.py +++ b/resources/Examples/Example2/DipolePortal_CCM.py @@ -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 @@ -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) @@ -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 @@ -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'])) \ No newline at end of file +controller.SaveEvents('output/CCM_Dipole_M%2.2f_mu%2.2e_example.hdf5'%(model_kwargs['m4'],model_kwargs['mu_tr_mu4']))