39 template <
typename TYPE>
88 std::vector<edm::InputTag>
tags = iConfig.
getParameter<std::vector<edm::InputTag>>(
"PFCandidate");
89 for (
unsigned int i = 0;
i < tags.size(); ++
i)
90 inputTagPFCandidates_.push_back(consumes<reco::PFCandidateCollection>(tags[
i]));
97 inputTagMuons_ = consumes<reco::MuonCollection>(
edm::InputTag(muonTag_.label()));
98 inputTagMuonMap_ = consumes<reco::MuonToMuonMap>(muonTag_);
106 producePFCandidates_ = iConfig.
getParameter<
bool>(
"ProducePFCandidates");
110 fillMuonRefs_ = iConfig.
getParameter<
bool>(
"FillMuonRefs");
112 forceElectronsInHGCAL_ = iConfig.
getParameter<
bool>(
"forceElectronsInHGCAL");
115 if (producePFCandidates_ && inputTagPFCandidates_.size() > 1) {
117 <<
" cannot read several collections of PFCandidates and produce a new collection at the same time. " 121 if (producePFCandidates_) {
122 produces<reco::PFCandidateCollection>(nameOutputPF_);
124 produces<edm::ValueMap<reco::PFCandidatePtr>>(nameOutputElectronsPF_);
125 produces<edm::ValueMap<reco::PFCandidatePtr>>(nameOutputPhotonsPF_);
126 produces<edm::ValueMap<reco::PFCandidatePtr>>(nameOutputMergedPF_);
128 produces<edm::ValueMap<reco::PFCandidatePtr>>(muonTag_.label());
134 auto pfCandidates_p = std::make_unique<reco::PFCandidateCollection>();
138 std::map<reco::GsfElectronRef, reco::PFCandidatePtr> electronCandidateMap;
141 std::map<reco::PhotonRef, reco::PFCandidatePtr> photonCandidateMap;
145 muonMap = iEvent.
getHandle(inputTagMuonMap_);
146 std::map<reco::MuonRef, reco::PFCandidatePtr> muonCandidateMap;
148 unsigned nColPF = inputTagPFCandidates_.size();
150 for (
unsigned icol = 0; icol < nColPF; ++icol) {
154 for (
unsigned i = 0;
i < ncand; ++
i) {
164 if (!(isphoton || iselectron || hasNonNullMuonRef)) {
165 pfCandidates_p->push_back(cand);
169 if (hasNonNullMuonRef) {
172 muonCandidateMap[muRef] = candPtr;
178 auto itcheck = find_if(gsfElectrons->begin(), gsfElectrons->end(), [&gsfTrackRef](
const auto& ele) {
179 return (ele.gsfTrack() == gsfTrackRef);
181 if (itcheck == gsfElectrons->end()) {
182 if (!forceElectronsInHGCAL_) {
183 std::ostringstream
err;
184 err <<
" Problem in PFLinker: no GsfElectron " << std::endl;
187 LogDebug(
"PFLinker") <<
"Forcing an electron pfCandidate at: " << cand.
eta() <<
" in HGCAL" << std::endl;
188 pfCandidates_p->push_back(cand);
196 cand.
setEcalEnergy(electronRef->superCluster()->rawEnergy(), electronRef->ecalEnergy());
199 electronCandidateMap[electronRef] = candPtr;
205 auto itcheck = find_if(
207 if (itcheck ==
photons->end()) {
208 std::ostringstream
err;
209 err <<
" Problem in PFLinker: no Photon " << std::endl;
221 photonCandidateMap[photonRef] = candPtr;
224 pfCandidates_p->push_back(cand);
229 (producePFCandidates_) ? iEvent.
put(
std::move(pfCandidates_p), nameOutputPF_)
235 iEvent, nameOutputElectronsPF_,
gsfElectrons, electronCandidateMap, pfCandidateRefProd);
238 iEvent, nameOutputPhotonsPF_,
photons, photonCandidateMap, pfCandidateRefProd);
243 auto muons = iEvent.getHandle(inputTagMuons_);
246 fillValueMap<reco::MuonCollection>(
iEvent, muonTag_.label(),
muons, muonCandidateMap, pfCandidateRefProd);
249 auto pfMapMerged = std::make_unique<edm::ValueMap<reco::PFCandidatePtr>>();
252 *pfMapMerged += pfMapGsfElectrons;
253 *pfMapMerged += pfMapPhotons;
255 *pfMapMerged += pfMapMuons;
257 iEvent.put(
std::move(pfMapMerged), nameOutputMergedPF_);
260 template <
typename TYPE>
267 auto pfMap_p = std::make_unique<edm::ValueMap<reco::PFCandidatePtr>>();
272 unsigned nObj = inputObjCollection->size();
273 std::vector<reco::PFCandidatePtr>
values(nObj);
275 for (
unsigned iobj = 0; iobj < nObj; ++iobj) {
277 MapTYPE_it itcheck = mapToTheCandidate.find(objRef);
281 if (itcheck != mapToTheCandidate.end())
282 candPtr = producePFCandidates_ ?
reco::PFCandidatePtr(newPFCandColl, itcheck->second.key()) : itcheck->second;
284 values[iobj] = candPtr;
287 filler.insert(inputObjCollection, values.begin(), values.end());
T getParameter(std::string const &) const
edm::InputTag muonTag_
Input Muons.
void setDeltaP(double dp)
set uncertainty on momentum
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
bool isNonnull() const
Checks for non-null.
double eta() const final
momentum pseudorapidity
void setGsfElectronRef(const reco::GsfElectronRef &ref)
set GsfElectronRef
edm::EDGetTokenT< reco::MuonCollection > inputTagMuons_
float mva_nothing_gamma() const
mva for gamma detection
void produce(edm::Event &, const edm::EventSetup &) override
bool producePFCandidates_
Flags - if true: References will be towards new collection ; if false to the original one...
edm::EDGetTokenT< reco::PhotonCollection > inputTagPhotons_
Input Photons.
PFLinker(const edm::ParameterSet &)
edm::ValueMap< reco::PFCandidatePtr > fillValueMap(edm::Event &event, std::string label, edm::Handle< TYPE > &inputObjCollection, const std::map< edm::Ref< TYPE >, reco::PFCandidatePtr > &mapToTheCandidate, const edm::OrphanHandle< reco::PFCandidateCollection > &newPFCandColl) const
edm::EDGetTokenT< reco::MuonToMuonMap > inputTagMuonMap_
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
#define DEFINE_FWK_MODULE(type)
std::string nameOutputElectronsPF_
name of output ValueMap electrons
std::string nameOutputPhotonsPF_
name of output ValueMap photons
std::string nameOutputPF_
name of output collection of PFCandidate
reco::MuonRef muonRef() const
void setEcalEnergy(float eeRaw, float eeCorr)
set corrected Ecal energy
bool fillMuonRefs_
Set muon refs and produce the value map?
void setPhotonRef(const reco::PhotonRef &phRef)
set ref to the corresponding reco::Photon if any
Particle reconstructed by the particle flow algorithm.
void setMuonRef(const reco::MuonRef &ref)
set muon reference
bool forceElectronsInHGCAL_
Put Electrons within HGCAL coming from SimPFProducer.
reco::GsfTrackRef gsfTrackRef() const
void setSuperClusterRef(const reco::SuperClusterRef &scRef)
virtual ParticleType particleId() const
edm::EDGetTokenT< reco::GsfElectronCollection > inputTagGsfElectrons_
Input GsfElectrons.
void setP4(const LorentzVector &p4) final
set 4-momentum
std::vector< edm::EDGetTokenT< reco::PFCandidateCollection > > inputTagPFCandidates_
Input PFCandidates.
std::string nameOutputMergedPF_
name of output merged ValueMap
reco::SuperClusterRef superClusterRef() const
return a reference to the corresponding SuperCluster if any