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