Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split matching into GSF to track and GSF to Packed, store the first i…
…n AOD
- Loading branch information
mauro verzetti
committed
Apr 9, 2019
1 parent
282628c
commit de347ed
Showing
7 changed files
with
118 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
RecoEgamma/EgammaElectronProducers/plugins/LowPtGSFToTrackLinker.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
RecoEgamma/EgammaElectronProducers/python/lowPtGsfToTrackLinks_cfi.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from RecoEgamma.EgammaElectronProducers.lowPtGsfToTrackLinksDefault_cfi import * | ||
|
||
lowPtGsfToTrackLinks = lowPtGsfToTrackLinksDefault.clone() |