DUNE / larnd-sim

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

Error when simulating non-spill events #159

Closed sam-fogarty closed 9 months ago

sam-fogarty commented 1 year ago

Currently we are calculating the total number of event ids with this line in simulate_pixels.py: num_evids = (tracks[sim.EVENT_SEPARATOR].max() % sim.MAX_EVENTS_PER_FILE) + 1

The purpose of this is to deal with offsets in the event ids. You need to set sim.MAX_EVENTS_PER_FILE equal to the maximum number of events in the input file (which in and of itself is not ideal IMO). Some events will not deposit energy in the detector and will not be accounted for in the datasets at this stage. So for instance if there are 10000 events initially simulated and 50 don't deposit energy, then there will only be 9950 event ids in the datasets (e.g. len(np.unique(tracks['event_id'])) = 9950). Now just below the line above, inside the if input_has_vertices and not sim.IS_SPILL_SIM statement, we have the following lines:

uniq_ev, counts = np.unique(vertices[sim.EVENT_SEPARATOR], return_counts=True)
vertices['t_event'] = np.repeat(event_times.get(),counts) 

We'll get an error at the second of these two lines like this: ValueError: operands could not be broadcast together with shape (10000,) (9950,)

This happens because counts and event_times.get() have different lengths, which is caused by the fact that vertices[sim.EVENT_SEPARATOR] doesn't contain all 10000 event ids. We need to modify these lines to avoid this error.

YifanC commented 9 months ago

@sam-fogarty Can you check if this commit solves the above issue?

sam-fogarty commented 9 months ago

@YifanC Hi Yifan, sorry for getting back to you so late on this! I checked and that commit does work and I can run particle gun-type MC and cosmics MC through larnd-sim now without this error. Thanks for fixing this!