28 #include "TMVA/MethodBDT.h"
31 #include "combination.hpp"
37 #define docast(x,y) dynamic_cast<x>(y)
38 #define LOGVERB(x) edm::LogVerbatim(x)
39 #define LOGWARN(x) edm::LogWarning(x)
40 #define LOGERR(x) edm::LogError(x)
41 #define LOGDRESSED(x) edm::LogInfo(x)
43 #define docast(x,y) reinterpret_cast<x>(y)
44 #define LOGVERB(x) LogTrace(x)
45 #define LOGWARN(x) edm::LogWarning(x)
46 #define LOGERR(x) edm::LogError(x)
47 #define LOGDRESSED(x) LogDebug(x)
56 typedef std::pair<CaloClusterPtr::key_type,CaloClusterPtr> EEtoPSElement;
64 typedef std::unary_function<
const ClusterFlaggedElement&,
67 typedef std::unary_function<
const PFFlaggedElement&,
68 bool> PFFlaggedElementMatcher;
69 typedef std::binary_function<
const PFFlaggedElement&,
70 const PFFlaggedElement&,
71 bool> PFFlaggedElementSorter;
74 bool> PFElementMatcher;
79 typedef std::unary_function<PFFlaggedElement&,
80 ClusterFlaggedElement> ClusterElementConverter;
82 struct SumPSEnergy :
public std::binary_function<double,
83 const ClusterFlaggedElement&,
87 double operator()(
double a,
88 const ClusterFlaggedElement&
b) {
90 return a + (_thetype == b.first->type())*b.first->clusterRef()->energy();
94 bool comparePSMapByKey(
const EEtoPSElement&
a,
95 const EEtoPSElement&
b) {
96 return a.first < b.first;
99 struct UsableElementToPSCluster :
public ClusterElementConverter {
100 ClusterFlaggedElement operator () (PFFlaggedElement&
elem) {
101 const ClusterElement* pselemascluster =
102 docast(
const ClusterElement*,elem.first);
105 std::stringstream ps_err;
106 pselemascluster->Dump(ps_err,
"\t");
108 <<
"This element is not a PS cluster!" << std::endl
109 << ps_err.str() << std::endl;
111 if( elem.second ==
false ) {
112 std::stringstream ps_err;
113 pselemascluster->Dump(ps_err,
"\t");
115 <<
"PS Cluster matched to EE is already used! "
116 <<
"This should be impossible!" << std::endl
117 << ps_err.str() << std::endl;
120 return std::make_pair(pselemascluster,
true);
124 struct SeedMatchesToSCElement :
public PFFlaggedElementMatcher {
129 bool operator() (
const PFFlaggedElement&
elem) {
130 const SCElement* scelem =
docast(
const SCElement*,elem.first);
131 if( _scfromseed.isNull() || !elem.second || !scelem)
return false;
132 return ( _scfromseed->seed()->seed() ==
133 scelem->superClusterRef()->seed()->seed() );
137 struct SCSubClusterMatchesToElement :
public PFFlaggedElementMatcher {
143 bool operator() (
const PFFlaggedElement&
elem) {
144 const ClusterElement* cluselem =
145 docast(
const ClusterElement*,elem.first);
146 if( !elem.second || !cluselem)
return false;
148 for( ; cl !=
end; ++
cl ) {
149 if((*cl)->seed() == cluselem->clusterRef()->seed()) {
157 struct SeedMatchesToProtoObject :
public POMatcher {
163 if( _scfromseed.isNonnull() ) {
168 bool operator() (
const PFEGammaAlgo::ProtoEGObject& po) {
169 if( _scfromseed.isNull() || !po.
parentSC )
return false;
171 return ( _scfromseed->seed() ==
174 return ( _scfromseed->seed()->seed() ==
179 template<
bool useConvs=false>
185 const float EoPin_cut = 1.0e6) {
194 &(block->elements()[
key]));
196 const ClusterElement* elemasclus =
197 reinterpret_cast<const ClusterElement*
>(&(block->elements()[
test]));
198 float cluster_e = elemasclus->clusterRef()->correctedEnergy();
199 float trk_pin = elemasgsf->
Pin().P();
200 if( cluster_e / trk_pin > EoPin_cut ) {
202 <<
"GSF track failed EoP cut to match with cluster!";
212 &(block->elements()[
key]));
214 const ClusterElement* elemasclus =
215 reinterpret_cast<const ClusterElement*
>(&(block->elements()[
test]));
216 float cluster_e = elemasclus->clusterRef()->correctedEnergy();
219 if( cluster_e / trk_pin > EoPin_cut ) {
221 <<
"KF track failed EoP cut to match with cluster!";
233 if( dist == -1.0
f )
return false;
234 std::multimap<double, unsigned> dists_to_val;
235 block->associatedElements(test,block->linkData(),dists_to_val,keytype,
237 for(
const auto& valdist : dists_to_val ) {
238 const size_t idx = valdist.second;
245 &(block->elements()[
idx]));
246 if( !useConvs && elemasgsf->
trackType(ConvType) )
return false;
248 const ClusterElement* elemasclus =
249 docast(
const ClusterElement*,&(block->elements()[
test]));
250 float cluster_e = elemasclus->clusterRef()->correctedEnergy();
251 float trk_pin = elemasgsf->
Pin().P();
252 if( cluster_e / trk_pin > EoPin_cut )
continue;
260 &(block->elements()[
idx]));
261 if( !useConvs && elemaskf->
trackType(ConvType) )
return false;
263 const ClusterElement* elemasclus =
264 reinterpret_cast<const ClusterElement*
>(&(block->elements()[
test]));
265 float cluster_e = elemasclus->clusterRef()->correctedEnergy();
268 if( cluster_e / trk_pin > EoPin_cut )
continue;
275 if( valdist.first < dist && idx != key ) {
277 <<
"key element of type " << keytype
278 <<
" is closer to another element of type" << valtype
286 struct CompatibleEoPOut :
public PFFlaggedElementMatcher {
289 bool operator()(
const PFFlaggedElement&
e)
const {
291 const ClusterElement* elemascluster =
292 docast(
const ClusterElement*,e.first);
293 const float gsf_eta_diff =
std::abs(
comp->positionAtECALEntrance().eta()-
296 return ( gsf_eta_diff <= 0.3 && cRef->
energy()/
comp->Pout().t() <= 5 );
300 template<
class TrackElementType>
301 struct IsConversionTrack : PFFlaggedElementMatcher {
302 bool operator()(
const PFFlaggedElement&
e) {
305 const TrackElementType* elemastrk =
306 docast(
const TrackElementType*,e.first);
307 return elemastrk->trackType(ConvType);
314 struct NotCloserToOther :
public PFFlaggedElementMatcher {
315 const reco::PFBlockElement*
comp;
318 const float EoPin_cut;
321 const PFFlaggedElement*
e,
322 const float EoPcut=1.0e6):
comp(e->first),
329 const reco::PFBlockElement* e,
330 const float EoPcut=1.0e6):
comp(e),
335 bool operator () (
const PFFlaggedElement& e) {
336 if( !e.second || valtype != e.first->type() )
return false;
337 return elementNotCloserToOther<useConv>(
block,
338 keytype,
comp->index(),
339 valtype,e.first->index(),
344 struct LesserByDistance :
public PFFlaggedElementSorter {
345 const reco::PFBlockElement*
comp;
350 const PFFlaggedElement*
e):
comp(e->first),
355 const reco::PFBlockElement* e):
comp(e),
358 bool operator () (
const PFFlaggedElement& e1,
359 const PFFlaggedElement& e2) {
360 double dist1 = block->dist(
comp->index(),
364 double dist2 = block->dist(
comp->index(),
368 dist1 = ( dist1 == -1.0 ? 1e6 : dist1 );
369 dist2 = ( dist2 == -1.0 ? 1e6 : dist2 );
370 return dist1 < dist2;
374 bool isROLinkedByClusterOrTrack(
const PFEGammaAlgo::ProtoEGObject& RO1,
375 const PFEGammaAlgo::ProtoEGObject& RO2 ) {
380 <<
"cannot merge, both have GSFs!" << std::endl;
385 if(RO1.
ecalclusters.front().first->clusterRef()->layer() !=
386 RO2.
ecalclusters.front().first->clusterRef()->layer() ) {
388 <<
"cannot merge, different ECAL types!" << std::endl;
398 elementNotCloserToOther(blk,
399 cluster.first->type(),
400 cluster.first->
index(),
401 primgsf.first->type(),
402 primgsf.first->index());
405 <<
"merged by cluster to primary GSF" << std::endl;
409 <<
"cluster to primary GSF failed since"
410 <<
" cluster closer to another GSF" << std::endl;
415 elementNotCloserToOther(blk,
416 cluster.first->type(),
417 cluster.first->
index(),
418 primkf.first->type(),
419 primkf.first->index());
422 <<
"merged by cluster to primary KF" << std::endl;
428 elementNotCloserToOther(blk,
429 cluster.first->type(),
430 cluster.first->
index(),
431 secdkf.first->type(),
432 secdkf.first->index());
435 <<
"merged by cluster to secondary KF" << std::endl;
440 for(
const auto& brem : RO2.
brems ) {
441 not_closer = elementNotCloserToOther(blk,
442 cluster.first->type(),
443 cluster.first->
index(),
445 brem.first->index());
448 <<
"merged by cluster to brem KF" << std::endl;
457 elementNotCloserToOther(blk,
458 primgsf.first->type(),
459 primgsf.first->
index(),
460 secdkf.first->type(),
461 secdkf.first->index());
464 <<
"merged by GSF to secondary KF" << std::endl;
473 elementNotCloserToOther(blk,
474 primkf.first->type(),
475 primkf.first->
index(),
476 secdkf.first->type(),
477 secdkf.first->index());
480 <<
"merged by primary KF to secondary KF" << std::endl;
489 elementNotCloserToOther<true>(blk,
490 secdkf1.first->type(),
491 secdkf1.first->
index(),
492 secdkf2.first->type(),
493 secdkf2.first->index());
496 <<
"merged by secondary KF to secondary KF" << std::endl;
504 struct TestIfROMergableByLink :
public POMatcher {
505 const PFEGammaAlgo::ProtoEGObject&
comp;
506 TestIfROMergableByLink(
const PFEGammaAlgo::ProtoEGObject& RO) :
508 bool operator() (
const PFEGammaAlgo::ProtoEGObject& ro) {
509 const bool result = ( isROLinkedByClusterOrTrack(
comp,ro) ||
510 isROLinkedByClusterOrTrack(ro,
comp) );
515 std::vector<const ClusterElement*>
517 std::vector<PFFlaggedElement>& ecals) {
518 std::vector<const ClusterElement*> cluster_list;
519 auto sccl = scref->clustersBegin();
520 auto scend = scref->clustersEnd();
521 auto pfc = ecals.begin();
522 auto pfcend = ecals.end();
523 for( ; sccl != scend; ++sccl ) {
524 std::vector<const ClusterElement*> matched_pfcs;
525 const double eg_energy = (*sccl)->energy();
527 for( pfc = ecals.begin(); pfc != pfcend; ++pfc ) {
528 const ClusterElement *pfcel =
529 docast(
const ClusterElement*, pfc->first);
534 if( matched && pfcel->clusterRef()->energy() < 1.2*scref->energy()) {
535 matched_pfcs.push_back(pfcel);
538 std::sort(matched_pfcs.begin(),matched_pfcs.end());
540 double min_residual = 1e6;
541 std::vector<const ClusterElement*> best_comb;
542 for(
size_t i = 1;
i <= matched_pfcs.size(); ++
i ) {
547 double energy = std::accumulate(matched_pfcs.begin(),
548 matched_pfcs.begin()+
i,
551 const ClusterElement*
c)
552 {
return a +
c->clusterRef()->energy(); });
553 const double resid =
std::abs(energy - eg_energy);
554 if( resid < min_residual ) {
556 best_comb.reserve(
i);
557 min_residual = resid;
558 best_comb.insert(best_comb.begin(),
559 matched_pfcs.begin(),
560 matched_pfcs.begin()+
i);
563 matched_pfcs.begin()+
i,
564 matched_pfcs.end()));
566 for(
const auto& clelem : best_comb ) {
568 if(
std::find(cluster_list.begin(),cluster_list.end(),clelem) ==
569 cluster_list.end() ) {
570 cluster_list.push_back(clelem);
576 bool addPFClusterToROSafe(
const ClusterElement*
cl,
577 PFEGammaAlgo::ProtoEGObject& RO) {
585 if( clayer == blayer ) {
595 void setROElectronCluster(PFEGammaAlgo::ProtoEGObject& RO) {
602 *kfCluster =
NULL, *gsfCluster_noassc =
NULL;
604 int nBremClusters = 0;
606 float mDist_gsf(maxDist), mDist_gsf_noassc(maxDist), mDist_kf(maxDist);
609 const bool hasclu = elementNotCloserToOther(parent,
612 cluster.first->type(),
613 cluster.first->index());
615 std::abs(cluster.first->clusterRef()->positionREP().eta() -
616 gsf.first->positionAtECALEntrance().eta());
619 cluster.first->clusterRef()->positionREP().phi() -
620 gsf.first->positionAtECALEntrance().phi()));
621 const float dist = std::hypot(deta,dphi);
622 if( hasclu && dist < mDist_gsf ) {
623 gsfCluster = cluster.first;
625 }
else if ( dist < mDist_gsf_noassc ) {
626 gsfCluster_noassc = cluster.first;
627 mDist_gsf_noassc = dist;
631 const bool hasclu = elementNotCloserToOther(parent,
634 cluster.first->type(),
635 cluster.first->index());
636 const float dist = parent->dist(cluster.first->index(),
640 if( hasclu && dist < mDist_kf ) {
641 kfCluster = cluster.first;
645 for(
const auto& brem : RO.
brems ) {
646 const bool hasclu = elementNotCloserToOther(parent,
649 cluster.first->type(),
650 cluster.first->index());
655 brem.first->indTrajPoint() - 2) ) {
656 firstBrem = brem.first;
659 ( lastBrem->indTrajPoint() - 2 <
660 brem.first->indTrajPoint() - 2) ) {
661 lastBrem = brem.first;
662 bremCluster = cluster.first;
667 if( !gsfCluster && !kfCluster && !bremCluster ) {
668 gsfCluster = gsfCluster_noassc;
674 }
else if ( kfCluster ) {
677 if( bremCluster && !gsfCluster && !kfCluster ) {
682 if( bremCluster == gsfCluster ) RO.
lateBrem = 1;
693 chi2(0.0), STIP(0.0), del_phi(0.0),HoverPt(0.0), EoverPt(0.0), track_pt(0.0),
695 CrysPhi_(0.0), CrysEta_(0.0), VtxZ_(0.0), ClusPhi_(0.0), ClusEta_(0.0),
696 ClusR9_(0.0), Clus5x5ratio_(0.0), PFCrysEtaCrack_(0.0), logPFClusE_(0.0), e3x3_(0.0),
697 CrysIPhi_(0), CrysIEta_(0),
698 CrysX_(0.0), CrysY_(0.0),
700 eSeed_(0.0), e1x3_(0.0),e3x1_(0.0), e1x5_(0.0), e2x5Top_(0.0), e2x5Bottom_(0.0), e2x5Left_(0.0), e2x5Right_(0.0),
701 etop_(0.0), ebottom_(0.0), eleft_(0.0), eright_(0.0),
703 PFPhoEta_(0.0), PFPhoPhi_(0.0), PFPhoR9_(0.0), PFPhoR9Corr_(0.0), SCPhiWidth_(0.0), SCEtaWidth_(0.0),
704 PFPhoEt_(0.0), RConv_(0.0), PFPhoEtCorr_(0.0), PFPhoE_(0.0), PFPhoECorr_(0.0), MustE_(0.0), E3x3_(0.0),
705 dEta_(0.0), dPhi_(0.0), LowClusE_(0.0), RMSAll_(0.0), RMSMust_(0.0), nPFClus_(0.0),
706 TotPS1_(0.0), TotPS2_(0.0),
708 x0inner_(0.0), x0middle_(0.0), x0outer_(0.0),
709 excluded_(0.0), Mustache_EtRatio_(0.0), Mustache_Et_out_(0.0)
712 TFile *XO_File =
new TFile(
cfg_.
X0_Map.c_str(),
"READ");
713 X0_sum = (TH2D*)XO_File->Get(
"TrackerSum");
714 X0_inner = (TH2D*)XO_File->Get(
"Inner");
715 X0_middle = (TH2D*)XO_File->Get(
"Middle");
716 X0_outer = (TH2D*)XO_File->Get(
"Outer");
722 std::vector<bool>& active) {
741 unsigned int track_index) {
747 chi2=elements[track_index].trackRef()->chi2()/elements[track_index].trackRef()->ndof();
748 nlost=elements[track_index].trackRef()->hitPattern().numberOfLostHits(HitPattern::MISSING_INNER_HITS);
749 nlayers=elements[track_index].trackRef()->hitPattern().trackerLayersWithMeasurement();
750 track_pt=elements[track_index].trackRef()->pt();
751 STIP=elements[track_index].trackRefPF()->STIP();
755 std::multimap<double, unsigned int> ecalAssoTrack;
760 std::multimap<double, unsigned int> hcalAssoTrack;
765 if(ecalAssoTrack.size() > 0) {
766 for(std::multimap<double, unsigned int>::iterator itecal = ecalAssoTrack.begin();
767 itecal != ecalAssoTrack.end(); ++itecal) {
768 linked_e=linked_e+elements[itecal->second].clusterRef()->energy();
771 if(hcalAssoTrack.size() > 0) {
772 for(std::multimap<double, unsigned int>::iterator ithcal = hcalAssoTrack.begin();
773 ithcal != hcalAssoTrack.end(); ++ithcal) {
774 linked_h=linked_h+elements[ithcal->second].clusterRef()->energy();
777 EoverPt=linked_e/elements[track_index].trackRef()->pt();
778 HoverPt=linked_h/elements[track_index].trackRef()->pt();
779 GlobalVector rvtx(elements[track_index].trackRef()->innerPosition().
X()-primaryvtx.
x(),
780 elements[track_index].trackRef()->innerPosition().Y()-primaryvtx.
y(),
781 elements[track_index].trackRef()->innerPosition().Z()-primaryvtx.
z());
782 double vtx_phi=rvtx.
phi();
784 del_phi=fabs(
deltaPhi(vtx_phi, elements[track_index].trackRef()->innerMomentum().
Phi()));
795 switch( pfbe.
type() ) {
799 std::multimap<double,unsigned> tks;
805 for(
const auto& tk : tks ) {
824 <<
"Resetting PFEGammaAlgo for new block and running!" << std::endl;
834 LOGVERB(
"PFEGammaAlgo") <<
"Splaying block" << std::endl;
837 if(
isAMuon(pfelement) )
continue;
838 const size_t itype = (size_t)pfelement.type();
840 _splayedblock[itype].push_back(std::make_pair(&pfelement,
true));
845 std::stringstream splayout;
846 for(
size_t itype = 0; itype <
_splayedblock.size(); ++itype ) {
847 splayout <<
"\tType: " << itype <<
" indices: ";
849 splayout << flaggedelement.first->index() <<
' ';
851 if( itype !=
_splayedblock.size() - 1 ) splayout << std::endl;
853 LOGVERB(
"PFEGammaAlgo") << splayout.str();
890 <<
"Dumping after GSF and KF Track (Primary) Linking : " << std::endl;
897 <<
"Dumping after first merging operation : " << std::endl;
903 for(
auto& RO : _refinableObjects ) {
914 <<
"Dumping after ECAL to Track (Secondary) Linking : " << std::endl;
921 <<
"There are " << _refinableObjects.size()
922 <<
" after the 2nd merging step." << std::endl;
926 for(
auto& RO : _refinableObjects ) {
933 std::sort(RO.ecalclusters.begin(), RO.ecalclusters.end(),
936 {
return ( a.first->clusterRef()->correctedEnergy() >
937 b.first->clusterRef()->correctedEnergy() ) ; });
938 setROElectronCluster(RO);
942 <<
"There are " << _refinableObjects.size()
943 <<
" after the unlinking and vetos step." << std::endl;
958 <<
"creating SC-based proto-object" << std::endl
959 <<
"\tSC at index: " << element.first->index()
960 <<
" has type: " << element.first->type() << std::endl;
961 element.second =
false;
992 std::list<ProtoEGObject>::iterator objsbegin, objsend;
995 <<
"creating GSF-based proto-object" << std::endl
996 <<
"\tGSF at index: " << element.first->index()
997 <<
" has type: " << element.first->type() << std::endl;
1003 element.second =
false;
1018 std::stringstream gsf_err;
1019 elementAsGSF->
Dump(gsf_err,
"\t");
1021 <<
"Found a GSF track with no seed! This should not happen!"
1022 << std::endl << gsf_err.str() << std::endl;
1026 element.second =
false;
1028 fromGSF.
primaryGSFs.push_back(std::make_pair(elementAsGSF,
true));
1032 brem.first->index(),
1035 if( dist == 0.001
f ) {
1038 fromGSF.
brems.push_back(std::make_pair(eAsBrem,
true));
1041 brem.second =
false;
1051 <<
"GSF-based proto-object is ECAL driven, merging SC-cand"
1058 SeedMatchesToProtoObject sctoseedmatch(fromGSF.
electronSeed);
1062 auto clusmatch = std::find_if(objsbegin,objsend,sctoseedmatch);
1063 if( clusmatch != objsend ) {
1064 fromGSF.
parentSC = clusmatch->parentSC;
1065 fromGSF.
ecalclusters = std::move(clusmatch->ecalclusters);
1066 fromGSF.
ecal2ps = std::move(clusmatch->ecal2ps);
1074 <<
"Encountered the known GSF-SC splitting bug "
1075 <<
" in PFBlockAlgo! We should really fix this!" << std::endl;
1077 std::stringstream gsf_err;
1078 elementAsGSF->
Dump(gsf_err,
"\t");
1080 <<
"Expected SuperCluster from ECAL driven GSF seed "
1081 <<
"was not found in the block!" << std::endl
1082 << gsf_err.str() << std::endl;
1106 std::vector<PFClusterFlaggedElement>& ecalclusters,
1108 ecalclusters.clear();
1111 <<
"Pointer to SC element: 0x"
1112 << std::hex << thesc <<
std::dec << std::endl
1113 <<
"cleared ecalclusters and ecal2ps!" << std::endl;
1116 if( ecalbegin == ecalend ) {
1117 LOGERR(
"PFEGammaAlgo::unwrapSuperCluster()")
1118 <<
"There are no ECAL elements in a block with imported SC!"
1119 <<
" This is a bug we should fix this!"
1127 <<
"SuperCluster pointed to by block element is null!"
1131 <<
"Got a valid super cluster ref! 0x"
1132 << std::hex << scref.
get() <<
std::dec << std::endl;
1133 const size_t nscclusters = scref->clustersSize();
1134 const size_t nscpsclusters = scref->preshowerClustersSize();
1135 size_t npfpsclusters = 0;
1136 size_t npfclusters = 0;
1138 <<
"Precalculated cluster multiplicities: "
1139 << nscclusters <<
' ' << nscpsclusters << std::endl;
1140 NotCloserToOther<reco::PFBlockElement::SC,reco::PFBlockElement::ECAL>
1142 auto firstnotinsc = std::partition(ecalbegin,ecalend,ecalClustersInSC);
1151 if( firstnotinsc == ecalbegin ) {
1152 LOGERR(
"PFEGammaAlgo::unwrapSuperCluster()")
1153 <<
"No associated block elements to SuperCluster!"
1154 <<
" This is a bug we should fix!"
1161 if( is_pf_sc && nscclusters != npfclusters ) {
1162 std::stringstream sc_err;
1163 thesc->
Dump(sc_err,
"\t");
1165 <<
"The number of found ecal elements ("
1166 << nscclusters <<
") in block is not the same as"
1167 <<
" the number of ecal PF clusters reported by the PFSuperCluster"
1168 <<
" itself (" << npfclusters
1169 <<
")! This should not happen!" << std::endl
1170 << sc_err.str() << std::endl;
1172 for(
auto ecalitr = ecalbegin; ecalitr != firstnotinsc; ++ecalitr ) {
1178 if(!is_pf_sc &&
std::find(safePFClusters.begin(),safePFClusters.end(),elemascluster) ==
1179 safePFClusters.end() )
continue;
1182 ecalclusters.push_back(std::make_pair(elemascluster,
true));
1184 ecalitr->second =
false;
1188 auto emplaceresult = ecal2ps.emplace(elemascluster,
1189 ClusterMap::mapped_type());
1190 if( !emplaceresult.second ) {
1191 std::stringstream clus_err;
1192 elemascluster->
Dump(clus_err,
"\t");
1194 <<
"List of pointers to ECAL block elements contains non-unique items!"
1195 <<
" This is very bad!" << std::endl
1196 <<
"cluster ptr = 0x" << std::hex << elemascluster <<
std::dec
1197 << std::endl << clus_err.str() << std::endl;
1199 ClusterMap::mapped_type& eslist = emplaceresult.first->second;
1218 <<
" Unwrapped SC has " << npfclusters <<
" ECAL sub-clusters"
1219 <<
" and " << npfpsclusters <<
" PreShower layers 1 & 2 clusters!"
1227 ClusterMap::mapped_type& eslist) {
1230 EEtoPSElement ecalkey = std::make_pair(clusptr.
key(),clusptr);
1231 auto assc_ps = std::equal_range(
eetops_->cbegin(),
1237 for(
auto pscl = assc_ps.first; pscl != assc_ps.second; ++pscl ) {
1238 if( pscl->second == temp ) {
1239 const ClusterElement* pstemp =
1240 docast(
const ClusterElement*,ps1.first);
1247 for(
auto pscl = assc_ps.first; pscl != assc_ps.second; ++pscl ) {
1248 if( pscl->second == temp ) {
1249 const ClusterElement* pstemp =
1250 docast(
const ClusterElement*,ps2.first);
1255 return eslist.size();
1263 <<
" refinable objects for this block: " << std::endl;
1265 std::stringstream
info;
1266 info <<
"Refinable Object:" << std::endl;
1268 info <<
"\tSuperCluster element attached to object:" << std::endl
1270 ro.parentSC->Dump(info,
"\t");
1273 if( ro.electronSeed.isNonnull() ) {
1274 info <<
"\tGSF element attached to object:" << std::endl;
1275 ro.primaryGSFs.front().first->Dump(info,
"\t");
1277 info <<
"firstBrem : " << ro.firstBrem
1278 <<
" lateBrem : " << ro.lateBrem
1279 <<
" nBrems with cluster : " << ro.nBremsWithClusters
1281 if( ro.electronClusters.size() && ro.electronClusters[0] ) {
1282 info <<
"electron cluster : ";
1283 ro.electronClusters[0]->Dump(info,
"\t");
1286 info <<
" no electron cluster." << std::endl;
1289 if( ro.primaryKFs.size() ) {
1290 info <<
"\tPrimary KF tracks attached to object: " << std::endl;
1291 for(
const auto& kf : ro.primaryKFs ) {
1292 kf.first->Dump(info,
"\t");
1296 if( ro.secondaryKFs.size() ) {
1297 info <<
"\tSecondary KF tracks attached to object: " << std::endl;
1298 for(
const auto& kf : ro.secondaryKFs ) {
1299 kf.first->Dump(info,
"\t");
1303 if( ro.brems.size() ) {
1304 info <<
"\tBrem tangents attached to object: " << std::endl;
1305 for(
const auto& brem : ro.brems ) {
1306 brem.first->Dump(info,
"\t");
1310 if( ro.ecalclusters.size() ) {
1311 info <<
"\tECAL clusters attached to object: " << std::endl;
1312 for(
const auto& clus : ro.ecalclusters ) {
1313 clus.first->Dump(info,
"\t");
1315 if( ro.ecal2ps.find(clus.first) != ro.ecal2ps.end() ) {
1316 for(
const auto& psclus : ro.ecal2ps.at(clus.first) ) {
1317 info <<
"\t\t Attached PS Cluster: ";
1318 psclus.first->Dump(info,
"");
1332 typedef std::multimap<double, unsigned> MatchedMap;
1336 MatchedMap matchedGSFs, matchedECALs;
1337 std::unordered_map<GsfTrackElementPtr,MatchedMap> gsf_ecal_cache;
1339 matchedGSFs.clear();
1344 if( !matchedGSFs.size() ) {
1349 std::partial_sort(ecalbegin,ecalbegin+1,ecalend,closestTrackToECAL);
1352 const float dist =
_currentblock->dist(kftrack.first->index(),
1353 closestECAL.first->index(),
1359 closestECAL.first->index(),
1362 if( dist_sc != -1.0
f) { inSC =
true;
break; }
1365 if( dist != -1.0
f && closestECAL.second ) {
1366 bool gsflinked =
false;
1368 for(
const auto& gsfflag :
_splayedblock[reco::PFBlockElement::GSF]) {
1375 if( !gsf_ecal_cache.count(elemasgsf) ) {
1376 matchedECALs.clear();
1381 gsf_ecal_cache.emplace(elemasgsf,matchedECALs);
1382 MatchedMap().swap(matchedECALs);
1384 const MatchedMap& ecal_matches = gsf_ecal_cache[elemasgsf];
1385 if( ecal_matches.size() ) {
1386 if( ecal_matches.begin()->second == closestECAL.first->index() ) {
1392 if( !gsflinked && !inSC) {
1399 trackref->hitPattern().numberOfLostHits(HitPattern::MISSING_INNER_HITS);
1400 bool fromprimaryvertex =
false;
1404 fromprimaryvertex =
true;
1410 closestECAL.second =
false;
1423 if( ROs.size() < 2 )
return;
1424 bool check_for_merge =
true;
1425 while( check_for_merge ) {
1430 for(
auto it1 = ROs.begin(); it1 != ROs.end(); ++it1 ) {
1431 TestIfROMergableByLink mergeTest(*it1);
1432 auto find_start = it1; ++find_start;
1433 auto has_merge = std::find_if(find_start,ROs.end(),mergeTest);
1434 if( has_merge != ROs.end() && it1 != ROs.begin() ) {
1440 TestIfROMergableByLink mergeTest(thefront);
1441 auto mergestart = ROs.begin(); ++mergestart;
1442 auto nomerge = std::partition(mergestart,ROs.end(),mergeTest);
1443 if( nomerge != mergestart ) {
1444 LOGDRESSED(
"PFEGammaAlgo::mergeROsByAnyLink()")
1446 <<
" to merge by links to the front!" << std::endl;
1447 for(
auto roToMerge = mergestart; roToMerge != nomerge; ++roToMerge) {
1449 roToMerge->ecalclusters.begin(),
1450 roToMerge->ecalclusters.end());
1451 thefront.
ecal2ps.insert(roToMerge->ecal2ps.begin(),
1452 roToMerge->ecal2ps.end());
1454 roToMerge->secondaryKFs.begin(),
1455 roToMerge->secondaryKFs.end());
1458 roToMerge->localMap.begin(),
1459 roToMerge->localMap.end());
1461 if( !thefront.
parentSC && roToMerge->parentSC ) {
1462 thefront.
parentSC = roToMerge->parentSC;
1465 roToMerge->electronSeed.isNonnull() ) {
1468 roToMerge->primaryGSFs.begin(),
1469 roToMerge->primaryGSFs.end());
1471 roToMerge->primaryKFs.begin(),
1472 roToMerge->primaryKFs.end());
1474 roToMerge->brems.begin(),
1475 roToMerge->brems.end());
1478 thefront.
firstBrem = roToMerge->firstBrem;
1479 thefront.
lateBrem = roToMerge->lateBrem;
1481 roToMerge->electronSeed.isNonnull()) {
1482 LOGWARN(
"PFEGammaAlgo::mergeROsByAnyLink")
1483 <<
"Need to implement proper merging of two gsf candidates!"
1487 ROs.erase(mergestart,nomerge);
1489 ROs.push_back(ROs.front());
1492 check_for_merge =
false;
1495 LOGDRESSED(
"PFEGammaAlgo::mergeROsByAnyLink()")
1496 <<
"After merging by links there are: " << ROs.size()
1497 <<
" refinable EGamma objects!" << std::endl;
1515 NotCloserToOther<reco::PFBlockElement::GSF,reco::PFBlockElement::TRACK>
1518 auto notlinked = std::partition(KFbegin,KFend,gsfTrackToKFs);
1520 for(
auto kft = KFbegin; kft != notlinked; ++kft ) {
1527 kft->second =
false;
1528 RO.
primaryKFs.push_back(std::make_pair(elemaskf,
true));
1531 }
else if ( elemaskf->
trackType(convType) ) {
1532 kft->second =
false;
1533 RO.
secondaryKFs.push_back(std::make_pair(elemaskf,
true));
1552 throw cms::Exception(
"PFEGammaAlgo::linkRefinableObjectPrimaryKFsToSecondaryKFs()")
1553 <<
"A KF track from conversion has been assigned as a primary!!"
1556 NotCloserToOther<reco::PFBlockElement::TRACK,reco::PFBlockElement::TRACK,true>
1559 auto notlinked = std::partition(KFbegin,KFend,kfTrackToKFs);
1561 for(
auto kft = KFbegin; kft != notlinked; ++kft ) {
1567 kft->second =
false;
1568 RO.
secondaryKFs.push_back(std::make_pair(elemaskf,
true));
1586 NotCloserToOther<reco::PFBlockElement::GSF,reco::PFBlockElement::ECAL>
1588 CompatibleEoPOut eoverp_test(primgsf.first);
1590 auto notmatched_blk = std::partition(ECALbegin,ECALend,gsfTracksToECALs);
1591 notmatched_blk = std::partition(ECALbegin,notmatched_blk,eoverp_test);
1593 auto notmatched_sc = std::partition(RO.
ecalclusters.begin(),
1596 notmatched_sc = std::partition(RO.
ecalclusters.begin(),
1604 LOGDRESSED(
"PFEGammaAlgo::linkGSFTracktoECAL()")
1605 <<
"Found a cluster already in RO by GSF extrapolation"
1606 <<
" at ECAL surface!" << std::endl
1607 << *elemascluster << std::endl;
1613 for(
auto ecal = ECALbegin;
ecal != notmatched_blk; ++
ecal ) {
1616 LOGDRESSED(
"PFEGammaAlgo::linkGSFTracktoECAL()")
1617 <<
"Found a cluster not already in RO by GSF extrapolation"
1618 <<
" at ECAL surface!" << std::endl
1619 << *elemascluster << std::endl;
1620 if( addPFClusterToROSafe(elemascluster,RO) ) {
1624 ecal->second =
false;
1637 NotCloserToOther<reco::PFBlockElement::GSF,reco::PFBlockElement::HCAL>
1639 CompatibleEoPOut eoverp_test(primgsf.first);
1640 auto notmatched = std::partition(HCALbegin,HCALend,gsfTracksToHCALs);
1641 for(
auto hcal = HCALbegin;
hcal != notmatched; ++
hcal ) {
1645 LOGDRESSED(
"PFEGammaAlgo::linkGSFTracktoECAL()")
1646 <<
"Found an HCAL cluster associated to GSF extrapolation"
1651 hcal->second =
false;
1667 std::vector<PFClusterFlaggedElement>& currentECAL = RO.
ecalclusters;
1670 NotCloserToOther<reco::PFBlockElement::TRACK,reco::PFBlockElement::ECAL>
1672 NotCloserToOther<reco::PFBlockElement::GSF,reco::PFBlockElement::ECAL>
1675 auto notmatched_sc = std::partition(currentECAL.begin(),
1679 notmatched_sc = std::partition(currentECAL.begin(),
1682 for(
auto ecalitr = currentECAL.begin(); ecalitr != notmatched_sc;
1688 LOGDRESSED(
"PFEGammaAlgo::linkKFTracktoECAL()")
1689 <<
"Found a cluster already in RO by KF extrapolation"
1690 <<
" at ECAL surface!" << std::endl
1691 << *elemascluster << std::endl;
1698 auto notmatched_blk = std::partition(ECALbegin,ECALend,kfTrackToECALs);
1700 notmatched_blk = std::partition(ECALbegin,notmatched_blk,kfTrackGSFToECALs);
1701 for(
auto ecalitr = ECALbegin; ecalitr != notmatched_blk; ++ecalitr ) {
1704 if( addPFClusterToROSafe(elemascluster,RO) ) {
1706 ecalitr->second =
false;
1708 LOGDRESSED(
"PFEGammaAlgo::linkKFTracktoECAL()")
1709 <<
"Found a cluster not in RO by KF extrapolation"
1710 <<
" at ECAL surface!" << std::endl
1711 << *elemascluster << std::endl;
1722 if( !RO.
brems.size() )
return;
1725 int lastBremTrajPos = -1;
1726 for(
auto& bremflagged : RO.
brems ) {
1727 bool has_clusters =
false;
1728 TrajPos = (bremflagged.first->indTrajPoint())-2;
1731 NotCloserToOther<reco::PFBlockElement::BREM,reco::PFBlockElement::ECAL>
1736 auto notmatched_rsc = std::partition(RSCBegin,RSCEnd,BremToECALs);
1737 for(
auto ecal = RSCBegin;
ecal != notmatched_rsc; ++
ecal ) {
1739 std::abs(
ecal->first->clusterRef()->positionREP().eta() -
1740 bremflagged.first->positionAtECALEntrance().eta() );
1741 if( deta < 0.015 ) {
1742 has_clusters =
true;
1743 if( lastBremTrajPos == -1 || lastBremTrajPos < TrajPos ) {
1744 lastBremTrajPos = TrajPos;
1746 if( FirstBrem == -1 || TrajPos < FirstBrem ) {
1747 FirstBrem = TrajPos;
1751 <<
"Found a cluster already in SC linked to brem extrapolation"
1752 <<
" at ECAL surface!" << std::endl;
1758 auto notmatched_block = std::partition(ECALbegin,ECALend,BremToECALs);
1759 for(
auto ecal = ECALbegin;
ecal != notmatched_block; ++
ecal ) {
1761 std::abs(
ecal->first->clusterRef()->positionREP().eta() -
1762 bremflagged.first->positionAtECALEntrance().eta() );
1763 if( deta < 0.015 ) {
1764 has_clusters =
true;
1765 if( lastBremTrajPos == -1 || lastBremTrajPos < TrajPos ) {
1766 lastBremTrajPos = TrajPos;
1768 if( FirstBrem == -1 || TrajPos < FirstBrem ) {
1770 FirstBrem = TrajPos;
1775 if( addPFClusterToROSafe(elemasclus,RO) ) {
1780 ecal->second =
false;
1782 <<
"Found a cluster not already associated by brem extrapolation"
1783 <<
" at ECAL surface!" << std::endl;
1797 IsConversionTrack<reco::PFBlockElementTrack> isConvKf;
1802 auto ronotconv = std::partition(BeginROskfs,EndROskfs,isConvKf);
1804 for(
size_t idx = 0;
idx < convkfs_end; ++
idx ) {
1805 const std::vector<PFKFFlaggedElement>& secKFs = RO.
secondaryKFs;
1810 auto notmatched = std::partition(KFbegin,KFend,TracksToTracks);
1811 notmatched = std::partition(KFbegin,notmatched,isConvKf);
1812 for(
auto kf = KFbegin; kf != notmatched; ++kf ) {
1815 RO.
secondaryKFs.push_back( std::make_pair(elemaskf,
true) );
1826 IsConversionTrack<reco::PFBlockElementTrack> isConvKf;
1834 auto notmatchedkf = std::partition(KFbegin,KFend,ECALToTracks);
1835 auto notconvkf = std::partition(KFbegin,notmatchedkf,isConvKf);
1837 for(
auto kf = KFbegin; kf != notconvkf; ++kf ) {
1840 RO.
secondaryKFs.push_back( std::make_pair(elemaskf,
true) );
1846 for(
auto kf = notconvkf; kf != notmatchedkf; ++kf ) {
1849 kf->first->
index());
1853 RO.
secondaryKFs.push_back( std::make_pair(elemaskf,
true) );
1873 auto notmatched = std::partition(ECALbegin,ECALend,TracksToECALwithCut);
1874 for(
auto ecal = ECALbegin;
ecal != notmatched; ++
ecal ) {
1877 if( addPFClusterToROSafe(elemascluster,RO) ) {
1881 ecal->second =
false;
1889 const std::list<PFEGammaAlgo::ProtoEGObject>& ROs,
1896 egcands.reserve(ROs.size());
1897 egxs.reserve(ROs.size());
1899 for(
auto& RO : ROs ) {
1900 if( RO.ecalclusters.size() == 0 &&
1905 if( RO.primaryGSFs.size() || RO.primaryKFs.size() ) {
1910 if( RO.primaryKFs.size() ) {
1911 cand.
setCharge(RO.primaryKFs[0].first->trackRef()->charge());
1913 cand.
setTrackRef(RO.primaryKFs[0].first->trackRef());
1916 if( RO.primaryGSFs.size() ) {
1917 cand.
setCharge(RO.primaryGSFs[0].first->GsftrackRef()->chargeMode());
1930 for(
const auto& bremflagged : RO.brems ) {
1935 for(
const auto&
ecal : RO.ecalclusters ) {
1938 for(
auto& ps : RO.ecal2ps.at(clus) ) {
1944 for(
const auto& secdkf : RO.secondaryKFs ) {
1948 bool no_conv_ref =
true;
1949 for(
const auto& convref : convrefs ) {
1950 if( convref.isNonnull() && convref.isAvailable() ) {
1952 no_conv_ref =
false;
1959 const auto &mvavalmapped = RO.singleLegConversionMvaMap.find(kf);
1962 float mvaval = ( mvavalmapped != RO.singleLegConversionMvaMap.end() ?
1963 mvavalmapped->second :
1980 const double scE = the_sc.
energy();
1984 egDir = egDir.Unit();
1993 RO.primaryGSFs.size() ) {
1997 gref->pzMode(),gref->pMode());
2001 RO.primaryKFs.size() ) {
2011 xtra.
setMVA(ele_mva_value);
2013 egcands.push_back(cand);
2014 egxs.push_back(xtra);
2029 const double Ein_gsf = std::hypot(RefGSF->pMode(),m_el);
2030 double deta_gsfecal = 1e6;
2031 double sigmaEtaEta = 1
e-14;
2032 const double Ene_hcalgsf = std::accumulate(RO.
hcalClusters.begin(),
2037 {
return a +
b.first->clusterRef()->energy(); }
2040 RefKF = RO.
primaryKFs.front().first->trackRef();
2042 const double Eout_gsf = gsfElement->
Pout().t();
2044 double FirstEcalGsfEnergy(0.0), OtherEcalGsfEnergy(0.0), EcalBremEnergy(0.0);
2046 std::vector<const reco::PFCluster*> gsfcluster;
2048 const double cenergy =
ecal.first->clusterRef()->correctedEnergy();
2057 bool hasbrem =
false;
2058 for(
const auto& brem : RO.
brems ) {
2066 EcalBremEnergy += cenergy;
2069 if( hasgsf ) OtherEcalGsfEnergy += cenergy;
2070 if( haskf ) EcalBremEnergy += cenergy;
2071 if( !(hasgsf || haskf) ) OtherEcalGsfEnergy += cenergy;
2078 FirstEcalGsfEnergy = cref->correctedEnergy();
2079 deta_gsfecal = cref->positionREP().eta() - Etaout_gsf;
2080 gsfcluster.push_back(&*cref);
2096 if( FirstEcalGsfEnergy > 0.0 ) {
2100 const float Pt_gsf = RefGSF->ptMode();
2104 const double ptModeErrorGsf = RefGSF->ptModeError();
2105 dPtOverPt_gsf = (ptModeErrorGsf > 0. ? ptModeErrorGsf/Pt_gsf : 1.0);
2106 nhit_gsf = RefGSF->hitPattern().trackerLayersWithMeasurement();
2107 chi2_gsf = RefGSF->normalizedChi2();
2114 nhit_kf = RefKF->hitPattern().trackerLayersWithMeasurement();
2115 chi2_kf = RefKF->normalizedChi2();
2120 const double EcalETot =
2121 (FirstEcalGsfEnergy+OtherEcalGsfEnergy+EcalBremEnergy);
2125 (Ein_gsf - Eout_gsf) );
2131 HOverHE = Ene_hcalgsf/(Ene_hcalgsf + FirstEcalGsfEnergy);
2182 return hoc->
gbrEle_->GetAdaBoostClassifier(vars);
2192 IsConversionTrack<reco::PFBlockElementTrack> isConvKf;
2200 auto notmatchedkf = std::partition(KFbegin,KFend,ECALToTracks);
2201 auto notconvkf = std::partition(KFbegin,notmatchedkf,isConvKf);
2203 for(
auto kf = notconvkf; kf != notmatchedkf; ++kf ) {
2226 std::vector<const reco::PFCluster*> bare_ptrs;
2228 double posX(0), posY(0), posZ(0),
2229 rawSCEnergy(0), corrSCEnergy(0), corrPSEnergy(0),
2230 PS1_clus_sum(0), PS2_clus_sum(0),
2231 ePS1(0), ePS2(0), ps1_energy(0.0), ps2_energy(0.0);
2237 edm::refToPtr<reco::PFClusterCollection>(clus.first->clusterRef());
2238 bare_ptrs.push_back(clusptr.
get());
2240 const double cluseraw = clusptr->energy();
2241 double cluscalibe = clusptr->correctedEnergy();
2243 posX += cluseraw * cluspos.X();
2244 posY += cluseraw * cluspos.Y();
2245 posZ += cluseraw * cluspos.Z();
2248 const auto& psclusters = RO.
ecal2ps.at(clus.first);
2249 PS1_clus_sum = std::accumulate(psclusters.begin(),psclusters.end(),
2251 PS2_clus_sum = std::accumulate(psclusters.begin(),psclusters.end(),
2255 PS1_clus_sum,PS2_clus_sum,
2260 rawSCEnergy += cluseraw;
2261 corrSCEnergy += cluscalibe;
2264 corrPSEnergy += ePS1 + ePS2;
2266 posX /= rawSCEnergy;
2267 posY /= rawSCEnergy;
2268 posZ /= rawSCEnergy;
2274 edm::refToPtr<reco::PFClusterCollection>(RO.
ecalclusters.front().
2275 first->clusterRef());
2283 edm::refToPtr<reco::PFClusterCollection>(clus.first->clusterRef());
2285 auto& hits_and_fractions = clusptr->hitsAndFractions();
2286 for(
auto& hit_and_fraction : hits_and_fractions ) {
2290 const auto& cluspsassociation = RO.
ecal2ps.at(clus.first);
2294 for(
const auto& pscluselem : cluspsassociation ) {
2296 edm::refToPtr<reco::PFClusterCollection>(pscluselem.first->
2307 throw cms::Exception(
"PFECALSuperClusterAlgo::buildSuperCluster")
2308 <<
"Found a PS cluster matched to more than one EE cluster!"
2309 << std::endl << std::hex << psclus.
get() <<
" == "
2310 << found_pscluster->get() <<
std::dec << std::endl;
2332 const double Pin_gsf = RO.
primaryGSFs.front().first->GsftrackRef()->pMode();
2333 const double gsfOuterEta =
2334 RO.
primaryGSFs.front().first->positionAtECALEntrance().Eta();
2335 double tot_ecal= 0.0;
2336 std::vector<double> min_brem_dists;
2337 std::vector<double> closest_brem_eta;
2340 tot_ecal +=
ecal.first->clusterRef()->correctedEnergy();
2343 double min_brem_dist = 5000.0;
2344 double eta = -999.0;
2345 for(
const auto& brem : RO.
brems ) {
2347 ecal.first->index(),
2350 if( dist < min_brem_dist && dist != -1.0
f ) {
2351 min_brem_dist = dist;
2352 eta = brem.first->positionAtECALEntrance().Eta();
2355 min_brem_dists.push_back(min_brem_dist);
2356 closest_brem_eta.push_back(eta);
2364 const float secpin = secd_kf->first->trackRef()->p();
2365 bool remove_this_kf =
false;
2369 const float minbremdist = min_brem_dists[bremidx];
2370 const double ecalenergy =
ecal->first->clusterRef()->correctedEnergy();
2371 const double Epin = ecalenergy/secpin;
2372 const double detaGsf =
2373 std::abs(gsfOuterEta -
ecal->first->clusterRef()->positionREP().Eta());
2374 const double detaBrem =
2375 std::abs(closest_brem_eta[bremidx] -
2376 ecal->first->clusterRef()->positionREP().Eta());
2383 const float tkdist =
_currentblock->dist(secd_kf->first->index(),
2384 ecal->first->index(),
2391 if( Epin > 3 && kf_matched != RO.
localMap.end() &&
2392 tkdist != -1.0f && tkdist < minbremdist &&
2393 detaGsf > 0.05 && detaBrem > 0.015) {
2394 double res_with =
std::abs((tot_ecal-Pin_gsf)/Pin_gsf);
2395 double res_without =
std::abs((tot_ecal-ecalenergy-Pin_gsf)/Pin_gsf);
2396 if(res_without < res_with) {
2398 <<
" REJECTED_RES totenergy " << tot_ecal
2399 <<
" Pin_gsf " << Pin_gsf
2400 <<
" cluster to secondary " << ecalenergy
2401 <<
" res_with " << res_with
2402 <<
" res_without " << res_without << std::endl;
2403 tot_ecal -= ecalenergy;
2404 remove_this_kf =
true;
2410 if( remove_this_kf ) {
2419 bool removeFreeECAL,
2420 bool removeSCEcal) {
2421 std::vector<bool> cluster_in_sc;
2428 bool remove_this_kf =
false;
2429 NotCloserToOther<reco::PFBlockElement::TRACK,reco::PFBlockElement::HCAL>
2433 const float secpin = trkRef->p();
2435 for(
auto ecal = ecal_begin;
ecal != ecal_end; ++
ecal ) {
2436 const double ecalenergy =
ecal->first->clusterRef()->correctedEnergy();
2439 if( cluster_in_sc.size() < clus_idx + 1) {
2443 ecal->first->index(),
2447 cluster_in_sc.push_back(dist != -1.0
f);
2458 if( kf_matched != RO.
localMap.end() ) {
2459 auto hcal_matched = std::partition(hcal_begin,hcal_end,tracksToHCALs);
2460 for(
auto hcalclus = hcal_begin;
2461 hcalclus != hcal_matched;
2465 const double hcalenergy = clusthcal->
clusterRef()->energy();
2466 const double hpluse = ecalenergy+hcalenergy;
2467 const bool isHoHE = ( (hcalenergy / hpluse ) > 0.1 && Algo < 3 );
2468 const bool isHoE = ( hcalenergy > ecalenergy );
2469 const bool isPoHE = ( secpin > hpluse );
2470 if( cluster_in_sc[clus_idx] ) {
2471 if(isHoE || isPoHE) {
2473 <<
"REJECTED TRACK FOR H/E or P/(H+E), CLUSTER IN SC"
2474 <<
" H/H+E " << (hcalenergy / hpluse)
2475 <<
" H/E " << (hcalenergy > ecalenergy)
2476 <<
" P/(H+E) " << (secpin/hpluse)
2477 <<
" HCAL ENE " << hcalenergy
2478 <<
" ECAL ENE " << ecalenergy
2479 <<
" secPIN " << secpin
2480 <<
" Algo Track " << Algo << std::endl;
2481 remove_this_kf =
true;
2486 <<
"REJECTED TRACK FOR H/H+E, CLUSTER NOT IN SC"
2487 <<
" H/H+E " << (hcalenergy / hpluse)
2488 <<
" H/E " << (hcalenergy > ecalenergy)
2489 <<
" P/(H+E) " << (secpin/hpluse)
2490 <<
" HCAL ENE " << hcalenergy
2491 <<
" ECAL ENE " << ecalenergy
2492 <<
" secPIN " << secpin
2493 <<
" Algo Track " << Algo << std::endl;
2494 remove_this_kf =
true;
2500 if( remove_this_kf ) {
2509 unsigned int Algo = 0;
2510 switch (trackRef->algo()) {
2511 case TrackBase::ctf:
2516 case TrackBase::muonSeededStepInOut:
2517 case TrackBase::muonSeededStepOutIn:
2540 bool isPrimary =
false;
2546 PFRecTrackRef kfPfRef_fromGsf = (*gsfPfRef).kfPFRecTrackRef();
2551 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
unsigned int whichTrackAlgo(const reco::TrackRef &trackRef)
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
virtual void setCharge(Charge q)
set electric charge
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
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
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 &)
virtual void setP4(const LorentzVector &p4)
set 4-momentum
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
TrackAlgorithm
track algorithm
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)
tuple detachedTripletStep
std::vector< PFKFFlaggedElement > secondaryKFs
void setEtaWidth(double ew)
void setSigmaEtaEta(float val)
set the sigmaetaeta
void dumpCurrentRefinableObjects() const
void initializeProtoCands(std::list< ProtoEGObject > &)
void linkRefinableObjectPrimaryKFsToSecondaryKFs(ProtoEGObject &)
bool unwrapSuperCluster(const reco::PFBlockElementSuperCluster *, std::vector< PFClusterFlaggedElement > &, ClusterMap &)
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
std::vector< PFBremFlaggedElement > brems
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
Container::value_type value_type
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
tuple jetCoreRegionalStep
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
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< 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
virtual void setPdgId(int pdgId)
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.
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 &)