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: 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.8 2011/10/25 00:23:52 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
67  {
68  RESOLUTION = 0xff,
73  };
74 
76  {
77  FIXED = 0,
81  };
82 
83  explicit FFTJetProducer(const edm::ParameterSet&);
84  virtual ~FFTJetProducer();
85 
86  // Parser for the resolution enum
87  static Resolution parse_resolution(const std::string& name);
88 
89 protected:
90  // Functions which should be overriden from the base
91  virtual void beginJob();
92  virtual void produce(edm::Event&, const edm::EventSetup&);
93  virtual void endJob();
94 
95  // The following functions can be overriden by derived classes
96  // in order to adjust jet reconstruction algorithm behavior.
97 
98  // Override the following method in order to implement
99  // your own precluster selection strategy
100  virtual void selectPreclusters(
101  const SparseTree& tree,
102  const fftjet::Functor1<bool,fftjet::Peak>& peakSelector,
103  std::vector<fftjet::Peak>* preclusters);
104 
105  // Override the following method (which by default does not do
106  // anything) in order to implement your own process-dependent
107  // assignment of membership functions to preclusters. This method
108  // will be called once per event, just before the main algorithm.
109  virtual void assignMembershipFunctions(
110  std::vector<fftjet::Peak>* preclusters);
111 
112  // Parser for the peak selector
113  virtual std::auto_ptr<fftjet::Functor1<bool,fftjet::Peak> >
115 
116  // Parser for the default jet membership function
117  virtual std::auto_ptr<fftjet::ScaleSpaceKernel>
119 
120  // Parser for the background membership function
121  virtual std::auto_ptr<fftjetcms::AbsBgFunctor>
123 
124  // Calculator for the recombination scale
125  virtual std::auto_ptr<fftjet::Functor1<double,fftjet::Peak> >
127 
128  // Calculator for the recombination scale ratio
129  virtual std::auto_ptr<fftjet::Functor1<double,fftjet::Peak> >
131 
132  // Calculator for the membership function factor
133  virtual std::auto_ptr<fftjet::Functor1<double,fftjet::Peak> >
135 
136  // Similar calculators for the iterative algorithm
137  virtual std::auto_ptr<fftjet::Functor1<double,RecoFFTJet> >
139 
140  virtual std::auto_ptr<fftjet::Functor1<double,RecoFFTJet> >
142 
143  virtual std::auto_ptr<fftjet::Functor1<double,RecoFFTJet> >
145 
146  // Calculator of the distance between jets which is used to make
147  // the decision about convergence of the iterative algorithm
148  virtual std::auto_ptr<fftjet::Functor2<double,RecoFFTJet,RecoFFTJet> >
150 
151  // Pile-up density calculator
152  virtual std::auto_ptr<fftjetcms::AbsPileupCalculator>
154 
155  // The following function performs most of the precluster selection
156  // work in this module. You might want to reuse it if only a slight
157  // modification of the "selectPreclusters" method is desired.
158  void selectTreeNodes(const SparseTree& tree,
159  const fftjet::Functor1<bool,fftjet::Peak>& peakSelect,
160  std::vector<SparseTree::NodeId>* nodes);
161 private:
162  typedef fftjet::AbsVectorRecombinationAlg<
164  typedef fftjet::AbsRecombinationAlg<
166 
167  // Explicitly disable other ways to construct this object
168  FFTJetProducer();
171 
172  // Useful local utilities
173  template<class Real>
174  void loadSparseTreeData(const edm::Event&);
175 
176  void removeFakePreclusters();
177 
178  // The following methods do most of the work.
179  // The following function tells us if the grid was rebuilt.
180  static bool loadEnergyFlow(
181  const edm::Event& iEvent, const edm::InputTag& label,
182  std::auto_ptr<fftjet::Grid2d<fftjetcms::Real> >& flow);
183  void buildGridAlg();
185  bool checkConvergence(const std::vector<RecoFFTJet>& previousIterResult,
186  std::vector<RecoFFTJet>& thisIterResult);
190  unsigned nPreclustersFound);
191 
192  template <typename Jet>
194 
195  template <typename Jet>
196  void makeProduces(const std::string& alias, const std::string& tag);
197 
198  // The following function scans the pile-up density
199  // and fills the pile-up grid. Can be overriden if
200  // necessary.
201  virtual void determinePileupDensity(
202  const edm::Event& iEvent, const edm::InputTag& label,
203  std::auto_ptr<fftjet::Grid2d<fftjetcms::Real> >& density);
204 
205  // The following function builds the pile-up estimate
206  // for each jet
207  void determinePileup();
208 
209  // The following function returns the number of iterations
210  // performed. If this number equals to or less than "maxIterations"
211  // then the iterations have converged. If the number larger than
212  // "maxIterations" then the iterations failed to converge (note,
213  // however, that only "maxIterations" iterations would still be
214  // performed).
215  unsigned iterateJetReconstruction();
216 
217  // A function to set jet status bits
218  static void setJetStatusBit(RecoFFTJet* jet, int mask, bool value);
219 
220  //
221  // ----------member data ---------------------------
222  //
223 
224  // Local copy of the module configuration
226 
227  // Label for the tree produced by FFTJetPatRecoProducer
229 
230  // Are we going to use energy flow discretization grid as input
231  // to jet reconstruction?
233 
234  // Are we going to rebuild the energy flow discretization grid
235  // or to reuse the grid made by FFTJetPatRecoProducer?
236  const bool reuseExistingGrid;
237 
238  // Are we iterating?
239  const unsigned maxIterations;
240 
241  // Parameters which affect iteration convergence
242  const unsigned nJetsRequiredToConverge;
243  const double convergenceDistance;
244 
245  // Are we building assignments of collection members to jets?
246  const bool assignConstituents;
247 
248  // Are we resumming the constituents to determine jet 4-vectors?
249  // This might make sense if FFTJet is used in the crisp, gridded
250  // mode to determine jet areas, and vector recombination is desired.
251  const bool resumConstituents;
252 
253  // Are we going to subtract the pile-up? Note that
254  // pile-up subtraction does not modify eta and phi moments.
255  const bool calculatePileup;
256  const bool subtractPileup;
258 
259  // Label for the pile-up energy flow. Must be specified
260  // if the pile-up is subtracted.
262 
263  // Scale for the peak selection (if the scale is fixed)
264  const double fixedScale;
265 
266  // Minimum and maximum scale for searching stable configurations
267  const double minStableScale;
268  const double maxStableScale;
269 
270  // Stability "alpha"
271  const double stabilityAlpha;
272 
273  // Not sure at this point how to treat noise... For now, this is
274  // just a single configurable number...
275  const double noiseLevel;
276 
277  // Number of clusters requested (if the scale is adaptive)
278  const unsigned nClustersRequested;
279 
280  // Maximum eta for the grid-based algorithm
281  const double gridScanMaxEta;
282 
283  // Parameters related to the recombination algorithm
284  const std::string recombinationAlgorithm;
285  const bool isCrisp;
286  const double unlikelyBgWeight;
288 
289  // Resolution. The corresponding parameter value
290  // should be one of "fixed", "maximallyStable",
291  // "globallyAdaptive", or "locallyAdaptive".
293 
294  // Scales used
295  std::auto_ptr<std::vector<double> > iniScales;
296 
297  // The sparse clustering tree
299 
300  // Peak selector for the peaks already in the tree
301  std::auto_ptr<fftjet::Functor1<bool,fftjet::Peak> > peakSelector;
302 
303  // Recombination algorithms and related quantities
304  std::auto_ptr<RecoAlg> recoAlg;
305  std::auto_ptr<GridAlg> gridAlg;
306  std::auto_ptr<fftjet::ScaleSpaceKernel> jetMembershipFunction;
307  std::auto_ptr<fftjetcms::AbsBgFunctor> bgMembershipFunction;
308 
309  // Calculator for the recombination scale
310  std::auto_ptr<fftjet::Functor1<double,fftjet::Peak> > recoScaleCalcPeak;
311 
312  // Calculator for the recombination scale ratio
313  std::auto_ptr<fftjet::Functor1<double,fftjet::Peak> >
315 
316  // Calculator for the membership function factor
317  std::auto_ptr<fftjet::Functor1<double,fftjet::Peak> > memberFactorCalcPeak;
318 
319  // Similar calculators for the iterative algorithm
320  std::auto_ptr<fftjet::Functor1<double,RecoFFTJet> > recoScaleCalcJet;
321  std::auto_ptr<fftjet::Functor1<double,RecoFFTJet> > recoScaleRatioCalcJet;
322  std::auto_ptr<fftjet::Functor1<double,RecoFFTJet> > memberFactorCalcJet;
323 
324  // Calculator for the jet distance used to estimate convergence
325  // of the iterative algorithm
326  std::auto_ptr<fftjet::Functor2<double,RecoFFTJet,RecoFFTJet> >
328 
329  // Vector of selected tree nodes
330  std::vector<SparseTree::NodeId> nodes;
331 
332  // Vector of selected preclusters
333  std::vector<fftjet::Peak> preclusters;
334 
335  // Vector of reconstructed jets (we will refill it in every event)
336  std::vector<RecoFFTJet> recoJets;
337 
338  // Cluster occupancy calculated as a function of level number
339  std::vector<unsigned> occupancy;
340 
341  // The thresholds obtained by the LOCALLY_ADAPTIVE method
342  std::vector<double> thresholds;
343 
344  // Minimum, maximum and used level calculated by some algorithms
346 
347  // Unclustered/unused energy produced during recombination
349  double unused;
350 
351  // Quantities defined below are used in the iterative mode only
352  std::vector<fftjet::Peak> iterPreclusters;
353  std::vector<RecoFFTJet> iterJets;
355 
356  // Vectors of constituents
357  std::vector<std::vector<reco::CandidatePtr> > constituents;
358 
359  // Vector of pile-up. We will subtract it from the
360  // 4-vectors of reconstructed jets.
361  std::vector<fftjetcms::VectorLike> pileup;
362 
363  // The pile-up transverse energy density discretization grid.
364  // Note that this is _density_, not energy. To get energy,
365  // multiply by cell area.
366  std::auto_ptr<fftjet::Grid2d<fftjetcms::Real> > pileupEnergyFlow;
367 
368  // The functor that calculates the pile-up density
369  std::auto_ptr<fftjetcms::AbsPileupCalculator> pileupDensityCalc;
370 
371  // Memory buffers related to pile-up subtraction
372  std::vector<fftjet::AbsKernel2d*> memFcns2dVec;
373  std::vector<double> doubleBuf;
374  std::vector<unsigned> cellCountsVec;
375 };
376 
377 #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)
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
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
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 &)
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::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 &)
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
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()