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