32 string mvaWeightFileEleID,
33 const std::shared_ptr<PFSCEnergyCalibration>& thePFSCEnergyCalibration,
34 const std::shared_ptr<PFEnergyCalibration>& thePFEnergyCalibration,
46 mvaEleCut_(mvaEleCut),
47 thePFSCEnergyCalibration_(thePFSCEnergyCalibration),
48 thePFEnergyCalibration_(thePFEnergyCalibration),
49 applyCrackCorrections_(applyCrackCorrections),
50 usePFSCEleCalib_(usePFSCEleCalib),
51 useEGElectrons_(useEGElectrons),
52 useEGammaSupercluster_(useEGammaSupercluster),
53 sumEtEcalIsoForEgammaSC_barrel_(sumEtEcalIsoForEgammaSC_barrel),
54 sumEtEcalIsoForEgammaSC_endcap_(sumEtEcalIsoForEgammaSC_endcap),
55 coneEcalIsoForEgammaSC_(coneEcalIsoForEgammaSC),
56 sumPtTrackIsoForEgammaSC_barrel_(sumPtTrackIsoForEgammaSC_barrel),
57 sumPtTrackIsoForEgammaSC_endcap_(sumPtTrackIsoForEgammaSC_endcap),
58 nTrackIsoForEgammaSC_(nTrackIsoForEgammaSC),
59 coneTrackIsoForEgammaSC_(coneTrackIsoForEgammaSC)
81 tmvaReader_->BookMVA(
"BDT",mvaWeightFileEleID.c_str());
84 std::vector<bool>& active,
101 bool blockHasGSF =
SetLinks(blockRef,associatedToGsf,
102 associatedToBrems,associatedToEcal,
103 active, primaryVertex);
112 BDToutput_.assign(associatedToGsf.size(),-1.);
116 SetIDOutputs(blockRef,associatedToGsf,associatedToBrems,associatedToEcal,primaryVertex);
121 SetCandidates(blockRef,associatedToGsf,associatedToBrems,associatedToEcal);
126 SetActive(blockRef,associatedToGsf,associatedToBrems,associatedToEcal,active);
132 AssMap& associatedToBrems_,
133 AssMap& associatedToEcal_,
134 std::vector<bool>& active,
136 unsigned int CutIndex = 100000;
137 double CutGSFECAL = 10000. ;
140 bool DebugSetLinksSummary =
false;
141 bool DebugSetLinksDetailed =
false;
147 bool IsThereAGSFTrack =
false;
148 bool IsThereAGoodGSFTrack =
false;
150 vector<unsigned int> trackIs(0);
151 vector<unsigned int> gsfIs(0);
152 vector<unsigned int> ecalIs(0);
154 std::vector<bool> localactive(elements.
size(),
true);
158 std::multimap<double, unsigned int> kfElems;
159 for(
unsigned int iEle=0; iEle<elements.
size(); iEle++) {
160 localactive[iEle] = active[iEle];
161 bool thisIsAMuon =
false;
164 case PFBlockElement::TRACK:
168 if ( !thisIsAMuon && active[iEle] ) {
169 trackIs.push_back( iEle );
170 if (DebugSetLinksDetailed)
171 cout<<
"TRACK, stored index, continue "<< iEle << endl;
174 case PFBlockElement::GSF:
180 thisIsAMuon = !kfElems.empty() ?
183 if ( !thisIsAMuon && active[iEle] ) {
184 IsThereAGSFTrack =
true;
185 gsfIs.push_back( iEle );
186 if (DebugSetLinksDetailed)
187 cout<<
"GSF, stored index, continue "<< iEle << endl;
191 if ( active[iEle] ) {
192 ecalIs.push_back( iEle );
193 if (DebugSetLinksDetailed)
194 cout<<
"ECAL, stored index, continue "<< iEle << endl;
203 if(IsThereAGSFTrack) {
214 if (DebugSetLinksDetailed) {
215 cout<<
"#########################################################"<<endl;
216 cout<<
"##### Process Block: #####"<<endl;
217 cout<<
"#########################################################"<<endl;
222 for(
unsigned int iEle=0; iEle<trackIs.size(); iEle++) {
223 std::multimap<double, unsigned int> gsfElems;
228 if(gsfElems.empty()){
231 std::multimap<double, unsigned int> ecalKfElems;
236 if(!ecalKfElems.empty()) {
237 unsigned int ecalKf_index = ecalKfElems.begin()->second;
238 if(localactive[ecalKf_index]==
true) {
242 bool isGsfLinked =
false;
243 for(
unsigned int iGsf=0; iGsf<gsfIs.size(); iGsf++) {
251 std::multimap<double, unsigned int> ecalGsfElems;
256 if(!ecalGsfElems.empty()) {
257 if (ecalGsfElems.begin()->second == ecalKf_index) {
262 if(isGsfLinked ==
false) {
269 int nexhits = refKf->hitPattern().numberOfLostHits(HitPattern::MISSING_INNER_HITS);
271 bool isGoodTrack=
false;
276 bool trackIsFromPrimaryVertex =
false;
278 if ( (*trackIt).castTo<
TrackRef>() == refKf ) {
279 trackIsFromPrimaryVertex =
true;
285 && nexhits == 0 && trackIsFromPrimaryVertex) {
286 localactive[ecalKf_index] =
false;
298 for(
unsigned int iEle=0; iEle<gsfIs.size(); iEle++) {
300 if (!localactive[(gsfIs[iEle])])
continue;
302 localactive[gsfIs[iEle]] =
false;
303 bool ClosestEcalWithKf =
false;
305 if (DebugSetLinksDetailed)
cout <<
" Gsf Index " << gsfIs[iEle] << endl;
312 IsThereAGoodGSFTrack =
true;
314 float etaOut_gsf = GsfEl->
Pout().eta();
315 float diffOutEcalEta = fabs(eta_gsf-etaOut_gsf);
317 float Pin_gsf = 0.01;
319 Pin_gsf = RefGSF->pMode();
323 unsigned int KfGsf_index = CutIndex;
324 unsigned int KfGsf_secondIndex = CutIndex;
325 std::multimap<double, unsigned int> kfElems;
330 std::multimap<double, unsigned int> ecalKfElems;
331 if (!kfElems.empty()) {
335 for(std::multimap<double, unsigned int>::iterator itkf = kfElems.begin();
336 itkf != kfElems.end(); ++itkf) {
344 if(localactive[itkf->second] ==
true) {
346 KfGsf_index = itkf->second;
347 localactive[KfGsf_index] =
false;
355 KfGsf_secondIndex = itkf->second;
361 std::multimap<double, unsigned int> ecalGsfElems;
366 double ecalGsf_dist = CutGSFECAL;
367 unsigned int ClosestEcalGsf_index = CutIndex;
368 if (!ecalGsfElems.empty()) {
369 if(localactive[(ecalGsfElems.begin()->second)] ==
true) {
371 bool compatibleEPout =
true;
372 if(diffOutEcalEta > 0.3) {
373 reco::PFClusterRef clusterRef = elements[(ecalGsfElems.begin()->second)].clusterRef();
374 float EoPout = (clusterRef->energy())/(GsfEl->
Pout().t());
376 compatibleEPout =
false;
378 if(compatibleEPout) {
379 ClosestEcalGsf_index = ecalGsfElems.begin()->second;
380 ecalGsf_dist = block.
dist(gsfIs[iEle],ClosestEcalGsf_index,
385 std::multimap<double, unsigned int> ecalOtherGsfElems;
391 if(!ecalOtherGsfElems.empty()) {
396 if(ecalOtherGsfElems.begin()->second != gsfIs[iEle]&&
398 ecalGsf_dist = CutGSFECAL;
399 ClosestEcalGsf_index = CutIndex;
407 else if(!ecalKfElems.empty()) {
408 if(localactive[(ecalKfElems.begin()->second)] ==
true) {
409 ClosestEcalGsf_index = ecalKfElems.begin()->second;
410 ecalGsf_dist = block.
dist(gsfIs[iEle],ClosestEcalGsf_index,
412 ClosestEcalWithKf =
true;
415 std::multimap<double, unsigned int> ecalOtherGsfElems;
420 if(!ecalOtherGsfElems.empty()) {
424 if(ecalOtherGsfElems.begin()->second != gsfIs[iEle] &&
426 ecalGsf_dist = CutGSFECAL;
427 ClosestEcalGsf_index = CutIndex;
428 ClosestEcalWithKf =
false;
434 if (DebugSetLinksDetailed)
435 cout <<
" Closest Ecal to the Gsf/Kf: index " << ClosestEcalGsf_index
436 <<
" dist " << ecalGsf_dist << endl;
441 std::multimap<double, unsigned int> bremElems;
448 multimap<unsigned int,unsigned int> cleanedEcalBremElems;
449 vector<unsigned int> keyBremIndex(0);
450 unsigned int latestBrem_trajP = 0;
451 unsigned int latestBrem_index = CutIndex;
452 for(std::multimap<double, unsigned int>::iterator ieb = bremElems.begin();
453 ieb != bremElems.end(); ++ieb ) {
454 unsigned int brem_index = ieb->second;
455 if(localactive[brem_index] ==
false)
continue;
459 std::multimap<double, unsigned int> ecalBremsElems;
466 for (std::multimap<double, unsigned int>::iterator ie = ecalBremsElems.begin();
467 ie != ecalBremsElems.end();ie++) {
468 unsigned int ecalBrem_index = ie->second;
469 if(localactive[ecalBrem_index] ==
false)
continue;
472 float ecalBrem_dist = block.
dist(brem_index,ecalBrem_index,
476 if (ecalBrem_index == ClosestEcalGsf_index && (ecalBrem_dist + 0.0012) > ecalGsf_dist)
continue;
479 std::multimap<double, unsigned int> sortedBremElems;
485 bool isGoodBrem =
false;
486 unsigned int sortedBrem_index = CutIndex;
487 for (std::multimap<double, unsigned int>::iterator ibs = sortedBremElems.begin();
488 ibs != sortedBremElems.end();ibs++) {
489 unsigned int temp_sortedBrem_index = ibs->second;
490 std::multimap<double, unsigned int> sortedGsfElems;
495 bool enteredInPrimaryGsf =
false;
496 for (std::multimap<double, unsigned int>::iterator igs = sortedGsfElems.begin();
497 igs != sortedGsfElems.end();igs++) {
502 if(igs->second == gsfIs[iEle]) {
504 sortedBrem_index = temp_sortedBrem_index;
506 enteredInPrimaryGsf =
true;
510 if(enteredInPrimaryGsf)
518 std::multimap<double, unsigned int> ecalOtherGsfElems;
523 if (!ecalOtherGsfElems.empty()) {
526 if(ecalOtherGsfElems.begin()->second != gsfIs[iEle] &&
536 elements[ecalBrem_index].clusterRef();
542 if(sortedBremEcal_deta < 0.015) {
544 cleanedEcalBremElems.
insert(pair<unsigned int,unsigned int>(sortedBrem_index,ecalBrem_index));
547 if (BremTrajP > latestBrem_trajP) {
548 latestBrem_trajP = BremTrajP;
549 latestBrem_index = sortedBrem_index;
551 if (DebugSetLinksDetailed)
552 cout <<
" brem Index " << sortedBrem_index
553 <<
" associated cluster " << ecalBrem_index <<
" BremTrajP " << BremTrajP <<endl;
558 localactive[ecalBrem_index] =
false;
559 bool alreadyfound =
false;
560 for(
unsigned int ii=0;
ii<keyBremIndex.size();
ii++) {
561 if (sortedBrem_index == keyBremIndex[
ii]) alreadyfound =
true;
563 if (alreadyfound ==
false) {
564 keyBremIndex.push_back(sortedBrem_index);
565 localactive[sortedBrem_index] =
false;
574 vector<unsigned int> GsfElemIndex(0);
575 vector<unsigned int> EcalIndex(0);
578 if (ClosestEcalGsf_index < CutIndex) {
579 GsfElemIndex.push_back(ClosestEcalGsf_index);
580 localactive[ClosestEcalGsf_index] =
false;
581 for (std::multimap<double, unsigned int>::iterator
ii = ecalGsfElems.begin();
582 ii != ecalGsfElems.end();
ii++) {
583 if(localactive[
ii->second]) {
585 std::multimap<double, unsigned int> ecalOtherGsfElems;
590 if(!ecalOtherGsfElems.empty()) {
591 if(ecalOtherGsfElems.begin()->second != gsfIs[iEle])
continue;
596 float etacl = clusterRef->eta();
597 if( fabs(eta_gsf-etacl) < 0.05) {
598 GsfElemIndex.push_back(
ii->second);
599 localactive[
ii->second] =
false;
600 if (DebugSetLinksDetailed)
601 cout <<
" ExtraCluster From Gsf " <<
ii->second << endl;
638 if(GsfElemIndex.empty()){
639 if(latestBrem_index < CutIndex) {
640 unsigned int ckey = cleanedEcalBremElems.count(latestBrem_index);
642 unsigned int temp_cal =
643 cleanedEcalBremElems.find(latestBrem_index)->second;
644 GsfElemIndex.push_back(temp_cal);
645 if (DebugSetLinksDetailed)
646 cout <<
"******************** Gsf Cluster From Brem " << temp_cal
647 <<
" Latest Brem index " << latestBrem_index
648 <<
" ************************* " << endl;
651 pair<multimap<unsigned int,unsigned int>::iterator,multimap<unsigned int,unsigned int>::iterator> ret;
652 ret = cleanedEcalBremElems.equal_range(latestBrem_index);
653 multimap<unsigned int,unsigned int>::iterator it;
654 for(it=ret.first; it!=ret.second; ++it) {
655 GsfElemIndex.push_back((*it).second);
656 if (DebugSetLinksDetailed)
657 cout <<
"******************** Gsf Cluster From Brem " << (*it).second
658 <<
" Latest Brem index " << latestBrem_index
659 <<
" ************************* " << endl;
663 unsigned int elToErase = 0;
664 for(
unsigned int i = 0;
i<keyBremIndex.size();
i++) {
665 if(latestBrem_index == keyBremIndex[
i]) {
669 keyBremIndex.erase(keyBremIndex.begin()+elToErase);
677 for(
unsigned int iConv=0; iConv<gsfIs.size(); iConv++) {
685 if (DebugSetLinksDetailed)
686 cout <<
" PFElectronAlgo:: I'm running on convGsfBrem " << endl;
688 float conv_dist = block.
dist(gsfIs[iConv],gsfIs[iEle],
693 std::multimap<double, unsigned int> ecalConvElems;
698 if(!ecalConvElems.empty()) {
700 if(localactive[(ecalConvElems.begin()->second)] ==
true) {
701 if (DebugSetLinksDetailed)
702 cout <<
" PFElectronAlgo:: convGsfBrem has a ECAL cluster linked and free" << endl;
704 std::multimap<double, unsigned int> ecalOtherGsfPrimElems;
706 ecalOtherGsfPrimElems,
709 if(!ecalOtherGsfPrimElems.empty()) {
710 unsigned int gsfprimcheck_index = ecalOtherGsfPrimElems.begin()->second;
716 if (DebugSetLinksDetailed)
717 cout <<
" PFElectronAlgo: !!!!!!! convGsfBrem ECAL cluster has been stored !!!!!!! " 718 <<
" Energy " << clusterRef->energy() <<
" eta,phi " << clusterRef->position().eta()
719 <<
", " << clusterRef->position().phi() << endl;
721 GsfElemIndex.push_back(ecalConvElems.begin()->second);
722 convGsfTrack_.emplace_back(ecalConvElems.begin()->second,gsfIs[iConv]);
723 localactive[ecalConvElems.begin()->second] =
false;
735 EcalIndex.insert(EcalIndex.end(),GsfElemIndex.begin(),GsfElemIndex.end());
740 for(
unsigned int i =0;
i<keyBremIndex.size();
i++) {
741 unsigned int ikey = keyBremIndex[
i];
742 unsigned int ckey = cleanedEcalBremElems.count(ikey);
743 vector<unsigned int> BremElemIndex(0);
745 unsigned int temp_cal =
746 cleanedEcalBremElems.find(ikey)->second;
747 BremElemIndex.push_back(temp_cal);
750 pair<multimap<unsigned int,unsigned int>::iterator,multimap<unsigned int,unsigned int>::iterator> ret;
751 ret = cleanedEcalBremElems.equal_range(ikey);
752 multimap<unsigned int,unsigned int>::iterator it;
753 for(it=ret.first; it!=ret.second; ++it) {
754 BremElemIndex.push_back((*it).second);
757 EcalIndex.insert(EcalIndex.end(),BremElemIndex.begin(),BremElemIndex.end());
758 associatedToBrems_.insert(pair<
unsigned int,vector<unsigned int> >(ikey,BremElemIndex));
763 vector<unsigned int> convBremKFTrack;
764 convBremKFTrack.clear();
765 if (!kfElems.empty()) {
766 for(std::multimap<double, unsigned int>::iterator itkf = kfElems.begin();
767 itkf != kfElems.end(); ++itkf) {
775 std::multimap<double, unsigned int> ecalConvElems;
780 if(!ecalConvElems.empty()) {
785 float secpin = trkRef->p();
789 float eneclust =clust->
clusterRef()->energy();
795 std::multimap<double, unsigned int> hcalConvElems;
805 float enehcalclust = -1;
806 if(!hcalConvElems.empty()) {
809 enehcalclust =clusthcal->
clusterRef()->energy();
811 if( (enehcalclust / (enehcalclust+eneclust) ) > 0.1 && isGoodTrack) {
813 if(enehcalclust > eneclust)
815 if(secpin > (enehcalclust+eneclust) )
821 if(localactive[(ecalConvElems.begin()->second)] ==
false) {
823 if(isHoE || isPoHE) {
824 if (DebugSetLinksDetailed)
825 cout <<
"PFElectronAlgo:: LOCKED ECAL REJECTED TRACK FOR H/E or P/(H+E) " 826 <<
" H/H+E " << enehcalclust/(enehcalclust+eneclust)
827 <<
" H/E " << enehcalclust/eneclust
828 <<
" P/(H+E) " << secpin/(enehcalclust+eneclust)
829 <<
" HCAL ENE " << enehcalclust
830 <<
" ECAL ENE " << eneclust
831 <<
" secPIN " << secpin
832 <<
" Algo Track " << trkRef->algo() << endl;
837 for(
unsigned int iecal =0; iecal < EcalIndex.size(); iecal++) {
840 if(EcalIndex[iecal] == ecalConvElems.begin()->second) {
841 if (DebugSetLinksDetailed)
842 cout <<
" PFElectronAlgo:: Conv Brem Recovery locked cluster and I will lock also the KF track " << endl;
843 convBremKFTrack.push_back(itkf->second);
852 if (DebugSetLinksDetailed)
853 cout <<
"PFElectronAlgo:: FREE ECAL REJECTED TRACK FOR H/H+E " 854 <<
" H/H+E " << (enehcalclust / (enehcalclust+eneclust) )
855 <<
" H/E " << enehcalclust/eneclust
856 <<
" P/(H+E) " << secpin/(enehcalclust+eneclust)
857 <<
" HCAL ENE " << enehcalclust
858 <<
" ECAL ENE " << eneclust
859 <<
" secPIN " << secpin
860 <<
" Algo Track " << trkRef->algo() << endl;
865 std::multimap<double, unsigned int> ecalOtherKFPrimElems;
867 ecalOtherKFPrimElems,
870 if(!ecalOtherKFPrimElems.empty()) {
874 bool isFromGSF =
false;
875 for(std::multimap<double, unsigned int>::iterator itclos = kfElems.begin();
876 itclos != kfElems.end(); ++itclos) {
877 if(ecalOtherKFPrimElems.begin()->second == itclos->second) {
887 float Epin = eneclust/secpin;
890 float totenergy = 0.;
891 for(
unsigned int ikeyecal = 0;
892 ikeyecal<EcalIndex.size(); ikeyecal++){
894 bool foundcluster =
false;
896 for(
unsigned int i2 = 0; i2<ikeyecal-1; i2++) {
897 if(EcalIndex[ikeyecal] == EcalIndex[i2])
901 if(foundcluster)
continue;
904 totenergy += clusasso->
clusterRef()->energy();
909 if(totenergy == 0.) {
910 if (DebugSetLinksDetailed)
911 cout <<
"PFElectronAlgo:: REJECTED_NULLTOT totenergy " << totenergy << endl;
917 double res_before = fabs((totenergy-Pin_gsf)/Pin_gsf);
918 double res_after = fabs(((totenergy+eneclust)-Pin_gsf)/Pin_gsf);
920 if(res_before < res_after) {
921 if (DebugSetLinksDetailed)
922 cout <<
"PFElectronAlgo::REJECTED_RES totenergy " << totenergy <<
" Pin_gsf " << Pin_gsf <<
" cluster to secondary " << eneclust
923 <<
" Res before " << res_before <<
" res_after " << res_after << endl;
928 if (DebugSetLinksDetailed)
929 cout <<
"PFElectronAlgo:: conv brem found asso to ECAL linked to a secondary KF " << endl;
930 convBremKFTrack.push_back(itkf->second);
931 GsfElemIndex.push_back(ecalConvElems.begin()->second);
932 EcalIndex.push_back(ecalConvElems.begin()->second);
933 localactive[(ecalConvElems.begin()->second)] =
false;
934 localactive[(itkf->second)] =
false;
945 double sumEtEcalInTheCone = 0.;
950 double PhiFC = clust->
clusterRef()->position().Phi();
951 double EtaFC = clust->
clusterRef()->position().Eta();
954 for(
unsigned int iEcal=0; iEcal<ecalIs.size(); iEcal++) {
955 bool foundcluster =
false;
956 for(
unsigned int ikeyecal = 0;
957 ikeyecal<EcalIndex.size(); ikeyecal++){
958 if(ecalIs[iEcal] == EcalIndex[ikeyecal])
963 if(foundcluster ==
false) {
966 double eta_clust = clustExt->
clusterRef()->position().Eta();
967 double phi_clust = clustExt->
clusterRef()->position().Phi();
968 double theta_clust = clustExt->
clusterRef()->position().Theta();
969 double deta_clust = eta_clust - EtaFC;
970 double dphi_clust = phi_clust - PhiFC;
971 if ( dphi_clust < -
M_PI )
972 dphi_clust = dphi_clust + 2.*
M_PI;
973 else if ( dphi_clust >
M_PI )
974 dphi_clust = dphi_clust - 2.*
M_PI;
975 double DR =
sqrt(deta_clust*deta_clust+
976 dphi_clust*dphi_clust);
980 vector<double> ps1Ene(0);
981 vector<double> ps2Ene(0);
985 double ET_calib = EE_calib*
sin(theta_clust);
986 sumEtEcalInTheCone += ET_calib;
992 unsigned int sumNTracksInTheCone = 0;
993 double sumPtTracksInTheCone = 0.;
994 for(
unsigned int iTrack=0; iTrack<trackIs.size(); iTrack++) {
996 if(localactive[(trackIs[iTrack])]==
true) {
1001 double deta_trk = trkref->eta() - RefGSF->etaMode();
1002 double dphi_trk = trkref->phi() - RefGSF->phiMode();
1003 if ( dphi_trk < -
M_PI )
1004 dphi_trk = dphi_trk + 2.*
M_PI;
1005 else if ( dphi_trk >
M_PI )
1006 dphi_trk = dphi_trk - 2.*
M_PI;
1007 double DR =
sqrt(deta_trk*deta_trk+
1010 int NValPixelHit = trkref->hitPattern().numberOfValidPixelHits();
1012 if(DR < coneTrackIsoForEgammaSC_ && NValPixelHit >=3) {
1013 sumNTracksInTheCone++;
1014 sumPtTracksInTheCone+=trkref->pt();
1021 bool isBarrelIsolated =
false;
1022 if( fabs(EtaFC < 1.478) &&
1025 isBarrelIsolated =
true;
1028 bool isEndcapIsolated =
false;
1029 if( fabs(EtaFC >= 1.478) &&
1032 isEndcapIsolated =
true;
1036 if(DebugSetLinksDetailed) {
1037 if(fabs(EtaFC < 1.478) && isBarrelIsolated ==
false) {
1038 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND BUT FAILS ISOLATION:BARREL *** " 1039 <<
" sumEtEcalInTheCone " <<sumEtEcalInTheCone
1040 <<
" sumNTracksInTheCone " << sumNTracksInTheCone
1041 <<
" sumPtTracksInTheCone " << sumPtTracksInTheCone << endl;
1043 if(fabs(EtaFC >= 1.478) && isEndcapIsolated ==
false) {
1044 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND BUT FAILS ISOLATION:ENDCAP *** " 1045 <<
" sumEtEcalInTheCone " <<sumEtEcalInTheCone
1046 <<
" sumNTracksInTheCone " << sumNTracksInTheCone
1047 <<
" sumPtTracksInTheCone " << sumPtTracksInTheCone << endl;
1054 if(isBarrelIsolated || isEndcapIsolated ) {
1058 double totenergy = 0.;
1059 for(
unsigned int ikeyecal = 0;
1060 ikeyecal<EcalIndex.size(); ikeyecal++){
1062 bool foundcluster =
false;
1064 for(
unsigned int i2 = 0; i2<ikeyecal-1; i2++) {
1065 if(EcalIndex[ikeyecal] == EcalIndex[i2])
1066 foundcluster =
true;;
1069 if(foundcluster)
continue;
1072 totenergy += clusasso->
clusterRef()->energy();
1078 for(
unsigned int ikeyecal = 0;
1079 ikeyecal<EcalIndex.size(); ikeyecal++){
1081 bool foundcluster =
false;
1083 for(
unsigned int i2 = 0; i2<ikeyecal-1; i2++) {
1084 if(EcalIndex[ikeyecal] == EcalIndex[i2])
1085 foundcluster =
true;
1088 if(foundcluster)
continue;
1091 std::multimap<double, unsigned int> ecalFromSuperClusterElems;
1093 ecalFromSuperClusterElems,
1096 if(!ecalFromSuperClusterElems.empty()) {
1097 for(std::multimap<double, unsigned int>::iterator itsc = ecalFromSuperClusterElems.begin();
1098 itsc != ecalFromSuperClusterElems.end(); ++itsc) {
1099 if(localactive[itsc->second] ==
false) {
1103 std::multimap<double, unsigned int> ecalOtherKFPrimElems;
1105 ecalOtherKFPrimElems,
1108 if(!ecalOtherKFPrimElems.empty()) {
1109 if(localactive[ecalOtherKFPrimElems.begin()->second] ==
true) {
1110 if (DebugSetLinksDetailed)
1111 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND BUT FAILS KF VETO *** " << endl;
1115 bool isInTheEtaRange =
false;
1118 double deta_clustToAdd = clustToAdd->
clusterRef()->position().Eta() - EtaFC;
1119 double ene_clustToAdd = clustToAdd->
clusterRef()->energy();
1121 if(fabs(deta_clustToAdd) < 0.05)
1122 isInTheEtaRange =
true;
1125 bool isBetterEpin =
false;
1126 if(isInTheEtaRange ==
false ) {
1127 if (DebugSetLinksDetailed)
1128 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND BUT FAILS GAMMA DETA RANGE *** " 1129 << fabs(deta_clustToAdd) << endl;
1131 if(KfGsf_index < CutIndex) {
1133 double res_before_gsf = fabs((totenergy-Pin_gsf)/Pin_gsf);
1134 double res_after_gsf = fabs(((totenergy+ene_clustToAdd)-Pin_gsf)/Pin_gsf);
1139 double Pin_kf = trackEl->
trackRef()->p();
1140 double res_before_kf = fabs((totenergy-Pin_kf)/Pin_kf);
1141 double res_after_kf = fabs(((totenergy+ene_clustToAdd)-Pin_kf)/Pin_kf);
1144 if(res_after_gsf < res_before_gsf && res_after_kf < res_before_kf ) {
1145 isBetterEpin =
true;
1148 if (DebugSetLinksDetailed)
1149 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND AND FAILS ALSO RES_EPIN" 1150 <<
" tot energy " << totenergy
1151 <<
" Pin_gsf " << Pin_gsf
1152 <<
" Pin_kf " << Pin_kf
1153 <<
" cluster from SC to ADD " << ene_clustToAdd
1154 <<
" Res before GSF " << res_before_gsf <<
" res_after_gsf " << res_after_gsf
1155 <<
" Res before KF " << res_before_kf <<
" res_after_kf " << res_after_kf << endl;
1160 if(isInTheEtaRange || isBetterEpin) {
1161 if (DebugSetLinksDetailed)
1162 cout <<
"!!!! PFElectronAlgo:: ECAL from SUPERCLUSTER FOUND !!!!! " << endl;
1163 GsfElemIndex.push_back(itsc->second);
1164 EcalIndex.push_back(itsc->second);
1165 localactive[(itsc->second)] =
false;
1174 if(KfGsf_index < CutIndex)
1175 GsfElemIndex.push_back(KfGsf_index);
1176 else if(KfGsf_secondIndex < CutIndex)
1177 GsfElemIndex.push_back(KfGsf_secondIndex);
1180 GsfElemIndex.insert(GsfElemIndex.end(),convBremKFTrack.begin(),convBremKFTrack.end());
1181 GsfElemIndex.insert(GsfElemIndex.end(),keyBremIndex.begin(),keyBremIndex.end());
1182 associatedToGsf_.insert(pair<
unsigned int, vector<unsigned int> >(gsfIs[iEle],GsfElemIndex));
1185 for(
unsigned int ikeyecal = 0;
1186 ikeyecal<EcalIndex.size(); ikeyecal++){
1189 vector<unsigned int> EcalElemsIndex(0);
1191 std::multimap<double, unsigned int> PS1Elems;
1196 for( std::multimap<double, unsigned int>::iterator it = PS1Elems.begin();
1197 it != PS1Elems.end();it++) {
1198 unsigned int index = it->second;
1199 if(localactive[index] ==
true) {
1202 std::multimap<double, unsigned> sortedECAL;
1207 unsigned jEcal = sortedECAL.begin()->second;
1208 if ( jEcal != EcalIndex[ikeyecal])
continue;
1211 EcalElemsIndex.push_back(index);
1212 localactive[
index] =
false;
1216 std::multimap<double, unsigned int> PS2Elems;
1221 for( std::multimap<double, unsigned int>::iterator it = PS2Elems.begin();
1222 it != PS2Elems.end();it++) {
1223 unsigned int index = it->second;
1224 if(localactive[index] ==
true) {
1226 std::multimap<double, unsigned> sortedECAL;
1231 unsigned jEcal = sortedECAL.begin()->second;
1232 if ( jEcal != EcalIndex[ikeyecal])
continue;
1234 EcalElemsIndex.push_back(index);
1235 localactive[
index] =
false;
1242 std::multimap<double, unsigned int> hcalGsfElems;
1247 for( std::multimap<double, unsigned int>::iterator it = hcalGsfElems.begin();
1248 it != hcalGsfElems.end();it++) {
1249 unsigned int index = it->second;
1262 EcalElemsIndex.push_back(index);
1263 localactive[
index] =
false;
1268 if(hcalGsfElems.empty() && ClosestEcalWithKf ==
true) {
1269 std::multimap<double, unsigned int> hcalKfElems;
1274 for( std::multimap<double, unsigned int>::iterator it = hcalKfElems.begin();
1275 it != hcalKfElems.end();it++) {
1276 unsigned int index = it->second;
1277 if(localactive[index] ==
true) {
1280 std::multimap<double, unsigned> sortedKf;
1285 unsigned jKf = sortedKf.begin()->second;
1286 if ( jKf != KfGsf_index)
continue;
1287 EcalElemsIndex.push_back(index);
1288 localactive[
index] =
false;
1293 std::multimap<double, unsigned int> kfEtraElems;
1298 if(!kfEtraElems.empty()) {
1299 for( std::multimap<double, unsigned int>::iterator it = kfEtraElems.begin();
1300 it != kfEtraElems.end();it++) {
1301 unsigned int index = it->second;
1309 bool thisIsAMuon =
false;
1311 if (DebugSetLinksDetailed && thisIsAMuon)
1312 cout <<
" This is a Muon: index " << index << endl;
1313 if(localactive[index] ==
true && !thisIsAMuon) {
1314 if(index != KfGsf_index) {
1317 std::multimap<double, unsigned> sortedECAL;
1322 unsigned jEcal = sortedECAL.begin()->second;
1323 if ( jEcal != EcalIndex[ikeyecal])
continue;
1324 EcalElemsIndex.push_back(index);
1325 localactive[
index] =
false;
1332 associatedToEcal_.insert(pair<
unsigned int,vector<unsigned int> >(EcalIndex[ikeyecal],EcalElemsIndex));
1341 if (DebugSetLinksSummary) {
1342 if(IsThereAGoodGSFTrack) {
1343 if (DebugSetLinksSummary)
cout <<
" -- The Link Summary --" << endl;
1344 for(
map<
unsigned int,vector<unsigned int> >::iterator it = associatedToGsf_.begin();
1345 it != associatedToGsf_.end(); it++) {
1347 if (DebugSetLinksSummary)
cout <<
" AssoGsf " << it->first << endl;
1348 vector<unsigned int> eleasso = it->second;
1349 for(
unsigned int i=0;
i<eleasso.size();
i++) {
1352 if (DebugSetLinksSummary)
1353 cout <<
" AssoGsfElements BREM " << eleasso[
i] << endl;
1356 if (DebugSetLinksSummary)
1357 cout <<
" AssoGsfElements ECAL " << eleasso[
i] << endl;
1360 if (DebugSetLinksSummary)
1361 cout <<
" AssoGsfElements KF " << eleasso[
i] << endl;
1364 if (DebugSetLinksSummary)
1365 cout <<
" AssoGsfElements ????? " << eleasso[
i] << endl;
1370 for(
map<
unsigned int,vector<unsigned int> >::iterator it = associatedToBrems_.begin();
1371 it != associatedToBrems_.end(); it++) {
1372 if (DebugSetLinksSummary)
cout <<
" AssoBrem " << it->first << endl;
1373 vector<unsigned int> eleasso = it->second;
1374 for(
unsigned int i=0;
i<eleasso.size();
i++) {
1377 if (DebugSetLinksSummary)
1378 cout <<
" AssoBremElements ECAL " << eleasso[
i] << endl;
1381 if (DebugSetLinksSummary)
1382 cout <<
" AssoBremElements ????? " << eleasso[
i] << endl;
1387 for(
map<
unsigned int,vector<unsigned int> >::iterator it = associatedToEcal_.begin();
1388 it != associatedToEcal_.end(); it++) {
1389 if (DebugSetLinksSummary)
cout <<
" AssoECAL " << it->first << endl;
1390 vector<unsigned int> eleasso = it->second;
1391 for(
unsigned int i=0;
i<eleasso.size();
i++) {
1394 if (DebugSetLinksSummary)
1395 cout <<
" AssoECALElements PS1 " << eleasso[
i] << endl;
1398 if (DebugSetLinksSummary)
1399 cout <<
" AssoECALElements PS2 " << eleasso[
i] << endl;
1402 if (DebugSetLinksSummary)
1403 cout <<
" AssoECALElements HCAL " << eleasso[
i] << endl;
1406 if (DebugSetLinksSummary)
1407 cout <<
" AssoHCALElements ????? " << eleasso[
i] << endl;
1411 if (DebugSetLinksSummary)
1412 cout <<
"-- End Summary --" << endl;
1417 return IsThereAGoodGSFTrack;
1421 AssMap& associatedToGsf_,
1422 AssMap& associatedToBrems_,
1423 AssMap& associatedToEcal_,
1429 bool DebugIDOutputs =
false;
1430 if(DebugIDOutputs)
cout <<
" ######## Enter in SetIDOutputs #########" << endl;
1432 unsigned int cgsf=0;
1433 for (
map<
unsigned int,vector<unsigned int> >::iterator igsf = associatedToGsf_.begin();
1434 igsf != associatedToGsf_.end(); igsf++,cgsf++) {
1436 float Ene_ecalgsf = 0.;
1437 float Ene_hcalgsf = 0.;
1439 float deta_gsfecal = 0.;
1440 float Ene_ecalbrem = 0.;
1441 float Ene_extraecalgsf = 0.;
1442 bool LateBrem =
false;
1444 int FirstBrem = 1000;
1445 unsigned int ecalGsf_index = 100000;
1446 unsigned int kf_index = 100000;
1454 unsigned int gsf_index = igsf->first;
1461 Ein_gsf =
sqrt(RefGSF->pMode()*
1462 RefGSF->pMode()+m_el*m_el);
1465 float Eout_gsf = GsfEl->
Pout().t();
1470 cout <<
" setIdOutput! GSF Track: Ein " << Ein_gsf
1471 <<
" eta,phi " << Etaout_gsf
1475 vector<unsigned int> assogsf_index = igsf->second;
1476 bool FirstEcalGsf =
true;
1477 for (
unsigned int ielegsf=0;ielegsf<assogsf_index.size();ielegsf++) {
1488 if(!isPrim)
continue;
1490 kf_index = assogsf_index[ielegsf];
1495 unsigned int keyecalgsf = assogsf_index[ielegsf];
1496 vector<unsigned int> assoecalgsf_index = associatedToEcal_.find(keyecalgsf)->second;
1498 vector<double> ps1Ene(0);
1499 vector<double> ps2Ene(0);
1500 for(
unsigned int ips =0; ips<assoecalgsf_index.size();ips++) {
1503 PFClusterRef psref = elements[(assoecalgsf_index[ips])].clusterRef();
1504 ps1Ene.push_back(psref->energy());
1507 PFClusterRef psref = elements[(assoecalgsf_index[ips])].clusterRef();
1508 ps2Ene.push_back(psref->energy());
1517 FirstEcalGsf =
false;
1518 ecalGsf_index = assogsf_index[ielegsf];
1525 posX += Ene_ecalgsf * clusterRef->position().X();
1526 posY += Ene_ecalgsf * clusterRef->position().Y();
1527 posZ += Ene_ecalgsf * clusterRef->position().Z();
1530 cout <<
" setIdOutput! GSF ECAL Cluster E " << Ene_ecalgsf
1531 <<
" eta,phi " << clusterRef->position().eta()
1532 <<
", " << clusterRef->position().phi() << endl;
1534 deta_gsfecal = clusterRef->position().eta() - Etaout_gsf;
1536 vector< const reco::PFCluster * > pfClust_vec(0);
1537 pfClust_vec.clear();
1538 pfClust_vec.push_back(&(*clusterRef));
1548 Ene_extraecalgsf += TempClus_energy;
1549 posX += TempClus_energy * clusterRef->position().X();
1550 posY += TempClus_energy * clusterRef->position().Y();
1551 posZ += TempClus_energy * clusterRef->position().Z();
1554 cout <<
" setIdOutput! Extra ECAL Cluster E " 1555 << TempClus_energy <<
" Tot " << Ene_extraecalgsf << endl;
1561 unsigned int brem_index = assogsf_index[ielegsf];
1566 if (TrajPos < FirstBrem) FirstBrem = TrajPos;
1568 vector<unsigned int> assobrem_index = associatedToBrems_.find(brem_index)->second;
1569 for (
unsigned int ibrem = 0; ibrem < assobrem_index.size(); ibrem++){
1571 unsigned int keyecalbrem = assobrem_index[ibrem];
1572 vector<unsigned int> assoelebrem_index = associatedToEcal_.find(keyecalbrem)->second;
1573 vector<double> ps1EneFromBrem(0);
1574 vector<double> ps2EneFromBrem(0);
1575 for (
unsigned int ielebrem=0; ielebrem<assoelebrem_index.size();ielebrem++) {
1577 PFClusterRef psref = elements[(assoelebrem_index[ielebrem])].clusterRef();
1578 ps1EneFromBrem.push_back(psref->energy());
1581 PFClusterRef psref = elements[(assoelebrem_index[ielebrem])].clusterRef();
1582 ps2EneFromBrem.push_back(psref->energy());
1586 if( assobrem_index[ibrem] != ecalGsf_index) {
1588 elements[(assobrem_index[ibrem])].clusterRef();
1590 Ene_ecalbrem += BremClus_energy;
1591 posX += BremClus_energy * clusterRef->position().X();
1592 posY += BremClus_energy * clusterRef->position().Y();
1593 posZ += BremClus_energy * clusterRef->position().Z();
1596 if (DebugIDOutputs)
cout <<
" setIdOutput::BREM Cluster " 1597 << BremClus_energy <<
" eta,phi " 1598 << clusterRef->position().eta() <<
", " 1599 << clusterRef->position().phi() << endl;
1608 if (Ene_ecalgsf > 0.) {
1616 float Pt_gsf = RefGSF->ptMode();
1621 if(RefGSF->ptModeError() > 0.)
1624 nhit_gsf= RefGSF->hitPattern().trackerLayersWithMeasurement();
1625 chi2_gsf = RefGSF->normalizedChi2();
1634 nhit_kf= RefKF->hitPattern().trackerLayersWithMeasurement();
1635 chi2_kf = RefKF->normalizedChi2();
1644 EtotPinMode = (Ene_ecalgsf + Ene_ecalbrem + Ene_extraecalgsf) / Ein_gsf;
1663 HOverHE = Ene_hcalgsf/(Ene_hcalgsf + Ene_ecalgsf);
1698 double mvaValue =
tmvaReader_->EvaluateMVA(
"BDT");
1702 myExtra.
setMVA(mvaValue);
1721 unsigned int iextratrack = 0;
1722 unsigned int itrackHcalLinked = 0;
1723 float SumExtraKfP = 0.;
1726 double Etotal = Ene_ecalgsf + Ene_ecalbrem + Ene_extraecalgsf;
1731 double ETtotal = Etotal*
sin(sc_pflow.Theta());
1732 double phiTrack = RefGSF->phiMode();
1733 double dphi_normalsc = sc_pflow.Phi() - phiTrack;
1734 if ( dphi_normalsc < -
M_PI )
1735 dphi_normalsc = dphi_normalsc + 2.*
M_PI;
1736 else if ( dphi_normalsc >
M_PI )
1737 dphi_normalsc = dphi_normalsc - 2.*
M_PI;
1738 dphi_normalsc = fabs(dphi_normalsc);
1741 if(ecalGsf_index < 100000) {
1742 vector<unsigned int> assoecalgsf_index = associatedToEcal_.find(ecalGsf_index)->second;
1743 for(
unsigned int itrk =0; itrk<assoecalgsf_index.size();itrk++) {
1758 int nexhits = trackref->hitPattern().numberOfLostHits(HitPattern::MISSING_INNER_HITS);
1760 bool trackIsFromPrimaryVertex =
false;
1762 if ( (*trackIt).castTo<
TrackRef>() == trackref ) {
1763 trackIsFromPrimaryVertex =
true;
1769 if(goodTrack && nexhits == 0 && trackIsFromPrimaryVertex) {
1772 cout <<
" The ecalGsf cluster is not isolated: >0 KF extra with algo < 3" << endl;
1774 float p_trk = trackref->p();
1779 cout <<
" p_trk " << p_trk
1780 <<
" nexhits " << nexhits << endl;
1782 SumExtraKfP += p_trk;
1785 std::multimap<double, unsigned int> hcalKfElems;
1790 if(!hcalKfElems.empty()) {
1797 if( iextratrack > 0) {
1799 if(iextratrack > 3 || Ene_hcalgsf > 10 || (SumExtraKfP/Ene_ecalgsf) > 1.
1800 || (ETtotal > 50. && iextratrack > 1 && (Ene_hcalgsf/Ene_ecalgsf) > 0.1) ) {
1802 cout <<
" *****This electron candidate is discarded: Non isolated # tracks " 1803 << iextratrack <<
" HOverHE " <<
HOverHE 1804 <<
" SumExtraKfP/Ene_ecalgsf " << SumExtraKfP/Ene_ecalgsf
1805 <<
" SumExtraKfP " << SumExtraKfP
1806 <<
" Ene_ecalgsf " << Ene_ecalgsf
1807 <<
" ETtotal " << ETtotal
1808 <<
" Ene_hcalgsf/Ene_ecalgsf " << Ene_hcalgsf/Ene_ecalgsf
1817 ((EtotPinMode < 1.1 && EtotPinMode > 0.6) && (fabs(
Eta_gsf) >= 1.0 && fabs(
Eta_gsf) <= 2.0))) {
1819 (itrackHcalLinked == iextratrack) &&
1820 kf_index < 100000 ) {
1825 cout <<
" *****This electron is reactivated # tracks " 1826 << iextratrack <<
" #tracks hcal linked " << itrackHcalLinked
1827 <<
" SumExtraKfP/Ene_ecalgsf " << SumExtraKfP/Ene_ecalgsf
1829 <<
" eta gsf " << fabs(
Eta_gsf) <<
" kf index " << kf_index <<endl;
1836 cout <<
" *****This electron candidate is discarded HCAL ENERGY " 1847 cout <<
" *****This electron candidate is discarded Low ETOTPIN " 1853 if(ETtotal > 50. && dphi_normalsc > 0.1 ) {
1855 cout <<
" *****This electron candidate is discarded Large ANGLE " 1856 <<
" ETtotal " << ETtotal <<
" EGsfPoutMode " << dphi_normalsc << endl;
1862 if (DebugIDOutputs) {
1863 cout <<
" **** BDT observables ****" << endl;
1864 cout <<
" < Normalization > " << endl;
1865 cout <<
" Pt_gsf " << Pt_gsf <<
" Pin " << Ein_gsf <<
" Pout " << Eout_gsf
1866 <<
" Eta_gsf " <<
Eta_gsf << endl;
1867 cout <<
" < PureTracking > " << endl;
1874 <<
" nhit_kf " <<
nhit_kf << endl;
1875 cout <<
" < track-ecal-hcal-ps " << endl;
1881 <<
" HOverHE " <<
HOverHE <<
" Hcal energy " << Ene_hcalgsf
1885 cout <<
" !!!!!!!!!!!!!!!! the BDT output !!!!!!!!!!!!!!!!!: direct " << mvaValue
1886 <<
" corrected " <<
BDToutput_[cgsf] << endl;
1892 cout <<
" Gsf Ref isNULL " << endl;
1897 cout <<
" No clusters associated to the gsf " << endl;
1900 DebugIDOutputs =
false;
1908 AssMap& associatedToGsf_,
1909 AssMap& associatedToBrems_,
1910 AssMap& associatedToEcal_){
1918 bool DebugIDCandidates =
false;
1922 unsigned int cgsf=0;
1923 for (
map<
unsigned int,vector<unsigned int> >::iterator igsf = associatedToGsf_.begin();
1924 igsf != associatedToGsf_.end(); igsf++,cgsf++) {
1925 unsigned int gsf_index = igsf->first;
1935 float dpt=0;
float dpt_gsf=0;
1936 float Eene=0;
float dene=0;
float Hene=0.;
1941 std::vector<float> bremEnergyVec;
1943 std::vector<const PFCluster*> pfSC_Clust_vec;
1945 float de_gs = 0., de_me = 0., de_kf = 0.;
1951 float ps1TotEne = 0;
1952 float ps2TotEne = 0;
1953 vector<unsigned int> elementsToAdd(0);
1958 elementsToAdd.push_back(gsf_index);
1967 charge= RefGSF->chargeMode();
1968 nhit_gsf= RefGSF->hitPattern().trackerLayersWithMeasurement();
1970 momentum_gsf.SetPx(RefGSF->pxMode());
1971 momentum_gsf.SetPy(RefGSF->pyMode());
1972 momentum_gsf.SetPz(RefGSF->pzMode());
1973 float ENE=
sqrt(RefGSF->pMode()*
1974 RefGSF->pMode()+m_el*m_el);
1976 if( DebugIDCandidates )
1977 cout <<
"SetCandidates:: GsfTrackRef: Ene " << ENE
1978 <<
" charge " << charge <<
" nhits " << nhit_gsf <<endl;
1980 momentum_gsf.SetE(ENE);
1981 dpt_gsf=RefGSF->ptModeError()*
1982 (RefGSF->pMode()/RefGSF->ptMode());
1984 momentum_mean.SetPx(RefGSF->px());
1985 momentum_mean.SetPy(RefGSF->py());
1986 momentum_mean.SetPz(RefGSF->pz());
1987 float ENEm=
sqrt(RefGSF->p()*
1988 RefGSF->p()+m_el*m_el);
1989 momentum_mean.SetE(ENEm);
1994 if( DebugIDCandidates )
1995 cout <<
"SetCandidates:: !!!! NULL GSF Track Ref " << endl;
1999 vector<unsigned int> assogsf_index = igsf->second;
2000 unsigned int ecalGsf_index = 100000;
2001 bool FirstEcalGsf =
true;
2002 for (
unsigned int ielegsf=0;ielegsf<assogsf_index.size();ielegsf++) {
2005 elementsToAdd.push_back((assogsf_index[ielegsf]));
2010 if(!isPrim)
continue;
2016 nhit_kf=RefKF->hitPattern().trackerLayersWithMeasurement();
2017 momentum_kf.SetPx(RefKF->px());
2018 momentum_kf.SetPy(RefKF->py());
2019 momentum_kf.SetPz(RefKF->pz());
2020 float ENE=
sqrt(RefKF->p()*RefKF->p()+m_el*m_el);
2021 if( DebugIDCandidates )
2022 cout <<
"SetCandidates:: KFTrackRef: Ene " << ENE <<
" nhits " << nhit_kf << endl;
2024 momentum_kf.SetE(ENE);
2027 if( DebugIDCandidates )
2028 cout <<
"SetCandidates:: !!!! NULL KF Track Ref " << endl;
2033 unsigned int keyecalgsf = assogsf_index[ielegsf];
2034 vector<unsigned int> assoecalgsf_index = associatedToEcal_.find(keyecalgsf)->second;
2035 vector<double> ps1Ene(0);
2036 vector<double> ps2Ene(0);
2040 for(
unsigned int ips =0; ips<assoecalgsf_index.size();ips++) {
2043 PFClusterRef psref = elements[(assoecalgsf_index[ips])].clusterRef();
2044 ps1Ene.push_back(psref->energy());
2045 elementsToAdd.push_back((assoecalgsf_index[ips]));
2048 PFClusterRef psref = elements[(assoecalgsf_index[ips])].clusterRef();
2049 ps2Ene.push_back(psref->energy());
2050 elementsToAdd.push_back((assoecalgsf_index[ips]));
2055 elementsToAdd.push_back((assoecalgsf_index[ips]));
2060 elementsToAdd.push_back((assogsf_index[ielegsf]));
2078 float ceta=
cl.position().eta();
2079 float cphi=
cl.position().phi();
2092 if( DebugIDCandidates )
2093 cout <<
"SetCandidates:: EcalCluster: EneNoCalib " << clust->
clusterRef()->energy()
2094 <<
" eta,phi " << ceta <<
"," << cphi <<
" Calib " << EE <<
" dE " << dE <<endl;
2096 bool elecCluster=
false;
2098 FirstEcalGsf =
false;
2100 ecalGsf_index = assogsf_index[ielegsf];
2108 clusterMomentum.SetPxPyPzE(EE*direction.x(),
2125 std::map<unsigned int,std::vector<reco::PFCandidate> >::iterator itcheck=
2130 std::vector<reco::PFCandidate> tmpVec;
2131 tmpVec.push_back(cluster_Candidate);
2137 itcheck->second.push_back(cluster_Candidate);
2141 posX += EE *
cl.position().X();
2142 posY += EE *
cl.position().Y();
2143 posZ += EE *
cl.position().Z();
2149 pfSC_Clust_vec.push_back( &
cl );
2157 unsigned int brem_index = assogsf_index[ielegsf];
2158 vector<unsigned int> assobrem_index = associatedToBrems_.find(brem_index)->second;
2159 elementsToAdd.push_back(brem_index);
2160 for (
unsigned int ibrem = 0; ibrem < assobrem_index.size(); ibrem++){
2163 if( assobrem_index[ibrem] != ecalGsf_index) {
2164 unsigned int keyecalbrem = assobrem_index[ibrem];
2165 const vector<unsigned int>& assoelebrem_index = associatedToEcal_.find(keyecalbrem)->second;
2166 vector<double> ps1EneFromBrem(0);
2167 vector<double> ps2EneFromBrem(0);
2168 for (
unsigned int ielebrem=0; ielebrem<assoelebrem_index.size();ielebrem++) {
2170 PFClusterRef psref = elements[(assoelebrem_index[ielebrem])].clusterRef();
2171 ps1EneFromBrem.push_back(psref->energy());
2172 elementsToAdd.push_back(assoelebrem_index[ielebrem]);
2175 PFClusterRef psref = elements[(assoelebrem_index[ielebrem])].clusterRef();
2176 ps2EneFromBrem.push_back(psref->energy());
2177 elementsToAdd.push_back(assoelebrem_index[ielebrem]);
2180 elementsToAdd.push_back(assobrem_index[ibrem]);
2187 bremEnergyVec.push_back(EE);
2189 float ceta = clusterRef->position().eta();
2192 if( DebugIDCandidates )
2193 cout <<
"SetCandidates:: BremCluster: Ene " << EE <<
" dE " << dE <<endl;
2196 posX += EE * clusterRef->position().X();
2197 posY += EE * clusterRef->position().Y();
2198 posZ += EE * clusterRef->position().Z();
2206 pfSC_Clust_vec.push_back( clusterRef.
get() );
2211 math::XYZPoint direction=clusterRef->position()/clusterRef->position().R();
2213 photonMomentum.SetPxPyPzE(EE*direction.x(),
2229 std::map<unsigned int,std::vector<reco::PFCandidate> >::iterator itcheck=
2234 std::vector<reco::PFCandidate> tmpVec;
2235 tmpVec.push_back(photon_Candidate);
2241 itcheck->second.push_back(photon_Candidate);
2251 double unCorrEene = Eene;
2252 double absEta = fabs(momentum_gsf.Eta());
2253 double emTheta = momentum_gsf.Theta();
2256 pfSC_Clust_vec.clear();
2258 if( DebugIDCandidates )
2259 cout <<
"PFEelectronAlgo:: absEta " << absEta <<
" theta " << emTheta
2260 <<
" EneRaw " << Eene <<
" Err " << dene;
2266 double Etene = Eene*
sin(emTheta);
2268 double emBR_et = emBR_e*
sin(emTheta);
2270 Eene = emCorrFull_et/
sin(emTheta);
2275 double emBR_et = emBR_e*
sin(emTheta);
2277 Eene = emCorrFull_et/
sin(emTheta);
2279 dene =
sqrt(dene)*(Eene/unCorrEene);
2283 if( DebugIDCandidates )
2284 cout <<
" EneCorrected " << Eene <<
" Err " << dene << endl;
2289 if(has_kf && unCorrEene > 0.) {
2295 std::multimap<double, unsigned int> bremElems;
2301 double phiTrack = RefGSF->phiMode();
2302 if(!bremElems.empty()) {
2303 unsigned int brem_index = bremElems.begin()->second;
2309 double dphi_normalsc = sc_pflow.Phi() - phiTrack;
2310 if ( dphi_normalsc < -
M_PI )
2311 dphi_normalsc = dphi_normalsc + 2.*
M_PI;
2312 else if ( dphi_normalsc >
M_PI )
2313 dphi_normalsc = dphi_normalsc - 2.*
M_PI;
2315 int chargeGsf = RefGSF->chargeMode();
2316 int chargeKf = RefKF->charge();
2319 if(dphi_normalsc < 0.)
2324 if(chargeKf == chargeGsf)
2326 else if(chargeGsf == chargeSC)
2331 if( DebugIDCandidates )
2332 cout <<
"PFElectronAlgo:: charge determination " 2333 <<
" charge GSF " << chargeGsf
2334 <<
" charge KF " << chargeKf
2335 <<
" charge SC " << chargeSC
2336 <<
" Final Charge " << charge << endl;
2341 if ((nhit_gsf<8) && (has_kf)){
2345 momentum=momentum_kf;
2347 float scale= Fe/momentum.E();
2350 if (Eene < 0.0001) {
2356 newmomentum.SetPxPyPzE(scale*momentum.Px(),
2357 scale*momentum.Py(),
2358 scale*momentum.Pz(),Fe);
2359 if( DebugIDCandidates )
2360 cout <<
"SetCandidates:: (nhit_gsf<8) && (has_kf):: pt " << newmomentum.pt() <<
" Ene " << Fe <<endl;
2364 if ((nhit_gsf>7) || (has_kf==
false)){
2366 de_gs=1-momentum_gsf.E()/Eene;
2367 de_me=1-momentum_mean.E()/Eene;
2368 de_kf=1-momentum_kf.E()/Eene;
2371 momentum=momentum_gsf;
2372 dpt=1/(dpt_gsf*dpt_gsf);
2379 Fe =((dene*Eene) +(dpt*momentum.E()))/(dene+dpt);
2385 if ((de_gs>0.05)&&(de_kf>0.05)){
2388 if ((de_gs<-0.1)&&(de_me<-0.1) &&(de_kf<0.) &&
2389 (momentum.E()/dpt_gsf) > 5. && momentum_gsf.pt() < 30.){
2392 float scale= Fe/momentum.E();
2394 newmomentum.SetPxPyPzE(scale*momentum.Px(),
2395 scale*momentum.Py(),
2396 scale*momentum.Pz(),Fe);
2397 if( DebugIDCandidates )
2398 cout <<
"SetCandidates::(nhit_gsf>7) || (has_kf==false) " << newmomentum.pt() <<
" Ene " << Fe <<endl;
2402 if (newmomentum.pt()>0.5){
2407 if( DebugIDCandidates )
2408 cout <<
"SetCandidates:: I am before doing candidate " <<endl;
2411 std::vector<float> clusterEnergyVec;
2412 clusterEnergyVec.push_back(RawEene);
2413 clusterEnergyVec.insert(clusterEnergyVec.end(),bremEnergyVec.begin(),bremEnergyVec.end());
2416 std::vector<reco::PFCandidateElectronExtra>::iterator itextra;
2420 itextra->setClusterEnergies(clusterEnergyVec);
2424 std::cout <<
" There is a big problem with the electron extra, PFElectronAlgo should crash soon " << RawEene << std::endl;
2430 temp_Candidate =
PFCandidate(charge,newmomentum,particleType);
2447 if(seedRef.
isAvailable() && seedRef->isEcalDriven()) {
2454 if( DebugIDCandidates )
2455 cout <<
"SetCandidates:: I am after doing candidate " <<endl;
2457 for (
unsigned int elad=0; elad<elementsToAdd.size();elad++){
2462 std::map<unsigned int, std::vector<reco::PFCandidate> >::const_iterator itcluster=
2466 const std::vector<reco::PFCandidate> & theClusters=itcluster->second;
2467 unsigned nclus=theClusters.size();
2469 for(
unsigned iclus=0;iclus<nclus;++iclus)
2476 bool bypassmva=
false;
2479 [&RefGSF](
const auto& ele) {
return (ele.gsfTrack() == RefGSF);} );
2485 if( DebugIDCandidates ) {
2487 float esceg = itcheck->caloEnergy();
2489 <<
" SuperClusterEnergy " << esceg
2490 <<
" PF Energy " << Eene << endl;
2492 cout <<
" hoe " << itcheck->hcalOverEcal()
2493 <<
" tkiso04 " << itcheck->dr04TkSumPt()
2494 <<
" ecaliso04 " << itcheck->dr04EcalRecHitSumEt()
2495 <<
" hcaliso04 " << itcheck->dr04HcalTowerSumEt()
2496 <<
" tkiso03 " << itcheck->dr03TkSumPt()
2497 <<
" ecaliso03 " << itcheck->dr03EcalRecHitSumEt()
2498 <<
" hcaliso03 " << itcheck->dr03HcalTowerSumEt() << endl;
2506 if( mvaSelected || bypassmva ) {
2509 itextra->setStatus(PFCandidateElectronExtra::Selected,
true);
2513 itextra->setStatus(PFCandidateElectronExtra::Rejected,
true);
2519 itextra->setStatus(PFCandidateElectronExtra::ECALDrivenPreselected,bypassmva);
2520 itextra->setStatus(PFCandidateElectronExtra::MVASelected,mvaSelected);
2528 if( DebugIDCandidates )
2529 cout <<
"SetCandidates:: No Candidate Produced because of Pt cut: 0.5 " <<endl;
2534 if( DebugIDCandidates )
2535 cout <<
"SetCandidates:: No Candidate Produced because of No GSF Track Ref " <<endl;
2544 AssMap& associatedToGsf_,
2545 AssMap& associatedToBrems_,
2546 AssMap& associatedToEcal_,
2547 std::vector<bool>& active){
2553 unsigned int cgsf=0;
2554 for (
map<
unsigned int,vector<unsigned int> >::iterator igsf = associatedToGsf_.begin();
2555 igsf != associatedToGsf_.end(); igsf++,cgsf++) {
2557 unsigned int gsf_index = igsf->first;
2563 bool bypassmva=
false;
2566 [&RefGSF](
const auto& ele) {
return (ele.gsfTrack() == RefGSF);} );
2576 active[gsf_index] =
false;
2577 vector<unsigned int> assogsf_index = igsf->second;
2578 for (
unsigned int ielegsf=0;ielegsf<assogsf_index.size();ielegsf++) {
2581 active[(assogsf_index[ielegsf])] =
false;
2583 unsigned int keyecalgsf = assogsf_index[ielegsf];
2596 for(
unsigned int iconv = 0; iconv <
convGsfTrack_.size(); iconv++) {
2601 std::multimap<double, unsigned> convKf;
2607 if(!convKf.empty()) {
2608 active[convKf.begin()->second] =
false;
2615 vector<unsigned int> assoecalgsf_index = associatedToEcal_.find(keyecalgsf)->second;
2616 for(
unsigned int ips =0; ips<assoecalgsf_index.size();ips++) {
2619 active[(assoecalgsf_index[ips])] =
false;
2621 active[(assoecalgsf_index[ips])] =
false;
2624 active[(assoecalgsf_index[ips])] =
false;
2630 unsigned int brem_index = assogsf_index[ielegsf];
2631 vector<unsigned int> assobrem_index = associatedToBrems_.find(brem_index)->second;
2632 for (
unsigned int ibrem = 0; ibrem < assobrem_index.size(); ibrem++){
2634 unsigned int keyecalbrem = assobrem_index[ibrem];
2636 active[(assobrem_index[ibrem])] =
false;
2647 vector<unsigned int> assoelebrem_index = associatedToEcal_.find(keyecalbrem)->second;
2649 for (
unsigned int ielebrem=0; ielebrem<assoelebrem_index.size();ielebrem++) {
2651 active[(assoelebrem_index[ielebrem])] =
false;
2653 active[(assoelebrem_index[ielebrem])] =
false;
2668 bool isPrimary =
false;
2674 PFRecTrackRef kfPfRef_fromGsf = (*gsfPfRef).kfPFRecTrackRef();
2679 if(kfref == kfref_fromGsf)
std::vector< std::pair< unsigned int, unsigned int > > fifthStepKfTrack_
sumPtTrackIsoForEgammaSC_barrel
const math::XYZTLorentzVector & Pout() const
void setPs2Energy(float e2)
set corrected PS2 energy
const math::XYZPointF & positionAtECALEntrance() const
bool SetLinks(const reco::PFBlockRef &blockRef, AssMap &associatedToGsf_, AssMap &associatedToBrems_, AssMap &associatedToEcal_, std::vector< bool > &active, const reco::Vertex &primaryVertex)
std::map< unsigned int, std::vector< unsigned int > > AssMap
const reco::GsfTrackRef & GsftrackRef() const
void setPs1Energy(float e1)
set corrected PS1 energy
ParticleType
particle types
bool isNonnull() const
Checks for non-null.
sumPtTrackIsoForEgammaSC_endcap
void setMVA(float val)
set the result (mostly for debugging)
void setLateBrem(float val)
set LateBrem
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
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
float EtotBremPinPoutMode
void SetCandidates(const reco::PFBlockRef &blockRef, AssMap &associatedToGsf_, AssMap &associatedToBrems_, AssMap &associatedToEcal_)
std::vector< std::pair< unsigned int, unsigned int > > convGsfTrack_
void setSigmaEtaEta(float val)
set the sigmaetaeta
const PFClusterRef & clusterRef() const override
void setGsfTrackPout(const math::XYZTLorentzVector &pout)
set the pout (not trivial to get from the GSF track)
const math::XYZPointF & positionAtECALEntrance() const
std::vector< reco::PFCandidateElectronExtra > electronExtra_
const reco::TrackRef & trackRef() const override
Sin< T >::type sin(const T &t)
std::map< unsigned int, Link > LinkData
double pflowPhiWidth() const
std::shared_ptr< PFEnergyCalibration > thePFEnergyCalibration_
void setEarlyBrem(float val)
set EarlyBrem
const std::vector< reco::GsfElectron > * theGsfElectrons_
bool isPrimaryTrack(const reco::PFBlockElementTrack &KfEl, const reco::PFBlockElementGsfTrack &GsfEl)
const GsfPFRecTrackRef & GsftrackRefPF() const
const edm::OwnVector< reco::PFBlockElement > & elements() const
sumEtEcalIsoForEgammaSC_endcap
const LinkData & linkData() const
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float > > XYZPointF
point in space with cartesian internal representation
unsigned int indTrajPoint() const
double pflowEtaWidth() const
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
double coneEcalIsoForEgammaSC_
TMVA::Reader * tmvaReader_
U second(std::pair< T, U > const &p)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
std::shared_ptr< PFSCEnergyCalibration > thePFSCEnergyCalibration_
void set_mva_e_pi(float mvaNI)
void SetActive(const reco::PFBlockRef &blockRef, AssMap &associatedToGsf_, AssMap &associatedToBrems_, AssMap &associatedToEcal_, std::vector< bool > &active)
void setVertexSource(PFVertexType vt)
double getEnergyResolutionEm(double CorrectedEnergy, double eta) const
bool goodTrack(const reco::Track *pTrack, math::XYZPoint leadPV, trackSelectionParameters parameters, bool debug=false)
double pflowSigmaEtaEta() const
void addElementInBlock(const reco::PFBlockRef &blockref, unsigned elementIndex)
add an element to the current PFCandidate
PFElectronAlgo(const double mvaEleCut, std::string mvaWeightFileEleID, const std::shared_ptr< PFSCEnergyCalibration > &thePFSCEnergyCalibration, const std::shared_ptr< PFEnergyCalibration > &thePFEnergyCalibration, bool applyCrackCorrections, bool usePFSCEleCalib, bool useEGElectrons, bool useEGammaSupercluster, double sumEtEcalIsoForEgammaSC_barrel, double sumEtEcalIsoForEgammaSC_endcap, double coneEcalIsoForEgammaSC, double sumPtTrackIsoForEgammaSC_barrel, double sumPtTrackIsoForEgammaSC_endcap, unsigned int nTrackIsoForEgammaSC, double coneTrackIsoForEgammaSC)
bool trackType(TrackType trType) const override
double sumEtEcalIsoForEgammaSC_barrel_
std::vector< bool > lockExtraKf_
std::vector< double > BDToutput_
void setDeltaEta(float val)
set the delta eta
double sumEtEcalIsoForEgammaSC_endcap_
T const * get() const
Returns C++ pointer to the item.
void SetIDOutputs(const reco::PFBlockRef &blockRef, AssMap &associatedToGsf_, AssMap &associatedToBrems_, AssMap &associatedToEcal_, const reco::Vertex &primaryVertex)
sumEtEcalIsoForEgammaSC_barrel
void addDaughter(const Candidate &, const std::string &s="")
add a clone of the passed candidate as daughter
std::map< unsigned int, std::vector< reco::PFCandidate > > electronConstituents_
void setEcalEnergy(float eeRaw, float eeCorr)
set corrected Ecal energy
void setKfTrackRef(const reco::TrackRef &ref)
set kf track reference
double sumPtTrackIsoForEgammaSC_endcap_
void setGsfTrackRef(const reco::GsfTrackRef &ref)
set gsftrack reference
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
Particle reconstructed by the particle flow algorithm.
std::vector< TrackBaseRef >::const_iterator trackRef_iterator
The iteratator for the vector<TrackRef>
const PFRecTrackRef & trackRefPF() const override
double sumPtTrackIsoForEgammaSC_barrel_
void setSuperClusterRef(const reco::SuperClusterRef &scRef)
double dist(unsigned ie1, unsigned ie2, const LinkData &linkData, LinkTest test) const
trackRef_iterator tracks_begin() const
first iterator over tracks
unsigned int nTrackIsoForEgammaSC_
void setTrackRef(const reco::TrackRef &ref)
set track reference
void insert(const_iterator i, D *&d)
void RunPFElectron(const reco::PFBlockRef &blockRef, std::vector< bool > &active, const reco::Vertex &primaryVertex)
void setHadEnergy(float val)
set the had energy. The cluster energies should be entered before
void setHcalEnergy(float ehRaw, float ehCorr)
set corrected Hcal energy
std::vector< reco::PFCandidate > elCandidate_
bool applyCrackCorrections_
void setEGElectronCollection(const reco::GsfElectronCollection &egelectrons)
bool useEGammaSupercluster_
std::vector< reco::PFCandidate > allElCandidate_