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"
31 #define make_param(type, varname) const type& varname(ps.getParameter<type>(#varname))
38 if (strcmp(
fname,
"eta") == 0)
40 else if (strcmp(
fname,
"phi") == 0)
42 else if (strcmp(
fname,
"magnitude") == 0)
43 *
f = &fftjet::Peak::magnitude;
44 else if (strcmp(
fname,
"driftSpeed") == 0)
45 *
f = &fftjet::Peak::driftSpeed;
46 else if (strcmp(
fname,
"magSpeed") == 0)
47 *
f = &fftjet::Peak::magSpeed;
48 else if (strcmp(
fname,
"lifetime") == 0)
49 *
f = &fftjet::Peak::lifetime;
50 else if (strcmp(
fname,
"mergeTime") == 0)
51 *
f = &fftjet::Peak::mergeTime;
52 else if (strcmp(
fname,
"splitTime") == 0)
53 *
f = &fftjet::Peak::splitTime;
54 else if (strcmp(
fname,
"scale") == 0)
56 else if (strcmp(
fname,
"nearestNeighborDistance") == 0)
57 *
f = &fftjet::Peak::nearestNeighborDistance;
58 else if (strcmp(
fname,
"membershipFactor") == 0)
59 *
f = &fftjet::Peak::membershipFactor;
60 else if (strcmp(
fname,
"recoScale") == 0)
61 *
f = &fftjet::Peak::recoScale;
62 else if (strcmp(
fname,
"recoScaleRatio") == 0)
63 *
f = &fftjet::Peak::recoScaleRatio;
64 else if (strcmp(
fname,
"laplacian") == 0)
65 *
f = &fftjet::Peak::laplacian;
66 else if (strcmp(
fname,
"hessianDeterminant") == 0)
67 *
f = &fftjet::Peak::hessianDeterminant;
68 else if (strcmp(
fname,
"clusterRadius") == 0)
69 *
f = &fftjet::Peak::clusterRadius;
70 else if (strcmp(
fname,
"clusterSeparation") == 0)
71 *
f = &fftjet::Peak::clusterSeparation;
79 if (strcmp(
fname,
"peakEta") == 0)
80 *
f = &RecoFFTJet::peakEta;
81 else if (strcmp(
fname,
"peakPhi") == 0)
82 *
f = &RecoFFTJet::peakPhi;
83 else if (strcmp(
fname,
"peakMagnitude") == 0)
84 *
f = &RecoFFTJet::peakMagnitude;
85 else if (strcmp(
fname,
"magnitude") == 0)
86 *
f = &RecoFFTJet::magnitude;
87 else if (strcmp(
fname,
"driftSpeed") == 0)
88 *
f = &RecoFFTJet::driftSpeed;
89 else if (strcmp(
fname,
"magSpeed") == 0)
90 *
f = &RecoFFTJet::magSpeed;
91 else if (strcmp(
fname,
"lifetime") == 0)
92 *
f = &RecoFFTJet::lifetime;
93 else if (strcmp(
fname,
"mergeTime") == 0)
94 *
f = &RecoFFTJet::mergeTime;
95 else if (strcmp(
fname,
"splitTime") == 0)
96 *
f = &RecoFFTJet::splitTime;
97 else if (strcmp(
fname,
"scale") == 0)
99 else if (strcmp(
fname,
"nearestNeighborDistance") == 0)
100 *
f = &RecoFFTJet::nearestNeighborDistance;
101 else if (strcmp(
fname,
"membershipFactor") == 0)
102 *
f = &RecoFFTJet::membershipFactor;
103 else if (strcmp(
fname,
"recoScale") == 0)
104 *
f = &RecoFFTJet::recoScale;
105 else if (strcmp(
fname,
"recoScaleRatio") == 0)
106 *
f = &RecoFFTJet::recoScaleRatio;
107 else if (strcmp(
fname,
"laplacian") == 0)
108 *
f = &RecoFFTJet::laplacian;
109 else if (strcmp(
fname,
"hessianDeterminant") == 0)
110 *
f = &RecoFFTJet::hessianDeterminant;
111 else if (strcmp(
fname,
"clusterRadius") == 0)
112 *
f = &RecoFFTJet::clusterRadius;
113 else if (strcmp(
fname,
"clusterSeparation") == 0)
114 *
f = &RecoFFTJet::clusterSeparation;
124 typedef std::unique_ptr<fftjet::Grid2d<Real> > return_type;
125 fftjet::Grid2d<Real>*
g =
nullptr;
132 throw cms::Exception(
"FFTJetBadConfig") <<
"Failed to open file " <<
file << std::endl;
135 throw cms::Exception(
"FFTJetBadConfig") <<
"Failed to read file " <<
file << std::endl;
145 return return_type(
nullptr);
151 const std::vector<Real>&
data = ps.
getParameter<std::vector<Real> >(
"data");
161 return return_type(
g);
165 typedef std::unique_ptr<fftjet::Functor1<bool, fftjet::Peak> > return_type;
169 if (!peakselector_type.compare(
"AllPeaksPass")) {
170 return return_type(
new fftjet::AllPeaksPass());
173 if (!peakselector_type.compare(
"EtaAndPtDependentPeakSelector")) {
177 throw cms::Exception(
"FFTJetBadConfig") <<
"Failed to open file " <<
file << std::endl;
180 throw cms::Exception(
"FFTJetBadConfig") <<
"Failed to read file " <<
file << std::endl;
181 return return_type(ptr);
184 if (!peakselector_type.compare(
"EtaAndPtLookupPeakSelector")) {
194 throw cms::Exception(
"FFTJetBadConfig") <<
"Failed to configure EtaAndPtLookupPeakSelector" << std::endl;
199 if (!peakselector_type.compare(
"SimplePeakSelector")) {
209 return return_type(
new fftjet::SimplePeakSelector(
213 if (!peakselector_type.compare(
"ScalePowerPeakSelector")) {
219 return return_type(
new fftjet::ScalePowerPeakSelector(
a,
p,
b,
etaCut));
222 return return_type(
nullptr);
226 typedef std::unique_ptr<fftjet::ScaleSpaceKernel> return_type;
231 if (!MembershipFunction_type.compare(
"InterpolatedMembershipFcn")) {
240 throw cms::Exception(
"FFTJetBadConfig") <<
"Failed to open file " <<
file << std::endl;
244 if (!MembershipFunction_type.compare(
"Composite")) {
246 <<
"Parsing of CompositeKernel objects is not implemented yet" << std::endl;
249 if (!MembershipFunction_type.compare(
"MagneticSmearing")) {
254 make_param(std::vector<double>, fragmentationData);
260 if (fragmentationData.empty())
261 throw cms::Exception(
"FFTJetBadConfig") <<
"Fragmentation function data not defined for "
262 "MagneticSmearingKernel"
264 if (samplesPerBin < 1
U)
265 throw cms::Exception(
"FFTJetBadConfig") <<
"Bad number of samples per bin in "
266 "MagneticSmearingKernel"
269 fftjet::LinearInterpolator1d* fragmentationFunction =
270 new fftjet::LinearInterpolator1d(&fragmentationData[0], fragmentationData.size(), 0.0, 1.0);
272 return return_type(
new fftjet::MagneticSmearingKernel<fftjet::LinearInterpolator1d>(
273 fragmentationFunction, numeratorConst, charge1Fraction, charge2Fraction, samplesPerBin,
true));
276 if (!MembershipFunction_type.compare(
"Interpolated")) {
289 if (
data.size() != nxbins * nybins)
290 throw cms::Exception(
"FFTJetBadConfig") <<
"Bad number of data points for Interpolated kernel" << std::endl;
296 if (!MembershipFunction_type.compare(
"Interpolated3d")) {
308 if (
data.size() != nxbins * nybins * scales.size())
309 throw cms::Exception(
"FFTJetBadConfig") <<
"Bad number of data points for Interpolated3d kernel" << std::endl;
311 return return_type(
new fftjet::InterpolatedKernel3d(
317 fftjet::DefaultKernel2dFactory factory;
318 if (factory[MembershipFunction_type] ==
nullptr) {
319 return return_type(
nullptr);
327 const int n_expected = factory[MembershipFunction_type]->nParameters();
330 throw cms::Exception(
"FFTJetBadConfig") <<
"Bad number of kernel parameters" << std::endl;
332 return std::unique_ptr<fftjet::ScaleSpaceKernel>(
339 if (!bg_Membership_type.compare(
"GaussianNoiseMembershipFcn")) {
342 return std::unique_ptr<AbsBgFunctor>(
new fftjet::GaussianNoiseMembershipFcn(
minWeight,
prior));
345 return std::unique_ptr<AbsBgFunctor>(
nullptr);
349 typedef std::unique_ptr<std::vector<double> > return_type;
353 if (!
className.compare(
"EquidistantInLinearSpace") || !
className.compare(
"EquidistantInLogSpace")) {
359 return return_type(
nullptr);
364 if (!
className.compare(
"EquidistantInLinearSpace"))
371 return_type scales(
new std::vector<double>(ps.
getParameter<std::vector<double> >(
"scales")));
374 const unsigned nscales = scales->size();
375 for (
unsigned i = 0;
i < nscales; ++
i)
376 if ((*scales)[
i] <= 0.0)
377 return return_type(
nullptr);
379 for (
unsigned i = 1;
i < nscales; ++
i)
380 for (
unsigned j = 0;
j <
i; ++
j)
381 if ((*scales)[
i] == (*scales)[
j])
382 return return_type(
nullptr);
387 return return_type(
nullptr);
392 typedef std::unique_ptr<fftjet::ClusteringTreeSparsifier<fftjet::Peak, long> > return_type;
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;
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);
455 const std::vector<double>
data(ps.
getParameter<std::vector<double> >(
"data"));
457 return std::unique_ptr<fftjet::LinearInterpolator1d>(
nullptr);
459 return std::unique_ptr<fftjet::LinearInterpolator1d>(
467 throw cms::Exception(
"FFTJetBadConfig") <<
"Failed to open file " <<
file << std::endl;
470 throw cms::Exception(
"FFTJetBadConfig") <<
"Failed to read file " <<
file << std::endl;
471 return std::unique_ptr<fftjet::LinearInterpolator2d>(ip);
475 typedef fftjet::Functor1<double, fftjet::Peak> ptr_type;
476 typedef std::unique_ptr<ptr_type> return_type;
480 if (!property_type.compare(
"Log")) {
482 ptr_type* wr = wrapped.get();
484 return_type
result = return_type(
new fftjet::LogProperty<fftjet::Peak>(wr,
true));
490 if (!property_type.compare(
"PeakProperty")) {
492 fftjet::JetProperty<fftjet::Peak>::JetMemberFunction
fcn;
494 return return_type(
new fftjet::JetProperty<fftjet::Peak>(
fcn));
496 return return_type(
nullptr);
499 if (!property_type.compare(
"MinusScaledLaplacian")) {
502 return return_type(
new fftjet::MinusScaledLaplacian<fftjet::Peak>(
sx,
sy));
505 if (!property_type.compare(
"ScaledHessianDet")) {
506 return return_type(
new fftjet::ScaledHessianDet<fftjet::Peak>());
509 if (!property_type.compare(
"ScaledMagnitude")) {
510 return return_type(
new fftjet::ScaledMagnitude<fftjet::Peak>());
513 if (!property_type.compare(
"ScaledMagnitude2")) {
514 return return_type(
new fftjet::ScaledMagnitude2<fftjet::Peak>());
517 if (!property_type.compare(
"ConstDouble")) {
522 if (!property_type.compare(
"ProportionalToScale")) {
527 if (!property_type.compare(
"MultiplyByConst")) {
530 ptr_type* ptr =
function.get();
538 if (!property_type.compare(
"CompositeFunctor")) {
539 std::unique_ptr<fftjet::Functor1<double, double> > fcn1 =
542 fftjet::Functor1<double, double>*
f1 = fcn1.get();
543 ptr_type*
f2 = fcn2.get();
552 if (!property_type.compare(
"ProductFunctor")) {
555 ptr_type*
f1 = fcn1.get();
556 ptr_type*
f2 = fcn2.get();
565 if (!property_type.compare(
"MagnitudeDependent")) {
566 std::unique_ptr<fftjet::Functor1<double, double> > fcn1 =
568 fftjet::Functor1<double, double>*
f1 = fcn1.get();
576 if (!property_type.compare(
"PeakEtaDependent")) {
577 std::unique_ptr<fftjet::Functor1<double, double> > fcn1 =
579 fftjet::Functor1<double, double>*
f1 = fcn1.get();
587 return return_type(
nullptr);
592 typedef fftjet::Functor1<double, RecoFFTJet> ptr_type;
593 typedef std::unique_ptr<ptr_type> return_type;
597 if (!property_type.compare(
"Log")) {
599 fftjet::Functor1<double, RecoFFTJet>* wr = wrapped.get();
601 return_type
result = return_type(
new fftjet::LogProperty<RecoFFTJet>(wr,
true));
607 if (!property_type.compare(
"JetEtaDependent")) {
608 std::unique_ptr<fftjet::Functor1<double, double> > fcn1 =
610 fftjet::Functor1<double, double>*
f1 = fcn1.get();
618 if (!property_type.compare(
"JetProperty")) {
620 fftjet::JetProperty<RecoFFTJet>::JetMemberFunction
fcn;
622 return return_type(
new fftjet::JetProperty<RecoFFTJet>(
fcn));
624 return return_type(
nullptr);
627 if (!property_type.compare(
"ConstDouble")) {
632 if (!property_type.compare(
"ProportionalToScale")) {
637 if (!property_type.compare(
"MultiplyByConst")) {
640 ptr_type* ptr =
function.get();
648 if (!property_type.compare(
"CompositeFunctor")) {
649 std::unique_ptr<fftjet::Functor1<double, double> > fcn1 =
652 fftjet::Functor1<double, double>*
f1 = fcn1.get();
653 ptr_type*
f2 = fcn2.get();
662 if (!property_type.compare(
"ProductFunctor")) {
665 ptr_type*
f1 = fcn1.get();
666 ptr_type*
f2 = fcn2.get();
675 if (!property_type.compare(
"MagnitudeDependent")) {
676 std::unique_ptr<fftjet::Functor1<double, double> > fcn1 =
678 fftjet::Functor1<double, double>*
f1 = fcn1.get();
686 return return_type(
nullptr);
689 std::unique_ptr<fftjet::Functor2<double, fftjet::RecombinedJet<VectorLike>, fftjet::RecombinedJet<VectorLike> > >
692 fftjet::Functor2<double, fftjet::RecombinedJet<VectorLike>, fftjet::RecombinedJet<VectorLike> > >
697 if (!distance_type.compare(
"JetConvergenceDistance")) {
705 return return_type(
nullptr);
709 typedef std::unique_ptr<fftjet::Functor1<double, double> > return_type;
713 if (!fcn_type.compare(
"LinearInterpolator1d")) {
715 fftjet::LinearInterpolator1d* ptr =
p.get();
718 return return_type(ptr);
722 if (!fcn_type.compare(
"LinInterpolatedTable1D")) {
727 return return_type(ptr);
731 if (!fcn_type.compare(
"Polynomial")) {
732 std::vector<double> coeffs;
733 for (
unsigned i = 0;; ++
i) {
734 std::ostringstream
s;
744 return return_type(
nullptr);
748 typedef std::unique_ptr<AbsPileupCalculator> return_type;
752 if (!fcn_type.compare(
"EtaDependentPileup")) {
753 std::unique_ptr<fftjet::LinearInterpolator2d> interp =
755 const double inputRhoFactor = ps.
getParameter<
double>(
"inputRhoFactor");
756 const double outputRhoFactor = ps.
getParameter<
double>(
"outputRhoFactor");
758 const fftjet::LinearInterpolator2d* ip = interp.get();
762 return return_type(
nullptr);
765 if (!fcn_type.compare(
"PileupGrid2d")) {
767 const double rhoFactor = ps.
getParameter<
double>(
"rhoFactor");
769 const fftjet::Grid2d<Real>*
g =
grid.get();
773 return return_type(
nullptr);
776 return return_type(
nullptr);
781 std::unique_ptr<fftjet::LinearInterpolator2d> responseCurve =
784 const double minPredictor = ps.
getParameter<
double>(
"minPredictor");
785 const double maxPredictor = ps.
getParameter<
double>(
"maxPredictor");
786 const unsigned nPredPoints = ps.
getParameter<
unsigned>(
"nPredPoints");
787 const double maxMagnitude = ps.
getParameter<
double>(
"maxMagnitude");
788 const unsigned nMagPoints = ps.
getParameter<
unsigned>(
"nMagPoints");
791 new fftjet::JetMagnitudeMapper2d<fftjet::Peak>(*responseCurve,
803 std::unique_ptr<fftjet::LinearInterpolator2d> responseCurve =
806 const double minPredictor = ps.
getParameter<
double>(
"minPredictor");
807 const double maxPredictor = ps.
getParameter<
double>(
"maxPredictor");
808 const unsigned nPredPoints = ps.
getParameter<
unsigned>(
"nPredPoints");
809 const double maxMagnitude = ps.
getParameter<
double>(
"maxMagnitude");
810 const unsigned nMagPoints = ps.
getParameter<
unsigned>(
"nMagPoints");
813 new fftjet::JetMagnitudeMapper2d<RecoFFTJet>(*responseCurve,