DUNE / larnd-sim

Simulation framework for a pixelated Liquid Argon TPC
Apache License 2.0
10 stars 27 forks source link

Replace n_tracks parameter with n_events #145

Closed sam-fogarty closed 1 year ago

sam-fogarty commented 1 year ago

The n_tracks input parameter allows one to specify how many segments to simulate. A much more useful parameter (especially for testing purposes) would be one that allows for selecting a certain number of events to simulate. I suggest replacing n_tracks with n_events, and this pull contains an implementation of this. Note also that n_tracks was broken before this, since the segment_ids array was not being sliced similarly to the tracks array. Additionally, only the tracks array was being sliced, while the rest of the datasets remained unchanged. This pull applies the n_events cut to all datasets.

Note also that I needed to make a minor change in the save_results function (and thus in fee.export_to_hdf5). The is_first_event parameter is replaced by is_first_batch and is turned into a bool. The point of this parameter originally (I believe) was to only create the mc_packets_assn dataset after the first event, so that after that it only added new data to the dataset. But since data is saved to the file after each batch and not after each event, it makes more sense to use the is_first_batch parameter. It is True initially and is turned False after passing through save_results once. This ensures that we will never get an error by trying to create the mc_packets_assn dataset multiple times. In fact, in the original implementation you'd get an error with n_events=1 with a spill simulation.