CMS 3D CMS Logo

ReducedEGProducer.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <vector>
3 #include <memory>
4 #include <unordered_set>
5 
6 // Framework
9 
11 
16 
17 
29 
30 
33 
36 
39 
44 
46 
47 namespace std {
48  template<>
49  struct hash<DetId> {
50  size_t operator()(const DetId& id) const {
51  return std::hash<uint32_t>()(id.rawId());
52  }
53  };
54 }
55 
57  photonT_(consumes<reco::PhotonCollection>(config.getParameter<edm::InputTag>("photons"))),
58  ootPhotonT_(consumes<reco::PhotonCollection>(config.getParameter<edm::InputTag>("ootPhotons"))),
59  gsfElectronT_(consumes<reco::GsfElectronCollection>(config.getParameter<edm::InputTag>("gsfElectrons"))),
60  gsfTrackT_(consumes<reco::GsfTrackCollection>(config.getParameter<edm::InputTag>("gsfTracks"))),
61  conversionT_(consumes<reco::ConversionCollection>(config.getParameter<edm::InputTag>("conversions"))),
62  singleConversionT_(consumes<reco::ConversionCollection>(config.getParameter<edm::InputTag>("singleConversions"))),
63  barrelEcalHits_(consumes<EcalRecHitCollection>(config.getParameter<edm::InputTag>("barrelEcalHits"))),
64  endcapEcalHits_(consumes<EcalRecHitCollection>(config.getParameter<edm::InputTag>("endcapEcalHits"))),
65  doPreshowerEcalHits_(!config.getParameter<edm::InputTag>("preshowerEcalHits").label().empty()),
66  preshowerEcalHits_(doPreshowerEcalHits_ ? consumes<EcalRecHitCollection>(config.getParameter<edm::InputTag>("preshowerEcalHits")) : edm::EDGetTokenT<EcalRecHitCollection>()),
67  photonPfCandMapT_(consumes<edm::ValueMap<std::vector<reco::PFCandidateRef> > >(config.getParameter<edm::InputTag>("photonsPFValMap"))),
68  gsfElectronPfCandMapT_(consumes<edm::ValueMap<std::vector<reco::PFCandidateRef> > >(config.getParameter<edm::InputTag>("gsfElectronsPFValMap"))),
69  //calibration flags
70  applyPhotonCalibOnData_(config.getParameter<bool>("applyPhotonCalibOnData")),
71  applyPhotonCalibOnMC_(config.getParameter<bool>("applyPhotonCalibOnMC")),
72  applyGsfElectronCalibOnData_(config.getParameter<bool>("applyGsfElectronCalibOnData")),
73  applyGsfElectronCalibOnMC_(config.getParameter<bool>("applyGsfElectronCalibOnMC")),
74  //output collections
75  outPhotons_("reducedGedPhotons"),
76  outPhotonCores_("reducedGedPhotonCores"),
77  outOOTPhotons_("reducedOOTPhotons"),
78  outOOTPhotonCores_("reducedOOTPhotonCores"),
79  outGsfElectrons_("reducedGedGsfElectrons"),
80  outGsfElectronCores_("reducedGedGsfElectronCores"),
81  outGsfTracks_("reducedGsfTracks"),
82  outConversions_("reducedConversions"),
83  outSingleConversions_("reducedSingleLegConversions"),
84  outSuperClusters_("reducedSuperClusters"),
85  outEBEEClusters_("reducedEBEEClusters"),
86  outESClusters_("reducedESClusters"),
87  outOOTSuperClusters_("reducedOOTSuperClusters"),
88  outOOTEBEEClusters_("reducedOOTEBEEClusters"),
89  outOOTESClusters_("reducedOOTESClusters"),
90  outEBRecHits_("reducedEBRecHits"),
91  outEERecHits_("reducedEERecHits"),
92  outESRecHits_("reducedESRecHits"),
93  outPhotonPfCandMap_("reducedPhotonPfCandMap"),
94  outGsfElectronPfCandMap_("reducedGsfElectronPfCandMap"),
95  outPhotonIds_(config.getParameter<std::vector<std::string> >("photonIDOutput")),
96  outGsfElectronIds_(config.getParameter<std::vector<std::string> >("gsfElectronIDOutput")),
97  outPhotonFloatValueMaps_(config.getParameter<std::vector<std::string> >("photonFloatValueMapOutput")),
98  outOOTPhotonFloatValueMaps_(config.getParameter<std::vector<std::string> >("ootPhotonFloatValueMapOutput")),
99  outGsfElectronFloatValueMaps_(config.getParameter<std::vector<std::string> >("gsfElectronFloatValueMapOutput")),
100  keepPhotonSel_(config.getParameter<std::string>("keepPhotons")),
101  slimRelinkPhotonSel_(config.getParameter<std::string>("slimRelinkPhotons")),
102  relinkPhotonSel_(config.getParameter<std::string>("relinkPhotons")),
103  keepOOTPhotonSel_(config.getParameter<std::string>("keepOOTPhotons")),
104  slimRelinkOOTPhotonSel_(config.getParameter<std::string>("slimRelinkOOTPhotons")),
105  relinkOOTPhotonSel_(config.getParameter<std::string>("relinkOOTPhotons")),
106  keepGsfElectronSel_(config.getParameter<std::string>("keepGsfElectrons")),
107  slimRelinkGsfElectronSel_(config.getParameter<std::string>("slimRelinkGsfElectrons")),
108  relinkGsfElectronSel_(config.getParameter<std::string>("relinkGsfElectrons"))
109 {
110  const std::vector<edm::InputTag>& photonidinputs =
111  config.getParameter<std::vector<edm::InputTag> >("photonIDSources");
112  for (const edm::InputTag &tag : photonidinputs) {
113  photonIdTs_.emplace_back(consumes<edm::ValueMap<bool> >(tag));
114  }
115 
116  const std::vector<edm::InputTag>& gsfelectronidinputs =
117  config.getParameter<std::vector<edm::InputTag> >("gsfElectronIDSources");
118  for (const edm::InputTag &tag : gsfelectronidinputs) {
120  }
121 
122  const std::vector<edm::InputTag>& photonpfclusterisoinputs =
123  config.getParameter<std::vector<edm::InputTag> >("photonFloatValueMapSources");
124  for (const edm::InputTag &tag : photonpfclusterisoinputs) {
126  }
127 
128  const std::vector<edm::InputTag>& ootphotonpfclusterisoinputs =
129  config.getParameter<std::vector<edm::InputTag> >("ootPhotonFloatValueMapSources");
130  for (const edm::InputTag &tag : ootphotonpfclusterisoinputs) {
132  }
133 
134  const std::vector<edm::InputTag>& gsfelectronpfclusterisoinputs =
135  config.getParameter<std::vector<edm::InputTag> >("gsfElectronFloatValueMapSources");
136  for (const edm::InputTag &tag : gsfelectronpfclusterisoinputs) {
138  }
139 
141  setToken(photonCalibEnergyT_,config,"photonCalibEnergySource");
142  setToken(photonCalibEnergyErrT_,config,"photonCalibEnergyErrSource");
143  }
145  setToken(gsfElectronCalibEnergyT_,config,"gsfElectronCalibEnergySource");
146  setToken(gsfElectronCalibEnergyErrT_,config,"gsfElectronCalibEnergyErrSource");
147  setToken(gsfElectronCalibEcalEnergyT_,config,"gsfElectronCalibEcalEnergySource");
148  setToken(gsfElectronCalibEcalEnergyErrT_,config,"gsfElectronCalibEcalEnergyErrSource");
149  }
150 
151  produces< reco::PhotonCollection >(outPhotons_);
152  produces< reco::PhotonCoreCollection >(outPhotonCores_);
153  produces< reco::PhotonCollection >(outOOTPhotons_);
154  produces< reco::PhotonCoreCollection >(outOOTPhotonCores_);
155  produces< reco::GsfElectronCollection >(outGsfElectrons_);
156  produces< reco::GsfElectronCoreCollection >(outGsfElectronCores_);
157  produces< reco::GsfTrackCollection >(outGsfTracks_);
158  produces< reco::ConversionCollection >(outConversions_);
159  produces< reco::ConversionCollection >(outSingleConversions_);
160  produces< reco::SuperClusterCollection >(outSuperClusters_);
161  produces< reco::CaloClusterCollection >(outEBEEClusters_);
162  produces< reco::CaloClusterCollection >(outESClusters_);
163  produces< reco::SuperClusterCollection >(outOOTSuperClusters_);
164  produces< reco::CaloClusterCollection >(outOOTEBEEClusters_);
165  produces< reco::CaloClusterCollection >(outOOTESClusters_);
166  produces< EcalRecHitCollection >(outEBRecHits_);
167  produces< EcalRecHitCollection >(outEERecHits_);
168  if (doPreshowerEcalHits_) produces< EcalRecHitCollection >(outESRecHits_);
169  produces< edm::ValueMap<std::vector<reco::PFCandidateRef> > >(outPhotonPfCandMap_);
170  produces< edm::ValueMap<std::vector<reco::PFCandidateRef> > >(outGsfElectronPfCandMap_);
171  for (const std::string &outid : outPhotonIds_) {
172  produces< edm::ValueMap<bool> >(outid);
173  }
174  for (const std::string &outid : outGsfElectronIds_) {
175  produces< edm::ValueMap<float> >(outid);
176  }
177  for (const std::string &outid : outPhotonFloatValueMaps_) {
178  produces< edm::ValueMap<float> >(outid);
179  }
180  for (const std::string &outid : outOOTPhotonFloatValueMaps_) {
181  produces< edm::ValueMap<float> >(outid);
182  }
183  for (const std::string &outid : outGsfElectronFloatValueMaps_) {
184  produces< edm::ValueMap<float> >(outid);
185  }
186 }
187 
189 {
190 }
191 
192 void ReducedEGProducer::produce(edm::Event& theEvent, const edm::EventSetup& theEventSetup) {
193 
194  //get input collections
195 
196 
198  theEvent.getByToken(photonT_, photonHandle);
199 
200  edm::Handle<reco::PhotonCollection> ootPhotonHandle;
201  theEvent.getByToken(ootPhotonT_, ootPhotonHandle);
202 
204  theEvent.getByToken(gsfElectronT_, gsfElectronHandle);
205 
207  theEvent.getByToken(gsfTrackT_, gsfTrackHandle);
208 
210  theEvent.getByToken(conversionT_, conversionHandle);
211 
212  edm::Handle<reco::ConversionCollection> singleConversionHandle;
213  theEvent.getByToken(singleConversionT_, singleConversionHandle);
214 
215  edm::Handle<EcalRecHitCollection> barrelHitHandle;
216  theEvent.getByToken(barrelEcalHits_, barrelHitHandle);
217 
218  edm::Handle<EcalRecHitCollection> endcapHitHandle;
219  theEvent.getByToken(endcapEcalHits_, endcapHitHandle);
220 
221  edm::Handle<EcalRecHitCollection> preshowerHitHandle;
222  if (doPreshowerEcalHits_) theEvent.getByToken(preshowerEcalHits_, preshowerHitHandle);
223 
225  theEvent.getByToken(photonPfCandMapT_, photonPfCandMapHandle);
226 
228  theEvent.getByToken(gsfElectronPfCandMapT_, gsfElectronPfCandMapHandle);
229 
230  std::vector<edm::Handle<edm::ValueMap<bool> > > photonIdHandles(photonIdTs_.size());
231  int index = 0; // universal index for range based loops
232  for (const auto& photonIdT : photonIdTs_) {
233  theEvent.getByToken(photonIdT,photonIdHandles[index++]);
234  }
235 
236  std::vector<edm::Handle<edm::ValueMap<float> > > gsfElectronIdHandles(gsfElectronIdTs_.size());
237  index = 0;
238  for (const auto& gsfElectronIdT : gsfElectronIdTs_) {
239  theEvent.getByToken(gsfElectronIdT,gsfElectronIdHandles[index++]);
240  }
241 
242  std::vector<edm::Handle<edm::ValueMap<float> > > photonFloatValueMapHandles(photonFloatValueMapTs_.size());
243  index = 0;
244  for (const auto& photonFloatValueMapT : photonFloatValueMapTs_) {
245  theEvent.getByToken(photonFloatValueMapT,photonFloatValueMapHandles[index++]);
246  }
247 
248  std::vector<edm::Handle<edm::ValueMap<float> > > ootPhotonFloatValueMapHandles(ootPhotonFloatValueMapTs_.size());
249  index = 0;
250  for (const auto& ootPhotonFloatValueMapT : ootPhotonFloatValueMapTs_) {
251  theEvent.getByToken(ootPhotonFloatValueMapT,ootPhotonFloatValueMapHandles[index++]);
252  }
253 
254  std::vector<edm::Handle<edm::ValueMap<float> > > gsfElectronFloatValueMapHandles(gsfElectronFloatValueMapTs_.size());
255  index = 0;
256  for (const auto& gsfElectronFloatValueMapT : gsfElectronFloatValueMapTs_) {
257  theEvent.getByToken(gsfElectronFloatValueMapT,gsfElectronFloatValueMapHandles[index++]);
258  }
259 
260 
261  edm::Handle<edm::ValueMap<float> > gsfElectronCalibEnergyHandle;
262  edm::Handle<edm::ValueMap<float> > gsfElectronCalibEnergyErrHandle;
263  edm::Handle<edm::ValueMap<float> > gsfElectronCalibEcalEnergyHandle;
264  edm::Handle<edm::ValueMap<float> > gsfElectronCalibEcalEnergyErrHandle;
266  theEvent.getByToken(gsfElectronCalibEnergyT_,gsfElectronCalibEnergyHandle);
267  theEvent.getByToken(gsfElectronCalibEnergyErrT_,gsfElectronCalibEnergyErrHandle);
268  theEvent.getByToken(gsfElectronCalibEcalEnergyT_,gsfElectronCalibEcalEnergyHandle);
269  theEvent.getByToken(gsfElectronCalibEcalEnergyErrT_,gsfElectronCalibEcalEnergyErrHandle);
270  }
271  edm::Handle<edm::ValueMap<float> > photonCalibEnergyHandle;
272  edm::Handle<edm::ValueMap<float> > photonCalibEnergyErrHandle;
274  theEvent.getByToken(photonCalibEnergyT_,photonCalibEnergyHandle);
275  theEvent.getByToken(photonCalibEnergyErrT_,photonCalibEnergyErrHandle);
276  }
277 
278  edm::ESHandle<CaloTopology> theCaloTopology;
279  theEventSetup.get<CaloTopologyRecord>().get(theCaloTopology);
280  const CaloTopology *caloTopology = & (*theCaloTopology);
281 
282  //initialize output collections
283  auto photons = std::make_unique<reco::PhotonCollection>();
284  auto photonCores = std::make_unique<reco::PhotonCoreCollection>();
285  auto ootPhotons = std::make_unique<reco::PhotonCollection>();
286  auto ootPhotonCores = std::make_unique<reco::PhotonCoreCollection>();
287  auto gsfElectrons = std::make_unique<reco::GsfElectronCollection>();
288  auto gsfElectronCores = std::make_unique<reco::GsfElectronCoreCollection>();
289  auto gsfTracks = std::make_unique<reco::GsfTrackCollection>();
290  auto conversions = std::make_unique<reco::ConversionCollection>();
291  auto singleConversions = std::make_unique<reco::ConversionCollection>();
292  auto superClusters = std::make_unique<reco::SuperClusterCollection>();
293  auto ebeeClusters = std::make_unique<reco::CaloClusterCollection>();
294  auto esClusters = std::make_unique<reco::CaloClusterCollection>();
295  auto ootSuperClusters = std::make_unique<reco::SuperClusterCollection>();
296  auto ootEbeeClusters = std::make_unique<reco::CaloClusterCollection>();
297  auto ootEsClusters = std::make_unique<reco::CaloClusterCollection>();
298  auto ebRecHits = std::make_unique<EcalRecHitCollection>();
299  auto eeRecHits = std::make_unique<EcalRecHitCollection>();
300  auto esRecHits = std::make_unique<EcalRecHitCollection>();
301  auto photonPfCandMap = std::make_unique<edm::ValueMap<std::vector<reco::PFCandidateRef>>>();
302  auto gsfElectronPfCandMap = std::make_unique<edm::ValueMap<std::vector<reco::PFCandidateRef>>>();
303 
304  //maps to collection indices of output objects
305  std::map<reco::PhotonCoreRef, unsigned int> photonCoreMap;
306  std::map<reco::PhotonCoreRef, unsigned int> ootPhotonCoreMap;
307  std::map<reco::GsfElectronCoreRef, unsigned int> gsfElectronCoreMap;
308  std::map<reco::GsfTrackRef, unsigned int> gsfTrackMap;
309  std::map<reco::ConversionRef, unsigned int> conversionMap;
310  std::map<reco::ConversionRef, unsigned int> singleConversionMap;
311  std::map<reco::SuperClusterRef, unsigned int> superClusterMap;
312  std::map<reco::CaloClusterPtr, unsigned int> ebeeClusterMap;
313  std::map<reco::CaloClusterPtr, unsigned int> esClusterMap;
314  std::map<reco::SuperClusterRef, unsigned int> ootSuperClusterMap;
315  std::map<reco::CaloClusterPtr, unsigned int> ootEbeeClusterMap;
316  std::map<reco::CaloClusterPtr, unsigned int> ootEsClusterMap;
317  std::unordered_set<DetId> rechitMap;
318 
319  std::unordered_set<unsigned int> superClusterFullRelinkMap;
320  std::unordered_set<unsigned int> ootSuperClusterFullRelinkMap;
321 
322  //vectors for pfcandidate valuemaps
323  std::vector<std::vector<reco::PFCandidateRef> > pfCandIsoPairVecPho;
324  std::vector<std::vector<reco::PFCandidateRef> > pfCandIsoPairVecEle;
325 
326  //vectors for id valuemaps
327  std::vector<std::vector<bool> > photonIdVals(photonIdHandles.size());
328  std::vector<std::vector<float> > gsfElectronIdVals(gsfElectronIdHandles.size());
329  std::vector<std::vector<float> > photonFloatValueMapVals(photonFloatValueMapHandles.size());
330  std::vector<std::vector<float> > ootPhotonFloatValueMapVals(ootPhotonFloatValueMapHandles.size());
331  std::vector<std::vector<float> > gsfElectronFloatValueMapVals(gsfElectronFloatValueMapHandles.size());
332 
333  //loop over photons and fill maps
334  index = -1;
335  for (const auto& photon : *photonHandle) {
336  index++;
337 
338  reco::PhotonRef photonref(photonHandle,index);
339  photons->push_back(photon);
340  auto& newPhoton = photons->back();
341 
342  if( (applyPhotonCalibOnData_ && theEvent.isRealData()) ||
343  (applyPhotonCalibOnMC_ && !theEvent.isRealData()) ){
344  calibratePhoton(newPhoton,photonref,
345  *photonCalibEnergyHandle,*photonCalibEnergyErrHandle);
346  }
347 
348  //we do this after calibration
349  bool keep = keepPhotonSel_(newPhoton);
350  if (!keep){
351  photons->pop_back();
352  continue;
353  }
354 
355  //fill pf candidate value map vector
356  pfCandIsoPairVecPho.push_back((*photonPfCandMapHandle)[photonref]);
357 
358  //fill photon id valuemap vectors
359  int subindex = 0;
360  for (const auto& photonIdHandle : photonIdHandles) {
361  photonIdVals[subindex++].push_back((*photonIdHandle)[photonref]);
362  }
363 
364  subindex = 0;
365  for (const auto& photonFloatValueMapHandle : photonFloatValueMapHandles) {
366  photonFloatValueMapVals[subindex++].push_back((*photonFloatValueMapHandle)[photonref]);
367  }
368 
369  //link photon core
370  const reco::PhotonCoreRef &photonCore = photon.photonCore();
371  linkCore(photonCore, *photonCores, photonCoreMap);
372 
373  bool slimRelink = slimRelinkPhotonSel_(newPhoton);
374  //no supercluster relinking unless slimRelink selection is satisfied
375  if (!slimRelink) continue;
376 
377  bool relink = relinkPhotonSel_(newPhoton);
378 
379  //link supercluster
380  const reco::SuperClusterRef &superCluster = photon.superCluster();
381  linkSuperCluster(superCluster, superClusterMap, *superClusters, relink, superClusterFullRelinkMap);
382 
383  //conversions only for full relinking
384  if (!relink) continue;
385 
386  const reco::ConversionRefVector &convrefs = photon.conversions();
387  linkConversions(convrefs, *conversions, conversionMap);
388 
389  //explicitly references conversions
390  const reco::ConversionRefVector &singleconvrefs = photon.conversionsOneLeg();
391  linkConversions(singleconvrefs, *singleConversions, singleConversionMap);
392  }
393 
394  //loop over oot photons and fill maps
395  //special note1: since not PFCand --> no PF isolation, IDs (but we do have FloatValueMap!)
396  //special note2: conversion sequence not run over bcs from oot phos, so skip relinking of oot phos
397  //special note3: clusters and superclusters in own collections!
398  index = -1;
399  for (const auto& ootPhoton : *ootPhotonHandle) {
400  index++;
401 
402  bool keep = keepOOTPhotonSel_(ootPhoton);
403  if (!keep) continue;
404 
405  reco::PhotonRef ootPhotonref(ootPhotonHandle,index);
406 
407  ootPhotons->push_back(ootPhoton);
408 
409  //fill photon pfclusteriso valuemap vectors
410  int subindex = 0;
411  for (const auto& ootPhotonFloatValueMapHandle : ootPhotonFloatValueMapHandles) {
412  ootPhotonFloatValueMapVals[subindex++].push_back((*ootPhotonFloatValueMapHandle)[ootPhotonref]);
413  }
414 
415  //link photon core
416  const reco::PhotonCoreRef &ootPhotonCore = ootPhoton.photonCore();
417  linkCore(ootPhotonCore, *ootPhotonCores, ootPhotonCoreMap);
418 
419  bool slimRelink = slimRelinkOOTPhotonSel_(ootPhoton);
420  //no supercluster relinking unless slimRelink selection is satisfied
421  if (!slimRelink) continue;
422 
423  bool relink = relinkOOTPhotonSel_(ootPhoton);
424 
425  const reco::SuperClusterRef &ootSuperCluster = ootPhoton.superCluster();
426  linkSuperCluster(ootSuperCluster, ootSuperClusterMap, *ootSuperClusters, relink, ootSuperClusterFullRelinkMap);
427  }
428 
429  //loop over electrons and fill maps
430  index = -1;
431  for (const auto& gsfElectron : *gsfElectronHandle) {
432  index++;
433 
434  reco::GsfElectronRef gsfElectronref(gsfElectronHandle,index);
435  gsfElectrons->push_back(gsfElectron);
436  auto& newGsfElectron = gsfElectrons->back();
437  if( (applyGsfElectronCalibOnData_ && theEvent.isRealData()) ||
438  (applyGsfElectronCalibOnMC_ && !theEvent.isRealData()) ){
439  calibrateElectron(newGsfElectron, gsfElectronref,
440  *gsfElectronCalibEnergyHandle,*gsfElectronCalibEnergyErrHandle,
441  *gsfElectronCalibEcalEnergyHandle,*gsfElectronCalibEcalEnergyErrHandle);
442 
443  }
444 
445  bool keep = keepGsfElectronSel_(newGsfElectron);
446  if (!keep) {
447  gsfElectrons->pop_back();
448  continue;
449  }
450 
451  pfCandIsoPairVecEle.push_back((*gsfElectronPfCandMapHandle)[gsfElectronref]);
452 
453  //fill electron id valuemap vectors
454  int subindex = 0;
455  for (const auto& gsfElectronIdHandle : gsfElectronIdHandles) {
456  gsfElectronIdVals[subindex++].push_back((*gsfElectronIdHandle)[gsfElectronref]);
457  }
458 
459  subindex = 0;
460  for (const auto& gsfElectronFloatValueMapHandle : gsfElectronFloatValueMapHandles) {
461  gsfElectronFloatValueMapVals[subindex++].push_back((*gsfElectronFloatValueMapHandle)[gsfElectronref]);
462  }
463 
464  const reco::GsfElectronCoreRef &gsfElectronCore = gsfElectron.core();
465  linkCore(gsfElectronCore, *gsfElectronCores, gsfElectronCoreMap);
466 
467  const reco::GsfTrackRef &gsfTrack = gsfElectron.gsfTrack();
468 
469  // Save the main gsfTrack
470  if (!gsfTrackMap.count(gsfTrack)) {
471  gsfTracks->push_back(*gsfTrack);
472  gsfTrackMap[gsfTrack] = gsfTracks->size() - 1;
473  }
474 
475  // Save additional ambiguous gsf tracks in a map:
476  for (reco::GsfTrackRefVector::const_iterator igsf = gsfElectron.ambiguousGsfTracksBegin(); igsf != gsfElectron.ambiguousGsfTracksEnd(); ++igsf) {
477  const reco::GsfTrackRef &ambigGsfTrack = *igsf;
478  if (!gsfTrackMap.count(ambigGsfTrack)) {
479  gsfTracks->push_back(*ambigGsfTrack);
480  gsfTrackMap[ambigGsfTrack] = gsfTracks->size() - 1;
481  }
482  }
483 
484  bool slimRelink = slimRelinkGsfElectronSel_(newGsfElectron);
485  //no supercluster relinking unless slimRelink selection is satisfied
486  if (!slimRelink) continue;
487 
488  bool relink = relinkGsfElectronSel_(newGsfElectron);
489 
490  const reco::SuperClusterRef &superCluster = gsfElectron.superCluster();
491  linkSuperCluster(superCluster, superClusterMap, *superClusters, relink, superClusterFullRelinkMap);
492 
493  //conversions only for full relinking
494  if (!relink) continue;
495 
496  const reco::ConversionRefVector &convrefs = gsfElectron.core()->conversions();
497  linkConversions(convrefs, *conversions, conversionMap);
498 
499  //explicitly references conversions
500  const reco::ConversionRefVector &singleconvrefs = gsfElectron.core()->conversionsOneLeg();
501  linkConversions(singleconvrefs, *singleConversions, singleConversionMap);
502 
503  //conversions matched by trackrefs
504  linkConversionsByTrackRef(conversionHandle, gsfElectron, *conversions, conversionMap);
505 
506  //single leg conversions matched by trackrefs
507  linkConversionsByTrackRef(singleConversionHandle, gsfElectron, *singleConversions, singleConversionMap);
508  }
509 
510  //loop over output SuperClusters and fill maps
511  index = 0;
512  for (auto& superCluster : *superClusters) {
513 
514  //link seed cluster no matter what
515  const reco::CaloClusterPtr &seedCluster = superCluster.seed();
516  linkCaloCluster(seedCluster, *ebeeClusters, ebeeClusterMap);
517 
518  //only proceed if superCluster is marked for full relinking
519  bool fullrelink = superClusterFullRelinkMap.count(index++);
520  if (!fullrelink) {
521  //zero detid vector which is anyways not useful without stored rechits
522  superCluster.clearHitsAndFractions();
523  continue;
524  }
525 
526  // link calo clusters
527  linkCaloClusters(superCluster, *ebeeClusters, ebeeClusterMap, rechitMap, barrelHitHandle, endcapHitHandle, caloTopology, *esClusters, esClusterMap);
528 
529  //conversions matched geometrically
530  linkConversionsByTrackRef(conversionHandle, superCluster, *conversions, conversionMap);
531 
532  //single leg conversions matched by trackrefs
533  linkConversionsByTrackRef(singleConversionHandle, superCluster, *singleConversions, singleConversionMap);
534  }
535 
536  //loop over output OOTSuperClusters and fill maps
537  index = 0;
538  for (auto& ootSuperCluster : *ootSuperClusters) {
539 
540  //link seed cluster no matter what
541  const reco::CaloClusterPtr &ootSeedCluster = ootSuperCluster.seed();
542  linkCaloCluster(ootSeedCluster, *ootEbeeClusters, ootEbeeClusterMap);
543 
544  //only proceed if ootSuperCluster is marked for full relinking
545  bool fullrelink = ootSuperClusterFullRelinkMap.count(index++);
546  if (!fullrelink) {
547  //zero detid vector which is anyways not useful without stored rechits
548  ootSuperCluster.clearHitsAndFractions();
549  continue;
550  }
551 
552  // link calo clusters
553  linkCaloClusters(ootSuperCluster, *ootEbeeClusters, ootEbeeClusterMap, rechitMap, barrelHitHandle, endcapHitHandle, caloTopology, *ootEsClusters, ootEsClusterMap);
554  }
555 
556  //now finalize and add to the event collections in "reverse" order
557 
558  //rechits (fill output collections of rechits to be stored)
559  for (const EcalRecHit &rechit : *barrelHitHandle) {
560  if (rechitMap.count(rechit.detid())) {
561  ebRecHits->push_back(rechit);
562  }
563  }
564 
565  for (const EcalRecHit &rechit : *endcapHitHandle) {
566  if (rechitMap.count(rechit.detid())) {
567  eeRecHits->push_back(rechit);
568  }
569  }
570 
571  theEvent.put(std::move(ebRecHits),outEBRecHits_);
572  theEvent.put(std::move(eeRecHits),outEERecHits_);
573 
574  if (doPreshowerEcalHits_) {
575  for (const EcalRecHit &rechit : *preshowerHitHandle) {
576  if (rechitMap.count(rechit.detid())) {
577  esRecHits->push_back(rechit);
578  }
579  }
580  theEvent.put(std::move(esRecHits),outESRecHits_);
581  }
582 
583  //CaloClusters
584  //put calocluster output collections in event and get orphan handles to create ptrs
585  const edm::OrphanHandle<reco::CaloClusterCollection> &outEBEEClusterHandle = theEvent.put(std::move(ebeeClusters),outEBEEClusters_);
586  const edm::OrphanHandle<reco::CaloClusterCollection> &outESClusterHandle = theEvent.put(std::move(esClusters),outESClusters_);;
587 
588  //Loop over SuperClusters and relink GEDPhoton + GSFElectron CaloClusters
589  for (reco::SuperCluster &superCluster : *superClusters) {
590  relinkCaloClusters(superCluster, ebeeClusterMap, esClusterMap, outEBEEClusterHandle, outESClusterHandle);
591  }
592 
593  //OOTCaloClusters
594  //put ootcalocluster output collections in event and get orphan handles to create ptrs
595  const edm::OrphanHandle<reco::CaloClusterCollection> &outOOTEBEEClusterHandle = theEvent.put(std::move(ootEbeeClusters),outOOTEBEEClusters_);
596  const edm::OrphanHandle<reco::CaloClusterCollection> &outOOTESClusterHandle = theEvent.put(std::move(ootEsClusters),outOOTESClusters_);;
597 
598  //Loop over OOTSuperClusters and relink OOTPhoton CaloClusters
599  for (reco::SuperCluster &ootSuperCluster : *ootSuperClusters) {
600  relinkCaloClusters(ootSuperCluster, ootEbeeClusterMap, ootEsClusterMap, outOOTEBEEClusterHandle, outOOTESClusterHandle);
601  }
602 
603  //put superclusters and conversions in the event
604  const edm::OrphanHandle<reco::SuperClusterCollection> &outSuperClusterHandle = theEvent.put(std::move(superClusters),outSuperClusters_);
605  const edm::OrphanHandle<reco::ConversionCollection> &outConversionHandle = theEvent.put(std::move(conversions),outConversions_);
606  const edm::OrphanHandle<reco::ConversionCollection> &outSingleConversionHandle = theEvent.put(std::move(singleConversions),outSingleConversions_);
607  const edm::OrphanHandle<reco::GsfTrackCollection> &outGsfTrackHandle = theEvent.put(std::move(gsfTracks),outGsfTracks_);
608 
609  //Loop over PhotonCores and relink GEDPhoton SuperClusters (and conversions)
610  for (reco::PhotonCore &photonCore : *photonCores) {
611  // superclusters
612  relinkSuperCluster(photonCore, superClusterMap, outSuperClusterHandle);
613 
614  //conversions
615  const reco::ConversionRefVector &convrefs = photonCore.conversions();
616  relinkConversions(photonCore, convrefs, conversionMap, outConversionHandle);
617 
618  //single leg conversions
619  const reco::ConversionRefVector &singleconvrefs = photonCore.conversionsOneLeg();
620  relinkConversions(photonCore, singleconvrefs, singleConversionMap, outSingleConversionHandle);
621  }
622 
623  //Relink GSFElectron SuperClusters and main GSF Tracks
624  for (reco::GsfElectronCore &gsfElectronCore : *gsfElectronCores) {
625  relinkSuperCluster(gsfElectronCore, superClusterMap, outSuperClusterHandle);
626  relinkGsfTrack(gsfElectronCore, gsfTrackMap, outGsfTrackHandle);
627  }
628 
629  //put ootsuperclusters in the event
630  const edm::OrphanHandle<reco::SuperClusterCollection> &outOOTSuperClusterHandle = theEvent.put(std::move(ootSuperClusters),outOOTSuperClusters_);
631 
632  //Relink OOTPhoton SuperClusters
633  for (reco::PhotonCore &ootPhotonCore : *ootPhotonCores) {
634  relinkSuperCluster(ootPhotonCore, ootSuperClusterMap, outOOTSuperClusterHandle);
635  }
636 
637  //put photoncores and gsfelectroncores into the event
638  const edm::OrphanHandle<reco::PhotonCoreCollection> &outPhotonCoreHandle = theEvent.put(std::move(photonCores),outPhotonCores_);
639  const edm::OrphanHandle<reco::PhotonCoreCollection> &outOOTPhotonCoreHandle = theEvent.put(std::move(ootPhotonCores),outOOTPhotonCores_);
640  const edm::OrphanHandle<reco::GsfElectronCoreCollection> &outgsfElectronCoreHandle = theEvent.put(std::move(gsfElectronCores),outGsfElectronCores_);
641 
642  //loop over photons, oot photons, and electrons and relink the cores
643  for (reco::Photon &photon : *photons) {
644  relinkPhotonCore(photon, photonCoreMap, outPhotonCoreHandle);
645  }
646 
647  for (reco::Photon &ootPhoton : *ootPhotons) {
648  relinkPhotonCore(ootPhoton, ootPhotonCoreMap, outOOTPhotonCoreHandle);
649  }
650 
651  for (reco::GsfElectron &gsfElectron : *gsfElectrons) {
652  relinkGsfElectronCore(gsfElectron, gsfElectronCoreMap, outgsfElectronCoreHandle);
653 
654  // -----
655  // Also in this loop let's relink ambiguous tracks
656  std::vector<reco::GsfTrackRef> ambigTracksInThisElectron;
657  // Here we loop over the ambiguous tracks and save them in a vector
658  for (reco::GsfTrackRefVector::const_iterator igsf = gsfElectron.ambiguousGsfTracksBegin(); igsf != gsfElectron.ambiguousGsfTracksEnd(); ++igsf) {
659  ambigTracksInThisElectron.push_back(*igsf);
660  }
661 
662  // Now we need to clear them (they are the refs to original collection):
663  gsfElectron.clearAmbiguousGsfTracks();
664 
665  // And here we add them back, now from a new reduced collection:
666  for (const auto &it : ambigTracksInThisElectron) {
667  const auto &gsftkmapped = gsfTrackMap.find(it);
668 
669  if (gsftkmapped != gsfTrackMap.end()) {
670  reco::GsfTrackRef gsftkref(outGsfTrackHandle, gsftkmapped->second);
671  gsfElectron.addAmbiguousGsfTrack(gsftkref);
672  }
673  else
674  throw cms::Exception("There must be a problem with linking and mapping of ambiguous gsf tracks...");
675  }
676 
677  if (gsfElectron.ambiguousGsfTracksSize() > 0)
678  gsfElectron.setAmbiguous(true); // Set the flag
679 
680  ambigTracksInThisElectron.clear();
681 
682  }
683 
684  //(finally) store the output photon and electron collections
685  const edm::OrphanHandle<reco::PhotonCollection> &outPhotonHandle = theEvent.put(std::move(photons),outPhotons_);
686  const edm::OrphanHandle<reco::PhotonCollection> &outOOTPhotonHandle = theEvent.put(std::move(ootPhotons),outOOTPhotons_);
687  const edm::OrphanHandle<reco::GsfElectronCollection> &outGsfElectronHandle = theEvent.put(std::move(gsfElectrons),outGsfElectrons_);
688 
689  //still need to output relinked valuemaps
690 
691  //photon pfcand isolation valuemap
692  edm::ValueMap<std::vector<reco::PFCandidateRef>>::Filler fillerPhotons(*photonPfCandMap);
693  fillerPhotons.insert(outPhotonHandle,pfCandIsoPairVecPho.begin(),pfCandIsoPairVecPho.end());
694  fillerPhotons.fill();
695 
696  //electron pfcand isolation valuemap
697  edm::ValueMap<std::vector<reco::PFCandidateRef>>::Filler fillerGsfElectrons(*gsfElectronPfCandMap);
698  fillerGsfElectrons.insert(outGsfElectronHandle,pfCandIsoPairVecEle.begin(),pfCandIsoPairVecEle.end());
699  fillerGsfElectrons.fill();
700 
701  theEvent.put(std::move(photonPfCandMap),outPhotonPfCandMap_);
702  theEvent.put(std::move(gsfElectronPfCandMap),outGsfElectronPfCandMap_);
703 
704  auto fillMap = [](auto refH, auto& vec, edm::Event& ev, const std::string& cAl = ""){
706  auto oMap = std::make_unique<MapType>();
707  {
708  typename MapType::Filler filler(*oMap);
709  filler.insert(refH, vec.begin(), vec.end());
710  filler.fill();
711  }
712  ev.put(std::move(oMap), cAl);
713  };
714 
715  //photon id value maps
716  index = 0;
717  for (auto const& vals : photonIdVals){
718  fillMap(outPhotonHandle, vals, theEvent, outPhotonIds_[index++]);
719  }
720 
721  //electron id value maps
722  index = 0;
723  for (auto const& vals : gsfElectronIdVals){
724  fillMap(outGsfElectronHandle, vals, theEvent, outGsfElectronIds_[index++]);
725  }
726 
727  // photon iso value maps
728  index = 0;
729  for (auto const& vals : photonFloatValueMapVals){
730  fillMap(outPhotonHandle, vals, theEvent, outPhotonFloatValueMaps_[index++]);
731  }
732 
733  //oot photon iso value maps
734  index = 0;
735  for (auto const& vals : ootPhotonFloatValueMapVals){
736  fillMap(outOOTPhotonHandle, vals, theEvent, outOOTPhotonFloatValueMaps_[index++]);
737  }
738 
739  //electron iso value maps
740  index = 0;
741  for (auto const& vals : gsfElectronFloatValueMapVals){
742  fillMap(outGsfElectronHandle, vals, theEvent, outGsfElectronFloatValueMaps_[index++]);
743  }
744 }
745 
746 template <typename T, typename U>
747 void ReducedEGProducer::linkCore(const T& core, U& cores, std::map<T, unsigned int>& coreMap)
748 {
749  if (!coreMap.count(core)) {
750  cores.push_back(*core);
751  coreMap[core] = cores.size() - 1;
752  }
753 }
754 
756  std::map<reco::SuperClusterRef, unsigned int>& superClusterMap,
757  reco::SuperClusterCollection& superClusters,
758  const bool relink,
759  std::unordered_set<unsigned int>& superClusterFullRelinkMap)
760 {
761  const auto &mappedsc = superClusterMap.find(superCluster);
762  //get index in output collection in order to keep track whether superCluster
763  //will be subject to full relinking
764  unsigned int mappedscidx = 0;
765  if (mappedsc==superClusterMap.end()) {
766  superClusters.push_back(*superCluster);
767  mappedscidx = superClusters.size() - 1;
768  superClusterMap[superCluster] = mappedscidx;
769  }
770  else {
771  mappedscidx = mappedsc->second;
772  }
773 
774  //additionally mark supercluster for full relinking
775  if (relink) superClusterFullRelinkMap.insert(mappedscidx);
776 }
777 
780  std::map<reco::ConversionRef, unsigned int>& conversionMap)
781 {
782  for (const auto& convref : convrefs) {
783  linkConversion(convref, conversions, conversionMap);
784  }
785 }
786 
788  const reco::GsfElectron& gsfElectron,
790  std::map<reco::ConversionRef, unsigned int>& conversionMap)
791 {
792  int index = 0;
793  for (const auto& conversion : *conversionHandle) {
794 
795  reco::ConversionRef convref(conversionHandle,index++);
796 
797  bool matched = ConversionTools::matchesConversion(gsfElectron,conversion,true,true);
798  if (!matched) continue;
799 
800  linkConversion(convref, conversions, conversionMap);
801  }
802 }
803 
805  const reco::SuperCluster& superCluster,
807  std::map<reco::ConversionRef, unsigned int>& conversionMap)
808 {
809  int index = 0;
810  for (const auto& conversion : *conversionHandle) {
811 
812  reco::ConversionRef convref(conversionHandle,index++);
813 
814  bool matched = ConversionTools::matchesConversion(superCluster,conversion,0.2);
815  if (!matched) continue;
816 
817  linkConversion(convref, conversions, conversionMap);
818  }
819 }
820 
823  std::map<reco::ConversionRef, unsigned int>& conversionMap)
824 {
825  if (!conversionMap.count(convref)) {
826  conversions.push_back(*convref);
827  conversionMap[convref] = conversions.size() - 1;
828  }
829 }
830 
832  reco::CaloClusterCollection& caloClusters,
833  std::map<reco::CaloClusterPtr, unsigned int>& caloClusterMap)
834 {
835  if (!caloClusterMap.count(caloCluster)) {
836  caloClusters.push_back(*caloCluster);
837  caloClusterMap[caloCluster] = caloClusters.size() - 1;
838  }
839 }
840 
842  reco::CaloClusterCollection& ebeeClusters,
843  std::map<reco::CaloClusterPtr, unsigned int>& ebeeClusterMap,
844  std::unordered_set<DetId>& rechitMap,
845  const edm::Handle<EcalRecHitCollection>& barrelHitHandle,
846  const edm::Handle<EcalRecHitCollection>& endcapHitHandle,
847  const CaloTopology *caloTopology,
848  reco::CaloClusterCollection& esClusters,
849  std::map<reco::CaloClusterPtr, unsigned int>& esClusterMap)
850 {
851  for (const auto& cluster : superCluster.clusters()) {
852  linkCaloCluster(cluster, ebeeClusters, ebeeClusterMap);
853 
854  for (const auto& hitfrac : cluster->hitsAndFractions()) {
855  rechitMap.insert(hitfrac.first);
856  }
857  //make sure to also take all hits in the 5x5 around the max energy xtal
858  bool barrel = cluster->hitsAndFractions().front().first.subdetId()==EcalBarrel;
859  const EcalRecHitCollection *rhcol = barrel ? barrelHitHandle.product() : endcapHitHandle.product();
860  DetId seed = EcalClusterTools::getMaximum(*cluster, rhcol).first;
861 
862  std::vector<DetId> dets5x5 = caloTopology->getSubdetectorTopology(DetId::Ecal, barrel ? EcalBarrel : EcalEndcap)->getWindow(seed,5,5);
863  for (const auto& detid : dets5x5) {
864  rechitMap.insert(detid);
865  }
866  }
867  for (const auto& cluster : superCluster.preshowerClusters()) {
868  linkCaloCluster(cluster, esClusters, esClusterMap);
869 
870  for (const auto& hitfrac : cluster->hitsAndFractions()) {
871  rechitMap.insert(hitfrac.first);
872  }
873  }
874 }
875 
876 
878  const std::map<reco::CaloClusterPtr, unsigned int>& ebeeClusterMap,
879  const std::map<reco::CaloClusterPtr, unsigned int>& esClusterMap,
880  const edm::OrphanHandle<reco::CaloClusterCollection>& outEBEEClusterHandle,
881  const edm::OrphanHandle<reco::CaloClusterCollection>& outESClusterHandle)
882 {
883  //remap seed cluster
884  const auto &seedmapped = ebeeClusterMap.find(superCluster.seed());
885  if (seedmapped != ebeeClusterMap.end()) {
886  //make new ptr
887  reco::CaloClusterPtr clusptr(outEBEEClusterHandle,seedmapped->second);
888  superCluster.setSeed(clusptr);
889  }
890 
891  //remap all clusters
893  for (const auto &cluster : superCluster.clusters()) {
894  const auto &clustermapped = ebeeClusterMap.find(cluster);
895  if (clustermapped != ebeeClusterMap.end()) {
896  //make new ptr
897  reco::CaloClusterPtr clusptr(outEBEEClusterHandle,clustermapped->second);
898  clusters.push_back(clusptr);
899  }
900  else {
901  //can only relink if all clusters are being relinked, so if one is missing, then skip the relinking completely
902  clusters.clear();
903  break;
904  }
905  }
906  if (!clusters.empty()) {
907  superCluster.setClusters(clusters);
908  }
909 
910  //remap preshower clusters
911  reco::CaloClusterPtrVector esclusters;
912  for (const auto& cluster : superCluster.preshowerClusters()) {
913  const auto &clustermapped = esClusterMap.find(cluster);
914  if (clustermapped != esClusterMap.end()) {
915  //make new ptr
916  reco::CaloClusterPtr clusptr(outESClusterHandle,clustermapped->second);
917  esclusters.push_back(clusptr);
918  }
919  else {
920  //can only relink if all clusters are being relinked, so if one is missing, then skip the relinking completely
921  esclusters.clear();
922  break;
923  }
924  }
925  if (!esclusters.empty()) {
926  superCluster.setPreshowerClusters(esclusters);
927  }
928 }
929 
930 template <typename T>
932  const std::map<reco::SuperClusterRef, unsigned int>& superClusterMap,
933  const edm::OrphanHandle<reco::SuperClusterCollection>& outSuperClusterHandle)
934 {
935  const auto &scmapped = superClusterMap.find(core.superCluster());
936  if (scmapped != superClusterMap.end()) {
937  //make new ref
938  reco::SuperClusterRef scref(outSuperClusterHandle,scmapped->second);
939  core.setSuperCluster(scref);
940  }
941 }
942 
944  const std::map<reco::GsfTrackRef, unsigned int>& gsfTrackMap,
945  const edm::OrphanHandle<reco::GsfTrackCollection>& outGsfTrackHandle)
946 {
947  const auto &gsftkmapped = gsfTrackMap.find(gsfElectronCore.gsfTrack());
948  if (gsftkmapped != gsfTrackMap.end()) {
949  reco::GsfTrackRef gsftkref(outGsfTrackHandle, gsftkmapped->second);
950  gsfElectronCore.setGsfTrack(gsftkref);
951  }
952 }
953 
955  const reco::ConversionRefVector& convrefs,
956  const std::map<reco::ConversionRef, unsigned int>& conversionMap,
957  const edm::OrphanHandle<reco::ConversionCollection> &outConversionHandle)
958 {
959  reco::ConversionRefVector outconvrefs;
960  for (const auto& convref : convrefs) {
961  const auto &convmapped = conversionMap.find(convref);
962  if (convmapped != conversionMap.end()) {
963  //make new ref
964  reco::ConversionRef outref(outConversionHandle,convmapped->second);
965  }
966  else {
967  //can only relink if all conversions are being relinked, so if one is missing, then skip the relinking completely
968  outconvrefs.clear();
969  break;
970  }
971  }
972  if (!outconvrefs.empty()) {
973  photonCore.setConversions(outconvrefs);
974  }
975 }
976 
978  const std::map<reco::PhotonCoreRef, unsigned int>& photonCoreMap,
979  const edm::OrphanHandle<reco::PhotonCoreCollection>& outPhotonCoreHandle)
980 {
981  const auto &coremapped = photonCoreMap.find(photon.photonCore());
982  if (coremapped != photonCoreMap.end()) {
983  //make new ref
984  reco::PhotonCoreRef coreref(outPhotonCoreHandle,coremapped->second);
985  photon.setPhotonCore(coreref);
986  }
987 }
988 
990  const std::map<reco::GsfElectronCoreRef, unsigned int>& gsfElectronCoreMap,
991  const edm::OrphanHandle<reco::GsfElectronCoreCollection>& outgsfElectronCoreHandle)
992 {
993  const auto &coremapped = gsfElectronCoreMap.find(gsfElectron.core());
994  if (coremapped != gsfElectronCoreMap.end()) {
995  //make new ref
996  reco::GsfElectronCoreRef coreref(outgsfElectronCoreHandle,coremapped->second);
997  gsfElectron.setCore(coreref);
998  }
999 }
1000 
1002  const reco::PhotonRef& oldPhoRef,
1003  const edm::ValueMap<float>& energyMap,
1004  const edm::ValueMap<float>& energyErrMap)
1005 {
1006  float newEnergy = energyMap[oldPhoRef];
1007  float newEnergyErr = energyErrMap[oldPhoRef];
1008  photon.setCorrectedEnergy(reco::Photon::P4type::regression2, newEnergy, newEnergyErr, true);
1009 
1010 }
1011 
1013  const reco::GsfElectronRef& oldEleRef,
1014  const edm::ValueMap<float>& energyMap,
1015  const edm::ValueMap<float>& energyErrMap,
1016  const edm::ValueMap<float>& ecalEnergyMap,
1017  const edm::ValueMap<float>& ecalEnergyErrMap)
1018 {
1019  const float newEnergy = energyMap[oldEleRef];
1020  const float newEnergyErr = energyErrMap[oldEleRef];
1021  const float newEcalEnergy = ecalEnergyMap[oldEleRef];
1022  const float newEcalEnergyErr = ecalEnergyErrMap[oldEleRef];
1023 
1024  //make a copy of this as the setCorrectedEcalEnergy call with modifiy the electrons p4
1025  const math::XYZTLorentzVector oldP4 = electron.p4();
1026  const float corr = newEnergy / oldP4.E();
1027 
1028  electron.setCorrectedEcalEnergy(newEcalEnergy);
1029  electron.setCorrectedEcalEnergyError(newEcalEnergyErr);
1030 
1032  oldP4.y() * corr,
1033  oldP4.z() * corr,
1034  newEnergy);
1035  electron.correctMomentum(newP4, electron.trackMomentumError(), newEnergyErr);
1036 
1037 }
const bool doPreshowerEcalHits_
void setPreshowerClusters(const CaloClusterPtrVector &clusters)
Definition: SuperCluster.h:105
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, const CaloTopology *caloTopology, reco::CaloClusterCollection &esClusters, std::map< reco::CaloClusterPtr, unsigned int > &esClusterMap)
void relinkGsfTrack(reco::GsfElectronCore &electroncore, const std::map< reco::GsfTrackRef, unsigned int > &gsfTrackMap, const edm::OrphanHandle< reco::GsfTrackCollection > &outGsfTrackHandle)
T getParameter(std::string const &) const
const StringCutObjectSelector< reco::Photon > relinkOOTPhotonSel_
static bool matchesConversion(const reco::GsfElectron &ele, const reco::Conversion &conv, bool allowCkfMatch=true, bool allowAmbiguousGsfMatch=false)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:127
const edm::EDGetTokenT< reco::GsfElectronCollection > gsfElectronT_
float trackMomentumError() const
Definition: GsfElectron.h:825
void setCore(const reco::GsfElectronCoreRef &core)
Definition: GsfElectron.h:181
const bool applyPhotonCalibOnData_
const edm::EDGetTokenT< reco::GsfTrackCollection > gsfTrackT_
edm::EDGetTokenT< edm::ValueMap< float > > gsfElectronCalibEnergyT_
const StringCutObjectSelector< reco::Photon > slimRelinkPhotonSel_
void setGsfTrack(const GsfTrackRef &gsfTrack)
const edm::EDGetTokenT< reco::ConversionCollection > singleConversionT_
const LorentzVector & p4(P4Kind kind) const
Definition: GsfElectron.cc:225
const std::vector< std::string > outPhotonIds_
void setCorrectedEnergy(P4type type, float E, float dE, bool toCand=true)
~ReducedEGProducer() override
const std::vector< std::string > outOOTPhotonFloatValueMaps_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:508
static void calibratePhoton(reco::Photon &photon, const reco::PhotonRef &oldPhoRef, const edm::ValueMap< float > &energyMap, const edm::ValueMap< float > &energyErrMap)
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:140
edm::EDGetTokenT< edm::ValueMap< float > > photonCalibEnergyT_
void correctMomentum(const LorentzVector &p4, float trackMomentumError, float p4Error)
Definition: GsfElectron.h:847
const std::vector< std::string > outPhotonFloatValueMaps_
bool empty() const
Is the RefVector empty.
Definition: PtrVectorBase.h:71
Definition: __init__.py:1
const GsfTrackRef & gsfTrack() const
const std::string outGsfTracks_
void setToken(edm::EDGetTokenT< T > &token, const edm::ParameterSet &config, const std::string &name)
const StringCutObjectSelector< reco::GsfElectron > keepGsfElectronSel_
const std::string outOOTPhotons_
bool ev
Definition: config.py:1
const std::string outEBEEClusters_
void setSeed(const CaloClusterPtr &r)
list of used xtals by DetId // now inherited by CaloCluster
Definition: SuperCluster.h:96
const StringCutObjectSelector< reco::Photon > keepPhotonSel_
const edm::EDGetTokenT< edm::ValueMap< std::vector< reco::PFCandidateRef > > > photonPfCandMapT_
const bool applyGsfElectronCalibOnData_
const CaloClusterPtrVector & clusters() const
const access to the cluster list itself
Definition: SuperCluster.h:69
bool empty() const
Is the RefVector empty.
Definition: RefVector.h:104
edm::EDGetTokenT< edm::ValueMap< float > > photonCalibEnergyErrT_
bool isRealData() const
Definition: EventBase.h:64
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
const StringCutObjectSelector< reco::GsfElectron > relinkGsfElectronSel_
void setClusters(const CaloClusterPtrVector &clusters)
Definition: SuperCluster.h:99
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_
const std::string outEBRecHits_
const std::string outESRecHits_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
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)
reco::PhotonCoreRef photonCore() const
returns a reference to the core photon object
Definition: Photon.h:50
const int keep
const std::vector< std::string > outGsfElectronIds_
void setCorrectedEcalEnergyError(float newEnergyError)
Definition: GsfElectron.cc:179
void setPhotonCore(const reco::PhotonCoreRef &photonCore)
Definition: Photon.h:51
const std::string outSingleConversions_
const std::string outESClusters_
const std::string outOOTSuperClusters_
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
const StringCutObjectSelector< reco::Photon > keepOOTPhotonSel_
const std::string outOOTESClusters_
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)
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)
void setConversions(const reco::ConversionRefVector &conversions)
Definition: PhotonCore.h:79
const std::string outOOTEBEEClusters_
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)
const StringCutObjectSelector< reco::Photon > relinkPhotonSel_
std::vector< edm::EDGetTokenT< edm::ValueMap< float > > > gsfElectronIdTs_
edm::EDGetTokenT< edm::ValueMap< float > > gsfElectronCalibEnergyErrT_
edm::Ref< PFCandidateCollection > PFCandidateRef
persistent reference to a PFCandidate
const CaloClusterPtrVector & preshowerClusters() const
const access to the preshower cluster list itself
Definition: SuperCluster.h:72
const 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::string outPhotons_
JetCorrectorParameters corr
Definition: classes.h:5
const std::string outGsfElectronPfCandMap_
void relinkSuperCluster(T &core, const std::map< reco::SuperClusterRef, unsigned int > &superClusterMap, const edm::OrphanHandle< reco::SuperClusterCollection > &outSuperClusterHandle)
const std::string outGsfElectronCores_
std::vector< edm::EDGetTokenT< edm::ValueMap< float > > > photonFloatValueMapTs_
Definition: DetId.h:18
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
const std::string outSuperClusters_
virtual std::vector< DetId > getWindow(const DetId &id, const int &northSouthSize, const int &eastWestSize) const
const std::string outConversions_
T const * product() const
Definition: Handle.h:81
void clear()
Clear the vector.
Definition: RefVector.h:147
std::vector< Photon > PhotonCollection
collectin of Photon objects
Definition: PhotonFwd.h:9
std::vector< edm::EDGetTokenT< edm::ValueMap< float > > > ootPhotonFloatValueMapTs_
const T & get() const
Definition: EventSetup.h:55
const std::string outGsfElectrons_
const CaloSubdetectorTopology * getSubdetectorTopology(const DetId &id) const
access the subdetector Topology for the given subdetector directly
Definition: CaloTopology.cc:25
const StringCutObjectSelector< reco::GsfElectron > slimRelinkGsfElectronSel_
virtual GsfElectronCoreRef core() const
Definition: GsfElectron.cc:8
const std::string outPhotonCores_
void setCorrectedEcalEnergy(float newEnergy)
Definition: GsfElectron.cc:182
void clear()
Clear the PtrVector.
Definition: PtrVectorBase.h:80
fixed size matrix
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 std::string outEERecHits_
const StringCutObjectSelector< reco::Photon > slimRelinkOOTPhotonSel_
void produce(edm::Event &evt, const edm::EventSetup &es) final
const std::vector< std::string > outGsfElectronFloatValueMaps_
const std::string outPhotonPfCandMap_
const edm::EDGetTokenT< EcalRecHitCollection > endcapEcalHits_
const CaloClusterPtr & seed() const
seed BasicCluster
Definition: SuperCluster.h:66
size_t operator()(const DetId &id) const
std::vector< edm::EDGetTokenT< edm::ValueMap< bool > > > photonIdTs_
const std::string outOOTPhotonCores_
long double T
edm::EDGetTokenT< edm::ValueMap< float > > gsfElectronCalibEcalEnergyT_
const edm::EDGetTokenT< reco::PhotonCollection > ootPhotonT_
const edm::EDGetTokenT< EcalRecHitCollection > barrelEcalHits_
def move(src, dest)
Definition: eostools.py:510
const bool applyGsfElectronCalibOnMC_
ReducedEGProducer(const edm::ParameterSet &ps)
const edm::EDGetTokenT< reco::ConversionCollection > conversionT_