Skip to content

Commit

Permalink
Merge pull request #35018 from Dr15Jones/esConsumesRecoBTag
Browse files Browse the repository at this point in the history
Modernized some modules in RecoBTag
  • Loading branch information
cmsbuild authored Aug 27, 2021
2 parents fd04911 + cb85cb1 commit 310e644
Show file tree
Hide file tree
Showing 8 changed files with 328 additions and 360 deletions.
13 changes: 7 additions & 6 deletions RecoBTag/PixelCluster/plugins/PixelClusterTagInfoProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -79,6 +80,8 @@ class PixelClusterTagInfoProducer : public edm::global::EDProducer<> {
const edm::EDGetTokenT<edm::View<reco::Jet> > m_jets;
const edm::EDGetTokenT<reco::VertexCollection> m_vertices;
const edm::EDGetTokenT<edmNew::DetSetVector<SiPixelCluster> > m_pixelhit;
const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> m_geomToken;
const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> m_topoToken;
const bool m_isPhase1;
const bool m_addFPIX;
const int m_minADC;
Expand All @@ -92,6 +95,8 @@ PixelClusterTagInfoProducer::PixelClusterTagInfoProducer(const edm::ParameterSet
: m_jets(consumes<edm::View<reco::Jet> >(iConfig.getParameter<edm::InputTag>("jets"))),
m_vertices(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertices"))),
m_pixelhit(consumes<edmNew::DetSetVector<SiPixelCluster> >(iConfig.getParameter<edm::InputTag>("pixelhit"))),
m_geomToken(esConsumes()),
m_topoToken(esConsumes()),
m_isPhase1(iConfig.getParameter<bool>("isPhase1")),
m_addFPIX(iConfig.getParameter<bool>("addForward")),
m_minADC(iConfig.getParameter<int>("minAdcCount")),
Expand Down Expand Up @@ -140,14 +145,10 @@ void PixelClusterTagInfoProducer::produce(edm::StreamID iID, edm::Event& iEvent,
const edmNew::DetSetVector<SiPixelCluster>& collectionClusters(*collectionHandle);

// Open Geometry
edm::ESHandle<TrackerGeometry> geom;
iSetup.get<TrackerDigiGeometryRecord>().get(geom);
const TrackerGeometry& theTracker(*geom);
const TrackerGeometry& theTracker = iSetup.getData(m_geomToken);

// Retrieve tracker topology from geometry
edm::ESHandle<TrackerTopology> tTopoH;
iSetup.get<TrackerTopologyRcd>().get(tTopoH);
const TrackerTopology* tTopo = tTopoH.product();
const TrackerTopology* tTopo = &iSetup.getData(m_topoToken);

std::vector<reco::PixelClusterProperties> clusters;

Expand Down
188 changes: 134 additions & 54 deletions RecoBTag/SoftLepton/plugins/SoftLepton.cc

Large diffs are not rendered by default.

116 changes: 0 additions & 116 deletions RecoBTag/SoftLepton/plugins/SoftLepton.h

This file was deleted.

153 changes: 103 additions & 50 deletions RecoBTag/SoftLepton/plugins/SoftPFElectronTagInfoProducer.cc
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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 <cmath>
#include "CommonTools/Egamma/interface/ConversionTools.h"
#include "DataFormats/PatCandidates/interface/Electron.h"

SoftPFElectronTagInfoProducer::SoftPFElectronTagInfoProducer(const edm::ParameterSet& conf) {
token_jets = consumes<edm::View<reco::Jet> >(conf.getParameter<edm::InputTag>("jets"));
token_elec = consumes<edm::View<reco::GsfElectron> >(conf.getParameter<edm::InputTag>("electrons"));
token_primaryVertex = consumes<reco::VertexCollection>(conf.getParameter<edm::InputTag>("primaryVertex"));
token_BeamSpot = consumes<reco::BeamSpot>(edm::InputTag("offlineBeamSpot"));
token_allConversions = consumes<reco::ConversionCollection>(edm::InputTag("allConversions"));
DeltaRElectronJet = conf.getParameter<double>("DeltaRElectronJet");
MaxSip3Dsig = conf.getParameter<double>("MaxSip3Dsig");
produces<reco::CandSoftLeptonTagInfoCollection>();
#include <cmath>
#include <vector>

// 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<reco::VertexCollection> token_primaryVertex;
const edm::EDGetTokenT<edm::View<reco::Jet> > token_jets;
const edm::EDGetTokenT<edm::View<reco::GsfElectron> > token_elec;
const edm::EDGetTokenT<reco::BeamSpot> token_BeamSpot;
const edm::EDGetTokenT<reco::ConversionCollection> token_allConversions;
const edm::ESGetToken<TransientTrackBuilder, TransientTrackRecord> token_builder;
const edm::EDPutTokenT<reco::CandSoftLeptonTagInfoCollection> token_put;
const float DeltaRElectronJet, MaxSip3Dsig;
};

SoftPFElectronTagInfoProducer::SoftPFElectronTagInfoProducer(const edm::ParameterSet& conf)
: token_primaryVertex(consumes(conf.getParameter<edm::InputTag>("primaryVertex"))),
token_jets(consumes(conf.getParameter<edm::InputTag>("jets"))),
token_elec(consumes(conf.getParameter<edm::InputTag>("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<double>("DeltaRElectronJet")),
MaxSip3Dsig(conf.getParameter<double>("MaxSip3Dsig")) {}

void SoftPFElectronTagInfoProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("primaryVertex");
desc.add<edm::InputTag>("jets");
desc.add<edm::InputTag>("electrons");
desc.add<double>("DeltaRElectronJet");
desc.add<double>("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<reco::VertexCollection> 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<reco::CandSoftLeptonTagInfoCollection>();
edm::ESHandle<TransientTrackBuilder> builder;
iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", builder);
transientTrackBuilder = builder.product();
edm::View<reco::Jet> const& theJetCollection = iEvent.get(token_jets);

edm::Handle<reco::VertexCollection> PVCollection;
iEvent.getByToken(token_primaryVertex, PVCollection);
if (!PVCollection.isValid())
edm::View<reco::GsfElectron> 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<reco::ConversionCollection> hConversions;
iEvent.getByToken(token_allConversions, hConversions);

edm::Handle<edm::View<reco::Jet> > theJetCollection;
iEvent.getByToken(token_jets, theJetCollection);

edm::Handle<edm::View<reco::GsfElectron> > theGEDGsfElectronCollection;
iEvent.getByToken(token_elec, theGEDGsfElectronCollection);

edm::Handle<reco::BeamSpot> bsHandle;
iEvent.getByToken(token_BeamSpot, bsHandle);
const reco::BeamSpot& beamspot = *bsHandle.product();

for (unsigned int i = 0; i < theJetCollection->size(); i++) {
edm::RefToBase<reco::Jet> jetRef = theJetCollection->refAt(i);
}

const reco::BeamSpot& beamspot = iEvent.get(token_BeamSpot);

for (unsigned int i = 0; i < theJetCollection.size(); i++) {
edm::RefToBase<reco::Jet> jetRef = theJetCollection.refAt(i);
reco::CandSoftLeptonTagInfo tagInfo;
tagInfo.setJetRef(jetRef);
std::vector<const reco::GsfElectron*> 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<reco::Candidate> lepPtr = theGEDGsfElectronCollection->ptrAt(ie);
const reco::GsfElectron* recoelectron = theGEDGsfElectronCollection->refAt(ie).get();
edm::Ptr<reco::Candidate> lepPtr = theGEDGsfElectronCollection.ptrAt(ie);
const reco::GsfElectron* recoelectron = theGEDGsfElectronCollection.refAt(ie).get();
const pat::Electron* patelec = dynamic_cast<const pat::Electron*>(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
Expand All @@ -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();
Expand All @@ -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) {
Expand All @@ -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);
Loading

0 comments on commit 310e644

Please sign in to comment.