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 //
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 // framework include files
42 
44 
45 // local FFTJet-related definitions
49 
50 namespace fftjetcms {
52 }
53 
54 //
55 // class declaration
56 //
59 {
60 public:
61  typedef fftjet::RecombinedJet<fftjetcms::VectorLike> RecoFFTJet;
62  typedef fftjet::SparseClusteringTree<fftjet::Peak,long> SparseTree;
63 
64  // Masks for the status bits. Do not add anything
65  // here -- higher bits (starting with 0x1000) will be
66  // used to indicate jet correction levels applied.
68  {
69  RESOLUTION = 0xff,
74  };
75 
77  {
78  FIXED = 0,
83  };
84 
85  explicit FFTJetProducer(const edm::ParameterSet&);
86  virtual ~FFTJetProducer();
87 
88  // Parser for the resolution enum
90 
91 protected:
92  // Functions which should be overriden from the base
93  virtual void beginJob();
94  virtual void produce(edm::Event&, const edm::EventSetup&);
95  virtual void endJob();
96 
97  // The following functions can be overriden by derived classes
98  // in order to adjust jet reconstruction algorithm behavior.
99 
100  // Override the following method in order to implement
101  // your own precluster selection strategy
102  virtual void selectPreclusters(
103  const SparseTree& tree,
104  const fftjet::Functor1<bool,fftjet::Peak>& peakSelector,
105  std::vector<fftjet::Peak>* preclusters);
106 
107  // Precluster maker from GenJets (useful in calibration)
108  virtual void genJetPreclusters(
109  const SparseTree& tree,
110  edm::Event&, const edm::EventSetup&,
111  const fftjet::Functor1<bool,fftjet::Peak>& peakSelector,
112  std::vector<fftjet::Peak>* preclusters);
113 
114  // Override the following method (which by default does not do
115  // anything) in order to implement your own process-dependent
116  // assignment of membership functions to preclusters. This method
117  // will be called once per event, just before the main algorithm.
118  virtual void assignMembershipFunctions(
119  std::vector<fftjet::Peak>* preclusters);
120 
121  // Parser for the peak selector
122  virtual std::auto_ptr<fftjet::Functor1<bool,fftjet::Peak> >
124 
125  // Parser for the default jet membership function
126  virtual std::auto_ptr<fftjet::ScaleSpaceKernel>
128 
129  // Parser for the background membership function
130  virtual std::auto_ptr<fftjetcms::AbsBgFunctor>
132 
133  // Calculator for the recombination scale
134  virtual std::auto_ptr<fftjet::Functor1<double,fftjet::Peak> >
136 
137  // Calculator for the recombination scale ratio
138  virtual std::auto_ptr<fftjet::Functor1<double,fftjet::Peak> >
140 
141  // Calculator for the membership function factor
142  virtual std::auto_ptr<fftjet::Functor1<double,fftjet::Peak> >
144 
145  // Similar calculators for the iterative algorithm
146  virtual std::auto_ptr<fftjet::Functor1<double,RecoFFTJet> >
148 
149  virtual std::auto_ptr<fftjet::Functor1<double,RecoFFTJet> >
151 
152  virtual std::auto_ptr<fftjet::Functor1<double,RecoFFTJet> >
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::auto_ptr<fftjet::Functor2<double,RecoFFTJet,RecoFFTJet> >
159 
160  // Pile-up density calculator
161  virtual std::auto_ptr<fftjetcms::AbsPileupCalculator>
163 
164  // The following function performs most of the precluster selection
165  // work in this module. You might want to reuse it if only a slight
166  // modification of the "selectPreclusters" method is desired.
167  void selectTreeNodes(const SparseTree& tree,
168  const fftjet::Functor1<bool,fftjet::Peak>& peakSelect,
169  std::vector<SparseTree::NodeId>* nodes);
170 private:
171  typedef fftjet::AbsVectorRecombinationAlg<
173  typedef fftjet::AbsRecombinationAlg<
175 
176  // Explicitly disable other ways to construct this object
177  FFTJetProducer();
180 
181  // Useful local utilities
182  template<class Real>
183  void loadSparseTreeData(const edm::Event&);
184 
185  void removeFakePreclusters();
186 
187  // The following methods do most of the work.
188  // The following function tells us if the grid was rebuilt.
189  static bool loadEnergyFlow(
190  const edm::Event& iEvent, const edm::InputTag& label,
191  std::auto_ptr<fftjet::Grid2d<fftjetcms::Real> >& flow);
192  void buildGridAlg();
194  bool checkConvergence(const std::vector<RecoFFTJet>& previousIterResult,
195  std::vector<RecoFFTJet>& thisIterResult);
199  unsigned nPreclustersFound);
200 
201  template <typename Jet>
203 
204  template <typename Jet>
205  void makeProduces(const std::string& alias, const std::string& tag);
206 
207  // The following function scans the pile-up density
208  // and fills the pile-up grid. Can be overriden if
209  // necessary.
211  const edm::Event& iEvent, const edm::InputTag& label,
212  std::auto_ptr<fftjet::Grid2d<fftjetcms::Real> >& density);
213 
214  // Similar function for getting pile-up shape from the database
215  virtual void determinePileupDensityFromDB(
216  const edm::Event& iEvent, const edm::EventSetup& iSetup,
217  const edm::InputTag& label,
218  std::auto_ptr<fftjet::Grid2d<fftjetcms::Real> >& density);
219 
220  // The following function builds the pile-up estimate
221  // for each jet
222  void determinePileup();
223 
224  // The following function returns the number of iterations
225  // performed. If this number equals to or less than "maxIterations"
226  // then the iterations have converged. If the number larger than
227  // "maxIterations" then the iterations failed to converge (note,
228  // however, that only "maxIterations" iterations would still be
229  // performed).
230  unsigned iterateJetReconstruction();
231 
232  // A function to set jet status bits
233  static void setJetStatusBit(RecoFFTJet* jet, int mask, bool value);
234 
235  //
236  // ----------member data ---------------------------
237  //
238 
239  // Local copy of the module configuration
241 
242  // Label for the tree produced by FFTJetPatRecoProducer
244 
245  // Are we going to use energy flow discretization grid as input
246  // to jet reconstruction?
248 
249  // Are we going to rebuild the energy flow discretization grid
250  // or to reuse the grid made by FFTJetPatRecoProducer?
251  const bool reuseExistingGrid;
252 
253  // Are we iterating?
254  const unsigned maxIterations;
255 
256  // Parameters which affect iteration convergence
257  const unsigned nJetsRequiredToConverge;
258  const double convergenceDistance;
259 
260  // Are we building assignments of collection members to jets?
261  const bool assignConstituents;
262 
263  // Are we resumming the constituents to determine jet 4-vectors?
264  // This might make sense if FFTJet is used in the crisp, gridded
265  // mode to determine jet areas, and vector recombination is desired.
266  const bool resumConstituents;
267 
268  // Are we going to subtract the pile-up? Note that
269  // pile-up subtraction does not modify eta and phi moments.
270  const bool calculatePileup;
271  const bool subtractPileup;
273 
274  // Label for the pile-up energy flow. Must be specified
275  // if the pile-up is subtracted.
277 
278  // Scale for the peak selection (if the scale is fixed)
279  const double fixedScale;
280 
281  // Minimum and maximum scale for searching stable configurations
282  const double minStableScale;
283  const double maxStableScale;
284 
285  // Stability "alpha"
286  const double stabilityAlpha;
287 
288  // Not sure at this point how to treat noise... For now, this is
289  // just a single configurable number...
290  const double noiseLevel;
291 
292  // Number of clusters requested (if the scale is adaptive)
293  const unsigned nClustersRequested;
294 
295  // Maximum eta for the grid-based algorithm
296  const double gridScanMaxEta;
297 
298  // Parameters related to the recombination algorithm
300  const bool isCrisp;
301  const double unlikelyBgWeight;
303 
304  // Label for the genJets used as seeds for jets
306 
307  // Maximum number of preclusters to use as jet seeds.
308  // This does not take into account the preclusters
309  // for which the value of the membership factor is 0.
310  const unsigned maxInitialPreclusters;
311 
312  // Resolution. The corresponding parameter value
313  // should be one of "fixed", "maximallyStable",
314  // "globallyAdaptive", "locallyAdaptive", or "fromGenJets".
316 
317  // Parameters related to the pileup shape stored
318  // in the database
323 
324  // Scales used
325  std::auto_ptr<std::vector<double> > iniScales;
326 
327  // The sparse clustering tree
329 
330  // Peak selector for the peaks already in the tree
331  std::auto_ptr<fftjet::Functor1<bool,fftjet::Peak> > peakSelector;
332 
333  // Recombination algorithms and related quantities
334  std::auto_ptr<RecoAlg> recoAlg;
335  std::auto_ptr<GridAlg> gridAlg;
336  std::auto_ptr<fftjet::ScaleSpaceKernel> jetMembershipFunction;
337  std::auto_ptr<fftjetcms::AbsBgFunctor> bgMembershipFunction;
338 
339  // Calculator for the recombination scale
340  std::auto_ptr<fftjet::Functor1<double,fftjet::Peak> > recoScaleCalcPeak;
341 
342  // Calculator for the recombination scale ratio
343  std::auto_ptr<fftjet::Functor1<double,fftjet::Peak> >
345 
346  // Calculator for the membership function factor
347  std::auto_ptr<fftjet::Functor1<double,fftjet::Peak> > memberFactorCalcPeak;
348 
349  // Similar calculators for the iterative algorithm
350  std::auto_ptr<fftjet::Functor1<double,RecoFFTJet> > recoScaleCalcJet;
351  std::auto_ptr<fftjet::Functor1<double,RecoFFTJet> > recoScaleRatioCalcJet;
352  std::auto_ptr<fftjet::Functor1<double,RecoFFTJet> > memberFactorCalcJet;
353 
354  // Calculator for the jet distance used to estimate convergence
355  // of the iterative algorithm
356  std::auto_ptr<fftjet::Functor2<double,RecoFFTJet,RecoFFTJet> >
358 
359  // Vector of selected tree nodes
360  std::vector<SparseTree::NodeId> nodes;
361 
362  // Vector of selected preclusters
363  std::vector<fftjet::Peak> preclusters;
364 
365  // Vector of reconstructed jets (we will refill it in every event)
366  std::vector<RecoFFTJet> recoJets;
367 
368  // Cluster occupancy calculated as a function of level number
369  std::vector<unsigned> occupancy;
370 
371  // The thresholds obtained by the LOCALLY_ADAPTIVE method
372  std::vector<double> thresholds;
373 
374  // Minimum, maximum and used level calculated by some algorithms
376 
377  // Unclustered/unused energy produced during recombination
379  double unused;
380 
381  // Quantities defined below are used in the iterative mode only
382  std::vector<fftjet::Peak> iterPreclusters;
383  std::vector<RecoFFTJet> iterJets;
385 
386  // Vectors of constituents
387  std::vector<std::vector<reco::CandidatePtr> > constituents;
388 
389  // Vector of pile-up. We will subtract it from the
390  // 4-vectors of reconstructed jets.
391  std::vector<fftjetcms::VectorLike> pileup;
392 
393  // The pile-up transverse energy density discretization grid.
394  // Note that this is _density_, not energy. To get energy,
395  // multiply by cell area.
396  std::auto_ptr<fftjet::Grid2d<fftjetcms::Real> > pileupEnergyFlow;
397 
398  // The functor that calculates the pile-up density
399  std::auto_ptr<fftjetcms::AbsPileupCalculator> pileupDensityCalc;
400 
401  // Memory buffers related to pile-up subtraction
402  std::vector<fftjet::AbsKernel2d*> memFcns2dVec;
403  std::vector<double> doubleBuf;
404  std::vector<unsigned> cellCountsVec;
405 };
406 
407 #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()