Skip to content
39 changes: 39 additions & 0 deletions invisible_cities/io/trigger_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from .. evm import nh5 as table_formats
from .. reco.tbl_functions import filters as tbl_filters
from .. io .table_io import make_table


def store_trigger(tables, trg_type, trg_channels):
Expand Down Expand Up @@ -41,3 +42,41 @@ def _make_tables(hdf5_file, n_sensors, compression="ZLIB4"):
trg_tables = trg_type, trg_channels

return trg_tables


def trigger_dst_writer(hdf5_file, **kwargs):#{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why **kwargs? They are not used.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also what's this #{? Also in line 54.

trigger_table = make_table(hdf5_file,
group = "Trigger",
name = "DST" ,
fformat = table_formats.TriggerTable,
description = "Simulated trigger data",
compression = 'ZLIB4')
def write_trigger(trigger_info):#{
[event , pmt ,
trigger_time , charge , width , height ,
valid_q , valid_w , valid_h , valid_peak,
mean_baseline, max_height ,
n_coinc , closest_ttime, closest_pmt] = trigger_info
row = trigger_table.row
row["event" ] = event
row["pmt" ] = pmt
row["trigger_time" ] = trigger_time
row["q" ] = charge
row["width" ] = width
row["height" ] = height
row["valid_q" ] = valid_q
row["valid_w" ] = valid_w
row["valid_h" ] = valid_h
row["valid_peak" ] = valid_peak
row["valid_all" ] = (valid_q + valid_w + valid_h + valid_peak) == 4
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the writer shouldn't need to know anything about what it is writing. you may also want to consider creating a dataframe and saving it using the dataframe writer?

also, since these are booleans, it's more appropriate to use all.

row["baseline" ] = mean_baseline
row["max_height" ] = max_height
row["n_coinc" ] = n_coinc
row["closest_ttime"] = closest_ttime
row["closest_pmt" ] = closest_pmt
row.append()

def write_triggers(triggers):
for t in triggers: write_trigger(t)

return write_triggers