23 #include "fftjet/ProximityClusteringTree.hh"
24 #include "fftjet/ClusteringSequencer.hh"
25 #include "fftjet/ClusteringTreeSparsifier.hh"
26 #include "fftjet/FrequencyKernelConvolver.hh"
27 #include "fftjet/FrequencySequentialConvolver.hh"
28 #include "fftjet/DiscreteGauss1d.hh"
29 #include "fftjet/DiscreteGauss2d.hh"
59 using namespace fftjetcms;
75 typedef fftjet::SparseClusteringTree<fftjet::Peak, long>
SparseTree;
76 typedef fftjet::ClusteringSequencer<Real>
Sequencer;
77 typedef fftjet::ClusteringTreeSparsifier<fftjet::Peak, long>
Sparsifier;
82 void endJob()
override;
107 std::unique_ptr<fftjet::AbsFrequencyKernel>
kernel2d;
108 std::unique_ptr<fftjet::AbsFrequencyKernel1d>
etaKernel;
109 std::unique_ptr<fftjet::AbsFrequencyKernel1d>
phiKernel;
112 std::unique_ptr<fftjet::AbsConvolverBase<Real> >
convolver;
118 std::unique_ptr<fftjet::AbsDistanceCalculator<fftjet::Peak> >
distanceCalc;
153 clusteringTree(nullptr),
154 completeEventDataCutoff(ps.getParameter<double>(
"completeEventDataCutoff")),
155 makeClusteringTree(ps.getParameter<bool>(
"makeClusteringTree")),
156 verifyDataConversion(ps.getUntrackedParameter<bool>(
"verifyDataConversion",
false)),
157 storeDiscretizationGrid(ps.getParameter<bool>(
"storeDiscretizationGrid")),
158 sparsify(ps.getParameter<bool>(
"sparsify")),
163 produces<reco::PattRecoTree<float, reco::PattRecoPeak<float> > >(
outputLabel);
165 produces<reco::PattRecoTree<double, reco::PattRecoPeak<double> > >(
outputLabel);
168 produces<reco::DiscretizedEnergyFlow>(
outputLabel);
177 <<
"FFTJetPatRecoProducer failed to open file " << externalGridFile << std::endl;
182 <<
"FFTJetPatRecoProducer is not configured to produce anything" << std::endl;
200 std::unique_ptr<std::vector<double> > iniScales =
205 const unsigned maxAdaptiveScales = ps.
getParameter<
unsigned>(
"maxAdaptiveScales");
206 const double minAdaptiveRatioLog = ps.
getParameter<
double>(
"minAdaptiveRatioLog");
207 if (minAdaptiveRatioLog <= 0.0)
208 throw cms::Exception(
"FFTJetBadConfig") <<
"bad adaptive ratio logarithm limit" << std::endl;
214 const unsigned nscales = iniScales->size();
215 for (
unsigned i = 0;
i < nscales; ++
i)
216 if (cs >= (*iniScales)[
i])
217 throw cms::Exception(
"FFTJetBadConfig") <<
"incompatible scale for complete event" << std::endl;
241 const std::vector<double> etaDependentScaleFactors(ps.
getParameter<std::vector<double> >(
"etaDependentScaleFactors"));
244 const bool use2dKernel = etaDependentScaleFactors.empty();
246 if (etaDependentScaleFactors.size() !=
energyFlow->nEta())
247 throw cms::Exception(
"FFTJetBadConfig") <<
"invalid number of eta-dependent scale factors" << std::endl;
250 double kernelEtaScale = ps.
getParameter<
double>(
"kernelEtaScale");
251 const double kernelPhiScale = ps.
getParameter<
double>(
"kernelPhiScale");
252 if (kernelEtaScale <= 0.0 || kernelPhiScale <= 0.0)
253 throw cms::Exception(
"FFTJetBadConfig") <<
"invalid kernel scale" << std::endl;
260 const bool fixEfficiency = ps.
getParameter<
bool>(
"fixEfficiency");
263 unsigned convolverMinBin = 0, convolverMaxBin = 0;
264 if (fixEfficiency || !use2dKernel) {
265 convolverMinBin = ps.
getParameter<
unsigned>(
"convolverMinBin");
266 convolverMaxBin = ps.
getParameter<
unsigned>(
"convolverMaxBin");
274 kernel2d = std::unique_ptr<fftjet::AbsFrequencyKernel>(
275 new fftjet::DiscreteGauss2d(kernelEtaScale, kernelPhiScale,
energyFlow->nEta(),
energyFlow->nPhi()));
278 convolver = std::unique_ptr<fftjet::AbsConvolverBase<Real> >(
new fftjet::FrequencyKernelConvolver<Real, Complex>(
279 engine.get(), kernel2d.get(), convolverMinBin, convolverMaxBin));
287 std::unique_ptr<fftjet::AbsFrequencyKernel1d>(
new fftjet::DiscreteGauss1d(kernelEtaScale,
energyFlow->nEta()));
290 std::unique_ptr<fftjet::AbsFrequencyKernel1d>(
new fftjet::DiscreteGauss1d(kernelPhiScale,
energyFlow->nPhi()));
293 convolver = std::unique_ptr<fftjet::AbsConvolverBase<Real> >(
294 new fftjet::FrequencySequentialConvolver<Real, Complex>(
engine.get(),
298 etaDependentScaleFactors,
306 const double peakFinderMaxEta = ps.
getParameter<
double>(
"peakFinderMaxEta");
307 if (peakFinderMaxEta <= 0.0)
308 throw cms::Exception(
"FFTJetBadConfig") <<
"invalid peak finder eta cut" << std::endl;
309 const double maxMagnitude = ps.
getParameter<
double>(
"peakFinderMaxMagnitude");
316 return fftjet::PeakFinder(maxMagnitude,
true, minBin, maxBin);
329 template <
class Real>
333 auto tree = std::make_unique<StoredTree>();
340 const std::vector<double>& scalesUsed(
sequencer->getInitialScales());
343 throw cms::Exception(
"FFTJetInterface") <<
"Data conversion failed for sparse clustering tree" << std::endl;
349 template <
class Real>
353 auto tree = std::make_unique<StoredTree>();
360 const std::vector<double>& scalesUsed(
sequencer->getInitialScales());
363 throw cms::Exception(
"FFTJetInterface") <<
"Data conversion failed for dense clustering tree" << std::endl;
388 buildSparseProduct<float>(
iEvent);
390 buildSparseProduct<double>(
iEvent);
393 buildDenseProduct<float>(iEvent);
395 buildDenseProduct<double>(
iEvent);
402 auto flow = std::make_unique<reco::DiscretizedEnergyFlow>(
403 g.data(), g.title(), g.etaMin(), g.etaMax(), g.phiBin0Edge(), g.nEta(), g.nPhi());
406 fftjet::Grid2d<Real>
check(
407 flow->nEtaBins(), flow->etaMin(), flow->etaMax(), flow->nPhiBins(), flow->phiBin0Edge(), flow->title());
408 check.blockSet(flow->data(), flow->nEtaBins(), flow->nPhiBins());
422 <<
"Failed to write grid data into an external file" << std::endl;
fftjet::Grid2d< float > * convert_Grid2d_to_float(const fftjet::Grid2d< Numeric > &grid)
std::unique_ptr< Sparsifier > sparsifier
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
std::unique_ptr< fftjet::AbsFrequencyKernel1d > etaKernel
Class for storing FFTJet sparse clustering trees.
std::ofstream externalGridStream
constexpr unsigned int maxBin
#define DEFINE_FWK_MODULE(type)
void loadInputCollection(const edm::Event &)
unique_ptr< ClusterSequence > cs
void buildSparseProduct(edm::Event &) const
void buildKernelConvolver(const edm::ParameterSet &)
void checkConfig(const Ptr &ptr, const char *message)
std::unique_ptr< fftjet::Grid2d< Real > > fftjet_Grid2d_parser(const edm::ParameterSet &ps)
fftjet::SparseClusteringTree< fftjet::Peak, long > SparseTree
std::unique_ptr< fftjet::AbsDistanceCalculator< fftjet::Peak > > distanceCalc
fftjet::ClusteringTreeSparsifier< fftjet::Peak, long > Sparsifier
void buildDenseProduct(edm::Event &) 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
const bool storeDiscretizationGrid
std::unique_ptr< fftjet::AbsFrequencyKernel1d > phiKernel
FFTJetPatRecoProducer()=delete
std::unique_ptr< Sequencer > sequencer
double getEventScale() const
std::unique_ptr< fftjet::Functor1< bool, fftjet::Peak > > peakSelector
void produce(edm::Event &, const edm::EventSetup &) override
std::unique_ptr< fftjet::Grid2d< fftjetcms::Real > > energyFlow
~FFTJetPatRecoProducer() override
void sparsePeakTreeToStorable(const fftjet::SparseClusteringTree< fftjet::Peak, long > &in, bool writeOutScaleInfo, reco::PattRecoTree< Real, reco::PattRecoPeak< Real > > *out)
std::unique_ptr< MyFFTEngine > anotherEngine
ClusteringTree * clusteringTree
fftjet::ClusteringSequencer< Real > Sequencer
std::unique_ptr< fftjet::AbsDistanceCalculator< fftjet::Peak > > fftjet_DistanceCalculator_parser(const edm::ParameterSet &ps)
bool storeInSinglePrecision() const
void densePeakTreeToStorable(const fftjet::AbsClusteringTree< fftjet::Peak, long > &in, bool writeOutScaleInfo, reco::PattRecoTree< Real, reco::PattRecoPeak< Real > > *out)
const double completeEventDataCutoff
const bool makeClusteringTree
void sparsePeakTreeFromStorable(const reco::PattRecoTree< Real, reco::PattRecoPeak< Real > > &in, const std::vector< double > *scaleSetIfNotAdaptive, double completeEventScale, fftjet::SparseClusteringTree< fftjet::Peak, long > *out)
void densePeakTreeFromStorable(const reco::PattRecoTree< Real, reco::PattRecoPeak< Real > > &in, const std::vector< double > *scaleSetIfNotAdaptive, double completeEventScale, fftjet::AbsClusteringTree< fftjet::Peak, long > *out)
std::unique_ptr< fftjet::AbsConvolverBase< Real > > convolver
T getParameter(std::string const &) const
void copy_Grid2d_data(fftjet::Grid2d< F2 > *to, const fftjet::Grid2d< F1 > &from)
void discretizeEnergyFlow()
std::unique_ptr< fftjet::AbsFrequencyKernel > kernel2d
fftjet::PeakFinder buildPeakFinder(const edm::ParameterSet &)
std::unique_ptr< fftjet::Functor1< bool, fftjet::Peak > > fftjet_PeakSelector_parser(const edm::ParameterSet &ps)
const bool verifyDataConversion
bool storeGridsExternally
std::unique_ptr< fftjet::ClusteringTreeSparsifier< fftjet::Peak, long > > fftjet_ClusteringTreeSparsifier_parser(const edm::ParameterSet &ps)
fftjet::ProximityClusteringTree< fftjet::Peak, long > ClusteringTree
fftjet::Grid2d< float > * extGrid
std::unique_ptr< std::vector< double > > fftjet_ScaleSet_parser(const edm::ParameterSet &ps)
const std::string outputLabel
std::unique_ptr< MyFFTEngine > engine
constexpr unsigned int minBin