CMS 3D CMS Logo

FFTJetProducer.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: RecoJets/FFTJetProducers
4 // Class: FFTJetProducer
5 //
21 //
22 // Original Author: Igor Volobouev
23 // Created: Sun Jun 20 14:32:36 CDT 2010
24 //
25 //
26 
27 #ifndef RecoJets_FFTJetProducers_FFTJetProducer_h
28 #define RecoJets_FFTJetProducers_FFTJetProducer_h
29 
30 #include <memory>
31 
32 // FFTJet headers
33 #include "fftjet/AbsRecombinationAlg.hh"
34 #include "fftjet/AbsVectorRecombinationAlg.hh"
35 #include "fftjet/SparseClusteringTree.hh"
36 
37 // Additional FFTJet headers
38 #include "fftjet/VectorRecombinationAlgFactory.hh"
39 #include "fftjet/RecombinationAlgFactory.hh"
40 
49 
55 
57 
58 // framework include files
62 
64 
65 // local FFTJet-related definitions
69 
71 
72 namespace fftjetcms {
74 }
75 
76 class CaloGeometry;
77 class CaloGeometryRecord;
78 class HcalTopology;
80 
81 //
82 // class declaration
83 //
85 public:
86  typedef fftjet::RecombinedJet<fftjetcms::VectorLike> RecoFFTJet;
87  typedef fftjet::SparseClusteringTree<fftjet::Peak, long> SparseTree;
88 
89  // Masks for the status bits. Do not add anything
90  // here -- higher bits (starting with 0x1000) will be
91  // used to indicate jet correction levels applied.
92  enum StatusBits {
93  RESOLUTION = 0xff,
98  };
99 
101 
102  explicit FFTJetProducer(const edm::ParameterSet&);
103  // Explicitly disable other ways to construct this object
104  FFTJetProducer() = delete;
105  FFTJetProducer(const FFTJetProducer&) = delete;
106  FFTJetProducer& operator=(const FFTJetProducer&) = delete;
107 
108  ~FFTJetProducer() override;
109 
110  // Parser for the resolution enum
112 
113 protected:
114  // Functions which should be overriden from the base
115  void beginStream(edm::StreamID) override;
116  void produce(edm::Event&, const edm::EventSetup&) override;
117 
118  // The following functions can be overriden by derived classes
119  // in order to adjust jet reconstruction algorithm behavior.
120 
121  // Override the following method in order to implement
122  // your own precluster selection strategy
123  virtual void selectPreclusters(const SparseTree& tree,
124  const fftjet::Functor1<bool, fftjet::Peak>& peakSelector,
125  std::vector<fftjet::Peak>* preclusters);
126 
127  // Precluster maker from GenJets (useful in calibration)
128  virtual void genJetPreclusters(const SparseTree& tree,
129  edm::Event&,
130  const edm::EventSetup&,
131  const fftjet::Functor1<bool, fftjet::Peak>& peakSelector,
132  std::vector<fftjet::Peak>* preclusters);
133 
134  // Override the following method (which by default does not do
135  // anything) in order to implement your own process-dependent
136  // assignment of membership functions to preclusters. This method
137  // will be called once per event, just before the main algorithm.
138  virtual void assignMembershipFunctions(std::vector<fftjet::Peak>* preclusters);
139 
140  // Parser for the peak selector
141  virtual std::unique_ptr<fftjet::Functor1<bool, fftjet::Peak> > parse_peakSelector(const edm::ParameterSet&);
142 
143  // Parser for the default jet membership function
144  virtual std::unique_ptr<fftjet::ScaleSpaceKernel> parse_jetMembershipFunction(const edm::ParameterSet&);
145 
146  // Parser for the background membership function
147  virtual std::unique_ptr<fftjetcms::AbsBgFunctor> parse_bgMembershipFunction(const edm::ParameterSet&);
148 
149  // Calculator for the recombination scale
150  virtual std::unique_ptr<fftjet::Functor1<double, fftjet::Peak> > parse_recoScaleCalcPeak(const edm::ParameterSet&);
151 
152  // Calculator for the recombination scale ratio
153  virtual std::unique_ptr<fftjet::Functor1<double, fftjet::Peak> > parse_recoScaleRatioCalcPeak(
154  const edm::ParameterSet&);
155 
156  // Calculator for the membership function factor
157  virtual std::unique_ptr<fftjet::Functor1<double, fftjet::Peak> > parse_memberFactorCalcPeak(const edm::ParameterSet&);
158 
159  // Similar calculators for the iterative algorithm
160  virtual std::unique_ptr<fftjet::Functor1<double, RecoFFTJet> > parse_recoScaleCalcJet(const edm::ParameterSet&);
161 
162  virtual std::unique_ptr<fftjet::Functor1<double, RecoFFTJet> > parse_recoScaleRatioCalcJet(const edm::ParameterSet&);
163 
164  virtual std::unique_ptr<fftjet::Functor1<double, RecoFFTJet> > parse_memberFactorCalcJet(const edm::ParameterSet&);
165 
166  // Calculator of the distance between jets which is used to make
167  // the decision about convergence of the iterative algorithm
168  virtual std::unique_ptr<fftjet::Functor2<double, RecoFFTJet, RecoFFTJet> > parse_jetDistanceCalc(
169  const edm::ParameterSet&);
170 
171  // Pile-up density calculator
172  virtual std::unique_ptr<fftjetcms::AbsPileupCalculator> parse_pileupDensityCalc(const edm::ParameterSet& ps);
173 
174  // The following function performs most of the precluster selection
175  // work in this module. You might want to reuse it if only a slight
176  // modification of the "selectPreclusters" method is desired.
177  void selectTreeNodes(const SparseTree& tree,
178  const fftjet::Functor1<bool, fftjet::Peak>& peakSelect,
179  std::vector<SparseTree::NodeId>* nodes);
180 
181 private:
182  typedef fftjet::AbsVectorRecombinationAlg<fftjetcms::VectorLike, fftjetcms::BgData> RecoAlg;
183  typedef fftjet::AbsRecombinationAlg<fftjetcms::Real, fftjetcms::VectorLike, fftjetcms::BgData> GridAlg;
184 
185  // Useful local utilities
186  template <class Real>
187  void loadSparseTreeData(const edm::Event&,
189 
190  void removeFakePreclusters();
191 
192  // The following methods do most of the work.
193  // The following function tells us if the grid was rebuilt.
194  bool loadEnergyFlow(const edm::Event& iEvent, std::unique_ptr<fftjet::Grid2d<fftjetcms::Real> >& flow);
195  void buildGridAlg();
197  bool checkConvergence(const std::vector<RecoFFTJet>& previousIterResult, std::vector<RecoFFTJet>& thisIterResult);
200  void saveResults(edm::Event& iEvent, const edm::EventSetup&, unsigned nPreclustersFound);
201 
202  template <typename Jet>
204 
205  template <typename Jet>
206  void makeProduces(const std::string& alias, const std::string& tag);
207 
208  // The following function scans the pile-up density
209  // and fills the pile-up grid. Can be overriden if
210  // necessary.
212  std::unique_ptr<fftjet::Grid2d<fftjetcms::Real> >& density);
213 
214  // Similar function for getting pile-up shape from the database
215  virtual void determinePileupDensityFromDB(const edm::Event& iEvent,
216  const edm::EventSetup& iSetup,
217  std::unique_ptr<fftjet::Grid2d<fftjetcms::Real> >& density);
218 
219  // The following function builds the pile-up estimate
220  // for each jet
221  void determinePileup();
222 
223  // The following function returns the number of iterations
224  // performed. If this number equals to or less than "maxIterations"
225  // then the iterations have converged. If the number larger than
226  // "maxIterations" then the iterations failed to converge (note,
227  // however, that only "maxIterations" iterations would still be
228  // performed).
229  unsigned iterateJetReconstruction();
230 
231  // A function to set jet status bits
232  static void setJetStatusBit(RecoFFTJet* jet, int mask, bool value);
233 
234  //
235  // ----------member data ---------------------------
236  //
237 
238  // Local copy of the module configuration
240 
241  // Label for the tree produced by FFTJetPatRecoProducer
243 
244  // Are we going to use energy flow discretization grid as input
245  // to jet reconstruction?
247 
248  // Are we going to rebuild the energy flow discretization grid
249  // or to reuse the grid made by FFTJetPatRecoProducer?
250  const bool reuseExistingGrid;
251 
252  // Are we iterating?
253  const unsigned maxIterations;
254 
255  // Parameters which affect iteration convergence
256  const unsigned nJetsRequiredToConverge;
257  const double convergenceDistance;
258 
259  // Are we building assignments of collection members to jets?
260  const bool assignConstituents;
261 
262  // Are we resumming the constituents to determine jet 4-vectors?
263  // This might make sense if FFTJet is used in the crisp, gridded
264  // mode to determine jet areas, and vector recombination is desired.
265  const bool resumConstituents;
266 
267  // Are we going to subtract the pile-up? Note that
268  // pile-up subtraction does not modify eta and phi moments.
269  const bool calculatePileup;
270  const bool subtractPileup;
272 
273  // Label for the pile-up energy flow. Must be specified
274  // if the pile-up is subtracted.
276 
277  // Scale for the peak selection (if the scale is fixed)
278  const double fixedScale;
279 
280  // Minimum and maximum scale for searching stable configurations
281  const double minStableScale;
282  const double maxStableScale;
283 
284  // Stability "alpha"
285  const double stabilityAlpha;
286 
287  // Not sure at this point how to treat noise... For now, this is
288  // just a single configurable number...
289  const double noiseLevel;
290 
291  // Number of clusters requested (if the scale is adaptive)
292  const unsigned nClustersRequested;
293 
294  // Maximum eta for the grid-based algorithm
295  const double gridScanMaxEta;
296 
297  // Parameters related to the recombination algorithm
299  const bool isCrisp;
300  const double unlikelyBgWeight;
302 
303  // Label for the genJets used as seeds for jets
305 
306  // Maximum number of preclusters to use as jet seeds.
307  // This does not take into account the preclusters
308  // for which the value of the membership factor is 0.
309  const unsigned maxInitialPreclusters;
310 
311  // Resolution. The corresponding parameter value
312  // should be one of "fixed", "maximallyStable",
313  // "globallyAdaptive", "locallyAdaptive", or "fromGenJets".
315 
316  // Parameters related to the pileup shape stored
317  // in the database
322 
323  // Scales used
324  std::unique_ptr<std::vector<double> > iniScales;
325 
326  // The sparse clustering tree
328 
329  // Peak selector for the peaks already in the tree
330  std::unique_ptr<fftjet::Functor1<bool, fftjet::Peak> > peakSelector;
331 
332  // Recombination algorithms and related quantities
333  std::unique_ptr<RecoAlg> recoAlg;
334  std::unique_ptr<GridAlg> gridAlg;
335  std::unique_ptr<fftjet::ScaleSpaceKernel> jetMembershipFunction;
336  std::unique_ptr<fftjetcms::AbsBgFunctor> bgMembershipFunction;
337 
338  // Calculator for the recombination scale
339  std::unique_ptr<fftjet::Functor1<double, fftjet::Peak> > recoScaleCalcPeak;
340 
341  // Calculator for the recombination scale ratio
342  std::unique_ptr<fftjet::Functor1<double, fftjet::Peak> > recoScaleRatioCalcPeak;
343 
344  // Calculator for the membership function factor
345  std::unique_ptr<fftjet::Functor1<double, fftjet::Peak> > memberFactorCalcPeak;
346 
347  // Similar calculators for the iterative algorithm
348  std::unique_ptr<fftjet::Functor1<double, RecoFFTJet> > recoScaleCalcJet;
349  std::unique_ptr<fftjet::Functor1<double, RecoFFTJet> > recoScaleRatioCalcJet;
350  std::unique_ptr<fftjet::Functor1<double, RecoFFTJet> > memberFactorCalcJet;
351 
352  // Calculator for the jet distance used to estimate convergence
353  // of the iterative algorithm
354  std::unique_ptr<fftjet::Functor2<double, RecoFFTJet, RecoFFTJet> > jetDistanceCalc;
355 
356  // Vector of selected tree nodes
357  std::vector<SparseTree::NodeId> nodes;
358 
359  // Vector of selected preclusters
360  std::vector<fftjet::Peak> preclusters;
361 
362  // Vector of reconstructed jets (we will refill it in every event)
363  std::vector<RecoFFTJet> recoJets;
364 
365  // Cluster occupancy calculated as a function of level number
366  std::vector<unsigned> occupancy;
367 
368  // The thresholds obtained by the LOCALLY_ADAPTIVE method
369  std::vector<double> thresholds;
370 
371  // Minimum, maximum and used level calculated by some algorithms
373 
374  // Unclustered/unused energy produced during recombination
376  double unused;
377 
378  // Quantities defined below are used in the iterative mode only
379  std::vector<fftjet::Peak> iterPreclusters;
380  std::vector<RecoFFTJet> iterJets;
382 
383  // Vectors of constituents
384  std::vector<std::vector<reco::CandidatePtr> > constituents;
385 
386  // Vector of pile-up. We will subtract it from the
387  // 4-vectors of reconstructed jets.
388  std::vector<fftjetcms::VectorLike> pileup;
389 
390  // The pile-up transverse energy density discretization grid.
391  // Note that this is _density_, not energy. To get energy,
392  // multiply by cell area.
393  std::unique_ptr<fftjet::Grid2d<fftjetcms::Real> > pileupEnergyFlow;
394 
395  // The functor that calculates the pile-up density
396  std::unique_ptr<fftjetcms::AbsPileupCalculator> pileupDensityCalc;
397 
398  // Memory buffers related to pile-up subtraction
399  std::vector<fftjet::AbsKernel2d*> memFcns2dVec;
400  std::vector<double> doubleBuf;
401  std::vector<unsigned> cellCountsVec;
402 
403  // Tokens for data access
409 
412 
414 };
415 
416 #endif // RecoJets_FFTJetProducers_FFTJetProducer_h
void loadSparseTreeData(const edm::Event &, const edm::EDGetTokenT< reco::PattRecoTree< Real, reco::PattRecoPeak< Real > > > &tok)
std::vector< std::vector< reco::CandidatePtr > > constituents
void produce(edm::Event &, const edm::EventSetup &) override
virtual std::unique_ptr< fftjet::ScaleSpaceKernel > parse_jetMembershipFunction(const edm::ParameterSet &)
std::unique_ptr< fftjet::Functor2< double, RecoFFTJet, RecoFFTJet > > jetDistanceCalc
unsigned iterationsPerformed
const bool useGriddedAlgorithm
std::vector< fftjetcms::VectorLike > pileup
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.
Definition: PattRecoTree.h:20
Preclusters from FFTJet pattern recognition stage.
Definition: PattRecoPeak.h:16
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
std::unique_ptr< fftjet::Functor1< double, RecoFFTJet > > recoScaleCalcJet
const std::string recombinationAlgorithm
const double fixedScale
const bool subtractPileupAs4Vec
virtual std::unique_ptr< fftjetcms::AbsBgFunctor > parse_bgMembershipFunction(const edm::ParameterSet &)
const double unlikelyBgWeight
void makeProduces(const std::string &alias, const std::string &tag)
const bool subtractPileup
const unsigned nJetsRequiredToConverge
Resolution resolution
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 bool isCrisp
const double recombinationDataCutoff
fftjet::AbsVectorRecombinationAlg< fftjetcms::VectorLike, fftjetcms::BgData > RecoAlg
std::vector< unsigned > occupancy
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
const double minStableScale
const double maxStableScale
std::vector< fftjet::Peak > preclusters
constexpr uint32_t mask
Definition: gpuClustering.h:26
FFTJetProducer & operator=(const FFTJetProducer &)=delete
void determineVectorConstituents()
FFTJetProducer()=delete
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
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< reco::PattRecoTree< double, reco::PattRecoPeak< double > > > input_recotree_token_d_
fftjet::AbsRecombinationAlg< fftjetcms::Real, fftjetcms::VectorLike, fftjetcms::BgData > GridAlg
std::unique_ptr< fftjetcms::AbsBgFunctor > bgMembershipFunction
virtual std::unique_ptr< fftjet::Functor1< double, RecoFFTJet > > parse_recoScaleCalcJet(const edm::ParameterSet &)
std::unique_ptr< fftjet::Functor1< double, RecoFFTJet > > memberFactorCalcJet
math::XYZTLorentzVector VectorLike
unsigned usedLevel
fftjet::SparseClusteringTree< fftjet::Peak, long > SparseTree
edm::EDGetTokenT< reco::PattRecoTree< float, reco::PattRecoPeak< float > > > input_recotree_token_f_
virtual std::unique_ptr< fftjet::Functor1< double, fftjet::Peak > > parse_recoScaleRatioCalcPeak(const edm::ParameterSet &)
const double noiseLevel
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
std::unique_ptr< fftjet::ScaleSpaceKernel > jetMembershipFunction
Definition: value.py:1
std::string pileupTableRecord
std::string pileupTableName
std::vector< double > thresholds
unsigned iterateJetReconstruction()
const bool calculatePileup
const bool assignConstituents
bool checkConvergence(const std::vector< RecoFFTJet > &previousIterResult, std::vector< RecoFFTJet > &thisIterResult)
A grid filled with discretized energy flow.
const edm::InputTag treeLabel
virtual void selectPreclusters(const SparseTree &tree, const fftjet::Functor1< bool, fftjet::Peak > &peakSelector, std::vector< fftjet::Peak > *preclusters)
double Real
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 beginStream(edm::StreamID) override
const unsigned maxInitialPreclusters
std::string pileupTableCategory
SparseTree sparseTree
std::unique_ptr< fftjetcms::AbsPileupCalculator > pileupDensityCalc
std::vector< SparseTree::NodeId > nodes
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 &)
Definition: tree.py:1
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)
std::unique_ptr< fftjet::Functor1< double, fftjet::Peak > > recoScaleCalcPeak
FFTJetLookupTableSequenceLoader esLoader_
std::unique_ptr< RecoAlg > recoAlg
virtual std::unique_ptr< fftjet::Functor1< double, fftjet::Peak > > parse_memberFactorCalcPeak(const edm::ParameterSet &)
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 removeFakePreclusters()
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 &)