38 #include "combination.hpp" 44 #define docast(x,y) dynamic_cast<x>(y) 45 #define LOGVERB(x) edm::LogVerbatim(x) 46 #define LOGWARN(x) edm::LogWarning(x) 47 #define LOGERR(x) edm::LogError(x) 48 #define LOGDRESSED(x) edm::LogInfo(x) 50 #define docast(x,y) reinterpret_cast<x>(y) 51 #define LOGVERB(x) LogTrace(x) 52 #define LOGWARN(x) edm::LogWarning(x) 53 #define LOGERR(x) edm::LogError(x) 54 #define LOGDRESSED(x) LogDebug(x) 64 typedef std::pair<CaloClusterPtr::key_type,CaloClusterPtr> EEtoPSElement;
72 class SeedMatchesToProtoObject {
78 if( scfromseed_.isNonnull() )
86 if( scfromseed_.isNull() || !po.
parentSC )
return false;
99 template<
bool useConvs=false>
105 const float EoPin_cut = 1.0e6) {
114 &(block->elements()[
key]));
116 const ClusterElement* elemasclus =
117 reinterpret_cast<const ClusterElement*
>(&(block->elements()[
test]));
118 float cluster_e = elemasclus->clusterRef()->correctedEnergy();
119 float trk_pin = elemasgsf->
Pin().P();
120 if( cluster_e / trk_pin > EoPin_cut ) {
122 <<
"GSF track failed EoP cut to match with cluster!";
132 &(block->elements()[
key]));
134 const ClusterElement* elemasclus =
135 reinterpret_cast<const ClusterElement*
>(&(block->elements()[
test]));
136 float cluster_e = elemasclus->clusterRef()->correctedEnergy();
139 if( cluster_e / trk_pin > EoPin_cut ) {
141 <<
"KF track failed EoP cut to match with cluster!";
153 if( dist == -1.0
f )
return false;
154 std::multimap<double, unsigned> dists_to_val;
155 block->associatedElements(test,block->linkData(),dists_to_val,keytype,
158 for(
const auto& valdist : dists_to_val ) {
159 const size_t idx = valdist.second;
166 &(block->elements()[
idx]));
167 if( !useConvs && elemasgsf->
trackType(ConvType) )
return false;
169 const ClusterElement* elemasclus =
170 docast(
const ClusterElement*,&(block->elements()[
test]));
171 float cluster_e = elemasclus->clusterRef()->correctedEnergy();
172 float trk_pin = elemasgsf->
Pin().P();
173 if( cluster_e / trk_pin > EoPin_cut )
continue;
181 &(block->elements()[
idx]));
182 if( !useConvs && elemaskf->
trackType(ConvType) )
return false;
184 const ClusterElement* elemasclus =
185 reinterpret_cast<const ClusterElement*
>(&(block->elements()[
test]));
186 float cluster_e = elemasclus->clusterRef()->correctedEnergy();
189 if( cluster_e / trk_pin > EoPin_cut )
continue;
196 if( valdist.first < dist && idx != key ) {
198 <<
"key element of type " << keytype
199 <<
" is closer to another element of type" << valtype
213 const ClusterElement* elemascluster =
docast(
const ClusterElement*,e.first);
216 return ( gsf_eta_diff <= 0.3 && cRef->energy()/comp->
Pout().t() <= 5 );
219 template<
class TrackElementType>
220 bool isConversionTrack(
const PFFlaggedElement& e)
223 const TrackElementType* elemastrk =
docast(
const TrackElementType*,e.first);
224 return elemastrk->trackType(ConvType);
232 struct NotCloserToOther {
236 const float EoPin_cut;
239 const PFFlaggedElement* e,
240 const float EoPcut=1.0e6):
comp(e->first),
248 const float EoPcut=1.0e6):
comp(e),
253 bool operator () (
const PFFlaggedElement& e) {
254 if( !e.second || valtype != e.first->type() )
return false;
255 return elementNotCloserToOther<useConv>(
block,
256 keytype,comp->
index(),
257 valtype,e.first->index(),
262 struct LesserByDistance {
268 const PFFlaggedElement* e):
comp(e->first),
276 bool operator () (
const PFFlaggedElement& e1,
277 const PFFlaggedElement& e2) {
278 double dist1 = block->dist(comp->
index(),
282 double dist2 = block->dist(comp->
index(),
286 dist1 = ( dist1 == -1.0 ? 1e6 : dist1 );
287 dist2 = ( dist2 == -1.0 ? 1e6 : dist2 );
288 return dist1 < dist2;
298 <<
"cannot merge, both have GSFs!" << std::endl;
303 if(RO1.
ecalclusters.front().first->clusterRef()->layer() !=
304 RO2.
ecalclusters.front().first->clusterRef()->layer() ) {
306 <<
"cannot merge, different ECAL types!" << std::endl;
316 elementNotCloserToOther(blk,
317 cluster.first->type(),
318 cluster.first->
index(),
319 primgsf.first->type(),
320 primgsf.first->index());
323 <<
"merged by cluster to primary GSF" << std::endl;
327 <<
"cluster to primary GSF failed since" 328 <<
" cluster closer to another GSF" << std::endl;
333 elementNotCloserToOther(blk,
334 cluster.first->type(),
335 cluster.first->
index(),
336 primkf.first->type(),
337 primkf.first->index());
340 <<
"merged by cluster to primary KF" << std::endl;
346 elementNotCloserToOther(blk,
347 cluster.first->type(),
348 cluster.first->
index(),
349 secdkf.first->type(),
350 secdkf.first->index());
353 <<
"merged by cluster to secondary KF" << std::endl;
358 for(
const auto& brem : RO2.
brems ) {
359 not_closer = elementNotCloserToOther(blk,
360 cluster.first->type(),
361 cluster.first->
index(),
363 brem.first->index());
366 <<
"merged by cluster to brem KF" << std::endl;
375 elementNotCloserToOther(blk,
376 primgsf.first->type(),
377 primgsf.first->
index(),
378 secdkf.first->type(),
379 secdkf.first->index());
382 <<
"merged by GSF to secondary KF" << std::endl;
391 elementNotCloserToOther(blk,
392 primkf.first->type(),
393 primkf.first->
index(),
394 secdkf.first->type(),
395 secdkf.first->index());
398 <<
"merged by primary KF to secondary KF" << std::endl;
407 elementNotCloserToOther<true>(blk,
408 secdkf1.first->type(),
409 secdkf1.first->
index(),
410 secdkf2.first->type(),
411 secdkf2.first->index());
414 <<
"merged by secondary KF to secondary KF" << std::endl;
424 const bool result = ( isROLinkedByClusterOrTrack(comp,ro) || isROLinkedByClusterOrTrack(ro,comp) );
428 std::vector<const ClusterElement*>
430 std::vector<PFFlaggedElement>& ecals) {
431 std::vector<const ClusterElement*> cluster_list;
432 auto sccl = scref->clustersBegin();
433 auto scend = scref->clustersEnd();
434 auto pfc = ecals.begin();
435 auto pfcend = ecals.end();
436 for( ; sccl != scend; ++sccl ) {
437 std::vector<const ClusterElement*> matched_pfcs;
438 const double eg_energy = (*sccl)->energy();
440 for( pfc = ecals.begin(); pfc != pfcend; ++pfc ) {
441 const ClusterElement *pfcel =
442 docast(
const ClusterElement*, pfc->first);
447 if( matched && pfcel->clusterRef()->energy() < 1.2*scref->energy()) {
448 matched_pfcs.push_back(pfcel);
451 std::sort(matched_pfcs.begin(),matched_pfcs.end());
453 double min_residual = 1e6;
454 std::vector<const ClusterElement*> best_comb;
455 for(
size_t i = 1;
i <= matched_pfcs.size(); ++
i ) {
460 double energy = std::accumulate(matched_pfcs.begin(),
461 matched_pfcs.begin()+
i,
464 const ClusterElement*
c)
465 {
return a +
c->clusterRef()->energy(); });
466 const double resid =
std::abs(energy - eg_energy);
467 if( resid < min_residual ) {
469 best_comb.reserve(
i);
470 min_residual = resid;
471 best_comb.insert(best_comb.begin(),
472 matched_pfcs.begin(),
473 matched_pfcs.begin()+
i);
476 matched_pfcs.begin()+
i,
477 matched_pfcs.end()));
479 for(
const auto& clelem : best_comb ) {
480 if(
std::find(cluster_list.begin(),cluster_list.end(),clelem) ==
481 cluster_list.end() ) {
482 cluster_list.push_back(clelem);
488 bool addPFClusterToROSafe(
const ClusterElement*
cl,
497 if( clayer == blayer ) {
514 *kfCluster =
nullptr, *gsfCluster_noassc =
nullptr;
516 int nBremClusters = 0;
518 float mDist_gsf(maxDist), mDist_gsf_noassc(maxDist), mDist_kf(maxDist);
521 const bool hasclu = elementNotCloserToOther(parent,
524 cluster.first->type(),
525 cluster.first->index());
527 std::abs(cluster.first->clusterRef()->positionREP().eta() -
528 gsf.first->positionAtECALEntrance().eta());
531 cluster.first->clusterRef()->positionREP().phi() -
532 gsf.first->positionAtECALEntrance().phi()));
533 const float dist = std::hypot(deta,dphi);
534 if( hasclu && dist < mDist_gsf ) {
535 gsfCluster = cluster.first;
537 }
else if ( dist < mDist_gsf_noassc ) {
538 gsfCluster_noassc = cluster.first;
539 mDist_gsf_noassc = dist;
543 const bool hasclu = elementNotCloserToOther(parent,
546 cluster.first->type(),
547 cluster.first->index());
548 const float dist = parent->dist(cluster.first->index(),
552 if( hasclu && dist < mDist_kf ) {
553 kfCluster = cluster.first;
557 for(
const auto& brem : RO.
brems ) {
558 const bool hasclu = elementNotCloserToOther(parent,
561 cluster.first->type(),
562 cluster.first->index());
567 brem.first->indTrajPoint() - 2) ) {
568 firstBrem = brem.first;
571 ( lastBrem->indTrajPoint() - 2 <
572 brem.first->indTrajPoint() - 2) ) {
573 lastBrem = brem.first;
574 bremCluster = cluster.first;
579 if( !gsfCluster && !kfCluster && !bremCluster ) {
580 gsfCluster = gsfCluster_noassc;
586 }
else if ( kfCluster ) {
589 if( bremCluster && !gsfCluster && !kfCluster ) {
594 if( bremCluster == gsfCluster ) RO.
lateBrem = 1;
605 std::vector<bool>& active) {
616 unsigned int trackIndex)
623 const float chi2 = elements[trackIndex].trackRef()->chi2()/elements[trackIndex].trackRef()->ndof();
624 const float nlost = elements[trackIndex].trackRef()->hitPattern().numberOfLostHits(HitPattern::MISSING_INNER_HITS);
625 const float nLayers = elements[trackIndex].trackRef()->hitPattern().trackerLayersWithMeasurement();
626 const float trackPt = elements[trackIndex].trackRef()->pt();
627 const float stip = elements[trackIndex].trackRefPF()->STIP();
631 std::multimap<double, unsigned int> ecalAssoTrack;
636 std::multimap<double, unsigned int> hcalAssoTrack;
641 if(!ecalAssoTrack.empty())
643 for (
auto & itecal : ecalAssoTrack)
645 linkedE = linkedE+elements[itecal.second].clusterRef()->energy();
648 if(!hcalAssoTrack.empty())
650 for (
auto & ithcal : hcalAssoTrack)
652 linkedH = linkedH+elements[ithcal.second].clusterRef()->energy();
655 const float eOverPt = linkedE / elements[trackIndex].trackRef()->pt();
656 const float hOverPt = linkedH / elements[trackIndex].trackRef()->pt();
657 GlobalVector rvtx(elements[trackIndex].trackRef()->innerPosition().
X()-primaryVtx.
x(),
658 elements[trackIndex].trackRef()->innerPosition().Y()-primaryVtx.
y(),
659 elements[trackIndex].trackRef()->innerPosition().Z()-primaryVtx.
z());
660 double vtxPhi = rvtx.
phi();
662 float delPhi = fabs(
deltaPhi(vtxPhi, elements[trackIndex].trackRef()->innerMomentum().
Phi()));
665 hOverPt,
trackPt, stip, nlost };
671 switch( pfbe.
type() ) {
675 std::multimap<double,unsigned> tks;
681 for(
const auto& tk : tks ) {
700 <<
"Resetting PFEGammaAlgo for new block and running!" << std::endl;
708 LOGVERB(
"PFEGammaAlgo") <<
"Splaying block" << std::endl;
711 if(
isMuon(pfelement) )
continue;
714 const size_t itype = (size_t)pfelement.type();
721 std::stringstream splayout;
722 for(
size_t itype = 0; itype <
_splayedblock.size(); ++itype ) {
723 splayout <<
"\tType: " << itype <<
" indices: ";
725 splayout << flaggedelement.first->index() <<
' ';
727 if( itype !=
_splayedblock.size() - 1 ) splayout << std::endl;
729 LOGVERB(
"PFEGammaAlgo") << splayout.str();
766 <<
"Dumping after GSF and KF Track (Primary) Linking : " << std::endl;
773 <<
"Dumping after first merging operation : " << std::endl;
779 for(
auto& RO : _refinableObjects ) {
790 <<
"Dumping after ECAL to Track (Secondary) Linking : " << std::endl;
797 <<
"There are " << _refinableObjects.size()
798 <<
" after the 2nd merging step." << std::endl;
802 for(
auto& RO : _refinableObjects ) {
809 std::sort(RO.ecalclusters.begin(), RO.ecalclusters.end(),
812 {
return ( a.first->clusterRef()->correctedEnergy() >
813 b.first->clusterRef()->correctedEnergy() ) ; });
814 setROElectronCluster(RO);
818 <<
"There are " << _refinableObjects.size()
819 <<
" after the unlinking and vetos step." << std::endl;
834 <<
"creating SC-based proto-object" << std::endl
835 <<
"\tSC at index: " << element.first->index()
836 <<
" has type: " << element.first->type() << std::endl;
837 element.second =
false;
870 <<
"creating GSF-based proto-object" << std::endl
871 <<
"\tGSF at index: " << element.first->index()
872 <<
" has type: " << element.first->type() << std::endl;
878 element.second =
false;
893 std::stringstream gsf_err;
894 elementAsGSF->
Dump(gsf_err,
"\t");
896 <<
"Found a GSF track with no seed! This should not happen!" 897 << std::endl << gsf_err.str() << std::endl;
901 element.second =
false;
903 fromGSF.
primaryGSFs.emplace_back(elementAsGSF,
true);
910 if( dist == 0.001
f ) {
913 fromGSF.
brems.emplace_back(eAsBrem,
true);
914 fromGSF.
localMap.emplace_back(eAsBrem,elementAsGSF);
915 fromGSF.
localMap.emplace_back(elementAsGSF,eAsBrem);
926 <<
"GSF-based proto-object is ECAL driven, merging SC-cand" 933 SeedMatchesToProtoObject sctoseedmatch(fromGSF.
electronSeed);
937 auto clusmatch = std::find_if(objsbegin,objsend,sctoseedmatch);
938 if( clusmatch != objsend ) {
939 fromGSF.
parentSC = clusmatch->parentSC;
949 <<
"Encountered the known GSF-SC splitting bug " 950 <<
" in PFBlockAlgo! We should really fix this!" << std::endl;
952 std::stringstream gsf_err;
953 elementAsGSF->
Dump(gsf_err,
"\t");
955 <<
"Expected SuperCluster from ECAL driven GSF seed " 956 <<
"was not found in the block!" << std::endl
957 << gsf_err.str() << std::endl;
981 std::vector<PFClusterFlaggedElement>& ecalclusters,
983 ecalclusters.clear();
986 <<
"Pointer to SC element: 0x" 987 << std::hex << thesc <<
std::dec << std::endl
988 <<
"cleared ecalclusters and ecal2ps!" << std::endl;
993 if( ecalbegin == ecalend && hgcalbegin == hgcalend ) {
994 LOGERR(
"PFEGammaAlgo::unwrapSuperCluster()")
995 <<
"There are no ECAL elements in a block with imported SC!" 996 <<
" This is a bug we should fix this!" 1004 <<
"SuperCluster pointed to by block element is null!" 1008 <<
"Got a valid super cluster ref! 0x" 1009 << std::hex << scref.
get() <<
std::dec << std::endl;
1010 const size_t nscclusters = scref->clustersSize();
1011 const size_t nscpsclusters = scref->preshowerClustersSize();
1012 size_t npfpsclusters = 0;
1013 size_t npfclusters = 0;
1015 <<
"Precalculated cluster multiplicities: " 1016 << nscclusters <<
' ' << nscpsclusters << std::endl;
1017 NotCloserToOther<reco::PFBlockElement::SC,reco::PFBlockElement::ECAL>
1019 NotCloserToOther<reco::PFBlockElement::SC,reco::PFBlockElement::HGCAL>
1021 auto ecalfirstnotinsc = std::partition(ecalbegin,ecalend,ecalClustersInSC);
1022 auto hgcalfirstnotinsc = std::partition(hgcalbegin,hgcalend,hgcalClustersInSC);
1034 if( ecalfirstnotinsc == ecalbegin &&
1035 hgcalfirstnotinsc == hgcalbegin) {
1036 LOGERR(
"PFEGammaAlgo::unwrapSuperCluster()")
1037 <<
"No associated block elements to SuperCluster!" 1038 <<
" This is a bug we should fix!" 1045 if( is_pf_sc && nscclusters != npfclusters ) {
1046 std::stringstream sc_err;
1047 thesc->
Dump(sc_err,
"\t");
1049 <<
"The number of found ecal elements (" 1050 << nscclusters <<
") in block is not the same as" 1051 <<
" the number of ecal PF clusters reported by the PFSuperCluster" 1052 <<
" itself (" << npfclusters
1053 <<
")! This should not happen!" << std::endl
1054 << sc_err.str() << std::endl;
1056 for(
auto ecalitr = ecalbegin; ecalitr != ecalfirstnotinsc; ++ecalitr ) {
1062 if(!is_pf_sc &&
std::find(safePFClusters.begin(),safePFClusters.end(),elemascluster) ==
1063 safePFClusters.end() )
continue;
1066 ecalclusters.emplace_back(elemascluster,
true);
1068 ecalitr->second =
false;
1072 auto emplaceresult = ecal2ps.emplace(elemascluster,
1073 ClusterMap::mapped_type());
1074 if( !emplaceresult.second ) {
1075 std::stringstream clus_err;
1076 elemascluster->
Dump(clus_err,
"\t");
1078 <<
"List of pointers to ECAL block elements contains non-unique items!" 1079 <<
" This is very bad!" << std::endl
1080 <<
"cluster ptr = 0x" << std::hex << elemascluster <<
std::dec 1081 << std::endl << clus_err.str() << std::endl;
1083 ClusterMap::mapped_type& eslist = emplaceresult.first->second;
1087 for(
auto hgcalitr = hgcalbegin; hgcalitr != hgcalfirstnotinsc; ++hgcalitr ) {
1093 if(!is_pf_sc &&
std::find(safePFClusters.begin(),safePFClusters.end(),elemascluster) ==
1094 safePFClusters.end() )
continue;
1097 ecalclusters.emplace_back(elemascluster,
true);
1099 hgcalitr->second =
false;
1117 <<
" Unwrapped SC has " << npfclusters <<
" ECAL sub-clusters" 1118 <<
" and " << npfpsclusters <<
" PreShower layers 1 & 2 clusters!" 1125 ClusterMap::mapped_type& eslist) {
1128 EEtoPSElement ecalkey(clusptr.
key(),clusptr);
1129 auto assc_ps = std::equal_range(
eetops_->cbegin(),
1132 [](
const EEtoPSElement&
a,
const EEtoPSElement&
b){
return a.first <
b.first;});
1135 for(
auto pscl = assc_ps.first; pscl != assc_ps.second; ++pscl ) {
1136 if( pscl->second == temp ) {
1137 const ClusterElement* pstemp =
1138 docast(
const ClusterElement*,ps1.first);
1139 eslist.emplace_back(pstemp,
true);
1145 for(
auto pscl = assc_ps.first; pscl != assc_ps.second; ++pscl ) {
1146 if( pscl->second == temp ) {
1147 const ClusterElement* pstemp =
1148 docast(
const ClusterElement*,ps2.first);
1149 eslist.emplace_back(pstemp,
true);
1153 return eslist.size();
1161 <<
" refinable objects for this block: " << std::endl;
1163 std::stringstream
info;
1164 info <<
"Refinable Object:" << std::endl;
1166 info <<
"\tSuperCluster element attached to object:" << std::endl
1168 ro.parentSC->Dump(info,
"\t");
1171 if( ro.electronSeed.isNonnull() ) {
1172 info <<
"\tGSF element attached to object:" << std::endl;
1173 ro.primaryGSFs.front().first->Dump(info,
"\t");
1175 info <<
"firstBrem : " << ro.firstBrem
1176 <<
" lateBrem : " << ro.lateBrem
1177 <<
" nBrems with cluster : " << ro.nBremsWithClusters
1179 if( ro.electronClusters.size() && ro.electronClusters[0] ) {
1180 info <<
"electron cluster : ";
1181 ro.electronClusters[0]->Dump(info,
"\t");
1184 info <<
" no electron cluster." << std::endl;
1187 if( ro.primaryKFs.size() ) {
1188 info <<
"\tPrimary KF tracks attached to object: " << std::endl;
1189 for(
const auto& kf : ro.primaryKFs ) {
1190 kf.first->Dump(info,
"\t");
1194 if( ro.secondaryKFs.size() ) {
1195 info <<
"\tSecondary KF tracks attached to object: " << std::endl;
1196 for(
const auto& kf : ro.secondaryKFs ) {
1197 kf.first->Dump(info,
"\t");
1201 if( ro.brems.size() ) {
1202 info <<
"\tBrem tangents attached to object: " << std::endl;
1203 for(
const auto& brem : ro.brems ) {
1204 brem.first->Dump(info,
"\t");
1208 if( ro.ecalclusters.size() ) {
1209 info <<
"\tECAL clusters attached to object: " << std::endl;
1210 for(
const auto& clus : ro.ecalclusters ) {
1211 clus.first->Dump(info,
"\t");
1213 if( ro.ecal2ps.find(clus.first) != ro.ecal2ps.end() ) {
1214 for(
const auto& psclus : ro.ecal2ps.at(clus.first) ) {
1215 info <<
"\t\t Attached PS Cluster: ";
1216 psclus.first->Dump(info,
"");
1230 typedef std::multimap<double, unsigned> MatchedMap;
1234 MatchedMap matchedGSFs, matchedECALs;
1235 std::unordered_map<GsfTrackElementPtr,MatchedMap> gsf_ecal_cache;
1237 matchedGSFs.clear();
1242 if( matchedGSFs.empty() ) {
1247 std::partial_sort(ecalbegin,ecalbegin+1,ecalend,closestTrackToECAL);
1250 const float dist =
_currentblock->dist(kftrack.first->index(),
1251 closestECAL.first->index(),
1257 closestECAL.first->index(),
1260 if( dist_sc != -1.0
f) { inSC =
true;
break; }
1263 if( dist != -1.0
f && closestECAL.second ) {
1264 bool gsflinked =
false;
1266 for(
const auto& gsfflag :
_splayedblock[reco::PFBlockElement::GSF]) {
1273 if( !gsf_ecal_cache.count(elemasgsf) ) {
1274 matchedECALs.clear();
1279 gsf_ecal_cache.emplace(elemasgsf,matchedECALs);
1280 MatchedMap().swap(matchedECALs);
1282 const MatchedMap& ecal_matches = gsf_ecal_cache[elemasgsf];
1283 if( !ecal_matches.empty() ) {
1284 if( ecal_matches.begin()->second == closestECAL.first->index() ) {
1290 if( !gsflinked && !inSC) {
1297 trackref->hitPattern().numberOfLostHits(HitPattern::MISSING_INNER_HITS);
1298 bool fromprimaryvertex =
false;
1302 fromprimaryvertex =
true;
1308 closestECAL.second =
false;
1318 if( ROs.size() < 2 )
return;
1319 bool check_for_merge =
true;
1320 while( check_for_merge ) {
1325 for(
auto it1 = ROs.begin(); it1 != ROs.end(); ++it1 ) {
1326 auto find_start = it1; ++find_start;
1327 auto has_merge = std::find_if(find_start,ROs.end(),
1328 std::bind(testIfROMergableByLink, _1, *it1));
1329 if( has_merge != ROs.end() && it1 != ROs.begin() ) {
1335 auto mergestart = ROs.begin(); ++mergestart;
1336 auto nomerge = std::partition(mergestart,ROs.end(),
1337 std::bind(testIfROMergableByLink, _1, thefront));
1338 if( nomerge != mergestart ) {
1339 LOGDRESSED(
"PFEGammaAlgo::mergeROsByAnyLink()")
1341 <<
" to merge by links to the front!" << std::endl;
1342 for(
auto roToMerge = mergestart; roToMerge != nomerge; ++roToMerge) {
1345 if( !thefront.
ecalclusters.empty() && !roToMerge->ecalclusters.empty() ) {
1346 if( thefront.
ecalclusters.front().first->clusterRef()->layer() !=
1347 roToMerge->ecalclusters.front().first->clusterRef()->layer() ) {
1348 LOGWARN(
"PFEGammaAlgo::mergeROsByAnyLink")
1349 <<
"Tried to merge EB and EE clusters! Skipping!";
1350 ROs.push_back(*roToMerge);
1356 roToMerge->ecalclusters.begin(),
1357 roToMerge->ecalclusters.end());
1358 thefront.
ecal2ps.insert(roToMerge->ecal2ps.begin(),
1359 roToMerge->ecal2ps.end());
1361 roToMerge->secondaryKFs.begin(),
1362 roToMerge->secondaryKFs.end());
1365 roToMerge->localMap.begin(),
1366 roToMerge->localMap.end());
1368 if( !thefront.
parentSC && roToMerge->parentSC ) {
1369 thefront.
parentSC = roToMerge->parentSC;
1372 roToMerge->electronSeed.isNonnull() ) {
1375 roToMerge->primaryGSFs.begin(),
1376 roToMerge->primaryGSFs.end());
1378 roToMerge->primaryKFs.begin(),
1379 roToMerge->primaryKFs.end());
1381 roToMerge->brems.begin(),
1382 roToMerge->brems.end());
1385 thefront.
firstBrem = roToMerge->firstBrem;
1386 thefront.
lateBrem = roToMerge->lateBrem;
1388 roToMerge->electronSeed.isNonnull()) {
1389 LOGDRESSED(
"PFEGammaAlgo::mergeROsByAnyLink")
1390 <<
"Need to implement proper merging of two gsf candidates!" 1394 ROs.erase(mergestart,nomerge);
1396 ROs.push_back(ROs.front());
1399 check_for_merge =
false;
1402 LOGDRESSED(
"PFEGammaAlgo::mergeROsByAnyLink()")
1403 <<
"After merging by links there are: " << ROs.size()
1404 <<
" refinable EGamma objects!" << std::endl;
1422 NotCloserToOther<reco::PFBlockElement::GSF,reco::PFBlockElement::TRACK>
1425 auto notlinked = std::partition(KFbegin,KFend,gsfTrackToKFs);
1427 for(
auto kft = KFbegin; kft != notlinked; ++kft ) {
1434 kft->second =
false;
1436 RO.
localMap.emplace_back(seedtk,elemaskf);
1437 RO.
localMap.emplace_back(elemaskf,seedtk);
1438 }
else if ( elemaskf->
trackType(convType) ) {
1439 kft->second =
false;
1441 RO.
localMap.emplace_back(seedtk,elemaskf);
1442 RO.
localMap.emplace_back(elemaskf,seedtk);
1459 throw cms::Exception(
"PFEGammaAlgo::linkRefinableObjectPrimaryKFsToSecondaryKFs()")
1460 <<
"A KF track from conversion has been assigned as a primary!!" 1463 NotCloserToOther<reco::PFBlockElement::TRACK,reco::PFBlockElement::TRACK,true>
1466 auto notlinked = std::partition(KFbegin,KFend,kfTrackToKFs);
1468 for(
auto kft = KFbegin; kft != notlinked; ++kft ) {
1474 kft->second =
false;
1476 RO.
localMap.emplace_back(primkf,elemaskf);
1477 RO.
localMap.emplace_back(elemaskf,primkf);
1493 NotCloserToOther<reco::PFBlockElement::GSF,reco::PFBlockElement::ECAL>
1495 auto eoverp_test = std::bind(compatibleEoPOut, _1, primgsf.first);
1497 auto notmatched_blk = std::partition(ECALbegin,ECALend,gsfTracksToECALs);
1498 notmatched_blk = std::partition(ECALbegin,notmatched_blk,eoverp_test);
1500 auto notmatched_sc = std::partition(RO.
ecalclusters.begin(),
1503 notmatched_sc = std::partition(RO.
ecalclusters.begin(),
1511 LOGDRESSED(
"PFEGammaAlgo::linkGSFTracktoECAL()")
1512 <<
"Found a cluster already in RO by GSF extrapolation" 1513 <<
" at ECAL surface!" << std::endl
1514 << *elemascluster << std::endl;
1516 RO.
localMap.emplace_back(primgsf.first,temp.first);
1517 RO.
localMap.emplace_back(temp.first,primgsf.first);
1520 for(
auto ecal = ECALbegin;
ecal != notmatched_blk; ++
ecal ) {
1523 LOGDRESSED(
"PFEGammaAlgo::linkGSFTracktoECAL()")
1524 <<
"Found a cluster not already in RO by GSF extrapolation" 1525 <<
" at ECAL surface!" << std::endl
1526 << *elemascluster << std::endl;
1527 if( addPFClusterToROSafe(elemascluster,RO) ) {
1529 RO.
localMap.emplace_back(primgsf.first,elemascluster);
1530 RO.
localMap.emplace_back(elemascluster,primgsf.first);
1531 ecal->second =
false;
1544 NotCloserToOther<reco::PFBlockElement::GSF,reco::PFBlockElement::HCAL>
1546 auto notmatched = std::partition(HCALbegin,HCALend,gsfTracksToHCALs);
1547 for(
auto hcal = HCALbegin;
hcal != notmatched; ++
hcal ) {
1551 LOGDRESSED(
"PFEGammaAlgo::linkGSFTracktoECAL()")
1552 <<
"Found an HCAL cluster associated to GSF extrapolation" 1555 RO.
localMap.emplace_back(primgsf.first,temp.first);
1556 RO.
localMap.emplace_back(temp.first,primgsf.first);
1557 hcal->second =
false;
1573 std::vector<PFClusterFlaggedElement>& currentECAL = RO.
ecalclusters;
1576 NotCloserToOther<reco::PFBlockElement::TRACK,reco::PFBlockElement::ECAL>
1578 NotCloserToOther<reco::PFBlockElement::GSF,reco::PFBlockElement::ECAL>
1581 auto notmatched_sc = std::partition(currentECAL.begin(),
1585 notmatched_sc = std::partition(currentECAL.begin(),
1588 for(
auto ecalitr = currentECAL.begin(); ecalitr != notmatched_sc;
1594 LOGDRESSED(
"PFEGammaAlgo::linkKFTracktoECAL()")
1595 <<
"Found a cluster already in RO by KF extrapolation" 1596 <<
" at ECAL surface!" << std::endl
1597 << *elemascluster << std::endl;
1598 RO.
localMap.emplace_back(elemascluster,kfflagged.first);
1599 RO.
localMap.emplace_back(kfflagged.first,elemascluster);
1602 auto notmatched_blk = std::partition(ECALbegin,ECALend,kfTrackToECALs);
1604 notmatched_blk = std::partition(ECALbegin,notmatched_blk,kfTrackGSFToECALs);
1605 for(
auto ecalitr = ECALbegin; ecalitr != notmatched_blk; ++ecalitr ) {
1608 if( addPFClusterToROSafe(elemascluster,RO) ) {
1610 ecalitr->second =
false;
1612 LOGDRESSED(
"PFEGammaAlgo::linkKFTracktoECAL()")
1613 <<
"Found a cluster not in RO by KF extrapolation" 1614 <<
" at ECAL surface!" << std::endl
1615 << *elemascluster << std::endl;
1616 RO.
localMap.emplace_back(elemascluster,kfflagged.first);
1617 RO.
localMap.emplace_back(kfflagged.first,elemascluster);
1624 if( RO.
brems.empty() )
return;
1627 int lastBremTrajPos = -1;
1628 for(
auto& bremflagged : RO.
brems ) {
1629 bool has_clusters =
false;
1630 TrajPos = (bremflagged.first->indTrajPoint())-2;
1633 NotCloserToOther<reco::PFBlockElement::BREM,reco::PFBlockElement::ECAL>
1638 auto notmatched_rsc = std::partition(RSCBegin,RSCEnd,BremToECALs);
1639 for(
auto ecal = RSCBegin;
ecal != notmatched_rsc; ++
ecal ) {
1641 std::abs(
ecal->first->clusterRef()->positionREP().eta() -
1642 bremflagged.first->positionAtECALEntrance().eta() );
1643 if( deta < 0.015 ) {
1644 has_clusters =
true;
1645 if( lastBremTrajPos == -1 || lastBremTrajPos < TrajPos ) {
1646 lastBremTrajPos = TrajPos;
1648 if( FirstBrem == -1 || TrajPos < FirstBrem ) {
1649 FirstBrem = TrajPos;
1653 <<
"Found a cluster already in SC linked to brem extrapolation" 1654 <<
" at ECAL surface!" << std::endl;
1655 RO.
localMap.emplace_back(
ecal->first,bremflagged.first);
1656 RO.
localMap.emplace_back(bremflagged.first,
ecal->first);
1660 auto notmatched_block = std::partition(ECALbegin,ECALend,BremToECALs);
1661 for(
auto ecal = ECALbegin;
ecal != notmatched_block; ++
ecal ) {
1663 std::abs(
ecal->first->clusterRef()->positionREP().eta() -
1664 bremflagged.first->positionAtECALEntrance().eta() );
1665 if( deta < 0.015 ) {
1666 has_clusters =
true;
1667 if( lastBremTrajPos == -1 || lastBremTrajPos < TrajPos ) {
1668 lastBremTrajPos = TrajPos;
1670 if( FirstBrem == -1 || TrajPos < FirstBrem ) {
1672 FirstBrem = TrajPos;
1677 if( addPFClusterToROSafe(elemasclus,RO) ) {
1680 RO.
localMap.emplace_back(
ecal->first,bremflagged.first);
1681 RO.
localMap.emplace_back(bremflagged.first,
ecal->first);
1682 ecal->second =
false;
1684 <<
"Found a cluster not already associated by brem extrapolation" 1685 <<
" at ECAL surface!" << std::endl;
1703 auto ronotconv = std::partition(BeginROskfs,EndROskfs,isConversionTrack<reco::PFBlockElementTrack>);
1705 for(
size_t idx = 0;
idx < convkfs_end; ++
idx ) {
1706 const std::vector<PFKFFlaggedElement>& secKFs = RO.
secondaryKFs;
1711 auto notmatched = std::partition(KFbegin,KFend,TracksToTracks);
1712 notmatched = std::partition(KFbegin,notmatched,isConversionTrack<reco::PFBlockElementTrack>);
1713 for(
auto kf = KFbegin; kf != notmatched; ++kf ) {
1717 RO.
localMap.emplace_back(secKFs[
idx].first,kf->first);
1718 RO.
localMap.emplace_back(kf->first,secKFs[
idx].first);
1734 auto notmatchedkf = std::partition(KFbegin,KFend,ECALToTracks);
1735 auto notconvkf = std::partition(KFbegin,notmatchedkf,isConversionTrack<reco::PFBlockElementTrack>);
1737 for(
auto kf = KFbegin; kf != notconvkf; ++kf ) {
1746 for(
auto kf = notconvkf; kf != notmatchedkf; ++kf ) {
1749 kf->first->
index());
1773 auto notmatched = std::partition(ECALbegin,ECALend,TracksToECALwithCut);
1774 for(
auto ecal = ECALbegin;
ecal != notmatched; ++
ecal ) {
1777 if( addPFClusterToROSafe(elemascluster,RO) ) {
1781 ecal->second =
false;
1789 const std::list<PFEGammaAlgo::ProtoEGObject>& ROs,
1796 egcands.reserve(ROs.size());
1797 egxs.reserve(ROs.size());
1799 for(
auto& RO : ROs ) {
1800 if( RO.ecalclusters.empty() &&
1805 if( !RO.primaryGSFs.empty() || !RO.primaryKFs.empty() ) {
1810 if( !RO.primaryKFs.empty() ) {
1811 cand.
setCharge(RO.primaryKFs[0].first->trackRef()->charge());
1813 cand.
setTrackRef(RO.primaryKFs[0].first->trackRef());
1816 if( !RO.primaryGSFs.empty() ) {
1817 cand.
setCharge(RO.primaryGSFs[0].first->GsftrackRef()->chargeMode());
1830 for(
const auto& bremflagged : RO.brems ) {
1835 for(
const auto&
ecal : RO.ecalclusters ) {
1838 if( RO.ecal2ps.count(clus) ) {
1839 for(
auto& ps : RO.ecal2ps.at(clus) ) {
1846 for(
const auto& secdkf : RO.secondaryKFs ) {
1850 bool no_conv_ref =
true;
1851 for(
const auto& convref : convrefs ) {
1852 if( convref.isNonnull() && convref.isAvailable() ) {
1854 no_conv_ref =
false;
1861 const auto &mvavalmapped = RO.singleLegConversionMvaMap.find(kf);
1864 float mvaval = ( mvavalmapped != RO.singleLegConversionMvaMap.end() ?
1865 mvavalmapped->second :
1878 float trkTime = 0, trkTimeErr = -1;
1879 if (!RO.primaryGSFs.empty() && RO.primaryGSFs[0].first->isTimeValid()) {
1880 trkTime = RO.primaryGSFs[0].first->time();
1881 trkTimeErr = RO.primaryGSFs[0].first->timeError();
1882 }
else if (!RO.primaryKFs.empty() && RO.primaryKFs[0].first->isTimeValid()) {
1883 trkTime = RO.primaryKFs[0].first->time();
1884 trkTimeErr = RO.primaryKFs[0].first->timeError();
1886 if (trkTimeErr >= 0) {
1887 cand.
setTime( trkTime, trkTimeErr );
1895 const double scE = the_sc.
energy();
1899 egDir = egDir.Unit();
1908 !RO.primaryGSFs.empty() ) {
1912 gref->pzMode(),gref->pMode());
1916 !RO.primaryKFs.empty() ) {
1926 xtra.
setMVA(eleMVAValue);
1928 egcands.push_back(cand);
1929 egxs.push_back(xtra);
1950 const double eInGsf = std::hypot(refGsf->pMode(),mEl);
1951 double dEtGsfEcal = 1e6;
1953 const double eneHcalGsf = std::accumulate(
1958 {
return a +
b.first->clusterRef()->energy(); }
1962 refKf = ro.
primaryKFs.front().first->trackRef();
1964 const double eOutGsf = gsfElement->
Pout().t();
1966 double firstEcalGsfEnergy {0.0};
1967 double otherEcalGsfEnergy {0.0};
1968 double ecalBremEnergy {0.0};
1970 std::vector<const reco::PFCluster*> gsfCluster;
1973 const double cenergy =
ecal.first->clusterRef()->correctedEnergy();
1978 bool hasbrem =
false;
1979 for(
const auto& brem : ro.
brems )
1989 ecalBremEnergy += cenergy;
1993 if( hasgsf ) otherEcalGsfEnergy += cenergy;
1994 if( haskf ) ecalBremEnergy += cenergy;
1995 if( !(hasgsf || haskf) ) otherEcalGsfEnergy += cenergy;
2003 firstEcalGsfEnergy = cref->correctedEnergy();
2004 dEtGsfEcal = cref->positionREP().eta() - etaOutGsf;
2005 gsfCluster.push_back(&*cref);
2011 float firstBrem {-1.0f};
2012 float earlyBrem {-1.0f};
2013 float lateBrem {-1.0f};
2017 earlyBrem = ro.
firstBrem < 4 ? 1.0f : 0.0f;
2018 lateBrem = ro.
lateBrem == 1 ? 1.0f : 0.0f;
2022 if( firstEcalGsfEnergy > 0.0 )
2028 const float ptGsf = refGsf->ptMode();
2029 const float etaGsf = refGsf->etaMode();
2031 const double ptModeErrorGsf = refGsf->ptModeError();
2032 float ptModeErrOverPtGsf = (ptModeErrorGsf > 0. ? ptModeErrorGsf/ptGsf : 1.0);
2033 float chi2Gsf = refGsf->normalizedChi2();
2034 float dPtOverPtGsf = (ptGsf - gsfElement->
Pout().pt())/ptGsf;
2036 float nHitKf = refKf.
isNonnull() ? refKf->hitPattern().trackerLayersWithMeasurement() : 0;
2037 float chi2Kf = refKf.
isNonnull() ? refKf->normalizedChi2() : -0.01;
2040 float eTotPinMode = (firstEcalGsfEnergy+otherEcalGsfEnergy+ecalBremEnergy)/ eInGsf;
2041 float eGsfPoutMode = firstEcalGsfEnergy / eOutGsf;
2042 float eTotBremPinPoutMode = (ecalBremEnergy + otherEcalGsfEnergy) / (eInGsf - eOutGsf);
2043 float dEtaGsfEcalClust =
std::abs(dEtGsfEcal);
2044 float logSigmaEtaEta =
std::log(sigmaEtaEta);
2045 float hOverHe = eneHcalGsf/(eneHcalGsf + firstEcalGsfEnergy);
2052 dPtOverPtGsf = std::clamp(dPtOverPtGsf, -0.2
f, 1.0
f);
2053 ptModeErrOverPtGsf =
std::min(ptModeErrOverPtGsf,0.3
f);
2056 eTotPinMode = std::clamp(eTotPinMode,0.0
f, 5.0
f);
2057 eGsfPoutMode = std::clamp(eGsfPoutMode,0.0
f, 5.0
f);
2058 eTotBremPinPoutMode = std::clamp(eTotBremPinPoutMode,0.0
f, 5.0
f);
2059 dEtaGsfEcalClust =
std::min(dEtaGsfEcalClust,0.1
f);
2060 logSigmaEtaEta =
std::max(logSigmaEtaEta,-14.0
f);
2093 float vars[] = {
std::log(ptGsf), etaGsf, ptModeErrOverPtGsf, dPtOverPtGsf, chi2Gsf,
2094 nHitKf, chi2Kf, eTotPinMode, eGsfPoutMode, eTotBremPinPoutMode,
2095 dEtaGsfEcalClust, logSigmaEtaEta, hOverHe, lateBrem, firstBrem };
2097 return hoc->
gbrEle_->GetAdaBoostClassifier(vars);
2114 auto notmatchedkf = std::partition(KFbegin,KFend,ECALToTracks);
2115 auto notconvkf = std::partition(KFbegin,notmatchedkf,isConversionTrack<reco::PFBlockElementTrack>);
2117 for(
auto kf = notconvkf; kf != notmatchedkf; ++kf ) {
2137 std::vector<const reco::PFCluster*> bare_ptrs;
2140 rawSCEnergy(0), corrSCEnergy(0), corrPSEnergy(0),
2141 PS1_clus_sum(0), PS2_clus_sum(0),
2142 ePS1(0), ePS2(0), ps1_energy(0.0), ps2_energy(0.0);
2143 int condP1(1), condP2(1);
2149 edm::refToPtr<reco::PFClusterCollection>(clus.first->clusterRef());
2150 bare_ptrs.push_back(clusptr.
get());
2152 const double cluseraw = clusptr->
energy();
2155 posX += cluseraw * cluspos.X();
2156 posY += cluseraw * cluspos.Y();
2157 posZ += cluseraw * cluspos.Z();
2159 if( isEE && RO.
ecal2ps.count(clus.first)) {
2162 condP1 = condP2 = 1;
2164 const auto& psclusters = RO.
ecal2ps.at(clus.first);
2166 for(
auto i_ps = psclusters.begin(); i_ps != psclusters.end(); ++i_ps) {
2167 const PFClusterRef& psclus = i_ps->first->clusterRef();
2169 auto const& recH_Frac = psclus->recHitFractions();
2171 switch( psclus->layer() ) {
2173 for (
auto const& recH : recH_Frac){
2174 ESDetId strip1 = recH.recHitRef()->detId();
2179 if(status_p1->getStatusCode() == 0) condP1 = 0;
2184 for (
auto const& recH : recH_Frac){
2185 ESDetId strip2 = recH.recHitRef()->detId();
2188 if(status_p2->getStatusCode() == 0) condP2 = 0;
2198 {
return a + (
type == b.first->type())*b.first->clusterRef()->energy(); };
2200 PS1_clus_sum = std::accumulate(psclusters.begin(),psclusters.end(),
2202 PS2_clus_sum = std::accumulate(psclusters.begin(),psclusters.end(),
2205 if(condP1 == 1) ePS1 = -1.;
2206 if(condP2 == 1) ePS2 = -1.;
2210 PS1_clus_sum,PS2_clus_sum,
2214 if(ePS1 == -1.) ePS1 = 0;
2215 if(ePS2 == -1.) ePS2 = 0;
2217 rawSCEnergy += cluseraw;
2218 corrSCEnergy += cluscalibe;
2221 corrPSEnergy += ePS1 + ePS2;
2223 posX /= rawSCEnergy;
2224 posY /= rawSCEnergy;
2225 posZ /= rawSCEnergy;
2231 edm::refToPtr<reco::PFClusterCollection>(RO.
ecalclusters.front().
2232 first->clusterRef());
2240 edm::refToPtr<reco::PFClusterCollection>(clus.first->clusterRef());
2243 for(
auto& hit_and_fraction : hits_and_fractions ) {
2247 if( RO.
ecal2ps.count(clus.first) ) {
2248 const auto& cluspsassociation = RO.
ecal2ps.at(clus.first);
2252 for(
const auto& pscluselem : cluspsassociation ) {
2254 edm::refToPtr<reco::PFClusterCollection>(pscluselem.first->
2265 throw cms::Exception(
"PFECALSuperClusterAlgo::buildSuperCluster")
2266 <<
"Found a PS cluster matched to more than one EE cluster!" 2267 << std::endl << std::hex << psclus.
get() <<
" == " 2268 << found_pscluster->get() <<
std::dec << std::endl;
2291 const double Pin_gsf = RO.
primaryGSFs.front().first->GsftrackRef()->pMode();
2292 const double gsfOuterEta =
2293 RO.
primaryGSFs.front().first->positionAtECALEntrance().Eta();
2294 double tot_ecal= 0.0;
2295 std::vector<double> min_brem_dists;
2296 std::vector<double> closest_brem_eta;
2299 tot_ecal +=
ecal.first->clusterRef()->correctedEnergy();
2302 double min_brem_dist = 5000.0;
2303 double eta = -999.0;
2304 for(
const auto& brem : RO.
brems ) {
2306 ecal.first->index(),
2309 if( dist < min_brem_dist && dist != -1.0
f ) {
2310 min_brem_dist = dist;
2311 eta = brem.first->positionAtECALEntrance().Eta();
2314 min_brem_dists.push_back(min_brem_dist);
2315 closest_brem_eta.push_back(eta);
2323 const float secpin = secd_kf->first->trackRef()->p();
2324 bool remove_this_kf =
false;
2328 const float minbremdist = min_brem_dists[bremidx];
2329 const double ecalenergy =
ecal->first->clusterRef()->correctedEnergy();
2330 const double Epin = ecalenergy/secpin;
2331 const double detaGsf =
2332 std::abs(gsfOuterEta -
ecal->first->clusterRef()->positionREP().Eta());
2333 const double detaBrem =
2334 std::abs(closest_brem_eta[bremidx] -
2335 ecal->first->clusterRef()->positionREP().Eta());
2342 const float tkdist =
_currentblock->dist(secd_kf->first->index(),
2343 ecal->first->index(),
2350 if( Epin > 3 && kf_matched != RO.
localMap.end() &&
2351 tkdist != -1.0f && tkdist < minbremdist &&
2352 detaGsf > 0.05 && detaBrem > 0.015) {
2353 double res_with =
std::abs((tot_ecal-Pin_gsf)/Pin_gsf);
2354 double res_without =
std::abs((tot_ecal-ecalenergy-Pin_gsf)/Pin_gsf);
2355 if(res_without < res_with) {
2357 <<
" REJECTED_RES totenergy " << tot_ecal
2358 <<
" Pin_gsf " << Pin_gsf
2359 <<
" cluster to secondary " << ecalenergy
2360 <<
" res_with " << res_with
2361 <<
" res_without " << res_without << std::endl;
2362 tot_ecal -= ecalenergy;
2363 remove_this_kf =
true;
2369 if( remove_this_kf ) {
2378 bool removeFreeECAL,
2379 bool removeSCEcal) {
2380 std::vector<bool> cluster_in_sc;
2387 bool remove_this_kf =
false;
2388 NotCloserToOther<reco::PFBlockElement::TRACK,reco::PFBlockElement::HCAL>
2393 const float secpin = trkRef->p();
2395 for(
auto ecal = ecal_begin;
ecal != ecal_end; ++
ecal ) {
2396 const double ecalenergy =
ecal->first->clusterRef()->correctedEnergy();
2399 if( cluster_in_sc.size() < clus_idx + 1) {
2403 ecal->first->index(),
2407 cluster_in_sc.push_back(dist != -1.0
f);
2418 if( kf_matched != RO.
localMap.end() ) {
2419 auto hcal_matched = std::partition(hcal_begin,hcal_end,tracksToHCALs);
2420 for(
auto hcalclus = hcal_begin;
2421 hcalclus != hcal_matched;
2425 const double hcalenergy = clusthcal->
clusterRef()->energy();
2426 const double hpluse = ecalenergy+hcalenergy;
2427 const bool isHoHE = ( (hcalenergy / hpluse ) > 0.1 && goodTrack );
2428 const bool isHoE = ( hcalenergy > ecalenergy );
2429 const bool isPoHE = ( secpin > hpluse );
2430 if( cluster_in_sc[clus_idx] ) {
2431 if(isHoE || isPoHE) {
2433 <<
"REJECTED TRACK FOR H/E or P/(H+E), CLUSTER IN SC" 2434 <<
" H/H+E " << (hcalenergy / hpluse)
2435 <<
" H/E " << (hcalenergy > ecalenergy)
2436 <<
" P/(H+E) " << (secpin/hpluse)
2437 <<
" HCAL ENE " << hcalenergy
2438 <<
" ECAL ENE " << ecalenergy
2439 <<
" secPIN " << secpin
2440 <<
" Algo Track " << trkRef->algo() << std::endl;
2441 remove_this_kf =
true;
2446 <<
"REJECTED TRACK FOR H/H+E, CLUSTER NOT IN SC" 2447 <<
" H/H+E " << (hcalenergy / hpluse)
2448 <<
" H/E " << (hcalenergy > ecalenergy)
2449 <<
" P/(H+E) " << (secpin/hpluse)
2450 <<
" HCAL ENE " << hcalenergy
2451 <<
" ECAL ENE " << ecalenergy
2452 <<
" secPIN " << secpin
2453 <<
" Algo Track " <<trkRef->algo() << std::endl;
2454 remove_this_kf =
true;
2460 if( remove_this_kf ) {
2471 bool isPrimary =
false;
2477 PFRecTrackRef kfPfRef_fromGsf = (*gsfPfRef).kfPFRecTrackRef();
2482 if(kfref == kfref_fromGsf)
const SuperClusterRef & superClusterRef() const
const math::XYZTLorentzVector & Pout() const
Abstract base class for a PFBlock element (track, cluster...)
const math::XYZPoint & position() const
cluster centroid position
CaloCluster_iterator preshowerClustersBegin() const
fist iterator over PreshowerCluster constituents
const reco::GsfTrackRef & GsftrackRef() const
std::vector< PFClusterFlaggedElement > ecalclusters
static bool overlap(const reco::CaloCluster &sc1, const reco::CaloCluster &sc, float minfrac=0.01, bool debug=false)
bool isNonnull() const
Checks for non-null.
void setSuperClusterRef(reco::SuperClusterRef sc)
set reference to the corresponding supercluster
Ptr< typename C::value_type > refToPtr(Ref< C, typename C::value_type, refhelper::FindUsingAdvance< C, typename C::value_type > > const &ref)
double correctedEnergy() const
std::vector< std::pair< unsigned int, unsigned int > > fifthStepKfTrack_
reco::SuperClusterCollection refinedscs_
void addHitAndFraction(DetId id, float fraction)
reco::PFBlockRef parentBlock
void Dump(std::ostream &out=std::cout, const char *tab=" ") const override
print the object inside the element
void unlinkRefinableObjectKFandECALWithBadEoverP(ProtoEGObject &)
trackRef_iterator tracks_end() const
last iterator over tracks
static bool isMuon(const reco::PFBlockElement &elt)
void setPositionAtECALEntrance(const math::XYZPointF &pos)
set position at ECAL entrance
void setGsfElectronClusterRef(const reco::PFBlockRef &blk, const reco::PFBlockElementCluster &ref)
set gsf electron cluster ref
const PFClusterRef & clusterRef() const override
void addSingleLegConvTrackRefMva(const std::pair< reco::TrackRef, float > &trackrefmva)
add Single Leg Conversion TrackRef
void setPreshowerEnergyPlane2(double preshowerEnergy2)
std::pair< const PFClusterElement *, bool > PFClusterFlaggedElement
const self & getMap() const
T const * get() const
Returns C++ pointer to the item.
double y() const
y coordinate
void setHadEnergy(float val)
set the had energy. The cluster energies should be entered before
const math::XYZPointF & positionAtECALEntrance() const
std::shared_ptr< PFEnergyCalibration > thePFEnergyCalibration
const reco::TrackRef & trackRef() const override
void Dump(std::ostream &out=std::cout, const char *tab=" ") const override
print the object inside the element
const ConversionRefVector & convRefs() const override
std::map< unsigned int, Link > LinkData
Geom::Phi< T > phi() const
double pflowPhiWidth() const
std::vector< PFClusterFlaggedElement > hcalClusters
bool isPrimaryTrack(const reco::PFBlockElementTrack &KfEl, const reco::PFBlockElementGsfTrack &GsfEl)
bool trackType(TrackType trType) const override
void linkRefinableObjectPrimaryGSFTrackToECAL(ProtoEGObject &)
const GsfPFRecTrackRef & GsftrackRefPF() const
const edm::OwnVector< reco::PFBlockElement > & elements() const
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
edm::Ref< TrackExtraCollection > TrackExtraRef
persistent reference to a TrackExtra
void linkRefinableObjectECALToSingleLegConv(const pfEGHelpers::HeavyObjectCache *hoc, ProtoEGObject &)
std::vector< const PFClusterElement * > electronClusters
unsigned int index
index type
const LinkData & linkData() const
std::vector< std::vector< PFFlaggedElement > > _splayedblock
void setSeed(const CaloClusterPtr &r)
list of used xtals by DetId // now inherited by CaloCluster
const math::XYZTLorentzVector & Pin() const
std::pair< const PFGSFElement *, bool > PFGSFFlaggedElement
edm::Ptr< CaloCluster > CaloClusterPtr
void linkRefinableObjectBremTangentsToECAL(ProtoEGObject &)
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float > > XYZPointF
point in space with cartesian internal representation
const reco::Vertex * primaryVtx
unsigned int indTrajPoint() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
reco::PFBlockRef _currentblock
void setGsfTrackRef(const reco::GsfTrackRef &ref)
set gsftrack reference
std::pair< const reco::PFBlockElement *, bool > PFFlaggedElement
void setPhiWidth(double pw)
const Point & position() const
position
double pflowEtaWidth() const
std::pair< const PFSCElement *, bool > PFSCFlaggedElement
const math::XYZPointF & positionAtECALEntrance() const
edm::Handle< reco::PFCluster::EEtoPSAssociation > eetops_
void setCharge(Charge q) final
set electric charge
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
void set_mva_e_pi(float mvaNI)
std::vector< PFKFFlaggedElement > secondaryKFs
static double delPhi(const double phi1, const double phi2)
void setEtaWidth(double ew)
void setSigmaEtaEta(float val)
set the sigmaetaeta
void dumpCurrentRefinableObjects() const
Container::value_type value_type
void initializeProtoCands(std::list< ProtoEGObject > &)
void linkRefinableObjectPrimaryKFsToSecondaryKFs(ProtoEGObject &)
bool unwrapSuperCluster(const reco::PFBlockElementSuperCluster *, std::vector< PFClusterFlaggedElement > &, ClusterMap &)
bool goodTrack(const reco::Track *pTrack, math::XYZPoint leadPV, trackSelectionParameters parameters, bool debug=false)
double pflowSigmaEtaEta() const
bool fromPFSuperCluster() const
void setCorrectedEnergy(double cenergy)
void addElementInBlock(const reco::PFBlockRef &blockref, unsigned elementIndex)
add an element to the current PFCandidate
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
reco::PFCluster::EEtoPSAssociation EEtoPSAssociation
PFEGammaAlgo(const PFEGConfigInfo &)
bool produceEGCandsWithNoSuperCluster
const PFSCElement * parentSC
bool trackType(TrackType trType) const override
std::vector< reco::PFCandidateEGammaExtra > PFCandidateEGammaExtraCollection
collection of PFCandidateEGammaExtras
const_iterator find(uint32_t rawId) const
std::vector< PFBremFlaggedElement > brems
void setEarlyBrem(float val)
set EarlyBrem
Abs< T >::type abs(const T &t)
double z() const
z coordinate
void setGsfTrackPout(const math::XYZTLorentzVector &pout)
set the pout (not trivial to get from the GSF track)
double energy() const
cluster energy
T const * get() const
Returns C++ pointer to the item.
std::list< ProtoEGObject > _refinableObjects
KFValMap singleLegConversionMvaMap
bool isNull() const
Checks for null.
void Dump(std::ostream &out=std::cout, const char *tab=" ") const override
print the object inside the element
reco::PFCandidateEGammaExtraCollection outcandsextra_
double energy() const
cluster energy
void linkKFTrackToECAL(const PFKFFlaggedElement &, ProtoEGObject &)
bool isNonnull() const
Checks for non-null.
void setEcalEnergy(float eeRaw, float eeCorr)
set corrected Ecal energy
reco::PFBlock::LinkData _currentlinks
void buildAndRefineEGObjects(const pfEGHelpers::HeavyObjectCache *hoc, const reco::PFBlockRef &block)
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
double x() const
x coordinate
double rawEnergy() const
raw uncorrected energy (sum of energies of component BasicClusters)
bool isMuon(const reco::PFBlockElement &)
void fillExtraInfo(const ProtoEGObject &, reco::PFCandidateEGammaExtra &)
float calculateEleMVA(const pfEGHelpers::HeavyObjectCache *hoc, const ProtoEGObject &, reco::PFCandidateEGammaExtra &) const
bool applyCrackCorrections
void setDeltaEta(float val)
set the delta eta
void setGsfTrackRef(const reco::GsfTrackRef &ref)
set gsftrack reference
reco::ElectronSeedRef electronSeed
float evaluateSingleLegMVA(const pfEGHelpers::HeavyObjectCache *hoc, const reco::PFBlockRef &blockref, const reco::Vertex &primaryVtx, unsigned int trackIndex)
XYZVectorD XYZVector
spatial vector with cartesian internal representation
void associatedElements(unsigned i, const LinkData &linkData, std::multimap< double, unsigned > &sortedAssociates, reco::PFBlockElement::Type type=PFBlockElement::NONE, LinkTest test=LINKTEST_RECHIT) const
XYZPointD XYZPoint
point in space with cartesian internal representation
void addPreshowerCluster(const CaloClusterPtr &r)
add reference to constituent BasicCluster
void linkRefinableObjectGSFTracksToKFs(ProtoEGObject &)
std::vector< std::pair< unsigned int, unsigned int > > convGsfTrack_
void setSuperClusterPFECALRef(reco::SuperClusterRef sc)
set reference to the corresponding supercluster
void addConversionRef(const reco::ConversionRef &convref)
add Conversions from PF
std::vector< Item >::const_iterator const_iterator
std::vector< PFKFFlaggedElement > primaryKFs
std::unordered_map< const PFClusterElement *, std::vector< PFClusterFlaggedElement > > ClusterMap
void addCluster(const CaloClusterPtr &r)
add reference to constituent BasicCluster
void fillPFCandidates(const pfEGHelpers::HeavyObjectCache *hoc, const std::list< ProtoEGObject > &, reco::PFCandidateCollection &, reco::PFCandidateEGammaExtraCollection &)
void removeOrLinkECALClustersToKFTracks()
Particle reconstructed by the particle flow algorithm.
reco::SuperCluster buildRefinedSuperCluster(const ProtoEGObject &)
void unlinkRefinableObjectKFandECALMatchedToHCAL(ProtoEGObject &, bool removeFreeECAL=false, bool removeSCECAL=false)
std::pair< const PFKFElement *, bool > PFKFFlaggedElement
void mergeROsByAnyLink(std::list< ProtoEGObject > &)
void RunPFEG(const pfEGHelpers::HeavyObjectCache *hoc, const reco::PFBlockRef &blockRef, std::vector< bool > &active)
const PFRecTrackRef & trackRefPF() const override
void setSuperClusterRef(const reco::SuperClusterRef &scRef)
int attachPSClusters(const PFClusterElement *, ClusterMap::mapped_type &)
void linkRefinableObjectKFTracksToECAL(ProtoEGObject &)
void setKfTrackRef(const reco::TrackRef &ref)
set kf track reference
const CaloClusterPtr & seed() const
seed BasicCluster
void setMVA(float val)
set the result (mostly for debugging)
void linkRefinableObjectSecondaryKFsToECAL(ProtoEGObject &)
void setLateBrem(float val)
set LateBrem
trackRef_iterator tracks_begin() const
first iterator over tracks
void linkRefinableObjectConvSecondaryKFsToSecondaryKFs(ProtoEGObject &)
void setTrackRef(const reco::TrackRef &ref)
set track reference
reco::PFCandidateCollection outcands_
bool next_combination(BidIt n_begin, BidIt n_end, BidIt r_begin, BidIt r_end)
void setTime(float time, float timeError=0.f)
the timing information
void setPdgId(int pdgId) final
void setPreshowerEnergyPlane1(double preshowerEnergy1)
std::vector< PFGSFFlaggedElement > primaryGSFs
const std::unique_ptr< const GBRForest > gbrEle_
void setP4(const LorentzVector &p4) final
set 4-momentum
const ESChannelStatus * channelStatus_
CaloCluster_iterator preshowerClustersEnd() const
last iterator over PreshowerCluster constituents
void addExtraNonConvTrack(const reco::PFBlockRef &blk, const reco::PFBlockElementTrack &tkref)
track counting for electrons and photons
void setPreshowerEnergy(double preshowerEnergy)
const std::unique_ptr< const GBRForest > gbrSingleLeg_
void linkRefinableObjectPrimaryGSFTrackToHCAL(ProtoEGObject &)