CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/RecoJets/JetProducers/plugins/VirtualJetProducer.h

Go to the documentation of this file.
00001 #ifndef RecoJets_JetProducers_plugins_VirtualJetProducer_h
00002 #define RecoJets_JetProducers_plugins_VirtualJetProducer_h
00003 
00004 
00005 #include "FWCore/Framework/interface/EDProducer.h"
00006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00007 #include "DataFormats/Candidate/interface/Candidate.h"
00008 #include "DataFormats/Candidate/interface/CandidateFwd.h"
00009 #include "DataFormats/JetReco/interface/Jet.h"
00010 #include "DataFormats/JetReco/interface/CaloJet.h"
00011 #include "DataFormats/JetReco/interface/PFJet.h"
00012 #include "DataFormats/JetReco/interface/BasicJet.h"
00013 #include "DataFormats/JetReco/interface/GenJet.h"
00014 
00015 #include "RecoJets/JetProducers/interface/PileUpSubtractor.h"
00016 #include "RecoJets/JetProducers/interface/AnomalousTower.h"
00017 
00018 #include "fastjet/JetDefinition.hh"
00019 #include "fastjet/ClusterSequence.hh"
00020 #include "fastjet/ClusterSequenceArea.hh"
00021 #include "fastjet/PseudoJet.hh"
00022 #include "fastjet/ActiveAreaSpec.hh"
00023 
00024 #include <memory>
00025 #include <vector>
00026 #include <boost/shared_ptr.hpp>
00027 
00028 
00029 class VirtualJetProducer : public edm::EDProducer
00030 {
00031 protected:
00032   //
00033   // typedefs & structs
00034   //
00035   struct JetType {
00036     enum Type {
00037       BasicJet,
00038       GenJet,
00039       CaloJet,
00040       PFJet,
00041       TrackJet,
00042       PFClusterJet,
00043       LastJetType  // no real type, technical
00044     };
00045     static const char *names[];
00046     static Type byName(const std::string &name);
00047   };
00048     
00049   JetType::Type jetTypeE;
00050 
00051   inline bool makeCaloJet(const JetType::Type &fTag) {
00052     return fTag == JetType::CaloJet;
00053   }
00054   inline bool makePFJet(const JetType::Type &fTag) {
00055     return fTag == JetType::PFJet;
00056   }
00057   inline bool makeGenJet(const JetType::Type &fTag) {
00058     return fTag == JetType::GenJet;
00059   }
00060   inline bool makeTrackJet(const JetType::Type &fTag) {
00061     return fTag == JetType::TrackJet;
00062   }
00063   inline bool makePFClusterJet(const JetType::Type &fTag) {
00064     return fTag == JetType::PFClusterJet;
00065   }
00066   inline bool makeBasicJet(const JetType::Type &fTag) {
00067     return fTag == JetType::BasicJet;
00068   }
00069   
00070 
00071   //
00072   // construction/destruction
00073   //
00074 public:
00075   explicit VirtualJetProducer(const edm::ParameterSet& iConfig);
00076   virtual ~VirtualJetProducer();
00077   
00078   // typedefs
00079   typedef boost::shared_ptr<fastjet::ClusterSequence>        ClusterSequencePtr;
00080   typedef boost::shared_ptr<fastjet::JetDefinition::Plugin>  PluginPtr;
00081   typedef boost::shared_ptr<fastjet::JetDefinition>          JetDefPtr;
00082   typedef boost::shared_ptr<fastjet::ActiveAreaSpec>         ActiveAreaSpecPtr;
00083   typedef boost::shared_ptr<fastjet::RangeDefinition>        RangeDefPtr;
00084   
00085   //
00086   // member functions
00087   //
00088 public:
00089   virtual void  produce(edm::Event& iEvent, const edm::EventSetup& iSetup);
00090   std::string   jetType() const { return jetType_; }
00091   
00092 protected:
00093 
00094   //
00095   // Internal methods for jet production.
00096   // The user can either use the defaults, or override all of these methods. 
00097   //
00098 
00099   // This method creates the "produces" statement in the constructor.
00100   // The default is to produce a single jet collection as per the user's request
00101   // (Calo,PF,Basic, or Gen). 
00102   virtual void makeProduces( std::string s, std::string tag = "" );
00103 
00104   // This method inputs the constituents from "inputs" and modifies
00105   // fjInputs. 
00106   virtual void inputTowers();
00107 
00108   // This checks if the tower is anomalous (if a calo tower).
00109   virtual bool isAnomalousTower(reco::CandidatePtr input);
00110 
00111   // This will copy the fastjet constituents to the jet itself.
00112   virtual void copyConstituents(const std::vector<fastjet::PseudoJet>&fjConstituents,
00113                                 reco::Jet* jet);
00114 
00115   // This will run the actual algorithm. This method is pure virtual and
00116   // has no default. 
00117   virtual void runAlgorithm( edm::Event& iEvent, const edm::EventSetup& iSetup) = 0;
00118 
00119   // Do the offset correction. 
00120   // Only runs if "doPUOffsetCorrection_" is true.  
00121   void offsetCorrectJets(std::vector<fastjet::PseudoJet> & orphanInput);
00122 
00123   // This will write the jets to the event. 
00124   // The default is to write out the single jet collection in the default "produces"
00125   // statement. 
00126   // This is a function template that can be called for the six types
00127   // CaloJet, PFJet, GenJet, TrackJet, PFClusterJet, BasicJet. 
00128   // This is not suitable for compound jets. 
00129   // Note: The "output" method is virtual and can be overriden.
00130   // The default behavior is to call the function template "writeJets". 
00131   virtual void output(  edm::Event & iEvent, edm::EventSetup const& iSetup );
00132   template< typename T >
00133   void writeJets( edm::Event & iEvent, edm::EventSetup const& iSetup );
00134   
00135   // This method copies the constituents from the fjConstituents method
00136   // to an output of CandidatePtr's. 
00137   virtual std::vector<reco::CandidatePtr>
00138     getConstituents(const std::vector<fastjet::PseudoJet>&fjConstituents);
00139   
00140   //
00141   // member data
00142   //
00143 protected:
00144   std::string           moduleLabel_;               // label for this module
00145   edm::InputTag         src_;                       // input constituent source
00146   edm::InputTag         srcPVs_;                    // primary vertex source
00147   std::string           jetType_;                   // type of jet (Calo,PF,Basic,Gen)
00148   std::string           jetAlgorithm_;              // the jet algorithm to use
00149   double                rParam_;                    // the R parameter to use
00150   double                inputEtMin_;                // minimum et of input constituents
00151   double                inputEMin_;                 // minimum e of input constituents
00152   double                jetPtMin_;                  // minimum jet pt
00153   bool                  doPVCorrection_;            // correct to primary vertex? 
00154 
00155   // for restricting inputs due to processing time
00156   bool                  restrictInputs_;            // restrict inputs to first "maxInputs" inputs.
00157   unsigned int          maxInputs_;                 // maximum number of inputs. 
00158 
00159   // for fastjet jet area calculation
00160   bool                  doAreaFastjet_;             // calculate area w/ fastjet?
00161   bool                  doAreaDiskApprox_;          // calculate area w/ disk approximation (only makes sense for anti-KT)?
00162   // for fastjet rho calculation
00163   bool                  doRhoFastjet_;              // calculate rho w/ fastjet?
00164   bool                  doFastJetNonUniform_;       // choice of eta-dependent PU calculation
00165   double                voronoiRfact_;              // negative to calculate rho using active area (ghosts); otherwise calculates Voronoi area with this effective scale factor
00166   
00167   // for pileup offset correction
00168   bool                  doPUOffsetCorr_;            // add the pileup calculation from offset correction? 
00169   std::string           puSubtractorName_;
00170 
00171 
00172   std::vector<edm::Ptr<reco::Candidate> > inputs_;  // input candidates [View, PtrVector and CandCollection have limitations]
00173   reco::Particle::Point           vertex_;          // Primary vertex 
00174   ClusterSequencePtr              fjClusterSeq_;    // fastjet cluster sequence
00175   JetDefPtr                       fjJetDefinition_; // fastjet jet definition
00176   PluginPtr                       fjPlugin_;        // fastjet plugin
00177   ActiveAreaSpecPtr               fjActiveArea_;    // fastjet active area definition
00178   RangeDefPtr                     fjRangeDef_;      // range definition
00179   std::vector<fastjet::PseudoJet> fjInputs_;        // fastjet inputs
00180   std::vector<fastjet::PseudoJet> fjJets_;          // fastjet jets
00181 
00182   // Parameters of the eta-dependent rho calculation
00183   std::vector<double>             puCenters_;
00184   double                          puWidth_;
00185   unsigned int                    nExclude_;
00186 
00187   std::string                     jetCollInstanceName_;       // instance name for output jet collection
00188   boost::shared_ptr<PileUpSubtractor>  subtractor_;
00189 
00190   bool                            useDeterministicSeed_; // If desired, use a deterministic seed to fastjet
00191   unsigned int                    minSeed_;              // minimum seed to use, useful for MC generation
00192 
00193 private:
00194   std::auto_ptr<AnomalousTower>   anomalousTowerDef_;  // anomalous tower definition
00195 };
00196 
00197 
00198 
00199 
00200 
00201 #endif