cait.cuts

class cait.cuts.LogicalCut(initial_condition=None)[source]

Bases: object

A class for the application of logical cuts to given data.

Parameters

initial_condition (1D bool array or None) – An initial condition can be applied, e.g. ph > 0.01, where ph is an 1D array. The number of events is equal to the length of the array.

add_condition(condition)[source]

Add and condition that is linked with and AND statement to all other conditions.

Parameters

condition (1D bool array) – A condition to be applied to all events, e.g. ph > 0.01.

counts()[source]

Return the number of events that survive all cuts.

Returns

The number of events that survive all cuts.

Return type

int

force_false(idx)[source]

Force certain events to false.

Parameters

idx (1D int array) – All indices that we want to set to false.

force_true(idx)[source]

Force certain events to true.

Parameters

idx (1D int array) – All indices that we want to set to true.

get_antiflag()[source]

Return a bool array of all events, indicating which do not survive all cuts.

Returns

Indicates which events do not survive all cuts.

Return type

1D int array

get_antiidx()[source]

Return an int array of all event indices that do not survive all cuts.

Returns

The indices that do not survive all cuts.

Return type

1D int array

get_flag()[source]

Return a bool array of all events, indicating which do survive all cuts.

Returns

Indicates which events do survive all cuts.

Return type

1D int array

get_idx()[source]

Return an int array of all event indices that survive all cuts.

Returns

The indices that survive all cuts.

Return type

1D int array

total()[source]

Return the total number of events.

Returns

The total number of events.

Return type

int

cait.cuts.controlpulse_stability(hours_ev, cphs=None, hours_cp=None, significance=3, max_gap=1, lb=0, ub=100, instable_iv=None)[source]

Find all stable control pulses and events.

A control pulse is defined as stable, if its height is between the lower and upper bound, and within a significant amount of sigmas of the mean height of control pulses. Every time interval between two control pulses is defined as stable, if they are both stable. A single unstable control pulse is in this definition ignored, so only two consecutive instable control pulses lead to an instable time interval. All events in instable time intervals are counted as instable.

This method is described in “CRESST Collaboration, First results from the CRESST-III low-mass dark matter program” (10.1103/PhysRevD.100.102002).

Parameters
  • cphs (1D float array) – The pulse heights of the control pulses.

  • hours_cp (1D float array) – The hours time stamps of the control pulses.

  • hours_ev (1D float array) – The hours time stamps of the events.

  • significance (float) – The multiplcator of the standard deviation of the pulse heights sigma, that is used to exclude all pulses outside significance*sigma of the mean pulse height.

  • max_gap (float) – For control pulses that are further apart than this value, the interval in between is automatically counted as instable.

  • lb (float) – All control pulse heights below this value are counted as instable.

  • ub (float) – All control pulse heights above this value are counted as instable.

  • instable_iv (list) – A list of the instable intervals. If this is handed, the instable intervals are not calculated but those are used. Useful for e.g. the cut efficiency.

Returns

The flag that specifies which events are stable. The flag that specifies which control pulses are stable. The list of instable intervals in hours.

Return type

two 1D bool arrays, one list

cait.cuts.outside(ex, ey, x, y1, y2)[source]

Cut all events inside a connected set of trapezoids in an XY plane.

Parameters
  • ex (1D numpy array) – The x coordinates of the events.

  • ey (1D numpy array) – The y coordinates of the events.

  • x (list) – The x values of the region, a list of arbirary length.

  • y1 (list) – The lower y values of the region, a list of same length as x.

  • y2 (list) – The upper y values of the region, a list of same length as x, the values must be larger than the corresponding ones in y1.

Returns

The cut flag corresponding to the events.

Return type

1D numpy bool array

>>> import cait as ai
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> nx, ny = (1000, 1000)
>>> x = np.linspace(0, 1, nx)
>>> y = np.linspace(0, 1, ny)
>>> xv, yv = np.meshgrid(x, y)
>>> cutflag = ai.cuts.outside(ex=xv.reshape(-1),
...                          ey=yv.reshape(-1),
...                          x=[0.1, 0.4, 0.9],
...                          y1=[0.1, 0.2, 0.1],
...                          y2=[0.7, 0.9, 0.3],
...                          )
>>> plt.contourf(xv, yv, cutflag.reshape((nx, ny)))
>>> plt.show()
cait.cuts.rate_cut(timestamps, timestamps_cp=None, timestamps_tp=None, interval=10, significance=3, min=0, max=60, use_poisson=True, intervals=None)[source]

Return a bool array for all timestamps, with true for events that are in intervals with sigma rate.

Parameters
  • timestamps (1D array) – The array of the event time stamps in minutes.

  • timestamps_cp – The array of the control pulse time stamps in minutes.

  • timestamps_tp – The array of the test pulse time stamps in minutes.

  • interval (float) – In minutes, the interval we compare.

  • significance (float) – All intervals, that have an event rate not within significance-sigma of mean event rate, are cut.

  • min (float) – Intervals with lower rate than this are excluded from the calculation.

  • max – Intervals with higher rate than this are excluded from the calculation.

  • max – float

  • use_poisson (bool) – If this is activated (per default) we use the median and poisson confidence intervals instead of standard normal statistics.

  • intervals (list of 2-tuples) – A list of the stable intervals in minutes. If this is handed, these intervals are used instead of calculating them from scratch. This is useful e.g. for the cut efficiency.

Returns

For events, controlpulses and testpulses arrays: True if event survives rate cut, false if not. The list of the stable intervals in minutes.

Return type

3 boolean arrays of same size as timestamps, list of tuples

cait.cuts.testpulse_stability(tpas, tphs, hours_tp, hours_ev, significance=3, noise_level=0.005, max_gap=1, lb=None, ub=None)[source]

Find all test pulses and events.

The stability is evaluated for all TPA values independently. A test pulse is defined as stable, if its height is between the lower and upper bound, and within a significant amount of sigmas of the mean height of test pulses with this TPA value. Every time interval between two test pulses is defined as stable, if they are both stable. All events in instable time intervals are counted as instable.

Parameters
  • tpas (1D float array) – The TPA values of the test pulses.

  • tphs (1D float array) – The pulse heights of the test pulses.

  • hours_tp (1D float array) – The hours time stamps of the test pulses.

  • hours_ev (1D float array) – The hours time stamps of the events.

  • significance (float) – The multiplcator of the standard deviation of the pulse heights sigma, that is used to exclude all pulses outside significance*sigma of the mean pulse height.

  • noise_level (float) – The

  • max_gap (float) – For control pulses that are further apart than this value, the interval in between is automatically counted as instable.

  • lb (float) – All control pulse heights below this value are counted as instable.

  • ub (float) – All control pulse heights above this value are counted as instable.

Returns

( The flag that specifies which events are stable; The flag that specifies which test pulses are stable.)

Return type

2-tuple of 1D bool arrays