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