npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
InterpolatedDistro1D1P.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_INTERPOLATEDDISTRO1D1P_HH_
2 #define NPSTAT_INTERPOLATEDDISTRO1D1P_HH_
3 
4 /*!
5 // \file InterpolatedDistro1D1P.hh
6 //
7 // \brief Interpolation of 1-d distributions as a function of one parameter
8 //
9 // Author: I. Volobouev
10 //
11 // December 2014
12 */
13 
14 #include "geners/CPP11_shared_ptr.hh"
15 
16 #include "npstat/nm/GridAxis.hh"
18 
19 namespace npstat {
21  {
22  public:
23 #ifndef SWIGBUG
24  /**
25  // This constructor builds an object which is ready to use.
26  // The "distros" argument must provide one distribution for
27  // each grid cell.
28  */
30  const GridAxis& axis,
31  const std::vector<CPP11_shared_ptr<const AbsDistribution1D> >& distros,
32  double initialParameterValue = 0.0, bool interpolateVertically = false);
33 #endif // SWIGBUG
34 
35  /**
36  // If this constructor is used, the object must be built incrementally,
37  // using "setGridDistro" calls, one call for each grid cell. After all
38  // distributions have been set, provide the parameter value with
39  // "setParameter". Only then one can call methods "density", etc.
40  */
41  explicit InterpolatedDistro1D1P(const GridAxis& axis,
42  bool interpolateVertically = false);
43 
44  inline virtual ~InterpolatedDistro1D1P() {delete interpolator_;}
45 
48 
49  /** Set the distribution corresponding to the given grid point */
50  void setGridDistro(unsigned cell, const AbsDistribution1D& distro);
51 
52  /** Set the value of the parameter */
53  void setParameter(double value);
54 
55  /** Get the value of the parameter */
56  inline double getParameter() const {checkReady(); return param_;}
57 
58  inline const GridAxis& getAxis() const {return axis_;}
59  inline unsigned nDistros() const {return axis_.nCoords();}
60 
61  void interpolateVertically(bool b);
62  inline bool interpolatingVertically() const {return vertical_;}
63 
64  /** "Virtual copy constructor" */
65  inline virtual InterpolatedDistro1D1P* clone() const
66  {return new InterpolatedDistro1D1P(*this);}
67 
68  inline double density(const double x) const
69  {checkReady(); return interpolator_->density(x);}
70  inline double cdf(const double x) const
71  {checkReady(); return interpolator_->cdf(x);}
72  inline double exceedance(const double x) const
73  {checkReady(); return interpolator_->exceedance(x);}
74  inline double quantile(const double x) const
75  {checkReady(); return interpolator_->quantile(x);}
76 
77  //@{
78  /** Prototype needed for I/O */
79  virtual inline gs::ClassId classId() const {return gs::ClassId(*this);}
80  virtual bool write(std::ostream&) const;
81  //@}
82 
83  static inline const char* classname()
84  {return "npstat::InterpolatedDistro1D1P";}
85  static inline unsigned version() {return 2;}
86  static InterpolatedDistro1D1P* read(const gs::ClassId& id,
87  std::istream& in);
88  protected:
89  virtual bool isEqual(const AbsDistribution1D&) const;
90 
91  private:
93 
94  void rebuildInterpolator();
95  void checkDistros();
96  void checkReady() const;
97 
98  GridAxis axis_;
99  std::vector<CPP11_shared_ptr<const AbsDistribution1D> > distros_;
100  AbsInterpolatedDistribution1D* interpolator_;
101  double param_;
102  bool vertical_;
103  bool parameterSet_;
104  bool haveAllDistros_;
105  };
106 }
107 
108 #endif // NPSTAT_INTERPOLATEDDISTRO1D1P_HH_
Interface for interpolating 1-d distributions.
Non-uniformly spaced coordinate sets for use in constructing rectangular grids.
Definition: AbsInterpolatedDistribution1D.hh:18
Definition: GridAxis.hh:31
unsigned nCoords() const
Definition: GridAxis.hh:95
Definition: InterpolatedDistro1D1P.hh:21
double density(const double x) const
Definition: InterpolatedDistro1D1P.hh:68
void setParameter(double value)
double quantile(const double x) const
Definition: InterpolatedDistro1D1P.hh:74
virtual InterpolatedDistro1D1P * clone() const
Definition: InterpolatedDistro1D1P.hh:65
virtual bool isEqual(const AbsDistribution1D &) const
virtual gs::ClassId classId() const
Definition: InterpolatedDistro1D1P.hh:79
double exceedance(const double x) const
Definition: InterpolatedDistro1D1P.hh:72
InterpolatedDistro1D1P(const GridAxis &axis, bool interpolateVertically=false)
double cdf(const double x) const
Definition: InterpolatedDistro1D1P.hh:70
InterpolatedDistro1D1P(const GridAxis &axis, const std::vector< CPP11_shared_ptr< const AbsDistribution1D > > &distros, double initialParameterValue=0.0, bool interpolateVertically=false)
void setGridDistro(unsigned cell, const AbsDistribution1D &distro)
double getParameter() const
Definition: InterpolatedDistro1D1P.hh:56
Definition: AbsArrayProjector.hh:14
Definition: AbsDistribution1D.hh:31
virtual double density(double x) const =0
virtual double exceedance(double x) const =0
virtual double quantile(double x) const =0
virtual double cdf(double x) const =0