CMS 3D CMS Logo

LowPtGSFToTrackLinker.cc
Go to the documentation of this file.
1 #include <string>
2 
22 
24 public:
26 
27  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
29 
30 private:
34 };
35 
37  : tracks_{consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracks"))},
38  preid_{consumes<std::vector<reco::PreId> >(iConfig.getParameter<edm::InputTag>("gsfPreID"))},
39  gsftracks_{consumes<std::vector<reco::GsfTrack> >(iConfig.getParameter<edm::InputTag>("gsfTracks"))} {
40  produces<edm::Association<reco::TrackCollection> >();
41 }
42 
44  auto gsftracks = iEvent.getHandle(gsftracks_);
45  auto tracks = iEvent.getHandle(tracks_);
46  auto preid = iEvent.getHandle(preid_);
47 
48  // collection sizes, for reference
49  const size_t ngsf = gsftracks->size();
50 
51  //store mapping for association
52  std::vector<int> gsf2track(ngsf, -1);
53 
54  //map Track --> GSF and fill GSF --> PackedCandidates and GSF --> Lost associations
55  for (unsigned int igsf = 0; igsf < ngsf; ++igsf) {
56  reco::GsfTrackRef gref(gsftracks, igsf);
57  reco::TrackRef trk = preid->at(gref->seedRef().castTo<reco::ElectronSeedRef>().index()).trackRef();
58 
59  if (trk.id() != tracks.id()) {
60  throw cms::Exception(
61  "WrongCollection",
62  "The reco::Track collection used to match against the GSF Tracks was not used to produce such tracks");
63  }
64 
65  size_t trkid = trk.index();
66  gsf2track[igsf] = trkid;
67  }
68 
69  // create output collections from the mappings
70  auto assoc = std::make_unique<edm::Association<reco::TrackCollection> >(tracks);
72  filler.insert(gsftracks, gsf2track.begin(), gsf2track.end());
73  filler.fill();
74  iEvent.put(std::move(assoc));
75 }
76 
79  desc.add<edm::InputTag>("tracks", edm::InputTag("generalTracks"));
80  desc.add<edm::InputTag>("gsfPreID", edm::InputTag("lowPtGsfElectronSeeds"));
81  desc.add<edm::InputTag>("gsfTracks", edm::InputTag("lowPtGsfEleGsfTracks"));
82  descriptions.add("lowPtGsfToTrackLinks", desc);
83 }
84 
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
const edm::EDGetTokenT< std::vector< reco::PreId > > preid_
ProductID id() const
Accessor for product ID.
Definition: Ref.h:244
LowPtGSFToTrackLinker(const edm::ParameterSet &)
static void fillDescriptions(edm::ConfigurationDescriptions &)
int iEvent
Definition: GenABIO.cc:224
const edm::EDGetTokenT< std::vector< reco::GsfTrack > > gsftracks_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
key_type index() const
Definition: Ref.h:253
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const edm::EDGetTokenT< reco::TrackCollection > tracks_
def move(src, dest)
Definition: eostools.py:511