Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-23 22:53:16

0001 #ifndef RecoJets_JetProducers_plugins_VirtualJetProducer_h
0002 #define RecoJets_JetProducers_plugins_VirtualJetProducer_h
0003 
0004 #include "RecoJets/JetProducers/interface/JetSpecific.h"
0005 
0006 #include "FWCore/Framework/interface/stream/EDProducer.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0010 #include "DataFormats/Candidate/interface/Candidate.h"
0011 #include "DataFormats/Candidate/interface/CandidateFwd.h"
0012 #include "DataFormats/JetReco/interface/Jet.h"
0013 #include "DataFormats/JetReco/interface/CaloJet.h"
0014 #include "DataFormats/JetReco/interface/PFJet.h"
0015 #include "DataFormats/JetReco/interface/BasicJet.h"
0016 #include "DataFormats/JetReco/interface/GenJet.h"
0017 #include "DataFormats/PatCandidates/interface/PackedCandidate.h"
0018 #include "DataFormats/PatCandidates/interface/PackedGenParticle.h"
0019 
0020 #include "DataFormats/JetReco/interface/BasicJetCollection.h"
0021 
0022 #include "RecoJets/JetProducers/interface/PileUpSubtractor.h"
0023 #include "RecoJets/JetProducers/interface/AnomalousTower.h"
0024 
0025 #include "fastjet/JetDefinition.hh"
0026 #include "fastjet/ClusterSequence.hh"
0027 #include "fastjet/ClusterSequenceArea.hh"
0028 #include "fastjet/PseudoJet.hh"
0029 #include "fastjet/GhostedAreaSpec.hh"
0030 #include "fastjet/Selector.hh"
0031 
0032 #include <memory>
0033 #include <vector>
0034 
0035 class CaloGeometryRecord;
0036 class HcalRecNumberingRecord;
0037 
0038 class dso_hidden VirtualJetProducer : public edm::stream::EDProducer<> {
0039 protected:
0040   //
0041   // typedefs & structs
0042   //
0043   struct JetType {
0044     enum Type {
0045       BasicJet,
0046       GenJet,
0047       CaloJet,
0048       PFJet,
0049       TrackJet,
0050       PFClusterJet,
0051       LastJetType  // no real type, technical
0052     };
0053     static const char* const names[];
0054     static Type byName(const std::string& name);
0055   };
0056 
0057   JetType::Type jetTypeE;
0058 
0059   inline bool makeCaloJet(const JetType::Type& fTag) { return fTag == JetType::CaloJet; }
0060   inline bool makePFJet(const JetType::Type& fTag) { return fTag == JetType::PFJet; }
0061   inline bool makeGenJet(const JetType::Type& fTag) { return fTag == JetType::GenJet; }
0062   inline bool makeTrackJet(const JetType::Type& fTag) { return fTag == JetType::TrackJet; }
0063   inline bool makePFClusterJet(const JetType::Type& fTag) { return fTag == JetType::PFClusterJet; }
0064   inline bool makeBasicJet(const JetType::Type& fTag) { return fTag == JetType::BasicJet; }
0065 
0066   //
0067   // construction/destruction
0068   //
0069 public:
0070   explicit VirtualJetProducer(const edm::ParameterSet& iConfig);
0071   ~VirtualJetProducer() override;
0072   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0073   static void fillDescriptionsFromVirtualJetProducer(edm::ParameterSetDescription& desc);
0074 
0075   // typedefs
0076   typedef std::shared_ptr<fastjet::ClusterSequence> ClusterSequencePtr;
0077   typedef std::shared_ptr<fastjet::JetDefinition::Plugin> PluginPtr;
0078   typedef std::shared_ptr<fastjet::JetDefinition> JetDefPtr;
0079   typedef std::shared_ptr<fastjet::GhostedAreaSpec> ActiveAreaSpecPtr;
0080   typedef std::shared_ptr<fastjet::AreaDefinition> AreaDefinitionPtr;
0081   typedef std::shared_ptr<fastjet::Selector> SelectorPtr;
0082 
0083   //
0084   // member functions
0085   //
0086 public:
0087   void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
0088   std::string jetType() const { return jetType_; }
0089 
0090 protected:
0091   //
0092   // Internal methods for jet production.
0093   // The user can either use the defaults, or override all of these methods.
0094   //
0095 
0096   // This method creates the "produces" statement in the constructor.
0097   // The default is to produce a single jet collection as per the user's request
0098   // (Calo,PF,Basic, or Gen).
0099   virtual void makeProduces(std::string s, std::string tag = "");
0100 
0101   // This method inputs the constituents from "inputs" and modifies
0102   // fjInputs.
0103   virtual void inputTowers();
0104 
0105   // This checks if the tower is anomalous (if a calo tower).
0106   virtual bool isAnomalousTower(reco::CandidatePtr input);
0107 
0108   // This will copy the fastjet constituents to the jet itself.
0109   virtual void copyConstituents(const std::vector<fastjet::PseudoJet>& fjConstituents, reco::Jet* jet);
0110 
0111   // This will run the actual algorithm. This method is pure virtual and
0112   // has no default.
0113   virtual void runAlgorithm(edm::Event& iEvent, const edm::EventSetup& iSetup) = 0;
0114 
0115   // This will allow making the HTTTopJetTagInfoCollection
0116   virtual void addHTTTopJetTagInfoCollection(edm::Event& iEvent,
0117                                              const edm::EventSetup& iSetup,
0118                                              edm::OrphanHandle<reco::BasicJetCollection>& oh){};
0119 
0120   // Do the offset correction.
0121   // Only runs if "doPUOffsetCorrection_" is true.
0122   void offsetCorrectJets(std::vector<fastjet::PseudoJet>& orphanInput);
0123 
0124   // This will write the jets to the event.
0125   // The default is to write out the single jet collection in the default "produces"
0126   // statement.
0127   // This is a function template that can be called for the six types
0128   // CaloJet, PFJet, GenJet, TrackJet, PFClusterJet, BasicJet.
0129   // This is not suitable for compound jets.
0130   // Note: The "output" method is virtual and can be overriden.
0131   // The default behavior is to call the function template "writeJets".
0132   virtual void output(edm::Event& iEvent, edm::EventSetup const& iSetup);
0133   template <typename T>
0134   void writeJets(edm::Event& iEvent, edm::EventSetup const& iSetup);
0135 
0136   template <typename T>
0137   void writeCompoundJets(edm::Event& iEvent, edm::EventSetup const& iSetup);
0138 
0139   template <typename T>
0140   void writeJetsWithConstituents(edm::Event& iEvent, edm::EventSetup const& iSetup);
0141 
0142   // This method copies the constituents from the fjConstituents method
0143   // to an output of CandidatePtr's.
0144   virtual std::vector<reco::CandidatePtr> getConstituents(const std::vector<fastjet::PseudoJet>& fjConstituents);
0145 
0146   //These are only valid if we are dealing with CaloJets
0147   CaloGeometry const& getGeometry(edm::EventSetup const&) const;
0148   HcalTopology const& getTopology(edm::EventSetup const&) const;
0149 
0150   //
0151   // member data
0152   //
0153 protected:
0154   std::string moduleLabel_;   // label for this module
0155   edm::InputTag src_;         // input constituent source
0156   edm::InputTag srcPVs_;      // primary vertex source
0157   std::string jetType_;       // type of jet (Calo,PF,Basic,Gen)
0158   std::string jetAlgorithm_;  // the jet algorithm to use
0159   double rParam_;             // the R parameter to use
0160   double inputEtMin_;         // minimum et of input constituents
0161   double inputEMin_;          // minimum e of input constituents
0162   double jetPtMin_;           // minimum jet pt
0163   bool doPVCorrection_;       // correct to primary vertex?
0164 
0165   // for restricting inputs due to processing time
0166   bool restrictInputs_;     // restrict inputs to first "maxInputs" inputs.
0167   unsigned int maxInputs_;  // maximum number of inputs.
0168 
0169   // for fastjet jet area calculation
0170   bool doAreaFastjet_;      // calculate area w/ fastjet?
0171   bool useExplicitGhosts_;  // use explicit ghosts in fastjet clustering sequence
0172   bool doAreaDiskApprox_;   // calculate area w/ disk approximation (only makes sense for anti-KT)?
0173   // for fastjet rho calculation
0174   bool doRhoFastjet_;         // calculate rho w/ fastjet?
0175   bool doFastJetNonUniform_;  // choice of eta-dependent PU calculation
0176   double
0177       voronoiRfact_;  // negative to calculate rho using active area (ghosts); otherwise calculates Voronoi area with this effective scale factor
0178 
0179   double
0180       rhoEtaMax_;  // Eta range of jets to be considered for Rho calculation; Should be at most (jet acceptance - jet radius)
0181   double ghostEtaMax_;     // default Ghost_EtaMax should be 5
0182   int activeAreaRepeats_;  // default Active_Area_Repeats 1
0183   double ghostArea_;       // default GhostArea 0.01
0184 
0185   // for pileup offset correction
0186   bool doPUOffsetCorr_;  // add the pileup calculation from offset correction?
0187   std::string puSubtractorName_;
0188 
0189   std::vector<edm::Ptr<reco::Candidate>>
0190       inputs_;                                // input candidates [View, PtrVector and CandCollection have limitations]
0191   reco::Particle::Point vertex_;              // Primary vertex
0192   ClusterSequencePtr fjClusterSeq_;           // fastjet cluster sequence
0193   JetDefPtr fjJetDefinition_;                 // fastjet jet definition
0194   PluginPtr fjPlugin_;                        // fastjet plugin
0195   ActiveAreaSpecPtr fjActiveArea_;            // fastjet active area definition
0196   AreaDefinitionPtr fjAreaDefinition_;        // fastjet area definition
0197   SelectorPtr fjSelector_;                    // selector for range definition
0198   std::vector<fastjet::PseudoJet> fjInputs_;  // fastjet inputs
0199   std::vector<fastjet::PseudoJet> fjJets_;    // fastjet jets
0200 
0201   // Parameters of the eta-dependent rho calculation
0202   std::vector<double> puCenters_;
0203   double puWidth_;
0204   unsigned int nExclude_;
0205 
0206   std::string jetCollInstanceName_;  // instance name for output jet collection
0207   bool writeCompound_;               // write compound jets (i.e. jets of jets)
0208   bool writeJetsWithConst_;          // write jets with constituents
0209   std::shared_ptr<PileUpSubtractor> subtractor_;
0210 
0211   bool useDeterministicSeed_;  // If desired, use a deterministic seed to fastjet
0212   unsigned int minSeed_;       // minimum seed to use, useful for MC generation
0213 
0214   int verbosity_;                       // flag to enable/disable debug output
0215   bool fromHTTTopJetProducer_ = false;  // for running the v2.0 HEPTopTagger
0216   bool applyWeight_;              // Apply weights stored in a value map or inside PackedCandidate (e.g. from PUPPI)
0217   edm::ValueMap<float> weights_;  // weights per particle (e.g. from PUPPI)
0218 
0219 private:
0220   //These are only initialized if we are dealing with CaloJets
0221   edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geometry_token_;
0222   edm::ESGetToken<HcalTopology, HcalRecNumberingRecord> topology_token_;
0223 
0224   std::unique_ptr<AnomalousTower> anomalousTowerDef_;  // anomalous tower definition
0225 
0226   // tokens for the data access
0227   edm::EDGetTokenT<reco::CandidateView> input_candidateview_token_;
0228   edm::EDGetTokenT<std::vector<edm::FwdPtr<reco::PFCandidate>>> input_candidatefwdptr_token_;
0229   edm::EDGetTokenT<std::vector<edm::FwdPtr<pat::PackedCandidate>>> input_packedcandidatefwdptr_token_;
0230   edm::EDGetTokenT<std::vector<edm::FwdPtr<reco::GenParticle>>> input_gencandidatefwdptr_token_;
0231   edm::EDGetTokenT<std::vector<edm::FwdPtr<pat::PackedGenParticle>>> input_packedgencandidatefwdptr_token_;
0232 
0233 protected:
0234   edm::EDGetTokenT<reco::VertexCollection> input_vertex_token_;
0235   edm::EDGetTokenT<edm::ValueMap<float>> input_weights_token_;
0236 };
0237 
0238 #endif