STIR 6.4.0
InputStreamFromROOTFile.h
Go to the documentation of this file.
1
11/*
12 * Copyright (C) 2015, 2016 University of Leeds
13 Copyright (C) 2016, 2021, 2020, 2021 UCL
14 Copyright (C) 2018 University of Hull
15 This file is part of STIR.
16
17 SPDX-License-Identifier: Apache-2.0
18
19 See STIR/LICENSE.txt for details
20*/
21
22#ifndef __stir_IO_InputStreamFromROOTFile_H__
23#define __stir_IO_InputStreamFromROOTFile_H__
24
25#include "stir/shared_ptr.h"
26#include "stir/Succeeded.h"
29#include "stir/error.h"
30
31// forward declaration of ROOT's TChain
32class TChain;
33class TBranch;
34
35START_NAMESPACE_STIR
36
38
66
67class InputStreamFromROOTFile : public RegisteredObject<InputStreamFromROOTFile>
68{
69public:
70 typedef std::vector<long long int>::size_type SavedPosition;
71
74
75#if 0 // disabled as not used
77 InputStreamFromROOTFile(std::string filename,
78 std::string chain_name,
81 int offset_dets);
82#endif
83
85 {}
91 inline Succeeded reset();
93 virtual Succeeded set_up(const std::string& header_path);
95 inline SavedPosition save_get_position();
97 inline Succeeded set_get_position(const SavedPosition&);
99 inline std::vector<unsigned long int> get_saved_get_positions() const;
101 inline void set_saved_get_positions(const std::vector<unsigned long int>&);
103 inline unsigned long int get_total_number_of_events() const;
104
105 inline std::string get_ROOT_filename() const;
106
108 virtual int get_num_rings() const = 0;
110 virtual int get_num_dets_per_ring() const = 0;
112 virtual int get_num_axial_blocks_per_bucket_v() const = 0;
116 inline int get_num_axial_crystals_per_block_v() const;
124
130 inline int get_num_virtual_transaxial_crystals_per_block() const;
131 void set_num_virtual_axial_crystals_per_block(int);
132 void set_num_virtual_transaxial_crystals_per_block(int);
134
136 inline float get_low_energy_thres() const;
138 inline float get_up_energy_thres() const;
139
141 inline void set_singles_readout_depth(int);
142
143 inline void set_input_filename(const std::string&);
144
145 inline void set_chain_name(const std::string&);
146
147 inline void set_exclude_true_events(bool);
148
149 inline void set_exclude_scattered_events(bool);
150
151 inline void set_exclude_unscattered_events(bool);
152
153 inline void set_exclude_random_events(bool);
154
155#ifdef STIR_ROOT_ROTATION_AS_V4
156 inline void set_detectors_offset(int);
157#endif
158
159 inline void set_low_energy_window(float);
160
161 inline void set_upper_energy_window(float);
163 inline void set_optional_ROOT_fields(bool);
164
165 void set_crystal_repeater_x(int);
166 void set_crystal_repeater_y(int);
167 void set_crystal_repeater_z(int);
168
169protected:
170 void set_defaults() override;
171 void initialise_keymap() override;
172 bool post_processing() override;
173
175 std::string filename;
177 unsigned long int starting_stream_position;
179 unsigned long int nentries;
181 unsigned long int current_position;
183 std::vector<unsigned long int> saved_get_positions;
185 std::string chain_name;
192
194
195 int crystal_repeater_x;
196 int crystal_repeater_y;
197 int crystal_repeater_z;
198 //}
199
201
202 TChain* stream_ptr;
203 // note: should be ROOT's Int_t, Double_t and Float_t types, but those
204 // are only defined when including ROOT .h files, which we want to avoid
205 // here, as it creates a public dependency on the ROOT .h files
206 // checking https://github.com/root-project/root/blob/8695045aeff4b2e606a5febdcd58a0a7e7f6c7af/core/base/inc/RtypesCore.h
207 // we can use int32_t, float and double instead
208 std::int32_t eventID1, eventID2, runID, sourceID1, sourceID2;
209 double time1, time2;
210 float energy1, energy2, rotation_angle, sinogramS, sinogramTheta, axialPos;
211 int32_t comptonphantom1, comptonphantom2;
212 float globalPosX1, globalPosX2, globalPosY1, globalPosY2, globalPosZ1, globalPosZ2;
213 float sourcePosX1, sourcePosX2, sourcePosY1, sourcePosY2, sourcePosZ1, sourcePosZ2;
215
217
218 TBranch* br_time1 = nullptr;
219 TBranch* br_time2 = nullptr;
220 TBranch* br_eventID1 = nullptr;
221 TBranch* br_eventID2 = nullptr;
222 TBranch* br_energy1 = nullptr;
223 TBranch* br_energy2 = nullptr;
224 TBranch* br_comptonPhantom1 = nullptr;
225 TBranch* br_comptonPhantom2 = nullptr;
226 // Optional Branch variables. To be used if read_optional_root_fields is true.
227 TBranch* br_axialPos = nullptr;
228 TBranch* br_globalPosX1 = nullptr;
229 TBranch* br_globalPosX2 = nullptr;
230 TBranch* br_globalPosY1 = nullptr;
231 TBranch* br_globalPosY2 = nullptr;
232 TBranch* br_globalPosZ1 = nullptr;
233 TBranch* br_globalPosZ2 = nullptr;
234 TBranch* br_rotation_angle = nullptr;
235 TBranch* br_runID = nullptr;
236 TBranch* br_sinogramS = nullptr;
237 TBranch* br_sinogramTheta = nullptr;
238 TBranch* br_sourceID1 = nullptr;
239 TBranch* br_sourceID2 = nullptr;
240 TBranch* br_sourcePosX1 = nullptr;
241 TBranch* br_sourcePosX2 = nullptr;
242 TBranch* br_sourcePosY1 = nullptr;
243 TBranch* br_sourcePosY2 = nullptr;
244 TBranch* br_sourcePosZ1 = nullptr;
245 TBranch* br_sourcePosZ2 = nullptr;
247
249
250 int num_virtual_axial_crystals_per_block;
251 int num_virtual_transaxial_crystals_per_block;
253
267#ifdef STIR_ROOT_ROTATION_AS_V4
269 int offset_dets;
270#endif
275
276 // This member will try to give to the continuous time register in GATE
277 // data, a finite least significant bit.
278 double least_significant_clock_bit;
279
281 float get_energy1_in_keV() const
282 {
283 return energy1 * 1e3;
284 };
285 float get_energy2_in_keV() const
286 {
287 return energy2 * 1e3;
288 };
289
291 bool check_brentry_randoms_scatter_energy_conditions(long long int brentry);
292
294 void GetEntryCheck(const int ret)
295 {
296 if (ret > 0)
297 return;
298 error(ret == 0 ? "Entry is null." : "ROOT I/O error.");
299 };
300};
301
302END_NAMESPACE_STIR
303
305
306#endif
Classes for listmode events for GATE simulated ROOT data.
Implementation of class stir::InputStreamFromROOTFile.
Declaration of class stiir::RegisteredObject.
Declaration of class stir::Succeeded.
A class for a general element of a listmode file for a Siemens scanner using the ROOT files.
Definition CListRecordROOT.h:98
std::string chain_name
The name of the ROOT chain to be read.
Definition InputStreamFromROOTFile.h:185
int get_num_virtual_axial_crystals_per_block() const
Definition InputStreamFromROOTFile.inl:168
bool exclude_scattered
Skip scattered events (comptonphantom1 > 0 && comptonphantom2 > 0). Default is false.
Definition InputStreamFromROOTFile.h:256
unsigned long int starting_stream_position
The starting position.
Definition InputStreamFromROOTFile.h:177
InputStreamFromROOTFile()
Default constructor.
Definition InputStreamFromROOTFile.cxx:36
float get_energy1_in_keV() const
OpenGATE output ROOT energy information is given in MeV, these methods convert to keV.
Definition InputStreamFromROOTFile.h:281
unsigned long int nentries
The total number of entries.
Definition InputStreamFromROOTFile.h:179
bool exclude_nonrandom
Skip True events (eventID1 == eventID2). Default is false.
Definition InputStreamFromROOTFile.h:254
std::vector< unsigned long int > get_saved_get_positions() const
Get the vector with the saved positions.
Definition InputStreamFromROOTFile.inl:58
unsigned long int get_total_number_of_events() const
Returns the total number of events.
Definition InputStreamFromROOTFile.inl:25
void initialise_keymap() override
Initialise all keywords.
Definition InputStreamFromROOTFile.cxx:81
void set_optional_ROOT_fields(bool)
Set the read_optional_root_fields flag.
Definition InputStreamFromROOTFile.inl:150
void set_defaults() override
Set defaults before parsing.
Definition InputStreamFromROOTFile.cxx:61
std::vector< unsigned long int > saved_get_positions
A vector with saved position indices.
Definition InputStreamFromROOTFile.h:183
virtual Succeeded set_up(const std::string &header_path)
Must be called before calling for the first event.
Definition InputStreamFromROOTFile.cxx:110
float low_energy_window
Lower energy threshold. Default is 1000 (keV)
Definition InputStreamFromROOTFile.h:264
SavedPosition save_get_position()
Save current position in a vector.
Definition InputStreamFromROOTFile.inl:38
virtual int get_num_rings() const =0
Get the number of rings as calculated from the number of repeaters.
Succeeded reset()
Go to the first event.
Definition InputStreamFromROOTFile.inl:31
virtual int get_num_transaxial_blocks_per_bucket_v() const =0
Get the number of transaxial modules.
int get_num_axial_crystals_per_block_v() const
Get the axial number of crystals per module.
Definition InputStreamFromROOTFile.inl:156
void set_saved_get_positions(const std::vector< unsigned long int > &)
Set a vector with saved positions.
Definition InputStreamFromROOTFile.inl:64
float get_up_energy_thres() const
Upper energy threshold.
Definition InputStreamFromROOTFile.inl:76
int singles_readout_depth
For the singles_readout_depth from GATE's online documentation: (here )
Definition InputStreamFromROOTFile.h:274
unsigned long int current_position
Current get position.
Definition InputStreamFromROOTFile.h:181
virtual int get_num_trans_crystals_per_singles_unit() const =0
Get the number of transaxial crystals per singles unit.
virtual int get_num_dets_per_ring() const =0
Get the number of dets per ring as calculated from the number of repeaters.
void set_singles_readout_depth(int)
Set singles_readout_depth.
Definition InputStreamFromROOTFile.inl:88
Succeeded set_get_position(const SavedPosition &)
Set current position.
Definition InputStreamFromROOTFile.inl:46
int get_num_transaxial_crystals_per_block_v() const
Get the transaxial number of crystals per module.
Definition InputStreamFromROOTFile.inl:162
bool exclude_unscattered
Skip unscattered events (comptonphantom1 == 0 && comptonphantom2 == 0)). Default is false.
Definition InputStreamFromROOTFile.h:258
virtual int get_num_axial_blocks_per_bucket_v() const =0
Get the number of axial modules.
bool post_processing() override
This will be called at the end of the parsing.
Definition InputStreamFromROOTFile.cxx:104
bool exclude_randoms
Skip random events (eventID1 != eventID2). Default is false.
Definition InputStreamFromROOTFile.h:260
std::string filename
Input data file name.
Definition InputStreamFromROOTFile.h:175
float get_low_energy_thres() const
Lower energy threshold.
Definition InputStreamFromROOTFile.inl:70
bool read_optional_root_fields
This variable can be used to setBranchAddress to ROOT fields that currently are not used by STIR....
Definition InputStreamFromROOTFile.h:191
bool check_energy_window_information
Check energy window information (low_energy_window < energy < up_energy_window). Default is true.
Definition InputStreamFromROOTFile.h:262
virtual Succeeded get_next_record(CListRecordROOT &record)=0
void GetEntryCheck(const int ret)
Checks the return of branch->GetEntry(brentry) and errors if return <= 0.
Definition InputStreamFromROOTFile.h:294
float up_energy_window
Upper energy threshold. Default is 0 (keV)
Definition InputStreamFromROOTFile.h:266
virtual int get_num_axial_crystals_per_singles_unit() const =0
Get the number of axial crystals per singles unit.
a class containing an enumeration type that can be used by functions to signal successful operation o...
Definition Succeeded.h:44
Declaration of stir::error()
void error(const char *const s,...)
Print error with format string a la printf and throw exception.
Definition error.cxx:42
Import of std::shared_ptr, std::dynamic_pointer_cast and std::static_pointer_cast into the stir names...