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