35 #include "art_root_io/TFileService.h"
36 #include "art/Framework/Services/Registry/ServiceHandle.h"
37 #include "art/Utilities/make_tool.h"
38 #include "canvas/Utilities/Exception.h"
39 #include "messagefacility/MessageLogger/MessageLogger.h"
40 #include "fhiclcpp/ParameterSet.h"
41 #include "cetlib/search_path.h"
83 , fUseCryoBoundary(
false)
84 , fLibraryBuildJob(
false)
85 , fDoNotLoadLibrary(
false)
86 , fParameterization(
false)
88 , fStoreReflected(
false)
90 , fIncludePropTime(
false)
91 , fUseNhitsModel(
false)
93 , fParPropTime_npar(0)
94 , fParPropTime_formula()
95 , fParPropTime_MaxRange()
97 , fReflectOverZeroX(
false)
98 , fparslogNorm(nullptr)
99 , fparslogNorm_far(nullptr)
101 , fparsMPV_far(nullptr)
102 , fparsWidth(nullptr)
104 , fparsCte_far(nullptr)
105 , fparsSlope(nullptr)
108 , fTF1_sampling_factor(0.0)
109 , fparslogNorm_refl(nullptr)
110 , fparsMPV_refl(nullptr)
111 , fparsWidth_refl(nullptr)
112 , fparsCte_refl(nullptr)
113 , fparsSlope_refl(nullptr)
115 , fT0_break_point(0.0)
117 , fTheLibrary(nullptr)
122 if (pset.has_key(
"ReflectOverZeroX")) {
123 if (pset.has_key(
"Mapping")) {
124 throw art::Exception(art::errors::Configuration)
125 <<
"`PhotonVisbilityService` configuration specifies both `Mapping` and "
126 "`ReflectOverZeroX`."
127 " Please remove the latter (and use `PhotonMappingXMirrorTransformations` tool).";
130 mf::LogWarning(
"PhotonVisbilityService")
131 <<
"Please update the configuration of `PhotonVisbilityService` service"
132 " replacing `ReflectOverZeroX` with tool configuration:"
133 "\n Mapping: { tool_type: \"PhotonMappingXMirrorTransformations\" }";
136 fhicl::ParameterSet mapDefaultSet;
137 mapDefaultSet.put(
"tool_type",
139 "PhotonMappingIdentityTransformations");
140 fMapping = art::make_tool<phot::IPhotonMappingTransformations>(
141 pset.get<fhicl::ParameterSet>(
"Mapping", mapDefaultSet));
143 mf::LogInfo(
"PhotonVisibilityService") <<
"PhotonVisbilityService initializing" << std::endl;
155 std::string LibraryFileWithPath;
156 cet::search_path sp(
"FW_SEARCH_PATH");
159 throw cet::exception(
"PhotonVisibilityService")
160 <<
"Unable to find photon library in " << sp.to_string() <<
"\n";
163 art::ServiceHandle<geo::Geometry const> geom;
165 mf::LogInfo(
"PhotonVisibilityService")
166 <<
"PhotonVisibilityService Loading photon library from file " << LibraryFileWithPath
168 <<
" optical detectors." << std::endl;
196 mf::LogWarning(
"PhotonVisbilityService")
197 <<
"Photon library reports the geometry:\n"
198 << lib->
GetVoxelDef() <<
"while PhotonVisbilityService is configured with:\n"
205 art::ServiceHandle<geo::Geometry const> geom;
207 size_t NOpDets = geom->NOpDets();
210 mf::LogInfo(
"PhotonVisibilityService")
211 <<
" Vis service running library build job. Please ensure "
212 <<
" job contains LightSource, LArG4, SimPhotonCounter";
215 art::TFileDirectory* pDir =
nullptr;
217 pDir = art::ServiceHandle<art::TFileService>().
get();
219 catch (art::Exception
const&
e) {
220 if (e.categoryCode() != art::errors::ServiceNotFound)
throw;
222 throw art::Exception(e.categoryCode(),
"",
e)
223 <<
"PhotonVisibilityService: "
224 "service `TFileService` is required when building a photon library.\n";
246 std::cout <<
"This is would be building a Hybrid Library. Not defined. " << std::endl;
248 mf::LogInfo(
"PhotonVisibilityService") <<
" Vis service "
249 <<
" Storing Library entries to file..." << std::endl;
260 art::ServiceHandle<geo::Geometry const> geom;
265 fHybrid = p.get<
bool>(
"HybridLibrary",
false);
281 fParPropTime = p.get<
bool>(
"ParametrisedTimePropagation",
false);
286 if (!fParPropTime) { fParPropTime_npar = 0; }
288 if (!fUseNhitsModel) {
290 if (fUseCryoBoundary) {
291 double CryoBounds[6];
292 geom->CryostatBoundaries(CryoBounds);
293 fXmin = CryoBounds[0];
294 fXmax = CryoBounds[1];
295 fYmin = CryoBounds[2];
296 fYmax = CryoBounds[3];
297 fZmin = CryoBounds[4];
298 fZmax = CryoBounds[5];
301 fXmin = p.get<
double>(
"XMin");
302 fXmax = p.get<
double>(
"XMax");
303 fYmin = p.get<
double>(
"YMin");
304 fYmax = p.get<
double>(
"YMax");
305 fZmin = p.get<
double>(
"ZMin");
306 fZmax = p.get<
double>(
"ZMax");
309 fNx = p.get<
int>(
"NX");
310 fNy = p.get<
int>(
"NY");
311 fNz = p.get<
int>(
"NZ");
316 if (fIncludePropTime) {
319 std::cout <<
"Loading the VUV time parametrization" << std::endl;
322 fMpv = p.get<std::vector<std::vector<double>>>(
"Mpv");
323 fWidth = p.get<std::vector<std::vector<double>>>(
"Width");
325 fSlope = p.get<std::vector<std::vector<double>>>(
"Slope");
328 fmax_d = p.get<
double>(
"max_d");
329 fmin_d = p.get<
double>(
"min_d");
335 if (fStoreReflected) {
338 std::cout <<
"Loading the VIS time paramterisation" << std::endl;
341 fCut_off = p.get<std::vector<std::vector<std::vector<double>>>>(
"Cut_off");
342 fTau = p.get<std::vector<std::vector<std::vector<double>>>>(
"Tau");
348 if (fUseNhitsModel) {
349 std::cout <<
"Loading semi-analytic mode models" << std::endl;
355 fGHvuvpars_flat = p.get<std::vector<std::vector<double>>>(
"GH_PARS_flat");
360 fGHvuvpars_dome = p.get<std::vector<std::vector<double>>>(
"GH_PARS_dome");
365 if (fStoreReflected) {
370 fvispars_flat = p.get<std::vector<std::vector<std::vector<double>>>>(
"VIS_correction_flat");
375 fvispars_dome = p.get<std::vector<std::vector<std::vector<double>>>>(
"VIS_correction_dome");
379 fradius = p.get<
double>(
"PMT_radius", 10.16);
411 static std::vector<float> ret;
412 ret.resize(fMapping->libraryMappingSize(
p));
413 for (std::size_t libIndex = 0; libIndex < ret.size(); ++libIndex) {
414 ret[libIndex] = doGetVisibilityOfOpLib(
p,
LibraryIndex_t(libIndex), wantReflected);
419 auto const VoxID = VoxelAt(
p);
420 data = GetLibraryEntries(VoxID, wantReflected);
422 return fMapping->applyOpDetMapping(
p, data);
431 art::ServiceHandle<geo::Geometry const> geom;
432 return geom->OpDetGeoFromOpDet(OpDet).DistanceToPoint(p);
441 art::ServiceHandle<geo::Geometry const> geom;
442 return geom->OpDetGeoFromOpDet(OpDet).CosThetaFromNormal(p);
450 bool wantReflected )
const
456 if (!neis)
return 0.0;
461 if (
n.id < 0)
continue;
471 bool wantReflected )
const
480 unsigned int OpChannel,
481 bool wantReflected)
const
495 mf::LogInfo(
"PhotonVisibilityService")
496 <<
" PVS notes production of " << N <<
" photons at Vox " << VoxID << std::endl;
524 MF_LOG_DEBUG(
"PhotonVisibilityService")
525 <<
" PVS logging " << VoxID <<
" " << OpChannel << std::endl;
556 bool wantReflected)
const
575 int const VoxID = VoxelAt(
p);
577 return fMapping->applyOpDetMapping(
p, data);
600 MF_LOG_DEBUG(
"PhotonVisibilityService")
601 <<
" PVS logging " << VoxID <<
" " << OpChannel << std::endl;
621 int const VoxID = VoxelAt(
p);
623 return fMapping->applyOpDetMapping(
p, params);
629 int const VoxID = VoxelAt(
p);
631 return fMapping->applyOpDetMapping(
p, functions);
669 MF_LOG_DEBUG(
"PhotonVisibilityService")
670 <<
" PVS logging " << VoxID <<
" " << OpChannel << std::endl;
683 MF_LOG_DEBUG(
"PhotonVisibilityService")
684 <<
" PVS logging " << VoxID <<
" " << OpChannel << std::endl;
707 return fMapping->opDetMappingSize();
715 double& tf1_sampling_factor)
const
735 double& t0_break_point)
const
753 double& vuv_vgroup_mean,
754 double& vuv_vgroup_max,
755 double& inflexion_point_distance,
756 double& angle_bin_timing_vuv)
const
777 std::vector<double>& radial_distances,
781 double& angle_bin_timing_vis)
const
794 double &delta_angulo_vuv,
795 double &radius)
const
803 std::vector<double> &border_corr_angulo_flat,
804 std::vector<std::vector<double>> &border_corr_flat)
const
812 std::vector<double> &border_corr_angulo_dome,
813 std::vector<std::vector<double>> &border_corr_dome)
const
821 double &radius)
const
827 std::vector<double> &vis_distances_r_flat,
836 std::vector<double> &vis_distances_r_dome,
853 return fMapping->detectorToLibrary(p);
std::vector< std::vector< std::vector< double > > > fTau
MappedParams_t doGetTimingPar(geo::Point_t const &p) const
void LoadTimingsForVISPar(std::vector< double > &distances, std::vector< double > &radial_distances, std::vector< std::vector< std::vector< double >>> &cut_off, std::vector< std::vector< std::vector< double >>> &tau, double &vis_vmean, double &angle_bin_timing_vis) const
phot::IPhotonLibrary::Counts_t GetLibraryReflT0Entries(int VoxID) const
MappedCounts_t doGetAllVisibilities(geo::Point_t const &p, bool wantReflected=false) const
phot::IPhotonLibrary::Counts_t GetLibraryEntries(int VoxID, bool wantReflected=false) const
~PhotonVisibilityService()
std::unique_ptr< phot::IPhotonMappingTransformations > fMapping
Mapping of detector space into library space.
void RetrieveLightProd(int &VoxID, double &N) const
void SetDirectLightPropFunctions(TF1 const *functions[8], double &d_break, double &d_max, double &tf1_sampling_factor) const
void LoadLibraryFromFile(std::string LibraryFile, size_t NVoxels, bool storeReflected=false, bool storeReflT0=false, size_t storeTiming=0, int maxrange=200)
virtual float GetReflT0(size_t Voxel, size_t OpChannel) const =0
std::vector< std::vector< double > > fborder_corr_flat
std::vector< double > fvis_distances_r_flat
void LoadTimingsForVUVPar(std::vector< std::vector< double >>(&v)[7], double &step_size, double &max_d, double &min_d, double &vuv_vgroup_mean, double &vuv_vgroup_max, double &inflexion_point_distance, double &angle_bin_timing_vuv) const
std::vector< double > fvis_distances_x_dome
void CreateEmptyLibrary(size_t NVoxels, size_t NChannels, bool storeReflected=false, bool storeReflT0=false, size_t storeTiming=0)
void SetLibraryTimingParEntry(int VoxID, int OpChannel, float value, size_t parnum)
sim::PhotonVoxelDef const & GetVoxelDef() const
bool hasVoxelDef() const
Returns whether voxel metadata is available.
virtual float GetReflCount(size_t Voxel, size_t OpChannel) const =0
std::vector< std::vector< double > > fWidth
std::vector< double > fvis_distances_r_dome
sim::PhotonVoxelDef fVoxelDef
phot::IPhotonMappingTransformations::LibraryIndex_t LibraryIndex_t
Type of optical library index.
double fangle_bin_timing_vis
Representation of a region of space diced into voxels.
double fTF1_sampling_factor
std::vector< double > fDistances_exp
float GetLibraryTimingParEntry(int VoxID, OpDetID_t libOpChannel, size_t npar) const
std::vector< double > fDistances_refl
bool HasLibraryEntries(int VoxID, bool wantReflected=false) const
void LoadVisParsFlat(std::vector< double > &vis_distances_x_flat, std::vector< double > &vis_distances_r_flat, std::vector< std::vector< std::vector< double >>> &vispars_flat) const
float doGetVisibilityOfOpLib(geo::Point_t const &p, LibraryIndex_t libIndex, bool wantReflected=false) const
virtual float GetCount(size_t Voxel, size_t OpChannel) const =0
bool doHasVisibility(geo::Point_t const &p, bool wantReflected=false) const
std::string fVISBorderCorrectionType
std::vector< double > fvis_distances_x_flat
void StoreLibraryToFile(std::string LibraryFile, bool storeReflected=false, bool storeReflT0=false, size_t storeTiming=0) const
std::vector< std::vector< std::vector< double > > > fCut_off
float GetLibraryEntry(int VoxID, OpDetID_t libOpChannel, bool wantReflected=false) const
void LoadGHDome(std::vector< std::vector< double >> &GHvuvpars_dome, std::vector< double > &border_corr_angulo_dome, std::vector< std::vector< double >> &border_corr_dome) const
int VoxelAt(geo::Point_t const &p) const
void SetCount(size_t Voxel, size_t OpChannel, float Count)
std::vector< double > fDistances_landau
int fParPropTime_MaxRange
void SetTimingTF1(size_t Voxel, size_t OpChannel, TF1 func)
void LoadVUVSemiAnalyticProperties(bool &isFlatPDCorr, bool &isDomePDCorr, double &delta_angulo_vuv, double &radius) const
double GetQuenchingFactor(double dQdx) const
unsigned int GetNVoxels() const
Returns the total number of voxels in the volume.
float GetLibraryReflT0Entry(int VoxID, OpDetID_t libOpChannel) const
void SetReflectedCOLightPropFunctions(TF1 const *functions[5], double &t0_max, double &t0_break_point) const
std::string fParPropTime_formula
void StoreLightProd(int VoxID, double N)
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
void SetVoxelDef(sim::PhotonVoxelDef const &voxelDef)
PhotonVisibilityService(fhicl::ParameterSet const &pset)
Definitions of voxel data structures.
void LoadGHFlat(std::vector< std::vector< double >> &GHvuvpars_flat, std::vector< double > &border_corr_angulo_flat, std::vector< std::vector< double >> &border_corr_flat) const
MappedFunctions_t doGetTimingTF1(geo::Point_t const &p) const
geo::Point_t LibLocation(geo::Point_t const &p) const
void SetReflT0(size_t Voxel, size_t OpChannel, float reflT0)
void LoadVisParsDome(std::vector< double > &vis_distances_x_dome, std::vector< double > &vis_distances_r_dome, std::vector< std::vector< std::vector< double >>> &vispars_dome) const
std::vector< double > fDistances_radial_refl
void SetLibraryReflT0Entry(int VoxID, int OpChannel, float value)
virtual T0s_t GetReflT0s(size_t Voxel) const =0
void reconfigure(fhicl::ParameterSet const &p)
TF1 * GetTimingTF1s(size_t Voxel) const
const std::vector< float > * GetTimingPars(size_t Voxel) const
std::vector< std::vector< double > > fGHvuvpars_flat
phot::IPhotonMappingTransformations::OpDetID_t OpDetID_t
Type of (global) optical detector ID.
std::vector< float > const * Params_t
virtual bool isVoxelValid(size_t Voxel) const
double fangle_bin_timing_vuv
bool fApplyVISBorderCorrection
std::vector< std::vector< double > > fGHvuvpars_dome
Encapsulate the geometry of an optical detector.
void SetTimingPar(size_t Voxel, size_t OpChannel, float Count, size_t parnum)
std::vector< std::vector< double > > fExpo_over_Landau_norm
const sim::PhotonVoxelDef & GetVoxelDef() const
virtual Counts_t GetCounts(size_t Voxel) const =0
Returns a pointer to NOpChannels() visibility values, one per channel.
void LoadVisSemiAnalyticProperties(double &delta_angulo_vis, double &radius) const
std::vector< std::vector< double > > fMpv
std::optional< std::array< NeiInfo, 8U > > GetNeighboringVoxelIDs(Point const &v) const
Returns IDs of the eight neighboring voxels around v.
void SetLibraryEntry(int VoxID, OpDetID_t libOpChannel, float N, bool wantReflected=false)
A container for photon visibility mapping data.
size_t NOpDets(int cryostat)
IPhotonLibrary * fTheLibrary
double finflexion_point_distance
process_name largeant stream1 can override from command line with o or output physics producers generator N
std::vector< std::vector< double > > fborder_corr_dome
float GetTimingPar(size_t Voxel, size_t OpChannel, size_t parnum) const
float doGetVisibility(geo::Point_t const &p, unsigned int OpChannel, bool wantReflected=false) const
std::vector< double > fborder_corr_angulo_flat
void SetLibraryTimingTF1Entry(int VoxID, int OpChannel, TF1 const &func)
std::vector< std::vector< std::vector< double > > > fvispars_dome
std::vector< std::vector< double > > fNorm_over_entries
const float * Counts_t
Type for visibility count per optical channel.
static double DistanceToOpDetImpl(geo::Point_t const &p, unsigned int OpDet)
MappedT0s_t doGetReflT0s(geo::Point_t const &p) const
static double SolidAngleFactorImpl(geo::Point_t const &p, unsigned int OpDet)
size_t NOpChannels() const
void SetReflCount(size_t Voxel, size_t OpChannel, float Count)
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
std::vector< std::vector< double > > fSlope
phot::IPhotonLibrary::Functions_t GetLibraryTimingTF1Entries(int VoxID) const
std::vector< double > fborder_corr_angulo_dome
phot::IPhotonLibrary::Params_t GetLibraryTimingParEntries(int VoxID) const
std::vector< std::vector< std::vector< double > > > fvispars_flat
virtual Counts_t GetReflCounts(size_t Voxel) const =0
art framework interface to geometry description
BEGIN_PROLOG could also be cout
process_name opdaq physics producers generator physics producers generator physics producers generator physics producers generator physics producers generator physics producers generator physics producers generator physics producers generator T0