DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
plot_emulated_triggers Namespace Reference

Functions

None plot_all_event_displays (list[NDArray] tc_data, list[NDArray] tc_data_tas, list[NDArray] ta_data, list[NDArray] ta_data_tps, int run_id, int file_index, bool batch, str|None output_file=None)
 
None main (str filename, int verbose, int start_frag, int end_frag, bool batch, str|None output_file)
 

Detailed Description

Plot the trigger candidates, with their trigger activities & trigger primitives
for a given tpstream file

Function Documentation

◆ main()

None plot_emulated_triggers.main ( str filename,
int verbose,
int start_frag,
int end_frag,
bool batch,
str | None output_file )

Definition at line 123 of file plot_emulated_triggers.py.

123def main(filename: str, verbose: int, start_frag: int, end_frag: int, batch: bool, output_file: str | None) -> None:
124 verbosity = verbose
125 # start_frag and end_frag are intentionally parsed but not yet used.
126 _ = (start_frag, end_frag)
127
128 # Getting the ta data
129 ta_reader = trgtools.TAReader(filename, verbosity, batch)
130 ta_reader.read_all_fragments()
131
132 # Getting the tc data
133 tc_reader = trgtools.TCReader(filename, verbosity, batch)
134 tc_reader.read_all_fragments()
135
136 # Make the displays
137 plot_all_event_displays(
138 tc_reader.tc_data,
139 tc_reader.ta_data,
140 ta_reader.ta_data,
141 ta_reader.tp_data,
142 tc_reader.run_id,
143 tc_reader.file_index,
144 batch,
145 output_file,
146 )
147
148 print(f"From TCReader: number of TCs: {len(tc_reader.tc_data)}, all the TAs in TCs: {len(np.concatenate(tc_reader.ta_data))}")
149 print(f"From TAReader: number of TAs: {len(ta_reader.tp_data)}")
150
int main(int argc, char *argv[])

◆ plot_all_event_displays()

None plot_emulated_triggers.plot_all_event_displays ( list[NDArray] tc_data,
list[NDArray] tc_data_tas,
list[NDArray] ta_data,
list[NDArray] ta_data_tps,
int run_id,
int file_index,
bool batch,
str | None output_file = None )
Plots all the event displays, one per TC.

Each event display will contain TriggerActivities (red boxes), and
TriggerPrimitives (black points) for each TriggerActivity.

Args:
    tc_data (list[NDArray]): A list of TriggerCandidates
    tc_data_tas (list[NDArray]): A list of TriggerActivityData per TriggerCandidate
    ta_data (list[NDArray]): A full list of TriggerActivities
    ta_data_tps (list[NDArray]): A list of TriggerPrimitives per TriggerActivity
    run_id (int): Run ID number
    file_index (int): File index

Definition at line 22 of file plot_emulated_triggers.py.

29 output_file: str | None = None) -> None:
30 """
31
32 Plots all the event displays, one per TC.
33
34 Each event display will contain TriggerActivities (red boxes), and
35 TriggerPrimitives (black points) for each TriggerActivity.
36
37 Args:
38 tc_data (list[NDArray]): A list of TriggerCandidates
39 tc_data_tas (list[NDArray]): A list of TriggerActivityData per TriggerCandidate
40 ta_data (list[NDArray]): A full list of TriggerActivities
41 ta_data_tps (list[NDArray]): A list of TriggerPrimitives per TriggerActivity
42 run_id (int): Run ID number
43 file_index (int): File index
44 """
45
46 time_unit = "Ticks"
47
48 output_pdf = output_file if output_file is not None else f"event_displays_{run_id}.{file_index:04}.pdf"
49 with PdfPages(output_pdf) as pdf:
50 for tcdx, (tc, tas) in tqdm(enumerate(zip(tc_data, tc_data_tas)), total=len(tc_data), desc="Saving event displays", disable=batch):
51 plt.figure(figsize=(6, 4))
52
53 yend = tc["time_end"] - tc["time_start"]
54 ta_times_starts = tas['time_start'] - tc["time_start"]
55 ta_times_ends = tas['time_end'] - tc["time_start"]
56 ta_times_peak = tas['time_peak'] - tc["time_start"]
57 ta_chan_peak = tas['channel_peak']
58
59 channel_start = np.min(tas['channel_start'])
60 channel_end = np.max(tas['channel_end'])
61
62 # Only change the xlim if there is more than one TP.
63 yexpansion = yend * 0.05
64 xexpansion = (channel_end - channel_start) * 0.05
65
66 currentAxis = plt.gca()
67 for tadx, ta in enumerate(tas):
68 rectangle = mtp.patches.Rectangle((ta['channel_start'], ta_times_starts[tadx]), ta['channel_end'] - ta['channel_start'], ta_times_ends[tadx] - ta_times_starts[tadx], linewidth=1, edgecolor='r', facecolor='none')
69 currentAxis.add_patch(rectangle)
70
71 for tatmpdx, tatmp in enumerate(ta_data):
72 if (tatmp['time_start'] == ta['time_start']) and (tatmp['time_end'] == ta['time_end']) and (tatmp['channel_start'] == ta['channel_start']) and (tatmp['channel_end'] == ta['channel_end']):
73 time_starts = ta_data_tps[tatmpdx]['time_start'] - tc["time_start"]
74 time_ends = ta_data_tps[tatmpdx]['time_start']+32*ta_data_tps[tatmpdx]['samples_over_threshold'] - tc["time_start"]
75 plt.vlines(ta_data_tps[tatmpdx]['channel'], time_starts, time_ends)
76
77
78 plt.plot([ta['channel_peak']],[ta['time_peak']- tc["time_start"]], color='black', marker='x', markersize=10)
79
80
81 plt.title(f'Run {run_id}.{file_index:04} Event Display: {tcdx:03}')
82 plt.ylabel(f"Relative Start Time ({time_unit})")
83 plt.xlabel("Channel")
84 plt.ylim(0 - yexpansion, yend + yexpansion)
85 plt.xlim(channel_start - xexpansion, channel_end + xexpansion)
86
87 plt.tight_layout()
88 pdf.savefig()
89 plt.close()
90
91@click.command(help="Display diagnostic information for TCs for a given HDF5 file.")
92@click.argument("filename", type=click.Path(exists=True, dir_okay=False, path_type=str))
93@click.option(
94 "--verbose", "-v",
95 count=True,
96 help="Increment the verbose level (errors, warnings, all). Save names and skipped writes are always printed. Default: 0.",
97)
98@click.option(
99 "--start-frag",
100 type=int,
101 default=-10,
102 show_default=True,
103 help="Starting fragment index to process from. Takes negative indexing (NOT SUPPORTED YET).",
104)
105@click.option(
106 "--end-frag",
107 type=int,
108 default=0,
109 show_default=True,
110 help="Fragment index to stop processing (i.e. not inclusive). Takes negative indexing (NOT SUPPORTED YET).",
111)
112@click.option(
113 "--batch", "-b",
114 is_flag=True,
115 help="Run in batch mode (e.g. without loading bars/tqdm).",
116)
117@click.option(
118 "--output-file", "-o",
119 type=click.Path(dir_okay=False, path_type=str),
120 default=None,
121 help="Output PDF file name. Defaults to event_displays_<run_id>.<file_index>.pdf.",
122)