57 std::vector<const reco::PFCluster*>&,
62 unsigned plane)
const;
91 void getAmbiguousGsfTracks(
const reco::PFBlockElement& PFBE, std::vector<reco::GsfTrackRef>&)
const;
137 std::map<reco::GsfTrackRef, reco::SuperClusterRef>
scMap_;
151 if (useIsolationValues) {
152 if (!iConfig.
exists(
"isolationValues"))
153 throw cms::Exception(
"PFElectronTranslator|InternalError") <<
"Missing ParameterSet isolationValues";
172 checkStatusFlag_ = iConfig.
getParameter<
bool>(
"CheckStatusFlag");
174 if (iConfig.
exists(
"emptyIsOk"))
179 produces<reco::BasicClusterCollection>(PFBasicClusterCollection_);
180 produces<reco::PreshowerClusterCollection>(PFPreshowerClusterCollection_);
181 produces<reco::SuperClusterCollection>(PFSuperClusterCollection_);
182 produces<reco::GsfElectronCoreCollection>(GsfElectronCoreCollection_);
183 produces<reco::GsfElectronCollection>(GsfElectronCollection_);
184 produces<edm::ValueMap<float>>(PFMVAValueMap_);
185 produces<edm::ValueMap<reco::SuperClusterRef>>(PFSCValueMap_);
191 auto gsfElectronCores_p = std::make_unique<reco::GsfElectronCoreCollection>();
193 auto gsfElectrons_p = std::make_unique<reco::GsfElectronCollection>();
195 auto superClusters_p = std::make_unique<reco::SuperClusterCollection>();
197 auto basicClusters_p = std::make_unique<reco::BasicClusterCollection>();
199 auto psClusters_p = std::make_unique<reco::PreshowerClusterCollection>();
201 auto mvaMap_p = std::make_unique<edm::ValueMap<float>>();
204 auto scMap_p = std::make_unique<edm::ValueMap<reco::SuperClusterRef>>();
208 bool status = fetchCandidateCollection(pfCandidates, inputTagPFCandidates_, iEvent);
211 for (
size_t j = 0;
j < inputTagIsoVals_.size(); ++
j) {
216 GsfTrackRef_.clear();
217 CandidatePtr_.clear();
218 ambiguousGsfTracks_.clear();
220 basicClusters_.clear();
222 preshowerClusters_.clear();
223 superClusters_.clear();
224 basicClusterPtr_.clear();
225 preshowerClusterPtr_.clear();
226 gsfPFCandidateIndex_.clear();
227 gsfElectronCoreRefs_.clear();
235 unsigned ncand = (
status) ? pfCandidates->size() : 0;
237 for (
unsigned i = 0;
i < ncand; ++
i) {
254 kfTrackRef_.push_back(cand.
trackRef());
255 gsfPFCandidateIndex_.push_back(
i);
259 CandidatePtr_.push_back(ptrToPFElectron);
262 pfClusters_.push_back(std::vector<const reco::PFCluster*>());
264 ambiguousGsfTracks_.push_back(std::vector<reco::GsfTrackRef>());
285 createBasicCluster(pfbe, basicClusters_[iGSF], pfClusters_[iGSF], correspondingDaughterCandidate(cand, pfbe));
288 createPreshowerCluster(pfbe, preshowerClusters_[iGSF], 1);
291 createPreshowerCluster(pfbe, preshowerClusters_[iGSF], 2);
294 getAmbiguousGsfTracks(pfbe, ambiguousGsfTracks_[iGSF]);
300 basicClusters_p->insert(basicClusters_p->end(), basicClusters_[iGSF].begin(), basicClusters_[iGSF].end());
302 psClusters_p->insert(psClusters_p->end(), preshowerClusters_[iGSF].begin(), preshowerClusters_[iGSF].end());
310 iEvent.
put(
std::move(basicClusters_p), PFBasicClusterCollection_);
314 iEvent.
put(
std::move(psClusters_p), PFPreshowerClusterCollection_);
317 createBasicClusterPtrs(bcRefProd);
319 createPreshowerClusterPtrs(psRefProd);
323 createSuperClusters(*pfCandidates, *superClusters_p);
327 iEvent.
put(
std::move(superClusters_p), PFSuperClusterCollection_);
329 createSuperClusterGsfMapRefs(scRefProd);
332 createGsfElectronCores(*gsfElectronCores_p);
335 iEvent.
put(
std::move(gsfElectronCores_p), GsfElectronCoreCollection_);
338 createGsfElectronCoreRefs(gsfElectronCoreRefProd);
342 iEvent.
put(
std::move(gsfElectrons_p), GsfElectronCollection_);
344 fillMVAValueMap(iEvent, mvaFiller);
347 fillSCRefValueMap(iEvent, scRefFiller);
361 if (!found && !emptyIsOk_) {
362 std::ostringstream
err;
363 err <<
" cannot get PFCandidates: " << tag << std::endl;
375 std::ostringstream
err;
376 err <<
" cannot get GSFTracks: " << tag << std::endl;
387 std::vector<const reco::PFCluster*>& pfClusters,
390 if (myPFClusterRef.
isNull())
394 pfClusters.push_back(&myPFCluster);
406 myPFCluster.
seed()));
411 unsigned plane)
const {
414 myPFClusterRef->energy(), myPFClusterRef->position(), myPFClusterRef->hitsAndFractions(), plane));
419 unsigned size = GsfTrackRef_.size();
420 unsigned basicClusterCounter = 0;
421 basicClusterPtr_.resize(size);
423 for (
unsigned iGSF = 0; iGSF <
size; ++iGSF)
425 unsigned nbc = basicClusters_[iGSF].size();
426 for (
unsigned ibc = 0; ibc < nbc; ++ibc)
430 basicClusterPtr_[iGSF].push_back(bcPtr);
431 ++basicClusterCounter;
438 unsigned size = GsfTrackRef_.size();
439 unsigned psClusterCounter = 0;
440 preshowerClusterPtr_.resize(size);
442 for (
unsigned iGSF = 0; iGSF <
size; ++iGSF)
444 unsigned nbc = preshowerClusters_[iGSF].size();
445 for (
unsigned ibc = 0; ibc < nbc; ++ibc)
449 preshowerClusterPtr_[iGSF].push_back(psPtr);
457 unsigned size = GsfTrackRef_.size();
459 for (
unsigned iGSF = 0; iGSF <
size; ++iGSF)
462 scMap_[GsfTrackRef_[iGSF]] = scRef;
469 bool status = fetchCandidateCollection(pfCandidates, inputTagPFCandidateElectrons_, iEvent);
471 unsigned ncand = (
status) ? pfCandidates->size() : 0;
472 for (
unsigned i = 0;
i < ncand; ++
i) {
483 fetchGsfCollection(gsfTracks, inputTagGSFTracks_, iEvent);
484 unsigned ngsf = gsfTracks->size();
485 std::vector<float>
values;
486 for (
unsigned igsf = 0; igsf < ngsf; ++igsf) {
488 std::map<reco::GsfTrackRef, float>::const_iterator itcheck = gsfMvaMap_.find(theTrackRef);
489 if (itcheck == gsfMvaMap_.end()) {
491 values.push_back(-99.);
495 values.push_back(itcheck->second);
498 filler.
insert(gsfTracks, values.begin(), values.end());
504 fetchGsfCollection(gsfTracks, inputTagGSFTracks_, iEvent);
505 unsigned ngsf = gsfTracks->size();
506 std::vector<reco::SuperClusterRef>
values;
507 for (
unsigned igsf = 0; igsf < ngsf; ++igsf) {
509 std::map<reco::GsfTrackRef, reco::SuperClusterRef>::const_iterator itcheck = scMap_.find(theTrackRef);
510 if (itcheck == scMap_.end()) {
514 values.push_back(itcheck->second);
517 filler.
insert(gsfTracks, values.begin(), values.end());
522 unsigned nGSF = GsfTrackRef_.size();
523 for (
unsigned iGSF = 0; iGSF < nGSF; ++iGSF) {
525 double sclusterE = 0;
530 unsigned nbasics = basicClusters_[iGSF].size();
531 for (
unsigned ibc = 0; ibc < nbasics; ++ibc) {
532 double e = basicClusters_[iGSF][ibc].energy();
534 posX += e * basicClusters_[iGSF][ibc].position().X();
535 posY += e * basicClusters_[iGSF][ibc].position().Y();
536 posZ += e * basicClusters_[iGSF][ibc].position().Z();
542 if (pfCand[gsfPFCandidateIndex_[iGSF]].gsfTrackRef() != GsfTrackRef_[iGSF]) {
543 edm::LogError(
"PFElectronTranslator") <<
" Major problem in PFElectron Translator" << std::endl;
549 double correctedEnergy = pfCand[gsfPFCandidateIndex_[iGSF]].ecalEnergy();
556 mySuperCluster.
setSeed(basicClusterPtr_[iGSF][0]);
567 for (
unsigned ibc = 0; ibc < nbasics; ++ibc) {
568 mySuperCluster.
addCluster(basicClusterPtr_[iGSF][ibc]);
570 const std::vector<std::pair<DetId, float>>& v1 = basicClusters_[iGSF][ibc].hitsAndFractions();
572 for (std::vector<std::pair<DetId, float>>::const_iterator diIt = v1.begin(); diIt != v1.end(); ++diIt) {
578 unsigned nps = preshowerClusterPtr_[iGSF].size();
579 for (
unsigned ips = 0; ips < nps; ++ips) {
585 pfCand[gsfPFCandidateIndex_[iGSF]].pS2Energy());
592 superClusters.push_back(mySuperCluster);
598 unsigned refindex = pfbe.
index();
603 for (; myDaughterCandidate != itend; ++myDaughterCandidate) {
611 return *myPFCandidate;
618 unsigned nGSF = GsfTrackRef_.size();
619 for (
unsigned iGSF = 0; iGSF < nGSF; ++iGSF) {
621 myElectronCore.
setCtfTrack(kfTrackRef_[iGSF], -1.);
622 std::map<reco::GsfTrackRef, reco::SuperClusterRef>::const_iterator itcheck = scMap_.find(GsfTrackRef_[iGSF]);
623 if (itcheck != scMap_.end())
625 gsfElectronCores.push_back(myElectronCore);
631 unsigned size = GsfTrackRef_.size();
633 for (
unsigned iGSF = 0; iGSF <
size; ++iGSF)
636 gsfElectronCoreRefs_.push_back(elecCoreRef);
641 std::vector<reco::GsfTrackRef>&
tracks)
const {
643 if (GsfEl ==
nullptr)
645 const std::vector<reco::GsfPFRecTrackRef>& ambPFRecTracks(GsfEl->
GsftrackRefPF()->convBremGsfPFRecTrackRef());
646 unsigned ntracks = ambPFRecTracks.size();
647 for (
unsigned it = 0; it < ntracks; ++it) {
648 tracks.push_back(ambPFRecTracks[it]->gsfTrackRef());
655 unsigned size = GsfTrackRef_.size();
657 for (
unsigned iGSF = 0; iGSF <
size; ++iGSF)
688 unsigned ntracks = ambiguousGsfTracks_[iGSF].size();
689 for (
unsigned it = 0; it < ntracks; ++it) {
694 if (!isolationValues.empty()) {
697 myPFIso.
sumPhotonEt = (*isolationValues[1])[CandidatePtr_[iGSF]];
699 myPFIso.
sumPUPt = (*isolationValues[3])[CandidatePtr_[iGSF]];
703 gsfelectrons.push_back(myElectron);
T getParameter(std::string const &) const
std::string PFPreshowerClusterCollection_
Abstract base class for a PFBlock element (track, cluster...)
const math::XYZPoint & position() const
cluster centroid position
void setCtfTrack(const TrackRef &closestCtfTrack, float ctfGsfOverlap)
void setP4(P4Kind kind, const LorentzVector &p4, float p4Error, bool setCandidate)
void MustacheID(const CaloClusterPtrVector &clusters, int &nclusters, float &EoutsideMustache)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
std::string PFMVAValueMap_
bool fetchCandidateCollection(edm::Handle< reco::PFCandidateCollection > &c, const edm::InputTag &tag, const edm::Event &iEvent) const
double rawEcalEnergy() const
return corrected Ecal energy
virtual SuperClusterRef parentSuperCluster() const
void addHitAndFraction(DetId id, float fraction)
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
void produce(edm::Event &, const edm::EventSetup &) override
void createGsfElectronCoreRefs(const edm::OrphanHandle< reco::GsfElectronCoreCollection > &gsfElectronCoreHandle)
virtual const PFClusterRef & clusterRef() const
std::vector< reco::CaloClusterPtrVector > basicClusterPtr_
std::vector< reco::GsfElectronCoreRef > gsfElectronCoreRefs_
double pflowPhiWidth() const
void setMvaInput(const MvaInput &mi)
void insert(const H &h, I begin, I end)
void createBasicClusterPtrs(const edm::OrphanHandle< reco::BasicClusterCollection > &basicClustersHandle)
float sumPUPt
sum pt of charged Particles not from PV (for Pu corrections)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
~PFElectronTranslator() override
const GsfPFRecTrackRef & GsftrackRefPF() const
void setSeed(const CaloClusterPtr &r)
list of used xtals by DetId // now inherited by CaloCluster
std::string GsfElectronCollection_
std::vector< std::vector< const reco::PFCluster * > > pfClusters_
void setPfIsolationVariables(const PflowIsolationVariables &iso)
void setPhiWidth(double pw)
void setMvaOutput(const MvaOutput &mo)
double pflowEtaWidth() const
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
std::map< reco::GsfTrackRef, float > gsfMvaMap_
void fillSCRefValueMap(edm::Event &iEvent, edm::ValueMap< reco::SuperClusterRef >::Filler &filler) const
reco::TrackRef trackRef() const
AlgoId algo() const
algorithm identifier
std::map< reco::GsfTrackRef, reco::SuperClusterRef > scMap_
void setEtaWidth(double ew)
std::vector< reco::GsfTrackRef > GsfTrackRef_
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
#define DEFINE_FWK_MODULE(type)
void fillMVAValueMap(edm::Event &iEvent, edm::ValueMap< float >::Filler &filler)
void setParentSuperCluster(const SuperClusterRef &scl)
const CaloID & caloID() const
const reco::PFCandidate & correspondingDaughterCandidate(const reco::PFCandidate &cand, const reco::PFBlockElement &pfbe) const
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
float sumPhotonEt
sum pt of PF photons // old float photonIso ;
const_iterator end() const
last daughter const_iterator
std::vector< GsfElectronCore > GsfElectronCoreCollection
std::vector< reco::PreshowerClusterCollection > preshowerClusters_
void createSuperClusterGsfMapRefs(const edm::OrphanHandle< reco::SuperClusterCollection > &superClustersHandle)
std::vector< PreshowerCluster > PreshowerClusterCollection
collection of PreshowerCluster objects
const LorentzVector & p4() const final
four-momentum Lorentz vector
float sumNeutralHadronEt
sum pt of neutral hadrons // old float neutralHadronIso ;
std::vector< int > gsfPFCandidateIndex_
std::vector< edm::Handle< edm::ValueMap< double > > > IsolationValueMaps
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
edm::InputTag inputTagPFCandidateElectrons_
bool isNull() const
Checks for null.
std::vector< reco::CandidatePtr > CandidatePtr_
edm::InputTag inputTagPFCandidates_
std::vector< std::vector< reco::GsfTrackRef > > ambiguousGsfTracks_
edm::InputTag inputTagGSFTracks_
float mva_e_pi() const
mva for electron-pion discrimination
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
double rawEnergy() const
raw uncorrected energy (sum of energies of component BasicClusters)
reco::PFCandidateElectronExtraRef electronExtraRef() const
return a reference to the electron extra
DetId seed() const
return DetId of seed
void fetchGsfCollection(edm::Handle< reco::GsfTrackCollection > &c, const edm::InputTag &tag, const edm::Event &iEvent) const
std::string PFBasicClusterCollection_
void createBasicCluster(const reco::PFBlockElement &, reco::BasicClusterCollection &basicClusters, std::vector< const reco::PFCluster * > &, const reco::PFCandidate &coCandidate) const
std::vector< reco::SuperClusterCollection > superClusters_
XYZPointD XYZPoint
point in space with cartesian internal representation
std::vector< reco::CaloClusterPtrVector > preshowerClusterPtr_
void createSuperClusters(const reco::PFCandidateCollection &, reco::SuperClusterCollection &superClusters) const
void addPreshowerCluster(const CaloClusterPtr &r)
add reference to constituent BasicCluster
void getAmbiguousGsfTracks(const reco::PFBlockElement &PFBE, std::vector< reco::GsfTrackRef > &) const
std::string GsfElectronCoreCollection_
std::vector< BasicCluster > BasicClusterCollection
collection of BasicCluster objects
std::vector< edm::InputTag > inputTagIsoVals_
void addCluster(const CaloClusterPtr &r)
add reference to constituent BasicCluster
std::vector< reco::BasicClusterCollection > basicClusters_
Particle reconstructed by the particle flow algorithm.
std::vector< reco::TrackRef > kfTrackRef_
void createPreshowerCluster(const reco::PFBlockElement &PFBE, reco::PreshowerClusterCollection &preshowerClusters, unsigned plane) const
PFElectronTranslator(const edm::ParameterSet &)
reco::GsfTrackRef gsfTrackRef() const
const_iterator begin() const
first daughter const_iterator
std::string PFSCValueMap_
std::string PFSuperClusterCollection_
void createGsfElectronCores(reco::GsfElectronCoreCollection &) const
virtual ParticleType particleId() const
void createGsfElectrons(const reco::PFCandidateCollection &, const IsolationValueMaps &isolationValues, reco::GsfElectronCollection &)
const ElementsInBlocks & elementsInBlocks() const
float sumChargedHadronPt
sum-pt of charged Hadron // old float chargedHadronIso ;
void addAmbiguousGsfTrack(const reco::GsfTrackRef &t)
void createPreshowerClusterPtrs(const edm::OrphanHandle< reco::PreshowerClusterCollection > &preshowerClustersHandle)
double deltaP() const
uncertainty on 3-momentum
void setPreshowerEnergy(double preshowerEnergy)