CMS 3D CMS Logo

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 #include "fftjet/LinearInterpolator2d.hh"
10 #include "fftjet/JetMagnitudeMapper2d.hh"
11 
13 
14 namespace fftjetcms {
15  // Return a predefined constant
16  template <typename Arg1>
17  class ConstDouble : public fftjet::Functor1<double, Arg1> {
18  public:
19  inline ConstDouble(const double value) : c_(value) {}
20  inline double operator()(const Arg1&) const override { return c_; }
21 
22  private:
23  ConstDouble() = delete;
24  double c_;
25  };
26 
27  // Multiplication of a constant by the "scale()" member
28  template <class T>
29  class ProportionalToScale : public fftjet::Functor1<double, T> {
30  public:
31  inline ProportionalToScale(const double value) : c_(value) {}
32  inline double operator()(const T& r) const override { return r.scale() * c_; }
33 
34  private:
35  ProportionalToScale() = delete;
36  double c_;
37  };
38 
39  // Multiplication by a constant
40  template <class T>
41  class MultiplyByConst : public fftjet::Functor1<double, T> {
42  public:
43  inline MultiplyByConst(const double factor, const fftjet::Functor1<double, T>* f, const bool takeOwnership = false)
44  : c_(factor), func_(f), ownsPointer_(takeOwnership) {}
45 
46  inline ~MultiplyByConst() override {
47  if (ownsPointer_)
48  delete func_;
49  }
50 
51  inline double operator()(const T& r) const override { return (*func_)(r)*c_; }
52 
53  private:
54  MultiplyByConst() = delete;
55  double c_;
56  const fftjet::Functor1<double, T>* func_;
57  const bool ownsPointer_;
58  };
59 
60  // Function composition
61  template <class T>
62  class CompositeFunctor : public fftjet::Functor1<double, T> {
63  public:
64  inline CompositeFunctor(const fftjet::Functor1<double, double>* f1,
65  const fftjet::Functor1<double, T>* f2,
66  const bool takeOwnership = false)
67  : f1_(f1), f2_(f2), ownsPointers_(takeOwnership) {}
68 
69  inline ~CompositeFunctor() override {
70  if (ownsPointers_) {
71  delete f1_;
72  delete f2_;
73  }
74  }
75 
76  inline double operator()(const T& r) const override { return (*f1_)((*f2_)(r)); }
77 
78  private:
79  CompositeFunctor() = delete;
80  const fftjet::Functor1<double, double>* f1_;
81  const fftjet::Functor1<double, T>* f2_;
82  const bool ownsPointers_;
83  };
84 
85  // Product of two functors
86  template <class T>
87  class ProductFunctor : public fftjet::Functor1<double, T> {
88  public:
89  inline ProductFunctor(const fftjet::Functor1<double, T>* f1,
90  const fftjet::Functor1<double, T>* f2,
91  const bool takeOwnership = false)
92  : f1_(f1), f2_(f2), ownsPointers_(takeOwnership) {}
93 
94  inline ~ProductFunctor() override {
95  if (ownsPointers_) {
96  delete f1_;
97  delete f2_;
98  }
99  }
100 
101  inline double operator()(const T& r) const override { return (*f1_)(r) * (*f2_)(r); }
102 
103  private:
104  ProductFunctor() = delete;
105  const fftjet::Functor1<double, T>* f1_;
106  const fftjet::Functor1<double, T>* f2_;
107  const bool ownsPointers_;
108  };
109 
110  // Function dependent on magnitude
111  template <class T>
112  class MagnitudeDependent : public fftjet::Functor1<double, T> {
113  public:
114  inline MagnitudeDependent(const fftjet::Functor1<double, double>* f1, const bool takeOwnership = false)
115  : f1_(f1), ownsPointer_(takeOwnership) {}
116 
117  inline ~MagnitudeDependent() override {
118  if (ownsPointer_)
119  delete f1_;
120  }
121 
122  inline double operator()(const T& r) const override { return (*f1_)(r.magnitude()); }
123 
124  private:
125  MagnitudeDependent() = delete;
126  const fftjet::Functor1<double, double>* f1_;
127  const bool ownsPointer_;
128  };
129 
130  // Functions dependent on peak eta
131  class PeakEtaDependent : public fftjet::Functor1<double, fftjet::Peak> {
132  public:
133  inline PeakEtaDependent(const fftjet::Functor1<double, double>* f1, const bool takeOwnership = false)
134  : f1_(f1), ownsPointer_(takeOwnership) {}
135 
136  inline ~PeakEtaDependent() override {
137  if (ownsPointer_)
138  delete f1_;
139  }
140 
141  inline double operator()(const fftjet::Peak& r) const override { return (*f1_)(r.eta()); }
142 
143  private:
144  PeakEtaDependent() = delete;
145  const fftjet::Functor1<double, double>* f1_;
146  const bool ownsPointer_;
147  };
148 
149  class PeakEtaMagSsqDependent : public fftjet::Functor1<double, fftjet::Peak> {
150  public:
151  inline PeakEtaMagSsqDependent(const fftjet::LinearInterpolator2d* f1,
152  const bool takeOwnership,
153  const fftjet::JetMagnitudeMapper2d<fftjet::Peak>* jmmp,
154  const bool ownjmp,
155  const double fc)
156  : f1_(f1), ownsPointer_(takeOwnership), jmmp_(jmmp), ownsjmmpPointer_(ownjmp), factor_(fc) {}
157 
158  inline ~PeakEtaMagSsqDependent() override {
159  if (ownsPointer_)
160  delete f1_;
161  if (ownsjmmpPointer_)
162  delete jmmp_;
163  }
164 
165  inline double operator()(const fftjet::Peak& r) const override {
166  const double scale = r.scale();
167  const double magnitude = r.magnitude();
168  const double pt = scale * scale * factor_ * magnitude;
169  const double partonpt = (*jmmp_)(pt, r);
170  return (*f1_)(std::abs(r.eta()), partonpt);
171  }
172 
173  private:
174  PeakEtaMagSsqDependent() = delete;
175  const fftjet::LinearInterpolator2d* f1_;
176  const bool ownsPointer_;
177  const fftjet::JetMagnitudeMapper2d<fftjet::Peak>* jmmp_;
178  const bool ownsjmmpPointer_;
179  const double factor_;
180  };
181 
182  // Functions dependent on jet eta
183  class JetEtaDependent : public fftjet::Functor1<double, fftjet::RecombinedJet<VectorLike> > {
184  public:
185  inline JetEtaDependent(const fftjet::Functor1<double, double>* f1, const bool takeOwnership = false)
186  : f1_(f1), ownsPointer_(takeOwnership) {}
187 
188  inline ~JetEtaDependent() override {
189  if (ownsPointer_)
190  delete f1_;
191  }
192 
193  inline double operator()(const fftjet::RecombinedJet<VectorLike>& r) const override {
194  return (*f1_)(r.vec().eta());
195  }
196 
197  private:
198  JetEtaDependent() = delete;
199  const fftjet::Functor1<double, double>* f1_;
200  const bool ownsPointer_;
201  };
202 
203  // A simple polynomial. Coefficients are in the order c0, c1, c2, ...
204  class Polynomial : public fftjet::Functor1<double, double> {
205  public:
206  inline Polynomial(const std::vector<double>& coeffs) : coeffs_(nullptr), nCoeffs(coeffs.size()) {
207  if (nCoeffs) {
208  coeffs_ = new double[nCoeffs];
209  std::copy(coeffs.begin(), coeffs.end(), coeffs_);
210  }
211  }
212  inline ~Polynomial() override { delete[] coeffs_; }
213 
214  inline double operator()(const double& x) const override {
215  double sum = 0.0;
216  const double* p = coeffs_ + nCoeffs - 1;
217  for (unsigned i = 0; i < nCoeffs; ++i) {
218  sum *= x;
219  sum += *p--;
220  }
221  return sum;
222  }
223 
224  private:
225  Polynomial() = delete;
226  double* coeffs_;
227  const unsigned nCoeffs;
228  };
229 } // namespace fftjetcms
230 
231 #endif // RecoJets_FFTJetAlgorithms_ScaleCalculators_h
size
Write out results.
const fftjet::Functor1< double, double > * f1_
const fftjet::Functor1< double, T > * func_
MultiplyByConst(const double factor, const fftjet::Functor1< double, T > *f, const bool takeOwnership=false)
double operator()(const fftjet::Peak &r) const override
JetEtaDependent(const fftjet::Functor1< double, double > *f1, const bool takeOwnership=false)
const fftjet::Functor1< double, T > * f1_
double operator()(const fftjet::Peak &r) const override
const fftjet::Functor1< double, double > * f1_
double operator()(const double &x) const override
#define nullptr
ProportionalToScale(const double value)
MagnitudeDependent(const fftjet::Functor1< double, double > *f1, const bool takeOwnership=false)
const fftjet::Functor1< double, T > * f2_
double operator()(const Arg1 &) const override
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)
double operator()(const fftjet::RecombinedJet< VectorLike > &r) const override
Polynomial(const std::vector< double > &coeffs)
PeakEtaMagSsqDependent(const fftjet::LinearInterpolator2d *f1, const bool takeOwnership, const fftjet::JetMagnitudeMapper2d< fftjet::Peak > *jmmp, const bool ownjmp, const double fc)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
Definition: value.py:1
const fftjet::LinearInterpolator2d * f1_
PeakEtaDependent(const fftjet::Functor1< double, double > *f1, const bool takeOwnership=false)
const fftjet::Functor1< double, double > * f1_
double operator()(const T &r) const override
double operator()(const T &r) const override
const fftjet::Functor1< double, T > * f2_
const fftjet::JetMagnitudeMapper2d< fftjet::Peak > * jmmp_
double operator()(const T &r) const override
double operator()(const T &r) const override
long double T
const fftjet::Functor1< double, double > * f1_
double operator()(const T &r) const override
ConstDouble(const double value)