def diomira_cwf_blr(ffile, n_evt=10, plot=False): """ 1) Reads the RWF and BLR waveforms in the RWF file produced by the previous cell 2) Computes CWF files passing a blr algorithm. 3) Returns the differences (in area) between CWF and BLR """ e40rwf= tb.open_file(ffile,'r+') pmtrwf = e40rwf.root.RD.pmtrwf pmtblr = e40rwf.root.RD.pmtblr DataPMT = load_db.DataPMT(0) coeff_c = DataPMT.coeff_c.values.astype(np.double) coeff_blr = DataPMT.coeff_blr.values.astype(np.double) DIFF = [] for event in range(n_evt): if plot == True: mpl.plot_waveforms(pmtrwf[event], zoom=True, window_size=600) plt.show() # input('Raw waveforms: return to continue') mpl.plot_waveforms(pmtblr[event], zoom=True, window_size=600) plt.show() # input('BLR waveforms: return to continue') BLR = pmtblr[event] CWF = blr.deconv_pmt(pmtrwf[event], coeff_c, coeff_blr, n_baseline=28000, thr_trigger=5) if plot == True: mpl.plot_blr_cwf(pmtblr[event], CWF, zoom=True, window_size=600) plt.show() #input('BLR vs CWF waveforms: return to continue') for i, _ in enumerate(CWF): diff = abs(np.sum(BLR[i][5000:5100]) - np.sum(CWF[i][5000:5100])) diff = 100. * diff/np.sum(BLR[i]) DIFF.append(diff) return np.array(DIFF)
def load_sensors(file_names : List[str], db_file : str , run_no : int ) -> Generator[Tuple, None, None]: pmt_ids = DB.DataPMT (db_file, run_no).SensorID sipm_ids = DB.DataSiPM(db_file, run_no).SensorID for file_name in file_names: (all_evt , pmt_binwid , sipm_binwid, all_wf ) = load_mcsensor_response_df(file_name, db_file, run_no) with tb.open_file(file_name, 'r') as h5in: mc_info = tbl.get_mc_info(h5in) timestamps = event_timestamp(h5in) for evt in all_evt: pmt_wfs = all_wf.loc[evt].loc[ pmt_ids] sipm_wfs = all_wf.loc[evt].loc[sipm_ids] yield dict(evt = evt , mc = mc_info , timestamp = timestamps(), pmt_binwid = pmt_binwid , sipm_binwid = sipm_binwid , pmt_wfs = pmt_wfs , sipm_wfs = sipm_wfs )
def __init__(self): super(NEW_meta, self).__init__() # Load the database objects self._det_geo = load_db.DetectorGeo() self._pmt_data = load_db.DataPMT() self._sipm_data = load_db.DataSiPM() self.skim_det_info(self._det_geo)
def __init__(self): super(io_manager, self).__init__() # Load the database objects self._det_geo = load_db.DetectorGeo() self._pmt_data = load_db.DataPMT() self._sipm_data = load_db.DataSiPM() self._events = [] self._entry = 0 self._max_entry = 0 self._run = 5
def relative_coordinates(detector_db: str, run_number: int) -> Callable: pmt_xyphi = DB.DataPMT(detector_db, run_number)[['X', 'Y']] pmt_xyphi['phi'] = np.arctan2(pmt_xyphi.loc[:, 'Y'], pmt_xyphi.loc[:, 'X']) def get_relative_coords(x: np.ndarray, y: np.ndarray) -> Tuple: rel_r = np.sqrt((x - pmt_xyphi.X)**2 + (y - pmt_xyphi.Y)**2) rel_phi = np.abs(np.arctan2(y, x) - pmt_xyphi.phi) rel_phi[rel_phi > np.pi] = 2 * np.pi - rel_phi return rel_r, rel_phi return get_relative_coords
def main(): """ version of fft_tests.py stripped down and adapted for MC wf """ ## Filter definition fSample = 40E6 freqLPF = 100E3 freqLPFd = 2 * freqLPF / fSample b, a = signal.butter(1, freqLPFd, 'low', analog=False) ## DataPMT = load_db.DataPMT(4821) defsDone = False with load_input(sys.argv[1]) as file0: npmt = len(DataPMT.ChannelID) if not defsDone: wf_len = get_wf_len(file0) meanAbs = [ np.zeros(int(wf_len / 2 + 1), np.float64) for i in range(npmt) ] frq_plot = np.empty(int(wf_len / 2 + 1)) defsDone = True for i in range(npmt): for ievt in range(len(file0.root.RD.pmtrwf)): sg = file0.root.RD.pmtrwf[ievt][i] sg = sg - np.mean(sg) ## Filter wf sg = signal.lfilter(b, a, sg) ft = np.fft.rfft(sg) if i == 0 and ievt == 0: frq_plot = np.fft.rfftfreq(len(sg), d=25E-9) meanAbs[i] += np.abs(ft) meanAbs[i] /= len(file0.root.RD.pmtrwf) fig, axes = plt.subplots(nrows=4, ncols=3, figsize=(20, 6)) for i, (ax, row) in enumerate(zip(axes.flatten(), meanAbs)): ax.plot(frq_plot, row) ax.set_title('Mean FFT magnitude, Eid ' + str(DataPMT.ChannelID[i]) + ', Sensor ' + DataPMT.PmtID[i]) ax.set_xlim(300, 25000) plt.tight_layout() fig.show() fig.savefig('avFFTMag_simOsc2.png') input('happy with plots?')
def load_sensors(file_names: List[str], db_file: str, run_no: int) -> Generator: """ Loads the nexus MC sensor information into a pandas DataFrame using the IC function load_mcsensor_response_df. Returns info event by event in as a generator in the structure expected by the dataflow. file_names : List of strings List of input file names to be read db_file : string Name of detector database to be used run_no : int Run number for database """ pmt_ids = DB.DataPMT(db_file, run_no).SensorID sipm_ids = DB.DataSiPM(db_file, run_no).SensorID for file_name in file_names: (all_evt, pmt_binwid, sipm_binwid, all_wf) = load_mcsensor_response_df(file_name, db_file, run_no) with tb.open_file(file_name, 'r') as h5in: mc_info = tbl.get_mc_info(h5in) timestamps = event_timestamp(h5in) for evt in all_evt: pmt_wfs = all_wf.loc[evt].loc[pmt_ids] sipm_wfs = all_wf.loc[evt].loc[sipm_ids] yield dict(evt=evt, mc=mc_info, timestamp=timestamps(), pmt_binwid=pmt_binwid, sipm_binwid=sipm_binwid, pmt_wfs=pmt_wfs, sipm_wfs=sipm_wfs)
def plot_cwf_blr(ffile, event, pmt, xi=4900, xf=5200): """Draw CWF and BLR waveform togethers for selected event and pmt %. """ e40rwf= tb.open_file(ffile,'r+') pmtrwf = e40rwf.root.RD.pmtrwf pmtblr = e40rwf.root.RD.pmtblr DataPMT = load_db.DataPMT(0) coeff_c = DataPMT.coeff_c.values.astype(np.double) coeff_blr = DataPMT.coeff_blr.values.astype(np.double) CWF = blr.deconv_pmt(pmtrwf[event], coeff_c, coeff_blr, n_baseline=28000, thr_trigger=5) plt.plot(pmtblr[event,pmt][xi:xf]) plt.plot(CWF[pmt][xi:xf]) plt.show()
def s2_peak(): times = np.arange(20) * units.mus bin_widths = np.full_like(times, units.mus) pmt_ids = DB.DataPMT('new', 6400).SensorID.values sipm_ids = DB.DataSiPM('new', 6400).index.values np.random.seed(22) pmts = PMTResponses(pmt_ids, np.random.uniform(0, 100, (len(pmt_ids), len(times)))) sipms = SiPMResponses( sipm_ids, np.random.uniform(0, 10, (len(sipm_ids), len(times)))) ## Values for comparison in tests chan_slice = slice(3, 9) raw_arr = [ [ 7.51759755, 5.60509619, 6.42950506, 9.20429423, 9.70312128, 2.02362046 ], [ 7.05972334, 2.22846472, 5.46749176, 7.31111882, 3.40960906, 4.56294121 ], [ 6.70472842, 3.59272265, 5.16309049, 1.56536978, 9.81538459, 6.82850322 ], [ 4.15689334, 3.41990664, 5.79051761, 0.81210519, 1.0304272, 0.40297561 ], [4.73786661, 0.6207543, 1.6485871, 2.52693314, 8.91532864, 1.52840296], [ 5.92994762, 3.13080909, 2.56228467, 3.18354286, 1.55118873, 0.60703854 ], [ 3.51052921, 6.40861592, 4.52017217, 1.08859183, 5.93003437, 7.38501235 ], [ 8.57725314, 5.32329684, 4.3160815, 6.77629621, 7.49288644, 9.25124645 ], [8.0475847, 6.4163836, 3.62396899, 5.04696816, 8.86944591, 0.08356193], [3.0936211, 3.95499815, 5.96360799, 0.6605126, 3.86466816, 9.6719478], [ 1.96541611, 5.36489548, 3.70399066, 1.12084339, 7.96734339, 3.24741959 ], [6.14385189, 1.83113282, 2.0741162, 4.83746891, 3.2362641, 0.17227037], [ 1.67604863, 5.59126381, 2.09007632, 5.46945561, 9.71342408, 1.6268169 ], [ 9.61221953, 5.27643349, 2.7304223, 7.30143289, 2.37011787, 7.83264795 ], [ 9.90983548, 5.79429284, 3.23532663, 9.17294685, 5.97553658, 4.4452637 ], [ 0.35683435, 4.30303963, 1.90266857, 4.17023551, 4.06186979, 2.7965879 ], [0.83376644, 9.7300586, 6.05654181, 5.09992868, 8.97882656, 4.6280693], [ 8.48222031, 0.12398542, 7.06665329, 7.90802805, 8.97576213, 1.98215824 ], [0.45055814, 9.90187098, 0.7664873, 4.74533329, 8.9772245, 6.48808184], [ 0.88080893, 5.19986295, 6.27365681, 4.46247949, 4.42179112, 0.3344096 ] ] sn_arr = [[ 2.55346379, 2.1727307, 2.35093766, 2.86042287, 2.97285019, 1.15426079 ], [ 2.46390195, 1.23075187, 2.14164701, 2.51344824, 1.6329798, 1.92597048 ], [ 2.3922998, 1.6673905, 2.07136149, 0.94995374, 2.99152438, 2.43278461 ], [ 1.80446599, 1.61757723, 2.21397598, 0.57976386, 0.73221374, 0.33431018 ], [ 1.95255757, 0.48024565, 1.00356077, 1.31780419, 2.83845215, 0.95183676 ], [ 2.22861903, 1.5311806, 1.34814435, 1.52928755, 0.98082474, 0.47157412 ], [ 1.62612892, 2.34657869, 1.91522882, 0.72757474, 2.26079876, 2.54277753 ], [ 2.75012934, 2.10862141, 1.86320656, 2.40689549, 2.57871696, 2.88240738 ], [ 2.65355845, 2.34820047, 1.67626069, 2.02740696, 2.83043378, 0.07848485 ], [ 1.50175408, 1.76784557, 2.25184422, 0.49088564, 1.76128254, 2.95377289 ], [ 1.11351605, 2.11819761, 1.69879401, 0.74379173, 2.66806122, 1.56651489 ], [ 2.27489977, 1.07879322, 1.17346325, 1.97695394, 1.58172378, 0.15582134 ], [ 0.99700377, 2.16962471, 1.17948397, 2.1258517, 2.97456874, 0.99432725 ], [ 2.93003466, 2.09778509, 1.40429925, 2.51155634, 1.30074808, 2.62807274 ], [ 2.97983427, 2.21480833, 1.56288192, 2.85500604, 2.27064999, 1.89628347 ], [ 0.29069255, 1.859838, 1.10727576, 1.80798637, 1.81437105, 1.42590517 ], [ 0.59196924, 2.96349975, 2.27193322, 2.03998311, 2.84951285, 1.94222486 ], [ 2.73304224, 0.11442983, 2.48042035, 2.62755231, 2.84898002, 1.13831482 ], [0.35613537, 2.99207933, 0.56870727, 1.95439588, 2.8492343, 2.36312065], [ 0.61808354, 2.07996798, 2.3182313, 1.8836441, 1.90782557, 0.28421464 ]] expected_array = { SiPMCharge.raw: raw_arr, SiPMCharge.signal_to_noise: sn_arr } expected_single = { SiPMCharge.raw: [99.6473, 93.8179, 81.3852, 92.4639, 125.2603, 75.8990], SiPMCharge.signal_to_noise: [9.6651, 9.3927, 8.7087, 9.3396, 10.9941, 8.4203] } return (S2(times, bin_widths, pmts, sipms), chan_slice, expected_single, expected_array)
def pmt_ids(): return DB.DataPMT('new', 6400).SensorID.values
def __init__( self, detector: str = 'new', # detector name in data-base run_number: int = -1, # run number -1 for MC krmap_filename: str = '', # KrMap file name to generate PMT-PSF psfsipm_filename: str = '', # PSF-SiPM file name to generate SiPM-PSF **kargs): self.ws = 60.0 * units.eV self.wi = 22.4 * units.eV self.fano_factor = 0.15 self.conde_policarpo_factor = 0.10 self.drift_velocity = 1.00 * units.mm / units.mus self.lifetime = 7.00 * units.ms self.transverse_diffusion = 1.00 * units.mm / units.cm**0.5 self.longitudinal_diffusion = 0.30 * units.mm / units.cm**0.5 self.voxel_sizes = np.array( (2.00 * units.mm, 2.00 * units.mm, 0.2 * units.mm), dtype=float) self.el_gain = 1e3 self.wf_buffer_time = 1300 * units.mus self.wf_pmt_bin_time = 25 * units.ns self.wf_sipm_bin_time = 1 * units.mus self.EP_z = 632 * units.mm self.EL_dz = 5 * units.mm self.TP_z = -self.EL_dz self.EL_dtime = self.EL_dz / self.drift_velocity self.EL_pmt_time_sample = self.wf_pmt_bin_time self.EL_sipm_time_sample = self.wf_sipm_bin_time self.s1_dtime = 200 * units.ns db_pmts = db.DataPMT(detector, run_number) self.x_pmts = db_pmts['X'].values self.y_pmts = db_pmts['Y'].values self.adc_to_pes_pmts = db_pmts['adc_to_pes'].values self.npmts = len(self.x_pmts) db_sipms = db.DataSiPM(detector, run_number) self.x_sipms = db_sipms['X'].values self.y_sipms = db_sipms['Y'].values self.adc_to_pes_sipms = db_sipms['adc_to_pes'].values self.nsipms = len(self.x_sipms) ## TODO nphotons = (41.5 * units.keV / self.wi) * self.el_gain * self.npmts if (krmap_filename != ''): print('load psf pmt from file : ', krmap_filename) if (psfsipm_filename != ''): print('load psf sipm from file : ', psfsipm_filename) psf_pmt = partial(_psf, dz=self.EP_z, factor=25e3) psf_sipm = partial(_psf, dz=self.TP_z, factor=0.15) psf_s1 = partial(_psf, factor=1e3) factor = 1. / nphotons self.psf_pmt = psf_pmt if krmap_filename == '' else get_psf_pmt_from_krmap( krmap_filename, factor) self.psf_sipm = psf_sipm if psfsipm_filename == '' else get_psf_sipm_from_file( psfsipm_filename, factor / 0.7e-4) self.psf_s1 = psf_s1 self._configure(**kargs) self._update()
def relative_pmt_response(): """ Script which uses pmaps (will be generalised in future to check XY dependence) to look at the relative response of the PMTs in Kr events and compares to the results on Poisson mu from calibrations """ pmap_file_base = sys.argv[1] dst_file_base = sys.argv[2] run_number = pmap_file_base.split('/')[2][1:] pmt_dats = DB.DataPMT(int(run_number)) s1hists = {x: [] for x in range(12)} s2hists = {x: [] for x in range(12)} s1sumh = [] s2sumh = [] hitPMTdist = {x: [] for x in range(12)} hitPMTZpos = {x: [] for x in range(12)} pmap_sorter = sorter_func(pmap_file_base) pmap_file_list = sorted(glob(pmap_file_base + '*.h5'), key=pmap_sorter) dst_sorter = sorter_func(dst_file_base) dst_file_list = sorted(glob(dst_file_base + '*.h5'), key=dst_sorter) ## dst_frame = load_dsts(dst_file_list, 'DST', 'Events') dst_frame = load_dsts(dst_file_list, 'RECO', 'Events') dst_evt_list = dst_frame['event'].unique() #for fn in iglob(pmap_file_base + '*.h5'): for fn in pmap_file_list: ## This version just using pmt databases s1df, s2df, _, s1pmtdf, s2pmtdf = load_pmaps_as_df(fn) common_evts = np.intersect1d(s1pmtdf['event'].unique(), dst_evt_list) for evt in common_evts: #for evt in s1pmtdf['event'].unique(): #evt = dst_evt_iter[0] s1evt = s1pmtdf[s1pmtdf['event'] == evt] s2evt = s2pmtdf[s2pmtdf['event'] == evt] s1sevt = s1df[s1df['event'] == evt] s2sevt = s2df[s2df['event'] == evt] hit_evt = dst_frame[dst_frame['event'] == evt] ## if hit_evt['nS2'].iloc[0] == 1 and len(s2evt['peak'].unique()) == 1 and len(s1evt['peak'].unique()) == 1: if hit_evt['npeak'].nunique() == 1 and len( s2evt['peak'].unique()) == 1 and len( s1evt['peak'].unique()) == 1: ## Not well defined for multi-S2 events hit_x = hit_evt['X'].iloc[0] hit_y = hit_evt['Y'].iloc[0] hit_z = hit_evt['Z'].iloc[0] for peak in s1evt['peak'].unique(): s1peak = s1evt[s1evt['peak'] == peak] s1sumh.append(s1sevt[s1sevt['peak'] == peak]['ene'].sum()) pmt1Q = s1peak[s1peak['npmt'] == 1]['ene'].sum() for pmt in s1peak['npmt'].unique(): hitPMTdist[pmt].append( np.sqrt( np.power( hit_x - pmt_dats[pmt_dats['SensorID'] == pmt].X.values, 2) + np.power( hit_y - pmt_dats[pmt_dats['SensorID'] == pmt].Y.values, 2))) hitPMTZpos[pmt].append(hit_z) if pmt != 1: s1hists[pmt].append( s1peak[s1peak['npmt'] == pmt]['ene'].sum() / pmt1Q) else: s1hists[pmt].append(pmt1Q) for peak in s2evt['peak'].unique(): s2peak = s2evt[s2evt['peak'] == peak] s2sumh.append(s2sevt[s2sevt['peak'] == peak]['ene'].sum()) if s2sumh[-1] > 4000: # and s2sumh[-1] < 12000: ## pmt1Q = s2peak[s2peak['npmt'] == 1]['ene'].values[5:-5] pmt1Q = s2peak[s2peak['npmt'] == 1]['ene'].sum() for pmt in s2peak['npmt'].unique(): if pmt != 1: ## s2hists[pmt].append(s2peak[s2peak['npmt'] == pmt]['ene'].values[5:-5]/pmt1Q) s2hists[pmt].append( s2peak[s2peak['npmt'] == pmt]['ene'].sum() / pmt1Q) else: s2hists[pmt].append(pmt1Q) #dst_evt_iter.iternext() ## Make the plots s1sumh = np.array(s1sumh) s2sumh = np.array(s2sumh) figs0, axes0 = plt.subplots(nrows=1, ncols=2) axes0[0].hist(s1sumh) axes0[0].set_title('PMT sum S1 distribution') axes0[1].hist(s2sumh) axes0[1].set_title('PMT sum S2 distribution') plt.tight_layout() figs0.show() figs0.savefig('SumChargescharge_R' + run_number + '.png') figs1, axess1 = plt.subplots(nrows=3, ncols=4, figsize=(20, 6)) s1pmt1 = np.array(s1hists[1]) s1bins = np.arange(-2, 4, 0.1) s2bins = np.arange(0.4, 1.1, 0.005) s1select = (s1sumh > 2) & (s1sumh < 150) for (key, val), ax in zip(s1hists.items(), axess1.flatten()): if key == 1: ax.hist(np.array(val)[s1select], bins=100) #ax.scatter(s1sumh[s1select], np.array(val)[s1select]) ## ax.scatter(np.array(hitPMTdist[key])[s1select], np.array(val)[s1select]) #ax.scatter(np.array(hitPMTZpos[key])[s1select], np.array(val)[s1select]) ax.set_title('PMT 1 S1 charge') #ax.set_xlabel('integrated charge in PMT sum (pe)') #ax.set_xlabel('z pos.') #ax.set_ylabel('integrated charge in PMT1 (pe)') ax.set_ylabel('AU)') ax.set_xlabel('integrated charge in PMT1 (pe)') sh_hits = np.array(hitPMTZpos[key])[s1select].shape sh_val = np.array(val)[s1select].shape covar = np.cov( np.array(hitPMTZpos[key])[s1select].reshape(1, sh_hits[0]), np.array(val)[s1select].reshape(1, sh_val[0]))[0, 1] corr_coef = covar / ( np.std(np.array(val)[s1select], ddof=1) * np.std(np.array(hitPMTZpos[key])[s1select], ddof=1)) print('Sensor ', key, ' correlation coefficient = ', corr_coef) else: vals, bins, _ = ax.hist(np.array(val)[s1select], bins=s1bins) ## ax.scatter(s1pmt1[np.abs(val) < 10], np.array(val)[np.abs(val) < 10]) #ax.scatter(s1sumh[s1select], np.array(val)[s1select]) ## ax.scatter(np.array(hitPMTdist[key])[s1select & (np.abs(val) < 10)], np.array(val)[s1select & (np.abs(val) < 10)]) #ax.scatter(np.array(hitPMTZpos[key])[s1select & (np.abs(val) < 10)], np.array(val)[s1select & (np.abs(val) < 10)]) ax.set_title('PMT ' + str(key) + ' S1 relative charge') #ax.set_xlabel('integrated charge in PMT sum (pe)') ## ax.set_xlabel('PMT-hit dist. (mm)') #ax.set_xlabel('hit Z pos') #ax.set_ylabel('pmt q / pmt1 q') ax.set_ylabel('AU') ax.set_xlabel('pmt q / pmt1 q') ## sh_hits = np.array(hitPMTZpos[key])[s1select].shape ## sh_val = np.array(val)[s1select].shape ## covar = np.cov(np.array(hitPMTZpos[key])[s1select].reshape(1, sh_hits[0]), np.array(val)[s1select].reshape(1, sh_val[0]))[0, 1] ## corr_coef = covar / (np.std(np.array(val)[s1select], ddof=1)*np.std(np.array(hitPMTZpos[key])[s1select], ddof=1)) s1select2 = s1select & (np.array(val) > 0) & (np.array(val) <= 2) print('Sensor ', key, ' mean = ', np.mean(np.array(val)[s1select2])) useful_bins = np.argwhere(vals >= 100) b1 = useful_bins[0][0] b2 = useful_bins[-1][0] errs = np.sqrt(vals[b1:b2]) fvals = fitf.fit(fitf.gauss, shift_to_bin_centers(bins)[b1:b2], vals[b1:b2], seed=(vals.sum(), bins[vals.argmax()], 0.1), sigma=errs) ax.plot( shift_to_bin_centers(bins)[b1:b2], fvals.fn(shift_to_bin_centers(bins)[b1:b2])) print('Fit S1 ' + str(key), fvals.values, fvals.errors, fvals.chi2) plt.tight_layout() figs1.show() figs1.savefig('s1relativechargeThzoom_R' + run_number + '.png') fitVals = {} figs2, axess2 = plt.subplots(nrows=3, ncols=4, figsize=(20, 6)) s2pmt1 = np.array(s2hists[1]) for (key, val), ax in zip(s2hists.items(), axess2.flatten()): if key == 1: ## ax.set_title('PMT 1 S2 charge') ax.set_title('PMT 1 S2 charge vs s2 sum charge') ax.set_xlabel('S2pmt sum charge (pe)') #ax.set_xlabel('integrated charge in PMT sum (pe)') #ax.set_xlabel('z pos') ax.set_ylabel('integrated charge in PMT1 (pe)') #ax.set_ylabel('AU') ax.set_xlabel('integrated charge in PMT1 (pe)') ## ax.hist(np.array(val)[(s2sumh>4000) & (s2sumh<12000)], bins=100) ##ax.hist(np.concatenate(val), bins=100) ## ax.hist(np.array(val)[s2sumh>4000], bins=100) ax.scatter(s2sumh[s2sumh > 4000], np.array(val)[s2sumh > 4000]) #ax.scatter(s2sumh[(s2sumh>4000) & (s2sumh<12000)], np.array(val)[(s2sumh>4000) & (s2sumh<12000)]) ## ax.scatter(np.array(hitPMTdist[key])[(s2sumh>4000) & (s2sumh<12000)], np.array(val)[(s2sumh>4000) & (s2sumh<12000)]) #ax.scatter(np.array(hitPMTZpos[key])[(s2sumh>4000) & (s2sumh<12000)], np.array(val)[(s2sumh>4000) & (s2sumh<12000)]) ## sh_hits = np.array(hitPMTdist[key])[(s2sumh>4000) & (s2sumh<12000)].shape ## sh_val = np.array(val)[(s2sumh>4000) & (s2sumh<12000)].shape ## covar = np.cov(np.array(hitPMTdist[key])[(s2sumh>4000) & (s2sumh<12000)].reshape(1, sh_hits[0]), np.array(val)[(s2sumh>4000) & (s2sumh<12000)].reshape(1, sh_val[0]))[0, 1] ## corr_coef = covar / (np.std(np.array(val)[(s2sumh>4000) & (s2sumh<12000)], ddof=1)*np.std(np.array(hitPMTdist[key])[(s2sumh>4000) & (s2sumh<12000)], ddof=1)) ## print('Sensor ', key, ' correlation coefficient = ', corr_coef) else: ## ax.set_title('PMT '+str(key)+' S2 relative charge') ax.set_title('PMT ' + str(key) + ' S2 relative charge vs pmt sum') ax.set_ylabel('pmt q / pmt1 q') #ax.set_xlabel('zpos') ax.set_xlabel('integrated charge in PMT sum (pe)') #ax.set_xlabel('pmt q / pmt1 q') #ax.set_ylabel('AU') #ax.scatter(s2pmt1[np.abs(val) < 10], np.array(val)[np.abs(val) < 10]) #ax.scatter(s2sumh[(s2sumh>4000) & (s2sumh<12000)], np.array(val)[(s2sumh>4000) & (s2sumh<12000)]) ## vals, bins, _ = ax.hist(np.array(val)[(s2sumh>4000) & (s2sumh<12000)], bins=s2bins) ## vals, bins, _ = ax.hist(np.concatenate(val), bins=s2bins) ## vals, bins, _ = ax.hist(np.array(val)[s2sumh>4000], bins=s2bins) ax.scatter(s2sumh[s2sumh > 4000], np.array(val)[s2sumh > 4000]) ## ax.scatter(np.array(hitPMTdist[key])[(s2sumh>4000) & (s2sumh<12000)], np.array(val)[(s2sumh>4000) & (s2sumh<12000)]) #ax.scatter(np.array(hitPMTZpos[key])[(s2sumh>4000) & (s2sumh<12000)], np.array(val)[(s2sumh>4000) & (s2sumh<12000)]) sh_sum = s2sumh[s2sumh > 4000].shape sh_vals = np.array(val)[s2sumh > 4000].shape covar = np.cov(s2sumh[s2sumh > 4000].reshape(1, sh_sum[0]), np.array(val)[s2sumh > 4000].reshape(1, sh_vals[0]))[0, 1] corr_coef = covar / (np.std(np.array(val)[s2sumh > 4000], ddof=1) * np.std(s2sumh[s2sumh > 4000], ddof=1)) ## sh_hits = np.array(hitPMTdist[key])[(s2sumh>4000) & (s2sumh<12000)].shape ## sh_val = np.array(val)[(s2sumh>4000) & (s2sumh<12000)].shape ## covar = np.cov(np.array(hitPMTdist[key])[(s2sumh>4000) & (s2sumh<12000)].reshape(1, sh_hits[0]), np.array(val)[(s2sumh>4000) & (s2sumh<12000)].reshape(1, sh_val[0]))[0, 1] ## corr_coef = covar / (np.std(np.array(val)[(s2sumh>4000) & (s2sumh<12000)], ddof=1)*np.std(np.array(hitPMTdist[key])[(s2sumh>4000) & (s2sumh<12000)], ddof=1)) print('Sensor ', key, ' correlation coefficient = ', corr_coef) ## limit fit to region with stat error <= 10% Poisson ## useful_bins = np.argwhere(vals>=200) ## b1 = useful_bins[0][0] ## b2 = useful_bins[-1][0] ## errs = np.sqrt(vals[b1:b2]) ## print('Seed check: ', (vals.sum(), bins[vals.argmax()], 0.02)) ## fvals = fitf.fit(fitf.gauss, shift_to_bin_centers(bins)[b1:b2], vals[b1:b2], ## seed=(vals.sum(), bins[vals.argmax()], 0.02), ## sigma=errs, bounds=[(0, 0, 0.00001), (1e10, 2, 3)]) ## ax.plot(shift_to_bin_centers(bins), ## fitf.gauss(shift_to_bin_centers(bins), *fvals.values)) ## fitVals[key] = (fvals.values[1], fvals.values[2]) ## print('Fit PMT '+str(key), fvals.values, fvals.errors, fvals.chi2) plt.tight_layout() figs2.show() figs2.savefig('s2relativechargeThvsSum_R' + run_number + '.png') ## figcal, axcal = plt.subplots() ## axcal.errorbar(list(fitVals.keys()), ## np.fromiter((x[0] for x in fitVals.values()), np.float), ## yerr=np.fromiter((x[1] for x in fitVals.values()), np.float), ## label='Average response of PMTs to Kr relative to PMT 1') ## ## Get the calibration info for comparison. ## cal_files = [ fname for fname in sys.argv[3:] ] ## read_params = partial(spr, table_name='FIT_pmt_scaled_dark_pedestal', ## param_names=['poisson_mu']) ## ## Assumes ordering, ok? ## for i, fn in enumerate(cal_files): ## cal_run = fn.split('_')[1] ## with tb.open_file(fn) as cal_in: ## pmt1Val = 0 ## pmt1Err = 0 ## cVals = [] ## cErrs = [] ## for sens, (pars, errs) in read_params(cal_in): ## if sens != 1: ## cVals.append(pars['poisson_mu']) ## cErrs.append(errs['poisson_mu']) ## else: ## pmt1Val = pars['poisson_mu'] ## pmt1Err = errs['poisson_mu'] ## normVals = np.array(cVals) / pmt1Val ## normErrs = normVals * np.sqrt(np.power(np.array(cErrs)/np.array(cVals), 2) + ## np.power(pmt1Err/pmt1Val, 2)) ## axcal.errorbar(list(fitVals.keys()), normVals, ## yerr=normErrs, label='Calibration '+cal_run) ## axcal.legend() ## axcal.set_xlabel('PMT sensor ID') ## axcal.set_ylabel('Response relative to that of PMT 1') ## figcal.show() ## figcal.savefig('calPoisKrRelCompStatsFILT.png') input('plots good?')
import invisible_cities.sierpe.fee as FE # In[6]: from invisible_cities.cities.diomira import Diomira # In[7]: import invisible_cities.sierpe.blr as blr # In[8]: DataPMT = load_db.DataPMT() # ## Run example configuration # ### Configuration file # In[9]: os.environ['IC_NOTEBOOK_DIR'] # Below an example of configuration file for Diomira. The main variables to set are the input file path and name list (in the example a single file), the output path and file, print frequency, number of events to run and the noise cut (in pes) for the SiPMs. # # The noise cut is discussed later in the NB # set_input_files