CMS 3D CMS Logo

LowPtGSFToTrackLinker.cc
Go to the documentation of this file.
1 #include <string>
2 
22 
24 public:
26  ~LowPtGSFToTrackLinker() override;
27 
28  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
30 
31 private:
35 };
36 
38  tracks_{consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracks"))},
39  preid_{consumes<std::vector<reco::PreId> >(iConfig.getParameter<edm::InputTag>("gsfPreID"))},
40  gsftracks_{consumes<std::vector<reco::GsfTrack> >(iConfig.getParameter<edm::InputTag>("gsfTracks"))} {
41  produces< edm::Association<reco::TrackCollection> > ();
42  }
43 
45 
48  iEvent.getByToken(gsftracks_, gsftracks);
49 
51  iEvent.getByToken(tracks_, tracks);
52 
54  iEvent.getByToken(preid_, preid);
55 
56  // collection sizes, for reference
57  const size_t ngsf = gsftracks->size();
58 
59  //store mapping for association
60  std::vector<int> gsf2track(ngsf, -1);
61 
62  //map Track --> GSF and fill GSF --> PackedCandidates and GSF --> Lost associations
63  for(unsigned int igsf=0; igsf < ngsf; ++igsf) {
64  reco::GsfTrackRef gref(gsftracks, igsf);
65  reco::TrackRef trk = preid->at(
66  gref->seedRef().castTo<reco::ElectronSeedRef>().index()
67  ).trackRef();
68 
69  if(trk.id() != tracks.id()) {
70  throw cms::Exception("WrongCollection", "The reco::Track collection used to match against the GSF Tracks was not used to produce such tracks");
71  }
72 
73  size_t trkid = trk.index();
74  gsf2track[igsf] = trkid;
75  }
76 
77  // create output collections from the mappings
78  auto assoc = std::make_unique< edm::Association<reco::TrackCollection> >(tracks);
80  filler.insert(gsftracks, gsf2track.begin(), gsf2track.end());
81  filler.fill();
82  iEvent.put(std::move(assoc));
83 }
84 
87  desc.add<edm::InputTag>("tracks", edm::InputTag("generalTracks"));
88  desc.add<edm::InputTag>("gsfPreID", edm::InputTag("lowPtGsfElectronSeeds"));
89  desc.add<edm::InputTag>("gsfTracks", edm::InputTag("lowPtGsfEleGsfTracks"));
90  descriptions.add("lowPtGsfToTrackLinksDefault", desc);
91 }
92 
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
ProductID id() const
Definition: HandleBase.cc:15
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
LowPtGSFToTrackLinker(const edm::ParameterSet &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
key_type index() const
Definition: Ref.h:268
static void fillDescriptions(edm::ConfigurationDescriptions &)
ProductID id() const
Accessor for product ID.
Definition: Ref.h:259
int iEvent
Definition: GenABIO.cc:230
const edm::EDGetTokenT< std::vector< reco::PreId > > preid_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const edm::EDGetTokenT< std::vector< reco::GsfTrack > > gsftracks_
const edm::EDGetTokenT< reco::TrackCollection > tracks_
def move(src, dest)
Definition: eostools.py:510