CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // $Id: FFTJetProducer.h,v 1.12 2012/11/21 03:13:26 igv Exp $
25 //
26 //
27 
28 #ifndef RecoJets_FFTJetProducers_FFTJetProducer_h
29 #define RecoJets_FFTJetProducers_FFTJetProducer_h
30 
31 #include <memory>
32 
33 // FFTJet headers
34 #include "fftjet/AbsRecombinationAlg.hh"
35 #include "fftjet/AbsVectorRecombinationAlg.hh"
36 #include "fftjet/SparseClusteringTree.hh"
37 
38 // framework include files
43 
45 
46 // local FFTJet-related definitions
50 
51 namespace fftjetcms {
53 }
54 
55 //
56 // class declaration
57 //
60 {
61 public:
62  typedef fftjet::RecombinedJet<fftjetcms::VectorLike> RecoFFTJet;
63  typedef fftjet::SparseClusteringTree<fftjet::Peak,long> SparseTree;
64 
65  // Masks for the status bits. Do not add anything
66  // here -- higher bits (starting with 0x1000) will be
67  // used to indicate jet correction levels applied.
69  {
70  RESOLUTION = 0xff,
75  };
76 
78  {
79  FIXED = 0,
84  };
85 
86  explicit FFTJetProducer(const edm::ParameterSet&);
87  virtual ~FFTJetProducer();
88 
89  // Parser for the resolution enum
91 
92 protected:
93  // Functions which should be overriden from the base
94  virtual void beginJob();
95  virtual void produce(edm::Event&, const edm::EventSetup&);
96  virtual void endJob();
97 
98  // The following functions can be overriden by derived classes
99  // in order to adjust jet reconstruction algorithm behavior.
100 
101  // Override the following method in order to implement
102  // your own precluster selection strategy
103  virtual void selectPreclusters(
104  const SparseTree& tree,
105  const fftjet::Functor1<bool,fftjet::Peak>& peakSelector,
106  std::vector<fftjet::Peak>* preclusters);
107 
108  // Precluster maker from GenJets (useful in calibration)
109  virtual void genJetPreclusters(
110  const SparseTree& tree,
111  edm::Event&, const edm::EventSetup&,
112  const fftjet::Functor1<bool,fftjet::Peak>& peakSelector,
113  std::vector<fftjet::Peak>* preclusters);
114 
115  // Override the following method (which by default does not do
116  // anything) in order to implement your own process-dependent
117  // assignment of membership functions to preclusters. This method
118  // will be called once per event, just before the main algorithm.
119  virtual void assignMembershipFunctions(
120  std::vector<fftjet::Peak>* preclusters);
121 
122  // Parser for the peak selector
123  virtual std::auto_ptr<fftjet::Functor1<bool,fftjet::Peak> >
125 
126  // Parser for the default jet membership function
127  virtual std::auto_ptr<fftjet::ScaleSpaceKernel>
129 
130  // Parser for the background membership function
131  virtual std::auto_ptr<fftjetcms::AbsBgFunctor>
133 
134  // Calculator for the recombination scale
135  virtual std::auto_ptr<fftjet::Functor1<double,fftjet::Peak> >
137 
138  // Calculator for the recombination scale ratio
139  virtual std::auto_ptr<fftjet::Functor1<double,fftjet::Peak> >
141 
142  // Calculator for the membership function factor
143  virtual std::auto_ptr<fftjet::Functor1<double,fftjet::Peak> >
145 
146  // Similar calculators for the iterative algorithm
147  virtual std::auto_ptr<fftjet::Functor1<double,RecoFFTJet> >
149 
150  virtual std::auto_ptr<fftjet::Functor1<double,RecoFFTJet> >
152 
153  virtual std::auto_ptr<fftjet::Functor1<double,RecoFFTJet> >
155 
156  // Calculator of the distance between jets which is used to make
157  // the decision about convergence of the iterative algorithm
158  virtual std::auto_ptr<fftjet::Functor2<double,RecoFFTJet,RecoFFTJet> >
160 
161  // Pile-up density calculator
162  virtual std::auto_ptr<fftjetcms::AbsPileupCalculator>
164 
165  // The following function performs most of the precluster selection
166  // work in this module. You might want to reuse it if only a slight
167  // modification of the "selectPreclusters" method is desired.
168  void selectTreeNodes(const SparseTree& tree,
169  const fftjet::Functor1<bool,fftjet::Peak>& peakSelect,
170  std::vector<SparseTree::NodeId>* nodes);
171 private:
172  typedef fftjet::AbsVectorRecombinationAlg<
174  typedef fftjet::AbsRecombinationAlg<
176 
177  // Explicitly disable other ways to construct this object
178  FFTJetProducer();
181 
182  // Useful local utilities
183  template<class Real>
184  void loadSparseTreeData(const edm::Event&);
185 
186  void removeFakePreclusters();
187 
188  // The following methods do most of the work.
189  // The following function tells us if the grid was rebuilt.
190  static bool loadEnergyFlow(
191  const edm::Event& iEvent, const edm::InputTag& label,
192  std::auto_ptr<fftjet::Grid2d<fftjetcms::Real> >& flow);
193  void buildGridAlg();
195  bool checkConvergence(const std::vector<RecoFFTJet>& previousIterResult,
196  std::vector<RecoFFTJet>& thisIterResult);
200  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  const edm::Event& iEvent, const edm::InputTag& label,
213  std::auto_ptr<fftjet::Grid2d<fftjetcms::Real> >& density);
214 
215  // Similar function for getting pile-up shape from the database
216  virtual void determinePileupDensityFromDB(
217  const edm::Event& iEvent, const edm::EventSetup& iSetup,
218  const edm::InputTag& label,
219  std::auto_ptr<fftjet::Grid2d<fftjetcms::Real> >& density);
220 
221  // The following function builds the pile-up estimate
222  // for each jet
223  void determinePileup();
224 
225  // The following function returns the number of iterations
226  // performed. If this number equals to or less than "maxIterations"
227  // then the iterations have converged. If the number larger than
228  // "maxIterations" then the iterations failed to converge (note,
229  // however, that only "maxIterations" iterations would still be
230  // performed).
231  unsigned iterateJetReconstruction();
232 
233  // A function to set jet status bits
234  static void setJetStatusBit(RecoFFTJet* jet, int mask, bool value);
235 
236  //
237  // ----------member data ---------------------------
238  //
239 
240  // Local copy of the module configuration
242 
243  // Label for the tree produced by FFTJetPatRecoProducer
245 
246  // Are we going to use energy flow discretization grid as input
247  // to jet reconstruction?
249 
250  // Are we going to rebuild the energy flow discretization grid
251  // or to reuse the grid made by FFTJetPatRecoProducer?
252  const bool reuseExistingGrid;
253 
254  // Are we iterating?
255  const unsigned maxIterations;
256 
257  // Parameters which affect iteration convergence
258  const unsigned nJetsRequiredToConverge;
259  const double convergenceDistance;
260 
261  // Are we building assignments of collection members to jets?
262  const bool assignConstituents;
263 
264  // Are we resumming the constituents to determine jet 4-vectors?
265  // This might make sense if FFTJet is used in the crisp, gridded
266  // mode to determine jet areas, and vector recombination is desired.
267  const bool resumConstituents;
268 
269  // Are we going to subtract the pile-up? Note that
270  // pile-up subtraction does not modify eta and phi moments.
271  const bool calculatePileup;
272  const bool subtractPileup;
274 
275  // Label for the pile-up energy flow. Must be specified
276  // if the pile-up is subtracted.
278 
279  // Scale for the peak selection (if the scale is fixed)
280  const double fixedScale;
281 
282  // Minimum and maximum scale for searching stable configurations
283  const double minStableScale;
284  const double maxStableScale;
285 
286  // Stability "alpha"
287  const double stabilityAlpha;
288 
289  // Not sure at this point how to treat noise... For now, this is
290  // just a single configurable number...
291  const double noiseLevel;
292 
293  // Number of clusters requested (if the scale is adaptive)
294  const unsigned nClustersRequested;
295 
296  // Maximum eta for the grid-based algorithm
297  const double gridScanMaxEta;
298 
299  // Parameters related to the recombination algorithm
301  const bool isCrisp;
302  const double unlikelyBgWeight;
304 
305  // Label for the genJets used as seeds for jets
307 
308  // Maximum number of preclusters to use as jet seeds.
309  // This does not take into account the preclusters
310  // for which the value of the membership factor is 0.
311  const unsigned maxInitialPreclusters;
312 
313  // Resolution. The corresponding parameter value
314  // should be one of "fixed", "maximallyStable",
315  // "globallyAdaptive", "locallyAdaptive", or "fromGenJets".
317 
318  // Parameters related to the pileup shape stored
319  // in the database
324 
325  // Scales used
326  std::auto_ptr<std::vector<double> > iniScales;
327 
328  // The sparse clustering tree
330 
331  // Peak selector for the peaks already in the tree
332  std::auto_ptr<fftjet::Functor1<bool,fftjet::Peak> > peakSelector;
333 
334  // Recombination algorithms and related quantities
335  std::auto_ptr<RecoAlg> recoAlg;
336  std::auto_ptr<GridAlg> gridAlg;
337  std::auto_ptr<fftjet::ScaleSpaceKernel> jetMembershipFunction;
338  std::auto_ptr<fftjetcms::AbsBgFunctor> bgMembershipFunction;
339 
340  // Calculator for the recombination scale
341  std::auto_ptr<fftjet::Functor1<double,fftjet::Peak> > recoScaleCalcPeak;
342 
343  // Calculator for the recombination scale ratio
344  std::auto_ptr<fftjet::Functor1<double,fftjet::Peak> >
346 
347  // Calculator for the membership function factor
348  std::auto_ptr<fftjet::Functor1<double,fftjet::Peak> > memberFactorCalcPeak;
349 
350  // Similar calculators for the iterative algorithm
351  std::auto_ptr<fftjet::Functor1<double,RecoFFTJet> > recoScaleCalcJet;
352  std::auto_ptr<fftjet::Functor1<double,RecoFFTJet> > recoScaleRatioCalcJet;
353  std::auto_ptr<fftjet::Functor1<double,RecoFFTJet> > memberFactorCalcJet;
354 
355  // Calculator for the jet distance used to estimate convergence
356  // of the iterative algorithm
357  std::auto_ptr<fftjet::Functor2<double,RecoFFTJet,RecoFFTJet> >
359 
360  // Vector of selected tree nodes
361  std::vector<SparseTree::NodeId> nodes;
362 
363  // Vector of selected preclusters
364  std::vector<fftjet::Peak> preclusters;
365 
366  // Vector of reconstructed jets (we will refill it in every event)
367  std::vector<RecoFFTJet> recoJets;
368 
369  // Cluster occupancy calculated as a function of level number
370  std::vector<unsigned> occupancy;
371 
372  // The thresholds obtained by the LOCALLY_ADAPTIVE method
373  std::vector<double> thresholds;
374 
375  // Minimum, maximum and used level calculated by some algorithms
377 
378  // Unclustered/unused energy produced during recombination
380  double unused;
381 
382  // Quantities defined below are used in the iterative mode only
383  std::vector<fftjet::Peak> iterPreclusters;
384  std::vector<RecoFFTJet> iterJets;
386 
387  // Vectors of constituents
388  std::vector<std::vector<reco::CandidatePtr> > constituents;
389 
390  // Vector of pile-up. We will subtract it from the
391  // 4-vectors of reconstructed jets.
392  std::vector<fftjetcms::VectorLike> pileup;
393 
394  // The pile-up transverse energy density discretization grid.
395  // Note that this is _density_, not energy. To get energy,
396  // multiply by cell area.
397  std::auto_ptr<fftjet::Grid2d<fftjetcms::Real> > pileupEnergyFlow;
398 
399  // The functor that calculates the pile-up density
400  std::auto_ptr<fftjetcms::AbsPileupCalculator> pileupDensityCalc;
401 
402  // Memory buffers related to pile-up subtraction
403  std::vector<fftjet::AbsKernel2d*> memFcns2dVec;
404  std::vector<double> doubleBuf;
405  std::vector<unsigned> cellCountsVec;
406 };
407 
408 #endif // RecoJets_FFTJetProducers_FFTJetProducer_h
std::vector< std::vector< reco::CandidatePtr > > constituents
virtual ~FFTJetProducer()
std::auto_ptr< fftjet::Grid2d< fftjetcms::Real > > pileupEnergyFlow
std::auto_ptr< RecoAlg > recoAlg
std::auto_ptr< fftjet::Functor1< double, fftjet::Peak > > memberFactorCalcPeak
unsigned iterationsPerformed
virtual void beginJob()
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)
const double gridScanMaxEta
void saveResults(edm::Event &iEvent, const edm::EventSetup &, unsigned nPreclustersFound)
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)
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)
virtual void determinePileupDensityFromDB(const edm::Event &iEvent, const edm::EventSetup &iSetup, const edm::InputTag &label, std::auto_ptr< fftjet::Grid2d< fftjetcms::Real > > &density)
double BgData
const std::string recombinationAlgorithm
const double fixedScale
virtual std::auto_ptr< fftjetcms::AbsBgFunctor > parse_bgMembershipFunction(const edm::ParameterSet &)
const bool subtractPileupAs4Vec
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::auto_ptr< fftjet::Functor1< double, fftjet::Peak > > recoScaleCalcPeak
std::vector< fftjet::AbsKernel2d * > memFcns2dVec
std::vector< RecoFFTJet > recoJets
const bool isCrisp
const double recombinationDataCutoff
std::vector< unsigned > occupancy
const double minStableScale
const double maxStableScale
std::vector< fftjet::Peak > preclusters
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
const unsigned nClustersRequested
virtual void produce(edm::Event &, const edm::EventSetup &)
int iEvent
Definition: GenABIO.cc:243
fftjet::AbsVectorRecombinationAlg< fftjetcms::VectorLike, fftjetcms::BgData > RecoAlg
std::auto_ptr< std::vector< double > > iniScales
math::XYZTLorentzVector VectorLike
unsigned usedLevel
virtual void determinePileupDensityFromConfig(const edm::Event &iEvent, const edm::InputTag &label, std::auto_ptr< fftjet::Grid2d< fftjetcms::Real > > &density)
std::auto_ptr< fftjet::Functor1< double, RecoFFTJet > > memberFactorCalcJet
virtual std::auto_ptr< fftjet::Functor1< double, RecoFFTJet > > parse_recoScaleCalcJet(const edm::ParameterSet &)
const double noiseLevel
static void setJetStatusBit(RecoFFTJet *jet, int mask, bool value)
std::vector< RecoFFTJet > iterJets
fftjet::SparseClusteringTree< fftjet::Peak, long > SparseTree
std::vector< unsigned > cellCountsVec
std::string pileupTableRecord
std::string pileupTableName
std::vector< double > thresholds
virtual std::auto_ptr< fftjet::Functor2< double, RecoFFTJet, RecoFFTJet > > parse_jetDistanceCalc(const edm::ParameterSet &)
virtual void endJob()
unsigned iterateJetReconstruction()
fftjet::AbsRecombinationAlg< fftjetcms::Real, fftjetcms::VectorLike, fftjetcms::BgData > GridAlg
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
FFTJetProducer & operator=(const FFTJetProducer &)
const edm::InputTag genJetsLabel
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 &)
const unsigned maxInitialPreclusters
std::string pileupTableCategory
SparseTree sparseTree
virtual std::auto_ptr< fftjet::Functor1< double, fftjet::Peak > > parse_recoScaleCalcPeak(const edm::ParameterSet &)
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
virtual void genJetPreclusters(const SparseTree &tree, edm::Event &, const edm::EventSetup &, const fftjet::Functor1< bool, fftjet::Peak > &peakSelector, std::vector< fftjet::Peak > *preclusters)
static bool loadEnergyFlow(const edm::Event &iEvent, const edm::InputTag &label, std::auto_ptr< fftjet::Grid2d< fftjetcms::Real > > &flow)
fftjetcms::VectorLike unclustered
std::auto_ptr< fftjet::Functor1< bool, fftjet::Peak > > peakSelector
std::vector< fftjet::Peak > iterPreclusters
std::auto_ptr< fftjet::Functor2< double, RecoFFTJet, RecoFFTJet > > jetDistanceCalc
std::auto_ptr< fftjet::ScaleSpaceKernel > jetMembershipFunction
void removeFakePreclusters()
const unsigned maxIterations
std::auto_ptr< fftjet::Functor1< double, RecoFFTJet > > recoScaleCalcJet
void prepareRecombinationScales()