28 #include "fftjet/VectorRecombinationAlgFactory.hh"
29 #include "fftjet/RecombinationAlgFactory.hh"
60 #define make_param(type, varname) const \
61 type & varname (ps.getParameter< type >( #varname ))
63 #define init_param(type, varname) varname (ps.getParameter< type >( #varname ))
72 #define jet_type_switch(method, arg1, arg2) do {\
76 method <reco::CaloJet> ( arg1 , arg2 );\
79 method <reco::PFJet> ( arg1 , arg2 );\
82 method <reco::GenJet> ( arg1 , arg2 );\
85 method <reco::TrackJet> ( arg1 , arg2 );\
88 method <reco::BasicJet> ( arg1 , arg2 );\
91 assert(!"ERROR in FFTJetProducer : invalid jet type."\
92 " This is a bug. Please report.");\
96 using namespace fftjetcms;
99 const std::string&
name)
101 if (!name.compare(
"fixed"))
103 else if (!name.compare(
"maximallyStable"))
104 return MAXIMALLY_STABLE;
105 else if (!name.compare(
"globallyAdaptive"))
106 return GLOBALLY_ADAPTIVE;
107 else if (!name.compare(
"locallyAdaptive"))
108 return LOCALLY_ADAPTIVE;
111 <<
"Invalid resolution specification \""
112 << name <<
"\"" << std::endl;
116 template <
typename T>
118 const std::string& alias,
const std::string&
tag)
120 produces<std::vector<reco::FFTAnyJet<T> > >(
tag).setBranchAlias(alias);
133 init_param(unsigned, nJetsRequiredToConverge),
148 init_param(std::string, recombinationAlgorithm),
152 resolution(parse_resolution(ps.getParameter<std::string>(
"resolution"))),
158 iterationsPerformed(1U),
164 <<
"Can't resum constituents if they are not assigned"
167 produces<reco::FFTJetProducerSummary>(
outputLabel);
203 if (!input->isSparse())
205 <<
"The stored clustering tree is not sparse" << std::endl;
215 const fftjet::Functor1<bool,fftjet::Peak>& peakSelector,
216 std::vector<fftjet::Peak>* preclusters)
222 const unsigned nNodes =
nodes.size();
223 const SparseTree::NodeId* pnodes = nNodes ? &
nodes[0] : 0;
224 preclusters->reserve(nNodes);
225 for (
unsigned i=0;
i<nNodes; ++
i)
226 preclusters->push_back(
231 fftjet::Peak* clusters = nNodes ? &(*preclusters)[0] : 0;
232 for (
unsigned i=0; i<nNodes; ++
i)
234 clusters[
i].setCode(pnodes[i]);
242 const fftjet::Functor1<bool,fftjet::Peak>& peakSelect,
243 std::vector<SparseTree::NodeId>* mynodes)
254 tree.getPassingNodes(
usedLevel, peakSelect, mynodes);
265 if (tree.stableClusterCount(
267 minStartingLevel, maxStartingLevel))
270 tree.getPassingNodes(
usedLevel, peakSelect, mynodes);
277 const bool stable = tree.clusterCountLevels(
284 const int maxlev = tree.maxStoredLevel();
285 bool levelFound =
false;
287 for (
int ifac=1; ifac>-2 && !levelFound; ifac-=2)
290 if (level > 0 && level <= maxlev)
308 const unsigned maxlev = tree.maxStoredLevel();
320 const unsigned d = nClustersRequested > n ?
331 tree.getPassingNodes(
usedLevel, peakSelect, mynodes);
344 assert(!
"ERROR in FFTJetProducer::selectTreeNodes : "
345 "should never get here! This is a bug. Please report.");
356 fftjet::Functor1<double,fftjet::Peak>&
358 fftjet::Functor1<double,fftjet::Peak>&
360 fftjet::Functor1<double,fftjet::Peak>&
363 for (
unsigned i=0;
i<nClus; ++
i)
365 clus[
i].setRecoScale(scaleCalc(clus[
i]));
366 clus[
i].setRecoScaleRatio(ratioCalc(clus[i]));
367 clus[
i].setMembershipFactor(factorCalc(clus[i]));
382 fftjet::DefaultRecombinationAlgFactory<
386 <<
"Invalid grid recombination algorithm \""
388 gridAlg = std::auto_ptr<GridAlg>(
399 std::auto_ptr<fftjet::Grid2d<fftjetcms::Real> >& flow)
405 bool rebuildGrid = flow.get() ==
NULL;
408 !(flow->nEta() == input->nEtaBins() &&
409 flow->nPhi() == input->nPhiBins() &&
410 flow->etaMin() == input->etaMin() &&
411 flow->etaMax() == input->etaMax() &&
412 flow->phiBin0Edge() == input->phiBin0Edge());
416 flow = std::auto_ptr<fftjet::Grid2d<Real> >(
417 new fftjet::Grid2d<Real>(
418 input->nEtaBins(), input->etaMin(), input->etaMax(),
419 input->nPhiBins(), input->phiBin0Edge(), input->title()));
421 flow->blockSet(input->data(), input->nEtaBins(), input->nPhiBins());
427 std::vector<RecoFFTJet>& nextSet)
429 fftjet::Functor2<double,RecoFFTJet,RecoFFTJet>&
432 const unsigned nJets = previous.size();
433 if (nJets != nextSet.size())
440 bool converged =
true;
441 for (
unsigned i=0;
i<nJets; ++
i)
443 const double d = distanceCalc(prev[
i], next[i]);
444 next[
i].setConvergenceDistance(d);
460 unsigned iterNum = 1U;
461 bool converged =
false;
468 for (
unsigned i=0;
i<nJets; ++
i)
471 fftjet::Peak
p(jet.precluster());
472 p.setEtaPhi(jet.vec().Eta(), jet.vec().Phi());
473 p.setRecoScale(scaleCalc(jet));
474 p.setRecoScaleRatio(ratioCalc(jet));
475 p.setMembershipFactor(factorCalc(jet));
490 <<
"FFTJet algorithm failed" << std::endl;
513 for (
unsigned i=0;
i<nJets; ++
i)
516 jets[
i].setPeakEtaPhi(oldp.eta(), oldp.phi());
532 const unsigned nJets =
recoJets.size();
533 const unsigned* clusterMask =
gridAlg->getClusterMask();
534 const int nEta =
gridAlg->getLastNEta();
535 const int nPhi =
gridAlg->getLastNPhi();
538 const unsigned nInputs =
eventData.size();
541 for (
unsigned i=0;
i<nInputs; ++
i)
544 const int iPhi = g.getPhiBin(item.Phi());
545 const int iEta = g.getEtaBin(item.Eta());
546 const unsigned mask = iEta >= 0 && iEta < nEta ?
547 clusterMask[iEta*nPhi + iPhi] : 0;
548 assert(mask <= nJets);
556 const unsigned nJets =
recoJets.size();
557 const unsigned* clusterMask =
recoAlg->getClusterMask();
558 const unsigned maskLength =
recoAlg->getLastNData();
562 for (
unsigned i=0;
i<maskLength; ++
i)
568 const unsigned mask = clusterMask[
i];
569 assert(mask <= nJets);
577 template <
typename T>
581 using namespace reco;
599 const unsigned nJets =
recoJets.size();
600 jets->reserve(nJets);
602 for (
unsigned ijet=0; ijet<nJets; ++ijet)
613 for (
unsigned i=0;
i<nCon; ++
i)
629 const double pt = jet4vec.Pt();
632 const double pileupPt =
pileup[ijet].Pt();
633 jet4vec *= ((pt - pileupPt)/pt);
647 double ncells = myjet.ncells();
653 jet.setJetArea(cellArea*ncells);
663 jets->push_back(OutputJet(jet, fj));
672 const unsigned nPreclustersFound)
684 for (
unsigned i=0;
i<nCon; ++
i)
694 std::auto_ptr<reco::FFTJetProducerSummary>
summary(
698 minScale, maxScale, scaleUsed,
712 loadSparseTreeData<float>(
iEvent);
714 loadSparseTreeData<double>(
iEvent);
748 unsigned nPreclustersFound = 0U;
750 for (
unsigned i=0;
i<npre; ++
i)
765 <<
"FFTJet algorithm failed (first iteration)" << std::endl;
775 const unsigned nJets =
recoJets.size();
788 const unsigned nJets =
recoJets.size();
793 for (
unsigned i=0;
i<=nJets; ++
i)
814 std::auto_ptr<fftjet::Functor1<bool,fftjet::Peak> >
823 std::auto_ptr<fftjet::ScaleSpaceKernel>
832 std::auto_ptr<AbsBgFunctor>
841 std::auto_ptr<fftjet::Functor1<double,fftjet::Peak> >
850 std::auto_ptr<fftjetcms::AbsPileupCalculator>
859 std::auto_ptr<fftjet::Functor1<double,fftjet::Peak> >
868 std::auto_ptr<fftjet::Functor1<double,fftjet::Peak> >
876 std::auto_ptr<fftjet::Functor1<double,FFTJetProducer::RecoFFTJet> >
884 std::auto_ptr<fftjet::Functor1<double,FFTJetProducer::RecoFFTJet> >
892 std::auto_ptr<fftjet::Functor1<double,FFTJetProducer::RecoFFTJet> >
900 std::auto_ptr<fftjet::Functor2<
932 fftjet::DefaultVectorRecombinationAlgFactory<
936 <<
"Invalid vector recombination algorithm \""
938 recoAlg = std::auto_ptr<RecoAlg>(
967 "reconstruction scale calculator from peaks");
972 "reconstruction scale ratio calculator from peaks");
977 "membership function factor calculator from peaks");
984 "reconstruction scale calculator from jets");
988 "reconstruction scale ratio calculator from jets");
992 "membership function factor calculator from jets");
996 "jet distance calculator");
1010 std::vector<int> matchTable;
1016 assert(nmatched ==
recoJets.size());
1021 for (
unsigned i=0;
i<nmatched; ++
i)
1028 const int mask,
const bool value)
1030 int status = jet->status();
1035 jet->setStatus(status);
1041 std::auto_ptr<fftjet::Grid2d<fftjetcms::Real> >& density)
1050 fftjet::Grid2d<Real>&
g(*density);
1051 const unsigned nEta = g.nEta();
1052 const unsigned nPhi = g.nPhi();
1054 for (
unsigned ieta=0; ieta<nEta; ++ieta)
1056 const double eta(g.etaBinCenter(ieta));
1060 for (
unsigned iphi=0; iphi<nPhi; ++iphi)
1062 const double phi(g.phiBinCenter(iphi));
1063 g.uncheckedSetBin(ieta, iphi, calc(
eta,
phi, s));
1068 const double pil = calc(
eta, 0.0, s);
1069 for (
unsigned iphi=0; iphi<nPhi; ++iphi)
1070 g.uncheckedSetBin(ieta, iphi, pil);
1080 assert(!
"Pile-up subtraction for fuzzy clustering "
1081 "is not implemented yet");
1084 const unsigned nJets =
recoJets.size();
1089 for (
unsigned i=0;
i<nJets; ++
i)
1094 const unsigned nEta = g.nEta();
1095 const unsigned nPhi = g.nPhi();
1096 const double cellArea = g.etaBinWidth() * g.phiBinWidth();
1107 doubleBuf.resize(nJets*4U + nJets*nPhi);
1109 double* recoScaleRatios = recoScales + nJets;
1110 double* memFactors = recoScaleRatios + nJets;
1111 double* dEta = memFactors + nJets;
1112 double* dPhiBuf = dEta + nJets;
1118 for (
unsigned ijet=0; ijet<nJets; ++ijet)
1121 const fftjet::Peak& peak(jet.precluster());
1125 fftjet::AbsMembershipFunction* m3d =
1126 dynamic_cast<fftjet::AbsMembershipFunction*
>(
1127 peak.membershipFunction());
1129 m3d =
dynamic_cast<fftjet::AbsMembershipFunction*
>(
1133 assert(!
"Pile-up subtraction for 3-d membership functions "
1134 "is not implemented yet");
1138 fftjet::AbsKernel2d* m2d =
1139 dynamic_cast<fftjet::AbsKernel2d*
>(
1140 peak.membershipFunction());
1142 m2d =
dynamic_cast<fftjet::AbsKernel2d*
>(
1145 memFcns2d[ijet] = m2d;
1147 recoScales[ijet] = scaleCalc(jet);
1148 recoScaleRatios[ijet] = ratioCalc(jet);
1149 memFactors[ijet] = factorCalc(jet);
1150 cellCounts[ijet] = 0U;
1152 const double jetPhi = jet.vec().Phi();
1153 for (
unsigned iphi=0; iphi<nPhi; ++iphi)
1155 double dphi = g.phiBinCenter(iphi) -
jetPhi;
1158 while (dphi < -
M_PI)
1160 dPhiBuf[iphi*nJets+ijet] = dphi;
1167 for (
unsigned ieta=0; ieta<nEta; ++ieta)
1169 const double eta(g.etaBinCenter(ieta));
1170 const Real* databuf = g.data() + ieta*nPhi;
1173 for (
unsigned ijet=0; ijet<nJets; ++ijet)
1176 for (
unsigned iphi=0; iphi<nPhi; ++iphi)
1179 unsigned maxWJet(nJets);
1180 const double*
dPhi = dPhiBuf + iphi*nJets;
1182 for (
unsigned ijet=0; ijet<nJets; ++ijet)
1184 if (recoScaleRatios[ijet] > 0.0)
1185 memFcns2d[ijet]->setScaleRatio(recoScaleRatios[ijet]);
1186 const double f = memFactors[ijet]*
1187 (*memFcns2d[ijet])(dEta[ijet], dPhi[ijet],
1196 if (maxWJet < nJets)
1198 pileup[maxWJet] += vMaker(cellArea*databuf[iphi],
1199 eta, g.phiBinCenter(iphi));
1200 cellCounts[maxWJet]++;
std::vector< std::vector< reco::CandidatePtr > > constituents
virtual ~FFTJetProducer()
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
std::auto_ptr< fftjet::Grid2d< fftjetcms::Real > > pileupEnergyFlow
T getUntrackedParameter(std::string const &, T const &) const
std::auto_ptr< fftjet::Grid2d< fftjetcms::Real > > energyFlow
std::auto_ptr< RecoAlg > recoAlg
std::auto_ptr< fftjet::Functor1< double, fftjet::Peak > > memberFactorCalcPeak
unsigned iterationsPerformed
std::vector< ProtoJet > OutputCollection
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)
std::auto_ptr< fftjet::Grid2d< Real > > fftjet_Grid2d_parser(const edm::ParameterSet &ps)
virtual std::auto_ptr< fftjet::Functor1< double, fftjet::Peak > > parse_recoScaleRatioCalcPeak(const edm::ParameterSet &)
std::auto_ptr< GridAlg > gridAlg
std::auto_ptr< fftjetcms::AbsPileupCalculator > pileupDensityCalc
virtual void assignMembershipFunctions(std::vector< fftjet::Peak > *preclusters)
const reco::Particle::Point & vertexUsed() const
#define DEFINE_FWK_MODULE(type)
void loadInputCollection(const edm::Event &)
virtual std::auto_ptr< fftjet::Functor1< bool, fftjet::Peak > > parse_peakSelector(const edm::ParameterSet &)
virtual std::auto_ptr< fftjetcms::AbsPileupCalculator > parse_pileupDensityCalc(const edm::ParameterSet &ps)
const std::string recombinationAlgorithm
Data processing summary generated by FFTJetProducer.
virtual std::auto_ptr< fftjetcms::AbsBgFunctor > parse_bgMembershipFunction(const edm::ParameterSet &)
const bool subtractPileupAs4Vec
std::auto_ptr< fftjet::ScaleSpaceKernel > fftjet_MembershipFunction_parser(const edm::ParameterSet &ps)
void checkConfig(const Ptr &ptr, const char *message)
const double unlikelyBgWeight
void makeProduces(const std::string &alias, const std::string &tag)
const bool subtractPileup
std::auto_ptr< AbsPileupCalculator > fftjet_PileupCalculator_parser(const edm::ParameterSet &ps)
std::vector< double > doubleBuf
std::auto_ptr< fftjet::Functor1< double, fftjet::Peak > > recoScaleCalcPeak
std::vector< fftjet::AbsKernel2d * > memFcns2dVec
std::vector< RecoFFTJet > recoJets
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()
virtual std::auto_ptr< fftjet::Functor1< double, fftjet::Peak > > parse_memberFactorCalcPeak(const edm::ParameterSet &)
void loadSparseTreeData(const edm::Event &)
std::auto_ptr< fftjetcms::AbsBgFunctor > bgMembershipFunction
const bool reuseExistingGrid
std::auto_ptr< fftjet::Functor1< bool, fftjet::Peak > > fftjet_PeakSelector_parser(const edm::ParameterSet &ps)
double getEventScale() const
const unsigned nClustersRequested
virtual void produce(edm::Event &, const edm::EventSetup &)
std::vector< unsigned > candidateIndex
std::auto_ptr< fftjet::Functor2< double, fftjet::RecombinedJet< VectorLike >, fftjet::RecombinedJet< VectorLike > > > fftjet_JetDistance_parser(const edm::ParameterSet &ps)
double dPhi(double phi1, double phi2)
std::auto_ptr< std::vector< double > > iniScales
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
math::XYZTLorentzVector VectorLike
std::auto_ptr< fftjet::Functor1< double, RecoFFTJet > > memberFactorCalcJet
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
virtual std::auto_ptr< fftjet::Functor1< double, RecoFFTJet > > parse_recoScaleCalcJet(const edm::ParameterSet &)
Implements inheritance relationships for FFTJet jets.
static void setJetStatusBit(RecoFFTJet *jet, int mask, bool value)
std::vector< RecoFFTJet > iterJets
fftjet::SparseClusteringTree< fftjet::Peak, long > SparseTree
std::vector< unsigned > cellCountsVec
virtual void determinePileupDensity(const edm::Event &iEvent, const edm::InputTag &label, std::auto_ptr< fftjet::Grid2d< fftjetcms::Real > > &density)
std::vector< double > thresholds
virtual std::auto_ptr< fftjet::Functor2< double, RecoFFTJet, RecoFFTJet > > parse_jetDistanceCalc(const edm::ParameterSet &)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
unsigned iterateJetReconstruction()
void setNCells(const double nc)
const bool calculatePileup
const bool assignConstituents
bool storeInSinglePrecision() const
void setPileup(const math::XYZTLorentzVector &p)
std::auto_ptr< fftjet::Functor1< double, fftjet::Peak > > fftjet_PeakFunctor_parser(const edm::ParameterSet &ps)
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::ParameterSet myConfiguration
fftjet::RecombinedJet< fftjetcms::VectorLike > RecoFFTJet
const double stabilityAlpha
std::auto_ptr< fftjet::Functor1< double, fftjet::Peak > > recoScaleRatioCalcPeak
virtual std::auto_ptr< fftjet::Functor1< double, RecoFFTJet > > parse_memberFactorCalcJet(const edm::ParameterSet &)
void discretizeEnergyFlow()
virtual std::auto_ptr< fftjet::Functor1< double, fftjet::Peak > > parse_recoScaleCalcPeak(const edm::ParameterSet &)
void setFourVec(const math::XYZTLorentzVector &p)
std::vector< SparseTree::NodeId > nodes
void determineGriddedConstituents()
const double convergenceDistance
void writeJets(edm::Event &iEvent, const edm::EventSetup &)
virtual std::auto_ptr< fftjet::ScaleSpaceKernel > parse_jetMembershipFunction(const edm::ParameterSet &)
virtual std::auto_ptr< fftjet::Functor1< double, RecoFFTJet > > parse_recoScaleRatioCalcJet(const edm::ParameterSet &)
std::auto_ptr< fftjet::Functor1< double, RecoFFTJet > > recoScaleRatioCalcJet
const edm::InputTag pileupLabel
#define jet_type_switch(method, arg1, arg2)
static bool loadEnergyFlow(const edm::Event &iEvent, const edm::InputTag &label, std::auto_ptr< fftjet::Grid2d< fftjetcms::Real > > &flow)
virtual bool isPhiDependent() const =0
std::auto_ptr< AbsBgFunctor > fftjet_BgFunctor_parser(const edm::ParameterSet &ps)
std::vector< fftjetcms::VectorLike > eventData
const std::string outputLabel
fftjetcms::VectorLike unclustered
std::auto_ptr< fftjet::Functor1< bool, fftjet::Peak > > peakSelector
std::vector< fftjet::Peak > iterPreclusters
std::auto_ptr< std::vector< double > > fftjet_ScaleSet_parser(const edm::ParameterSet &ps)
std::auto_ptr< fftjet::Functor2< double, RecoFFTJet, RecoFFTJet > > jetDistanceCalc
std::auto_ptr< fftjet::ScaleSpaceKernel > jetMembershipFunction
std::auto_ptr< fftjet::Functor1< double, fftjet::RecombinedJet< VectorLike > > > fftjet_JetFunctor_parser(const edm::ParameterSet &ps)
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()
const unsigned maxIterations
std::auto_ptr< fftjet::Functor1< double, RecoFFTJet > > recoScaleCalcJet
void prepareRecombinationScales()