@@ -293,6 +293,7 @@ def _coincidences_sorter(
293293 processing_finished = False
294294 start = time .time ()
295295 time_lost = 0
296+ allow_intra_volume_coincidences = result_type == ResultType .COINCIDENT_SINGLES
296297 while (
297298 not processing_finished
298299 and num_chunk_size_increases < max_num_chunk_size_increases
@@ -320,7 +321,9 @@ def _coincidences_sorter(
320321 queue .append (chunk_pd )
321322 # Process a chunk, unless only one has been read so far
322323 if len (queue ) > 1 :
323- coincidences = _process_chunk (queue , time_window )
324+ coincidences = _process_chunk (
325+ queue , time_window , allow_intra_volume_coincidences
326+ )
324327 # Before filtering coincidences, we want to make sure that we have all
325328 # coincidences that belong to the same time window (same SingleIndex1 value).
326329 # When processing the next chunk of singles, we may still find one or more
@@ -386,7 +389,9 @@ def _coincidences_sorter(
386389 num_singles += num_singles_in_chunk
387390
388391 # At this point, all chunks have been read. Now process the last chunk.
389- coincidences_to_process = _process_chunk (queue , time_window )
392+ coincidences_to_process = _process_chunk (
393+ queue , time_window , allow_intra_volume_coincidences
394+ )
390395 if coincidences_to_transfer is not None :
391396 coincidences_to_process = pd .concat (
392397 [coincidences_to_transfer , coincidences_to_process ],
@@ -457,7 +462,7 @@ def _coincidences_sorter(
457462 return coincidences_to_return
458463
459464
460- def _process_chunk (queue , time_window ):
465+ def _process_chunk (queue , time_window , allow_intra_volume_coincidences ):
461466 """
462467 Processes singles in the chunk queue[0],
463468 possibly transferring some of those singles to the next chunk queue[1].
@@ -479,7 +484,9 @@ def _process_chunk(queue, time_window):
479484 raise ChunkSizeTooSmallError
480485
481486 # Find coincidences in the current chunk
482- coincidences = _run_coincidence_detection_in_chunk (chunk , time_window )
487+ coincidences = _run_coincidence_detection_in_chunk (
488+ chunk , time_window , allow_intra_volume_coincidences
489+ )
483490
484491 if next_chunk is not None :
485492 # If there are singles in the current chunk that are beyond t_min
@@ -500,17 +507,20 @@ def _process_chunk(queue, time_window):
500507 return coincidences
501508
502509
503- def _run_coincidence_detection_in_chunk (chunk , time_window ):
510+ def _run_coincidence_detection_in_chunk (
511+ chunk , time_window , allow_intra_volume_coincidences
512+ ):
504513 """
505514 Detects coincidences between singles in the given chunk, excluding coincidences
506515 between singles in the same volume.
507516 """
508- # Add a temporary column containing hash values of the strings identifying the volumes,
509- # to assist in excluding coincidences between singles in the same volume
510- # (calculating and comparing hash values is much faster than comparing strings).
511- chunk ["VolumeIDHash" ] = pd .util .hash_pandas_object (
512- chunk ["PreStepUniqueVolumeID" ], index = False
513- )
517+ if not allow_intra_volume_coincidences :
518+ # Add a temporary column containing hash values of the strings identifying the volumes,
519+ # to assist in excluding coincidences between singles in the same volume
520+ # (calculating and comparing hash values is much faster than comparing strings).
521+ chunk ["VolumeIDHash" ] = pd .util .hash_pandas_object (
522+ chunk ["PreStepUniqueVolumeID" ], index = False
523+ )
514524 time_np = chunk ["GlobalTime" ].to_numpy ()
515525 # Sort the time values chronologically (singles in the chunk may not be in chronological order).
516526 time_np_sorted_indices = np .argsort (time_np )
@@ -555,12 +565,13 @@ def _run_coincidence_detection_in_chunk(chunk, time_window):
555565 coincidences = pd .concat ([coincidence_singles1 , coincidence_singles2 ], axis = 1 )[
556566 interleaved_columns
557567 ]
558- # Remove coincidences between singles in the same volume.
559- coincidences = coincidences .loc [
560- coincidences ["VolumeIDHash1" ] != coincidences ["VolumeIDHash2" ]
561- ].reset_index (drop = True )
562- # Remove the temporary volume ID hash columns.
563- coincidences = coincidences .drop (columns = ["VolumeIDHash1" , "VolumeIDHash2" ])
568+ if not allow_intra_volume_coincidences :
569+ # Remove coincidences between singles in the same volume.
570+ coincidences = coincidences .loc [
571+ coincidences ["VolumeIDHash1" ] != coincidences ["VolumeIDHash2" ]
572+ ].reset_index (drop = True )
573+ # Remove the temporary volume ID hash columns.
574+ coincidences = coincidences .drop (columns = ["VolumeIDHash1" , "VolumeIDHash2" ])
564575
565576 return coincidences
566577
0 commit comments