LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
PhotonLibrary.h
Go to the documentation of this file.
1 #ifndef PHOTONLIBRARY_H
5 #define PHOTONLIBRARY_H
6 
8 
9 #include "TTree.h"
10 #include "TF1.h"
12 
14 
15 
16 namespace phot{
17 
19  {
20  public:
21  PhotonLibrary() = default;
22 
23  TTree * ProduceTTree() const;
24 
25 
26  virtual float GetCount(size_t Voxel, size_t OpChannel) const override;
27  void SetCount(size_t Voxel, size_t OpChannel, float Count);
28 
29  float GetTimingPar(size_t Voxel, size_t OpChannel, size_t parnum) const;
30  void SetTimingPar(size_t Voxel, size_t OpChannel, float Count, size_t parnum);
31 
32 // TF1& GetTimingTF1(size_t Voxel, size_t OpChannel) const;
33  void SetTimingTF1(size_t Voxel, size_t OpChannel, TF1 func);
34 
35 
36  virtual float GetReflCount(size_t Voxel, size_t OpChannel) const override;
37  void SetReflCount(size_t Voxel, size_t OpChannel, float Count);
38 
39  virtual float GetReflT0(size_t Voxel, size_t OpChannel) const override;
40  void SetReflT0(size_t Voxel, size_t OpChannel, float reflT0);
41 
43  virtual float const* GetCounts(size_t Voxel) const override;
44  const std::vector<float>* GetTimingPars(size_t Voxel) const;
45  TF1* GetTimingTF1s(size_t Voxel) const;
46 
47  virtual float const* GetReflCounts(size_t Voxel) const override;
48  virtual float const* GetReflT0s(size_t Voxel) const override;
49 
51  bool hasTiming() const { return fHasTiming; }
52 
54  virtual bool hasReflected() const override { return fHasReflected; }
55 
57  virtual bool hasReflectedT0() const override { return fHasReflectedT0; }
58 
59 
60  void StoreLibraryToFile(std::string LibraryFile, bool storeReflected=false, bool storeReflT0=false, size_t storeTiming=0) const;
61  void LoadLibraryFromFile(std::string LibraryFile, size_t NVoxels, bool storeReflected=false, bool storeReflT0=false, size_t storeTiming=0);
62  void CreateEmptyLibrary(size_t NVoxels, size_t NChannels, bool storeReflected=false, bool storeReflT0=false, size_t storeTiming=0);
63 
64 
65  virtual int NOpChannels() const override { return fNOpChannels; }
66  virtual int NVoxels() const override { return fNVoxels; }
67 
68  private:
69 
70  bool fHasReflected = false;
71  bool fHasReflectedT0 = false;
72 
73  size_t fHasTiming = 0;
74 
75 
76  // fLookupTable[unchecked_index(Voxel, OpChannel)] = Count
77  // for each voxel, all NChannels() channels are stored in sequence
83  std::string fTimingParFormula;
85 
86  size_t fNOpChannels;
87  size_t fNVoxels;
88 
90  size_t uncheckedIndex(size_t Voxel, size_t OpChannel) const
91  { return Voxel * fNOpChannels + OpChannel; }
92 
94  float uncheckedAccess (size_t Voxel, size_t OpChannel) const
95  { return fLookupTable[uncheckedIndex(Voxel, OpChannel)]; }
96 
98  float& uncheckedAccess(size_t Voxel, size_t OpChannel)
99  { return fLookupTable[uncheckedIndex(Voxel, OpChannel)]; }
100 
102  float uncheckedAccessRefl (size_t Voxel, size_t OpChannel) const
103  { return fReflLookupTable[uncheckedIndex(Voxel, OpChannel)]; }
104 
106  float& uncheckedAccessRefl(size_t Voxel, size_t OpChannel)
107  { return fReflLookupTable[uncheckedIndex(Voxel, OpChannel)]; }
108 
110  float uncheckedAccessReflT (size_t Voxel, size_t OpChannel) const
111  { return fReflTLookupTable[uncheckedIndex(Voxel, OpChannel)]; }
112 
114  float& uncheckedAccessReflT(size_t Voxel, size_t OpChannel)
115  { return fReflTLookupTable[uncheckedIndex(Voxel, OpChannel)]; }
116 
117 
119  float uncheckedAccessTimingPar (size_t Voxel, size_t OpChannel, size_t parnum) const
120  { return fTimingParLookupTable[uncheckedIndex(Voxel, OpChannel)][parnum];}
121 
123  float& uncheckedAccessTimingPar(size_t Voxel, size_t OpChannel, size_t parnum)
124  { return fTimingParLookupTable[uncheckedIndex(Voxel, OpChannel)][parnum]; }
125 
126 
128  TF1& uncheckedAccessTimingTF1(size_t Voxel, size_t OpChannel)
129  { return fTimingParTF1LookupTable[uncheckedIndex(Voxel, OpChannel)]; }
130 
132  const TF1& uncheckedAccessTimingTF1(size_t Voxel, size_t OpChannel) const
133  {
134  // note that this will produce a segmentation fault if the formula is not there
135  return *(fTimingParTF1LookupTable.data_address(uncheckedIndex(Voxel, OpChannel)));
136  }
137 
139  static std::string const OpChannelBranchName;
140 
142  static size_t ExtractNOpChannels(TTree* tree);
143 
145  static int size_t2int(size_t val) {
146  return (val <= INT_MAX) ? (int)((ssize_t)val) : -1; }
147  };
148 
149 }
150 
151 #endif
virtual float GetReflT0(size_t Voxel, size_t OpChannel) const override
const_pointer data_address(size_type pos) const
Returns a constant pointer to the specified element.
Definition: LazyVector.h:510
size_t fTimingParNParameters
Definition: PhotonLibrary.h:84
static int size_t2int(size_t val)
Converts size_t into integer.
TTree * ProduceTTree() const
float & uncheckedAccess(size_t Voxel, size_t OpChannel)
Unchecked access to a visibility datum.
Definition: PhotonLibrary.h:98
size_t fHasTiming
Whether the current library deals with time propagation distribution.
Definition: PhotonLibrary.h:73
util::LazyVector< float > fReflLookupTable
Definition: PhotonLibrary.h:79
virtual float const * GetCounts(size_t Voxel) const override
Returns a pointer to NOpChannels() visibility values, one per channel.
bool fHasReflectedT0
Whether the current library deals with reflected light timing.
Definition: PhotonLibrary.h:71
void CreateEmptyLibrary(size_t NVoxels, size_t NChannels, bool storeReflected=false, bool storeReflT0=false, size_t storeTiming=0)
virtual float const * GetReflT0s(size_t Voxel) const override
virtual int NOpChannels() const override
Definition: PhotonLibrary.h:65
virtual float GetReflCount(size_t Voxel, size_t OpChannel) const override
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.
Definition: PhotonLibrary.h:94
void StoreLibraryToFile(std::string LibraryFile, bool storeReflected=false, bool storeReflT0=false, size_t storeTiming=0) const
float uncheckedAccessReflT(size_t Voxel, size_t OpChannel) const
Unchecked access to a reflected T0 visibility datum.
void SetCount(size_t Voxel, size_t OpChannel, float Count)
void SetTimingTF1(size_t Voxel, size_t OpChannel, TF1 func)
std::string fTimingParFormula
Definition: PhotonLibrary.h:83
size_t uncheckedIndex(size_t Voxel, size_t OpChannel) const
Returns the index of visibility of specified voxel and cell.
Definition: PhotonLibrary.h:90
PhotonLibrary()=default
util::LazyVector< float > fLookupTable
Definition: PhotonLibrary.h:78
virtual bool hasReflectedT0() const override
Returns whether the current library deals with reflected light timing.
Definition: PhotonLibrary.h:57
static size_t ExtractNOpChannels(TTree *tree)
Returns the number of optical channels in the specified tree.
void SetReflT0(size_t Voxel, size_t OpChannel, float reflT0)
bool fHasReflected
Whether the current library deals with reflected light counts.
Definition: PhotonLibrary.h:70
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.
TF1 * GetTimingTF1s(size_t Voxel) const
const std::vector< float > * GetTimingPars(size_t Voxel) const
Contiguous data container with lazy resizing on access.
util::LazyVector< TF1 > fTimingParTF1LookupTable
Definition: PhotonLibrary.h:82
void LoadLibraryFromFile(std::string LibraryFile, size_t NVoxels, bool storeReflected=false, bool storeReflT0=false, size_t storeTiming=0)
virtual float GetCount(size_t Voxel, size_t OpChannel) const override
void SetTimingPar(size_t Voxel, size_t OpChannel, float Count, size_t parnum)
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:54
float GetTimingPar(size_t Voxel, size_t OpChannel, size_t parnum) const
Interface shared by all PhotonLibrary-like classes.
util::LazyVector< std::vector< float > > fTimingParLookupTable
Definition: PhotonLibrary.h:81
util::LazyVector< float > fReflTLookupTable
Definition: PhotonLibrary.h:80
float & uncheckedAccessReflT(size_t Voxel, size_t OpChannel)
Unchecked access to a reflected T0 visibility datum.
virtual float const * GetReflCounts(size_t Voxel) const override
virtual int NVoxels() const override
Definition: PhotonLibrary.h:66
void SetReflCount(size_t Voxel, size_t OpChannel, float Count)
bool hasTiming() const
Returns whether the current library deals with time propagation distributions.
Definition: PhotonLibrary.h:51
float uncheckedAccessTimingPar(size_t Voxel, size_t OpChannel, size_t parnum) const
Unchecked access to a parameter the time distribution.