km3modules.k40

A collection of k40 related functions and modules.

Module Contents

Classes

K40BackgroundSubtractor() Subtracts random coincidence background from K40 data
IntraDOMCalibrator() Intra DOM calibrator which performs the calibration from K40Counts.
TwofoldCounter() Counts twofold coincidences in timeslice hits per PMT combination.
HRVFIFOTimesliceFilter() Creat a frame index lookup table which holds DOM IDs of frames with
SummaryMedianPMTRateService()
MedianPMTRatesService()
ResetTwofoldCounts()

Functions

calibrate_dom(dom_id, data, detector, livetime=None, fit_ang_dist=False, scale_mc_to_data=True, ad_fit_shape=’pexp’, fit_background=True, ctmin=-1.0) Calibrate intra DOM PMT time offsets, efficiencies and sigmas
calculate_weights(fitted_rates, data)
load_k40_coincidences_from_hdf5(filename, dom_id) Load k40 coincidences from hdf5 file
load_k40_coincidences_from_rootfile(filename, dom_id) Load k40 coincidences from JMonitorK40 ROOT file
gaussian(x, mean, sigma, rate, offset)
gaussian_wo_offset(x, mean, sigma, rate)
fit_delta_ts(data, livetime, fit_background=True) Fits gaussians to delta t for each PMT pair.
calculate_angles(detector, combs) Calculates angles between PMT combinations according to positions in
exponential_polinomial(x, p1, p2, p3, p4)
exponential(x, a, b)
fit_angular_distribution(angles, rates, rate_errors, shape=’pexp’) Fits angular distribution of rates.
minimize_t0s(means, weights, combs) Varies t0s to minimize the deviation of the gaussian means from zero.
minimize_sigmas(sigmas, weights, combs) Varies sigmas to minimize gaussian sigma12 - sqrt(sigma1² + sigma2²).
minimize_qes(fitted_rates, rates, weights, combs) Varies QEs to minimize the deviation of the rates from the fitted_rates.
correct_means(means, opt_t0s, combs) Applies optimal t0s to gaussians means.
correct_rates(rates, opt_qes, combs) Applies optimal qes to rates.
calculate_rms_means(means, corrected_means) Calculates RMS of means from zero before and after correction
calculate_rms_rates(rates, fitted_rates, corrected_rates) Calculates RMS of rates from fitted_rates before and after correction
get_comb_index(i, j) Return the index of PMT pair combinations
add_to_twofold_matrix(times, tdcs, mat, tmax=10) Add counts to twofold coincidences for a given tmax.
km3modules.k40.log[source]
km3modules.k40.TIMESLICE_LENGTH = 0.1[source]
km3modules.k40.MC_ANG_DIST[source]
class km3modules.k40.K40BackgroundSubtractor[source]

Bases:km3pipe.Module

Subtracts random coincidence background from K40 data

configure(self)[source]
process(self, blob)[source]
get_corrected_counts(self)[source]
subtract_background(self)[source]
finish(self)[source]
dump(self, mean_rates, corrected_counts, livetime)[source]
class km3modules.k40.IntraDOMCalibrator[source]

Bases:km3pipe.Module

Intra DOM calibrator which performs the calibration from K40Counts.

Parameters:
det_id: int

Detector ID [default: 14]

ctmin: float

Minimum cos(angle)

mode: str (‘offline’ | ‘online’)

Calibration mode [default: ‘online’]

configure(self)[source]
process(self, blob)[source]
calibrate(self, twofold_counts, fit_background=False)[source]
finish(self)[source]
class km3modules.k40.TwofoldCounter[source]

Bases:km3pipe.Module

Counts twofold coincidences in timeslice hits per PMT combination.

Parameters:
‘tmax’: int

time window of twofold coincidences [ns]

‘dump_filename’: str

name for the dump file

configure(self)[source]
reset(self)[source]

Reset coincidence counter

get_livetime(self)[source]
process(self, blob)[source]
dump(self)[source]

Write coincidence counts into a Python pickle

class km3modules.k40.HRVFIFOTimesliceFilter[source]

Bases:km3pipe.Module

Creat a frame index lookup table which holds DOM IDs of frames with at least one PMT in HRV.

configure(self)[source]
get_skipped_frames(self)[source]
class km3modules.k40.SummaryMedianPMTRateService[source]

Bases:km3pipe.Module

configure(self)[source]
get_median_rates(self)[source]
class km3modules.k40.MedianPMTRatesService[source]

Bases:km3pipe.Module

configure(self)[source]
process(self, blob)[source]
get_median_rates(self)[source]
class km3modules.k40.ResetTwofoldCounts[source]

Bases:km3pipe.Module

process(self, blob)[source]
km3modules.k40.calibrate_dom(dom_id, data, detector, livetime=None, fit_ang_dist=False, scale_mc_to_data=True, ad_fit_shape='pexp', fit_background=True, ctmin=-1.0)[source]

Calibrate intra DOM PMT time offsets, efficiencies and sigmas

Parameters:
dom_id: DOM ID
data: dict of coincidences or root or hdf5 file
detector: instance of detector class
livetime: data-taking duration [s]
fixed_ang_dist: fixing angular distribution e.g. for data mc comparison
auto_scale: auto scales the fixed angular distribution to the data
Returns:
return_data: dictionary with fit results
km3modules.k40.calculate_weights(fitted_rates, data)[source]
km3modules.k40.load_k40_coincidences_from_hdf5(filename, dom_id)[source]

Load k40 coincidences from hdf5 file

Parameters:
filename: filename of hdf5 file
dom_id: DOM ID
Returns:
data: numpy array of coincidences
livetime: duration of data-taking
km3modules.k40.load_k40_coincidences_from_rootfile(filename, dom_id)[source]

Load k40 coincidences from JMonitorK40 ROOT file

Parameters:
filename: root file produced by JMonitorK40
dom_id: DOM ID
Returns:
data: numpy array of coincidences
dom_weight: weight to apply to coincidences to get rate in Hz
km3modules.k40.gaussian(x, mean, sigma, rate, offset)[source]
km3modules.k40.gaussian_wo_offset(x, mean, sigma, rate)[source]
km3modules.k40.fit_delta_ts(data, livetime, fit_background=True)[source]

Fits gaussians to delta t for each PMT pair.

Parameters:
data: 2d np.array: x = PMT combinations (465), y = time, entry = frequency
livetime: length of data taking in seconds
fit_background: if True: fits gaussian with offset, else without offset
Returns:
numpy arrays with rates and means for all PMT combinations
km3modules.k40.calculate_angles(detector, combs)[source]

Calculates angles between PMT combinations according to positions in detector_file

Parameters:
detector_file: file from which to read the PMT positions (.detx)
combs: pmt combinations
Returns:
angles: numpy array of angles between all PMT combinations
km3modules.k40.exponential_polinomial(x, p1, p2, p3, p4)[source]
km3modules.k40.exponential(x, a, b)[source]
km3modules.k40.fit_angular_distribution(angles, rates, rate_errors, shape='pexp')[source]

Fits angular distribution of rates.

Parameters:
rates: numpy array

with rates for all PMT combinations

angles: numpy array

with angles for all PMT combinations

shape:

which function to fit; exp for exponential or pexp for exponential_polinomial

Returns:
fitted_rates: numpy array of fitted rates (fit_function(angles, popt…))
km3modules.k40.minimize_t0s(means, weights, combs)[source]

Varies t0s to minimize the deviation of the gaussian means from zero.

Parameters:
means: numpy array of means of all PMT combinations
weights: numpy array of weights for the squared sum
combs: pmt combinations to use for minimization
Returns:
opt_t0s: optimal t0 values for all PMTs
km3modules.k40.minimize_sigmas(sigmas, weights, combs)[source]

Varies sigmas to minimize gaussian sigma12 - sqrt(sigma1² + sigma2²).

Parameters:
sigmas: numpy array of fitted sigmas of gaussians
weights: numpy array of weights for the squared sum
combs: pmt combinations to use for minimization
Returns:
opt_sigmas: optimal sigma values for all PMTs
km3modules.k40.minimize_qes(fitted_rates, rates, weights, combs)[source]

Varies QEs to minimize the deviation of the rates from the fitted_rates.

Parameters:
fitted_rates: numpy array of fitted rates from fit_angular_distribution
rates: numpy array of rates of all PMT combinations
weights: numpy array of weights for the squared sum
combs: pmt combinations to use for minimization
Returns:
opt_qes: optimal qe values for all PMTs
km3modules.k40.correct_means(means, opt_t0s, combs)[source]

Applies optimal t0s to gaussians means.

Should be around zero afterwards.

Parameters:
means: numpy array of means of gaussians of all PMT combinations
opt_t0s: numpy array of optimal t0 values for all PMTs
combs: pmt combinations used to correct
Returns:
corrected_means: numpy array of corrected gaussian means for all PMT combs
km3modules.k40.correct_rates(rates, opt_qes, combs)[source]

Applies optimal qes to rates.

Should be closer to fitted_rates afterwards.

Parameters:
rates: numpy array of rates of all PMT combinations
opt_qes: numpy array of optimal qe values for all PMTs
combs: pmt combinations used to correct
Returns:
corrected_rates: numpy array of corrected rates for all PMT combinations
km3modules.k40.calculate_rms_means(means, corrected_means)[source]

Calculates RMS of means from zero before and after correction

Parameters:
means: numpy array of means of gaussians of all PMT combinations
corrected_means: numpy array of corrected gaussian means for all PMT combs
Returns:
rms_means: RMS of means from zero
rms_corrected_means: RMS of corrected_means from zero
km3modules.k40.calculate_rms_rates(rates, fitted_rates, corrected_rates)[source]

Calculates RMS of rates from fitted_rates before and after correction

Parameters:
rates: numpy array of rates of all PMT combinations
corrected_rates: numpy array of corrected rates for all PMT combinations
Returns:
rms_rates: RMS of rates from fitted_rates
rms_corrected_rates: RMS of corrected_ratesrates from fitted_rates
km3modules.k40.get_comb_index(i, j)[source]

Return the index of PMT pair combinations

km3modules.k40.add_to_twofold_matrix(times, tdcs, mat, tmax=10)[source]

Add counts to twofold coincidences for a given tmax.

Parameters:
times: np.ndarray of hit times (int32)
tdcs: np.ndarray of channel_ids (uint8)
mat: ref to a np.array((465, tmax * 2 + 1))
tmax: int (time window)
Returns:
mat: coincidence matrix (np.array((465, tmax * 2 + 1)))