Sorting to find coincident events

Dear @RasmusWallentin ,

Thanks for reaching out to the forum. I will try to guide you further with your case.

My understanding is that this is indeed not a case of sorting, so I will ask you a few more questions.

abs(Timestamp[1] - Timestamp[2]) <= 400

What is [1] and [2] here? Does the Timestamp column actually contain arrays per each event? Or do you mean that you want to take for every event, the difference between the timestamp of that event with the timestamp of the previous event? And would this lag/shift only include a window of two events or would you need to consider potentially different far events?

I want to store the energy of both events and which detector pair it belongs to

This means that you are changing the dataset schema with your output tree, because the meaning of a row of the dataset changes from one event to two events at the same time.

In your post I do not see any mention of where or how you would sort the data, once the difference between timestamps is computed you don’t care about which values are smaller/larger than which other values, or do you?

If you indeed want to store the differences between timestamps of a window of 2 events at a time, then I suggest you take a look at this simple example from the forum : Event mixing with RDataFrame - #5 by eguiraud

Or let us know if you need something else entirely. Also, it would help to know your dataset schema to better understand the use case.

Cheers,
Vincenzo