CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ReducedEGProducer.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <vector>
3 #include <memory>
4 
5 // Framework
8 
10 
15 
16 
28 
29 
32 
35 
38 
43 
45 
47  keepPhotonSel_(config.getParameter<std::string>("keepPhotons")),
48  slimRelinkPhotonSel_(config.getParameter<std::string>("slimRelinkPhotons")),
49  relinkPhotonSel_(config.getParameter<std::string>("relinkPhotons")),
50  keepGsfElectronSel_(config.getParameter<std::string>("keepGsfElectrons")),
51  slimRelinkGsfElectronSel_(config.getParameter<std::string>("slimRelinkGsfElectrons")),
52  relinkGsfElectronSel_(config.getParameter<std::string>("relinkGsfElectrons"))
53 {
54 
55 
56  photonT_ = consumes<reco::PhotonCollection>(config.getParameter<edm::InputTag>("photons"));
57  gsfElectronT_ = consumes<reco::GsfElectronCollection>(config.getParameter<edm::InputTag>("gsfElectrons"));
58  conversionT_ = consumes<reco::ConversionCollection>(config.getParameter<edm::InputTag>("conversions"));
59  singleConversionT_ = consumes<reco::ConversionCollection>(config.getParameter<edm::InputTag>("singleConversions"));
60 
62  consumes<EcalRecHitCollection>(config.getParameter<edm::InputTag>("barrelEcalHits"));
64  consumes<EcalRecHitCollection>(config.getParameter<edm::InputTag>("endcapEcalHits"));
66  consumes<EcalRecHitCollection>(config.getParameter<edm::InputTag>("preshowerEcalHits"));
67 
68  photonPfCandMapT_ = consumes<edm::ValueMap<std::vector<reco::PFCandidateRef> > >(config.getParameter<edm::InputTag>("photonsPFValMap"));
69  gsfElectronPfCandMapT_ = consumes<edm::ValueMap<std::vector<reco::PFCandidateRef> > >(config.getParameter<edm::InputTag>("gsfElectronsPFValMap"));
70 
71  std::vector<edm::InputTag> photonidinputs(config.getParameter<std::vector<edm::InputTag> >("photonIDSources"));
72  for (edm::InputTag &tag : photonidinputs) {
74  }
75 
76  std::vector<edm::InputTag> gsfelectronidinputs(config.getParameter<std::vector<edm::InputTag> >("gsfElectronIDSources"));
77  for (edm::InputTag &tag : gsfelectronidinputs) {
79  }
80 
81  //output collections
82  outPhotons_ = "reducedGedPhotons";
83  outPhotonCores_ = "reducedGedPhotonCores";
84  outGsfElectrons_ = "reducedGedGsfElectrons";
85  outGsfElectronCores_ = "reducedGedGsfElectronCores";
86  outConversions_ = "reducedConversions";
87  outSingleConversions_ = "reducedSingleLegConversions";
88  outSuperClusters_ = "reducedSuperClusters";
89  outEBEEClusters_ = "reducedEBEEClusters";
90  outESClusters_ = "reducedESClusters";
91  outEBRecHits_ = "reducedEBRecHits";
92  outEERecHits_ = "reducedEERecHits";
93  outESRecHits_ = "reducedESRecHits";
94  outPhotonPfCandMap_ = "reducedPhotonPfCandMap";
95  outGsfElectronPfCandMap_ = "reducedGsfElectronPfCandMap";
96  outPhotonIds_ = config.getParameter<std::vector<std::string> >("photonIDOutput");
97  outGsfElectronIds_ = config.getParameter<std::vector<std::string> >("gsfElectronIDOutput");
98 
99 
100  produces< reco::PhotonCollection >(outPhotons_);
101  produces< reco::PhotonCoreCollection >(outPhotonCores_);
102  produces< reco::GsfElectronCollection >(outGsfElectrons_);
103  produces< reco::GsfElectronCoreCollection >(outGsfElectronCores_);
104  produces< reco::ConversionCollection >(outConversions_);
105  produces< reco::ConversionCollection >(outSingleConversions_);
106  produces< reco::SuperClusterCollection >(outSuperClusters_);
107  produces< reco::CaloClusterCollection >(outEBEEClusters_);
108  produces< reco::CaloClusterCollection >(outESClusters_);
109  produces< EcalRecHitCollection >(outEBRecHits_);
110  produces< EcalRecHitCollection >(outEERecHits_);
111  produces< EcalRecHitCollection >(outESRecHits_);
112  produces< edm::ValueMap<std::vector<reco::PFCandidateRef> > >(outPhotonPfCandMap_);
113  produces< edm::ValueMap<std::vector<reco::PFCandidateRef> > >(outGsfElectronPfCandMap_);
114  for (const std::string &outid : outPhotonIds_) {
115  produces< edm::ValueMap<bool> >(outid);
116  }
117  for (const std::string &outid : outGsfElectronIds_) {
118  produces< edm::ValueMap<float> >(outid);
119  }
120 
121 }
122 
124 {
125 }
126 
127 
128 
129 
130 void ReducedEGProducer::produce(edm::Event& theEvent, const edm::EventSetup& theEventSetup) {
131 
132  //get input collections
133 
134 
136  theEvent.getByToken(photonT_, photonHandle);
137 
139  theEvent.getByToken(gsfElectronT_, gsfElectronHandle);
140 
142  theEvent.getByToken(conversionT_, conversionHandle);
143 
144  edm::Handle<reco::ConversionCollection> singleConversionHandle;
145  theEvent.getByToken(singleConversionT_, singleConversionHandle);
146 
147  edm::Handle<EcalRecHitCollection> barrelHitHandle;
148  theEvent.getByToken(barrelEcalHits_, barrelHitHandle);
149 
150  edm::Handle<EcalRecHitCollection> endcapHitHandle;
151  theEvent.getByToken(endcapEcalHits_, endcapHitHandle);
152 
153  edm::Handle<EcalRecHitCollection> preshowerHitHandle;
154  theEvent.getByToken(preshowerEcalHits_, preshowerHitHandle);
155 
157  theEvent.getByToken(photonPfCandMapT_, photonPfCandMapHandle);
158 
160  theEvent.getByToken(gsfElectronPfCandMapT_, gsfElectronPfCandMapHandle);
161 
162  std::vector<edm::Handle<edm::ValueMap<bool> > > photonIdHandles(photonIdTs_.size());
163  for (unsigned int itok=0; itok<photonIdTs_.size(); ++itok) {
164  theEvent.getByToken(photonIdTs_[itok],photonIdHandles[itok]);
165  }
166 
167  std::vector<edm::Handle<edm::ValueMap<float> > > gsfElectronIdHandles(gsfElectronIdTs_.size());
168  for (unsigned int itok=0; itok<gsfElectronIdTs_.size(); ++itok) {
169  theEvent.getByToken(gsfElectronIdTs_[itok],gsfElectronIdHandles[itok]);
170  }
171 
172  edm::ESHandle<CaloTopology> theCaloTopology;
173  theEventSetup.get<CaloTopologyRecord>().get(theCaloTopology);
174  const CaloTopology *caloTopology = & (*theCaloTopology);
175 
176  //initialize output collections
177  std::auto_ptr<reco::PhotonCollection> photons(new reco::PhotonCollection);
178  std::auto_ptr<reco::PhotonCoreCollection> photonCores(new reco::PhotonCoreCollection);
179  std::auto_ptr<reco::GsfElectronCollection> gsfElectrons(new reco::GsfElectronCollection);
180  std::auto_ptr<reco::GsfElectronCoreCollection> gsfElectronCores(new reco::GsfElectronCoreCollection);
181  std::auto_ptr<reco::ConversionCollection> conversions(new reco::ConversionCollection);
182  std::auto_ptr<reco::ConversionCollection> singleConversions(new reco::ConversionCollection);
183  std::auto_ptr<reco::SuperClusterCollection> superClusters(new reco::SuperClusterCollection);
184  std::auto_ptr<reco::CaloClusterCollection> ebeeClusters(new reco::CaloClusterCollection);
185  std::auto_ptr<reco::CaloClusterCollection> esClusters(new reco::CaloClusterCollection);
186  std::auto_ptr<EcalRecHitCollection> ebRecHits(new EcalRecHitCollection);
187  std::auto_ptr<EcalRecHitCollection> eeRecHits(new EcalRecHitCollection);
188  std::auto_ptr<EcalRecHitCollection> esRecHits(new EcalRecHitCollection);
189  std::auto_ptr<edm::ValueMap<std::vector<reco::PFCandidateRef> > > photonPfCandMap(new edm::ValueMap<std::vector<reco::PFCandidateRef> >);
190  std::auto_ptr<edm::ValueMap<std::vector<reco::PFCandidateRef> > > gsfElectronPfCandMap(new edm::ValueMap<std::vector<reco::PFCandidateRef> >);
191 
192  std::vector<std::auto_ptr<edm::ValueMap<bool> > > photonIds;
193  for (unsigned int iid=0; iid<photonIdHandles.size(); ++iid) {
194  photonIds.emplace_back(new edm::ValueMap<bool>);
195  }
196 
197  std::vector<std::auto_ptr<edm::ValueMap<float> > > gsfElectronIds;
198  for (unsigned int iid=0; iid<gsfElectronIdHandles.size(); ++iid) {
199  gsfElectronIds.emplace_back(new edm::ValueMap<float>);
200  }
201 
202  //maps to collection indices of output objects
203  std::map<reco::PhotonCoreRef, unsigned int> photonCoreMap;
204  std::map<reco::GsfElectronCoreRef, unsigned int> gsfElectronCoreMap;
205  std::map<reco::ConversionRef, unsigned int> conversionMap;
206  std::map<reco::ConversionRef, unsigned int> singleConversionMap;
207  std::map<reco::SuperClusterRef, unsigned int> superClusterMap;
208  std::map<reco::CaloClusterPtr, unsigned int> ebeeClusterMap;
209  std::map<reco::CaloClusterPtr, unsigned int> esClusterMap;
210  std::set<DetId> rechitMap;
211 
212  std::set<unsigned int> superClusterFullRelinkMap;
213 
214  //vectors for pfcandidate valuemaps
215  std::vector<std::vector<reco::PFCandidateRef>> pfCandIsoPairVecPho;
216  std::vector<std::vector<reco::PFCandidateRef>> pfCandIsoPairVecEle;
217 
218  //vectors for id valuemaps
219  std::vector<std::vector<bool> > photonIdVals(photonIds.size());
220  std::vector<std::vector<float> > gsfElectronIdVals(gsfElectronIds.size());
221 
222  //loop over photons and fill maps
223  for (unsigned int ipho=0; ipho<photonHandle->size(); ++ipho) {
224  const reco::Photon &photon = (*photonHandle)[ipho];
225 
226  bool keep = keepPhotonSel_(photon);
227  if (!keep) continue;
228 
229  reco::PhotonRef photonref(photonHandle,ipho);
230 
231  photons->push_back(photon);
232 
233  //fill pf candidate value map vector
234  pfCandIsoPairVecPho.push_back((*photonPfCandMapHandle)[photonref]);
235 
236  //fill photon id valuemap vectors
237  for (unsigned int iid=0; iid<photonIds.size(); ++iid) {
238  photonIdVals[iid].push_back( (*photonIdHandles[iid])[photonref] );
239  }
240 
241  const reco::PhotonCoreRef &photonCore = photon.photonCore();
242  if (!photonCoreMap.count(photonCore)) {
243  photonCores->push_back(*photonCore);
244  photonCoreMap[photonCore] = photonCores->size() - 1;
245  }
246 
247  bool slimRelink = slimRelinkPhotonSel_(photon);
248  //no supercluster relinking unless slimRelink selection is satisfied
249  if (!slimRelink) continue;
250 
251  bool relink = relinkPhotonSel_(photon);
252 
253  const reco::SuperClusterRef &superCluster = photon.superCluster();
254  const auto &mappedsc = superClusterMap.find(superCluster);
255  //get index in output collection in order to keep track whether superCluster
256  //will be subject to full relinking
257  unsigned int mappedscidx = 0;
258  if (mappedsc==superClusterMap.end()) {
259  superClusters->push_back(*superCluster);
260  mappedscidx = superClusters->size() - 1;
261  superClusterMap[superCluster] = mappedscidx;
262  }
263  else {
264  mappedscidx = mappedsc->second;
265  }
266 
267  //additionally mark supercluster for full relinking
268  if (relink) superClusterFullRelinkMap.insert(mappedscidx);
269 
270  //conversions only for full relinking
271  if (!relink) continue;
272 
273  const reco::ConversionRefVector &convrefs = photon.conversions();
274  for (const reco::ConversionRef &convref : convrefs) {
275  if (!conversionMap.count(convref)) {
276  conversions->push_back(*convref);
277  conversionMap[convref] = conversions->size() - 1;
278  }
279  }
280 
281  //explicitly references conversions
282  const reco::ConversionRefVector &singleconvrefs = photon.conversionsOneLeg();
283  for (const reco::ConversionRef &convref : singleconvrefs) {
284  if (!singleConversionMap.count(convref)) {
285  singleConversions->push_back(*convref);
286  singleConversionMap[convref] = singleConversions->size() - 1;
287  }
288  }
289 
290  }
291 
292  //loop over electrons and fill maps
293  for (unsigned int iele = 0; iele<gsfElectronHandle->size(); ++iele) {
294  const reco::GsfElectron &gsfElectron = (*gsfElectronHandle)[iele];
295 
296  bool keep = keepGsfElectronSel_(gsfElectron);
297  if (!keep) continue;
298 
299  reco::GsfElectronRef gsfElectronref(gsfElectronHandle,iele);
300 
301  gsfElectrons->push_back(gsfElectron);
302  pfCandIsoPairVecEle.push_back((*gsfElectronPfCandMapHandle)[gsfElectronref]);
303 
304  //fill electron id valuemap vectors
305  for (unsigned int iid=0; iid<gsfElectronIds.size(); ++iid) {
306  gsfElectronIdVals[iid].push_back( (*gsfElectronIdHandles[iid])[gsfElectronref] );
307  }
308 
309  const reco::GsfElectronCoreRef &gsfElectronCore = gsfElectron.core();
310  if (!gsfElectronCoreMap.count(gsfElectronCore)) {
311  gsfElectronCores->push_back(*gsfElectronCore);
312  gsfElectronCoreMap[gsfElectronCore] = gsfElectronCores->size() - 1;
313  }
314 
315  bool slimRelink = slimRelinkGsfElectronSel_(gsfElectron);
316  //no supercluster relinking unless slimRelink selection is satisfied
317  if (!slimRelink) continue;
318 
319  bool relink = relinkGsfElectronSel_(gsfElectron);
320 
321  const reco::SuperClusterRef &superCluster = gsfElectron.superCluster();
322  const auto &mappedsc = superClusterMap.find(superCluster);
323  //get index in output collection in order to keep track whether superCluster
324  //will be subject to full relinking
325  unsigned int mappedscidx = 0;
326  if (mappedsc==superClusterMap.end()) {
327  superClusters->push_back(*superCluster);
328  mappedscidx = superClusters->size() - 1;
329  superClusterMap[superCluster] = mappedscidx;
330  }
331  else {
332  mappedscidx = mappedsc->second;
333  }
334 
335  //additionally mark supercluster for full relinking
336  if (relink) superClusterFullRelinkMap.insert(mappedscidx);
337 
338  //conversions only for full relinking
339  if (!relink) continue;
340 
341  //conversions matched by trackrefs
342  for (unsigned int iconv = 0; iconv<conversionHandle->size(); ++iconv) {
343  const reco::Conversion &conversion = (*conversionHandle)[iconv];
344  reco::ConversionRef convref(conversionHandle,iconv);
345 
346  bool matched = ConversionTools::matchesConversion(gsfElectron,conversion,true,true);
347  if (!matched) continue;
348 
349  if (!conversionMap.count(convref)) {
350  conversions->push_back(conversion);
351  conversionMap[convref] = conversions->size() - 1;
352  }
353 
354  }
355 
356  //single leg conversions matched by trackrefs
357  for (unsigned int iconv = 0; iconv<singleConversionHandle->size(); ++iconv) {
358  const reco::Conversion &conversion = (*singleConversionHandle)[iconv];
359  reco::ConversionRef convref(singleConversionHandle,iconv);
360 
361  bool matched = ConversionTools::matchesConversion(gsfElectron,conversion,true,true);
362  if (!matched) continue;
363 
364  if (!singleConversionMap.count(convref)) {
365  singleConversions->push_back(conversion);
366  singleConversionMap[convref] = singleConversions->size() - 1;
367  }
368 
369  }
370 
371  }
372 
373  //loop over output SuperClusters and fill maps
374  for (unsigned int isc = 0; isc<superClusters->size(); ++isc) {
375  reco::SuperCluster &superCluster = (*superClusters)[isc];
376 
377  //link seed cluster no matter what
378  if (!ebeeClusterMap.count(superCluster.seed())) {
379  ebeeClusters->push_back(*superCluster.seed());
380  ebeeClusterMap[superCluster.seed()] = ebeeClusters->size() - 1;
381  }
382 
383  //only proceed if superCluster is marked for full relinking
384  bool fullrelink = superClusterFullRelinkMap.count(isc);
385  if (!fullrelink) {
386  //zero detid vector which is anyways not useful without stored rechits
387  superCluster.clearHitsAndFractions();
388  continue;
389  }
390 
391  for (const reco::CaloClusterPtr &cluster : superCluster.clusters()) {
392  if (!ebeeClusterMap.count(cluster)) {
393  ebeeClusters->push_back(*cluster);
394  ebeeClusterMap[cluster] = ebeeClusters->size() - 1;
395  }
396  for (std::pair<DetId,float> hitfrac : cluster->hitsAndFractions()) {
397  rechitMap.insert(hitfrac.first);
398  }
399  //make sure to also take all hits in the 5x5 around the max energy xtal
400  bool barrel = cluster->hitsAndFractions().front().first.subdetId()==EcalBarrel;
401  const EcalRecHitCollection *rhcol = barrel ? barrelHitHandle.product() : endcapHitHandle.product();
402  DetId seed = EcalClusterTools::getMaximum(*cluster, rhcol).first;
403 
404  std::vector<DetId> dets5x5 = (barrel) ? caloTopology->getSubdetectorTopology(DetId::Ecal,EcalBarrel)->getWindow(seed,5,5) : caloTopology->getSubdetectorTopology(DetId::Ecal,EcalEndcap)->getWindow(seed,5,5);
405  for (const DetId &detid : dets5x5) {
406  rechitMap.insert(detid);
407  }
408  }
409  for (const reco::CaloClusterPtr &cluster : superCluster.preshowerClusters()) {
410  if (!esClusterMap.count(cluster)) {
411  esClusters->push_back(*cluster);
412  esClusterMap[cluster] = esClusters->size() - 1;
413  }
414  for (std::pair<DetId,float> hitfrac : cluster->hitsAndFractions()) {
415  rechitMap.insert(hitfrac.first);
416  }
417  }
418 
419  //conversions matched geometrically
420  for (unsigned int iconv = 0; iconv<conversionHandle->size(); ++iconv) {
421  const reco::Conversion &conversion = (*conversionHandle)[iconv];
422  reco::ConversionRef convref(conversionHandle,iconv);
423 
424  bool matched = ConversionTools::matchesConversion(superCluster,conversion,0.2);
425  if (!matched) continue;
426 
427  if (!conversionMap.count(convref)) {
428  conversions->push_back(conversion);
429  conversionMap[convref] = conversions->size() - 1;
430  }
431 
432  }
433 
434  //single leg conversions matched by trackrefs
435  for (unsigned int iconv = 0; iconv<singleConversionHandle->size(); ++iconv) {
436  const reco::Conversion &conversion = (*singleConversionHandle)[iconv];
437  reco::ConversionRef convref(singleConversionHandle,iconv);
438 
439  bool matched = ConversionTools::matchesConversion(superCluster,conversion,0.2);
440  if (!matched) continue;
441 
442  if (!singleConversionMap.count(convref)) {
443  singleConversions->push_back(conversion);
444  singleConversionMap[convref] = singleConversions->size() - 1;
445  }
446 
447  }
448 
449  }
450 
451  //now finalize and add to the event collections in "reverse" order
452 
453  //rechits (fill output collections of rechits to be stored)
454  for (const EcalRecHit &rechit : *barrelHitHandle) {
455  if (rechitMap.count(rechit.detid())) {
456  ebRecHits->push_back(rechit);
457  }
458  }
459 
460  for (const EcalRecHit &rechit : *endcapHitHandle) {
461  if (rechitMap.count(rechit.detid())) {
462  eeRecHits->push_back(rechit);
463  }
464  }
465 
466  for (const EcalRecHit &rechit : *preshowerHitHandle) {
467  if (rechitMap.count(rechit.detid())) {
468  esRecHits->push_back(rechit);
469  }
470  }
471 
472  theEvent.put(ebRecHits,outEBRecHits_);
473  theEvent.put(eeRecHits,outEERecHits_);
474  theEvent.put(esRecHits,outESRecHits_);
475 
476 
477  //CaloClusters
478  //put calocluster output collections in event and get orphan handles to create ptrs
479  const edm::OrphanHandle<reco::CaloClusterCollection> &outEBEEClusterHandle = theEvent.put(ebeeClusters,outEBEEClusters_);
480  const edm::OrphanHandle<reco::CaloClusterCollection> &outESClusterHandle = theEvent.put(esClusters,outESClusters_);;
481 
482  //loop over output superclusters and relink to output caloclusters
483  for (reco::SuperCluster &superCluster : *superClusters) {
484  //remap seed cluster
485  const auto &seedmapped = ebeeClusterMap.find(superCluster.seed());
486  if (seedmapped != ebeeClusterMap.end()) {
487  //make new ptr
488  reco::CaloClusterPtr clusptr(outEBEEClusterHandle,seedmapped->second);
489  superCluster.setSeed(clusptr);
490  }
491 
492  //remap all clusters
494  for (const reco::CaloClusterPtr &cluster : superCluster.clusters()) {
495  const auto &clustermapped = ebeeClusterMap.find(cluster);
496  if (clustermapped != ebeeClusterMap.end()) {
497  //make new ptr
498  reco::CaloClusterPtr clusptr(outEBEEClusterHandle,clustermapped->second);
499  clusters.push_back(clusptr);
500  }
501  else {
502  //can only relink if all clusters are being relinked, so if one is missing, then skip the relinking completely
503  clusters.clear();
504  break;
505  }
506  }
507  if (clusters.size()) {
508  superCluster.setClusters(clusters);
509  }
510 
511  //remap preshower clusters
512  reco::CaloClusterPtrVector esclusters;
513  for (const reco::CaloClusterPtr &cluster : superCluster.preshowerClusters()) {
514  const auto &clustermapped = esClusterMap.find(cluster);
515  if (clustermapped != esClusterMap.end()) {
516  //make new ptr
517  reco::CaloClusterPtr clusptr(outESClusterHandle,clustermapped->second);
518  esclusters.push_back(clusptr);
519  }
520  else {
521  //can only relink if all clusters are being relinked, so if one is missing, then skip the relinking completely
522  esclusters.clear();
523  break;
524  }
525  }
526  if (esclusters.size()) {
527  superCluster.setPreshowerClusters(esclusters);
528  }
529 
530  }
531 
532  //put superclusters and conversions in the event
533  const edm::OrphanHandle<reco::SuperClusterCollection> &outSuperClusterHandle = theEvent.put(superClusters,outSuperClusters_);
534  const edm::OrphanHandle<reco::ConversionCollection> &outConversionHandle = theEvent.put(conversions,outConversions_);
535  const edm::OrphanHandle<reco::ConversionCollection> &outSingleConversionHandle = theEvent.put(singleConversions,outSingleConversions_);
536 
537  //loop over photoncores and relink superclusters (and conversions)
538  for (reco::PhotonCore &photonCore : *photonCores) {
539  const auto &scmapped = superClusterMap.find(photonCore.superCluster());
540  if (scmapped != superClusterMap.end()) {
541  //make new ref
542  reco::SuperClusterRef scref(outSuperClusterHandle,scmapped->second);
543  photonCore.setSuperCluster(scref);
544  }
545 
546  //conversions
547  const reco::ConversionRefVector &convrefs = photonCore.conversions();
548  reco::ConversionRefVector outconvrefs;
549  for (const reco::ConversionRef &convref : convrefs) {
550  const auto &convmapped = conversionMap.find(convref);
551  if (convmapped != conversionMap.end()) {
552  //make new ref
553  reco::ConversionRef outref(outConversionHandle,convmapped->second);
554  }
555  else {
556  //can only relink if all conversions are being relinked, so if one is missing, then skip the relinking completely
557  outconvrefs.clear();
558  break;
559  }
560  }
561  if (outconvrefs.size()) {
562  photonCore.setConversions(outconvrefs);
563  }
564 
565  //single leg conversions
566  const reco::ConversionRefVector &singleconvrefs = photonCore.conversionsOneLeg();
567  reco::ConversionRefVector outsingleconvrefs;
568  for (const reco::ConversionRef &convref : singleconvrefs) {
569  const auto &convmapped = singleConversionMap.find(convref);
570  if (convmapped != singleConversionMap.end()) {
571  //make new ref
572  reco::ConversionRef outref(outSingleConversionHandle,convmapped->second);
573  }
574  else {
575  //can only relink if all conversions are being relinked, so if one is missing, then skip the relinking completely
576  outsingleconvrefs.clear();
577  break;
578  }
579  }
580  if (outsingleconvrefs.size()) {
581  photonCore.setConversionsOneLeg(outsingleconvrefs);
582  }
583 
584  }
585 
586  //loop over gsfelectroncores and relink superclusters
587  for (reco::GsfElectronCore &gsfElectronCore : *gsfElectronCores) {
588  const auto &scmapped = superClusterMap.find(gsfElectronCore.superCluster());
589  if (scmapped != superClusterMap.end()) {
590  //make new ref
591  reco::SuperClusterRef scref(outSuperClusterHandle,scmapped->second);
592  gsfElectronCore.setSuperCluster(scref);
593  }
594  }
595 
596  //put photon and gsfelectroncores into the event
597  const edm::OrphanHandle<reco::PhotonCoreCollection> &outPhotonCoreHandle = theEvent.put(photonCores,outPhotonCores_);
598  const edm::OrphanHandle<reco::GsfElectronCoreCollection> &outgsfElectronCoreHandle = theEvent.put(gsfElectronCores,outGsfElectronCores_);
599 
600  //loop over photons and electrons and relink the cores
601  for (reco::Photon &photon : *photons) {
602  const auto &coremapped = photonCoreMap.find(photon.photonCore());
603  if (coremapped != photonCoreMap.end()) {
604  //make new ref
605  reco::PhotonCoreRef coreref(outPhotonCoreHandle,coremapped->second);
606  photon.setPhotonCore(coreref);
607  }
608  }
609 
610  for (reco::GsfElectron &gsfElectron : *gsfElectrons) {
611  const auto &coremapped = gsfElectronCoreMap.find(gsfElectron.core());
612  if (coremapped != gsfElectronCoreMap.end()) {
613  //make new ref
614  reco::GsfElectronCoreRef coreref(outgsfElectronCoreHandle,coremapped->second);
615  gsfElectron.setCore(coreref);
616  }
617  }
618 
619  //(finally) store the output photon and electron collections
620  const edm::OrphanHandle<reco::PhotonCollection> &outPhotonHandle = theEvent.put(photons,outPhotons_);
621  const edm::OrphanHandle<reco::GsfElectronCollection> &outGsfElectronHandle = theEvent.put(gsfElectrons,outGsfElectrons_);
622 
623  //still need to output relinked valuemaps
624 
625  //photon pfcand isolation valuemap
626  edm::ValueMap<std::vector<reco::PFCandidateRef>>::Filler fillerPhotons(*photonPfCandMap);
627  fillerPhotons.insert(outPhotonHandle,pfCandIsoPairVecPho.begin(),pfCandIsoPairVecPho.end());
628  fillerPhotons.fill();
629 
630  //electron pfcand isolation valuemap
631  edm::ValueMap<std::vector<reco::PFCandidateRef>>::Filler fillerGsfElectrons(*gsfElectronPfCandMap);
632  fillerGsfElectrons.insert(outGsfElectronHandle,pfCandIsoPairVecEle.begin(),pfCandIsoPairVecEle.end());
633  fillerGsfElectrons.fill();
634 
635  theEvent.put(photonPfCandMap,outPhotonPfCandMap_);
636  theEvent.put(gsfElectronPfCandMap,outGsfElectronPfCandMap_);
637 
638  //photon id value maps
639  for (unsigned int iid=0; iid<photonIds.size(); ++iid) {
640  edm::ValueMap<bool>::Filler fillerPhotonId(*photonIds[iid]);
641  fillerPhotonId.insert(outPhotonHandle,photonIdVals[iid].begin(),photonIdVals[iid].end());
642  fillerPhotonId.fill();
643  theEvent.put(photonIds[iid],outPhotonIds_[iid]);
644  }
645 
646  //electron id value maps
647  for (unsigned int iid=0; iid<gsfElectronIds.size(); ++iid) {
648  edm::ValueMap<float>::Filler fillerGsfElectronId(*gsfElectronIds[iid]);
649  fillerGsfElectronId.insert(outGsfElectronHandle,gsfElectronIdVals[iid].begin(),gsfElectronIdVals[iid].end());
650  fillerGsfElectronId.fill();
651  theEvent.put(gsfElectronIds[iid],outGsfElectronIds_[iid]);
652  }
653 
654 }
655 
656 
T getParameter(std::string const &) const
edm::EDGetTokenT< reco::GsfElectronCollection > gsfElectronT_
static bool matchesConversion(const reco::GsfElectron &ele, const reco::Conversion &conv, bool allowCkfMatch=true, bool allowAmbiguousGsfMatch=false)
edm::EDGetTokenT< reco::ConversionCollection > conversionT_
std::string outPhotonCores_
std::string outGsfElectronCores_
size_type size() const
Size of the RefVector.
Definition: PtrVectorBase.h:73
edm::EDGetTokenT< EcalRecHitCollection > endcapEcalHits_
edm::EDGetTokenT< EcalRecHitCollection > barrelEcalHits_
std::vector< std::string > outPhotonIds_
std::string outPhotonPfCandMap_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
reco::ConversionRefVector conversionsOneLeg() const
vector of references to one leg Conversion&#39;s
Definition: Photon.h:69
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:138
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
reco::SuperClusterRef superCluster() const
Ref to SuperCluster.
Definition: Photon.cc:58
StringCutObjectSelector< reco::Photon > keepPhotonSel_
const CaloClusterPtrVector & clusters() const
const access to the cluster list itself
Definition: SuperCluster.h:69
edm::EDGetTokenT< edm::ValueMap< std::vector< reco::PFCandidateRef > > > photonPfCandMapT_
std::string outGsfElectrons_
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
std::vector< Conversion > ConversionCollection
collectin of Conversion objects
Definition: ConversionFwd.h:9
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::EDGetTokenT< reco::PhotonCollection > photonT_
reco::PhotonCoreRef photonCore() const
returns a reference to the core photon object
Definition: Photon.h:49
std::string outGsfElectronPfCandMap_
std::string outEERecHits_
const int keep
edm::EDGetTokenT< EcalRecHitCollection > preshowerEcalHits_
std::string outSingleConversions_
edm::EDGetTokenT< edm::ValueMap< std::vector< reco::PFCandidateRef > > > gsfElectronPfCandMapT_
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
reco::ConversionRefVector conversions() const
vector of references to Conversion&#39;s
Definition: Photon.h:63
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
virtual SuperClusterRef superCluster() const
reference to a SuperCluster
Definition: GsfElectron.h:169
std::vector< GsfElectronCore > GsfElectronCoreCollection
StringCutObjectSelector< reco::Photon > slimRelinkPhotonSel_
std::vector< CaloCluster > CaloClusterCollection
collection of CaloCluster objects
#define end
Definition: vmac.h:37
std::vector< edm::EDGetTokenT< edm::ValueMap< float > > > gsfElectronIdTs_
const CaloClusterPtrVector & preshowerClusters() const
const access to the preshower cluster list itself
Definition: SuperCluster.h:72
StringCutObjectSelector< reco::Photon > relinkPhotonSel_
edm::EDGetTokenT< reco::ConversionCollection > singleConversionT_
StringCutObjectSelector< reco::GsfElectron > relinkGsfElectronSel_
Definition: DetId.h:18
void clearHitsAndFractions()
Definition: SuperCluster.h:108
void conversion(EventAux const &from, EventAuxiliary &to)
Definition: EventAux.cc:9
virtual std::vector< DetId > getWindow(const DetId &id, const int &northSouthSize, const int &eastWestSize) const
void clear()
Clear the vector.
Definition: RefVector.h:133
std::vector< std::string > outGsfElectronIds_
const T & get() const
Definition: EventSetup.h:55
std::string outConversions_
const CaloSubdetectorTopology * getSubdetectorTopology(const DetId &id) const
access the subdetector Topology for the given subdetector directly
Definition: CaloTopology.cc:26
std::vector< Photon > PhotonCollection
collectin of Photon objects
Definition: PhotonFwd.h:9
StringCutObjectSelector< reco::GsfElectron > slimRelinkGsfElectronSel_
T const * product() const
Definition: Handle.h:81
virtual GsfElectronCoreRef core() const
Definition: GsfElectron.cc:8
std::vector< PhotonCore > PhotonCoreCollection
collectin of PhotonCore objects
Definition: PhotonCoreFwd.h:9
std::string outESRecHits_
void clear()
Clear the PtrVector.
Definition: PtrVectorBase.h:79
size_t size() const
size in number of hits (e.g. in crystals for ECAL)
Definition: CaloCluster.h:167
#define begin
Definition: vmac.h:30
virtual void produce(edm::Event &evt, const edm::EventSetup &es)
void push_back(value_type const &ref)
Add a Ref&lt;C, T&gt; to the RefVector.
Definition: RefVector.h:64
std::string outSuperClusters_
size_type size() const
Size of the RefVector.
Definition: RefVector.h:89
std::string outEBEEClusters_
const CaloClusterPtr & seed() const
seed BasicCluster
Definition: SuperCluster.h:66
std::vector< edm::EDGetTokenT< edm::ValueMap< bool > > > photonIdTs_
std::string outEBRecHits_
std::string outPhotons_
std::string outESClusters_
StringCutObjectSelector< reco::GsfElectron > keepGsfElectronSel_
ReducedEGProducer(const edm::ParameterSet &ps)