58 constexpr
float square(
float x) {
return x *
x; };
68 return std::make_unique<convbremhelpers::HeavyObjectCache>(conf);
88 std::vector<unsigned int>& secondaries,
95 bool& bothGsfEcalDriven,
103 bool& bothGsfTrackerDriven,
114 std::vector<reco::GsfPFRecTrack>& gsfPFRecTrackPrimary,
115 const std::map<
unsigned int, std::vector<reco::GsfPFRecTrack> >& MapPrimSec);
172 using namespace reco;
195 produces<GsfPFRecTrackCollection>();
196 produces<GsfPFRecTrackCollection>(
"Secondary").setBranchAlias(
"secondary");
228 auto gsfPFRecTrackCollection = std::make_unique<GsfPFRecTrackCollection>();
230 auto gsfPFRecTrackCollectionSecondary = std::make_unique<GsfPFRecTrackCollection>();
245 auto trackEtaPhiTable = makeLazy<edm::soa::EtaPhiTable>(*thePfRecTrackCollection);
272 vector<Trajectory> tjvec(0);
279 vector<reco::GsfPFRecTrack> selGsfPFRecTracks;
280 vector<reco::GsfPFRecTrack> primaryGsfPFRecTracks;
281 std::map<unsigned int, std::vector<reco::GsfPFRecTrack> > GsfPFMap;
283 for (
unsigned igsf = 0; igsf < gsftracks.size(); igsf++) {
294 for (
unsigned int igsf = 0; igsf < gsftracks.size(); igsf++) {
297 int kf_ind =
findPfRef(*thePfRecTrackCollection, gsftracks[igsf], trackEtaPhiTable.value());
305 bool isEcalDriven =
true;
306 bool isTrackerDriven =
true;
308 if (trackRef->seedRef().
get() ==
nullptr) {
309 isEcalDriven =
false;
310 isTrackerDriven =
false;
312 auto const& SeedFromRef = static_cast<ElectronSeed const&>(*(trackRef->extra()->seedRef()));
313 if (SeedFromRef.caloCluster().isNull())
314 isEcalDriven =
false;
315 if (SeedFromRef.ctfTrack().isNull())
316 isTrackerDriven =
false;
339 bool validgsfbrem =
false;
350 if (validgsfbrem && passSel)
351 selGsfPFRecTracks.push_back(
pftrack_);
354 unsigned int count_primary = 0;
355 if (!selGsfPFRecTracks.empty()) {
356 for (
unsigned int ipfgsf = 0; ipfgsf < selGsfPFRecTracks.size(); ipfgsf++) {
357 vector<unsigned int> secondaries(0);
362 keepGsf =
resolveGsfTracks(selGsfPFRecTracks, ipfgsf, secondaries, theEcalClusters);
366 if (keepGsf ==
true) {
369 thePrimaryVertexColl,
378 selGsfPFRecTracks[ipfgsf])) {
379 const vector<PFRecTrackRef>& convBremPFRecTracks(
convBremFinder_->getConvBremPFRecTracks());
380 for (
unsigned int ii = 0;
ii < convBremPFRecTracks.size();
ii++) {
381 selGsfPFRecTracks[ipfgsf].addConvBremPFRecTrackRef(convBremPFRecTracks[
ii]);
387 primaryGsfPFRecTracks.push_back(selGsfPFRecTracks[ipfgsf]);
392 unsigned int primGsfIndex = selGsfPFRecTracks[ipfgsf].trackId();
393 vector<reco::GsfPFRecTrack> trueGsfPFRecTracks;
394 if (!secondaries.empty()) {
396 for (
unsigned int isecpfgsf = 0; isecpfgsf < secondaries.size(); isecpfgsf++) {
397 PFRecTrackRef refsecKF = selGsfPFRecTracks[(secondaries[isecpfgsf])].kfPFRecTrackRef();
399 unsigned int secGsfIndex = selGsfPFRecTracks[(secondaries[isecpfgsf])].trackId();
400 GsfTrackRef secGsfRef = selGsfPFRecTracks[(secondaries[isecpfgsf])].gsfTrackRef();
413 bool validgsfbrem =
false;
422 gsfPFRecTrackCollectionSecondary->push_back(
secpftrack_);
427 GsfPFMap.insert(pair<
unsigned int, std::vector<reco::GsfPFRecTrack> >(count_primary, trueGsfPFRecTracks));
428 trueGsfPFRecTracks.clear();
440 for (
unsigned int iGSF = 0; iGSF < primaryGsfPFRecTracks.size(); iGSF++) {
441 gsfPFRecTrackCollection->push_back(primaryGsfPFRecTracks[iGSF]);
445 selGsfPFRecTracks.clear();
447 primaryGsfPFRecTracks.clear();
455 std::vector<reco::GsfPFRecTrack>& gsfPFRecTrackPrimary,
456 const std::map<
unsigned int, std::vector<reco::GsfPFRecTrack> >& MapPrimSec) {
457 unsigned int cgsf = 0;
458 unsigned int csecgsf = 0;
459 for (
std::map<
unsigned int, std::vector<reco::GsfPFRecTrack> >::const_iterator igsf = MapPrimSec.begin();
460 igsf != MapPrimSec.end();
462 vector<reco::GsfPFRecTrack> SecGsfPF = igsf->second;
463 for (
unsigned int iSecGsf = 0; iSecGsf < SecGsfPF.size(); iSecGsf++) {
465 gsfPFRecTrackPrimary[cgsf].addConvBremGsfPFRecTrackRef(refgprt);
481 constexpr
float maxDR2 =
square(0.05
f);
484 float gsftkEta = gsftk.
eta();
485 float gsftkPhi = gsftk.
phi();
488 auto const& electronSeedFromRef = static_cast<ElectronSeed const&>(*(gsftk.
extra()->seedRef()));
490 if (electronSeedFromRef.ctfTrack().isNull()) {
491 unsigned int i_pf = 0;
493 unsigned int ish_max = 0;
494 float dr2_min =
square(1000.
f);
498 for (
auto const& pft : trackEtaPhiTable) {
499 unsigned int ish = 0;
505 for (
auto const& hhit : pfRTkColl[i_pf].trackRef()->
recHits()) {
506 if (!hhit->isValid())
508 for (
auto const&
hit : gsftkHits) {
514 if ((ish > ish_max) || ((ish == ish_max) && (dr2 < dr2_min))) {
524 return ((ish_max == 0) || (dr2_min > maxDR2)) ? -1 : ibest;
528 unsigned int i_pf = 0;
530 for (
auto const& pft : pfRTkColl) {
532 if (pft.trackRef() == electronSeedFromRef.ctfTrack()) {
545 auto const& ElSeedFromRef = static_cast<ElectronSeed const&>(*(gsftk.
extra()->seedRef()));
547 bool passCut =
false;
548 if (ElSeedFromRef.ctfTrack().isNull()) {
549 if (ElSeedFromRef.caloCluster().isNull())
551 auto const* scRef = static_cast<SuperCluster const*>(ElSeedFromRef.caloCluster().get());
554 float caloEne = scRef->energy();
556 float fphi = fabs(scRef->phi() - gsftk.
phiMode());
570 vector<unsigned int>& secondaries,
573 bool n_keepGsf =
true;
577 if (nGsfTrack->seedRef().
get() ==
nullptr)
579 auto const& nElSeedFromRef = static_cast<ElectronSeed const&>(*(nGsfTrack->extra()->seedRef()));
592 float neta = nGsfTrack->innerMomentum().eta();
593 float nphi = nGsfTrack->innerMomentum().phi();
596 cout <<
" PFElecTkProducer:: considering track " << nGsfTrack->pt() <<
" eta,phi " << nGsfTrack->eta() <<
", "
597 << nGsfTrack->phi() << endl;
599 for (
unsigned int igsf = 0; igsf < GsfPFVec.size(); igsf++) {
604 cout <<
" PFElecTkProducer:: and comparing with track " << iGsfTrack->pt() <<
" eta,phi " << iGsfTrack->eta()
605 <<
", " << iGsfTrack->phi() << endl;
607 float ieta = iGsfTrack->innerMomentum().eta();
608 float iphi = iGsfTrack->innerMomentum().phi();
615 if (
feta < 0.5 && fabs(fphi) < 1.0) {
617 cout <<
" Entering angular superloose preselection " << endl;
630 if (iGsfTrack->seedRef().
get() ==
nullptr)
632 auto const& iElSeedFromRef = static_cast<ElectronSeed const&>(*(iGsfTrack->extra()->seedRef()));
636 bool areBothGsfEcalDriven =
false;
638 bool isSameSC =
isSameEgSC(nElSeedFromRef, iElSeedFromRef, areBothGsfEcalDriven,
SCEnergy);
641 if (areBothGsfEcalDriven) {
646 cout <<
" Entering SAME supercluster case "
647 <<
" nEP " << nEP <<
" iEP " << iEP << endl;
653 bool isSameLayer =
false;
657 cout <<
" iGsf is InnerMostWithLostHits " << iGsfInnermostWithLostHits <<
" isSameLayer " << isSameLayer
660 if (iGsfInnermostWithLostHits) {
663 }
else if (isSameLayer) {
664 if (fabs(iEP - 1) < fabs(nEP - 1)) {
668 secondaries.push_back(igsf);
672 secondaries.push_back(igsf);
677 float minBremDphi =
minTangDist(GsfPFVec[ngsf], GsfPFVec[igsf]);
680 bool isBothGsfTrackerDriven =
false;
681 bool nEcalDriven =
false;
682 bool iEcalDriven =
false;
688 isBothGsfTrackerDriven,
695 bool isSameLayer =
false;
702 cout <<
" Sharing ECAL energy passed "
703 <<
" nEtot " << nETot <<
" iEtot " << iETot << endl;
704 if (isBothGsfTrackerDriven)
705 cout <<
" Both Track are trackerDriven " << endl;
709 if (iGsfInnermostWithLostHits) {
712 }
else if (isSameLayer) {
720 if (isBothGsfTrackerDriven ==
false) {
726 secondaries.push_back(igsf);
733 if (nETot != iETot) {
741 float nEP = ETot / nPin;
742 float iEP = ETot / iPin;
745 cout <<
" nETot " << nETot <<
" iETot " << iETot <<
" ETot " << ETot << endl
746 <<
" nPin " << nPin <<
" iPin " << iPin <<
" nEP " << nEP <<
" iEP " << iEP << endl;
748 if (fabs(iEP - 1) < fabs(nEP - 1)) {
752 secondaries.push_back(igsf);
756 secondaries.push_back(igsf);
760 bool secPushedBack =
false;
761 if (nEcalDriven ==
false && nETot == 0.) {
764 }
else if (iEcalDriven ==
false && iETot == 0.) {
765 secondaries.push_back(igsf);
766 secPushedBack =
true;
769 cout <<
" Close Tracks "
770 <<
" feta " <<
feta <<
" fabs(fphi) " << fabs(fphi) <<
" minBremDphi " << minBremDphi <<
" nETot "
771 << nETot <<
" iETot " << iETot <<
" nLostHits " << nGsfTrack->missingInnerHits() <<
" iLostHits "
772 << iGsfTrack->missingInnerHits() << endl;
776 if (iGsfInnermostWithLostHits) {
779 }
else if (isSameLayer ==
false) {
780 if (secPushedBack ==
false)
781 secondaries.push_back(igsf);
784 }
else if (
feta < 0.1 && minBremDphi < 0.2) {
788 cout <<
" Close Tracks and failed all the conditions "
789 <<
" feta " <<
feta <<
" fabs(fphi) " << fabs(fphi) <<
" minBremDphi " << minBremDphi <<
" nETot "
790 << nETot <<
" iETot " << iETot <<
" nLostHits " << nGsfTrack->missingInnerHits() <<
" iLostHits "
791 << iGsfTrack->missingInnerHits() << endl;
793 if (nEcalDriven ==
false && nETot == 0.) {
809 std::vector<reco::PFBrem> primPFBrem = primGsf.
PFRecBrem();
810 std::vector<reco::PFBrem> secPFBrem = secGsf.
PFRecBrem();
812 unsigned int cbrem = 0;
813 for (
unsigned isbrem = 0; isbrem < secPFBrem.size(); isbrem++) {
814 if (secPFBrem[isbrem].indTrajPoint() == 99)
822 unsigned int sbrem = 0;
823 for (
unsigned ipbrem = 0; ipbrem < primPFBrem.size(); ipbrem++) {
824 if (primPFBrem[ipbrem].indTrajPoint() == 99)
834 float dphi = fabs(primPhi - secPhi);
851 bool& bothGsfEcalDriven,
853 bool isSameSC =
false;
856 auto const* nscRef = static_cast<SuperCluster const*>(nSeed.
caloCluster().
get());
857 auto const* iscRef = static_cast<SuperCluster const*>(iSeed.
caloCluster().
get());
859 if (nscRef && iscRef) {
860 bothGsfEcalDriven =
true;
861 if (nscRef == iscRef) {
875 bool& bothGsfTrackerDriven,
880 bool isSharingEnergy =
false;
883 bool oneEcalDriven =
true;
888 scRef = static_cast<SuperCluster const*>(nSeed.
caloCluster().
get());
890 nEnergy = scRef->
energy();
892 gsfPfTrack = iGsfPFRecTrack;
894 scRef = static_cast<SuperCluster const*>(iSeed.
caloCluster().
get());
896 iEnergy = scRef->
energy();
898 gsfPfTrack = nGsfPFRecTrack;
900 oneEcalDriven =
false;
906 vector<PFCluster> vecPFClusters;
907 vecPFClusters.clear();
909 for (PFClusterCollection::const_iterator clus = theEClus.begin(); clus != theEClus.end(); clus++) {
920 if (deta < 0.5 && fabs(dphi) < 1.0) {
927 iEnergy += clust.
energy();
929 nEnergy += clust.
energy();
930 vecPFClusters.push_back(clust);
934 vector<PFBrem> primPFBrem = gsfPfTrack.
PFRecBrem();
935 for (
unsigned ipbrem = 0; ipbrem < primPFBrem.size(); ipbrem++) {
936 if (primPFBrem[ipbrem].indTrajPoint() == 99)
944 iEnergy += clust.
energy();
946 nEnergy += clust.
energy();
947 vecPFClusters.push_back(clust);
953 if (!vecPFClusters.empty()) {
954 for (
unsigned int pf = 0;
pf < vecPFClusters.size();
pf++) {
957 isSharingEnergy =
true;
965 bothGsfTrackerDriven =
true;
966 vector<PFCluster> nPFCluster;
967 vector<PFCluster> iPFCluster;
972 for (PFClusterCollection::const_iterator clus = theEClus.begin(); clus != theEClus.end(); clus++) {
982 if (ndeta < 0.5 && fabs(ndphi) < 1.0) {
987 nPFCluster.push_back(clust);
988 nEnergy += clust.
energy();
990 const vector<PFBrem>& primPFBrem = nGsfPFRecTrack.
PFRecBrem();
991 for (
unsigned ipbrem = 0; ipbrem < primPFBrem.size(); ipbrem++) {
992 if (primPFBrem[ipbrem].indTrajPoint() == 99)
999 nPFCluster.push_back(clust);
1000 nEnergy += clust.
energy();
1013 if (ideta < 0.5 && fabs(idphi) < 1.0) {
1018 iPFCluster.push_back(clust);
1019 iEnergy += clust.
energy();
1021 vector<PFBrem> primPFBrem = iGsfPFRecTrack.
PFRecBrem();
1022 for (
unsigned ipbrem = 0; ipbrem < primPFBrem.size(); ipbrem++) {
1023 if (primPFBrem[ipbrem].indTrajPoint() == 99)
1028 iPFCluster.push_back(clust);
1029 iEnergy += clust.
energy();
1037 if (!nPFCluster.empty() && !iPFCluster.empty()) {
1038 for (
unsigned int npf = 0; npf < nPFCluster.size(); npf++) {
1039 for (
unsigned int ipf = 0; ipf < iPFCluster.size(); ipf++) {
1042 isSharingEnergy =
true;
1046 if (isSharingEnergy)
1052 return isSharingEnergy;
1064 int gsfHitCounter1 = 0;
1065 for (
auto const&
hit : nGsfTrack->recHits()) {
1071 int gsfHitCounter2 = 0;
1072 for (
auto const&
hit : iGsfTrack->recHits()) {
1078 uint32_t gsfHit1 = gsfHitPattern1.
getHitPattern(HitPattern::TRACK_HITS, gsfHitCounter1);
1079 uint32_t gsfHit2 = gsfHitPattern2.
getHitPattern(HitPattern::TRACK_HITS, gsfHitCounter2);
1083 }
else if (gsfHitPattern1.
getLayer(gsfHit1) != gsfHitPattern2.
getLayer(gsfHit2)) {
1084 return (gsfHitPattern2.
getLayer(gsfHit2) < gsfHitPattern1.
getLayer(gsfHit1));
1094 unsigned int nLostHits = nGsfTrack->missingInnerHits();
1095 unsigned int iLostHits = iGsfTrack->missingInnerHits();
1097 if (nLostHits != iLostHits) {
1098 return (nLostHits > iLostHits);