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  ConstDouble() = delete;
21  inline double operator()(const Arg1&) const override { return c_; }
22 
23  private:
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  ProportionalToScale() = delete;
33  inline double operator()(const T& r) const override { return r.scale() * c_; }
34 
35  private:
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  MultiplyByConst() = delete;
46 
47  inline ~MultiplyByConst() override {
48  if (ownsPointer_)
49  delete func_;
50  }
51 
52  inline double operator()(const T& r) const override { return (*func_)(r)*c_; }
53 
54  private:
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  CompositeFunctor() = delete;
69 
70  inline ~CompositeFunctor() override {
71  if (ownsPointers_) {
72  delete f1_;
73  delete f2_;
74  }
75  }
76 
77  inline double operator()(const T& r) const override { return (*f1_)((*f2_)(r)); }
78 
79  private:
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  ProductFunctor() = delete;
94 
95  inline ~ProductFunctor() override {
96  if (ownsPointers_) {
97  delete f1_;
98  delete f2_;
99  }
100  }
101 
102  inline double operator()(const T& r) const override { return (*f1_)(r) * (*f2_)(r); }
103 
104  private:
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  MagnitudeDependent() = delete;
117 
118  inline ~MagnitudeDependent() override {
119  if (ownsPointer_)
120  delete f1_;
121  }
122 
123  inline double operator()(const T& r) const override { return (*f1_)(r.magnitude()); }
124 
125  private:
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  PeakEtaDependent() = delete;
136 
137  inline ~PeakEtaDependent() override {
138  if (ownsPointer_)
139  delete f1_;
140  }
141 
142  inline double operator()(const fftjet::Peak& r) const override { return (*f1_)(r.eta()); }
143 
144  private:
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  PeakEtaMagSsqDependent() = delete;
158 
159  inline ~PeakEtaMagSsqDependent() override {
160  if (ownsPointer_)
161  delete f1_;
162  if (ownsjmmpPointer_)
163  delete jmmp_;
164  }
165 
166  inline double operator()(const fftjet::Peak& r) const override {
167  const double scale = r.scale();
168  const double magnitude = r.magnitude();
169  const double pt = scale * scale * factor_ * magnitude;
170  const double partonpt = (*jmmp_)(pt, r);
171  return (*f1_)(std::abs(r.eta()), partonpt);
172  }
173 
174  private:
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  JetEtaDependent() = delete;
188 
189  inline ~JetEtaDependent() override {
190  if (ownsPointer_)
191  delete f1_;
192  }
193 
194  inline double operator()(const fftjet::RecombinedJet<VectorLike>& r) const override {
195  return (*f1_)(r.vec().eta());
196  }
197 
198  private:
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  Polynomial() = delete;
213  inline ~Polynomial() override { delete[] coeffs_; }
214 
215  inline double operator()(const double& x) const override {
216  double sum = 0.0;
217  const double* p = coeffs_ + nCoeffs - 1;
218  for (unsigned i = 0; i < nCoeffs; ++i) {
219  sum *= x;
220  sum += *p--;
221  }
222  return sum;
223  }
224 
225  private:
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:215
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:428
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:21
fftjetcms
Definition: AbsPileupCalculator.h:15
L1EGammaCrystalsEmulatorProducer_cfi.scale
scale
Definition: L1EGammaCrystalsEmulatorProducer_cfi.py:10
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:189
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
fftjetcms::CompositeFunctor::~CompositeFunctor
~CompositeFunctor() override
Definition: ScaleCalculators.h:70
fftjetTypedefs.h
fftjetcms::ProportionalToScale::operator()
double operator()(const T &r) const override
Definition: ScaleCalculators.h:33
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:118
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:213
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:95
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
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:123
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
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:194
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
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:52
fftjetcms::PeakEtaDependent::ownsPointer_
const bool ownsPointer_
Definition: ScaleCalculators.h:146
value
Definition: value.py:1
fftjetcms::MultiplyByConst::~MultiplyByConst
~MultiplyByConst() override
Definition: ScaleCalculators.h:47
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:102
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:142
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:77
fftjetcms::PeakEtaDependent::PeakEtaDependent
PeakEtaDependent()=delete
fftjetcms::PeakEtaMagSsqDependent::operator()
double operator()(const fftjet::Peak &r) const override
Definition: ScaleCalculators.h:166
fftjetcms::PeakEtaMagSsqDependent::PeakEtaMagSsqDependent
PeakEtaMagSsqDependent()=delete
fftjetcms::CompositeFunctor
Definition: ScaleCalculators.h:62
fftjetcms::PeakEtaMagSsqDependent::~PeakEtaMagSsqDependent
~PeakEtaMagSsqDependent() override
Definition: ScaleCalculators.h:159
fftjetcms::PeakEtaDependent::~PeakEtaDependent
~PeakEtaDependent() override
Definition: ScaleCalculators.h:137
fftjetcms::MagnitudeDependent::MagnitudeDependent
MagnitudeDependent()=delete
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443