CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoJets/FFTJetProducers/plugins/FFTJetProducer.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    FFTJetProducers
00004 // Class:      FFTJetProducer
00005 // 
00021 //
00022 // Original Author:  Igor Volobouev
00023 //         Created:  Sun Jun 20 14:32:36 CDT 2010
00024 // $Id: FFTJetProducer.h,v 1.2 2010/12/07 00:19:43 igv Exp $
00025 //
00026 //
00027 
00028 #ifndef RecoJets_FFTJetProducers_FFTJetProducer_h
00029 #define RecoJets_FFTJetProducers_FFTJetProducer_h
00030 
00031 #include <memory>
00032 
00033 // FFTJet headers
00034 #include "fftjet/AbsRecombinationAlg.hh"
00035 #include "fftjet/AbsVectorRecombinationAlg.hh"
00036 #include "fftjet/SparseClusteringTree.hh"
00037 
00038 // framework include files
00039 #include "FWCore/Framework/interface/Frameworkfwd.h"
00040 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00041 #include "FWCore/Framework/interface/EDProducer.h"
00042 #include "FWCore/Framework/interface/Event.h"
00043 
00044 #include "DataFormats/Candidate/interface/CandidateFwd.h"
00045 
00046 // local FFTJet-related definitions
00047 #include "RecoJets/FFTJetAlgorithms/interface/fftjetTypedefs.h"
00048 #include "RecoJets/FFTJetProducers/interface/FFTJetInterface.h"
00049 
00050 namespace fftjetcms {
00051     class DiscretizedEnergyFlow;
00052 }
00053 
00054 //
00055 // class declaration
00056 //
00057 class FFTJetProducer : public edm::EDProducer, 
00058                        public fftjetcms::FFTJetInterface
00059 {
00060 public:
00061     typedef fftjet::RecombinedJet<fftjetcms::VectorLike> RecoFFTJet;
00062     typedef fftjet::SparseClusteringTree<fftjet::Peak,long> SparseTree;
00063 
00064     enum Resolution
00065     {
00066         FIXED = 0,
00067         MAXIMALLY_STABLE,
00068         GLOBALLY_ADAPTIVE,
00069         LOCALLY_ADAPTIVE
00070     };
00071 
00072     explicit FFTJetProducer(const edm::ParameterSet&);
00073     virtual ~FFTJetProducer();
00074 
00075     // Parser for the resolution enum
00076     static Resolution parse_resolution(const std::string& name);
00077 
00078 protected:
00079     // Functions which should be overriden from the base
00080     virtual void beginJob();
00081     virtual void produce(edm::Event&, const edm::EventSetup&);
00082     virtual void endJob();
00083 
00084     // The following functions can be overriden by derived classes 
00085     // in order to adjust jet reconstruction algorithm behavior.
00086 
00087     // Override the following method in order to implement
00088     // your own precluster selection strategy
00089     virtual void selectPreclusters(
00090         const SparseTree& tree,
00091         const fftjet::Functor1<bool,fftjet::Peak>& peakSelector,
00092         std::vector<fftjet::Peak>* preclusters);
00093 
00094     // Override the following method (which by default does not do
00095     // anything) in order to implement your own process-dependent
00096     // assignment of membership functions to preclusters. This method
00097     // will be called once per event, just before the main algorithm.
00098     virtual void assignMembershipFunctions(
00099         std::vector<fftjet::Peak>* preclusters);
00100 
00101     // Parser for the peak selector
00102     virtual std::auto_ptr<fftjet::Functor1<bool,fftjet::Peak> >
00103     parse_peakSelector(const edm::ParameterSet&);
00104 
00105     // Parser for the default jet membership function
00106     virtual std::auto_ptr<fftjet::ScaleSpaceKernel>
00107     parse_jetMembershipFunction(const edm::ParameterSet&);
00108 
00109     // Parser for the background membership function
00110     virtual std::auto_ptr<fftjetcms::AbsBgFunctor>
00111     parse_bgMembershipFunction(const edm::ParameterSet&);
00112 
00113     // Calculator for the recombination scale
00114     virtual std::auto_ptr<fftjet::Functor1<double,fftjet::Peak> >
00115     parse_recoScaleCalcPeak(const edm::ParameterSet&);
00116 
00117     // Calculator for the recombination scale ratio
00118     virtual std::auto_ptr<fftjet::Functor1<double,fftjet::Peak> >
00119     parse_recoScaleRatioCalcPeak(const edm::ParameterSet&);
00120 
00121     // Calculator for the membership function factor
00122     virtual std::auto_ptr<fftjet::Functor1<double,fftjet::Peak> >
00123     parse_memberFactorCalcPeak(const edm::ParameterSet&);
00124 
00125     // Similar calculators for the iterative algorithm
00126     virtual std::auto_ptr<fftjet::Functor1<double,RecoFFTJet> >
00127     parse_recoScaleCalcJet(const edm::ParameterSet&);
00128 
00129     virtual std::auto_ptr<fftjet::Functor1<double,RecoFFTJet> >
00130     parse_recoScaleRatioCalcJet(const edm::ParameterSet&);
00131 
00132     virtual std::auto_ptr<fftjet::Functor1<double,RecoFFTJet> >
00133     parse_memberFactorCalcJet(const edm::ParameterSet&);
00134 
00135     // Calculator of the distance between jets which is used to make
00136     // the decision about convergence of the iterative algorithm
00137     virtual std::auto_ptr<fftjet::Functor2<double,RecoFFTJet,RecoFFTJet> >
00138     parse_jetDistanceCalc(const edm::ParameterSet&);
00139 
00140     // The following function performs most of the precluster selection
00141     // work in this module. You might want to reuse it if only a slight
00142     // modification of the "selectPreclusters" method is desired.
00143     void selectTreeNodes(const SparseTree& tree,
00144                          const fftjet::Functor1<bool,fftjet::Peak>& peakSelect,
00145                          std::vector<SparseTree::NodeId>* nodes);
00146 private:
00147     typedef fftjet::AbsVectorRecombinationAlg<
00148         fftjetcms::VectorLike,fftjetcms::BgData> RecoAlg;
00149     typedef fftjet::AbsRecombinationAlg<
00150         fftjetcms::Real,fftjetcms::VectorLike,fftjetcms::BgData> GridAlg;
00151 
00152     // Explicitly disable other ways to construct this object
00153     FFTJetProducer();
00154     FFTJetProducer(const FFTJetProducer&);
00155     FFTJetProducer& operator=(const FFTJetProducer&);
00156 
00157     // Useful local utilities
00158     template<class Real>
00159     void loadSparseTreeData(const edm::Event&);
00160 
00161     // The following methods do most of the work
00162     void buildGridAlg();
00163     void prepareRecombinationScales();
00164     void loadEnergyFlow(const edm::Event& iEvent);
00165     bool checkConvergence(const std::vector<RecoFFTJet>& previousIterResult,
00166                           std::vector<RecoFFTJet>& thisIterResult);
00167     void determineGriddedConstituents();
00168     void determineVectorConstituents();
00169     void saveResults(edm::Event& iEvent, const edm::EventSetup&);
00170 
00171     template <typename Jet>
00172     void writeJets(edm::Event& iEvent, const edm::EventSetup&);
00173 
00174     template <typename Jet>
00175     void makeProduces(const std::string& alias, const std::string& tag);
00176 
00177     // The following function returns the number of iterations
00178     // performed. If this number equals to or less than "maxIterations"
00179     // then the iterations have converged. If the number larger than
00180     // "maxIterations" then the iterations failed to converge (note,
00181     // however, that only "maxIterations" iterations would still be
00182     // performed).
00183     unsigned iterateJetReconstruction();
00184 
00185     //
00186     // ----------member data ---------------------------
00187     //
00188 
00189     // Local copy of the module configuration 
00190     const edm::ParameterSet myConfiguration;
00191 
00192     // Label for the tree produced by FFTJetPatRecoProducer
00193     const edm::InputTag treeLabel;
00194 
00195     // Are we going to use energy flow discretization grid as input
00196     // to jet reconstruction?
00197     const bool useGriddedAlgorithm;
00198 
00199     // Are we going to rebuild the energy flow discretization grid
00200     // or to reuse the grid made by FFTJetPatRecoProducer?
00201     const bool reuseExistingGrid;
00202 
00203     // Are we iterating?
00204     const unsigned maxIterations;
00205 
00206     // Parameters which affect iteration convergence
00207     const unsigned nJetsRequiredToConverge;
00208     const double convergenceDistance;
00209 
00210     // Are we building assignments of collection members to jets?
00211     const bool assignConstituents;
00212 
00213     // Are we resumming the constituents to determine jet 4-vectors?
00214     // This might make sense if FFTJet is used in the crisp, gridded
00215     // mode to determine jet areas, and vector recombination is desired.
00216     const bool resumConstituents;
00217 
00218     // Scale for the peak selection (if the scale is fixed)
00219     const double fixedScale;
00220 
00221     // Minimum and maximum scale for searching stable configurations
00222     const double minStableScale;
00223     const double maxStableScale;
00224 
00225     // Stability "alpha"
00226     const double stabilityAlpha;
00227 
00228     // Not sure at this point how to treat noise... For now, this is
00229     // just a single configurable number...
00230     const double noiseLevel;
00231 
00232     // Number of clusters requested (if the scale is adaptive)
00233     const unsigned nClustersRequested;
00234 
00235     // Maximum eta for the grid-based algorithm
00236     const double gridScanMaxEta;
00237 
00238     // Parameters related to the recombination algorithm
00239     const std::string recombinationAlgorithm;
00240     const bool isCrisp;
00241     const double unlikelyBgWeight;
00242     const double recombinationDataCutoff;
00243 
00244     // Resolution. The corresponding parameter value
00245     // should be one of "fixed", "maximallyStable",
00246     // "globallyAdaptive", or "locallyAdaptive".
00247     Resolution resolution;
00248 
00249     // Scales used
00250     std::auto_ptr<std::vector<double> > iniScales;
00251 
00252     // The sparse clustering tree
00253     SparseTree sparseTree;
00254 
00255     // Peak selector for the peaks already in the tree
00256     std::auto_ptr<fftjet::Functor1<bool,fftjet::Peak> > peakSelector;
00257 
00258     // Recombination algorithms and related quantities
00259     std::auto_ptr<RecoAlg> recoAlg;
00260     std::auto_ptr<GridAlg> gridAlg;
00261     std::auto_ptr<fftjet::ScaleSpaceKernel> jetMembershipFunction;
00262     std::auto_ptr<fftjetcms::AbsBgFunctor> bgMembershipFunction;
00263 
00264     // Calculator for the recombination scale
00265     std::auto_ptr<fftjet::Functor1<double,fftjet::Peak> > recoScaleCalcPeak;
00266 
00267     // Calculator for the recombination scale ratio
00268     std::auto_ptr<fftjet::Functor1<double,fftjet::Peak> >
00269     recoScaleRatioCalcPeak;
00270 
00271     // Calculator for the membership function factor
00272     std::auto_ptr<fftjet::Functor1<double,fftjet::Peak> > memberFactorCalcPeak;
00273 
00274     // Similar calculators for the iterative algorithm
00275     std::auto_ptr<fftjet::Functor1<double,RecoFFTJet> > recoScaleCalcJet;
00276     std::auto_ptr<fftjet::Functor1<double,RecoFFTJet> > recoScaleRatioCalcJet;
00277     std::auto_ptr<fftjet::Functor1<double,RecoFFTJet> > memberFactorCalcJet;
00278 
00279     // Calculator for the jet distance used to estimate convergence
00280     // of the iterative algorithm
00281     std::auto_ptr<fftjet::Functor2<double,RecoFFTJet,RecoFFTJet> >
00282     jetDistanceCalc;
00283 
00284     // Vector of selected tree nodes
00285     std::vector<SparseTree::NodeId> nodes;
00286 
00287     // Vector of selected preclusters
00288     std::vector<fftjet::Peak> preclusters;
00289 
00290     // Vector of reconstructed jets (we will refill it in every event)
00291     std::vector<RecoFFTJet> recoJets;
00292 
00293     // Cluster occupancy calculated as a function of level number
00294     std::vector<unsigned> occupancy;
00295 
00296     // The thresholds obtained by the LOCALLY_ADAPTIVE method
00297     std::vector<double> thresholds;
00298 
00299     // Minimum, maximum and used level calculated by some algorithms
00300     unsigned minLevel, maxLevel, usedLevel;
00301 
00302     // Unclustered/unused energy produced during recombination
00303     fftjetcms::VectorLike unclustered;
00304     double unused;
00305 
00306     // Quantities defined below are used in the iterative mode only
00307     std::vector<fftjet::Peak> iterPreclusters;
00308     std::vector<RecoFFTJet> iterJets;
00309     unsigned iterationsPerformed;
00310 
00311     // Vectors of constituents
00312     std::vector<std::vector<reco::CandidatePtr> > constituents;
00313 };
00314 
00315 #endif // RecoJets_FFTJetProducers_FFTJetProducer_h