138 unsigned int CutIndex = 100000;
139 double CutGSFECAL = 10000. ;
142 bool DebugSetLinksSummary =
false;
143 bool DebugSetLinksDetailed =
false;
149 bool IsThereAGSFTrack =
false;
150 bool IsThereAGoodGSFTrack =
false;
152 vector<unsigned int> trackIs(0);
153 vector<unsigned int> gsfIs(0);
154 vector<unsigned int> ecalIs(0);
156 std::vector<bool> localactive(elements.
size(),
true);
160 std::multimap<double, unsigned int> kfElems;
161 for(
unsigned int iEle=0; iEle<elements.
size(); iEle++) {
162 localactive[iEle] = active[iEle];
163 bool thisIsAMuon =
false;
166 case PFBlockElement::TRACK:
170 if ( !thisIsAMuon && active[iEle] ) {
171 trackIs.push_back( iEle );
172 if (DebugSetLinksDetailed)
173 cout<<
"TRACK, stored index, continue "<< iEle << endl;
176 case PFBlockElement::GSF:
182 thisIsAMuon = !kfElems.empty() ?
185 if ( !thisIsAMuon && active[iEle] ) {
186 IsThereAGSFTrack =
true;
187 gsfIs.push_back( iEle );
188 if (DebugSetLinksDetailed)
189 cout<<
"GSF, stored index, continue "<< iEle << endl;
193 if ( active[iEle] ) {
194 ecalIs.push_back( iEle );
195 if (DebugSetLinksDetailed)
196 cout<<
"ECAL, stored index, continue "<< iEle << endl;
205 if(IsThereAGSFTrack) {
216 if (DebugSetLinksDetailed) {
217 cout<<
"#########################################################"<<endl;
218 cout<<
"##### Process Block: #####"<<endl;
219 cout<<
"#########################################################"<<endl;
224 for(
unsigned int iEle=0; iEle<trackIs.size(); iEle++) {
225 std::multimap<double, unsigned int> gsfElems;
230 if(gsfElems.empty()){
233 std::multimap<double, unsigned int> ecalKfElems;
238 if(!ecalKfElems.empty()) {
239 unsigned int ecalKf_index = ecalKfElems.begin()->second;
240 if(localactive[ecalKf_index]==
true) {
244 bool isGsfLinked =
false;
245 for(
unsigned int iGsf=0; iGsf<gsfIs.size(); iGsf++) {
253 std::multimap<double, unsigned int> ecalGsfElems;
258 if(!ecalGsfElems.empty()) {
259 if (ecalGsfElems.begin()->second == ecalKf_index) {
264 if(isGsfLinked ==
false) {
271 int nexhits = refKf->hitPattern().numberOfLostHits(HitPattern::MISSING_INNER_HITS);
273 bool isGoodTrack=
false;
278 bool trackIsFromPrimaryVertex =
false;
280 if ( (*trackIt).castTo<
TrackRef>() == refKf ) {
281 trackIsFromPrimaryVertex =
true;
287 && nexhits == 0 && trackIsFromPrimaryVertex) {
288 localactive[ecalKf_index] =
false;
300 for(
unsigned int iEle=0; iEle<gsfIs.size(); iEle++) {
302 if (!localactive[(gsfIs[iEle])])
continue;
304 localactive[gsfIs[iEle]] =
false;
305 bool ClosestEcalWithKf =
false;
307 if (DebugSetLinksDetailed)
cout <<
" Gsf Index " << gsfIs[iEle] << endl;
314 IsThereAGoodGSFTrack =
true;
316 float etaOut_gsf = GsfEl->
Pout().eta();
317 float diffOutEcalEta = fabs(eta_gsf-etaOut_gsf);
319 float Pin_gsf = 0.01;
321 Pin_gsf = RefGSF->pMode();
325 unsigned int KfGsf_index = CutIndex;
326 unsigned int KfGsf_secondIndex = CutIndex;
327 std::multimap<double, unsigned int> kfElems;
332 std::multimap<double, unsigned int> ecalKfElems;
333 if (!kfElems.empty()) {
337 for(std::multimap<double, unsigned int>::iterator itkf = kfElems.begin();
338 itkf != kfElems.end(); ++itkf) {
346 if(localactive[itkf->second] ==
true) {
348 KfGsf_index = itkf->second;
349 localactive[KfGsf_index] =
false;
357 KfGsf_secondIndex = itkf->second;
363 std::multimap<double, unsigned int> ecalGsfElems;
368 double ecalGsf_dist = CutGSFECAL;
369 unsigned int ClosestEcalGsf_index = CutIndex;
370 if (!ecalGsfElems.empty()) {
371 if(localactive[(ecalGsfElems.begin()->second)] ==
true) {
373 bool compatibleEPout =
true;
374 if(diffOutEcalEta > 0.3) {
375 reco::PFClusterRef clusterRef = elements[(ecalGsfElems.begin()->second)].clusterRef();
376 float EoPout = (clusterRef->energy())/(GsfEl->
Pout().t());
378 compatibleEPout =
false;
380 if(compatibleEPout) {
381 ClosestEcalGsf_index = ecalGsfElems.begin()->second;
382 ecalGsf_dist = block.
dist(gsfIs[iEle],ClosestEcalGsf_index,
387 std::multimap<double, unsigned int> ecalOtherGsfElems;
393 if(!ecalOtherGsfElems.empty()) {
398 if(ecalOtherGsfElems.begin()->second != gsfIs[iEle]&&
400 ecalGsf_dist = CutGSFECAL;
401 ClosestEcalGsf_index = CutIndex;
409 else if(!ecalKfElems.empty()) {
410 if(localactive[(ecalKfElems.begin()->second)] ==
true) {
411 ClosestEcalGsf_index = ecalKfElems.begin()->second;
412 ecalGsf_dist = block.
dist(gsfIs[iEle],ClosestEcalGsf_index,
414 ClosestEcalWithKf =
true;
417 std::multimap<double, unsigned int> ecalOtherGsfElems;
422 if(!ecalOtherGsfElems.empty()) {
426 if(ecalOtherGsfElems.begin()->second != gsfIs[iEle] &&
428 ecalGsf_dist = CutGSFECAL;
429 ClosestEcalGsf_index = CutIndex;
430 ClosestEcalWithKf =
false;
436 if (DebugSetLinksDetailed)
437 cout <<
" Closest Ecal to the Gsf/Kf: index " << ClosestEcalGsf_index
438 <<
" dist " << ecalGsf_dist << endl;
443 std::multimap<double, unsigned int> bremElems;
450 multimap<unsigned int,unsigned int> cleanedEcalBremElems;
451 vector<unsigned int> keyBremIndex(0);
452 unsigned int latestBrem_trajP = 0;
453 unsigned int latestBrem_index = CutIndex;
454 for(std::multimap<double, unsigned int>::iterator ieb = bremElems.begin();
455 ieb != bremElems.end(); ++ieb ) {
456 unsigned int brem_index = ieb->second;
457 if(localactive[brem_index] ==
false)
continue;
461 std::multimap<double, unsigned int> ecalBremsElems;
468 for (std::multimap<double, unsigned int>::iterator ie = ecalBremsElems.begin();
469 ie != ecalBremsElems.end();ie++) {
470 unsigned int ecalBrem_index = ie->second;
471 if(localactive[ecalBrem_index] ==
false)
continue;
474 float ecalBrem_dist = block.
dist(brem_index,ecalBrem_index,
478 if (ecalBrem_index == ClosestEcalGsf_index && (ecalBrem_dist + 0.0012) > ecalGsf_dist)
continue;
481 std::multimap<double, unsigned int> sortedBremElems;
487 bool isGoodBrem =
false;
488 unsigned int sortedBrem_index = CutIndex;
489 for (std::multimap<double, unsigned int>::iterator ibs = sortedBremElems.begin();
490 ibs != sortedBremElems.end();ibs++) {
491 unsigned int temp_sortedBrem_index = ibs->second;
492 std::multimap<double, unsigned int> sortedGsfElems;
497 bool enteredInPrimaryGsf =
false;
498 for (std::multimap<double, unsigned int>::iterator igs = sortedGsfElems.begin();
499 igs != sortedGsfElems.end();igs++) {
504 if(igs->second == gsfIs[iEle]) {
506 sortedBrem_index = temp_sortedBrem_index;
508 enteredInPrimaryGsf =
true;
512 if(enteredInPrimaryGsf)
520 std::multimap<double, unsigned int> ecalOtherGsfElems;
525 if (!ecalOtherGsfElems.empty()) {
528 if(ecalOtherGsfElems.begin()->second != gsfIs[iEle] &&
538 elements[ecalBrem_index].clusterRef();
544 if(sortedBremEcal_deta < 0.015) {
546 cleanedEcalBremElems.
insert(pair<unsigned int,unsigned int>(sortedBrem_index,ecalBrem_index));
549 if (BremTrajP > latestBrem_trajP) {
550 latestBrem_trajP = BremTrajP;
551 latestBrem_index = sortedBrem_index;
553 if (DebugSetLinksDetailed)
554 cout <<
" brem Index " << sortedBrem_index
555 <<
" associated cluster " << ecalBrem_index <<
" BremTrajP " << BremTrajP <<endl;
560 localactive[ecalBrem_index] =
false;
561 bool alreadyfound =
false;
562 for(
unsigned int ii=0;
ii<keyBremIndex.size();
ii++) {
563 if (sortedBrem_index == keyBremIndex[
ii]) alreadyfound =
true;
565 if (alreadyfound ==
false) {
566 keyBremIndex.push_back(sortedBrem_index);
567 localactive[sortedBrem_index] =
false;
576 vector<unsigned int> GsfElemIndex(0);
577 vector<unsigned int> EcalIndex(0);
580 if (ClosestEcalGsf_index < CutIndex) {
581 GsfElemIndex.push_back(ClosestEcalGsf_index);
582 localactive[ClosestEcalGsf_index] =
false;
583 for (std::multimap<double, unsigned int>::iterator
ii = ecalGsfElems.begin();
584 ii != ecalGsfElems.end();
ii++) {
585 if(localactive[
ii->second]) {
587 std::multimap<double, unsigned int> ecalOtherGsfElems;
592 if(!ecalOtherGsfElems.empty()) {
593 if(ecalOtherGsfElems.begin()->second != gsfIs[iEle])
continue;
598 float etacl = clusterRef->eta();
599 if( fabs(eta_gsf-etacl) < 0.05) {
600 GsfElemIndex.push_back(
ii->second);
601 localactive[
ii->second] =
false;
602 if (DebugSetLinksDetailed)
603 cout <<
" ExtraCluster From Gsf " <<
ii->second << endl;
640 if(GsfElemIndex.empty()){
641 if(latestBrem_index < CutIndex) {
642 unsigned int ckey = cleanedEcalBremElems.count(latestBrem_index);
644 unsigned int temp_cal =
645 cleanedEcalBremElems.find(latestBrem_index)->second;
646 GsfElemIndex.push_back(temp_cal);
647 if (DebugSetLinksDetailed)
648 cout <<
"******************** Gsf Cluster From Brem " << temp_cal
649 <<
" Latest Brem index " << latestBrem_index
650 <<
" ************************* " << endl;
653 pair<multimap<unsigned int,unsigned int>::iterator,multimap<unsigned int,unsigned int>::iterator> ret;
654 ret = cleanedEcalBremElems.equal_range(latestBrem_index);
655 multimap<unsigned int,unsigned int>::iterator it;
656 for(it=ret.first; it!=ret.second; ++it) {
657 GsfElemIndex.push_back((*it).second);
658 if (DebugSetLinksDetailed)
659 cout <<
"******************** Gsf Cluster From Brem " << (*it).second
660 <<
" Latest Brem index " << latestBrem_index
661 <<
" ************************* " << endl;
665 unsigned int elToErase = 0;
666 for(
unsigned int i = 0;
i<keyBremIndex.size();
i++) {
667 if(latestBrem_index == keyBremIndex[
i]) {
671 keyBremIndex.erase(keyBremIndex.begin()+elToErase);
679 for(
unsigned int iConv=0; iConv<gsfIs.size(); iConv++) {
687 if (DebugSetLinksDetailed)
688 cout <<
" PFElectronAlgo:: I'm running on convGsfBrem " << endl;
690 float conv_dist = block.
dist(gsfIs[iConv],gsfIs[iEle],
695 std::multimap<double, unsigned int> ecalConvElems;
700 if(!ecalConvElems.empty()) {
702 if(localactive[(ecalConvElems.begin()->second)] ==
true) {
703 if (DebugSetLinksDetailed)
704 cout <<
" PFElectronAlgo:: convGsfBrem has a ECAL cluster linked and free" << endl;
706 std::multimap<double, unsigned int> ecalOtherGsfPrimElems;
708 ecalOtherGsfPrimElems,
711 if(!ecalOtherGsfPrimElems.empty()) {
712 unsigned int gsfprimcheck_index = ecalOtherGsfPrimElems.begin()->second;
718 if (DebugSetLinksDetailed)
719 cout <<
" PFElectronAlgo: !!!!!!! convGsfBrem ECAL cluster has been stored !!!!!!! " 720 <<
" Energy " << clusterRef->energy() <<
" eta,phi " << clusterRef->position().eta()
721 <<
", " << clusterRef->position().phi() << endl;
723 GsfElemIndex.push_back(ecalConvElems.begin()->second);
724 convGsfTrack_.push_back(make_pair(ecalConvElems.begin()->second,gsfIs[iConv]));
725 localactive[ecalConvElems.begin()->second] =
false;
737 EcalIndex.insert(EcalIndex.end(),GsfElemIndex.begin(),GsfElemIndex.end());
742 for(
unsigned int i =0;
i<keyBremIndex.size();
i++) {
743 unsigned int ikey = keyBremIndex[
i];
744 unsigned int ckey = cleanedEcalBremElems.count(ikey);
745 vector<unsigned int> BremElemIndex(0);
747 unsigned int temp_cal =
748 cleanedEcalBremElems.find(ikey)->second;
749 BremElemIndex.push_back(temp_cal);
752 pair<multimap<unsigned int,unsigned int>::iterator,multimap<unsigned int,unsigned int>::iterator> ret;
753 ret = cleanedEcalBremElems.equal_range(ikey);
754 multimap<unsigned int,unsigned int>::iterator it;
755 for(it=ret.first; it!=ret.second; ++it) {
756 BremElemIndex.push_back((*it).second);
759 EcalIndex.insert(EcalIndex.end(),BremElemIndex.begin(),BremElemIndex.end());
760 associatedToBrems_.insert(pair<
unsigned int,vector<unsigned int> >(ikey,BremElemIndex));
765 vector<unsigned int> convBremKFTrack;
766 convBremKFTrack.clear();
767 if (!kfElems.empty()) {
768 for(std::multimap<double, unsigned int>::iterator itkf = kfElems.begin();
769 itkf != kfElems.end(); ++itkf) {
777 std::multimap<double, unsigned int> ecalConvElems;
782 if(!ecalConvElems.empty()) {
787 float secpin = trkRef->p();
791 float eneclust =clust->
clusterRef()->energy();
797 std::multimap<double, unsigned int> hcalConvElems;
807 float enehcalclust = -1;
808 if(!hcalConvElems.empty()) {
811 enehcalclust =clusthcal->
clusterRef()->energy();
813 if( (enehcalclust / (enehcalclust+eneclust) ) > 0.1 && isGoodTrack) {
815 if(enehcalclust > eneclust)
817 if(secpin > (enehcalclust+eneclust) )
823 if(localactive[(ecalConvElems.begin()->second)] ==
false) {
825 if(isHoE || isPoHE) {
826 if (DebugSetLinksDetailed)
827 cout <<
"PFElectronAlgo:: LOCKED ECAL REJECTED TRACK FOR H/E or P/(H+E) " 828 <<
" H/H+E " << enehcalclust/(enehcalclust+eneclust)
829 <<
" H/E " << enehcalclust/eneclust
830 <<
" P/(H+E) " << secpin/(enehcalclust+eneclust)
831 <<
" HCAL ENE " << enehcalclust
832 <<
" ECAL ENE " << eneclust
833 <<
" secPIN " << secpin
834 <<
" Algo Track " << trkRef->algo() << endl;
839 for(
unsigned int iecal =0; iecal < EcalIndex.size(); iecal++) {
842 if(EcalIndex[iecal] == ecalConvElems.begin()->second) {
843 if (DebugSetLinksDetailed)
844 cout <<
" PFElectronAlgo:: Conv Brem Recovery locked cluster and I will lock also the KF track " << endl;
845 convBremKFTrack.push_back(itkf->second);
854 if (DebugSetLinksDetailed)
855 cout <<
"PFElectronAlgo:: FREE ECAL REJECTED TRACK FOR H/H+E " 856 <<
" H/H+E " << (enehcalclust / (enehcalclust+eneclust) )
857 <<
" H/E " << enehcalclust/eneclust
858 <<
" P/(H+E) " << secpin/(enehcalclust+eneclust)
859 <<
" HCAL ENE " << enehcalclust
860 <<
" ECAL ENE " << eneclust
861 <<
" secPIN " << secpin
862 <<
" Algo Track " << trkRef->algo() << endl;
867 std::multimap<double, unsigned int> ecalOtherKFPrimElems;
869 ecalOtherKFPrimElems,
872 if(!ecalOtherKFPrimElems.empty()) {
876 bool isFromGSF =
false;
877 for(std::multimap<double, unsigned int>::iterator itclos = kfElems.begin();
878 itclos != kfElems.end(); ++itclos) {
879 if(ecalOtherKFPrimElems.begin()->second == itclos->second) {
889 float Epin = eneclust/secpin;
892 float totenergy = 0.;
893 for(
unsigned int ikeyecal = 0;
894 ikeyecal<EcalIndex.size(); ikeyecal++){
896 bool foundcluster =
false;
898 for(
unsigned int i2 = 0; i2<ikeyecal-1; i2++) {
899 if(EcalIndex[ikeyecal] == EcalIndex[i2])
903 if(foundcluster)
continue;
906 totenergy += clusasso->
clusterRef()->energy();
911 if(totenergy == 0.) {
912 if (DebugSetLinksDetailed)
913 cout <<
"PFElectronAlgo:: REJECTED_NULLTOT totenergy " << totenergy << endl;
919 double res_before = fabs((totenergy-Pin_gsf)/Pin_gsf);
920 double res_after = fabs(((totenergy+eneclust)-Pin_gsf)/Pin_gsf);
922 if(res_before < res_after) {
923 if (DebugSetLinksDetailed)
924 cout <<
"PFElectronAlgo::REJECTED_RES totenergy " << totenergy <<
" Pin_gsf " << Pin_gsf <<
" cluster to secondary " << eneclust
925 <<
" Res before " << res_before <<
" res_after " << res_after << endl;
930 if (DebugSetLinksDetailed)
931 cout <<
"PFElectronAlgo:: conv brem found asso to ECAL linked to a secondary KF " << endl;
932 convBremKFTrack.push_back(itkf->second);
933 GsfElemIndex.push_back(ecalConvElems.begin()->second);
934 EcalIndex.push_back(ecalConvElems.begin()->second);
935 localactive[(ecalConvElems.begin()->second)] =
false;
936 localactive[(itkf->second)] =
false;
947 double sumEtEcalInTheCone = 0.;
952 double PhiFC = clust->
clusterRef()->position().Phi();
953 double EtaFC = clust->
clusterRef()->position().Eta();
956 for(
unsigned int iEcal=0; iEcal<ecalIs.size(); iEcal++) {
957 bool foundcluster =
false;
958 for(
unsigned int ikeyecal = 0;
959 ikeyecal<EcalIndex.size(); ikeyecal++){
960 if(ecalIs[iEcal] == EcalIndex[ikeyecal])
965 if(foundcluster ==
false) {
968 double eta_clust = clustExt->
clusterRef()->position().Eta();
969 double phi_clust = clustExt->
clusterRef()->position().Phi();
970 double theta_clust = clustExt->
clusterRef()->position().Theta();
971 double deta_clust = eta_clust - EtaFC;
972 double dphi_clust = phi_clust - PhiFC;
973 if ( dphi_clust < -
M_PI )
974 dphi_clust = dphi_clust + 2.*
M_PI;
975 else if ( dphi_clust >
M_PI )
976 dphi_clust = dphi_clust - 2.*
M_PI;
977 double DR =
sqrt(deta_clust*deta_clust+
978 dphi_clust*dphi_clust);
982 vector<double> ps1Ene(0);
983 vector<double> ps2Ene(0);
987 double ET_calib = EE_calib*
sin(theta_clust);
988 sumEtEcalInTheCone += ET_calib;
994 unsigned int sumNTracksInTheCone = 0;
995 double sumPtTracksInTheCone = 0.;
996 for(
unsigned int iTrack=0; iTrack<trackIs.size(); iTrack++) {
998 if(localactive[(trackIs[iTrack])]==
true) {
1003 double deta_trk = trkref->eta() - RefGSF->etaMode();
1004 double dphi_trk = trkref->phi() - RefGSF->phiMode();
1005 if ( dphi_trk < -
M_PI )
1006 dphi_trk = dphi_trk + 2.*
M_PI;
1007 else if ( dphi_trk >
M_PI )
1008 dphi_trk = dphi_trk - 2.*
M_PI;
1009 double DR =
sqrt(deta_trk*deta_trk+
1012 int NValPixelHit = trkref->hitPattern().numberOfValidPixelHits();
1014 if(DR < coneTrackIsoForEgammaSC_ && NValPixelHit >=3) {
1015 sumNTracksInTheCone++;
1016 sumPtTracksInTheCone+=trkref->pt();
1023 bool isBarrelIsolated =
false;
1024 if( fabs(EtaFC < 1.478) &&
1027 isBarrelIsolated =
true;
1030 bool isEndcapIsolated =
false;
1031 if( fabs(EtaFC >= 1.478) &&
1034 isEndcapIsolated =
true;
1038 if(DebugSetLinksDetailed) {
1039 if(fabs(EtaFC < 1.478) && isBarrelIsolated ==
false) {
1040 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND BUT FAILS ISOLATION:BARREL *** " 1041 <<
" sumEtEcalInTheCone " <<sumEtEcalInTheCone
1042 <<
" sumNTracksInTheCone " << sumNTracksInTheCone
1043 <<
" sumPtTracksInTheCone " << sumPtTracksInTheCone << endl;
1045 if(fabs(EtaFC >= 1.478) && isEndcapIsolated ==
false) {
1046 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND BUT FAILS ISOLATION:ENDCAP *** " 1047 <<
" sumEtEcalInTheCone " <<sumEtEcalInTheCone
1048 <<
" sumNTracksInTheCone " << sumNTracksInTheCone
1049 <<
" sumPtTracksInTheCone " << sumPtTracksInTheCone << endl;
1056 if(isBarrelIsolated || isEndcapIsolated ) {
1060 double totenergy = 0.;
1061 for(
unsigned int ikeyecal = 0;
1062 ikeyecal<EcalIndex.size(); ikeyecal++){
1064 bool foundcluster =
false;
1066 for(
unsigned int i2 = 0; i2<ikeyecal-1; i2++) {
1067 if(EcalIndex[ikeyecal] == EcalIndex[i2])
1068 foundcluster =
true;;
1071 if(foundcluster)
continue;
1074 totenergy += clusasso->
clusterRef()->energy();
1080 for(
unsigned int ikeyecal = 0;
1081 ikeyecal<EcalIndex.size(); ikeyecal++){
1083 bool foundcluster =
false;
1085 for(
unsigned int i2 = 0; i2<ikeyecal-1; i2++) {
1086 if(EcalIndex[ikeyecal] == EcalIndex[i2])
1087 foundcluster =
true;
1090 if(foundcluster)
continue;
1093 std::multimap<double, unsigned int> ecalFromSuperClusterElems;
1095 ecalFromSuperClusterElems,
1098 if(!ecalFromSuperClusterElems.empty()) {
1099 for(std::multimap<double, unsigned int>::iterator itsc = ecalFromSuperClusterElems.begin();
1100 itsc != ecalFromSuperClusterElems.end(); ++itsc) {
1101 if(localactive[itsc->second] ==
false) {
1105 std::multimap<double, unsigned int> ecalOtherKFPrimElems;
1107 ecalOtherKFPrimElems,
1108 reco::PFBlockElement::TRACK,
1110 if(!ecalOtherKFPrimElems.empty()) {
1111 if(localactive[ecalOtherKFPrimElems.begin()->second] ==
true) {
1112 if (DebugSetLinksDetailed)
1113 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND BUT FAILS KF VETO *** " << endl;
1117 bool isInTheEtaRange =
false;
1120 double deta_clustToAdd = clustToAdd->
clusterRef()->position().Eta() - EtaFC;
1121 double ene_clustToAdd = clustToAdd->
clusterRef()->energy();
1123 if(fabs(deta_clustToAdd) < 0.05)
1124 isInTheEtaRange =
true;
1127 bool isBetterEpin =
false;
1128 if(isInTheEtaRange ==
false ) {
1129 if (DebugSetLinksDetailed)
1130 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND BUT FAILS GAMMA DETA RANGE *** " 1131 << fabs(deta_clustToAdd) << endl;
1133 if(KfGsf_index < CutIndex) {
1135 double res_before_gsf = fabs((totenergy-Pin_gsf)/Pin_gsf);
1136 double res_after_gsf = fabs(((totenergy+ene_clustToAdd)-Pin_gsf)/Pin_gsf);
1141 double Pin_kf = trackEl->
trackRef()->p();
1142 double res_before_kf = fabs((totenergy-Pin_kf)/Pin_kf);
1143 double res_after_kf = fabs(((totenergy+ene_clustToAdd)-Pin_kf)/Pin_kf);
1146 if(res_after_gsf < res_before_gsf && res_after_kf < res_before_kf ) {
1147 isBetterEpin =
true;
1150 if (DebugSetLinksDetailed)
1151 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND AND FAILS ALSO RES_EPIN" 1152 <<
" tot energy " << totenergy
1153 <<
" Pin_gsf " << Pin_gsf
1154 <<
" Pin_kf " << Pin_kf
1155 <<
" cluster from SC to ADD " << ene_clustToAdd
1156 <<
" Res before GSF " << res_before_gsf <<
" res_after_gsf " << res_after_gsf
1157 <<
" Res before KF " << res_before_kf <<
" res_after_kf " << res_after_kf << endl;
1162 if(isInTheEtaRange || isBetterEpin) {
1163 if (DebugSetLinksDetailed)
1164 cout <<
"!!!! PFElectronAlgo:: ECAL from SUPERCLUSTER FOUND !!!!! " << endl;
1165 GsfElemIndex.push_back(itsc->second);
1166 EcalIndex.push_back(itsc->second);
1167 localactive[(itsc->second)] =
false;
1176 if(KfGsf_index < CutIndex)
1177 GsfElemIndex.push_back(KfGsf_index);
1178 else if(KfGsf_secondIndex < CutIndex)
1179 GsfElemIndex.push_back(KfGsf_secondIndex);
1182 GsfElemIndex.insert(GsfElemIndex.end(),convBremKFTrack.begin(),convBremKFTrack.end());
1183 GsfElemIndex.insert(GsfElemIndex.end(),keyBremIndex.begin(),keyBremIndex.end());
1184 associatedToGsf_.insert(pair<
unsigned int, vector<unsigned int> >(gsfIs[iEle],GsfElemIndex));
1187 for(
unsigned int ikeyecal = 0;
1188 ikeyecal<EcalIndex.size(); ikeyecal++){
1191 vector<unsigned int> EcalElemsIndex(0);
1193 std::multimap<double, unsigned int> PS1Elems;
1198 for( std::multimap<double, unsigned int>::iterator it = PS1Elems.begin();
1199 it != PS1Elems.end();it++) {
1200 unsigned int index = it->second;
1201 if(localactive[index] ==
true) {
1204 std::multimap<double, unsigned> sortedECAL;
1209 unsigned jEcal = sortedECAL.begin()->second;
1210 if ( jEcal != EcalIndex[ikeyecal])
continue;
1213 EcalElemsIndex.push_back(index);
1214 localactive[
index] =
false;
1218 std::multimap<double, unsigned int> PS2Elems;
1223 for( std::multimap<double, unsigned int>::iterator it = PS2Elems.begin();
1224 it != PS2Elems.end();it++) {
1225 unsigned int index = it->second;
1226 if(localactive[index] ==
true) {
1228 std::multimap<double, unsigned> sortedECAL;
1233 unsigned jEcal = sortedECAL.begin()->second;
1234 if ( jEcal != EcalIndex[ikeyecal])
continue;
1236 EcalElemsIndex.push_back(index);
1237 localactive[
index] =
false;
1244 std::multimap<double, unsigned int> hcalGsfElems;
1249 for( std::multimap<double, unsigned int>::iterator it = hcalGsfElems.begin();
1250 it != hcalGsfElems.end();it++) {
1251 unsigned int index = it->second;
1264 EcalElemsIndex.push_back(index);
1265 localactive[
index] =
false;
1270 if(hcalGsfElems.empty() && ClosestEcalWithKf ==
true) {
1271 std::multimap<double, unsigned int> hcalKfElems;
1276 for( std::multimap<double, unsigned int>::iterator it = hcalKfElems.begin();
1277 it != hcalKfElems.end();it++) {
1278 unsigned int index = it->second;
1279 if(localactive[index] ==
true) {
1282 std::multimap<double, unsigned> sortedKf;
1285 reco::PFBlockElement::TRACK,
1287 unsigned jKf = sortedKf.begin()->second;
1288 if ( jKf != KfGsf_index)
continue;
1289 EcalElemsIndex.push_back(index);
1290 localactive[
index] =
false;
1295 std::multimap<double, unsigned int> kfEtraElems;
1298 reco::PFBlockElement::TRACK,
1300 if(!kfEtraElems.empty()) {
1301 for( std::multimap<double, unsigned int>::iterator it = kfEtraElems.begin();
1302 it != kfEtraElems.end();it++) {
1303 unsigned int index = it->second;
1311 bool thisIsAMuon =
false;
1313 if (DebugSetLinksDetailed && thisIsAMuon)
1314 cout <<
" This is a Muon: index " << index << endl;
1315 if(localactive[index] ==
true && !thisIsAMuon) {
1316 if(index != KfGsf_index) {
1319 std::multimap<double, unsigned> sortedECAL;
1324 unsigned jEcal = sortedECAL.begin()->second;
1325 if ( jEcal != EcalIndex[ikeyecal])
continue;
1326 EcalElemsIndex.push_back(index);
1327 localactive[
index] =
false;
1334 associatedToEcal_.insert(pair<
unsigned int,vector<unsigned int> >(EcalIndex[ikeyecal],EcalElemsIndex));
1343 if (DebugSetLinksSummary) {
1344 if(IsThereAGoodGSFTrack) {
1345 if (DebugSetLinksSummary)
cout <<
" -- The Link Summary --" << endl;
1346 for(
map<
unsigned int,vector<unsigned int> >::iterator it = associatedToGsf_.begin();
1347 it != associatedToGsf_.end(); it++) {
1349 if (DebugSetLinksSummary)
cout <<
" AssoGsf " << it->first << endl;
1350 vector<unsigned int> eleasso = it->second;
1351 for(
unsigned int i=0;
i<eleasso.size();
i++) {
1354 if (DebugSetLinksSummary)
1355 cout <<
" AssoGsfElements BREM " << eleasso[
i] << endl;
1358 if (DebugSetLinksSummary)
1359 cout <<
" AssoGsfElements ECAL " << eleasso[
i] << endl;
1361 else if(type == reco::PFBlockElement::TRACK) {
1362 if (DebugSetLinksSummary)
1363 cout <<
" AssoGsfElements KF " << eleasso[
i] << endl;
1366 if (DebugSetLinksSummary)
1367 cout <<
" AssoGsfElements ????? " << eleasso[
i] << endl;
1372 for(
map<
unsigned int,vector<unsigned int> >::iterator it = associatedToBrems_.begin();
1373 it != associatedToBrems_.end(); it++) {
1374 if (DebugSetLinksSummary)
cout <<
" AssoBrem " << it->first << endl;
1375 vector<unsigned int> eleasso = it->second;
1376 for(
unsigned int i=0;
i<eleasso.size();
i++) {
1379 if (DebugSetLinksSummary)
1380 cout <<
" AssoBremElements ECAL " << eleasso[
i] << endl;
1383 if (DebugSetLinksSummary)
1384 cout <<
" AssoBremElements ????? " << eleasso[
i] << endl;
1389 for(
map<
unsigned int,vector<unsigned int> >::iterator it = associatedToEcal_.begin();
1390 it != associatedToEcal_.end(); it++) {
1391 if (DebugSetLinksSummary)
cout <<
" AssoECAL " << it->first << endl;
1392 vector<unsigned int> eleasso = it->second;
1393 for(
unsigned int i=0;
i<eleasso.size();
i++) {
1396 if (DebugSetLinksSummary)
1397 cout <<
" AssoECALElements PS1 " << eleasso[
i] << endl;
1400 if (DebugSetLinksSummary)
1401 cout <<
" AssoECALElements PS2 " << eleasso[
i] << endl;
1404 if (DebugSetLinksSummary)
1405 cout <<
" AssoECALElements HCAL " << eleasso[
i] << endl;
1408 if (DebugSetLinksSummary)
1409 cout <<
" AssoHCALElements ????? " << eleasso[
i] << endl;
1413 if (DebugSetLinksSummary)
1414 cout <<
"-- End Summary --" << endl;
1419 return IsThereAGoodGSFTrack;
std::vector< std::pair< unsigned int, unsigned int > > fifthStepKfTrack_
const math::XYZTLorentzVector & Pout() const
const math::XYZPointF & positionAtECALEntrance() const
const reco::GsfTrackRef & GsftrackRef() const
bool isNonnull() const
Checks for non-null.
trackRef_iterator tracks_end() const
last iterator over tracks
static bool isMuon(const reco::PFBlockElement &elt)
std::vector< std::pair< unsigned int, unsigned int > > convGsfTrack_
const PFClusterRef & clusterRef() const override
const math::XYZPointF & positionAtECALEntrance() const
const reco::TrackRef & trackRef() const override
Sin< T >::type sin(const T &t)
std::map< unsigned int, Link > LinkData
bool isPrimaryTrack(const reco::PFBlockElementTrack &KfEl, const reco::PFBlockElementGsfTrack &GsfEl)
const edm::OwnVector< reco::PFBlockElement > & elements() const
const LinkData & linkData() const
unsigned int indTrajPoint() const
double coneEcalIsoForEgammaSC_
bool trackType(TrackType trType) const override
double sumEtEcalIsoForEgammaSC_barrel_
double sumEtEcalIsoForEgammaSC_endcap_
double sumPtTrackIsoForEgammaSC_endcap_
void associatedElements(unsigned i, const LinkData &linkData, std::multimap< double, unsigned > &sortedAssociates, reco::PFBlockElement::Type type=PFBlockElement::NONE, LinkTest test=LINKTEST_RECHIT) const
std::vector< TrackBaseRef >::const_iterator trackRef_iterator
The iteratator for the vector<TrackRef>
double sumPtTrackIsoForEgammaSC_barrel_
double dist(unsigned ie1, unsigned ie2, const LinkData &linkData, LinkTest test) const
trackRef_iterator tracks_begin() const
first iterator over tracks
unsigned int nTrackIsoForEgammaSC_
void insert(const_iterator i, D *&d)
boost::shared_ptr< PFEnergyCalibration > thePFEnergyCalibration_
bool applyCrackCorrections_
bool useEGammaSupercluster_