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