Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-10 02:51:23

0001 #ifndef RecoTauTag_RecoTau_RecoTauBuilderPlugin_h
0002 #define RecoTauTag_RecoTau_RecoTauBuilderPlugin_h
0003 
0004 /*
0005  * RecoTauBuilderPlugins
0006  *
0007  * Author: Evan K. Friis (UC Davis)
0008  *
0009  * Classes for building new and modifying existing PFTaus from PFJets and
0010  * reconstructed PiZeros.
0011  *
0012  * RecoTauBuilderPlugin is the base class for any algorithm that constructs
0013  * taus.  Algorithms should override the abstract function
0014  *
0015  * std::vector<PFTau> operator()(const PFJet&, const
0016  * std::vector<RecoTauPiZero>&) const;
0017  *
0018  * implementing it such that a list of taus a produced for a given jet and its
0019  * associated collection of PiZeros.
0020  *
0021  * RecoTauModifierPlugin takes an input tau and modifies it.
0022  *
0023  * Both plugins inherit from RecoTauEventHolderPlugin, which provides the
0024  * methods
0025  *
0026  *    const edm::Event* evt() const; const edm::EventSetup* evtSetup()
0027  *
0028  * to retrieve the current event if necessary.
0029  *
0030  *
0031  */
0032 
0033 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0034 #include "FWCore/Framework/interface/ConsumesCollector.h"
0035 
0036 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0037 #include "DataFormats/JetReco/interface/JetCollection.h"
0038 #include "DataFormats/TauReco/interface/PFTau.h"
0039 #include "DataFormats/TauReco/interface/PFRecoTauChargedHadron.h"
0040 #include "DataFormats/TauReco/interface/RecoTauPiZero.h"
0041 #include "RecoTauTag/RecoTau/interface/RecoTauPluginsCommon.h"
0042 #include "RecoTauTag/RecoTau/interface/RecoTauVertexAssociator.h"
0043 
0044 #include "DataFormats/Provenance/interface/EventID.h"
0045 #include "DataFormats/Common/interface/Handle.h"
0046 
0047 #include <vector>
0048 
0049 namespace reco {
0050   namespace tau {
0051 
0052     /* Class that constructs PFTau(s) from a Jet and its associated PiZeros */
0053     class RecoTauBuilderPlugin : public RecoTauEventHolderPlugin {
0054     public:
0055       typedef std::vector<std::unique_ptr<reco::PFTau>> output_type;
0056       typedef output_type return_type;
0057 
0058       explicit RecoTauBuilderPlugin(const edm::ParameterSet& pset, edm::ConsumesCollector&& iC)
0059           : RecoTauEventHolderPlugin(pset),
0060             // The vertex association configuration is specified with the quality cuts.
0061             vertexAssociator_(pset.getParameter<edm::ParameterSet>("qualityCuts"), std::move(iC)) {
0062         pfCandSrc_ = pset.getParameter<edm::InputTag>("pfCandSrc");
0063         pfCand_token = iC.consumes<edm::View<reco::Candidate>>(pfCandSrc_);
0064       };
0065 
0066       ~RecoTauBuilderPlugin() override {}
0067 
0068       /// Construct one or more PFTaus from the a PFJet and its asscociated
0069       /// reconstructed PiZeros and regional extras i.e. objects in a 0.8 cone
0070       /// about the jet
0071       virtual return_type operator()(const reco::JetBaseRef&,
0072                                      const std::vector<reco::PFRecoTauChargedHadron>&,
0073                                      const std::vector<reco::RecoTauPiZero>&,
0074                                      const std::vector<CandidatePtr>&) const = 0;
0075 
0076       /// Hack to be able to convert Ptrs to Refs
0077       const edm::Handle<edm::View<reco::Candidate>>& getPFCands() const { return pfCands_; };
0078 
0079       /// Get primary vertex associated to this jet
0080       reco::VertexRef primaryVertex(const reco::JetBaseRef& jet) const {
0081         return vertexAssociator_.associatedVertex(*jet);
0082       }
0083       /// Get primary vertex associated to this tau
0084       reco::VertexRef primaryVertex(const reco::PFTau& tau, bool useJet = false) const {
0085         return vertexAssociator_.associatedVertex(tau, useJet);
0086       }
0087 
0088       // Hook called by base class at the beginning of each event. Used to update
0089       // handle to PFCandidates
0090       void beginEvent() override;
0091 
0092     private:
0093       edm::InputTag pfCandSrc_;
0094       // Handle to PFCandidates needed to build Refs
0095       edm::Handle<edm::View<reco::Candidate>> pfCands_;
0096       reco::tau::RecoTauVertexAssociator vertexAssociator_;
0097       edm::EDGetTokenT<edm::View<reco::Candidate>> pfCand_token;
0098     };
0099 
0100     /* Class that updates a PFTau's members (i.e. electron variables) */
0101     class RecoTauModifierPlugin : public RecoTauEventHolderPlugin {
0102     public:
0103       explicit RecoTauModifierPlugin(const edm::ParameterSet& pset, edm::ConsumesCollector&& iC)
0104           : RecoTauEventHolderPlugin(pset) {}
0105       ~RecoTauModifierPlugin() override {}
0106       // Modify an existing PFTau (i.e. add electron rejection, etc)
0107       virtual void operator()(PFTau&) const = 0;
0108       void beginEvent() override {}
0109       virtual void endEvent() {}
0110     };
0111 
0112     /* Class that returns a double value indicating the quality of a given tau */
0113     class RecoTauCleanerPlugin : public RecoTauEventHolderPlugin {
0114     public:
0115       explicit RecoTauCleanerPlugin(const edm::ParameterSet& pset, edm::ConsumesCollector&& iC)
0116           : RecoTauEventHolderPlugin(pset) {}
0117       ~RecoTauCleanerPlugin() override {}
0118       // Modify an existing PFTau (i.e. add electron rejection, etc)
0119       virtual double operator()(const PFTauRef&) const = 0;
0120       void beginEvent() override {}
0121     };
0122   }  // namespace tau
0123 }  // namespace reco
0124 
0125 #include "FWCore/PluginManager/interface/PluginFactory.h"
0126 
0127 typedef edmplugin::PluginFactory<reco::tau::RecoTauBuilderPlugin*(const edm::ParameterSet&, edm::ConsumesCollector&& iC)>
0128     RecoTauBuilderPluginFactory;
0129 typedef edmplugin::PluginFactory<reco::tau::RecoTauModifierPlugin*(const edm::ParameterSet&,
0130                                                                    edm::ConsumesCollector&& iC)>
0131     RecoTauModifierPluginFactory;
0132 typedef edmplugin::PluginFactory<reco::tau::RecoTauCleanerPlugin*(const edm::ParameterSet&, edm::ConsumesCollector&& iC)>
0133     RecoTauCleanerPluginFactory;
0134 
0135 #endif