LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
PhotonLibrary.h
Go to the documentation of this file.
1 #ifndef PHOTONLIBRARY_H
5 #define PHOTONLIBRARY_H
6 
8 
10 
11 #include "TF1.h"
12 class TTree;
13 
15 
16 #include <limits> // std::numeric_limits
17 #include <optional>
18 
19 namespace art {
20  class TFileDirectory;
21 }
22 
23 namespace phot {
24 
25  class PhotonLibrary : public IPhotonLibrary {
26  public:
28  PhotonLibrary(art::TFileDirectory* pDir = nullptr);
29 
30  TTree* ProduceTTree() const;
31 
32  virtual float GetCount(size_t Voxel, size_t OpChannel) const override;
33  void SetCount(size_t Voxel, size_t OpChannel, float Count);
34 
35  float GetTimingPar(size_t Voxel, size_t OpChannel, size_t parnum) const;
36  void SetTimingPar(size_t Voxel, size_t OpChannel, float Count, size_t parnum);
37 
38  // TF1& GetTimingTF1(size_t Voxel, size_t OpChannel) const;
39  void SetTimingTF1(size_t Voxel, size_t OpChannel, TF1 func);
40 
41  virtual float GetReflCount(size_t Voxel, size_t OpChannel) const override;
42  void SetReflCount(size_t Voxel, size_t OpChannel, float Count);
43 
44  virtual float GetReflT0(size_t Voxel, size_t OpChannel) const override;
45  void SetReflT0(size_t Voxel, size_t OpChannel, float reflT0);
46 
48  virtual float const* GetCounts(size_t Voxel) const override;
49  const std::vector<float>* GetTimingPars(size_t Voxel) const;
50  TF1* GetTimingTF1s(size_t Voxel) const;
51 
52  virtual float const* GetReflCounts(size_t Voxel) const override;
53  virtual float const* GetReflT0s(size_t Voxel) const override;
54 
56  bool hasTiming() const { return fHasTiming; }
57 
59  virtual bool hasReflected() const override { return fHasReflected; }
60 
62  virtual bool hasReflectedT0() const override { return fHasReflectedT0; }
63 
64  void StoreLibraryToFile(std::string LibraryFile,
65  bool storeReflected = false,
66  bool storeReflT0 = false,
67  size_t storeTiming = 0) const;
68  void LoadLibraryFromFile(std::string LibraryFile,
69  size_t NVoxels,
70  bool storeReflected = false,
71  bool storeReflT0 = false,
72  size_t storeTiming = 0,
73  int maxrange = 200);
74  void CreateEmptyLibrary(size_t NVoxels,
75  size_t NChannels,
76  bool storeReflected = false,
77  bool storeReflT0 = false,
78  size_t storeTiming = 0);
79 
80  // --- BEGIN --- Metadata: voxel information -------------------------------
83 
85  bool hasVoxelDef() const { return fVoxelDef.has_value(); }
86 
90  {
91  assert(fVoxelDef);
92  return *fVoxelDef;
93  }
94 
97  void SetVoxelDef(sim::PhotonVoxelDef const& voxelDef) { fVoxelDef = voxelDef; }
98 
100  // --- END --- Metadata: voxel information ---------------------------------
101 
102  private:
103  virtual int NOpChannels() const override { return fNOpChannels; }
104  virtual int NVoxels() const override { return fNVoxels; }
105 
106  virtual bool isVoxelValid(size_t Voxel) const override { return isVoxelValidImpl(Voxel); }
107 
108  bool fHasReflected = false;
109  bool fHasReflectedT0 =
110  false;
111 
112  size_t fHasTiming =
113  0;
114 
115  // fLookupTable[unchecked_index(Voxel, OpChannel)] = Count
116  // for each voxel, all NChannels() channels are stored in sequence
122  std::string fTimingParFormula;
124 
125  size_t fNOpChannels;
126  size_t fNVoxels;
127 
129  std::optional<sim::PhotonVoxelDef> fVoxelDef;
130 
132  art::TFileDirectory* fDir = nullptr;
133 
134  bool isVoxelValidImpl(size_t Voxel) const { return Voxel < fNVoxels; }
135 
137  size_t uncheckedIndex(size_t Voxel, size_t OpChannel) const
138  {
139  return Voxel * fNOpChannels + OpChannel;
140  }
141 
143  float uncheckedAccess(size_t Voxel, size_t OpChannel) const
144  {
145  return fLookupTable[uncheckedIndex(Voxel, OpChannel)];
146  }
147 
149  float& uncheckedAccess(size_t Voxel, size_t OpChannel)
150  {
151  return fLookupTable[uncheckedIndex(Voxel, OpChannel)];
152  }
153 
155  float uncheckedAccessRefl(size_t Voxel, size_t OpChannel) const
156  {
157  return fReflLookupTable[uncheckedIndex(Voxel, OpChannel)];
158  }
159 
161  float& uncheckedAccessRefl(size_t Voxel, size_t OpChannel)
162  {
163  return fReflLookupTable[uncheckedIndex(Voxel, OpChannel)];
164  }
165 
167  float uncheckedAccessReflT(size_t Voxel, size_t OpChannel) const
168  {
169  return fReflTLookupTable[uncheckedIndex(Voxel, OpChannel)];
170  }
171 
173  float& uncheckedAccessReflT(size_t Voxel, size_t OpChannel)
174  {
175  return fReflTLookupTable[uncheckedIndex(Voxel, OpChannel)];
176  }
177 
179  float uncheckedAccessTimingPar(size_t Voxel, size_t OpChannel, size_t parnum) const
180  {
181  return fTimingParLookupTable[uncheckedIndex(Voxel, OpChannel)][parnum];
182  }
183 
185  float& uncheckedAccessTimingPar(size_t Voxel, size_t OpChannel, size_t parnum)
186  {
187  return fTimingParLookupTable[uncheckedIndex(Voxel, OpChannel)][parnum];
188  }
189 
191  TF1& uncheckedAccessTimingTF1(size_t Voxel, size_t OpChannel)
192  {
193  return fTimingParTF1LookupTable[uncheckedIndex(Voxel, OpChannel)];
194  }
195 
197  const TF1& uncheckedAccessTimingTF1(size_t Voxel, size_t OpChannel) const
198  {
199  // note that this will produce a segmentation fault if the formula is not there
200  return *(fTimingParTF1LookupTable.data_address(uncheckedIndex(Voxel, OpChannel)));
201  }
202 
204  void LoadMetadata(TDirectory& srcDir);
205 
207  void StoreMetadata() const;
208 
210  static std::string const OpChannelBranchName;
211 
213  static size_t ExtractNOpChannels(TTree* tree);
214 
216  static int size_t2int(size_t val)
217  {
218  constexpr size_t int_max_as_size_t{std::numeric_limits<int>::max()};
219  return val <= int_max_as_size_t ? static_cast<int>(val) : -1;
220  }
221  };
222 
223 }
224 
225 #endif
Definitions of voxel data structures.
const_pointer data_address(size_type pos) const
Returns a constant pointer to the specified element.
Definition: LazyVector.h:549
static int size_t2int(size_t val)
Converts size_t into integer.
std::optional< sim::PhotonVoxelDef > fVoxelDef
Voxel definition loaded from library metadata.
float & uncheckedAccess(size_t Voxel, size_t OpChannel)
Unchecked access to a visibility datum.
util::LazyVector< float > fReflLookupTable
sim::PhotonVoxelDef const & GetVoxelDef() const
Definition: PhotonLibrary.h:89
bool hasVoxelDef() const
Returns whether voxel metadata is available.
Definition: PhotonLibrary.h:85
virtual int NOpChannels() const override
Representation of a region of space diced into voxels.
Definition: PhotonVoxels.h:58
static std::string const OpChannelBranchName
Name of the optical channel number in the input tree.
float uncheckedAccess(size_t Voxel, size_t OpChannel) const
Unchecked access to a visibility datum.
float uncheckedAccessReflT(size_t Voxel, size_t OpChannel) const
Unchecked access to a reflected T0 visibility datum.
std::string fTimingParFormula
size_t uncheckedIndex(size_t Voxel, size_t OpChannel) const
Returns the index of visibility of specified voxel and cell.
util::LazyVector< float > fLookupTable
virtual bool hasReflectedT0() const override
Returns whether the current library deals with reflected light timing.
Definition: PhotonLibrary.h:62
void SetVoxelDef(sim::PhotonVoxelDef const &voxelDef)
Definition: PhotonLibrary.h:97
bool isVoxelValidImpl(size_t Voxel) const
const TF1 & uncheckedAccessTimingTF1(size_t Voxel, size_t OpChannel) const
Unchecked access to a parameter of the time distribution.
TF1 & uncheckedAccessTimingTF1(size_t Voxel, size_t OpChannel)
Unchecked access to a parameter of the time distribution.
float & uncheckedAccessTimingPar(size_t Voxel, size_t OpChannel, size_t parnum)
Unchecked access to a parameter of the time distribution.
Contiguous data container with lazy resizing on access.
util::LazyVector< TF1 > fTimingParTF1LookupTable
virtual bool isVoxelValid(size_t Voxel) const override
General LArSoft Utilities.
float uncheckedAccessRefl(size_t Voxel, size_t OpChannel) const
Unchecked access to a reflected visibility datum.
float & uncheckedAccessRefl(size_t Voxel, size_t OpChannel)
Unchecked access to a reflected visibility datum.
virtual bool hasReflected() const override
Returns whether the current library deals with reflected light count.
Definition: PhotonLibrary.h:59
Definition: MVAAlg.h:12
Interface shared by all PhotonLibrary-like classes.
util::LazyVector< std::vector< float > > fTimingParLookupTable
util::LazyVector< float > fReflTLookupTable
float & uncheckedAccessReflT(size_t Voxel, size_t OpChannel)
Unchecked access to a reflected T0 visibility datum.
virtual int NVoxels() const override
bool hasTiming() const
Returns whether the current library deals with time propagation distributions.
Definition: PhotonLibrary.h:56
float uncheckedAccessTimingPar(size_t Voxel, size_t OpChannel, size_t parnum) const
Unchecked access to a parameter the time distribution.