Jpp 20.0.0-195-g190c9e876
the software that should make you happy
Loading...
Searching...
No Matches
JPDFSupportkit.hh
Go to the documentation of this file.
1
2#ifndef __JPHYSICS_JPDFSUPPORTKIT__
3#define __JPHYSICS_JPDFSUPPORTKIT__
4
5#include <string>
6#include <istream>
7#include <ostream>
8#include <iomanip>
9#include <map>
10
12
13/**
14 * \author mdejong
15 */
16
17namespace JPHYSICS {}
18namespace JPP { using namespace JPHYSICS; }
19
20namespace NAMESPACE {
21 extern double getAbsorptionLength(const double lambda);
22 extern double getScatteringLength(const double lambda);
23 extern double getScatteringProbability(const double x);
24}
25
26namespace JPHYSICS {
27
28 /**
29 * Auxiliary data structure to define pointer to global function.
30 */
32 typedef double (*pF)(const double); // type definition of pointer to global function
33 };
34
35
36 /**
37 * Auxiliary data structure to customize absorption length.
38 */
41 public std::map<std::string, JAbsorptionLength_t::pF>
42 {
43 /**
44 * Default constructor.
45 */
47 {
48 (*this)["default"] = NAMESPACE::getAbsorptionLength;
49 (*this)["Smith&Baker"] = getAbsorptionLengthSmithAndBaker;
50 }
51
52
53 /**
54 * Read absorption length from input stream.
55 *
56 * \param in input stream
57 * \param absorption absorption length
58 * \return input stream
59 */
60 friend inline std::istream& operator>>(std::istream& in, JAbsorptionLength& absorption)
61 {
62 using namespace std;
63
64 for (string option; in >> option >> JAbsorptionLength::get_factor(); ) {
65
66 JAbsorptionLength::const_iterator p = absorption.find(option);
67
68 if (p != absorption.end())
70 else
71 in.setstate(ios_base::badbit);
72 }
73
74 return in;
75 }
76
77
78 /**
79 * Write absorption length to output stream.
80 *
81 * \param out output stream
82 * \param absorption absorption length
83 * \return output stream
84 */
85 friend inline std::ostream& operator<<(std::ostream& out, const JAbsorptionLength& absorption)
86 {
87 for (const_iterator i = absorption.begin(); i != absorption.end(); ++i) {
88 if (i->second == JAbsorptionLength::get_function()) {
89 out << i->first << ' ';
90 }
91 }
92
93 return out << JAbsorptionLength::get_factor();
94 }
95
96
97 /**
98 * Get absorption length.
99 *
100 * \param lambda wavelength of light [nm]
101 * \return absorption length [m]
102 */
103 static inline double getAbsorptionLength(const double lambda)
104 {
105 return get_factor() * (*get_function())(lambda);
106 }
107
108 private:
109 /**
110 * Get reference to multiplication factor.
111 *
112 * \return factor
113 */
114 static double& get_factor()
115 {
116 static double factor = 1.0;
117
118 return factor;
119 }
120
121
122 /**
123 * Get reference to global functon.
124 *
125 * \return function
126 */
127 static pF& get_function()
128 {
130
131 return f1;
132 }
133 };
134
135
136 /**
137 * Auxiliary data structure to define pointer to global function.
138 */
140 typedef double (*pF)(const double); // type definition of pointer to global function
141 };
142
143
144 /**
145 * Auxiliary data structure to customize scattering length.
146 */
148 public JScatteringLength_t,
149 public std::map<std::string, JScatteringLength_t::pF>
150 {
151 /**
152 * Default constructor.
153 */
155 {
156 (*this)["default"] = NAMESPACE::getScatteringLength;
157 }
158
159
160 /**
161 * Read scattering length from input stream.
162 *
163 * \param in input stream
164 * \param scattering scattering length
165 * \return input stream
166 */
167 friend inline std::istream& operator>>(std::istream& in, JScatteringLength& scattering)
168 {
169 using namespace std;
170
171 for (string option; in >> option >> JScatteringLength::get_factor(); ) {
172
173 JScatteringLength::const_iterator p = scattering.find(option);
174
175 if (p != scattering.end())
177 else
178 in.setstate(ios_base::badbit);
179 }
180
181 return in;
182 }
183
184
185 /**
186 * Write scattering length to output stream.
187 *
188 * \param out output stream
189 * \param scattering scattering length
190 * \return output stream
191 */
192 friend inline std::ostream& operator<<(std::ostream& out, const JScatteringLength& scattering)
193 {
194 for (const_iterator i = scattering.begin(); i != scattering.end(); ++i) {
195 if (i->second == JScatteringLength::get_function()) {
196 out << i->first << ' ';
197 }
198 }
199
200 return out << JScatteringLength::get_factor();
201 }
202
203
204 /**
205 * Get scattering length.
206 *
207 * \param lambda wavelength of light [nm]
208 * \return scattering length [m]
209 */
210 static inline double getScatteringLength(const double lambda)
211 {
212 return get_factor() * (*get_function())(lambda);
213 }
214
215 private:
216 /**
217 * Get reference to multiplication factor.
218 *
219 * \return factor
220 */
221 static double& get_factor()
222 {
223 static double factor = 1.0;
224
225 return factor;
226 }
227
228
229 /**
230 * Get reference to global functon.
231 *
232 * \return function
233 */
234 static pF& get_function()
235 {
237
238 return f1;
239 }
240 };
241
242
243 /**
244 * Auxiliary data structure to define pointer to global function.
245 */
247 typedef double (*pF)(const double); // type definition of pointer to global function
248 };
249
250
251 /**
252 * Auxiliary data structure to customize scattering probability.
253 */
256 public std::map<std::string, JScatteringProbability_t::pF>
257 {
258 /**
259 * Default constructor.
260 */
262 {
263 (*this)["default"] = NAMESPACE::getScatteringProbability;
264 (*this)["f4"] = f4;
265 (*this)["p00075"] = p00075;
266 (*this)["petzhold"] = petzhold;
267 }
268
269
270 /**
271 * Read scattering probability from input stream.
272 *
273 * \param in input stream
274 * \param scattering scattering probability
275 * \return input stream
276 */
277 friend inline std::istream& operator>>(std::istream& in, JScatteringProbability& scattering)
278 {
279 using namespace std;
280
281 for (string option; in >> option >> JScatteringProbability::get_weight(); ) {
282
283 JScatteringProbability::const_iterator p = scattering.find(option);
284
285 if (p != scattering.end())
287 else
288 in.setstate(ios_base::badbit);
289 }
290
291 return in;
292 }
293
294
295 /**
296 * Write scattering probability to output stream.
297 *
298 * \param out output stream
299 * \param scattering scattering probability
300 * \return output stream
301 */
302 friend inline std::ostream& operator<<(std::ostream& out, const JScatteringProbability& scattering)
303 {
304 for (const_iterator i = scattering.begin(); i != scattering.end(); ++i) {
305 if (i->second == JScatteringProbability::get_function()) {
306 out << i->first << ' ';
307 }
308 }
309
311 }
312
313
314 /**
315 * Get scattering probability.
316 *
317 * \param x cosine scattering angle
318 * \return probability
319 */
320 static inline double getScatteringProbability(const double x)
321 {
322 return (1.0 - get_weight()) * rayleigh(x) + get_weight() * (*get_function())(x);
323 }
324
325 private:
326 /**
327 * Get reference to weight.
328 *
329 * \return weight
330 */
331 static double& get_weight()
332 {
333 static double weight = 1.0;
334
335 return weight;
336 }
337
338
339 /**
340 * Get reference to global functon.
341 *
342 * \return function
343 */
344 static pF& get_function()
345 {
347
348 return f1;
349 }
350 };
351}
352
353#endif
Auxiliary methods for light properties of deep-sea water.
double p00075(const double x)
Model specific function to describe light scattering in water (p00075).
double petzhold(const double x)
Model specific function to describe light scattering in water (Petzhold).
double rayleigh(const double a, const double x)
Auxiliary method to describe light scattering in water (Rayleigh).
double getAbsorptionLengthSmithAndBaker(const double lambda)
Absorption length of deep-sea water according Smith & Baker.
double f4(const double x)
Model specific function to describe light scattering in water (f4).
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
double getAbsorptionLength(const double lambda)
double getScatteringLength(const double lambda)
double getScatteringProbability(const double x)
Auxiliary data structure to define pointer to global function.
double(*) pF(const double)
Auxiliary data structure to customize absorption length.
JAbsorptionLength()
Default constructor.
static double & get_factor()
Get reference to multiplication factor.
friend std::istream & operator>>(std::istream &in, JAbsorptionLength &absorption)
Read absorption length from input stream.
static pF & get_function()
Get reference to global functon.
friend std::ostream & operator<<(std::ostream &out, const JAbsorptionLength &absorption)
Write absorption length to output stream.
static double getAbsorptionLength(const double lambda)
Get absorption length.
Auxiliary data structure to define pointer to global function.
double(*) pF(const double)
Auxiliary data structure to customize scattering length.
friend std::ostream & operator<<(std::ostream &out, const JScatteringLength &scattering)
Write scattering length to output stream.
static double & get_factor()
Get reference to multiplication factor.
JScatteringLength()
Default constructor.
static double getScatteringLength(const double lambda)
Get scattering length.
friend std::istream & operator>>(std::istream &in, JScatteringLength &scattering)
Read scattering length from input stream.
static pF & get_function()
Get reference to global functon.
Auxiliary data structure to define pointer to global function.
Auxiliary data structure to customize scattering probability.
JScatteringProbability()
Default constructor.
static double getScatteringProbability(const double x)
Get scattering probability.
friend std::ostream & operator<<(std::ostream &out, const JScatteringProbability &scattering)
Write scattering probability to output stream.
static double & get_weight()
Get reference to weight.
friend std::istream & operator>>(std::istream &in, JScatteringProbability &scattering)
Read scattering probability from input stream.
static pF & get_function()
Get reference to global functon.