25 #include "fftjet/peakEtLifetime.hh" 47 #define make_param(type, varname) const type& varname(ps.getParameter<type>(#varname)) 49 #define init_param(type, varname) varname(ps.getParameter<type>(#varname)) 58 #define jet_type_switch(method, arg1, arg2) \ 62 method<reco::CaloJet>(arg1, arg2); \ 65 method<reco::PFJet>(arg1, arg2); \ 68 method<reco::GenJet>(arg1, arg2); \ 71 method<reco::TrackJet>(arg1, arg2); \ 74 method<reco::BasicJet>(arg1, arg2); \ 77 assert(!"ERROR in FFTJetProducer : invalid jet type."\ 78 " This is a bug. Please report."); \ 83 struct LocalSortByPt {
85 inline bool operator()(
const Jet&
l,
const Jet&
r)
const {
86 return l.pt() >
r.pt();
94 if (!
name.compare(
"fixed"))
96 else if (!
name.compare(
"maximallyStable"))
97 return MAXIMALLY_STABLE;
98 else if (!
name.compare(
"globallyAdaptive"))
99 return GLOBALLY_ADAPTIVE;
100 else if (!
name.compare(
"locallyAdaptive"))
101 return LOCALLY_ADAPTIVE;
102 else if (!
name.compare(
"fromGenJets"))
105 throw cms::Exception(
"FFTJetBadConfig") <<
"Invalid resolution specification \"" <<
name <<
"\"" << std::endl;
108 template <
typename T>
110 produces<std::vector<reco::FFTAnyJet<T> > >(
tag).setBranchAlias(
alias);
154 iterationsPerformed(1
U),
158 throw cms::Exception(
"FFTJetBadConfig") <<
"Can't resum constituents if they are not assigned" << std::endl;
160 produces<reco::FFTJetProducerSummary>(
outputLabel);
177 consumes<reco::PattRecoTree<fftjetcms::Real, reco::PattRecoPeak<fftjetcms::Real> > >(
treeLabel);
193 template <
class Real>
201 if (!
input->isSparse())
202 throw cms::Exception(
"FFTJetBadConfig") <<
"The stored clustering tree is not sparse" << std::endl;
212 const fftjet::Functor1<bool, fftjet::Peak>& peakSelect,
213 std::vector<fftjet::Peak>* preclusters) {
220 const unsigned sz =
input->size();
222 for (
unsigned i = 0;
i < sz; ++
i) {
224 fftjet::Peak
p(
jet.precluster());
225 const double scale(
p.scale());
226 p.setEtaPhi(
jet.vec().Eta(),
jet.vec().Phi());
235 const fftjet::Functor1<bool, fftjet::Peak>& peakSelect,
236 std::vector<fftjet::Peak>* preclusters) {
241 const unsigned nNodes =
nodes.size();
242 const SparseTree::NodeId* pnodes = nNodes ? &
nodes[0] :
nullptr;
244 for (
unsigned i = 0;
i < nNodes; ++
i)
249 fftjet::Peak*
clusters = nNodes ? &(*preclusters)[0] :
nullptr;
250 for (
unsigned i = 0;
i < nNodes; ++
i) {
257 const fftjet::Functor1<bool, fftjet::Peak>& peakSelect,
258 std::vector<SparseTree::NodeId>* mynodes) {
273 if (
tree.stableClusterCount(
285 const int maxlev =
tree.maxStoredLevel();
286 bool levelFound =
false;
288 for (
int ifac = 1; ifac > -2 && !levelFound; ifac -= 2) {
304 const unsigned maxlev =
tree.maxStoredLevel();
331 assert(!
"ERROR in FFTJetProducer::selectTreeNodes : " 332 "should never get here! This is a bug. Please report.");
344 for (
unsigned i = 0;
i < nClus; ++
i) {
345 clus[
i].setRecoScale(scaleCalc(clus[
i]));
346 clus[
i].setRecoScaleRatio(ratioCalc(clus[
i]));
347 clus[
i].setMembershipFactor(factorCalc(clus[
i]));
360 fftjet::DefaultRecombinationAlgFactory<Real, VectorLike, BgData, VBuilder> factory;
380 bool rebuildGrid =
flow.get() ==
nullptr;
387 flow = std::make_unique<fftjet::Grid2d<Real> >(
395 fftjet::Functor2<double, RecoFFTJet, RecoFFTJet>& distanceCalc(*
jetDistanceCalc);
397 const unsigned nJets =
previous.size();
398 if (nJets != nextSet.size())
405 bool converged =
true;
406 for (
unsigned i = 0;
i < nJets; ++
i) {
407 const double d = distanceCalc(prev[
i],
next[
i]);
408 next[
i].setConvergenceDistance(
d);
422 unsigned iterNum = 1
U;
423 bool converged =
false;
429 for (
unsigned i = 0;
i < nJets; ++
i) {
431 fftjet::Peak
p(
jet.precluster());
432 p.setEtaPhi(
jet.vec().Eta(),
jet.vec().Phi());
433 p.setRecoScale(scaleCalc(
jet));
434 p.setRecoScaleRatio(ratioCalc(
jet));
435 p.setMembershipFactor(factorCalc(
jet));
446 throw cms::Exception(
"FFTJetInterface") <<
"FFTJet algorithm failed" << std::endl;
468 for (
unsigned i = 0;
i < nJets; ++
i) {
470 jets[
i].setPeakEtaPhi(oldp.eta(), oldp.phi());
484 const unsigned nJets =
recoJets.size();
485 const unsigned* clusterMask =
gridAlg->getClusterMask();
490 const unsigned nInputs =
eventData.size();
493 for (
unsigned i = 0;
i < nInputs; ++
i) {
495 const int iPhi =
g.getPhiBin(
item.Phi());
496 const int iEta =
g.getEtaBin(
item.Eta());
504 const unsigned nJets =
recoJets.size();
505 const unsigned* clusterMask =
recoAlg->getClusterMask();
506 const unsigned maskLength =
recoAlg->getLastNData();
509 const unsigned* candIdx = maskLength ? &
candidateIndex[0] :
nullptr;
510 for (
unsigned i = 0;
i < maskLength; ++
i) {
515 const unsigned mask = clusterMask[
i];
523 template <
typename T>
525 using namespace reco;
541 auto jets = std::make_unique<OutputCollection>();
542 const unsigned nJets =
recoJets.size();
543 jets->reserve(nJets);
546 double previousPt = DBL_MAX;
547 for (
unsigned ijet = 0; ijet < nJets; ++ijet) {
556 for (
unsigned i = 0;
i < nCon; ++
i)
575 if constexpr (std::is_same_v<T, reco::CaloJet>) {
584 double ncells = myjet.ncells();
589 jet.setJetArea(cellArea * ncells);
598 jets->push_back(OutputJet(
jet, fj));
601 const double pt =
jet.pt();
625 for (
unsigned i = 0;
i < nCon; ++
i)
636 std::make_unique<reco::FFTJetProducerSummary>(
thresholds,
654 loadSparseTreeData<float>(
iEvent);
656 loadSparseTreeData<double>(
iEvent);
694 unsigned nPreclustersFound = 0
U;
696 for (
unsigned i = 0;
i < npre; ++
i)
707 throw cms::Exception(
"FFTJetInterface") <<
"FFTJet algorithm failed (first iteration)" << std::endl;
716 const unsigned nJets =
recoJets.size();
727 const unsigned nJets =
recoJets.size();
731 for (
unsigned i = 0;
i <= nJets; ++
i)
805 std::unique_ptr<fftjet::Functor2<double, FFTJetProducer::RecoFFTJet, FFTJetProducer::RecoFFTJet> >
828 fftjet::DefaultVectorRecombinationAlgFactory<VectorLike, BgData, VBuilder> factory;
861 "invalid spec for the " 862 "reconstruction scale calculator from peaks");
867 "invalid spec for the " 868 "reconstruction scale ratio calculator from peaks");
873 "invalid spec for the " 874 "membership function factor calculator from peaks");
880 "invalid spec for the " 881 "reconstruction scale calculator from jets");
885 "invalid spec for the " 886 "reconstruction scale ratio calculator from jets");
890 "invalid spec for the " 891 "membership function factor calculator from jets");
895 "invalid spec for the " 896 "jet distance calculator");
908 std::vector<int> matchTable;
918 for (
unsigned i = 0;
i < nmatched; ++
i)
942 const unsigned nEta =
g.nEta();
943 const unsigned nPhi =
g.nPhi();
946 const double eta(
g.etaBinCenter(
ieta));
950 const double phi(
g.phiBinCenter(
iphi));
954 const double pil = calc(
eta, 0.0,
s);
972 const bool phiDependent =
f->minDim() == 3
U;
975 const unsigned nEta =
g.nEta();
976 const unsigned nPhi =
g.nPhi();
978 double functorArg[3] = {0.0, 0.0, 0.0};
985 const double eta(
g.etaBinCenter(
ieta));
990 functorArg[1] =
g.phiBinCenter(
iphi);
991 g.uncheckedSetBin(
ieta,
iphi, (*
f)(functorArg, 3
U));
994 const double pil = (*f)(functorArg, 2
U);
1004 assert(!
"Pile-up subtraction for fuzzy clustering " 1005 "is not implemented yet");
1008 const unsigned nJets =
recoJets.size();
1013 for (
unsigned i = 0;
i < nJets; ++
i)
1018 const unsigned nEta =
g.nEta();
1019 const unsigned nPhi =
g.nPhi();
1020 const double cellArea =
g.etaBinWidth() *
g.phiBinWidth();
1033 double* recoScaleRatios = recoScales + nJets;
1034 double* memFactors = recoScaleRatios + nJets;
1035 double*
dEta = memFactors + nJets;
1036 double* dPhiBuf =
dEta + nJets;
1042 for (
unsigned ijet = 0; ijet < nJets; ++ijet) {
1044 const fftjet::Peak& peak(
jet.precluster());
1048 fftjet::AbsMembershipFunction* m3d =
dynamic_cast<fftjet::AbsMembershipFunction*
>(peak.membershipFunction());
1052 assert(!
"Pile-up subtraction for 3-d membership functions " 1053 "is not implemented yet");
1055 fftjet::AbsKernel2d* m2d =
dynamic_cast<fftjet::AbsKernel2d*
>(peak.membershipFunction());
1059 memFcns2d[ijet] = m2d;
1061 recoScales[ijet] = scaleCalc(
jet);
1062 recoScaleRatios[ijet] = ratioCalc(
jet);
1063 memFactors[ijet] = factorCalc(
jet);
1064 cellCounts[ijet] = 0
U;
1070 dphi -= (2.0 *
M_PI);
1071 while (dphi < -
M_PI)
1072 dphi += (2.0 *
M_PI);
1073 dPhiBuf[
iphi * nJets + ijet] = dphi;
1081 const double eta(
g.etaBinCenter(
ieta));
1085 for (
unsigned ijet = 0; ijet < nJets; ++ijet)
1090 unsigned maxWJet(nJets);
1091 const double*
dPhi = dPhiBuf +
iphi * nJets;
1093 for (
unsigned ijet = 0; ijet < nJets; ++ijet) {
1094 if (recoScaleRatios[ijet] > 0.0)
1095 memFcns2d[ijet]->setScaleRatio(recoScaleRatios[ijet]);
1096 const double f = memFactors[ijet] * (*memFcns2d[ijet])(
dEta[ijet],
dPhi[ijet], recoScales[ijet]);
1103 if (maxWJet < nJets) {
1105 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)
virtual std::unique_ptr< fftjet::ScaleSpaceKernel > parse_jetMembershipFunction(const edm::ParameterSet &)
std::unique_ptr< fftjet::Functor2< double, RecoFFTJet, RecoFFTJet > > jetDistanceCalc
T getParameter(std::string const &) const
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
double getEventScale() const
constexpr unsigned int maxBin
#define DEFINE_FWK_MODULE(type)
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)
const reco::Particle::Point & vertexUsed() const
void checkConfig(const Ptr &ptr, const char *message)
const double unlikelyBgWeight
void writeSpecific(reco::CaloJet &jet, reco::Particle::LorentzVector const &p4, reco::Particle::Point const &point, std::vector< reco::CandidatePtr > const &constituents, CaloGeometry const &geometry, HcalTopology const &topology)
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
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > geometry_token_
const double recombinationDataCutoff
Summary info for pile-up determined by Gaussian filtering.
std::vector< unsigned > occupancy
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
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_
T getUntrackedParameter(std::string const &, T const &) const
void loadSparseTreeData(const edm::Event &)
const bool reuseExistingGrid
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
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)
virtual std::unique_ptr< fftjet::Functor1< double, fftjet::Peak > > parse_recoScaleRatioCalcPeak(const edm::ParameterSet &)
Implements inheritance relationships for FFTJet jets.
static void setJetStatusBit(RecoFFTJet *jet, int mask, bool value)
std::vector< RecoFFTJet > iterJets
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
bool getData(T &iHolder) const
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
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)
bool storeInSinglePrecision() const
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::ESGetToken< HcalTopology, HcalRecNumberingRecord > topology_token_
edm::EDGetTokenT< reco::FFTJetPileupSummary > input_pusummary_token_
const double stabilityAlpha
void discretizeEnergyFlow()
const unsigned maxInitialPreclusters
std::string pileupTableCategory
std::unique_ptr< fftjetcms::AbsPileupCalculator > pileupDensityCalc
void clear(HadCaloObj &c)
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 &)
#define jet_type_switch(method, arg1, arg2)
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)
virtual bool isPhiDependent() const =0
std::unique_ptr< fftjet::Functor1< double, fftjet::Peak > > recoScaleCalcPeak
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
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)
constexpr unsigned int minBin
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 &)