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
fftjetcms::Polynomial::operator()
double operator()(const double &x) const override
Definition: ScaleCalculators.h:214
fftjetcms::PeakEtaMagSsqDependent::ownsjmmpPointer_
const bool ownsjmmpPointer_
Definition: ScaleCalculators.h:178
fftjetcms::ProductFunctor::ownsPointers_
const bool ownsPointers_
Definition: ScaleCalculators.h:107
mps_fire.i
i
Definition: mps_fire.py:355
fftjetcms::PeakEtaDependent::f1_
const fftjet::Functor1< double, double > * f1_
Definition: ScaleCalculators.h:145
fftjetcms::ConstDouble::operator()
double operator()(const Arg1 &) const override
Definition: ScaleCalculators.h:20
fftjetcms
Definition: AbsPileupCalculator.h:15
fftjetcms::MultiplyByConst::ownsPointer_
const bool ownsPointer_
Definition: ScaleCalculators.h:57
fftjetcms::MagnitudeDependent::ownsPointer_
const bool ownsPointer_
Definition: ScaleCalculators.h:127
fftjetcms::ProportionalToScale::c_
double c_
Definition: ScaleCalculators.h:36
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
fftjetcms::JetEtaDependent::~JetEtaDependent
~JetEtaDependent() override
Definition: ScaleCalculators.h:188
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
fftjetcms::Polynomial::Polynomial
Polynomial()=delete
fftjetcms::MultiplyByConst::c_
double c_
Definition: ScaleCalculators.h:55
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
fftjetcms::ConstDouble
Definition: ScaleCalculators.h:17
fftjetcms::JetEtaDependent::JetEtaDependent
JetEtaDependent(const fftjet::Functor1< double, double > *f1, const bool takeOwnership=false)
Definition: ScaleCalculators.h:185
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
fftjetcms::CompositeFunctor::~CompositeFunctor
~CompositeFunctor() override
Definition: ScaleCalculators.h:69
fftjetTypedefs.h
fftjetcms::ProportionalToScale::operator()
double operator()(const T &r) const override
Definition: ScaleCalculators.h:32
fftjetcms::MultiplyByConst::MultiplyByConst
MultiplyByConst(const double factor, const fftjet::Functor1< double, T > *f, const bool takeOwnership=false)
Definition: ScaleCalculators.h:43
fftjetcms::MagnitudeDependent::~MagnitudeDependent
~MagnitudeDependent() override
Definition: ScaleCalculators.h:117
fftjetcms::PeakEtaMagSsqDependent
Definition: ScaleCalculators.h:149
fftjetcms::CompositeFunctor::f2_
const fftjet::Functor1< double, T > * f2_
Definition: ScaleCalculators.h:81
fftjetcms::CompositeFunctor::CompositeFunctor
CompositeFunctor(const fftjet::Functor1< double, double > *f1, const fftjet::Functor1< double, T > *f2, const bool takeOwnership=false)
Definition: ScaleCalculators.h:64
fftjetcms::Polynomial::~Polynomial
~Polynomial() override
Definition: ScaleCalculators.h:212
fftjetcms::MultiplyByConst
Definition: ScaleCalculators.h:41
fftjetcms::Polynomial::Polynomial
Polynomial(const std::vector< double > &coeffs)
Definition: ScaleCalculators.h:206
fftjetcms::ProductFunctor::~ProductFunctor
~ProductFunctor() override
Definition: ScaleCalculators.h:94
fftjetcms::MagnitudeDependent::MagnitudeDependent
MagnitudeDependent(const fftjet::Functor1< double, double > *f1, const bool takeOwnership=false)
Definition: ScaleCalculators.h:114
fftjetcms::MagnitudeDependent::f1_
const fftjet::Functor1< double, double > * f1_
Definition: ScaleCalculators.h:126
fftjetcms::PeakEtaMagSsqDependent::PeakEtaMagSsqDependent
PeakEtaMagSsqDependent(const fftjet::LinearInterpolator2d *f1, const bool takeOwnership, const fftjet::JetMagnitudeMapper2d< fftjet::Peak > *jmmp, const bool ownjmp, const double fc)
Definition: ScaleCalculators.h:151
fftjetcms::ConstDouble::ConstDouble
ConstDouble()=delete
benchmark_cfg.fc
fc
Definition: benchmark_cfg.py:15
fftjetcms::JetEtaDependent::ownsPointer_
const bool ownsPointer_
Definition: ScaleCalculators.h:200
fftjetcms::JetEtaDependent
Definition: ScaleCalculators.h:183
DQMScaleToClient_cfi.factor
factor
Definition: DQMScaleToClient_cfi.py:8
fftjetcms::ProductFunctor::f1_
const fftjet::Functor1< double, T > * f1_
Definition: ScaleCalculators.h:105
fftjetcms::MagnitudeDependent::operator()
double operator()(const T &r) const override
Definition: ScaleCalculators.h:122
fftjetcms::Polynomial::nCoeffs
const unsigned nCoeffs
Definition: ScaleCalculators.h:227
fftjetcms::CompositeFunctor::ownsPointers_
const bool ownsPointers_
Definition: ScaleCalculators.h:82
fftjetcms::ProportionalToScale
Definition: ScaleCalculators.h:29
fftjetcms::CompositeFunctor::CompositeFunctor
CompositeFunctor()=delete
Scenarios_cff.scale
scale
Definition: Scenarios_cff.py:2186
fftjetcms::PeakEtaMagSsqDependent::ownsPointer_
const bool ownsPointer_
Definition: ScaleCalculators.h:176
fftjetcms::PeakEtaDependent::PeakEtaDependent
PeakEtaDependent(const fftjet::Functor1< double, double > *f1, const bool takeOwnership=false)
Definition: ScaleCalculators.h:133
fftjetcms::JetEtaDependent::operator()
double operator()(const fftjet::RecombinedJet< VectorLike > &r) const override
Definition: ScaleCalculators.h:193
fftjetcms::ProportionalToScale::ProportionalToScale
ProportionalToScale(const double value)
Definition: ScaleCalculators.h:31
DeadROC_duringRun.f2
f2
Definition: DeadROC_duringRun.py:220
fftjetcms::MultiplyByConst::operator()
double operator()(const T &r) const override
Definition: ScaleCalculators.h:51
fftjetcms::PeakEtaDependent::ownsPointer_
const bool ownsPointer_
Definition: ScaleCalculators.h:146
value
Definition: value.py:1
fftjetcms::MultiplyByConst::~MultiplyByConst
~MultiplyByConst() override
Definition: ScaleCalculators.h:46
fftjetcms::PeakEtaDependent
Definition: ScaleCalculators.h:131
fftjetcms::Polynomial::coeffs_
double * coeffs_
Definition: ScaleCalculators.h:226
fftjetcms::MultiplyByConst::func_
const fftjet::Functor1< double, T > * func_
Definition: ScaleCalculators.h:56
fftjetcms::Polynomial
Definition: ScaleCalculators.h:204
fftjetcms::ProductFunctor::operator()
double operator()(const T &r) const override
Definition: ScaleCalculators.h:101
alignCSCRings.r
r
Definition: alignCSCRings.py:93
fftjetcms::MagnitudeDependent
Definition: ScaleCalculators.h:112
fftjetcms::JetEtaDependent::f1_
const fftjet::Functor1< double, double > * f1_
Definition: ScaleCalculators.h:199
fftjetcms::PeakEtaMagSsqDependent::f1_
const fftjet::LinearInterpolator2d * f1_
Definition: ScaleCalculators.h:175
fftjetcms::CompositeFunctor::f1_
const fftjet::Functor1< double, double > * f1_
Definition: ScaleCalculators.h:80
fftjetcms::PeakEtaMagSsqDependent::factor_
const double factor_
Definition: ScaleCalculators.h:179
fftjetcms::MultiplyByConst::MultiplyByConst
MultiplyByConst()=delete
fftjetcms::ProportionalToScale::ProportionalToScale
ProportionalToScale()=delete
T
long double T
Definition: Basic3DVectorLD.h:48
fftjetcms::ConstDouble::ConstDouble
ConstDouble(const double value)
Definition: ScaleCalculators.h:19
fftjetcms::ProductFunctor
Definition: ScaleCalculators.h:87
fftjetcms::ConstDouble::c_
double c_
Definition: ScaleCalculators.h:24
fftjetcms::ProductFunctor::ProductFunctor
ProductFunctor(const fftjet::Functor1< double, T > *f1, const fftjet::Functor1< double, T > *f2, const bool takeOwnership=false)
Definition: ScaleCalculators.h:89
fftjetcms::ProductFunctor::f2_
const fftjet::Functor1< double, T > * f2_
Definition: ScaleCalculators.h:106
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
fftjetcms::PeakEtaDependent::operator()
double operator()(const fftjet::Peak &r) const override
Definition: ScaleCalculators.h:141
fftjetcms::ProductFunctor::ProductFunctor
ProductFunctor()=delete
fftjetcms::PeakEtaMagSsqDependent::jmmp_
const fftjet::JetMagnitudeMapper2d< fftjet::Peak > * jmmp_
Definition: ScaleCalculators.h:177
fftjetcms::JetEtaDependent::JetEtaDependent
JetEtaDependent()=delete
DeadROC_duringRun.f1
f1
Definition: DeadROC_duringRun.py:219
fftjetcms::CompositeFunctor::operator()
double operator()(const T &r) const override
Definition: ScaleCalculators.h:76
fftjetcms::PeakEtaDependent::PeakEtaDependent
PeakEtaDependent()=delete
fftjetcms::PeakEtaMagSsqDependent::operator()
double operator()(const fftjet::Peak &r) const override
Definition: ScaleCalculators.h:165
fftjetcms::PeakEtaMagSsqDependent::PeakEtaMagSsqDependent
PeakEtaMagSsqDependent()=delete
fftjetcms::CompositeFunctor
Definition: ScaleCalculators.h:62
fftjetcms::PeakEtaMagSsqDependent::~PeakEtaMagSsqDependent
~PeakEtaMagSsqDependent() override
Definition: ScaleCalculators.h:158
fftjetcms::PeakEtaDependent::~PeakEtaDependent
~PeakEtaDependent() override
Definition: ScaleCalculators.h:136
fftjetcms::MagnitudeDependent::MagnitudeDependent
MagnitudeDependent()=delete
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443