pema package

Submodules

pema.compare_plots module

pema.compare_plots.axvline(v, **kwargs)[source]
pema.compare_plots.compare_outcomes(st: Context, data: ndarray, st_alt: Context | None = None, data_alt: ndarray | None = None, match_fuzz: int = 500, plot_fuzz: int = 500, max_peaks: int = 10, default_label: str = 'default', custom_label: str = 'custom', fig_dir: None | str = None, show: bool = True, randomize: bool = True, different_by: bool | str | None = 'acceptance_fraction', run_id: None | str = None, raw: bool = False, pulse: bool = True) None[source]

Compare the outcomes of two contexts with one another. In order to allow for selections, we need to pass the data as second and third argument respectively.

Parameters:
  • st – the context of the current master, to compare with st_custom

  • data – the data consistent with the default context, can be cut to select certain data

  • st_alt – context wherewith to compare st_default

  • data_alt – the data with the custom context, should be same length as truth_vs_default

  • match_fuzz – Extend loading peaks this many ns to allow for small shifts in reconstruction. Will extend the time range left and right

  • plot_fuzz – Make the plot slightly larger with this many ns for readability

  • max_peaks – max number of peaks to be shown. Set to 1 for plotting a singe peak.

  • default_label – How to label the default reconstruction

:param custom_label:How to label the custom reconstruction :param fig_dir: Where to save figures (if None, don’t save) :param show: show the figures or not. :param randomize: randomly order peaks to get a random sample of

<max_peaks> every time

Parameters:
  • different_by – Field to filter waveforms by. Only show waveforms where this field is different in data. If False, plot any waveforms from the two data sets.

  • run_id – Optional argument in case run_id is not a field in the data.

  • raw – include raw-records-trace

  • pulse – plot raw-record traces.

Returns:

None

pema.compare_plots.compare_truth_and_outcome(st: Context, data: ndarray, **kwargs) None[source]

Compare the outcomes of the truth and the reconstructed peaks

Parameters:
  • st – the context of the current master, to compare with

  • data – the data consistent with the default context, can be cut to select certain data

  • match_fuzz – Extend loading peaks this many ns to allow for small shifts in reconstruction. Will extend the time range left and right

  • plot_fuzz – Make the plot slightly larger with this many ns for readability

  • max_peaks – max number of peaks to be shown. Set to 1 for plotting a singe peak.

  • label – How to label the default reconstruction

  • fig_dir – Where to save figures (if None, don’t save)

  • show – show the figures or not.

  • randomize – randomly order peaks to get a random sample of <max_peaks> every time

  • run_id – Optional argument in case run_id is not a field in the data.

  • raw – include raw-records-trace

  • pulse – plot raw-record traces.

Returns:

None

pema.compare_plots.plot_peak(p, t0=None, center_time=True, include_info=None, **kwargs)[source]
pema.compare_plots.rr_simple_plot(st, run_id, t_range)[source]

Plot some raw-record pulses within (touching) the t_range :param st: :param run_id: :param t_range: :param legend: :return:

pema.compare_plots.seconds_range_xaxis(seconds_range, t0=None)[source]

Make a pretty time axis given seconds_range

pema.contexts module

pema.contexts.pema_context(base_dir: str, fax_config: str, cmt_run_id_sim: str, config_update: dict | None = None, cmt_version='global_v8', raw_dir=None, data_dir=None, raw_types=None, **kwargs) Context[source]

Central context for pema, allows to init from a config. :param base_dir: Where store instructions, :param fax_config: fax configuration file :param cmt_run_id_sim: run_id for CMT (see wfsim.contexts.xenonnt_simulation) :param cmt_version: the global correction version applied to the data :param config_update: Setup the config of the context :param raw_dir: Where to store the low level datatypes :param data_dir: Where to store the high level datatypes :param raw_types: Low level datatypes, stored separately from

high level datatypes

Kwargs:

any kwargs are directly passed to the context

Returns:

context

pema.match_plugins module

class pema.match_plugins.AcceptanceComputer[source]

Bases: Plugin

Compute the acceptance of the matched peaks. This is done on the basis of arbitrary settings to allow better to disentangle possible scenarios that might be undesirable (like splitting an S2 into small S1 signals that could affect event reconstruction).

compute(truth, peaks)[source]
config: Dict
data_kind: str | immutabledict | dict = 'truth'
depends_on: tuple = ('truth', 'truth_matched', 'peak_basics', 'peak_id')
deps: Dict
dtype: tuple | dtype | immutabledict | dict
infer_dtype()[source]

Return dtype of computed data; used only if no dtype attribute defined.

input_buffer: Dict[str, Chunk]
keep_peak_fields

Dispatch on URL protocol.

unrecognized protocol returns identity inspired by dasks Dispatch and fsspec fs protocols.

min_s2_bias_rec

Dispatch on URL protocol.

unrecognized protocol returns identity inspired by dasks Dispatch and fsspec fs protocols.

penalty_s2_by

Dispatch on URL protocol.

unrecognized protocol returns identity inspired by dasks Dispatch and fsspec fs protocols.

provides: tuple = ('match_acceptance',)
run_i: int
run_id: str
setup()[source]

Hook if plugin wants to do something on initialization.

takes_config = immutabledict({'keep_peak_fields': <straxen.url_config.URLConfig object>, 'penalty_s2_by': <straxen.url_config.URLConfig object>, 'min_s2_bias_rec': <straxen.url_config.URLConfig object>})
class pema.match_plugins.MatchPeaks[source]

Bases: OverlapWindowPlugin

Match WFSim truth to the outcome peaks. To this end use the

matching algorithm of pema. Assign a peak-id to both the truth and the reconstructed peaks to be able to match the two. Also define the outcome of the matching (see pema.matching for possible outcomes).

compute(truth, peaks)[source]
config: Dict
data_kind: str | immutabledict | dict = 'truth'
depends_on: tuple = ('truth', 'truth_id', 'peak_basics', 'peak_id')
deps: Dict
dtype: tuple | dtype | immutabledict | dict
get_window_size()[source]

Return the required window size in nanoseconds.

infer_dtype()[source]

Return dtype of computed data; used only if no dtype attribute defined.

input_buffer: Dict[str, Chunk]
provides: tuple = ('truth_matched',)
run_i: int
run_id: str
takes_config = immutabledict({'truth_lookup_window': <straxen.url_config.URLConfig object>})
truth_lookup_window

Dispatch on URL protocol.

unrecognized protocol returns identity inspired by dasks Dispatch and fsspec fs protocols.

class pema.match_plugins.TruthExtended[source]

Bases: MergeOnlyPlugin

Merge the matched acceptance to the extended truth

config: Dict
data_kind: str | immutabledict | dict = 'truth'
depends_on: tuple = ('match_acceptance', 'truth', 'truth_id', 'truth_matched')
deps: Dict
dtype: tuple | dtype | immutabledict | dict
input_buffer: Dict[str, Chunk]
provides: tuple = ('truth_extended',)
run_i: int
run_id: str
save_when = 2

pema.matching module

Utility to match peaks from results of different processor versions / processor and simulator

pema.matching.append_fields(base, names, data, dtypes=None, fill_value=-1, usemask=False, asrecarray=False)[source]

Append fields to numpy structured array Does nothing if array already has fields with the same name.

pema.matching.match_peaks(allpeaks1, allpeaks2, matching_fuzz=0, unknown_types=(0,))[source]
Perform peak matching between two numpy record arrays with fields:

time, endtime (or dt and length), id, type, area

If a peak is split into many fragments (e.g. two close peaks split into three peaks), the results are unreliable and depend on which peak set is peaks1 and which is peaks2.

Returns (allpeaks1, allpeaks2), each with two extra fields: outcome, matched_to:

outcome: Can be one of:
found: Peak was matched 1-1 between peaks1 and peaks2 (type agrees,
no other peaks in range).

Note that area, widths, etc. can still be quite different!

missed: Peak is not present in the other list misid_as_XX: Peak is present in the other list, but has type XX merged: Peak is merged with another peak in the other list, the new

‘super-peak’ has the same type

merged_to_XX: As above, but ‘super-peak’ has type XX split: Peak is split in the other list, but more than one fragment

has the same type as the parent.

chopped: As split, but one or several fragments are unclassified,

exactly one has the correct type.

split_and_unclassified: As split, but all fragments are unclassified

in the other list.

split_and_misid: As split, but at least one fragment has a different

peak type.

matched_to: id of matching in peak in the other list if outcome is found

or misid_as_XX, INT_NAN otherwise.

pema.misc module

pema.misc.save_canvas(name: str, save_dir: str = './figures', dpi: int = 200, tight_layout: bool = False, pickle_dump: bool = False, other_formats: List[str] | None = None) None[source]

Wrapper for saving current figure. Saves to PNG by default and also adds pdf and svg formats

Parameters:
  • name – How to name the figure (no extension required)

  • save_dir – Base where to store figures

  • dpi – dots per inch for saving the option

  • tight_layout – if true use plt.tight_layout

  • pickle_dump – DEPRECATED option

  • other_formats – other formats to save in (by default svg and pdf)

Returns:

None

pema.scripts module

Helpers for doing processing on dali

exception pema.scripts.JobFailedError[source]

Bases: ValueError

If a script job failes, raise this error

class pema.scripts.ProcessRun(st: <module 'strax.context' from '/home/docs/checkouts/readthedocs.org/user_builds/pema/envs/latest/lib/python3.9/site-packages/strax/context.py'>, run_id: str | tuple | list, target: str | tuple, config: dict | ~immutabledict.immutabledict | None = None)[source]

Bases: object

Class that allows for bookkeeping of runs of simulations

all_stored(show_key=False, return_bool=False)[source]
base_dir_requires = ('configs', 'logs', 'scripts')
exec_dali(cmd, job_name, bash_activate, mem=2000, partition='xenon1t', max_hours='04:00:00')[source]
exec_local(cmd, job_name)[source]
static extract_base_dir(st)[source]

Extract a base dir from the context (either from self or storage)

job_finished()[source]
log_file = None
make_cmd(debug=True, not_lazy=True)[source]

return_command = just return the command, don’t do the actual file stuf

process = None
purge_below(delete_below='peaklets', exclude=('raw_records', 'records'))[source]

Delete all the data below the given peaklet :param delete_below: target where below all the data :param exclude: :return:

read_log()[source]
script_file = None
pema.scripts.write_dict_to_json(path: str, to_write: dict)[source]
pema.scripts.write_script(fn, script, **kwargs)[source]

pema.summary_plots module

pema.summary_plots.binom_interval(success, total, conf_level=0.95)[source]

Confidence interval on binomial - using Jeffreys interval Code stolen from https://gist.github.com/paulgb/6627336 Agrees with http://statpages.info/confint.html for binom_interval(1, 10)

pema.summary_plots.peak_matching_histogram(results, histogram_key, bin_edges)[source]

Make 1D histogram of peak matching results (=peaks with extra fields) added by histogram_key

pema.summary_plots.plot_peak_matching_histogram(*args, **kwargs)[source]

pema.wfsim_utils module

pema.wfsim_utils.inst_to_csv(csv_file: str, get_inst_from=<function rand_instructions>, **kwargs)[source]

Write instructions to csv file :param csv_file: path to the csv file :param get_inst_from: function to modify instructions and generate S1 S2 instructions from :param kwargs: key word arguments to give to the get_inst_from-function

pema.wfsim_utils.rand_instructions(event_rate: int, chunk_size: int, n_chunk: int, drift_field: float, energy_range: tuple | list | ndarray, tpc_length: float = 148.6515, tpc_radius: float = 66.4, nest_inst_types: List[int] | Tuple[List] | ndarray | None = None) dict[source]

Generate instructions to run WFSim :param event_rate: # events per second :param chunk_size: the size of each chunk :param n_chunk: the number of chunks :param energy_range: the energy range (in keV) of the recoil type :param tpc_length: the max depth of the detector :param tpc_radius: the max radius of the detector :param nest_inst_types: the :param drift_field: :return:

Module contents