Skip to content

Commit

Permalink
Remove 1T related codes
Browse files Browse the repository at this point in the history
  • Loading branch information
dachengx committed Nov 15, 2024
1 parent 6a166b9 commit 84df0ea
Show file tree
Hide file tree
Showing 28 changed files with 38 additions and 2,110 deletions.
1 change: 0 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
[report]
omit =
straxen/storage/rucio_remote.py
straxen/legacy/plugins_1t/pax_interface.py
straxen/entry_points.py
straxen/daq_core.py
straxen/scripts/*.py
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ live_data
daq_test_data
strax_data
strax_test_data
from_fake_daq
from_eb
from_eb_finished
resource_cache
Expand Down
50 changes: 19 additions & 31 deletions docs/source/build_datastructure_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@
"""

titles = {
"": "Straxen {xT} datastructure",
"_he": "Straxen {xT} datastructure for high energy channels",
"_nv": "Straxen {xT} datastructure for neutron veto",
"_mv": "Straxen {xT} datastructure for muon veto",
"": "Straxen nT datastructure",
"_he": "Straxen nT datastructure for high energy channels",
"_nv": "Straxen nT datastructure for neutron veto",
"_mv": "Straxen nT datastructure for muon veto",
}
tree_suffices = list(titles.keys())

Expand Down Expand Up @@ -144,44 +144,35 @@ def get_plugins_deps(st):
return plugins_by_deps


def get_context(is_nt):
def get_context():
"""Need to init a context without initializing the runs_db as that requires the appropriate
passwords.
:return: straxen context that mimics the xenonnt_online context without the rundb init
"""
if is_nt:
st = straxen.contexts.xenonnt_online(_database_init=False)
st.context_config["forbid_creation_of"] = straxen.daqreader.DAQReader.provides
else:
st = straxen.contexts.xenon1t_dali()
st.register_all(straxen.legacy.plugins_1t.x1t_cuts)
st.context_config["forbid_creation_of"] = straxen.daqreader.DAQReader.provides
st = straxen.contexts.xenonnt_online(_database_init=False)
st.context_config["forbid_creation_of"] = straxen.daqreader.DAQReader.provides
return st


def build_datastructure_doc(is_nt):
def build_datastructure_doc():
"""Build a dependency tree for all plugins."""
pd.set_option("display.max_colwidth", int(1e9))

st = get_context(is_nt)
one_tonne_or_n_tonne = "nT" if is_nt else "1T"
st = get_context()
# Too lazy to write proper graph sorter
# Make dictionary {total number of dependencies below -> list of plugins}

plugins_by_deps = get_plugins_deps(st)

# Make graph for each suffix ('' referring to TPC)
for suffix in tree_suffices:
title = titles[suffix].format(xT=one_tonne_or_n_tonne)
out = page_header.format(title=title, context="xenonnt_online" if is_nt else "xenon1t_dali")
if not is_nt and suffix != "":
# No NV/MV/HE for 1T
continue

print(f"------------ {one_tonne_or_n_tonne}{suffix} ------------")
os.makedirs(this_dir + f"/graphs{suffix}_{one_tonne_or_n_tonne}", exist_ok=True)
title = titles[suffix]
out = page_header.format(title=title, context="xenonnt_online")

print(f"------------ nT{suffix} ------------")
os.makedirs(this_dir + f"/graphs{suffix}_nT", exist_ok=True)
for n_deps in list(reversed(sorted(list(plugins_by_deps[suffix].keys())))):
for this_data_type in plugins_by_deps[suffix][n_deps]:
this_plugin = st._get_plugins(targets=(this_data_type,), run_id="0")[this_data_type]
Expand All @@ -192,7 +183,7 @@ def build_datastructure_doc(is_nt):
add_deps_to_graph_tree(graph_tree, this_plugin, this_data_type)

# Where to save this node
fn = this_dir + f"/graphs{suffix}_{one_tonne_or_n_tonne}/" + this_data_type
fn = this_dir + f"/graphs{suffix}_nT/" + this_data_type
graph_tree.render(fn)
with open(f"{fn}.svg", mode="r") as f:
svg = add_spaces(f.readlines()[5:])
Expand Down Expand Up @@ -225,12 +216,10 @@ def build_datastructure_doc(is_nt):
config_options=add_spaces(config_df.to_html(index=False)),
)

with open(
this_dir + f"/reference/datastructure{suffix}_{one_tonne_or_n_tonne}.rst", mode="w"
) as f:
with open(this_dir + f"/reference/datastructure{suffix}_nT.rst", mode="w") as f:
f.write(out)

shutil.rmtree(this_dir + f"/graphs{suffix}_{one_tonne_or_n_tonne}")
shutil.rmtree(this_dir + f"/graphs{suffix}_nT")


def tree_to_svg(graph_tree, save_as="data_kinds_nT"):
Expand All @@ -246,7 +235,7 @@ def tree_to_svg(graph_tree, save_as="data_kinds_nT"):
def write_data_kind_dep_tree():
"""Work in progress to build a dependency tree of the datakinds."""
print("------------ data kinds ------------")
st = get_context(is_nt=True)
st = get_context()

def get_plugin(pov):
return st._get_plugins((pov,), "0")[pov]
Expand Down Expand Up @@ -342,5 +331,4 @@ def get_plugin(pov):

if __name__ == "__main__":
write_data_kind_dep_tree()
build_datastructure_doc(True)
build_datastructure_doc(False)
build_datastructure_doc()
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ repository = "https://github.com/XENONnT/straxen"
[tool.poetry.scripts]
ajax = "straxen.scripts.ajax:main"
bootstrax = "straxen.scripts.bootstrax:main"
fake_daq = "straxen.scripts.fake_daq:main"
microstrax = "straxen.scripts.microstrax:main"
refresh_raw_records = "straxen.scripts.refresh_raw_records:main"
restrax = "straxen.scripts.restrax:main"
Expand Down
10 changes: 2 additions & 8 deletions straxen/analyses/bokeh_waveform_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def event_display_interactive(
plot_all_pmts=False,
plot_record_matrix=False,
plot_records_threshold=10,
xenon1t=False,
colors=("gray", "blue", "green"),
yscale=("linear", "linear", "linear"),
log=True,
Expand All @@ -53,7 +52,6 @@ def event_display_interactive(
:param plot_records_threshold: Threshold at which zoom level to display
record matrix as polygons. Larger values may lead to longer
render times since more polygons are shown.
:param xenon1t: Flag to use event display with 1T data.
:param colors: Colors to be used for peaks. Order is as peak types,
0 = Unknown, 1 = S1, 2 = S2. Can be any colors accepted by bokeh.
:param yscale: Defines scale for main/alt S1 == 0, main/alt S2 == 1,
Expand Down Expand Up @@ -149,7 +147,6 @@ def event_display_interactive(
to_pe,
labels,
plot_all_pmts,
xenon1t=xenon1t,
log=log,
)

Expand Down Expand Up @@ -306,7 +303,7 @@ def plot_detail_plot_s1_s2(signal, s1_keys, s2_keys, labels, colors, yscale=("li


def plot_pmt_arrays_and_positions(
top_array_keys, bottom_array_keys, signal, to_pe, labels, plot_all_pmts, xenon1t=False, log=True
top_array_keys, bottom_array_keys, signal, to_pe, labels, plot_all_pmts, log=True
):
"""Function which plots the Top and Bottom PMT array.
Expand Down Expand Up @@ -335,7 +332,6 @@ def plot_pmt_arrays_and_positions(
to_pe,
plot_all_pmts=plot_all_pmts,
label=labels[k],
xenon1t=xenon1t,
fig=fig,
log=log,
)
Expand Down Expand Up @@ -534,7 +530,6 @@ def plot_pmt_array(
to_pe,
plot_all_pmts=False,
log=False,
xenon1t=False,
fig=None,
label="",
):
Expand All @@ -545,7 +540,6 @@ def plot_pmt_array(
:param to_pe: PMT gains.
:param log: If true use a log-scale for the color scale.
:param plot_all_pmts: If True colors all PMTs instead of showing swtiched off PMTs as gray dots.
:param xenon1t: If True plots 1T array.
:param fig: Instance of bokeh.plotting.figure if None one will be created via
straxen.bokeh.utils.default_figure().
:param label: Label of the peak which should be used for the plot legend
Expand Down Expand Up @@ -574,7 +568,7 @@ def plot_pmt_array(
fig = _plot_tpc(fig)

# Plotting PMTs:
pmts = straxen.pmt_positions(xenon1t)
pmts = straxen.pmt_positions()
if plot_all_pmts:
mask_pmts = np.zeros(len(pmts), dtype=np.bool_)
else:
Expand Down
12 changes: 3 additions & 9 deletions straxen/analyses/event_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def event_display(
s2_fuzz=50,
s1_fuzz=0,
max_peaks=500,
xenon1t=False,
s1_hp_kwargs=None,
s2_hp_kwargs=None,
event_time_limit=None,
Expand Down Expand Up @@ -92,7 +91,6 @@ def event_display(
s2_fuzz=s2_fuzz,
s1_fuzz=s1_fuzz,
max_peaks=max_peaks,
xenon1t=xenon1t,
display_peak_info=display_peak_info,
display_event_info=display_event_info,
s1_hp_kwargs=s1_hp_kwargs,
Expand All @@ -112,7 +110,6 @@ def _event_display(
s2_fuzz=50,
s1_fuzz=0,
max_peaks=500,
xenon1t=False,
display_peak_info=PEAK_DISPLAY_DEFAULT_INFO,
display_event_info=EVENT_DISPLAY_DEFAULT_INFO,
s1_hp_kwargs=None,
Expand Down Expand Up @@ -170,7 +167,6 @@ def _event_display(
# Hit patterns options:
for hp_opt, color_map in ((s1_hp_kwargs, "Blues"), (s2_hp_kwargs, "Greens")):
_common_opt = dict(
xenon1t=xenon1t,
pmt_label_color="lightgrey",
log_scale=True,
vmin=0.1,
Expand Down Expand Up @@ -239,7 +235,7 @@ def _event_display(
)
# Mark reconstructed position (corrected)
plt.scatter(event["x"], event["y"], marker="X", s=100, c="k")
if not xenon1t and axi == 0 and plot_all_positions:
if axi == 0 and plot_all_positions:
_scatter_rec(event)

# Fill panels with peak/event info
Expand Down Expand Up @@ -279,9 +275,8 @@ def _event_display(
single_figure=False,
)
ax_rec.tick_params(axis="x", rotation=0)
if not xenon1t:
# Top vs bottom division
ax_rec.axhline(straxen.n_top_pmts, c="k")
# Top vs bottom division
ax_rec.axhline(straxen.n_top_pmts, c="k")
if ev_range is not None:
plt.xlim(*ev_range)

Expand Down Expand Up @@ -450,7 +445,6 @@ def _scatter_rec(
:param s2_fuzz: extra time around main S2 [ns]
:param s1_fuzz: extra time around main S1 [ns]
:param max_peaks: max peaks for plotting in the wf plot
:param xenon1t: True: is 1T, False: is nT
:param display_peak_info: tuple, items that will be extracted from
event and displayed in the event info panel see above for format
:param display_event_info: tuple, items that will be extracted from
Expand Down
2 changes: 1 addition & 1 deletion straxen/analyses/holoviews_waveform_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def hvdisp_plot_pmt_pattern(*, config, records, to_pe, array="bottom"):
"""
import holoviews as hv

pmts = straxen.pmt_positions(xenon1t=config["n_tpc_pmts"] < 300)
pmts = straxen.pmt_positions()
areas = np.bincount(
records["channel"], weights=records["area"] * to_pe[records["channel"]], minlength=len(pmts)
)
Expand Down
2 changes: 0 additions & 2 deletions straxen/analyses/waveform_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ def plot_hit_pattern(
log_scale=False,
label=None,
single_figure=False,
xenon1t=False,
figsize=(10, 4),
):
if single_figure:
Expand All @@ -124,7 +123,6 @@ def plot_hit_pattern(
vmin=vmin,
log_scale=log_scale,
label=label,
xenon1t=xenon1t,
)


Expand Down
47 changes: 5 additions & 42 deletions straxen/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import os.path as osp
import json
from re import match
import ast
import configparser
import gzip
import inspect
from typing import Union, Dict, Any
Expand Down Expand Up @@ -100,35 +98,14 @@ def rotate_perp_wires(x_obs: np.ndarray, y_obs: np.ndarray, angle_extra: Union[f


@export
def pmt_positions(xenon1t=False):
def pmt_positions():
"""Return pandas dataframe with PMT positions
columns: array (top/bottom), i (PMT number), x, y
"""
if xenon1t:
# Get PMT positions from the XENON1T config without PAX
config = configparser.ConfigParser()
config.read_string(
resource_from_url(
"https://raw.githubusercontent.com/XENON1T/pax/master/pax/config/XENON1T.ini"
)
)
pmt_config = ast.literal_eval(config["DEFAULT"]["pmts"])
return pd.DataFrame(
[
dict(
x=q["position"]["x"],
y=q["position"]["y"],
i=q["pmt_position"],
array=q.get("array", "other"),
)
for q in pmt_config[:248]
]
)
else:
return resource_from_url(
aux_repo + "874de2ffe41147719263183b89d26c9ee562c334/pmt_positions_xenonnt.csv",
fmt="csv",
)
return resource_from_url(
aux_repo + "874de2ffe41147719263183b89d26c9ee562c334/pmt_positions_xenonnt.csv",
fmt="csv",
)


# In-memory resource cache
Expand Down Expand Up @@ -585,17 +562,3 @@ def _swap_values_in_array(data_arr, buffer, items, replacements):
buffer[i] = replacements[k]
break
return buffer


##
# Old XENON1T Stuff
##


first_sr1_run = 170118_1327


@export
def pax_file(x):
"""Return URL to file hosted in the pax repository master branch."""
return "https://raw.githubusercontent.com/XENON1T/pax/master/pax/data/" + x
25 changes: 0 additions & 25 deletions straxen/contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,28 +326,3 @@ def xenonnt_led(**kwargs):
)
st.set_config({"coincidence_level_recorder_nv": 1})
return st


##
# XENON1T, see straxen/legacy
##


def demo():
"""Return strax context used in the straxen demo notebook."""
return straxen.legacy.contexts_1t.demo()


def fake_daq():
"""Context for processing fake DAQ data in the current directory."""
return straxen.legacy.contexts_1t.fake_daq()


def xenon1t_dali(output_folder="./strax_data", build_lowlevel=False, **kwargs):
return straxen.legacy.contexts_1t.xenon1t_dali(
output_folder=output_folder, build_lowlevel=build_lowlevel, **kwargs
)


def xenon1t_led(**kwargs):
return straxen.legacy.contexts_1t.xenon1t_led(**kwargs)
Loading

0 comments on commit 84df0ea

Please sign in to comment.