diff --git a/RecoBTag/PixelCluster/plugins/PixelClusterTagInfoProducer.cc b/RecoBTag/PixelCluster/plugins/PixelClusterTagInfoProducer.cc index 1f0c291c9a699..b05d51ecb0dde 100644 --- a/RecoBTag/PixelCluster/plugins/PixelClusterTagInfoProducer.cc +++ b/RecoBTag/PixelCluster/plugins/PixelClusterTagInfoProducer.cc @@ -37,6 +37,7 @@ #include "FWCore/Framework/interface/ESHandle.h" #include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Utilities/interface/ESGetToken.h" // TagInfo #include "DataFormats/BTauReco/interface/PixelClusterTagInfo.h" @@ -79,6 +80,8 @@ class PixelClusterTagInfoProducer : public edm::global::EDProducer<> { const edm::EDGetTokenT > m_jets; const edm::EDGetTokenT m_vertices; const edm::EDGetTokenT > m_pixelhit; + const edm::ESGetToken m_geomToken; + const edm::ESGetToken m_topoToken; const bool m_isPhase1; const bool m_addFPIX; const int m_minADC; @@ -92,6 +95,8 @@ PixelClusterTagInfoProducer::PixelClusterTagInfoProducer(const edm::ParameterSet : m_jets(consumes >(iConfig.getParameter("jets"))), m_vertices(consumes(iConfig.getParameter("vertices"))), m_pixelhit(consumes >(iConfig.getParameter("pixelhit"))), + m_geomToken(esConsumes()), + m_topoToken(esConsumes()), m_isPhase1(iConfig.getParameter("isPhase1")), m_addFPIX(iConfig.getParameter("addForward")), m_minADC(iConfig.getParameter("minAdcCount")), @@ -140,14 +145,10 @@ void PixelClusterTagInfoProducer::produce(edm::StreamID iID, edm::Event& iEvent, const edmNew::DetSetVector& collectionClusters(*collectionHandle); // Open Geometry - edm::ESHandle geom; - iSetup.get().get(geom); - const TrackerGeometry& theTracker(*geom); + const TrackerGeometry& theTracker = iSetup.getData(m_geomToken); // Retrieve tracker topology from geometry - edm::ESHandle tTopoH; - iSetup.get().get(tTopoH); - const TrackerTopology* tTopo = tTopoH.product(); + const TrackerTopology* tTopo = &iSetup.getData(m_topoToken); std::vector clusters; diff --git a/RecoBTag/SoftLepton/plugins/SoftLepton.cc b/RecoBTag/SoftLepton/plugins/SoftLepton.cc index 67a7c3a216a48..09705ed584dc0 100644 --- a/RecoBTag/SoftLepton/plugins/SoftLepton.cc +++ b/RecoBTag/SoftLepton/plugins/SoftLepton.cc @@ -8,6 +8,7 @@ Description: CMSSW EDProducer for soft lepton b tagging. Implementation: + The actual tagging is performed by SoftLeptonAlgorithm. */ // Original Author: fwyzard @@ -17,10 +18,37 @@ #include #include #include +#include + +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/global/EDProducer.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" +#include "DataFormats/Common/interface/RefToBase.h" +#include "DataFormats/Math/interface/Vector3D.h" +#include "DataFormats/GeometryVector/interface/GlobalVector.h" +#include "DataFormats/JetReco/interface/Jet.h" +#include "DataFormats/JetReco/interface/JetTracksAssociation.h" +#include "DataFormats/VertexReco/interface/VertexFwd.h" +#include "DataFormats/VertexReco/interface/Vertex.h" +#include "DataFormats/Common/interface/ValueMap.h" +#include "DataFormats/EgammaCandidates/interface/GsfElectron.h" +#include "DataFormats/EgammaCandidates/interface/Electron.h" +#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" +#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" +#include "DataFormats/TrackReco/interface/Track.h" +#include "DataFormats/MuonReco/interface/Muon.h" +#include "DataFormats/MuonReco/interface/MuonSelectors.h" +#include "DataFormats/BTauReco/interface/SoftLeptonTagInfo.h" +#include "TrackingTools/Records/interface/TransientTrackRecord.h" #include "FWCore/Utilities/interface/InputTag.h" #include "FWCore/ParameterSet/interface/ParameterSetDescription.h" +#include "FWCore/Framework/interface/ModuleFactory.h" +#include "FWCore/Framework/interface/MakerMacros.h" + // ROOT::Math vectors (aka math::XYZVector) #include "DataFormats/Math/interface/LorentzVector.h" #include "Math/GenVector/PxPyPzM4D.h" @@ -33,7 +61,74 @@ #include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h" #include "TrackingTools/Records/interface/TransientTrackRecord.h" #include "TrackingTools/IPTools/interface/IPTools.h" -#include "SoftLepton.h" + +class SoftLepton : public edm::global::EDProducer<> { +public: + explicit SoftLepton(const edm::ParameterSet &iConfig); + + static void fillDescriptions(edm::ConfigurationDescriptions &descriptions); + + struct TrackCompare { + inline bool operator()(const edm::RefToBase &t1, const edm::RefToBase &t2) const { + return t1.key() < t2.key(); + } + }; + + using LeptonIds = std::map; + using Leptons = std::map, LeptonIds, TrackCompare>; + + // generic interface, using a TrackRefVector for lepton tracks + reco::SoftLeptonTagInfo tag(const edm::RefToBase &jet, + const reco::TrackRefVector &tracks, + const Leptons &leptons, + const reco::Vertex &primaryVertex, + const TransientTrackBuilder &builder) const; + +protected: + // generic interface, using a TrackRefVector for lepton tracks + + GlobalVector refineJetAxis(const edm::RefToBase &jet, + const reco::TrackRefVector &tracks, + const edm::RefToBase &exclude = edm::RefToBase()) const; + + static double relativeEta(const math::XYZVector &vector, const math::XYZVector &axis); + + static double boostedPPar(const math::XYZVector &vector, const math::XYZVector &axis); + +private: + void produce(edm::StreamID, edm::Event &event, const edm::EventSetup &setup) const final; + + // configuration + const edm::InputTag m_jets; + const edm::EDGetTokenT token_jtas; + const edm::EDGetTokenT > token_jets; + const edm::EDGetTokenT token_primaryVertex; + const edm::InputTag m_leptons; + const edm::EDGetTokenT > token_gsfElectrons; + const edm::EDGetTokenT > token_electrons; + const edm::EDGetTokenT token_pfElectrons; + const edm::EDGetTokenT > token_muons; + const edm::EDGetTokenT > token_tracks; + const edm::InputTag m_leptonCands; + const edm::EDGetTokenT > token_leptonCands; + const edm::InputTag m_leptonId; + const edm::EDGetTokenT > token_leptonId; + + // service used to make transient tracks from tracks + const edm::ESGetToken token_builder; + + const edm::EDPutTokenT token_put; + // algorithm configuration + const unsigned int m_refineJetAxis; + const double m_deltaRCut; + const double m_chi2Cut; + + // specific for reco::Muons + const muon::SelectionType m_muonSelection; + + // nominal beam spot position + static const reco::Vertex s_nominalBeamSpot; +}; enum AxisType { AXIS_CALORIMETRIC = 0, // use the calorimietric jet axis @@ -69,39 +164,30 @@ const reco::Vertex SoftLepton::s_nominalBeamSpot( // ------------ c'tor -------------------------------------------------------------------- SoftLepton::SoftLepton(const edm::ParameterSet &iConfig) : m_jets(iConfig.getParameter("jets")), - token_jtas(mayConsume(iConfig.getParameter("jets"))), - token_jets(mayConsume >(iConfig.getParameter("jets"))), + token_jtas(mayConsume(m_jets)), + token_jets(mayConsume >(m_jets)), token_primaryVertex(consumes(iConfig.getParameter("primaryVertex"))), m_leptons(iConfig.getParameter("leptons")), - token_gsfElectrons(mayConsume(iConfig.getParameter("leptons"))), - token_electrons(mayConsume(iConfig.getParameter("leptons"))), - token_pfElectrons(mayConsume(iConfig.getParameter("leptons"))), - token_muons(mayConsume(iConfig.getParameter("leptons"))), - token_tracks(mayConsume >(iConfig.getParameter("leptons"))), - m_leptonCands(iConfig.exists("leptonCands") ? iConfig.getParameter("leptonCands") - : edm::InputTag()), - token_leptonCands(mayConsume >( - iConfig.exists("leptonCands") ? iConfig.getParameter("leptonCands") : edm::InputTag())), - m_leptonId(iConfig.exists("leptonId") ? iConfig.getParameter("leptonId") : edm::InputTag()), - token_leptonId(mayConsume >( - iConfig.exists("leptonId") ? iConfig.getParameter("leptonId") : edm::InputTag())), - m_transientTrackBuilder(nullptr), + token_gsfElectrons(mayConsume(m_leptons)), + token_electrons(mayConsume(m_leptons)), + token_pfElectrons(mayConsume(m_leptons)), + token_muons(mayConsume(m_leptons)), + token_tracks(mayConsume >(m_leptons)), + m_leptonCands(iConfig.getParameter("leptonCands")), + token_leptonCands(mayConsume >(m_leptonCands)), + m_leptonId(iConfig.getParameter("leptonId")), + token_leptonId(mayConsume >(m_leptonId)), + token_builder(esConsumes(edm::ESInputTag("", "TransientTrackBuilder"))), + token_put(produces()), m_refineJetAxis(iConfig.getParameter("refineJetAxis")), m_deltaRCut(iConfig.getParameter("leptonDeltaRCut")), m_chi2Cut(iConfig.getParameter("leptonChi2Cut")), - m_muonSelection((muon::SelectionType)iConfig.getParameter("muonSelection")) { - produces(); -} - -// ------------ d'tor -------------------------------------------------------------------- -SoftLepton::~SoftLepton(void) {} + m_muonSelection((muon::SelectionType)iConfig.getParameter("muonSelection")) {} // ------------ method called once per event during the event loop ----------------------- -void SoftLepton::produce(edm::Event &event, const edm::EventSetup &setup) { +void SoftLepton::produce(edm::StreamID, edm::Event &event, const edm::EventSetup &setup) const { // grab a TransientTrack helper from the Event Setup - edm::ESHandle builder; - setup.get().get("TransientTrackBuilder", builder); - m_transientTrackBuilder = builder.product(); + auto const &transientTrackBuilder = setup.getData(token_builder); // input objects @@ -112,8 +198,7 @@ void SoftLepton::produce(edm::Event &event, const edm::EventSetup &setup) { do { { // look for a JetTracksAssociationCollection - edm::Handle h_jtas; - event.getByToken(token_jtas, h_jtas); + edm::Handle h_jtas = event.getHandle(token_jtas); if (h_jtas.isValid()) { unsigned int size = h_jtas->size(); jets.resize(size); @@ -127,8 +212,7 @@ void SoftLepton::produce(edm::Event &event, const edm::EventSetup &setup) { } { // else... // look for a View - edm::Handle > h_jets; - event.getByToken(token_jets, h_jets); + edm::Handle > h_jets = event.getHandle(token_jets); if (h_jets.isValid()) { unsigned int size = h_jets->size(); jets.resize(size); @@ -147,8 +231,7 @@ void SoftLepton::produce(edm::Event &event, const edm::EventSetup &setup) { // input primary vetex reco::Vertex vertex; - Handle h_primaryVertex; - event.getByToken(token_primaryVertex, h_primaryVertex); + Handle h_primaryVertex = event.getHandle(token_primaryVertex); if (h_primaryVertex.isValid() and not h_primaryVertex->empty()) vertex = h_primaryVertex->front(); else @@ -161,7 +244,7 @@ void SoftLepton::produce(edm::Event &event, const edm::EventSetup &setup) { Handle > h_leptonCands; bool haveLeptonCands = !(m_leptonCands == edm::InputTag()); if (haveLeptonCands) - event.getByToken(token_leptonCands, h_leptonCands); + h_leptonCands = event.getHandle(token_leptonCands); // try to access the input collection as a collection of GsfElectrons, Muons or Tracks @@ -169,8 +252,7 @@ void SoftLepton::produce(edm::Event &event, const edm::EventSetup &setup) { do { { // look for View - Handle h_electrons; - event.getByToken(token_gsfElectrons, h_electrons); + Handle h_electrons = event.getHandle(token_gsfElectrons); if (h_electrons.isValid()) { leptonId = SoftLeptonProperties::Quality::egammaElectronId; @@ -188,8 +270,7 @@ void SoftLepton::produce(edm::Event &event, const edm::EventSetup &setup) { { // else // look for View // FIXME: is this obsolete? - Handle h_electrons; - event.getByToken(token_electrons, h_electrons); + Handle h_electrons = event.getHandle(token_electrons); if (h_electrons.isValid()) { leptonId = SoftLeptonProperties::Quality::egammaElectronId; for (ElectronView::const_iterator electron = h_electrons->begin(); electron != h_electrons->end(); ++electron) { @@ -204,8 +285,7 @@ void SoftLepton::produce(edm::Event &event, const edm::EventSetup &setup) { { // else // look for PFElectrons // FIXME: is this obsolete? - Handle h_electrons; - event.getByToken(token_pfElectrons, h_electrons); + Handle h_electrons = event.getHandle(token_pfElectrons); if (h_electrons.isValid()) { leptonId = SoftLeptonProperties::Quality::egammaElectronId; for (reco::PFCandidateCollection::const_iterator electron = h_electrons->begin(); @@ -228,8 +308,7 @@ void SoftLepton::produce(edm::Event &event, const edm::EventSetup &setup) { } { // else // look for View - Handle h_muons; - event.getByToken(token_muons, h_muons); + Handle h_muons = event.getHandle(token_muons); if (h_muons.isValid()) { for (MuonView::const_iterator muon = h_muons->begin(); muon != h_muons->end(); ++muon) { // FIXME -> turn this selection into a muonCands input? @@ -254,8 +333,7 @@ void SoftLepton::produce(edm::Event &event, const edm::EventSetup &setup) { } { // else // look for edm::View - Handle > h_tracks; - event.getByToken(token_tracks, h_tracks); + Handle > h_tracks = event.getHandle(token_tracks); if (h_tracks.isValid()) { for (unsigned int i = 0; i < h_tracks->size(); i++) { LeptonIds &id = leptons[h_tracks->refAt(i)]; @@ -273,27 +351,27 @@ void SoftLepton::produce(edm::Event &event, const edm::EventSetup &setup) { } while (false); if (!(m_leptonId == edm::InputTag())) { - Handle > h_leptonId; - event.getByToken(token_leptonId, h_leptonId); + edm::ValueMap const &h_leptonId = event.get(token_leptonId); for (Leptons::iterator lepton = leptons.begin(); lepton != leptons.end(); ++lepton) - lepton->second[leptonId] = (*h_leptonId)[lepton->first]; + lepton->second[leptonId] = h_leptonId[lepton->first]; } // output collections - auto outputCollection = std::make_unique(); + reco::SoftLeptonTagInfoCollection outputCollection; for (unsigned int i = 0; i < jets.size(); ++i) { - reco::SoftLeptonTagInfo result = tag(jets[i], tracks[i], leptons, vertex); - outputCollection->push_back(result); + reco::SoftLeptonTagInfo result = tag(jets[i], tracks[i], leptons, vertex, transientTrackBuilder); + outputCollection.push_back(result); } - event.put(std::move(outputCollection)); + event.emplace(token_put, std::move(outputCollection)); } // --------------------------------------------------------------------------------------- reco::SoftLeptonTagInfo SoftLepton::tag(const edm::RefToBase &jet, const reco::TrackRefVector &tracks, const Leptons &leptons, - const reco::Vertex &primaryVertex) const { + const reco::Vertex &primaryVertex, + const TransientTrackBuilder &transientTrackBuilder) const { reco::SoftLeptonTagInfo info; info.setJetRef(jet); @@ -310,7 +388,7 @@ reco::SoftLeptonTagInfo SoftLepton::tag(const edm::RefToBase &jet, reco::SoftLeptonProperties properties; - reco::TransientTrack transientTrack = m_transientTrackBuilder->build(*lepton->first); + reco::TransientTrack transientTrack = transientTrackBuilder.build(*lepton->first); Measurement1D ip2d = IPTools::signedTransverseImpactParameter(transientTrack, jetAxis, primaryVertex).second; Measurement1D ip3d = IPTools::signedImpactParameter3D(transientTrack, jetAxis, primaryVertex).second; properties.sip2dsig = ip2d.significance(); @@ -434,11 +512,13 @@ void SoftLepton::fillDescriptions(edm::ConfigurationDescriptions &descriptions) desc.add("muonSelection", 1); desc.add("leptons", edm::InputTag("muons")); desc.add("primaryVertex", edm::InputTag("offlinePrimaryVertices")); - desc.add("leptonCands", edm::InputTag("")); - desc.add("leptonId", edm::InputTag("")); + desc.add("leptonCands", edm::InputTag()); + desc.add("leptonId", edm::InputTag()); desc.add("refineJetAxis", 0); desc.add("jets", edm::InputTag("ak4PFJetsCHS")); desc.add("leptonDeltaRCut", 0.4); desc.add("leptonChi2Cut", 9999.0); descriptions.addDefault(desc); } + +DEFINE_FWK_MODULE(SoftLepton); diff --git a/RecoBTag/SoftLepton/plugins/SoftLepton.h b/RecoBTag/SoftLepton/plugins/SoftLepton.h deleted file mode 100644 index 245bdfb2e84b0..0000000000000 --- a/RecoBTag/SoftLepton/plugins/SoftLepton.h +++ /dev/null @@ -1,116 +0,0 @@ -#ifndef RecoBTag_SoftLepton_SoftLepton_h -#define RecoBTag_SoftLepton_SoftLepton_h - -// -*- C++ -*- -// -// Package: SoftLepton -// Class: SoftLepton -// -/**\class SoftLepton SoftLepton.h RecoBTag/SoftLepton/plugin/SoftLepton.h - - Description: CMSSW EDProducer wrapper for sot lepton b tagging. - - Implementation: - The actual tagging is performed by SoftLeptonAlgorithm. -*/ -// -// Original Author: fwyzard -// Created: Wed Oct 18 18:02:07 CEST 2006 -// - -// system include files -#include -#include - -// user include files -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/stream/EDProducer.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" -#include "DataFormats/Common/interface/RefToBase.h" -#include "DataFormats/Math/interface/Vector3D.h" -#include "DataFormats/GeometryVector/interface/GlobalVector.h" -#include "DataFormats/JetReco/interface/Jet.h" -#include "DataFormats/JetReco/interface/JetTracksAssociation.h" -#include "DataFormats/VertexReco/interface/VertexFwd.h" -#include "DataFormats/VertexReco/interface/Vertex.h" -#include "DataFormats/Common/interface/ValueMap.h" -#include "DataFormats/EgammaCandidates/interface/GsfElectron.h" -#include "DataFormats/EgammaCandidates/interface/Electron.h" -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" -#include "DataFormats/TrackReco/interface/Track.h" -#include "DataFormats/MuonReco/interface/Muon.h" -#include "DataFormats/MuonReco/interface/MuonSelectors.h" -#include "DataFormats/BTauReco/interface/SoftLeptonTagInfo.h" - -class TransientTrackBuilder; - -class SoftLepton : public edm::stream::EDProducer<> { -public: - explicit SoftLepton(const edm::ParameterSet& iConfig); - ~SoftLepton() override; - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - - struct TrackCompare { - inline bool operator()(const edm::RefToBase& t1, const edm::RefToBase& t2) const { - return t1.key() < t2.key(); - } - }; - - typedef std::map LeptonIds; - typedef std::map, LeptonIds, TrackCompare> Leptons; - - // generic interface, using a TrackRefVector for lepton tracks - reco::SoftLeptonTagInfo tag(const edm::RefToBase& jet, - const reco::TrackRefVector& tracks, - const Leptons& leptons, - const reco::Vertex& primaryVertex) const; - -protected: - // generic interface, using a TrackRefVector for lepton tracks - - GlobalVector refineJetAxis(const edm::RefToBase& jet, - const reco::TrackRefVector& tracks, - const edm::RefToBase& exclude = edm::RefToBase()) const; - - static double relativeEta(const math::XYZVector& vector, const math::XYZVector& axis); - - static double boostedPPar(const math::XYZVector& vector, const math::XYZVector& axis); - -private: - void produce(edm::Event& event, const edm::EventSetup& setup) override; - - // configuration - const edm::InputTag m_jets; - const edm::EDGetTokenT token_jtas; - const edm::EDGetTokenT > token_jets; - const edm::EDGetTokenT token_primaryVertex; - const edm::InputTag m_leptons; - const edm::EDGetTokenT > token_gsfElectrons; - const edm::EDGetTokenT > token_electrons; - const edm::EDGetTokenT token_pfElectrons; - const edm::EDGetTokenT > token_muons; - const edm::EDGetTokenT > token_tracks; - const edm::InputTag m_leptonCands; - const edm::EDGetTokenT > token_leptonCands; - const edm::InputTag m_leptonId; - const edm::EDGetTokenT > token_leptonId; - - // service used to make transient tracks from tracks - const TransientTrackBuilder* m_transientTrackBuilder; - - // algorithm configuration - unsigned int m_refineJetAxis; - double m_deltaRCut; - double m_chi2Cut; - - // specific for reco::Muons - muon::SelectionType m_muonSelection; - - // nominal beam spot position - static const reco::Vertex s_nominalBeamSpot; -}; - -#endif // RecoBTag_SoftLepton_SoftLepton_h diff --git a/RecoBTag/SoftLepton/plugins/SoftPFElectronTagInfoProducer.cc b/RecoBTag/SoftLepton/plugins/SoftPFElectronTagInfoProducer.cc index 940bf0f31eb01..2d173c32e1b35 100644 --- a/RecoBTag/SoftLepton/plugins/SoftPFElectronTagInfoProducer.cc +++ b/RecoBTag/SoftLepton/plugins/SoftPFElectronTagInfoProducer.cc @@ -1,4 +1,5 @@ -#include "RecoBTag/SoftLepton/plugins/SoftPFElectronTagInfoProducer.h" +#include "FWCore/Framework/interface/ModuleFactory.h" +#include "FWCore/Framework/interface/MakerMacros.h" #include "DataFormats/EgammaCandidates/interface/GsfElectron.h" #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h" #include "DataFormats/GsfTrackReco/interface/GsfTrack.h" @@ -15,72 +16,121 @@ #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" #include "DataFormats/BTauReco/interface/SoftLeptonTagInfo.h" +#include "FWCore/Framework/interface/global/EDProducer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "DataFormats/EgammaCandidates/interface/GsfElectron.h" +#include "DataFormats/Common/interface/ValueMap.h" +#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" +#include "DataFormats/JetReco/interface/PFJetCollection.h" + +#include "TrackingTools/TransientTrack/interface/TransientTrack.h" +#include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h" +#include "TrackingTools/Records/interface/TransientTrackRecord.h" + +// Vertex +#include "DataFormats/VertexReco/interface/Vertex.h" +#include "DataFormats/VertexReco/interface/VertexFwd.h" +#include "DataFormats/BTauReco/interface/SoftLeptonTagInfo.h" +#include "DataFormats/PatCandidates/interface/Electron.h" + // Transient Track and IP #include "TrackingTools/TransientTrack/interface/TransientTrack.h" #include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h" #include "TrackingTools/Records/interface/TransientTrackRecord.h" #include "TrackingTools/IPTools/interface/IPTools.h" #include "DataFormats/GeometryVector/interface/GlobalVector.h" -#include #include "CommonTools/Egamma/interface/ConversionTools.h" #include "DataFormats/PatCandidates/interface/Electron.h" -SoftPFElectronTagInfoProducer::SoftPFElectronTagInfoProducer(const edm::ParameterSet& conf) { - token_jets = consumes >(conf.getParameter("jets")); - token_elec = consumes >(conf.getParameter("electrons")); - token_primaryVertex = consumes(conf.getParameter("primaryVertex")); - token_BeamSpot = consumes(edm::InputTag("offlineBeamSpot")); - token_allConversions = consumes(edm::InputTag("allConversions")); - DeltaRElectronJet = conf.getParameter("DeltaRElectronJet"); - MaxSip3Dsig = conf.getParameter("MaxSip3Dsig"); - produces(); +#include +#include + +// SoftPFElectronTagInfoProducer: the SoftPFElectronTagInfoProducer takes +// a PFCandidateCollection as input and produces a RefVector +// to the likely soft electrons in this collection. + +class SoftPFElectronTagInfoProducer : public edm::global::EDProducer<> { +public: + SoftPFElectronTagInfoProducer(const edm::ParameterSet& conf); + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + +private: + void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const final; + static bool isElecClean(edm::Event&, const reco::GsfElectron*); + static float boostedPPar(const math::XYZVector&, const math::XYZVector&); + + // service used to make transient tracks from tracks + const edm::EDGetTokenT token_primaryVertex; + const edm::EDGetTokenT > token_jets; + const edm::EDGetTokenT > token_elec; + const edm::EDGetTokenT token_BeamSpot; + const edm::EDGetTokenT token_allConversions; + const edm::ESGetToken token_builder; + const edm::EDPutTokenT token_put; + const float DeltaRElectronJet, MaxSip3Dsig; +}; + +SoftPFElectronTagInfoProducer::SoftPFElectronTagInfoProducer(const edm::ParameterSet& conf) + : token_primaryVertex(consumes(conf.getParameter("primaryVertex"))), + token_jets(consumes(conf.getParameter("jets"))), + token_elec(consumes(conf.getParameter("electrons"))), + token_BeamSpot(consumes(edm::InputTag("offlineBeamSpot"))), + token_allConversions(consumes(edm::InputTag("allConversions"))), + token_builder(esConsumes(edm::ESInputTag("", "TransientTrackBuilder"))), + token_put(produces()), + DeltaRElectronJet(conf.getParameter("DeltaRElectronJet")), + MaxSip3Dsig(conf.getParameter("MaxSip3Dsig")) {} + +void SoftPFElectronTagInfoProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + desc.add("primaryVertex"); + desc.add("jets"); + desc.add("electrons"); + desc.add("DeltaRElectronJet"); + desc.add("MaxSip3Dsig"); + descriptions.addDefault(desc); } -SoftPFElectronTagInfoProducer::~SoftPFElectronTagInfoProducer() {} +void SoftPFElectronTagInfoProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const { + reco::CandSoftLeptonTagInfoCollection theElecTagInfo; + const auto& transientTrackBuilder = iSetup.getData(token_builder); + + edm::Handle PVCollection = iEvent.getHandle(token_primaryVertex); + if (!PVCollection.isValid()) { + iEvent.emplace(token_put, std::move(theElecTagInfo)); + return; + } + reco::ConversionCollection const& hConversions = iEvent.get(token_allConversions); -void SoftPFElectronTagInfoProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { - auto theElecTagInfo = std::make_unique(); - edm::ESHandle builder; - iSetup.get().get("TransientTrackBuilder", builder); - transientTrackBuilder = builder.product(); + edm::View const& theJetCollection = iEvent.get(token_jets); - edm::Handle PVCollection; - iEvent.getByToken(token_primaryVertex, PVCollection); - if (!PVCollection.isValid()) + edm::View const& theGEDGsfElectronCollection = iEvent.get(token_elec); + + if (PVCollection->empty() and not theJetCollection.empty() and not theGEDGsfElectronCollection.empty()) { + //we would need to access a vertex from the collection but there isn't one. + iEvent.emplace(token_put, std::move(theElecTagInfo)); return; - if (!PVCollection->empty()) { - goodvertex = true; - vertex = &PVCollection->front(); - } else - goodvertex = false; - edm::Handle hConversions; - iEvent.getByToken(token_allConversions, hConversions); - - edm::Handle > theJetCollection; - iEvent.getByToken(token_jets, theJetCollection); - - edm::Handle > theGEDGsfElectronCollection; - iEvent.getByToken(token_elec, theGEDGsfElectronCollection); - - edm::Handle bsHandle; - iEvent.getByToken(token_BeamSpot, bsHandle); - const reco::BeamSpot& beamspot = *bsHandle.product(); - - for (unsigned int i = 0; i < theJetCollection->size(); i++) { - edm::RefToBase jetRef = theJetCollection->refAt(i); + } + + const reco::BeamSpot& beamspot = iEvent.get(token_BeamSpot); + + for (unsigned int i = 0; i < theJetCollection.size(); i++) { + edm::RefToBase jetRef = theJetCollection.refAt(i); reco::CandSoftLeptonTagInfo tagInfo; tagInfo.setJetRef(jetRef); - std::vector Elec; - for (unsigned int ie = 0, ne = theGEDGsfElectronCollection->size(); ie < ne; ++ie) { + for (unsigned int ie = 0, ne = theGEDGsfElectronCollection.size(); ie < ne; ++ie) { //Get the edm::Ptr and the GsfElectron - edm::Ptr lepPtr = theGEDGsfElectronCollection->ptrAt(ie); - const reco::GsfElectron* recoelectron = theGEDGsfElectronCollection->refAt(ie).get(); + edm::Ptr lepPtr = theGEDGsfElectronCollection.ptrAt(ie); + const reco::GsfElectron* recoelectron = theGEDGsfElectronCollection.refAt(ie).get(); const pat::Electron* patelec = dynamic_cast(recoelectron); if (patelec) { if (!patelec->passConversionVeto()) continue; } else { - if (ConversionTools::hasMatchedConversion(*(recoelectron), *hConversions, beamspot.position())) + if (ConversionTools::hasMatchedConversion(*(recoelectron), hConversions, beamspot.position())) continue; } //Make sure that the electron is inside the jet @@ -96,12 +146,13 @@ void SoftPFElectronTagInfoProducer::produce(edm::Event& iEvent, const edm::Event //Compute the TagInfos members math::XYZVector pel = recoelectron->p4().Vect(); math::XYZVector pjet = jetRef->p4().Vect(); - reco::TransientTrack transientTrack = transientTrackBuilder->build(recoelectron->gsfTrack()); + reco::TransientTrack transientTrack = transientTrackBuilder.build(recoelectron->gsfTrack()); + auto const& vertex = PVCollection->front(); Measurement1D ip2d = IPTools::signedTransverseImpactParameter( - transientTrack, GlobalVector(jetRef->px(), jetRef->py(), jetRef->pz()), *vertex) + transientTrack, GlobalVector(jetRef->px(), jetRef->py(), jetRef->pz()), vertex) .second; Measurement1D ip3d = IPTools::signedImpactParameter3D( - transientTrack, GlobalVector(jetRef->px(), jetRef->py(), jetRef->pz()), *vertex) + transientTrack, GlobalVector(jetRef->px(), jetRef->py(), jetRef->pz()), vertex) .second; properties.sip2dsig = ip2d.significance(); properties.sip3dsig = ip3d.significance(); @@ -122,9 +173,9 @@ void SoftPFElectronTagInfoProducer::produce(edm::Event& iEvent, const edm::Event // Fill the TagInfos tagInfo.insert(lepPtr, properties); } - theElecTagInfo->push_back(tagInfo); + theElecTagInfo.push_back(tagInfo); } - iEvent.put(std::move(theElecTagInfo)); + iEvent.emplace(token_put, std::move(theElecTagInfo)); } bool SoftPFElectronTagInfoProducer::isElecClean(edm::Event& iEvent, const reco::GsfElectron* candidate) { @@ -149,3 +200,5 @@ float SoftPFElectronTagInfoProducer::boostedPPar(const math::XYZVector& vector, ROOT::Math::BoostX boost(-jet.Beta()); return boost(lepton).x(); } + +DEFINE_FWK_MODULE(SoftPFElectronTagInfoProducer); diff --git a/RecoBTag/SoftLepton/plugins/SoftPFElectronTagInfoProducer.h b/RecoBTag/SoftLepton/plugins/SoftPFElectronTagInfoProducer.h deleted file mode 100644 index f837f28057683..0000000000000 --- a/RecoBTag/SoftLepton/plugins/SoftPFElectronTagInfoProducer.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef RecoBTag_SoftLepton_SoftPFElectronTagInfoProducer_h -#define RecoBTag_SoftLepton_SoftPFElectronTagInfoProducer_h - -#include - -#include "FWCore/Framework/interface/stream/EDProducer.h" -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/EventSetup.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "DataFormats/EgammaCandidates/interface/GsfElectron.h" -#include "DataFormats/Common/interface/ValueMap.h" -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" -#include "DataFormats/JetReco/interface/PFJetCollection.h" - -#include "TrackingTools/TransientTrack/interface/TransientTrack.h" -#include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h" - -// Vertex -#include "DataFormats/VertexReco/interface/Vertex.h" -#include "DataFormats/VertexReco/interface/VertexFwd.h" -#include "DataFormats/BTauReco/interface/SoftLeptonTagInfo.h" -#include "DataFormats/PatCandidates/interface/Electron.h" -// SoftPFElectronTagInfoProducer: the SoftPFElectronTagInfoProducer takes -// a PFCandidateCollection as input and produces a RefVector -// to the likely soft electrons in this collection. - -class SoftPFElectronTagInfoProducer : public edm::stream::EDProducer<> { -public: - SoftPFElectronTagInfoProducer(const edm::ParameterSet& conf); - ~SoftPFElectronTagInfoProducer() override; - -private: - void produce(edm::Event&, const edm::EventSetup&) override; - bool isElecClean(edm::Event&, const reco::GsfElectron*); - float boostedPPar(const math::XYZVector&, const math::XYZVector&); - - // service used to make transient tracks from tracks - const TransientTrackBuilder* transientTrackBuilder; - edm::EDGetTokenT token_primaryVertex; - edm::EDGetTokenT > token_jets; - edm::EDGetTokenT > token_elec; - edm::EDGetTokenT token_BeamSpot; - edm::EDGetTokenT token_allConversions; - float DeltaRElectronJet, MaxSip3Dsig; - bool goodvertex; - - const reco::Vertex* vertex; -}; - -#endif diff --git a/RecoBTag/SoftLepton/plugins/SoftPFMuonTagInfoProducer.cc b/RecoBTag/SoftLepton/plugins/SoftPFMuonTagInfoProducer.cc index 64bacc10a386a..f81ec88868025 100644 --- a/RecoBTag/SoftLepton/plugins/SoftPFMuonTagInfoProducer.cc +++ b/RecoBTag/SoftLepton/plugins/SoftPFMuonTagInfoProducer.cc @@ -2,7 +2,28 @@ // * Mail: a.zucchetta@cern.ch // * January 16, 2015 -#include "RecoBTag/SoftLepton/plugins/SoftPFMuonTagInfoProducer.h" +#include "FWCore/Framework/interface/ModuleFactory.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/Framework/interface/global/EDProducer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "DataFormats/Common/interface/ValueMap.h" +#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" +#include "DataFormats/JetReco/interface/PFJetCollection.h" +#include "DataFormats/MuonReco/interface/Muon.h" +#include "DataFormats/MuonReco/interface/MuonFwd.h" +#include "DataFormats/MuonReco/interface/MuonSelectors.h" +#include "TrackingTools/TransientTrack/interface/TransientTrack.h" +#include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h" +#include "TrackingTools/Records/interface/TransientTrackRecord.h" +#include "DataFormats/VertexReco/interface/Vertex.h" +#include "DataFormats/VertexReco/interface/VertexFwd.h" + +#include "DataFormats/BTauReco/interface/SoftLeptonTagInfo.h" +#include "DataFormats/BTauReco/interface/CandSoftLeptonTagInfo.h" + #include "DataFormats/GsfTrackReco/interface/GsfTrack.h" #include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h" #include "DataFormats/Math/interface/deltaR.h" @@ -31,45 +52,74 @@ #include "TrackingTools/IPTools/interface/IPTools.h" #include "DataFormats/GeometryVector/interface/GlobalVector.h" #include - -SoftPFMuonTagInfoProducer::SoftPFMuonTagInfoProducer(const edm::ParameterSet& conf) { - jetToken = consumes >(conf.getParameter("jets")); - muonToken = consumes >(conf.getParameter("muons")); - vertexToken = consumes(conf.getParameter("primaryVertex")); - pTcut = conf.getParameter("muonPt"); - SIPsigcut = conf.getParameter("muonSIPsig"); - IPsigcut = conf.getParameter("filterIpsig"); - ratio1cut = conf.getParameter("filterRatio1"); - ratio2cut = conf.getParameter("filterRatio2"); - useFilter = conf.getParameter("filterPromptMuons"); - produces(); +#include + +class SoftPFMuonTagInfoProducer : public edm::global::EDProducer<> { +public: + SoftPFMuonTagInfoProducer(const edm::ParameterSet& conf); + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + +private: + void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const final; + float boostedPPar(const math::XYZVector&, const math::XYZVector&) const; + + const edm::EDGetTokenT > jetToken; + const edm::EDGetTokenT > muonToken; + const edm::EDGetTokenT vertexToken; + const edm::ESGetToken builderToken; + const edm::EDPutTokenT putToken; + const float pTcut, SIPsigcut, IPsigcut, ratio1cut, ratio2cut; + const bool useFilter; +}; + +SoftPFMuonTagInfoProducer::SoftPFMuonTagInfoProducer(const edm::ParameterSet& conf) + : jetToken(consumes(conf.getParameter("jets"))), + muonToken(consumes(conf.getParameter("muons"))), + vertexToken(consumes(conf.getParameter("primaryVertex"))), + builderToken(esConsumes(edm::ESInputTag("", "TransientTrackBuilder"))), + putToken(produces()), + pTcut(conf.getParameter("muonPt")), + SIPsigcut(conf.getParameter("muonSIPsig")), + IPsigcut(conf.getParameter("filterIpsig")), + ratio1cut(conf.getParameter("filterRatio1")), + ratio2cut(conf.getParameter("filterRatio2")), + useFilter(conf.getParameter("filterPromptMuons")) {} + +void SoftPFMuonTagInfoProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + desc.add("jets"); + desc.add("muons"); + desc.add("primaryVertex"); + desc.add("muonPt"); + desc.add("muonSIPsig"); + desc.add("filterIpsig"); + desc.add("filterRatio1"); + desc.add("filterRatio2"); + desc.add("filterPromptMuons"); + descriptions.addDefault(desc); } -SoftPFMuonTagInfoProducer::~SoftPFMuonTagInfoProducer() {} - -void SoftPFMuonTagInfoProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { +void SoftPFMuonTagInfoProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const { // Declare produced collection - auto theMuonTagInfo = std::make_unique(); + reco::CandSoftLeptonTagInfoCollection theMuonTagInfo; // Declare and open Jet collection - edm::Handle > theJetCollection; - iEvent.getByToken(jetToken, theJetCollection); + edm::Handle > theJetCollection = iEvent.getHandle(jetToken); // Declare Muon collection - edm::Handle > theMuonCollection; - iEvent.getByToken(muonToken, theMuonCollection); + edm::Handle > theMuonCollection = iEvent.getHandle(muonToken); // Declare and open Vertex collection - edm::Handle theVertexCollection; - iEvent.getByToken(vertexToken, theVertexCollection); - if (!theVertexCollection.isValid() || theVertexCollection->empty()) + edm::Handle theVertexCollection = iEvent.getHandle(vertexToken); + if (!theVertexCollection.isValid() || theVertexCollection->empty()) { + iEvent.emplace(putToken, std::move(theMuonTagInfo)); return; + } const reco::Vertex* vertex = &theVertexCollection->front(); - // Biult TransientTrackBuilder - edm::ESHandle theTrackBuilder; - iSetup.get().get("TransientTrackBuilder", theTrackBuilder); - const TransientTrackBuilder* transientTrackBuilder = theTrackBuilder.product(); + // Build TransientTrackBuilder + const TransientTrackBuilder& transientTrackBuilder = iSetup.getData(builderToken); // Loop on jets for (unsigned int ij = 0, nj = theJetCollection->size(); ij < nj; ij++) { @@ -116,7 +166,7 @@ void SoftPFMuonTagInfoProducer::produce(edm::Event& iEvent, const edm::EventSetu reco::TrackRef trkRef(muon->innerTrack()); reco::TrackBaseRef trkBaseRef(trkRef); // Build Transient Track - reco::TransientTrack transientTrack = transientTrackBuilder->build(trkRef); + reco::TransientTrack transientTrack = transientTrackBuilder.build(trkRef); // Define jet and muon vectors reco::Candidate::Vector jetvect(jetRef->p4().Vect()), muonvect(muon->p4().Vect()); // Calculate variables @@ -155,15 +205,15 @@ void SoftPFMuonTagInfoProducer::produce(edm::Event& iEvent, const edm::EventSetu } // --- End loop on daughters // Fill the TagInfo collection - theMuonTagInfo->push_back(tagInfo); + theMuonTagInfo.push_back(tagInfo); } // --- End loop on jets // Put the TagInfo collection in the event - iEvent.put(std::move(theMuonTagInfo)); + iEvent.emplace(putToken, std::move(theMuonTagInfo)); } // compute the lepton momentum along the jet axis, in the jet rest frame -float SoftPFMuonTagInfoProducer::boostedPPar(const math::XYZVector& vector, const math::XYZVector& axis) { +float SoftPFMuonTagInfoProducer::boostedPPar(const math::XYZVector& vector, const math::XYZVector& axis) const { static const double lepton_mass = 0.00; // assume a massless (ultrarelativistic) lepton static const double jet_mass = 5.279; // use B±/B0 mass as the jet rest mass [PDG 2007 updates] ROOT::Math::LorentzVector > lepton( @@ -172,3 +222,5 @@ float SoftPFMuonTagInfoProducer::boostedPPar(const math::XYZVector& vector, cons ROOT::Math::BoostX boost(-jet.Beta()); return boost(lepton).x(); } + +DEFINE_FWK_MODULE(SoftPFMuonTagInfoProducer); diff --git a/RecoBTag/SoftLepton/plugins/SoftPFMuonTagInfoProducer.h b/RecoBTag/SoftLepton/plugins/SoftPFMuonTagInfoProducer.h deleted file mode 100644 index d0f5017623ec2..0000000000000 --- a/RecoBTag/SoftLepton/plugins/SoftPFMuonTagInfoProducer.h +++ /dev/null @@ -1,44 +0,0 @@ -// * Author: Alberto Zucchetta -// * Mail: a.zucchetta@cern.ch -// * January 16, 2015 - -#ifndef RecoBTag_SoftLepton_SoftPFMuonTagInfoProducer_h -#define RecoBTag_SoftLepton_SoftPFMuonTagInfoProducer_h - -#include - -#include "FWCore/Framework/interface/stream/EDProducer.h" -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/EventSetup.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "DataFormats/Common/interface/ValueMap.h" -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" -#include "DataFormats/JetReco/interface/PFJetCollection.h" -#include "DataFormats/MuonReco/interface/Muon.h" -#include "DataFormats/MuonReco/interface/MuonFwd.h" -#include "DataFormats/MuonReco/interface/MuonSelectors.h" -#include "TrackingTools/TransientTrack/interface/TransientTrack.h" -#include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h" -#include "DataFormats/VertexReco/interface/Vertex.h" -#include "DataFormats/VertexReco/interface/VertexFwd.h" - -#include "DataFormats/BTauReco/interface/SoftLeptonTagInfo.h" -#include "DataFormats/BTauReco/interface/CandSoftLeptonTagInfo.h" - -class SoftPFMuonTagInfoProducer : public edm::stream::EDProducer<> { -public: - SoftPFMuonTagInfoProducer(const edm::ParameterSet& conf); - ~SoftPFMuonTagInfoProducer() override; - -private: - void produce(edm::Event&, const edm::EventSetup&) override; - virtual float boostedPPar(const math::XYZVector&, const math::XYZVector&); - - edm::EDGetTokenT > jetToken; - edm::EDGetTokenT > muonToken; - edm::EDGetTokenT vertexToken; - float pTcut, SIPsigcut, IPsigcut, ratio1cut, ratio2cut; - bool useFilter; -}; - -#endif diff --git a/RecoBTag/SoftLepton/plugins/module.cc b/RecoBTag/SoftLepton/plugins/module.cc index 710db04f699e3..3d2a231f7ecc8 100644 --- a/RecoBTag/SoftLepton/plugins/module.cc +++ b/RecoBTag/SoftLepton/plugins/module.cc @@ -1,10 +1,6 @@ #include "FWCore/Framework/interface/ModuleFactory.h" #include "FWCore/Framework/interface/MakerMacros.h" -#include "RecoBTag/SoftLepton/plugins/SoftLepton.h" -#include "RecoBTag/SoftLepton/plugins/SoftPFElectronTagInfoProducer.h" -#include "RecoBTag/SoftLepton/plugins/SoftPFMuonTagInfoProducer.h" - #include "DataFormats/EgammaCandidates/interface/GsfElectron.h" #include "RecoBTag/SoftLepton/interface/GenericSelectorByValueMap.h" @@ -16,10 +12,6 @@ #include "RecoBTag/SoftLepton/interface/MuonTagger.h" #include "RecoBTag/SoftLepton/interface/MuonTaggerNoIP.h" -DEFINE_FWK_MODULE(SoftLepton); -DEFINE_FWK_MODULE(SoftPFElectronTagInfoProducer); -DEFINE_FWK_MODULE(SoftPFMuonTagInfoProducer); - // "float" is the type stored in the ValueMap typedef edm::GenericSelectorByValueMap BtagGsfElectronSelector; DEFINE_FWK_MODULE(BtagGsfElectronSelector);