25 mf::LogInfo(
"PhotonLibrary") <<
"Writing photon library to input file: " << LibraryFile.c_str()<<std::endl;
29 TTree *
tt = tfs->
make<TTree>(
"PhotonLibraryData",
"PhotonLibraryData");
34 Float_t Visibility = 0;
35 Float_t ReflVisibility = 0;
36 Float_t ReflTfirst = 0;
37 Float_t *timing_par =
nullptr;
39 tt->Branch(
"Voxel", &Voxel,
"Voxel/I");
41 tt->Branch(
"Visibility", &Visibility,
"Visibility/F");
48 <<
"StoreLibraryToFile() requested to store the time propagation distribution parameters, which was not simulated.";
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. ";
61 <<
"StoreLibraryToFile() requested to store reflected light, which was not simulated.";
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. ";
72 <<
"StoreLibraryToFile() requested to store reflected light timing, which was not simulated.";
74 tt->Branch(
"ReflTfirst", &ReflTfirst,
"ReflTfirst/F");
76 for(
size_t ivox=0; ivox!=
fNVoxels; ++ivox)
90 if (Visibility > 0 || ReflVisibility > 0)
106 bool storeReflected ,
143 mf::LogInfo(
"PhotonLibrary") <<
"Reading photon library from input file: " << LibraryFile.c_str()<<std::endl;
150 f = TFile::Open(LibraryFile.c_str());
151 tt = (TTree*)f->Get(
"PhotonLibraryData");
153 TKey *key = f->FindKeyAny(
"PhotonLibraryData");
155 tt = (TTree*)key->ReadObj();
157 mf::LogError(
"PhotonLibrary") <<
"PhotonLibraryData not found in file" <<LibraryFile;
163 throw cet::exception(
"PhotonLibrary") <<
"Error in ttree load, reading photon library: " << LibraryFile <<
"\n";
170 Float_t ReflVisibility;
172 std::vector<Float_t> timing_par;
174 tt->SetBranchAddress(
"Voxel", &Voxel);
175 tt->SetBranchAddress(
"OpChannel", &OpChannel);
176 tt->SetBranchAddress(
"Visibility", &Visibility);
182 tt->SetBranchAddress(
"ReflVisibility", &ReflVisibility);
185 tt->SetBranchAddress(
"ReflTfirst", &ReflTfirst);
200 timing_par.resize(getTiming);
201 tt->SetBranchAddress(
"timing_par", timing_par.data());
203 TNamed *
n = (TNamed*)f->Get(
"fTimingParFormula");
204 if(!n)
mf::LogError(
"PhotonLibrary") <<
"Error reading the photon propagation formula. Please check the photon library." << std::endl;
219 size_t NEntries = tt->GetEntries();
221 for(
size_t i=0; i!=NEntries; ++i) {
236 TF1 timingfunction(Form(
"timing_%i_%i",Voxel,OpChannel),
fTimingParFormula.c_str(),timing_par[0],fTimingMaxRange);
237 timingfunction.SetParameter(0,0.0);
240 timingfunction.SetParameter(k,timing_par[k]);
247 mf::LogInfo(
"PhotonLibrary") <<
"Photon lookup table size : "<< NVoxels <<
" voxels, " <<
fNOpChannels<<
" channels";
255 mf::LogError(
"PhotonLibrary") <<
"Error in closing file : " << LibraryFile;
301 mf::LogError(
"PhotonLibrary")<<
"Error - attempting to set count in voxel " << Voxel<<
" which is out of range";
310 mf::LogError(
"PhotonLibrary")<<
"Error - attempting to set timing t0 count in voxel " << Voxel<<
" which is out of range";
319 mf::LogError(
"PhotonLibrary")<<
"Error - attempting to set a propagation function in voxel " << Voxel<<
" which is out of range";
329 mf::LogError(
"PhotonLibrary")<<
"Error - attempting to set count in voxel " << Voxel<<
" which is out of range";
338 mf::LogError(
"PhotonLibrary")<<
"Error - attempting to set count in voxel " << Voxel<<
" which is out of range";
347 if (Voxel >=
fNVoxels)
return nullptr;
355 if (Voxel >=
fNVoxels)
return nullptr;
363 if (Voxel >=
fNVoxels)
return nullptr;
390 if (Voxel >=
fNVoxels)
return nullptr;
398 if (Voxel >=
fNVoxels)
return nullptr;
406 if (!channelBranch) {
408 <<
"Tree '" << tree->GetName() <<
"' has no branch 'OpChannel'";
412 char* oldAddress = channelBranch->GetAddress();
414 channelBranch->SetAddress(&channel);
415 Int_t maxChannel = -1;
419 while (channelBranch->GetEntry(iEntry++)) {
420 if (channel > maxChannel) maxChannel = channel;
424 <<
"Detected highest channel to be " << maxChannel <<
" from " << iEntry
428 channelBranch->SetAddress(oldAddress);
430 return size_t(maxChannel + 1);
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.
size_t fTimingParNParameters
static int size_t2int(size_t val)
Converts size_t into integer.
size_t fHasTiming
Whether the current library deals with time propagation distribution.
void LoadLibraryFromFile(std::string LibraryFile, size_t NVoxels, bool storeReflected=false, bool storeReflT0=false, size_t storeTiming=0, int maxrange=200)
util::LazyVector< float > fReflLookupTable
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.
void CreateEmptyLibrary(size_t NVoxels, size_t NChannels, bool storeReflected=false, bool storeReflT0=false, size_t storeTiming=0)
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
virtual float const * GetReflT0s(size_t Voxel) const override
virtual int NOpChannels() const override
virtual float GetReflCount(size_t Voxel, size_t OpChannel) const override
void data_init(size_type startIndex, size_type endIndex)
Allocates the specified range and stores default values for it.
void clear()
Removes all stored data and sets the nominal size to 0.
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.
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
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
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.
static size_t ExtractNOpChannels(TTree *tree)
Returns the number of optical channels in the specified tree.
size_type size() const noexcept
Returns the size of the vector.
void SetReflT0(size_t Voxel, size_t OpChannel, float reflT0)
bool fHasReflected
Whether the current library deals with reflected light counts.
TF1 & uncheckedAccessTimingTF1(size_t Voxel, size_t OpChannel)
Unchecked access to a parameter of the time distribution.
TF1 * GetTimingTF1s(size_t Voxel) const
const std::vector< float > * GetTimingPars(size_t Voxel) const
util::LazyVector< TF1 > fTimingParTF1LookupTable
virtual float GetCount(size_t Voxel, size_t OpChannel) const override
void SetTimingPar(size_t Voxel, size_t OpChannel, float Count, size_t parnum)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
General LArSoft Utilities.
T * make(ARGS...args) const
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.
virtual bool hasReflected() const override
Returns whether the current library deals with reflected light count.
float GetTimingPar(size_t Voxel, size_t OpChannel, size_t parnum) const
void resize(size_type newSize)
Changes the nominal size of the container.
util::LazyVector< std::vector< float > > fTimingParLookupTable
util::LazyVector< float > fReflTLookupTable
virtual float const * GetReflCounts(size_t Voxel) const override
virtual int NVoxels() const override
void SetReflCount(size_t Voxel, size_t OpChannel, float Count)
bool hasTiming() const
Returns whether the current library deals with time propagation distributions.
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception
float uncheckedAccessTimingPar(size_t Voxel, size_t OpChannel, size_t parnum) const
Unchecked access to a parameter the time distribution.