1494 unsigned int CutIndex = 100000;
1495 double CutGSFECAL = 10000. ;
1498 bool DebugSetLinksSummary =
false;
1499 bool DebugSetLinksDetailed =
false;
1505 bool IsThereAGSFTrack =
false;
1506 bool IsThereAGoodGSFTrack =
false;
1508 vector<unsigned int> trackIs(0);
1509 vector<unsigned int> gsfIs(0);
1510 vector<unsigned int> ecalIs(0);
1512 std::vector<bool> localactive(elements.
size(),
true);
1516 std::multimap<double, unsigned int> kfElems;
1517 for(
unsigned int iEle=0; iEle<elements.
size(); iEle++) {
1518 localactive[iEle] = active[iEle];
1519 bool thisIsAMuon =
false;
1522 case PFBlockElement::TRACK:
1526 if ( !thisIsAMuon && active[iEle] ) {
1527 trackIs.push_back( iEle );
1528 if (DebugSetLinksDetailed)
1529 cout<<
"TRACK, stored index, continue "<< iEle << endl;
1532 case PFBlockElement::GSF:
1538 thisIsAMuon = kfElems.size() ?
1541 if ( !thisIsAMuon && active[iEle] ) {
1542 IsThereAGSFTrack =
true;
1543 gsfIs.push_back( iEle );
1544 if (DebugSetLinksDetailed)
1545 cout<<
"GSF, stored index, continue "<< iEle << endl;
1549 if ( active[iEle] ) {
1550 ecalIs.push_back( iEle );
1551 if (DebugSetLinksDetailed)
1552 cout<<
"ECAL, stored index, continue "<< iEle << endl;
1561 if(IsThereAGSFTrack) {
1572 if (DebugSetLinksDetailed) {
1573 cout<<
"#########################################################"<<endl;
1574 cout<<
"##### Process Block: #####"<<endl;
1575 cout<<
"#########################################################"<<endl;
1580 for(
unsigned int iEle=0; iEle<trackIs.size(); iEle++) {
1581 std::multimap<double, unsigned int> gsfElems;
1586 if(gsfElems.size() == 0){
1589 std::multimap<double, unsigned int> ecalKfElems;
1594 if(ecalKfElems.size() > 0) {
1595 unsigned int ecalKf_index = ecalKfElems.begin()->second;
1596 if(localactive[ecalKf_index]==
true) {
1600 bool isGsfLinked =
false;
1601 for(
unsigned int iGsf=0; iGsf<gsfIs.size(); iGsf++) {
1609 std::multimap<double, unsigned int> ecalGsfElems;
1614 if(ecalGsfElems.size() > 0) {
1615 if (ecalGsfElems.begin()->second == ecalKf_index) {
1620 if(isGsfLinked ==
false) {
1627 int nexhits = refKf->trackerExpectedHitsInner().numberOfLostHits();
1629 unsigned int Algo = 0;
1631 Algo = refKf->algo();
1633 bool trackIsFromPrimaryVertex =
false;
1635 if ( (*trackIt).castTo<
TrackRef>() == refKf ) {
1636 trackIsFromPrimaryVertex =
true;
1641 if(Algo < 9 && nexhits == 0 && trackIsFromPrimaryVertex) {
1642 localactive[ecalKf_index] =
false;
1654 for(
unsigned int iEle=0; iEle<gsfIs.size(); iEle++) {
1656 if (!localactive[(gsfIs[iEle])])
continue;
1658 localactive[gsfIs[iEle]] =
false;
1659 bool ClosestEcalWithKf =
false;
1661 if (DebugSetLinksDetailed)
cout <<
" Gsf Index " << gsfIs[iEle] << endl;
1668 IsThereAGoodGSFTrack =
true;
1670 float etaOut_gsf = GsfEl->
Pout().eta();
1671 float diffOutEcalEta = fabs(eta_gsf-etaOut_gsf);
1673 float Pin_gsf = 0.01;
1675 Pin_gsf = RefGSF->pMode();
1679 unsigned int KfGsf_index = CutIndex;
1680 unsigned int KfGsf_secondIndex = CutIndex;
1681 std::multimap<double, unsigned int> kfElems;
1686 std::multimap<double, unsigned int> ecalKfElems;
1687 if (kfElems.size() > 0) {
1691 for(std::multimap<double, unsigned int>::iterator itkf = kfElems.begin();
1692 itkf != kfElems.end(); ++itkf) {
1700 if(localactive[itkf->second] ==
true) {
1702 KfGsf_index = itkf->second;
1703 localactive[KfGsf_index] =
false;
1711 KfGsf_secondIndex = itkf->second;
1717 std::multimap<double, unsigned int> ecalGsfElems;
1722 double ecalGsf_dist = CutGSFECAL;
1723 unsigned int ClosestEcalGsf_index = CutIndex;
1724 if (ecalGsfElems.size() > 0) {
1725 if(localactive[(ecalGsfElems.begin()->second)] ==
true) {
1727 bool compatibleEPout =
true;
1728 if(diffOutEcalEta > 0.3) {
1729 reco::PFClusterRef clusterRef = elements[(ecalGsfElems.begin()->second)].clusterRef();
1730 float EoPout = (clusterRef->energy())/(GsfEl->
Pout().t());
1732 compatibleEPout =
false;
1734 if(compatibleEPout) {
1735 ClosestEcalGsf_index = ecalGsfElems.begin()->second;
1736 ecalGsf_dist = block.
dist(gsfIs[iEle],ClosestEcalGsf_index,
1741 std::multimap<double, unsigned int> ecalOtherGsfElems;
1747 if(ecalOtherGsfElems.size()>0) {
1752 if(ecalOtherGsfElems.begin()->second != gsfIs[iEle]&&
1754 ecalGsf_dist = CutGSFECAL;
1755 ClosestEcalGsf_index = CutIndex;
1763 else if(ecalKfElems.size() > 0) {
1764 if(localactive[(ecalKfElems.begin()->second)] ==
true) {
1765 ClosestEcalGsf_index = ecalKfElems.begin()->second;
1766 ecalGsf_dist = block.
dist(gsfIs[iEle],ClosestEcalGsf_index,
1768 ClosestEcalWithKf =
true;
1771 std::multimap<double, unsigned int> ecalOtherGsfElems;
1776 if(ecalOtherGsfElems.size() > 0) {
1780 if(ecalOtherGsfElems.begin()->second != gsfIs[iEle] &&
1782 ecalGsf_dist = CutGSFECAL;
1783 ClosestEcalGsf_index = CutIndex;
1784 ClosestEcalWithKf =
false;
1790 if (DebugSetLinksDetailed)
1791 cout <<
" Closest Ecal to the Gsf/Kf: index " << ClosestEcalGsf_index
1792 <<
" dist " << ecalGsf_dist << endl;
1797 std::multimap<double, unsigned int> bremElems;
1804 multimap<unsigned int,unsigned int> cleanedEcalBremElems;
1805 vector<unsigned int> keyBremIndex(0);
1806 unsigned int latestBrem_trajP = 0;
1807 unsigned int latestBrem_index = CutIndex;
1808 for(std::multimap<double, unsigned int>::iterator ieb = bremElems.begin();
1809 ieb != bremElems.end(); ++ieb ) {
1810 unsigned int brem_index = ieb->second;
1811 if(localactive[brem_index] ==
false)
continue;
1815 std::multimap<double, unsigned int> ecalBremsElems;
1822 for (std::multimap<double, unsigned int>::iterator ie = ecalBremsElems.begin();
1823 ie != ecalBremsElems.end();ie++) {
1824 unsigned int ecalBrem_index = ie->second;
1825 if(localactive[ecalBrem_index] ==
false)
continue;
1828 float ecalBrem_dist = block.
dist(brem_index,ecalBrem_index,
1832 if (ecalBrem_index == ClosestEcalGsf_index && (ecalBrem_dist + 0.0012) > ecalGsf_dist)
continue;
1835 std::multimap<double, unsigned int> sortedBremElems;
1841 bool isGoodBrem =
false;
1842 unsigned int sortedBrem_index = CutIndex;
1843 for (std::multimap<double, unsigned int>::iterator ibs = sortedBremElems.begin();
1844 ibs != sortedBremElems.end();ibs++) {
1845 unsigned int temp_sortedBrem_index = ibs->second;
1846 std::multimap<double, unsigned int> sortedGsfElems;
1851 bool enteredInPrimaryGsf =
false;
1852 for (std::multimap<double, unsigned int>::iterator igs = sortedGsfElems.begin();
1853 igs != sortedGsfElems.end();igs++) {
1858 if(igs->second == gsfIs[iEle]) {
1860 sortedBrem_index = temp_sortedBrem_index;
1862 enteredInPrimaryGsf =
true;
1866 if(enteredInPrimaryGsf)
1874 std::multimap<double, unsigned int> ecalOtherGsfElems;
1879 if (ecalOtherGsfElems.size() > 0) {
1882 if(ecalOtherGsfElems.begin()->second != gsfIs[iEle] &&
1892 elements[ecalBrem_index].clusterRef();
1898 if(sortedBremEcal_deta < 0.015) {
1900 cleanedEcalBremElems.insert(pair<unsigned int,unsigned int>(sortedBrem_index,ecalBrem_index));
1903 if (BremTrajP > latestBrem_trajP) {
1904 latestBrem_trajP = BremTrajP;
1905 latestBrem_index = sortedBrem_index;
1907 if (DebugSetLinksDetailed)
1908 cout <<
" brem Index " << sortedBrem_index
1909 <<
" associated cluster " << ecalBrem_index <<
" BremTrajP " << BremTrajP <<endl;
1914 localactive[ecalBrem_index] =
false;
1915 bool alreadyfound =
false;
1916 for(
unsigned int ii=0;
ii<keyBremIndex.size();
ii++) {
1917 if (sortedBrem_index == keyBremIndex[
ii]) alreadyfound =
true;
1919 if (alreadyfound ==
false) {
1920 keyBremIndex.push_back(sortedBrem_index);
1921 localactive[sortedBrem_index] =
false;
1930 vector<unsigned int> GsfElemIndex(0);
1931 vector<unsigned int> EcalIndex(0);
1934 if (ClosestEcalGsf_index < CutIndex) {
1935 GsfElemIndex.push_back(ClosestEcalGsf_index);
1936 localactive[ClosestEcalGsf_index] =
false;
1937 for (std::multimap<double, unsigned int>::iterator
ii = ecalGsfElems.begin();
1938 ii != ecalGsfElems.end();
ii++) {
1939 if(localactive[
ii->second]) {
1941 std::multimap<double, unsigned int> ecalOtherGsfElems;
1946 if(ecalOtherGsfElems.size()) {
1947 if(ecalOtherGsfElems.begin()->second != gsfIs[iEle])
continue;
1952 float etacl = clusterRef->eta();
1953 if( fabs(eta_gsf-etacl) < 0.05) {
1954 GsfElemIndex.push_back(
ii->second);
1955 localactive[
ii->second] =
false;
1956 if (DebugSetLinksDetailed)
1957 cout <<
" ExtraCluster From Gsf " <<
ii->second << endl;
1994 if(GsfElemIndex.size() == 0){
1995 if(latestBrem_index < CutIndex) {
1996 unsigned int ckey = cleanedEcalBremElems.count(latestBrem_index);
1998 unsigned int temp_cal =
1999 cleanedEcalBremElems.find(latestBrem_index)->second;
2000 GsfElemIndex.push_back(temp_cal);
2001 if (DebugSetLinksDetailed)
2002 cout <<
"******************** Gsf Cluster From Brem " << temp_cal
2003 <<
" Latest Brem index " << latestBrem_index
2004 <<
" ************************* " << endl;
2007 pair<multimap<unsigned int,unsigned int>::iterator,multimap<unsigned int,unsigned int>::iterator>
ret;
2008 ret = cleanedEcalBremElems.equal_range(latestBrem_index);
2009 multimap<unsigned int,unsigned int>::iterator it;
2010 for(it=ret.first; it!=ret.second; ++it) {
2011 GsfElemIndex.push_back((*it).second);
2012 if (DebugSetLinksDetailed)
2013 cout <<
"******************** Gsf Cluster From Brem " << (*it).second
2014 <<
" Latest Brem index " << latestBrem_index
2015 <<
" ************************* " << endl;
2019 unsigned int elToErase = 0;
2020 for(
unsigned int i = 0;
i<keyBremIndex.size();
i++) {
2021 if(latestBrem_index == keyBremIndex[
i]) {
2025 keyBremIndex.erase(keyBremIndex.begin()+elToErase);
2033 for(
unsigned int iConv=0; iConv<gsfIs.size(); iConv++) {
2041 if (DebugSetLinksDetailed)
2042 cout <<
" PFElectronAlgo:: I'm running on convGsfBrem " << endl;
2044 float conv_dist = block.
dist(gsfIs[iConv],gsfIs[iEle],
2046 if(conv_dist > 0.) {
2049 std::multimap<double, unsigned int> ecalConvElems;
2054 if(ecalConvElems.size() > 0) {
2056 if(localactive[(ecalConvElems.begin()->second)] ==
true) {
2057 if (DebugSetLinksDetailed)
2058 cout <<
" PFElectronAlgo:: convGsfBrem has a ECAL cluster linked and free" << endl;
2060 std::multimap<double, unsigned int> ecalOtherGsfPrimElems;
2062 ecalOtherGsfPrimElems,
2065 if(ecalOtherGsfPrimElems.size()>0) {
2066 unsigned int gsfprimcheck_index = ecalOtherGsfPrimElems.begin()->second;
2071 reco::PFClusterRef clusterRef = elements[ecalConvElems.begin()->second].clusterRef();
2072 if (DebugSetLinksDetailed)
2073 cout <<
" PFElectronAlgo: !!!!!!! convGsfBrem ECAL cluster has been stored !!!!!!! "
2074 <<
" Energy " << clusterRef->energy() <<
" eta,phi " << clusterRef->position().eta()
2075 <<
", " << clusterRef->position().phi() << endl;
2077 GsfElemIndex.push_back(ecalConvElems.begin()->second);
2078 convGsfTrack_.push_back(make_pair(ecalConvElems.begin()->second,gsfIs[iConv]));
2079 localactive[ecalConvElems.begin()->second] =
false;
2091 EcalIndex.insert(EcalIndex.end(),GsfElemIndex.begin(),GsfElemIndex.end());
2096 for(
unsigned int i =0;
i<keyBremIndex.size();
i++) {
2097 unsigned int ikey = keyBremIndex[
i];
2098 unsigned int ckey = cleanedEcalBremElems.count(ikey);
2099 vector<unsigned int> BremElemIndex(0);
2101 unsigned int temp_cal =
2102 cleanedEcalBremElems.find(ikey)->second;
2103 BremElemIndex.push_back(temp_cal);
2106 pair<multimap<unsigned int,unsigned int>::iterator,multimap<unsigned int,unsigned int>::iterator>
ret;
2107 ret = cleanedEcalBremElems.equal_range(ikey);
2108 multimap<unsigned int,unsigned int>::iterator it;
2109 for(it=ret.first; it!=ret.second; ++it) {
2110 BremElemIndex.push_back((*it).second);
2113 EcalIndex.insert(EcalIndex.end(),BremElemIndex.begin(),BremElemIndex.end());
2114 associatedToBrems_.insert(pair<
unsigned int,vector<unsigned int> >(ikey,BremElemIndex));
2119 vector<unsigned int> convBremKFTrack;
2120 convBremKFTrack.clear();
2121 if (kfElems.size() > 0) {
2122 for(std::multimap<double, unsigned int>::iterator itkf = kfElems.begin();
2123 itkf != kfElems.end(); ++itkf) {
2131 std::multimap<double, unsigned int> ecalConvElems;
2136 if(ecalConvElems.size() > 0) {
2142 float secpin = trkRef->p();
2146 float eneclust =clust->
clusterRef()->energy();
2152 std::multimap<double, unsigned int> hcalConvElems;
2158 bool isHoHE =
false;
2160 bool isPoHE =
false;
2162 float enehcalclust = -1;
2163 if(hcalConvElems.size() > 0) {
2166 enehcalclust =clusthcal->
clusterRef()->energy();
2168 if( (enehcalclust / (enehcalclust+eneclust) ) > 0.1 && Algo < 3) {
2170 if(enehcalclust > eneclust)
2172 if(secpin > (enehcalclust+eneclust) )
2178 if(localactive[(ecalConvElems.begin()->second)] ==
false) {
2180 if(isHoE || isPoHE) {
2181 if (DebugSetLinksDetailed)
2182 cout <<
"PFElectronAlgo:: LOCKED ECAL REJECTED TRACK FOR H/E or P/(H+E) "
2183 <<
" H/H+E " << enehcalclust/(enehcalclust+eneclust)
2184 <<
" H/E " << enehcalclust/eneclust
2185 <<
" P/(H+E) " << secpin/(enehcalclust+eneclust)
2186 <<
" HCAL ENE " << enehcalclust
2187 <<
" ECAL ENE " << eneclust
2188 <<
" secPIN " << secpin
2189 <<
" Algo Track " << Algo << endl;
2194 for(
unsigned int iecal =0; iecal < EcalIndex.size(); iecal++) {
2197 if(EcalIndex[iecal] == ecalConvElems.begin()->second) {
2198 if (DebugSetLinksDetailed)
2199 cout <<
" PFElectronAlgo:: Conv Brem Recovery locked cluster and I will lock also the KF track " << endl;
2200 convBremKFTrack.push_back(itkf->second);
2209 if (DebugSetLinksDetailed)
2210 cout <<
"PFElectronAlgo:: FREE ECAL REJECTED TRACK FOR H/H+E "
2211 <<
" H/H+E " << (enehcalclust / (enehcalclust+eneclust) )
2212 <<
" H/E " << enehcalclust/eneclust
2213 <<
" P/(H+E) " << secpin/(enehcalclust+eneclust)
2214 <<
" HCAL ENE " << enehcalclust
2215 <<
" ECAL ENE " << eneclust
2216 <<
" secPIN " << secpin
2217 <<
" Algo Track " << Algo << endl;
2222 std::multimap<double, unsigned int> ecalOtherKFPrimElems;
2224 ecalOtherKFPrimElems,
2227 if(ecalOtherKFPrimElems.size() > 0) {
2231 bool isFromGSF =
false;
2232 for(std::multimap<double, unsigned int>::iterator itclos = kfElems.begin();
2233 itclos != kfElems.end(); ++itclos) {
2234 if(ecalOtherKFPrimElems.begin()->second == itclos->second) {
2244 float Epin = eneclust/secpin;
2247 float totenergy = 0.;
2248 for(
unsigned int ikeyecal = 0;
2249 ikeyecal<EcalIndex.size(); ikeyecal++){
2251 bool foundcluster =
false;
2253 for(
unsigned int i2 = 0; i2<ikeyecal-1; i2++) {
2254 if(EcalIndex[ikeyecal] == EcalIndex[i2])
2255 foundcluster =
true;
2258 if(foundcluster)
continue;
2261 totenergy += clusasso->
clusterRef()->energy();
2266 if(totenergy == 0.) {
2267 if (DebugSetLinksDetailed)
2268 cout <<
"PFElectronAlgo:: REJECTED_NULLTOT totenergy " << totenergy << endl;
2274 double res_before = fabs((totenergy-Pin_gsf)/Pin_gsf);
2275 double res_after = fabs(((totenergy+eneclust)-Pin_gsf)/Pin_gsf);
2277 if(res_before < res_after) {
2278 if (DebugSetLinksDetailed)
2279 cout <<
"PFElectronAlgo::REJECTED_RES totenergy " << totenergy <<
" Pin_gsf " << Pin_gsf <<
" cluster to secondary " << eneclust
2280 <<
" Res before " << res_before <<
" res_after " << res_after << endl;
2285 if (DebugSetLinksDetailed)
2286 cout <<
"PFElectronAlgo:: conv brem found asso to ECAL linked to a secondary KF " << endl;
2287 convBremKFTrack.push_back(itkf->second);
2288 GsfElemIndex.push_back(ecalConvElems.begin()->second);
2289 EcalIndex.push_back(ecalConvElems.begin()->second);
2290 localactive[(ecalConvElems.begin()->second)] =
false;
2291 localactive[(itkf->second)] =
false;
2302 double sumEtEcalInTheCone = 0.;
2307 double PhiFC = clust->
clusterRef()->position().Phi();
2308 double EtaFC = clust->
clusterRef()->position().Eta();
2311 for(
unsigned int iEcal=0; iEcal<ecalIs.size(); iEcal++) {
2312 bool foundcluster =
false;
2313 for(
unsigned int ikeyecal = 0;
2314 ikeyecal<EcalIndex.size(); ikeyecal++){
2315 if(ecalIs[iEcal] == EcalIndex[ikeyecal])
2316 foundcluster =
true;
2320 if(foundcluster ==
false) {
2323 double eta_clust = clustExt->
clusterRef()->position().Eta();
2324 double phi_clust = clustExt->
clusterRef()->position().Phi();
2325 double theta_clust = clustExt->
clusterRef()->position().Theta();
2326 double deta_clust = eta_clust - EtaFC;
2327 double dphi_clust = phi_clust - PhiFC;
2328 if ( dphi_clust < -
M_PI )
2329 dphi_clust = dphi_clust + 2.*
M_PI;
2330 else if ( dphi_clust >
M_PI )
2331 dphi_clust = dphi_clust - 2.*
M_PI;
2332 double DR =
sqrt(deta_clust*deta_clust+
2333 dphi_clust*dphi_clust);
2337 vector<double> ps1Ene(0);
2338 vector<double> ps2Ene(0);
2342 double ET_calib = EE_calib*
sin(theta_clust);
2343 sumEtEcalInTheCone += ET_calib;
2349 unsigned int sumNTracksInTheCone = 0;
2350 double sumPtTracksInTheCone = 0.;
2351 for(
unsigned int iTrack=0; iTrack<trackIs.size(); iTrack++) {
2353 if(localactive[(trackIs[iTrack])]==
true) {
2358 double deta_trk = trkref->eta() - RefGSF->etaMode();
2359 double dphi_trk = trkref->phi() - RefGSF->phiMode();
2360 if ( dphi_trk < -
M_PI )
2361 dphi_trk = dphi_trk + 2.*
M_PI;
2362 else if ( dphi_trk >
M_PI )
2363 dphi_trk = dphi_trk - 2.*
M_PI;
2364 double DR =
sqrt(deta_trk*deta_trk+
2370 if(DR < coneTrackIsoForEgammaSC_ && NValPixelHit >=3) {
2371 sumNTracksInTheCone++;
2372 sumPtTracksInTheCone+=trkref->pt();
2379 bool isBarrelIsolated =
false;
2380 if( fabs(EtaFC < 1.478) &&
2383 isBarrelIsolated =
true;
2386 bool isEndcapIsolated =
false;
2387 if( fabs(EtaFC >= 1.478) &&
2390 isEndcapIsolated =
true;
2394 if(DebugSetLinksDetailed) {
2395 if(fabs(EtaFC < 1.478) && isBarrelIsolated ==
false) {
2396 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND BUT FAILS ISOLATION:BARREL *** "
2397 <<
" sumEtEcalInTheCone " <<sumEtEcalInTheCone
2398 <<
" sumNTracksInTheCone " << sumNTracksInTheCone
2399 <<
" sumPtTracksInTheCone " << sumPtTracksInTheCone << endl;
2401 if(fabs(EtaFC >= 1.478) && isEndcapIsolated ==
false) {
2402 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND BUT FAILS ISOLATION:ENDCAP *** "
2403 <<
" sumEtEcalInTheCone " <<sumEtEcalInTheCone
2404 <<
" sumNTracksInTheCone " << sumNTracksInTheCone
2405 <<
" sumPtTracksInTheCone " << sumPtTracksInTheCone << endl;
2412 if(isBarrelIsolated || isEndcapIsolated ) {
2416 double totenergy = 0.;
2417 for(
unsigned int ikeyecal = 0;
2418 ikeyecal<EcalIndex.size(); ikeyecal++){
2420 bool foundcluster =
false;
2422 for(
unsigned int i2 = 0; i2<ikeyecal-1; i2++) {
2423 if(EcalIndex[ikeyecal] == EcalIndex[i2])
2424 foundcluster =
true;;
2427 if(foundcluster)
continue;
2430 totenergy += clusasso->
clusterRef()->energy();
2436 for(
unsigned int ikeyecal = 0;
2437 ikeyecal<EcalIndex.size(); ikeyecal++){
2439 bool foundcluster =
false;
2441 for(
unsigned int i2 = 0; i2<ikeyecal-1; i2++) {
2442 if(EcalIndex[ikeyecal] == EcalIndex[i2])
2443 foundcluster =
true;
2446 if(foundcluster)
continue;
2449 std::multimap<double, unsigned int> ecalFromSuperClusterElems;
2451 ecalFromSuperClusterElems,
2454 if(ecalFromSuperClusterElems.size() > 0) {
2455 for(std::multimap<double, unsigned int>::iterator itsc = ecalFromSuperClusterElems.begin();
2456 itsc != ecalFromSuperClusterElems.end(); ++itsc) {
2457 if(localactive[itsc->second] ==
false) {
2461 std::multimap<double, unsigned int> ecalOtherKFPrimElems;
2463 ecalOtherKFPrimElems,
2464 reco::PFBlockElement::TRACK,
2466 if(ecalOtherKFPrimElems.size() > 0) {
2467 if(localactive[ecalOtherKFPrimElems.begin()->second] ==
true) {
2468 if (DebugSetLinksDetailed)
2469 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND BUT FAILS KF VETO *** " << endl;
2473 bool isInTheEtaRange =
false;
2476 double deta_clustToAdd = clustToAdd->
clusterRef()->position().Eta() - EtaFC;
2477 double ene_clustToAdd = clustToAdd->
clusterRef()->energy();
2479 if(fabs(deta_clustToAdd) < 0.05)
2480 isInTheEtaRange =
true;
2483 bool isBetterEpin =
false;
2484 if(isInTheEtaRange ==
false ) {
2485 if (DebugSetLinksDetailed)
2486 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND BUT FAILS GAMMA DETA RANGE *** "
2487 << fabs(deta_clustToAdd) << endl;
2489 if(KfGsf_index < CutIndex) {
2491 double res_before_gsf = fabs((totenergy-Pin_gsf)/Pin_gsf);
2492 double res_after_gsf = fabs(((totenergy+ene_clustToAdd)-Pin_gsf)/Pin_gsf);
2497 double Pin_kf = trackEl->
trackRef()->p();
2498 double res_before_kf = fabs((totenergy-Pin_kf)/Pin_kf);
2499 double res_after_kf = fabs(((totenergy+ene_clustToAdd)-Pin_kf)/Pin_kf);
2502 if(res_after_gsf < res_before_gsf && res_after_kf < res_before_kf ) {
2503 isBetterEpin =
true;
2506 if (DebugSetLinksDetailed)
2507 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND AND FAILS ALSO RES_EPIN"
2508 <<
" tot energy " << totenergy
2509 <<
" Pin_gsf " << Pin_gsf
2510 <<
" Pin_kf " << Pin_kf
2511 <<
" cluster from SC to ADD " << ene_clustToAdd
2512 <<
" Res before GSF " << res_before_gsf <<
" res_after_gsf " << res_after_gsf
2513 <<
" Res before KF " << res_before_kf <<
" res_after_kf " << res_after_kf << endl;
2518 if(isInTheEtaRange || isBetterEpin) {
2519 if (DebugSetLinksDetailed)
2520 cout <<
"!!!! PFElectronAlgo:: ECAL from SUPERCLUSTER FOUND !!!!! " << endl;
2521 GsfElemIndex.push_back(itsc->second);
2522 EcalIndex.push_back(itsc->second);
2523 localactive[(itsc->second)] =
false;
2532 if(KfGsf_index < CutIndex)
2533 GsfElemIndex.push_back(KfGsf_index);
2534 else if(KfGsf_secondIndex < CutIndex)
2535 GsfElemIndex.push_back(KfGsf_secondIndex);
2538 GsfElemIndex.insert(GsfElemIndex.end(),convBremKFTrack.begin(),convBremKFTrack.end());
2539 GsfElemIndex.insert(GsfElemIndex.end(),keyBremIndex.begin(),keyBremIndex.end());
2540 associatedToGsf_.insert(pair<
unsigned int, vector<unsigned int> >(gsfIs[iEle],GsfElemIndex));
2543 for(
unsigned int ikeyecal = 0;
2544 ikeyecal<EcalIndex.size(); ikeyecal++){
2547 vector<unsigned int> EcalElemsIndex(0);
2549 std::multimap<double, unsigned int> PS1Elems;
2554 for( std::multimap<double, unsigned int>::iterator it = PS1Elems.begin();
2555 it != PS1Elems.end();it++) {
2556 unsigned int index = it->second;
2557 if(localactive[index] ==
true) {
2560 std::multimap<double, unsigned> sortedECAL;
2565 unsigned jEcal = sortedECAL.begin()->second;
2566 if ( jEcal != EcalIndex[ikeyecal])
continue;
2569 EcalElemsIndex.push_back(index);
2570 localactive[
index] =
false;
2574 std::multimap<double, unsigned int> PS2Elems;
2579 for( std::multimap<double, unsigned int>::iterator it = PS2Elems.begin();
2580 it != PS2Elems.end();it++) {
2581 unsigned int index = it->second;
2582 if(localactive[index] ==
true) {
2584 std::multimap<double, unsigned> sortedECAL;
2589 unsigned jEcal = sortedECAL.begin()->second;
2590 if ( jEcal != EcalIndex[ikeyecal])
continue;
2592 EcalElemsIndex.push_back(index);
2593 localactive[
index] =
false;
2600 std::multimap<double, unsigned int> hcalGsfElems;
2605 for( std::multimap<double, unsigned int>::iterator it = hcalGsfElems.begin();
2606 it != hcalGsfElems.end();it++) {
2607 unsigned int index = it->second;
2620 EcalElemsIndex.push_back(index);
2621 localactive[
index] =
false;
2626 if(hcalGsfElems.size() == 0 && ClosestEcalWithKf ==
true) {
2627 std::multimap<double, unsigned int> hcalKfElems;
2632 for( std::multimap<double, unsigned int>::iterator it = hcalKfElems.begin();
2633 it != hcalKfElems.end();it++) {
2634 unsigned int index = it->second;
2635 if(localactive[index] ==
true) {
2638 std::multimap<double, unsigned> sortedKf;
2641 reco::PFBlockElement::TRACK,
2643 unsigned jKf = sortedKf.begin()->second;
2644 if ( jKf != KfGsf_index)
continue;
2645 EcalElemsIndex.push_back(index);
2646 localactive[
index] =
false;
2651 std::multimap<double, unsigned int> kfEtraElems;
2654 reco::PFBlockElement::TRACK,
2656 if(kfEtraElems.size() > 0) {
2657 for( std::multimap<double, unsigned int>::iterator it = kfEtraElems.begin();
2658 it != kfEtraElems.end();it++) {
2659 unsigned int index = it->second;
2667 bool thisIsAMuon =
false;
2669 if (DebugSetLinksDetailed && thisIsAMuon)
2670 cout <<
" This is a Muon: index " << index << endl;
2671 if(localactive[index] ==
true && !thisIsAMuon) {
2672 if(index != KfGsf_index) {
2675 std::multimap<double, unsigned> sortedECAL;
2680 unsigned jEcal = sortedECAL.begin()->second;
2681 if ( jEcal != EcalIndex[ikeyecal])
continue;
2682 EcalElemsIndex.push_back(index);
2683 localactive[
index] =
false;
2690 associatedToEcal_.insert(pair<
unsigned int,vector<unsigned int> >(EcalIndex[ikeyecal],EcalElemsIndex));
2699 if (DebugSetLinksSummary) {
2700 if(IsThereAGoodGSFTrack) {
2701 if (DebugSetLinksSummary)
cout <<
" -- The Link Summary --" << endl;
2702 for(
map<
unsigned int,vector<unsigned int> >::iterator it = associatedToGsf_.begin();
2703 it != associatedToGsf_.end(); it++) {
2705 if (DebugSetLinksSummary)
cout <<
" AssoGsf " << it->first << endl;
2706 vector<unsigned int> eleasso = it->second;
2707 for(
unsigned int i=0;
i<eleasso.size();
i++) {
2710 if (DebugSetLinksSummary)
2711 cout <<
" AssoGsfElements BREM " << eleasso[
i] << endl;
2714 if (DebugSetLinksSummary)
2715 cout <<
" AssoGsfElements ECAL " << eleasso[
i] << endl;
2717 else if(type == reco::PFBlockElement::TRACK) {
2718 if (DebugSetLinksSummary)
2719 cout <<
" AssoGsfElements KF " << eleasso[
i] << endl;
2722 if (DebugSetLinksSummary)
2723 cout <<
" AssoGsfElements ????? " << eleasso[
i] << endl;
2728 for(
map<
unsigned int,vector<unsigned int> >::iterator it = associatedToBrems_.begin();
2729 it != associatedToBrems_.end(); it++) {
2730 if (DebugSetLinksSummary)
cout <<
" AssoBrem " << it->first << endl;
2731 vector<unsigned int> eleasso = it->second;
2732 for(
unsigned int i=0;
i<eleasso.size();
i++) {
2735 if (DebugSetLinksSummary)
2736 cout <<
" AssoBremElements ECAL " << eleasso[
i] << endl;
2739 if (DebugSetLinksSummary)
2740 cout <<
" AssoBremElements ????? " << eleasso[
i] << endl;
2745 for(
map<
unsigned int,vector<unsigned int> >::iterator it = associatedToEcal_.begin();
2746 it != associatedToEcal_.end(); it++) {
2747 if (DebugSetLinksSummary)
cout <<
" AssoECAL " << it->first << endl;
2748 vector<unsigned int> eleasso = it->second;
2749 for(
unsigned int i=0;
i<eleasso.size();
i++) {
2752 if (DebugSetLinksSummary)
2753 cout <<
" AssoECALElements PS1 " << eleasso[
i] << endl;
2756 if (DebugSetLinksSummary)
2757 cout <<
" AssoECALElements PS2 " << eleasso[
i] << endl;
2760 if (DebugSetLinksSummary)
2761 cout <<
" AssoECALElements HCAL " << eleasso[
i] << endl;
2764 if (DebugSetLinksSummary)
2765 cout <<
" AssoHCALElements ????? " << eleasso[
i] << endl;
2769 if (DebugSetLinksSummary)
2770 cout <<
"-- End Summary --" << endl;
2775 return IsThereAGoodGSFTrack;
const math::XYZTLorentzVector & Pout() const
const math::XYZPointF & positionAtECALEntrance() const
unsigned int whichTrackAlgo(const reco::TrackRef &trackRef)
bool useEGammaSupercluster_
std::vector< std::pair< unsigned int, unsigned int > > fifthStepKfTrack_
trackRef_iterator tracks_end() const
last iterator over tracks
static bool isMuon(const reco::PFBlockElement &elt)
bool applyCrackCorrections_
PFClusterRef clusterRef() const
const math::XYZPointF & positionAtECALEntrance() const
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
boost::shared_ptr< PFEnergyCalibration > thePFEnergyCalibration_
bool isNonnull() const
Checks for non-null.
double sumPtTrackIsoForEgammaSC_endcap_
reco::GsfTrackRef GsftrackRef() const
unsigned int nTrackIsoForEgammaSC_
virtual bool trackType(TrackType trType) const
block
Formating index page's pieces.
double sumPtTrackIsoForEgammaSC_barrel_
void associatedElements(unsigned i, const LinkData &linkData, std::multimap< double, unsigned > &sortedAssociates, reco::PFBlockElement::Type type=PFBlockElement::NONE, LinkTest test=LINKTEST_RECHIT) const
double coneEcalIsoForEgammaSC_
std::vector< std::pair< unsigned int, unsigned int > > convGsfTrack_
reco::TrackRef trackRef() const
double sumEtEcalIsoForEgammaSC_endcap_
double sumEtEcalIsoForEgammaSC_barrel_
std::vector< TrackBaseRef >::const_iterator trackRef_iterator
The iteratator for the vector<TrackRef>
int numberOfValidPixelHits() const
double dist(unsigned ie1, unsigned ie2, const LinkData &linkData, LinkTest test) const
trackRef_iterator tracks_begin() const
first iterator over tracks