CMS 3D CMS Logo

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