Skip to content

Commit

Permalink
Merge pull request #26404 from mverzett/split_lowpt_links_10_2
Browse files Browse the repository at this point in the history
Split lowpt links
  • Loading branch information
cmsbuild committed Apr 15, 2019
2 parents 282628c + de347ed commit e4f74ba
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 8 deletions.
4 changes: 4 additions & 0 deletions DataFormats/TrackReco/interface/TrackFwd.h
Expand Up @@ -7,6 +7,7 @@
#include "DataFormats/Common/interface/RefVector.h"
#include "DataFormats/Common/interface/RefToBase.h"
#include "DataFormats/Common/interface/RefToBaseVector.h"
#include "DataFormats/Common/interface/Association.h"

namespace reco
{
Expand All @@ -19,6 +20,9 @@ typedef std::vector<Track> TrackCollection;
/// persistent reference to a Track
typedef edm::Ref<TrackCollection> TrackRef;

/// association to a track collection
typedef edm::Association<TrackCollection> TrackAssociation;

/// persistent reference to a Track collection
typedef edm::RefProd<TrackCollection> TrackRefProd;

Expand Down
2 changes: 2 additions & 0 deletions DataFormats/TrackReco/src/classes_def.xml
Expand Up @@ -340,6 +340,8 @@
<class name="std::vector<edm::Ref<std::vector<reco::Track>,reco::Track,edm::refhelper::FindUsingAdvance<std::vector<reco::Track>,reco::Track> > >"/>
<class name="edm::Ptr<reco::Track>" />
<class name="std::vector<edm::Ptr<reco::Track> >" />
<class name="edm::Association<reco::TrackCollection>"/>
<class name="edm::Wrapper<edm::Association<reco::TrackCollection> >"/>

<class pattern="edm::Wrapper<edm::AssociationMap<*>" />

Expand Down
17 changes: 9 additions & 8 deletions PhysicsTools/PatAlgos/plugins/LowPtGSFToPackedCandidateLinker.cc
Expand Up @@ -34,7 +34,7 @@ class LowPtGSFToPackedCandidateLinker : public edm::global::EDProducer<> {
const edm::EDGetTokenT<reco::TrackCollection> tracks_;
const edm::EDGetTokenT<edm::Association<pat::PackedCandidateCollection> > pf2packed_;
const edm::EDGetTokenT<edm::Association<pat::PackedCandidateCollection> > lost2trk_;
const edm::EDGetTokenT< std::vector<reco::PreId> > preid_;
const edm::EDGetTokenT< edm::Association<reco::TrackCollection> > gsf2trk_;
const edm::EDGetTokenT< std::vector<reco::GsfTrack> > gsftracks_;
};

Expand All @@ -45,7 +45,7 @@ LowPtGSFToPackedCandidateLinker::LowPtGSFToPackedCandidateLinker(const edm::Para
tracks_{consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracks"))},
pf2packed_{consumes<edm::Association<pat::PackedCandidateCollection> >(iConfig.getParameter<edm::InputTag>("packedCandidates"))},
lost2trk_{consumes<edm::Association<pat::PackedCandidateCollection> >(iConfig.getParameter<edm::InputTag>("lostTracks"))},
preid_{consumes<std::vector<reco::PreId> >(iConfig.getParameter<edm::InputTag>("gsfPreID"))},
gsf2trk_{consumes<edm::Association<reco::TrackCollection> >(iConfig.getParameter<edm::InputTag>("gsfToTrack"))},
gsftracks_{consumes<std::vector<reco::GsfTrack> >(iConfig.getParameter<edm::InputTag>("gsfTracks"))} {
produces< edm::Association<pat::PackedCandidateCollection> > ("packedCandidates");
produces< edm::Association<pat::PackedCandidateCollection> > ("lostTracks");
Expand Down Expand Up @@ -75,8 +75,8 @@ void LowPtGSFToPackedCandidateLinker::produce(edm::StreamID, edm::Event& iEvent,
edm::Handle<reco::TrackCollection> tracks;
iEvent.getByToken(tracks_, tracks);

edm::Handle<std::vector<reco::PreId> > preid;
iEvent.getByToken(preid_, preid);
edm::Handle<edm::Association<reco::TrackCollection> > gsf2trk;
iEvent.getByToken(gsf2trk_, gsf2trk);

// collection sizes, for reference
const size_t npf = pfcands->size();
Expand Down Expand Up @@ -120,9 +120,10 @@ void LowPtGSFToPackedCandidateLinker::produce(edm::StreamID, edm::Event& iEvent,
//map Track --> GSF and fill GSF --> PackedCandidates and GSF --> Lost associations
for(unsigned int igsf=0; igsf < ngsf; ++igsf) {
reco::GsfTrackRef gref(gsftracks, igsf);
reco::TrackRef trk = preid->at(
gref->seedRef().castTo<reco::ElectronSeedRef>().index()
).trackRef();
reco::TrackRef trk = (*gsf2trk)[gref];
if(trk.id() != tracks.id()) {
throw cms::Exception("WrongCollection", "The reco::Track collection used to match against the GSF Tracks was not used to produce such tracks");
}
size_t trkid = trk.index();

if(trk2packed[trkid] != npacked) {
Expand Down Expand Up @@ -153,7 +154,7 @@ void LowPtGSFToPackedCandidateLinker::fillDescriptions(edm::ConfigurationDescrip
desc.add<edm::InputTag>("packedCandidates", edm::InputTag("packedPFCandidates"));
desc.add<edm::InputTag>("lostTracks", edm::InputTag("lostTracks"));
desc.add<edm::InputTag>("tracks", edm::InputTag("generalTracks"));
desc.add<edm::InputTag>("gsfPreID", edm::InputTag("lowPtGsfElectronSeeds"));
desc.add<edm::InputTag>("gsfToTrack", edm::InputTag("lowPtGsfToTrackLinks"));
desc.add<edm::InputTag>("gsfTracks", edm::InputTag("lowPtGsfEleGsfTracks"));
descriptions.add("lowPtGsfLinksDefault", desc);
}
Expand Down
Expand Up @@ -46,6 +46,7 @@
'keep recoGsfElectrons_lowPtGsfElectrons_*_*',
'keep recoGsfElectronCores_lowPtGsfElectronCores_*_*',
'keep recoGsfTracks_lowPtGsfEleGsfTracks_*_*',
'keep *_lowPtGsfToTrackLinks_*_*',
'keep recoSuperClusters_lowPtGsfElectronSuperClusters_*_*',
'keep floatedmValueMap_lowPtGsfElectronSeedValueMaps_*_*',
'keep floatedmValueMap_lowPtGsfElectronID_*_*',
Expand Down Expand Up @@ -110,6 +111,7 @@
'keep recoGsfElectrons_lowPtGsfElectrons_*_*',
'keep recoGsfElectronCores_lowPtGsfElectronCores_*_*',
'keep recoGsfTracks_lowPtGsfEleGsfTracks_*_*',
'keep *_lowPtGsfToTrackLinks_*_*',
'keep recoSuperClusters_lowPtGsfElectronSuperClusters_*_*',
'keep floatedmValueMap_lowPtGsfElectronSeedValueMaps_*_*',
'keep floatedmValueMap_lowPtGsfElectronID_*_*',
Expand Down Expand Up @@ -163,6 +165,7 @@
'keep recoGsfElectrons_lowPtGsfElectrons_*_*',
'keep recoGsfElectronCores_lowPtGsfElectronCores_*_*',
'keep recoGsfTracks_lowPtGsfEleGsfTracks_*_*',
'keep *_lowPtGsfToTrackLinks_*_*',
'keep recoSuperClusters_lowPtGsfElectronSuperClusters_*_*',
'keep floatedmValueMap_lowPtGsfElectronSeedValueMaps_*_*',
'keep floatedmValueMap_lowPtGsfElectronID_*_*',
Expand Down
@@ -0,0 +1,93 @@
#include <string>

#include "DataFormats/Candidate/interface/Candidate.h"
#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
#include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
#include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h"
#include "DataFormats/Common/interface/Association.h"
#include "FWCore/Framework/interface/global/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "DataFormats/ParticleFlowReco/interface/PreId.h"
#include "DataFormats/ParticleFlowReco/interface/PreIdFwd.h"
#include "DataFormats/EgammaReco/interface/ElectronSeed.h"
#include "DataFormats/EgammaReco/interface/ElectronSeedFwd.h"
#include "DataFormats/EgammaReco/interface/ElectronSeedFwd.h"
#include "DataFormats/TrackReco/interface/Track.h"
#include "FWCore/Framework/interface/MakerMacros.h"

class LowPtGSFToTrackLinker : public edm::global::EDProducer<> {
public:
explicit LowPtGSFToTrackLinker(const edm::ParameterSet&);
~LowPtGSFToTrackLinker() override;

void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
static void fillDescriptions(edm::ConfigurationDescriptions&);

private:
const edm::EDGetTokenT<reco::TrackCollection> tracks_;
const edm::EDGetTokenT< std::vector<reco::PreId> > preid_;
const edm::EDGetTokenT< std::vector<reco::GsfTrack> > gsftracks_;
};

LowPtGSFToTrackLinker::LowPtGSFToTrackLinker(const edm::ParameterSet& iConfig) :
tracks_{consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracks"))},
preid_{consumes<std::vector<reco::PreId> >(iConfig.getParameter<edm::InputTag>("gsfPreID"))},
gsftracks_{consumes<std::vector<reco::GsfTrack> >(iConfig.getParameter<edm::InputTag>("gsfTracks"))} {
produces< edm::Association<reco::TrackCollection> > ();
}

LowPtGSFToTrackLinker::~LowPtGSFToTrackLinker() {}

void LowPtGSFToTrackLinker::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
edm::Handle<std::vector<reco::GsfTrack> > gsftracks;
iEvent.getByToken(gsftracks_, gsftracks);

edm::Handle<reco::TrackCollection> tracks;
iEvent.getByToken(tracks_, tracks);

edm::Handle<std::vector<reco::PreId> > preid;
iEvent.getByToken(preid_, preid);

// collection sizes, for reference
const size_t ngsf = gsftracks->size();

//store mapping for association
std::vector<int> gsf2track(ngsf, -1);

//map Track --> GSF and fill GSF --> PackedCandidates and GSF --> Lost associations
for(unsigned int igsf=0; igsf < ngsf; ++igsf) {
reco::GsfTrackRef gref(gsftracks, igsf);
reco::TrackRef trk = preid->at(
gref->seedRef().castTo<reco::ElectronSeedRef>().index()
).trackRef();

if(trk.id() != tracks.id()) {
throw cms::Exception("WrongCollection", "The reco::Track collection used to match against the GSF Tracks was not used to produce such tracks");
}

size_t trkid = trk.index();
gsf2track[igsf] = trkid;
}

// create output collections from the mappings
auto assoc = std::make_unique< edm::Association<reco::TrackCollection> >(tracks);
edm::Association<reco::TrackCollection>::Filler filler(*assoc);
filler.insert(gsftracks, gsf2track.begin(), gsf2track.end());
filler.fill();
iEvent.put(std::move(assoc));
}

void LowPtGSFToTrackLinker::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("tracks", edm::InputTag("generalTracks"));
desc.add<edm::InputTag>("gsfPreID", edm::InputTag("lowPtGsfElectronSeeds"));
desc.add<edm::InputTag>("gsfTracks", edm::InputTag("lowPtGsfEleGsfTracks"));
descriptions.add("lowPtGsfToTrackLinksDefault", desc);
}

DEFINE_FWK_MODULE(LowPtGSFToTrackLinker);
Expand Up @@ -41,6 +41,9 @@

fastSim.toModify(lowPtGsfEleGsfTracks,src = cms.InputTag("fastLowPtGsfTkfTrackCandidates"))

# GSFTrack to track association
from RecoEgamma.EgammaElectronProducers.lowPtGsfToTrackLinks_cfi import *

# GsfPFRecTracks
from RecoParticleFlow.PFTracking.pfTrackElec_cfi import *
lowPtGsfElePfGsfTracks = pfTrackElec.clone()
Expand Down Expand Up @@ -73,6 +76,7 @@
lowPtGsfElectronSeeds,
lowPtGsfEleCkfTrackCandidates,
lowPtGsfEleGsfTracks,
lowPtGsfToTrackLinks,
lowPtGsfElePfGsfTracks,
lowPtGsfElectronSuperClusters,
lowPtGsfElectronCores,
Expand Down
@@ -0,0 +1,3 @@
from RecoEgamma.EgammaElectronProducers.lowPtGsfToTrackLinksDefault_cfi import *

lowPtGsfToTrackLinks = lowPtGsfToTrackLinksDefault.clone()

0 comments on commit e4f74ba

Please sign in to comment.