Jpp  17.3.0-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JNPETable.hh
Go to the documentation of this file.
1 #ifndef __JPHYSICS__JNPETABLE__
2 #define __JPHYSICS__JNPETABLE__
3 
5 #include "JLang/JException.hh"
6 
10 #include "JTools/JToolsToolkit.hh"
11 
12 
13 /**
14  * \author mdejong
15  */
16 
17 namespace JPHYSICS {}
18 namespace JPP { using namespace JPHYSICS; }
19 
20 namespace JPHYSICS {
21 
23  using JTOOLS::JMapList;
27 
28 
29  /**
30  * Custom class for integrated values of the PDF of the arrival time of Cherenkov light.
31  *
32  * This class provides for the number of photo-electrons as a function
33  * of the leading <tt>(n - 1)</tt> parameter values.
34  */
35  template<class JArgument_t,
36  class JResult_t,
37  class JMaplist_t,
38  class JDistance_t = JTOOLS::JDistance<JArgument_t> >
39  class JNPETable :
40  public JMultiFunction<JConstantFunction1D<JArgument_t, JResult_t>,
41  JMaplist_t,
42  JDistance_t>
43  {
44  public:
45 
47  JMaplist_t,
48  JDistance_t> multifunction_t;
49 
51 
53  typedef typename multifunction_t::map_type map_type;
54 
57  typedef typename multifunction_t::supervisor_type supervisor_type;
58 
62 
67 
70 
72 
73 
74  /**
75  * Default constructor.
76  */
78  transformer(transformer_type::getClone())
79  {}
80 
81 
82  /**
83  * Constructor.
84  *
85  * \param input multi-dimensional PDF
86  */
87  template<class JPDF_t, class JPDFMaplist_t, class JPDFDistance_t>
89  transformer(transformer_type::getClone())
90  {
91  using namespace JTOOLS;
92 
93  typedef JTransformableMultiFunction<JPDF_t, JPDFMaplist_t, JPDFDistance_t> JTransformableMultiFunction_t;
94  typedef JMultiKey<JTransformableMultiFunction_t::NUMBER_OF_DIMENSIONS - 1, argument_type> JMultiKey_t;
95  typedef typename JTransformableMultiFunction_t::transformer_type transformer_type;
96 
97 
98  this->transformer.reset(input.transformer->clone());
99 
100  for (typename JTransformableMultiFunction_t::super_const_iterator i = input.super_begin(); i != input.super_end(); ++i) {
101 
102  const JMultiKey_t& key = (*i).getKey();
103  const JPDF_t& value = (*i).getValue();
104 
105  const typename transformer_type::array_type array(key);
106 
107  const double V = getIntegral(value);
108  const argument_type z = input.transformer->getXn(array, 1.0) - input.transformer->getXn(array, 0.0);
109 
110  this->insert(key, function_type(z*V));
111  }
112 
113  this->compile();
114  }
115 
116 
117  /**
118  * Add NPE table.
119  *
120  * Note that the summation is made via iteration of the elements in this multidimensional table.
121  *
122  * \param input NPE table
123  */
124  void add(const JNPETable& input)
125  {
126  using namespace JTOOLS;
127 
128  for (super_iterator i = this->super_begin(); i != this->super_end(); ++i) {
129 
130  map_type& f1 = (*i).getValue();
131 
132  for (typename map_type::iterator j = f1.begin(); j != f1.end(); ++j) {
133 
134  try {
135 
136  const JArray<NUMBER_OF_DIMENSIONS, argument_type> buffer((*i).getKey(), j->getX());
137 
138  const double npe = get_value(input.evaluate(buffer.data()));
139  const double W = this->transformer->getWeight(buffer);
140 
141  j->getY() += npe/W;
142  }
143  catch(JLANG::JException& error) {}
144  }
145  }
146  }
147 
148 
149  /**
150  * Get number of photo-electrons.
151  *
152  * \param args comma separated argument list
153  * \return number of photo-electrons
154  */
155  template<class ...Args>
156  result_type operator()(const Args& ...args) const
157  {
158  this->buffer.set(args...);
159 
160  return this->evaluate(this->buffer.data());
161  }
162 
163 
164  /**
165  * Recursive function value evaluation.
166  *
167  * \param pX pointer to abscissa values
168  * \return function value
169  */
170  virtual result_type evaluate(const argument_type* pX) const override
171  {
172  for (int i = 0; i != NUMBER_OF_DIMENSIONS; ++i) {
173  this->buffer[i] = pX[i];
174  }
175 
176  const double W = transformer->getWeight(buffer);
177  const result_type npe = multifunction_t::evaluate(buffer.data());
178 
179  return W * npe;
180  }
181 
182 
183  /**
184  * Application of weight function.
185  *
186  * \param transformer function transformer
187  */
189  {
190  using namespace JTOOLS;
191 
192  for (super_iterator i = this->super_begin(); i != this->super_end(); ++i) {
193 
194  map_type& f1 = (*i).getValue();
195 
196  for (typename map_type::iterator j = f1.begin(); j != f1.end(); ++j) {
197 
198  const JArray<NUMBER_OF_DIMENSIONS, argument_type> array((*i).getKey(), j->getX());
199 
200  j->getY() *= this->transformer->getWeight(array) / transformer.getWeight(array);
201  }
202  }
203 
204  this->transformer.reset(transformer.clone());
205  this->compile();
206  }
207 
208 
210 
211  protected:
213  };
214 }
215 
216 #endif
function_type::argument_type argument_type
void compile()
Compilation.
multifunction_t::value_type value_type
Definition: JNPETable.hh:55
General exception.
Definition: JException.hh:23
Exceptions.
multifunction_t::argument_type argument_type
Definition: JNPETable.hh:56
multimap_type::iterator iterator
multimap_type::super_iterator super_iterator
Transformable multidimensional function.
multimap_type::super_const_iterator super_const_iterator
multifunction_t::iterator iterator
Definition: JNPETable.hh:65
multifunction_t::supervisor_type supervisor_type
Definition: JNPETable.hh:57
Template class for distance evaluation.
Definition: JDistance.hh:24
multifunction_t::super_iterator super_iterator
Definition: JNPETable.hh:68
V(JDAQEvent-JTriggerReprocessor)*1.0/(JDAQEvent+1.0e-10)
JArray & set(const Args &...args)
Set array.
Definition: JArray.hh:199
void add(const JNPETable &input)
Add NPE table.
Definition: JNPETable.hh:124
multimap_type::reverse_iterator reverse_iterator
Multidimensional key.
Definition: JMultiKey.hh:34
const JPolynome f1(1.0, 2.0, 3.0)
Function.
virtual clone_type clone() const override
Get clone of this object.
Definition: JClonable.hh:69
multifunction_t::map_type map_type
Definition: JNPETable.hh:53
virtual result_type evaluate(const argument_type *pX) const override
Recursive function value evaluation.
Definition: JNPETable.hh:170
Template implementation of function object in one dimension returning a constant value.
function_type::value_type value_type
virtual double getWeight(const_array_type &buffer) const =0
Weight function.
The template JSharedPointer class can be used to share a pointer to an object.
Multidimensional interpolation method.
JConstantFunction1D< JArgument_t, JResult_t > function_type
Definition: JNPETable.hh:52
Map list.
Definition: JMapList.hh:24
multifunction_t::result_type result_type
Definition: JNPETable.hh:61
JMultiMapTransformer< NUMBER_OF_DIMENSIONS, argument_type > transformer_type
Definition: JNPETable.hh:71
void insert(const JMultiFunction< __JFunction_t, __JMaplist_t, __JDistance_t > &input)
Insert multidimensional input.
multimap_type::const_reverse_iterator const_reverse_iterator
multimap_type::ordinate_type ordinate_type
This include file contains various recursive methods to operate on multi-dimensional collections...
result_type operator()(const Args &...args) const
Get number of photo-electrons.
Definition: JNPETable.hh:156
JMultiFunction< JConstantFunction1D< JArgument_t, JResult_t >, JMaplist_t, JDistance_t > multifunction_t
Definition: JNPETable.hh:48
JTOOLS::JArray< NUMBER_OF_DIMENSIONS, argument_type > buffer
Definition: JNPETable.hh:212
JNPETable()
Default constructor.
Definition: JNPETable.hh:77
One dimensional array of template objects with fixed length.
Definition: JArray.hh:40
multifunction_t::super_const_iterator super_const_iterator
Definition: JNPETable.hh:69
JLANG::JSharedPointer< transformer_type > transformer
Definition: JNPETable.hh:209
multimap_type::result_type result_type
multimap_type::abscissa_type abscissa_type
multimap_type::const_iterator const_iterator
multifunction_t::ordinate_type ordinate_type
Definition: JNPETable.hh:60
multifunction_t::const_iterator const_iterator
Definition: JNPETable.hh:63
Interface for weight application and coordinate transformation of function.
JNPETable(const JTransformableMultiFunction< JPDF_t, JPDFMaplist_t, JPDFDistance_t > &input)
Constructor.
Definition: JNPETable.hh:88
int j
Definition: JPolint.hh:703
void transform(const transformer_type &transformer)
Application of weight function.
Definition: JNPETable.hh:188
multifunction_t::const_reverse_iterator const_reverse_iterator
Definition: JNPETable.hh:64
JLANG::JSharedPointer< transformer_type > transformer
multifunction_t::abscissa_type abscissa_type
Definition: JNPETable.hh:59
JResultEvaluator< JResult_t >::result_type get_value(const JResult_t &value)
Helper method to recursively evaluate a to function value.
Definition: JResult.hh:998
const_pointer data() const
Get pointer to data.
Definition: JArray.hh:284
JContainer_t::ordinate_type getIntegral(const JContainer_t &input)
Get integral of input data points.
Custom class for integrated values of the PDF of the arrival time of Cherenkov light.
Definition: JNPETable.hh:39
double getValue(const double x) const
Function value.
Definition: JPolynome.hh:233
multifunction_t::reverse_iterator reverse_iterator
Definition: JNPETable.hh:66