Skip to content

Commit 90fa9bd

Browse files
authored
Merge pull request #213 from DUNE/feature/calibration_inputs
Feature/calibration inputs
2 parents f177862 + e6e1df6 commit 90fa9bd

File tree

5 files changed

+306
-15
lines changed

5 files changed

+306
-15
lines changed

data/fsd_flow/lifetime.json

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
{
2+
"2024_11_06_20_55_32": [
3+
1.577277961042115,
4+
0.039806122461080486
5+
],
6+
"2024_11_06_21_59_59": [
7+
1.630257417897641,
8+
0.060374535457603316
9+
],
10+
"2024_11_06_23_04_24": [
11+
1.5853578479039832,
12+
0.042003642358984274
13+
],
14+
"2024_11_07_00_26_34": [
15+
1.500368177399003,
16+
0.04899574088667156
17+
],
18+
"2024_11_07_02_21_14": [
19+
1.5516842540097127,
20+
0.07009934137861634
21+
],
22+
"2024_11_07_04_35_05": [
23+
1.6406250102988174,
24+
0.03599917189004143
25+
],
26+
"2024_11_07_06_37_38": [
27+
1.6571450972492676,
28+
0.06363941309041149
29+
],
30+
"2024_11_07_08_43_57": [
31+
1.5709722400705348,
32+
0.0307359356082764
33+
],
34+
"2024_11_07_11_02_02": [
35+
1.6262445181691392,
36+
0.045404820201034375
37+
],
38+
"2024_11_07_13_11_16": [
39+
1.4950807193448195,
40+
0.036400811777294075
41+
],
42+
"2024_11_07_01_07_43": [
43+
1.570008766443589,
44+
0.04737095826666833
45+
],
46+
"2024_11_07_03_25_58": [
47+
1.6082747206364676,
48+
0.04007799025276755
49+
],
50+
"2024_11_07_05_24_07": [
51+
1.630841375439514,
52+
0.047182519657849295
53+
],
54+
"2024_11_07_07_43_54": [
55+
1.6292324602523904,
56+
0.04177709377111918
57+
],
58+
"2024_11_07_09_57_01": [
59+
1.5929639688252348,
60+
0.049151185416101105
61+
],
62+
"2024_11_07_11_51_28": [
63+
1.6238702009706794,
64+
0.04537931003022776
65+
],
66+
"2024_11_07_16_24_02": [
67+
1.6419342787452582,
68+
0.05502680652309337
69+
],
70+
"2024_11_07_20_27_01": [
71+
1.616114968200223,
72+
0.03679999435261566
73+
],
74+
"2024_11_07_21_34_40": [
75+
1.6099670407403148,
76+
0.038230507088728875
77+
],
78+
"2024_11_07_22_39_53": [
79+
1.585377422503604,
80+
0.035265838031508914
81+
],
82+
"2024_11_08_00_30_44": [
83+
1.6184503621583408,
84+
0.034141317893890785
85+
],
86+
"2024_11_08_01_35_09": [
87+
1.625042022115719,
88+
0.04212317803615335
89+
],
90+
"2024_11_08_02_39_54": [
91+
1.604523882603167,
92+
0.04524559552428178
93+
],
94+
"2024_11_08_03_44_38": [
95+
1.5646922311686682,
96+
0.045351548122790526
97+
],
98+
"2024_11_08_04_48_54": [
99+
1.6400675758215202,
100+
0.03768485119093251
101+
],
102+
"2024_11_08_05_53_31": [
103+
1.5998737680152453,
104+
0.048880581388980326
105+
],
106+
"2024_11_08_07_00_05": [
107+
1.6299924169104059,
108+
0.042682266923110786
109+
],
110+
"2024_11_08_08_05_58": [
111+
1.5591984844277502,
112+
0.04211444849824356
113+
],
114+
"2024_11_08_09_10_14": [
115+
1.6327919889030924,
116+
0.05317970260903283
117+
],
118+
"2024_11_08_10_14_40": [
119+
1.6368205904512052,
120+
0.04418198597933583
121+
],
122+
"2024_11_08_11_19_27": [
123+
1.5958678809456843,
124+
0.04557640477048005
125+
],
126+
"2024_11_08_12_24_07": [
127+
1.6347246586346225,
128+
0.049934056996716776
129+
],
130+
"2024_11_08_13_28_43": [
131+
1.6907337097854191,
132+
0.03560988428380175
133+
],
134+
"2024_11_08_14_33_40": [
135+
1.6100677076101246,
136+
0.047141830050953175
137+
],
138+
"2024_11_08_15_38_32": [
139+
1.6794184754286599,
140+
0.04967743258378785
141+
],
142+
"2024_11_08_16_51_09": [
143+
1.6624719172847522,
144+
0.049215116807065015
145+
],
146+
"2024_11_08_18_03_27": [
147+
1.654758282925744,
148+
0.051042003320451924
149+
],
150+
"2024_11_08_19_07_44": [
151+
1.6600112086003227,
152+
0.043714078417970335
153+
],
154+
"2024_11_08_20_11_53": [
155+
1.6676791821790498,
156+
0.04279217250800042
157+
],
158+
"2024_11_08_21_16_11": [
159+
1.6415737744885077,
160+
0.049255573223597644
161+
],
162+
"2024_11_08_22_20_25": [
163+
1.6697372501345074,
164+
0.060468115359432154
165+
],
166+
"2024_11_08_23_24_54": [
167+
1.595071244920473,
168+
0.042124321805340356
169+
],
170+
"2024_11_09_00_32_22": [
171+
1.7114850562460737,
172+
0.05252266888996385
173+
],
174+
"2024_11_09_01_37_16": [
175+
1.649074300314467,
176+
0.05684512770605545
177+
],
178+
"2024_11_09_02_42_04": [
179+
1.6338198556637782,
180+
0.04597631215509739
181+
],
182+
"2024_11_09_03_46_47": [
183+
1.5792600148695335,
184+
0.04254210789783654
185+
],
186+
"2024_11_09_04_51_05": [
187+
1.701027188810814,
188+
0.0707039427192136
189+
],
190+
"2024_11_09_05_54_52": [
191+
1.6012440885116588,
192+
0.03437063462614836
193+
],
194+
"2024_11_09_06_58_33": [
195+
1.5698298477917767,
196+
0.04130956019874265
197+
],
198+
"2024_11_09_13_03_45": [
199+
1.682382580027364,
200+
0.03269562588932695
201+
],
202+
"2024_11_09_20_28_00": [
203+
1.6108841492187151,
204+
0.032392970707146855
205+
]
206+
}

src/proto_nd_flow/reco/charge/calib_prompt_hits.py

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,15 @@ def __init__(self, **params):
103103
self.packets_index_name = params.get('packets_index_name', self.packets_dset_name + '_index')
104104
self.t0_dset_name = params.get('t0_dset_name')
105105
self.pedestal_file = params.get('pedestal_file', '')
106+
self.gain_file = params.get('gain_file', '')
106107
self.configuration_file = params.get('configuration_file', '')
107108
self.pedestal_mv = params.get('pedestal_mv', self.default_pedestal_mv)
108109
self.vref_mv = params.get('vref_mv', self.default_vref_mv)
109110
self.vcm_mv = params.get('vcm_mv', self.default_vcm_mv)
110111
self.adc_counts = params.get('adc_counts', self.default_adc_counts)
111112
self.gain = params.get('gain', self.default_gain)
112113
self.adc_droop_calibration = params.get('adc_droop_calibration', False)
114+
self.elifetime_calibration = params.get('elifetime_calibration',False)
113115
self.hit_ref = params.get('hit_ref', True)
114116

115117
#: ASIC ADC configuration lookup table
@@ -123,9 +125,14 @@ def __init__(self, **params):
123125
pedestal_mv=self.pedestal_mv
124126
))
125127

128+
self.gains = defaultdict(lambda : dict(
129+
gain=self.gain
130+
))
131+
126132
def init(self, source_name):
127133
super(CalibHitBuilder, self).init(source_name)
128134
self.load_pedestals()
135+
self.load_gains()
129136
self.load_configurations()
130137

131138
def run(self, source_name, source_slice, cache):
@@ -172,6 +179,7 @@ def run(self, source_name, source_slice, cache):
172179
packets_dset=self.packets_dset_name,
173180
t0_dset=self.t0_dset_name,
174181
pedestal_file=self.pedestal_file,
182+
gain_file=self.gain_file,
175183
configuration_file=self.configuration_file,
176184
adc_droop_calibration=self.adc_droop_calibration
177185
)
@@ -236,9 +244,13 @@ def run(self, source_name, source_slice, cache):
236244
# This time we add the rollover period instead of subtracting.
237245
drift_t[after_sync_mask] += resources['RunData'].rollover_ticks
238246

239-
drift_d = drift_t * (resources['LArData'].v_drift * resources['RunData'].crs_ticks) / units.cm # convert mm -> cm
247+
v_drift_arr = resources['LArData'].v_drift
248+
if len(v_drift_arr) == 1:
249+
v_drift = v_drift_arr[0] #Default vdrift
250+
else :
251+
v_drift = v_drift_arr[(packets_arr['io_group']-1)//2]
252+
drift_d = drift_t * (v_drift * resources['RunData'].crs_ticks) / units.cm # convert mm -> cm
240253
x = resources['Geometry'].get_drift_coordinate(packets_arr['io_group'],packets_arr['io_channel'],drift_d)
241-
242254
## true drift position pair
243255
#if has_mc_truth:
244256
# drift_t_true = packet_seg_bt_arr['t'] #us
@@ -265,6 +277,11 @@ def run(self, source_name, source_slice, cache):
265277
for unique_id in hit_uniqueid_str])
266278
else:
267279
ped = np.full(len(hit_uniqueid_str), self.pedestal_mv)
280+
if self.gain_file != '':
281+
gain = np.array([self.gains[unique_id]['gain'] for unique_id in hit_uniqueid_str])
282+
else:
283+
gain = np.full(len(hit_uniqueid_str), self.gain)
284+
268285
calib_hits_arr['id'] = calib_hits_slice.start + np.arange(n, dtype=int)
269286
calib_hits_arr['x'] = x
270287
#if has_mc_truth:
@@ -277,16 +294,20 @@ def run(self, source_name, source_slice, cache):
277294
calib_hits_arr['io_channel'] = packets_arr['io_channel']
278295
calib_hits_arr['chip_id'] = packets_arr['chip_id']
279296
calib_hits_arr['channel_id'] = packets_arr['channel_id']
280-
hits_charge = self.charge_from_dataword(packets_arr['dataword'], vref, vcm, ped, self.adc_counts, self.gain) # ke-
297+
hits_charge = self.charge_from_dataword(packets_arr['dataword'], vref, vcm, ped, self.adc_counts, gain) # ke-
281298
calib_hits_arr['Q_raw'] = hits_charge # ke-
282299
if self.adc_droop_calibration:
283-
hits_charge_calibrated = self.charge_from_dataword_corrected(packets_arr['dataword'], packets_arr['timestamp'], hit_uniqueid, vref, vcm, ped, self.adc_counts, self.gain) # ke-
284-
calib_hits_arr['Q'] = hits_charge_calibrated # ke-
300+
hits_charge_calibrated = self.charge_from_dataword_corrected(packets_arr['dataword'], packets_arr['timestamp'], hit_uniqueid, vref, vcm, ped, self.adc_counts, gain) # ke-
301+
calib_hits_arr['Q'] = hits_charge_calibrated # ke-
285302
else:
286-
calib_hits_arr['Q'] = hits_charge
287-
303+
calib_hits_arr['Q'] = hits_charge # ke-
304+
305+
306+
288307
#FIXME supply more realistic dEdx in the recombination; also apply measured electron lifetime
289-
calib_hits_arr['E'] = calib_hits_arr['Q'] * (1000 * units.e) / resources['LArData'].ionization_recombination(mode=2,dEdx=2) * (resources['LArData'].ionization_w / units.MeV) # MeV
308+
calib_hits_arr['E'] = calib_hits_arr['Q'] * (1000 * units.e) / resources['LArData'].ionization_recombination(mode=2,dEdx=2) * (resources['LArData'].ionization_w / units.MeV) # MeV
309+
if self.elifetime_calibration:
310+
calib_hits_arr['E'] /= resources['LArData'].charge_reduction_lifetime(t_drift=(drift_t * resources['RunData'].crs_ticks )) # ke- we change the drift_t to µs
290311
#if has_mc_truth:
291312
# true_recomb = resources['LArData'].ionization_recombination(mode=2,dEdx=packet_seg_bt_arr['dEdx'])
292313
# 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
@@ -384,6 +405,12 @@ def load_pedestals(self):
384405
for key, value in json.load(infile).items():
385406
self.pedestal[key] = value
386407

408+
def load_gains(self):
409+
if self.gain_file != '':
410+
with open(self.gain_file, 'r') as infile:
411+
for key, value in json.load(infile).items():
412+
self.gains[key] = value
413+
387414
def load_configurations(self):
388415
if self.configuration_file != '' and not resources['RunData'].is_mc:
389416
with open(self.configuration_file, 'r') as infile:

0 commit comments

Comments
 (0)