30 #include "combination.hpp"
36 #define docast(x,y) dynamic_cast<x>(y)
37 #define LOGVERB(x) edm::LogVerbatim(x)
38 #define LOGWARN(x) edm::LogWarning(x)
39 #define LOGERR(x) edm::LogError(x)
40 #define LOGDRESSED(x) edm::LogInfo(x)
42 #define docast(x,y) reinterpret_cast<x>(y)
43 #define LOGVERB(x) LogTrace(x)
44 #define LOGWARN(x) edm::LogWarning(x)
45 #define LOGERR(x) edm::LogError(x)
46 #define LOGDRESSED(x) LogDebug(x)
55 typedef std::pair<CaloClusterPtr::key_type,CaloClusterPtr> EEtoPSElement;
63 typedef std::unary_function<
const ClusterFlaggedElement&,
66 typedef std::unary_function<
const PFFlaggedElement&,
67 bool> PFFlaggedElementMatcher;
68 typedef std::binary_function<
const PFFlaggedElement&,
69 const PFFlaggedElement&,
70 bool> PFFlaggedElementSorter;
73 bool> PFElementMatcher;
78 typedef std::unary_function<PFFlaggedElement&,
79 ClusterFlaggedElement> ClusterElementConverter;
81 struct SumPSEnergy :
public std::binary_function<double,
82 const ClusterFlaggedElement&,
86 double operator()(
double a,
87 const ClusterFlaggedElement&
b) {
89 return a + (_thetype == b.first->type())*b.first->clusterRef()->energy();
93 bool comparePSMapByKey(
const EEtoPSElement&
a,
94 const EEtoPSElement&
b) {
95 return a.first < b.first;
98 struct UsableElementToPSCluster :
public ClusterElementConverter {
99 ClusterFlaggedElement operator () (PFFlaggedElement&
elem) {
100 const ClusterElement* pselemascluster =
101 docast(
const ClusterElement*,elem.first);
104 std::stringstream ps_err;
105 pselemascluster->Dump(ps_err,
"\t");
107 <<
"This element is not a PS cluster!" << std::endl
108 << ps_err.str() << std::endl;
110 if( elem.second ==
false ) {
111 std::stringstream ps_err;
112 pselemascluster->Dump(ps_err,
"\t");
114 <<
"PS Cluster matched to EE is already used! "
115 <<
"This should be impossible!" << std::endl
116 << ps_err.str() << std::endl;
119 return std::make_pair(pselemascluster,
true);
123 struct SeedMatchesToSCElement :
public PFFlaggedElementMatcher {
128 bool operator() (
const PFFlaggedElement&
elem) {
129 const SCElement* scelem =
docast(
const SCElement*,elem.first);
130 if( _scfromseed.isNull() || !elem.second || !scelem)
return false;
131 return ( _scfromseed->seed()->seed() ==
132 scelem->superClusterRef()->seed()->seed() );
136 struct SCSubClusterMatchesToElement :
public PFFlaggedElementMatcher {
142 bool operator() (
const PFFlaggedElement&
elem) {
143 const ClusterElement* cluselem =
144 docast(
const ClusterElement*,elem.first);
145 if( !elem.second || !cluselem)
return false;
147 for( ; cl !=
end; ++
cl ) {
148 if((*cl)->seed() == cluselem->clusterRef()->seed()) {
156 struct SeedMatchesToProtoObject :
public POMatcher {
162 if( _scfromseed.isNonnull() ) {
167 bool operator() (
const PFEGammaAlgo::ProtoEGObject& po) {
168 if( _scfromseed.isNull() || !po.
parentSC )
return false;
170 return ( _scfromseed->seed() ==
173 return ( _scfromseed->seed()->seed() ==
178 template<
bool useConvs=false>
184 const float EoPin_cut = 1.0e6) {
193 &(block->elements()[
key]));
195 const ClusterElement* elemasclus =
196 reinterpret_cast<const ClusterElement*
>(&(block->elements()[
test]));
197 float cluster_e = elemasclus->clusterRef()->correctedEnergy();
198 float trk_pin = elemasgsf->
Pin().P();
199 if( cluster_e / trk_pin > EoPin_cut ) {
201 <<
"GSF track failed EoP cut to match with cluster!";
211 &(block->elements()[
key]));
213 const ClusterElement* elemasclus =
214 reinterpret_cast<const ClusterElement*
>(&(block->elements()[
test]));
215 float cluster_e = elemasclus->clusterRef()->correctedEnergy();
218 if( cluster_e / trk_pin > EoPin_cut ) {
220 <<
"KF track failed EoP cut to match with cluster!";
232 if( dist == -1.0
f )
return false;
233 std::multimap<double, unsigned> dists_to_val;
234 block->associatedElements(test,block->linkData(),dists_to_val,keytype,
236 for(
const auto& valdist : dists_to_val ) {
237 const size_t idx = valdist.second;
244 &(block->elements()[
idx]));
245 if( !useConvs && elemasgsf->
trackType(ConvType) )
return false;
247 const ClusterElement* elemasclus =
248 docast(
const ClusterElement*,&(block->elements()[
test]));
249 float cluster_e = elemasclus->clusterRef()->correctedEnergy();
250 float trk_pin = elemasgsf->
Pin().P();
251 if( cluster_e / trk_pin > EoPin_cut )
continue;
259 &(block->elements()[
idx]));
260 if( !useConvs && elemaskf->
trackType(ConvType) )
return false;
262 const ClusterElement* elemasclus =
263 reinterpret_cast<const ClusterElement*
>(&(block->elements()[
test]));
264 float cluster_e = elemasclus->clusterRef()->correctedEnergy();
267 if( cluster_e / trk_pin > EoPin_cut )
continue;
274 if( valdist.first < dist && idx != key ) {
276 <<
"key element of type " << keytype
277 <<
" is closer to another element of type" << valtype
285 struct CompatibleEoPOut :
public PFFlaggedElementMatcher {
288 bool operator()(
const PFFlaggedElement&
e)
const {
290 const ClusterElement* elemascluster =
291 docast(
const ClusterElement*,e.first);
292 const float gsf_eta_diff =
std::abs(
comp->positionAtECALEntrance().eta()-
295 return ( gsf_eta_diff <= 0.3 && cRef->
energy()/
comp->Pout().t() <= 5 );
299 template<
class TrackElementType>
300 struct IsConversionTrack : PFFlaggedElementMatcher {
301 bool operator()(
const PFFlaggedElement&
e) {
304 const TrackElementType* elemastrk =
305 docast(
const TrackElementType*,e.first);
306 return elemastrk->trackType(ConvType);
313 struct NotCloserToOther :
public PFFlaggedElementMatcher {
314 const reco::PFBlockElement*
comp;
317 const float EoPin_cut;
320 const PFFlaggedElement*
e,
321 const float EoPcut=1.0e6):
comp(e->first),
328 const reco::PFBlockElement* e,
329 const float EoPcut=1.0e6):
comp(e),
334 bool operator () (
const PFFlaggedElement& e) {
335 if( !e.second || valtype != e.first->type() )
return false;
336 return elementNotCloserToOther<useConv>(
block,
337 keytype,
comp->index(),
338 valtype,e.first->index(),
343 struct LesserByDistance :
public PFFlaggedElementSorter {
344 const reco::PFBlockElement*
comp;
349 const PFFlaggedElement*
e):
comp(e->first),
354 const reco::PFBlockElement* e):
comp(e),
357 bool operator () (
const PFFlaggedElement&
e1,
358 const PFFlaggedElement&
e2) {
359 double dist1 = block->dist(
comp->index(),
363 double dist2 = block->dist(
comp->index(),
367 dist1 = ( dist1 == -1.0 ? 1e6 : dist1 );
368 dist2 = ( dist2 == -1.0 ? 1e6 : dist2 );
369 return dist1 < dist2;
373 bool isROLinkedByClusterOrTrack(
const PFEGammaAlgo::ProtoEGObject& RO1,
374 const PFEGammaAlgo::ProtoEGObject& RO2 ) {
379 <<
"cannot merge, both have GSFs!" << std::endl;
384 if(RO1.
ecalclusters.front().first->clusterRef()->layer() !=
385 RO2.
ecalclusters.front().first->clusterRef()->layer() ) {
387 <<
"cannot merge, different ECAL types!" << std::endl;
397 elementNotCloserToOther(blk,
398 cluster.first->type(),
399 cluster.first->
index(),
400 primgsf.first->type(),
401 primgsf.first->index());
404 <<
"merged by cluster to primary GSF" << std::endl;
408 <<
"cluster to primary GSF failed since"
409 <<
" cluster closer to another GSF" << std::endl;
414 elementNotCloserToOther(blk,
415 cluster.first->type(),
416 cluster.first->
index(),
417 primkf.first->type(),
418 primkf.first->index());
421 <<
"merged by cluster to primary KF" << std::endl;
427 elementNotCloserToOther(blk,
428 cluster.first->type(),
429 cluster.first->
index(),
430 secdkf.first->type(),
431 secdkf.first->index());
434 <<
"merged by cluster to secondary KF" << std::endl;
439 for(
const auto& brem : RO2.
brems ) {
440 not_closer = elementNotCloserToOther(blk,
441 cluster.first->type(),
442 cluster.first->
index(),
444 brem.first->index());
447 <<
"merged by cluster to brem KF" << std::endl;
456 elementNotCloserToOther(blk,
457 primgsf.first->type(),
458 primgsf.first->
index(),
459 secdkf.first->type(),
460 secdkf.first->index());
463 <<
"merged by GSF to secondary KF" << std::endl;
472 elementNotCloserToOther(blk,
473 primkf.first->type(),
474 primkf.first->
index(),
475 secdkf.first->type(),
476 secdkf.first->index());
479 <<
"merged by primary KF to secondary KF" << std::endl;
488 elementNotCloserToOther<true>(blk,
489 secdkf1.first->type(),
490 secdkf1.first->
index(),
491 secdkf2.first->type(),
492 secdkf2.first->index());
495 <<
"merged by secondary KF to secondary KF" << std::endl;
503 struct TestIfROMergableByLink :
public POMatcher {
504 const PFEGammaAlgo::ProtoEGObject&
comp;
505 TestIfROMergableByLink(
const PFEGammaAlgo::ProtoEGObject& RO) :
507 bool operator() (
const PFEGammaAlgo::ProtoEGObject& ro) {
508 const bool result = ( isROLinkedByClusterOrTrack(
comp,ro) ||
509 isROLinkedByClusterOrTrack(ro,
comp) );
514 std::vector<const ClusterElement*>
516 std::vector<PFFlaggedElement>& ecals) {
517 std::vector<const ClusterElement*> cluster_list;
518 auto sccl = scref->clustersBegin();
519 auto scend = scref->clustersEnd();
520 auto pfc = ecals.begin();
521 auto pfcend = ecals.end();
522 for( ; sccl != scend; ++sccl ) {
523 std::vector<const ClusterElement*> matched_pfcs;
524 const double eg_energy = (*sccl)->energy();
526 for( pfc = ecals.begin(); pfc != pfcend; ++pfc ) {
527 const ClusterElement *pfcel =
528 docast(
const ClusterElement*, pfc->first);
533 if( matched && pfcel->clusterRef()->energy() < 1.2*scref->energy()) {
534 matched_pfcs.push_back(pfcel);
537 std::sort(matched_pfcs.begin(),matched_pfcs.end());
539 double min_residual = 1e6;
540 std::vector<const ClusterElement*> best_comb;
541 for(
size_t i = 1;
i <= matched_pfcs.size(); ++
i ) {
546 double energy = std::accumulate(matched_pfcs.begin(),
547 matched_pfcs.begin()+
i,
550 const ClusterElement*
c)
551 {
return a +
c->clusterRef()->energy(); });
552 const double resid =
std::abs(energy - eg_energy);
553 if( resid < min_residual ) {
555 best_comb.reserve(
i);
556 min_residual = resid;
557 best_comb.insert(best_comb.begin(),
558 matched_pfcs.begin(),
559 matched_pfcs.begin()+
i);
562 matched_pfcs.begin()+
i,
563 matched_pfcs.end()));
565 for(
const auto& clelem : best_comb ) {
567 if(
std::find(cluster_list.begin(),cluster_list.end(),clelem) ==
568 cluster_list.end() ) {
569 cluster_list.push_back(clelem);
575 bool addPFClusterToROSafe(
const ClusterElement*
cl,
576 PFEGammaAlgo::ProtoEGObject& RO) {
584 if( clayer == blayer ) {
594 void setROElectronCluster(PFEGammaAlgo::ProtoEGObject& RO) {
601 *kfCluster =
NULL, *gsfCluster_noassc =
NULL;
603 int nBremClusters = 0;
605 float mDist_gsf(maxDist), mDist_gsf_noassc(maxDist), mDist_kf(maxDist);
608 const bool hasclu = elementNotCloserToOther(parent,
611 cluster.first->type(),
612 cluster.first->index());
614 std::abs(cluster.first->clusterRef()->positionREP().eta() -
615 gsf.first->positionAtECALEntrance().eta());
618 cluster.first->clusterRef()->positionREP().phi() -
619 gsf.first->positionAtECALEntrance().phi()));
620 const float dist = std::hypot(deta,dphi);
621 if( hasclu && dist < mDist_gsf ) {
622 gsfCluster = cluster.first;
624 }
else if ( dist < mDist_gsf_noassc ) {
625 gsfCluster_noassc = cluster.first;
626 mDist_gsf_noassc = dist;
630 const bool hasclu = elementNotCloserToOther(parent,
633 cluster.first->type(),
634 cluster.first->index());
635 const float dist = parent->dist(cluster.first->index(),
639 if( hasclu && dist < mDist_kf ) {
640 kfCluster = cluster.first;
644 for(
const auto& brem : RO.
brems ) {
645 const bool hasclu = elementNotCloserToOther(parent,
648 cluster.first->type(),
649 cluster.first->index());
654 brem.first->indTrajPoint() - 2) ) {
655 firstBrem = brem.first;
658 ( lastBrem->indTrajPoint() - 2 <
659 brem.first->indTrajPoint() - 2) ) {
660 lastBrem = brem.first;
661 bremCluster = cluster.first;
666 if( !gsfCluster && !kfCluster && !bremCluster ) {
667 gsfCluster = gsfCluster_noassc;
673 }
else if ( kfCluster ) {
676 if( bremCluster && !gsfCluster && !kfCluster ) {
681 if( bremCluster == gsfCluster ) RO.
lateBrem = 1;
691 nlost(0.0), nlayers(0.0),
692 chi2(0.0), STIP(0.0), del_phi(0.0),HoverPt(0.0), EoverPt(0.0), track_pt(0.0),
694 CrysPhi_(0.0), CrysEta_(0.0), VtxZ_(0.0), ClusPhi_(0.0), ClusEta_(0.0),
695 ClusR9_(0.0), Clus5x5ratio_(0.0), PFCrysEtaCrack_(0.0), logPFClusE_(0.0), e3x3_(0.0),
696 CrysIPhi_(0), CrysIEta_(0),
697 CrysX_(0.0), CrysY_(0.0),
699 eSeed_(0.0), e1x3_(0.0),e3x1_(0.0), e1x5_(0.0), e2x5Top_(0.0), e2x5Bottom_(0.0), e2x5Left_(0.0), e2x5Right_(0.0),
700 etop_(0.0), ebottom_(0.0), eleft_(0.0), eright_(0.0),
702 PFPhoEta_(0.0), PFPhoPhi_(0.0), PFPhoR9_(0.0), PFPhoR9Corr_(0.0), SCPhiWidth_(0.0), SCEtaWidth_(0.0),
703 PFPhoEt_(0.0), RConv_(0.0), PFPhoEtCorr_(0.0), PFPhoE_(0.0), PFPhoECorr_(0.0), MustE_(0.0), E3x3_(0.0),
704 dEta_(0.0), dPhi_(0.0), LowClusE_(0.0), RMSAll_(0.0), RMSMust_(0.0), nPFClus_(0.0),
705 TotPS1_(0.0), TotPS2_(0.0),
707 x0inner_(0.0), x0middle_(0.0), x0outer_(0.0),
708 excluded_(0.0), Mustache_EtRatio_(0.0), Mustache_Et_out_(0.0)
747 TFile *XO_File =
new TFile(
cfg_.
X0_Map.c_str(),
"READ");
748 X0_sum = (TH2D*)XO_File->Get(
"TrackerSum");
749 X0_inner = (TH2D*)XO_File->Get(
"Inner");
750 X0_middle = (TH2D*)XO_File->Get(
"Middle");
751 X0_outer = (TH2D*)XO_File->Get(
"Outer");
756 std::vector<bool>& active) {
773 unsigned int track_index) {
779 chi2=elements[track_index].trackRef()->chi2()/elements[track_index].trackRef()->ndof();
780 nlost=elements[track_index].trackRef()->trackerExpectedHitsInner().numberOfLostHits();
781 nlayers=elements[track_index].trackRef()->hitPattern().trackerLayersWithMeasurement();
782 track_pt=elements[track_index].trackRef()->pt();
783 STIP=elements[track_index].trackRefPF()->STIP();
787 std::multimap<double, unsigned int> ecalAssoTrack;
792 std::multimap<double, unsigned int> hcalAssoTrack;
797 if(ecalAssoTrack.size() > 0) {
798 for(std::multimap<double, unsigned int>::iterator itecal = ecalAssoTrack.begin();
799 itecal != ecalAssoTrack.end(); ++itecal) {
800 linked_e=linked_e+elements[itecal->second].clusterRef()->energy();
803 if(hcalAssoTrack.size() > 0) {
804 for(std::multimap<double, unsigned int>::iterator ithcal = hcalAssoTrack.begin();
805 ithcal != hcalAssoTrack.end(); ++ithcal) {
806 linked_h=linked_h+elements[ithcal->second].clusterRef()->energy();
809 EoverPt=linked_e/elements[track_index].trackRef()->pt();
810 HoverPt=linked_h/elements[track_index].trackRef()->pt();
811 GlobalVector rvtx(elements[track_index].trackRef()->innerPosition().
X()-primaryvtx.
x(),
812 elements[track_index].trackRef()->innerPosition().Y()-primaryvtx.
y(),
813 elements[track_index].trackRef()->innerPosition().Z()-primaryvtx.
z());
814 double vtx_phi=rvtx.
phi();
816 del_phi=fabs(
deltaPhi(vtx_phi, elements[track_index].trackRef()->innerMomentum().
Phi()));
823 switch( pfbe.
type() ) {
827 std::multimap<double,unsigned> tks;
833 for(
const auto& tk : tks ) {
851 <<
"Resetting PFEGammaAlgo for new block and running!" << std::endl;
861 LOGVERB(
"PFEGammaAlgo") <<
"Splaying block" << std::endl;
864 if(
isAMuon(pfelement) )
continue;
865 const size_t itype = (size_t)pfelement.type();
867 _splayedblock[itype].push_back(std::make_pair(&pfelement,
true));
872 std::stringstream splayout;
873 for(
size_t itype = 0; itype <
_splayedblock.size(); ++itype ) {
874 splayout <<
"\tType: " << itype <<
" indices: ";
876 splayout << flaggedelement.first->index() <<
' ';
878 if( itype !=
_splayedblock.size() - 1 ) splayout << std::endl;
880 LOGVERB(
"PFEGammaAlgo") << splayout.str();
917 <<
"Dumping after GSF and KF Track (Primary) Linking : " << std::endl;
924 <<
"Dumping after first merging operation : " << std::endl;
930 for(
auto& RO : _refinableObjects ) {
941 <<
"Dumping after ECAL to Track (Secondary) Linking : " << std::endl;
948 <<
"There are " << _refinableObjects.size()
949 <<
" after the 2nd merging step." << std::endl;
953 for(
auto& RO : _refinableObjects ) {
960 std::sort(RO.ecalclusters.begin(), RO.ecalclusters.end(),
963 {
return ( a.first->clusterRef()->correctedEnergy() >
964 b.first->clusterRef()->correctedEnergy() ) ; });
965 setROElectronCluster(RO);
969 <<
"There are " << _refinableObjects.size()
970 <<
" after the unlinking and vetos step." << std::endl;
985 <<
"creating SC-based proto-object" << std::endl
986 <<
"\tSC at index: " << element.first->index()
987 <<
" has type: " << element.first->type() << std::endl;
988 element.second =
false;
1019 std::list<ProtoEGObject>::iterator objsbegin, objsend;
1022 <<
"creating GSF-based proto-object" << std::endl
1023 <<
"\tGSF at index: " << element.first->index()
1024 <<
" has type: " << element.first->type() << std::endl;
1030 element.second =
false;
1045 std::stringstream gsf_err;
1046 elementAsGSF->
Dump(gsf_err,
"\t");
1048 <<
"Found a GSF track with no seed! This should not happen!"
1049 << std::endl << gsf_err.str() << std::endl;
1053 element.second =
false;
1055 fromGSF.
primaryGSFs.push_back(std::make_pair(elementAsGSF,
true));
1059 brem.first->index(),
1062 if( dist == 0.001
f ) {
1065 fromGSF.
brems.push_back(std::make_pair(eAsBrem,
true));
1068 brem.second =
false;
1078 <<
"GSF-based proto-object is ECAL driven, merging SC-cand"
1085 SeedMatchesToProtoObject sctoseedmatch(fromGSF.
electronSeed);
1089 auto clusmatch = std::find_if(objsbegin,objsend,sctoseedmatch);
1090 if( clusmatch != objsend ) {
1091 fromGSF.
parentSC = clusmatch->parentSC;
1092 fromGSF.
ecalclusters = std::move(clusmatch->ecalclusters);
1093 fromGSF.
ecal2ps = std::move(clusmatch->ecal2ps);
1101 <<
"Encountered the known GSF-SC splitting bug "
1102 <<
" in PFBlockAlgo! We should really fix this!" << std::endl;
1104 std::stringstream gsf_err;
1105 elementAsGSF->
Dump(gsf_err,
"\t");
1107 <<
"Expected SuperCluster from ECAL driven GSF seed "
1108 <<
"was not found in the block!" << std::endl
1109 << gsf_err.str() << std::endl;
1133 std::vector<PFClusterFlaggedElement>& ecalclusters,
1135 ecalclusters.clear();
1138 <<
"Pointer to SC element: 0x"
1139 << std::hex << thesc << std::dec << std::endl
1140 <<
"cleared ecalclusters and ecal2ps!" << std::endl;
1143 if( ecalbegin == ecalend ) {
1144 LOGERR(
"PFEGammaAlgo::unwrapSuperCluster()")
1145 <<
"There are no ECAL elements in a block with imported SC!"
1146 <<
" This is a bug we should fix this!"
1154 <<
"SuperCluster pointed to by block element is null!"
1158 <<
"Got a valid super cluster ref! 0x"
1159 << std::hex << scref.
get() << std::dec << std::endl;
1160 const size_t nscclusters = scref->clustersSize();
1161 const size_t nscpsclusters = scref->preshowerClustersSize();
1162 size_t npfpsclusters = 0;
1163 size_t npfclusters = 0;
1165 <<
"Precalculated cluster multiplicities: "
1166 << nscclusters <<
' ' << nscpsclusters << std::endl;
1167 NotCloserToOther<reco::PFBlockElement::SC,reco::PFBlockElement::ECAL>
1169 auto firstnotinsc = std::partition(ecalbegin,ecalend,ecalClustersInSC);
1178 if( firstnotinsc == ecalbegin ) {
1179 LOGERR(
"PFEGammaAlgo::unwrapSuperCluster()")
1180 <<
"No associated block elements to SuperCluster!"
1181 <<
" This is a bug we should fix!"
1185 npfclusters = std::distance(ecalbegin,firstnotinsc);
1188 if( is_pf_sc && nscclusters != npfclusters ) {
1189 std::stringstream sc_err;
1190 thesc->
Dump(sc_err,
"\t");
1192 <<
"The number of found ecal elements ("
1193 << nscclusters <<
") in block is not the same as"
1194 <<
" the number of ecal PF clusters reported by the PFSuperCluster"
1195 <<
" itself (" << npfclusters
1196 <<
")! This should not happen!" << std::endl
1197 << sc_err.str() << std::endl;
1199 for(
auto ecalitr = ecalbegin; ecalitr != firstnotinsc; ++ecalitr ) {
1205 if(!is_pf_sc &&
std::find(safePFClusters.begin(),safePFClusters.end(),elemascluster) ==
1206 safePFClusters.end() )
continue;
1209 ecalclusters.push_back(std::make_pair(elemascluster,
true));
1211 ecalitr->second =
false;
1215 auto emplaceresult = ecal2ps.emplace(elemascluster,
1216 ClusterMap::mapped_type());
1217 if( !emplaceresult.second ) {
1218 std::stringstream clus_err;
1219 elemascluster->
Dump(clus_err,
"\t");
1221 <<
"List of pointers to ECAL block elements contains non-unique items!"
1222 <<
" This is very bad!" << std::endl
1223 <<
"cluster ptr = 0x" << std::hex << elemascluster << std::dec
1224 << std::endl << clus_err.str() << std::endl;
1226 ClusterMap::mapped_type& eslist = emplaceresult.first->second;
1245 <<
" Unwrapped SC has " << npfclusters <<
" ECAL sub-clusters"
1246 <<
" and " << npfpsclusters <<
" PreShower layers 1 & 2 clusters!"
1254 ClusterMap::mapped_type& eslist) {
1257 EEtoPSElement ecalkey = std::make_pair(clusptr.
key(),clusptr);
1258 auto assc_ps = std::equal_range(
eetops_->cbegin(),
1264 for(
auto pscl = assc_ps.first; pscl != assc_ps.second; ++pscl ) {
1265 if( pscl->second == temp ) {
1266 const ClusterElement* pstemp =
1267 docast(
const ClusterElement*,ps1.first);
1274 for(
auto pscl = assc_ps.first; pscl != assc_ps.second; ++pscl ) {
1275 if( pscl->second == temp ) {
1276 const ClusterElement* pstemp =
1277 docast(
const ClusterElement*,ps2.first);
1282 return eslist.size();
1290 <<
" refinable objects for this block: " << std::endl;
1292 std::stringstream
info;
1293 info <<
"Refinable Object:" << std::endl;
1295 info <<
"\tSuperCluster element attached to object:" << std::endl
1297 ro.parentSC->Dump(info,
"\t");
1300 if( ro.electronSeed.isNonnull() ) {
1301 info <<
"\tGSF element attached to object:" << std::endl;
1302 ro.primaryGSFs.front().first->Dump(info,
"\t");
1304 info <<
"firstBrem : " << ro.firstBrem
1305 <<
" lateBrem : " << ro.lateBrem
1306 <<
" nBrems with cluster : " << ro.nBremsWithClusters
1308 if( ro.electronClusters.size() && ro.electronClusters[0] ) {
1309 info <<
"electron cluster : ";
1310 ro.electronClusters[0]->Dump(info,
"\t");
1313 info <<
" no electron cluster." << std::endl;
1316 if( ro.primaryKFs.size() ) {
1317 info <<
"\tPrimary KF tracks attached to object: " << std::endl;
1318 for(
const auto& kf : ro.primaryKFs ) {
1319 kf.first->Dump(info,
"\t");
1323 if( ro.secondaryKFs.size() ) {
1324 info <<
"\tSecondary KF tracks attached to object: " << std::endl;
1325 for(
const auto& kf : ro.secondaryKFs ) {
1326 kf.first->Dump(info,
"\t");
1330 if( ro.brems.size() ) {
1331 info <<
"\tBrem tangents attached to object: " << std::endl;
1332 for(
const auto& brem : ro.brems ) {
1333 brem.first->Dump(info,
"\t");
1337 if( ro.ecalclusters.size() ) {
1338 info <<
"\tECAL clusters attached to object: " << std::endl;
1339 for(
const auto& clus : ro.ecalclusters ) {
1340 clus.first->Dump(info,
"\t");
1342 if( ro.ecal2ps.find(clus.first) != ro.ecal2ps.end() ) {
1343 for(
const auto& psclus : ro.ecal2ps.at(clus.first) ) {
1344 info <<
"\t\t Attached PS Cluster: ";
1345 psclus.first->Dump(info,
"");
1361 std::multimap<double, unsigned> matchedGSFs, matchedECALs;
1363 matchedGSFs.clear();
1368 if( !matchedGSFs.size() ) {
1373 std::partial_sort(ecalbegin,ecalbegin+1,ecalend,closestTrackToECAL);
1376 const float dist =
_currentblock->dist(kftrack.first->index(),
1377 closestECAL.first->index(),
1383 closestECAL.first->index(),
1386 if( dist_sc != -1.0
f) { inSC =
true;
break; }
1389 if( dist != -1.0
f && closestECAL.second ) {
1390 bool gsflinked =
false;
1392 for(
const auto& gsfflag :
_splayedblock[reco::PFBlockElement::GSF]) {
1398 matchedECALs.clear();
1403 if( matchedECALs.size() ) {
1404 if( matchedECALs.begin()->second == closestECAL.first->index() ) {
1410 if( !gsflinked && !inSC) {
1415 const unsigned Algo = trackref->algo();
1417 trackref->trackerExpectedHitsInner().numberOfLostHits();
1418 bool fromprimaryvertex =
false;
1422 fromprimaryvertex =
true;
1427 if( Algo < 9 && nexhits == 0 && fromprimaryvertex ) {
1428 closestECAL.second =
false;
1441 if( ROs.size() < 2 )
return;
1442 bool check_for_merge =
true;
1443 while( check_for_merge ) {
1448 for(
auto it1 = ROs.begin(); it1 != ROs.end(); ++it1 ) {
1449 TestIfROMergableByLink mergeTest(*it1);
1450 auto find_start = it1; ++find_start;
1451 auto has_merge = std::find_if(find_start,ROs.end(),mergeTest);
1452 if( has_merge != ROs.end() && it1 != ROs.begin() ) {
1458 TestIfROMergableByLink mergeTest(thefront);
1459 auto mergestart = ROs.begin(); ++mergestart;
1460 auto nomerge = std::partition(mergestart,ROs.end(),mergeTest);
1461 if( nomerge != mergestart ) {
1462 LOGDRESSED(
"PFEGammaAlgo::mergeROsByAnyLink()")
1463 <<
"Found objects " << std::distance(mergestart,nomerge)
1464 <<
" to merge by links to the front!" << std::endl;
1465 for(
auto roToMerge = mergestart; roToMerge != nomerge; ++roToMerge) {
1467 roToMerge->ecalclusters.begin(),
1468 roToMerge->ecalclusters.end());
1469 thefront.
ecal2ps.insert(roToMerge->ecal2ps.begin(),
1470 roToMerge->ecal2ps.end());
1472 roToMerge->secondaryKFs.begin(),
1473 roToMerge->secondaryKFs.end());
1476 roToMerge->localMap.begin(),
1477 roToMerge->localMap.end());
1479 if( !thefront.
parentSC && roToMerge->parentSC ) {
1480 thefront.
parentSC = roToMerge->parentSC;
1483 roToMerge->electronSeed.isNonnull() ) {
1486 roToMerge->primaryGSFs.begin(),
1487 roToMerge->primaryGSFs.end());
1489 roToMerge->primaryKFs.begin(),
1490 roToMerge->primaryKFs.end());
1492 roToMerge->brems.begin(),
1493 roToMerge->brems.end());
1496 thefront.
firstBrem = roToMerge->firstBrem;
1497 thefront.
lateBrem = roToMerge->lateBrem;
1499 roToMerge->electronSeed.isNonnull()) {
1500 LOGWARN(
"PFEGammaAlgo::mergeROsByAnyLink")
1501 <<
"Need to implement proper merging of two gsf candidates!"
1505 ROs.erase(mergestart,nomerge);
1507 ROs.push_back(ROs.front());
1510 check_for_merge =
false;
1513 LOGDRESSED(
"PFEGammaAlgo::mergeROsByAnyLink()")
1514 <<
"After merging by links there are: " << ROs.size()
1515 <<
" refinable EGamma objects!" << std::endl;
1533 NotCloserToOther<reco::PFBlockElement::GSF,reco::PFBlockElement::TRACK>
1536 auto notlinked = std::partition(KFbegin,KFend,gsfTrackToKFs);
1538 for(
auto kft = KFbegin; kft != notlinked; ++kft ) {
1545 kft->second =
false;
1546 RO.
primaryKFs.push_back(std::make_pair(elemaskf,
true));
1549 }
else if ( elemaskf->
trackType(convType) ) {
1550 kft->second =
false;
1551 RO.
secondaryKFs.push_back(std::make_pair(elemaskf,
true));
1570 throw cms::Exception(
"PFEGammaAlgo::linkRefinableObjectPrimaryKFsToSecondaryKFs()")
1571 <<
"A KF track from conversion has been assigned as a primary!!"
1574 NotCloserToOther<reco::PFBlockElement::TRACK,reco::PFBlockElement::TRACK,true>
1577 auto notlinked = std::partition(KFbegin,KFend,kfTrackToKFs);
1579 for(
auto kft = KFbegin; kft != notlinked; ++kft ) {
1585 kft->second =
false;
1586 RO.
secondaryKFs.push_back(std::make_pair(elemaskf,
true));
1604 NotCloserToOther<reco::PFBlockElement::GSF,reco::PFBlockElement::ECAL>
1606 CompatibleEoPOut eoverp_test(primgsf.first);
1608 auto notmatched_blk = std::partition(ECALbegin,ECALend,gsfTracksToECALs);
1609 notmatched_blk = std::partition(ECALbegin,notmatched_blk,eoverp_test);
1611 auto notmatched_sc = std::partition(RO.
ecalclusters.begin(),
1614 notmatched_sc = std::partition(RO.
ecalclusters.begin(),
1622 LOGDRESSED(
"PFEGammaAlgo::linkGSFTracktoECAL()")
1623 <<
"Found a cluster already in RO by GSF extrapolation"
1624 <<
" at ECAL surface!" << std::endl
1625 << *elemascluster << std::endl;
1631 for(
auto ecal = ECALbegin;
ecal != notmatched_blk; ++
ecal ) {
1634 LOGDRESSED(
"PFEGammaAlgo::linkGSFTracktoECAL()")
1635 <<
"Found a cluster not already in RO by GSF extrapolation"
1636 <<
" at ECAL surface!" << std::endl
1637 << *elemascluster << std::endl;
1638 if( addPFClusterToROSafe(elemascluster,RO) ) {
1642 ecal->second =
false;
1655 NotCloserToOther<reco::PFBlockElement::GSF,reco::PFBlockElement::HCAL>
1657 CompatibleEoPOut eoverp_test(primgsf.first);
1658 auto notmatched = std::partition(HCALbegin,HCALend,gsfTracksToHCALs);
1659 for(
auto hcal = HCALbegin;
hcal != notmatched; ++
hcal ) {
1663 LOGDRESSED(
"PFEGammaAlgo::linkGSFTracktoECAL()")
1664 <<
"Found an HCAL cluster associated to GSF extrapolation"
1669 hcal->second =
false;
1685 std::vector<PFClusterFlaggedElement>& currentECAL = RO.
ecalclusters;
1688 NotCloserToOther<reco::PFBlockElement::TRACK,reco::PFBlockElement::ECAL>
1690 NotCloserToOther<reco::PFBlockElement::GSF,reco::PFBlockElement::ECAL>
1693 auto notmatched_sc = std::partition(currentECAL.begin(),
1697 notmatched_sc = std::partition(currentECAL.begin(),
1700 for(
auto ecalitr = currentECAL.begin(); ecalitr != notmatched_sc;
1706 LOGDRESSED(
"PFEGammaAlgo::linkKFTracktoECAL()")
1707 <<
"Found a cluster already in RO by KF extrapolation"
1708 <<
" at ECAL surface!" << std::endl
1709 << *elemascluster << std::endl;
1716 auto notmatched_blk = std::partition(ECALbegin,ECALend,kfTrackToECALs);
1718 notmatched_blk = std::partition(ECALbegin,notmatched_blk,kfTrackGSFToECALs);
1719 for(
auto ecalitr = ECALbegin; ecalitr != notmatched_blk; ++ecalitr ) {
1722 if( addPFClusterToROSafe(elemascluster,RO) ) {
1724 ecalitr->second =
false;
1726 LOGDRESSED(
"PFEGammaAlgo::linkKFTracktoECAL()")
1727 <<
"Found a cluster not in RO by KF extrapolation"
1728 <<
" at ECAL surface!" << std::endl
1729 << *elemascluster << std::endl;
1740 if( !RO.
brems.size() )
return;
1743 int lastBremTrajPos = -1;
1744 for(
auto& bremflagged : RO.
brems ) {
1745 bool has_clusters =
false;
1746 TrajPos = (bremflagged.first->indTrajPoint())-2;
1749 NotCloserToOther<reco::PFBlockElement::BREM,reco::PFBlockElement::ECAL>
1754 auto notmatched_rsc = std::partition(RSCBegin,RSCEnd,BremToECALs);
1755 for(
auto ecal = RSCBegin;
ecal != notmatched_rsc; ++
ecal ) {
1757 std::abs(
ecal->first->clusterRef()->positionREP().eta() -
1758 bremflagged.first->positionAtECALEntrance().eta() );
1759 if( deta < 0.015 ) {
1760 has_clusters =
true;
1761 if( lastBremTrajPos == -1 || lastBremTrajPos < TrajPos ) {
1762 lastBremTrajPos = TrajPos;
1764 if( FirstBrem == -1 || TrajPos < FirstBrem ) {
1765 FirstBrem = TrajPos;
1769 <<
"Found a cluster already in SC linked to brem extrapolation"
1770 <<
" at ECAL surface!" << std::endl;
1776 auto notmatched_block = std::partition(ECALbegin,ECALend,BremToECALs);
1777 for(
auto ecal = ECALbegin;
ecal != notmatched_block; ++
ecal ) {
1779 std::abs(
ecal->first->clusterRef()->positionREP().eta() -
1780 bremflagged.first->positionAtECALEntrance().eta() );
1781 if( deta < 0.015 ) {
1782 has_clusters =
true;
1783 if( lastBremTrajPos == -1 || lastBremTrajPos < TrajPos ) {
1784 lastBremTrajPos = TrajPos;
1786 if( FirstBrem == -1 || TrajPos < FirstBrem ) {
1788 FirstBrem = TrajPos;
1793 if( addPFClusterToROSafe(elemasclus,RO) ) {
1798 ecal->second =
false;
1800 <<
"Found a cluster not already associated by brem extrapolation"
1801 <<
" at ECAL surface!" << std::endl;
1815 IsConversionTrack<reco::PFBlockElementTrack> isConvKf;
1820 auto ronotconv = std::partition(BeginROskfs,EndROskfs,isConvKf);
1821 size_t convkfs_end = std::distance(BeginROskfs,ronotconv);
1822 for(
size_t idx = 0;
idx < convkfs_end; ++
idx ) {
1828 auto notmatched = std::partition(KFbegin,KFend,TracksToTracks);
1829 notmatched = std::partition(KFbegin,notmatched,isConvKf);
1830 for(
auto kf = KFbegin; kf != notmatched; ++kf ) {
1833 RO.
secondaryKFs.push_back( std::make_pair(elemaskf,
true) );
1843 IsConversionTrack<reco::PFBlockElementTrack> isConvKf;
1851 auto notmatchedkf = std::partition(KFbegin,KFend,ECALToTracks);
1852 auto notconvkf = std::partition(KFbegin,notmatchedkf,isConvKf);
1854 for(
auto kf = KFbegin; kf != notconvkf; ++kf ) {
1857 RO.
secondaryKFs.push_back( std::make_pair(elemaskf,
true) );
1863 for(
auto kf = notconvkf; kf != notmatchedkf; ++kf ) {
1865 kf->first->
index());
1869 RO.
secondaryKFs.push_back( std::make_pair(elemaskf,
true) );
1889 auto notmatched = std::partition(ECALbegin,ECALend,TracksToECALwithCut);
1890 for(
auto ecal = ECALbegin;
ecal != notmatched; ++
ecal ) {
1893 if( addPFClusterToROSafe(elemascluster,RO) ) {
1897 ecal->second =
false;
1911 egcands.reserve(ROs.size());
1912 egxs.reserve(ROs.size());
1914 for(
auto& RO : ROs ) {
1915 if( RO.ecalclusters.size() == 0 &&
1920 if( RO.primaryGSFs.size() || RO.primaryKFs.size() ) {
1925 if( RO.primaryKFs.size() ) {
1926 cand.
setCharge(RO.primaryKFs[0].first->trackRef()->charge());
1928 cand.
setTrackRef(RO.primaryKFs[0].first->trackRef());
1931 if( RO.primaryGSFs.size() ) {
1932 cand.
setCharge(RO.primaryGSFs[0].first->GsftrackRef()->chargeMode());
1945 for(
const auto& bremflagged : RO.brems ) {
1950 for(
const auto&
ecal : RO.ecalclusters ) {
1953 for(
auto& ps : RO.ecal2ps.at(clus) ) {
1959 for(
const auto& secdkf : RO.secondaryKFs ) {
1963 bool no_conv_ref =
true;
1964 for(
const auto& convref : convrefs ) {
1965 if( convref.isNonnull() && convref.isAvailable() ) {
1967 no_conv_ref =
false;
1974 const auto &mvavalmapped = RO.singleLegConversionMvaMap.find(kf);
1992 const double scE = the_sc.
energy();
1996 egDir = egDir.Unit();
2005 RO.primaryGSFs.size() ) {
2009 gref->pzMode(),gref->pMode());
2013 RO.primaryKFs.size() ) {
2023 xtra.
setMVA(ele_mva_value);
2025 egcands.push_back(cand);
2026 egxs.push_back(xtra);
2040 const double Ein_gsf = std::hypot(RefGSF->pMode(),m_el);
2041 double deta_gsfecal = 1e6;
2042 double sigmaEtaEta = 1
e-14;
2043 const double Ene_hcalgsf = std::accumulate(RO.
hcalClusters.begin(),
2048 {
return a +
b.first->clusterRef()->energy(); }
2051 RefKF = RO.
primaryKFs.front().first->trackRef();
2053 const double Eout_gsf = gsfElement->
Pout().t();
2055 double FirstEcalGsfEnergy(0.0), OtherEcalGsfEnergy(0.0), EcalBremEnergy(0.0);
2057 std::vector<const reco::PFCluster*> gsfcluster;
2059 const double cenergy =
ecal.first->clusterRef()->correctedEnergy();
2068 bool hasbrem =
false;
2069 for(
const auto& brem : RO.
brems ) {
2077 EcalBremEnergy += cenergy;
2080 if( hasgsf ) OtherEcalGsfEnergy += cenergy;
2081 if( haskf ) EcalBremEnergy += cenergy;
2082 if( !(hasgsf || haskf) ) OtherEcalGsfEnergy += cenergy;
2089 FirstEcalGsfEnergy = cref->correctedEnergy();
2090 deta_gsfecal = cref->positionREP().eta() - Etaout_gsf;
2091 gsfcluster.push_back(&*cref);
2107 if( FirstEcalGsfEnergy > 0.0 ) {
2111 const float Pt_gsf = RefGSF->ptMode();
2115 const double ptModeErrorGsf = RefGSF->ptModeError();
2116 dPtOverPt_gsf = (ptModeErrorGsf > 0. ? ptModeErrorGsf/Pt_gsf : 1.0);
2117 nhit_gsf = RefGSF->hitPattern().trackerLayersWithMeasurement();
2118 chi2_gsf = RefGSF->normalizedChi2();
2125 nhit_kf = RefKF->hitPattern().trackerLayersWithMeasurement();
2126 chi2_kf = RefKF->normalizedChi2();
2131 const double EcalETot =
2132 (FirstEcalGsfEnergy+OtherEcalGsfEnergy+EcalBremEnergy);
2136 (Ein_gsf - Eout_gsf) );
2142 HOverHE = Ene_hcalgsf/(Ene_hcalgsf + FirstEcalGsfEnergy);
2199 IsConversionTrack<reco::PFBlockElementTrack> isConvKf;
2207 auto notmatchedkf = std::partition(KFbegin,KFend,ECALToTracks);
2208 auto notconvkf = std::partition(KFbegin,notmatchedkf,isConvKf);
2210 for(
auto kf = notconvkf; kf != notmatchedkf; ++kf ) {
2233 std::vector<const reco::PFCluster*> bare_ptrs;
2235 double posX(0), posY(0), posZ(0),
2236 rawSCEnergy(0), corrSCEnergy(0), corrPSEnergy(0),
2237 PS1_clus_sum(0), PS2_clus_sum(0),
2238 ePS1(0), ePS2(0), ps1_energy(0.0), ps2_energy(0.0);
2244 edm::refToPtr<reco::PFClusterCollection>(clus.first->clusterRef());
2245 bare_ptrs.push_back(clusptr.
get());
2247 const double cluseraw = clusptr->energy();
2248 double cluscalibe = clusptr->correctedEnergy();
2250 posX += cluseraw * cluspos.X();
2251 posY += cluseraw * cluspos.Y();
2252 posZ += cluseraw * cluspos.Z();
2255 const auto& psclusters = RO.
ecal2ps.at(clus.first);
2256 PS1_clus_sum = std::accumulate(psclusters.begin(),psclusters.end(),
2258 PS2_clus_sum = std::accumulate(psclusters.begin(),psclusters.end(),
2262 PS1_clus_sum,PS2_clus_sum,
2267 rawSCEnergy += cluseraw;
2268 corrSCEnergy += cluscalibe;
2271 corrPSEnergy += ePS1 + ePS2;
2273 posX /= rawSCEnergy;
2274 posY /= rawSCEnergy;
2275 posZ /= rawSCEnergy;
2281 edm::refToPtr<reco::PFClusterCollection>(RO.
ecalclusters.front().
2282 first->clusterRef());
2290 edm::refToPtr<reco::PFClusterCollection>(clus.first->clusterRef());
2292 auto& hits_and_fractions = clusptr->hitsAndFractions();
2293 for(
auto& hit_and_fraction : hits_and_fractions ) {
2297 const auto& cluspsassociation = RO.
ecal2ps.at(clus.first);
2301 for(
const auto& pscluselem : cluspsassociation ) {
2303 edm::refToPtr<reco::PFClusterCollection>(pscluselem.first->
2314 throw cms::Exception(
"PFECALSuperClusterAlgo::buildSuperCluster")
2315 <<
"Found a PS cluster matched to more than one EE cluster!"
2316 << std::endl << std::hex << psclus.
get() <<
" == "
2317 << found_pscluster->get() << std::dec << std::endl;
2339 const double Pin_gsf = RO.
primaryGSFs.front().first->GsftrackRef()->pMode();
2340 const double gsfOuterEta =
2341 RO.
primaryGSFs.front().first->positionAtECALEntrance().Eta();
2342 double tot_ecal= 0.0;
2343 std::vector<double> min_brem_dists;
2344 std::vector<double> closest_brem_eta;
2347 tot_ecal +=
ecal.first->clusterRef()->correctedEnergy();
2350 double min_brem_dist = 5000.0;
2351 double eta = -999.0;
2352 for(
const auto& brem : RO.
brems ) {
2354 ecal.first->index(),
2357 if( dist < min_brem_dist && dist != -1.0
f ) {
2358 min_brem_dist = dist;
2359 eta = brem.first->positionAtECALEntrance().Eta();
2362 min_brem_dists.push_back(min_brem_dist);
2363 closest_brem_eta.push_back(eta);
2371 const float secpin = secd_kf->first->trackRef()->p();
2372 bool remove_this_kf =
false;
2376 const float minbremdist = min_brem_dists[bremidx];
2377 const double ecalenergy =
ecal->first->clusterRef()->correctedEnergy();
2378 const double Epin = ecalenergy/secpin;
2379 const double detaGsf =
2380 std::abs(gsfOuterEta -
ecal->first->clusterRef()->positionREP().Eta());
2381 const double detaBrem =
2382 std::abs(closest_brem_eta[bremidx] -
2383 ecal->first->clusterRef()->positionREP().Eta());
2390 const float tkdist =
_currentblock->dist(secd_kf->first->index(),
2391 ecal->first->index(),
2398 if( Epin > 3 && kf_matched != RO.
localMap.end() &&
2399 tkdist != -1.0f && tkdist < minbremdist &&
2400 detaGsf > 0.05 && detaBrem > 0.015) {
2401 double res_with =
std::abs((tot_ecal-Pin_gsf)/Pin_gsf);
2402 double res_without =
std::abs((tot_ecal-ecalenergy-Pin_gsf)/Pin_gsf);
2403 if(res_without < res_with) {
2405 <<
" REJECTED_RES totenergy " << tot_ecal
2406 <<
" Pin_gsf " << Pin_gsf
2407 <<
" cluster to secondary " << ecalenergy
2408 <<
" res_with " << res_with
2409 <<
" res_without " << res_without << std::endl;
2410 tot_ecal -= ecalenergy;
2411 remove_this_kf =
true;
2417 if( remove_this_kf ) {
2426 bool removeFreeECAL,
2427 bool removeSCEcal) {
2428 std::vector<bool> cluster_in_sc;
2435 bool remove_this_kf =
false;
2436 NotCloserToOther<reco::PFBlockElement::TRACK,reco::PFBlockElement::HCAL>
2440 const float secpin = trkRef->p();
2442 for(
auto ecal = ecal_begin;
ecal != ecal_end; ++
ecal ) {
2443 const double ecalenergy =
ecal->first->clusterRef()->correctedEnergy();
2445 const size_t clus_idx = std::distance(ecal_begin,
ecal);
2446 if( cluster_in_sc.size() < clus_idx + 1) {
2450 ecal->first->index(),
2454 cluster_in_sc.push_back(dist != -1.0
f);
2465 if( kf_matched != RO.
localMap.end() ) {
2466 auto hcal_matched = std::partition(hcal_begin,hcal_end,tracksToHCALs);
2467 for(
auto hcalclus = hcal_begin;
2468 hcalclus != hcal_matched;
2472 const double hcalenergy = clusthcal->
clusterRef()->energy();
2473 const double hpluse = ecalenergy+hcalenergy;
2474 const bool isHoHE = ( (hcalenergy / hpluse ) > 0.1 && Algo < 3 );
2475 const bool isHoE = ( hcalenergy > ecalenergy );
2476 const bool isPoHE = ( secpin > hpluse );
2477 if( cluster_in_sc[clus_idx] ) {
2478 if(isHoE || isPoHE) {
2480 <<
"REJECTED TRACK FOR H/E or P/(H+E), CLUSTER IN SC"
2481 <<
" H/H+E " << (hcalenergy / hpluse)
2482 <<
" H/E " << (hcalenergy > ecalenergy)
2483 <<
" P/(H+E) " << (secpin/hpluse)
2484 <<
" HCAL ENE " << hcalenergy
2485 <<
" ECAL ENE " << ecalenergy
2486 <<
" secPIN " << secpin
2487 <<
" Algo Track " << Algo << std::endl;
2488 remove_this_kf =
true;
2493 <<
"REJECTED TRACK FOR H/H+E, CLUSTER NOT IN SC"
2494 <<
" H/H+E " << (hcalenergy / hpluse)
2495 <<
" H/E " << (hcalenergy > ecalenergy)
2496 <<
" P/(H+E) " << (secpin/hpluse)
2497 <<
" HCAL ENE " << hcalenergy
2498 <<
" ECAL ENE " << ecalenergy
2499 <<
" secPIN " << secpin
2500 <<
" Algo Track " << Algo << std::endl;
2501 remove_this_kf =
true;
2507 if( remove_this_kf ) {
2516 unsigned int Algo = 0;
2517 switch (trackRef->algo()) {
2518 case TrackBase::ctf:
2519 case TrackBase::iter0:
2520 case TrackBase::iter1:
2521 case TrackBase::iter2:
2524 case TrackBase::iter3:
2527 case TrackBase::iter4:
2530 case TrackBase::iter5:
2533 case TrackBase::iter6:
2544 bool isPrimary =
false;
2550 PFRecTrackRef kfPfRef_fromGsf = (*gsfPfRef).kfPFRecTrackRef();
2555 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)
virtual void setCharge(Charge q) GCC11_FINAL
set electric charge
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)
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)
void RunPFEG(const reco::PFBlockRef &blockRef, std::vector< bool > &active)
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
void addSingleLegConvTrackRefMva(const std::pair< reco::TrackRef, float > &trackrefmva)
add Single Leg Conversion TrackRef
void setPreshowerEnergyPlane2(double preshowerEnergy2)
std::pair< const PFClusterElement *, bool > PFClusterFlaggedElement
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 &)
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
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
void set_mva_e_pi(float mva)
void linkRefinableObjectECALToSingleLegConv(ProtoEGObject &)
edm::Handle< reco::PFCluster::EEtoPSAssociation > eetops_
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
float EvaluateSingleLegMVA(const reco::PFBlockRef &blockref, const reco::Vertex &primaryvtx, unsigned int track_index)
bool isNonnull() const
Checks for non-null.
std::vector< PFKFFlaggedElement > secondaryKFs
void setEtaWidth(double ew)
void setSigmaEtaEta(float val)
set the sigmaetaeta
void dumpCurrentRefinableObjects() const
bool isNull() const
Checks for null.
void initializeProtoCands(std::list< ProtoEGObject > &)
T const * get() const
Returns C++ pointer to the item.
void linkRefinableObjectPrimaryKFsToSecondaryKFs(ProtoEGObject &)
const T & max(const T &a, const T &b)
bool unwrapSuperCluster(const reco::PFBlockElementSuperCluster *, std::vector< PFClusterFlaggedElement > &, ClusterMap &)
double pflowSigmaEtaEta() const
bool fromPFSuperCluster() const
void setCorrectedEnergy(double cenergy)
void addElementInBlock(const reco::PFBlockRef &blockref, unsigned elementIndex)
add an element to the current PFCandidate
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
reco::PFCluster::EEtoPSAssociation EEtoPSAssociation
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
std::list< ProtoEGObject > _refinableObjects
virtual bool trackType(TrackType trType) const
Container::value_type value_type
KFValMap singleLegConversionMvaMap
reco::PFCandidateEGammaExtraCollection outcandsextra_
void linkKFTrackToECAL(const PFKFFlaggedElement &, ProtoEGObject &)
void buildAndRefineEGObjects(const reco::PFBlockRef &block)
void setEcalEnergy(float eeRaw, float eeCorr)
set corrected Ecal energy
reco::PFBlock::LinkData _currentlinks
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)
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
float calculate_ele_mva(const ProtoEGObject &, reco::PFCandidateEGammaExtra &)
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
std::string mvaWeightFileEleID
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
TMVA::Reader * tmvaReaderEle_
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 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)
virtual void setP4(const LorentzVector &p4) GCC11_FINAL
set 4-momentum
std::pair< const PFKFElement *, bool > PFKFFlaggedElement
const PFRecTrackRef & trackRefPF() const
void mergeROsByAnyLink(std::list< ProtoEGObject > &)
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)
std::string mvaweightfile
volatile std::atomic< bool > shutdown_flag false
TMVA::Reader * tmvaReader_
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_
T const * get() const
Returns C++ pointer to the item.
void setTrackRef(const reco::TrackRef &ref)
set track reference
virtual void setPdgId(int pdgId) GCC11_FINAL
reco::PFCandidateCollection outcands_
void fillPFCandidates(const std::list< ProtoEGObject > &, reco::PFCandidateCollection &, reco::PFCandidateEGammaExtraCollection &)
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 &)