npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
CdfTransform1D.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_CDFTRANSFORM1D_HH_
2 #define NPSTAT_CDFTRANSFORM1D_HH_
3 
4 /*!
5 // \file CdfTransform1D.hh
6 //
7 // \brief Coordinate transform y = a*cdf(x) + b, where cdf(x) is provided
8 // by some cumulative distribution function
9 //
10 // Author: I. Volobouev
11 //
12 // February 2023
13 */
14 
17 
18 namespace npstat {
20  {
21  public:
22  CdfTransform1D(const AbsDistribution1D& distro, double a, double b);
23 
24  inline CdfTransform1D(const CdfTransform1D& r)
25  : AbsDistributionTransform1D(r), distro_(r.distro_->clone()),
26  a_(r.a_), b_(r.b_), xmin_(r.xmin_), xmax_(r.xmax_) {}
27 
28  CdfTransform1D& operator=(const CdfTransform1D& r);
29 
30  inline virtual ~CdfTransform1D() {delete distro_;}
31 
32  inline virtual CdfTransform1D* clone() const
33  {return new CdfTransform1D(*this);}
34 
35  inline double a() const {return a_;}
36  inline double b() const {return b_;}
37  inline double xmin() const {return xmin_;}
38  inline double xmax() const {return xmax_;}
39 
40  double transformForward(double x, double* dydx) const;
41  double transformBack(double y) const;
42  inline bool isIncreasing() const {return a_ > 0.0;}
43 
44  //@{
45  /** Prototype needed for I/O */
46  inline virtual gs::ClassId classId() const {return gs::ClassId(*this);}
47  virtual bool write(std::ostream&) const;
48  //@}
49 
50  static inline const char* classname()
51  {return "npstat::CdfTransform1D";}
52  static inline unsigned version() {return 1;}
53  static CdfTransform1D* read(const gs::ClassId& id, std::istream&);
54 
55  protected:
56  inline bool isEqual(const AbsDistributionTransform1D& o) const
57  {
58  const CdfTransform1D& r =
59  static_cast<const CdfTransform1D&>(o);
60  return *distro_ == *r.distro_ && a_ == r.a_&& b_ == r.b_;
61  }
62 
63  private:
64  inline void setParameterChecked(const unsigned which,
65  const double value)
66  {
67  if (which)
68  b_ = value;
69  else
70  {
71  validateScale(value);
72  a_ = value;
73  }
74  }
75  inline void setAllParametersChecked(const double* p)
76  {
77  validateScale(p[0]);
78  a_ = p[0];
79  b_ = p[1];
80  }
81  inline double getParameterChecked(const unsigned which) const
82  {return which ? b_ : a_;}
83 
84  void validateScale(double a);
85 
86  const AbsDistribution1D* distro_;
87  double a_;
88  double b_;
89  double xmin_;
90  double xmax_;
91  };
92 }
93 
94 #endif // NPSTAT_CDFTRANSFORM1D_HH_
Interface definition for 1-d continuous statistical distributions.
Interface definition for 1-d coordinate transformations used to build statistical distributions.
Definition: AbsDistributionTransform1D.hh:29
Definition: CdfTransform1D.hh:20
double transformForward(double x, double *dydx) const
virtual CdfTransform1D * clone() const
Definition: CdfTransform1D.hh:32
bool isEqual(const AbsDistributionTransform1D &o) const
Definition: CdfTransform1D.hh:56
bool isIncreasing() const
Definition: CdfTransform1D.hh:42
virtual gs::ClassId classId() const
Definition: CdfTransform1D.hh:46
Definition: AbsArrayProjector.hh:14
Definition: AbsDistribution1D.hh:31
virtual AbsDistribution1D * clone() const =0