77 std::vector<unsigned int>& secondaries,
84 bool& bothGsfEcalDriven,
92 bool& bothGsfTrackerDriven,
103 std::vector<reco::GsfPFRecTrack>& gsfPFRecTrackPrimary,
104 const std::map<
unsigned int, std::vector<reco::GsfPFRecTrack> >& MapPrimSec);
161 using namespace reco;
184 produces<GsfPFRecTrackCollection>();
185 produces<GsfPFRecTrackCollection>(
"Secondary").setBranchAlias(
"secondary");
217 auto gsfPFRecTrackCollection = std::make_unique<GsfPFRecTrackCollection>();
219 auto gsfPFRecTrackCollectionSecondary = std::make_unique<GsfPFRecTrackCollection>();
258 vector<Trajectory> tjvec(0);
265 vector<reco::GsfPFRecTrack> selGsfPFRecTracks;
266 vector<reco::GsfPFRecTrack> primaryGsfPFRecTracks;
267 std::map<unsigned int, std::vector<reco::GsfPFRecTrack> > GsfPFMap;
269 for (
unsigned igsf = 0; igsf < gsftracks.size(); igsf++) {
280 for (
unsigned int igsf = 0; igsf < gsftracks.size(); igsf++) {
283 int kf_ind =
FindPfRef(PfRTkColl, gsftracks[igsf],
false);
291 bool isEcalDriven =
true;
292 bool isTrackerDriven =
true;
294 if (trackRef->seedRef().
get() ==
nullptr) {
295 isEcalDriven =
false;
296 isTrackerDriven =
false;
298 auto const& SeedFromRef = static_cast<ElectronSeed const&>(*(trackRef->extra()->seedRef()));
299 if (SeedFromRef.caloCluster().isNull())
300 isEcalDriven =
false;
301 if (SeedFromRef.ctfTrack().isNull())
302 isTrackerDriven =
false;
325 bool validgsfbrem =
false;
336 if (validgsfbrem && passSel)
337 selGsfPFRecTracks.push_back(
pftrack_);
340 unsigned int count_primary = 0;
341 if (!selGsfPFRecTracks.empty()) {
342 for (
unsigned int ipfgsf = 0; ipfgsf < selGsfPFRecTracks.size(); ipfgsf++) {
343 vector<unsigned int> secondaries(0);
348 keepGsf =
resolveGsfTracks(selGsfPFRecTracks, ipfgsf, secondaries, theEcalClusters);
352 if (keepGsf ==
true) {
355 thePrimaryVertexColl,
364 selGsfPFRecTracks[ipfgsf])) {
365 const vector<PFRecTrackRef>& convBremPFRecTracks(
convBremFinder_->getConvBremPFRecTracks());
366 for (
unsigned int ii = 0;
ii < convBremPFRecTracks.size();
ii++) {
367 selGsfPFRecTracks[ipfgsf].addConvBremPFRecTrackRef(convBremPFRecTracks[
ii]);
373 primaryGsfPFRecTracks.push_back(selGsfPFRecTracks[ipfgsf]);
378 unsigned int primGsfIndex = selGsfPFRecTracks[ipfgsf].trackId();
379 vector<reco::GsfPFRecTrack> trueGsfPFRecTracks;
380 if (!secondaries.empty()) {
382 for (
unsigned int isecpfgsf = 0; isecpfgsf < secondaries.size(); isecpfgsf++) {
383 PFRecTrackRef refsecKF = selGsfPFRecTracks[(secondaries[isecpfgsf])].kfPFRecTrackRef();
385 unsigned int secGsfIndex = selGsfPFRecTracks[(secondaries[isecpfgsf])].trackId();
386 GsfTrackRef secGsfRef = selGsfPFRecTracks[(secondaries[isecpfgsf])].gsfTrackRef();
399 bool validgsfbrem =
false;
408 gsfPFRecTrackCollectionSecondary->push_back(
secpftrack_);
413 GsfPFMap.insert(pair<
unsigned int, std::vector<reco::GsfPFRecTrack> >(count_primary, trueGsfPFRecTracks));
414 trueGsfPFRecTracks.clear();
426 for (
unsigned int iGSF = 0; iGSF < primaryGsfPFRecTracks.size(); iGSF++) {
427 gsfPFRecTrackCollection->push_back(primaryGsfPFRecTracks[iGSF]);
431 selGsfPFRecTracks.clear();
433 primaryGsfPFRecTracks.clear();
441 std::vector<reco::GsfPFRecTrack>& gsfPFRecTrackPrimary,
442 const std::map<
unsigned int, std::vector<reco::GsfPFRecTrack> >& MapPrimSec) {
443 unsigned int cgsf = 0;
444 unsigned int csecgsf = 0;
445 for (
std::map<
unsigned int, std::vector<reco::GsfPFRecTrack> >::const_iterator igsf = MapPrimSec.begin();
446 igsf != MapPrimSec.end();
448 vector<reco::GsfPFRecTrack> SecGsfPF = igsf->second;
449 for (
unsigned int iSecGsf = 0; iSecGsf < SecGsfPF.size(); iSecGsf++) {
451 gsfPFRecTrackPrimary[cgsf].addConvBremGsfPFRecTrackRef(refgprt);
464 auto const& ElSeedFromRef = static_cast<ElectronSeed const&>(*(gsftk.
extra()->seedRef()));
466 if (ElSeedFromRef.ctfTrack().isNull()) {
467 reco::PFRecTrackCollection::const_iterator pft = PfRTkColl.begin();
468 reco::PFRecTrackCollection::const_iterator pftend = PfRTkColl.end();
469 unsigned int i_pf = 0;
471 unsigned int ish_max = 0;
475 for (; pft != pftend; ++pft) {
476 unsigned int ish = 0;
478 float dph = fabs(pft->trackRef()->phi() - gsftk.
phi());
481 float det = fabs(pft->trackRef()->eta() - gsftk.
eta());
482 float dr =
sqrt(dph * dph + det * det);
484 for (
auto const& hhit : pft->trackRef()->recHits()) {
485 if (!hhit->isValid())
489 for (;
hit != hit_end; ++
hit) {
490 if (!(
hit->isValid()))
499 if ((ish > ish_max) || ((ish == ish_max) && (
dr < dr_min))) {
510 if ((ish_max == 0) || (dr_min > 0.05))
512 if (otherColl && (ish_max == 0))
518 reco::PFRecTrackCollection::const_iterator pft = PfRTkColl.begin();
519 reco::PFRecTrackCollection::const_iterator pftend = PfRTkColl.end();
520 unsigned int i_pf = 0;
522 for (; pft != pftend; ++pft) {
524 if (pft->trackRef() == ElSeedFromRef.ctfTrack()) {
537 auto const& ElSeedFromRef = static_cast<ElectronSeed const&>(*(gsftk.
extra()->seedRef()));
539 bool passCut =
false;
540 if (ElSeedFromRef.ctfTrack().isNull()) {
541 if (ElSeedFromRef.caloCluster().isNull())
543 auto const* scRef = static_cast<SuperCluster const*>(ElSeedFromRef.caloCluster().get());
546 float caloEne = scRef->energy();
548 float fphi = fabs(scRef->phi() - gsftk.
phiMode());
562 vector<unsigned int>& secondaries,
565 bool n_keepGsf =
true;
569 if (nGsfTrack->seedRef().
get() ==
nullptr)
571 auto const& nElSeedFromRef = static_cast<ElectronSeed const&>(*(nGsfTrack->extra()->seedRef()));
584 float neta = nGsfTrack->innerMomentum().eta();
585 float nphi = nGsfTrack->innerMomentum().phi();
588 cout <<
" PFElecTkProducer:: considering track " << nGsfTrack->pt() <<
" eta,phi " << nGsfTrack->eta() <<
", "
589 << nGsfTrack->phi() << endl;
591 for (
unsigned int igsf = 0; igsf < GsfPFVec.size(); igsf++) {
596 cout <<
" PFElecTkProducer:: and comparing with track " << iGsfTrack->pt() <<
" eta,phi " << iGsfTrack->eta()
597 <<
", " << iGsfTrack->phi() << endl;
599 float ieta = iGsfTrack->innerMomentum().eta();
600 float iphi = iGsfTrack->innerMomentum().phi();
607 if (
feta < 0.5 && fabs(fphi) < 1.0) {
609 cout <<
" Entering angular superloose preselection " << endl;
622 if (iGsfTrack->seedRef().
get() ==
nullptr)
624 auto const& iElSeedFromRef = static_cast<ElectronSeed const&>(*(iGsfTrack->extra()->seedRef()));
628 bool areBothGsfEcalDriven =
false;
630 bool isSameSC =
isSameEgSC(nElSeedFromRef, iElSeedFromRef, areBothGsfEcalDriven,
SCEnergy);
633 if (areBothGsfEcalDriven) {
638 cout <<
" Entering SAME supercluster case "
639 <<
" nEP " << nEP <<
" iEP " << iEP << endl;
645 bool isSameLayer =
false;
649 cout <<
" iGsf is InnerMostWithLostHits " << iGsfInnermostWithLostHits <<
" isSameLayer " << isSameLayer
652 if (iGsfInnermostWithLostHits) {
655 }
else if (isSameLayer) {
656 if (fabs(iEP - 1) < fabs(nEP - 1)) {
660 secondaries.push_back(igsf);
664 secondaries.push_back(igsf);
669 float minBremDphi =
minTangDist(GsfPFVec[ngsf], GsfPFVec[igsf]);
672 bool isBothGsfTrackerDriven =
false;
673 bool nEcalDriven =
false;
674 bool iEcalDriven =
false;
680 isBothGsfTrackerDriven,
687 bool isSameLayer =
false;
694 cout <<
" Sharing ECAL energy passed "
695 <<
" nEtot " << nETot <<
" iEtot " << iETot << endl;
696 if (isBothGsfTrackerDriven)
697 cout <<
" Both Track are trackerDriven " << endl;
701 if (iGsfInnermostWithLostHits) {
704 }
else if (isSameLayer) {
712 if (isBothGsfTrackerDriven ==
false) {
718 secondaries.push_back(igsf);
725 if (nETot != iETot) {
733 float nEP = ETot / nPin;
734 float iEP = ETot / iPin;
737 cout <<
" nETot " << nETot <<
" iETot " << iETot <<
" ETot " << ETot << endl
738 <<
" nPin " << nPin <<
" iPin " << iPin <<
" nEP " << nEP <<
" iEP " << iEP << endl;
740 if (fabs(iEP - 1) < fabs(nEP - 1)) {
744 secondaries.push_back(igsf);
748 secondaries.push_back(igsf);
752 bool secPushedBack =
false;
753 if (nEcalDriven ==
false && nETot == 0.) {
756 }
else if (iEcalDriven ==
false && iETot == 0.) {
757 secondaries.push_back(igsf);
758 secPushedBack =
true;
761 cout <<
" Close Tracks "
762 <<
" feta " <<
feta <<
" fabs(fphi) " << fabs(fphi) <<
" minBremDphi " << minBremDphi <<
" nETot "
763 << nETot <<
" iETot " << iETot <<
" nLostHits "
764 << nGsfTrack->hitPattern().numberOfLostHits(HitPattern::MISSING_INNER_HITS) <<
" iLostHits "
765 << iGsfTrack->hitPattern().numberOfLostHits(HitPattern::MISSING_INNER_HITS) << endl;
769 if (iGsfInnermostWithLostHits) {
772 }
else if (isSameLayer ==
false) {
773 if (secPushedBack ==
false)
774 secondaries.push_back(igsf);
777 }
else if (
feta < 0.1 && minBremDphi < 0.2) {
781 cout <<
" Close Tracks and failed all the conditions "
782 <<
" feta " <<
feta <<
" fabs(fphi) " << fabs(fphi) <<
" minBremDphi " << minBremDphi <<
" nETot "
783 << nETot <<
" iETot " << iETot <<
" nLostHits "
784 << nGsfTrack->hitPattern().numberOfLostHits(HitPattern::MISSING_INNER_HITS) <<
" iLostHits "
785 << iGsfTrack->hitPattern().numberOfLostHits(HitPattern::MISSING_INNER_HITS) << endl;
787 if (nEcalDriven ==
false && nETot == 0.) {
803 std::vector<reco::PFBrem> primPFBrem = primGsf.
PFRecBrem();
804 std::vector<reco::PFBrem> secPFBrem = secGsf.
PFRecBrem();
806 unsigned int cbrem = 0;
807 for (
unsigned isbrem = 0; isbrem < secPFBrem.size(); isbrem++) {
808 if (secPFBrem[isbrem].indTrajPoint() == 99)
816 unsigned int sbrem = 0;
817 for (
unsigned ipbrem = 0; ipbrem < primPFBrem.size(); ipbrem++) {
818 if (primPFBrem[ipbrem].indTrajPoint() == 99)
828 float dphi = fabs(primPhi - secPhi);
845 bool& bothGsfEcalDriven,
847 bool isSameSC =
false;
850 auto const* nscRef = static_cast<SuperCluster const*>(nSeed.
caloCluster().
get());
851 auto const* iscRef = static_cast<SuperCluster const*>(iSeed.
caloCluster().
get());
853 if (nscRef && iscRef) {
854 bothGsfEcalDriven =
true;
855 if (nscRef == iscRef) {
869 bool& bothGsfTrackerDriven,
874 bool isSharingEnergy =
false;
877 bool oneEcalDriven =
true;
882 scRef = static_cast<SuperCluster const*>(nSeed.
caloCluster().
get());
884 nEnergy = scRef->
energy();
886 gsfPfTrack = iGsfPFRecTrack;
888 scRef = static_cast<SuperCluster const*>(iSeed.
caloCluster().
get());
890 iEnergy = scRef->
energy();
892 gsfPfTrack = nGsfPFRecTrack;
894 oneEcalDriven =
false;
900 vector<PFCluster> vecPFClusters;
901 vecPFClusters.clear();
903 for (PFClusterCollection::const_iterator clus = theEClus.begin(); clus != theEClus.end(); clus++) {
914 if (deta < 0.5 && fabs(dphi) < 1.0) {
921 iEnergy += clust.
energy();
923 nEnergy += clust.
energy();
924 vecPFClusters.push_back(clust);
928 vector<PFBrem> primPFBrem = gsfPfTrack.
PFRecBrem();
929 for (
unsigned ipbrem = 0; ipbrem < primPFBrem.size(); ipbrem++) {
930 if (primPFBrem[ipbrem].indTrajPoint() == 99)
938 iEnergy += clust.
energy();
940 nEnergy += clust.
energy();
941 vecPFClusters.push_back(clust);
947 if (!vecPFClusters.empty()) {
948 for (
unsigned int pf = 0;
pf < vecPFClusters.size();
pf++) {
951 isSharingEnergy =
true;
959 bothGsfTrackerDriven =
true;
960 vector<PFCluster> nPFCluster;
961 vector<PFCluster> iPFCluster;
966 for (PFClusterCollection::const_iterator clus = theEClus.begin(); clus != theEClus.end(); clus++) {
976 if (ndeta < 0.5 && fabs(ndphi) < 1.0) {
981 nPFCluster.push_back(clust);
982 nEnergy += clust.
energy();
984 const vector<PFBrem>& primPFBrem = nGsfPFRecTrack.
PFRecBrem();
985 for (
unsigned ipbrem = 0; ipbrem < primPFBrem.size(); ipbrem++) {
986 if (primPFBrem[ipbrem].indTrajPoint() == 99)
993 nPFCluster.push_back(clust);
994 nEnergy += clust.
energy();
1007 if (ideta < 0.5 && fabs(idphi) < 1.0) {
1012 iPFCluster.push_back(clust);
1013 iEnergy += clust.
energy();
1015 vector<PFBrem> primPFBrem = iGsfPFRecTrack.
PFRecBrem();
1016 for (
unsigned ipbrem = 0; ipbrem < primPFBrem.size(); ipbrem++) {
1017 if (primPFBrem[ipbrem].indTrajPoint() == 99)
1022 iPFCluster.push_back(clust);
1023 iEnergy += clust.
energy();
1031 if (!nPFCluster.empty() && !iPFCluster.empty()) {
1032 for (
unsigned int npf = 0; npf < nPFCluster.size(); npf++) {
1033 for (
unsigned int ipf = 0; ipf < iPFCluster.size(); ipf++) {
1036 isSharingEnergy =
true;
1040 if (isSharingEnergy)
1046 return isSharingEnergy;
1058 int gsfHitCounter1 = 0;
1059 for (
auto const&
hit : nGsfTrack->recHits()) {
1065 int gsfHitCounter2 = 0;
1066 for (
auto const&
hit : iGsfTrack->recHits()) {
1072 uint32_t gsfHit1 = gsfHitPattern1.
getHitPattern(HitPattern::TRACK_HITS, gsfHitCounter1);
1073 uint32_t gsfHit2 = gsfHitPattern2.
getHitPattern(HitPattern::TRACK_HITS, gsfHitCounter2);
1077 }
else if (gsfHitPattern1.
getLayer(gsfHit1) != gsfHitPattern2.
getLayer(gsfHit2)) {
1078 return (gsfHitPattern2.
getLayer(gsfHit2) < gsfHitPattern1.
getLayer(gsfHit1));
1088 unsigned int nLostHits = nGsfTrack->hitPattern().numberOfLostHits(HitPattern::MISSING_INNER_HITS);
1089 unsigned int iLostHits = iGsfTrack->hitPattern().numberOfLostHits(HitPattern::MISSING_INNER_HITS);
1091 if (nLostHits != iLostHits) {
1092 return (nLostHits > iLostHits);