CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
FFTGenericScaleCalculator.cc
Go to the documentation of this file.
1 #include <cassert>
2 #include <cfloat>
3 
7 
8 #define int_param(varname) m_##varname(ps.getParameter<int>(#varname))
9 
10 #define check_param(varname) \
11  if ((m_##varname) >= 0) { \
12  if ((m_##varname) >= nFactors) \
13  throw cms::Exception("FFTJetBadConfig") \
14  << "In FFTGenericScaleCalculator constructor: " \
15  << "out of range mapping for variable \"" << #varname << "\"" << std::endl; \
16  mask[(m_##varname)] = 1; \
17  ++dim; \
18  }
19 
20 static inline double delPhi(const double phi1, const double phi2) {
21  double dphi = phi1 - phi2;
22  if (dphi > M_PI)
23  dphi -= 2.0 * M_PI;
24  else if (dphi < -M_PI)
25  dphi += 2.0 * M_PI;
26  return dphi;
27 }
28 
30  : m_factors(ps.getParameter<std::vector<double> >("factors")),
31  m_minLog(ps.getUntrackedParameter<double>("minLog", -800.0)),
32  int_param(eta),
33  int_param(phi),
34  int_param(pt),
35  int_param(logPt),
36  int_param(mass),
37  int_param(logMass),
39  int_param(logEnergy),
40  int_param(gamma),
41  int_param(logGamma),
42  int_param(pileup),
43  int_param(ncells),
44  int_param(etSum),
45  int_param(etaWidth),
46  int_param(phiWidth),
47  int_param(averageWidth),
48  int_param(widthRatio),
49  int_param(etaPhiCorr),
50  int_param(fuzziness),
51  int_param(convergenceDistance),
52  int_param(recoScale),
53  int_param(recoScaleRatio),
54  int_param(membershipFactor),
55  int_param(magnitude),
56  int_param(logMagnitude),
57  int_param(magS1),
58  int_param(LogMagS1),
59  int_param(magS2),
60  int_param(LogMagS2),
61  int_param(driftSpeed),
62  int_param(magSpeed),
63  int_param(lifetime),
64  int_param(splitTime),
65  int_param(mergeTime),
67  int_param(logScale),
68  int_param(nearestNeighborDistance),
69  int_param(clusterRadius),
70  int_param(clusterSeparation),
71  int_param(dRFromJet),
72  int_param(LaplacianS1),
73  int_param(LaplacianS2),
74  int_param(LaplacianS3),
75  int_param(HessianS2),
76  int_param(HessianS4),
77  int_param(HessianS6),
78  int_param(nConstituents),
79  int_param(aveConstituentPt),
80  int_param(logAveConstituentPt),
81  int_param(constituentPtDistribution),
82  int_param(constituentEtaPhiSpread),
88  int_param(HFHadronEnergyFraction),
89  int_param(HFEMEnergyFraction),
95  int_param(HFHadronMultiplicity),
96  int_param(HFEMMultiplicity),
97  int_param(chargedEmEnergyFraction),
98  int_param(chargedMuEnergyFraction),
99  int_param(neutralEmEnergyFraction),
100  int_param(EmEnergyFraction),
101  int_param(chargedMultiplicity),
102  int_param(neutralMultiplicity) {
103  const int nFactors = m_factors.size();
104  std::vector<int> mask(nFactors, 0);
105  int dim = 0;
106 
107  check_param(eta);
108  check_param(phi);
109  check_param(pt);
110  check_param(logPt);
111  check_param(mass);
112  check_param(logMass);
114  check_param(logEnergy);
115  check_param(gamma);
116  check_param(logGamma);
117  check_param(pileup);
118  check_param(ncells);
119  check_param(etSum);
120  check_param(etaWidth);
121  check_param(phiWidth);
122  check_param(averageWidth);
123  check_param(widthRatio);
124  check_param(etaPhiCorr);
125  check_param(fuzziness);
126  check_param(convergenceDistance);
127  check_param(recoScale);
128  check_param(recoScaleRatio);
129  check_param(membershipFactor);
130  check_param(magnitude);
131  check_param(logMagnitude);
132  check_param(magS1);
133  check_param(LogMagS1);
134  check_param(magS2);
135  check_param(LogMagS2);
136  check_param(driftSpeed);
137  check_param(magSpeed);
138  check_param(lifetime);
139  check_param(splitTime);
140  check_param(mergeTime);
142  check_param(logScale);
143  check_param(nearestNeighborDistance);
144  check_param(clusterRadius);
145  check_param(clusterSeparation);
146  check_param(dRFromJet);
147  check_param(LaplacianS1);
148  check_param(LaplacianS2);
149  check_param(LaplacianS3);
150  check_param(HessianS2);
151  check_param(HessianS4);
152  check_param(HessianS6);
153  check_param(nConstituents);
154  check_param(aveConstituentPt);
155  check_param(logAveConstituentPt);
156  check_param(constituentPtDistribution);
157  check_param(constituentEtaPhiSpread);
163  check_param(HFHadronEnergyFraction);
164  check_param(HFEMEnergyFraction);
170  check_param(HFHadronMultiplicity);
171  check_param(HFEMMultiplicity);
172  check_param(chargedEmEnergyFraction);
173  check_param(chargedMuEnergyFraction);
174  check_param(neutralEmEnergyFraction);
175  check_param(EmEnergyFraction);
176  check_param(chargedMultiplicity);
177  check_param(neutralMultiplicity);
178 
179  if (dim != nFactors)
180  throw cms::Exception("FFTJetBadConfig")
181  << "In FFTGenericScaleCalculator constructor: "
182  << "incompatible number of scaling factors: expected " << dim << ", got " << nFactors << std::endl;
183  for (int i = 0; i < nFactors; ++i)
184  if (mask[i] == 0)
185  throw cms::Exception("FFTJetBadConfig") << "In FFTGenericScaleCalculator constructor: "
186  << "variable number " << i << " is not mapped" << std::endl;
187 }
188 
190  const reco::FFTJet<float>& fftJet,
191  const math::XYZTLorentzVector& current,
192  double* buf,
193  const unsigned dim) const {
194  // Verify that the input is reasonable
195  if (dim != m_factors.size())
196  throw cms::Exception("FFTJetBadConfig")
197  << "In FFTGenericScaleCalculator::mapFFTJet: "
198  << "incompatible table dimensionality: expected " << m_factors.size() << ", got " << dim << std::endl;
199  if (dim)
200  assert(buf);
201  else
202  return;
203 
204  // Go over all variables and map them as configured.
205  // Variables from the "current" Lorentz vector.
206  if (m_eta >= 0)
207  buf[m_eta] = current.eta();
208 
209  if (m_phi >= 0)
210  buf[m_phi] = current.phi();
211 
212  if (m_pt >= 0)
213  buf[m_pt] = current.pt();
214 
215  if (m_logPt >= 0)
216  buf[m_logPt] = f_safeLog(current.pt());
217 
218  if (m_mass >= 0)
219  buf[m_mass] = current.M();
220 
221  if (m_logMass >= 0)
222  buf[m_mass] = f_safeLog(current.M());
223 
224  if (m_energy >= 0)
225  buf[m_energy] = current.e();
226 
227  if (m_logEnergy >= 0)
228  buf[m_energy] = f_safeLog(current.e());
229 
230  if (m_gamma >= 0) {
231  const double m = current.M();
232  if (m > 0.0)
233  buf[m_gamma] = current.e() / m;
234  else
235  buf[m_gamma] = DBL_MAX;
236  }
237 
238  if (m_logGamma >= 0) {
239  const double m = current.M();
240  if (m > 0.0)
241  buf[m_gamma] = current.e() / m;
242  else
243  buf[m_gamma] = DBL_MAX;
244  buf[m_gamma] = log(buf[m_gamma]);
245  }
246 
247  // Variables from fftJet
248  if (m_pileup >= 0)
249  buf[m_pileup] = fftJet.f_pileup().pt();
250 
251  if (m_ncells >= 0)
252  buf[m_ncells] = fftJet.f_ncells();
253 
254  if (m_etSum >= 0)
255  buf[m_etSum] = fftJet.f_etSum();
256 
257  if (m_etaWidth >= 0)
258  buf[m_etaWidth] = fftJet.f_etaWidth();
259 
260  if (m_phiWidth >= 0)
261  buf[m_phiWidth] = fftJet.f_phiWidth();
262 
263  if (m_averageWidth >= 0) {
264  const double etaw = fftJet.f_etaWidth();
265  const double phiw = fftJet.f_phiWidth();
266  buf[m_averageWidth] = sqrt(etaw * etaw + phiw * phiw);
267  }
268 
269  if (m_widthRatio >= 0) {
270  const double etaw = fftJet.f_etaWidth();
271  const double phiw = fftJet.f_phiWidth();
272  if (phiw > 0.0)
273  buf[m_widthRatio] = etaw / phiw;
274  else
275  buf[m_widthRatio] = DBL_MAX;
276  }
277 
278  if (m_etaPhiCorr >= 0)
279  buf[m_etaPhiCorr] = fftJet.f_etaPhiCorr();
280 
281  if (m_fuzziness >= 0)
282  buf[m_fuzziness] = fftJet.f_fuzziness();
283 
284  if (m_convergenceDistance >= 0)
286 
287  if (m_recoScale >= 0)
288  buf[m_recoScale] = fftJet.f_recoScale();
289 
290  if (m_recoScaleRatio >= 0)
291  buf[m_recoScaleRatio] = fftJet.f_recoScaleRatio();
292 
293  if (m_membershipFactor >= 0)
294  buf[m_membershipFactor] = fftJet.f_membershipFactor();
295 
296  // Get most often used precluster quantities
297  const reco::PattRecoPeak<float>& preclus = fftJet.f_precluster();
298  const double scale = preclus.scale();
299 
300  if (m_magnitude >= 0)
301  buf[m_magnitude] = preclus.magnitude();
302 
303  if (m_logMagnitude >= 0)
304  buf[m_logMagnitude] = f_safeLog(preclus.magnitude());
305 
306  if (m_magS1 >= 0)
307  buf[m_magS1] = preclus.magnitude() * scale;
308 
309  if (m_LogMagS1 >= 0)
310  buf[m_LogMagS1] = f_safeLog(preclus.magnitude() * scale);
311 
312  if (m_magS2 >= 0)
313  buf[m_magS2] = preclus.magnitude() * scale * scale;
314 
315  if (m_LogMagS2 >= 0)
316  buf[m_LogMagS2] = f_safeLog(preclus.magnitude() * scale * scale);
317 
318  if (m_driftSpeed >= 0)
319  buf[m_driftSpeed] = preclus.driftSpeed();
320 
321  if (m_magSpeed >= 0)
322  buf[m_magSpeed] = preclus.magSpeed();
323 
324  if (m_lifetime >= 0)
325  buf[m_lifetime] = preclus.lifetime();
326 
327  if (m_splitTime >= 0)
328  buf[m_splitTime] = preclus.splitTime();
329 
330  if (m_mergeTime >= 0)
331  buf[m_mergeTime] = preclus.mergeTime();
332 
333  if (m_scale >= 0)
334  buf[m_scale] = scale;
335 
336  if (m_logScale >= 0)
337  buf[m_logScale] = f_safeLog(scale);
338 
339  if (m_nearestNeighborDistance >= 0)
341 
342  if (m_clusterRadius >= 0)
343  buf[m_clusterRadius] = preclus.clusterRadius();
344 
345  if (m_clusterSeparation >= 0)
346  buf[m_clusterSeparation] = preclus.clusterSeparation();
347 
348  if (m_dRFromJet >= 0) {
349  const double deta = preclus.eta() - current.eta();
350  const double dphi = delPhi(preclus.phi(), current.phi());
351  buf[m_dRFromJet] = sqrt(deta * deta + dphi * dphi);
352  }
353 
354  if (m_LaplacianS1 >= 0) {
355  double h[3];
356  preclus.hessian(h);
357  buf[m_LaplacianS1] = fabs(h[0] + h[2]) * scale;
358  }
359 
360  if (m_LaplacianS2 >= 0) {
361  double h[3];
362  preclus.hessian(h);
363  buf[m_LaplacianS2] = fabs(h[0] + h[2]) * scale * scale;
364  }
365 
366  if (m_LaplacianS3 >= 0) {
367  double h[3];
368  preclus.hessian(h);
369  buf[m_LaplacianS3] = fabs(h[0] + h[2]) * scale * scale * scale;
370  }
371 
372  if (m_HessianS2 >= 0) {
373  double h[3];
374  preclus.hessian(h);
375  buf[m_HessianS2] = fabs(h[0] * h[2] - h[1] * h[1]) * scale * scale;
376  }
377 
378  if (m_HessianS4 >= 0) {
379  double h[3];
380  preclus.hessian(h);
381  buf[m_HessianS4] = fabs(h[0] * h[2] - h[1] * h[1]) * pow(scale, 4);
382  }
383 
384  if (m_HessianS6 >= 0) {
385  double h[3];
386  preclus.hessian(h);
387  buf[m_HessianS6] = fabs(h[0] * h[2] - h[1] * h[1]) * pow(scale, 6);
388  }
389 
390  // Variables from reco::Jet
391  if (m_nConstituents >= 0)
392  buf[m_nConstituents] = jet.nConstituents();
393 
394  if (m_aveConstituentPt >= 0)
395  buf[m_aveConstituentPt] = current.pt() / jet.nConstituents();
396 
397  if (m_logAveConstituentPt >= 0)
398  buf[m_logAveConstituentPt] = f_safeLog(current.pt() / jet.nConstituents());
399 
402 
403  if (m_constituentEtaPhiSpread >= 0)
405 
406  // Variables from reco::PFJet
407  const reco::PFJet* pfjet = dynamic_cast<const reco::PFJet*>(&jet);
408  if (pfjet) {
409  // Particle flow jet
412 
415 
416  if (m_photonEnergyFraction >= 0)
418 
419  if (m_electronEnergyFraction >= 0)
421 
422  if (m_muonEnergyFraction >= 0)
424 
425  if (m_HFHadronEnergyFraction >= 0)
427 
428  if (m_HFEMEnergyFraction >= 0)
430 
433 
436 
437  if (m_photonMultiplicity >= 0)
439 
440  if (m_electronMultiplicity >= 0)
442 
443  if (m_muonMultiplicity >= 0)
444  buf[m_muonMultiplicity] = pfjet->muonMultiplicity();
445 
446  if (m_HFHadronMultiplicity >= 0)
448 
449  if (m_HFEMMultiplicity >= 0)
450  buf[m_HFEMMultiplicity] = pfjet->HFEMMultiplicity();
451 
452  if (m_chargedEmEnergyFraction >= 0)
454 
455  if (m_chargedMuEnergyFraction >= 0)
457 
458  if (m_neutralEmEnergyFraction >= 0)
460 
461  if (m_EmEnergyFraction >= 0)
463 
464  if (m_chargedMultiplicity >= 0)
466 
467  if (m_neutralMultiplicity >= 0)
469  } else {
470  // Not a particle flow jet
478  throw cms::Exception("FFTJetBadConfig") << "In FFTGenericScaleCalculator::mapFFTJet: "
479  << "this configuration is valid for particle flow jets only" << std::endl;
480  }
481 
482  // Apply the scaling factors
483  for (unsigned i = 0; i < dim; ++i)
484  buf[i] *= m_factors[i];
485 }
Real scale() const
Definition: PattRecoPeak.h:74
int photonMultiplicity() const
photonMultiplicity
Definition: PFJet.h:128
static std::vector< std::string > checklist log
float constituentEtaPhiSpread() const
Real eta() const
Definition: PattRecoPeak.h:66
Real phi() const
Definition: PattRecoPeak.h:67
Real f_convergenceDistance() const
Definition: FFTJet.h:84
float chargedHadronEnergyFraction() const
chargedHadronEnergyFraction
Definition: PFJet.h:97
Base class for all types of Jets.
Definition: Jet.h:20
Real mergeTime() const
Definition: PattRecoPeak.h:73
Real driftSpeed() const
Definition: PattRecoPeak.h:69
float HFEMEnergyFraction() const
HFEMEnergyFraction.
Definition: PFJet.h:121
assert(be >=bs)
int chargedMultiplicity() const
chargedMultiplicity
Definition: PFJet.h:152
float photonEnergyFraction() const
photonEnergyFraction
Definition: PFJet.h:105
Jets made from PFObjects.
Definition: PFJet.h:20
Real f_membershipFactor() const
Definition: FFTJet.h:87
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
static double delPhi(const double phi1, const double phi2)
float neutralEmEnergyFraction() const
neutralEmEnergyFraction
Definition: PFJet.h:149
FFTGenericScaleCalculator(const edm::ParameterSet &ps)
Real f_etSum() const
Definition: FFTJet.h:77
Real f_phiWidth() const
Definition: FFTJet.h:81
Real nearestNeighborDistance() const
Definition: PattRecoPeak.h:75
Real f_recoScale() const
Definition: FFTJet.h:85
Real lifetime() const
Definition: PattRecoPeak.h:71
T sqrt(T t)
Definition: SSEVec.h:19
Real splitTime() const
Definition: PattRecoPeak.h:72
void mapFFTJet(const reco::Jet &jet, const reco::FFTJet< float > &fftJet, const math::XYZTLorentzVector &current, double *buf, unsigned dim) const override
Real f_ncells() const
Definition: FFTJet.h:76
int neutralHadronMultiplicity() const
neutralHadronMultiplicity
Definition: PFJet.h:126
Real clusterSeparation() const
Definition: PattRecoPeak.h:77
float neutralHadronEnergyFraction() const
neutralHadronEnergyFraction
Definition: PFJet.h:101
int neutralMultiplicity() const
neutralMultiplicity
Definition: PFJet.h:154
#define M_PI
Real magSpeed() const
Definition: PattRecoPeak.h:70
const PattRecoPeak< Real > & f_precluster() const
Definition: FFTJet.h:73
Real f_etaWidth() const
Definition: FFTJet.h:80
float chargedEmEnergyFraction() const
chargedEmEnergyFraction
Definition: PFJet.h:141
float HFHadronEnergyFraction() const
HFHadronEnergyFraction.
Definition: PFJet.h:117
float electronEnergyFraction() const
electronEnergyFraction
Definition: PFJet.h:109
#define int_param(varname)
int chargedHadronMultiplicity() const
chargedHadronMultiplicity
Definition: PFJet.h:124
#define check_param(varname)
int muonMultiplicity() const
muonMultiplicity
Definition: PFJet.h:132
int HFEMMultiplicity() const
HFEMMultiplicity.
Definition: PFJet.h:136
float constituentPtDistribution() const
virtual int nConstituents() const
of constituents
Definition: Jet.h:65
Real clusterRadius() const
Definition: PattRecoPeak.h:76
Real f_etaPhiCorr() const
Definition: FFTJet.h:82
float chargedMuEnergyFraction() const
chargedMuEnergyFraction
Definition: PFJet.h:145
const math::XYZTLorentzVector & f_pileup() const
Definition: FFTJet.h:75
double f_safeLog(const double x) const
float muonEnergyFraction() const
muonEnergyFraction
Definition: PFJet.h:113
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
Real magnitude() const
Definition: PattRecoPeak.h:68
Real f_recoScaleRatio() const
Definition: FFTJet.h:86
int HFHadronMultiplicity() const
HFHadronMultiplicity.
Definition: PFJet.h:134
void hessian(double hessianArray[3]) const
Definition: PattRecoPeak.h:78
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
int electronMultiplicity() const
electronMultiplicity
Definition: PFJet.h:130
Real f_fuzziness() const
Definition: FFTJet.h:83