Jpp
JPDFTable.hh
Go to the documentation of this file.
1 #ifndef __JPHYSICS__JPDFTABLE__
2 #define __JPHYSICS__JPDFTABLE__
3 
4 #include <cmath>
5 
6 #include "JIO/JObjectBinaryIO.hh"
8 #include "JTools/JQuantiles.hh"
9 #include "JTools/JSet.hh"
10 #include "JTools/JRange.hh"
11 #include "JTools/JConstants.hh"
13 
14 
15 /**
16  * \author mdejong
17  */
18 
19 namespace JPHYSICS {}
20 namespace JPP { using namespace JPHYSICS; }
21 
22 namespace JPHYSICS {
23 
24  using JIO::JSerialisable;
25  using JIO::JReader;
26  using JIO::JWriter;
30  using JTOOLS::JRange;
31 
32 
33  /**
34  * Multi-dimensional PDF table for arrival time of Cherenkov light.
35  */
36  template<class JFunction1D_t,
37  class JMaplist_t,
39  class JPDFTable :
40  public JTransformableMultiFunction<JFunction1D_t, JMaplist_t, JDistance_t>,
41  public JSerialisable,
42  public JObjectBinaryIO< JPDFTable<JFunction1D_t, JMaplist_t, JDistance_t> >
43  {
44  public:
45 
47 
51 
54 
56 
60 
62 
63 
64  /**
65  * Default constructor.
66  */
69  {}
70 
71 
72  /**
73  * Constructor.
74  *
75  * \param input multi-dimensional function
76  */
77  template<class JPDF_t, class JPDFMaplist_t, class JPDFDistance_t>
80  {}
81 
82 
83  /**
84  * Constructor.
85  *
86  * \param input multi-dimensional histogram
87  */
88  template<class JHistogram1D_t, class JHistogramMaplist_t, class JHistogramDistance_t>
91  {}
92 
93 
94  /**
95  * Blur PDF.
96  *
97  * The arrival times of Cherenkov light are smeared according to a Gaussian distribution
98  * with the specified width (i.e. TTS) using Gauss-Hermite integration.
99  * An exception is made when the time range according the specified quantile is
100  * smaller than the specified width (TTS) of the Gaussian distribution.
101  * In that case, the resulting PDF is a Gaussian distribution with the specified width (TTS)
102  * and normalisation according to the integral value of the input PDF.
103  * A smooth transition is imposed between the normal regime and this exeption.
104  *
105  * \param TTS TTS [ns]
106  * \param numberOfPoints number of points for Gauss-Hermite integration
107  * \param epsilon precision
108  * \param quantile quantile
109  */
110  void blur(const double TTS,
111  const int numberOfPoints = 25,
112  const double epsilon = 1.0e-10,
113  const double quantile = 0.99)
114  {
115  using namespace std;
116  using namespace JTOOLS;
117 
118  typedef typename transformer_type::array_type array_type;
119 
120  const JGaussHermite engine(numberOfPoints, epsilon);
121 
122  for (super_iterator i = this->super_begin(); i != this->super_end(); ++i) {
123 
124  const array_type array = (*i).getKey();
125  function_type& f1 = (*i).getValue();
126 
127  if (!f1.empty()) {
128 
129  const typename function_type::supervisor_type& supervisor = f1.getSupervisor();
130 
132  const JMultiMapPutTransformer<NUMBER_OF_DIMENSIONS - 1, value_type> put(*(this->transformer), array);
133 
134  f1.transform(get);
135  f1.compile();
136 
137  const JQuantiles Q(f1, quantile);
138 
139  // abscissa
140 
141  JSet<double> X;
142 
143  for (JGaussHermite::const_iterator j = engine.begin(); j != engine.end(); ++j) {
144  X.insert(Q.getX() + TTS*sqrt(2.0)*j->getX());
145  }
146 
147  for (typename function_type::const_iterator j = f1.begin(); j != f1.end(); ++j) {
148 
149  if (j->getX() - TTS < X.getXmin()) {
150  X.insert(j->getX() - TTS);
151  }
152 
153  if (j->getX() + TTS > X.getXmax()) {
154  X.insert(j->getX() + TTS);
155  }
156  }
157 
158 
159  const double W = gauss(Q.getUpperLimit() - Q.getLowerLimit(), TTS);
160 
162 
163  for (JSet<double>::const_iterator x = X.begin(); x != X.end(); ++x) {
164 
165  double y = 0.0;
166 
167  for (JGaussHermite::const_iterator j = engine.begin(); j != engine.end(); ++j) {
168 
169  const double u = j->getX();
170  const double v = j->getY() / sqrt(PI);
171  const double w = get_value(f1(*x + u*TTS*sqrt(2.0)));
172 
173  y += v * w;
174  }
175 
176  buffer[*x] = W * Q.getIntegral() * Gauss(*x - Q.getX(), TTS) + (1.0 - W) * y;
177  }
178 
179  buffer.transform(put);
180  buffer.compile();
181 
182  f1 = buffer;
183 
184  f1.setExceptionHandler(supervisor);
185  }
186  }
187  }
188 
189  /**
190  * Compresses PDF to abscissa range specified by Crange
191  *
192  * \param Crange Compression Range [PDF abscissa_type]
193  */
195  {
196 
197  for (super_iterator pdf_it=this->super_begin(); pdf_it!=this->super_end(); ++pdf_it) {
198  function_type& f1 = pdf_it.getValue();
199 
200  typename function_type::iterator f1_newB = f1.lower_bound(Crange.getLowerLimit());
201  f1.function_type::container_type::erase(f1.begin(),f1_newB);
202  typename function_type::iterator f1_newE = f1.lower_bound(Crange.getUpperLimit());
203  f1.function_type::container_type::erase(++f1_newE,f1.end());
204  }
205 
206  }
207 
208  /**
209  * Read from input.
210  *
211  * \param in reader
212  * \return reader
213  */
214  virtual JReader& read(JReader& in)
215  {
216  if (in >> static_cast<transformablemultifunction_t&>(*this)) {
217 
218  // read optional transformer
219 
221 
222  if (buffer.read(in)) {
223 
224  this->transformer.reset(buffer.clone());
225 
226  } else {
227 
228  in.clear();
229 
231  }
232  }
233 
234  this->compile();
235 
236  return in;
237  }
238 
239 
240  /**
241  * Write from input.
242  *
243  * \param out writer
244  * \return writer
245  */
246  virtual JWriter& write(JWriter& out) const
247  {
248  out << static_cast<const transformablemultifunction_t&>(*this);
249 
250  this->transformer->write(out);
251 
252  return out;
253  }
254 
255  protected:
256  /**
257  * Gauss function (normalised to 1 at x = 0).
258  *
259  * \param x x
260  * \param sigma sigma
261  * \return function value
262  */
263  static double gauss(const double x, const double sigma)
264  {
265  const double u = x / sigma;
266 
267  if (fabs(u) < 10.0)
268  return exp(-0.5*u*u);
269  else
270  return 0.0;
271  }
272 
273 
274  /**
275  * Normalised Gauss function.
276  *
277  * \param x x
278  * \param sigma sigma
279  * \return function value
280  */
281  static double Gauss(const double x, const double sigma)
282  {
283  return gauss(x, sigma) / sqrt(2.0*JTOOLS::PI) / sigma;
284  }
285 
286 
287  /**
288  * Normalised Gauss function.
289  *
290  * \param x x
291  * \param x0 central value
292  * \param sigma sigma
293  * \return function value
294  */
295  static double Gauss(const double x, const double x0, const double sigma)
296  {
297  return Gauss(x - x0, sigma);
298  }
299  };
300 }
301 
302 #endif
JIO::JReader::clear
virtual void clear()
Clear status of reader.
Definition: JSerialisable.hh:70
JPHYSICS::JPDFTable::compress
void compress(const JRange< typename function_type::abscissa_type > &Crange)
Compresses PDF to abscissa range specified by Crange.
Definition: JPDFTable.hh:194
JTOOLS::JMultiMap
Multidimensional map.
Definition: JMultiMap.hh:46
JTOOLS::JMultiMapGetTransformer
Auxiliary class to convert JMultiMapTransformer to JCollectionElementTransformer.
Definition: JMultiMapTransformer.hh:291
JTOOLS::JRange::getLowerLimit
T getLowerLimit() const
Get lower limit.
Definition: JRange.hh:215
JIO::JReader
Interface for binary input.
Definition: JSerialisable.hh:62
JPHYSICS::JPDFTable::multimap_type
transformablemultifunction_t::multimap_type multimap_type
Definition: JPDFTable.hh:52
JPHYSICS::JPDFTable::transformablemultifunction_t
JTransformableMultiFunction< JFunction1D_t, JMaplist_t, JDistance_t > transformablemultifunction_t
Definition: JPDFTable.hh:46
JTOOLS::JRange::getUpperLimit
T getUpperLimit() const
Get upper limit.
Definition: JRange.hh:226
JTOOLS::w
data_type w[N+1][M+1]
Definition: JPolint.hh:708
JPHYSICS::JPDFTable::blur
void blur(const double TTS, const int numberOfPoints=25, const double epsilon=1.0e-10, const double quantile=0.99)
Blur PDF.
Definition: JPDFTable.hh:110
JTOOLS::JTransformableMultiFunction
Transformable multidimensional function.
Definition: JTransformableMultiFunction.hh:38
JTOOLS::JMultiFunction::function_type
JFunction_t function_type
Definition: JMultiFunction.hh:52
JTOOLS::JGaussHermite
Numerical integrator for W(x) = e^-(x^2).
Definition: JQuadrature.hh:253
JPHYSICS::JPDFTable::Gauss
static double Gauss(const double x, const double sigma)
Normalised Gauss function.
Definition: JPDFTable.hh:281
JPHYSICS::JPDFTable::transformer_type
transformablemultifunction_t::transformer_type transformer_type
Definition: JPDFTable.hh:53
JIO::JSerialisable
Forward declaration of binary output.
Definition: JSerialisable.hh:31
JTOOLS::JTransformableMultiFunction::NUMBER_OF_DIMENSIONS
Definition: JTransformableMultiFunction.hh:48
numberOfPoints
int numberOfPoints
Definition: JResultPDF.cc:22
JPHYSICS::JPDFTable::function_type
transformablemultifunction_t::function_type function_type
Definition: JPDFTable.hh:59
JPHYSICS::JPDFTable::write
virtual JWriter & write(JWriter &out) const
Write from input.
Definition: JPDFTable.hh:246
JTOOLS::u
double u[N+1]
Definition: JPolint.hh:706
JTOOLS::JArray< N, argument_type >
JTOOLS::JRange
Range of values.
Definition: JRange.hh:34
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
JPHYSICS::JPDFTable::super_iterator
transformablemultifunction_t::super_iterator super_iterator
Definition: JPDFTable.hh:58
JTransformableMultiFunction.hh
JIO::JObjectBinaryIO
Auxiliary base class for storing and loading a single object to and from a binary file,...
Definition: JObjectBinaryIO.hh:23
JTOOLS::JMultiMapTransformer::getClone
static JMultiMapTransformer * getClone()
Get clone of default transformer.
Definition: JMultiMapTransformer.hh:124
JPHYSICS::JPDFTransformer
Template definition of transformer of the Probability Density Functions of the time response of a PMT...
Definition: JPDFTransformer.hh:33
JPHYSICS::JPDFTable::gauss
static double gauss(const double x, const double sigma)
Gauss function (normalised to 1 at x = 0).
Definition: JPDFTable.hh:263
JPDFTransformer.hh
JTOOLS::get_value
JResultEvaluator< JResult_t >::result_type get_value(const JResult_t &value)
Helper method to recursively evaluate a to function value.
Definition: JResult.hh:936
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JTOOLS::JSet::getXmin
virtual abscissa_type getXmin() const
Get minimal abscissa value.
Definition: JSet.hh:103
JTOOLS::JTransformableMultiFunction::array_type
transformer_type::array_type array_type
Definition: JTransformableMultiFunction.hh:69
JTOOLS::JQuantiles::getIntegral
double getIntegral() const
Get integral of function.
Definition: JQuantiles.hh:346
JRange.hh
JTOOLS::JMultiFunction::super_iterator
multimap_type::super_iterator super_iterator
Definition: JMultiFunction.hh:67
JTOOLS::JTransformableMultiFunction< JFunction1D_t, JPDFMaplist_t, JTOOLS::JDistance< typename JFunction1D_t::argument_type > >::super_iterator
multifunction_type::super_iterator super_iterator
Definition: JTransformableMultiFunction.hh:65
JTOOLS::JMultiFunction::buffer
JArray< NUMBER_OF_DIMENSIONS, argument_type > buffer
Definition: JMultiFunction.hh:236
JConstants.hh
JTOOLS::JTransformableMultiFunction< JFunction1D_t, JPDFMaplist_t, JTOOLS::JDistance< typename JFunction1D_t::argument_type > >::value_type
multifunction_type::value_type value_type
Definition: JTransformableMultiFunction.hh:52
JTOOLS::JMultiMapTransformer
Interface for weight application and coordinate transformation of function.
Definition: JMultiMapTransformer.hh:35
JIO::JWriter
Interface for binary output.
Definition: JSerialisable.hh:130
JTOOLS::JMultiMapPutTransformer
Auxiliary class to convert JMultiMapTransformer to JCollectionElementTransformer.
Definition: JMultiMapTransformer.hh:240
JTOOLS::JMultiFunction::value_type
JFunction_t::value_type value_type
Definition: JMultiFunction.hh:54
JPHYSICS::JPDFTable::NUMBER_OF_DIMENSIONS
Definition: JPDFTable.hh:55
JTOOLS::JMultiFunction::argument_type
JFunction_t::argument_type argument_type
Definition: JMultiFunction.hh:55
JPHYSICS::JPDFTable
Multi-dimensional PDF table for arrival time of Cherenkov light.
Definition: JPDFTable.hh:39
JTOOLS::JTransformableMultiFunction< JFunction1D_t, JPDFMaplist_t, JTOOLS::JDistance< typename JFunction1D_t::argument_type > >::super_const_iterator
multifunction_type::super_const_iterator super_const_iterator
Definition: JTransformableMultiFunction.hh:66
JQuantiles.hh
JTOOLS::JTransformableMultiFunction::transformer
JLANG::JSharedPointer< transformer_type > transformer
Definition: JTransformableMultiFunction.hh:279
JPHYSICS::JPDFTable::JPDFTable
JPDFTable(const JTransformableMultiFunction< JPDF_t, JPDFMaplist_t, JPDFDistance_t > &input)
Constructor.
Definition: JPDFTable.hh:78
JTOOLS::v
data_type v[N+1][M+1]
Definition: JPolint.hh:707
JTOOLS::JSet::getXmax
virtual abscissa_type getXmax() const
Get maximal abscissa value.
Definition: JSet.hh:114
JPHYSICS::JPDFTable::JPDFTable
JPDFTable()
Default constructor.
Definition: JPDFTable.hh:67
JPHYSICS::JPDFTable::value_type
transformablemultifunction_t::value_type value_type
Definition: JPDFTable.hh:50
JObjectBinaryIO.hh
JTOOLS::JSet
Simple data structure for an abstract collection of non-equidistant abscissa values.
Definition: JSet.hh:29
JPHYSICS::JPDFTable::Gauss
static double Gauss(const double x, const double x0, const double sigma)
Normalised Gauss function.
Definition: JPDFTable.hh:295
JTOOLS::JMultiFunction::compile
void compile()
Compilation.
Definition: JMultiFunction.hh:143
std
Definition: jaanetDictionary.h:36
JTOOLS::PI
static const double PI
Constants.
Definition: JConstants.hh:20
JTOOLS::JTransformableMultiHistogram
Transformable multidimensional histogram.
Definition: JTransformableMultiHistogram.hh:37
JTOOLS::JDistance
Template class for distance evaluation.
Definition: JDistance.hh:24
JTOOLS::JQuantiles::getX
double getX() const
Get position of maximum.
Definition: JQuantiles.hh:313
JTOOLS::JQuantiles
Quantile calculator for a given function.
Definition: JQuantiles.hh:106
JTOOLS::JTransformableMultiFunction< JFunction1D_t, JPDFMaplist_t, JTOOLS::JDistance< typename JFunction1D_t::argument_type > >::result_type
multifunction_type::result_type result_type
Definition: JTransformableMultiFunction.hh:58
JPHYSICS::JPDFTable::read
virtual JReader & read(JReader &in)
Read from input.
Definition: JPDFTable.hh:214
JSet.hh
JPHYSICS::JPDFTable::argument_type
transformablemultifunction_t::argument_type argument_type
Definition: JPDFTable.hh:48
JPHYSICS::JPDFTable::JPDFTable
JPDFTable(const JTransformableMultiHistogram< JHistogram1D_t, JHistogramMaplist_t, JHistogramDistance_t > &input)
Constructor.
Definition: JPDFTable.hh:89
JAANET::get
T get(const JHead &header)
Get object from header.
Definition: JHeadToolkit.hh:295
JTOOLS
Auxiliary classes and methods for multi-dimensional interpolations and histograms.
Definition: JAbstractCollection.hh:9
JPHYSICS::JPDFTable::result_type
transformablemultifunction_t::result_type result_type
Definition: JPDFTable.hh:49
JTOOLS::JCollection< JElement2D_t >::const_iterator
container_type::const_iterator const_iterator
Definition: JCollection.hh:89
JTOOLS::JTransformableMultiFunction::insert
void insert(const JTransformableMultiFunction< JPDF_t, JPDFMaplist_t, JPDFDistance_t > &input)
Insert multidimensional input.
Definition: JTransformableMultiFunction.hh:124
JPHYSICS::JPDFTable::super_const_iterator
transformablemultifunction_t::super_const_iterator super_const_iterator
Definition: JPDFTable.hh:57
JTOOLS::JTransformableMultiFunction< JFunction1D_t, JPDFMaplist_t, JTOOLS::JDistance< typename JFunction1D_t::argument_type > >::function_type
JFunction1D_t function_type
Definition: JTransformableMultiFunction.hh:50
JTOOLS::JTransformableMultiFunction< JFunction1D_t, JPDFMaplist_t, JTOOLS::JDistance< typename JFunction1D_t::argument_type > >::argument_type
multifunction_type::argument_type argument_type
Definition: JTransformableMultiFunction.hh:53