CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FFTJetParameterParser.cc
Go to the documentation of this file.
1 #include <cstdlib>
2 #include <cstring>
3 #include <string>
4 #include <fstream>
5 
7 
14 
17 
18 #include "fftjet/PeakSelectors.hh"
19 #include "fftjet/Kernel2dFactory.hh"
20 #include "fftjet/GaussianNoiseMembershipFcn.hh"
21 #include "fftjet/EquidistantSequence.hh"
22 #include "fftjet/PeakEtaPhiDistance.hh"
23 #include "fftjet/PeakEtaDependentDistance.hh"
24 #include "fftjet/JetProperty.hh"
25 #include "fftjet/InterpolatedMembershipFcn.hh"
26 #include "fftjet/CompositeKernel.hh"
27 #include "fftjet/InterpolatedKernel.hh"
28 #include "fftjet/InterpolatedKernel3d.hh"
29 #include "fftjet/MagneticSmearingKernel.hh"
30 
31 #define make_param(type, varname) const \
32  type & varname (ps.getParameter< type >( #varname ))
33 
34 using namespace fftjetcms;
35 
36 typedef fftjet::RecombinedJet<VectorLike> RecoFFTJet;
37 
38 static bool parse_peak_member_function(const char* fname,
39  fftjet::JetProperty<fftjet::Peak>::JetMemberFunction *f)
40 {
41  if (strcmp(fname, "eta") == 0)
42  *f = &fftjet::Peak::eta;
43  else if (strcmp(fname, "phi") == 0)
44  *f = &fftjet::Peak::phi;
45  else if (strcmp(fname, "magnitude") == 0)
46  *f = &fftjet::Peak::magnitude;
47  else if (strcmp(fname, "driftSpeed") == 0)
48  *f = &fftjet::Peak::driftSpeed;
49  else if (strcmp(fname, "magSpeed") == 0)
50  *f = &fftjet::Peak::magSpeed;
51  else if (strcmp(fname, "lifetime") == 0)
52  *f = &fftjet::Peak::lifetime;
53  else if (strcmp(fname, "scale") == 0)
54  *f = &fftjet::Peak::scale;
55  else if (strcmp(fname, "nearestNeighborDistance") == 0)
56  *f = &fftjet::Peak::nearestNeighborDistance;
57  else if (strcmp(fname, "membershipFactor") == 0)
58  *f = &fftjet::Peak::membershipFactor;
59  else if (strcmp(fname, "recoScale") == 0)
60  *f = &fftjet::Peak::recoScale;
61  else if (strcmp(fname, "recoScaleRatio") == 0)
62  *f = &fftjet::Peak::recoScaleRatio;
63  else if (strcmp(fname, "laplacian") == 0)
64  *f = &fftjet::Peak::laplacian;
65  else if (strcmp(fname, "hessianDeterminant") == 0)
66  *f = &fftjet::Peak::hessianDeterminant;
67  else if (strcmp(fname, "clusterRadius") == 0)
68  *f = &fftjet::Peak::clusterRadius;
69  else if (strcmp(fname, "clusterSeparation") == 0)
70  *f = &fftjet::Peak::clusterSeparation;
71  else
72  {
73  return false;
74  }
75  return true;
76 }
77 
78 static bool parse_jet_member_function(const char* fname,
79  fftjet::JetProperty<RecoFFTJet>::JetMemberFunction *f)
80 {
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, "scale") == 0)
96  *f = &RecoFFTJet::scale;
97  else if (strcmp(fname, "nearestNeighborDistance") == 0)
98  *f = &RecoFFTJet::nearestNeighborDistance;
99  else if (strcmp(fname, "membershipFactor") == 0)
100  *f = &RecoFFTJet::membershipFactor;
101  else if (strcmp(fname, "recoScale") == 0)
102  *f = &RecoFFTJet::recoScale;
103  else if (strcmp(fname, "recoScaleRatio") == 0)
104  *f = &RecoFFTJet::recoScaleRatio;
105  else if (strcmp(fname, "laplacian") == 0)
106  *f = &RecoFFTJet::laplacian;
107  else if (strcmp(fname, "hessianDeterminant") == 0)
108  *f = &RecoFFTJet::hessianDeterminant;
109  else if (strcmp(fname, "clusterRadius") == 0)
110  *f = &RecoFFTJet::clusterRadius;
111  else if (strcmp(fname, "clusterSeparation") == 0)
112  *f = &RecoFFTJet::clusterSeparation;
113  else
114  {
115  return false;
116  }
117  return true;
118 }
119 
120 
121 namespace fftjetcms {
122 
123 std::auto_ptr<fftjet::Grid2d<Real> >
125 {
126  typedef std::auto_ptr<fftjet::Grid2d<Real> > return_type;
127  fftjet::Grid2d<Real> *g = 0;
128 
129  // Check if the grid should be read from file
130  if (ps.exists("file"))
131  {
132  const std::string file = ps.getParameter<std::string>("file");
133  std::ifstream in(file.c_str(),
134  std::ios_base::in | std::ios_base::binary);
135  if (!in.is_open())
136  throw cms::Exception("FFTJetBadConfig")
137  << "Failed to open file " << file << std::endl;
139  if (g == 0)
140  throw cms::Exception("FFTJetBadConfig")
141  << "Failed to read file " << file << std::endl;
142  }
143  else
144  {
145  const unsigned nEtaBins = ps.getParameter<unsigned>("nEtaBins");
146  const Real etaMin = ps.getParameter<Real>("etaMin");
147  const Real etaMax = ps.getParameter<Real>("etaMax");
148  const unsigned nPhiBins = ps.getParameter<unsigned>("nPhiBins");
149  const Real phiBin0Edge = ps.getParameter<Real>("phiBin0Edge");
150  const std::string& title = ps.getUntrackedParameter<std::string>(
151  "title", "");
152 
153  if (nEtaBins == 0 || nPhiBins == 0 || etaMin >= etaMax)
154  return return_type(NULL);
155 
156  g = new fftjet::Grid2d<Real>(
157  nEtaBins,
158  etaMin,
159  etaMax,
160  nPhiBins,
161  phiBin0Edge,
162  title.c_str()
163  );
164 
165  // Check if the grid data is provided
166  if (ps.exists("data"))
167  {
168  const std::vector<Real>& data =
169  ps.getParameter<std::vector<Real> >("data");
170  if (data.size() == nEtaBins*nPhiBins)
171  g->blockSet(&data[0], nEtaBins, nPhiBins);
172  else
173  {
174  delete g;
175  g = 0;
176  }
177  }
178  }
179 
180  return return_type(g);
181 }
182 
183 
184 std::auto_ptr<fftjet::Functor1<bool,fftjet::Peak> >
186 {
187  typedef std::auto_ptr<fftjet::Functor1<bool,fftjet::Peak> > return_type;
188 
189  const std::string peakselector_type = ps.getParameter<std::string>(
190  "Class");
191 
192  if (!peakselector_type.compare("AllPeaksPass"))
193  {
194  return return_type(new fftjet::AllPeaksPass());
195  }
196 
197  if (!peakselector_type.compare("EtaAndPtDependentPeakSelector"))
198  {
199  const std::string file = ps.getParameter<std::string>("file");
200  std::ifstream in(file.c_str(),
201  std::ios_base::in | std::ios_base::binary);
202  if (!in.is_open())
203  throw cms::Exception("FFTJetBadConfig")
204  << "Failed to open file " << file << std::endl;
207  if (!ptr->isValid())
208  throw cms::Exception("FFTJetBadConfig")
209  << "Failed to read file " << file << std::endl;
210  return return_type(ptr);
211  }
212 
213  if (!peakselector_type.compare("EtaAndPtLookupPeakSelector"))
214  {
215  make_param(unsigned, nx);
216  make_param(unsigned, ny);
217  make_param(double, xmin);
218  make_param(double, xmax);
219  make_param(double, ymin);
220  make_param(double, ymax);
221  make_param(std::vector<double>, data);
222 
223  if (xmin >= xmax || ymin >= ymax || !nx || !ny || data.size() != nx*ny)
224  throw cms::Exception("FFTJetBadConfig")
225  << "Failed to configure EtaAndPtLookupPeakSelector" << std::endl;
226 
227  return return_type(new EtaAndPtLookupPeakSelector(
228  nx, xmin, xmax, ny, ymin, ymax, data));
229  }
230 
231  if (!peakselector_type.compare("SimplePeakSelector"))
232  {
233  const double magCut = ps.getParameter<double>("magCut");
234  const double driftSpeedCut = ps.getParameter<double>("driftSpeedCut");
235  const double magSpeedCut = ps.getParameter<double>("magSpeedCut");
236  const double lifeTimeCut = ps.getParameter<double>("lifeTimeCut");
237  const double NNDCut = ps.getParameter<double>("NNDCut");
238  const double etaCut = ps.getParameter<double>("etaCut");
239 
240  return return_type(new fftjet::SimplePeakSelector(
241  magCut, driftSpeedCut ,magSpeedCut, lifeTimeCut, NNDCut, etaCut));
242  }
243 
244  if (!peakselector_type.compare("ScalePowerPeakSelector"))
245  {
246  const double a = ps.getParameter<double>("a");
247  const double p = ps.getParameter<double>("p");
248  const double b = ps.getParameter<double>("b");
249  const double etaCut = ps.getParameter<double>("etaCut");
250 
251  return return_type(new fftjet::ScalePowerPeakSelector(
252  a, p, b, etaCut));
253  }
254 
255  return return_type(NULL);
256 }
257 
258 
259 std::auto_ptr<fftjet::ScaleSpaceKernel>
261 {
262  typedef std::auto_ptr<fftjet::ScaleSpaceKernel> return_type;
263 
264  const std::string MembershipFunction_type = ps.getParameter<std::string>(
265  "Class");
266 
267  // Parse special cases first
268  if (!MembershipFunction_type.compare("InterpolatedMembershipFcn"))
269  {
270  // This is a kernel defined by a 4d (sparsified) lookup table.
271  // Here, it is simply loaded from a file using a built-in
272  // method from fftjet. Note that the table representation
273  // must be native binary (this will not work on platforms with
274  // different endianity of floating point standard).
275  const std::string file = ps.getParameter<std::string>("file");
276  std::ifstream in(file.c_str(),
277  std::ios_base::in | std::ios_base::binary);
278  if (!in.is_open())
279  throw cms::Exception("FFTJetBadConfig")
280  << "Failed to open file " << file << std::endl;
282  }
283 
284  if (!MembershipFunction_type.compare("Composite"))
285  {
286  throw cms::Exception("FFTJetBadConfig")
287  << "Parsing of CompositeKernel objects is not implemented yet"
288  << std::endl;
289  }
290 
291  if (!MembershipFunction_type.compare("MagneticSmearing"))
292  {
293  // This kernel represents smearing of a jet in phi
294  // in a magnetic field. The meaning of the parameters
295  // is explained in the comments in the MagneticSmearingKernel.hh
296  // header file of the fftjet package.
297  make_param(std::vector<double>, fragmentationData);
298  make_param(double, numeratorConst);
299  make_param(double, charge1Fraction);
300  make_param(double, charge2Fraction);
301  make_param(unsigned, samplesPerBin);
302 
303  if (fragmentationData.empty())
304  throw cms::Exception("FFTJetBadConfig")
305  << "Fragmentation function data not defined for "
306  "MagneticSmearingKernel" << std::endl;
307  if (samplesPerBin < 1U)
308  throw cms::Exception("FFTJetBadConfig")
309  << "Bad number of samples per bin in "
310  "MagneticSmearingKernel" << std::endl;
311 
312  fftjet::LinearInterpolator1d* fragmentationFunction =
313  new fftjet::LinearInterpolator1d(
314  &fragmentationData[0], fragmentationData.size(), 0.0, 1.0);
315 
316  return return_type(
317  new fftjet::MagneticSmearingKernel<fftjet::LinearInterpolator1d>(
318  fragmentationFunction, numeratorConst,
319  charge1Fraction, charge2Fraction,
320  samplesPerBin, true));
321  }
322 
323  if (!MembershipFunction_type.compare("Interpolated"))
324  {
325  // This is a kernel defined by a histogram-like 2d lookup table
326  make_param(double, sx);
327  make_param(double, sy);
328  make_param(int, scalePower);
329  make_param(unsigned, nxbins);
330  make_param(double, xmin);
331  make_param(double, xmax);
332  make_param(unsigned, nybins);
333  make_param(double, ymin);
334  make_param(double, ymax);
335  make_param(std::vector<double>, data);
336 
337  if (data.size() != nxbins*nybins)
338  throw cms::Exception("FFTJetBadConfig")
339  << "Bad number of data points for Interpolated kernel"
340  << std::endl;
341 
342  return return_type(new fftjet::InterpolatedKernel(
343  sx, sy, scalePower,
344  &data[0], nxbins, xmin, xmax,
345  nybins, ymin, ymax));
346  }
347 
348  if (!MembershipFunction_type.compare("Interpolated3d"))
349  {
350  // This is a kernel defined by a histogram-like 3d lookup table
351  make_param(std::vector<double>, data);
352  make_param(std::vector<double>, scales);
353  make_param(bool, useLogSpaceForScale);
354  make_param(unsigned, nxbins);
355  make_param(double, xmin);
356  make_param(double, xmax);
357  make_param(unsigned, nybins);
358  make_param(double, ymin);
359  make_param(double, ymax);
360 
361  if (data.size() != nxbins*nybins*scales.size())
362  throw cms::Exception("FFTJetBadConfig")
363  << "Bad number of data points for Interpolated3d kernel"
364  << std::endl;
365 
366  return return_type(new fftjet::InterpolatedKernel3d(
367  &data[0], scales, useLogSpaceForScale,
368  nxbins, xmin, xmax, nybins, ymin, ymax));
369  }
370 
371  // This is not a special kernel. Try one of the classes
372  // in the kernel factory provided by FFTJet.
373  fftjet::DefaultKernel2dFactory factory;
374  if (factory[MembershipFunction_type] == NULL) {
375  return return_type(NULL);
376  }
377 
378  make_param(double, sx);
379  make_param(double, sy);
380  make_param(int, scalePower);
381  make_param(std::vector<double>, kernelParameters);
382 
383  const int n_expected = factory[MembershipFunction_type]->nParameters();
384  if (n_expected >= 0)
385  if (static_cast<unsigned>(n_expected) != kernelParameters.size())
386  throw cms::Exception("FFTJetBadConfig")
387  << "Bad number of kernel parameters" << std::endl;
388 
389  return std::auto_ptr<fftjet::ScaleSpaceKernel>(
390  factory[MembershipFunction_type]->create(
391  sx, sy, scalePower, kernelParameters));
392 }
393 
394 
395 std::auto_ptr<AbsBgFunctor>
397 {
398  const std::string bg_Membership_type = ps.getParameter<std::string>(
399  "Class");
400 
401  if (!bg_Membership_type.compare("GaussianNoiseMembershipFcn"))
402  {
403  const double minWeight = ps.getParameter<double>("minWeight");
404  const double prior = ps.getParameter<double>("prior");
405  return std::auto_ptr<AbsBgFunctor>(
406  new fftjet::GaussianNoiseMembershipFcn(minWeight,prior));
407  }
408 
409  return std::auto_ptr<AbsBgFunctor>(NULL);
410 }
411 
412 
413 std::auto_ptr<std::vector<double> >
415 {
416  typedef std::auto_ptr<std::vector<double> > return_type;
417 
418  const std::string className = ps.getParameter<std::string>("Class");
419 
420  if (!className.compare("EquidistantInLinearSpace") ||
421  !className.compare("EquidistantInLogSpace"))
422  {
423  const double minScale = ps.getParameter<double>("minScale");
424  const double maxScale = ps.getParameter<double>("maxScale");
425  const unsigned nScales = ps.getParameter<unsigned>("nScales");
426 
427  if (minScale <= 0.0 || maxScale <= 0.0 ||
428  nScales == 0 || minScale == maxScale)
429  return return_type(NULL);
430 
431  // Can't return pointers to EquidistantInLinearSpace
432  // or EquidistantInLogSpace directly because std::vector
433  // destructor is not virtual.
434  if (!className.compare("EquidistantInLinearSpace"))
435  return return_type(new std::vector<double>(
436  fftjet::EquidistantInLinearSpace(
437  minScale, maxScale, nScales)));
438  else
439  return return_type(new std::vector<double>(
440  fftjet::EquidistantInLogSpace(
441  minScale, maxScale, nScales)));
442  }
443 
444  if (!className.compare("UserSet"))
445  {
446  return_type scales(new std::vector<double>(
447  ps.getParameter<std::vector<double> >("scales")));
448 
449  // Verify that all scales are positive and unique
450  const unsigned nscales = scales->size();
451  for (unsigned i=0; i<nscales; ++i)
452  if ((*scales)[i] <= 0.0)
453  return return_type(NULL);
454 
455  for (unsigned i=1; i<nscales; ++i)
456  for (unsigned j=0; j<i; ++j)
457  if ((*scales)[i] == (*scales)[j])
458  return return_type(NULL);
459 
460  return scales;
461  }
462 
463  return return_type(NULL);
464 }
465 
466 
467 std::auto_ptr<fftjet::ClusteringTreeSparsifier<fftjet::Peak,long> >
469 {
470  typedef std::auto_ptr<fftjet::ClusteringTreeSparsifier<fftjet::Peak,long> > return_type;
471 
472  const int maxLevelNumber = ps.getParameter<int>("maxLevelNumber");
473  const unsigned filterMask = ps.getParameter<unsigned>("filterMask");
474  const std::vector<double> userScalesV =
475  ps.getParameter<std::vector<double> >("userScales");
476  const unsigned nUserScales = userScalesV.size();
477  const double* userScales = nUserScales ? NULL : &userScalesV[0];
478 
479  return return_type(
480  new fftjet::ClusteringTreeSparsifier<fftjet::Peak,long>(
481  maxLevelNumber,
482  filterMask,
483  userScales,
484  nUserScales
485  )
486  );
487 }
488 
489 
490 std::auto_ptr<fftjet::AbsDistanceCalculator<fftjet::Peak> >
492 {
493  typedef std::auto_ptr<fftjet::AbsDistanceCalculator<fftjet::Peak> > return_type;
494 
495  const std::string calc_type = ps.getParameter<std::string>("Class");
496 
497  if (!calc_type.compare("PeakEtaPhiDistance"))
498  {
499  const double etaToPhiBandwidthRatio = ps.getParameter<double>(
500  "etaToPhiBandwidthRatio");
501  return return_type(new fftjet::PeakEtaPhiDistance(etaToPhiBandwidthRatio));
502  }
503 
504  if (!calc_type.compare("PeakEtaDependentDistance"))
505  {
506  std::auto_ptr<fftjet::LinearInterpolator1d> interp =
508  ps.getParameter<edm::ParameterSet>("Interpolator"));
509  const fftjet::LinearInterpolator1d* ip = interp.get();
510  if (ip == NULL)
511  return return_type(NULL);
512 
513  // Check that the interpolator is always positive
514  const unsigned n = ip->nx();
515  const double* data = ip->getData();
516  for (unsigned i=0; i<n; ++i)
517  if (data[i] <= 0.0)
518  return return_type(NULL);
519  if (ip->fLow() <= 0.0 || ip->fHigh() <= 0.0)
520  return return_type(NULL);
521 
522  return return_type(new fftjet::PeakEtaDependentDistance(*ip));
523  }
524 
525  return return_type(NULL);
526 }
527 
528 
529 std::auto_ptr<fftjetcms::LinInterpolatedTable1D>
531 {
532  const double xmin = ps.getParameter<double>("xmin");
533  const double xmax = ps.getParameter<double>("xmax");
534  const bool leftExtrapolationLinear =
535  ps.getParameter<bool>("leftExtrapolationLinear");
536  const bool rightExtrapolationLinear =
537  ps.getParameter<bool>("rightExtrapolationLinear");
538  const std::vector<double> data(
539  ps.getParameter<std::vector<double> >("data"));
540  if (data.empty())
541  return std::auto_ptr<fftjetcms::LinInterpolatedTable1D>(NULL);
542  else
543  return std::auto_ptr<fftjetcms::LinInterpolatedTable1D>(
545  &data[0], data.size(), xmin, xmax,
546  leftExtrapolationLinear, rightExtrapolationLinear));
547 }
548 
549 
550 std::auto_ptr<fftjet::LinearInterpolator1d>
552 {
553  const double xmin = ps.getParameter<double>("xmin");
554  const double xmax = ps.getParameter<double>("xmax");
555  const double flow = ps.getParameter<double>("flow");
556  const double fhigh = ps.getParameter<double>("fhigh");
557  const std::vector<double> data(
558  ps.getParameter<std::vector<double> >("data"));
559  if (data.empty())
560  return std::auto_ptr<fftjet::LinearInterpolator1d>(NULL);
561  else
562  return std::auto_ptr<fftjet::LinearInterpolator1d>(
563  new fftjet::LinearInterpolator1d(
564  &data[0], data.size(), xmin, xmax, flow, fhigh));
565 }
566 
567 
568 std::auto_ptr<fftjet::LinearInterpolator2d>
570 {
571  const std::string file = ps.getParameter<std::string>("file");
572  std::ifstream in(file.c_str(),
573  std::ios_base::in | std::ios_base::binary);
574  if (!in.is_open())
575  throw cms::Exception("FFTJetBadConfig")
576  << "Failed to open file " << file << std::endl;
577  fftjet::LinearInterpolator2d* ip = fftjet::LinearInterpolator2d::read(in);
578  if (!ip)
579  throw cms::Exception("FFTJetBadConfig")
580  << "Failed to read file " << file << std::endl;
581  return std::auto_ptr<fftjet::LinearInterpolator2d>(ip);
582 }
583 
584 
585 std::auto_ptr<fftjet::Functor1<double,fftjet::Peak> >
587 {
588  typedef fftjet::Functor1<double,fftjet::Peak> ptr_type;
589  typedef std::auto_ptr<ptr_type> return_type;
590 
591  const std::string property_type = ps.getParameter<std::string>("Class");
592 
593  if (!property_type.compare("Log"))
594  {
595  return_type wrapped = fftjet_PeakFunctor_parser(
596  ps.getParameter<edm::ParameterSet>("function"));
597  ptr_type* wr = wrapped.get();
598  if (wr)
599  {
600  return_type result = return_type(
601  new fftjet::LogProperty<fftjet::Peak>(wr, true));
602  wrapped.release();
603  return result;
604  }
605  }
606 
607  if (!property_type.compare("PeakProperty"))
608  {
609  const std::string member = ps.getParameter<std::string>("member");
610  fftjet::JetProperty<fftjet::Peak>::JetMemberFunction fcn;
611  if (parse_peak_member_function(member.c_str(), &fcn))
612  return return_type(
613  new fftjet::JetProperty<fftjet::Peak>(fcn));
614  else
615  return return_type(NULL);
616  }
617 
618  if (!property_type.compare("MinusScaledLaplacian"))
619  {
620  const double sx = ps.getParameter<double>("sx");
621  const double sy = ps.getParameter<double>("sx");
622  return return_type(
623  new fftjet::MinusScaledLaplacian<fftjet::Peak>(sx, sy));
624  }
625 
626  if (!property_type.compare("ScaledHessianDet"))
627  {
628  return return_type(
629  new fftjet::ScaledHessianDet<fftjet::Peak>());
630  }
631 
632  if (!property_type.compare("ScaledMagnitude"))
633  {
634  return return_type(
635  new fftjet::ScaledMagnitude<fftjet::Peak>());
636  }
637 
638  if (!property_type.compare("ScaledMagnitude2"))
639  {
640  return return_type(
641  new fftjet::ScaledMagnitude2<fftjet::Peak>());
642  }
643 
644  if (!property_type.compare("ConstDouble"))
645  {
646  const double value = ps.getParameter<double>("value");
647  return return_type(new ConstDouble<fftjet::Peak>(value));
648  }
649 
650  if (!property_type.compare("ProportionalToScale"))
651  {
652  const double value = ps.getParameter<double>("value");
653  return return_type(
655  }
656 
657  if (!property_type.compare("MultiplyByConst"))
658  {
659  const double factor = ps.getParameter<double>("factor");
660  return_type function = fftjet_PeakFunctor_parser(
661  ps.getParameter<edm::ParameterSet>("function"));
662  ptr_type* ptr = function.get();
663  if (ptr)
664  {
665  return_type result = return_type(
666  new MultiplyByConst<fftjet::Peak>(factor, ptr, true));
667  function.release();
668  return result;
669  }
670  }
671 
672  if (!property_type.compare("CompositeFunctor"))
673  {
674  std::auto_ptr<fftjet::Functor1<double,double> > fcn1 =
676  ps.getParameter<edm::ParameterSet>("function1"));
677  return_type fcn2 = fftjet_PeakFunctor_parser(
678  ps.getParameter<edm::ParameterSet>("function2"));
679  fftjet::Functor1<double,double>* f1 = fcn1.get();
680  ptr_type* f2 = fcn2.get();
681  if (f1 && f2)
682  {
683  return_type result = return_type(
684  new CompositeFunctor<fftjet::Peak>(f1, f2, true));
685  fcn1.release();
686  fcn2.release();
687  return result;
688  }
689  }
690 
691  if (!property_type.compare("ProductFunctor"))
692  {
693  return_type fcn1 = fftjet_PeakFunctor_parser(
694  ps.getParameter<edm::ParameterSet>("function1"));
695  return_type fcn2 = fftjet_PeakFunctor_parser(
696  ps.getParameter<edm::ParameterSet>("function2"));
697  ptr_type* f1 = fcn1.get();
698  ptr_type* f2 = fcn2.get();
699  if (f1 && f2)
700  {
701  return_type result = return_type(
702  new ProductFunctor<fftjet::Peak>(f1, f2, true));
703  fcn1.release();
704  fcn2.release();
705  return result;
706  }
707  }
708 
709  if (!property_type.compare("MagnitudeDependent"))
710  {
711  std::auto_ptr<fftjet::Functor1<double,double> > fcn1 =
713  ps.getParameter<edm::ParameterSet>("function"));
714  fftjet::Functor1<double,double>* f1 = fcn1.get();
715  if (f1)
716  {
717  return_type result = return_type(
718  new MagnitudeDependent<fftjet::Peak>(f1, true));
719  fcn1.release();
720  return result;
721  }
722  }
723 
724  if (!property_type.compare("PeakEtaDependent"))
725  {
726  std::auto_ptr<fftjet::Functor1<double,double> > fcn1 =
728  ps.getParameter<edm::ParameterSet>("function"));
729  fftjet::Functor1<double,double>* f1 = fcn1.get();
730  if (f1)
731  {
732  return_type result = return_type(new PeakEtaDependent(f1, true));
733  fcn1.release();
734  return result;
735  }
736  }
737 
738  return return_type(NULL);
739 }
740 
741 
742 std::auto_ptr<fftjet::Functor1<double,fftjet::RecombinedJet<VectorLike> > >
744 {
745  typedef fftjet::Functor1<double,RecoFFTJet> ptr_type;
746  typedef std::auto_ptr<ptr_type> return_type;
747 
748  const std::string property_type = ps.getParameter<std::string>("Class");
749 
750  if (!property_type.compare("Log"))
751  {
752  return_type wrapped = fftjet_JetFunctor_parser(
753  ps.getParameter<edm::ParameterSet>("function"));
754  fftjet::Functor1<double,RecoFFTJet>* wr = wrapped.get();
755  if (wr)
756  {
757  return_type result = return_type(
758  new fftjet::LogProperty<RecoFFTJet>(wr, true));
759  wrapped.release();
760  return result;
761  }
762  }
763 
764  if (!property_type.compare("JetEtaDependent"))
765  {
766  std::auto_ptr<fftjet::Functor1<double,double> > fcn1 =
768  ps.getParameter<edm::ParameterSet>("function"));
769  fftjet::Functor1<double,double>* f1 = fcn1.get();
770  if (f1)
771  {
772  return_type result = return_type(new JetEtaDependent(f1, true));
773  fcn1.release();
774  return result;
775  }
776  }
777 
778  if (!property_type.compare("JetProperty"))
779  {
780  const std::string member = ps.getParameter<std::string>("member");
781  fftjet::JetProperty<RecoFFTJet>::JetMemberFunction fcn;
782  if (parse_jet_member_function(member.c_str(), &fcn))
783  return return_type(
784  new fftjet::JetProperty<RecoFFTJet>(fcn));
785  else
786  return return_type(NULL);
787  }
788 
789  if (!property_type.compare("ConstDouble"))
790  {
791  const double value = ps.getParameter<double>("value");
792  return return_type(new ConstDouble<RecoFFTJet>(value));
793  }
794 
795  if (!property_type.compare("ProportionalToScale"))
796  {
797  const double value = ps.getParameter<double>("value");
798  return return_type(
800  }
801 
802  if (!property_type.compare("MultiplyByConst"))
803  {
804  const double factor = ps.getParameter<double>("factor");
805  return_type function = fftjet_JetFunctor_parser(
806  ps.getParameter<edm::ParameterSet>("function"));
807  ptr_type* ptr = function.get();
808  if (ptr)
809  {
810  return_type result = return_type(
811  new MultiplyByConst<RecoFFTJet>(factor, ptr, true));
812  function.release();
813  return result;
814  }
815  }
816 
817  if (!property_type.compare("CompositeFunctor"))
818  {
819  std::auto_ptr<fftjet::Functor1<double,double> > fcn1 =
821  ps.getParameter<edm::ParameterSet>("function1"));
822  return_type fcn2 = fftjet_JetFunctor_parser(
823  ps.getParameter<edm::ParameterSet>("function2"));
824  fftjet::Functor1<double,double>* f1 = fcn1.get();
825  ptr_type* f2 = fcn2.get();
826  if (f1 && f2)
827  {
828  return_type result = return_type(
829  new CompositeFunctor<RecoFFTJet>(f1, f2, true));
830  fcn1.release();
831  fcn2.release();
832  return result;
833  }
834  }
835 
836  if (!property_type.compare("ProductFunctor"))
837  {
838  return_type fcn1 = fftjet_JetFunctor_parser(
839  ps.getParameter<edm::ParameterSet>("function1"));
840  return_type fcn2 = fftjet_JetFunctor_parser(
841  ps.getParameter<edm::ParameterSet>("function2"));
842  ptr_type* f1 = fcn1.get();
843  ptr_type* f2 = fcn2.get();
844  if (f1 && f2)
845  {
846  return_type result = return_type(
847  new ProductFunctor<RecoFFTJet>(f1, f2, true));
848  fcn1.release();
849  fcn2.release();
850  return result;
851  }
852  }
853 
854  if (!property_type.compare("MagnitudeDependent"))
855  {
856  std::auto_ptr<fftjet::Functor1<double,double> > fcn1 =
858  ps.getParameter<edm::ParameterSet>("function"));
859  fftjet::Functor1<double,double>* f1 = fcn1.get();
860  if (f1)
861  {
862  return_type result = return_type(
863  new MagnitudeDependent<RecoFFTJet>(f1, true));
864  fcn1.release();
865  return result;
866  }
867  }
868 
869  return return_type(NULL);
870 }
871 
872 
873 std::auto_ptr<fftjet::Functor2<double,
874  fftjet::RecombinedJet<VectorLike>,
875  fftjet::RecombinedJet<VectorLike> > >
877 {
878  typedef std::auto_ptr<fftjet::Functor2<
879  double,
880  fftjet::RecombinedJet<VectorLike>,
881  fftjet::RecombinedJet<VectorLike> > > return_type;
882 
883  const std::string distance_type = ps.getParameter<std::string>(
884  "Class");
885 
886  if (!distance_type.compare("JetConvergenceDistance"))
887  {
888  make_param(double, etaToPhiBandwidthRatio);
889  make_param(double, relativePtBandwidth);
890 
891  if (etaToPhiBandwidthRatio > 0.0 && relativePtBandwidth > 0.0)
892  return return_type(new JetConvergenceDistance(
893  etaToPhiBandwidthRatio, relativePtBandwidth));
894  }
895 
896  return return_type(NULL);
897 }
898 
899 
900 std::auto_ptr<fftjet::Functor1<double,double> >
902 {
903  typedef std::auto_ptr<fftjet::Functor1<double,double> > return_type;
904 
905  const std::string fcn_type = ps.getParameter<std::string>("Class");
906 
907  if (!fcn_type.compare("LinearInterpolator1d"))
908  {
909  std::auto_ptr<fftjet::LinearInterpolator1d> p =
911  fftjet::LinearInterpolator1d* ptr = p.get();
912  if (ptr)
913  {
914  p.release();
915  return return_type(ptr);
916  }
917  }
918 
919  if (!fcn_type.compare("LinInterpolatedTable1D"))
920  {
921  std::auto_ptr<fftjetcms::LinInterpolatedTable1D> p =
923  fftjetcms::LinInterpolatedTable1D* ptr = p.get();
924  if (ptr)
925  {
926  p.release();
927  return return_type(ptr);
928  }
929  }
930 
931  if (!fcn_type.compare("Polynomial"))
932  {
933  std::vector<double> coeffs;
934  for (unsigned i=0; ; ++i)
935  {
936  std::ostringstream s;
937  s << 'c' << i;
938  if (ps.exists(s.str()))
939  coeffs.push_back(ps.getParameter<double>(s.str()));
940  else
941  break;
942  }
943  return return_type(new Polynomial(coeffs));
944  }
945 
946  return return_type(NULL);
947 }
948 
949 
950 std::auto_ptr<AbsPileupCalculator>
952 {
953  typedef std::auto_ptr<AbsPileupCalculator> return_type;
954 
955  const std::string fcn_type = ps.getParameter<std::string>("Class");
956 
957  if (!fcn_type.compare("EtaDependentPileup"))
958  {
959  std::auto_ptr<fftjet::LinearInterpolator2d> interp =
961  ps.getParameter<edm::ParameterSet>("Interpolator2d"));
962  const double inputRhoFactor = ps.getParameter<double>("inputRhoFactor");
963  const double outputRhoFactor = ps.getParameter<double>("outputRhoFactor");
964 
965  const fftjet::LinearInterpolator2d* ip = interp.get();
966  if (ip)
967  return return_type(new EtaDependentPileup(
968  *ip, inputRhoFactor, outputRhoFactor));
969  else
970  return return_type(NULL);
971  }
972 
973  if (!fcn_type.compare("PileupGrid2d"))
974  {
975  std::auto_ptr<fftjet::Grid2d<Real> > grid =
977  ps.getParameter<edm::ParameterSet>("Grid2d"));
978  const double rhoFactor = ps.getParameter<double>("rhoFactor");
979 
980  const fftjet::Grid2d<Real>* g = grid.get();
981  if (g)
982  return return_type(new PileupGrid2d(*g, rhoFactor));
983  else
984  return return_type(NULL);
985  }
986 
987  return return_type(NULL);
988 }
989 
990 
991 std::auto_ptr<fftjet::JetMagnitudeMapper2d <fftjet::Peak> >
993 {
994  std::auto_ptr<fftjet::LinearInterpolator2d> responseCurve =
996  ps.getParameter<edm::ParameterSet>("responseCurve"));
997 
998  const double minPredictor = ps.getParameter<double>("minPredictor");
999  const double maxPredictor = ps.getParameter<double>("maxPredictor");
1000  const unsigned nPredPoints = ps.getParameter<unsigned>("nPredPoints");
1001  const double maxMagnitude = ps.getParameter<double>("maxMagnitude");
1002  const unsigned nMagPoints = ps.getParameter<unsigned>("nMagPoints");
1003 
1004  return (std::auto_ptr<fftjet::JetMagnitudeMapper2d<fftjet::Peak> >
1005  (new fftjet::JetMagnitudeMapper2d<fftjet::Peak>(
1006  *responseCurve,
1008  true,minPredictor,maxPredictor,nPredPoints,
1009  maxMagnitude,nMagPoints)));
1010 }
1011 
1012 
1013 std::auto_ptr<fftjet::JetMagnitudeMapper2d <fftjet::RecombinedJet<VectorLike> > >
1015 {
1016  std::auto_ptr<fftjet::LinearInterpolator2d> responseCurve =
1018  ps.getParameter<edm::ParameterSet>("responseCurve"));
1019 
1020  const double minPredictor = ps.getParameter<double>("minPredictor");
1021  const double maxPredictor = ps.getParameter<double>("maxPredictor");
1022  const unsigned nPredPoints = ps.getParameter<unsigned>("nPredPoints");
1023  const double maxMagnitude = ps.getParameter<double>("maxMagnitude");
1024  const unsigned nMagPoints = ps.getParameter<unsigned>("nMagPoints");
1025 
1026  return (std::auto_ptr<fftjet::JetMagnitudeMapper2d<RecoFFTJet> >
1027  (new fftjet::JetMagnitudeMapper2d<RecoFFTJet>(
1028  *responseCurve,
1030  true,minPredictor,maxPredictor,nPredPoints,
1031  maxMagnitude,nMagPoints)));
1032 }
1033 
1034 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
std::auto_ptr< fftjetcms::LinInterpolatedTable1D > fftjet_LinInterpolatedTable1D_parser(const edm::ParameterSet &ps)
std::auto_ptr< fftjet::Grid2d< Real > > fftjet_Grid2d_parser(const edm::ParameterSet &ps)
std::auto_ptr< fftjet::JetMagnitudeMapper2d< fftjet::Peak > > fftjet_PeakMagnitudeMapper2d_parser(const edm::ParameterSet &ps)
bool exists(std::string const &parameterName) const
checks if a parameter exists
#define NULL
Definition: scimark2.h:8
std::auto_ptr< fftjet::ScaleSpaceKernel > fftjet_MembershipFunction_parser(const edm::ParameterSet &ps)
std::auto_ptr< AbsPileupCalculator > fftjet_PileupCalculator_parser(const edm::ParameterSet &ps)
T eta() const
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
fftjet::RecombinedJet< VectorLike > RecoFFTJet
std::auto_ptr< fftjet::Functor1< bool, fftjet::Peak > > fftjet_PeakSelector_parser(const edm::ParameterSet &ps)
std::auto_ptr< fftjet::Functor2< double, fftjet::RecombinedJet< VectorLike >, fftjet::RecombinedJet< VectorLike > > > fftjet_JetDistance_parser(const edm::ParameterSet &ps)
std::auto_ptr< fftjet::Functor1< double, double > > fftjet_Function_parser(const edm::ParameterSet &ps)
static bool parse_peak_member_function(const char *fname, fftjet::JetProperty< fftjet::Peak >::JetMemberFunction *f)
tuple result
Definition: query.py:137
int j
Definition: DBlmapReader.cc:9
double f[11][100]
#define make_param(type, varname)
std::auto_ptr< fftjet::Functor1< double, fftjet::Peak > > fftjet_PeakFunctor_parser(const edm::ParameterSet &ps)
double Real
std::auto_ptr< fftjet::JetMagnitudeMapper2d< fftjet::RecombinedJet< VectorLike > > > fftjet_JetMagnitudeMapper2d_parser(const edm::ParameterSet &ps)
void fcn(int &, double *, double &, double *, int)
std::auto_ptr< fftjet::LinearInterpolator1d > fftjet_LinearInterpolator1d_parser(const edm::ParameterSet &ps)
double b
Definition: hdecay.h:120
dictionary prior
string fname
main script
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
std::auto_ptr< fftjet::AbsDistanceCalculator< fftjet::Peak > > fftjet_DistanceCalculator_parser(const edm::ParameterSet &ps)
double a
Definition: hdecay.h:121
std::auto_ptr< fftjet::ClusteringTreeSparsifier< fftjet::Peak, long > > fftjet_ClusteringTreeSparsifier_parser(const edm::ParameterSet &ps)
static bool parse_jet_member_function(const char *fname, fftjet::JetProperty< RecoFFTJet >::JetMemberFunction *f)
std::auto_ptr< AbsBgFunctor > fftjet_BgFunctor_parser(const edm::ParameterSet &ps)
std::auto_ptr< std::vector< double > > fftjet_ScaleSet_parser(const edm::ParameterSet &ps)
std::string className(const T &t)
Definition: ClassName.h:30
std::auto_ptr< fftjet::Functor1< double, fftjet::RecombinedJet< VectorLike > > > fftjet_JetFunctor_parser(const edm::ParameterSet &ps)
std::auto_ptr< fftjet::LinearInterpolator2d > fftjet_LinearInterpolator2d_parser(const edm::ParameterSet &ps)
Definition: DDAxes.h:10