From bbff22042b46d27ea02786c2069451e75650838b Mon Sep 17 00:00:00 2001 From: Yifan Chen Date: Sat, 14 Sep 2024 20:58:42 -0700 Subject: [PATCH] add an option of larpix fee config as a constant in yaml --- .../reco/charge/calib_prompt_hits.py | 30 +++++++++++++------ .../reco/charge/CalibHitBuilder.yaml | 6 ++++ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/proto_nd_flow/reco/charge/calib_prompt_hits.py b/src/proto_nd_flow/reco/charge/calib_prompt_hits.py index 8781107f..153c1410 100644 --- a/src/proto_nd_flow/reco/charge/calib_prompt_hits.py +++ b/src/proto_nd_flow/reco/charge/calib_prompt_hits.py @@ -102,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('pdestal_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) @@ -211,12 +216,19 @@ def run(self, source_name, source_slice, cache): + packets_arr['chip_id'].astype(int)) * 64 \ + 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: @@ -227,7 +239,7 @@ 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'] - 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 @@ -266,8 +278,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: diff --git a/yamls/proto_nd_flow/reco/charge/CalibHitBuilder.yaml b/yamls/proto_nd_flow/reco/charge/CalibHitBuilder.yaml index 0521fd98..553c504e 100644 --- a/yamls/proto_nd_flow/reco/charge/CalibHitBuilder.yaml +++ b/yamls/proto_nd_flow/reco/charge/CalibHitBuilder.yaml @@ -32,3 +32,9 @@ params: # download link: https://portal.nersc.gov/project/dune/data/Module0/TPC1+2/configFiles/datalog_2021_04_02_19_00_46_CESTevd_ped.json #configuration_file: 'data/module0_flow/evd_config_21-03-31_12-36-13.json' # download link: https://portal.nersc.gov/project/dune/data/Module0/TPC1+2/configFiles/evd_config_21-03-31_12-36-13.json + + pedestal_mv: 580.0 + vref_mv: 1568.0 #M0-like: 1300 #2x2: 1568.0 + vcm_mv: 478.1 #M0-like:288 #478.0 #2x2: 478.1 + adc_counts: 256 + gain: 4.522 #datasheet: 4 #measurement(?): 4.522