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