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

Commit

Permalink
Load MC pattern map if no data-driven LCE map provided (#241)
Browse files Browse the repository at this point in the history
* Update load_resource.py

Change afterpulse loading file format to pkl (because thats the file format...)

* if no lce map load the pattermap

* fix

* There was an oops

* fix oops

* Add squeeze

* Update load_resource.py

Co-authored-by: petergaemers <petergamers@hotmail.com>
Co-authored-by: ramirezdiego <diego.ramirez@physik.uni-freiburg.de>
  • Loading branch information
3 people authored Oct 29, 2021
1 parent 860ca5f commit efb9b63
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 7 additions & 0 deletions wfsim/core/s1.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,16 @@ def get_n_photons(n_photons, positions, s1_lce_correction_map, config):
return array with number photons"""
ly = s1_lce_correction_map(positions)
# depending on if you use the data driven or mc pattern map for light yield
#the shape of n_photon_hits will change. Mc needs a squeeze
if len(ly.shape)!=1:
ly=np.squeeze(ly,axis=-1)
ly /= 1 + config['p_double_pe_emision']
ly *= config['s1_detection_efficiency']


n_photon_hits = np.random.binomial(n=n_photons, p=ly)

return n_photon_hits

@staticmethod
Expand Down
14 changes: 13 additions & 1 deletion wfsim/load_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ def get_file_path(base, fname):
cache files that might not be updated with the latest github commit.
"""
if not fname:
log.warning(f"A file has value False, assuming this is intentional.")
return

if fname.startswith('/'):
log.warning(f"Using local file {fname} for a resource. "
f"Do not set this as a default or TravisCI tests will break")
Expand Down Expand Up @@ -226,10 +230,18 @@ def __init__(self, config=None):

elif config.get('detector', 'XENONnT') == 'XENONnT':
self.s1_pattern_map = make_map(files['s1_pattern_map'], fmt='pkl')
self.s1_lce_correction_map = make_map(files['s1_lce_correction_map'])
self.s2_pattern_map = make_map(files['s2_pattern_map'], fmt='pkl')
self.s2_correction_map = make_map(files['s2_correction_map'])

#if there is a (data driven!) map, load it. If not make it from the pattern map
if files['s1_lce_correction_map']:
self.s1_lce_correction_map = make_map(files['s1_lce_correction_map'])
else:
lymap = deepcopy(self.s1_pattern_map)
lymap.data['map'] = np.sum(lymap.data['map'][:][:][:], axis=3, keepdims=True)
lymap.__init__(lymap.data)
self.s1_lce_correction_map = lymap

# Garfield luminescence timing samples
if config.get('s2_luminescence_model', False) == 'garfield':
s2_luminescence_map = straxen.get_resource(files['s2_luminescence'], fmt='npy_pickle')['arr_0']
Expand Down

0 comments on commit efb9b63

Please sign in to comment.