CMS 3D CMS Logo

FFTJetParameterParser.cc
Go to the documentation of this file.
1 #include <cstdlib>
2 #include <cstring>
3 #include <memory>
4 
5 #include <string>
6 #include <fstream>
7 
9 
16 
19 
20 #include "fftjet/PeakSelectors.hh"
21 #include "fftjet/Kernel2dFactory.hh"
22 #include "fftjet/GaussianNoiseMembershipFcn.hh"
23 #include "fftjet/EquidistantSequence.hh"
24 #include "fftjet/PeakEtaPhiDistance.hh"
25 #include "fftjet/PeakEtaDependentDistance.hh"
26 #include "fftjet/JetProperty.hh"
27 #include "fftjet/InterpolatedMembershipFcn.hh"
28 #include "fftjet/CompositeKernel.hh"
29 #include "fftjet/InterpolatedKernel.hh"
30 #include "fftjet/InterpolatedKernel3d.hh"
31 #include "fftjet/MagneticSmearingKernel.hh"
32 
33 #define make_param(type, varname) const type& varname(ps.getParameter<type>(#varname))
34 
35 using namespace fftjetcms;
36 
37 typedef fftjet::RecombinedJet<VectorLike> RecoFFTJet;
38 
39 static bool parse_peak_member_function(const char* fname, fftjet::JetProperty<fftjet::Peak>::JetMemberFunction* f) {
40  if (strcmp(fname, "eta") == 0)
41  *f = &fftjet::Peak::eta;
42  else if (strcmp(fname, "phi") == 0)
43  *f = &fftjet::Peak::phi;
44  else if (strcmp(fname, "magnitude") == 0)
45  *f = &fftjet::Peak::magnitude;
46  else if (strcmp(fname, "driftSpeed") == 0)
47  *f = &fftjet::Peak::driftSpeed;
48  else if (strcmp(fname, "magSpeed") == 0)
49  *f = &fftjet::Peak::magSpeed;
50  else if (strcmp(fname, "lifetime") == 0)
51  *f = &fftjet::Peak::lifetime;
52  else if (strcmp(fname, "mergeTime") == 0)
53  *f = &fftjet::Peak::mergeTime;
54  else if (strcmp(fname, "splitTime") == 0)
55  *f = &fftjet::Peak::splitTime;
56  else if (strcmp(fname, "scale") == 0)
58  else if (strcmp(fname, "nearestNeighborDistance") == 0)
59  *f = &fftjet::Peak::nearestNeighborDistance;
60  else if (strcmp(fname, "membershipFactor") == 0)
61  *f = &fftjet::Peak::membershipFactor;
62  else if (strcmp(fname, "recoScale") == 0)
63  *f = &fftjet::Peak::recoScale;
64  else if (strcmp(fname, "recoScaleRatio") == 0)
65  *f = &fftjet::Peak::recoScaleRatio;
66  else if (strcmp(fname, "laplacian") == 0)
67  *f = &fftjet::Peak::laplacian;
68  else if (strcmp(fname, "hessianDeterminant") == 0)
69  *f = &fftjet::Peak::hessianDeterminant;
70  else if (strcmp(fname, "clusterRadius") == 0)
71  *f = &fftjet::Peak::clusterRadius;
72  else if (strcmp(fname, "clusterSeparation") == 0)
73  *f = &fftjet::Peak::clusterSeparation;
74  else {
75  return false;
76  }
77  return true;
78 }
79 
80 static bool parse_jet_member_function(const char* fname, fftjet::JetProperty<RecoFFTJet>::JetMemberFunction* f) {
81  if (strcmp(fname, "peakEta") == 0)
82  *f = &RecoFFTJet::peakEta;
83  else if (strcmp(fname, "peakPhi") == 0)
84  *f = &RecoFFTJet::peakPhi;
85  else if (strcmp(fname, "peakMagnitude") == 0)
86  *f = &RecoFFTJet::peakMagnitude;
87  else if (strcmp(fname, "magnitude") == 0)
88  *f = &RecoFFTJet::magnitude;
89  else if (strcmp(fname, "driftSpeed") == 0)
90  *f = &RecoFFTJet::driftSpeed;
91  else if (strcmp(fname, "magSpeed") == 0)
92  *f = &RecoFFTJet::magSpeed;
93  else if (strcmp(fname, "lifetime") == 0)
94  *f = &RecoFFTJet::lifetime;
95  else if (strcmp(fname, "mergeTime") == 0)
96  *f = &RecoFFTJet::mergeTime;
97  else if (strcmp(fname, "splitTime") == 0)
98  *f = &RecoFFTJet::splitTime;
99  else if (strcmp(fname, "scale") == 0)
100  *f = &RecoFFTJet::scale;
101  else if (strcmp(fname, "nearestNeighborDistance") == 0)
102  *f = &RecoFFTJet::nearestNeighborDistance;
103  else if (strcmp(fname, "membershipFactor") == 0)
104  *f = &RecoFFTJet::membershipFactor;
105  else if (strcmp(fname, "recoScale") == 0)
106  *f = &RecoFFTJet::recoScale;
107  else if (strcmp(fname, "recoScaleRatio") == 0)
108  *f = &RecoFFTJet::recoScaleRatio;
109  else if (strcmp(fname, "laplacian") == 0)
110  *f = &RecoFFTJet::laplacian;
111  else if (strcmp(fname, "hessianDeterminant") == 0)
112  *f = &RecoFFTJet::hessianDeterminant;
113  else if (strcmp(fname, "clusterRadius") == 0)
114  *f = &RecoFFTJet::clusterRadius;
115  else if (strcmp(fname, "clusterSeparation") == 0)
116  *f = &RecoFFTJet::clusterSeparation;
117  else {
118  return false;
119  }
120  return true;
121 }
122 
123 namespace fftjetcms {
124 
125  std::unique_ptr<fftjet::Grid2d<Real>> fftjet_Grid2d_parser(const edm::ParameterSet& ps) {
126  typedef std::unique_ptr<fftjet::Grid2d<Real>> return_type;
127  fftjet::Grid2d<Real>* g = nullptr;
128 
129  // Check if the grid should be read from file
130  if (ps.exists("file")) {
131  const std::string file = ps.getParameter<std::string>("file");
132  std::ifstream in(file.c_str(), std::ios_base::in | std::ios_base::binary);
133  if (!in.is_open())
134  throw cms::Exception("FFTJetBadConfig") << "Failed to open file " << file << std::endl;
136  if (g == nullptr)
137  throw cms::Exception("FFTJetBadConfig") << "Failed to read file " << file << std::endl;
138  } else {
139  const unsigned nEtaBins = ps.getParameter<unsigned>("nEtaBins");
140  const Real etaMin = ps.getParameter<Real>("etaMin");
141  const Real etaMax = ps.getParameter<Real>("etaMax");
142  const unsigned nPhiBins = ps.getParameter<unsigned>("nPhiBins");
143  const Real phiBin0Edge = ps.getParameter<Real>("phiBin0Edge");
144  const std::string& title = ps.getUntrackedParameter<std::string>("title", "");
145 
146  if (nEtaBins == 0 || nPhiBins == 0 || etaMin >= etaMax)
147  return return_type(nullptr);
148 
149  g = new fftjet::Grid2d<Real>(nEtaBins, etaMin, etaMax, nPhiBins, phiBin0Edge, title.c_str());
150 
151  // Check if the grid data is provided
152  if (ps.exists("data")) {
153  const std::vector<Real>& data = ps.getParameter<std::vector<Real>>("data");
154  if (data.size() == nEtaBins * nPhiBins)
155  g->blockSet(&data[0], nEtaBins, nPhiBins);
156  else {
157  delete g;
158  g = nullptr;
159  }
160  }
161  }
162 
163  return return_type(g);
164  }
165 
166  std::unique_ptr<fftjet::Functor1<bool, fftjet::Peak>> fftjet_PeakSelector_parser(const edm::ParameterSet& ps) {
167  typedef std::unique_ptr<fftjet::Functor1<bool, fftjet::Peak>> return_type;
168 
169  const std::string peakselector_type = ps.getParameter<std::string>("Class");
170 
171  if (!peakselector_type.compare("AllPeaksPass")) {
172  return return_type(new fftjet::AllPeaksPass());
173  }
174 
175  if (!peakselector_type.compare("EtaAndPtDependentPeakSelector")) {
176  const std::string file = ps.getParameter<std::string>("file");
177  std::ifstream in(file.c_str(), std::ios_base::in | std::ios_base::binary);
178  if (!in.is_open())
179  throw cms::Exception("FFTJetBadConfig") << "Failed to open file " << file << std::endl;
181  if (!ptr->isValid())
182  throw cms::Exception("FFTJetBadConfig") << "Failed to read file " << file << std::endl;
183  return return_type(ptr);
184  }
185 
186  if (!peakselector_type.compare("EtaAndPtLookupPeakSelector")) {
187  make_param(unsigned, nx);
188  make_param(unsigned, ny);
189  make_param(double, xmin);
190  make_param(double, xmax);
191  make_param(double, ymin);
192  make_param(double, ymax);
193  make_param(std::vector<double>, data);
194 
195  if (xmin >= xmax || ymin >= ymax || !nx || !ny || data.size() != nx * ny)
196  throw cms::Exception("FFTJetBadConfig") << "Failed to configure EtaAndPtLookupPeakSelector" << std::endl;
197 
198  return return_type(new EtaAndPtLookupPeakSelector(nx, xmin, xmax, ny, ymin, ymax, data));
199  }
200 
201  if (!peakselector_type.compare("SimplePeakSelector")) {
202  const double magCut = ps.getParameter<double>("magCut");
203  const double driftSpeedCut = ps.getParameter<double>("driftSpeedCut");
204  const double magSpeedCut = ps.getParameter<double>("magSpeedCut");
205  const double lifeTimeCut = ps.getParameter<double>("lifeTimeCut");
206  const double NNDCut = ps.getParameter<double>("NNDCut");
207  const double etaCut = ps.getParameter<double>("etaCut");
208  const double splitTimeCut = ps.getParameter<double>("splitTimeCut");
209  const double mergeTimeCut = ps.getParameter<double>("mergeTimeCut");
210 
211  return return_type(new fftjet::SimplePeakSelector(
213  }
214 
215  if (!peakselector_type.compare("ScalePowerPeakSelector")) {
216  const double a = ps.getParameter<double>("a");
217  const double p = ps.getParameter<double>("p");
218  const double b = ps.getParameter<double>("b");
219  const double etaCut = ps.getParameter<double>("etaCut");
220 
221  return return_type(new fftjet::ScalePowerPeakSelector(a, p, b, etaCut));
222  }
223 
224  return return_type(nullptr);
225  }
226 
227  std::unique_ptr<fftjet::ScaleSpaceKernel> fftjet_MembershipFunction_parser(const edm::ParameterSet& ps) {
228  typedef std::unique_ptr<fftjet::ScaleSpaceKernel> return_type;
229 
230  const std::string MembershipFunction_type = ps.getParameter<std::string>("Class");
231 
232  // Parse special cases first
233  if (!MembershipFunction_type.compare("InterpolatedMembershipFcn")) {
234  // This is a kernel defined by a 4d (sparsified) lookup table.
235  // Here, it is simply loaded from a file using a built-in
236  // method from fftjet. Note that the table representation
237  // must be native binary (this will not work on platforms with
238  // different endianity of floating point standard).
239  const std::string file = ps.getParameter<std::string>("file");
240  std::ifstream in(file.c_str(), std::ios_base::in | std::ios_base::binary);
241  if (!in.is_open())
242  throw cms::Exception("FFTJetBadConfig") << "Failed to open file " << file << std::endl;
244  }
245 
246  if (!MembershipFunction_type.compare("Composite")) {
247  throw cms::Exception("FFTJetBadConfig")
248  << "Parsing of CompositeKernel objects is not implemented yet" << std::endl;
249  }
250 
251  if (!MembershipFunction_type.compare("MagneticSmearing")) {
252  // This kernel represents smearing of a jet in phi
253  // in a magnetic field. The meaning of the parameters
254  // is explained in the comments in the MagneticSmearingKernel.hh
255  // header file of the fftjet package.
256  make_param(std::vector<double>, fragmentationData);
257  make_param(double, numeratorConst);
258  make_param(double, charge1Fraction);
259  make_param(double, charge2Fraction);
260  make_param(unsigned, samplesPerBin);
261 
262  if (fragmentationData.empty())
263  throw cms::Exception("FFTJetBadConfig") << "Fragmentation function data not defined for "
264  "MagneticSmearingKernel"
265  << std::endl;
266  if (samplesPerBin < 1U)
267  throw cms::Exception("FFTJetBadConfig") << "Bad number of samples per bin in "
268  "MagneticSmearingKernel"
269  << std::endl;
270 
271  fftjet::LinearInterpolator1d* fragmentationFunction =
272  new fftjet::LinearInterpolator1d(&fragmentationData[0], fragmentationData.size(), 0.0, 1.0);
273 
274  return return_type(new fftjet::MagneticSmearingKernel<fftjet::LinearInterpolator1d>(
275  fragmentationFunction, numeratorConst, charge1Fraction, charge2Fraction, samplesPerBin, true));
276  }
277 
278  if (!MembershipFunction_type.compare("Interpolated")) {
279  // This is a kernel defined by a histogram-like 2d lookup table
280  make_param(double, sx);
281  make_param(double, sy);
282  make_param(int, scalePower);
283  make_param(unsigned, nxbins);
284  make_param(double, xmin);
285  make_param(double, xmax);
286  make_param(unsigned, nybins);
287  make_param(double, ymin);
288  make_param(double, ymax);
289  make_param(std::vector<double>, data);
290 
291  if (data.size() != nxbins * nybins)
292  throw cms::Exception("FFTJetBadConfig") << "Bad number of data points for Interpolated kernel" << std::endl;
293 
294  return return_type(
295  new fftjet::InterpolatedKernel(sx, sy, scalePower, &data[0], nxbins, xmin, xmax, nybins, ymin, ymax));
296  }
297 
298  if (!MembershipFunction_type.compare("Interpolated3d")) {
299  // This is a kernel defined by a histogram-like 3d lookup table
300  make_param(std::vector<double>, data);
301  make_param(std::vector<double>, scales);
302  make_param(bool, useLogSpaceForScale);
303  make_param(unsigned, nxbins);
304  make_param(double, xmin);
305  make_param(double, xmax);
306  make_param(unsigned, nybins);
307  make_param(double, ymin);
308  make_param(double, ymax);
309 
310  if (data.size() != nxbins * nybins * scales.size())
311  throw cms::Exception("FFTJetBadConfig") << "Bad number of data points for Interpolated3d kernel" << std::endl;
312 
313  return return_type(new fftjet::InterpolatedKernel3d(
314  &data[0], scales, useLogSpaceForScale, nxbins, xmin, xmax, nybins, ymin, ymax));
315  }
316 
317  // This is not a special kernel. Try one of the classes
318  // in the kernel factory provided by FFTJet.
319  fftjet::DefaultKernel2dFactory factory;
320  if (factory[MembershipFunction_type] == nullptr) {
321  return return_type(nullptr);
322  }
323 
324  make_param(double, sx);
325  make_param(double, sy);
326  make_param(int, scalePower);
327  make_param(std::vector<double>, kernelParameters);
328 
329  const int n_expected = factory[MembershipFunction_type]->nParameters();
330  if (n_expected >= 0)
331  if (static_cast<unsigned>(n_expected) != kernelParameters.size())
332  throw cms::Exception("FFTJetBadConfig") << "Bad number of kernel parameters" << std::endl;
333 
334  return std::unique_ptr<fftjet::ScaleSpaceKernel>(
335  factory[MembershipFunction_type]->create(sx, sy, scalePower, kernelParameters));
336  }
337 
338  std::unique_ptr<AbsBgFunctor> fftjet_BgFunctor_parser(const edm::ParameterSet& ps) {
339  const std::string bg_Membership_type = ps.getParameter<std::string>("Class");
340 
341  if (!bg_Membership_type.compare("GaussianNoiseMembershipFcn")) {
342  const double minWeight = ps.getParameter<double>("minWeight");
343  const double prior = ps.getParameter<double>("prior");
344  return std::unique_ptr<AbsBgFunctor>(new fftjet::GaussianNoiseMembershipFcn(minWeight, prior));
345  }
346 
347  return std::unique_ptr<AbsBgFunctor>(nullptr);
348  }
349 
350  std::unique_ptr<std::vector<double>> fftjet_ScaleSet_parser(const edm::ParameterSet& ps) {
351  typedef std::unique_ptr<std::vector<double>> return_type;
352 
353  const std::string className = ps.getParameter<std::string>("Class");
354 
355  if (!className.compare("EquidistantInLinearSpace") || !className.compare("EquidistantInLogSpace")) {
356  const double minScale = ps.getParameter<double>("minScale");
357  const double maxScale = ps.getParameter<double>("maxScale");
358  const unsigned nScales = ps.getParameter<unsigned>("nScales");
359 
360  if (minScale <= 0.0 || maxScale <= 0.0 || nScales == 0 || minScale == maxScale)
361  return return_type(nullptr);
362 
363  // Can't return pointers to EquidistantInLinearSpace
364  // or EquidistantInLogSpace directly because std::vector
365  // destructor is not virtual.
366  if (!className.compare("EquidistantInLinearSpace"))
367  return std::make_unique<std::vector<double>>(fftjet::EquidistantInLinearSpace(minScale, maxScale, nScales));
368  else
369  return std::make_unique<std::vector<double>>(fftjet::EquidistantInLogSpace(minScale, maxScale, nScales));
370  }
371 
372  if (!className.compare("UserSet")) {
373  return_type scales(new std::vector<double>(ps.getParameter<std::vector<double>>("scales")));
374 
375  // Verify that all scales are positive and unique
376  const unsigned nscales = scales->size();
377  for (unsigned i = 0; i < nscales; ++i)
378  if ((*scales)[i] <= 0.0)
379  return return_type(nullptr);
380 
381  for (unsigned i = 1; i < nscales; ++i)
382  for (unsigned j = 0; j < i; ++j)
383  if ((*scales)[i] == (*scales)[j])
384  return return_type(nullptr);
385 
386  return scales;
387  }
388 
389  return return_type(nullptr);
390  }
391 
392  std::unique_ptr<fftjet::ClusteringTreeSparsifier<fftjet::Peak, long>> fftjet_ClusteringTreeSparsifier_parser(
393  const edm::ParameterSet& ps) {
394  const int maxLevelNumber = ps.getParameter<int>("maxLevelNumber");
395  const unsigned filterMask = ps.getParameter<unsigned>("filterMask");
396  const std::vector<double> userScalesV = ps.getParameter<std::vector<double>>("userScales");
397  const unsigned nUserScales = userScalesV.size();
398  const double* userScales = nUserScales ? &userScalesV[0] : nullptr;
399 
400  return std::make_unique<fftjet::ClusteringTreeSparsifier<fftjet::Peak, long>>(
401  maxLevelNumber, filterMask, userScales, nUserScales);
402  }
403 
404  std::unique_ptr<fftjet::AbsDistanceCalculator<fftjet::Peak>> fftjet_DistanceCalculator_parser(
405  const edm::ParameterSet& ps) {
406  typedef std::unique_ptr<fftjet::AbsDistanceCalculator<fftjet::Peak>> return_type;
407 
408  const std::string calc_type = ps.getParameter<std::string>("Class");
409 
410  if (!calc_type.compare("PeakEtaPhiDistance")) {
411  const double etaToPhiBandwidthRatio = ps.getParameter<double>("etaToPhiBandwidthRatio");
412  return return_type(new fftjet::PeakEtaPhiDistance(etaToPhiBandwidthRatio));
413  }
414 
415  if (!calc_type.compare("PeakEtaDependentDistance")) {
416  std::unique_ptr<fftjet::LinearInterpolator1d> interp =
418  const fftjet::LinearInterpolator1d* ip = interp.get();
419  if (ip == nullptr)
420  return return_type(nullptr);
421 
422  // Check that the interpolator is always positive
423  const unsigned n = ip->nx();
424  const double* data = ip->getData();
425  for (unsigned i = 0; i < n; ++i)
426  if (data[i] <= 0.0)
427  return return_type(nullptr);
428  if (ip->fLow() <= 0.0 || ip->fHigh() <= 0.0)
429  return return_type(nullptr);
430 
431  return return_type(new fftjet::PeakEtaDependentDistance(*ip));
432  }
433 
434  return return_type(nullptr);
435  }
436 
437  std::unique_ptr<fftjetcms::LinInterpolatedTable1D> fftjet_LinInterpolatedTable1D_parser(const edm::ParameterSet& ps) {
438  const double xmin = ps.getParameter<double>("xmin");
439  const double xmax = ps.getParameter<double>("xmax");
440  const bool leftExtrapolationLinear = ps.getParameter<bool>("leftExtrapolationLinear");
441  const bool rightExtrapolationLinear = ps.getParameter<bool>("rightExtrapolationLinear");
442  const std::vector<double> data(ps.getParameter<std::vector<double>>("data"));
443  if (data.empty())
444  return std::unique_ptr<fftjetcms::LinInterpolatedTable1D>(nullptr);
445  else
446  return std::make_unique<fftjetcms::LinInterpolatedTable1D>(
448  }
449 
450  std::unique_ptr<fftjet::LinearInterpolator1d> fftjet_LinearInterpolator1d_parser(const edm::ParameterSet& ps) {
451  const double xmin = ps.getParameter<double>("xmin");
452  const double xmax = ps.getParameter<double>("xmax");
453  const double flow = ps.getParameter<double>("flow");
454  const double fhigh = ps.getParameter<double>("fhigh");
455  const std::vector<double> data(ps.getParameter<std::vector<double>>("data"));
456  if (data.empty())
457  return std::unique_ptr<fftjet::LinearInterpolator1d>(nullptr);
458  else
459  return std::make_unique<fftjet::LinearInterpolator1d>(&data[0], data.size(), xmin, xmax, flow, fhigh);
460  }
461 
462  std::unique_ptr<fftjet::LinearInterpolator2d> fftjet_LinearInterpolator2d_parser(const edm::ParameterSet& ps) {
463  const std::string file = ps.getParameter<std::string>("file");
464  std::ifstream in(file.c_str(), std::ios_base::in | std::ios_base::binary);
465  if (!in.is_open())
466  throw cms::Exception("FFTJetBadConfig") << "Failed to open file " << file << std::endl;
467  fftjet::LinearInterpolator2d* ip = fftjet::LinearInterpolator2d::read(in);
468  if (!ip)
469  throw cms::Exception("FFTJetBadConfig") << "Failed to read file " << file << std::endl;
470  return std::unique_ptr<fftjet::LinearInterpolator2d>(ip);
471  }
472 
473  std::unique_ptr<fftjet::Functor1<double, fftjet::Peak>> fftjet_PeakFunctor_parser(const edm::ParameterSet& ps) {
474  typedef fftjet::Functor1<double, fftjet::Peak> ptr_type;
475  typedef std::unique_ptr<ptr_type> return_type;
476 
477  const std::string property_type = ps.getParameter<std::string>("Class");
478 
479  if (!property_type.compare("Log")) {
480  return_type wrapped = fftjet_PeakFunctor_parser(ps.getParameter<edm::ParameterSet>("function"));
481  ptr_type* wr = wrapped.get();
482  if (wr) {
483  return_type result = return_type(new fftjet::LogProperty<fftjet::Peak>(wr, true));
484  wrapped.release();
485  return result;
486  }
487  }
488 
489  if (!property_type.compare("PeakProperty")) {
490  const std::string member = ps.getParameter<std::string>("member");
491  fftjet::JetProperty<fftjet::Peak>::JetMemberFunction fcn;
492  if (parse_peak_member_function(member.c_str(), &fcn))
493  return return_type(new fftjet::JetProperty<fftjet::Peak>(fcn));
494  else
495  return return_type(nullptr);
496  }
497 
498  if (!property_type.compare("MinusScaledLaplacian")) {
499  const double sx = ps.getParameter<double>("sx");
500  const double sy = ps.getParameter<double>("sx");
501  return return_type(new fftjet::MinusScaledLaplacian<fftjet::Peak>(sx, sy));
502  }
503 
504  if (!property_type.compare("ScaledHessianDet")) {
505  return return_type(new fftjet::ScaledHessianDet<fftjet::Peak>());
506  }
507 
508  if (!property_type.compare("ScaledMagnitude")) {
509  return return_type(new fftjet::ScaledMagnitude<fftjet::Peak>());
510  }
511 
512  if (!property_type.compare("ScaledMagnitude2")) {
513  return return_type(new fftjet::ScaledMagnitude2<fftjet::Peak>());
514  }
515 
516  if (!property_type.compare("ConstDouble")) {
517  const double value = ps.getParameter<double>("value");
518  return return_type(new ConstDouble<fftjet::Peak>(value));
519  }
520 
521  if (!property_type.compare("ProportionalToScale")) {
522  const double value = ps.getParameter<double>("value");
523  return return_type(new ProportionalToScale<fftjet::Peak>(value));
524  }
525 
526  if (!property_type.compare("MultiplyByConst")) {
527  const double factor = ps.getParameter<double>("factor");
528  return_type function = fftjet_PeakFunctor_parser(ps.getParameter<edm::ParameterSet>("function"));
529  ptr_type* ptr = function.get();
530  if (ptr) {
531  return_type result = return_type(new MultiplyByConst<fftjet::Peak>(factor, ptr, true));
532  function.release();
533  return result;
534  }
535  }
536 
537  if (!property_type.compare("CompositeFunctor")) {
538  std::unique_ptr<fftjet::Functor1<double, double>> fcn1 =
540  return_type fcn2 = fftjet_PeakFunctor_parser(ps.getParameter<edm::ParameterSet>("function2"));
541  fftjet::Functor1<double, double>* f1 = fcn1.get();
542  ptr_type* f2 = fcn2.get();
543  if (f1 && f2) {
544  return_type result = return_type(new CompositeFunctor<fftjet::Peak>(f1, f2, true));
545  fcn1.release();
546  fcn2.release();
547  return result;
548  }
549  }
550 
551  if (!property_type.compare("ProductFunctor")) {
552  return_type fcn1 = fftjet_PeakFunctor_parser(ps.getParameter<edm::ParameterSet>("function1"));
553  return_type fcn2 = fftjet_PeakFunctor_parser(ps.getParameter<edm::ParameterSet>("function2"));
554  ptr_type* f1 = fcn1.get();
555  ptr_type* f2 = fcn2.get();
556  if (f1 && f2) {
557  return_type result = return_type(new ProductFunctor<fftjet::Peak>(f1, f2, true));
558  fcn1.release();
559  fcn2.release();
560  return result;
561  }
562  }
563 
564  if (!property_type.compare("MagnitudeDependent")) {
565  std::unique_ptr<fftjet::Functor1<double, double>> fcn1 =
567  fftjet::Functor1<double, double>* f1 = fcn1.get();
568  if (f1) {
569  return_type result = return_type(new MagnitudeDependent<fftjet::Peak>(f1, true));
570  fcn1.release();
571  return result;
572  }
573  }
574 
575  if (!property_type.compare("PeakEtaDependent")) {
576  std::unique_ptr<fftjet::Functor1<double, double>> fcn1 =
578  fftjet::Functor1<double, double>* f1 = fcn1.get();
579  if (f1) {
580  return_type result = return_type(new PeakEtaDependent(f1, true));
581  fcn1.release();
582  return result;
583  }
584  }
585 
586  return return_type(nullptr);
587  }
588 
589  std::unique_ptr<fftjet::Functor1<double, fftjet::RecombinedJet<VectorLike>>> fftjet_JetFunctor_parser(
590  const edm::ParameterSet& ps) {
591  typedef fftjet::Functor1<double, RecoFFTJet> ptr_type;
592  typedef std::unique_ptr<ptr_type> return_type;
593 
594  const std::string property_type = ps.getParameter<std::string>("Class");
595 
596  if (!property_type.compare("Log")) {
597  return_type wrapped = fftjet_JetFunctor_parser(ps.getParameter<edm::ParameterSet>("function"));
598  fftjet::Functor1<double, RecoFFTJet>* wr = wrapped.get();
599  if (wr) {
600  return_type result = return_type(new fftjet::LogProperty<RecoFFTJet>(wr, true));
601  wrapped.release();
602  return result;
603  }
604  }
605 
606  if (!property_type.compare("JetEtaDependent")) {
607  std::unique_ptr<fftjet::Functor1<double, double>> fcn1 =
609  fftjet::Functor1<double, double>* f1 = fcn1.get();
610  if (f1) {
611  return_type result = return_type(new JetEtaDependent(f1, true));
612  fcn1.release();
613  return result;
614  }
615  }
616 
617  if (!property_type.compare("JetProperty")) {
618  const std::string member = ps.getParameter<std::string>("member");
619  fftjet::JetProperty<RecoFFTJet>::JetMemberFunction fcn;
620  if (parse_jet_member_function(member.c_str(), &fcn))
621  return return_type(new fftjet::JetProperty<RecoFFTJet>(fcn));
622  else
623  return return_type(nullptr);
624  }
625 
626  if (!property_type.compare("ConstDouble")) {
627  const double value = ps.getParameter<double>("value");
628  return return_type(new ConstDouble<RecoFFTJet>(value));
629  }
630 
631  if (!property_type.compare("ProportionalToScale")) {
632  const double value = ps.getParameter<double>("value");
633  return return_type(new ProportionalToScale<RecoFFTJet>(value));
634  }
635 
636  if (!property_type.compare("MultiplyByConst")) {
637  const double factor = ps.getParameter<double>("factor");
638  return_type function = fftjet_JetFunctor_parser(ps.getParameter<edm::ParameterSet>("function"));
639  ptr_type* ptr = function.get();
640  if (ptr) {
641  return_type result = return_type(new MultiplyByConst<RecoFFTJet>(factor, ptr, true));
642  function.release();
643  return result;
644  }
645  }
646 
647  if (!property_type.compare("CompositeFunctor")) {
648  std::unique_ptr<fftjet::Functor1<double, double>> fcn1 =
650  return_type fcn2 = fftjet_JetFunctor_parser(ps.getParameter<edm::ParameterSet>("function2"));
651  fftjet::Functor1<double, double>* f1 = fcn1.get();
652  ptr_type* f2 = fcn2.get();
653  if (f1 && f2) {
654  return_type result = return_type(new CompositeFunctor<RecoFFTJet>(f1, f2, true));
655  fcn1.release();
656  fcn2.release();
657  return result;
658  }
659  }
660 
661  if (!property_type.compare("ProductFunctor")) {
662  return_type fcn1 = fftjet_JetFunctor_parser(ps.getParameter<edm::ParameterSet>("function1"));
663  return_type fcn2 = fftjet_JetFunctor_parser(ps.getParameter<edm::ParameterSet>("function2"));
664  ptr_type* f1 = fcn1.get();
665  ptr_type* f2 = fcn2.get();
666  if (f1 && f2) {
667  return_type result = return_type(new ProductFunctor<RecoFFTJet>(f1, f2, true));
668  fcn1.release();
669  fcn2.release();
670  return result;
671  }
672  }
673 
674  if (!property_type.compare("MagnitudeDependent")) {
675  std::unique_ptr<fftjet::Functor1<double, double>> fcn1 =
677  fftjet::Functor1<double, double>* f1 = fcn1.get();
678  if (f1) {
679  return_type result = return_type(new MagnitudeDependent<RecoFFTJet>(f1, true));
680  fcn1.release();
681  return result;
682  }
683  }
684 
685  return return_type(nullptr);
686  }
687 
688  std::unique_ptr<fftjet::Functor2<double, fftjet::RecombinedJet<VectorLike>, fftjet::RecombinedJet<VectorLike>>>
690  typedef std::unique_ptr<
691  fftjet::Functor2<double, fftjet::RecombinedJet<VectorLike>, fftjet::RecombinedJet<VectorLike>>>
692  return_type;
693 
694  const std::string distance_type = ps.getParameter<std::string>("Class");
695 
696  if (!distance_type.compare("JetConvergenceDistance")) {
699 
700  if (etaToPhiBandwidthRatio > 0.0 && relativePtBandwidth > 0.0)
702  }
703 
704  return return_type(nullptr);
705  }
706 
707  std::unique_ptr<fftjet::Functor1<double, double>> fftjet_Function_parser(const edm::ParameterSet& ps) {
708  typedef std::unique_ptr<fftjet::Functor1<double, double>> return_type;
709 
710  const std::string fcn_type = ps.getParameter<std::string>("Class");
711 
712  if (!fcn_type.compare("LinearInterpolator1d")) {
713  std::unique_ptr<fftjet::LinearInterpolator1d> p = fftjet_LinearInterpolator1d_parser(ps);
714  fftjet::LinearInterpolator1d* ptr = p.get();
715  if (ptr) {
716  p.release();
717  return return_type(ptr);
718  }
719  }
720 
721  if (!fcn_type.compare("LinInterpolatedTable1D")) {
722  std::unique_ptr<fftjetcms::LinInterpolatedTable1D> p = fftjet_LinInterpolatedTable1D_parser(ps);
724  if (ptr) {
725  p.release();
726  return return_type(ptr);
727  }
728  }
729 
730  if (!fcn_type.compare("Polynomial")) {
731  std::vector<double> coeffs;
732  for (unsigned i = 0;; ++i) {
733  std::ostringstream s;
734  s << 'c' << i;
735  if (ps.exists(s.str()))
736  coeffs.push_back(ps.getParameter<double>(s.str()));
737  else
738  break;
739  }
740  return return_type(new Polynomial(coeffs));
741  }
742 
743  return return_type(nullptr);
744  }
745 
746  std::unique_ptr<AbsPileupCalculator> fftjet_PileupCalculator_parser(const edm::ParameterSet& ps) {
747  typedef std::unique_ptr<AbsPileupCalculator> return_type;
748 
749  const std::string fcn_type = ps.getParameter<std::string>("Class");
750 
751  if (!fcn_type.compare("EtaDependentPileup")) {
752  std::unique_ptr<fftjet::LinearInterpolator2d> interp =
754  const double inputRhoFactor = ps.getParameter<double>("inputRhoFactor");
755  const double outputRhoFactor = ps.getParameter<double>("outputRhoFactor");
756 
757  const fftjet::LinearInterpolator2d* ip = interp.get();
758  if (ip)
759  return return_type(new EtaDependentPileup(*ip, inputRhoFactor, outputRhoFactor));
760  else
761  return return_type(nullptr);
762  }
763 
764  if (!fcn_type.compare("PileupGrid2d")) {
765  std::unique_ptr<fftjet::Grid2d<Real>> grid = fftjet_Grid2d_parser(ps.getParameter<edm::ParameterSet>("Grid2d"));
766  const double rhoFactor = ps.getParameter<double>("rhoFactor");
767 
768  const fftjet::Grid2d<Real>* g = grid.get();
769  if (g)
770  return return_type(new PileupGrid2d(*g, rhoFactor));
771  else
772  return return_type(nullptr);
773  }
774 
775  return return_type(nullptr);
776  }
777 
778  std::unique_ptr<fftjet::JetMagnitudeMapper2d<fftjet::Peak>> fftjet_PeakMagnitudeMapper2d_parser(
779  const edm::ParameterSet& ps) {
780  std::unique_ptr<fftjet::LinearInterpolator2d> responseCurve =
782 
783  const double minPredictor = ps.getParameter<double>("minPredictor");
784  const double maxPredictor = ps.getParameter<double>("maxPredictor");
785  const unsigned nPredPoints = ps.getParameter<unsigned>("nPredPoints");
786  const double maxMagnitude = ps.getParameter<double>("maxMagnitude");
787  const unsigned nMagPoints = ps.getParameter<unsigned>("nMagPoints");
788 
789  return (std::make_unique<fftjet::JetMagnitudeMapper2d<fftjet::Peak>>(*responseCurve,
791  true,
792  minPredictor,
793  maxPredictor,
794  nPredPoints,
795  maxMagnitude,
796  nMagPoints));
797  }
798 
799  std::unique_ptr<fftjet::JetMagnitudeMapper2d<fftjet::RecombinedJet<VectorLike>>> fftjet_JetMagnitudeMapper2d_parser(
800  const edm::ParameterSet& ps) {
801  std::unique_ptr<fftjet::LinearInterpolator2d> responseCurve =
803 
804  const double minPredictor = ps.getParameter<double>("minPredictor");
805  const double maxPredictor = ps.getParameter<double>("maxPredictor");
806  const unsigned nPredPoints = ps.getParameter<unsigned>("nPredPoints");
807  const double maxMagnitude = ps.getParameter<double>("maxMagnitude");
808  const unsigned nMagPoints = ps.getParameter<unsigned>("nMagPoints");
809 
810  return (std::make_unique<fftjet::JetMagnitudeMapper2d<RecoFFTJet>>(*responseCurve,
812  true,
813  minPredictor,
814  maxPredictor,
815  nPredPoints,
816  maxMagnitude,
817  nMagPoints));
818  }
819 
820 } // namespace fftjetcms
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::unique_ptr< fftjetcms::LinInterpolatedTable1D > fftjet_LinInterpolatedTable1D_parser(const edm::ParameterSet &ps)
std::unique_ptr< fftjet::Functor1< double, fftjet::Peak > > fftjet_PeakFunctor_parser(const edm::ParameterSet &ps)
std::unique_ptr< fftjet::LinearInterpolator2d > fftjet_LinearInterpolator2d_parser(const edm::ParameterSet &ps)
std::unique_ptr< AbsBgFunctor > fftjet_BgFunctor_parser(const edm::ParameterSet &ps)
std::unique_ptr< fftjet::Grid2d< Real > > fftjet_Grid2d_parser(const edm::ParameterSet &ps)
std::unique_ptr< fftjet::JetMagnitudeMapper2d< fftjet::Peak > > fftjet_PeakMagnitudeMapper2d_parser(const edm::ParameterSet &ps)
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
std::unique_ptr< fftjet::Functor2< double, fftjet::RecombinedJet< VectorLike >, fftjet::RecombinedJet< VectorLike > > > fftjet_JetDistance_parser(const edm::ParameterSet &ps)
T getUntrackedParameter(std::string const &, T const &) const
fftjet::RecombinedJet< VectorLike > RecoFFTJet
std::unique_ptr< fftjet::JetMagnitudeMapper2d< fftjet::RecombinedJet< VectorLike > > > fftjet_JetMagnitudeMapper2d_parser(const edm::ParameterSet &ps)
std::unique_ptr< fftjet::Functor1< double, fftjet::RecombinedJet< VectorLike > > > fftjet_JetFunctor_parser(const edm::ParameterSet &ps)
static bool parse_peak_member_function(const char *fname, fftjet::JetProperty< fftjet::Peak >::JetMemberFunction *f)
double f[11][100]
Definition: value.py:1
#define make_param(type, varname)
std::unique_ptr< fftjet::AbsDistanceCalculator< fftjet::Peak > > fftjet_DistanceCalculator_parser(const edm::ParameterSet &ps)
std::unique_ptr< AbsPileupCalculator > fftjet_PileupCalculator_parser(const edm::ParameterSet &ps)
std::unique_ptr< fftjet::Functor1< double, double > > fftjet_Function_parser(const edm::ParameterSet &ps)
double Real
void fcn(int &, double *, double &, double *, int)
double b
Definition: hdecay.h:120
string fname
main script
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
static constexpr int nPhiBins
double a
Definition: hdecay.h:121
std::unique_ptr< fftjet::Functor1< bool, fftjet::Peak > > fftjet_PeakSelector_parser(const edm::ParameterSet &ps)
static bool parse_jet_member_function(const char *fname, fftjet::JetProperty< RecoFFTJet >::JetMemberFunction *f)
std::unique_ptr< fftjet::ClusteringTreeSparsifier< fftjet::Peak, long > > fftjet_ClusteringTreeSparsifier_parser(const edm::ParameterSet &ps)
std::unique_ptr< std::vector< double > > fftjet_ScaleSet_parser(const edm::ParameterSet &ps)
std::unique_ptr< fftjet::LinearInterpolator1d > fftjet_LinearInterpolator1d_parser(const edm::ParameterSet &ps)
std::string className(const T &t)
Definition: ClassName.h:31
std::unique_ptr< fftjet::ScaleSpaceKernel > fftjet_MembershipFunction_parser(const edm::ParameterSet &ps)