Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

refactor #363 #376

Merged
Merged

Conversation

JoranAngevaare
Copy link
Contributor

Fix a few problems and testing for #363

@JoranAngevaare JoranAngevaare marked this pull request as ready for review May 29, 2022 09:41

st = strax.Context(
storage=tempdir,
config=dict(
nchunk=2, event_rate=1, chunk_size=1,
detector='XENON1T',
fax_config=('https://raw.githubusercontent.com/XENONnT/strax_auxiliary_files'
'/36d352580b328ff057b1588b8af8c9a6ed8ae704/sim_files/fax_config_1t.json'), # noqa
'/a5b92102505d6d0bfcdb563b6117bd4040a93435/sim_files/fax_config_1t.json'), # noqa
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

important to get the latest version

fax_config_override=dict(
url_base=("https://raw.githubusercontent.com/XENONnT/strax_auxiliary_files"
"/36d352580b328ff057b1588b8af8c9a6ed8ae704/sim_files/"), ),
"/a5b92102505d6d0bfcdb563b6117bd4040a93435/sim_files/"),
**conf_1t,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and update with the test in the load-resource test


@skipIf(not straxen.utilix_is_configured(), 'utilix is not configured')
def test_sim_nt_advanced(
config = None
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should always test the default config - this wasn't done before

Comment on lines -124 to -129
st.set_config({'fax_config_override': dict(s2_luminescence_model='simple',
s2_time_model="s2_time_spread around zero",
s1_lce_correction_map='XENONnT_s1_xyz_LCE_corrected_qes_MCva43fa9b_wires.json.gz',
s1_time_spline='XENONnT_s1_proponly_va43fa9b_wires_20200625.json.gz',
s1_model_type='optical_propagation+simple',)})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add this in a separate test

Comment on lines +139 to +177
@skipIf(not straxen.utilix_is_configured(), 'utilix is not configured')
def test_nt_advanced_alt_s2_model():
config = dict(
fax_config_override=dict(
s2_luminescence_model='simple',
s2_time_model="s2_time_spread around zero",
s1_lce_correction_map='XENONnT_s1_xyz_LCE_corrected_qes_MCva43fa9b_wires.json.gz',
s1_time_spline='XENONnT_s1_proponly_va43fa9b_wires_20200625.json.gz',
s1_model_type='optical_propagation+simple',
)
)
test_sim_nt_advanced(config)


@skipIf(not straxen.utilix_is_configured(), 'utilix is not configured')
def test_nt_advanced_garfield():
config = dict(
fax_config_override=dict(
s2_luminescence_model='garfield',
s2_correction_map=False,
s2_time_model="s2_time_spread around zero",
s1_lce_correction_map='XENONnT_s1_xyz_LCE_corrected_qes_MCva43fa9b_wires.json.gz',
s1_time_spline='XENONnT_s1_proponly_va43fa9b_wires_20200625.json.gz',
s1_model_type='optical_propagation+simple',
)
)
test_sim_nt_advanced(config)

@skipIf(not straxen.utilix_is_configured(), 'utilix is not configured')
def test_nt_advanced_gas_gap_garfield():
config = dict(
fax_config_override=dict(
s2_luminescence_model='garfield_gas_gap',
s2_correction_map="XENONnT_s2_xy_map_v4_210503_mlp_3_in_1_iterated.json",
s2_luminescence_gg= "garfield_timing_map_gas_gap_sr0.npy",
garfield_gas_gap_map= "garfield_gas_gap_map_sr0.json",
se_gain_map="XENONnT_se_xy_map_v1_mlp.json",
)
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bunch of older test configurations that we should keep supporting

@@ -455,7 +457,7 @@ def digitizer_saturation(data, channel_mask):
@export
class RawDataOptical(RawData):

def __init__(self, config, channels=[], timings=[]):
def __init__(self, config, channels=tuple(), timings=tuple()):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having mutable default is an absolutely disastrous idea

wfsim/core/s2.py Outdated Show resolved Hide resolved
Comment on lines -235 to -243
if ('ext_eff_from_map' not in config):
cy = electron_lifetime_correction*config['electron_extraction_yield']
else:
if config['ext_eff_from_map'] == False:
cy = electron_lifetime_correction*config['electron_extraction_yield']
else:
# Extraction efficiency is g2(x,y)/SE_gain(x,y)
cy = config['g2_mean']*resource.s2_correction_map(xy_int)*\
electron_lifetime_correction/resource.se_gain_map(xy_int)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looked a bit convoluted

Comment on lines -296 to +309
s2_luminescence_map = straxen.get_resource(files['s2_luminescence'], fmt='npy')
self.s2_luminescence = s2_luminescence_map

gf_file_name = files['s2_luminescence']
if gf_file_name.endswith('npy'):
s2_luminescence_map = straxen.get_resource(gf_file_name, fmt='npy')
self.s2_luminescence = s2_luminescence_map
elif gf_file_name.endswith('npz'):
# Backwards compatibility from before #363 / #370
s2_luminescence_map = straxen.get_resource(gf_file_name, fmt='npy_pickle')['arr_0']
# Get directly the map for the simulated level
liquid_level_available = np.unique(s2_luminescence_map['ll']) # available levels (cm)
liquid_level = config['gate_to_anode_distance'] - config['elr_gas_gap_length'] # cm
liquid_level = min(liquid_level_available, key=lambda x: abs(x - liquid_level))
self.s2_luminescence = s2_luminescence_map[s2_luminescence_map['ll'] == liquid_level]
else:
raise ValueError(f'{gf_file_name} is of unknown format')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is why the tests kept failing

Comment on lines +96 to +98
def __init__(self, config=None):
if config is None:
config = {}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mutable defaults strike again

@JYangQi00
Copy link
Contributor

Hi Joran,

Thank you for checking these tests, I really appreciate it!

@JYangQi00 JYangQi00 merged commit 5f15d84 into xy_gain_extraction_eff_updat May 30, 2022
@JoranAngevaare JoranAngevaare deleted the xy_gain_extraction_eff_refactor branch May 30, 2022 07:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants