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