CMS 3D CMS Logo

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 
ElectronSeedTrackRefFix::idMapToken_
std::vector< edm::EDGetTokenT< edm::ValueMap< reco::PreIdRef > > > idMapToken_
Definition: ElectronSeedTrackRefFix.h:28
mps_fire.i
i
Definition: mps_fire.py:428
ElectronSeedTrackRefFix::seedsTag_
edm::InputTag seedsTag_
Definition: ElectronSeedTrackRefFix.h:33
ElectronSeedTrackRefFix
Definition: ElectronSeedTrackRefFix.h:12
ElectronSeedTrackRefFix::idsToken_
std::vector< edm::EDGetTokenT< reco::PreIdCollection > > idsToken_
Definition: ElectronSeedTrackRefFix.h:27
ElectronSeedTrackRefFix::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: ElectronSeedTrackRefFix.cc:103
patZpeak.handle
handle
Definition: patZpeak.py:23
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
ElectronSeedTrackRefFix::seedsToken_
edm::EDGetTokenT< reco::ElectronSeedCollection > seedsToken_
Definition: ElectronSeedTrackRefFix.h:26
ElectronSeedTrackRefFix::idsTag_
std::vector< edm::InputTag > idsTag_
Definition: ElectronSeedTrackRefFix.h:34
ElectronSeedTrackRefFix::preidLabel_
std::vector< std::string > preidLabel_
Definition: ElectronSeedTrackRefFix.h:30
edm::Handle
Definition: AssociativeIterator.h:50
edm::Ref< TrackCollection >
ElectronSeedTrackRefFix::newTracksToken_
edm::EDGetTokenT< reco::TrackCollection > newTracksToken_
Definition: ElectronSeedTrackRefFix.h:24
PreId.h
ElectronSeedTrackRefFix::~ElectronSeedTrackRefFix
~ElectronSeedTrackRefFix() override
Definition: ElectronSeedTrackRefFix.cc:59
MakerMacros.h
alignCSCRings.s
s
Definition: alignCSCRings.py:92
Track.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
contentValuesCheck.values
values
Definition: contentValuesCheck.py:38
ElectronSeedTrackRefFix::newTracksTag_
edm::InputTag newTracksTag_
Definition: ElectronSeedTrackRefFix.h:32
ElectronSeedTrackRefFix::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: ElectronSeedTrackRefFix.cc:65
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
ElectronSeedTrackRefFix::oldTracksToken_
edm::EDGetTokenT< reco::TrackCollection > oldTracksToken_
Definition: ElectronSeedTrackRefFix.h:25
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup
Definition: EventSetup.h:57
ValueMap.h
ElectronSeedTrackRefFix::ElectronSeedTrackRefFix
ElectronSeedTrackRefFix(const edm::ParameterSet &)
Definition: ElectronSeedTrackRefFix.cc:33
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
edm::OrphanHandle
Definition: EDProductfwd.h:39
edm::ValueMap
Definition: ValueMap.h:107
ElectronSeedTrackRefFix::oldTracksTag_
edm::InputTag oldTracksTag_
Definition: ElectronSeedTrackRefFix.h:31
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
ElectronSeedTrackRefFix.h
edm::helper::Filler
Definition: ValueMap.h:22
ParameterSet.h
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
edm::ConfigurationDescriptions::addDefault
void addDefault(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:99
ElectronSeedTrackRefFix::preidgsfLabel_
std::string preidgsfLabel_
Definition: ElectronSeedTrackRefFix.h:29
edm::InputTag
Definition: InputTag.h:15
label
const char * label
Definition: PFTauDecayModeTools.cc:11
ElectronSeed.h
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:318