Skip to content

Commit

Permalink
Added in temp drift map
Browse files Browse the repository at this point in the history
  • Loading branch information
josh0-jrg committed Sep 24, 2024
1 parent 14dc585 commit a4f9609
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
29 changes: 24 additions & 5 deletions flamedisx/nest/lxe_blocks/energy_spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,31 @@
export, __all__ = fd.exporter()
o = tf.newaxis


def apply_drift_map(data,drift_map,s2x_map,z_topDrift,drift_velocity):
#Replace with drift-time map
if drift_map is not None:
print("using drift-map")
data['drift_time']=drift_map(np.array([data['r'],data['z']]).T)
elif s2x_map is not None:
#leave this in for now
print("using S2x map")
costheta=data['x']/data['r']
sinetheta=data['y']/data['r']
data['s2x']=drift_map(np.array([data['r'],data['z']]).T)
data['x']=data['s2x']*costheta
data['y']=data['s2x']*sinetheta
else:
print("using linear relation")
data['drift_time'] = (z_topDrift-data['z']) / drift_velocity
return data
@export
class EnergySpectrum(fd.FirstBlock):
dimensions = ('energy',)
model_attributes = (
'energies',
'radius', 'z_top', 'z_bottom', 'z_topDrift',
'drift_velocity',
't_start', 't_stop')
't_start', 't_stop','drift_map')

# The default boundaries are at points where the WIMP wind is at its
# average speed.
Expand All @@ -32,6 +48,8 @@ class EnergySpectrum(fd.FirstBlock):
# Just a dummy 0-10 keV spectrum
energies = tf.cast(tf.linspace(0., 10., 1000),
dtype=fd.float_type())
#drift map variabls
drift_map=None

def domain(self, data_tensor):
assert isinstance(self.energies, tf.Tensor) # see WIMPsource for why
Expand Down Expand Up @@ -114,7 +132,8 @@ def draw_positions(self, n_events, **params):
size=n_events)
data['x'], data['y'] = fd.pol_to_cart(data['r'], data['theta'])

data['drift_time'] = (self.z_topDrift-data['z']) / self.drift_velocity
#Replace with drift-time map
data=apply_drift_map(data,self.drift_map,None,self.z_topDrift, self.drift_velocity)
return data

def draw_time(self, n_events, **params):
Expand Down Expand Up @@ -190,7 +209,7 @@ def validate_fix_truth(self, d):
else:
raise ValueError("When fixing position, give (x, y, z), "
"or (r, theta, z).")
d['drift_time'] = (self.z_topDrift-d['z']) / self.drift_velocity
data=apply_drift_map(data,self.drift_map,None,self.z_topDrift, self.drift_velocity)
elif 'event_time' not in d and 'energy' not in d:
# Neither position, time, nor energy given
raise ValueError(f"Dict should contain at least ['x', 'y', 'z'] "
Expand Down Expand Up @@ -348,7 +367,7 @@ def draw_positions(self, n_events, **params):
else:
data['r'], data['theta'] = fd.cart_to_pol(data['x'], data['y'])

data['drift_time'] = (self.z_topDrift-data['z']) / self.drift_velocity
data=apply_drift_map(data,self.drift_map,None,self.z_topDrift, self.drift_velocity)
return data


Expand Down
10 changes: 8 additions & 2 deletions flamedisx/nest/lxe_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

import flamedisx as fd
from .. import nest as fd_nest

import numpy as np
from scipy import interpolate
import math as m
pi = tf.constant(m.pi)

Expand All @@ -21,8 +22,13 @@


class nestSource(fd.BlockModelSource):
def __init__(self, *args, detector='default', **kwargs):
def __init__(self, *args, detector='default',drift_map_path=None, **kwargs):
assert detector in ('default', 'lz','lz_SR3')

if drift_map_path is not None:
print("Loading in Drift map:\n",drift_map_path)
drift_map=np.loadtxt(drift_map_path,delimiter=',').T
self.drift_map=interpolate.LinearNDInterpolator(drift_map[:2].T/10,drift_map[3]*1e3)

self.detector = detector

Expand Down

0 comments on commit a4f9609

Please sign in to comment.