Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JCDFTable.hh
Go to the documentation of this file.
1#ifndef __JPHYSICS__JCDFTABLE__
2#define __JPHYSICS__JCDFTABLE__
3
4#include <memory>
5
8#include "JLang/JException.hh"
9#include "JMath/JZero.hh"
10#include "JTools/JArray.hh"
11#include "JTools/JMultiKey.hh"
19
20
21/**
22 * \author mdejong
23 */
24
25namespace JPHYSICS {}
26namespace JPP { using namespace JPHYSICS; }
27
28namespace JPHYSICS {
29
31 using JIO::JReader;
32 using JIO::JWriter;
40 using JTOOLS::JArray;
42
43
44 /**
45 * Multi-dimensional CDF table for arrival time of Cherenkov light.
46 * This class can be used to determine the number of photo-electrons as a function of
47 * the values of the leading parameter values and to generate random photon arrival times.
48 *
49 * N.B. The transformation of the PDF is assumed to be linear.
50 */
51 template<class JFunction1D_t,
52 class JMaplist_t,
54 class JCDFTable :
55 public JSerialisable,
56 public JObjectBinaryIO< JCDFTable<JFunction1D_t, JMaplist_t, JDistance_t> >,
57 public JFunctional<>
58 {
59 public:
60
61 typedef typename JFunction1D_t::argument_type argument_type;
62 typedef typename JFunction1D_t::result_type result_type;
63 typedef typename JFunction1D_t::value_type value_type;
64
66
69
71
73
77
78
79 /**
80 * Default constructor.
81 */
83 transformer(transformer_type::getClone())
84 {}
85
86
87 /**
88 * Constructor.
89 *
90 * \param input multi-dimensional PDF
91 * \param eps minimal step size for CDF
92 */
93 template<class __JFunction_t, class __JMaplist_t, class __JDistance_t>
95 const typename __JFunction_t::ordinate_type eps = JMATH::zero) :
96 transformer(transformer_type::getClone())
97 {
98 this->transformer.reset(input.transformer->clone());
99
100 for (auto i = input.super_begin(); i != input.super_end(); ++i) {
101 this->insert((*i).getKey(), (*i).getValue(), eps);
102 }
103
104 this->compile();
105 }
106
107
108 /**
109 * Constructor.
110 *
111 * \param input multi-dimensional histogram
112 * \param eps minimal step size for CDF
113 */
114 template<class JHistogram_t, class __JMaplist_t, class __JDistance_t>
116 const typename JHistogram_t::ordinate_type eps = JMATH::zero) :
117 transformer(transformer_type::getClone())
118 {
119 this->transformer.reset(input.transformer->clone());
120
121 this->insert(JMultiKey<0, typename JHistogram_t::abscissa_type>(), input, eps);
122
123 this->compile();
124 }
125
126
127 /**
128 * Application of weight function.
129 *
130 * \param transformer function transformer
131 */
132 template<class JFunctionTransformer_t>
133 void transform(const JFunctionTransformer_t& transformer)
134 {
135 for (typename JMultiQuantile_t::super_iterator i = intensity.super_begin(); i != intensity.super_end(); ++i) {
136
137 const typename transformer_type::array_type array = (*i).getKey();
138 JConstantFunction1D_t& function = (*i).getValue();
139
140 const double W1 = this->transformer->getWeight(array);
141 const double W2 = transformer .getWeight(array);
142
144
145 function = JConstantFunction1D_t(y * W1 / W2);
146 }
147
148 this->transformer.reset(transformer.clone());
149 this->compile();
150 }
151
152
153 /**
154 * Get number of photo-electrons.
155 *
156 * \param args comma separated argument list
157 * \return number of photo-electrons
158 */
159 template<class ...Args>
160 double getNPE(const Args& ...args) const
161 {
162 const JArray<NUMBER_OF_DIMENSIONS - 1, argument_type> buffer(args...);
163
164 const double W = transformer->getWeight(buffer);
165 const double npe = intensity.evaluate(buffer.data());
166
167 return W * npe;
168 }
169
170
171 /**
172 * Generate arrival time.
173 *
174 * \param args comma seperated argument list (last value is random number between 0 and 1)
175 * \return arrival time
176 */
177 template<class ...Args>
178 double getTime(const Args& ...args) const
179 {
181
182 const argument_type y = function.evaluate(buffer.data());
183
184 return transformer->getXn(buffer, y);
185 }
186
187
188 /**
189 * Read CDF from input.
190 *
191 * \param in reader
192 * \return reader
193 */
194 virtual JReader& read(JReader& in) override
195 {
196 in >> intensity;
197 in >> function;
198
200
201 if (buffer.read(in))
202 transformer.reset(buffer.clone());
203 else
205
206 compile();
207
208 intensity.setExceptionHandler(new typename JMultiQuantile_t::function_type::JDefaultResult(JMATH::zero));
209 function .setExceptionHandler(new typename JMultiFunction_t::function_type::JDefaultResult(JMATH::zero));
210
211 return in;
212 }
213
214
215 /**
216 * Write CDF to output.
217 *
218 * \param out writer
219 * \return writer
220 */
221 virtual JWriter& write(JWriter& out) const override
222 {
223 out << intensity;
224 out << function;
225
226 return transformer->write(out);
227 }
228
229
230 JMultiQuantile_t intensity; // integrated PDF
231 JMultiFunction_t function; // normalised CDF
232 std::shared_ptr<transformer_type> transformer;
233
234
235 protected:
236 /**
237 * Function compilation.
238 */
239 virtual void do_compile() override
240 {
242 function .compile();
243 }
244
245
246 /**
247 * Insert value at given multidimensional key.
248 *
249 * \param key multi-dimensional key
250 * \param value function or histogram
251 * \param eps minimal step size for method JTOOLS::makeCDF
252 */
253 template<class JValue_t>
254 void insert(const multikey_type& key,
255 const JValue_t& value,
256 const typename JValue_t::ordinate_type eps)
257 {
258 using namespace JPP;
259
260 try {
261
262 const typename transformer_type::array_type array(key);
263
264 JFunction1D_t buffer;
265
266 const argument_type z = transformer->getXn(array, 1.0) - transformer->getXn(array, 0.0);
267 const result_type V = makeCDF(value, buffer, eps);
268
270 function .insert(key, buffer);
271 }
272 catch(const JException& error) {
274 }
275 }
276
277
278 /**
279 * Insert multi-dimensional histogram at multi-dimensional key.
280 *
281 * \param key multidimensional key
282 * \param value multidimensional histogram
283 * \param eps minimal step size for CDF
284 */
285 template<unsigned int N,
286 class __JAbscissa_t,
287 class __JContents_t,
288 template<class, class, class> class __JMap_t,
289 class __JDistance_t>
292 const __JContents_t eps)
293 {
294 if (value.getSize() > 1) {
295
296 for (auto j = value.begin(), i = j++; j != value.end(); ++i, ++j) {
297
298 const __JAbscissa_t x = 0.5 * (i->first + j->first);
299
300 insert(JMultiKey<N+1, __JAbscissa_t>(key, x), i->second, eps);
301 }
302 }
303 }
304 };
305}
306
307#endif
Exceptions.
This include file contains various recursive methods to operate on multi-dimensional collections.
Definition of zero value for any class.
Interface for binary input.
Forward declaration of binary output.
Interface for binary output.
General exception.
Definition JException.hh:24
Multi-dimensional CDF table for arrival time of Cherenkov light.
Definition JCDFTable.hh:58
virtual JWriter & write(JWriter &out) const override
Write CDF to output.
Definition JCDFTable.hh:221
JTransformableMultiFunction< JFunction1D_t, JMaplist_t, JDistance_t > transformablemultifunction_t
Definition JCDFTable.hh:65
virtual void do_compile() override
Function compilation.
Definition JCDFTable.hh:239
void insert(const multikey_type &key, const JValue_t &value, const typename JValue_t::ordinate_type eps)
Insert value at given multidimensional key.
Definition JCDFTable.hh:254
void transform(const JFunctionTransformer_t &transformer)
Application of weight function.
Definition JCDFTable.hh:133
double getTime(const Args &...args) const
Generate arrival time.
Definition JCDFTable.hh:178
JCDFTable()
Default constructor.
Definition JCDFTable.hh:82
JTOOLS::JMultiFunction< JFunction1D_t, JMaplist_t, JDistance_t > JMultiFunction_t
Definition JCDFTable.hh:76
JCDFTable(const JTransformableMultiHistogram< JHistogram_t, __JMaplist_t, __JDistance_t > &input, const typename JHistogram_t::ordinate_type eps=JMATH::zero)
Constructor.
Definition JCDFTable.hh:115
JFunction1D_t::value_type value_type
Definition JCDFTable.hh:63
JFunction1D_t::result_type result_type
Definition JCDFTable.hh:62
transformablemultifunction_t::transformer_type transformer_type
Definition JCDFTable.hh:68
JTOOLS::JConstantFunction1D< double, argument_type > JConstantFunction1D_t
Definition JCDFTable.hh:74
void insert(const JMultiKey< N, argument_type > &key, const JHistogramMap< __JAbscissa_t, __JContents_t, __JMap_t, __JDistance_t > &value, const __JContents_t eps)
Insert multi-dimensional histogram at multi-dimensional key.
Definition JCDFTable.hh:290
virtual JReader & read(JReader &in) override
Read CDF from input.
Definition JCDFTable.hh:194
JFunction1D_t::argument_type argument_type
Definition JCDFTable.hh:61
transformablemultifunction_t::multimap_type multimap_type
Definition JCDFTable.hh:67
JMultiKey< NUMBER_OF_DIMENSIONS - 1, argument_type > multikey_type
Definition JCDFTable.hh:72
JMultiFunction_t function
Definition JCDFTable.hh:231
std::shared_ptr< transformer_type > transformer
Definition JCDFTable.hh:232
JTOOLS::JMultiFunction< JConstantFunction1D_t, JMaplist_t, JDistance_t > JMultiQuantile_t
Definition JCDFTable.hh:75
JMultiQuantile_t intensity
Definition JCDFTable.hh:230
JCDFTable(const JTransformableMultiFunction< __JFunction_t, __JMaplist_t, __JDistance_t > &input, const typename __JFunction_t::ordinate_type eps=JMATH::zero)
Constructor.
Definition JCDFTable.hh:94
double getNPE(const Args &...args) const
Get number of photo-electrons.
Definition JCDFTable.hh:160
Template definition of transformer of the probability density function (PDF) of the time response of ...
One dimensional array of template objects with fixed length.
Definition JArray.hh:43
const_pointer data() const
Get pointer to data.
Definition JArray.hh:295
Template implementation of function object in one dimension returning a constant value.
Template definition of function object interface.
Multidimensional interpolation method.
multimap_type::super_iterator super_iterator
void setExceptionHandler(const typename function_type::supervisor_type &supervisor)
Set the supervisor for handling of exceptions.
void compile()
Compilation.
void insert(const JMultiFunction< __JFunction_t, __JMaplist_t, __JDistance_t > &input)
Insert multidimensional input.
Multidimensional key.
Definition JMultiKey.hh:69
Interface for weight application and coordinate transformation of function.
static JMultiMapTransformer * getClone()
Get clone of default transformer.
Multidimensional map.
Definition JMultiMap.hh:52
Transformable multidimensional function.
std::shared_ptr< transformer_type > transformer
Transformable multidimensional histogram.
std::shared_ptr< transformer_type > transformer
static const JZero zero
Function object to assign zero value.
Definition JZero.hh:105
Auxiliary methods for light properties of deep-sea water.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary base class for storing and loading a single object to and from a binary file,...
Template class for distance evaluation.
Definition JDistance.hh:24