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"
33 #define make_param(type, varname) const type& varname(ps.getParameter<type>(#varname))
40 if (strcmp(
fname,
"eta") == 0)
42 else if (strcmp(
fname,
"phi") == 0)
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;
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)
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;
126 typedef std::unique_ptr<fftjet::Grid2d<Real>> return_type;
127 fftjet::Grid2d<Real>*
g =
nullptr;
134 throw cms::Exception(
"FFTJetBadConfig") <<
"Failed to open file " <<
file << std::endl;
137 throw cms::Exception(
"FFTJetBadConfig") <<
"Failed to read file " <<
file << std::endl;
147 return return_type(
nullptr);
163 return return_type(
g);
167 typedef std::unique_ptr<fftjet::Functor1<bool, fftjet::Peak>> return_type;
171 if (!peakselector_type.compare(
"AllPeaksPass")) {
172 return return_type(
new fftjet::AllPeaksPass());
175 if (!peakselector_type.compare(
"EtaAndPtDependentPeakSelector")) {
179 throw cms::Exception(
"FFTJetBadConfig") <<
"Failed to open file " <<
file << std::endl;
182 throw cms::Exception(
"FFTJetBadConfig") <<
"Failed to read file " <<
file << std::endl;
183 return return_type(ptr);
186 if (!peakselector_type.compare(
"EtaAndPtLookupPeakSelector")) {
196 throw cms::Exception(
"FFTJetBadConfig") <<
"Failed to configure EtaAndPtLookupPeakSelector" << std::endl;
201 if (!peakselector_type.compare(
"SimplePeakSelector")) {
211 return return_type(
new fftjet::SimplePeakSelector(
215 if (!peakselector_type.compare(
"ScalePowerPeakSelector")) {
221 return return_type(
new fftjet::ScalePowerPeakSelector(
a,
p,
b,
etaCut));
224 return return_type(
nullptr);
228 typedef std::unique_ptr<fftjet::ScaleSpaceKernel> return_type;
233 if (!MembershipFunction_type.compare(
"InterpolatedMembershipFcn")) {
242 throw cms::Exception(
"FFTJetBadConfig") <<
"Failed to open file " <<
file << std::endl;
246 if (!MembershipFunction_type.compare(
"Composite")) {
248 <<
"Parsing of CompositeKernel objects is not implemented yet" << std::endl;
251 if (!MembershipFunction_type.compare(
"MagneticSmearing")) {
256 make_param(std::vector<double>, fragmentationData);
262 if (fragmentationData.empty())
263 throw cms::Exception(
"FFTJetBadConfig") <<
"Fragmentation function data not defined for "
264 "MagneticSmearingKernel"
266 if (samplesPerBin < 1
U)
267 throw cms::Exception(
"FFTJetBadConfig") <<
"Bad number of samples per bin in "
268 "MagneticSmearingKernel"
271 fftjet::LinearInterpolator1d* fragmentationFunction =
272 new fftjet::LinearInterpolator1d(&fragmentationData[0], fragmentationData.size(), 0.0, 1.0);
274 return return_type(
new fftjet::MagneticSmearingKernel<fftjet::LinearInterpolator1d>(
275 fragmentationFunction, numeratorConst, charge1Fraction, charge2Fraction, samplesPerBin,
true));
278 if (!MembershipFunction_type.compare(
"Interpolated")) {
291 if (
data.size() != nxbins * nybins)
292 throw cms::Exception(
"FFTJetBadConfig") <<
"Bad number of data points for Interpolated kernel" << std::endl;
298 if (!MembershipFunction_type.compare(
"Interpolated3d")) {
310 if (
data.size() != nxbins * nybins * scales.size())
311 throw cms::Exception(
"FFTJetBadConfig") <<
"Bad number of data points for Interpolated3d kernel" << std::endl;
313 return return_type(
new fftjet::InterpolatedKernel3d(
319 fftjet::DefaultKernel2dFactory factory;
320 if (factory[MembershipFunction_type] ==
nullptr) {
321 return return_type(
nullptr);
329 const int n_expected = factory[MembershipFunction_type]->nParameters();
332 throw cms::Exception(
"FFTJetBadConfig") <<
"Bad number of kernel parameters" << std::endl;
334 return std::unique_ptr<fftjet::ScaleSpaceKernel>(
341 if (!bg_Membership_type.compare(
"GaussianNoiseMembershipFcn")) {
344 return std::unique_ptr<AbsBgFunctor>(
new fftjet::GaussianNoiseMembershipFcn(
minWeight,
prior));
347 return std::unique_ptr<AbsBgFunctor>(
nullptr);
351 typedef std::unique_ptr<std::vector<double>> return_type;
355 if (!
className.compare(
"EquidistantInLinearSpace") || !
className.compare(
"EquidistantInLogSpace")) {
361 return return_type(
nullptr);
366 if (!
className.compare(
"EquidistantInLinearSpace"))
373 return_type scales(
new std::vector<double>(ps.
getParameter<std::vector<double>>(
"scales")));
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);
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);
389 return return_type(
nullptr);
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;
400 return std::make_unique<fftjet::ClusteringTreeSparsifier<fftjet::Peak, long>>(
406 typedef std::unique_ptr<fftjet::AbsDistanceCalculator<fftjet::Peak>> return_type;
410 if (!calc_type.compare(
"PeakEtaPhiDistance")) {
415 if (!calc_type.compare(
"PeakEtaDependentDistance")) {
416 std::unique_ptr<fftjet::LinearInterpolator1d> interp =
418 const fftjet::LinearInterpolator1d* ip = interp.get();
420 return return_type(
nullptr);
423 const unsigned n = ip->nx();
424 const double*
data = ip->getData();
425 for (
unsigned i = 0;
i <
n; ++
i)
427 return return_type(
nullptr);
428 if (ip->fLow() <= 0.0 || ip->fHigh() <= 0.0)
429 return return_type(
nullptr);
431 return return_type(
new fftjet::PeakEtaDependentDistance(*ip));
434 return return_type(
nullptr);
442 const std::vector<double>
data(ps.
getParameter<std::vector<double>>(
"data"));
444 return std::unique_ptr<fftjetcms::LinInterpolatedTable1D>(
nullptr);
446 return std::make_unique<fftjetcms::LinInterpolatedTable1D>(
455 const std::vector<double>
data(ps.
getParameter<std::vector<double>>(
"data"));
457 return std::unique_ptr<fftjet::LinearInterpolator1d>(
nullptr);
466 throw cms::Exception(
"FFTJetBadConfig") <<
"Failed to open file " <<
file << std::endl;
469 throw cms::Exception(
"FFTJetBadConfig") <<
"Failed to read file " <<
file << std::endl;
470 return std::unique_ptr<fftjet::LinearInterpolator2d>(ip);
474 typedef fftjet::Functor1<double, fftjet::Peak> ptr_type;
475 typedef std::unique_ptr<ptr_type> return_type;
479 if (!property_type.compare(
"Log")) {
481 ptr_type* wr = wrapped.get();
483 return_type
result = return_type(
new fftjet::LogProperty<fftjet::Peak>(wr,
true));
489 if (!property_type.compare(
"PeakProperty")) {
491 fftjet::JetProperty<fftjet::Peak>::JetMemberFunction
fcn;
493 return return_type(
new fftjet::JetProperty<fftjet::Peak>(
fcn));
495 return return_type(
nullptr);
498 if (!property_type.compare(
"MinusScaledLaplacian")) {
501 return return_type(
new fftjet::MinusScaledLaplacian<fftjet::Peak>(
sx,
sy));
504 if (!property_type.compare(
"ScaledHessianDet")) {
505 return return_type(
new fftjet::ScaledHessianDet<fftjet::Peak>());
508 if (!property_type.compare(
"ScaledMagnitude")) {
509 return return_type(
new fftjet::ScaledMagnitude<fftjet::Peak>());
512 if (!property_type.compare(
"ScaledMagnitude2")) {
513 return return_type(
new fftjet::ScaledMagnitude2<fftjet::Peak>());
516 if (!property_type.compare(
"ConstDouble")) {
521 if (!property_type.compare(
"ProportionalToScale")) {
526 if (!property_type.compare(
"MultiplyByConst")) {
529 ptr_type* ptr =
function.get();
537 if (!property_type.compare(
"CompositeFunctor")) {
538 std::unique_ptr<fftjet::Functor1<double, double>> fcn1 =
541 fftjet::Functor1<double, double>*
f1 = fcn1.get();
542 ptr_type*
f2 = fcn2.get();
551 if (!property_type.compare(
"ProductFunctor")) {
554 ptr_type*
f1 = fcn1.get();
555 ptr_type*
f2 = fcn2.get();
564 if (!property_type.compare(
"MagnitudeDependent")) {
565 std::unique_ptr<fftjet::Functor1<double, double>> fcn1 =
567 fftjet::Functor1<double, double>*
f1 = fcn1.get();
575 if (!property_type.compare(
"PeakEtaDependent")) {
576 std::unique_ptr<fftjet::Functor1<double, double>> fcn1 =
578 fftjet::Functor1<double, double>*
f1 = fcn1.get();
586 return return_type(
nullptr);
591 typedef fftjet::Functor1<double, RecoFFTJet> ptr_type;
592 typedef std::unique_ptr<ptr_type> return_type;
596 if (!property_type.compare(
"Log")) {
598 fftjet::Functor1<double, RecoFFTJet>* wr = wrapped.get();
600 return_type
result = return_type(
new fftjet::LogProperty<RecoFFTJet>(wr,
true));
606 if (!property_type.compare(
"JetEtaDependent")) {
607 std::unique_ptr<fftjet::Functor1<double, double>> fcn1 =
609 fftjet::Functor1<double, double>*
f1 = fcn1.get();
617 if (!property_type.compare(
"JetProperty")) {
619 fftjet::JetProperty<RecoFFTJet>::JetMemberFunction
fcn;
621 return return_type(
new fftjet::JetProperty<RecoFFTJet>(
fcn));
623 return return_type(
nullptr);
626 if (!property_type.compare(
"ConstDouble")) {
631 if (!property_type.compare(
"ProportionalToScale")) {
636 if (!property_type.compare(
"MultiplyByConst")) {
639 ptr_type* ptr =
function.get();
647 if (!property_type.compare(
"CompositeFunctor")) {
648 std::unique_ptr<fftjet::Functor1<double, double>> fcn1 =
651 fftjet::Functor1<double, double>*
f1 = fcn1.get();
652 ptr_type*
f2 = fcn2.get();
661 if (!property_type.compare(
"ProductFunctor")) {
664 ptr_type*
f1 = fcn1.get();
665 ptr_type*
f2 = fcn2.get();
674 if (!property_type.compare(
"MagnitudeDependent")) {
675 std::unique_ptr<fftjet::Functor1<double, double>> fcn1 =
677 fftjet::Functor1<double, double>*
f1 = fcn1.get();
685 return return_type(
nullptr);
688 std::unique_ptr<fftjet::Functor2<double, fftjet::RecombinedJet<VectorLike>, fftjet::RecombinedJet<VectorLike>>>
691 fftjet::Functor2<double, fftjet::RecombinedJet<VectorLike>, fftjet::RecombinedJet<VectorLike>>>
696 if (!distance_type.compare(
"JetConvergenceDistance")) {
704 return return_type(
nullptr);
708 typedef std::unique_ptr<fftjet::Functor1<double, double>> return_type;
712 if (!fcn_type.compare(
"LinearInterpolator1d")) {
714 fftjet::LinearInterpolator1d* ptr =
p.get();
717 return return_type(ptr);
721 if (!fcn_type.compare(
"LinInterpolatedTable1D")) {
726 return return_type(ptr);
730 if (!fcn_type.compare(
"Polynomial")) {
731 std::vector<double> coeffs;
732 for (
unsigned i = 0;; ++
i) {
733 std::ostringstream
s;
743 return return_type(
nullptr);
747 typedef std::unique_ptr<AbsPileupCalculator> return_type;
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");
757 const fftjet::LinearInterpolator2d* ip = interp.get();
761 return return_type(
nullptr);
764 if (!fcn_type.compare(
"PileupGrid2d")) {
766 const double rhoFactor = ps.
getParameter<
double>(
"rhoFactor");
768 const fftjet::Grid2d<Real>*
g =
grid.get();
772 return return_type(
nullptr);
775 return return_type(
nullptr);
780 std::unique_ptr<fftjet::LinearInterpolator2d> responseCurve =
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");
789 return (std::make_unique<fftjet::JetMagnitudeMapper2d<fftjet::Peak>>(*responseCurve,
801 std::unique_ptr<fftjet::LinearInterpolator2d> responseCurve =
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");
810 return (std::make_unique<fftjet::JetMagnitudeMapper2d<RecoFFTJet>>(*responseCurve,