24 #include "fftjet/peakEtLifetime.hh" 44 #define make_param(type, varname) const type& varname(ps.getParameter<type>(#varname)) 46 #define init_param(type, varname) varname(ps.getParameter<type>(#varname)) 55 #define jet_type_switch(method, arg1, arg2) \ 59 method<reco::CaloJet>(arg1, arg2); \ 62 method<reco::PFJet>(arg1, arg2); \ 65 method<reco::GenJet>(arg1, arg2); \ 68 method<reco::TrackJet>(arg1, arg2); \ 71 method<reco::BasicJet>(arg1, arg2); \ 74 assert(!"ERROR in FFTJetProducer : invalid jet type."\ 75 " This is a bug. Please report."); \ 80 struct LocalSortByPt {
82 inline bool operator()(
const Jet&
l,
const Jet&
r)
const {
83 return l.pt() > r.pt();
91 if (!name.compare(
"fixed"))
93 else if (!name.compare(
"maximallyStable"))
94 return MAXIMALLY_STABLE;
95 else if (!name.compare(
"globallyAdaptive"))
96 return GLOBALLY_ADAPTIVE;
97 else if (!name.compare(
"locallyAdaptive"))
98 return LOCALLY_ADAPTIVE;
99 else if (!name.compare(
"fromGenJets"))
102 throw cms::Exception(
"FFTJetBadConfig") <<
"Invalid resolution specification \"" << name <<
"\"" << std::endl;
105 template <
typename T>
107 produces<std::vector<reco::FFTAnyJet<T> > >(
tag).setBranchAlias(alias);
151 iterationsPerformed(1
U),
155 throw cms::Exception(
"FFTJetBadConfig") <<
"Can't resum constituents if they are not assigned" << std::endl;
157 produces<reco::FFTJetProducerSummary>(
outputLabel);
169 consumes<reco::PattRecoTree<fftjetcms::Real, reco::PattRecoPeak<fftjetcms::Real> > >(
treeLabel);
185 template <
class Real>
193 if (!input->isSparse())
194 throw cms::Exception(
"FFTJetBadConfig") <<
"The stored clustering tree is not sparse" << std::endl;
204 const fftjet::Functor1<bool, fftjet::Peak>& peakSelect,
212 const unsigned sz = input->size();
213 preclusters->reserve(sz);
214 for (
unsigned i = 0;
i < sz; ++
i) {
216 fftjet::Peak
p(jet.precluster());
217 const double scale(
p.scale());
218 p.setEtaPhi(jet.vec().Eta(), jet.vec().Phi());
222 preclusters->push_back(
p);
227 const fftjet::Functor1<bool, fftjet::Peak>& peakSelect,
233 const unsigned nNodes =
nodes.size();
234 const SparseTree::NodeId* pnodes = nNodes ? &
nodes[0] :
nullptr;
235 preclusters->reserve(nNodes);
236 for (
unsigned i = 0;
i < nNodes; ++
i)
237 preclusters->push_back(
sparseTree.uncheckedNode(pnodes[
i]).getCluster());
241 fftjet::Peak*
clusters = nNodes ? &(*preclusters)[0] :
nullptr;
242 for (
unsigned i = 0; i < nNodes; ++
i) {
243 clusters[
i].setCode(pnodes[i]);
249 const fftjet::Functor1<bool, fftjet::Peak>& peakSelect,
250 std::vector<SparseTree::NodeId>* mynodes) {
258 tree.getPassingNodes(
usedLevel, peakSelect, mynodes);
265 if (tree.stableClusterCount(
268 tree.getPassingNodes(
usedLevel, peakSelect, mynodes);
277 const int maxlev = tree.maxStoredLevel();
278 bool levelFound =
false;
280 for (
int ifac = 1; ifac > -2 && !levelFound; ifac -= 2) {
282 if (level > 0 && level <= maxlev)
296 const unsigned maxlev = tree.maxStoredLevel();
305 const unsigned d = nClustersRequested > n ? nClustersRequested - n : n -
nClustersRequested;
314 tree.getPassingNodes(
usedLevel, peakSelect, mynodes);
323 assert(!
"ERROR in FFTJetProducer::selectTreeNodes : " 324 "should never get here! This is a bug. Please report.");
336 for (
unsigned i = 0;
i < nClus; ++
i) {
337 clus[
i].setRecoScale(scaleCalc(clus[
i]));
338 clus[
i].setRecoScaleRatio(ratioCalc(clus[i]));
339 clus[
i].setMembershipFactor(factorCalc(clus[i]));
352 fftjet::DefaultRecombinationAlgFactory<Real, VectorLike, BgData, VBuilder> factory;
372 bool rebuildGrid =
flow.get() ==
nullptr;
379 flow = std::unique_ptr<fftjet::Grid2d<Real> >(
new fftjet::Grid2d<Real>(
387 fftjet::Functor2<double, RecoFFTJet, RecoFFTJet>& distanceCalc(*
jetDistanceCalc);
389 const unsigned nJets = previous.size();
390 if (nJets != nextSet.size())
397 bool converged =
true;
398 for (
unsigned i = 0;
i < nJets; ++
i) {
399 const double d = distanceCalc(prev[
i], next[i]);
400 next[
i].setConvergenceDistance(d);
414 unsigned iterNum = 1
U;
415 bool converged =
false;
421 for (
unsigned i = 0;
i < nJets; ++
i) {
423 fftjet::Peak
p(jet.precluster());
424 p.setEtaPhi(jet.vec().Eta(), jet.vec().Phi());
425 p.setRecoScale(scaleCalc(jet));
426 p.setRecoScaleRatio(ratioCalc(jet));
427 p.setMembershipFactor(factorCalc(jet));
438 throw cms::Exception(
"FFTJetInterface") <<
"FFTJet algorithm failed" << std::endl;
460 for (
unsigned i = 0;
i < nJets; ++
i) {
462 jets[
i].setPeakEtaPhi(oldp.eta(), oldp.phi());
476 const unsigned nJets =
recoJets.size();
477 const unsigned* clusterMask =
gridAlg->getClusterMask();
482 const unsigned nInputs =
eventData.size();
485 for (
unsigned i = 0;
i < nInputs; ++
i) {
487 const int iPhi = g.getPhiBin(item.Phi());
488 const int iEta = g.getEtaBin(item.Eta());
489 const unsigned mask = iEta >= 0 && iEta < nEta ? clusterMask[iEta * nPhi + iPhi] : 0;
490 assert(mask <= nJets);
496 const unsigned nJets =
recoJets.size();
497 const unsigned* clusterMask =
recoAlg->getClusterMask();
498 const unsigned maskLength =
recoAlg->getLastNData();
501 const unsigned* candIdx = maskLength ? &
candidateIndex[0] :
nullptr;
502 for (
unsigned i = 0;
i < maskLength; ++
i) {
507 const unsigned mask = clusterMask[
i];
508 assert(mask <= nJets);
515 template <
typename T>
517 using namespace reco;
533 auto jets = std::make_unique<OutputCollection>();
534 const unsigned nJets =
recoJets.size();
535 jets->reserve(nJets);
538 double previousPt = DBL_MAX;
539 for (
unsigned ijet = 0; ijet < nJets; ++ijet) {
548 for (
unsigned i = 0;
i < nCon; ++
i)
570 double ncells = myjet.ncells();
575 jet.setJetArea(cellArea * ncells);
584 jets->push_back(OutputJet(jet, fj));
587 const double pt = jet.pt();
595 std::sort(
jets->begin(),
jets->end(), LocalSortByPt());
611 for (
unsigned i = 0;
i < nCon; ++
i)
622 std::make_unique<reco::FFTJetProducerSummary>(
thresholds,
640 loadSparseTreeData<float>(
iEvent);
642 loadSparseTreeData<double>(
iEvent);
680 unsigned nPreclustersFound = 0
U;
682 for (
unsigned i = 0;
i < npre; ++
i)
693 throw cms::Exception(
"FFTJetInterface") <<
"FFTJet algorithm failed (first iteration)" << std::endl;
702 const unsigned nJets =
recoJets.size();
713 const unsigned nJets =
recoJets.size();
717 for (
unsigned i = 0;
i <= nJets; ++
i)
791 std::unique_ptr<fftjet::Functor2<double, FFTJetProducer::RecoFFTJet, FFTJetProducer::RecoFFTJet> >
814 fftjet::DefaultVectorRecombinationAlgFactory<VectorLike, BgData, VBuilder> factory;
847 "invalid spec for the " 848 "reconstruction scale calculator from peaks");
853 "invalid spec for the " 854 "reconstruction scale ratio calculator from peaks");
859 "invalid spec for the " 860 "membership function factor calculator from peaks");
866 "invalid spec for the " 867 "reconstruction scale calculator from jets");
871 "invalid spec for the " 872 "reconstruction scale ratio calculator from jets");
876 "invalid spec for the " 877 "membership function factor calculator from jets");
881 "invalid spec for the " 882 "jet distance calculator");
894 std::vector<int> matchTable;
899 assert(nmatched ==
recoJets.size());
904 for (
unsigned i = 0;
i < nmatched; ++
i)
910 int status = jet->status();
915 jet->setStatus(status);
919 std::unique_ptr<fftjet::Grid2d<fftjetcms::Real> >&
density) {
928 const unsigned nEta = g.nEta();
929 const unsigned nPhi = g.nPhi();
932 const double eta(g.etaBinCenter(
ieta));
936 const double phi(g.phiBinCenter(
iphi));
940 const double pil = calc(
eta, 0.0, s);
949 std::unique_ptr<fftjet::Grid2d<fftjetcms::Real> >&
density) {
958 const bool phiDependent = f->minDim() == 3
U;
961 const unsigned nEta = g.nEta();
962 const unsigned nPhi = g.nPhi();
964 double functorArg[3] = {0.0, 0.0, 0.0};
971 const double eta(g.etaBinCenter(
ieta));
976 functorArg[1] = g.phiBinCenter(
iphi);
977 g.uncheckedSetBin(
ieta,
iphi, (*f)(functorArg, 3
U));
980 const double pil = (*f)(functorArg, 2
U);
990 assert(!
"Pile-up subtraction for fuzzy clustering " 991 "is not implemented yet");
994 const unsigned nJets =
recoJets.size();
999 for (
unsigned i = 0;
i < nJets; ++
i)
1004 const unsigned nEta = g.nEta();
1005 const unsigned nPhi = g.nPhi();
1006 const double cellArea = g.etaBinWidth() * g.phiBinWidth();
1019 double* recoScaleRatios = recoScales + nJets;
1020 double* memFactors = recoScaleRatios + nJets;
1021 double*
dEta = memFactors + nJets;
1022 double* dPhiBuf = dEta + nJets;
1028 for (
unsigned ijet = 0; ijet < nJets; ++ijet) {
1030 const fftjet::Peak& peak(jet.precluster());
1034 fftjet::AbsMembershipFunction* m3d =
dynamic_cast<fftjet::AbsMembershipFunction*
>(peak.membershipFunction());
1038 assert(!
"Pile-up subtraction for 3-d membership functions " 1039 "is not implemented yet");
1041 fftjet::AbsKernel2d* m2d =
dynamic_cast<fftjet::AbsKernel2d*
>(peak.membershipFunction());
1045 memFcns2d[ijet] = m2d;
1047 recoScales[ijet] = scaleCalc(jet);
1048 recoScaleRatios[ijet] = ratioCalc(jet);
1049 memFactors[ijet] = factorCalc(jet);
1050 cellCounts[ijet] = 0
U;
1052 const double jetPhi = jet.vec().Phi();
1056 dphi -= (2.0 *
M_PI);
1057 while (dphi < -
M_PI)
1058 dphi += (2.0 *
M_PI);
1059 dPhiBuf[
iphi * nJets + ijet] = dphi;
1067 const double eta(g.etaBinCenter(
ieta));
1071 for (
unsigned ijet = 0; ijet < nJets; ++ijet)
1076 unsigned maxWJet(nJets);
1077 const double*
dPhi = dPhiBuf +
iphi * nJets;
1079 for (
unsigned ijet = 0; ijet < nJets; ++ijet) {
1080 if (recoScaleRatios[ijet] > 0.0)
1081 memFcns2d[ijet]->setScaleRatio(recoScaleRatios[ijet]);
1082 const double f = memFactors[ijet] * (*memFcns2d[ijet])(dEta[ijet], dPhi[ijet], recoScales[ijet]);
1089 if (maxWJet < nJets) {
1090 pileup[maxWJet] += vMaker(cellArea * databuf[
iphi],
eta, g.phiBinCenter(iphi));
1091 cellCounts[maxWJet]++;
std::vector< std::vector< reco::CandidatePtr > > constituents
void produce(edm::Event &, const edm::EventSetup &) override
unsigned matchOneToOne(const std::vector< T1 > &v1, const std::vector< T2 > &v2, const DistanceCalculator &calc, std::vector< int > *matchFrom1To2, const double maxMatchingDistance=1.0e300)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
virtual std::unique_ptr< fftjet::ScaleSpaceKernel > parse_jetMembershipFunction(const edm::ParameterSet &)
std::unique_ptr< fftjet::Functor2< double, RecoFFTJet, RecoFFTJet > > jetDistanceCalc
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
unsigned iterationsPerformed
const bool useGriddedAlgorithm
std::vector< fftjetcms::VectorLike > pileup
edm::Handle< reco::CandidateView > inputCollection
static Resolution parse_resolution(const std::string &name)
const bool resumConstituents
void selectTreeNodes(const SparseTree &tree, const fftjet::Functor1< bool, fftjet::Peak > &peakSelect, std::vector< SparseTree::NodeId > *nodes)
Class for storing FFTJet sparse clustering trees.
const double gridScanMaxEta
void saveResults(edm::Event &iEvent, const edm::EventSetup &, unsigned nPreclustersFound)
virtual void assignMembershipFunctions(std::vector< fftjet::Peak > *preclusters)
std::unique_ptr< fftjet::Functor1< double, fftjet::Peak > > memberFactorCalcPeak
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Ptr< value_type > ptrAt(size_type i) const
const reco::Particle::Point & vertexUsed() const
void loadInputCollection(const edm::Event &)
std::unique_ptr< fftjet::Functor1< double, RecoFFTJet > > recoScaleCalcJet
const std::string recombinationAlgorithm
const bool subtractPileupAs4Vec
std::unique_ptr< fftjet::Functor1< double, fftjet::Peak > > fftjet_PeakFunctor_parser(const edm::ParameterSet &ps)
virtual std::unique_ptr< fftjetcms::AbsBgFunctor > parse_bgMembershipFunction(const edm::ParameterSet &)
fftjet::RecombinedJet< VectorLike > jetFromStorable(const reco::FFTJet< Real > &jet)
void checkConfig(const Ptr &ptr, const char *message)
unsigned nEtaBins() const
const double unlikelyBgWeight
void makeProduces(const std::string &alias, const std::string &tag)
std::unique_ptr< AbsBgFunctor > fftjet_BgFunctor_parser(const edm::ParameterSet &ps)
const bool subtractPileup
std::unique_ptr< fftjet::Grid2d< Real > > fftjet_Grid2d_parser(const edm::ParameterSet &ps)
std::vector< double > doubleBuf
std::vector< fftjet::AbsKernel2d * > memFcns2dVec
std::vector< RecoFFTJet > recoJets
std::unique_ptr< GridAlg > gridAlg
const double recombinationDataCutoff
Summary info for pile-up determined by Gaussian filtering.
std::vector< unsigned > occupancy
const double minStableScale
const double maxStableScale
#define init_param(type, varname)
std::vector< fftjet::Peak > preclusters
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
void determineVectorConstituents()
static std::string const input
std::unique_ptr< fftjet::Functor2< double, fftjet::RecombinedJet< VectorLike >, fftjet::RecombinedJet< VectorLike > > > fftjet_JetDistance_parser(const edm::ParameterSet &ps)
edm::EDGetTokenT< reco::PattRecoTree< fftjetcms::Real, reco::PattRecoPeak< fftjetcms::Real > > > input_recotree_token_
const double * data() const
void loadSparseTreeData(const edm::Event &)
const bool reuseExistingGrid
double getEventScale() const
const unsigned nClustersRequested
virtual std::unique_ptr< fftjetcms::AbsPileupCalculator > parse_pileupDensityCalc(const edm::ParameterSet &ps)
std::unique_ptr< std::vector< double > > iniScales
std::vector< unsigned > candidateIndex
#define DEFINE_FWK_MODULE(type)
std::unique_ptr< fftjetcms::AbsBgFunctor > bgMembershipFunction
std::unique_ptr< fftjet::Grid2d< fftjetcms::Real > > energyFlow
virtual std::unique_ptr< fftjet::Functor1< double, RecoFFTJet > > parse_recoScaleCalcJet(const edm::ParameterSet &)
std::unique_ptr< fftjet::Functor1< double, RecoFFTJet > > memberFactorCalcJet
math::XYZTLorentzVector VectorLike
fftjet::SparseClusteringTree< fftjet::Peak, long > SparseTree
std::unique_ptr< fftjet::Functor1< double, fftjet::RecombinedJet< VectorLike > > > fftjet_JetFunctor_parser(const edm::ParameterSet &ps)
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
virtual std::unique_ptr< fftjet::Functor1< double, fftjet::Peak > > parse_recoScaleRatioCalcPeak(const edm::ParameterSet &)
Implements inheritance relationships for FFTJet jets.
unsigned nPhiBins() const
static void setJetStatusBit(RecoFFTJet *jet, int mask, bool value)
std::vector< RecoFFTJet > iterJets
const char * title() const
virtual void determinePileupDensityFromDB(const edm::Event &iEvent, const edm::EventSetup &iSetup, std::unique_ptr< fftjet::Grid2d< fftjetcms::Real > > &density)
std::vector< unsigned > cellCountsVec
std::unique_ptr< fftjet::Functor1< double, RecoFFTJet > > recoScaleRatioCalcJet
std::unique_ptr< fftjet::ScaleSpaceKernel > jetMembershipFunction
std::string pileupTableRecord
std::string pileupTableName
std::vector< double > thresholds
unsigned iterateJetReconstruction()
std::unique_ptr< AbsPileupCalculator > fftjet_PileupCalculator_parser(const edm::ParameterSet &ps)
void setNCells(const double nc)
const bool calculatePileup
const bool assignConstituents
bool storeInSinglePrecision() const
void setPileup(const math::XYZTLorentzVector &p)
bool checkConvergence(const std::vector< RecoFFTJet > &previousIterResult, std::vector< RecoFFTJet > &thisIterResult)
const edm::InputTag treeLabel
virtual void selectPreclusters(const SparseTree &tree, const fftjet::Functor1< bool, fftjet::Peak > &peakSelector, std::vector< fftjet::Peak > *preclusters)
void sparsePeakTreeFromStorable(const reco::PattRecoTree< Real, reco::PattRecoPeak< Real > > &in, const std::vector< double > *scaleSetIfNotAdaptive, double completeEventScale, fftjet::SparseClusteringTree< fftjet::Peak, long > *out)
const edm::InputTag genJetsLabel
const edm::ParameterSet myConfiguration
edm::EDGetTokenT< reco::DiscretizedEnergyFlow > input_energyflow_token_
fftjet::RecombinedJet< fftjetcms::VectorLike > RecoFFTJet
virtual std::unique_ptr< fftjet::Functor1< double, RecoFFTJet > > parse_recoScaleRatioCalcJet(const edm::ParameterSet &)
edm::EDGetTokenT< reco::FFTJetPileupSummary > input_pusummary_token_
virtual bool isPhiDependent() const =0
const double stabilityAlpha
void discretizeEnergyFlow()
const unsigned maxInitialPreclusters
std::string pileupTableCategory
std::unique_ptr< fftjetcms::AbsPileupCalculator > pileupDensityCalc
void setFourVec(const math::XYZTLorentzVector &p)
std::vector< SparseTree::NodeId > nodes
std::unique_ptr< fftjet::Functor1< bool, fftjet::Peak > > fftjet_PeakSelector_parser(const edm::ParameterSet &ps)
void determineGriddedConstituents()
std::unique_ptr< fftjet::Functor1< bool, fftjet::Peak > > peakSelector
const double convergenceDistance
edm::EDGetTokenT< std::vector< reco::FFTAnyJet< reco::GenJet > > > input_genjet_token_
void writeJets(edm::Event &iEvent, const edm::EventSetup &)
~FFTJetProducer() override
std::unique_ptr< fftjet::Functor1< double, fftjet::Peak > > recoScaleRatioCalcPeak
const edm::InputTag pileupLabel
virtual std::unique_ptr< fftjet::Functor1< bool, fftjet::Peak > > parse_peakSelector(const edm::ParameterSet &)
std::unique_ptr< fftjet::Grid2d< fftjetcms::Real > > pileupEnergyFlow
virtual void genJetPreclusters(const SparseTree &tree, edm::Event &, const edm::EventSetup &, const fftjet::Functor1< bool, fftjet::Peak > &peakSelector, std::vector< fftjet::Peak > *preclusters)
bool loadEnergyFlow(const edm::Event &iEvent, std::unique_ptr< fftjet::Grid2d< fftjetcms::Real > > &flow)
#define jet_type_switch(method, arg1, arg2)
std::unique_ptr< fftjet::Functor1< double, fftjet::Peak > > recoScaleCalcPeak
static const Mapper & instance()
std::unique_ptr< std::vector< double > > fftjet_ScaleSet_parser(const edm::ParameterSet &ps)
std::unique_ptr< RecoAlg > recoAlg
std::vector< fftjetcms::VectorLike > eventData
virtual std::unique_ptr< fftjet::Functor1< double, fftjet::Peak > > parse_memberFactorCalcPeak(const edm::ParameterSet &)
const std::string outputLabel
math::XYZTLorentzVector adjustForPileup(const math::XYZTLorentzVector &jet, const math::XYZTLorentzVector &pileup, bool subtractPileupAs4Vec)
fftjetcms::VectorLike unclustered
virtual std::unique_ptr< fftjet::Functor1< double, fftjet::Peak > > parse_recoScaleCalcPeak(const edm::ParameterSet &)
std::vector< fftjet::Peak > iterPreclusters
virtual void determinePileupDensityFromConfig(const edm::Event &iEvent, std::unique_ptr< fftjet::Grid2d< fftjetcms::Real > > &density)
void writeSpecific(reco::CaloJet &jet, reco::Particle::LorentzVector const &p4, reco::Particle::Point const &point, std::vector< reco::CandidatePtr > const &constituents, edm::EventSetup const &c)
void removeFakePreclusters()
std::unique_ptr< fftjet::ScaleSpaceKernel > fftjet_MembershipFunction_parser(const edm::ParameterSet &ps)
const unsigned maxIterations
void prepareRecombinationScales()
virtual std::unique_ptr< fftjet::Functor1< double, RecoFFTJet > > parse_memberFactorCalcJet(const edm::ParameterSet &)
virtual std::unique_ptr< fftjet::Functor2< double, RecoFFTJet, RecoFFTJet > > parse_jetDistanceCalc(const edm::ParameterSet &)
double phiBin0Edge() const