Skip to content

Commit

Permalink
Merge pull request #151 from DUNE/revert-150-develop-w-noise-filter
Browse files Browse the repository at this point in the history
Revert "add noise filter features to develop. Code from feature-noise-filter …"
  • Loading branch information
YifanC authored Dec 2, 2024
2 parents 139be8a + 844fd43 commit ce46ec7
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 338 deletions.
Binary file removed data/proto_nd_flow/filter_model_pars.pkl
Binary file not shown.
292 changes: 0 additions & 292 deletions src/proto_nd_flow/reco/charge/calib_noise_filter.py

This file was deleted.

43 changes: 25 additions & 18 deletions src/proto_nd_flow/reco/charge/calib_prompt_hits.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,10 @@ class CalibHitBuilder(H5FlowStage):
x f8, pixel x location [cm]
y f8, pixel y location [cm]
z f8, pixel z location [cm]
t_drift u8, drift time [ticks???]
ts_pps f8, PPS packet timestamp [ns]
t_drift u8, drift time [tick = 100ns]
ts_pps f8, PPS packet timestamp [tick = 100ns]
io_group u8, io group ID (PACMAN number)
io_channel u8, io channel ID (related to PACMAN number & PACMAN UART Number)
chip_id u8, chip_id on tile
channel_id u8, channel_id on single chip (0-63)
Q f8, hit charge [ke-]
E f8, hit energy [MeV]
Expand All @@ -88,8 +86,6 @@ class CalibHitBuilder(H5FlowStage):
('ts_pps', 'u8'),
('io_group', 'u8'),
('io_channel', 'u8'),
('chip_id', 'u8'),
('channel_id', 'u8'),
('Q', 'f8'),
('E', 'f8')
])
Expand All @@ -106,6 +102,11 @@ def __init__(self, **params):
self.t0_dset_name = params.get('t0_dset_name')
self.pedestal_file = params.get('pedestal_file', '')
self.configuration_file = params.get('configuration_file', '')
self.pedestal_mv = params.get('pedestal_mv', 580.0)
self.vref_mv = params.get('vref_mv', 1568.0)
self.vcm_mv = params.get('vcm_mv', 478.1)
self.adc_counts = params.get('adc_counts', 256)
self.gain = params.get('gain', 4.522)

def init(self, source_name):
super(CalibHitBuilder, self).init(source_name)
Expand All @@ -120,6 +121,7 @@ def run(self, source_name, source_slice, cache):
if resources['RunData'].is_mc:
packet_frac_bt = cache['packet_frac_backtrack']
packet_seg_bt = cache['packet_seg_backtrack']

t0_data = cache[self.t0_dset_name]
raw_hits = cache[self.raw_hits_dset_name]

Expand Down Expand Up @@ -215,12 +217,19 @@ def run(self, source_name, source_slice, cache):
+ packets_arr['chip_id'].astype(int)*100
+ packets_arr['channel_id'].astype(int))
hit_uniqueid_str = hit_uniqueid.astype(str)
vref = np.array(
[self.configuration[unique_id]['vref_mv'] for unique_id in hit_uniqueid_str])
vcm = np.array([self.configuration[unique_id]['vcm_mv']
for unique_id in hit_uniqueid_str])
ped = np.array([self.pedestal[unique_id]['pedestal_mv']
for unique_id in hit_uniqueid_str])
if self.configuration_file != '':
vref = np.array(
[self.configuration[unique_id]['vref_mv'] for unique_id in hit_uniqueid_str])
vcm = np.array([self.configuration[unique_id]['vcm_mv']
for unique_id in hit_uniqueid_str])
else:
vref = np.full(len(hit_uniqueid_str), self.vref_mv)
vcm = np.full(len(hit_uniqueid_str), self.vcm_mv)
if self.pedestal_file != '':
ped = np.array([self.pedestal[unique_id]['pedestal_mv']
for unique_id in hit_uniqueid_str])
else:
ped = np.full(len(hit_uniqueid_str), self.pedestal_mv)
calib_hits_arr['id'] = calib_hits_slice.start + np.arange(n, dtype=int)
calib_hits_arr['x'] = x
if has_mc_truth:
Expand All @@ -231,14 +240,12 @@ def run(self, source_name, source_slice, cache):
calib_hits_arr['t_drift'] = drift_t
calib_hits_arr['io_group'] = packets_arr['io_group']
calib_hits_arr['io_channel'] = packets_arr['io_channel']
calib_hits_arr['chip_id'] = packets_arr['chip_id']
calib_hits_arr['channel_id'] = packets_arr['channel_id']
hits_charge = self.charge_from_dataword(packets_arr['dataword'],vref,vcm,ped) # ke-
hits_charge = self.charge_from_dataword(packets_arr['dataword'], vref, vcm, ped, self.adc_counts, self.gain) # ke-
calib_hits_arr['Q'] = hits_charge # ke-
#FIXME supply more realistic dEdx in the recombination; also apply measured electron lifetime
calib_hits_arr['E'] = hits_charge * (1000 * units.e) / resources['LArData'].ionization_recombination(mode=2,dEdx=2) * (resources['LArData'].ionization_w / units.MeV) # MeV
if has_mc_truth:
true_recomb = resources['LArData'].ionization_recombination(mode=1,dEdx=packet_seg_bt_arr['dEdx'])
true_recomb = resources['LArData'].ionization_recombination(mode=2,dEdx=packet_seg_bt_arr['dEdx'])
calib_hits_arr['E_true_recomb_elife'] = np.divide(hits_charge.reshape((hits_charge.shape[0],1)) * (1000 * units.e), true_recomb, out=np.zeros_like(true_recomb), where=true_recomb!=0) / resources['LArData'].charge_reduction_lifetime(t_drift=drift_t_true) * (resources['LArData'].ionization_w / units.MeV) # MeV

# if back tracking information was available, write the merged back tracking
Expand Down Expand Up @@ -272,8 +279,8 @@ def run(self, source_name, source_slice, cache):


@staticmethod
def charge_from_dataword(dw, vref, vcm, ped):
return (dw / 256. * (vref - vcm) + vcm - ped) / 4. # hardcoding 4 mV/ke- conv.
def charge_from_dataword(dw, vref, vcm, ped, adc_counts, gain):
return (dw / adc_counts * (vref - vcm) + vcm - ped) / gain

def load_pedestals(self):
if self.pedestal_file != '' and not resources['RunData'].is_mc:
Expand Down
Loading

0 comments on commit ce46ec7

Please sign in to comment.