34 #include "TMVA/MethodBDT.h"
37 #include "combination.hpp"
43 #define docast(x,y) dynamic_cast<x>(y)
44 #define LOGVERB(x) edm::LogVerbatim(x)
45 #define LOGWARN(x) edm::LogWarning(x)
46 #define LOGERR(x) edm::LogError(x)
47 #define LOGDRESSED(x) edm::LogInfo(x)
49 #define docast(x,y) reinterpret_cast<x>(y)
50 #define LOGVERB(x) LogTrace(x)
51 #define LOGWARN(x) edm::LogWarning(x)
52 #define LOGERR(x) edm::LogError(x)
53 #define LOGDRESSED(x) LogDebug(x)
62 typedef std::pair<CaloClusterPtr::key_type,CaloClusterPtr> EEtoPSElement;
70 typedef std::unary_function<
const ClusterFlaggedElement&,
73 typedef std::unary_function<
const PFFlaggedElement&,
74 bool> PFFlaggedElementMatcher;
75 typedef std::binary_function<
const PFFlaggedElement&,
76 const PFFlaggedElement&,
77 bool> PFFlaggedElementSorter;
80 bool> PFElementMatcher;
85 typedef std::unary_function<PFFlaggedElement&,
86 ClusterFlaggedElement> ClusterElementConverter;
88 struct SumPSEnergy :
public std::binary_function<double,
89 const ClusterFlaggedElement&,
93 double operator()(
double a,
94 const ClusterFlaggedElement&
b) {
96 return a + (_thetype == b.first->type())*b.first->clusterRef()->energy();
100 bool comparePSMapByKey(
const EEtoPSElement&
a,
101 const EEtoPSElement&
b) {
102 return a.first < b.first;
105 struct UsableElementToPSCluster :
public ClusterElementConverter {
106 ClusterFlaggedElement operator () (PFFlaggedElement&
elem) {
107 const ClusterElement* pselemascluster =
108 docast(
const ClusterElement*,elem.first);
111 std::stringstream ps_err;
112 pselemascluster->Dump(ps_err,
"\t");
114 <<
"This element is not a PS cluster!" << std::endl
115 << ps_err.str() << std::endl;
117 if( elem.second ==
false ) {
118 std::stringstream ps_err;
119 pselemascluster->Dump(ps_err,
"\t");
121 <<
"PS Cluster matched to EE is already used! "
122 <<
"This should be impossible!" << std::endl
123 << ps_err.str() << std::endl;
126 return std::make_pair(pselemascluster,
true);
130 struct SeedMatchesToSCElement :
public PFFlaggedElementMatcher {
135 bool operator() (
const PFFlaggedElement&
elem) {
136 const SCElement* scelem =
docast(
const SCElement*,elem.first);
137 if( _scfromseed.isNull() || !elem.second || !scelem)
return false;
138 return ( _scfromseed->seed()->seed() ==
139 scelem->superClusterRef()->seed()->seed() );
143 struct SCSubClusterMatchesToElement :
public PFFlaggedElementMatcher {
149 bool operator() (
const PFFlaggedElement&
elem) {
150 const ClusterElement* cluselem =
151 docast(
const ClusterElement*,elem.first);
152 if( !elem.second || !cluselem)
return false;
154 for( ; cl !=
end; ++
cl ) {
155 if((*cl)->seed() == cluselem->clusterRef()->seed()) {
163 struct SeedMatchesToProtoObject :
public POMatcher {
169 if( _scfromseed.isNonnull() ) {
174 bool operator() (
const PFEGammaAlgo::ProtoEGObject& po) {
175 if( _scfromseed.isNull() || !po.
parentSC )
return false;
177 return ( _scfromseed->seed() ==
180 return ( _scfromseed->seed()->seed() ==
185 template<
bool useConvs=false>
191 const float EoPin_cut = 1.0e6) {
200 &(block->elements()[
key]));
202 const ClusterElement* elemasclus =
203 reinterpret_cast<const ClusterElement*
>(&(block->elements()[
test]));
204 float cluster_e = elemasclus->clusterRef()->correctedEnergy();
205 float trk_pin = elemasgsf->
Pin().P();
206 if( cluster_e / trk_pin > EoPin_cut ) {
208 <<
"GSF track failed EoP cut to match with cluster!";
218 &(block->elements()[
key]));
220 const ClusterElement* elemasclus =
221 reinterpret_cast<const ClusterElement*
>(&(block->elements()[
test]));
222 float cluster_e = elemasclus->clusterRef()->correctedEnergy();
225 if( cluster_e / trk_pin > EoPin_cut ) {
227 <<
"KF track failed EoP cut to match with cluster!";
239 if( dist == -1.0
f )
return false;
240 std::multimap<double, unsigned> dists_to_val;
241 block->associatedElements(test,block->linkData(),dists_to_val,keytype,
243 for(
const auto& valdist : dists_to_val ) {
244 const size_t idx = valdist.second;
251 &(block->elements()[
idx]));
252 if( !useConvs && elemasgsf->
trackType(ConvType) )
return false;
254 const ClusterElement* elemasclus =
255 docast(
const ClusterElement*,&(block->elements()[
test]));
256 float cluster_e = elemasclus->clusterRef()->correctedEnergy();
257 float trk_pin = elemasgsf->
Pin().P();
258 if( cluster_e / trk_pin > EoPin_cut )
continue;
266 &(block->elements()[
idx]));
267 if( !useConvs && elemaskf->
trackType(ConvType) )
return false;
269 const ClusterElement* elemasclus =
270 reinterpret_cast<const ClusterElement*
>(&(block->elements()[
test]));
271 float cluster_e = elemasclus->clusterRef()->correctedEnergy();
274 if( cluster_e / trk_pin > EoPin_cut )
continue;
281 if( valdist.first < dist && idx != key ) {
283 <<
"key element of type " << keytype
284 <<
" is closer to another element of type" << valtype
292 struct CompatibleEoPOut :
public PFFlaggedElementMatcher {
295 bool operator()(
const PFFlaggedElement&
e)
const {
297 const ClusterElement* elemascluster =
298 docast(
const ClusterElement*,e.first);
299 const float gsf_eta_diff =
std::abs(
comp->positionAtECALEntrance().eta()-
302 return ( gsf_eta_diff <= 0.3 && cRef->
energy()/
comp->Pout().t() <= 5 );
306 template<
class TrackElementType>
307 struct IsConversionTrack : PFFlaggedElementMatcher {
308 bool operator()(
const PFFlaggedElement&
e) {
311 const TrackElementType* elemastrk =
312 docast(
const TrackElementType*,e.first);
313 return elemastrk->trackType(ConvType);
320 struct NotCloserToOther :
public PFFlaggedElementMatcher {
321 const reco::PFBlockElement*
comp;
324 const float EoPin_cut;
327 const PFFlaggedElement*
e,
328 const float EoPcut=1.0e6):
comp(e->first),
335 const reco::PFBlockElement* e,
336 const float EoPcut=1.0e6):
comp(e),
341 bool operator () (
const PFFlaggedElement& e) {
342 if( !e.second || valtype != e.first->type() )
return false;
343 return elementNotCloserToOther<useConv>(
block,
344 keytype,
comp->index(),
345 valtype,e.first->index(),
350 struct LesserByDistance :
public PFFlaggedElementSorter {
351 const reco::PFBlockElement*
comp;
356 const PFFlaggedElement*
e):
comp(e->first),
361 const reco::PFBlockElement* e):
comp(e),
364 bool operator () (
const PFFlaggedElement&
e1,
365 const PFFlaggedElement&
e2) {
366 double dist1 = block->dist(
comp->index(),
370 double dist2 = block->dist(
comp->index(),
374 dist1 = ( dist1 == -1.0 ? 1e6 : dist1 );
375 dist2 = ( dist2 == -1.0 ? 1e6 : dist2 );
376 return dist1 < dist2;
380 bool isROLinkedByClusterOrTrack(
const PFEGammaAlgo::ProtoEGObject& RO1,
381 const PFEGammaAlgo::ProtoEGObject& RO2 ) {
386 <<
"cannot merge, both have GSFs!" << std::endl;
391 if(RO1.
ecalclusters.front().first->clusterRef()->layer() !=
392 RO2.
ecalclusters.front().first->clusterRef()->layer() ) {
394 <<
"cannot merge, different ECAL types!" << std::endl;
404 elementNotCloserToOther(blk,
405 cluster.first->type(),
406 cluster.first->
index(),
407 primgsf.first->type(),
408 primgsf.first->index());
411 <<
"merged by cluster to primary GSF" << std::endl;
415 <<
"cluster to primary GSF failed since"
416 <<
" cluster closer to another GSF" << std::endl;
421 elementNotCloserToOther(blk,
422 cluster.first->type(),
423 cluster.first->
index(),
424 primkf.first->type(),
425 primkf.first->index());
428 <<
"merged by cluster to primary KF" << std::endl;
434 elementNotCloserToOther(blk,
435 cluster.first->type(),
436 cluster.first->
index(),
437 secdkf.first->type(),
438 secdkf.first->index());
441 <<
"merged by cluster to secondary KF" << std::endl;
446 for(
const auto& brem : RO2.
brems ) {
447 not_closer = elementNotCloserToOther(blk,
448 cluster.first->type(),
449 cluster.first->
index(),
451 brem.first->index());
454 <<
"merged by cluster to brem KF" << std::endl;
463 elementNotCloserToOther(blk,
464 primgsf.first->type(),
465 primgsf.first->
index(),
466 secdkf.first->type(),
467 secdkf.first->index());
470 <<
"merged by GSF to secondary KF" << std::endl;
479 elementNotCloserToOther(blk,
480 primkf.first->type(),
481 primkf.first->
index(),
482 secdkf.first->type(),
483 secdkf.first->index());
486 <<
"merged by primary KF to secondary KF" << std::endl;
495 elementNotCloserToOther<true>(blk,
496 secdkf1.first->type(),
497 secdkf1.first->
index(),
498 secdkf2.first->type(),
499 secdkf2.first->index());
502 <<
"merged by secondary KF to secondary KF" << std::endl;
510 struct TestIfROMergableByLink :
public POMatcher {
511 const PFEGammaAlgo::ProtoEGObject&
comp;
512 TestIfROMergableByLink(
const PFEGammaAlgo::ProtoEGObject& RO) :
514 bool operator() (
const PFEGammaAlgo::ProtoEGObject& ro) {
515 const bool result = ( isROLinkedByClusterOrTrack(
comp,ro) ||
516 isROLinkedByClusterOrTrack(ro,
comp) );
521 std::vector<const ClusterElement*>
523 std::vector<PFFlaggedElement>& ecals) {
524 std::vector<const ClusterElement*> cluster_list;
525 auto sccl = scref->clustersBegin();
526 auto scend = scref->clustersEnd();
527 auto pfc = ecals.begin();
528 auto pfcend = ecals.end();
529 for( ; sccl != scend; ++sccl ) {
530 std::vector<const ClusterElement*> matched_pfcs;
531 const double eg_energy = (*sccl)->energy();
533 for( pfc = ecals.begin(); pfc != pfcend; ++pfc ) {
534 const ClusterElement *pfcel =
535 docast(
const ClusterElement*, pfc->first);
540 if( matched && pfcel->clusterRef()->energy() < 1.2*scref->energy()) {
541 matched_pfcs.push_back(pfcel);
544 std::sort(matched_pfcs.begin(),matched_pfcs.end());
546 double min_residual = 1e6;
547 std::vector<const ClusterElement*> best_comb;
548 for(
size_t i = 1;
i <= matched_pfcs.size(); ++
i ) {
553 double energy = std::accumulate(matched_pfcs.begin(),
554 matched_pfcs.begin()+
i,
557 const ClusterElement*
c)
558 {
return a +
c->clusterRef()->energy(); });
559 const double resid =
std::abs(energy - eg_energy);
560 if( resid < min_residual ) {
562 best_comb.reserve(
i);
563 min_residual = resid;
564 best_comb.insert(best_comb.begin(),
565 matched_pfcs.begin(),
566 matched_pfcs.begin()+
i);
569 matched_pfcs.begin()+
i,
570 matched_pfcs.end()));
572 for(
const auto& clelem : best_comb ) {
574 if(
std::find(cluster_list.begin(),cluster_list.end(),clelem) ==
575 cluster_list.end() ) {
576 cluster_list.push_back(clelem);
582 bool addPFClusterToROSafe(
const ClusterElement*
cl,
583 PFEGammaAlgo::ProtoEGObject& RO) {
591 if( clayer == blayer ) {
601 void setROElectronCluster(PFEGammaAlgo::ProtoEGObject& RO) {
608 *kfCluster =
NULL, *gsfCluster_noassc =
NULL;
610 int nBremClusters = 0;
612 float mDist_gsf(maxDist), mDist_gsf_noassc(maxDist), mDist_kf(maxDist);
615 const bool hasclu = elementNotCloserToOther(parent,
618 cluster.first->type(),
619 cluster.first->index());
621 std::abs(cluster.first->clusterRef()->positionREP().eta() -
622 gsf.first->positionAtECALEntrance().eta());
625 cluster.first->clusterRef()->positionREP().phi() -
626 gsf.first->positionAtECALEntrance().phi()));
627 const float dist = std::hypot(deta,dphi);
628 if( hasclu && dist < mDist_gsf ) {
629 gsfCluster = cluster.first;
631 }
else if ( dist < mDist_gsf_noassc ) {
632 gsfCluster_noassc = cluster.first;
633 mDist_gsf_noassc = dist;
637 const bool hasclu = elementNotCloserToOther(parent,
640 cluster.first->type(),
641 cluster.first->index());
642 const float dist = parent->dist(cluster.first->index(),
646 if( hasclu && dist < mDist_kf ) {
647 kfCluster = cluster.first;
651 for(
const auto& brem : RO.
brems ) {
652 const bool hasclu = elementNotCloserToOther(parent,
655 cluster.first->type(),
656 cluster.first->index());
661 brem.first->indTrajPoint() - 2) ) {
662 firstBrem = brem.first;
665 ( lastBrem->indTrajPoint() - 2 <
666 brem.first->indTrajPoint() - 2) ) {
667 lastBrem = brem.first;
668 bremCluster = cluster.first;
673 if( !gsfCluster && !kfCluster && !bremCluster ) {
674 gsfCluster = gsfCluster_noassc;
680 }
else if ( kfCluster ) {
683 if( bremCluster && !gsfCluster && !kfCluster ) {
688 if( bremCluster == gsfCluster ) RO.
lateBrem = 1;
699 chi2(0.0), STIP(0.0), del_phi(0.0),HoverPt(0.0), EoverPt(0.0), track_pt(0.0),
701 CrysPhi_(0.0), CrysEta_(0.0), VtxZ_(0.0), ClusPhi_(0.0), ClusEta_(0.0),
702 ClusR9_(0.0), Clus5x5ratio_(0.0), PFCrysEtaCrack_(0.0), logPFClusE_(0.0), e3x3_(0.0),
703 CrysIPhi_(0), CrysIEta_(0),
704 CrysX_(0.0), CrysY_(0.0),
706 eSeed_(0.0), e1x3_(0.0),e3x1_(0.0), e1x5_(0.0), e2x5Top_(0.0), e2x5Bottom_(0.0), e2x5Left_(0.0), e2x5Right_(0.0),
707 etop_(0.0), ebottom_(0.0), eleft_(0.0), eright_(0.0),
709 PFPhoEta_(0.0), PFPhoPhi_(0.0), PFPhoR9_(0.0), PFPhoR9Corr_(0.0), SCPhiWidth_(0.0), SCEtaWidth_(0.0),
710 PFPhoEt_(0.0), RConv_(0.0), PFPhoEtCorr_(0.0), PFPhoE_(0.0), PFPhoECorr_(0.0), MustE_(0.0), E3x3_(0.0),
711 dEta_(0.0), dPhi_(0.0), LowClusE_(0.0), RMSAll_(0.0), RMSMust_(0.0), nPFClus_(0.0),
712 TotPS1_(0.0), TotPS2_(0.0),
714 x0inner_(0.0), x0middle_(0.0), x0outer_(0.0),
715 excluded_(0.0), Mustache_EtRatio_(0.0), Mustache_Et_out_(0.0),
719 TFile *XO_File =
new TFile(
cfg_.
X0_Map.c_str(),
"READ");
720 X0_sum = (TH2D*)XO_File->Get(
"TrackerSum");
721 X0_inner = (TH2D*)XO_File->Get(
"Inner");
722 X0_middle = (TH2D*)XO_File->Get(
"Middle");
723 X0_outer = (TH2D*)XO_File->Get(
"Outer");
729 std::vector<bool>& active) {
748 unsigned int track_index) {
754 chi2=elements[track_index].trackRef()->chi2()/elements[track_index].trackRef()->ndof();
755 nlost=elements[track_index].trackRef()->hitPattern().numberOfLostHits(HitPattern::MISSING_INNER_HITS);
756 nlayers=elements[track_index].trackRef()->hitPattern().trackerLayersWithMeasurement();
757 track_pt=elements[track_index].trackRef()->pt();
758 STIP=elements[track_index].trackRefPF()->STIP();
762 std::multimap<double, unsigned int> ecalAssoTrack;
767 std::multimap<double, unsigned int> hcalAssoTrack;
772 if(ecalAssoTrack.size() > 0) {
773 for(std::multimap<double, unsigned int>::iterator itecal = ecalAssoTrack.begin();
774 itecal != ecalAssoTrack.end(); ++itecal) {
775 linked_e=linked_e+elements[itecal->second].clusterRef()->energy();
778 if(hcalAssoTrack.size() > 0) {
779 for(std::multimap<double, unsigned int>::iterator ithcal = hcalAssoTrack.begin();
780 ithcal != hcalAssoTrack.end(); ++ithcal) {
781 linked_h=linked_h+elements[ithcal->second].clusterRef()->energy();
784 EoverPt=linked_e/elements[track_index].trackRef()->pt();
785 HoverPt=linked_h/elements[track_index].trackRef()->pt();
786 GlobalVector rvtx(elements[track_index].trackRef()->innerPosition().
X()-primaryvtx.
x(),
787 elements[track_index].trackRef()->innerPosition().Y()-primaryvtx.
y(),
788 elements[track_index].trackRef()->innerPosition().Z()-primaryvtx.
z());
789 double vtx_phi=rvtx.
phi();
791 del_phi=fabs(
deltaPhi(vtx_phi, elements[track_index].trackRef()->innerMomentum().
Phi()));
802 switch( pfbe.
type() ) {
806 std::multimap<double,unsigned> tks;
812 for(
const auto& tk : tks ) {
831 <<
"Resetting PFEGammaAlgo for new block and running!" << std::endl;
841 LOGVERB(
"PFEGammaAlgo") <<
"Splaying block" << std::endl;
844 if(
isAMuon(pfelement) )
continue;
845 const size_t itype = (size_t)pfelement.type();
847 _splayedblock[itype].push_back(std::make_pair(&pfelement,
true));
852 std::stringstream splayout;
853 for(
size_t itype = 0; itype <
_splayedblock.size(); ++itype ) {
854 splayout <<
"\tType: " << itype <<
" indices: ";
856 splayout << flaggedelement.first->index() <<
' ';
858 if( itype !=
_splayedblock.size() - 1 ) splayout << std::endl;
860 LOGVERB(
"PFEGammaAlgo") << splayout.str();
897 <<
"Dumping after GSF and KF Track (Primary) Linking : " << std::endl;
904 <<
"Dumping after first merging operation : " << std::endl;
910 for(
auto& RO : _refinableObjects ) {
921 <<
"Dumping after ECAL to Track (Secondary) Linking : " << std::endl;
928 <<
"There are " << _refinableObjects.size()
929 <<
" after the 2nd merging step." << std::endl;
933 for(
auto& RO : _refinableObjects ) {
940 std::sort(RO.ecalclusters.begin(), RO.ecalclusters.end(),
943 {
return ( a.first->clusterRef()->correctedEnergy() >
944 b.first->clusterRef()->correctedEnergy() ) ; });
945 setROElectronCluster(RO);
949 <<
"There are " << _refinableObjects.size()
950 <<
" after the unlinking and vetos step." << std::endl;
965 <<
"creating SC-based proto-object" << std::endl
966 <<
"\tSC at index: " << element.first->index()
967 <<
" has type: " << element.first->type() << std::endl;
968 element.second =
false;
999 std::list<ProtoEGObject>::iterator objsbegin, objsend;
1002 <<
"creating GSF-based proto-object" << std::endl
1003 <<
"\tGSF at index: " << element.first->index()
1004 <<
" has type: " << element.first->type() << std::endl;
1010 element.second =
false;
1025 std::stringstream gsf_err;
1026 elementAsGSF->
Dump(gsf_err,
"\t");
1028 <<
"Found a GSF track with no seed! This should not happen!"
1029 << std::endl << gsf_err.str() << std::endl;
1033 element.second =
false;
1035 fromGSF.
primaryGSFs.push_back(std::make_pair(elementAsGSF,
true));
1039 brem.first->index(),
1042 if( dist == 0.001
f ) {
1045 fromGSF.
brems.push_back(std::make_pair(eAsBrem,
true));
1048 brem.second =
false;
1058 <<
"GSF-based proto-object is ECAL driven, merging SC-cand"
1065 SeedMatchesToProtoObject sctoseedmatch(fromGSF.
electronSeed);
1069 auto clusmatch = std::find_if(objsbegin,objsend,sctoseedmatch);
1070 if( clusmatch != objsend ) {
1071 fromGSF.
parentSC = clusmatch->parentSC;
1081 <<
"Encountered the known GSF-SC splitting bug "
1082 <<
" in PFBlockAlgo! We should really fix this!" << std::endl;
1084 std::stringstream gsf_err;
1085 elementAsGSF->
Dump(gsf_err,
"\t");
1087 <<
"Expected SuperCluster from ECAL driven GSF seed "
1088 <<
"was not found in the block!" << std::endl
1089 << gsf_err.str() << std::endl;
1113 std::vector<PFClusterFlaggedElement>& ecalclusters,
1115 ecalclusters.clear();
1118 <<
"Pointer to SC element: 0x"
1119 << std::hex << thesc <<
std::dec << std::endl
1120 <<
"cleared ecalclusters and ecal2ps!" << std::endl;
1123 if( ecalbegin == ecalend ) {
1124 LOGERR(
"PFEGammaAlgo::unwrapSuperCluster()")
1125 <<
"There are no ECAL elements in a block with imported SC!"
1126 <<
" This is a bug we should fix this!"
1134 <<
"SuperCluster pointed to by block element is null!"
1138 <<
"Got a valid super cluster ref! 0x"
1139 << std::hex << scref.
get() <<
std::dec << std::endl;
1140 const size_t nscclusters = scref->clustersSize();
1141 const size_t nscpsclusters = scref->preshowerClustersSize();
1142 size_t npfpsclusters = 0;
1143 size_t npfclusters = 0;
1145 <<
"Precalculated cluster multiplicities: "
1146 << nscclusters <<
' ' << nscpsclusters << std::endl;
1147 NotCloserToOther<reco::PFBlockElement::SC,reco::PFBlockElement::ECAL>
1149 auto firstnotinsc = std::partition(ecalbegin,ecalend,ecalClustersInSC);
1158 if( firstnotinsc == ecalbegin ) {
1159 LOGERR(
"PFEGammaAlgo::unwrapSuperCluster()")
1160 <<
"No associated block elements to SuperCluster!"
1161 <<
" This is a bug we should fix!"
1168 if( is_pf_sc && nscclusters != npfclusters ) {
1169 std::stringstream sc_err;
1170 thesc->
Dump(sc_err,
"\t");
1172 <<
"The number of found ecal elements ("
1173 << nscclusters <<
") in block is not the same as"
1174 <<
" the number of ecal PF clusters reported by the PFSuperCluster"
1175 <<
" itself (" << npfclusters
1176 <<
")! This should not happen!" << std::endl
1177 << sc_err.str() << std::endl;
1179 for(
auto ecalitr = ecalbegin; ecalitr != firstnotinsc; ++ecalitr ) {
1185 if(!is_pf_sc &&
std::find(safePFClusters.begin(),safePFClusters.end(),elemascluster) ==
1186 safePFClusters.end() )
continue;
1189 ecalclusters.push_back(std::make_pair(elemascluster,
true));
1191 ecalitr->second =
false;
1195 auto emplaceresult = ecal2ps.emplace(elemascluster,
1196 ClusterMap::mapped_type());
1197 if( !emplaceresult.second ) {
1198 std::stringstream clus_err;
1199 elemascluster->
Dump(clus_err,
"\t");
1201 <<
"List of pointers to ECAL block elements contains non-unique items!"
1202 <<
" This is very bad!" << std::endl
1203 <<
"cluster ptr = 0x" << std::hex << elemascluster <<
std::dec
1204 << std::endl << clus_err.str() << std::endl;
1206 ClusterMap::mapped_type& eslist = emplaceresult.first->second;
1225 <<
" Unwrapped SC has " << npfclusters <<
" ECAL sub-clusters"
1226 <<
" and " << npfpsclusters <<
" PreShower layers 1 & 2 clusters!"
1234 ClusterMap::mapped_type& eslist) {
1237 EEtoPSElement ecalkey = std::make_pair(clusptr.
key(),clusptr);
1238 auto assc_ps = std::equal_range(
eetops_->cbegin(),
1244 for(
auto pscl = assc_ps.first; pscl != assc_ps.second; ++pscl ) {
1245 if( pscl->second == temp ) {
1246 const ClusterElement* pstemp =
1247 docast(
const ClusterElement*,ps1.first);
1254 for(
auto pscl = assc_ps.first; pscl != assc_ps.second; ++pscl ) {
1255 if( pscl->second == temp ) {
1256 const ClusterElement* pstemp =
1257 docast(
const ClusterElement*,ps2.first);
1262 return eslist.size();
1270 <<
" refinable objects for this block: " << std::endl;
1272 std::stringstream
info;
1273 info <<
"Refinable Object:" << std::endl;
1275 info <<
"\tSuperCluster element attached to object:" << std::endl
1277 ro.parentSC->Dump(info,
"\t");
1280 if( ro.electronSeed.isNonnull() ) {
1281 info <<
"\tGSF element attached to object:" << std::endl;
1282 ro.primaryGSFs.front().first->Dump(info,
"\t");
1284 info <<
"firstBrem : " << ro.firstBrem
1285 <<
" lateBrem : " << ro.lateBrem
1286 <<
" nBrems with cluster : " << ro.nBremsWithClusters
1288 if( ro.electronClusters.size() && ro.electronClusters[0] ) {
1289 info <<
"electron cluster : ";
1290 ro.electronClusters[0]->Dump(info,
"\t");
1293 info <<
" no electron cluster." << std::endl;
1296 if( ro.primaryKFs.size() ) {
1297 info <<
"\tPrimary KF tracks attached to object: " << std::endl;
1298 for(
const auto& kf : ro.primaryKFs ) {
1299 kf.first->Dump(info,
"\t");
1303 if( ro.secondaryKFs.size() ) {
1304 info <<
"\tSecondary KF tracks attached to object: " << std::endl;
1305 for(
const auto& kf : ro.secondaryKFs ) {
1306 kf.first->Dump(info,
"\t");
1310 if( ro.brems.size() ) {
1311 info <<
"\tBrem tangents attached to object: " << std::endl;
1312 for(
const auto& brem : ro.brems ) {
1313 brem.first->Dump(info,
"\t");
1317 if( ro.ecalclusters.size() ) {
1318 info <<
"\tECAL clusters attached to object: " << std::endl;
1319 for(
const auto& clus : ro.ecalclusters ) {
1320 clus.first->Dump(info,
"\t");
1322 if( ro.ecal2ps.find(clus.first) != ro.ecal2ps.end() ) {
1323 for(
const auto& psclus : ro.ecal2ps.at(clus.first) ) {
1324 info <<
"\t\t Attached PS Cluster: ";
1325 psclus.first->Dump(info,
"");
1339 typedef std::multimap<double, unsigned> MatchedMap;
1343 MatchedMap matchedGSFs, matchedECALs;
1344 std::unordered_map<GsfTrackElementPtr,MatchedMap> gsf_ecal_cache;
1346 matchedGSFs.clear();
1351 if( !matchedGSFs.size() ) {
1356 std::partial_sort(ecalbegin,ecalbegin+1,ecalend,closestTrackToECAL);
1359 const float dist =
_currentblock->dist(kftrack.first->index(),
1360 closestECAL.first->index(),
1366 closestECAL.first->index(),
1369 if( dist_sc != -1.0
f) { inSC =
true;
break; }
1372 if( dist != -1.0
f && closestECAL.second ) {
1373 bool gsflinked =
false;
1375 for(
const auto& gsfflag :
_splayedblock[reco::PFBlockElement::GSF]) {
1382 if( !gsf_ecal_cache.count(elemasgsf) ) {
1383 matchedECALs.clear();
1388 gsf_ecal_cache.emplace(elemasgsf,matchedECALs);
1389 MatchedMap().swap(matchedECALs);
1391 const MatchedMap& ecal_matches = gsf_ecal_cache[elemasgsf];
1392 if( ecal_matches.size() ) {
1393 if( ecal_matches.begin()->second == closestECAL.first->index() ) {
1399 if( !gsflinked && !inSC) {
1406 trackref->hitPattern().numberOfLostHits(HitPattern::MISSING_INNER_HITS);
1407 bool fromprimaryvertex =
false;
1411 fromprimaryvertex =
true;
1417 closestECAL.second =
false;
1434 if( ROs.size() < 2 )
return;
1435 bool check_for_merge =
true;
1436 while( check_for_merge ) {
1441 for(
auto it1 = ROs.begin(); it1 != ROs.end(); ++it1 ) {
1442 TestIfROMergableByLink mergeTest(*it1);
1443 auto find_start = it1; ++find_start;
1444 auto has_merge = std::find_if(find_start,ROs.end(),mergeTest);
1445 if( has_merge != ROs.end() && it1 != ROs.begin() ) {
1451 TestIfROMergableByLink mergeTest(thefront);
1452 auto mergestart = ROs.begin(); ++mergestart;
1453 auto nomerge = std::partition(mergestart,ROs.end(),mergeTest);
1454 if( nomerge != mergestart ) {
1455 LOGDRESSED(
"PFEGammaAlgo::mergeROsByAnyLink()")
1457 <<
" to merge by links to the front!" << std::endl;
1458 for(
auto roToMerge = mergestart; roToMerge != nomerge; ++roToMerge) {
1461 if( thefront.
ecalclusters.size() && roToMerge->ecalclusters.size() ) {
1462 if( thefront.
ecalclusters.front().first->clusterRef()->layer() !=
1463 roToMerge->ecalclusters.front().first->clusterRef()->layer() ) {
1464 LOGWARN(
"PFEGammaAlgo::mergeROsByAnyLink")
1465 <<
"Tried to merge EB and EE clusters! Skipping!";
1466 ROs.push_back(*roToMerge);
1472 roToMerge->ecalclusters.begin(),
1473 roToMerge->ecalclusters.end());
1474 thefront.
ecal2ps.insert(roToMerge->ecal2ps.begin(),
1475 roToMerge->ecal2ps.end());
1477 roToMerge->secondaryKFs.begin(),
1478 roToMerge->secondaryKFs.end());
1481 roToMerge->localMap.begin(),
1482 roToMerge->localMap.end());
1484 if( !thefront.
parentSC && roToMerge->parentSC ) {
1485 thefront.
parentSC = roToMerge->parentSC;
1488 roToMerge->electronSeed.isNonnull() ) {
1491 roToMerge->primaryGSFs.begin(),
1492 roToMerge->primaryGSFs.end());
1494 roToMerge->primaryKFs.begin(),
1495 roToMerge->primaryKFs.end());
1497 roToMerge->brems.begin(),
1498 roToMerge->brems.end());
1501 thefront.
firstBrem = roToMerge->firstBrem;
1502 thefront.
lateBrem = roToMerge->lateBrem;
1504 roToMerge->electronSeed.isNonnull()) {
1505 LOGWARN(
"PFEGammaAlgo::mergeROsByAnyLink")
1506 <<
"Need to implement proper merging of two gsf candidates!"
1510 ROs.erase(mergestart,nomerge);
1512 ROs.push_back(ROs.front());
1515 check_for_merge =
false;
1518 LOGDRESSED(
"PFEGammaAlgo::mergeROsByAnyLink()")
1519 <<
"After merging by links there are: " << ROs.size()
1520 <<
" refinable EGamma objects!" << std::endl;
1538 NotCloserToOther<reco::PFBlockElement::GSF,reco::PFBlockElement::TRACK>
1541 auto notlinked = std::partition(KFbegin,KFend,gsfTrackToKFs);
1543 for(
auto kft = KFbegin; kft != notlinked; ++kft ) {
1550 kft->second =
false;
1551 RO.
primaryKFs.push_back(std::make_pair(elemaskf,
true));
1554 }
else if ( elemaskf->
trackType(convType) ) {
1555 kft->second =
false;
1556 RO.
secondaryKFs.push_back(std::make_pair(elemaskf,
true));
1575 throw cms::Exception(
"PFEGammaAlgo::linkRefinableObjectPrimaryKFsToSecondaryKFs()")
1576 <<
"A KF track from conversion has been assigned as a primary!!"
1579 NotCloserToOther<reco::PFBlockElement::TRACK,reco::PFBlockElement::TRACK,true>
1582 auto notlinked = std::partition(KFbegin,KFend,kfTrackToKFs);
1584 for(
auto kft = KFbegin; kft != notlinked; ++kft ) {
1590 kft->second =
false;
1591 RO.
secondaryKFs.push_back(std::make_pair(elemaskf,
true));
1609 NotCloserToOther<reco::PFBlockElement::GSF,reco::PFBlockElement::ECAL>
1611 CompatibleEoPOut eoverp_test(primgsf.first);
1613 auto notmatched_blk = std::partition(ECALbegin,ECALend,gsfTracksToECALs);
1614 notmatched_blk = std::partition(ECALbegin,notmatched_blk,eoverp_test);
1616 auto notmatched_sc = std::partition(RO.
ecalclusters.begin(),
1619 notmatched_sc = std::partition(RO.
ecalclusters.begin(),
1627 LOGDRESSED(
"PFEGammaAlgo::linkGSFTracktoECAL()")
1628 <<
"Found a cluster already in RO by GSF extrapolation"
1629 <<
" at ECAL surface!" << std::endl
1630 << *elemascluster << std::endl;
1636 for(
auto ecal = ECALbegin;
ecal != notmatched_blk; ++
ecal ) {
1639 LOGDRESSED(
"PFEGammaAlgo::linkGSFTracktoECAL()")
1640 <<
"Found a cluster not already in RO by GSF extrapolation"
1641 <<
" at ECAL surface!" << std::endl
1642 << *elemascluster << std::endl;
1643 if( addPFClusterToROSafe(elemascluster,RO) ) {
1647 ecal->second =
false;
1660 NotCloserToOther<reco::PFBlockElement::GSF,reco::PFBlockElement::HCAL>
1662 CompatibleEoPOut eoverp_test(primgsf.first);
1663 auto notmatched = std::partition(HCALbegin,HCALend,gsfTracksToHCALs);
1664 for(
auto hcal = HCALbegin;
hcal != notmatched; ++
hcal ) {
1668 LOGDRESSED(
"PFEGammaAlgo::linkGSFTracktoECAL()")
1669 <<
"Found an HCAL cluster associated to GSF extrapolation"
1674 hcal->second =
false;
1690 std::vector<PFClusterFlaggedElement>& currentECAL = RO.
ecalclusters;
1693 NotCloserToOther<reco::PFBlockElement::TRACK,reco::PFBlockElement::ECAL>
1695 NotCloserToOther<reco::PFBlockElement::GSF,reco::PFBlockElement::ECAL>
1698 auto notmatched_sc = std::partition(currentECAL.begin(),
1702 notmatched_sc = std::partition(currentECAL.begin(),
1705 for(
auto ecalitr = currentECAL.begin(); ecalitr != notmatched_sc;
1711 LOGDRESSED(
"PFEGammaAlgo::linkKFTracktoECAL()")
1712 <<
"Found a cluster already in RO by KF extrapolation"
1713 <<
" at ECAL surface!" << std::endl
1714 << *elemascluster << std::endl;
1721 auto notmatched_blk = std::partition(ECALbegin,ECALend,kfTrackToECALs);
1723 notmatched_blk = std::partition(ECALbegin,notmatched_blk,kfTrackGSFToECALs);
1724 for(
auto ecalitr = ECALbegin; ecalitr != notmatched_blk; ++ecalitr ) {
1727 if( addPFClusterToROSafe(elemascluster,RO) ) {
1729 ecalitr->second =
false;
1731 LOGDRESSED(
"PFEGammaAlgo::linkKFTracktoECAL()")
1732 <<
"Found a cluster not in RO by KF extrapolation"
1733 <<
" at ECAL surface!" << std::endl
1734 << *elemascluster << std::endl;
1745 if( !RO.
brems.size() )
return;
1748 int lastBremTrajPos = -1;
1749 for(
auto& bremflagged : RO.
brems ) {
1750 bool has_clusters =
false;
1751 TrajPos = (bremflagged.first->indTrajPoint())-2;
1754 NotCloserToOther<reco::PFBlockElement::BREM,reco::PFBlockElement::ECAL>
1759 auto notmatched_rsc = std::partition(RSCBegin,RSCEnd,BremToECALs);
1760 for(
auto ecal = RSCBegin;
ecal != notmatched_rsc; ++
ecal ) {
1762 std::abs(
ecal->first->clusterRef()->positionREP().eta() -
1763 bremflagged.first->positionAtECALEntrance().eta() );
1764 if( deta < 0.015 ) {
1765 has_clusters =
true;
1766 if( lastBremTrajPos == -1 || lastBremTrajPos < TrajPos ) {
1767 lastBremTrajPos = TrajPos;
1769 if( FirstBrem == -1 || TrajPos < FirstBrem ) {
1770 FirstBrem = TrajPos;
1774 <<
"Found a cluster already in SC linked to brem extrapolation"
1775 <<
" at ECAL surface!" << std::endl;
1781 auto notmatched_block = std::partition(ECALbegin,ECALend,BremToECALs);
1782 for(
auto ecal = ECALbegin;
ecal != notmatched_block; ++
ecal ) {
1784 std::abs(
ecal->first->clusterRef()->positionREP().eta() -
1785 bremflagged.first->positionAtECALEntrance().eta() );
1786 if( deta < 0.015 ) {
1787 has_clusters =
true;
1788 if( lastBremTrajPos == -1 || lastBremTrajPos < TrajPos ) {
1789 lastBremTrajPos = TrajPos;
1791 if( FirstBrem == -1 || TrajPos < FirstBrem ) {
1793 FirstBrem = TrajPos;
1798 if( addPFClusterToROSafe(elemasclus,RO) ) {
1803 ecal->second =
false;
1805 <<
"Found a cluster not already associated by brem extrapolation"
1806 <<
" at ECAL surface!" << std::endl;
1820 IsConversionTrack<reco::PFBlockElementTrack> isConvKf;
1825 auto ronotconv = std::partition(BeginROskfs,EndROskfs,isConvKf);
1827 for(
size_t idx = 0;
idx < convkfs_end; ++
idx ) {
1828 const std::vector<PFKFFlaggedElement>& secKFs = RO.
secondaryKFs;
1833 auto notmatched = std::partition(KFbegin,KFend,TracksToTracks);
1834 notmatched = std::partition(KFbegin,notmatched,isConvKf);
1835 for(
auto kf = KFbegin; kf != notmatched; ++kf ) {
1838 RO.
secondaryKFs.push_back( std::make_pair(elemaskf,
true) );
1849 IsConversionTrack<reco::PFBlockElementTrack> isConvKf;
1857 auto notmatchedkf = std::partition(KFbegin,KFend,ECALToTracks);
1858 auto notconvkf = std::partition(KFbegin,notmatchedkf,isConvKf);
1860 for(
auto kf = KFbegin; kf != notconvkf; ++kf ) {
1863 RO.
secondaryKFs.push_back( std::make_pair(elemaskf,
true) );
1869 for(
auto kf = notconvkf; kf != notmatchedkf; ++kf ) {
1872 kf->first->
index());
1876 RO.
secondaryKFs.push_back( std::make_pair(elemaskf,
true) );
1896 auto notmatched = std::partition(ECALbegin,ECALend,TracksToECALwithCut);
1897 for(
auto ecal = ECALbegin;
ecal != notmatched; ++
ecal ) {
1900 if( addPFClusterToROSafe(elemascluster,RO) ) {
1904 ecal->second =
false;
1912 const std::list<PFEGammaAlgo::ProtoEGObject>& ROs,
1919 egcands.reserve(ROs.size());
1920 egxs.reserve(ROs.size());
1922 for(
auto& RO : ROs ) {
1923 if( RO.ecalclusters.size() == 0 &&
1928 if( RO.primaryGSFs.size() || RO.primaryKFs.size() ) {
1933 if( RO.primaryKFs.size() ) {
1934 cand.
setCharge(RO.primaryKFs[0].first->trackRef()->charge());
1936 cand.
setTrackRef(RO.primaryKFs[0].first->trackRef());
1939 if( RO.primaryGSFs.size() ) {
1940 cand.
setCharge(RO.primaryGSFs[0].first->GsftrackRef()->chargeMode());
1953 for(
const auto& bremflagged : RO.brems ) {
1958 for(
const auto&
ecal : RO.ecalclusters ) {
1961 for(
auto& ps : RO.ecal2ps.at(clus) ) {
1967 for(
const auto& secdkf : RO.secondaryKFs ) {
1971 bool no_conv_ref =
true;
1972 for(
const auto& convref : convrefs ) {
1973 if( convref.isNonnull() && convref.isAvailable() ) {
1975 no_conv_ref =
false;
1982 const auto &mvavalmapped = RO.singleLegConversionMvaMap.find(kf);
1985 float mvaval = ( mvavalmapped != RO.singleLegConversionMvaMap.end() ?
1986 mvavalmapped->second :
2003 const double scE = the_sc.
energy();
2007 egDir = egDir.Unit();
2016 RO.primaryGSFs.size() ) {
2020 gref->pzMode(),gref->pMode());
2024 RO.primaryKFs.size() ) {
2034 xtra.
setMVA(ele_mva_value);
2036 egcands.push_back(cand);
2037 egxs.push_back(xtra);
2052 const double Ein_gsf = std::hypot(RefGSF->pMode(),m_el);
2053 double deta_gsfecal = 1e6;
2054 double sigmaEtaEta = 1
e-14;
2055 const double Ene_hcalgsf = std::accumulate(RO.
hcalClusters.begin(),
2060 {
return a +
b.first->clusterRef()->energy(); }
2063 RefKF = RO.
primaryKFs.front().first->trackRef();
2065 const double Eout_gsf = gsfElement->
Pout().t();
2067 double FirstEcalGsfEnergy(0.0), OtherEcalGsfEnergy(0.0), EcalBremEnergy(0.0);
2069 std::vector<const reco::PFCluster*> gsfcluster;
2071 const double cenergy =
ecal.first->clusterRef()->correctedEnergy();
2080 bool hasbrem =
false;
2081 for(
const auto& brem : RO.
brems ) {
2089 EcalBremEnergy += cenergy;
2092 if( hasgsf ) OtherEcalGsfEnergy += cenergy;
2093 if( haskf ) EcalBremEnergy += cenergy;
2094 if( !(hasgsf || haskf) ) OtherEcalGsfEnergy += cenergy;
2101 FirstEcalGsfEnergy = cref->correctedEnergy();
2102 deta_gsfecal = cref->positionREP().eta() - Etaout_gsf;
2103 gsfcluster.push_back(&*cref);
2119 if( FirstEcalGsfEnergy > 0.0 ) {
2123 const float Pt_gsf = RefGSF->ptMode();
2127 const double ptModeErrorGsf = RefGSF->ptModeError();
2128 dPtOverPt_gsf = (ptModeErrorGsf > 0. ? ptModeErrorGsf/Pt_gsf : 1.0);
2129 nhit_gsf = RefGSF->hitPattern().trackerLayersWithMeasurement();
2130 chi2_gsf = RefGSF->normalizedChi2();
2137 nhit_kf = RefKF->hitPattern().trackerLayersWithMeasurement();
2138 chi2_kf = RefKF->normalizedChi2();
2143 const double EcalETot =
2144 (FirstEcalGsfEnergy+OtherEcalGsfEnergy+EcalBremEnergy);
2148 (Ein_gsf - Eout_gsf) );
2154 HOverHE = Ene_hcalgsf/(Ene_hcalgsf + FirstEcalGsfEnergy);
2205 return hoc->
gbrEle_->GetAdaBoostClassifier(vars);
2215 IsConversionTrack<reco::PFBlockElementTrack> isConvKf;
2223 auto notmatchedkf = std::partition(KFbegin,KFend,ECALToTracks);
2224 auto notconvkf = std::partition(KFbegin,notmatchedkf,isConvKf);
2226 for(
auto kf = notconvkf; kf != notmatchedkf; ++kf ) {
2249 std::vector<const reco::PFCluster*> bare_ptrs;
2251 double posX(0), posY(0), posZ(0),
2252 rawSCEnergy(0), corrSCEnergy(0), corrPSEnergy(0),
2253 PS1_clus_sum(0), PS2_clus_sum(0),
2254 ePS1(0), ePS2(0), ps1_energy(0.0), ps2_energy(0.0);
2255 int condP1(1), condP2(1);
2261 edm::refToPtr<reco::PFClusterCollection>(clus.first->clusterRef());
2262 bare_ptrs.push_back(clusptr.
get());
2264 const double cluseraw = clusptr->energy();
2265 double cluscalibe = clusptr->correctedEnergy();
2267 posX += cluseraw * cluspos.X();
2268 posY += cluseraw * cluspos.Y();
2269 posZ += cluseraw * cluspos.Z();
2274 condP1 = condP2 = 1;
2275 const auto& psclusters = RO.
ecal2ps.at(clus.first);
2277 for(
auto i_ps = psclusters.begin(); i_ps != psclusters.end(); ++i_ps) {
2278 const PFClusterRef& psclus = i_ps->first->clusterRef();
2280 auto const& recH_Frac = psclus->recHitFractions();
2282 switch( psclus->layer() ) {
2284 for (
auto const& recH : recH_Frac){
2285 ESDetId strip1 = recH.recHitRef()->detId();
2290 if(status_p1->getStatusCode() == 0) condP1 = 0;
2295 for (
auto const& recH : recH_Frac){
2296 ESDetId strip2 = recH.recHitRef()->detId();
2299 if(status_p2->getStatusCode() == 0) condP2 = 0;
2308 PS1_clus_sum = std::accumulate(psclusters.begin(),psclusters.end(),
2310 PS2_clus_sum = std::accumulate(psclusters.begin(),psclusters.end(),
2313 if(condP1 == 1) ePS1 = -1.;
2314 if(condP2 == 1) ePS2 = -1.;
2318 PS1_clus_sum,PS2_clus_sum,
2322 if(ePS1 == -1.) ePS1 = 0;
2323 if(ePS2 == -1.) ePS2 = 0;
2325 rawSCEnergy += cluseraw;
2326 corrSCEnergy += cluscalibe;
2329 corrPSEnergy += ePS1 + ePS2;
2331 posX /= rawSCEnergy;
2332 posY /= rawSCEnergy;
2333 posZ /= rawSCEnergy;
2339 edm::refToPtr<reco::PFClusterCollection>(RO.
ecalclusters.front().
2340 first->clusterRef());
2348 edm::refToPtr<reco::PFClusterCollection>(clus.first->clusterRef());
2350 auto& hits_and_fractions = clusptr->hitsAndFractions();
2351 for(
auto& hit_and_fraction : hits_and_fractions ) {
2355 const auto& cluspsassociation = RO.
ecal2ps.at(clus.first);
2359 for(
const auto& pscluselem : cluspsassociation ) {
2361 edm::refToPtr<reco::PFClusterCollection>(pscluselem.first->
2372 throw cms::Exception(
"PFECALSuperClusterAlgo::buildSuperCluster")
2373 <<
"Found a PS cluster matched to more than one EE cluster!"
2374 << std::endl << std::hex << psclus.
get() <<
" == "
2375 << found_pscluster->get() <<
std::dec << std::endl;
2397 const double Pin_gsf = RO.
primaryGSFs.front().first->GsftrackRef()->pMode();
2398 const double gsfOuterEta =
2399 RO.
primaryGSFs.front().first->positionAtECALEntrance().Eta();
2400 double tot_ecal= 0.0;
2401 std::vector<double> min_brem_dists;
2402 std::vector<double> closest_brem_eta;
2405 tot_ecal +=
ecal.first->clusterRef()->correctedEnergy();
2408 double min_brem_dist = 5000.0;
2409 double eta = -999.0;
2410 for(
const auto& brem : RO.
brems ) {
2412 ecal.first->index(),
2415 if( dist < min_brem_dist && dist != -1.0
f ) {
2416 min_brem_dist = dist;
2417 eta = brem.first->positionAtECALEntrance().Eta();
2420 min_brem_dists.push_back(min_brem_dist);
2421 closest_brem_eta.push_back(eta);
2429 const float secpin = secd_kf->first->trackRef()->p();
2430 bool remove_this_kf =
false;
2434 const float minbremdist = min_brem_dists[bremidx];
2435 const double ecalenergy =
ecal->first->clusterRef()->correctedEnergy();
2436 const double Epin = ecalenergy/secpin;
2437 const double detaGsf =
2438 std::abs(gsfOuterEta -
ecal->first->clusterRef()->positionREP().Eta());
2439 const double detaBrem =
2440 std::abs(closest_brem_eta[bremidx] -
2441 ecal->first->clusterRef()->positionREP().Eta());
2448 const float tkdist =
_currentblock->dist(secd_kf->first->index(),
2449 ecal->first->index(),
2456 if( Epin > 3 && kf_matched != RO.
localMap.end() &&
2457 tkdist != -1.0f && tkdist < minbremdist &&
2458 detaGsf > 0.05 && detaBrem > 0.015) {
2459 double res_with =
std::abs((tot_ecal-Pin_gsf)/Pin_gsf);
2460 double res_without =
std::abs((tot_ecal-ecalenergy-Pin_gsf)/Pin_gsf);
2461 if(res_without < res_with) {
2463 <<
" REJECTED_RES totenergy " << tot_ecal
2464 <<
" Pin_gsf " << Pin_gsf
2465 <<
" cluster to secondary " << ecalenergy
2466 <<
" res_with " << res_with
2467 <<
" res_without " << res_without << std::endl;
2468 tot_ecal -= ecalenergy;
2469 remove_this_kf =
true;
2475 if( remove_this_kf ) {
2484 bool removeFreeECAL,
2485 bool removeSCEcal) {
2486 std::vector<bool> cluster_in_sc;
2493 bool remove_this_kf =
false;
2494 NotCloserToOther<reco::PFBlockElement::TRACK,reco::PFBlockElement::HCAL>
2499 const float secpin = trkRef->p();
2501 for(
auto ecal = ecal_begin;
ecal != ecal_end; ++
ecal ) {
2502 const double ecalenergy =
ecal->first->clusterRef()->correctedEnergy();
2505 if( cluster_in_sc.size() < clus_idx + 1) {
2509 ecal->first->index(),
2513 cluster_in_sc.push_back(dist != -1.0
f);
2524 if( kf_matched != RO.
localMap.end() ) {
2525 auto hcal_matched = std::partition(hcal_begin,hcal_end,tracksToHCALs);
2526 for(
auto hcalclus = hcal_begin;
2527 hcalclus != hcal_matched;
2531 const double hcalenergy = clusthcal->
clusterRef()->energy();
2532 const double hpluse = ecalenergy+hcalenergy;
2533 const bool isHoHE = ( (hcalenergy / hpluse ) > 0.1 && goodTrack );
2534 const bool isHoE = ( hcalenergy > ecalenergy );
2535 const bool isPoHE = ( secpin > hpluse );
2536 if( cluster_in_sc[clus_idx] ) {
2537 if(isHoE || isPoHE) {
2539 <<
"REJECTED TRACK FOR H/E or P/(H+E), CLUSTER IN SC"
2540 <<
" H/H+E " << (hcalenergy / hpluse)
2541 <<
" H/E " << (hcalenergy > ecalenergy)
2542 <<
" P/(H+E) " << (secpin/hpluse)
2543 <<
" HCAL ENE " << hcalenergy
2544 <<
" ECAL ENE " << ecalenergy
2545 <<
" secPIN " << secpin
2546 <<
" Algo Track " << trkRef->algo() << std::endl;
2547 remove_this_kf =
true;
2552 <<
"REJECTED TRACK FOR H/H+E, CLUSTER NOT IN SC"
2553 <<
" H/H+E " << (hcalenergy / hpluse)
2554 <<
" H/E " << (hcalenergy > ecalenergy)
2555 <<
" P/(H+E) " << (secpin/hpluse)
2556 <<
" HCAL ENE " << hcalenergy
2557 <<
" ECAL ENE " << ecalenergy
2558 <<
" secPIN " << secpin
2559 <<
" Algo Track " <<trkRef->algo() << std::endl;
2560 remove_this_kf =
true;
2566 if( remove_this_kf ) {
2577 bool isPrimary =
false;
2583 PFRecTrackRef kfPfRef_fromGsf = (*gsfPfRef).kfPFRecTrackRef();
2588 if(kfref == kfref_fromGsf)
float EtotBremPinPoutMode
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::TrackRef & trackRef() const
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 Dump(std::ostream &out=std::cout, const char *tab=" ") const
print the object inside the element
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)
reco::PFCandidateEGammaExtraCollection egExtra_
std::vector< std::pair< unsigned int, unsigned int > > fifthStepKfTrack_
reco::SuperClusterCollection refinedscs_
void addHitAndFraction(DetId id, float fraction)
reco::PFBlockRef parentBlock
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
float calculate_ele_mva(const pfEGHelpers::HeavyObjectCache *hoc, const ProtoEGObject &, reco::PFCandidateEGammaExtra &)
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
virtual void setPdgId(int pdgId) final
std::shared_ptr< PFEnergyCalibration > thePFEnergyCalibration
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)
void linkRefinableObjectPrimaryGSFTrackToECAL(ProtoEGObject &)
const GsfPFRecTrackRef & GsftrackRefPF() const
const PFClusterRef & clusterRef() const
const edm::OwnVector< reco::PFBlockElement > & elements() const
double Phi_mpi_pi(double x)
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
std::unique_ptr< const GBRForest > gbrEle_
edm::Handle< reco::PFCluster::EEtoPSAssociation > eetops_
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
void set_mva_e_pi(float mvaNI)
std::vector< PFKFFlaggedElement > secondaryKFs
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
std::unique_ptr< const GBRForest > gbrSingleLeg_
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
const ConversionRefVector & convRefs() const
PFEGammaAlgo(const PFEGConfigInfo &)
bool produceEGCandsWithNoSuperCluster
const PFSCElement * parentSC
std::vector< reco::PFCandidateEGammaExtra > PFCandidateEGammaExtraCollection
collection of PFCandidateEGammaExtras
const_iterator find(uint32_t rawId) const
std::vector< PFBremFlaggedElement > brems
virtual void setCharge(Charge q) final
set electric charge
void setEarlyBrem(float val)
set EarlyBrem
Abs< T >::type abs(const T &t)
double z() const
y 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
virtual bool trackType(TrackType trType) const
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
KFValMap singleLegConversionMvaMap
bool isNull() const
Checks for null.
reco::PFCandidateEGammaExtraCollection outcandsextra_
void linkKFTrackToECAL(const PFKFFlaggedElement &, ProtoEGObject &)
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
virtual bool trackType(TrackType trType) const
double rawEnergy() const
raw uncorrected energy (sum of energies of component BasicClusters)
float EvaluateSingleLegMVA(const pfEGHelpers::HeavyObjectCache *hoc, const reco::PFBlockRef &blockref, const reco::Vertex &primaryvtx, unsigned int track_index)
void fill_extra_info(const ProtoEGObject &, reco::PFCandidateEGammaExtra &)
reco::PFCandidateCollection egCandidate_
bool applyCrackCorrections
bool isAMuon(const reco::PFBlockElement &)
void setDeltaEta(float val)
set the delta eta
void setGsfTrackRef(const reco::GsfTrackRef &ref)
set gsftrack reference
reco::ElectronSeedRef electronSeed
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
tuple idx
DEBUGGING if hasattr(process,"trackMonIterativeTracking2012"): print "trackMonIterativeTracking2012 D...
void addPreshowerCluster(const CaloClusterPtr &r)
add reference to constituent BasicCluster
virtual void setP4(const LorentzVector &p4) final
set 4-momentum
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 Dump(std::ostream &out=std::cout, const char *tab=" ") const
print the object inside the element
ElementMap _recoveredlinks
void fillPFCandidates(const pfEGHelpers::HeavyObjectCache *hoc, const std::list< ProtoEGObject > &, reco::PFCandidateCollection &, reco::PFCandidateEGammaExtraCollection &)
void removeOrLinkECALClustersToKFTracks()
Particle reconstructed by the particle flow algorithm.
void Dump(std::ostream &out=std::cout, const char *tab=" ") const
print the object inside the element
reco::SuperCluster buildRefinedSuperCluster(const ProtoEGObject &)
void unlinkRefinableObjectKFandECALMatchedToHCAL(ProtoEGObject &, bool removeFreeECAL=false, bool removeSCECAL=false)
std::pair< const PFKFElement *, bool > PFKFFlaggedElement
const PFRecTrackRef & trackRefPF() const
void mergeROsByAnyLink(std::list< ProtoEGObject > &)
void RunPFEG(const pfEGHelpers::HeavyObjectCache *hoc, const reco::PFBlockRef &blockRef, std::vector< bool > &active)
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)
volatile std::atomic< bool > shutdown_flag false
void linkRefinableObjectSecondaryKFsToECAL(ProtoEGObject &)
void setLateBrem(float val)
set LateBrem
trackRef_iterator tracks_begin() const
first iterator over tracks
reco::PFCandidateCollection _finalCandidates
void linkRefinableObjectConvSecondaryKFsToSecondaryKFs(ProtoEGObject &)
verbosityLevel verbosityLevel_
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 setPreshowerEnergyPlane1(double preshowerEnergy1)
std::vector< PFGSFFlaggedElement > primaryGSFs
tuple size
Write out results.
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)
void linkRefinableObjectPrimaryGSFTrackToHCAL(ProtoEGObject &)