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  const reco::ConversionRefVector &convrefs = gsfElectron.core()->conversions();
342  for (const reco::ConversionRef &convref : convrefs) {
343  if (!conversionMap.count(convref)) {
344  conversions->push_back(*convref);
345  conversionMap[convref] = conversions->size() - 1;
346  }
347  }
348 
349  //explicitly references conversions
350  const reco::ConversionRefVector &singleconvrefs = gsfElectron.core()->conversionsOneLeg();
351  for (const reco::ConversionRef &convref : singleconvrefs) {
352  if (!singleConversionMap.count(convref)) {
353  singleConversions->push_back(*convref);
354  singleConversionMap[convref] = singleConversions->size() - 1;
355  }
356  }
357 
358  //conversions matched by trackrefs
359  for (unsigned int iconv = 0; iconv<conversionHandle->size(); ++iconv) {
360  const reco::Conversion &conversion = (*conversionHandle)[iconv];
361  reco::ConversionRef convref(conversionHandle,iconv);
362 
363  bool matched = ConversionTools::matchesConversion(gsfElectron,conversion,true,true);
364  if (!matched) continue;
365 
366  if (!conversionMap.count(convref)) {
367  conversions->push_back(conversion);
368  conversionMap[convref] = conversions->size() - 1;
369  }
370 
371  }
372 
373  //single leg conversions matched by trackrefs
374  for (unsigned int iconv = 0; iconv<singleConversionHandle->size(); ++iconv) {
375  const reco::Conversion &conversion = (*singleConversionHandle)[iconv];
376  reco::ConversionRef convref(singleConversionHandle,iconv);
377 
378  bool matched = ConversionTools::matchesConversion(gsfElectron,conversion,true,true);
379  if (!matched) continue;
380 
381  if (!singleConversionMap.count(convref)) {
382  singleConversions->push_back(conversion);
383  singleConversionMap[convref] = singleConversions->size() - 1;
384  }
385 
386  }
387 
388  }
389 
390  //loop over output SuperClusters and fill maps
391  for (unsigned int isc = 0; isc<superClusters->size(); ++isc) {
392  reco::SuperCluster &superCluster = (*superClusters)[isc];
393 
394  //link seed cluster no matter what
395  if (!ebeeClusterMap.count(superCluster.seed())) {
396  ebeeClusters->push_back(*superCluster.seed());
397  ebeeClusterMap[superCluster.seed()] = ebeeClusters->size() - 1;
398  }
399 
400  //only proceed if superCluster is marked for full relinking
401  bool fullrelink = superClusterFullRelinkMap.count(isc);
402  if (!fullrelink) {
403  //zero detid vector which is anyways not useful without stored rechits
404  superCluster.clearHitsAndFractions();
405  continue;
406  }
407 
408  for (const reco::CaloClusterPtr &cluster : superCluster.clusters()) {
409  if (!ebeeClusterMap.count(cluster)) {
410  ebeeClusters->push_back(*cluster);
411  ebeeClusterMap[cluster] = ebeeClusters->size() - 1;
412  }
413  for (std::pair<DetId,float> hitfrac : cluster->hitsAndFractions()) {
414  rechitMap.insert(hitfrac.first);
415  }
416  //make sure to also take all hits in the 5x5 around the max energy xtal
417  bool barrel = cluster->hitsAndFractions().front().first.subdetId()==EcalBarrel;
418  const EcalRecHitCollection *rhcol = barrel ? barrelHitHandle.product() : endcapHitHandle.product();
419  DetId seed = EcalClusterTools::getMaximum(*cluster, rhcol).first;
420 
421  std::vector<DetId> dets5x5 = (barrel) ? caloTopology->getSubdetectorTopology(DetId::Ecal,EcalBarrel)->getWindow(seed,5,5) : caloTopology->getSubdetectorTopology(DetId::Ecal,EcalEndcap)->getWindow(seed,5,5);
422  for (const DetId &detid : dets5x5) {
423  rechitMap.insert(detid);
424  }
425  }
426  for (const reco::CaloClusterPtr &cluster : superCluster.preshowerClusters()) {
427  if (!esClusterMap.count(cluster)) {
428  esClusters->push_back(*cluster);
429  esClusterMap[cluster] = esClusters->size() - 1;
430  }
431  for (std::pair<DetId,float> hitfrac : cluster->hitsAndFractions()) {
432  rechitMap.insert(hitfrac.first);
433  }
434  }
435 
436  //conversions matched geometrically
437  for (unsigned int iconv = 0; iconv<conversionHandle->size(); ++iconv) {
438  const reco::Conversion &conversion = (*conversionHandle)[iconv];
439  reco::ConversionRef convref(conversionHandle,iconv);
440 
441  bool matched = ConversionTools::matchesConversion(superCluster,conversion,0.2);
442  if (!matched) continue;
443 
444  if (!conversionMap.count(convref)) {
445  conversions->push_back(conversion);
446  conversionMap[convref] = conversions->size() - 1;
447  }
448 
449  }
450 
451  //single leg conversions matched by trackrefs
452  for (unsigned int iconv = 0; iconv<singleConversionHandle->size(); ++iconv) {
453  const reco::Conversion &conversion = (*singleConversionHandle)[iconv];
454  reco::ConversionRef convref(singleConversionHandle,iconv);
455 
456  bool matched = ConversionTools::matchesConversion(superCluster,conversion,0.2);
457  if (!matched) continue;
458 
459  if (!singleConversionMap.count(convref)) {
460  singleConversions->push_back(conversion);
461  singleConversionMap[convref] = singleConversions->size() - 1;
462  }
463 
464  }
465 
466  }
467 
468  //now finalize and add to the event collections in "reverse" order
469 
470  //rechits (fill output collections of rechits to be stored)
471  for (const EcalRecHit &rechit : *barrelHitHandle) {
472  if (rechitMap.count(rechit.detid())) {
473  ebRecHits->push_back(rechit);
474  }
475  }
476 
477  for (const EcalRecHit &rechit : *endcapHitHandle) {
478  if (rechitMap.count(rechit.detid())) {
479  eeRecHits->push_back(rechit);
480  }
481  }
482 
483  for (const EcalRecHit &rechit : *preshowerHitHandle) {
484  if (rechitMap.count(rechit.detid())) {
485  esRecHits->push_back(rechit);
486  }
487  }
488 
489  theEvent.put(ebRecHits,outEBRecHits_);
490  theEvent.put(eeRecHits,outEERecHits_);
491  theEvent.put(esRecHits,outESRecHits_);
492 
493 
494  //CaloClusters
495  //put calocluster output collections in event and get orphan handles to create ptrs
496  const edm::OrphanHandle<reco::CaloClusterCollection> &outEBEEClusterHandle = theEvent.put(ebeeClusters,outEBEEClusters_);
497  const edm::OrphanHandle<reco::CaloClusterCollection> &outESClusterHandle = theEvent.put(esClusters,outESClusters_);;
498 
499  //loop over output superclusters and relink to output caloclusters
500  for (reco::SuperCluster &superCluster : *superClusters) {
501  //remap seed cluster
502  const auto &seedmapped = ebeeClusterMap.find(superCluster.seed());
503  if (seedmapped != ebeeClusterMap.end()) {
504  //make new ptr
505  reco::CaloClusterPtr clusptr(outEBEEClusterHandle,seedmapped->second);
506  superCluster.setSeed(clusptr);
507  }
508 
509  //remap all clusters
511  for (const reco::CaloClusterPtr &cluster : superCluster.clusters()) {
512  const auto &clustermapped = ebeeClusterMap.find(cluster);
513  if (clustermapped != ebeeClusterMap.end()) {
514  //make new ptr
515  reco::CaloClusterPtr clusptr(outEBEEClusterHandle,clustermapped->second);
516  clusters.push_back(clusptr);
517  }
518  else {
519  //can only relink if all clusters are being relinked, so if one is missing, then skip the relinking completely
520  clusters.clear();
521  break;
522  }
523  }
524  if (clusters.size()) {
525  superCluster.setClusters(clusters);
526  }
527 
528  //remap preshower clusters
529  reco::CaloClusterPtrVector esclusters;
530  for (const reco::CaloClusterPtr &cluster : superCluster.preshowerClusters()) {
531  const auto &clustermapped = esClusterMap.find(cluster);
532  if (clustermapped != esClusterMap.end()) {
533  //make new ptr
534  reco::CaloClusterPtr clusptr(outESClusterHandle,clustermapped->second);
535  esclusters.push_back(clusptr);
536  }
537  else {
538  //can only relink if all clusters are being relinked, so if one is missing, then skip the relinking completely
539  esclusters.clear();
540  break;
541  }
542  }
543  if (esclusters.size()) {
544  superCluster.setPreshowerClusters(esclusters);
545  }
546 
547  }
548 
549  //put superclusters and conversions in the event
550  const edm::OrphanHandle<reco::SuperClusterCollection> &outSuperClusterHandle = theEvent.put(superClusters,outSuperClusters_);
551  const edm::OrphanHandle<reco::ConversionCollection> &outConversionHandle = theEvent.put(conversions,outConversions_);
552  const edm::OrphanHandle<reco::ConversionCollection> &outSingleConversionHandle = theEvent.put(singleConversions,outSingleConversions_);
553 
554  //loop over photoncores and relink superclusters (and conversions)
555  for (reco::PhotonCore &photonCore : *photonCores) {
556  const auto &scmapped = superClusterMap.find(photonCore.superCluster());
557  if (scmapped != superClusterMap.end()) {
558  //make new ref
559  reco::SuperClusterRef scref(outSuperClusterHandle,scmapped->second);
560  photonCore.setSuperCluster(scref);
561  }
562 
563  //conversions
564  const reco::ConversionRefVector &convrefs = photonCore.conversions();
565  reco::ConversionRefVector outconvrefs;
566  for (const reco::ConversionRef &convref : convrefs) {
567  const auto &convmapped = conversionMap.find(convref);
568  if (convmapped != conversionMap.end()) {
569  //make new ref
570  reco::ConversionRef outref(outConversionHandle,convmapped->second);
571  }
572  else {
573  //can only relink if all conversions are being relinked, so if one is missing, then skip the relinking completely
574  outconvrefs.clear();
575  break;
576  }
577  }
578  if (outconvrefs.size()) {
579  photonCore.setConversions(outconvrefs);
580  }
581 
582  //single leg conversions
583  const reco::ConversionRefVector &singleconvrefs = photonCore.conversionsOneLeg();
584  reco::ConversionRefVector outsingleconvrefs;
585  for (const reco::ConversionRef &convref : singleconvrefs) {
586  const auto &convmapped = singleConversionMap.find(convref);
587  if (convmapped != singleConversionMap.end()) {
588  //make new ref
589  reco::ConversionRef outref(outSingleConversionHandle,convmapped->second);
590  }
591  else {
592  //can only relink if all conversions are being relinked, so if one is missing, then skip the relinking completely
593  outsingleconvrefs.clear();
594  break;
595  }
596  }
597  if (outsingleconvrefs.size()) {
598  photonCore.setConversionsOneLeg(outsingleconvrefs);
599  }
600 
601  }
602 
603  //loop over gsfelectroncores and relink superclusters
604  for (reco::GsfElectronCore &gsfElectronCore : *gsfElectronCores) {
605  const auto &scmapped = superClusterMap.find(gsfElectronCore.superCluster());
606  if (scmapped != superClusterMap.end()) {
607  //make new ref
608  reco::SuperClusterRef scref(outSuperClusterHandle,scmapped->second);
609  gsfElectronCore.setSuperCluster(scref);
610  }
611  }
612 
613  //put photon and gsfelectroncores into the event
614  const edm::OrphanHandle<reco::PhotonCoreCollection> &outPhotonCoreHandle = theEvent.put(photonCores,outPhotonCores_);
615  const edm::OrphanHandle<reco::GsfElectronCoreCollection> &outgsfElectronCoreHandle = theEvent.put(gsfElectronCores,outGsfElectronCores_);
616 
617  //loop over photons and electrons and relink the cores
618  for (reco::Photon &photon : *photons) {
619  const auto &coremapped = photonCoreMap.find(photon.photonCore());
620  if (coremapped != photonCoreMap.end()) {
621  //make new ref
622  reco::PhotonCoreRef coreref(outPhotonCoreHandle,coremapped->second);
623  photon.setPhotonCore(coreref);
624  }
625  }
626 
627  for (reco::GsfElectron &gsfElectron : *gsfElectrons) {
628  const auto &coremapped = gsfElectronCoreMap.find(gsfElectron.core());
629  if (coremapped != gsfElectronCoreMap.end()) {
630  //make new ref
631  reco::GsfElectronCoreRef coreref(outgsfElectronCoreHandle,coremapped->second);
632  gsfElectron.setCore(coreref);
633  }
634  }
635 
636  //(finally) store the output photon and electron collections
637  const edm::OrphanHandle<reco::PhotonCollection> &outPhotonHandle = theEvent.put(photons,outPhotons_);
638  const edm::OrphanHandle<reco::GsfElectronCollection> &outGsfElectronHandle = theEvent.put(gsfElectrons,outGsfElectrons_);
639 
640  //still need to output relinked valuemaps
641 
642  //photon pfcand isolation valuemap
643  edm::ValueMap<std::vector<reco::PFCandidateRef>>::Filler fillerPhotons(*photonPfCandMap);
644  fillerPhotons.insert(outPhotonHandle,pfCandIsoPairVecPho.begin(),pfCandIsoPairVecPho.end());
645  fillerPhotons.fill();
646 
647  //electron pfcand isolation valuemap
648  edm::ValueMap<std::vector<reco::PFCandidateRef>>::Filler fillerGsfElectrons(*gsfElectronPfCandMap);
649  fillerGsfElectrons.insert(outGsfElectronHandle,pfCandIsoPairVecEle.begin(),pfCandIsoPairVecEle.end());
650  fillerGsfElectrons.fill();
651 
652  theEvent.put(photonPfCandMap,outPhotonPfCandMap_);
653  theEvent.put(gsfElectronPfCandMap,outGsfElectronPfCandMap_);
654 
655  //photon id value maps
656  for (unsigned int iid=0; iid<photonIds.size(); ++iid) {
657  edm::ValueMap<bool>::Filler fillerPhotonId(*photonIds[iid]);
658  fillerPhotonId.insert(outPhotonHandle,photonIdVals[iid].begin(),photonIdVals[iid].end());
659  fillerPhotonId.fill();
660  theEvent.put(photonIds[iid],outPhotonIds_[iid]);
661  }
662 
663  //electron id value maps
664  for (unsigned int iid=0; iid<gsfElectronIds.size(); ++iid) {
665  edm::ValueMap<float>::Filler fillerGsfElectronId(*gsfElectronIds[iid]);
666  fillerGsfElectronId.insert(outGsfElectronHandle,gsfElectronIdVals[iid].begin(),gsfElectronIdVals[iid].end());
667  fillerGsfElectronId.fill();
668  theEvent.put(gsfElectronIds[iid],outGsfElectronIds_[iid]);
669  }
670 
671 }
672 
673 
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:182
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)