CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ScaleCalculators.h
Go to the documentation of this file.
1 #ifndef RecoJets_FFTJetAlgorithms_ScaleCalculators_h
2 #define RecoJets_FFTJetAlgorithms_ScaleCalculators_h
3 
4 #include <vector>
5 #include <algorithm>
6 
7 #include "fftjet/SimpleFunctors.hh"
8 #include "fftjet/RecombinedJet.hh"
9 
11 
12 namespace fftjetcms {
13  // Return a predefined constant
14  template <typename Arg1>
15  class ConstDouble : public fftjet::Functor1<double,Arg1>
16  {
17  public:
18  inline ConstDouble(const double value) : c_(value) {}
19  inline double operator()(const Arg1&) const {return c_;}
20 
21  private:
22  ConstDouble();
23  double c_;
24  };
25 
26 
27  // Multiplication of a constant by the "scale()" member
28  template <class T>
29  class ProportionalToScale : public fftjet::Functor1<double,T>
30  {
31  public:
32  inline ProportionalToScale(const double value) : c_(value) {}
33  inline double operator()(const T& r) const {return r.scale()*c_;}
34 
35  private:
37  double c_;
38  };
39 
40 
41  // Multiplication by a constant
42  template <class T>
43  class MultiplyByConst : public fftjet::Functor1<double,T>
44  {
45  public:
46  inline MultiplyByConst(const double factor,
47  const fftjet::Functor1<double,T>* f,
48  const bool takeOwnership=false)
49  : c_(factor), func_(f), ownsPointer_(takeOwnership) {}
50 
51  inline ~MultiplyByConst() {if (ownsPointer_) delete func_;}
52 
53  inline double operator()(const T& r) const {return (*func_)(r)*c_;}
54 
55  private:
57  double c_;
58  const fftjet::Functor1<double,T>* func_;
59  const bool ownsPointer_;
60  };
61 
62 
63  // Function composition
64  template <class T>
65  class CompositeFunctor : public fftjet::Functor1<double,T>
66  {
67  public:
68  inline CompositeFunctor(const fftjet::Functor1<double,double>* f1,
69  const fftjet::Functor1<double,T>* f2,
70  const bool takeOwnership=false)
71  : f1_(f1), f2_(f2), ownsPointers_(takeOwnership) {}
72 
74  {if (ownsPointers_) {delete f1_; delete f2_;}}
75 
76  inline double operator()(const T& r) const {return (*f1_)((*f2_)(r));}
77 
78  private:
80  const fftjet::Functor1<double,double>* f1_;
81  const fftjet::Functor1<double,T>* f2_;
82  const bool ownsPointers_;
83  };
84 
85 
86  // Product of two functors
87  template <class T>
88  class ProductFunctor : public fftjet::Functor1<double,T>
89  {
90  public:
91  inline ProductFunctor(const fftjet::Functor1<double,T>* f1,
92  const fftjet::Functor1<double,T>* f2,
93  const bool takeOwnership=false)
94  : f1_(f1), f2_(f2), ownsPointers_(takeOwnership) {}
95 
96  inline ~ProductFunctor()
97  {if (ownsPointers_) {delete f1_; delete f2_;}}
98 
99  inline double operator()(const T& r) const
100  {return (*f1_)(r) * (*f2_)(r);}
101 
102  private:
103  ProductFunctor();
104  const fftjet::Functor1<double,T>* f1_;
105  const fftjet::Functor1<double,T>* f2_;
106  const bool ownsPointers_;
107  };
108 
109 
110  // Function dependent on magnitude
111  template <class T>
112  class MagnitudeDependent : public fftjet::Functor1<double,T>
113  {
114  public:
115  inline MagnitudeDependent(const fftjet::Functor1<double,double>* f1,
116  const bool takeOwnership=false)
117  : f1_(f1), ownsPointer_(takeOwnership) {}
118 
119  inline ~MagnitudeDependent() {if (ownsPointer_) delete f1_;}
120 
121  inline double operator()(const T& r) const
122  {return (*f1_)(r.magnitude());}
123 
124  private:
126  const fftjet::Functor1<double,double>* f1_;
127  const bool ownsPointer_;
128  };
129 
130 
131  // Functions dependent on peak eta
132  class PeakEtaDependent : public fftjet::Functor1<double,fftjet::Peak>
133  {
134  public:
135  inline PeakEtaDependent(const fftjet::Functor1<double,double>* f1,
136  const bool takeOwnership=false)
137  : f1_(f1), ownsPointer_(takeOwnership) {}
138 
139  inline ~PeakEtaDependent() {if (ownsPointer_) delete f1_;}
140 
141  inline double operator()(const fftjet::Peak& r) const
142  {return (*f1_)(r.eta());}
143 
144  private:
146  const fftjet::Functor1<double,double>* f1_;
147  const bool ownsPointer_;
148  };
149 
150 
151  // Functions dependent on jet eta
153  public fftjet::Functor1<double,fftjet::RecombinedJet<VectorLike> >
154  {
155  public:
156  inline JetEtaDependent(const fftjet::Functor1<double,double>* f1,
157  const bool takeOwnership=false)
158  : f1_(f1), ownsPointer_(takeOwnership) {}
159 
160  inline ~JetEtaDependent() {if (ownsPointer_) delete f1_;}
161 
162  inline double operator()(
163  const fftjet::RecombinedJet<VectorLike>& r) const
164  {return (*f1_)(r.vec().eta());}
165 
166  private:
167  JetEtaDependent();
168  const fftjet::Functor1<double,double>* f1_;
169  const bool ownsPointer_;
170  };
171 
172 
173  // A simple polynomial. Coefficients are in the order c0, c1, c2, ...
174  class Polynomial : public fftjet::Functor1<double,double>
175  {
176  public:
177  inline Polynomial(const std::vector<double>& coeffs)
178  : coeffs_(0), nCoeffs(coeffs.size())
179  {
180  if (nCoeffs)
181  {
182  coeffs_ = new double[nCoeffs];
183  std::copy(coeffs.begin(), coeffs.end(), coeffs_);
184  }
185  }
186  inline ~Polynomial() {delete [] coeffs_;}
187 
188  inline double operator()(const double& x) const
189  {
190  double sum = 0.0;
191  const double* p = coeffs_ + nCoeffs - 1;
192  for (unsigned i=0; i<nCoeffs; ++i)
193  {
194  sum *= x;
195  sum += *p--;
196  }
197  return sum;
198  }
199 
200  private:
201  Polynomial();
202  double* coeffs_;
203  const unsigned nCoeffs;
204  };
205 }
206 
207 #endif // RecoJets_FFTJetAlgorithms_ScaleCalculators_h
double operator()(const double &x) const
double operator()(const Arg1 &) const
int i
Definition: DBlmapReader.cc:9
MultiplyByConst(const double factor, const fftjet::Functor1< double, T > *f, const bool takeOwnership=false)
JetEtaDependent(const fftjet::Functor1< double, double > *f1, const bool takeOwnership=false)
const fftjet::Functor1< double, double > * f1_
const fftjet::Functor1< double, double > * f1_
double operator()(const T &r) const
const fftjet::Functor1< double, double > * f1_
ProportionalToScale(const double value)
const fftjet::Functor1< double, T > * f2_
MagnitudeDependent(const fftjet::Functor1< double, double > *f1, const bool takeOwnership=false)
double operator()(const T &r) const
double operator()(const fftjet::RecombinedJet< VectorLike > &r) const
CompositeFunctor(const fftjet::Functor1< double, double > *f1, const fftjet::Functor1< double, T > *f2, const bool takeOwnership=false)
ProductFunctor(const fftjet::Functor1< double, T > *f1, const fftjet::Functor1< double, T > *f2, const bool takeOwnership=false)
Polynomial(const std::vector< double > &coeffs)
const fftjet::Functor1< double, T > * f1_
double operator()(const T &r) const
const fftjet::Functor1< double, T > * func_
double f[11][100]
PeakEtaDependent(const fftjet::Functor1< double, double > *f1, const bool takeOwnership=false)
double operator()(const T &r) const
double operator()(const fftjet::Peak &r) const
const fftjet::Functor1< double, double > * f1_
Definition: DDAxes.h:10
long double T
const fftjet::Functor1< double, T > * f2_
tuple size
Write out results.
ConstDouble(const double value)
double operator()(const T &r) const