CMS 3D CMS Logo

LowPtGSFToPackedCandidateLinker.cc
Go to the documentation of this file.
1 #include <string>
2 
21 
23 public:
26 
27  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
29 
30 private:
39 };
40 
42  : pfcands_{consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("PFCandidates"))},
43  packed_{consumes<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("packedCandidates"))},
44  lost_tracks_{consumes<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("lostTracks"))},
45  tracks_{consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracks"))},
46  pf2packed_{consumes<edm::Association<pat::PackedCandidateCollection> >(
47  iConfig.getParameter<edm::InputTag>("packedCandidates"))},
48  lost2trk_{consumes<edm::Association<pat::PackedCandidateCollection> >(
49  iConfig.getParameter<edm::InputTag>("lostTracks"))},
50  gsf2trk_{consumes<edm::Association<reco::TrackCollection> >(iConfig.getParameter<edm::InputTag>("gsfToTrack"))},
51  gsftracks_{consumes<std::vector<reco::GsfTrack> >(iConfig.getParameter<edm::InputTag>("gsfTracks"))} {
52  produces<edm::Association<pat::PackedCandidateCollection> >("packedCandidates");
53  produces<edm::Association<pat::PackedCandidateCollection> >("lostTracks");
54 }
55 
57 
60  iEvent.getByToken(pfcands_, pfcands);
61 
63  iEvent.getByToken(packed_, packed);
64 
66  iEvent.getByToken(lost_tracks_, lost_tracks);
67 
69  iEvent.getByToken(pf2packed_, pf2packed);
70 
72  iEvent.getByToken(lost2trk_, lost2trk_assoc);
73 
75  iEvent.getByToken(gsftracks_, gsftracks);
76 
78  iEvent.getByToken(tracks_, tracks);
79 
81  iEvent.getByToken(gsf2trk_, gsf2trk);
82 
83  // collection sizes, for reference
84  const size_t npf = pfcands->size();
85  const size_t npacked = packed->size();
86  const size_t nlost = lost_tracks->size();
87  const size_t ntracks = tracks->size();
88  const size_t ngsf = gsftracks->size();
89 
90  //store index mapping in vectors for easy and fast access
91  std::vector<size_t> trk2packed(ntracks, npacked);
92  std::vector<size_t> trk2lost(ntracks, nlost);
93 
94  //store auxiliary mappings for association
95  std::vector<int> gsf2pack(ngsf, -1);
96  std::vector<int> gsf2lost(ngsf, -1);
97 
98  //electrons will never store their track (they store the Gsf track)
99  //map PackedPF <--> Track
100  for (unsigned int icand = 0; icand < npf; ++icand) {
101  edm::Ref<reco::PFCandidateCollection> pf_ref(pfcands, icand);
102  const reco::PFCandidate& cand = pfcands->at(icand);
103  auto packed_ref = (*pf2packed)[pf_ref];
104  if (cand.charge() && packed_ref.isNonnull() && cand.trackRef().isNonnull() && cand.trackRef().id() == tracks.id()) {
105  size_t trkid = cand.trackRef().index();
106  size_t packid = packed_ref.index();
107  trk2packed[trkid] = packid;
108  }
109  }
110 
111  //map LostTrack <--> Track
112  for (unsigned int itrk = 0; itrk < ntracks; ++itrk) {
113  reco::TrackRef key(tracks, itrk);
114  pat::PackedCandidateRef lostTrack = (*lost2trk_assoc)[key];
115  if (lostTrack.isNonnull()) {
116  size_t ilost = lostTrack.index(); //assumes that LostTracks are all made from the same track collection
117  trk2lost[itrk] = ilost;
118  }
119  }
120 
121  //map Track --> GSF and fill GSF --> PackedCandidates and GSF --> Lost associations
122  for (unsigned int igsf = 0; igsf < ngsf; ++igsf) {
123  reco::GsfTrackRef gref(gsftracks, igsf);
124  reco::TrackRef trk = (*gsf2trk)[gref];
125  if (trk.id() != tracks.id()) {
126  throw cms::Exception(
127  "WrongCollection",
128  "The reco::Track collection used to match against the GSF Tracks was not used to produce such tracks");
129  }
130  size_t trkid = trk.index();
131 
132  if (trk2packed[trkid] != npacked) {
133  gsf2pack[igsf] = trk2packed[trkid];
134  }
135  if (trk2lost[trkid] != nlost) {
136  gsf2lost[igsf] = trk2lost[trkid];
137  }
138  }
139 
140  // create output collections from the mappings
141  auto assoc_gsf2pack = std::make_unique<edm::Association<pat::PackedCandidateCollection> >(packed);
142  edm::Association<pat::PackedCandidateCollection>::Filler gsf2pack_filler(*assoc_gsf2pack);
143  gsf2pack_filler.insert(gsftracks, gsf2pack.begin(), gsf2pack.end());
144  gsf2pack_filler.fill();
145  iEvent.put(std::move(assoc_gsf2pack), "packedCandidates");
146 
147  auto assoc_gsf2lost = std::make_unique<edm::Association<pat::PackedCandidateCollection> >(lost_tracks);
148  edm::Association<pat::PackedCandidateCollection>::Filler gsf2lost_filler(*assoc_gsf2lost);
149  gsf2lost_filler.insert(gsftracks, gsf2lost.begin(), gsf2lost.end());
150  gsf2lost_filler.fill();
151  iEvent.put(std::move(assoc_gsf2lost), "lostTracks");
152 }
153 
156  desc.add<edm::InputTag>("PFCandidates", edm::InputTag("particleFlow"));
157  desc.add<edm::InputTag>("packedCandidates", edm::InputTag("packedPFCandidates"));
158  desc.add<edm::InputTag>("lostTracks", edm::InputTag("lostTracks"));
159  desc.add<edm::InputTag>("tracks", edm::InputTag("generalTracks"));
160  desc.add<edm::InputTag>("gsfToTrack", edm::InputTag("lowPtGsfToTrackLinks"));
161  desc.add<edm::InputTag>("gsfTracks", edm::InputTag("lowPtGsfEleGsfTracks"));
162  descriptions.add("lowPtGsfLinksDefault", desc);
163 }
164 
edm::StreamID
Definition: StreamID.h:30
PDWG_EXOHSCP_cff.tracks
tracks
Definition: PDWG_EXOHSCP_cff.py:28
LowPtGSFToPackedCandidateLinker::gsf2trk_
const edm::EDGetTokenT< edm::Association< reco::TrackCollection > > gsf2trk_
Definition: LowPtGSFToPackedCandidateLinker.cc:37
edm::Association::Filler
Definition: Association.h:78
PFCandidate.h
edm::EDGetTokenT< reco::PFCandidateCollection >
LowPtGSFToPackedCandidateLinker::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &)
Definition: LowPtGSFToPackedCandidateLinker.cc:154
LowPtGSFToPackedCandidateLinker::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: LowPtGSFToPackedCandidateLinker.cc:58
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89353
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
vertices_cff.ntracks
ntracks
Definition: vertices_cff.py:34
Association.h
edm::Ref::index
key_type index() const
Definition: Ref.h:253
edm::Handle
Definition: AssociativeIterator.h:50
ElectronSeedFwd.h
edm::Ref
Definition: AssociativeIterator.h:58
PreId.h
LowPtGSFToPackedCandidateLinker::~LowPtGSFToPackedCandidateLinker
~LowPtGSFToPackedCandidateLinker() override
Definition: LowPtGSFToPackedCandidateLinker.cc:56
MakerMacros.h
LowPtGSFToPackedCandidateLinker::lost2trk_
const edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > lost2trk_
Definition: LowPtGSFToPackedCandidateLinker.cc:36
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
LowPtGSFToPackedCandidateLinker
Definition: LowPtGSFToPackedCandidateLinker.cc:22
LowPtGSFToPackedCandidateLinker::packed_
const edm::EDGetTokenT< pat::PackedCandidateCollection > packed_
Definition: LowPtGSFToPackedCandidateLinker.cc:32
LowPtGSFToPackedCandidateLinker::tracks_
const edm::EDGetTokenT< reco::TrackCollection > tracks_
Definition: LowPtGSFToPackedCandidateLinker.cc:34
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
LowPtGSFToPackedCandidateLinker::LowPtGSFToPackedCandidateLinker
LowPtGSFToPackedCandidateLinker(const edm::ParameterSet &)
Definition: LowPtGSFToPackedCandidateLinker.cc:41
packedPFCandidateRefMixer_cfi.pf2packed
pf2packed
Definition: packedPFCandidateRefMixer_cfi.py:6
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
LowPtGSFToPackedCandidateLinker::pfcands_
const edm::EDGetTokenT< reco::PFCandidateCollection > pfcands_
Definition: LowPtGSFToPackedCandidateLinker.cc:31
PackedCandidate.h
edm::Ref::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
cand
Definition: decayParser.h:32
iEvent
int iEvent
Definition: GenABIO.cc:224
GsfTrack.h
edm::EventSetup
Definition: EventSetup.h:57
PreIdFwd.h
LowPtGSFToPackedCandidateLinker::gsftracks_
const edm::EDGetTokenT< std::vector< reco::GsfTrack > > gsftracks_
Definition: LowPtGSFToPackedCandidateLinker.cc:38
LowPtGSFToPackedCandidateLinker::pf2packed_
const edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > pf2packed_
Definition: LowPtGSFToPackedCandidateLinker.cc:35
edm::Ref::id
ProductID id() const
Accessor for product ID.
Definition: Ref.h:244
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
LowPtGSFToPackedCandidateLinker::lost_tracks_
const edm::EDGetTokenT< pat::PackedCandidateCollection > lost_tracks_
Definition: LowPtGSFToPackedCandidateLinker.cc:33
eostools.move
def move(src, dest)
Definition: eostools.py:511
GsfTrackFwd.h
Frameworkfwd.h
Exception
Definition: hltDiff.cc:246
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Exception.h
reco::PFCandidate
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
Candidate.h
ParameterSet.h
EDProducer.h
edm::Event
Definition: Event.h:73
crabWrapper.key
key
Definition: crabWrapper.py:19
edm::InputTag
Definition: InputTag.h:15
PFCandidateFwd.h
ElectronSeed.h