Jpp 21.0.0-rc.1-88-g0130508c4
the software that should make you happy
Loading...
Searching...
No Matches
JPDFSupportkit.hh
Go to the documentation of this file.
1#ifndef __JPHYSICS_JPDFSUPPORTKIT__
2#define __JPHYSICS_JPDFSUPPORTKIT__
3
4#include <string>
5#include <istream>
6#include <ostream>
7#include <iomanip>
8#include <map>
9
11
12/**
13 * \author mdejong
14 */
15
16namespace JPHYSICS {}
17namespace JPP { using namespace JPHYSICS; }
18
19namespace NAMESPACE {
20 extern double getAbsorptionLength(const double lambda);
21 extern double getScatteringLength(const double lambda);
22 extern double getScatteringProbability(const double x);
23 extern double getQE(const double lambda);
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)["SmithAndBaker"] = 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() >> JAbsorptionLength::get_offset(); ) {
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
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 const double y = 1.0 / (get_factor() * (*get_function())(lambda)) + 1.0 / get_offset();
106
107 return 1.0 / y;
108 }
109
110
111 /**
112 * Get reference to multiplication factor.
113 *
114 * \return factor
115 */
116 static double& get_factor()
117 {
118 static double factor = 1.0;
119
120 return factor;
121 }
122
123
124 /**
125 * Get reference to offset.
126 *
127 * \return offset
128 */
129 static double& get_offset()
130 {
131 static double offset = 1.0e6;
132
133 return offset;
134 }
135
136
137 /**
138 * Get reference to global functon.
139 *
140 * \return function
141 */
142 static pF& get_function()
143 {
145
146 return f1;
147 }
148 };
149
150
151 /**
152 * Auxiliary data structure to define pointer to global function.
153 */
155 typedef double (*pF)(const double); // type definition of pointer to global function
156 };
157
158
159 /**
160 * Auxiliary data structure to customize scattering length.
161 */
163 public JScatteringLength_t,
164 public std::map<std::string, JScatteringLength_t::pF>
165 {
166 /**
167 * Default constructor.
168 */
170 {
171 (*this)["default"] = NAMESPACE::getScatteringLength;
172 }
173
174
175 /**
176 * Read scattering length from input stream.
177 *
178 * \param in input stream
179 * \param scattering scattering length
180 * \return input stream
181 */
182 friend inline std::istream& operator>>(std::istream& in, JScatteringLength& scattering)
183 {
184 using namespace std;
185
186 for (string option; in >> option >> JScatteringLength::get_factor(); ) {
187
188 JScatteringLength::const_iterator p = scattering.find(option);
189
190 if (p != scattering.end())
192 else
193 in.setstate(ios_base::badbit);
194 }
195
196 return in;
197 }
198
199
200 /**
201 * Write scattering length to output stream.
202 *
203 * \param out output stream
204 * \param scattering scattering length
205 * \return output stream
206 */
207 friend inline std::ostream& operator<<(std::ostream& out, const JScatteringLength& scattering)
208 {
209 for (const_iterator i = scattering.begin(); i != scattering.end(); ++i) {
210 if (i->second == JScatteringLength::get_function()) {
211 out << i->first << ' ';
212 }
213 }
214
215 return out << JScatteringLength::get_factor();
216 }
217
218
219 /**
220 * Get scattering length.
221 *
222 * \param lambda wavelength of light [nm]
223 * \return scattering length [m]
224 */
225 static inline double getScatteringLength(const double lambda)
226 {
227 return get_factor() * (*get_function())(lambda);
228 }
229
230
231 /**
232 * Get reference to multiplication factor.
233 *
234 * \return factor
235 */
236 static double& get_factor()
237 {
238 static double factor = 1.0;
239
240 return factor;
241 }
242
243
244 /**
245 * Get reference to global functon.
246 *
247 * \return function
248 */
249 static pF& get_function()
250 {
252
253 return f1;
254 }
255 };
256
257
258 /**
259 * Auxiliary data structure to define pointer to global function.
260 */
262 typedef double (*pF)(const double); // type definition of pointer to global function
263 };
264
265
266 /**
267 * Auxiliary data structure to customize scattering probability.
268 */
271 public std::map<std::string, JScatteringProbability_t::pF>
272 {
273 /**
274 * Default constructor.
275 */
277 {
278 (*this)["default"] = NAMESPACE::getScatteringProbability;
279 (*this)["f4"] = f4;
280 (*this)["p00075"] = p00075;
281 (*this)["petzhold"] = petzhold;
282 }
283
284
285 /**
286 * Read scattering probability from input stream.
287 *
288 * \param in input stream
289 * \param scattering scattering probability
290 * \return input stream
291 */
292 friend inline std::istream& operator>>(std::istream& in, JScatteringProbability& scattering)
293 {
294 using namespace std;
295
296 for (string option; in >> option >> JScatteringProbability::get_weight(); ) {
297
298 JScatteringProbability::const_iterator p = scattering.find(option);
299
300 if (p != scattering.end())
302 else
303 in.setstate(ios_base::badbit);
304 }
305
306 return in;
307 }
308
309
310 /**
311 * Write scattering probability to output stream.
312 *
313 * \param out output stream
314 * \param scattering scattering probability
315 * \return output stream
316 */
317 friend inline std::ostream& operator<<(std::ostream& out, const JScatteringProbability& scattering)
318 {
319 for (const_iterator i = scattering.begin(); i != scattering.end(); ++i) {
320 if (i->second == JScatteringProbability::get_function()) {
321 out << i->first << ' ';
322 }
323 }
324
326 }
327
328
329 /**
330 * Get scattering probability.
331 *
332 * \param x cosine scattering angle
333 * \return probability
334 */
335 static inline double getScatteringProbability(const double x)
336 {
337 return (1.0 - get_weight()) * rayleigh(x) + get_weight() * (*get_function())(x);
338 }
339
340
341 /**
342 * Get reference to weight.
343 *
344 * \return weight
345 */
346 static double& get_weight()
347 {
348 static double weight = 1.0;
349
350 return weight;
351 }
352
353
354 /**
355 * Get reference to global functon.
356 *
357 * \return function
358 */
359 static pF& get_function()
360 {
362
363 return f1;
364 }
365 };
366
367
368 /**
369 * Auxiliary data structure to define pointer to global function.
370 */
371 struct JQE_t {
372 typedef double (*pF)(const double); // type definition of pointer to global function
373 };
374
375
376 /**
377 * Auxiliary data structure to customize quantum efficiency.
378 */
379 struct JQE :
380 public JQE_t,
381 public std::map<std::string, JQE_t::pF>
382 {
383 /**
384 * Default constructor.
385 */
387 {
388 (*this)["default"] = NAMESPACE::getQE;
389 }
390
391
392 /**
393 * Read quantum efficiency from input stream.
394 *
395 * \param in input stream
396 * \param scattering quantum efficiency
397 * \return input stream
398 */
399 friend inline std::istream& operator>>(std::istream& in, JQE& scattering)
400 {
401 using namespace std;
402
403 for (string option; in >> option >> JQE::get_factor(); ) {
404
405 JQE::const_iterator p = scattering.find(option);
406
407 if (p != scattering.end())
408 JQE::get_function() = p->second;
409 else
410 in.setstate(ios_base::badbit);
411 }
412
413 return in;
414 }
415
416
417 /**
418 * Write quantum efficiency to output stream.
419 *
420 * \param out output stream
421 * \param scattering quantum efficiency
422 * \return output stream
423 */
424 friend inline std::ostream& operator<<(std::ostream& out, const JQE& scattering)
425 {
426 for (const_iterator i = scattering.begin(); i != scattering.end(); ++i) {
427 if (i->second == JQE::get_function()) {
428 out << i->first << ' ';
429 }
430 }
431
432 return out << JQE::get_factor();
433 }
434
435
436 /**
437 * Get quantum efficiency.
438 *
439 * \param lambda wavelength of light [nm]
440 * \return quantum efficiency [m]
441 */
442 static inline double getQE(const double lambda)
443 {
444 return get_factor() * (*get_function())(lambda);
445 }
446
447
448 /**
449 * Get reference to multiplication factor.
450 *
451 * \return factor
452 */
453 static double& get_factor()
454 {
455 static double factor = 1.0;
456
457 return factor;
458 }
459
460
461 /**
462 * Get reference to global functon.
463 *
464 * \return function
465 */
466 static pF& get_function()
467 {
468 static pF f1 = NAMESPACE::getQE;
469
470 return f1;
471 }
472 };
473}
474
475#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)
double getQE(const double lambda)
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_offset()
Get reference to offset.
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 quantum efficiency.
friend std::istream & operator>>(std::istream &in, JQE &scattering)
Read quantum efficiency from input stream.
JQE()
Default constructor.
static double getQE(const double lambda)
Get quantum efficiency.
static double & get_factor()
Get reference to multiplication factor.
friend std::ostream & operator<<(std::ostream &out, const JQE &scattering)
Write quantum efficiency to output stream.
static pF & get_function()
Get reference to global functon.
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.