Jpp
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;
26 
27 
28  /**
29  * Custom class for integrated values of the PDF of the arrival time of Cherenkov light.
30  *
31  * This class provides for the number of photo-electrons as a function
32  * of the leading <tt>(n - 1)</tt> parameter values.
33  */
34  template<class JArgument_t,
35  class JResult_t,
36  class JMaplist_t,
37  class JDistance_t = JTOOLS::JDistance<JArgument_t> >
38  class JNPETable :
39  public JMultiFunction<JConstantFunction1D<JArgument_t, JResult_t>,
40  JMaplist_t,
41  JDistance_t>
42  {
43  public:
44 
46  JMaplist_t,
47  JDistance_t> multifunction_t;
48 
50 
52  typedef typename multifunction_t::map_type map_type;
53 
57 
61 
66 
69 
71 
72 
73  /**
74  * Default constructor.
75  */
77  transformer(transformer_type::getClone())
78  {}
79 
80 
81  /**
82  * Constructor.
83  *
84  * \param input multi-dimensional PDF
85  */
86  template<class JPDF_t, class JPDFMaplist_t, class JPDFDistance_t>
88  transformer(transformer_type::getClone())
89  {
90  using namespace JTOOLS;
91 
92  typedef JTransformableMultiFunction<JPDF_t, JPDFMaplist_t, JPDFDistance_t> JTransformableMultiFunction_t;
93  typedef JMultiKey<JTransformableMultiFunction_t::NUMBER_OF_DIMENSIONS - 1, argument_type> JMultiKey_t;
94  typedef typename JTransformableMultiFunction_t::transformer_type transformer_type;
95 
96 
97  this->transformer.reset(input.transformer->clone());
98 
99  for (typename JTransformableMultiFunction_t::super_const_iterator i = input.super_begin(); i != input.super_end(); ++i) {
100 
101  const JMultiKey_t& key = (*i).getKey();
102  const JPDF_t& value = (*i).getValue();
103 
104  const typename transformer_type::array_type array(key);
105 
106  const double V = getIntegral(value);
107  const argument_type z = input.transformer->getXn(array, 1.0) - input.transformer->getXn(array, 0.0);
108 
109  this->insert(key, function_type(z*V));
110  }
111 
112  this->compile();
113  }
114 
115 
116  /**
117  * Add NPE table.
118  *
119  * Note that the summation is made via iteration of the elements in this multidimensional table.
120  *
121  * \param input NPE table
122  */
123  void add(const JNPETable& input)
124  {
125  using namespace JTOOLS;
126 
127  for (super_iterator i = this->super_begin(); i != this->super_end(); ++i) {
128 
129  map_type& f1 = (*i).getValue();
130 
131  for (typename map_type::iterator j = f1.begin(); j != f1.end(); ++j) {
132 
133  try {
134 
135  const JArray<NUMBER_OF_DIMENSIONS, argument_type> buffer((*i).getKey(), j->getX());
136 
137  const double npe = input.evaluate(buffer.data());
138  const double W = this->transformer->getWeight(buffer);
139 
140  j->getY() += npe/W;
141  }
142  catch(JLANG::JException& error) {}
143  }
144  }
145  }
146 
147 
148  /**
149  * Get number of photo-electrons.
150  *
151  * \param x comma separated argument list
152  * \return number of photo-electrons
153  */
155  {
156  va_start(ap, x);
157 
158  buffer[0] = x;
159 
160  for (int i = 1; i != NUMBER_OF_DIMENSIONS; ++i) {
161  buffer[i] = va_arg(ap, argument_type);
162  }
163 
164  va_end(ap);
165 
166  return this->evaluate(this->buffer.data());
167  }
168 
169 
170  /**
171  * Recursive function value evaluation.
172  *
173  * \param pX pointer to abscissa values
174  * \return function value
175  */
176  virtual result_type evaluate(const argument_type* pX) const
177  {
178  for (int i = 0; i != NUMBER_OF_DIMENSIONS; ++i) {
179  this->buffer[i] = pX[i];
180  }
181 
182  const double W = transformer->getWeight(buffer);
183  const result_type npe = multifunction_t::evaluate(buffer.begin());
184 
185  return W * npe;
186  }
187 
188 
189  /**
190  * Application of weight function.
191  *
192  * \param transformer function transformer
193  */
195  {
196  using namespace JTOOLS;
197 
198  for (super_iterator i = this->super_begin(); i != this->super_end(); ++i) {
199 
200  map_type& f1 = (*i).getValue();
201 
202  for (typename map_type::iterator j = f1.begin(); j != f1.end(); ++j) {
203 
204  const JArray<NUMBER_OF_DIMENSIONS, argument_type> array((*i).getKey(), j->getX());
205 
206  j->getY() *= this->transformer->getWeight(array) / transformer.getWeight(array);
207  }
208  }
209 
210  this->transformer.reset(transformer.clone());
211  this->compile();
212  }
213 
214 
216 
217  protected:
218  mutable va_list ap;
220  };
221 }
222 
223 #endif
JException.hh
JPHYSICS::JNPETable::abscissa_type
multifunction_t::abscissa_type abscissa_type
Definition: JNPETable.hh:58
JPHYSICS::JNPETable::const_reverse_iterator
multifunction_t::const_reverse_iterator const_reverse_iterator
Definition: JNPETable.hh:63
JPHYSICS::JNPETable::multifunction_t
JMultiFunction< JConstantFunction1D< JArgument_t, JResult_t >, JMaplist_t, JDistance_t > multifunction_t
Definition: JNPETable.hh:47
JTOOLS::JArray::begin
const_iterator begin() const
get iterator to begin of data
Definition: JArray.hh:188
JTOOLS::pX
pX
Definition: JPolint.hh:625
JPHYSICS::JNPETable::supervisor_type
multifunction_t::supervisor_type supervisor_type
Definition: JNPETable.hh:56
JTOOLS::JTransformableMultiFunction
Transformable multidimensional function.
Definition: JTransformableMultiFunction.hh:38
JTOOLS::JConstantFunction1D
Template implementation of function object in one dimension returning a constant value.
Definition: JConstantFunction1D.hh:26
JTOOLS::JMultiFunction::super_const_iterator
multimap_type::super_const_iterator super_const_iterator
Definition: JMultiFunction.hh:68
JPHYSICS::JNPETable::result_type
multifunction_t::result_type result_type
Definition: JNPETable.hh:60
JPHYSICS::JNPETable::evaluate
virtual result_type evaluate(const argument_type *pX) const
Recursive function value evaluation.
Definition: JNPETable.hh:176
JPHYSICS::JNPETable::map_type
multifunction_t::map_type map_type
Definition: JNPETable.hh:52
JTOOLS::JMultiFunction::ordinate_type
multimap_type::ordinate_type ordinate_type
Definition: JMultiFunction.hh:59
JPHYSICS::JNPETable::const_iterator
multifunction_t::const_iterator const_iterator
Definition: JNPETable.hh:62
JSharedPointer.hh
JTOOLS::JArray< N, argument_type >
JPHYSICS
Auxiliary classes and methods for calculation of PDF and muon energy loss.
Definition: JAbstractMedium.hh:9
JTOOLS::j
int j
Definition: JPolint.hh:634
JTransformableMultiFunction.hh
JPHYSICS::JNPETable::transformer_type
JMultiMapTransformer< NUMBER_OF_DIMENSIONS, argument_type > transformer_type
Definition: JNPETable.hh:70
JPHYSICS::JNPETable::ap
va_list ap
Definition: JNPETable.hh:218
JTOOLS::JArray::data
const_pointer data() const
Get pointer to data.
Definition: JArray.hh:263
JPHYSICS::JNPETable
Custom class for integrated values of the PDF of the arrival time of Cherenkov light.
Definition: JNPETable.hh:38
JTOOLS::JMapList
Map list.
Definition: JMapList.hh:24
JPHYSICS::JNPETable::super_const_iterator
multifunction_t::super_const_iterator super_const_iterator
Definition: JNPETable.hh:68
JTOOLS::getIntegral
JContainer_t::ordinate_type getIntegral(const JContainer_t &input)
Get integral of input data points.
Definition: JToolsToolkit.hh:133
JPHYSICS::JNPETable::reverse_iterator
multifunction_t::reverse_iterator reverse_iterator
Definition: JNPETable.hh:65
JConstantFunction1D.hh
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JTOOLS::JMultiFunction::const_reverse_iterator
multimap_type::const_reverse_iterator const_reverse_iterator
Definition: JMultiFunction.hh:63
JPHYSICS::JNPETable::JNPETable
JNPETable(const JTransformableMultiFunction< JPDF_t, JPDFMaplist_t, JPDFDistance_t > &input)
Constructor.
Definition: JNPETable.hh:87
JTOOLS::JMultiFunction::super_iterator
multimap_type::super_iterator super_iterator
Definition: JMultiFunction.hh:67
JPHYSICS::JNPETable::transform
virtual void transform(const transformer_type &transformer)
Application of weight function.
Definition: JNPETable.hh:194
JPHYSICS::JNPETable::value_type
multifunction_t::value_type value_type
Definition: JNPETable.hh:54
JTOOLS::JMultiFunction::const_iterator
multimap_type::const_iterator const_iterator
Definition: JMultiFunction.hh:62
JToolsToolkit.hh
JTOOLS::JMultiMapTransformer
Interface for weight application and coordinate transformation of function.
Definition: JMultiMapTransformer.hh:35
JPHYSICS::JNPETable::argument_type
multifunction_t::argument_type argument_type
Definition: JNPETable.hh:55
JTOOLS::JMultiFunction::value_type
JFunction_t::value_type value_type
Definition: JMultiFunction.hh:54
JTOOLS::JMultiFunction::argument_type
JFunction_t::argument_type argument_type
Definition: JMultiFunction.hh:55
JPHYSICS::JNPETable::super_iterator
multifunction_t::super_iterator super_iterator
Definition: JNPETable.hh:67
JTOOLS::JMultiFunction::NUMBER_OF_DIMENSIONS
Definition: JMultiFunction.hh:50
JTOOLS::JMultiMapTransformer::getWeight
virtual double getWeight(const_array_type &buffer) const =0
Weight function.
JTOOLS::JMultiFunction::iterator
multimap_type::iterator iterator
Definition: JMultiFunction.hh:64
JTOOLS::JTransformableMultiFunction::transformer
JLANG::JSharedPointer< transformer_type > transformer
Definition: JTransformableMultiFunction.hh:279
JPHYSICS::JNPETable::JNPETable
JNPETable()
Default constructor.
Definition: JNPETable.hh:76
JPHYSICS::JNPETable::function_type
JConstantFunction1D< JArgument_t, JResult_t > function_type
Definition: JNPETable.hh:51
JMultiFunction.hh
JTOOLS::JMultiFunction::compile
void compile()
Compilation.
Definition: JMultiFunction.hh:143
JTOOLS::JMultiKey
Forward declaration of template JMultiKey class.
Definition: JMultiKey.hh:29
JPHYSICS::JNPETable::ordinate_type
multifunction_t::ordinate_type ordinate_type
Definition: JNPETable.hh:59
JTOOLS::JMultiFunction::abscissa_type
multimap_type::abscissa_type abscissa_type
Definition: JMultiFunction.hh:58
JPHYSICS::JNPETable::add
void add(const JNPETable &input)
Add NPE table.
Definition: JNPETable.hh:123
JTOOLS::JMultiFunction::result_type
multimap_type::result_type result_type
Definition: JMultiFunction.hh:60
JTOOLS::JDistance
Template class for distance evaluation.
Definition: JDistance.hh:24
JTOOLS::JMultiFunction::insert
void insert(const JMultiFunction< JPDF_t, JPDFMaplist_t, JPDFDistance_t > &input)
Insert multidimensional input.
Definition: JMultiFunction.hh:122
JTOOLS::JMultiFunction::supervisor_type
JFunction_t::supervisor_type supervisor_type
Definition: JMultiFunction.hh:56
JTOOLS
Auxiliary classes and methods for multi-dimensional interpolations and histograms.
Definition: JAbstractCollection.hh:9
JTOOLS::JMultiFunction
Multidimensional interpolation method.
Definition: JMultiFunction.hh:40
JLANG::JException
General exception.
Definition: JException.hh:23
JPHYSICS::JNPETable::iterator
multifunction_t::iterator iterator
Definition: JNPETable.hh:64
JPHYSICS::JNPETable::transformer
JLANG::JSharedPointer< transformer_type > transformer
Definition: JNPETable.hh:215
JLANG::JSharedPointer
The template JSharedPointer class can be used to share a pointer to an object.
Definition: JSharedPointer.hh:28
JPHYSICS::JNPETable::buffer
JTOOLS::JArray< NUMBER_OF_DIMENSIONS, argument_type > buffer
Definition: JNPETable.hh:219
JPHYSICS::JNPETable::operator()
result_type operator()(const argument_type x,...) const
Get number of photo-electrons.
Definition: JNPETable.hh:154
JTOOLS::JMultiFunction::reverse_iterator
multimap_type::reverse_iterator reverse_iterator
Definition: JMultiFunction.hh:65