npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
fcnOrConst.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_FCNORCONST_HH_
2 #define NPSTAT_FCNORCONST_HH_
3 
4 /*!
5 // \file fcnOrConst.hh
6 //
7 // \brief Templated utilities for use in various density estimation codes, etc
8 //
9 // Author: I. Volobouev
10 //
11 // June 2022
12 */
13 
14 #include "geners/IOIsClassType.hh"
16 
17 namespace npstat {
18  namespace Private {
19  template<class Fcn, bool isCallable=true>
21  {
22  inline static double call(const Fcn& fcn, const double x)
23  {return fcn(x);}
24  };
25 
26  template<class Fcn>
27  struct FcnOrConstHelper<Fcn, false>
28  {
29  inline static double call(const Fcn& fcn, const double /* x */)
30  {return fcn;}
31  };
32  }
33 
34  template<class Fcn>
35  inline double fcnOrConst(const Fcn& functor, const double x)
36  {
38  }
39 
40  template<class Fcn>
42  {
43  public:
44  inline MultFunctor(const Fcn& fcn, const double f)
45  : functor_(fcn), factor_(f) {}
46 
47  inline double operator()(const double& x) const
48  {return factor_*fcnOrConst(functor_, x);}
49 
50  private:
51  Fcn functor_;
52  double factor_;
53  };
54 
55  template<class DensityFcn, class Weight>
56  class DensitySquaredTimesWeight : public Functor1<double, double>
57  {
58  public:
59  inline DensitySquaredTimesWeight(const DensityFcn& df, const Weight& wf)
60  : df_(df), wf_(wf) {}
61 
62  inline virtual ~DensitySquaredTimesWeight() {}
63 
64  inline double operator()(const double& x) const
65  {
66  const double d = df_(x);
67  const double w = fcnOrConst(wf_, x);
68  return d*d*w;
69  }
70 
71  private:
72  DensityFcn df_;
73  Weight wf_;
74  };
75 
76  template<class DensityFcn, class Weight>
78  make_DensitySquaredTimesWeight(const DensityFcn& df, const Weight& wf)
79  {
81  }
82 }
83 
84 #endif // NPSTAT_FCNORCONST_HH_
Interface definitions and concrete simple functors for a variety of functor-based calculations.
Definition: fcnOrConst.hh:57
Definition: fcnOrConst.hh:42
Definition: AbsArrayProjector.hh:14
Definition: SimpleFunctors.hh:58
Definition: fcnOrConst.hh:21