30 string mvaWeightFileEleID,
31 const boost::shared_ptr<PFSCEnergyCalibration>& thePFSCEnergyCalibration,
32 bool applyCrackCorrections,
43 mvaEleCut_(mvaEleCut),
44 thePFSCEnergyCalibration_(thePFSCEnergyCalibration),
45 applyCrackCorrections_(applyCrackCorrections),
46 usePFSCEleCalib_(usePFSCEleCalib),
47 useEGElectrons_(useEGElectrons),
48 useEGammaSupercluster_(useEGammaSupercluster),
49 sumEtEcalIsoForEgammaSC_barrel_(sumEtEcalIsoForEgammaSC_barrel),
50 sumEtEcalIsoForEgammaSC_endcap_(sumEtEcalIsoForEgammaSC_endcap),
51 coneEcalIsoForEgammaSC_(coneEcalIsoForEgammaSC),
52 sumPtTrackIsoForEgammaSC_barrel_(sumPtTrackIsoForEgammaSC_barrel),
53 sumPtTrackIsoForEgammaSC_endcap_(sumPtTrackIsoForEgammaSC_endcap),
54 nTrackIsoForEgammaSC_(nTrackIsoForEgammaSC),
55 coneTrackIsoForEgammaSC_(coneTrackIsoForEgammaSC)
77 tmvaReader_->BookMVA(
"BDT",mvaWeightFileEleID.c_str());
80 std::vector<bool>& active){
96 bool blockHasGSF =
SetLinks(blockRef,associatedToGsf,
97 associatedToBrems,associatedToEcal,
107 BDToutput_.assign(associatedToGsf.size(),-1.);
111 SetIDOutputs(blockRef,associatedToGsf,associatedToBrems,associatedToEcal);
116 SetCandidates(blockRef,associatedToGsf,associatedToBrems,associatedToEcal);
121 SetActive(blockRef,associatedToGsf,associatedToBrems,associatedToEcal,active);
127 AssMap& associatedToBrems_,
128 AssMap& associatedToEcal_,
129 std::vector<bool>& active){
130 unsigned int CutIndex = 100000;
131 double CutGSFECAL = 10000. ;
134 bool DebugSetLinksSummary =
false;
135 bool DebugSetLinksDetailed =
false;
141 bool IsThereAGSFTrack =
false;
142 bool IsThereAGoodGSFTrack =
false;
144 vector<unsigned int> trackIs(0);
145 vector<unsigned int> gsfIs(0);
146 vector<unsigned int> ecalIs(0);
148 std::vector<bool> localactive(elements.
size(),
true);
152 std::multimap<double, unsigned int> kfElems;
153 for(
unsigned int iEle=0; iEle<elements.
size(); iEle++) {
154 localactive[iEle] = active[iEle];
155 bool thisIsAMuon =
false;
158 case PFBlockElement::TRACK:
162 if ( !thisIsAMuon && active[iEle] ) {
163 trackIs.push_back( iEle );
164 if (DebugSetLinksDetailed)
165 cout<<
"TRACK, stored index, continue "<< iEle << endl;
168 case PFBlockElement::GSF:
174 thisIsAMuon = kfElems.size() ?
177 if ( !thisIsAMuon && active[iEle] ) {
178 IsThereAGSFTrack =
true;
179 gsfIs.push_back( iEle );
180 if (DebugSetLinksDetailed)
181 cout<<
"GSF, stored index, continue "<< iEle << endl;
185 if ( active[iEle] ) {
186 ecalIs.push_back( iEle );
187 if (DebugSetLinksDetailed)
188 cout<<
"ECAL, stored index, continue "<< iEle << endl;
197 if(IsThereAGSFTrack) {
214 for(
unsigned int iEle=0; iEle<trackIs.size(); iEle++) {
215 std::multimap<double, unsigned int> gsfElems;
220 if(gsfElems.size() == 0){
223 std::multimap<double, unsigned int> ecalKfElems;
228 if(ecalKfElems.size() > 0) {
229 unsigned int ecalKf_index = ecalKfElems.begin()->second;
230 if(localactive[ecalKf_index]==
true) {
234 bool isGsfLinked =
false;
235 for(
unsigned int iGsf=0; iGsf<gsfIs.size(); iGsf++) {
243 std::multimap<double, unsigned int> ecalGsfElems;
248 if(ecalGsfElems.size() > 0) {
249 if (ecalGsfElems.begin()->second == ecalKf_index) {
254 if(isGsfLinked ==
false) {
260 unsigned int Algo = 0;
262 Algo = refKf->algo();
264 localactive[ecalKf_index] =
false;
277 for(
unsigned int iEle=0; iEle<gsfIs.size(); iEle++) {
279 if (!localactive[(gsfIs[iEle])])
continue;
281 localactive[gsfIs[iEle]] =
false;
282 bool ClosestEcalWithKf =
false;
284 if (DebugSetLinksDetailed)
cout <<
" Gsf Index " << gsfIs[iEle] << endl;
291 IsThereAGoodGSFTrack =
true;
293 float etaOut_gsf = GsfEl->
Pout().eta();
294 float diffOutEcalEta = fabs(eta_gsf-etaOut_gsf);
296 float Pin_gsf = 0.01;
298 Pin_gsf = RefGSF->pMode();
302 unsigned int KfGsf_index = CutIndex;
303 unsigned int KfGsf_secondIndex = CutIndex;
304 std::multimap<double, unsigned int> kfElems;
309 std::multimap<double, unsigned int> ecalKfElems;
310 if (kfElems.size() > 0) {
314 for(std::multimap<double, unsigned int>::iterator itkf = kfElems.begin();
315 itkf != kfElems.end(); ++itkf) {
323 if(localactive[itkf->second] ==
true) {
325 KfGsf_index = itkf->second;
326 localactive[KfGsf_index] =
false;
334 KfGsf_secondIndex = itkf->second;
340 std::multimap<double, unsigned int> ecalGsfElems;
345 double ecalGsf_dist = CutGSFECAL;
346 unsigned int ClosestEcalGsf_index = CutIndex;
347 if (ecalGsfElems.size() > 0) {
348 if(localactive[(ecalGsfElems.begin()->second)] ==
true) {
350 bool compatibleEPout =
true;
351 if(diffOutEcalEta > 0.3) {
352 reco::PFClusterRef clusterRef = elements[(ecalGsfElems.begin()->second)].clusterRef();
353 float EoPout = (clusterRef->energy())/(GsfEl->
Pout().t());
355 compatibleEPout =
false;
357 if(compatibleEPout) {
358 ClosestEcalGsf_index = ecalGsfElems.begin()->second;
359 ecalGsf_dist = block.
dist(gsfIs[iEle],ClosestEcalGsf_index,
364 std::multimap<double, unsigned int> ecalOtherGsfElems;
370 if(ecalOtherGsfElems.size()>0) {
375 if(ecalOtherGsfElems.begin()->second != gsfIs[iEle]&&
377 ecalGsf_dist = CutGSFECAL;
378 ClosestEcalGsf_index = CutIndex;
386 else if(ecalKfElems.size() > 0) {
387 if(localactive[(ecalKfElems.begin()->second)] ==
true) {
388 ClosestEcalGsf_index = ecalKfElems.begin()->second;
389 ecalGsf_dist = block.
dist(gsfIs[iEle],ClosestEcalGsf_index,
391 ClosestEcalWithKf =
true;
394 std::multimap<double, unsigned int> ecalOtherGsfElems;
399 if(ecalOtherGsfElems.size() > 0) {
403 if(ecalOtherGsfElems.begin()->second != gsfIs[iEle] &&
405 ecalGsf_dist = CutGSFECAL;
406 ClosestEcalGsf_index = CutIndex;
407 ClosestEcalWithKf =
false;
413 if (DebugSetLinksDetailed)
414 cout <<
" Closest Ecal to the Gsf/Kf: index " << ClosestEcalGsf_index
415 <<
" dist " << ecalGsf_dist << endl;
420 std::multimap<double, unsigned int> bremElems;
427 multimap<unsigned int,unsigned int> cleanedEcalBremElems;
428 vector<unsigned int> keyBremIndex(0);
429 unsigned int latestBrem_trajP = 0;
430 unsigned int latestBrem_index = CutIndex;
431 for(std::multimap<double, unsigned int>::iterator ieb = bremElems.begin();
432 ieb != bremElems.end(); ++ieb ) {
433 unsigned int brem_index = ieb->second;
434 if(localactive[brem_index] ==
false)
continue;
438 std::multimap<double, unsigned int> ecalBremsElems;
445 for (std::multimap<double, unsigned int>::iterator ie = ecalBremsElems.begin();
446 ie != ecalBremsElems.end();ie++) {
447 unsigned int ecalBrem_index = ie->second;
448 if(localactive[ecalBrem_index] ==
false)
continue;
451 float ecalBrem_dist = block.
dist(brem_index,ecalBrem_index,
455 if (ecalBrem_index == ClosestEcalGsf_index && (ecalBrem_dist + 0.0012) > ecalGsf_dist)
continue;
458 std::multimap<double, unsigned int> sortedBremElems;
464 bool isGoodBrem =
false;
465 unsigned int sortedBrem_index = CutIndex;
466 for (std::multimap<double, unsigned int>::iterator ibs = sortedBremElems.begin();
467 ibs != sortedBremElems.end();ibs++) {
468 unsigned int temp_sortedBrem_index = ibs->second;
469 std::multimap<double, unsigned int> sortedGsfElems;
474 bool enteredInPrimaryGsf =
false;
475 for (std::multimap<double, unsigned int>::iterator igs = sortedGsfElems.begin();
476 igs != sortedGsfElems.end();igs++) {
481 if(igs->second == gsfIs[iEle]) {
483 sortedBrem_index = temp_sortedBrem_index;
485 enteredInPrimaryGsf =
true;
489 if(enteredInPrimaryGsf)
497 std::multimap<double, unsigned int> ecalOtherGsfElems;
502 if (ecalOtherGsfElems.size() > 0) {
505 if(ecalOtherGsfElems.begin()->second != gsfIs[iEle] &&
515 elements[ecalBrem_index].clusterRef();
521 if(sortedBremEcal_deta < 0.015) {
523 cleanedEcalBremElems.insert(pair<unsigned int,unsigned int>(sortedBrem_index,ecalBrem_index));
526 if (BremTrajP > latestBrem_trajP) {
527 latestBrem_trajP = BremTrajP;
528 latestBrem_index = sortedBrem_index;
530 if (DebugSetLinksDetailed)
531 cout <<
" brem Index " << sortedBrem_index
532 <<
" associated cluster " << ecalBrem_index <<
" BremTrajP " << BremTrajP <<endl;
537 localactive[ecalBrem_index] =
false;
538 bool alreadyfound =
false;
539 for(
unsigned int ii=0;ii<keyBremIndex.size();ii++) {
540 if (sortedBrem_index == keyBremIndex[ii]) alreadyfound =
true;
542 if (alreadyfound ==
false) {
543 keyBremIndex.push_back(sortedBrem_index);
544 localactive[sortedBrem_index] =
false;
553 vector<unsigned int> GsfElemIndex(0);
554 vector<unsigned int> EcalIndex(0);
557 if (ClosestEcalGsf_index < CutIndex) {
558 GsfElemIndex.push_back(ClosestEcalGsf_index);
559 localactive[ClosestEcalGsf_index] =
false;
560 for (std::multimap<double, unsigned int>::iterator ii = ecalGsfElems.begin();
561 ii != ecalGsfElems.end();ii++) {
562 if(localactive[ii->second]) {
564 std::multimap<double, unsigned int> ecalOtherGsfElems;
569 if(ecalOtherGsfElems.size()) {
570 if(ecalOtherGsfElems.begin()->second != gsfIs[iEle])
continue;
575 float etacl = clusterRef->eta();
576 if( fabs(eta_gsf-etacl) < 0.05) {
577 GsfElemIndex.push_back(ii->second);
578 localactive[ii->second] =
false;
579 if (DebugSetLinksDetailed)
580 cout <<
" ExtraCluster From Gsf " << ii->second << endl;
617 if(GsfElemIndex.size() == 0){
618 if(latestBrem_index < CutIndex) {
619 unsigned int ckey = cleanedEcalBremElems.count(latestBrem_index);
621 unsigned int temp_cal =
622 cleanedEcalBremElems.find(latestBrem_index)->second;
623 GsfElemIndex.push_back(temp_cal);
624 if (DebugSetLinksDetailed)
625 cout <<
"******************** Gsf Cluster From Brem " << temp_cal
626 <<
" Latest Brem index " << latestBrem_index
627 <<
" ************************* " << endl;
630 pair<multimap<unsigned int,unsigned int>::iterator,multimap<unsigned int,unsigned int>::iterator>
ret;
631 ret = cleanedEcalBremElems.equal_range(latestBrem_index);
632 multimap<unsigned int,unsigned int>::iterator it;
633 for(it=ret.first; it!=ret.second; ++it) {
634 GsfElemIndex.push_back((*it).second);
635 if (DebugSetLinksDetailed)
636 cout <<
"******************** Gsf Cluster From Brem " << (*it).second
637 <<
" Latest Brem index " << latestBrem_index
638 <<
" ************************* " << endl;
642 unsigned int elToErase = 0;
643 for(
unsigned int i = 0;
i<keyBremIndex.size();
i++) {
644 if(latestBrem_index == keyBremIndex[
i]) {
648 keyBremIndex.erase(keyBremIndex.begin()+elToErase);
656 for(
unsigned int iConv=0; iConv<gsfIs.size(); iConv++) {
664 if (DebugSetLinksDetailed)
665 cout <<
" PFElectronAlgo:: I'm running on convGsfBrem " << endl;
667 float conv_dist = block.
dist(gsfIs[iConv],gsfIs[iEle],
672 std::multimap<double, unsigned int> ecalConvElems;
677 if(ecalConvElems.size() > 0) {
679 if(localactive[(ecalConvElems.begin()->second)] ==
true) {
680 if (DebugSetLinksDetailed)
681 cout <<
" PFElectronAlgo:: convGsfBrem has a ECAL cluster linked and free" << endl;
683 std::multimap<double, unsigned int> ecalOtherGsfPrimElems;
685 ecalOtherGsfPrimElems,
688 if(ecalOtherGsfPrimElems.size()>0) {
689 unsigned int gsfprimcheck_index = ecalOtherGsfPrimElems.begin()->second;
695 if (DebugSetLinksDetailed)
696 cout <<
" PFElectronAlgo: !!!!!!! convGsfBrem ECAL cluster has been stored !!!!!!! "
697 <<
" Energy " << clusterRef->energy() <<
" eta,phi " << clusterRef->position().eta()
698 <<
", " << clusterRef->position().phi() << endl;
700 GsfElemIndex.push_back(ecalConvElems.begin()->second);
701 convGsfTrack_.push_back(make_pair(ecalConvElems.begin()->second,gsfIs[iConv]));
702 localactive[ecalConvElems.begin()->second] =
false;
714 EcalIndex.insert(EcalIndex.end(),GsfElemIndex.begin(),GsfElemIndex.end());
719 for(
unsigned int i =0;
i<keyBremIndex.size();
i++) {
720 unsigned int ikey = keyBremIndex[
i];
721 unsigned int ckey = cleanedEcalBremElems.count(ikey);
722 vector<unsigned int> BremElemIndex(0);
724 unsigned int temp_cal =
725 cleanedEcalBremElems.find(ikey)->second;
726 BremElemIndex.push_back(temp_cal);
729 pair<multimap<unsigned int,unsigned int>::iterator,multimap<unsigned int,unsigned int>::iterator>
ret;
730 ret = cleanedEcalBremElems.equal_range(ikey);
731 multimap<unsigned int,unsigned int>::iterator it;
732 for(it=ret.first; it!=ret.second; ++it) {
733 BremElemIndex.push_back((*it).second);
736 EcalIndex.insert(EcalIndex.end(),BremElemIndex.begin(),BremElemIndex.end());
737 associatedToBrems_.insert(pair<
unsigned int,vector<unsigned int> >(ikey,BremElemIndex));
742 vector<unsigned int> convBremKFTrack;
743 convBremKFTrack.clear();
744 if (kfElems.size() > 0) {
745 for(std::multimap<double, unsigned int>::iterator itkf = kfElems.begin();
746 itkf != kfElems.end(); ++itkf) {
754 std::multimap<double, unsigned int> ecalConvElems;
759 if(ecalConvElems.size() > 0) {
765 float secpin = trkRef->p();
769 float eneclust =clust->
clusterRef()->energy();
775 std::multimap<double, unsigned int> hcalConvElems;
785 float enehcalclust = -1;
786 if(hcalConvElems.size() > 0) {
789 enehcalclust =clusthcal->
clusterRef()->energy();
791 if( (enehcalclust / (enehcalclust+eneclust) ) > 0.1 && Algo < 3) {
793 if(enehcalclust > eneclust)
795 if(secpin > (enehcalclust+eneclust) )
801 if(localactive[(ecalConvElems.begin()->second)] ==
false) {
803 if(isHoE || isPoHE) {
804 if (DebugSetLinksDetailed)
805 cout <<
"PFElectronAlgo:: LOCKED ECAL REJECTED TRACK FOR H/E or P/(H+E) "
806 <<
" H/H+E " << enehcalclust/(enehcalclust+eneclust)
807 <<
" H/E " << enehcalclust/eneclust
808 <<
" P/(H+E) " << secpin/(enehcalclust+eneclust)
809 <<
" HCAL ENE " << enehcalclust
810 <<
" ECAL ENE " << eneclust
811 <<
" secPIN " << secpin
812 <<
" Algo Track " << Algo << endl;
817 for(
unsigned int iecal =0; iecal < EcalIndex.size(); iecal++) {
820 if(EcalIndex[iecal] == ecalConvElems.begin()->second) {
821 if (DebugSetLinksDetailed)
822 cout <<
" PFElectronAlgo:: Conv Brem Recovery locked cluster and I will lock also the KF track " << endl;
823 convBremKFTrack.push_back(itkf->second);
832 if (DebugSetLinksDetailed)
833 cout <<
"PFElectronAlgo:: FREE ECAL REJECTED TRACK FOR H/H+E "
834 <<
" H/H+E " << (enehcalclust / (enehcalclust+eneclust) )
835 <<
" H/E " << enehcalclust/eneclust
836 <<
" P/(H+E) " << secpin/(enehcalclust+eneclust)
837 <<
" HCAL ENE " << enehcalclust
838 <<
" ECAL ENE " << eneclust
839 <<
" secPIN " << secpin
840 <<
" Algo Track " << Algo << endl;
845 std::multimap<double, unsigned int> ecalOtherKFPrimElems;
847 ecalOtherKFPrimElems,
850 if(ecalOtherKFPrimElems.size() > 0) {
854 bool isFromGSF =
false;
855 for(std::multimap<double, unsigned int>::iterator itclos = kfElems.begin();
856 itclos != kfElems.end(); ++itclos) {
857 if(ecalOtherKFPrimElems.begin()->second == itclos->second) {
867 float Epin = eneclust/secpin;
870 float totenergy = 0.;
871 for(
unsigned int ikeyecal = 0;
872 ikeyecal<EcalIndex.size(); ikeyecal++){
874 bool foundcluster =
false;
876 for(
unsigned int i2 = 0; i2<ikeyecal-1; i2++) {
877 if(EcalIndex[ikeyecal] == EcalIndex[i2])
881 if(foundcluster)
continue;
884 totenergy += clusasso->
clusterRef()->energy();
889 if(totenergy == 0.) {
890 if (DebugSetLinksDetailed)
891 cout <<
"PFElectronAlgo:: REJECTED_NULLTOT totenergy " << totenergy << endl;
897 double res_before = fabs((totenergy-Pin_gsf)/Pin_gsf);
898 double res_after = fabs(((totenergy+eneclust)-Pin_gsf)/Pin_gsf);
900 if(res_before < res_after) {
901 if (DebugSetLinksDetailed)
902 cout <<
"PFElectronAlgo::REJECTED_RES totenergy " << totenergy <<
" Pin_gsf " << Pin_gsf <<
" cluster to secondary " << eneclust
903 <<
" Res before " << res_before <<
" res_after " << res_after << endl;
908 if (DebugSetLinksDetailed)
909 cout <<
"PFElectronAlgo:: conv brem found asso to ECAL linked to a secondary KF " << endl;
910 convBremKFTrack.push_back(itkf->second);
911 GsfElemIndex.push_back(ecalConvElems.begin()->second);
912 EcalIndex.push_back(ecalConvElems.begin()->second);
913 localactive[(ecalConvElems.begin()->second)] =
false;
914 localactive[(itkf->second)] =
false;
925 double sumEtEcalInTheCone = 0.;
930 double PhiFC = clust->
clusterRef()->position().Phi();
931 double EtaFC = clust->
clusterRef()->position().Eta();
934 for(
unsigned int iEcal=0; iEcal<ecalIs.size(); iEcal++) {
935 bool foundcluster =
false;
936 for(
unsigned int ikeyecal = 0;
937 ikeyecal<EcalIndex.size(); ikeyecal++){
938 if(ecalIs[iEcal] == EcalIndex[ikeyecal])
943 if(foundcluster ==
false) {
946 double eta_clust = clustExt->
clusterRef()->position().Eta();
947 double phi_clust = clustExt->
clusterRef()->position().Phi();
948 double theta_clust = clustExt->
clusterRef()->position().Theta();
949 double deta_clust = eta_clust - EtaFC;
950 double dphi_clust = phi_clust - PhiFC;
951 if ( dphi_clust < -
M_PI )
952 dphi_clust = dphi_clust + 2.*
M_PI;
953 else if ( dphi_clust >
M_PI )
954 dphi_clust = dphi_clust - 2.*
M_PI;
955 double DR =
sqrt(deta_clust*deta_clust+
956 dphi_clust*dphi_clust);
960 vector<double> ps1Ene(0);
961 vector<double> ps2Ene(0);
965 double ET_calib = EE_calib*
sin(theta_clust);
966 sumEtEcalInTheCone += ET_calib;
972 unsigned int sumNTracksInTheCone = 0;
973 double sumPtTracksInTheCone = 0.;
974 for(
unsigned int iTrack=0; iTrack<trackIs.size(); iTrack++) {
976 if(localactive[(trackIs[iTrack])]==
true) {
981 double deta_trk = trkref->eta() - RefGSF->etaMode();
982 double dphi_trk = trkref->phi() - RefGSF->phiMode();
983 if ( dphi_trk < -
M_PI )
984 dphi_trk = dphi_trk + 2.*
M_PI;
985 else if ( dphi_trk >
M_PI )
986 dphi_trk = dphi_trk - 2.*
M_PI;
987 double DR =
sqrt(deta_trk*deta_trk+
993 if(DR < coneTrackIsoForEgammaSC_ && NValPixelHit >=3) {
994 sumNTracksInTheCone++;
995 sumPtTracksInTheCone+=trkref->pt();
1002 bool isBarrelIsolated =
false;
1003 if( fabs(EtaFC < 1.478) &&
1006 isBarrelIsolated =
true;
1009 bool isEndcapIsolated =
false;
1010 if( fabs(EtaFC >= 1.478) &&
1013 isEndcapIsolated =
true;
1017 if(DebugSetLinksDetailed) {
1018 if(fabs(EtaFC < 1.478) && isBarrelIsolated ==
false) {
1019 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND BUT FAILS ISOLATION:BARREL *** "
1020 <<
" sumEtEcalInTheCone " <<sumEtEcalInTheCone
1021 <<
" sumNTracksInTheCone " << sumNTracksInTheCone
1022 <<
" sumPtTracksInTheCone " << sumPtTracksInTheCone << endl;
1024 if(fabs(EtaFC >= 1.478) && isEndcapIsolated ==
false) {
1025 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND BUT FAILS ISOLATION:ENDCAP *** "
1026 <<
" sumEtEcalInTheCone " <<sumEtEcalInTheCone
1027 <<
" sumNTracksInTheCone " << sumNTracksInTheCone
1028 <<
" sumPtTracksInTheCone " << sumPtTracksInTheCone << endl;
1035 if(isBarrelIsolated || isEndcapIsolated ) {
1039 double totenergy = 0.;
1040 for(
unsigned int ikeyecal = 0;
1041 ikeyecal<EcalIndex.size(); ikeyecal++){
1043 bool foundcluster =
false;
1045 for(
unsigned int i2 = 0; i2<ikeyecal-1; i2++) {
1046 if(EcalIndex[ikeyecal] == EcalIndex[i2])
1047 foundcluster =
true;;
1050 if(foundcluster)
continue;
1053 totenergy += clusasso->
clusterRef()->energy();
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 std::multimap<double, unsigned int> ecalFromSuperClusterElems;
1074 ecalFromSuperClusterElems,
1077 if(ecalFromSuperClusterElems.size() > 0) {
1078 for(std::multimap<double, unsigned int>::iterator itsc = ecalFromSuperClusterElems.begin();
1079 itsc != ecalFromSuperClusterElems.end(); ++itsc) {
1080 if(localactive[itsc->second] ==
false) {
1084 std::multimap<double, unsigned int> ecalOtherKFPrimElems;
1086 ecalOtherKFPrimElems,
1089 if(ecalOtherKFPrimElems.size() > 0) {
1090 if(localactive[ecalOtherKFPrimElems.begin()->second] ==
true) {
1091 if (DebugSetLinksDetailed)
1092 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND BUT FAILS KF VETO *** " << endl;
1096 bool isInTheEtaRange =
false;
1099 double deta_clustToAdd = clustToAdd->
clusterRef()->position().Eta() - EtaFC;
1100 double ene_clustToAdd = clustToAdd->
clusterRef()->energy();
1102 if(fabs(deta_clustToAdd) < 0.05)
1103 isInTheEtaRange =
true;
1106 bool isBetterEpin =
false;
1107 if(isInTheEtaRange ==
false ) {
1108 if (DebugSetLinksDetailed)
1109 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND BUT FAILS GAMMA DETA RANGE *** "
1110 << fabs(deta_clustToAdd) << endl;
1112 if(KfGsf_index < CutIndex) {
1114 double res_before_gsf = fabs((totenergy-Pin_gsf)/Pin_gsf);
1115 double res_after_gsf = fabs(((totenergy+ene_clustToAdd)-Pin_gsf)/Pin_gsf);
1120 double Pin_kf = trackEl->
trackRef()->p();
1121 double res_before_kf = fabs((totenergy-Pin_kf)/Pin_kf);
1122 double res_after_kf = fabs(((totenergy+ene_clustToAdd)-Pin_kf)/Pin_kf);
1125 if(res_after_gsf < res_before_gsf && res_after_kf < res_before_kf ) {
1126 isBetterEpin =
true;
1129 if (DebugSetLinksDetailed)
1130 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND AND FAILS ALSO RES_EPIN"
1131 <<
" tot energy " << totenergy
1132 <<
" Pin_gsf " << Pin_gsf
1133 <<
" Pin_kf " << Pin_kf
1134 <<
" cluster from SC to ADD " << ene_clustToAdd
1135 <<
" Res before GSF " << res_before_gsf <<
" res_after_gsf " << res_after_gsf
1136 <<
" Res before KF " << res_before_kf <<
" res_after_kf " << res_after_kf << endl;
1141 if(isInTheEtaRange || isBetterEpin) {
1142 if (DebugSetLinksDetailed)
1143 cout <<
"!!!! PFElectronAlgo:: ECAL from SUPERCLUSTER FOUND !!!!! " << endl;
1144 GsfElemIndex.push_back(itsc->second);
1145 EcalIndex.push_back(itsc->second);
1146 localactive[(itsc->second)] =
false;
1155 if(KfGsf_index < CutIndex)
1156 GsfElemIndex.push_back(KfGsf_index);
1157 else if(KfGsf_secondIndex < CutIndex)
1158 GsfElemIndex.push_back(KfGsf_secondIndex);
1161 GsfElemIndex.insert(GsfElemIndex.end(),convBremKFTrack.begin(),convBremKFTrack.end());
1162 GsfElemIndex.insert(GsfElemIndex.end(),keyBremIndex.begin(),keyBremIndex.end());
1163 associatedToGsf_.insert(pair<
unsigned int, vector<unsigned int> >(gsfIs[iEle],GsfElemIndex));
1166 for(
unsigned int ikeyecal = 0;
1167 ikeyecal<EcalIndex.size(); ikeyecal++){
1170 vector<unsigned int> EcalElemsIndex(0);
1172 std::multimap<double, unsigned int> PS1Elems;
1177 for( std::multimap<double, unsigned int>::iterator it = PS1Elems.begin();
1178 it != PS1Elems.end();it++) {
1179 unsigned int index = it->second;
1180 if(localactive[index] ==
true) {
1183 std::multimap<double, unsigned> sortedECAL;
1188 unsigned jEcal = sortedECAL.begin()->second;
1189 if ( jEcal != EcalIndex[ikeyecal])
continue;
1192 EcalElemsIndex.push_back(index);
1193 localactive[
index] =
false;
1197 std::multimap<double, unsigned int> PS2Elems;
1202 for( std::multimap<double, unsigned int>::iterator it = PS2Elems.begin();
1203 it != PS2Elems.end();it++) {
1204 unsigned int index = it->second;
1205 if(localactive[index] ==
true) {
1207 std::multimap<double, unsigned> sortedECAL;
1212 unsigned jEcal = sortedECAL.begin()->second;
1213 if ( jEcal != EcalIndex[ikeyecal])
continue;
1215 EcalElemsIndex.push_back(index);
1216 localactive[
index] =
false;
1223 std::multimap<double, unsigned int> hcalGsfElems;
1228 for( std::multimap<double, unsigned int>::iterator it = hcalGsfElems.begin();
1229 it != hcalGsfElems.end();it++) {
1230 unsigned int index = it->second;
1243 EcalElemsIndex.push_back(index);
1244 localactive[
index] =
false;
1249 if(hcalGsfElems.size() == 0 && ClosestEcalWithKf ==
true) {
1250 std::multimap<double, unsigned int> hcalKfElems;
1255 for( std::multimap<double, unsigned int>::iterator it = hcalKfElems.begin();
1256 it != hcalKfElems.end();it++) {
1257 unsigned int index = it->second;
1258 if(localactive[index] ==
true) {
1261 std::multimap<double, unsigned> sortedKf;
1266 unsigned jKf = sortedKf.begin()->second;
1267 if ( jKf != KfGsf_index)
continue;
1268 EcalElemsIndex.push_back(index);
1269 localactive[
index] =
false;
1274 std::multimap<double, unsigned int> kfEtraElems;
1279 if(kfEtraElems.size() > 0) {
1280 for( std::multimap<double, unsigned int>::iterator it = kfEtraElems.begin();
1281 it != kfEtraElems.end();it++) {
1282 unsigned int index = it->second;
1290 bool thisIsAMuon =
false;
1292 if (DebugSetLinksDetailed && thisIsAMuon)
1293 cout <<
" This is a Muon: index " << index << endl;
1294 if(localactive[index] ==
true && !thisIsAMuon) {
1295 if(index != KfGsf_index) {
1298 std::multimap<double, unsigned> sortedECAL;
1303 unsigned jEcal = sortedECAL.begin()->second;
1304 if ( jEcal != EcalIndex[ikeyecal])
continue;
1305 EcalElemsIndex.push_back(index);
1306 localactive[
index] =
false;
1313 associatedToEcal_.insert(pair<
unsigned int,vector<unsigned int> >(EcalIndex[ikeyecal],EcalElemsIndex));
1322 if (DebugSetLinksSummary) {
1323 if(IsThereAGoodGSFTrack) {
1324 if (DebugSetLinksSummary)
cout <<
" -- The Link Summary --" << endl;
1325 for(
map<
unsigned int,vector<unsigned int> >::iterator it = associatedToGsf_.begin();
1326 it != associatedToGsf_.end(); it++) {
1328 if (DebugSetLinksSummary)
cout <<
" AssoGsf " << it->first << endl;
1329 vector<unsigned int> eleasso = it->second;
1330 for(
unsigned int i=0;
i<eleasso.size();
i++) {
1333 if (DebugSetLinksSummary)
1334 cout <<
" AssoGsfElements BREM " << eleasso[
i] << endl;
1337 if (DebugSetLinksSummary)
1338 cout <<
" AssoGsfElements ECAL " << eleasso[
i] << endl;
1341 if (DebugSetLinksSummary)
1342 cout <<
" AssoGsfElements KF " << eleasso[
i] << endl;
1345 if (DebugSetLinksSummary)
1346 cout <<
" AssoGsfElements ????? " << eleasso[
i] << endl;
1351 for(
map<
unsigned int,vector<unsigned int> >::iterator it = associatedToBrems_.begin();
1352 it != associatedToBrems_.end(); it++) {
1353 if (DebugSetLinksSummary)
cout <<
" AssoBrem " << it->first << endl;
1354 vector<unsigned int> eleasso = it->second;
1355 for(
unsigned int i=0;
i<eleasso.size();
i++) {
1358 if (DebugSetLinksSummary)
1359 cout <<
" AssoBremElements ECAL " << eleasso[
i] << endl;
1362 if (DebugSetLinksSummary)
1363 cout <<
" AssoBremElements ????? " << eleasso[
i] << endl;
1368 for(
map<
unsigned int,vector<unsigned int> >::iterator it = associatedToEcal_.begin();
1369 it != associatedToEcal_.end(); it++) {
1370 if (DebugSetLinksSummary)
cout <<
" AssoECAL " << it->first << endl;
1371 vector<unsigned int> eleasso = it->second;
1372 for(
unsigned int i=0;
i<eleasso.size();
i++) {
1375 if (DebugSetLinksSummary)
1376 cout <<
" AssoECALElements PS1 " << eleasso[
i] << endl;
1379 if (DebugSetLinksSummary)
1380 cout <<
" AssoECALElements PS2 " << eleasso[
i] << endl;
1383 if (DebugSetLinksSummary)
1384 cout <<
" AssoECALElements HCAL " << eleasso[
i] << endl;
1387 if (DebugSetLinksSummary)
1388 cout <<
" AssoHCALElements ????? " << eleasso[
i] << endl;
1392 if (DebugSetLinksSummary)
1393 cout <<
"-- End Summary --" << endl;
1398 return IsThereAGoodGSFTrack;
1402 AssMap& associatedToGsf_,
1403 AssMap& associatedToBrems_,
1404 AssMap& associatedToEcal_){
1409 bool DebugIDOutputs =
false;
1410 if(DebugIDOutputs)
cout <<
" ######## Enter in SetIDOutputs #########" << endl;
1412 unsigned int cgsf=0;
1413 for (
map<
unsigned int,vector<unsigned int> >::iterator igsf = associatedToGsf_.begin();
1414 igsf != associatedToGsf_.end(); igsf++,cgsf++) {
1416 float Ene_ecalgsf = 0.;
1417 float Ene_hcalgsf = 0.;
1418 double sigmaEtaEta = 0.;
1419 float deta_gsfecal = 0.;
1420 float Ene_ecalbrem = 0.;
1421 float Ene_extraecalgsf = 0.;
1422 bool LateBrem =
false;
1423 bool EarlyBrem =
false;
1424 int FirstBrem = 1000;
1425 unsigned int ecalGsf_index = 100000;
1426 unsigned int kf_index = 100000;
1427 unsigned int nhits_gsf = 0;
1434 unsigned int gsf_index = igsf->first;
1441 Ein_gsf =
sqrt(RefGSF->pMode()*
1442 RefGSF->pMode()+m_el*m_el);
1443 nhits_gsf = RefGSF->hitPattern().trackerLayersWithMeasurement();
1445 float Eout_gsf = GsfEl->
Pout().t();
1450 cout <<
" setIdOutput! GSF Track: Ein " << Ein_gsf
1451 <<
" eta,phi " << Etaout_gsf
1455 vector<unsigned int> assogsf_index = igsf->second;
1456 bool FirstEcalGsf =
true;
1457 for (
unsigned int ielegsf=0;ielegsf<assogsf_index.size();ielegsf++) {
1468 if(!isPrim)
continue;
1470 kf_index = assogsf_index[ielegsf];
1475 unsigned int keyecalgsf = assogsf_index[ielegsf];
1476 vector<unsigned int> assoecalgsf_index = associatedToEcal_.find(keyecalgsf)->second;
1478 vector<double> ps1Ene(0);
1479 vector<double> ps2Ene(0);
1480 for(
unsigned int ips =0; ips<assoecalgsf_index.size();ips++) {
1483 PFClusterRef psref = elements[(assoecalgsf_index[ips])].clusterRef();
1484 ps1Ene.push_back(psref->energy());
1487 PFClusterRef psref = elements[(assoecalgsf_index[ips])].clusterRef();
1488 ps2Ene.push_back(psref->energy());
1497 FirstEcalGsf =
false;
1498 ecalGsf_index = assogsf_index[ielegsf];
1505 posX += Ene_ecalgsf * clusterRef->position().X();
1506 posY += Ene_ecalgsf * clusterRef->position().Y();
1507 posZ += Ene_ecalgsf * clusterRef->position().Z();
1510 cout <<
" setIdOutput! GSF ECAL Cluster E " << Ene_ecalgsf
1511 <<
" eta,phi " << clusterRef->position().eta()
1512 <<
", " << clusterRef->position().phi() << endl;
1514 deta_gsfecal = clusterRef->position().eta() - Etaout_gsf;
1516 vector< const reco::PFCluster * > pfClust_vec(0);
1517 pfClust_vec.clear();
1518 pfClust_vec.push_back(&(*clusterRef));
1528 Ene_extraecalgsf += TempClus_energy;
1529 posX += TempClus_energy * clusterRef->position().X();
1530 posY += TempClus_energy * clusterRef->position().Y();
1531 posZ += TempClus_energy * clusterRef->position().Z();
1534 cout <<
" setIdOutput! Extra ECAL Cluster E "
1535 << TempClus_energy <<
" Tot " << Ene_extraecalgsf << endl;
1541 unsigned int brem_index = assogsf_index[ielegsf];
1545 if (TrajPos <= 3) EarlyBrem =
true;
1546 if (TrajPos < FirstBrem) FirstBrem = TrajPos;
1548 vector<unsigned int> assobrem_index = associatedToBrems_.find(brem_index)->second;
1549 for (
unsigned int ibrem = 0; ibrem < assobrem_index.size(); ibrem++){
1551 unsigned int keyecalbrem = assobrem_index[ibrem];
1552 vector<unsigned int> assoelebrem_index = associatedToEcal_.find(keyecalbrem)->second;
1553 vector<double> ps1EneFromBrem(0);
1554 vector<double> ps2EneFromBrem(0);
1555 for (
unsigned int ielebrem=0; ielebrem<assoelebrem_index.size();ielebrem++) {
1557 PFClusterRef psref = elements[(assoelebrem_index[ielebrem])].clusterRef();
1558 ps1EneFromBrem.push_back(psref->energy());
1561 PFClusterRef psref = elements[(assoelebrem_index[ielebrem])].clusterRef();
1562 ps2EneFromBrem.push_back(psref->energy());
1566 if( assobrem_index[ibrem] != ecalGsf_index) {
1568 elements[(assobrem_index[ibrem])].clusterRef();
1570 Ene_ecalbrem += BremClus_energy;
1571 posX += BremClus_energy * clusterRef->position().X();
1572 posY += BremClus_energy * clusterRef->position().Y();
1573 posZ += BremClus_energy * clusterRef->position().Z();
1576 if (DebugIDOutputs)
cout <<
" setIdOutput::BREM Cluster "
1577 << BremClus_energy <<
" eta,phi "
1578 << clusterRef->position().eta() <<
", "
1579 << clusterRef->position().phi() << endl;
1588 if (Ene_ecalgsf > 0.) {
1596 float Pt_gsf = RefGSF->ptMode();
1601 if(RefGSF->ptModeError() > 0.)
1604 nhit_gsf= RefGSF->hitPattern().trackerLayersWithMeasurement();
1605 chi2_gsf = RefGSF->normalizedChi2();
1614 nhit_kf= RefKF->hitPattern().trackerLayersWithMeasurement();
1615 chi2_kf = RefKF->normalizedChi2();
1624 EtotPinMode = (Ene_ecalgsf + Ene_ecalbrem + Ene_extraecalgsf) / Ein_gsf;
1643 HOverHE = Ene_hcalgsf/(Ene_hcalgsf + Ene_ecalgsf);
1678 double mvaValue =
tmvaReader_->EvaluateMVA(
"BDT");
1682 myExtra.
setMVA(mvaValue);
1700 unsigned int iextratrack = 0;
1701 unsigned int itrackHcalLinked = 0;
1702 float SumExtraKfP = 0.;
1705 double Etotal = Ene_ecalgsf + Ene_ecalbrem + Ene_extraecalgsf;
1710 double ETtotal = Etotal*
sin(sc_pflow.Theta());
1711 double phiTrack = RefGSF->phiMode();
1712 double dphi_normalsc = sc_pflow.Phi() - phiTrack;
1713 if ( dphi_normalsc < -
M_PI )
1714 dphi_normalsc = dphi_normalsc + 2.*
M_PI;
1715 else if ( dphi_normalsc >
M_PI )
1716 dphi_normalsc = dphi_normalsc - 2.*
M_PI;
1717 dphi_normalsc = fabs(dphi_normalsc);
1720 if(ecalGsf_index < 100000) {
1721 vector<unsigned int> assoecalgsf_index = associatedToEcal_.find(ecalGsf_index)->second;
1722 for(
unsigned int itrk =0; itrk<assoecalgsf_index.size();itrk++) {
1739 cout <<
" The ecalGsf cluster is not isolated: >0 KF extra with algo < 3" << endl;
1741 float p_trk = trackref->p();
1742 SumExtraKfP += p_trk;
1745 std::multimap<double, unsigned int> hcalKfElems;
1750 if(hcalKfElems.size() > 0) {
1757 if( iextratrack > 0) {
1758 if(iextratrack > 3 ||
HOverHE > 0.05 || (SumExtraKfP/Ene_ecalgsf) > 1.
1759 || (ETtotal > 50. && iextratrack > 1 && (Ene_hcalgsf/Ene_ecalgsf) > 0.1) ) {
1762 cout <<
" *****This electron candidate is discarded: Non isolated # tracks "
1763 << iextratrack <<
" HOverHE " <<
HOverHE
1764 <<
" SumExtraKfP/Ene_ecalgsf " << SumExtraKfP/Ene_ecalgsf
1765 <<
" ETtotal " << ETtotal
1766 <<
" Ene_hcalgsf/Ene_ecalgsf " << Ene_hcalgsf/Ene_ecalgsf
1775 ((EtotPinMode < 1.1 && EtotPinMode > 0.6) && (fabs(
Eta_gsf) >= 1.0 && fabs(
Eta_gsf) <= 2.0))) {
1777 (itrackHcalLinked == iextratrack) &&
1778 kf_index < 100000 ) {
1783 cout <<
" *****This electron is reactivated # tracks "
1784 << iextratrack <<
" #tracks hcal linked " << itrackHcalLinked
1785 <<
" SumExtraKfP/Ene_ecalgsf " << SumExtraKfP/Ene_ecalgsf
1787 <<
" eta gsf " << fabs(
Eta_gsf) <<
" kf index " << kf_index <<endl;
1794 cout <<
" *****This electron candidate is discarded HCAL ENERGY "
1805 cout <<
" *****This electron candidate is discarded Low ETOTPIN "
1811 if(ETtotal > 50. && dphi_normalsc > 0.1 ) {
1813 cout <<
" *****This electron candidate is discarded Large ANGLE "
1814 <<
" ETtotal " << ETtotal <<
" EGsfPoutMode " << dphi_normalsc << endl;
1820 if (DebugIDOutputs) {
1821 cout <<
" **** BDT observables ****" << endl;
1822 cout <<
" < Normalization > " << endl;
1824 <<
" Eta_gsf " <<
Eta_gsf << endl;
1825 cout <<
" < PureTracking > " << endl;
1832 <<
" nhit_kf " <<
nhit_kf << endl;
1833 cout <<
" < track-ecal-hcal-ps " << endl;
1843 cout <<
" !!!!!!!!!!!!!!!! the BDT output !!!!!!!!!!!!!!!!!: direct " << mvaValue
1844 <<
" corrected " <<
BDToutput_[cgsf] << endl;
1850 cout <<
" Gsf Ref isNULL " << endl;
1855 cout <<
" No clusters associated to the gsf " << endl;
1865 AssMap& associatedToGsf_,
1866 AssMap& associatedToBrems_,
1867 AssMap& associatedToEcal_){
1875 bool DebugIDCandidates =
false;
1879 unsigned int cgsf=0;
1880 for (
map<
unsigned int,vector<unsigned int> >::iterator igsf = associatedToGsf_.begin();
1881 igsf != associatedToGsf_.end(); igsf++,cgsf++) {
1882 unsigned int gsf_index = igsf->first;
1892 float dpt=0;
float dpt_kf=0;
float dpt_gsf=0;
float dpt_mean=0;
1893 float Eene=0;
float dene=0;
float Hene=0.;
1898 std::vector<float> bremEnergyVec;
1900 float de_gs = 0., de_me = 0., de_kf = 0.;
1906 float ps1TotEne = 0;
1907 float ps2TotEne = 0;
1908 vector<unsigned int> elementsToAdd(0);
1913 elementsToAdd.push_back(gsf_index);
1922 charge= RefGSF->chargeMode();
1923 nhit_gsf= RefGSF->hitPattern().trackerLayersWithMeasurement();
1925 momentum_gsf.SetPx(RefGSF->pxMode());
1926 momentum_gsf.SetPy(RefGSF->pyMode());
1927 momentum_gsf.SetPz(RefGSF->pzMode());
1928 float ENE=
sqrt(RefGSF->pMode()*
1929 RefGSF->pMode()+m_el*m_el);
1931 if( DebugIDCandidates )
1932 cout <<
"SetCandidates:: GsfTrackRef: Ene " << ENE
1933 <<
" charge " << charge <<
" nhits " << nhit_gsf <<endl;
1935 momentum_gsf.SetE(ENE);
1936 dpt_gsf=RefGSF->ptModeError()*
1937 (RefGSF->pMode()/RefGSF->ptMode());
1939 momentum_mean.SetPx(RefGSF->px());
1940 momentum_mean.SetPy(RefGSF->py());
1941 momentum_mean.SetPz(RefGSF->pz());
1942 float ENEm=
sqrt(RefGSF->p()*
1943 RefGSF->p()+m_el*m_el);
1944 momentum_mean.SetE(ENEm);
1945 dpt_mean=RefGSF->ptError()*
1946 (RefGSF->p()/RefGSF->pt());
1949 if( DebugIDCandidates )
1950 cout <<
"SetCandidates:: !!!! NULL GSF Track Ref " << endl;
1954 vector<unsigned int> assogsf_index = igsf->second;
1955 unsigned int ecalGsf_index = 100000;
1956 bool FirstEcalGsf =
true;
1957 for (
unsigned int ielegsf=0;ielegsf<assogsf_index.size();ielegsf++) {
1960 elementsToAdd.push_back((assogsf_index[ielegsf]));
1965 if(!isPrim)
continue;
1970 dpt_kf=(RefKF->ptError()*RefKF->ptError());
1971 nhit_kf=RefKF->hitPattern().trackerLayersWithMeasurement();
1972 momentum_kf.SetPx(RefKF->px());
1973 momentum_kf.SetPy(RefKF->py());
1974 momentum_kf.SetPz(RefKF->pz());
1975 float ENE=
sqrt(RefKF->p()*RefKF->p()+m_el*m_el);
1976 if( DebugIDCandidates )
1977 cout <<
"SetCandidates:: KFTrackRef: Ene " << ENE <<
" nhits " << nhit_kf << endl;
1979 momentum_kf.SetE(ENE);
1982 if( DebugIDCandidates )
1983 cout <<
"SetCandidates:: !!!! NULL KF Track Ref " << endl;
1988 unsigned int keyecalgsf = assogsf_index[ielegsf];
1989 vector<unsigned int> assoecalgsf_index = associatedToEcal_.find(keyecalgsf)->second;
1990 vector<double> ps1Ene(0);
1991 vector<double> ps2Ene(0);
1995 for(
unsigned int ips =0; ips<assoecalgsf_index.size();ips++) {
1998 PFClusterRef psref = elements[(assoecalgsf_index[ips])].clusterRef();
1999 ps1Ene.push_back(psref->energy());
2000 elementsToAdd.push_back((assoecalgsf_index[ips]));
2003 PFClusterRef psref = elements[(assoecalgsf_index[ips])].clusterRef();
2004 ps2Ene.push_back(psref->energy());
2005 elementsToAdd.push_back((assoecalgsf_index[ips]));
2010 elementsToAdd.push_back((assoecalgsf_index[ips]));
2015 elementsToAdd.push_back((assogsf_index[ielegsf]));
2033 float ceta=cl.position().eta();
2034 float cphi=cl.position().phi();
2036 float mphi=-2.97025;
2037 if (ceta<0) mphi+=0.00638;
2038 for (
int ip=1; ip<19; ip++){
2039 float df= cphi - (mphi+(ip*6.283185/18));
2040 if (fabs(df)<0.01) goodphi=
false;
2043 if( DebugIDCandidates )
2044 cout <<
"SetCandidates:: EcalCluster: EneNoCalib " << clust->
clusterRef()->energy()
2045 <<
" eta,phi " << ceta <<
"," << cphi <<
" Calib " << EE <<
" dE " << dE <<endl;
2047 bool elecCluster=
false;
2049 FirstEcalGsf =
false;
2051 ecalGsf_index = assogsf_index[ielegsf];
2059 clusterMomentum.SetPxPyPzE(EE*direction.x(),
2077 std::map<unsigned int,std::vector<reco::PFCandidate> >::iterator itcheck=
2082 std::vector<reco::PFCandidate> tmpVec;
2083 tmpVec.push_back(cluster_Candidate);
2089 itcheck->second.push_back(cluster_Candidate);
2093 posX += EE * cl.position().X();
2094 posY += EE * cl.position().Y();
2095 posZ += EE * cl.position().Z();
2105 unsigned int brem_index = assogsf_index[ielegsf];
2106 vector<unsigned int> assobrem_index = associatedToBrems_.find(brem_index)->second;
2107 elementsToAdd.push_back(brem_index);
2108 for (
unsigned int ibrem = 0; ibrem < assobrem_index.size(); ibrem++){
2111 unsigned int keyecalbrem = assobrem_index[ibrem];
2112 const vector<unsigned int>& assoelebrem_index = associatedToEcal_.find(keyecalbrem)->second;
2113 vector<double> ps1EneFromBrem(0);
2114 vector<double> ps2EneFromBrem(0);
2115 float ps1EneFromBremTot=0.;
2116 float ps2EneFromBremTot=0.;
2117 for (
unsigned int ielebrem=0; ielebrem<assoelebrem_index.size();ielebrem++) {
2119 PFClusterRef psref = elements[(assoelebrem_index[ielebrem])].clusterRef();
2120 ps1EneFromBrem.push_back(psref->energy());
2121 ps1EneFromBremTot+=psref->energy();
2122 elementsToAdd.push_back(assoelebrem_index[ielebrem]);
2125 PFClusterRef psref = elements[(assoelebrem_index[ielebrem])].clusterRef();
2126 ps2EneFromBrem.push_back(psref->energy());
2127 ps2EneFromBremTot+=psref->energy();
2128 elementsToAdd.push_back(assoelebrem_index[ielebrem]);
2133 if( assobrem_index[ibrem] != ecalGsf_index) {
2134 elementsToAdd.push_back(assobrem_index[ibrem]);
2141 bremEnergyVec.push_back(EE);
2143 float ceta = clusterRef->position().eta();
2146 if( DebugIDCandidates )
2147 cout <<
"SetCandidates:: BremCluster: Ene " << EE <<
" dE " << dE <<endl;
2150 posX += EE * clusterRef->position().X();
2151 posY += EE * clusterRef->position().Y();
2152 posZ += EE * clusterRef->position().Z();
2162 math::XYZPoint direction=clusterRef->position()/clusterRef->position().R();
2164 photonMomentum.SetPxPyPzE(EE*direction.x(),
2181 std::map<unsigned int,std::vector<reco::PFCandidate> >::iterator itcheck=
2186 std::vector<reco::PFCandidate> tmpVec;
2187 tmpVec.push_back(photon_Candidate);
2193 itcheck->second.push_back(photon_Candidate);
2203 double unCorrEene = Eene;
2204 double absEta = fabs(momentum_gsf.Eta());
2205 double emTheta = momentum_gsf.Theta();
2206 if( DebugIDCandidates )
2207 cout <<
"PFEelectronAlgo:: absEta " << absEta <<
" theta " << emTheta
2208 <<
" EneRaw " << Eene <<
" Err " << dene;
2213 double Etene = Eene*
sin(emTheta);
2215 Eene = emCorrFull_et/
sin(emTheta);
2218 double Etene = Eene*
sin(emTheta);
2220 Eene = emCorrFull_et/
sin(emTheta);
2222 dene =
sqrt(dene)*(Eene/unCorrEene);
2226 if( DebugIDCandidates )
2227 cout <<
" EneCorrected " << Eene <<
" Err " << dene << endl;
2233 if(has_kf && unCorrEene > 0.) {
2239 std::multimap<double, unsigned int> bremElems;
2245 double phiTrack = RefGSF->phiMode();
2246 if(bremElems.size()>0) {
2247 unsigned int brem_index = bremElems.begin()->second;
2253 double dphi_normalsc = sc_pflow.Phi() - phiTrack;
2254 if ( dphi_normalsc < -
M_PI )
2255 dphi_normalsc = dphi_normalsc + 2.*
M_PI;
2256 else if ( dphi_normalsc >
M_PI )
2257 dphi_normalsc = dphi_normalsc - 2.*
M_PI;
2259 int chargeGsf = RefGSF->chargeMode();
2260 int chargeKf = RefKF->charge();
2263 if(dphi_normalsc < 0.)
2268 if(chargeKf == chargeGsf)
2270 else if(chargeGsf == chargeSC)
2275 if( DebugIDCandidates )
2276 cout <<
"PFElectronAlgo:: charge determination "
2277 <<
" charge GSF " << chargeGsf
2278 <<
" charge KF " << chargeKf
2279 <<
" charge SC " << chargeSC
2280 <<
" Final Charge " << charge << endl;
2285 if ((nhit_gsf<8) && (has_kf)){
2289 momentum=momentum_kf;
2291 float scale= Fe/momentum.E();
2294 if (Eene < 0.0001) {
2300 newmomentum.SetPxPyPzE(scale*momentum.Px(),
2301 scale*momentum.Py(),
2302 scale*momentum.Pz(),Fe);
2303 if( DebugIDCandidates )
2304 cout <<
"SetCandidates:: (nhit_gsf<8) && (has_kf):: pt " << newmomentum.pt() <<
" Ene " << Fe <<endl;
2308 if ((nhit_gsf>7) || (has_kf==
false)){
2310 de_gs=1-momentum_gsf.E()/Eene;
2311 de_me=1-momentum_mean.E()/Eene;
2312 de_kf=1-momentum_kf.E()/Eene;
2315 momentum=momentum_gsf;
2316 dpt=1/(dpt_gsf*dpt_gsf);
2323 Fe =((dene*Eene) +(dpt*momentum.E()))/(dene+dpt);
2329 if ((de_gs>0.05)&&(de_kf>0.05)){
2332 if ((de_gs<-0.1)&&(de_me<-0.1) &&(de_kf<0.) &&
2333 (momentum.E()/dpt_gsf) > 5. && momentum_gsf.pt() < 30.){
2336 float scale= Fe/momentum.E();
2338 newmomentum.SetPxPyPzE(scale*momentum.Px(),
2339 scale*momentum.Py(),
2340 scale*momentum.Pz(),Fe);
2341 if( DebugIDCandidates )
2342 cout <<
"SetCandidates::(nhit_gsf>7) || (has_kf==false) " << newmomentum.pt() <<
" Ene " << Fe <<endl;
2346 if (newmomentum.pt()>0.5){
2351 if( DebugIDCandidates )
2352 cout <<
"SetCandidates:: I am before doing candidate " <<endl;
2355 std::vector<float> clusterEnergyVec;
2356 clusterEnergyVec.push_back(RawEene);
2357 clusterEnergyVec.insert(clusterEnergyVec.end(),bremEnergyVec.begin(),bremEnergyVec.end());
2360 std::vector<reco::PFCandidateElectronExtra>::iterator itextra;
2364 itextra->setClusterEnergies(clusterEnergyVec);
2368 std::cout <<
" There is a big problem with the electron extra, PFElectronAlgo should crash soon " << RawEene << std::endl;
2374 temp_Candidate =
PFCandidate(charge,newmomentum,particleType);
2387 temp_Candidate.
setVertex(RefGSF->vertex());
2390 if( DebugIDCandidates )
2391 cout <<
"SetCandidates:: I am after doing candidate " <<endl;
2393 for (
unsigned int elad=0; elad<elementsToAdd.size();elad++){
2403 std::map<unsigned int, std::vector<reco::PFCandidate> >::const_iterator itcluster=
2407 const std::vector<reco::PFCandidate> & theClusters=itcluster->second;
2408 unsigned nclus=theClusters.size();
2410 for(
unsigned iclus=0;iclus<nclus;++iclus)
2412 extendedElCandidate.
addDaughter(theClusters[iclus]);
2426 if( DebugIDCandidates )
2427 cout <<
"SetCandidates:: No Candidate Produced because of Pt cut: 0.5 " <<endl;
2432 if( DebugIDCandidates )
2433 cout <<
"SetCandidates:: No Candidate Produced because of No GSF Track Ref " <<endl;
2442 AssMap& associatedToGsf_,
2443 AssMap& associatedToBrems_,
2444 AssMap& associatedToEcal_,
2445 std::vector<bool>& active){
2451 unsigned int cgsf=0;
2452 for (
map<
unsigned int,vector<unsigned int> >::iterator igsf = associatedToGsf_.begin();
2453 igsf != associatedToGsf_.end(); igsf++,cgsf++) {
2458 unsigned int gsf_index = igsf->first;
2459 active[gsf_index] =
false;
2460 vector<unsigned int> assogsf_index = igsf->second;
2461 for (
unsigned int ielegsf=0;ielegsf<assogsf_index.size();ielegsf++) {
2464 active[(assogsf_index[ielegsf])] =
false;
2466 unsigned int keyecalgsf = assogsf_index[ielegsf];
2479 for(
unsigned int iconv = 0; iconv <
convGsfTrack_.size(); iconv++) {
2484 std::multimap<double, unsigned> convKf;
2490 if(convKf.size() > 0) {
2491 active[convKf.begin()->second] =
false;
2498 vector<unsigned int> assoecalgsf_index = associatedToEcal_.find(keyecalgsf)->second;
2499 for(
unsigned int ips =0; ips<assoecalgsf_index.size();ips++) {
2502 active[(assoecalgsf_index[ips])] =
false;
2504 active[(assoecalgsf_index[ips])] =
false;
2507 active[(assoecalgsf_index[ips])] =
false;
2513 unsigned int brem_index = assogsf_index[ielegsf];
2514 vector<unsigned int> assobrem_index = associatedToBrems_.find(brem_index)->second;
2515 for (
unsigned int ibrem = 0; ibrem < assobrem_index.size(); ibrem++){
2517 unsigned int keyecalbrem = assobrem_index[ibrem];
2519 active[(assobrem_index[ibrem])] =
false;
2530 vector<unsigned int> assoelebrem_index = associatedToEcal_.find(keyecalbrem)->second;
2532 for (
unsigned int ielebrem=0; ielebrem<assoelebrem_index.size();ielebrem++) {
2534 active[(assoelebrem_index[ielebrem])] =
false;
2536 active[(assoelebrem_index[ielebrem])] =
false;
2549 unsigned int Algo = 0;
2550 switch (trackRef->algo()) {
2551 case TrackBase::ctf:
2552 case TrackBase::iter0:
2553 case TrackBase::iter1:
2556 case TrackBase::iter2:
2559 case TrackBase::iter3:
2562 case TrackBase::iter4:
2565 case TrackBase::iter5:
2576 bool isPrimary =
false;
2582 PFRecTrackRef kfPfRef_fromGsf = (*gsfPfRef).kfPFRecTrackRef();
2587 if(kfref == kfref_fromGsf)
std::vector< std::pair< unsigned int, unsigned int > > fifthStepKfTrack_
const math::XYZTLorentzVector & Pout() const
void SetIDOutputs(const reco::PFBlockRef &blockRef, AssMap &associatedToGsf_, AssMap &associatedToBrems_, AssMap &associatedToEcal_)
void setPs2Energy(float e2)
set corrected PS2 energy
const math::XYZPointF & positionAtECALEntrance() const
std::map< unsigned int, std::vector< unsigned int > > AssMap
void setPs1Energy(float e1)
set corrected PS1 energy
tuple coneTrackIsoForEgammaSC
ParticleType
particle types
tuple coneEcalIsoForEgammaSC
tuple sumEtEcalIsoForEgammaSC_barrel
void setMVA(float val)
set the result (mostly for debugging)
void setLateBrem(float val)
set LateBrem
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
static bool isMuon(const reco::PFBlockElement &elt)
Check if a block element is a muon.
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_
PFClusterRef clusterRef() const
void setSigmaEtaEta(float val)
set the sigmaetaeta
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_
Sin< T >::type sin(const T &t)
std::map< unsigned int, Link > LinkData
tuple sumEtEcalIsoForEgammaSC_endcap
void setEarlyBrem(float val)
set EarlyBrem
const std::vector< reco::GsfElectron > * theGsfElectrons_
bool isPrimaryTrack(const reco::PFBlockElementTrack &KfEl, const reco::PFBlockElementGsfTrack &GsfEl)
const edm::OwnVector< reco::PFBlockElement > & elements() const
const LinkData & linkData() const
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float > > XYZPointF
point in space with cartesian internal representation
unsigned int indTrajPoint() const
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
double coneEcalIsoForEgammaSC_
TMVA::Reader * tmvaReader_
void set_mva_e_pi(float mva)
U second(std::pair< T, U > const &p)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
bool isNonnull() const
Checks for non-null.
void SetActive(const reco::PFBlockRef &blockRef, AssMap &associatedToGsf_, AssMap &associatedToBrems_, AssMap &associatedToEcal_, std::vector< bool > &active)
void RunPFElectron(const reco::PFBlockRef &blockRef, std::vector< bool > &active)
double getEnergyResolutionEm(double CorrectedEnergy, double eta) const
void setEcalEnergy(float ee)
set corrected Ecal energy
double pflowSigmaEtaEta() const
void addElementInBlock(const reco::PFBlockRef &blockref, unsigned elementIndex)
add an element to the current PFCandidate
reco::GsfTrackRef GsftrackRef() const
tuple nTrackIsoForEgammaSC
int numberOfValidPixelHits() const
double sumEtEcalIsoForEgammaSC_barrel_
std::vector< bool > lockExtraKf_
std::vector< double > BDToutput_
void setDeltaEta(float val)
set the delta eta
double sumEtEcalIsoForEgammaSC_endcap_
tuple sumPtTrackIsoForEgammaSC_endcap
virtual bool trackType(TrackType trType) const
block
Formating index page's pieces.
virtual void setVertex(const Point &vertex)
set vertex
double energyEm(double uncalibratedEnergyECAL, double eta=0, double phi=0) const
void addDaughter(const Candidate &, const std::string &s="")
add a clone of the passed candidate as daughter
void setRawEcalEnergy(float ee)
set corrected Ecal energy
std::map< unsigned int, std::vector< reco::PFCandidate > > electronConstituents_
void setKfTrackRef(const reco::TrackRef &ref)
set kf track reference
double sumPtTrackIsoForEgammaSC_endcap_
unsigned int whichTrackAlgo(const reco::TrackRef &trackRef)
Log< T >::type log(const T &t)
void setGsfTrackRef(const reco::GsfTrackRef &ref)
set gsftrack reference
PFRecTrackRef trackRefPF() const
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
boost::shared_ptr< PFSCEnergyCalibration > thePFSCEnergyCalibration_
tuple useEGammaSupercluster
tuple sumPtTrackIsoForEgammaSC_barrel
reco::TrackRef trackRef() const
bool SetLinks(const reco::PFBlockRef &blockRef, AssMap &associatedToGsf_, AssMap &associatedToBrems_, AssMap &associatedToEcal_, std::vector< bool > &active)
Particle reconstructed by the particle flow algorithm.
PFElectronAlgo(const double mvaEleCut, std::string mvaWeightFileEleID, const boost::shared_ptr< PFSCEnergyCalibration > &thePFSCEnergyCalibration, 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)
void setHcalEnergy(float eh)
set corrected Hcal energy
double sumPtTrackIsoForEgammaSC_barrel_
GsfPFRecTrackRef GsftrackRefPF() const
double dist(unsigned ie1, unsigned ie2, const LinkData &linkData, LinkTest test) const
unsigned int nTrackIsoForEgammaSC_
void setTrackRef(const reco::TrackRef &ref)
set track reference
void setHadEnergy(float val)
set the had energy. The cluster energies should be entered before
std::vector< reco::PFCandidate > elCandidate_
bool applyCrackCorrections_
void setEGElectronCollection(const reco::GsfElectronCollection &egelectrons)
bool useEGammaSupercluster_
std::vector< reco::PFCandidate > allElCandidate_