STIR  6.2.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"
28 #include "stir/RegisteredObject.h"
29 #include "stir/error.h"
30 
31 // forward declaration of ROOT's TChain
32 class TChain;
33 class TBranch;
34 
35 START_NAMESPACE_STIR
36 
38 
67 class InputStreamFromROOTFile : public RegisteredObject<InputStreamFromROOTFile>
68 {
69 public:
70  typedef std::vector<long long int>::size_type SavedPosition;
71 
74 
75 #if 0 // disabled as not used
76  InputStreamFromROOTFile(std::string filename,
78  std::string chain_name,
79  bool exclude_scattered, bool exclude_randoms,
80  float low_energy_window, float up_energy_window,
81  int offset_dets);
82 #endif
83 
84  ~InputStreamFromROOTFile() override
85  {}
89  virtual Succeeded get_next_record(CListRecordROOT& record) = 0;
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;
114  virtual int get_num_transaxial_blocks_per_bucket_v() const = 0;
116  inline int get_num_axial_crystals_per_block_v() const;
118  inline int get_num_transaxial_crystals_per_block_v() const;
120  virtual int get_num_axial_crystals_per_singles_unit() const = 0;
122  virtual int get_num_trans_crystals_per_singles_unit() const = 0;
124 
128 
129  inline int get_num_virtual_axial_crystals_per_block() const;
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 
169 protected:
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  bool exclude_nonrandom;
267 #ifdef STIR_ROOT_ROTATION_AS_V4
268  int offset_dets;
270 #endif
271  int singles_readout_depth;
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 
302 END_NAMESPACE_STIR
303 
305 
306 #endif
Declaration of class stir::Succeeded.
std::string filename
Input data file name.
Definition: InputStreamFromROOTFile.h:175
bool exclude_unscattered
Skip unscattered events (comptonphantom1 == 0 && comptonphantom2 == 0)). Default is false...
Definition: InputStreamFromROOTFile.h:258
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
std::string chain_name
The name of the ROOT chain to be read.
Definition: InputStreamFromROOTFile.h:185
unsigned long int nentries
The total number of entries.
Definition: InputStreamFromROOTFile.h:179
float get_energy1_in_keV() const
OpenGATE output ROOT energy information is given in MeV, these methods convert to keV...
Definition: InputStreamFromROOTFile.h:281
Import of std::shared_ptr, std::dynamic_pointer_cast and std::static_pointer_cast (or corresponding b...
bool exclude_randoms
Skip random events (eventID1 != eventID2). Default is false.
Definition: InputStreamFromROOTFile.h:260
Declaration of stir::error()
Classes for listmode events for GATE simulated ROOT data.
A class for a general element of a listmode file for a Siemens scanner using the ROOT files...
Definition: CListRecordROOT.h:97
float low_energy_window
Lower energy threshold. Default is 1000 (keV)
Definition: InputStreamFromROOTFile.h:264
float up_energy_window
Upper energy threshold. Default is 0 (keV)
Definition: InputStreamFromROOTFile.h:266
std::vector< unsigned long int > saved_get_positions
A vector with saved position indices.
Definition: InputStreamFromROOTFile.h:183
Declaration of class stiir::RegisteredObject.
Helper class to provide registry mechanisms to a Base classSuppose you have a hierarchy of classes wi...
Definition: RegisteredObject.h:95
Implementation of class stir::InputStreamFromROOTFile.
void error(const char *const s,...)
Print error with format string a la printf and throw exception.
Definition: error.cxx:42
bool exclude_scattered
Skip scattered events (comptonphantom1 > 0 && comptonphantom2 > 0). Default is false.
Definition: InputStreamFromROOTFile.h:256
unsigned long int current_position
Current get position.
Definition: InputStreamFromROOTFile.h:181
a class containing an enumeration type that can be used by functions to signal successful operation o...
Definition: Succeeded.h:43
void GetEntryCheck(const int ret)
Checks the return of branch->GetEntry(brentry) and errors if return <= 0.
Definition: InputStreamFromROOTFile.h:294
unsigned long int starting_stream_position
The starting position.
Definition: InputStreamFromROOTFile.h:177
A helper class to read data from a ROOT file Generated by GATE simulation toolkit.
Definition: InputStreamFromROOTFile.h:67