@@ -22,6 +22,7 @@ using petsird::binary::PETSIRDWriter;
2222#endif
2323
2424#include " petsird_helpers.h"
25+ #include " petsird_helpers/create.h"
2526
2627// these are constants for now
2728constexpr uint32_t NUMBER_OF_EVENT_ENERGY_BINS = 3 ;
@@ -108,33 +109,30 @@ get_scanner_geometry()
108109 return scanner_geometry;
109110}
110111
111- petsird::DetectionEfficiencies
112- get_detection_efficiencies (const petsird::ScannerInformation& scanner)
112+ // set some example efficiencies in the ScannerInformation object.
113+ void
114+ set_detection_efficiencies (petsird::ScannerInformation& scanner)
113115{
114116 const auto num_module_types = scanner.scanner_geometry .replicated_modules .size ();
115117 // only 1 type of module in the current scanner
116118 assert (num_module_types == 1 );
117119 const petsird::TypeOfModule type_of_module{ 0 };
118120 const auto num_detection_bins = petsird_helpers::get_num_detection_bins (scanner, type_of_module);
119- petsird::DetectionEfficiencies detection_efficiencies;
120121
121122 const auto & event_energy_bin_edges = scanner.event_energy_bin_edges [type_of_module];
122123 const auto num_event_energy_bins = event_energy_bin_edges.NumberOfBins ();
123124
124- std::vector<petsird::DetectionBinEfficiencies> detection_bin_efficiencies (num_module_types);
125- detection_efficiencies.detection_bin_efficiencies = detection_bin_efficiencies;
126- detection_efficiencies.module_pair_sgidlut = std::vector<std::vector<petsird::ModulePairSGIDLUT>>(num_module_types);
127- for (auto & elem : *detection_efficiencies.module_pair_sgidlut )
125+ // set all detection_bin_efficiencies to 1 in this example
126+ if (scanner.detection_efficiencies .detection_bin_efficiencies )
128127 {
129- elem.resize (num_module_types);
128+ auto & bin_effs = (*scanner.detection_efficiencies .detection_bin_efficiencies )[type_of_module];
129+ yardl::resize (bin_effs, { num_detection_bins });
130+ std::fill (begin (bin_effs), end (bin_effs), 1 .F );
130131 }
131- detection_efficiencies.module_pair_efficiencies_vectors
132- = std::vector<std::vector<petsird::ModulePairEfficienciesVector>>(num_module_types);
133- for (auto & elem : *detection_efficiencies.module_pair_efficiencies_vectors )
134- {
135- elem.resize (num_module_types);
136- }
137- (*detection_efficiencies.detection_bin_efficiencies )[type_of_module] = xt::ones<float >({ num_detection_bins });
132+
133+ // check if the caller wants to have module-pair stuff. If not, return.
134+ if (!scanner.detection_efficiencies .module_pair_efficiencies_vectors )
135+ return ;
138136
139137 const auto & rep_module = scanner.scanner_geometry .replicated_modules [type_of_module];
140138 const auto num_modules = rep_module.transforms .size ();
@@ -149,9 +147,9 @@ get_detection_efficiencies(const petsird::ScannerInformation& scanner)
149147 constexpr auto num_SGIDs = NUM_MODULES_ALONG_AXIS * NUM_MODULES_ALONG_AXIS * (NUM_MODULES_ALONG_RING - 1 );
150148 // SGID = z1 + NZ * (z2 + NZ * abs(a2 - a1) - 1)
151149 constexpr auto NZ = NUM_MODULES_ALONG_AXIS;
152- (*detection_efficiencies. module_pair_sgidlut )[type_of_module][type_of_module]
153- = yardl::NDArray< int , 2 >({ num_modules, num_modules }) ;
154- auto & module_pair_SGID_LUT = (*detection_efficiencies. module_pair_sgidlut )[type_of_module][type_of_module] ;
150+
151+ auto & module_pair_SGID_LUT = (*scanner. detection_efficiencies . module_pair_sgidlut )[type_of_module][type_of_module] ;
152+ module_pair_SGID_LUT = yardl::NDArray< int , 2 >({ num_modules, num_modules }) ;
155153 for (unsigned int mod1 = 0 ; mod1 < num_modules; ++mod1)
156154 {
157155 for (unsigned int mod2 = 0 ; mod2 < num_modules; ++mod2)
@@ -174,7 +172,7 @@ get_detection_efficiencies(const petsird::ScannerInformation& scanner)
174172
175173 // initialise module_pair_efficiencies
176174 auto & module_pair_efficiencies_vector
177- = (*detection_efficiencies.module_pair_efficiencies_vectors )[type_of_module][type_of_module];
175+ = (*scanner. detection_efficiencies .module_pair_efficiencies_vectors )[type_of_module][type_of_module];
178176 // assign an empty vector first, and reserve correct size
179177 module_pair_efficiencies_vector = petsird::ModulePairEfficienciesVector ();
180178 module_pair_efficiencies_vector.reserve (num_SGIDs);
@@ -194,8 +192,6 @@ get_detection_efficiencies(const petsird::ScannerInformation& scanner)
194192 module_pair_efficiencies_vector.emplace_back (module_pair_efficiencies);
195193 assert (module_pair_efficiencies_vector.size () == unsigned (SGID + 1 ));
196194 }
197-
198- return detection_efficiencies;
199195}
200196
201197petsird::ScannerInformation
@@ -206,47 +202,46 @@ get_scanner_info()
206202
207203 scanner_info.scanner_geometry = get_scanner_geometry ();
208204 const auto num_types_of_modules = scanner_info.scanner_geometry .replicated_modules .size ();
205+ // Pre-allocate various structures to have the correct size for num_types_of_modules
206+ // (We will still have to set descent values into each of these.)
207+ petsird_helpers::create::initialize_scanner_information_dimensions (scanner_info, num_types_of_modules,
208+ /* allocate_detection_bin_efficiencies = */ true ,
209+ /* allocate_module_pair_efficiencies = */ true );
209210
210211 // TODO scanner_info.bulk_materials
211212
212213 // TOF and energy information
213214 {
214- auto all_tof_bin_edges
215- = petsird_helpers::construct_2D_nested_vector<petsird::BinEdges>(num_types_of_modules, num_types_of_modules);
216- auto all_tof_resolutions = petsird_helpers::construct_2D_nested_vector<float >(num_types_of_modules, num_types_of_modules);
217- auto all_event_energy_bin_edges = petsird_helpers::construct_vector<petsird::BinEdges>(num_types_of_modules);
218- auto all_event_energy_resolutions = petsird_helpers::construct_vector<float >(num_types_of_modules);
215+ auto & all_tof_bin_edges = scanner_info.tof_bin_edges ;
216+ auto & all_tof_resolutions = scanner_info.tof_resolution ;
217+ auto & all_event_energy_bin_edges = scanner_info.event_energy_bin_edges ;
218+ auto & all_event_energy_resolutions = scanner_info.energy_resolution_at_511 ;
219219
220220 // only 1 type of module in the current scanner
221221 assert (num_types_of_modules == 1 );
222222 const petsird::TypeOfModule type_of_module{ 0 };
223223
224224 typedef yardl::NDArray<float , 1 > FArray1D;
225225 // TOF info (in mm)
226- FArray1D::shape_type tof_bin_edges_shape = { NUMBER_OF_TOF_BINS + 1 } ;
227- FArray1D tof_bin_edges_arr (tof_bin_edges_shape );
226+ FArray1D tof_bin_edges_arr ;
227+ yardl::resize (tof_bin_edges_arr, { NUMBER_OF_TOF_BINS + 1 } );
228228 for (std::size_t i = 0 ; i < tof_bin_edges_arr.size (); ++i)
229229 tof_bin_edges_arr[i] = (i - NUMBER_OF_TOF_BINS / 2 .F ) / NUMBER_OF_TOF_BINS * 2 * RADIUS;
230230 const petsird::BinEdges tof_bin_edges{ tof_bin_edges_arr };
231231 all_tof_bin_edges[type_of_module][type_of_module] = tof_bin_edges;
232232
233233 all_tof_resolutions[type_of_module][type_of_module] = 9 .4F ; // in mm
234234
235- FArray1D::shape_type event_energy_bin_edges_shape = { NUMBER_OF_EVENT_ENERGY_BINS + 1 } ;
236- FArray1D event_energy_bin_edges_arr (event_energy_bin_edges_shape );
235+ FArray1D event_energy_bin_edges_arr ;
236+ yardl::resize (event_energy_bin_edges_arr, { NUMBER_OF_EVENT_ENERGY_BINS + 1 } );
237237 for (std::size_t i = 0 ; i < event_energy_bin_edges_arr.size (); ++i)
238238 event_energy_bin_edges_arr[i] = 430 .F + i * (650 .F - 430 .F ) / NUMBER_OF_EVENT_ENERGY_BINS;
239239 petsird::BinEdges event_energy_bin_edges{ event_energy_bin_edges_arr };
240240 all_event_energy_bin_edges[type_of_module] = event_energy_bin_edges;
241241 all_event_energy_resolutions[type_of_module] = .11F ; // as fraction of 511
242-
243- scanner_info.tof_bin_edges = all_tof_bin_edges;
244- scanner_info.tof_resolution = all_tof_resolutions;
245- scanner_info.event_energy_bin_edges = all_event_energy_bin_edges;
246- scanner_info.energy_resolution_at_511 = all_event_energy_resolutions;
247242 }
248243
249- scanner_info. detection_efficiencies = get_detection_efficiencies (scanner_info);
244+ set_detection_efficiencies (scanner_info);
250245
251246 scanner_info.coincidence_policy = petsird::CoincidencePolicy::kRejectMultiples ;
252247 scanner_info.delayed_coincidences_are_stored = false ;
0 commit comments