Skip to content

Commit 9b40626

Browse files
fix RFS for TOF but change get_all_det_pos_pairs_for_bin
- get_all_det_pos_pairs_for_bin now defaults to ignore TOF. This is probably what is expected by most people. - fix multiply_crystal_factors for TOF (in the previous version, it was unexpectedly running over all unmashed TOF bins, giving the wrong scale factor, and taking a long time
1 parent 485843b commit 9b40626

File tree

4 files changed

+38
-27
lines changed

4 files changed

+38
-27
lines changed

src/buildblock/ProjDataInfoCylindricalNoArcCorr.cxx

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -336,31 +336,42 @@ initialise_det1det2_to_uncompressed_view_tangpos() const
336336

337337
unsigned int
338338
ProjDataInfoCylindricalNoArcCorr::
339-
get_num_det_pos_pairs_for_bin(const Bin& bin) const
339+
get_num_det_pos_pairs_for_bin(const Bin& bin, bool ignore_non_spatial_dimensions) const
340340
{
341341
return
342342
get_num_ring_pairs_for_segment_axial_pos_num(bin.segment_num(),
343343
bin.axial_pos_num())*
344344
get_view_mashing_factor()*
345-
std::max(1,get_tof_mash_factor());
345+
(ignore_non_spatial_dimensions ? 1 : std::max(1,get_tof_mash_factor()));
346346
}
347347

348348
void
349349
ProjDataInfoCylindricalNoArcCorr::
350350
get_all_det_pos_pairs_for_bin(vector<DetectionPositionPair<> >& dps,
351-
const Bin& bin) const
351+
const Bin& bin,
352+
bool ignore_non_spatial_dimensions) const
352353
{
353354
this->initialise_uncompressed_view_tangpos_to_det1det2_if_not_done_yet();
354355

355-
dps.resize(get_num_det_pos_pairs_for_bin(bin));
356+
dps.resize(get_num_det_pos_pairs_for_bin(bin, ignore_non_spatial_dimensions));
356357

357358
const ProjDataInfoCylindrical::RingNumPairs& ring_pairs =
358359
get_all_ring_pairs_for_segment_axial_pos_num(bin.segment_num(),
359360
bin.axial_pos_num());
360361
// not sure how to handle mashing with non-zero view offset...
361362
assert(get_min_view_num()==0);
362-
// not sure how to handle even tof mashing
363-
assert(!is_tof_data() || (get_tof_mash_factor() % 2 == 1));
363+
364+
int min_timing_pos_num = 0;
365+
int max_timing_pos_num = 0;
366+
if (!ignore_non_spatial_dimensions)
367+
{
368+
// not sure how to handle even tof mashing
369+
assert(!is_tof_data() || (get_tof_mash_factor() % 2 == 1)); // TODOTOF
370+
// we will need to add all (unmashed) timing_pos for the current bin
371+
min_timing_pos_num = bin.timing_pos_num()*get_tof_mash_factor() - (get_tof_mash_factor() / 2);
372+
max_timing_pos_num = bin.timing_pos_num()*get_tof_mash_factor() + (get_tof_mash_factor() / 2);
373+
}
374+
364375
unsigned int current_dp_num=0;
365376
for (int uncompressed_view_num=bin.view_num()*get_view_mashing_factor();
366377
uncompressed_view_num<(bin.view_num()+1)*get_view_mashing_factor();
@@ -374,25 +385,16 @@ get_all_det_pos_pairs_for_bin(vector<DetectionPositionPair<> >& dps,
374385
rings_iter != ring_pairs.end();
375386
++rings_iter)
376387
{
377-
for (int uncompressed_timing_pos_num = bin.timing_pos_num()*get_tof_mash_factor() - (get_tof_mash_factor() / 2);
378-
uncompressed_timing_pos_num <= bin.timing_pos_num()*get_tof_mash_factor() + (get_tof_mash_factor() / 2);
388+
for (int uncompressed_timing_pos_num = min_timing_pos_num;
389+
uncompressed_timing_pos_num <= max_timing_pos_num;
379390
++uncompressed_timing_pos_num)
380391
{
381392
assert(current_dp_num < get_num_det_pos_pairs_for_bin(bin));
382393
dps[current_dp_num].pos1().tangential_coord() = det1_num;
383394
dps[current_dp_num].pos1().axial_coord() = rings_iter->first;
384395
dps[current_dp_num].pos2().tangential_coord() = det2_num;
385396
dps[current_dp_num].pos2().axial_coord() = rings_iter->second;
386-
// need to keep dp.timing_pos positive
387-
if (uncompressed_timing_pos_num > 0)
388-
{
389-
dps[current_dp_num].timing_pos() = static_cast<unsigned>(uncompressed_timing_pos_num);
390-
}
391-
else
392-
{
393-
std::swap(dps[current_dp_num].pos1(), dps[current_dp_num].pos2());
394-
dps[current_dp_num].timing_pos() = static_cast<unsigned>(-uncompressed_timing_pos_num);
395-
}
397+
dps[current_dp_num].timing_pos() = uncompressed_timing_pos_num;
396398
++current_dp_num;
397399
}
398400
}

src/buildblock/multiply_crystal_factors.cxx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "stir/Bin.h"
2525
#include "stir/Sinogram.h"
2626
#include "stir/error.h"
27+
#include <memory>
2728

2829
START_NAMESPACE_STIR
2930

@@ -33,8 +34,9 @@ void multiply_crystal_factors_help(ProjData& proj_data,
3334
const TProjDataInfo& proj_data_info,
3435
const Array<2,float>& efficiencies, const float global_factor)
3536
{
36-
const auto non_tof_proj_data_info_sptr = proj_data_info.create_non_tof_clone();
37-
Bin bin;
37+
const auto non_tof_proj_data_info_sptr =
38+
std::dynamic_pointer_cast<TProjDataInfo>(proj_data_info.create_non_tof_clone());
39+
Bin bin;
3840

3941
for (bin.segment_num() = proj_data.get_min_segment_num();
4042
bin.segment_num() <= proj_data.get_max_segment_num();
@@ -59,8 +61,8 @@ void multiply_crystal_factors_help(ProjData& proj_data,
5961
view_num <= proj_data.get_max_view_num();
6062
++ view_num)
6163
{
62-
for (int tangential_pos_num = proj_data_info.get_min_tangential_pos_num();
63-
tangential_pos_num <= proj_data_info.get_max_tangential_pos_num();
64+
for (int tangential_pos_num = proj_data.get_min_tangential_pos_num();
65+
tangential_pos_num <= proj_data.get_max_tangential_pos_num();
6466
++tangential_pos_num)
6567
{
6668
// Construct bin with appropriate values
@@ -70,7 +72,7 @@ void multiply_crystal_factors_help(ProjData& proj_data,
7072
parallel_bin.tangential_pos_num() = tangential_pos_num;
7173

7274
std::vector<DetectionPositionPair<> > det_pos_pairs;
73-
proj_data_info.get_all_det_pos_pairs_for_bin(det_pos_pairs, parallel_bin);
75+
non_tof_proj_data_info_sptr->get_all_det_pos_pairs_for_bin(det_pos_pairs, parallel_bin); // using the default argument to ignore TOF here
7476
float result = 0.F;
7577
for (unsigned int i=0; i<det_pos_pairs.size(); ++i)
7678
{

src/include/stir/ProjDataInfoCylindricalNoArcCorr.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,17 @@ class ProjDataInfoCylindricalNoArcCorr : public ProjDataInfoCylindrical
208208
const Bin&) const;
209209

210210
//! This routine returns the number of detector pairs that correspond to a bin
211+
/*!
212+
\see get_all_det_pos_pairs_for_bin(). This function return the size of its output.
213+
*/
211214
unsigned int
212-
get_num_det_pos_pairs_for_bin(const Bin&) const;
215+
get_num_det_pos_pairs_for_bin(const Bin&, bool ignore_non_spatial_dimensions = true) const;
213216

214217
//! This routine fills a vector with all the detector pairs that correspond to a bin.
215-
/*!
218+
/*!
219+
\param[in] ignore_non_spatial_dimensions if \c true, only 1 \c timing_pos_num
220+
will be set, i.e. only the detection positions are returned, not TOF (nor energy)
221+
216222
\see ProjDataInfoCylindrical::get_all_ring_pairs_for_segment_axial_pos_num
217223
for restrictions.
218224
\todo It might be possible to return some weight factors in case there is
@@ -222,7 +228,8 @@ class ProjDataInfoCylindricalNoArcCorr : public ProjDataInfoCylindrical
222228
*/
223229
void
224230
get_all_det_pos_pairs_for_bin(std::vector<DetectionPositionPair<> >&,
225-
const Bin&) const;
231+
const Bin&,
232+
bool ignore_non_spatial_dimensions = true) const;
226233

227234
private:
228235
// old function, now private. Use get_bin_for_det_pos_pair instead.

src/test/test_proj_data_info.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,7 @@ ProjDataInfoCylindricalNoArcCorrTests::test_proj_data_info(ProjDataInfoCylindric
14081408
bin.view_num() = view_num;
14091409
bin.tangential_pos_num() = tangential_pos_num;
14101410
std::vector<DetectionPositionPair<>> det_pos_pairs;
1411-
proj_data_info.get_all_det_pos_pairs_for_bin(det_pos_pairs, bin);
1411+
proj_data_info.get_all_det_pos_pairs_for_bin(det_pos_pairs, bin, false); // include TOF
14121412
Bin new_bin;
14131413
// set value for comparison with bin
14141414
new_bin.set_bin_value(0);

0 commit comments

Comments
 (0)