Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions docs/source/user_guide/user_guide_reference_actors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -302,15 +302,15 @@ The Coincidence Sorter finds pairs of coincident singles within a defined time w
# Apply coincidence sorter
coincidences = coincidences_sorter(singles_tree, time_window, policy, minDistanceXY, maxDistanceZ, chunk_size=1000000)

The following policies are supported:
output_file = uproot.recreate(paths.output / "coinc2keepAll.root")
output_file["Coincidences"] = coincidences
output_file["Singles_crystal"] = copy_tree_for_dump(singles_tree)

- **takeAllGoods**: Each good pair is considered.
- **takeWinnerOfGoods**: Only the pair with the highest energy is considered.
- **takeWinnerIfIsGood**: If the highest energy pair is good, take it; otherwise, kill the event.
- **keepIfOnlyOneGood**: If exactly one good pair exists, keep the multicoincidence.
- **removeMultiples**: No multiple coincidences are accepted, even if there are good pairs.
Reference
^^^^^^^^^

.. autoclass:: opengate.actors.coincidences.Coincidences

Refer to test072 for more details.

ARFActor and ARFTrainingDatasetActor
------------------------------------
Expand Down
10 changes: 9 additions & 1 deletion opengate/actors/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
from . import digitizers, doseactors, miscactors, filters, arfactors, dynamicactors
from . import (
digitizers,
doseactors,
miscactors,
filters,
arfactors,
dynamicactors,
coincidences,
)
65 changes: 65 additions & 0 deletions opengate/actors/coincidences.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,68 @@
import awkward as ak
from tqdm import tqdm
from ..exception import fatal
from .base import ActorBase
from ..base import process_cls


class Coincidences(ActorBase):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"""
The Coincidence Sorter searches, into the singles list, for pairs of coincident singles. Whenever two or more singles are found within a coincidence window, these singles are grouped to form a Coincidence event. All singles open their own coincidence window, and a logical OR is made between all the individual singels to find coincidences.
For the moment Coincidence Sorter can be used only offline. It means that a user should do the simulation in two steps: 1) create system with needed digitizer chain in order to obtain singles within usual Gate simulation; 2) process the file containg the singles in order to obtain coincidecens.
Please, use test072 as an example of use.

Input: a ROOT File with singles with attributes : "EventID", "TotalEnergyDeposit", "PreStepUniqueVolumeID", "GlobalTime"
Output: a ROOT file with initial singles and sorted coincidecens

The term “good” means that a pair of singles are in coincidence and that the 2 singles are separated by a number of blocks greater than or equal to the minSecDiff parameter of the coincidence sorter.

Policies:
- keepAll: All "good" pairs are keeped
- removeMultiples: All multiple coincidences are discard

"""

user_info_defaults = {
"singles_tree": (
[],
{
"doc": "The name of the singles input tree from the provided root file. ",
},
),
"time_window": (
[],
{
"doc": "Time window where to sort the coincidences (in ns).",
},
),
"minSecDiff": (
[],
{
"doc": "Option will be added soon.",
},
),
"policy": (
"keepAll",
{
"doc": "The policy for tratement of multiple coincidences",
"allowed_values": (
"keepAll",
"removeMultiples",
),
},
),
}

def __init__(self, *args, **kwargs) -> None:
super().__init__(self, *args, **kwargs)

def initialize(self):
ActorBase.initialize(self)
if self.policy != "removeMultiples" and self.policy != "keepAll":
fatal(
f"Error, the policy for the Coincidence Sorter must be removeMultiples or "
f"keepAll, while is is '{self.policy}'"
)


def coincidences_sorter(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move all following functions into Coincidences class?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't manage to make it work. Keep it this way for the moment

Expand Down Expand Up @@ -119,3 +181,6 @@ def remove_multiples(coincidences):
ids = coincidences["EventID1"]
ids = [i for i in ids if ids.count(i) == 1]
return ids


process_cls(Coincidences)
Loading