CMS 3D CMS Logo

ReducedEGProducer.cc
Go to the documentation of this file.
1 
42 
43 #include <memory>
44 #include <unordered_set>
45 #include <vector>
46 
48 public:
50 
51  void beginRun(edm::Run const&, const edm::EventSetup&) final;
52  void produce(edm::Event& evt, const edm::EventSetup& es) final;
53 
54 private:
55  template <class T>
56  std::vector<edm::EDPutTokenT<T>> vproduces(std::vector<std::string> const& labels) {
57  std::vector<edm::EDPutTokenT<T>> putTokens{};
58  putTokens.reserve(labels.size());
59  for (const auto& label : labels) {
60  putTokens.push_back(produces<T>(label));
61  }
62  return putTokens;
63  }
64 
65  template <typename T, typename U>
66  void linkCore(const T& core, U& cores, std::map<T, unsigned int>& coreMap);
67 
68  void linkSuperCluster(const reco::SuperClusterRef& superCluster,
69  std::map<reco::SuperClusterRef, unsigned int>& superClusterMap,
71  const bool relink,
72  std::unordered_set<unsigned int>& superClusterFullRelinkMap);
73 
74  void linkConversions(const reco::ConversionRefVector& convrefs,
76  std::map<reco::ConversionRef, unsigned int>& conversionMap);
77 
79  const reco::GsfElectron& gsfElectron,
81  std::map<reco::ConversionRef, unsigned int>& conversionMap);
82 
84  const reco::SuperCluster& superCluster,
86  std::map<reco::ConversionRef, unsigned int>& conversionMap);
87 
88  void linkConversion(const reco::ConversionRef& convref,
90  std::map<reco::ConversionRef, unsigned int>& conversionMap);
91 
92  void linkCaloCluster(const reco::CaloClusterPtr& caloCluster,
93  reco::CaloClusterCollection& caloClusters,
94  std::map<reco::CaloClusterPtr, unsigned int>& caloClusterMap);
95 
96  void linkCaloClusters(const reco::SuperCluster& superCluster,
97  reco::CaloClusterCollection& ebeeClusters,
98  std::map<reco::CaloClusterPtr, unsigned int>& ebeeClusterMap,
99  std::unordered_set<DetId>& rechitMap,
100  const edm::Handle<EcalRecHitCollection>& barrelHitHandle,
101  const edm::Handle<EcalRecHitCollection>& endcapHitHandle,
102  CaloTopology const& caloTopology,
103  reco::CaloClusterCollection& esClusters,
104  std::map<reco::CaloClusterPtr, unsigned int>& esClusterMap);
105 
106  void linkHcalHits(const reco::SuperCluster& superClus,
108  std::unordered_set<DetId>& hcalDetIds);
109 
110  void relinkCaloClusters(reco::SuperCluster& superCluster,
111  const std::map<reco::CaloClusterPtr, unsigned int>& ebeeClusterMap,
112  const std::map<reco::CaloClusterPtr, unsigned int>& esClusterMap,
113  const edm::OrphanHandle<reco::CaloClusterCollection>& outEBEEClusterHandle,
114  const edm::OrphanHandle<reco::CaloClusterCollection>& outESClusterHandle);
115 
116  template <typename T>
117  void relinkSuperCluster(T& core,
118  const std::map<reco::SuperClusterRef, unsigned int>& superClusterMap,
119  const edm::OrphanHandle<reco::SuperClusterCollection>& outSuperClusterHandle);
120 
121  void relinkGsfTrack(reco::GsfElectronCore& electroncore,
122  const std::map<reco::GsfTrackRef, unsigned int>& gsfTrackMap,
123  const edm::OrphanHandle<reco::GsfTrackCollection>& outGsfTrackHandle);
124 
126  const reco::ConversionRefVector& convrefs,
127  const std::map<reco::ConversionRef, unsigned int>& conversionMap,
128  const edm::OrphanHandle<reco::ConversionCollection>& outConversionHandle);
129 
131  const std::map<reco::PhotonCoreRef, unsigned int>& photonCoreMap,
132  const edm::OrphanHandle<reco::PhotonCoreCollection>& outPhotonCoreHandle);
133 
134  void relinkGsfElectronCore(reco::GsfElectron& gsfElectron,
135  const std::map<reco::GsfElectronCoreRef, unsigned int>& gsfElectronCoreMap,
136  const edm::OrphanHandle<reco::GsfElectronCoreCollection>& outGsfElectronCoreHandle);
137 
138  static void calibratePhoton(reco::Photon& photon,
139  const reco::PhotonRef& oldPhoRef,
140  const edm::ValueMap<float>& energyMap,
141  const edm::ValueMap<float>& energyErrMap);
142 
143  static void calibrateElectron(reco::GsfElectron& gsfElectron,
144  const reco::GsfElectronRef& oldEleRef,
145  const edm::ValueMap<float>& energyMap,
146  const edm::ValueMap<float>& energyErrMap,
147  const edm::ValueMap<float>& ecalEnergyMap,
148  const edm::ValueMap<float>& ecalEnergyErrMap);
149 
150  template <typename T>
152  token = consumes<T>(config.getParameter<edm::InputTag>(name));
153  }
154 
155  //tokens for input collections
161 
167 
170 
171  std::vector<edm::EDGetTokenT<edm::ValueMap<bool>>> photonIdTs_;
172  std::vector<edm::EDGetTokenT<edm::ValueMap<float>>> gsfElectronIdTs_;
173 
174  std::vector<edm::EDGetTokenT<edm::ValueMap<float>>> photonFloatValueMapTs_;
175  std::vector<edm::EDGetTokenT<edm::ValueMap<float>>> ootPhotonFloatValueMapTs_;
176  std::vector<edm::EDGetTokenT<edm::ValueMap<float>>> gsfElectronFloatValueMapTs_;
177 
180 
191 
193  //names for output collections
215  const std::vector<edm::EDPutTokenT<edm::ValueMap<bool>>> outPhotonIds_;
216  const std::vector<edm::EDPutTokenT<edm::ValueMap<float>>> outGsfElectronIds_;
217  const std::vector<edm::EDPutTokenT<edm::ValueMap<float>>> outPhotonFloatValueMaps_;
218  std::vector<edm::EDPutTokenT<edm::ValueMap<float>>> outOOTPhotonFloatValueMaps_;
219  const std::vector<edm::EDPutTokenT<edm::ValueMap<float>>> outGsfElectronFloatValueMaps_;
220 
230 
232 };
233 
236 
237 namespace {
238 
239  template <class T>
240  auto getHandles(edm::Event const& event, std::vector<edm::EDGetTokenT<T>> const& tokens) {
241  std::vector<edm::Handle<T>> handles(tokens.size());
242  int index = 0;
243  for (const auto& token : tokens) {
244  event.getByToken(token, handles[index++]);
245  }
246  return handles;
247  }
248 
249  template <class Handle, class T>
250  auto emplaceValueMap(Handle const& handle,
251  std::vector<T> const& values,
252  edm::Event& ev,
253  edm::EDPutTokenT<edm::ValueMap<T>> const& putToken) {
254  using MapType = edm::ValueMap<T>;
255  MapType oMap{};
256  {
257  typename MapType::Filler filler(oMap);
258  filler.insert(handle, values.begin(), values.end());
259  filler.fill();
260  }
261  ev.emplace(putToken, std::move(oMap));
262  };
263 } // namespace
264 
266  : photonT_(consumes(config.getParameter<edm::InputTag>("photons"))),
267  gsfElectronT_(consumes(config.getParameter<edm::InputTag>("gsfElectrons"))),
268  conversionT_(consumes(config.getParameter<edm::InputTag>("conversions"))),
269  singleConversionT_(consumes(config.getParameter<edm::InputTag>("singleConversions"))),
270  barrelEcalHits_(consumes(config.getParameter<edm::InputTag>("barrelEcalHits"))),
271  endcapEcalHits_(consumes(config.getParameter<edm::InputTag>("endcapEcalHits"))),
272  doPreshowerEcalHits_(!config.getParameter<edm::InputTag>("preshowerEcalHits").label().empty()),
273  preshowerEcalHits_(doPreshowerEcalHits_
274  ? consumes<EcalRecHitCollection>(config.getParameter<edm::InputTag>("preshowerEcalHits"))
275  : edm::EDGetTokenT<EcalRecHitCollection>()),
276  hbheHits_(consumes<HBHERecHitCollection>(config.getParameter<edm::InputTag>("hbheHits"))),
277  photonPfCandMapT_(consumes(config.getParameter<edm::InputTag>("photonsPFValMap"))),
278  gsfElectronPfCandMapT_(consumes(config.getParameter<edm::InputTag>("gsfElectronsPFValMap"))),
279  recoHIPhotonIsolationMapInputToken_{
280  !config.getParameter<edm::InputTag>("hiPhotonIsolationMapInput").label().empty()
281  ? consumes<reco::HIPhotonIsolationMap>(config.getParameter<edm::InputTag>("hiPhotonIsolationMapInput"))
283  //calibration flags
284  applyPhotonCalibOnData_(config.getParameter<bool>("applyPhotonCalibOnData")),
285  applyPhotonCalibOnMC_(config.getParameter<bool>("applyPhotonCalibOnMC")),
286  applyGsfElectronCalibOnData_(config.getParameter<bool>("applyGsfElectronCalibOnData")),
287  applyGsfElectronCalibOnMC_(config.getParameter<bool>("applyGsfElectronCalibOnMC")),
288  //output collections
289  outPhotons_{produces<reco::PhotonCollection>("reducedGedPhotons")},
290  outPhotonCores_{produces<reco::PhotonCoreCollection>("reducedGedPhotonCores")},
291  outGsfElectrons_{produces<reco::GsfElectronCollection>("reducedGedGsfElectrons")},
292  outGsfElectronCores_{produces<reco::GsfElectronCoreCollection>("reducedGedGsfElectronCores")},
293  outGsfTracks_{produces<reco::GsfTrackCollection>("reducedGsfTracks")},
294  outConversions_{produces<reco::ConversionCollection>("reducedConversions")},
295  outSingleConversions_{produces<reco::ConversionCollection>("reducedSingleLegConversions")},
296  outSuperClusters_{produces<reco::SuperClusterCollection>("reducedSuperClusters")},
297  outEBEEClusters_{produces<reco::CaloClusterCollection>("reducedEBEEClusters")},
298  outESClusters_{produces<reco::CaloClusterCollection>("reducedESClusters")},
299  outEBRecHits_{produces<EcalRecHitCollection>("reducedEBRecHits")},
300  outEERecHits_{produces<EcalRecHitCollection>("reducedEERecHits")},
301  outHBHERecHits_{produces<HBHERecHitCollection>("reducedHBHEHits")},
302  outPhotonPfCandMap_{produces<edm::ValueMap<std::vector<reco::PFCandidateRef>>>("reducedPhotonPfCandMap")},
303  outGsfElectronPfCandMap_{
304  produces<edm::ValueMap<std::vector<reco::PFCandidateRef>>>("reducedGsfElectronPfCandMap")},
305  outPhotonIds_{vproduces<edm::ValueMap<bool>>(config.getParameter<std::vector<std::string>>("photonIDOutput"))},
306  outGsfElectronIds_{
307  vproduces<edm::ValueMap<float>>(config.getParameter<std::vector<std::string>>("gsfElectronIDOutput"))},
308  outPhotonFloatValueMaps_{
309  vproduces<edm::ValueMap<float>>(config.getParameter<std::vector<std::string>>("photonFloatValueMapOutput"))},
310  outGsfElectronFloatValueMaps_{vproduces<edm::ValueMap<float>>(
311  config.getParameter<std::vector<std::string>>("gsfElectronFloatValueMapOutput"))},
312  keepPhotonSel_(config.getParameter<std::string>("keepPhotons")),
313  slimRelinkPhotonSel_(config.getParameter<std::string>("slimRelinkPhotons")),
314  relinkPhotonSel_(config.getParameter<std::string>("relinkPhotons")),
315  keepOOTPhotonSel_(config.getParameter<std::string>("keepOOTPhotons")),
316  slimRelinkOOTPhotonSel_(config.getParameter<std::string>("slimRelinkOOTPhotons")),
317  relinkOOTPhotonSel_(config.getParameter<std::string>("relinkOOTPhotons")),
318  keepGsfElectronSel_(config.getParameter<std::string>("keepGsfElectrons")),
319  slimRelinkGsfElectronSel_(config.getParameter<std::string>("slimRelinkGsfElectrons")),
320  relinkGsfElectronSel_(config.getParameter<std::string>("relinkGsfElectrons")),
321  hcalHitSel_(config.getParameter<edm::ParameterSet>("hcalHitSel"), consumesCollector()) {
322  const auto& aTag = config.getParameter<edm::InputTag>("ootPhotons");
323  caloTopology_ = esConsumes();
324  if (not aTag.label().empty())
325  ootPhotonT_ = consumes<reco::PhotonCollection>(aTag);
326 
327  for (const edm::InputTag& tag : config.getParameter<std::vector<edm::InputTag>>("photonIDSources")) {
328  photonIdTs_.emplace_back(consumes<edm::ValueMap<bool>>(tag));
329  }
330 
331  for (const edm::InputTag& tag : config.getParameter<std::vector<edm::InputTag>>("gsfElectronIDSources")) {
332  gsfElectronIdTs_.emplace_back(consumes<edm::ValueMap<float>>(tag));
333  }
334 
335  for (const edm::InputTag& tag : config.getParameter<std::vector<edm::InputTag>>("photonFloatValueMapSources")) {
336  photonFloatValueMapTs_.emplace_back(consumes<edm::ValueMap<float>>(tag));
337  }
338 
339  for (const edm::InputTag& tag : config.getParameter<std::vector<edm::InputTag>>("ootPhotonFloatValueMapSources")) {
340  ootPhotonFloatValueMapTs_.emplace_back(consumes<edm::ValueMap<float>>(tag));
341  }
342 
343  for (const edm::InputTag& tag : config.getParameter<std::vector<edm::InputTag>>("gsfElectronFloatValueMapSources")) {
344  gsfElectronFloatValueMapTs_.emplace_back(consumes<edm::ValueMap<float>>(tag));
345  }
346 
347  if (applyPhotonCalibOnData_ || applyPhotonCalibOnMC_) {
348  setToken(photonCalibEnergyT_, config, "photonCalibEnergySource");
349  setToken(photonCalibEnergyErrT_, config, "photonCalibEnergyErrSource");
350  }
351  if (applyGsfElectronCalibOnData_ || applyGsfElectronCalibOnMC_) {
352  setToken(gsfElectronCalibEnergyT_, config, "gsfElectronCalibEnergySource");
353  setToken(gsfElectronCalibEnergyErrT_, config, "gsfElectronCalibEnergyErrSource");
354  setToken(gsfElectronCalibEcalEnergyT_, config, "gsfElectronCalibEcalEnergySource");
355  setToken(gsfElectronCalibEcalEnergyErrT_, config, "gsfElectronCalibEcalEnergyErrSource");
356  }
357 
358  if (!ootPhotonT_.isUninitialized()) {
359  outOOTPhotons_ = produces<reco::PhotonCollection>("reducedOOTPhotons");
360  outOOTPhotonCores_ = produces<reco::PhotonCoreCollection>("reducedOOTPhotonCores");
361  outOOTSuperClusters_ = produces<reco::SuperClusterCollection>("reducedOOTSuperClusters");
362  outOOTEBEEClusters_ = produces<reco::CaloClusterCollection>("reducedOOTEBEEClusters");
363  outOOTESClusters_ = produces<reco::CaloClusterCollection>("reducedOOTESClusters");
364  }
365  if (doPreshowerEcalHits_) {
366  outESRecHits_ = produces<EcalRecHitCollection>("reducedESRecHits");
367  }
368  if (!ootPhotonT_.isUninitialized()) {
369  outOOTPhotonFloatValueMaps_ =
370  vproduces<edm::ValueMap<float>>(config.getParameter<std::vector<std::string>>("ootPhotonFloatValueMapOutput"));
371  }
372  if (!recoHIPhotonIsolationMapInputToken_.isUninitialized()) {
373  recoHIPhotonIsolationMapOutputName_ =
374  produces<reco::HIPhotonIsolationMap>(config.getParameter<std::string>("hiPhotonIsolationMapOutput"));
375  }
376 }
377 
379 
381  //get input collections
382 
383  auto photonHandle = event.getHandle(photonT_);
384 
385  auto ootPhotonHandle =
387 
388  auto gsfElectronHandle = event.getHandle(gsfElectronT_);
389  auto conversionHandle = event.getHandle(conversionT_);
390  auto singleConversionHandle = event.getHandle(singleConversionT_);
391  auto barrelHitHandle = event.getHandle(barrelEcalHits_);
392  auto endcapHitHandle = event.getHandle(endcapEcalHits_);
393 
394  auto preshowerHitHandle =
396 
397  auto hbheHitHandle = event.getHandle(hbheHits_);
398  auto photonPfCandMapHandle = event.getHandle(photonPfCandMapT_);
399  auto gsfElectronPfCandMapHandle = event.getHandle(gsfElectronPfCandMapT_);
400 
401  auto photonIdHandles = getHandles(event, photonIdTs_);
402  auto gsfElectronIdHandles = getHandles(event, gsfElectronIdTs_);
403  auto photonFloatValueMapHandles = getHandles(event, photonFloatValueMapTs_);
404 
405  auto ootPhotonFloatValueMapHandles = !ootPhotonT_.isUninitialized()
406  ? getHandles(event, ootPhotonFloatValueMapTs_)
407  : std::vector<edm::Handle<edm::ValueMap<float>>>{};
408 
409  auto gsfElectronFloatValueMapHandles = getHandles(event, gsfElectronFloatValueMapTs_);
410 
411  edm::Handle<edm::ValueMap<float>> gsfElectronCalibEnergyHandle;
412  edm::Handle<edm::ValueMap<float>> gsfElectronCalibEnergyErrHandle;
413  edm::Handle<edm::ValueMap<float>> gsfElectronCalibEcalEnergyHandle;
414  edm::Handle<edm::ValueMap<float>> gsfElectronCalibEcalEnergyErrHandle;
416  event.getByToken(gsfElectronCalibEnergyT_, gsfElectronCalibEnergyHandle);
417  event.getByToken(gsfElectronCalibEnergyErrT_, gsfElectronCalibEnergyErrHandle);
418  event.getByToken(gsfElectronCalibEcalEnergyT_, gsfElectronCalibEcalEnergyHandle);
419  event.getByToken(gsfElectronCalibEcalEnergyErrT_, gsfElectronCalibEcalEnergyErrHandle);
420  }
421  edm::Handle<edm::ValueMap<float>> photonCalibEnergyHandle;
422  edm::Handle<edm::ValueMap<float>> photonCalibEnergyErrHandle;
424  event.getByToken(photonCalibEnergyT_, photonCalibEnergyHandle);
425  event.getByToken(photonCalibEnergyErrT_, photonCalibEnergyErrHandle);
426  }
427 
428  auto const& caloTopology = eventSetup.getData(caloTopology_);
429 
430  //initialize output collections
432  reco::PhotonCoreCollection photonCores;
434  reco::PhotonCoreCollection ootPhotonCores;
436  reco::GsfElectronCoreCollection gsfElectronCores;
441  reco::CaloClusterCollection ebeeClusters;
442  reco::CaloClusterCollection esClusters;
443  reco::SuperClusterCollection ootSuperClusters;
444  reco::CaloClusterCollection ootEbeeClusters;
445  reco::CaloClusterCollection ootEsClusters;
446  EcalRecHitCollection ebRecHits;
447  EcalRecHitCollection eeRecHits;
448  EcalRecHitCollection esRecHits;
452 
453  //maps to collection indices of output objects
454  std::map<reco::PhotonCoreRef, unsigned int> photonCoreMap;
455  std::map<reco::PhotonCoreRef, unsigned int> ootPhotonCoreMap;
456  std::map<reco::GsfElectronCoreRef, unsigned int> gsfElectronCoreMap;
457  std::map<reco::GsfTrackRef, unsigned int> gsfTrackMap;
458  std::map<reco::ConversionRef, unsigned int> conversionMap;
459  std::map<reco::ConversionRef, unsigned int> singleConversionMap;
460  std::map<reco::SuperClusterRef, unsigned int> superClusterMap;
461  std::map<reco::CaloClusterPtr, unsigned int> ebeeClusterMap;
462  std::map<reco::CaloClusterPtr, unsigned int> esClusterMap;
463  std::map<reco::SuperClusterRef, unsigned int> ootSuperClusterMap;
464  std::map<reco::CaloClusterPtr, unsigned int> ootEbeeClusterMap;
465  std::map<reco::CaloClusterPtr, unsigned int> ootEsClusterMap;
466  std::unordered_set<DetId> rechitMap;
467  std::unordered_set<DetId> hcalRechitMap;
468 
469  std::unordered_set<unsigned int> superClusterFullRelinkMap;
470  std::unordered_set<unsigned int> ootSuperClusterFullRelinkMap;
471 
472  //vectors for pfcandidate valuemaps
473  std::vector<std::vector<reco::PFCandidateRef>> pfCandIsoPairVecPho;
474  std::vector<std::vector<reco::PFCandidateRef>> pfCandIsoPairVecEle;
475 
476  //vectors for id valuemaps
477  std::vector<std::vector<bool>> photonIdVals(photonIdHandles.size());
478  std::vector<std::vector<float>> gsfElectronIdVals(gsfElectronIdHandles.size());
479  std::vector<std::vector<float>> photonFloatValueMapVals(photonFloatValueMapHandles.size());
480  std::vector<std::vector<float>> ootPhotonFloatValueMapVals(ootPhotonFloatValueMapHandles.size());
481  std::vector<std::vector<float>> gsfElectronFloatValueMapVals(gsfElectronFloatValueMapHandles.size());
482 
483  // HI photon iso value maps
484  reco::HIPhotonIsolationMap const* recoHIPhotonIsolationMapInputValueMap =
486  : nullptr;
487  std::vector<reco::HIPhotonIsolation> recoHIPhotonIsolationMapInputVals;
488 
489  //loop over photons and fill maps
490  int index = -1;
491  for (const auto& photon : *photonHandle) {
492  index++;
493 
494  reco::PhotonRef photonref(photonHandle, index);
495  photons.push_back(photon);
496  auto& newPhoton = photons.back();
497 
498  if ((applyPhotonCalibOnData_ && event.isRealData()) || (applyPhotonCalibOnMC_ && !event.isRealData())) {
499  calibratePhoton(newPhoton, photonref, *photonCalibEnergyHandle, *photonCalibEnergyErrHandle);
500  }
501 
502  //we do this after calibration
503  bool keep = keepPhotonSel_(newPhoton);
504  if (!keep) {
505  photons.pop_back();
506  continue;
507  }
508 
509  //fill pf candidate value map vector
510  pfCandIsoPairVecPho.push_back((*photonPfCandMapHandle)[photonref]);
511 
512  //fill photon id valuemap vectors
513  int subindex = 0;
514  for (const auto& photonIdHandle : photonIdHandles) {
515  photonIdVals[subindex++].push_back((*photonIdHandle)[photonref]);
516  }
517 
518  subindex = 0;
519  for (const auto& photonFloatValueMapHandle : photonFloatValueMapHandles) {
520  photonFloatValueMapVals[subindex++].push_back((*photonFloatValueMapHandle)[photonref]);
521  }
522 
523  // HI photon isolation
524  if (!recoHIPhotonIsolationMapInputToken_.isUninitialized()) {
525  recoHIPhotonIsolationMapInputVals.push_back((*recoHIPhotonIsolationMapInputValueMap)[photonref]);
526  }
527 
528  //link photon core
529  const reco::PhotonCoreRef& photonCore = photon.photonCore();
530  linkCore(photonCore, photonCores, photonCoreMap);
531 
532  bool slimRelink = slimRelinkPhotonSel_(newPhoton);
533  //no supercluster relinking unless slimRelink selection is satisfied
534  if (!slimRelink)
535  continue;
536 
537  bool relink = relinkPhotonSel_(newPhoton);
538 
539  //link supercluster
540  const reco::SuperClusterRef& superCluster = photon.superCluster();
541  linkSuperCluster(superCluster, superClusterMap, superClusters, relink, superClusterFullRelinkMap);
542 
543  //conversions only for full relinking
544  if (!relink)
545  continue;
546 
547  const reco::ConversionRefVector& convrefs = photon.conversions();
548  linkConversions(convrefs, conversions, conversionMap);
549 
550  //explicitly references conversions
551  const reco::ConversionRefVector& singleconvrefs = photon.conversionsOneLeg();
552  linkConversions(singleconvrefs, singleConversions, singleConversionMap);
553 
554  //hcal hits
555  linkHcalHits(*photon.superCluster(), *hbheHitHandle, hcalRechitMap);
556  }
557 
558  //loop over oot photons and fill maps
559  //special note1: since not PFCand --> no PF isolation, IDs (but we do have FloatValueMap!)
560  //special note2: conversion sequence not run over bcs from oot phos, so skip relinking of oot phos
561  //special note3: clusters and superclusters in own collections!
562  if (!ootPhotonT_.isUninitialized()) {
563  index = -1;
564  for (const auto& ootPhoton : *ootPhotonHandle) {
565  index++;
566 
567  bool keep = keepOOTPhotonSel_(ootPhoton);
568  if (!keep)
569  continue;
570 
571  reco::PhotonRef ootPhotonref(ootPhotonHandle, index);
572 
573  ootPhotons.push_back(ootPhoton);
574 
575  //fill photon pfclusteriso valuemap vectors
576  int subindex = 0;
577  for (const auto& ootPhotonFloatValueMapHandle : ootPhotonFloatValueMapHandles) {
578  ootPhotonFloatValueMapVals[subindex++].push_back((*ootPhotonFloatValueMapHandle)[ootPhotonref]);
579  }
580 
581  //link photon core
582  const reco::PhotonCoreRef& ootPhotonCore = ootPhoton.photonCore();
583  linkCore(ootPhotonCore, ootPhotonCores, ootPhotonCoreMap);
584 
585  bool slimRelink = slimRelinkOOTPhotonSel_(ootPhoton);
586  //no supercluster relinking unless slimRelink selection is satisfied
587  if (!slimRelink)
588  continue;
589 
590  bool relink = relinkOOTPhotonSel_(ootPhoton);
591 
592  const reco::SuperClusterRef& ootSuperCluster = ootPhoton.superCluster();
593  linkSuperCluster(ootSuperCluster, ootSuperClusterMap, ootSuperClusters, relink, ootSuperClusterFullRelinkMap);
594  //hcal hits
595  linkHcalHits(*ootPhoton.superCluster(), *hbheHitHandle, hcalRechitMap);
596  }
597  }
598 
599  //loop over electrons and fill maps
600  index = -1;
601  for (const auto& gsfElectron : *gsfElectronHandle) {
602  index++;
603 
604  reco::GsfElectronRef gsfElectronref(gsfElectronHandle, index);
605  gsfElectrons.push_back(gsfElectron);
606  auto& newGsfElectron = gsfElectrons.back();
607  if ((applyGsfElectronCalibOnData_ && event.isRealData()) || (applyGsfElectronCalibOnMC_ && !event.isRealData())) {
608  calibrateElectron(newGsfElectron,
609  gsfElectronref,
610  *gsfElectronCalibEnergyHandle,
611  *gsfElectronCalibEnergyErrHandle,
612  *gsfElectronCalibEcalEnergyHandle,
613  *gsfElectronCalibEcalEnergyErrHandle);
614  }
615 
616  bool keep = keepGsfElectronSel_(newGsfElectron);
617  if (!keep) {
618  gsfElectrons.pop_back();
619  continue;
620  }
621 
622  pfCandIsoPairVecEle.push_back((*gsfElectronPfCandMapHandle)[gsfElectronref]);
623 
624  //fill electron id valuemap vectors
625  int subindex = 0;
626  for (const auto& gsfElectronIdHandle : gsfElectronIdHandles) {
627  gsfElectronIdVals[subindex++].push_back((*gsfElectronIdHandle)[gsfElectronref]);
628  }
629 
630  subindex = 0;
631  for (const auto& gsfElectronFloatValueMapHandle : gsfElectronFloatValueMapHandles) {
632  gsfElectronFloatValueMapVals[subindex++].push_back((*gsfElectronFloatValueMapHandle)[gsfElectronref]);
633  }
634 
635  const reco::GsfElectronCoreRef& gsfElectronCore = gsfElectron.core();
636  linkCore(gsfElectronCore, gsfElectronCores, gsfElectronCoreMap);
637 
638  const reco::GsfTrackRef& gsfTrack = gsfElectron.gsfTrack();
639 
640  // Save the main gsfTrack
641  if (!gsfTrackMap.count(gsfTrack)) {
642  gsfTracks.push_back(*gsfTrack);
643  gsfTrackMap[gsfTrack] = gsfTracks.size() - 1;
644  }
645 
646  // Save additional ambiguous gsf tracks in a map:
647  for (auto const& ambigGsfTrack : gsfElectron.ambiguousGsfTracks()) {
648  if (!gsfTrackMap.count(ambigGsfTrack)) {
649  gsfTracks.push_back(*ambigGsfTrack);
650  gsfTrackMap[ambigGsfTrack] = gsfTracks.size() - 1;
651  }
652  }
653 
654  bool slimRelink = slimRelinkGsfElectronSel_(newGsfElectron);
655  //no supercluster relinking unless slimRelink selection is satisfied
656  if (!slimRelink)
657  continue;
658 
659  bool relink = relinkGsfElectronSel_(newGsfElectron);
660 
661  const reco::SuperClusterRef& superCluster = gsfElectron.superCluster();
662  linkSuperCluster(superCluster, superClusterMap, superClusters, relink, superClusterFullRelinkMap);
663 
664  //conversions only for full relinking
665  if (!relink)
666  continue;
667 
668  const reco::ConversionRefVector& convrefs = gsfElectron.core()->conversions();
669  linkConversions(convrefs, conversions, conversionMap);
670 
671  //explicitly references conversions
672  const reco::ConversionRefVector& singleconvrefs = gsfElectron.core()->conversionsOneLeg();
673  linkConversions(singleconvrefs, singleConversions, singleConversionMap);
674 
675  //conversions matched by trackrefs
676  linkConversionsByTrackRef(conversionHandle, gsfElectron, conversions, conversionMap);
677 
678  //single leg conversions matched by trackrefs
679  linkConversionsByTrackRef(singleConversionHandle, gsfElectron, singleConversions, singleConversionMap);
680 
681  //hcal hits
682  linkHcalHits(*gsfElectron.superCluster(), *hbheHitHandle, hcalRechitMap);
683  }
684 
685  //loop over output SuperClusters and fill maps
686  index = 0;
687  for (auto& superCluster : superClusters) {
688  //link seed cluster no matter what
689  const reco::CaloClusterPtr& seedCluster = superCluster.seed();
690  linkCaloCluster(seedCluster, ebeeClusters, ebeeClusterMap);
691 
692  //only proceed if superCluster is marked for full relinking
693  bool fullrelink = superClusterFullRelinkMap.count(index++);
694  if (!fullrelink) {
695  //zero detid vector which is anyways not useful without stored rechits
696  superCluster.clearHitsAndFractions();
697  continue;
698  }
699 
700  // link calo clusters
701  linkCaloClusters(superCluster,
702  ebeeClusters,
703  ebeeClusterMap,
704  rechitMap,
705  barrelHitHandle,
706  endcapHitHandle,
707  caloTopology,
708  esClusters,
709  esClusterMap);
710 
711  //conversions matched geometrically
712  linkConversionsByTrackRef(conversionHandle, superCluster, conversions, conversionMap);
713 
714  //single leg conversions matched by trackrefs
715  linkConversionsByTrackRef(singleConversionHandle, superCluster, singleConversions, singleConversionMap);
716  }
717 
718  //loop over output OOTSuperClusters and fill maps
719  if (!ootPhotonT_.isUninitialized()) {
720  index = 0;
721  for (auto& ootSuperCluster : ootSuperClusters) {
722  //link seed cluster no matter what
723  const reco::CaloClusterPtr& ootSeedCluster = ootSuperCluster.seed();
724  linkCaloCluster(ootSeedCluster, ootEbeeClusters, ootEbeeClusterMap);
725 
726  //only proceed if ootSuperCluster is marked for full relinking
727  bool fullrelink = ootSuperClusterFullRelinkMap.count(index++);
728  if (!fullrelink) {
729  //zero detid vector which is anyways not useful without stored rechits
730  ootSuperCluster.clearHitsAndFractions();
731  continue;
732  }
733 
734  // link calo clusters
735  linkCaloClusters(ootSuperCluster,
736  ootEbeeClusters,
737  ootEbeeClusterMap,
738  rechitMap,
739  barrelHitHandle,
740  endcapHitHandle,
741  caloTopology,
742  ootEsClusters,
743  ootEsClusterMap);
744  }
745  }
746  //now finalize and add to the event collections in "reverse" order
747 
748  //rechits (fill output collections of rechits to be stored)
749  for (const EcalRecHit& rechit : *barrelHitHandle) {
750  if (rechitMap.count(rechit.detid())) {
751  ebRecHits.push_back(rechit);
752  }
753  }
754 
755  for (const EcalRecHit& rechit : *endcapHitHandle) {
756  if (rechitMap.count(rechit.detid())) {
757  eeRecHits.push_back(rechit);
758  }
759  }
760 
761  event.emplace(outEBRecHits_, std::move(ebRecHits));
762  event.emplace(outEERecHits_, std::move(eeRecHits));
763 
764  if (doPreshowerEcalHits_) {
765  for (const EcalRecHit& rechit : *preshowerHitHandle) {
766  if (rechitMap.count(rechit.detid())) {
767  esRecHits.push_back(rechit);
768  }
769  }
770  event.emplace(outESRecHits_, std::move(esRecHits));
771  }
772 
773  for (const HBHERecHit& rechit : *hbheHitHandle) {
774  if (hcalRechitMap.count(rechit.detid())) {
775  hbheRecHits.push_back(rechit);
776  }
777  }
778  event.emplace(outHBHERecHits_, std::move(hbheRecHits));
779 
780  //CaloClusters
781  //put calocluster output collections in event and get orphan handles to create ptrs
782  const auto& outEBEEClusterHandle = event.emplace(outEBEEClusters_, std::move(ebeeClusters));
783  const auto& outESClusterHandle = event.emplace(outESClusters_, std::move(esClusters));
784  ;
785 
786  //Loop over SuperClusters and relink GEDPhoton + GSFElectron CaloClusters
787  for (reco::SuperCluster& superCluster : superClusters) {
788  relinkCaloClusters(superCluster, ebeeClusterMap, esClusterMap, outEBEEClusterHandle, outESClusterHandle);
789  }
790 
791  //OOTCaloClusters
792  //put ootcalocluster output collections in event and get orphan handles to create ptrs
793  edm::OrphanHandle<reco::CaloClusterCollection> outOOTEBEEClusterHandle;
795  //Loop over OOTSuperClusters and relink OOTPhoton CaloClusters
796  if (!ootPhotonT_.isUninitialized()) {
797  outOOTEBEEClusterHandle = event.emplace(outOOTEBEEClusters_, std::move(ootEbeeClusters));
798  outOOTESClusterHandle = event.emplace(outOOTESClusters_, std::move(ootEsClusters));
799  for (reco::SuperCluster& ootSuperCluster : ootSuperClusters) {
801  ootSuperCluster, ootEbeeClusterMap, ootEsClusterMap, outOOTEBEEClusterHandle, outOOTESClusterHandle);
802  }
803  }
804  //put superclusters and conversions in the event
805  const auto& outSuperClusterHandle = event.emplace(outSuperClusters_, std::move(superClusters));
806  const auto& outConversionHandle = event.emplace(outConversions_, std::move(conversions));
807  const auto& outSingleConversionHandle = event.emplace(outSingleConversions_, std::move(singleConversions));
808  const auto& outGsfTrackHandle = event.emplace(outGsfTracks_, std::move(gsfTracks));
809 
810  //Loop over PhotonCores and relink GEDPhoton SuperClusters (and conversions)
811  for (reco::PhotonCore& photonCore : photonCores) {
812  // superclusters
813  relinkSuperCluster(photonCore, superClusterMap, outSuperClusterHandle);
814 
815  //conversions
816  const reco::ConversionRefVector& convrefs = photonCore.conversions();
817  relinkConversions(photonCore, convrefs, conversionMap, outConversionHandle);
818 
819  //single leg conversions
820  const reco::ConversionRefVector& singleconvrefs = photonCore.conversionsOneLeg();
821  relinkConversions(photonCore, singleconvrefs, singleConversionMap, outSingleConversionHandle);
822  }
823 
824  //Relink GSFElectron SuperClusters and main GSF Tracks
825  for (reco::GsfElectronCore& gsfElectronCore : gsfElectronCores) {
826  relinkSuperCluster(gsfElectronCore, superClusterMap, outSuperClusterHandle);
827  relinkGsfTrack(gsfElectronCore, gsfTrackMap, outGsfTrackHandle);
828  }
829 
830  //put ootsuperclusters in the event
831  edm::OrphanHandle<reco::SuperClusterCollection> outOOTSuperClusterHandle;
833  outOOTSuperClusterHandle = event.emplace(outOOTSuperClusters_, std::move(ootSuperClusters));
834 
835  //Relink OOTPhoton SuperClusters
836  for (reco::PhotonCore& ootPhotonCore : ootPhotonCores) {
837  relinkSuperCluster(ootPhotonCore, ootSuperClusterMap, outOOTSuperClusterHandle);
838  }
839 
840  //put photoncores and gsfelectroncores into the event
841  const auto& outPhotonCoreHandle = event.emplace(outPhotonCores_, std::move(photonCores));
842  edm::OrphanHandle<reco::PhotonCoreCollection> outOOTPhotonCoreHandle;
844  outOOTPhotonCoreHandle = event.emplace(outOOTPhotonCores_, std::move(ootPhotonCores));
845  const auto& outgsfElectronCoreHandle = event.emplace(outGsfElectronCores_, std::move(gsfElectronCores));
846 
847  //loop over photons, oot photons, and electrons and relink the cores
848  for (reco::Photon& photon : photons) {
849  relinkPhotonCore(photon, photonCoreMap, outPhotonCoreHandle);
850  }
851 
852  if (!ootPhotonT_.isUninitialized()) {
853  for (reco::Photon& ootPhoton : ootPhotons) {
854  relinkPhotonCore(ootPhoton, ootPhotonCoreMap, outOOTPhotonCoreHandle);
855  }
856  }
857 
858  for (reco::GsfElectron& gsfElectron : gsfElectrons) {
859  relinkGsfElectronCore(gsfElectron, gsfElectronCoreMap, outgsfElectronCoreHandle);
860 
861  // -----
862  // Also in this loop let's relink ambiguous tracks
863  std::vector<reco::GsfTrackRef> ambigTracksInThisElectron;
864  // Here we loop over the ambiguous tracks and save them in a vector
865  for (auto const& igsf : gsfElectron.ambiguousGsfTracks()) {
866  ambigTracksInThisElectron.push_back(igsf);
867  }
868 
869  // Now we need to clear them (they are the refs to original collection):
870  gsfElectron.clearAmbiguousGsfTracks();
871 
872  // And here we add them back, now from a new reduced collection:
873  for (const auto& it : ambigTracksInThisElectron) {
874  const auto& gsftkmapped = gsfTrackMap.find(it);
875 
876  if (gsftkmapped != gsfTrackMap.end()) {
877  reco::GsfTrackRef gsftkref(outGsfTrackHandle, gsftkmapped->second);
878  gsfElectron.addAmbiguousGsfTrack(gsftkref);
879  } else
880  throw cms::Exception("There must be a problem with linking and mapping of ambiguous gsf tracks...");
881  }
882 
883  if (gsfElectron.ambiguousGsfTracksSize() > 0)
884  gsfElectron.setAmbiguous(true); // Set the flag
885 
886  ambigTracksInThisElectron.clear();
887  }
888 
889  //(finally) store the output photon and electron collections
890  const auto& outPhotonHandle = event.emplace(outPhotons_, std::move(photons));
893  outOOTPhotonHandle = event.emplace(outOOTPhotons_, std::move(ootPhotons));
894  const auto& outGsfElectronHandle = event.emplace(outGsfElectrons_, std::move(gsfElectrons));
895 
896  //still need to output relinked valuemaps
897 
898  //photon pfcand isolation valuemap
899  edm::ValueMap<std::vector<reco::PFCandidateRef>>::Filler fillerPhotons(photonPfCandMap);
900  fillerPhotons.insert(outPhotonHandle, pfCandIsoPairVecPho.begin(), pfCandIsoPairVecPho.end());
901  fillerPhotons.fill();
902 
903  //electron pfcand isolation valuemap
904  edm::ValueMap<std::vector<reco::PFCandidateRef>>::Filler fillerGsfElectrons(gsfElectronPfCandMap);
905  fillerGsfElectrons.insert(outGsfElectronHandle, pfCandIsoPairVecEle.begin(), pfCandIsoPairVecEle.end());
906  fillerGsfElectrons.fill();
907 
908  event.emplace(outPhotonPfCandMap_, std::move(photonPfCandMap));
909  event.emplace(outGsfElectronPfCandMap_, std::move(gsfElectronPfCandMap));
910 
911  //photon id value maps
912  index = 0;
913  for (auto const& vals : photonIdVals) {
914  emplaceValueMap(outPhotonHandle, vals, event, outPhotonIds_[index++]);
915  }
916 
917  //electron id value maps
918  index = 0;
919  for (auto const& vals : gsfElectronIdVals) {
920  emplaceValueMap(outGsfElectronHandle, vals, event, outGsfElectronIds_[index++]);
921  }
922 
923  // photon iso value maps
924  index = 0;
925  for (auto const& vals : photonFloatValueMapVals) {
926  emplaceValueMap(outPhotonHandle, vals, event, outPhotonFloatValueMaps_[index++]);
927  }
928 
929  if (!ootPhotonT_.isUninitialized()) {
930  //oot photon iso value maps
931  index = 0;
932  for (auto const& vals : ootPhotonFloatValueMapVals) {
933  emplaceValueMap(outOOTPhotonHandle, vals, event, outOOTPhotonFloatValueMaps_[index++]);
934  }
935  }
936 
937  // HI photon iso value maps
938  if (!recoHIPhotonIsolationMapInputToken_.isUninitialized()) {
939  emplaceValueMap(outPhotonHandle, recoHIPhotonIsolationMapInputVals, event, recoHIPhotonIsolationMapOutputName_);
940  }
941 
942  //electron iso value maps
943  index = 0;
944  for (auto const& vals : gsfElectronFloatValueMapVals) {
945  emplaceValueMap(outGsfElectronHandle, vals, event, outGsfElectronFloatValueMaps_[index++]);
946  }
947 }
948 
949 template <typename T, typename U>
950 void ReducedEGProducer::linkCore(const T& core, U& cores, std::map<T, unsigned int>& coreMap) {
951  if (!coreMap.count(core)) {
952  cores.push_back(*core);
953  coreMap[core] = cores.size() - 1;
954  }
955 }
956 
958  std::map<reco::SuperClusterRef, unsigned int>& superClusterMap,
960  const bool relink,
961  std::unordered_set<unsigned int>& superClusterFullRelinkMap) {
962  const auto& mappedsc = superClusterMap.find(superCluster);
963  //get index in output collection in order to keep track whether superCluster
964  //will be subject to full relinking
965  unsigned int mappedscidx = 0;
966  if (mappedsc == superClusterMap.end()) {
967  superClusters.push_back(*superCluster);
968  mappedscidx = superClusters.size() - 1;
969  superClusterMap[superCluster] = mappedscidx;
970  } else {
971  mappedscidx = mappedsc->second;
972  }
973 
974  //additionally mark supercluster for full relinking
975  if (relink)
976  superClusterFullRelinkMap.insert(mappedscidx);
977 }
978 
981  std::map<reco::ConversionRef, unsigned int>& conversionMap) {
982  for (const auto& convref : convrefs) {
983  linkConversion(convref, conversions, conversionMap);
984  }
985 }
986 
988  const reco::GsfElectron& gsfElectron,
990  std::map<reco::ConversionRef, unsigned int>& conversionMap) {
991  int index = 0;
992  for (const auto& conversion : *conversionHandle) {
994 
995  bool matched = ConversionTools::matchesConversion(gsfElectron, conversion, true, true);
996  if (!matched)
997  continue;
998 
999  linkConversion(convref, conversions, conversionMap);
1000  }
1001 }
1002 
1004  const reco::SuperCluster& superCluster,
1006  std::map<reco::ConversionRef, unsigned int>& conversionMap) {
1007  int index = 0;
1008  for (const auto& conversion : *conversionHandle) {
1010 
1011  bool matched = ConversionTools::matchesConversion(superCluster, conversion, 0.2);
1012  if (!matched)
1013  continue;
1014 
1015  linkConversion(convref, conversions, conversionMap);
1016  }
1017 }
1018 
1021  std::map<reco::ConversionRef, unsigned int>& conversionMap) {
1022  if (!conversionMap.count(convref)) {
1023  conversions.push_back(*convref);
1024  conversionMap[convref] = conversions.size() - 1;
1025  }
1026 }
1027 
1029  reco::CaloClusterCollection& caloClusters,
1030  std::map<reco::CaloClusterPtr, unsigned int>& caloClusterMap) {
1031  if (!caloClusterMap.count(caloCluster)) {
1032  caloClusters.push_back(*caloCluster);
1033  caloClusterMap[caloCluster] = caloClusters.size() - 1;
1034  }
1035 }
1036 
1038  reco::CaloClusterCollection& ebeeClusters,
1039  std::map<reco::CaloClusterPtr, unsigned int>& ebeeClusterMap,
1040  std::unordered_set<DetId>& rechitMap,
1041  const edm::Handle<EcalRecHitCollection>& barrelHitHandle,
1042  const edm::Handle<EcalRecHitCollection>& endcapHitHandle,
1043  CaloTopology const& caloTopology,
1044  reco::CaloClusterCollection& esClusters,
1045  std::map<reco::CaloClusterPtr, unsigned int>& esClusterMap) {
1046  for (const auto& cluster : superCluster.clusters()) {
1047  linkCaloCluster(cluster, ebeeClusters, ebeeClusterMap);
1048 
1049  for (const auto& hitfrac : cluster->hitsAndFractions()) {
1050  rechitMap.insert(hitfrac.first);
1051  }
1052  //make sure to also take all hits in the 5x5 around the max energy xtal
1053  bool barrel = cluster->hitsAndFractions().front().first.subdetId() == EcalBarrel;
1054  const EcalRecHitCollection* rhcol = barrel ? barrelHitHandle.product() : endcapHitHandle.product();
1055  DetId seed = EcalClusterTools::getMaximum(*cluster, rhcol).first;
1056 
1057  std::vector<DetId> dets5x5 =
1059  for (const auto& detid : dets5x5) {
1060  rechitMap.insert(detid);
1061  }
1062  }
1063  for (const auto& cluster : superCluster.preshowerClusters()) {
1064  linkCaloCluster(cluster, esClusters, esClusterMap);
1065 
1066  for (const auto& hitfrac : cluster->hitsAndFractions()) {
1067  rechitMap.insert(hitfrac.first);
1068  }
1069  }
1070 }
1071 
1074  std::unordered_set<DetId>& hcalDetIds) {
1075  hcalHitSel_.addDetIds(superClus, recHits, hcalDetIds);
1076 }
1077 
1079  const std::map<reco::CaloClusterPtr, unsigned int>& ebeeClusterMap,
1080  const std::map<reco::CaloClusterPtr, unsigned int>& esClusterMap,
1081  const edm::OrphanHandle<reco::CaloClusterCollection>& outEBEEClusterHandle,
1082  const edm::OrphanHandle<reco::CaloClusterCollection>& outESClusterHandle) {
1083  //remap seed cluster
1084  const auto& seedmapped = ebeeClusterMap.find(superCluster.seed());
1085  if (seedmapped != ebeeClusterMap.end()) {
1086  //make new ptr
1087  reco::CaloClusterPtr clusptr(outEBEEClusterHandle, seedmapped->second);
1088  superCluster.setSeed(clusptr);
1089  }
1090 
1091  //remap all clusters
1093  for (const auto& cluster : superCluster.clusters()) {
1094  const auto& clustermapped = ebeeClusterMap.find(cluster);
1095  if (clustermapped != ebeeClusterMap.end()) {
1096  //make new ptr
1097  reco::CaloClusterPtr clusptr(outEBEEClusterHandle, clustermapped->second);
1098  clusters.push_back(clusptr);
1099  } else {
1100  //can only relink if all clusters are being relinked, so if one is missing, then skip the relinking completely
1101  clusters.clear();
1102  break;
1103  }
1104  }
1105  if (!clusters.empty()) {
1106  superCluster.setClusters(clusters);
1107  }
1108 
1109  //remap preshower clusters
1110  reco::CaloClusterPtrVector esclusters;
1111  for (const auto& cluster : superCluster.preshowerClusters()) {
1112  const auto& clustermapped = esClusterMap.find(cluster);
1113  if (clustermapped != esClusterMap.end()) {
1114  //make new ptr
1115  reco::CaloClusterPtr clusptr(outESClusterHandle, clustermapped->second);
1116  esclusters.push_back(clusptr);
1117  } else {
1118  //can only relink if all clusters are being relinked, so if one is missing, then skip the relinking completely
1119  esclusters.clear();
1120  break;
1121  }
1122  }
1123  if (!esclusters.empty()) {
1124  superCluster.setPreshowerClusters(esclusters);
1125  }
1126 }
1127 
1128 template <typename T>
1130  T& core,
1131  const std::map<reco::SuperClusterRef, unsigned int>& superClusterMap,
1132  const edm::OrphanHandle<reco::SuperClusterCollection>& outSuperClusterHandle) {
1133  const auto& scmapped = superClusterMap.find(core.superCluster());
1134  if (scmapped != superClusterMap.end()) {
1135  //make new ref
1136  reco::SuperClusterRef scref(outSuperClusterHandle, scmapped->second);
1137  core.setSuperCluster(scref);
1138  }
1139 }
1140 
1142  const std::map<reco::GsfTrackRef, unsigned int>& gsfTrackMap,
1143  const edm::OrphanHandle<reco::GsfTrackCollection>& outGsfTrackHandle) {
1144  const auto& gsftkmapped = gsfTrackMap.find(gsfElectronCore.gsfTrack());
1145  if (gsftkmapped != gsfTrackMap.end()) {
1146  reco::GsfTrackRef gsftkref(outGsfTrackHandle, gsftkmapped->second);
1147  gsfElectronCore.setGsfTrack(gsftkref);
1148  }
1149 }
1150 
1152  const reco::ConversionRefVector& convrefs,
1153  const std::map<reco::ConversionRef, unsigned int>& conversionMap,
1154  const edm::OrphanHandle<reco::ConversionCollection>& outConversionHandle) {
1155  reco::ConversionRefVector outconvrefs;
1156  for (const auto& convref : convrefs) {
1157  const auto& convmapped = conversionMap.find(convref);
1158  if (convmapped != conversionMap.end()) {
1159  //make new ref
1160  reco::ConversionRef outref(outConversionHandle, convmapped->second);
1161  } else {
1162  //can only relink if all conversions are being relinked, so if one is missing, then skip the relinking completely
1163  outconvrefs.clear();
1164  break;
1165  }
1166  }
1167  if (!outconvrefs.empty()) {
1168  photonCore.setConversions(outconvrefs);
1169  }
1170 }
1171 
1173  const std::map<reco::PhotonCoreRef, unsigned int>& photonCoreMap,
1174  const edm::OrphanHandle<reco::PhotonCoreCollection>& outPhotonCoreHandle) {
1175  const auto& coremapped = photonCoreMap.find(photon.photonCore());
1176  if (coremapped != photonCoreMap.end()) {
1177  //make new ref
1178  reco::PhotonCoreRef coreref(outPhotonCoreHandle, coremapped->second);
1179  photon.setPhotonCore(coreref);
1180  }
1181 }
1182 
1184  reco::GsfElectron& gsfElectron,
1185  const std::map<reco::GsfElectronCoreRef, unsigned int>& gsfElectronCoreMap,
1186  const edm::OrphanHandle<reco::GsfElectronCoreCollection>& outgsfElectronCoreHandle) {
1187  const auto& coremapped = gsfElectronCoreMap.find(gsfElectron.core());
1188  if (coremapped != gsfElectronCoreMap.end()) {
1189  //make new ref
1190  reco::GsfElectronCoreRef coreref(outgsfElectronCoreHandle, coremapped->second);
1191  gsfElectron.setCore(coreref);
1192  }
1193 }
1194 
1196  const reco::PhotonRef& oldPhoRef,
1197  const edm::ValueMap<float>& energyMap,
1198  const edm::ValueMap<float>& energyErrMap) {
1199  float newEnergy = energyMap[oldPhoRef];
1200  float newEnergyErr = energyErrMap[oldPhoRef];
1201  photon.setCorrectedEnergy(reco::Photon::P4type::regression2, newEnergy, newEnergyErr, true);
1202 }
1203 
1205  const reco::GsfElectronRef& oldEleRef,
1206  const edm::ValueMap<float>& energyMap,
1207  const edm::ValueMap<float>& energyErrMap,
1208  const edm::ValueMap<float>& ecalEnergyMap,
1209  const edm::ValueMap<float>& ecalEnergyErrMap) {
1210  const float newEnergy = energyMap[oldEleRef];
1211  const float newEnergyErr = energyErrMap[oldEleRef];
1212  const float newEcalEnergy = ecalEnergyMap[oldEleRef];
1213  const float newEcalEnergyErr = ecalEnergyErrMap[oldEleRef];
1214 
1215  //make a copy of this as the setCorrectedEcalEnergy call with modifiy the electrons p4
1216  const math::XYZTLorentzVector oldP4 = electron.p4();
1217  const float corr = newEnergy / oldP4.E();
1218 
1219  electron.setCorrectedEcalEnergy(newEcalEnergy);
1220  electron.setCorrectedEcalEnergyError(newEcalEnergyErr);
1221 
1222  math::XYZTLorentzVector newP4{oldP4.x() * corr, oldP4.y() * corr, oldP4.z() * corr, newEnergy};
1223  electron.correctMomentum(newP4, electron.trackMomentumError(), newEnergyErr);
1224 }
const bool doPreshowerEcalHits_
void setPreshowerClusters(const CaloClusterPtrVector &clusters)
Definition: SuperCluster.h:116
edm::EDPutTokenT< EcalRecHitCollection > outESRecHits_
void relinkGsfTrack(reco::GsfElectronCore &electroncore, const std::map< reco::GsfTrackRef, unsigned int > &gsfTrackMap, const edm::OrphanHandle< reco::GsfTrackCollection > &outGsfTrackHandle)
const StringCutObjectSelector< reco::Photon > relinkOOTPhotonSel_
bool empty() const
Is the RefVector empty.
Definition: RefVector.h:99
static bool matchesConversion(const reco::GsfElectron &ele, const reco::Conversion &conv, bool allowCkfMatch=true, bool allowAmbiguousGsfMatch=false)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::EDPutTokenT< reco::PhotonCollection > outOOTPhotons_
const edm::EDGetTokenT< reco::HIPhotonIsolationMap > recoHIPhotonIsolationMapInputToken_
const edm::EDGetTokenT< reco::GsfElectronCollection > gsfElectronT_
const edm::EDPutTokenT< EcalRecHitCollection > outEERecHits_
const edm::EDPutTokenT< EcalRecHitCollection > outEBRecHits_
void setCore(const reco::GsfElectronCoreRef &core)
Definition: GsfElectron.h:152
const bool applyPhotonCalibOnData_
edm::EDGetTokenT< edm::ValueMap< float > > gsfElectronCalibEnergyT_
const edm::EDPutTokenT< reco::GsfTrackCollection > outGsfTracks_
const StringCutObjectSelector< reco::Photon > slimRelinkPhotonSel_
void setGsfTrack(const GsfTrackRef &gsfTrack)
const edm::EDGetTokenT< reco::ConversionCollection > singleConversionT_
EGHcalRecHitSelector hcalHitSel_
const std::vector< edm::EDPutTokenT< edm::ValueMap< float > > > outGsfElectronFloatValueMaps_
static void calibratePhoton(reco::Photon &photon, const reco::PhotonRef &oldPhoRef, const edm::ValueMap< float > &energyMap, const edm::ValueMap< float > &energyErrMap)
edm::EDPutTokenT< reco::PhotonCoreCollection > outOOTPhotonCores_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:149
edm::EDGetTokenT< edm::ValueMap< float > > photonCalibEnergyT_
const std::vector< edm::EDPutTokenT< edm::ValueMap< bool > > > outPhotonIds_
Definition: __init__.py:1
T const * product() const
Definition: Handle.h:70
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:99
void setToken(edm::EDGetTokenT< T > &token, const edm::ParameterSet &config, const std::string &name)
const edm::EDPutTokenT< reco::ConversionCollection > outConversions_
void setup(const edm::EventSetup &iSetup)
void push_back(T const &t)
const StringCutObjectSelector< reco::GsfElectron > keepGsfElectronSel_
void linkHcalHits(const reco::SuperCluster &superClus, const HBHERecHitCollection &recHits, std::unordered_set< DetId > &hcalDetIds)
void beginRun(edm::Run const &, const edm::EventSetup &) final
Definition: config.py:1
void setSeed(const CaloClusterPtr &r)
list of used xtals by DetId // now inherited by CaloCluster
Definition: SuperCluster.h:107
const StringCutObjectSelector< reco::Photon > keepPhotonSel_
const edm::EDGetTokenT< edm::ValueMap< std::vector< reco::PFCandidateRef > > > photonPfCandMapT_
const bool applyGsfElectronCalibOnData_
edm::EDGetTokenT< edm::ValueMap< float > > photonCalibEnergyErrT_
edm::EDPutTokenT< reco::SuperClusterCollection > outOOTSuperClusters_
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
const StringCutObjectSelector< reco::GsfElectron > relinkGsfElectronSel_
void setClusters(const CaloClusterPtrVector &clusters)
Definition: SuperCluster.h:110
void linkConversion(const reco::ConversionRef &convref, reco::ConversionCollection &conversions, std::map< reco::ConversionRef, unsigned int > &conversionMap)
std::vector< Conversion > ConversionCollection
collectin of Conversion objects
Definition: ConversionFwd.h:9
const edm::EDGetTokenT< edm::ValueMap< std::vector< reco::PFCandidateRef > > > gsfElectronPfCandMapT_
double getMaximum(TObjArray *array)
bool empty() const
Is the RefVector empty.
Definition: PtrVectorBase.h:72
void relinkConversions(reco::PhotonCore &photonCore, const reco::ConversionRefVector &convrefs, const std::map< reco::ConversionRef, unsigned int > &conversionMap, const edm::OrphanHandle< reco::ConversionCollection > &outConversionHandle)
const edm::EDGetTokenT< EcalRecHitCollection > preshowerEcalHits_
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
void linkConversions(const reco::ConversionRefVector &convrefs, reco::ConversionCollection &conversions, std::map< reco::ConversionRef, unsigned int > &conversionMap)
char const * label
edm::EDPutTokenT< reco::CaloClusterCollection > outOOTESClusters_
const edm::EDPutTokenT< reco::GsfElectronCollection > outGsfElectrons_
const edm::EDPutTokenT< reco::CaloClusterCollection > outEBEEClusters_
dictionary corr
const CaloClusterPtrVector & preshowerClusters() const
const access to the preshower cluster list itself
Definition: SuperCluster.h:83
std::vector< BaseVolumeHandle * > handles
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
const StringCutObjectSelector< reco::Photon > keepOOTPhotonSel_
edm::EDPutTokenT< reco::CaloClusterCollection > outOOTEBEEClusters_
void addDetIds(const reco::SuperCluster &superClus, const HBHERecHitCollection &recHits, CollType &detIdsToStore) const
const edm::EDPutTokenT< reco::CaloClusterCollection > outESClusters_
const edm::EDPutTokenT< reco::GsfElectronCoreCollection > outGsfElectronCores_
const edm::EDPutTokenT< reco::PhotonCoreCollection > outPhotonCores_
std::vector< GsfElectronCore > GsfElectronCoreCollection
std::vector< GsfTrack > GsfTrackCollection
collection of GsfTracks
Definition: GsfTrackFwd.h:9
static void calibrateElectron(reco::GsfElectron &gsfElectron, const reco::GsfElectronRef &oldEleRef, const edm::ValueMap< float > &energyMap, const edm::ValueMap< float > &energyErrMap, const edm::ValueMap< float > &ecalEnergyMap, const edm::ValueMap< float > &ecalEnergyErrMap)
const edm::EDPutTokenT< HBHERecHitCollection > outHBHERecHits_
std::vector< edm::EDPutTokenT< edm::ValueMap< float > > > outOOTPhotonFloatValueMaps_
void relinkGsfElectronCore(reco::GsfElectron &gsfElectron, const std::map< reco::GsfElectronCoreRef, unsigned int > &gsfElectronCoreMap, const edm::OrphanHandle< reco::GsfElectronCoreCollection > &outGsfElectronCoreHandle)
std::vector< edm::EDGetTokenT< edm::ValueMap< float > > > gsfElectronFloatValueMapTs_
void linkConversionsByTrackRef(const edm::Handle< reco::ConversionCollection > &conversionHandle, const reco::GsfElectron &gsfElectron, reco::ConversionCollection &conversions, std::map< reco::ConversionRef, unsigned int > &conversionMap)
edm::EDGetTokenT< reco::PhotonCollection > ootPhotonT_
std::vector< CaloCluster > CaloClusterCollection
collection of CaloCluster objects
void linkSuperCluster(const reco::SuperClusterRef &superCluster, std::map< reco::SuperClusterRef, unsigned int > &superClusterMap, reco::SuperClusterCollection &superClusters, const bool relink, std::unordered_set< unsigned int > &superClusterFullRelinkMap)
void linkCore(const T &core, U &cores, std::map< T, unsigned int > &coreMap)
virtual std::vector< DetId > getWindow(const DetId &id, const int &northSouthSize, const int &eastWestSize) const
const StringCutObjectSelector< reco::Photon > relinkPhotonSel_
std::vector< edm::EDGetTokenT< edm::ValueMap< float > > > gsfElectronIdTs_
edm::EDGetTokenT< edm::ValueMap< float > > gsfElectronCalibEnergyErrT_
const edm::EDPutTokenT< reco::SuperClusterCollection > outSuperClusters_
const edm::EDGetTokenT< HBHERecHitCollection > hbheHits_
const bool applyPhotonCalibOnMC_
void relinkCaloClusters(reco::SuperCluster &superCluster, const std::map< reco::CaloClusterPtr, unsigned int > &ebeeClusterMap, const std::map< reco::CaloClusterPtr, unsigned int > &esClusterMap, const edm::OrphanHandle< reco::CaloClusterCollection > &outEBEEClusterHandle, const edm::OrphanHandle< reco::CaloClusterCollection > &outESClusterHandle)
const std::vector< edm::EDPutTokenT< edm::ValueMap< float > > > outGsfElectronIds_
std::vector< edm::EDPutTokenT< T > > vproduces(std::vector< std::string > const &labels)
virtual GsfElectronCoreRef core() const
Definition: GsfElectron.cc:8
void relinkSuperCluster(T &core, const std::map< reco::SuperClusterRef, unsigned int > &superClusterMap, const edm::OrphanHandle< reco::SuperClusterCollection > &outSuperClusterHandle)
const edm::EDPutTokenT< reco::PhotonCollection > outPhotons_
std::vector< edm::EDGetTokenT< edm::ValueMap< float > > > photonFloatValueMapTs_
Definition: DetId.h:17
const edm::EDGetTokenT< reco::PhotonCollection > photonT_
void relinkPhotonCore(reco::Photon &photon, const std::map< reco::PhotonCoreRef, unsigned int > &photonCoreMap, const edm::OrphanHandle< reco::PhotonCoreCollection > &outPhotonCoreHandle)
void conversion(EventAux const &from, EventAuxiliary &to)
Definition: EventAux.cc:9
void clear()
Clear the vector.
Definition: RefVector.h:142
const CaloSubdetectorTopology * getSubdetectorTopology(const DetId &id) const
access the subdetector Topology for the given subdetector directly
Definition: CaloTopology.cc:17
std::vector< Photon > PhotonCollection
collectin of Photon objects
Definition: PhotonFwd.h:9
const edm::EDPutTokenT< reco::ConversionCollection > outSingleConversions_
std::vector< edm::EDGetTokenT< edm::ValueMap< float > > > ootPhotonFloatValueMapTs_
const CaloClusterPtrVector & clusters() const
const access to the cluster list itself
Definition: SuperCluster.h:80
const StringCutObjectSelector< reco::GsfElectron > slimRelinkGsfElectronSel_
const edm::EDPutTokenT< edm::ValueMap< std::vector< reco::PFCandidateRef > > > outGsfElectronPfCandMap_
const GsfTrackRef & gsfTrack() const
edm::EDPutTokenT< reco::HIPhotonIsolationMap > recoHIPhotonIsolationMapOutputName_
std::vector< PhotonCore > PhotonCoreCollection
collectin of PhotonCore objects
Definition: PhotonCoreFwd.h:9
const CaloClusterPtr & seed() const
seed BasicCluster
Definition: SuperCluster.h:77
void clear()
Clear the PtrVector.
Definition: PtrVectorBase.h:81
const std::vector< edm::EDPutTokenT< edm::ValueMap< float > > > outPhotonFloatValueMaps_
HLT enums.
edm::EDGetTokenT< edm::ValueMap< float > > gsfElectronCalibEcalEnergyErrT_
void linkCaloCluster(const reco::CaloClusterPtr &caloCluster, reco::CaloClusterCollection &caloClusters, std::map< reco::CaloClusterPtr, unsigned int > &caloClusterMap)
const StringCutObjectSelector< reco::Photon > slimRelinkOOTPhotonSel_
void produce(edm::Event &evt, const edm::EventSetup &es) final
const edm::EDGetTokenT< EcalRecHitCollection > endcapEcalHits_
std::vector< edm::EDGetTokenT< edm::ValueMap< bool > > > photonIdTs_
edm::ESGetToken< CaloTopology, CaloTopologyRecord > caloTopology_
long double T
edm::EDGetTokenT< edm::ValueMap< float > > gsfElectronCalibEcalEnergyT_
const edm::EDGetTokenT< EcalRecHitCollection > barrelEcalHits_
def move(src, dest)
Definition: eostools.py:511
const bool applyGsfElectronCalibOnMC_
Definition: event.py:1
Definition: Run.h:45
ReducedEGProducer(const edm::ParameterSet &ps)
const edm::EDGetTokenT< reco::ConversionCollection > conversionT_
const edm::EDPutTokenT< edm::ValueMap< std::vector< reco::PFCandidateRef > > > outPhotonPfCandMap_
void linkCaloClusters(const reco::SuperCluster &superCluster, reco::CaloClusterCollection &ebeeClusters, std::map< reco::CaloClusterPtr, unsigned int > &ebeeClusterMap, std::unordered_set< DetId > &rechitMap, const edm::Handle< EcalRecHitCollection > &barrelHitHandle, const edm::Handle< EcalRecHitCollection > &endcapHitHandle, CaloTopology const &caloTopology, reco::CaloClusterCollection &esClusters, std::map< reco::CaloClusterPtr, unsigned int > &esClusterMap)