CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ElectronSeedTrackRefFix.cc
Go to the documentation of this file.
9 
10 namespace {
11 
12  template <typename VMType, typename HandleType>
15  std::vector<VMType> values,
16  const std::string& label) {
17  auto vMap = std::make_unique<edm::ValueMap<VMType>>();
18  typename edm::ValueMap<VMType>::Filler mapFiller(*vMap);
19  mapFiller.insert(handle, values.begin(), values.end());
20  mapFiller.fill();
21  return event.put(std::move(vMap), label);
22  }
23 
24  template <typename T>
25  edm::Handle<T> getHandle(const edm::Event& event, const edm::EDGetTokenT<T>& token) {
27  event.getByToken(token, handle);
28  return handle;
29  }
30 
31 } // namespace
32 
34  // read parameters
35  preidgsfLabel_ = iConfig.getParameter<std::string>("PreGsfLabel");
36  preidLabel_ = iConfig.getParameter<std::vector<std::string>>("PreIdLabel");
37  oldTracksTag_ = iConfig.getParameter<edm::InputTag>("oldTrackCollection");
38  newTracksTag_ = iConfig.getParameter<edm::InputTag>("newTrackCollection");
39  seedsTag_ = iConfig.getParameter<edm::InputTag>("seedCollection");
40  idsTag_ = iConfig.getParameter<std::vector<edm::InputTag>>("idCollection");
41 
42  //register your products
43  produces<reco::ElectronSeedCollection>(preidgsfLabel_);
44  for (const auto& idLabel : preidLabel_) {
45  produces<reco::PreIdCollection>(idLabel);
46  produces<edm::ValueMap<reco::PreIdRef>>(idLabel);
47  }
48 
49  //create tokens
50  oldTracksToken_ = consumes<reco::TrackCollection>(oldTracksTag_);
51  newTracksToken_ = consumes<reco::TrackCollection>(newTracksTag_);
52  seedsToken_ = consumes<reco::ElectronSeedCollection>(seedsTag_);
53  for (const auto& idTag : idsTag_) {
54  idsToken_.emplace_back(consumes<reco::PreIdCollection>(idTag));
55  idMapToken_.emplace_back(consumes<edm::ValueMap<reco::PreIdRef>>(idTag));
56  }
57 }
58 
60  // do anything here that needs to be done at desctruction time
61  // (e.g. close files, deallocate resources etc.)
62 }
63 
64 // ------------ method called to produce the data ------------
66  auto oldTracks = getHandle(iEvent, oldTracksToken_);
67  auto newTracks = getHandle(iEvent, newTracksToken_);
68  auto iSeeds = getHandle(iEvent, seedsToken_);
69 
70  auto oSeeds = std::make_unique<reco::ElectronSeedCollection>();
71  for (unsigned int s = 0; s < iSeeds->size(); ++s) {
72  oSeeds->push_back(iSeeds->at(s));
73  reco::TrackRef newTrackRef(newTracks, oSeeds->back().ctfTrack().index());
74  oSeeds->back().setCtfTrack(newTrackRef);
75  }
76  iEvent.put(std::move(oSeeds), preidgsfLabel_);
77 
78  for (size_t idNr = 0; idNr < idsTag_.size(); idNr++) {
79  auto iIds = getHandle(iEvent, idsToken_[idNr]);
80  auto oIds = std::make_unique<reco::PreIdCollection>();
81  for (unsigned int i = 0; i < iIds->size(); ++i) {
82  oIds->push_back(iIds->at(i));
83  reco::TrackRef newTrackRef(newTracks, oIds->back().trackRef().index());
84  oIds->back().setTrack(newTrackRef);
85  }
86  const edm::OrphanHandle<reco::PreIdCollection> preIdProd = iEvent.put(std::move(oIds), preidLabel_[idNr]);
87 
88  auto iIdMap = getHandle(iEvent, idMapToken_[idNr]);
89  std::vector<reco::PreIdRef> values;
90  for (size_t trkNr = 0; trkNr < newTracks->size(); ++trkNr) {
91  //low pt electron seeds do not make the idMaps so this is now optional to fill in a useful way
92  if (trkNr < oldTracks->size() && iIdMap.isValid()) {
93  reco::TrackRef oldTrackRef(oldTracks, trkNr);
94  values.push_back(reco::PreIdRef(preIdProd, (*(iIdMap.product()))[oldTrackRef].index()));
95  } else
96  values.push_back(reco::PreIdRef());
97  }
98  addVMToEvent(iEvent, newTracks, std::move(values), preidLabel_[idNr]);
99  } //end loop over ids
100 }
101 
102 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
104  //The following says we do not know what parameters are allowed so do no validation
105  // Please change this to state exactly what you do use, even if it is no parameters
107  desc.setUnknown();
108  descriptions.addDefault(desc);
109 }
110 
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
void produce(edm::Event &, const edm::EventSetup &) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< reco::TrackCollection > newTracksToken_
std::vector< std::string > preidLabel_
edm::EDGetTokenT< reco::ElectronSeedCollection > seedsToken_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
ElectronSeedTrackRefFix(const edm::ParameterSet &)
char const * label
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
def move
Definition: eostools.py:511
tuple handle
Definition: patZpeak.py:25
std::vector< edm::EDGetTokenT< reco::PreIdCollection > > idsToken_
std::vector< edm::EDGetTokenT< edm::ValueMap< reco::PreIdRef > > > idMapToken_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::vector< edm::InputTag > idsTag_
edm::EDGetTokenT< reco::TrackCollection > oldTracksToken_
tuple size
Write out results.