WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 20d8e28

Browse files
Merge pull request #149 from MaxTousss/feature/shortCutForNormExtraction
Added a method to get detector efficiencies without creating an event
2 parents ed570d1 + 8aca933 commit 20d8e28

File tree

2 files changed

+46
-9
lines changed

2 files changed

+46
-9
lines changed

cpp/helpers/include/petsird_helpers.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,14 @@ make_detection_bin(const ScannerInformation& scanner, const TypeOfModule& type_o
101101

102102
inline float
103103
get_detection_efficiency(const ScannerInformation& scanner, const TypeOfModulePair& type_of_module_pair,
104-
const CoincidenceEvent& event)
104+
const DetectionBin& detection_bin_1, const DetectionBin& detection_bin_2)
105105
{
106106
float eff = 1.0F;
107107
const auto& detection_bin_efficiencies = scanner.detection_efficiencies.detection_bin_efficiencies;
108108
if (detection_bin_efficiencies)
109109
{
110-
eff *= ((*detection_bin_efficiencies)[type_of_module_pair[0]](event.detection_bins[0])
111-
* (*detection_bin_efficiencies)[type_of_module_pair[1]](event.detection_bins[1]));
110+
eff *= ((*detection_bin_efficiencies)[type_of_module_pair[0]](detection_bin_1)
111+
* (*detection_bin_efficiencies)[type_of_module_pair[1]](detection_bin_2));
112112
if (eff == 0.F)
113113
return 0.F;
114114
}
@@ -119,8 +119,8 @@ get_detection_efficiency(const ScannerInformation& scanner, const TypeOfModulePa
119119
const auto& module_pair_SGID_LUT
120120
= (*scanner.detection_efficiencies.module_pair_sgidlut)[type_of_module_pair[0]][type_of_module_pair[1]];
121121

122-
const auto expanded_det_bin0 = expand_detection_bin(scanner, type_of_module_pair[0], event.detection_bins[0]);
123-
const auto expanded_det_bin1 = expand_detection_bin(scanner, type_of_module_pair[1], event.detection_bins[1]);
122+
const auto expanded_det_bin0 = expand_detection_bin(scanner, type_of_module_pair[0], detection_bin_1);
123+
const auto expanded_det_bin1 = expand_detection_bin(scanner, type_of_module_pair[1], detection_bin_2);
124124
const int SGID = module_pair_SGID_LUT(expanded_det_bin0.module_index, expanded_det_bin1.module_index);
125125
if (SGID < 0)
126126
{
@@ -139,6 +139,13 @@ get_detection_efficiency(const ScannerInformation& scanner, const TypeOfModulePa
139139
return eff;
140140
}
141141

142+
inline float
143+
get_detection_efficiency(const ScannerInformation& scanner, const TypeOfModulePair& type_of_module_pair,
144+
const CoincidenceEvent& event)
145+
{
146+
return get_detection_efficiency(scanner, type_of_module_pair, event.detection_bins[0], event.detection_bins[1]);
147+
}
148+
142149
} // namespace petsird_helpers
143150

144151
#endif

python/petsird/helpers/__init__.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,40 @@ def make_detection_bin(
8383
[expanded_detection_bin])[0]
8484

8585

86+
@typing.overload
87+
def get_detection_efficiency(scanner: petsird.ScannerInformation,
88+
type_of_module_pair: petsird.TypeOfModulePair,
89+
detection_bin_1: petsird.DetectionBin,
90+
detection_bin_2: petsird.DetectionBin) -> float:
91+
"""Compute the detection efficiency for a pair of detectors"""
92+
...
93+
94+
95+
@typing.overload
8696
def get_detection_efficiency(scanner: petsird.ScannerInformation,
8797
type_of_module_pair: petsird.TypeOfModulePair,
8898
event: petsird.CoincidenceEvent) -> float:
8999
"""Compute the detection efficiency for a coincidence event"""
100+
...
101+
102+
103+
_DetectionBinUnannotated = typing.get_args(petsird.DetectionBin)[0]
104+
105+
106+
def get_detection_efficiency(
107+
scanner: petsird.ScannerInformation,
108+
type_of_module_pair: petsird.TypeOfModulePair,
109+
event_or_detection_bin_1: typing.Union[petsird.CoincidenceEvent,
110+
petsird.DetectionBin],
111+
detection_bin_2: petsird.DetectionBin = None) -> float:
112+
"""Compute the detection efficiency"""
113+
if isinstance(event_or_detection_bin_1, _DetectionBinUnannotated):
114+
detection_bin_1 = event_or_detection_bin_1
115+
assert detection_bin_2 is not None, "Second detection bin must be provided"
116+
else:
117+
detection_bin_1, detection_bin_2 = event_or_detection_bin_1.detection_bins[:
118+
2]
119+
90120
if scanner.detection_efficiencies is None:
91121
# should never happen really, but this way, we don't crash.
92122
return 1.
@@ -100,8 +130,8 @@ def get_detection_efficiency(scanner: petsird.ScannerInformation,
100130
detection_bin_efficiencies[type_of_module_pair[0]])
101131
detection_bin_efficiencies1 = (
102132
detection_bin_efficiencies[type_of_module_pair[1]])
103-
eff *= (detection_bin_efficiencies0[event.detection_bins[0]] *
104-
detection_bin_efficiencies1[event.detection_bins[1]])
133+
eff *= (detection_bin_efficiencies0[detection_bin_1] *
134+
detection_bin_efficiencies1[detection_bin_2])
105135
if eff == 0:
106136
return 0.
107137

@@ -113,10 +143,10 @@ def get_detection_efficiency(scanner: petsird.ScannerInformation,
113143
assert module_pair_SGID_LUT is not None
114144
expanded_det_bin0 = expand_detection_bin(scanner,
115145
type_of_module_pair[0],
116-
event.detection_bins[0])
146+
detection_bin_1)
117147
expanded_det_bin1 = expand_detection_bin(scanner,
118148
type_of_module_pair[1],
119-
event.detection_bins[1])
149+
detection_bin_2)
120150

121151
SGID = module_pair_SGID_LUT[type_of_module_pair[0]][
122152
type_of_module_pair[1]][expanded_det_bin0.module_index,

0 commit comments

Comments
 (0)