Jpp master_rocky-44-g75b7c4f75
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
6#include "JLang/JException.hh"
8#include "JMath/JZero.hh"
9#include "JTools/JArray.hh"
10#include "JTools/JMultiKey.hh"
18
19
20/**
21 * \author mdejong
22 */
23
24namespace JPHYSICS {}
25namespace JPP { using namespace JPHYSICS; }
26
27namespace JPHYSICS {
28
30 using JIO::JReader;
31 using JIO::JWriter;
39 using JTOOLS::JArray;
41
42
43 /**
44 * Multi-dimensional CDF table for arrival time of Cherenkov light.
45 * This class can be used to determine the number of photo-electrons as a function of
46 * the values of the leading parameter values and to generate random photon arrival times.
47 *
48 * N.B. The transformation of the PDF is assumed to be linear.
49 */
50 template<class JFunction1D_t,
51 class JMaplist_t,
53 class JCDFTable :
54 public JSerialisable,
55 public JObjectBinaryIO< JCDFTable<JFunction1D_t, JMaplist_t, JDistance_t> >,
56 public JFunctional<>
57 {
58 public:
59
60 typedef typename JFunction1D_t::argument_type argument_type;
61 typedef typename JFunction1D_t::result_type result_type;
62 typedef typename JFunction1D_t::value_type value_type;
63
65
68
70
72
76
77
78 /**
79 * Default constructor.
80 */
82 transformer(transformer_type::getClone())
83 {}
84
85
86 /**
87 * Constructor.
88 *
89 * \param input multi-dimensional PDF
90 * \param eps minimal step size for CDF
91 */
92 template<class __JFunction_t, class __JMaplist_t, class __JDistance_t>
94 const typename __JFunction_t::ordinate_type eps = JMATH::zero) :
95 transformer(transformer_type::getClone())
96 {
97 this->transformer.reset(input.transformer->clone());
98
99 for (auto i = input.super_begin(); i != input.super_end(); ++i) {
100 this->insert((*i).getKey(), (*i).getValue(), eps);
101 }
102
103 this->compile();
104 }
105
106
107 /**
108 * Constructor.
109 *
110 * \param input multi-dimensional histogram
111 * \param eps minimal step size for CDF
112 */
113 template<class JHistogram_t, class __JMaplist_t, class __JDistance_t>
115 const typename JHistogram_t::ordinate_type eps = JMATH::zero) :
116 transformer(transformer_type::getClone())
117 {
118 this->transformer.reset(input.transformer->clone());
119
120 this->insert(JMultiKey<0, typename JHistogram_t::abscissa_type>(), input, eps);
121
122 this->compile();
123 }
124
125
126 /**
127 * Application of weight function.
128 *
129 * \param transformer function transformer
130 */
131 template<class JFunctionTransformer_t>
132 void transform(const JFunctionTransformer_t& transformer)
133 {
134 for (typename JMultiQuantile_t::super_iterator i = intensity.super_begin(); i != intensity.super_end(); ++i) {
135
136 const typename transformer_type::array_type array = (*i).getKey();
137 JConstantFunction1D_t& function = (*i).getValue();
138
139 const double W1 = this->transformer->getWeight(array);
140 const double W2 = transformer .getWeight(array);
141
143
144 function = JConstantFunction1D_t(y * W1 / W2);
145 }
146
147 this->transformer.reset(transformer.clone());
148 this->compile();
149 }
150
151
152 /**
153 * Get number of photo-electrons.
154 *
155 * \param args comma separated argument list
156 * \return number of photo-electrons
157 */
158 template<class ...Args>
159 double getNPE(const Args& ...args) const
160 {
161 const JArray<NUMBER_OF_DIMENSIONS - 1, argument_type> buffer(args...);
162
163 const double W = transformer->getWeight(buffer);
164 const double npe = intensity.evaluate(buffer.data());
165
166 return W * npe;
167 }
168
169
170 /**
171 * Generate arrival time.
172 *
173 * \param args comma seperated argument list (last value is random number between 0 and 1)
174 * \return arrival time
175 */
176 template<class ...Args>
177 double getTime(const Args& ...args) const
178 {
180
181 const argument_type y = function.evaluate(buffer.data());
182
183 return transformer->getXn(buffer, y);
184 }
185
186
187 /**
188 * Read CDF from input.
189 *
190 * \param in reader
191 * \return reader
192 */
193 virtual JReader& read(JReader& in) override
194 {
195 in >> intensity;
196 in >> function;
197
199
200 if (buffer.read(in))
201 transformer.reset(buffer.clone());
202 else
204
205 compile();
206
207 intensity.setExceptionHandler(new typename JMultiQuantile_t::function_type::JDefaultResult(JMATH::zero));
208 function .setExceptionHandler(new typename JMultiFunction_t::function_type::JDefaultResult(JMATH::zero));
209
210 return in;
211 }
212
213
214 /**
215 * Write CDF to output.
216 *
217 * \param out writer
218 * \return writer
219 */
220 virtual JWriter& write(JWriter& out) const override
221 {
222 out << intensity;
223 out << function;
224
225 return transformer->write(out);
226 }
227
228
229 JMultiQuantile_t intensity; // integrated PDF
230 JMultiFunction_t function; // normalised CDF
232
233
234 protected:
235 /**
236 * Function compilation.
237 */
238 virtual void do_compile() override
239 {
241 function .compile();
242 }
243
244
245 /**
246 * Insert value at given multidimensional key.
247 *
248 * \param key multi-dimensional key
249 * \param value function or histogram
250 * \param eps minimal step size for method JTOOLS::makeCDF
251 */
252 template<class JValue_t>
253 void insert(const multikey_type& key,
254 const JValue_t& value,
255 const typename JValue_t::ordinate_type eps)
256 {
257 using namespace JPP;
258
259 try {
260
261 const typename transformer_type::array_type array(key);
262
263 JFunction1D_t buffer;
264
265 const argument_type z = transformer->getXn(array, 1.0) - transformer->getXn(array, 0.0);
266 const result_type V = makeCDF(value, buffer, eps);
267
269 function .insert(key, buffer);
270 }
271 catch(const JException& error) {
273 }
274 }
275
276
277 /**
278 * Insert multi-dimensional histogram at multi-dimensional key.
279 *
280 * \param key multidimensional key
281 * \param value multidimensional histogram
282 * \param eps minimal step size for CDF
283 */
284 template<unsigned int N,
285 class __JAbscissa_t,
286 class __JContents_t,
287 template<class, class, class> class __JMap_t,
288 class __JDistance_t>
291 const __JContents_t eps)
292 {
293 if (value.getSize() > 1) {
294
295 for (auto j = value.begin(), i = j++; j != value.end(); ++i, ++j) {
296
297 const __JAbscissa_t x = 0.5 * (i->first + j->first);
298
299 insert(JMultiKey<N+1, __JAbscissa_t>(key, x), i->second, eps);
300 }
301 }
302 }
303 };
304}
305
306#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
The template JSharedPointer class can be used to share a pointer to an object.
Multi-dimensional CDF table for arrival time of Cherenkov light.
Definition JCDFTable.hh:57
virtual JWriter & write(JWriter &out) const override
Write CDF to output.
Definition JCDFTable.hh:220
JTransformableMultiFunction< JFunction1D_t, JMaplist_t, JDistance_t > transformablemultifunction_t
Definition JCDFTable.hh:64
virtual void do_compile() override
Function compilation.
Definition JCDFTable.hh:238
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:253
void transform(const JFunctionTransformer_t &transformer)
Application of weight function.
Definition JCDFTable.hh:132
double getTime(const Args &...args) const
Generate arrival time.
Definition JCDFTable.hh:177
JLANG::JSharedPointer< transformer_type > transformer
Definition JCDFTable.hh:231
JCDFTable()
Default constructor.
Definition JCDFTable.hh:81
JTOOLS::JMultiFunction< JFunction1D_t, JMaplist_t, JDistance_t > JMultiFunction_t
Definition JCDFTable.hh:75
JCDFTable(const JTransformableMultiHistogram< JHistogram_t, __JMaplist_t, __JDistance_t > &input, const typename JHistogram_t::ordinate_type eps=JMATH::zero)
Constructor.
Definition JCDFTable.hh:114
JFunction1D_t::value_type value_type
Definition JCDFTable.hh:62
JFunction1D_t::result_type result_type
Definition JCDFTable.hh:61
transformablemultifunction_t::transformer_type transformer_type
Definition JCDFTable.hh:67
JTOOLS::JConstantFunction1D< double, argument_type > JConstantFunction1D_t
Definition JCDFTable.hh:73
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:289
virtual JReader & read(JReader &in) override
Read CDF from input.
Definition JCDFTable.hh:193
JFunction1D_t::argument_type argument_type
Definition JCDFTable.hh:60
transformablemultifunction_t::multimap_type multimap_type
Definition JCDFTable.hh:66
JMultiKey< NUMBER_OF_DIMENSIONS - 1, argument_type > multikey_type
Definition JCDFTable.hh:71
JMultiFunction_t function
Definition JCDFTable.hh:230
JTOOLS::JMultiFunction< JConstantFunction1D_t, JMaplist_t, JDistance_t > JMultiQuantile_t
Definition JCDFTable.hh:74
JMultiQuantile_t intensity
Definition JCDFTable.hh:229
JCDFTable(const JTransformableMultiFunction< __JFunction_t, __JMaplist_t, __JDistance_t > &input, const typename __JFunction_t::ordinate_type eps=JMATH::zero)
Constructor.
Definition JCDFTable.hh:93
double getNPE(const Args &...args) const
Get number of photo-electrons.
Definition JCDFTable.hh:159
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:284
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.
JLANG::JSharedPointer< transformer_type > transformer
Transformable multidimensional histogram.
JLANG::JSharedPointer< 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