SemiAnalyticalModel.h
Go to the documentation of this file.
1 #ifndef SEMIANALYTICALMODEL_H
2 #define SEMIANALYTICALMODEL_H
3 
4 // SemiAnalyticalModel
5 // - fast optical simulation using semi-analytical model
6 // - contains functions to calculate the number of direct and reflected photons incident
7 // each photo-detector, along with the necessary ultility functions (geometry calculations etc.)
8 // - full description of model: Eur. Phys. J. C 81, 349 (2021)
9 
10 // Nov 2021 by P. Green
11 
12 // fhicl
13 #include "fhiclcpp/ParameterSet.h"
14 
15 // LArSoft Libraries
17 
18 #include "TVector3.h"
19 
20 #include <vector>
21 
22 
23 // Define a new policy *not* internally promoting RealType to double:
24 typedef boost::math::policies::policy<boost::math::policies::promote_double<false>> noLDoublePromote;
25 
26 
28 
29 public:
30 
31  // constructor
32  SemiAnalyticalModel(fhicl::ParameterSet VUVHits, fhicl::ParameterSet VISHits, bool doReflectedLight = false, bool includeAnodeReflections = false);
33 
34  // direct / VUV light
35  void detectedDirectVisibilities(std::map<size_t, double>& DetectedVisibilities,
36  geo::Point_t const& ScintPoint);
37 
38  // reflected / visible light
39  void detectedReflectedVisibilities(std::map<size_t, double>& ReflDetectedVisibilities,
40  geo::Point_t const& ScintPoint,
41  bool AnodeMode = false);
42 
43 private:
44 
45  // parameter and geometry initialization
46  void Initialization();
47 
48  // structure for rectangular solid angle calculation
49  struct Dims {
50  double h, w; // height, width
51  };
52 
53  // structure for optical detector information
54  struct OpticalDetector {
55  double h; // height
56  double w; // width
58  int type;
60  };
61 
62  // direct light photo-detector visibility calculation
63  void VUVVisibility(geo::Point_t const& ScintPoint, OpticalDetector const& opDet, double &DetThis);
64 
65  // reflected light photo-detector visibility calculation
66  void VISVisibility(geo::Point_t const& ScintPoint, OpticalDetector const& opDet, const double cathode_visibility,
67  geo::Point_t const& hotspot, double &ReflDetThis, bool AnodeMode = false);
68 
69  // Gaisser-Hillas
70  double Gaisser_Hillas(const double x, const double* par) const;
71 
72  // solid angle calculations
73  // rectangular aperture
74  double Rectangle_SolidAngle(const double a, const double b, const double d) const;
75  double Rectangle_SolidAngle(Dims const& o, geo::Vector_t const& v, const double OpDetOrientation) const;
76  // circular aperture
77  double Disk_SolidAngle(const double d, const double h, const double b) const;
78  // dome aperture calculation
79  double Omega_Dome_Model(const double distance, const double theta) const;
80 
81  // utility functions
82  bool isOpDetInSameTPC(geo::Point_t const& ScintPoint, geo::Point_t const& OpDetPoint) const;
83 
84  double fast_acos(double x) const;
85 
86  double interpolate(const std::vector<double>& xData,
87  const std::vector<double>& yData,
88  double x,
89  bool extrapolate,
90  size_t i = 0) const;
91 
92  double interpolate2(const std::vector<double>& xDistances,
93  const std::vector<double>& rDistances,
94  const std::vector<std::vector<std::vector<double>>>& parameters,
95  const double x,
96  const double r,
97  const size_t k) const;
98 
99  // implements relative method - do not use for comparing with zero
100  // use this most of the time, tolerance needs to be meaningful in your context
101  template <typename TReal>
102  inline constexpr static bool
103  isApproximatelyEqual(TReal a, TReal b, TReal tolerance = std::numeric_limits<TReal>::epsilon())
104  {
105  TReal diff = std::fabs(a - b);
106  if (diff <= tolerance) return true;
107  if (diff < std::fmax(std::fabs(a), std::fabs(b)) * tolerance) return true;
108  return false;
109  }
110 
111  // supply tolerance that is meaningful in your context
112  // for example, default tolerance may not work if you are comparing double with
113  // float
114  template <typename TReal>
115  inline constexpr static bool
116  isApproximatelyZero(TReal a, TReal tolerance = std::numeric_limits<TReal>::epsilon())
117  {
118  if (std::fabs(a) <= tolerance) return true;
119  return false;
120  }
121 
122  // use this when you want to be on safe side
123  // for example, don't start rover unless signal is above 1
124  template <typename TReal>
125  inline constexpr static bool
126  isDefinitelyLessThan(TReal a, TReal b, TReal tolerance = std::numeric_limits<TReal>::epsilon())
127  {
128  TReal diff = a - b;
129  if (diff < tolerance) return true;
130  if (diff < std::fmax(std::fabs(a), std::fabs(b)) * tolerance) return true;
131  return false;
132  }
133 
134  template <typename TReal>
135  inline constexpr static bool
136  isDefinitelyGreaterThan(TReal a, TReal b, TReal tolerance = std::numeric_limits<TReal>::epsilon())
137  {
138  TReal diff = a - b;
139  if (diff > tolerance) return true;
140  if (diff > std::fmax(std::fabs(a), std::fabs(b)) * tolerance) return true;
141  return false;
142  }
143 
144  // fhicl parameter sets
147 
148  // geometry properties
149  int fNTPC;
151  std::vector<geo::BoxBoundedGeo> fActiveVolumes;
155 
156  // photodetector geometry properties
157  size_t nOpDets;
158  double fradius;
161  std::vector<geo::Point_t> fOpDetCenter;
162  std::vector<int> fOpDetType;
163  std::vector<int> fOpDetOrientation;
164  std::vector<double> fOpDetLength;
165  std::vector<double> fOpDetHeight;
166 
167  // absorption length
169 
170  // For VUV semi-analytic hits
172  // flat PDs
174  std::vector<std::vector<double>> fGHvuvpars_flat;
175  std::vector<double> fborder_corr_angulo_flat;
176  std::vector<std::vector<double>> fborder_corr_flat;
177  // lateral PDs
179  std::vector<double> fGH_distances_anode;
180  std::vector<std::vector<std::vector<double>>> fGHvuvpars_flat_lateral;
181  // dome PDs
183  std::vector<std::vector<double>> fGHvuvpars_dome;
184  std::vector<double> fborder_corr_angulo_dome;
185  std::vector<std::vector<double>> fborder_corr_dome;
186  // Field cage scaling
190 
191  // For VIS semi-analytic hits
194  // correction parameters for VIS Nhits estimation
197  // flat PDs
198  std::vector<double> fvis_distances_x_flat;
199  std::vector<double> fvis_distances_r_flat;
200  std::vector<std::vector<std::vector<double>>> fvispars_flat;
201  // lateral PDs
202  std::vector<double> fvis_distances_x_flat_lateral;
203  std::vector<double> fvis_distances_r_flat_lateral;
204  std::vector<std::vector<std::vector<double>>> fvispars_flat_lateral;
205  // dome PDs
206  std::vector<double> fvis_distances_x_dome;
207  std::vector<double> fvis_distances_r_dome;
208  std::vector<std::vector<std::vector<double>>> fvispars_dome;
209 
210 };
211 
212 #endif
std::vector< double > fvis_distances_r_dome
std::vector< std::vector< std::vector< double > > > fGHvuvpars_flat_lateral
std::vector< double > fvis_distances_r_flat_lateral
static constexpr bool isDefinitelyLessThan(TReal a, TReal b, TReal tolerance=std::numeric_limits< TReal >::epsilon())
double Gaisser_Hillas(const double x, const double *par) const
std::vector< std::vector< double > > fborder_corr_dome
double interpolate2(const std::vector< double > &xDistances, const std::vector< double > &rDistances, const std::vector< std::vector< std::vector< double >>> &parameters, const double x, const double r, const size_t k) const
std::vector< std::vector< std::vector< double > > > fvispars_flat_lateral
double Omega_Dome_Model(const double distance, const double theta) const
void detectedDirectVisibilities(std::map< size_t, double > &DetectedVisibilities, geo::Point_t const &ScintPoint)
std::vector< double > fGH_distances_anode
std::vector< std::vector< double > > fGHvuvpars_flat
auto const tolerance
std::vector< std::vector< double > > fGHvuvpars_dome
boost::math::policies::policy< boost::math::policies::promote_double< false > > noLDoublePromote
std::vector< double > fvis_distances_r_flat
struct vector vector
std::vector< double > fOpDetHeight
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:164
void VUVVisibility(geo::Point_t const &ScintPoint, OpticalDetector const &opDet, double &DetThis)
std::vector< std::vector< std::vector< double > > > fvispars_flat
void detectedReflectedVisibilities(std::map< size_t, double > &ReflDetectedVisibilities, geo::Point_t const &ScintPoint, bool AnodeMode=false)
double fast_acos(double x) const
double Rectangle_SolidAngle(const double a, const double b, const double d) const
std::vector< geo::BoxBoundedGeo > fActiveVolumes
std::vector< double > fvis_distances_x_flat
const double a
double interpolate(const std::vector< double > &xData, const std::vector< double > &yData, double x, bool extrapolate, size_t i=0) const
std::vector< double > fvis_distances_x_flat_lateral
double distance(double x1, double y1, double z1, double x2, double y2, double z2)
std::vector< geo::Point_t > fOpDetCenter
std::vector< double > fOpDetLength
std::vector< std::vector< double > > fborder_corr_flat
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:184
static constexpr bool isApproximatelyEqual(TReal a, TReal b, TReal tolerance=std::numeric_limits< TReal >::epsilon())
void VISVisibility(geo::Point_t const &ScintPoint, OpticalDetector const &opDet, const double cathode_visibility, geo::Point_t const &hotspot, double &ReflDetThis, bool AnodeMode=false)
static constexpr bool isApproximatelyZero(TReal a, TReal tolerance=std::numeric_limits< TReal >::epsilon())
std::vector< int > fOpDetType
std::vector< double > fborder_corr_angulo_dome
bool isOpDetInSameTPC(geo::Point_t const &ScintPoint, geo::Point_t const &OpDetPoint) const
static bool * b
Definition: config.cpp:1043
std::vector< double > fvis_distances_x_dome
static constexpr bool isDefinitelyGreaterThan(TReal a, TReal b, TReal tolerance=std::numeric_limits< TReal >::epsilon())
list x
Definition: train.py:276
double Disk_SolidAngle(const double d, const double h, const double b) const
fhicl::ParameterSet fVISHitsParams
SemiAnalyticalModel(fhicl::ParameterSet VUVHits, fhicl::ParameterSet VISHits, bool doReflectedLight=false, bool includeAnodeReflections=false)
std::vector< double > fborder_corr_angulo_flat
std::vector< int > fOpDetOrientation
fhicl::ParameterSet fVUVHitsParams
std::vector< std::vector< std::vector< double > > > fvispars_dome