24 #include "fftjet/FrequencyKernelConvolver.hh"
25 #include "fftjet/DiscreteGauss2d.hh"
26 #include "fftjet/EquidistantSequence.hh"
27 #include "fftjet/interpolate.hh"
48 using namespace fftjetcms;
65 void endJob()
override;
76 std::unique_ptr<fftjet::AbsFrequencyKernel>
kernel2d;
79 std::unique_ptr<fftjet::AbsConvolverBase<Real>>
convolver;
125 etaFlatteningFactors(ps.getParameter<std::
vector<double>>(
"etaFlatteningFactors")),
126 nPercentiles(ps.getParameter<unsigned>(
"nPercentiles")),
127 convolverMinBin(ps.getParameter<unsigned>(
"convolverMinBin")),
128 convolverMaxBin(ps.getParameter<unsigned>(
"convolverMaxBin")),
129 pileupEtaPhiArea(ps.getParameter<double>(
"pileupEtaPhiArea")),
130 externalGridFiles(ps.getParameter<std::
vector<std::
string>>(
"externalGridFiles")),
131 externalGridMaxEnergy(ps.getParameter<double>(
"externalGridMaxEnergy")),
132 currentFileNum(externalGridFiles.
size() + 1U),
133 flatteningTableRecord(ps.getParameter<std::
string>(
"flatteningTableRecord")),
134 flatteningTableName(ps.getParameter<std::
string>(
"flatteningTableName")),
135 flatteningTableCategory(ps.getParameter<std::
string>(
"flatteningTableCategory")),
136 loadFlatteningFactorsFromDB(ps.getParameter<bool>(
"loadFlatteningFactorsFromDB")) {
142 convolvedFlow = std::make_unique<fftjet::Grid2d<fftjetcms::Real>>(*energyFlow);
147 throw cms::Exception(
"FFTJetBadConfig") <<
"ERROR in FFTJetPileupProcessor constructor:"
148 " number of elements in the \"etaFlatteningFactors\""
149 " vector is inconsistent with the discretization grid binning"
158 const unsigned nScales = ps.
getParameter<
unsigned>(
"nScales");
159 const double minScale = ps.
getParameter<
double>(
"minScale");
160 const double maxScale = ps.
getParameter<
double>(
"maxScale");
161 if (minScale <= 0.0 || maxScale < minScale || nScales == 0U)
162 throw cms::Exception(
"FFTJetBadConfig") <<
"invalid filter scales" << std::endl;
164 filterScales = std::make_unique<fftjet::EquidistantInLogSpace>(minScale, maxScale, nScales);
168 produces<reco::DiscretizedEnergyFlow>(
outputLabel);
174 double kernelEtaScale = ps.
getParameter<
double>(
"kernelEtaScale");
175 const double kernelPhiScale = ps.
getParameter<
double>(
"kernelPhiScale");
176 if (kernelEtaScale <= 0.0 || kernelPhiScale <= 0.0)
177 throw cms::Exception(
"FFTJetBadConfig") <<
"invalid kernel scales" << std::endl;
181 throw cms::Exception(
"FFTJetBadConfig") <<
"invalid convolver bin range" << std::endl;
191 kernel2d = std::unique_ptr<fftjet::AbsFrequencyKernel>(
192 new fftjet::DiscreteGauss2d(kernelEtaScale, kernelPhiScale,
energyFlow->nEta(),
energyFlow->nPhi()));
195 convolver = std::unique_ptr<fftjet::AbsConvolverBase<Real>>(
new fftjet::FrequencyKernelConvolver<Real, Complex>(
212 double densityAfterMixing = -1.0;
220 const double* scales = &(*filterScales)[0];
231 convolver->setEventData(g.data(), g.nEta(), g.nPhi());
232 for (
unsigned iscale = 0; iscale < nScales; ++iscale) {
241 std::sort(sortData, sortData + dataLen);
248 const double dindex = q * (dataLen - 1U);
249 const unsigned ilow =
static_cast<unsigned>(std::floor(dindex));
250 const double percentile =
251 fftjet::lin_interpolate_1d(ilow, ilow + 1U, sortData[ilow], sortData[ilow + 1U], dindex);
260 iEvent.
put(std::make_unique<reco::DiscretizedEnergyFlow>(
264 iEvent.
put(std::make_unique<std::pair<double, double>>(densityBeforeMixing, densityAfterMixing),
outputLabel);
274 throw cms::Exception(
"FFTJetBadConfig") <<
"ERROR in FFTJetPileupProcessor::mixExtraGrid():"
275 " failed to open external grid file "
279 const fftjet::Grid2d<float>*
g =
nullptr;
280 const unsigned maxFail = 100U;
281 unsigned nEnergyRejected = 0;
292 throw cms::Exception(
"FFTJetBadConfig") <<
"ERROR in FFTJetPileupProcessor::mixExtraGrid():"
293 " failed to open external grid file "
302 if (++nEnergyRejected >= maxFail)
303 throw cms::Exception(
"FFTJetBadConfig") <<
"ERROR in FFTJetPileupProcessor::mixExtraGrid():"
304 " too many grids in a row ("
305 << nEnergyRejected <<
") failed the maximum energy cut" << std::endl;
314 throw cms::Exception(
"FFTJetBadConfig") <<
"ERROR in FFTJetPileupProcessor::mixExtraGrid():"
315 " no valid grid records found"
335 for (
unsigned ieta = 0; ieta <
nEta; ++ieta) {
std::unique_ptr< fftjet::AbsConvolverBase< Real > > convolver
std::vector< std::string > externalGridFiles
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
std::string flatteningTableRecord
#define DEFINE_FWK_MODULE(type)
void loadInputCollection(const edm::Event &)
void checkConfig(const Ptr &ptr, const char *message)
std::unique_ptr< fftjet::Grid2d< Real > > fftjet_Grid2d_parser(const edm::ParameterSet &ps)
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
std::string flatteningTableCategory
FFTJetPileupProcessor()=delete
std::unique_ptr< fftjet::Grid2d< fftjetcms::Real > > convolvedFlow
std::vector< double > percentileData
std::unique_ptr< fftjet::Grid2d< fftjetcms::Real > > energyFlow
~FFTJetPileupProcessor() override
std::unique_ptr< fftjet::EquidistantInLogSpace > filterScales
std::unique_ptr< MyFFTEngine > engine
void buildKernelConvolver(const edm::ParameterSet &)
std::vector< double > etaFlatteningFactors
void loadFlatteningFactors(const edm::EventSetup &iSetup)
std::string flatteningTableName
T getParameter(std::string const &) const
void produce(edm::Event &, const edm::EventSetup &) override
double externalGridMaxEnergy
void discretizeEnergyFlow()
bool loadFlatteningFactorsFromDB
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
static const Mapper & instance()
void add_Grid2d_data(fftjet::Grid2d< F2 > *to, const fftjet::Grid2d< F1 > &from)
tuple size
Write out results.
const std::string outputLabel
std::unique_ptr< fftjet::AbsFrequencyKernel > kernel2d