CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFGSFixLinker.cc
Go to the documentation of this file.
2 
4 
8 
11 
13 
15 
17 
19  electronsMapName_(_config.getParameter<std::string>("ValueMapElectrons")),
20  photonsMapName_(_config.getParameter<std::string>("ValueMapPhotons"))
21 {
22  getToken(inputCandidatesToken_, _config, "PFCandidate");
23  getToken(inputElectronsToken_, _config, "GsfElectrons");
24  getToken(inputPhotonsToken_, _config, "Photons");
25  getToken(electronMapToken_, _config, "GsfElectrons");
26  getToken(photonMapToken_, _config, "Photons");
27 
28  produces<reco::PFCandidateCollection>();
29  // new to old
30  produces<PFPtrMap>();
31 
32  // e/g collections to PF
33  produces<PFPtrMap>(electronsMapName_);
34  produces<PFPtrMap>(photonsMapName_);
35 }
36 
38 {
39 }
40 
41 void
43 {
44  std::auto_ptr<reco::PFCandidateCollection> pOutput(new reco::PFCandidateCollection);
45 
46  auto& inCandidates(*getHandle(_event, inputCandidatesToken_, "PFCandidate"));
47  auto&& inElectronsHandle(getHandle(_event, inputElectronsToken_, "GsfElectrons"));
48  auto& electronMap(*getHandle(_event, electronMapToken_, "GsfElectronsMap"));
49  auto&& inPhotonsHandle(getHandle(_event, inputPhotonsToken_, "Photons"));
50  auto& photonMap(*getHandle(_event, photonMapToken_, "PhotonsMap"));
51 
52  std::vector<reco::PFCandidatePtr> oldPtrs;
53  std::vector<unsigned> pfElectronIndices(inElectronsHandle->size(), -1);
54  std::vector<unsigned> pfPhotonIndices(inPhotonsHandle->size(), -1);
55 
56  unsigned iP(0);
57  for (auto& inCand : inCandidates) {
58  oldPtrs.emplace_back(inCandidates.ptrAt(iP++));
59 
60  pOutput->emplace_back(inCand);
61  auto& outCand(pOutput->back());
62 
63  auto&& eRef(inCand.gsfElectronRef());
64  if (eRef.isNonnull()) {
65  auto&& newERef(GainSwitchTools::findNewRef(eRef, inElectronsHandle, electronMap));
66  auto& newE(*newERef);
67  auto& newSC(*newE.superCluster());
68 
69  pfElectronIndices[newERef.key()] = pOutput->size() - 1;
70 
71  outCand.setGsfElectronRef(newERef);
72  outCand.setSuperClusterRef(newE.superCluster());
73  outCand.setEcalEnergy(newSC.rawEnergy(), newE.ecalEnergy());
74  outCand.setDeltaP(newE.p4Error(reco::GsfElectron::P4_COMBINATION));
75  outCand.setP4(newE.p4(reco::GsfElectron::P4_COMBINATION));
76  }
77 
78  auto&& phRef(inCand.photonRef());
79  if (phRef.isNonnull()) {
80  auto&& newPhRef(GainSwitchTools::findNewRef(phRef, inPhotonsHandle, photonMap));
81  auto& newPh(*newPhRef);
82  auto& newSC(*newPh.superCluster());
83 
84  pfPhotonIndices[newPhRef.key()] = pOutput->size() - 1;
85 
86  outCand.setPhotonRef(newPhRef);
87  outCand.setSuperClusterRef(newPh.superCluster());
88  outCand.setEcalEnergy(newSC.rawEnergy(), newPh.getCorrectedEnergy(reco::Photon::regression2));
89  outCand.setDeltaP(newPh.getCorrectedEnergyError(reco::Photon::regression2));
90  outCand.setP4(newPh.p4(reco::Photon::regression2));
91  }
92  }
93 
94  auto&& outCandsHandle(_event.put(pOutput));
95 
96  std::auto_ptr<PFPtrMap> pPFMap(new PFPtrMap);
97  PFPtrMap::Filler pfMapFiller(*pPFMap);
98  pfMapFiller.insert(outCandsHandle, oldPtrs.begin(), oldPtrs.end());
99  pfMapFiller.fill();
100  _event.put(pPFMap);
101 
102  std::vector<reco::PFCandidatePtr> pfElectrons;
103  for (unsigned idx : pfElectronIndices) {
104  if (idx == unsigned(-1))
105  pfElectrons.emplace_back();
106  else
107  pfElectrons.emplace_back(outCandsHandle, idx);
108  }
109 
110  std::auto_ptr<PFPtrMap> pEleMap(new PFPtrMap);
111  PFPtrMap::Filler eleMapFiller(*pEleMap);
112  eleMapFiller.insert(inElectronsHandle, pfElectrons.begin(), pfElectrons.end());
113  eleMapFiller.fill();
114  _event.put(pEleMap, electronsMapName_);
115 
116  std::vector<reco::PFCandidatePtr> pfPhotons;
117  for (unsigned idx : pfPhotonIndices) {
118  if (idx == unsigned(-1))
119  pfPhotons.emplace_back();
120  else
121  pfPhotons.emplace_back(outCandsHandle, idx);
122  }
123 
124  std::auto_ptr<PFPtrMap> pPhoMap(new PFPtrMap);
125  PFPtrMap::Filler phoMapFiller(*pPhoMap);
126  phoMapFiller.insert(inPhotonsHandle, pfPhotons.begin(), pfPhotons.end());
127  phoMapFiller.fill();
128  _event.put(pPhoMap, photonsMapName_);
129 }
130 
edm::Handle< T > getHandle(edm::Event const &_event, edm::EDGetTokenT< T > const &token, std::string const &name)
Definition: PFGSFixLinker.h:37
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
void produce(edm::Event &, const edm::EventSetup &) override
std::string electronsMapName_
Definition: PFGSFixLinker.h:58
PFGSFixLinker(const edm::ParameterSet &)
edm::EDGetTokenT< reco::PhotonCollection > inputPhotonsToken_
Definition: PFGSFixLinker.h:53
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
edm::EDGetTokenT< PFCandidateView > inputCandidatesToken_
Definition: PFGSFixLinker.h:51
edm::EDGetTokenT< ElectronRefMap > electronMapToken_
Definition: PFGSFixLinker.h:55
edm::EDGetTokenT< reco::GsfElectronCollection > inputElectronsToken_
Definition: PFGSFixLinker.h:52
void getToken(edm::EDGetTokenT< T > &token, edm::ParameterSet const &pset, std::string const &label)
Definition: PFGSFixLinker.h:31
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
edm::ValueMap< reco::PFCandidatePtr > PFPtrMap
std::string photonsMapName_
Definition: PFGSFixLinker.h:59
static edm::Ref< typename H::element_type > findNewRef(R const &, H const &, M const &)
edm::EDGetTokenT< PhotonRefMap > photonMapToken_
Definition: PFGSFixLinker.h:56