LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
phot::PhotonLibrary Class Reference

#include "PhotonLibrary.h"

Inheritance diagram for phot::PhotonLibrary:
phot::IPhotonLibrary

Public Member Functions

 PhotonLibrary ()=default
 
TTree * ProduceTTree () const
 
virtual float GetCount (size_t Voxel, size_t OpChannel) const override
 
void SetCount (size_t Voxel, size_t OpChannel, float Count)
 
float GetTimingPar (size_t Voxel, size_t OpChannel, size_t parnum) const
 
void SetTimingPar (size_t Voxel, size_t OpChannel, float Count, size_t parnum)
 
void SetTimingTF1 (size_t Voxel, size_t OpChannel, TF1 func)
 
virtual float GetReflCount (size_t Voxel, size_t OpChannel) const override
 
void SetReflCount (size_t Voxel, size_t OpChannel, float Count)
 
virtual float GetReflT0 (size_t Voxel, size_t OpChannel) const override
 
void SetReflT0 (size_t Voxel, size_t OpChannel, float reflT0)
 
virtual float const * GetCounts (size_t Voxel) const override
 Returns a pointer to NOpChannels() visibility values, one per channel. More...
 
const std::vector< float > * GetTimingPars (size_t Voxel) const
 
TF1 * GetTimingTF1s (size_t Voxel) const
 
virtual float const * GetReflCounts (size_t Voxel) const override
 
virtual float const * GetReflT0s (size_t Voxel) const override
 
bool hasTiming () const
 Returns whether the current library deals with time propagation distributions. More...
 
virtual bool hasReflected () const override
 Returns whether the current library deals with reflected light count. More...
 
virtual bool hasReflectedT0 () const override
 Returns whether the current library deals with reflected light timing. More...
 
void StoreLibraryToFile (std::string LibraryFile, bool storeReflected=false, bool storeReflT0=false, size_t storeTiming=0) const
 
void LoadLibraryFromFile (std::string LibraryFile, size_t NVoxels, bool storeReflected=false, bool storeReflT0=false, size_t storeTiming=0)
 
void CreateEmptyLibrary (size_t NVoxels, size_t NChannels, bool storeReflected=false, bool storeReflT0=false, size_t storeTiming=0)
 
virtual int NOpChannels () const override
 
virtual int NVoxels () const override
 
size_t LibrarySize () const
 Returns the number of elements in the library. More...
 

Private Member Functions

size_t uncheckedIndex (size_t Voxel, size_t OpChannel) const
 Returns the index of visibility of specified voxel and cell. More...
 
float uncheckedAccess (size_t Voxel, size_t OpChannel) const
 Unchecked access to a visibility datum. More...
 
float & uncheckedAccess (size_t Voxel, size_t OpChannel)
 Unchecked access to a visibility datum. More...
 
float uncheckedAccessRefl (size_t Voxel, size_t OpChannel) const
 Unchecked access to a reflected visibility datum. More...
 
float & uncheckedAccessRefl (size_t Voxel, size_t OpChannel)
 Unchecked access to a reflected visibility datum. More...
 
float uncheckedAccessReflT (size_t Voxel, size_t OpChannel) const
 Unchecked access to a reflected T0 visibility datum. More...
 
float & uncheckedAccessReflT (size_t Voxel, size_t OpChannel)
 Unchecked access to a reflected T0 visibility datum. More...
 
float uncheckedAccessTimingPar (size_t Voxel, size_t OpChannel, size_t parnum) const
 Unchecked access to a parameter the time distribution. More...
 
float & uncheckedAccessTimingPar (size_t Voxel, size_t OpChannel, size_t parnum)
 Unchecked access to a parameter of the time distribution. More...
 
TF1 & uncheckedAccessTimingTF1 (size_t Voxel, size_t OpChannel)
 Unchecked access to a parameter of the time distribution. More...
 
const TF1 & uncheckedAccessTimingTF1 (size_t Voxel, size_t OpChannel) const
 Unchecked access to a parameter of the time distribution. More...
 

Static Private Member Functions

static size_t ExtractNOpChannels (TTree *tree)
 Returns the number of optical channels in the specified tree. More...
 
static int size_t2int (size_t val)
 Converts size_t into integer. More...
 

Private Attributes

bool fHasReflected = false
 Whether the current library deals with reflected light counts. More...
 
bool fHasReflectedT0 = false
 Whether the current library deals with reflected light timing. More...
 
size_t fHasTiming = 0
 Whether the current library deals with time propagation distribution. More...
 
util::LazyVector< float > fLookupTable
 
util::LazyVector< float > fReflLookupTable
 
util::LazyVector< float > fReflTLookupTable
 
util::LazyVector< std::vector< float > > fTimingParLookupTable
 
util::LazyVector< TF1 > fTimingParTF1LookupTable
 
std::string fTimingParFormula
 
size_t fTimingParNParameters
 
size_t fNOpChannels
 
size_t fNVoxels
 

Static Private Attributes

static std::string const OpChannelBranchName = "OpChannel"
 Name of the optical channel number in the input tree. More...
 

Detailed Description

Definition at line 18 of file PhotonLibrary.h.

Constructor & Destructor Documentation

phot::PhotonLibrary::PhotonLibrary ( )
default

Member Function Documentation

void phot::PhotonLibrary::CreateEmptyLibrary ( size_t  NVoxels,
size_t  NChannels,
bool  storeReflected = false,
bool  storeReflT0 = false,
size_t  storeTiming = 0 
)

Definition at line 104 of file PhotonLibrary.cxx.

References util::LazyVector< T, A >::clear(), fHasReflected, fHasReflectedT0, fHasTiming, fLookupTable, fNOpChannels, fNVoxels, fReflLookupTable, fReflTLookupTable, fTimingParLookupTable, fTimingParTF1LookupTable, phot::IPhotonLibrary::LibrarySize(), NOpChannels(), NVoxels(), and util::LazyVector< T, A >::resize().

Referenced by hasReflectedT0(), and phot::PhotonVisibilityService::LoadLibrary().

109  {
115 
116  fNVoxels = NVoxels;
118 
120  fHasReflected = storeReflected;
121  if (storeReflected) fReflLookupTable.resize(LibrarySize());
122  fHasReflectedT0 = storeReflT0;
123  if (storeReflT0) fReflTLookupTable.resize(LibrarySize());
124  fHasTiming = storeTiming;
125  if (storeTiming!=0)
126  {
129  }
130  }
size_t fHasTiming
Whether the current library deals with time propagation distribution.
Definition: PhotonLibrary.h:73
util::LazyVector< float > fReflLookupTable
Definition: PhotonLibrary.h:79
bool fHasReflectedT0
Whether the current library deals with reflected light timing.
Definition: PhotonLibrary.h:71
virtual int NOpChannels() const override
Definition: PhotonLibrary.h:65
void clear()
Removes all stored data and sets the nominal size to 0.
Definition: LazyVector.h:548
util::LazyVector< float > fLookupTable
Definition: PhotonLibrary.h:78
bool fHasReflected
Whether the current library deals with reflected light counts.
Definition: PhotonLibrary.h:70
util::LazyVector< TF1 > fTimingParTF1LookupTable
Definition: PhotonLibrary.h:82
size_t LibrarySize() const
Returns the number of elements in the library.
void resize(size_type newSize)
Changes the nominal size of the container.
Definition: LazyVector.h:528
util::LazyVector< std::vector< float > > fTimingParLookupTable
Definition: PhotonLibrary.h:81
util::LazyVector< float > fReflTLookupTable
Definition: PhotonLibrary.h:80
virtual int NVoxels() const override
Definition: PhotonLibrary.h:66
size_t phot::PhotonLibrary::ExtractNOpChannels ( TTree *  tree)
staticprivate

Returns the number of optical channels in the specified tree.

Definition at line 402 of file PhotonLibrary.cxx.

References LOG_DEBUG, art::errors::NotFound, and OpChannelBranchName.

Referenced by LoadLibraryFromFile().

402  {
403  TBranch* channelBranch = tree->GetBranch(OpChannelBranchName.c_str());
404  if (!channelBranch) {
406  << "Tree '" << tree->GetName() << "' has no branch 'OpChannel'";
407  }
408 
409  // fix a new local address for the branch
410  char* oldAddress = channelBranch->GetAddress();
411  Int_t channel;
412  channelBranch->SetAddress(&channel);
413  Int_t maxChannel = -1;
414 
415  // read all the channel values and pick the largest one
416  Long64_t iEntry = 0;
417  while (channelBranch->GetEntry(iEntry++)) {
418  if (channel > maxChannel) maxChannel = channel;
419  } // while
420 
421  LOG_DEBUG("PhotonLibrary")
422  << "Detected highest channel to be " << maxChannel << " from " << iEntry
423  << " tree entries";
424 
425  // restore the old branch address
426  channelBranch->SetAddress(oldAddress);
427 
428  return size_t(maxChannel + 1);
429 
430  } // PhotonLibrary::ExtractNOpChannels()
static std::string const OpChannelBranchName
Name of the optical channel number in the input tree.
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
#define LOG_DEBUG(id)
float phot::PhotonLibrary::GetCount ( size_t  Voxel,
size_t  OpChannel 
) const
overridevirtual

Implements phot::IPhotonLibrary.

Definition at line 260 of file PhotonLibrary.cxx.

References fNOpChannels, fNVoxels, and uncheckedAccess().

261  {
262  if ((Voxel >= fNVoxels) || (OpChannel >= fNOpChannels))
263  return 0;
264  else
265  return uncheckedAccess(Voxel, OpChannel);
266  }
float uncheckedAccess(size_t Voxel, size_t OpChannel) const
Unchecked access to a visibility datum.
Definition: PhotonLibrary.h:94
float const * phot::PhotonLibrary::GetCounts ( size_t  Voxel) const
overridevirtual

Returns a pointer to NOpChannels() visibility values, one per channel.

Implements phot::IPhotonLibrary.

Definition at line 343 of file PhotonLibrary.cxx.

References util::LazyVector< T, A >::data_address(), fLookupTable, fNVoxels, and uncheckedIndex().

344  {
345  if (Voxel >= fNVoxels) return nullptr;
346  else return fLookupTable.data_address(uncheckedIndex(Voxel, 0));
347  }
const_pointer data_address(size_type pos) const
Returns a constant pointer to the specified element.
Definition: LazyVector.h:510
size_t uncheckedIndex(size_t Voxel, size_t OpChannel) const
Returns the index of visibility of specified voxel and cell.
Definition: PhotonLibrary.h:90
util::LazyVector< float > fLookupTable
Definition: PhotonLibrary.h:78
float phot::PhotonLibrary::GetReflCount ( size_t  Voxel,
size_t  OpChannel 
) const
overridevirtual

Implements phot::IPhotonLibrary.

Definition at line 277 of file PhotonLibrary.cxx.

References fNOpChannels, fNVoxels, and uncheckedAccessRefl().

278  {
279  if ((Voxel >= fNVoxels) || (OpChannel >= fNOpChannels))
280  return 0;
281  else
282  return uncheckedAccessRefl(Voxel, OpChannel);
283  }
float uncheckedAccessRefl(size_t Voxel, size_t OpChannel) const
Unchecked access to a reflected visibility datum.
float const * phot::PhotonLibrary::GetReflCounts ( size_t  Voxel) const
overridevirtual

Implements phot::IPhotonLibrary.

Definition at line 386 of file PhotonLibrary.cxx.

References util::LazyVector< T, A >::data_address(), fNVoxels, fReflLookupTable, and uncheckedIndex().

387  {
388  if (Voxel >= fNVoxels) return nullptr;
389  else return fReflLookupTable.data_address(uncheckedIndex(Voxel, 0));
390  }
const_pointer data_address(size_type pos) const
Returns a constant pointer to the specified element.
Definition: LazyVector.h:510
util::LazyVector< float > fReflLookupTable
Definition: PhotonLibrary.h:79
size_t uncheckedIndex(size_t Voxel, size_t OpChannel) const
Returns the index of visibility of specified voxel and cell.
Definition: PhotonLibrary.h:90
float phot::PhotonLibrary::GetReflT0 ( size_t  Voxel,
size_t  OpChannel 
) const
overridevirtual

Implements phot::IPhotonLibrary.

Definition at line 286 of file PhotonLibrary.cxx.

References fNOpChannels, fNVoxels, and uncheckedAccessReflT().

287  {
288  if ((Voxel >= fNVoxels) || (OpChannel >= fNOpChannels))
289  return 0;
290  else
291  return uncheckedAccessReflT(Voxel, OpChannel);
292  }
float uncheckedAccessReflT(size_t Voxel, size_t OpChannel) const
Unchecked access to a reflected T0 visibility datum.
float const * phot::PhotonLibrary::GetReflT0s ( size_t  Voxel) const
overridevirtual

Implements phot::IPhotonLibrary.

Definition at line 394 of file PhotonLibrary.cxx.

References util::LazyVector< T, A >::data_address(), fNVoxels, fReflTLookupTable, and uncheckedIndex().

395  {
396  if (Voxel >= fNVoxels) return nullptr;
397  else return fReflTLookupTable.data_address(uncheckedIndex(Voxel, 0));
398  }
const_pointer data_address(size_type pos) const
Returns a constant pointer to the specified element.
Definition: LazyVector.h:510
size_t uncheckedIndex(size_t Voxel, size_t OpChannel) const
Returns the index of visibility of specified voxel and cell.
Definition: PhotonLibrary.h:90
util::LazyVector< float > fReflTLookupTable
Definition: PhotonLibrary.h:80
float phot::PhotonLibrary::GetTimingPar ( size_t  Voxel,
size_t  OpChannel,
size_t  parnum 
) const

Definition at line 269 of file PhotonLibrary.cxx.

References fNOpChannels, fNVoxels, and uncheckedAccessTimingPar().

Referenced by phot::PhotonVisibilityService::GetLibraryTimingParEntry().

270  {
271  if ((Voxel >= fNVoxels) || (OpChannel >= fNOpChannels))
272  return 0;
273  else
274  return uncheckedAccessTimingPar(Voxel, OpChannel, parnum);
275  } //----------------------------------------------------
float uncheckedAccessTimingPar(size_t Voxel, size_t OpChannel, size_t parnum) const
Unchecked access to a parameter the time distribution.
const std::vector< float > * phot::PhotonLibrary::GetTimingPars ( size_t  Voxel) const

Definition at line 351 of file PhotonLibrary.cxx.

References util::LazyVector< T, A >::data_address(), fNVoxels, fTimingParLookupTable, and uncheckedIndex().

Referenced by phot::PhotonVisibilityService::GetLibraryTimingParEntries().

352  {
353  if (Voxel >= fNVoxels) return nullptr;
354  else return fTimingParLookupTable.data_address(uncheckedIndex(Voxel, 0));
355  }
const_pointer data_address(size_type pos) const
Returns a constant pointer to the specified element.
Definition: LazyVector.h:510
size_t uncheckedIndex(size_t Voxel, size_t OpChannel) const
Returns the index of visibility of specified voxel and cell.
Definition: PhotonLibrary.h:90
util::LazyVector< std::vector< float > > fTimingParLookupTable
Definition: PhotonLibrary.h:81
TF1 * phot::PhotonLibrary::GetTimingTF1s ( size_t  Voxel) const

Definition at line 359 of file PhotonLibrary.cxx.

References util::LazyVector< T, A >::data_address(), fNVoxels, fTimingParTF1LookupTable, and uncheckedIndex().

Referenced by phot::PhotonVisibilityService::GetLibraryTimingTF1Entries().

360  {
361  if (Voxel >= fNVoxels) return nullptr;
362  /*
363  * Sorry, Universe, but we can't undergo ROOT's bad design hell.
364  * TF1::GetRandom() is non-const member, because it uses some internal
365  * integral information which can be produced on the spot instead than
366  * always be present. That's called caching, it's Good, but it must not
367  * interfere with constantness of the interface (in fact, this is one of
368  * the few acceptable uses of `mutable` members).
369  * Because of this, this method can't return a constant `TF1`, therefore
370  * it can't be constant, therefore the underlying access returning a
371  * constant object is not acceptable.
372  * So I do the Bad thing.
373  * Plus I opened JIRA ROOT-9549
374  * (https://sft.its.cern.ch/jira/browse/ROOT-9549).
375  * After that is solved, this method should become:
376  *
377  * TF1 const* PhotonLibrary::GetTimingTF1s(size_t Voxel) const
378  *
379  * and the users should update their code accordingly.
380  */
381  else return const_cast<TF1*>(fTimingParTF1LookupTable.data_address(uncheckedIndex(Voxel, 0)));
382  }
const_pointer data_address(size_type pos) const
Returns a constant pointer to the specified element.
Definition: LazyVector.h:510
size_t uncheckedIndex(size_t Voxel, size_t OpChannel) const
Returns the index of visibility of specified voxel and cell.
Definition: PhotonLibrary.h:90
util::LazyVector< TF1 > fTimingParTF1LookupTable
Definition: PhotonLibrary.h:82
virtual bool phot::PhotonLibrary::hasReflected ( ) const
inlineoverridevirtual

Returns whether the current library deals with reflected light count.

Implements phot::IPhotonLibrary.

Definition at line 54 of file PhotonLibrary.h.

References fHasReflected.

Referenced by StoreLibraryToFile().

54 { return fHasReflected; }
bool fHasReflected
Whether the current library deals with reflected light counts.
Definition: PhotonLibrary.h:70
virtual bool phot::PhotonLibrary::hasReflectedT0 ( ) const
inlineoverridevirtual

Returns whether the current library deals with reflected light timing.

Implements phot::IPhotonLibrary.

Definition at line 57 of file PhotonLibrary.h.

References CreateEmptyLibrary(), fHasReflectedT0, LoadLibraryFromFile(), NVoxels(), and StoreLibraryToFile().

Referenced by StoreLibraryToFile().

57 { return fHasReflectedT0; }
bool fHasReflectedT0
Whether the current library deals with reflected light timing.
Definition: PhotonLibrary.h:71
bool phot::PhotonLibrary::hasTiming ( ) const
inline

Returns whether the current library deals with time propagation distributions.

Definition at line 51 of file PhotonLibrary.h.

References fHasTiming.

Referenced by StoreLibraryToFile().

51 { return fHasTiming; }
size_t fHasTiming
Whether the current library deals with time propagation distribution.
Definition: PhotonLibrary.h:73
size_t phot::IPhotonLibrary::LibrarySize ( ) const
inlineinherited

Returns the number of elements in the library.

Definition at line 37 of file IPhotonLibrary.h.

References phot::IPhotonLibrary::NOpChannels(), and phot::IPhotonLibrary::NVoxels().

Referenced by CreateEmptyLibrary(), and LoadLibraryFromFile().

37 { return NVoxels() * NOpChannels(); }
virtual int NOpChannels() const =0
virtual int NVoxels() const =0
void phot::PhotonLibrary::LoadLibraryFromFile ( std::string  LibraryFile,
size_t  NVoxels,
bool  storeReflected = false,
bool  storeReflT0 = false,
size_t  storeTiming = 0 
)

Definition at line 135 of file PhotonLibrary.cxx.

References util::LazyVector< T, A >::clear(), ExtractNOpChannels(), f, fHasReflected, fHasReflectedT0, fHasTiming, fLookupTable, fNOpChannels, fNVoxels, fReflLookupTable, fReflTLookupTable, fTimingParFormula, fTimingParLookupTable, fTimingParNParameters, fTimingParTF1LookupTable, phot::IPhotonLibrary::LibrarySize(), n, NVoxels(), util::LazyVector< T, A >::reserve(), util::LazyVector< T, A >::resize(), uncheckedAccess(), uncheckedAccessRefl(), uncheckedAccessReflT(), and uncheckedAccessTimingTF1().

Referenced by hasReflectedT0(), and phot::PhotonVisibilityService::LoadLibrary().

136  {
142 
143  mf::LogInfo("PhotonLibrary") << "Reading photon library from input file: " << LibraryFile.c_str()<<std::endl;
144 
145  TFile *f = nullptr;
146  TTree *tt = nullptr;
147 
148  try
149  {
150  f = TFile::Open(LibraryFile.c_str());
151  tt = (TTree*)f->Get("PhotonLibraryData");
152  if (!tt) { // Library not in the top directory
153  TKey *key = f->FindKeyAny("PhotonLibraryData");
154  if (key)
155  tt = (TTree*)key->ReadObj();
156  else {
157  mf::LogError("PhotonLibrary") << "PhotonLibraryData not found in file" <<LibraryFile;
158  }
159  }
160  }
161  catch(...)
162  {
163  throw cet::exception("PhotonLibrary") << "Error in ttree load, reading photon library: " << LibraryFile << "\n";
164  }
165 
166 
167  Int_t Voxel;
168  Int_t OpChannel;
169  Float_t Visibility;
170  Float_t ReflVisibility;
171  Float_t ReflTfirst;
172  std::vector<Float_t> timing_par;
173 
174  tt->SetBranchAddress("Voxel", &Voxel);
175  tt->SetBranchAddress("OpChannel", &OpChannel);
176  tt->SetBranchAddress("Visibility", &Visibility);
177 
178  fHasTiming = getTiming;
179 
180  fHasReflected = getReflected;
181  if(getReflected)
182  tt->SetBranchAddress("ReflVisibility", &ReflVisibility);
183  fHasReflectedT0 = getReflT0;
184  if(getReflT0)
185  tt->SetBranchAddress("ReflTfirst", &ReflTfirst);
186 
187  fNVoxels = NVoxels;
188  fNOpChannels = PhotonLibrary::ExtractNOpChannels(tt); // EXPENSIVE!!!
189 
190  // with STL vectors, where `resize()` directly controls the allocation of
191  // memory, reserving the space is redundant; not so with `util::LazyVector`,
192  // where `resize()` never increases the memory
195 
196  if(fHasTiming!=0)
197  {
198  timing_par.reserve(getTiming);
199  timing_par.resize(getTiming);
200  tt->SetBranchAddress("timing_par", timing_par.data());
202  TNamed *n = (TNamed*)f->Get("fTimingParFormula");
203  if(!n) mf::LogError("PhotonLibrary") <<"Error reading the photon propagation formula. Please check the photon library." << std::endl;
204  fTimingParFormula = n->GetTitle();
206  mf::LogInfo("PhotonLibrary") <<"Time parametrization is activated. Using the formula: "<< fTimingParFormula << " with " << fTimingParNParameters << " parameters."<< std::endl;
207  }
208  if(fHasReflected) {
211  }
212  if(fHasReflectedT0) {
215  }
216 
217  size_t NEntries = tt->GetEntries();
218 
219  for(size_t i=0; i!=NEntries; ++i) {
220 
221 
222  tt->GetEntry(i);
223 
224  // Set the visibility at this optical channel
225  uncheckedAccess(Voxel, OpChannel) = Visibility;
226 
227  if(fHasReflected)
228  uncheckedAccessRefl(Voxel, OpChannel) = ReflVisibility;
229  if(fHasReflectedT0)
230  uncheckedAccessReflT(Voxel, OpChannel) = ReflTfirst;
231  if(fHasTiming!=0)
232  {
233  // TODO: use TF1::Copy
234  TF1 timingfunction(Form("timing_%i_%i",Voxel,OpChannel),fTimingParFormula.c_str(),0,200);
235 
236  for (size_t k=0;k<fTimingParNParameters;k++)
237  {
238  timingfunction.SetParameter(k,timing_par[k]);
239  }
240 
241  uncheckedAccessTimingTF1(Voxel,OpChannel) = timingfunction;
242  }
243  } // for entries
244 
245  mf::LogInfo("PhotonLibrary") <<"Photon lookup table size : "<< NVoxels << " voxels, " << fNOpChannels<<" channels";
246 
247  try
248  {
249  f->Close();
250  }
251  catch(...)
252  {
253  mf::LogError("PhotonLibrary") << "Error in closing file : " << LibraryFile;
254  }
255 
256  }
size_t fTimingParNParameters
Definition: PhotonLibrary.h:84
size_t fHasTiming
Whether the current library deals with time propagation distribution.
Definition: PhotonLibrary.h:73
util::LazyVector< float > fReflLookupTable
Definition: PhotonLibrary.h:79
bool fHasReflectedT0
Whether the current library deals with reflected light timing.
Definition: PhotonLibrary.h:71
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
void clear()
Removes all stored data and sets the nominal size to 0.
Definition: LazyVector.h:548
float uncheckedAccess(size_t Voxel, size_t OpChannel) const
Unchecked access to a visibility datum.
Definition: PhotonLibrary.h:94
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
void reserve(size_type n)
Allocates enough memory in storage to store n elements.
Definition: LazyVector.h:344
float uncheckedAccessReflT(size_t Voxel, size_t OpChannel) const
Unchecked access to a reflected T0 visibility datum.
std::string fTimingParFormula
Definition: PhotonLibrary.h:83
TFile f
Definition: plotHisto.C:6
util::LazyVector< float > fLookupTable
Definition: PhotonLibrary.h:78
static size_t ExtractNOpChannels(TTree *tree)
Returns the number of optical channels in the specified tree.
Definition: type_traits.h:56
bool fHasReflected
Whether the current library deals with reflected light counts.
Definition: PhotonLibrary.h:70
TF1 & uncheckedAccessTimingTF1(size_t Voxel, size_t OpChannel)
Unchecked access to a parameter of the time distribution.
util::LazyVector< TF1 > fTimingParTF1LookupTable
Definition: PhotonLibrary.h:82
float uncheckedAccessRefl(size_t Voxel, size_t OpChannel) const
Unchecked access to a reflected visibility datum.
size_t LibrarySize() const
Returns the number of elements in the library.
Char_t n[5]
void resize(size_type newSize)
Changes the nominal size of the container.
Definition: LazyVector.h:528
util::LazyVector< std::vector< float > > fTimingParLookupTable
Definition: PhotonLibrary.h:81
util::LazyVector< float > fReflTLookupTable
Definition: PhotonLibrary.h:80
virtual int NVoxels() const override
Definition: PhotonLibrary.h:66
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
virtual int phot::PhotonLibrary::NOpChannels ( ) const
inlineoverridevirtual

Implements phot::IPhotonLibrary.

Definition at line 65 of file PhotonLibrary.h.

References fNOpChannels.

Referenced by CreateEmptyLibrary().

65 { return fNOpChannels; }
virtual int phot::PhotonLibrary::NVoxels ( ) const
inlineoverridevirtual

Implements phot::IPhotonLibrary.

Definition at line 66 of file PhotonLibrary.h.

References fNVoxels.

Referenced by CreateEmptyLibrary(), hasReflectedT0(), and LoadLibraryFromFile().

66 { return fNVoxels; }
TTree* phot::PhotonLibrary::ProduceTTree ( ) const
void phot::PhotonLibrary::SetCount ( size_t  Voxel,
size_t  OpChannel,
float  Count 
)

Definition at line 296 of file PhotonLibrary.cxx.

References fNOpChannels, fNVoxels, and uncheckedAccess().

Referenced by phot::PhotonVisibilityService::SetLibraryEntry().

297  {
298  if ((Voxel >= fNVoxels) || (OpChannel >= fNOpChannels))
299  mf::LogError("PhotonLibrary")<<"Error - attempting to set count in voxel " << Voxel<<" which is out of range";
300  else
301  uncheckedAccess(Voxel, OpChannel) = Count;
302  }
float uncheckedAccess(size_t Voxel, size_t OpChannel) const
Unchecked access to a visibility datum.
Definition: PhotonLibrary.h:94
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
void phot::PhotonLibrary::SetReflCount ( size_t  Voxel,
size_t  OpChannel,
float  Count 
)

Definition at line 324 of file PhotonLibrary.cxx.

References fNOpChannels, fNVoxels, and uncheckedAccessRefl().

Referenced by phot::PhotonVisibilityService::SetLibraryEntry().

325  {
326  if ((Voxel >= fNVoxels) || (OpChannel >= fNOpChannels))
327  mf::LogError("PhotonLibrary")<<"Error - attempting to set count in voxel " << Voxel<<" which is out of range";
328  else
329  uncheckedAccessRefl(Voxel, OpChannel) = Count;
330  }
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
float uncheckedAccessRefl(size_t Voxel, size_t OpChannel) const
Unchecked access to a reflected visibility datum.
void phot::PhotonLibrary::SetReflT0 ( size_t  Voxel,
size_t  OpChannel,
float  reflT0 
)

Definition at line 333 of file PhotonLibrary.cxx.

References fNOpChannels, fNVoxels, and uncheckedAccessReflT().

Referenced by phot::PhotonVisibilityService::SetLibraryReflT0Entry().

334  {
335  if ((Voxel >= fNVoxels) || (OpChannel >= fNOpChannels))
336  mf::LogError("PhotonLibrary")<<"Error - attempting to set count in voxel " << Voxel<<" which is out of range";
337  else
338  uncheckedAccessReflT(Voxel, OpChannel) = Count;
339  }
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
float uncheckedAccessReflT(size_t Voxel, size_t OpChannel) const
Unchecked access to a reflected T0 visibility datum.
void phot::PhotonLibrary::SetTimingPar ( size_t  Voxel,
size_t  OpChannel,
float  Count,
size_t  parnum 
)

Definition at line 305 of file PhotonLibrary.cxx.

References fNOpChannels, fNVoxels, and uncheckedAccessTimingPar().

Referenced by phot::PhotonVisibilityService::SetLibraryTimingParEntry().

306  {
307  if ((Voxel >= fNVoxels) || (OpChannel >= fNOpChannels))
308  mf::LogError("PhotonLibrary")<<"Error - attempting to set timing t0 count in voxel " << Voxel<<" which is out of range";
309  else
310  uncheckedAccessTimingPar(Voxel, OpChannel, parnum) = Count;
311  }
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
float uncheckedAccessTimingPar(size_t Voxel, size_t OpChannel, size_t parnum) const
Unchecked access to a parameter the time distribution.
void phot::PhotonLibrary::SetTimingTF1 ( size_t  Voxel,
size_t  OpChannel,
TF1  func 
)

Definition at line 314 of file PhotonLibrary.cxx.

References fNOpChannels, fNVoxels, and uncheckedAccessTimingTF1().

Referenced by phot::PhotonVisibilityService::SetLibraryTimingTF1Entry().

315  {
316  if ((Voxel >= fNVoxels) || (OpChannel >= fNOpChannels))
317  mf::LogError("PhotonLibrary")<<"Error - attempting to set a propagation function in voxel " << Voxel<<" which is out of range";
318  else
319  uncheckedAccessTimingTF1(Voxel, OpChannel) = func;
320  }
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
TF1 & uncheckedAccessTimingTF1(size_t Voxel, size_t OpChannel)
Unchecked access to a parameter of the time distribution.
static int phot::PhotonLibrary::size_t2int ( size_t  val)
inlinestaticprivate

Converts size_t into integer.

Definition at line 145 of file PhotonLibrary.h.

Referenced by StoreLibraryToFile().

145  {
146  return (val <= INT_MAX) ? (int)((ssize_t)val) : -1; }
void phot::PhotonLibrary::StoreLibraryToFile ( std::string  LibraryFile,
bool  storeReflected = false,
bool  storeReflT0 = false,
size_t  storeTiming = 0 
) const

Definition at line 23 of file PhotonLibrary.cxx.

References fLookupTable, fNOpChannels, fNVoxels, fReflLookupTable, fTimingParLookupTable, hasReflected(), hasReflectedT0(), hasTiming(), art::TFileDirectory::make(), OpChannelBranchName, util::LazyVector< T, A >::size(), size_t2int(), uncheckedAccess(), uncheckedAccessRefl(), uncheckedAccessReflT(), and uncheckedAccessTimingPar().

Referenced by hasReflectedT0(), and phot::PhotonVisibilityService::StoreLibrary().

24  {
25  mf::LogInfo("PhotonLibrary") << "Writing photon library to input file: " << LibraryFile.c_str()<<std::endl;
26 
28 
29  TTree *tt = tfs->make<TTree>("PhotonLibraryData","PhotonLibraryData");
30 
31 
32  Int_t Voxel = 0;
33  Int_t OpChannel = 0;
34  Float_t Visibility = 0;
35  Float_t ReflVisibility = 0;
36  Float_t ReflTfirst = 0;
37  Float_t *timing_par = nullptr;
38 
39  tt->Branch("Voxel", &Voxel, "Voxel/I");
40  tt->Branch(OpChannelBranchName.c_str(), &OpChannel, (OpChannelBranchName + "/I").c_str());
41  tt->Branch("Visibility", &Visibility, "Visibility/F");
42 
43  if(storeTiming!=0)
44  {
45  if (!hasTiming()) {
46  // if this happens, you need to call CreateEmptyLibrary() with storeReflected set true
47  throw cet::exception("PhotonLibrary")
48  << "StoreLibraryToFile() requested to store the time propagation distribution parameters, which was not simulated.";
49  }
50  tt->Branch("timing_par", timing_par, Form("timing_par[%i]/F",size_t2int(storeTiming)));
52  throw cet::exception(" Photon Library ") << "Time propagation lookup table is different size than Direct table \n"
53  << "this should not be happening. ";
54  }
55 
56  if(storeReflected)
57  {
58  if (!hasReflected()) {
59  // if this happens, you need to call CreateEmptyLibrary() with storeReflected set true
60  throw cet::exception("PhotonLibrary")
61  << "StoreLibraryToFile() requested to store reflected light, which was not simulated.";
62  }
63  tt->Branch("ReflVisibility", &ReflVisibility, "ReflVisibility/F");
65  throw cet::exception(" Photon Library ") << "Reflected light lookup table is different size than Direct table \n"
66  << "this should not be happening. ";
67  }
68  if(storeReflT0) {
69  if (!hasReflectedT0()) {
70  // if this happens, you need to call CreateEmptyLibrary() with storeReflectedT0 set true
71  throw cet::exception("PhotonLibrary")
72  << "StoreLibraryToFile() requested to store reflected light timing, which was not simulated.";
73  }
74  tt->Branch("ReflTfirst", &ReflTfirst, "ReflTfirst/F");
75  }
76  for(size_t ivox=0; ivox!= fNVoxels; ++ivox)
77  {
78  for(size_t ichan=0; ichan!= fNOpChannels; ++ichan)
79  {
80  Visibility = uncheckedAccess(ivox, ichan);
81  if(storeReflected)
82  ReflVisibility = uncheckedAccessRefl(ivox, ichan);
83  if(storeReflT0)
84  ReflTfirst = uncheckedAccessReflT(ivox, ichan);
85  if(storeTiming!=0)
86  {
87  for (size_t i =0; i<storeTiming; i++) timing_par[i] = uncheckedAccessTimingPar(ivox, ichan, i);
88 
89  }
90  if (Visibility > 0 || ReflVisibility > 0)
91  {
92  Voxel = ivox;
93  OpChannel = ichan;
94  // visibility(ies) is(are) already set
95  tt->Fill();
96  }
97  }
98  }
99  }
static int size_t2int(size_t val)
Converts size_t into integer.
util::LazyVector< float > fReflLookupTable
Definition: PhotonLibrary.h:79
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
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
float uncheckedAccessReflT(size_t Voxel, size_t OpChannel) const
Unchecked access to a reflected T0 visibility datum.
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
Definition: type_traits.h:56
size_type size() const noexcept
Returns the size of the vector.
Definition: LazyVector.h:156
T * make(ARGS...args) const
float uncheckedAccessRefl(size_t Voxel, size_t OpChannel) const
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
util::LazyVector< std::vector< float > > fTimingParLookupTable
Definition: PhotonLibrary.h:81
bool hasTiming() const
Returns whether the current library deals with time propagation distributions.
Definition: PhotonLibrary.h:51
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
float uncheckedAccessTimingPar(size_t Voxel, size_t OpChannel, size_t parnum) const
Unchecked access to a parameter the time distribution.
float phot::PhotonLibrary::uncheckedAccess ( size_t  Voxel,
size_t  OpChannel 
) const
inlineprivate

Unchecked access to a visibility datum.

Definition at line 94 of file PhotonLibrary.h.

References uncheckedIndex().

Referenced by GetCount(), LoadLibraryFromFile(), SetCount(), and StoreLibraryToFile().

95  { return fLookupTable[uncheckedIndex(Voxel, OpChannel)]; }
size_t uncheckedIndex(size_t Voxel, size_t OpChannel) const
Returns the index of visibility of specified voxel and cell.
Definition: PhotonLibrary.h:90
util::LazyVector< float > fLookupTable
Definition: PhotonLibrary.h:78
float& phot::PhotonLibrary::uncheckedAccess ( size_t  Voxel,
size_t  OpChannel 
)
inlineprivate

Unchecked access to a visibility datum.

Definition at line 98 of file PhotonLibrary.h.

References uncheckedIndex().

99  { return fLookupTable[uncheckedIndex(Voxel, OpChannel)]; }
size_t uncheckedIndex(size_t Voxel, size_t OpChannel) const
Returns the index of visibility of specified voxel and cell.
Definition: PhotonLibrary.h:90
util::LazyVector< float > fLookupTable
Definition: PhotonLibrary.h:78
float phot::PhotonLibrary::uncheckedAccessRefl ( size_t  Voxel,
size_t  OpChannel 
) const
inlineprivate

Unchecked access to a reflected visibility datum.

Definition at line 102 of file PhotonLibrary.h.

References uncheckedIndex().

Referenced by GetReflCount(), LoadLibraryFromFile(), SetReflCount(), and StoreLibraryToFile().

103  { return fReflLookupTable[uncheckedIndex(Voxel, OpChannel)]; }
util::LazyVector< float > fReflLookupTable
Definition: PhotonLibrary.h:79
size_t uncheckedIndex(size_t Voxel, size_t OpChannel) const
Returns the index of visibility of specified voxel and cell.
Definition: PhotonLibrary.h:90
float& phot::PhotonLibrary::uncheckedAccessRefl ( size_t  Voxel,
size_t  OpChannel 
)
inlineprivate

Unchecked access to a reflected visibility datum.

Definition at line 106 of file PhotonLibrary.h.

References uncheckedIndex().

107  { return fReflLookupTable[uncheckedIndex(Voxel, OpChannel)]; }
util::LazyVector< float > fReflLookupTable
Definition: PhotonLibrary.h:79
size_t uncheckedIndex(size_t Voxel, size_t OpChannel) const
Returns the index of visibility of specified voxel and cell.
Definition: PhotonLibrary.h:90
float phot::PhotonLibrary::uncheckedAccessReflT ( size_t  Voxel,
size_t  OpChannel 
) const
inlineprivate

Unchecked access to a reflected T0 visibility datum.

Definition at line 110 of file PhotonLibrary.h.

References uncheckedIndex().

Referenced by GetReflT0(), LoadLibraryFromFile(), SetReflT0(), and StoreLibraryToFile().

111  { return fReflTLookupTable[uncheckedIndex(Voxel, OpChannel)]; }
size_t uncheckedIndex(size_t Voxel, size_t OpChannel) const
Returns the index of visibility of specified voxel and cell.
Definition: PhotonLibrary.h:90
util::LazyVector< float > fReflTLookupTable
Definition: PhotonLibrary.h:80
float& phot::PhotonLibrary::uncheckedAccessReflT ( size_t  Voxel,
size_t  OpChannel 
)
inlineprivate

Unchecked access to a reflected T0 visibility datum.

Definition at line 114 of file PhotonLibrary.h.

References uncheckedIndex().

115  { return fReflTLookupTable[uncheckedIndex(Voxel, OpChannel)]; }
size_t uncheckedIndex(size_t Voxel, size_t OpChannel) const
Returns the index of visibility of specified voxel and cell.
Definition: PhotonLibrary.h:90
util::LazyVector< float > fReflTLookupTable
Definition: PhotonLibrary.h:80
float phot::PhotonLibrary::uncheckedAccessTimingPar ( size_t  Voxel,
size_t  OpChannel,
size_t  parnum 
) const
inlineprivate

Unchecked access to a parameter the time distribution.

Definition at line 119 of file PhotonLibrary.h.

References uncheckedIndex().

Referenced by GetTimingPar(), SetTimingPar(), and StoreLibraryToFile().

120  { return fTimingParLookupTable[uncheckedIndex(Voxel, OpChannel)][parnum];}
size_t uncheckedIndex(size_t Voxel, size_t OpChannel) const
Returns the index of visibility of specified voxel and cell.
Definition: PhotonLibrary.h:90
util::LazyVector< std::vector< float > > fTimingParLookupTable
Definition: PhotonLibrary.h:81
float& phot::PhotonLibrary::uncheckedAccessTimingPar ( size_t  Voxel,
size_t  OpChannel,
size_t  parnum 
)
inlineprivate

Unchecked access to a parameter of the time distribution.

Definition at line 123 of file PhotonLibrary.h.

References uncheckedIndex().

124  { return fTimingParLookupTable[uncheckedIndex(Voxel, OpChannel)][parnum]; }
size_t uncheckedIndex(size_t Voxel, size_t OpChannel) const
Returns the index of visibility of specified voxel and cell.
Definition: PhotonLibrary.h:90
util::LazyVector< std::vector< float > > fTimingParLookupTable
Definition: PhotonLibrary.h:81
TF1& phot::PhotonLibrary::uncheckedAccessTimingTF1 ( size_t  Voxel,
size_t  OpChannel 
)
inlineprivate

Unchecked access to a parameter of the time distribution.

Definition at line 128 of file PhotonLibrary.h.

References uncheckedIndex().

Referenced by LoadLibraryFromFile(), and SetTimingTF1().

129  { return fTimingParTF1LookupTable[uncheckedIndex(Voxel, OpChannel)]; }
size_t uncheckedIndex(size_t Voxel, size_t OpChannel) const
Returns the index of visibility of specified voxel and cell.
Definition: PhotonLibrary.h:90
util::LazyVector< TF1 > fTimingParTF1LookupTable
Definition: PhotonLibrary.h:82
const TF1& phot::PhotonLibrary::uncheckedAccessTimingTF1 ( size_t  Voxel,
size_t  OpChannel 
) const
inlineprivate

Unchecked access to a parameter of the time distribution.

Definition at line 132 of file PhotonLibrary.h.

References util::LazyVector< T, A >::data_address(), and uncheckedIndex().

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  }
const_pointer data_address(size_type pos) const
Returns a constant pointer to the specified element.
Definition: LazyVector.h:510
size_t uncheckedIndex(size_t Voxel, size_t OpChannel) const
Returns the index of visibility of specified voxel and cell.
Definition: PhotonLibrary.h:90
util::LazyVector< TF1 > fTimingParTF1LookupTable
Definition: PhotonLibrary.h:82
size_t phot::PhotonLibrary::uncheckedIndex ( size_t  Voxel,
size_t  OpChannel 
) const
inlineprivate

Returns the index of visibility of specified voxel and cell.

Definition at line 90 of file PhotonLibrary.h.

Referenced by GetCounts(), GetReflCounts(), GetReflT0s(), GetTimingPars(), GetTimingTF1s(), uncheckedAccess(), uncheckedAccessRefl(), uncheckedAccessReflT(), uncheckedAccessTimingPar(), and uncheckedAccessTimingTF1().

91  { return Voxel * fNOpChannels + OpChannel; }

Member Data Documentation

bool phot::PhotonLibrary::fHasReflected = false
private

Whether the current library deals with reflected light counts.

Definition at line 70 of file PhotonLibrary.h.

Referenced by CreateEmptyLibrary(), hasReflected(), and LoadLibraryFromFile().

bool phot::PhotonLibrary::fHasReflectedT0 = false
private

Whether the current library deals with reflected light timing.

Definition at line 71 of file PhotonLibrary.h.

Referenced by CreateEmptyLibrary(), hasReflectedT0(), and LoadLibraryFromFile().

size_t phot::PhotonLibrary::fHasTiming = 0
private

Whether the current library deals with time propagation distribution.

Definition at line 73 of file PhotonLibrary.h.

Referenced by CreateEmptyLibrary(), hasTiming(), and LoadLibraryFromFile().

util::LazyVector<float> phot::PhotonLibrary::fLookupTable
private
util::LazyVector<float> phot::PhotonLibrary::fReflLookupTable
private
util::LazyVector<float> phot::PhotonLibrary::fReflTLookupTable
private

Definition at line 80 of file PhotonLibrary.h.

Referenced by CreateEmptyLibrary(), GetReflT0s(), and LoadLibraryFromFile().

std::string phot::PhotonLibrary::fTimingParFormula
private

Definition at line 83 of file PhotonLibrary.h.

Referenced by LoadLibraryFromFile().

util::LazyVector<std::vector<float> > phot::PhotonLibrary::fTimingParLookupTable
private
size_t phot::PhotonLibrary::fTimingParNParameters
private

Definition at line 84 of file PhotonLibrary.h.

Referenced by LoadLibraryFromFile().

util::LazyVector<TF1> phot::PhotonLibrary::fTimingParTF1LookupTable
private

Definition at line 82 of file PhotonLibrary.h.

Referenced by CreateEmptyLibrary(), GetTimingTF1s(), and LoadLibraryFromFile().

std::string const phot::PhotonLibrary::OpChannelBranchName = "OpChannel"
staticprivate

Name of the optical channel number in the input tree.

Definition at line 139 of file PhotonLibrary.h.

Referenced by ExtractNOpChannels(), and StoreLibraryToFile().


The documentation for this class was generated from the following files: