CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_4/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/GhostedAreaSpec.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::GhostedAreaSpec>        ActiveAreaSpecPtr;
00083   typedef boost::shared_ptr<fastjet::AreaDefinition>         AreaDefinitionPtr;
00084   typedef boost::shared_ptr<fastjet::RangeDefinition>        RangeDefPtr;
00085   
00086   //
00087   // member functions
00088   //
00089 public:
00090   virtual void  produce(edm::Event& iEvent, const edm::EventSetup& iSetup);
00091   std::string   jetType() const { return jetType_; }
00092   
00093 protected:
00094 
00095   //
00096   // Internal methods for jet production.
00097   // The user can either use the defaults, or override all of these methods. 
00098   //
00099 
00100   // This method creates the "produces" statement in the constructor.
00101   // The default is to produce a single jet collection as per the user's request
00102   // (Calo,PF,Basic, or Gen). 
00103   virtual void makeProduces( std::string s, std::string tag = "" );
00104 
00105   // This method inputs the constituents from "inputs" and modifies
00106   // fjInputs. 
00107   virtual void inputTowers();
00108 
00109   // This checks if the tower is anomalous (if a calo tower).
00110   virtual bool isAnomalousTower(reco::CandidatePtr input);
00111 
00112   // This will copy the fastjet constituents to the jet itself.
00113   virtual void copyConstituents(const std::vector<fastjet::PseudoJet>&fjConstituents,
00114                                 reco::Jet* jet);
00115 
00116   // This will run the actual algorithm. This method is pure virtual and
00117   // has no default. 
00118   virtual void runAlgorithm( edm::Event& iEvent, const edm::EventSetup& iSetup) = 0;
00119 
00120   // Do the offset correction. 
00121   // Only runs if "doPUOffsetCorrection_" is true.  
00122   void offsetCorrectJets(std::vector<fastjet::PseudoJet> & orphanInput);
00123 
00124   // This will write the jets to the event. 
00125   // The default is to write out the single jet collection in the default "produces"
00126   // statement. 
00127   // This is a function template that can be called for the six types
00128   // CaloJet, PFJet, GenJet, TrackJet, PFClusterJet, BasicJet. 
00129   // This is not suitable for compound jets. 
00130   // Note: The "output" method is virtual and can be overriden.
00131   // The default behavior is to call the function template "writeJets". 
00132   virtual void output(  edm::Event & iEvent, edm::EventSetup const& iSetup );
00133   template< typename T >
00134   void writeJets( edm::Event & iEvent, edm::EventSetup const& iSetup );
00135   
00136   template< typename T>
00137   void writeCompoundJets(  edm::Event & iEvent, edm::EventSetup const& iSetup);
00138 
00139 
00140   // This method copies the constituents from the fjConstituents method
00141   // to an output of CandidatePtr's. 
00142   virtual std::vector<reco::CandidatePtr>
00143     getConstituents(const std::vector<fastjet::PseudoJet>&fjConstituents);
00144   
00145   //
00146   // member data
00147   //
00148 protected:
00149   std::string           moduleLabel_;               // label for this module
00150   edm::InputTag         src_;                       // input constituent source
00151   edm::InputTag         srcPVs_;                    // primary vertex source
00152   std::string           jetType_;                   // type of jet (Calo,PF,Basic,Gen)
00153   std::string           jetAlgorithm_;              // the jet algorithm to use
00154   double                rParam_;                    // the R parameter to use
00155   double                inputEtMin_;                // minimum et of input constituents
00156   double                inputEMin_;                 // minimum e of input constituents
00157   double                jetPtMin_;                  // minimum jet pt
00158   bool                  doPVCorrection_;            // correct to primary vertex? 
00159 
00160   // for restricting inputs due to processing time
00161   bool                  restrictInputs_;            // restrict inputs to first "maxInputs" inputs.
00162   unsigned int          maxInputs_;                 // maximum number of inputs. 
00163 
00164   // for fastjet jet area calculation
00165   bool                  doAreaFastjet_;             // calculate area w/ fastjet?
00166   bool                  useExplicitGhosts_;         // use explicit ghosts in fastjet clustering sequence
00167   bool                  doAreaDiskApprox_;          // calculate area w/ disk approximation (only makes sense for anti-KT)?
00168   // for fastjet rho calculation
00169   bool                  doRhoFastjet_;              // calculate rho w/ fastjet?
00170   bool                  doFastJetNonUniform_;       // choice of eta-dependent PU calculation
00171   double                voronoiRfact_;              // negative to calculate rho using active area (ghosts); otherwise calculates Voronoi area with this effective scale factor
00172   
00173   // for pileup offset correction
00174   bool                  doPUOffsetCorr_;            // add the pileup calculation from offset correction? 
00175   std::string           puSubtractorName_;
00176 
00177 
00178   std::vector<edm::Ptr<reco::Candidate> > inputs_;  // input candidates [View, PtrVector and CandCollection have limitations]
00179   reco::Particle::Point           vertex_;          // Primary vertex 
00180   ClusterSequencePtr              fjClusterSeq_;    // fastjet cluster sequence
00181   JetDefPtr                       fjJetDefinition_; // fastjet jet definition
00182   PluginPtr                       fjPlugin_;        // fastjet plugin
00183   ActiveAreaSpecPtr               fjActiveArea_;    // fastjet active area definition
00184   AreaDefinitionPtr               fjAreaDefinition_;// fastjet area definition
00185   RangeDefPtr                     fjRangeDef_;      // range definition
00186   std::vector<fastjet::PseudoJet> fjInputs_;        // fastjet inputs
00187   std::vector<fastjet::PseudoJet> fjJets_;          // fastjet jets
00188 
00189   // Parameters of the eta-dependent rho calculation
00190   std::vector<double>             puCenters_;
00191   double                          puWidth_;
00192   unsigned int                    nExclude_;
00193 
00194   std::string                     jetCollInstanceName_;       // instance name for output jet collection
00195   bool                            writeCompound_;    // write compound jets (i.e. jets of jets)
00196   boost::shared_ptr<PileUpSubtractor>  subtractor_;
00197 
00198   bool                            useDeterministicSeed_; // If desired, use a deterministic seed to fastjet
00199   unsigned int                    minSeed_;              // minimum seed to use, useful for MC generation
00200 
00201 private:
00202   std::auto_ptr<AnomalousTower>   anomalousTowerDef_;  // anomalous tower definition
00203 };
00204 
00205 
00206 
00207 
00208 
00209 #endif