Jpp 21.0.0-rc.3
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#include "Jeep/JProperties.hh"
13
14
15/**
16 * \author mdejong
17 */
18
19namespace JPHYSICS {}
20namespace JPP { using namespace JPHYSICS; }
21
22namespace NAMESPACE {
23 extern double getAbsorptionLength(const double lambda);
24 extern double getScatteringLength(const double lambda);
25 extern double getScatteringProbability(const double x);
26 extern double getAngularAcceptance(const double x);
27 extern double getQE(const double lambda);
28}
29
30namespace JPHYSICS {
31
33
34
35 /**
36 * Auxiliary method to get preferred key for given value.
37 *
38 * \param map map
39 * \param key preferred key
40 * \param value target value
41 * \return key
42 */
43 template<class T>
44 inline std::string getKey(const std::map<std::string, T>& map, const std::string& key, const T& value)
45 {
46 if (map.count(key) && map.at(key) == value) {
47 return key;
48 }
49
50 for (const auto& i : map) {
51 if (i.second == value) {
52 return i.first;
53 }
54 }
55
56 return "";
57 }
58
59
60 /**
61 * Auxiliary data structure to customize absorption length.
62 */
64 public std::map<std::string, double (*)(const double)>
65 {
66 static constexpr const char* const default_t = "default";
67 static constexpr const char* const nemo_t = "nemo";
68 static constexpr const char* const SmithAndBaker_t = "SmithAndBaker";
69
70
71 /**
72 * Default constructor.
73 */
84
85
86 /**
87 * Read absorption length from input stream.
88 *
89 * \param in input stream
90 * \param object absorption length
91 * \return input stream
92 */
93 friend inline std::istream& operator>>(std::istream& in, JAbsorptionLength& object)
94 {
95 using namespace std;
96
97 for (string option; in >> option >> JAbsorptionLength::get_factor() >> JAbsorptionLength::get_offset(); ) {
98
99 JAbsorptionLength::const_iterator p = object.find(option);
100
101 if (p != object.end())
103 else
104 in.setstate(ios_base::badbit);
105 }
106
107 return in;
108 }
109
110
111 /**
112 * Write absorption length to output stream.
113 *
114 * \param out output stream
115 * \param object absorption length
116 * \return output stream
117 */
118 friend inline std::ostream& operator<<(std::ostream& out, const JAbsorptionLength& object)
119 {
120 return out << getKey(object, default_t, get_function())
123 }
124
125
126 /**
127 * Get absorption length.
128 *
129 * \param lambda wavelength of light [nm]
130 * \return absorption length [m]
131 */
132 static inline double getAbsorptionLength(const double lambda)
133 {
134 const double y = 1.0 / (get_factor() * (*get_function())(lambda)) + 1.0 / get_offset();
135
136 return 1.0 / y;
137 }
138
139
140 /**
141 * Get reference to multiplication factor.
142 *
143 * \return factor
144 */
145 static double& get_factor()
146 {
147 static double factor = 1.0;
148
149 return factor;
150 }
151
152
153 /**
154 * Get reference to offset.
155 *
156 * \return offset
157 */
158 static double& get_offset()
159 {
160 static double offset = 1.0e6;
161
162 return offset;
163 }
164
165
166 /**
167 * Get reference to global functon.
168 *
169 * \return function
170 */
171 static mapped_type& get_function()
172 {
173 static mapped_type f1 = NAMESPACE::getAbsorptionLength;
174
175 return f1;
176 }
177 };
178
179
180 /**
181 * Auxiliary data structure to customize scattering length.
182 */
184 public std::map<std::string, double (*)(const double)>
185 {
186 static constexpr const char* const default_t = "default";
187
188
189 /**
190 * Default constructor.
191 */
193 {
195
196 get_factor() = 1.0;
197 get_function() = (*this)[default_t];
198 }
199
200
201 /**
202 * Read scattering length from input stream.
203 *
204 * \param in input stream
205 * \param object scattering length
206 * \return input stream
207 */
208 friend inline std::istream& operator>>(std::istream& in, JScatteringLength& object)
209 {
210 using namespace std;
211
212 for (string option; in >> option >> JScatteringLength::get_factor(); ) {
213
214 JScatteringLength::const_iterator p = object.find(option);
215
216 if (p != object.end())
218 else
219 in.setstate(ios_base::badbit);
220 }
221
222 return in;
223 }
224
225
226 /**
227 * Write scattering length to output stream.
228 *
229 * \param out output stream
230 * \param object scattering length
231 * \return output stream
232 */
233 friend inline std::ostream& operator<<(std::ostream& out, const JScatteringLength& object)
234 {
235 return out << getKey(object, default_t, get_function())
237 }
238
239
240 /**
241 * Get scattering length.
242 *
243 * \param lambda wavelength of light [nm]
244 * \return scattering length [m]
245 */
246 static inline double getScatteringLength(const double lambda)
247 {
248 return get_factor() * (*get_function())(lambda);
249 }
250
251
252 /**
253 * Get reference to multiplication factor.
254 *
255 * \return factor
256 */
257 static double& get_factor()
258 {
259 static double factor = 1.0;
260
261 return factor;
262 }
263
264
265 /**
266 * Get reference to global functon.
267 *
268 * \return function
269 */
270 static mapped_type& get_function()
271 {
272 static mapped_type f1 = NAMESPACE::getScatteringLength;
273
274 return f1;
275 }
276 };
277
278
279 /**
280 * Auxiliary data structure to customize scattering probability.
281 */
283 public std::map<std::string, double (*)(const double)>
284 {
285 static constexpr const char* const default_t = "default";
286 static constexpr const char* const f4_t = "f4";
287 static constexpr const char* const p00075_t = "p00075";
288 static constexpr const char* const petzhold_t = "petzhold";
289
290
291 /**
292 * Default constructor.
293 */
295 {
297 (*this)[f4_t] = f4;
298 (*this)[p00075_t] = p00075;
299 (*this)[petzhold_t] = petzhold;
300
301 get_weight() = 1.0;
302 get_function() = (*this)[default_t];
303 }
304
305
306 /**
307 * Read scattering probability from input stream.
308 *
309 * \param in input stream
310 * \param object scattering probability
311 * \return input stream
312 */
313 friend inline std::istream& operator>>(std::istream& in, JScatteringProbability& object)
314 {
315 using namespace std;
316
317 for (string option; in >> option >> JScatteringProbability::get_weight(); ) {
318
319 JScatteringProbability::const_iterator p = object.find(option);
320
321 if (p != object.end())
323 else
324 in.setstate(ios_base::badbit);
325 }
326
327 return in;
328 }
329
330
331 /**
332 * Write scattering probability to output stream.
333 *
334 * \param out output stream
335 * \param object scattering probability
336 * \return output stream
337 */
338 friend inline std::ostream& operator<<(std::ostream& out, const JScatteringProbability& object)
339 {
340 return out << getKey(object, default_t, get_function())
342 }
343
344
345 /**
346 * Get scattering probability.
347 *
348 * \param x cosine scattering angle
349 * \return probability
350 */
351 static inline double getScatteringProbability(const double x)
352 {
353 return (1.0 - get_weight()) * rayleigh(x) + get_weight() * (*get_function())(x);
354 }
355
356
357 /**
358 * Get reference to weight.
359 *
360 * \return weight
361 */
362 static double& get_weight()
363 {
364 static double weight = 1.0;
365
366 return weight;
367 }
368
369
370 /**
371 * Get reference to global functon.
372 *
373 * \return function
374 */
375 static mapped_type& get_function()
376 {
377 static mapped_type f1 = NAMESPACE::getScatteringProbability;
378
379 return f1;
380 }
381 };
382
383
384 /**
385 * Auxiliary data structure to customize PMT angular acceptance.
386 */
388 public std::map<std::string, double (*)(const double)>
389 {
390 static constexpr const char* const default_t = "default";
391
392
393 /**
394 * Default constructor.
395 */
397 {
399
400 get_function() = (*this)[default_t];
401 }
402
403
404 /**
405 * Read PMT angular acceptance from input stream.
406 *
407 * \param in input stream
408 * \param object PMT angular acceptance
409 * \return input stream
410 */
411 friend inline std::istream& operator>>(std::istream& in, JPMTAngularAcceptance& object)
412 {
413 using namespace std;
414
415 for (string option; in >> option; ) {
416
417 JPMTAngularAcceptance::const_iterator p = object.find(option);
418
419 if (p != object.end())
421 else
422 in.setstate(ios_base::badbit);
423 }
424
425 return in;
426 }
427
428
429 /**
430 * Write PMT angular acceptance to output stream.
431 *
432 * \param out output stream
433 * \param object PMT angular acceptance
434 * \return output stream
435 */
436 friend inline std::ostream& operator<<(std::ostream& out, const JPMTAngularAcceptance& object)
437 {
438 return out << getKey(object, default_t, get_function());
439 }
440
441
442 /**
443 * Get angular acceptance of PMT.
444 *
445 * \param x cosine angle of incidence
446 * \return probability
447 */
448 static inline double getAngularAcceptance(const double x)
449 {
450 return (*get_function())(x);
451 }
452
453
454 /**
455 * Get reference to global functon.
456 *
457 * \return function
458 */
459 static mapped_type& get_function()
460 {
461 static mapped_type f1 = NAMESPACE::getAngularAcceptance;
462
463 return f1;
464 }
465 };
466
467
468 /**
469 * Auxiliary data structure to customize quantum efficiency.
470 */
471 struct JQE :
472 public std::map<std::string, double (*)(const double)>
473 {
474 static constexpr const char* const default_t = "default";
475
476
477 /**
478 * Default constructor.
479 */
481 {
482 (*this)[default_t] = NAMESPACE::getQE;
483
484 get_factor() = 1.0;
485 get_function() = (*this)[default_t];
486 }
487
488
489 /**
490 * Read quantum efficiency from input stream.
491 *
492 * \param in input stream
493 * \param object quantum efficiency
494 * \return input stream
495 */
496 friend inline std::istream& operator>>(std::istream& in, JQE& object)
497 {
498 using namespace std;
499
500 for (string option; in >> option >> JQE::get_factor(); ) {
501
502 JQE::const_iterator p = object.find(option);
503
504 if (p != object.end())
505 JQE::get_function() = p->second;
506 else
507 in.setstate(ios_base::badbit);
508 }
509
510 return in;
511 }
512
513
514 /**
515 * Write quantum efficiency to output stream.
516 *
517 * \param out output stream
518 * \param object quantum efficiency
519 * \return output stream
520 */
521 friend inline std::ostream& operator<<(std::ostream& out, const JQE& object)
522 {
523 return out << getKey(object, default_t, get_function())
524 << ' ' << JQE::get_factor();
525 }
526
527
528 /**
529 * Get quantum efficiency.
530 *
531 * \param lambda wavelength of light [nm]
532 * \return quantum efficiency [m]
533 */
534 static inline double getQE(const double lambda)
535 {
536 return get_factor() * (*get_function())(lambda);
537 }
538
539
540 /**
541 * Get reference to multiplication factor.
542 *
543 * \return factor
544 */
545 static double& get_factor()
546 {
547 static double factor = 1.0;
548
549 return factor;
550 }
551
552
553 /**
554 * Get reference to global functon.
555 *
556 * \return function
557 */
558 static mapped_type& get_function()
559 {
560 static mapped_type f1 = NAMESPACE::getQE;
561
562 return f1;
563 }
564 };
565
566
567 namespace PDF {
568 /**
569 * Auxiliary data structure for complete configuration.
570 */
572
578
579
580 /**
581 * Get properties.
582 *
583 * \return properties
584 */
586 {
587 JProperties properties;
588
589 properties.insert(gmake_property(absorptionLength));
590 properties.insert(gmake_property(scatteringLength));
591 properties.insert(gmake_property(scatteringProbability));
592 properties.insert(gmake_property(angularAcceptance));
593 properties.insert(gmake_property(QE));
594
595 return properties;
596 }
597 };
598
599
600 /**
601 * Manipulator for help output.
602 */
603 struct help {
604 /**
605 * Auxiliary data structure to stream configuration to help output.
606 */
607 struct helper {
608 /**
609 * Constructor.
610 *
611 * \param out output stream
612 */
613 helper(std::ostream& out) :
614 out(out)
615 {}
616
617
618 /**
619 * Write configuration to output stream.
620 *
621 * \param configuration configuration
622 * \return output stream
623 */
624 inline std::ostream& operator<<(const configuration_type& configuration) const
625 {
626 using namespace std;
627 using namespace JPP;
628
629 this->out << endl;
630 this->out << " possible options absorptionLength: " << get_keys(configuration.absorptionLength) << endl;
631 this->out << " possible options scatteringLength: " << get_keys(configuration.scatteringLength) << endl;
632 this->out << " possible options scatteringProbability: " << get_keys(configuration.scatteringProbability) << endl;
633 this->out << " possible options angularAcceptance: " << get_keys(configuration.angularAcceptance) << endl;
634 this->out << " possible options QE: " << get_keys(configuration.QE) << endl << " ";
635
636 return this->out;
637 }
638
639 private:
640 std::ostream& out;
641 };
642
643
644 /**
645 * Transfer output stream to helper.
646 *
647 * \param out output stream
648 * \param help help
649 * \return helper
650 */
651 friend inline helper operator<<(std::ostream& out, const help& help)
652 {
653 return helper(out);
654 }
655 };
656
662 }
663}
664
665#endif
Utility class to parse parameter values.
#define gmake_property(A)
macros to convert (template) parameter to JPropertiesElement object
Utility class to parse parameter values.
const char * map
Definition elog.cc:87
auto getScatteringProbability
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).
std::string getKey(const std::map< std::string, T > &map, const std::string &key, const T &value)
Auxiliary method to get preferred key for given value.
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)
double getAngularAcceptance(const double x)
Auxiliary data structure to customize absorption length.
friend std::ostream & operator<<(std::ostream &out, const JAbsorptionLength &object)
Write absorption length to output stream.
JAbsorptionLength()
Default constructor.
friend std::istream & operator>>(std::istream &in, JAbsorptionLength &object)
Read absorption length from input stream.
static double & get_offset()
Get reference to offset.
static constexpr const char *const default_t
static constexpr const char *const SmithAndBaker_t
static double & get_factor()
Get reference to multiplication factor.
static constexpr const char *const nemo_t
static mapped_type & get_function()
Get reference to global functon.
static double getAbsorptionLength(const double lambda)
Get absorption length.
Auxiliary data structure to customize PMT angular acceptance.
friend std::ostream & operator<<(std::ostream &out, const JPMTAngularAcceptance &object)
Write PMT angular acceptance to output stream.
static constexpr const char *const default_t
static mapped_type & get_function()
Get reference to global functon.
friend std::istream & operator>>(std::istream &in, JPMTAngularAcceptance &object)
Read PMT angular acceptance from input stream.
JPMTAngularAcceptance()
Default constructor.
static double getAngularAcceptance(const double x)
Get angular acceptance of PMT.
Auxiliary data structure to customize quantum efficiency.
JQE()
Default constructor.
static double getQE(const double lambda)
Get quantum efficiency.
static double & get_factor()
Get reference to multiplication factor.
static mapped_type & get_function()
Get reference to global functon.
static constexpr const char *const default_t
friend std::ostream & operator<<(std::ostream &out, const JQE &object)
Write quantum efficiency to output stream.
friend std::istream & operator>>(std::istream &in, JQE &object)
Read quantum efficiency from input stream.
Auxiliary data structure to customize scattering length.
static constexpr const char *const default_t
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 &object)
Read scattering length from input stream.
friend std::ostream & operator<<(std::ostream &out, const JScatteringLength &object)
Write scattering length to output stream.
static mapped_type & get_function()
Get reference to global functon.
Auxiliary data structure to customize scattering probability.
static constexpr const char *const default_t
static constexpr const char *const p00075_t
JScatteringProbability()
Default constructor.
friend std::ostream & operator<<(std::ostream &out, const JScatteringProbability &object)
Write scattering probability to output stream.
static double getScatteringProbability(const double x)
Get scattering probability.
static double & get_weight()
Get reference to weight.
static constexpr const char *const petzhold_t
static constexpr const char *const f4_t
static mapped_type & get_function()
Get reference to global functon.
friend std::istream & operator>>(std::istream &in, JScatteringProbability &object)
Read scattering probability from input stream.
Auxiliary data structure for complete configuration.
JPMTAngularAcceptance angularAcceptance
JScatteringProbability scatteringProbability
JProperties getProperties()
Get properties.
Auxiliary data structure to stream configuration to help output.
helper(std::ostream &out)
Constructor.
std::ostream & operator<<(const configuration_type &configuration) const
Write configuration to output stream.
Manipulator for help output.
friend helper operator<<(std::ostream &out, const help &help)
Transfer output stream to helper.