33 string mvaWeightFileEleID,
34 const boost::shared_ptr<PFSCEnergyCalibration>& thePFSCEnergyCalibration,
35 const boost::shared_ptr<PFEnergyCalibration>& thePFEnergyCalibration,
36 bool applyCrackCorrections,
39 bool useEGammaSupercluster,
40 double sumEtEcalIsoForEgammaSC_barrel,
41 double sumEtEcalIsoForEgammaSC_endcap,
42 double coneEcalIsoForEgammaSC,
43 double sumPtTrackIsoForEgammaSC_barrel,
44 double sumPtTrackIsoForEgammaSC_endcap,
45 unsigned int nTrackIsoForEgammaSC,
46 double coneTrackIsoForEgammaSC):
47 mvaEleCut_(mvaEleCut),
48 thePFSCEnergyCalibration_(thePFSCEnergyCalibration),
49 thePFEnergyCalibration_(thePFEnergyCalibration),
50 applyCrackCorrections_(applyCrackCorrections),
51 usePFSCEleCalib_(usePFSCEleCalib),
52 useEGElectrons_(useEGElectrons),
53 useEGammaSupercluster_(useEGammaSupercluster),
54 sumEtEcalIsoForEgammaSC_barrel_(sumEtEcalIsoForEgammaSC_barrel),
55 sumEtEcalIsoForEgammaSC_endcap_(sumEtEcalIsoForEgammaSC_endcap),
56 coneEcalIsoForEgammaSC_(coneEcalIsoForEgammaSC),
57 sumPtTrackIsoForEgammaSC_barrel_(sumPtTrackIsoForEgammaSC_barrel),
58 sumPtTrackIsoForEgammaSC_endcap_(sumPtTrackIsoForEgammaSC_endcap),
59 nTrackIsoForEgammaSC_(nTrackIsoForEgammaSC),
60 coneTrackIsoForEgammaSC_(coneTrackIsoForEgammaSC)
82 tmvaReader_->BookMVA(
"BDT",mvaWeightFileEleID.c_str());
85 std::vector<bool>& active,
102 bool blockHasGSF =
SetLinks(blockRef,associatedToGsf,
103 associatedToBrems,associatedToEcal,
104 active, primaryVertex);
113 BDToutput_.assign(associatedToGsf.size(),-1.);
117 SetIDOutputs(blockRef,associatedToGsf,associatedToBrems,associatedToEcal,primaryVertex);
122 SetCandidates(blockRef,associatedToGsf,associatedToBrems,associatedToEcal);
127 SetActive(blockRef,associatedToGsf,associatedToBrems,associatedToEcal,active);
133 AssMap& associatedToBrems_,
134 AssMap& associatedToEcal_,
135 std::vector<bool>& active,
137 unsigned int CutIndex = 100000;
138 double CutGSFECAL = 10000. ;
141 bool DebugSetLinksSummary =
false;
142 bool DebugSetLinksDetailed =
false;
148 bool IsThereAGSFTrack =
false;
149 bool IsThereAGoodGSFTrack =
false;
151 vector<unsigned int> trackIs(0);
152 vector<unsigned int> gsfIs(0);
153 vector<unsigned int> ecalIs(0);
155 std::vector<bool> localactive(elements.
size(),
true);
159 std::multimap<double, unsigned int> kfElems;
160 for(
unsigned int iEle=0; iEle<elements.
size(); iEle++) {
161 localactive[iEle] = active[iEle];
162 bool thisIsAMuon =
false;
165 case PFBlockElement::TRACK:
169 if ( !thisIsAMuon && active[iEle] ) {
170 trackIs.push_back( iEle );
171 if (DebugSetLinksDetailed)
172 cout<<
"TRACK, stored index, continue "<< iEle << endl;
175 case PFBlockElement::GSF:
181 thisIsAMuon = kfElems.size() ?
184 if ( !thisIsAMuon && active[iEle] ) {
185 IsThereAGSFTrack =
true;
186 gsfIs.push_back( iEle );
187 if (DebugSetLinksDetailed)
188 cout<<
"GSF, stored index, continue "<< iEle << endl;
192 if ( active[iEle] ) {
193 ecalIs.push_back( iEle );
194 if (DebugSetLinksDetailed)
195 cout<<
"ECAL, stored index, continue "<< iEle << endl;
204 if(IsThereAGSFTrack) {
215 if (DebugSetLinksDetailed) {
216 cout<<
"#########################################################"<<endl;
217 cout<<
"##### Process Block: #####"<<endl;
218 cout<<
"#########################################################"<<endl;
223 for(
unsigned int iEle=0; iEle<trackIs.size(); iEle++) {
224 std::multimap<double, unsigned int> gsfElems;
229 if(gsfElems.size() == 0){
232 std::multimap<double, unsigned int> ecalKfElems;
237 if(ecalKfElems.size() > 0) {
238 unsigned int ecalKf_index = ecalKfElems.begin()->second;
239 if(localactive[ecalKf_index]==
true) {
243 bool isGsfLinked =
false;
244 for(
unsigned int iGsf=0; iGsf<gsfIs.size(); iGsf++) {
252 std::multimap<double, unsigned int> ecalGsfElems;
257 if(ecalGsfElems.size() > 0) {
258 if (ecalGsfElems.begin()->second == ecalKf_index) {
263 if(isGsfLinked ==
false) {
270 int nexhits = refKf->trackerExpectedHitsInner().numberOfLostHits();
272 unsigned int Algo = 0;
274 Algo = refKf->algo();
276 bool trackIsFromPrimaryVertex =
false;
278 if ( (*trackIt).castTo<
TrackRef>() == refKf ) {
279 trackIsFromPrimaryVertex =
true;
284 if(Algo < 9 && nexhits == 0 && trackIsFromPrimaryVertex) {
285 localactive[ecalKf_index] =
false;
297 for(
unsigned int iEle=0; iEle<gsfIs.size(); iEle++) {
299 if (!localactive[(gsfIs[iEle])])
continue;
301 localactive[gsfIs[iEle]] =
false;
302 bool ClosestEcalWithKf =
false;
304 if (DebugSetLinksDetailed)
cout <<
" Gsf Index " << gsfIs[iEle] << endl;
311 IsThereAGoodGSFTrack =
true;
313 float etaOut_gsf = GsfEl->
Pout().eta();
314 float diffOutEcalEta = fabs(eta_gsf-etaOut_gsf);
316 float Pin_gsf = 0.01;
318 Pin_gsf = RefGSF->pMode();
322 unsigned int KfGsf_index = CutIndex;
323 unsigned int KfGsf_secondIndex = CutIndex;
324 std::multimap<double, unsigned int> kfElems;
329 std::multimap<double, unsigned int> ecalKfElems;
330 if (kfElems.size() > 0) {
334 for(std::multimap<double, unsigned int>::iterator itkf = kfElems.begin();
335 itkf != kfElems.end(); ++itkf) {
343 if(localactive[itkf->second] ==
true) {
345 KfGsf_index = itkf->second;
346 localactive[KfGsf_index] =
false;
354 KfGsf_secondIndex = itkf->second;
360 std::multimap<double, unsigned int> ecalGsfElems;
365 double ecalGsf_dist = CutGSFECAL;
366 unsigned int ClosestEcalGsf_index = CutIndex;
367 if (ecalGsfElems.size() > 0) {
368 if(localactive[(ecalGsfElems.begin()->second)] ==
true) {
370 bool compatibleEPout =
true;
371 if(diffOutEcalEta > 0.3) {
372 reco::PFClusterRef clusterRef = elements[(ecalGsfElems.begin()->second)].clusterRef();
373 float EoPout = (clusterRef->energy())/(GsfEl->
Pout().t());
375 compatibleEPout =
false;
377 if(compatibleEPout) {
378 ClosestEcalGsf_index = ecalGsfElems.begin()->second;
379 ecalGsf_dist = block.
dist(gsfIs[iEle],ClosestEcalGsf_index,
384 std::multimap<double, unsigned int> ecalOtherGsfElems;
390 if(ecalOtherGsfElems.size()>0) {
395 if(ecalOtherGsfElems.begin()->second != gsfIs[iEle]&&
397 ecalGsf_dist = CutGSFECAL;
398 ClosestEcalGsf_index = CutIndex;
406 else if(ecalKfElems.size() > 0) {
407 if(localactive[(ecalKfElems.begin()->second)] ==
true) {
408 ClosestEcalGsf_index = ecalKfElems.begin()->second;
409 ecalGsf_dist = block.
dist(gsfIs[iEle],ClosestEcalGsf_index,
411 ClosestEcalWithKf =
true;
414 std::multimap<double, unsigned int> ecalOtherGsfElems;
419 if(ecalOtherGsfElems.size() > 0) {
423 if(ecalOtherGsfElems.begin()->second != gsfIs[iEle] &&
425 ecalGsf_dist = CutGSFECAL;
426 ClosestEcalGsf_index = CutIndex;
427 ClosestEcalWithKf =
false;
433 if (DebugSetLinksDetailed)
434 cout <<
" Closest Ecal to the Gsf/Kf: index " << ClosestEcalGsf_index
435 <<
" dist " << ecalGsf_dist << endl;
440 std::multimap<double, unsigned int> bremElems;
447 multimap<unsigned int,unsigned int> cleanedEcalBremElems;
448 vector<unsigned int> keyBremIndex(0);
449 unsigned int latestBrem_trajP = 0;
450 unsigned int latestBrem_index = CutIndex;
451 for(std::multimap<double, unsigned int>::iterator ieb = bremElems.begin();
452 ieb != bremElems.end(); ++ieb ) {
453 unsigned int brem_index = ieb->second;
454 if(localactive[brem_index] ==
false)
continue;
458 std::multimap<double, unsigned int> ecalBremsElems;
465 for (std::multimap<double, unsigned int>::iterator ie = ecalBremsElems.begin();
466 ie != ecalBremsElems.end();ie++) {
467 unsigned int ecalBrem_index = ie->second;
468 if(localactive[ecalBrem_index] ==
false)
continue;
471 float ecalBrem_dist = block.
dist(brem_index,ecalBrem_index,
475 if (ecalBrem_index == ClosestEcalGsf_index && (ecalBrem_dist + 0.0012) > ecalGsf_dist)
continue;
478 std::multimap<double, unsigned int> sortedBremElems;
484 bool isGoodBrem =
false;
485 unsigned int sortedBrem_index = CutIndex;
486 for (std::multimap<double, unsigned int>::iterator ibs = sortedBremElems.begin();
487 ibs != sortedBremElems.end();ibs++) {
488 unsigned int temp_sortedBrem_index = ibs->second;
489 std::multimap<double, unsigned int> sortedGsfElems;
494 bool enteredInPrimaryGsf =
false;
495 for (std::multimap<double, unsigned int>::iterator igs = sortedGsfElems.begin();
496 igs != sortedGsfElems.end();igs++) {
501 if(igs->second == gsfIs[iEle]) {
503 sortedBrem_index = temp_sortedBrem_index;
505 enteredInPrimaryGsf =
true;
509 if(enteredInPrimaryGsf)
517 std::multimap<double, unsigned int> ecalOtherGsfElems;
522 if (ecalOtherGsfElems.size() > 0) {
525 if(ecalOtherGsfElems.begin()->second != gsfIs[iEle] &&
535 elements[ecalBrem_index].clusterRef();
541 if(sortedBremEcal_deta < 0.015) {
543 cleanedEcalBremElems.insert(pair<unsigned int,unsigned int>(sortedBrem_index,ecalBrem_index));
546 if (BremTrajP > latestBrem_trajP) {
547 latestBrem_trajP = BremTrajP;
548 latestBrem_index = sortedBrem_index;
550 if (DebugSetLinksDetailed)
551 cout <<
" brem Index " << sortedBrem_index
552 <<
" associated cluster " << ecalBrem_index <<
" BremTrajP " << BremTrajP <<endl;
557 localactive[ecalBrem_index] =
false;
558 bool alreadyfound =
false;
559 for(
unsigned int ii=0;
ii<keyBremIndex.size();
ii++) {
560 if (sortedBrem_index == keyBremIndex[
ii]) alreadyfound =
true;
562 if (alreadyfound ==
false) {
563 keyBremIndex.push_back(sortedBrem_index);
564 localactive[sortedBrem_index] =
false;
573 vector<unsigned int> GsfElemIndex(0);
574 vector<unsigned int> EcalIndex(0);
577 if (ClosestEcalGsf_index < CutIndex) {
578 GsfElemIndex.push_back(ClosestEcalGsf_index);
579 localactive[ClosestEcalGsf_index] =
false;
580 for (std::multimap<double, unsigned int>::iterator
ii = ecalGsfElems.begin();
581 ii != ecalGsfElems.end();
ii++) {
582 if(localactive[
ii->second]) {
584 std::multimap<double, unsigned int> ecalOtherGsfElems;
589 if(ecalOtherGsfElems.size()) {
590 if(ecalOtherGsfElems.begin()->second != gsfIs[iEle])
continue;
595 float etacl = clusterRef->eta();
596 if( fabs(eta_gsf-etacl) < 0.05) {
597 GsfElemIndex.push_back(
ii->second);
598 localactive[
ii->second] =
false;
599 if (DebugSetLinksDetailed)
600 cout <<
" ExtraCluster From Gsf " <<
ii->second << endl;
637 if(GsfElemIndex.size() == 0){
638 if(latestBrem_index < CutIndex) {
639 unsigned int ckey = cleanedEcalBremElems.count(latestBrem_index);
641 unsigned int temp_cal =
642 cleanedEcalBremElems.find(latestBrem_index)->second;
643 GsfElemIndex.push_back(temp_cal);
644 if (DebugSetLinksDetailed)
645 cout <<
"******************** Gsf Cluster From Brem " << temp_cal
646 <<
" Latest Brem index " << latestBrem_index
647 <<
" ************************* " << endl;
650 pair<multimap<unsigned int,unsigned int>::iterator,multimap<unsigned int,unsigned int>::iterator>
ret;
651 ret = cleanedEcalBremElems.equal_range(latestBrem_index);
652 multimap<unsigned int,unsigned int>::iterator it;
653 for(it=ret.first; it!=ret.second; ++it) {
654 GsfElemIndex.push_back((*it).second);
655 if (DebugSetLinksDetailed)
656 cout <<
"******************** Gsf Cluster From Brem " << (*it).second
657 <<
" Latest Brem index " << latestBrem_index
658 <<
" ************************* " << endl;
662 unsigned int elToErase = 0;
663 for(
unsigned int i = 0;
i<keyBremIndex.size();
i++) {
664 if(latestBrem_index == keyBremIndex[
i]) {
668 keyBremIndex.erase(keyBremIndex.begin()+elToErase);
676 for(
unsigned int iConv=0; iConv<gsfIs.size(); iConv++) {
684 if (DebugSetLinksDetailed)
685 cout <<
" PFElectronAlgo:: I'm running on convGsfBrem " << endl;
687 float conv_dist = block.
dist(gsfIs[iConv],gsfIs[iEle],
692 std::multimap<double, unsigned int> ecalConvElems;
697 if(ecalConvElems.size() > 0) {
699 if(localactive[(ecalConvElems.begin()->second)] ==
true) {
700 if (DebugSetLinksDetailed)
701 cout <<
" PFElectronAlgo:: convGsfBrem has a ECAL cluster linked and free" << endl;
703 std::multimap<double, unsigned int> ecalOtherGsfPrimElems;
705 ecalOtherGsfPrimElems,
708 if(ecalOtherGsfPrimElems.size()>0) {
709 unsigned int gsfprimcheck_index = ecalOtherGsfPrimElems.begin()->second;
715 if (DebugSetLinksDetailed)
716 cout <<
" PFElectronAlgo: !!!!!!! convGsfBrem ECAL cluster has been stored !!!!!!! "
717 <<
" Energy " << clusterRef->energy() <<
" eta,phi " << clusterRef->position().eta()
718 <<
", " << clusterRef->position().phi() << endl;
720 GsfElemIndex.push_back(ecalConvElems.begin()->second);
721 convGsfTrack_.push_back(make_pair(ecalConvElems.begin()->second,gsfIs[iConv]));
722 localactive[ecalConvElems.begin()->second] =
false;
734 EcalIndex.insert(EcalIndex.end(),GsfElemIndex.begin(),GsfElemIndex.end());
739 for(
unsigned int i =0;
i<keyBremIndex.size();
i++) {
740 unsigned int ikey = keyBremIndex[
i];
741 unsigned int ckey = cleanedEcalBremElems.count(ikey);
742 vector<unsigned int> BremElemIndex(0);
744 unsigned int temp_cal =
745 cleanedEcalBremElems.find(ikey)->second;
746 BremElemIndex.push_back(temp_cal);
749 pair<multimap<unsigned int,unsigned int>::iterator,multimap<unsigned int,unsigned int>::iterator>
ret;
750 ret = cleanedEcalBremElems.equal_range(ikey);
751 multimap<unsigned int,unsigned int>::iterator it;
752 for(it=ret.first; it!=ret.second; ++it) {
753 BremElemIndex.push_back((*it).second);
756 EcalIndex.insert(EcalIndex.end(),BremElemIndex.begin(),BremElemIndex.end());
757 associatedToBrems_.insert(pair<
unsigned int,vector<unsigned int> >(ikey,BremElemIndex));
762 vector<unsigned int> convBremKFTrack;
763 convBremKFTrack.clear();
764 if (kfElems.size() > 0) {
765 for(std::multimap<double, unsigned int>::iterator itkf = kfElems.begin();
766 itkf != kfElems.end(); ++itkf) {
774 std::multimap<double, unsigned int> ecalConvElems;
779 if(ecalConvElems.size() > 0) {
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.size() > 0) {
809 enehcalclust =clusthcal->
clusterRef()->energy();
811 if( (enehcalclust / (enehcalclust+eneclust) ) > 0.1 && Algo < 3) {
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 " << 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 " << Algo << endl;
865 std::multimap<double, unsigned int> ecalOtherKFPrimElems;
867 ecalOtherKFPrimElems,
870 if(ecalOtherKFPrimElems.size() > 0) {
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+
1013 if(DR < coneTrackIsoForEgammaSC_ && NValPixelHit >=3) {
1014 sumNTracksInTheCone++;
1015 sumPtTracksInTheCone+=trkref->pt();
1022 bool isBarrelIsolated =
false;
1023 if( fabs(EtaFC < 1.478) &&
1026 isBarrelIsolated =
true;
1029 bool isEndcapIsolated =
false;
1030 if( fabs(EtaFC >= 1.478) &&
1033 isEndcapIsolated =
true;
1037 if(DebugSetLinksDetailed) {
1038 if(fabs(EtaFC < 1.478) && isBarrelIsolated ==
false) {
1039 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND BUT FAILS ISOLATION:BARREL *** "
1040 <<
" sumEtEcalInTheCone " <<sumEtEcalInTheCone
1041 <<
" sumNTracksInTheCone " << sumNTracksInTheCone
1042 <<
" sumPtTracksInTheCone " << sumPtTracksInTheCone << endl;
1044 if(fabs(EtaFC >= 1.478) && isEndcapIsolated ==
false) {
1045 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND BUT FAILS ISOLATION:ENDCAP *** "
1046 <<
" sumEtEcalInTheCone " <<sumEtEcalInTheCone
1047 <<
" sumNTracksInTheCone " << sumNTracksInTheCone
1048 <<
" sumPtTracksInTheCone " << sumPtTracksInTheCone << endl;
1055 if(isBarrelIsolated || isEndcapIsolated ) {
1059 double totenergy = 0.;
1060 for(
unsigned int ikeyecal = 0;
1061 ikeyecal<EcalIndex.size(); ikeyecal++){
1063 bool foundcluster =
false;
1065 for(
unsigned int i2 = 0; i2<ikeyecal-1; i2++) {
1066 if(EcalIndex[ikeyecal] == EcalIndex[i2])
1067 foundcluster =
true;;
1070 if(foundcluster)
continue;
1073 totenergy += clusasso->
clusterRef()->energy();
1079 for(
unsigned int ikeyecal = 0;
1080 ikeyecal<EcalIndex.size(); ikeyecal++){
1082 bool foundcluster =
false;
1084 for(
unsigned int i2 = 0; i2<ikeyecal-1; i2++) {
1085 if(EcalIndex[ikeyecal] == EcalIndex[i2])
1086 foundcluster =
true;
1089 if(foundcluster)
continue;
1092 std::multimap<double, unsigned int> ecalFromSuperClusterElems;
1094 ecalFromSuperClusterElems,
1097 if(ecalFromSuperClusterElems.size() > 0) {
1098 for(std::multimap<double, unsigned int>::iterator itsc = ecalFromSuperClusterElems.begin();
1099 itsc != ecalFromSuperClusterElems.end(); ++itsc) {
1100 if(localactive[itsc->second] ==
false) {
1104 std::multimap<double, unsigned int> ecalOtherKFPrimElems;
1106 ecalOtherKFPrimElems,
1109 if(ecalOtherKFPrimElems.size() > 0) {
1110 if(localactive[ecalOtherKFPrimElems.begin()->second] ==
true) {
1111 if (DebugSetLinksDetailed)
1112 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND BUT FAILS KF VETO *** " << endl;
1116 bool isInTheEtaRange =
false;
1119 double deta_clustToAdd = clustToAdd->
clusterRef()->position().Eta() - EtaFC;
1120 double ene_clustToAdd = clustToAdd->
clusterRef()->energy();
1122 if(fabs(deta_clustToAdd) < 0.05)
1123 isInTheEtaRange =
true;
1126 bool isBetterEpin =
false;
1127 if(isInTheEtaRange ==
false ) {
1128 if (DebugSetLinksDetailed)
1129 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND BUT FAILS GAMMA DETA RANGE *** "
1130 << fabs(deta_clustToAdd) << endl;
1132 if(KfGsf_index < CutIndex) {
1134 double res_before_gsf = fabs((totenergy-Pin_gsf)/Pin_gsf);
1135 double res_after_gsf = fabs(((totenergy+ene_clustToAdd)-Pin_gsf)/Pin_gsf);
1140 double Pin_kf = trackEl->
trackRef()->p();
1141 double res_before_kf = fabs((totenergy-Pin_kf)/Pin_kf);
1142 double res_after_kf = fabs(((totenergy+ene_clustToAdd)-Pin_kf)/Pin_kf);
1145 if(res_after_gsf < res_before_gsf && res_after_kf < res_before_kf ) {
1146 isBetterEpin =
true;
1149 if (DebugSetLinksDetailed)
1150 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND AND FAILS ALSO RES_EPIN"
1151 <<
" tot energy " << totenergy
1152 <<
" Pin_gsf " << Pin_gsf
1153 <<
" Pin_kf " << Pin_kf
1154 <<
" cluster from SC to ADD " << ene_clustToAdd
1155 <<
" Res before GSF " << res_before_gsf <<
" res_after_gsf " << res_after_gsf
1156 <<
" Res before KF " << res_before_kf <<
" res_after_kf " << res_after_kf << endl;
1161 if(isInTheEtaRange || isBetterEpin) {
1162 if (DebugSetLinksDetailed)
1163 cout <<
"!!!! PFElectronAlgo:: ECAL from SUPERCLUSTER FOUND !!!!! " << endl;
1164 GsfElemIndex.push_back(itsc->second);
1165 EcalIndex.push_back(itsc->second);
1166 localactive[(itsc->second)] =
false;
1175 if(KfGsf_index < CutIndex)
1176 GsfElemIndex.push_back(KfGsf_index);
1177 else if(KfGsf_secondIndex < CutIndex)
1178 GsfElemIndex.push_back(KfGsf_secondIndex);
1181 GsfElemIndex.insert(GsfElemIndex.end(),convBremKFTrack.begin(),convBremKFTrack.end());
1182 GsfElemIndex.insert(GsfElemIndex.end(),keyBremIndex.begin(),keyBremIndex.end());
1183 associatedToGsf_.insert(pair<
unsigned int, vector<unsigned int> >(gsfIs[iEle],GsfElemIndex));
1186 for(
unsigned int ikeyecal = 0;
1187 ikeyecal<EcalIndex.size(); ikeyecal++){
1190 vector<unsigned int> EcalElemsIndex(0);
1192 std::multimap<double, unsigned int> PS1Elems;
1197 for( std::multimap<double, unsigned int>::iterator it = PS1Elems.begin();
1198 it != PS1Elems.end();it++) {
1199 unsigned int index = it->second;
1200 if(localactive[index] ==
true) {
1203 std::multimap<double, unsigned> sortedECAL;
1208 unsigned jEcal = sortedECAL.begin()->second;
1209 if ( jEcal != EcalIndex[ikeyecal])
continue;
1212 EcalElemsIndex.push_back(index);
1213 localactive[
index] =
false;
1217 std::multimap<double, unsigned int> PS2Elems;
1222 for( std::multimap<double, unsigned int>::iterator it = PS2Elems.begin();
1223 it != PS2Elems.end();it++) {
1224 unsigned int index = it->second;
1225 if(localactive[index] ==
true) {
1227 std::multimap<double, unsigned> sortedECAL;
1232 unsigned jEcal = sortedECAL.begin()->second;
1233 if ( jEcal != EcalIndex[ikeyecal])
continue;
1235 EcalElemsIndex.push_back(index);
1236 localactive[
index] =
false;
1243 std::multimap<double, unsigned int> hcalGsfElems;
1248 for( std::multimap<double, unsigned int>::iterator it = hcalGsfElems.begin();
1249 it != hcalGsfElems.end();it++) {
1250 unsigned int index = it->second;
1263 EcalElemsIndex.push_back(index);
1264 localactive[
index] =
false;
1269 if(hcalGsfElems.size() == 0 && ClosestEcalWithKf ==
true) {
1270 std::multimap<double, unsigned int> hcalKfElems;
1275 for( std::multimap<double, unsigned int>::iterator it = hcalKfElems.begin();
1276 it != hcalKfElems.end();it++) {
1277 unsigned int index = it->second;
1278 if(localactive[index] ==
true) {
1281 std::multimap<double, unsigned> sortedKf;
1286 unsigned jKf = sortedKf.begin()->second;
1287 if ( jKf != KfGsf_index)
continue;
1288 EcalElemsIndex.push_back(index);
1289 localactive[
index] =
false;
1294 std::multimap<double, unsigned int> kfEtraElems;
1299 if(kfEtraElems.size() > 0) {
1300 for( std::multimap<double, unsigned int>::iterator it = kfEtraElems.begin();
1301 it != kfEtraElems.end();it++) {
1302 unsigned int index = it->second;
1310 bool thisIsAMuon =
false;
1312 if (DebugSetLinksDetailed && thisIsAMuon)
1313 cout <<
" This is a Muon: index " << index << endl;
1314 if(localactive[index] ==
true && !thisIsAMuon) {
1315 if(index != KfGsf_index) {
1318 std::multimap<double, unsigned> sortedECAL;
1323 unsigned jEcal = sortedECAL.begin()->second;
1324 if ( jEcal != EcalIndex[ikeyecal])
continue;
1325 EcalElemsIndex.push_back(index);
1326 localactive[
index] =
false;
1333 associatedToEcal_.insert(pair<
unsigned int,vector<unsigned int> >(EcalIndex[ikeyecal],EcalElemsIndex));
1342 if (DebugSetLinksSummary) {
1343 if(IsThereAGoodGSFTrack) {
1344 if (DebugSetLinksSummary)
cout <<
" -- The Link Summary --" << endl;
1345 for(
map<
unsigned int,vector<unsigned int> >::iterator it = associatedToGsf_.begin();
1346 it != associatedToGsf_.end(); it++) {
1348 if (DebugSetLinksSummary)
cout <<
" AssoGsf " << it->first << endl;
1349 vector<unsigned int> eleasso = it->second;
1350 for(
unsigned int i=0;
i<eleasso.size();
i++) {
1353 if (DebugSetLinksSummary)
1354 cout <<
" AssoGsfElements BREM " << eleasso[
i] << endl;
1357 if (DebugSetLinksSummary)
1358 cout <<
" AssoGsfElements ECAL " << eleasso[
i] << endl;
1361 if (DebugSetLinksSummary)
1362 cout <<
" AssoGsfElements KF " << eleasso[
i] << endl;
1365 if (DebugSetLinksSummary)
1366 cout <<
" AssoGsfElements ????? " << eleasso[
i] << endl;
1371 for(
map<
unsigned int,vector<unsigned int> >::iterator it = associatedToBrems_.begin();
1372 it != associatedToBrems_.end(); it++) {
1373 if (DebugSetLinksSummary)
cout <<
" AssoBrem " << it->first << endl;
1374 vector<unsigned int> eleasso = it->second;
1375 for(
unsigned int i=0;
i<eleasso.size();
i++) {
1378 if (DebugSetLinksSummary)
1379 cout <<
" AssoBremElements ECAL " << eleasso[
i] << endl;
1382 if (DebugSetLinksSummary)
1383 cout <<
" AssoBremElements ????? " << eleasso[
i] << endl;
1388 for(
map<
unsigned int,vector<unsigned int> >::iterator it = associatedToEcal_.begin();
1389 it != associatedToEcal_.end(); it++) {
1390 if (DebugSetLinksSummary)
cout <<
" AssoECAL " << it->first << endl;
1391 vector<unsigned int> eleasso = it->second;
1392 for(
unsigned int i=0;
i<eleasso.size();
i++) {
1395 if (DebugSetLinksSummary)
1396 cout <<
" AssoECALElements PS1 " << eleasso[
i] << endl;
1399 if (DebugSetLinksSummary)
1400 cout <<
" AssoECALElements PS2 " << eleasso[
i] << endl;
1403 if (DebugSetLinksSummary)
1404 cout <<
" AssoECALElements HCAL " << eleasso[
i] << endl;
1407 if (DebugSetLinksSummary)
1408 cout <<
" AssoHCALElements ????? " << eleasso[
i] << endl;
1412 if (DebugSetLinksSummary)
1413 cout <<
"-- End Summary --" << endl;
1418 return IsThereAGoodGSFTrack;
1422 AssMap& associatedToGsf_,
1423 AssMap& associatedToBrems_,
1424 AssMap& associatedToEcal_,
1430 bool DebugIDOutputs =
false;
1431 if(DebugIDOutputs)
cout <<
" ######## Enter in SetIDOutputs #########" << endl;
1433 unsigned int cgsf=0;
1434 for (
map<
unsigned int,vector<unsigned int> >::iterator igsf = associatedToGsf_.begin();
1435 igsf != associatedToGsf_.end(); igsf++,cgsf++) {
1437 float Ene_ecalgsf = 0.;
1438 float Ene_hcalgsf = 0.;
1439 double sigmaEtaEta = 0.;
1440 float deta_gsfecal = 0.;
1441 float Ene_ecalbrem = 0.;
1442 float Ene_extraecalgsf = 0.;
1443 bool LateBrem =
false;
1445 int FirstBrem = 1000;
1446 unsigned int ecalGsf_index = 100000;
1447 unsigned int kf_index = 100000;
1455 unsigned int gsf_index = igsf->first;
1462 Ein_gsf =
sqrt(RefGSF->pMode()*
1463 RefGSF->pMode()+m_el*m_el);
1466 float Eout_gsf = GsfEl->
Pout().t();
1471 cout <<
" setIdOutput! GSF Track: Ein " << Ein_gsf
1472 <<
" eta,phi " << Etaout_gsf
1476 vector<unsigned int> assogsf_index = igsf->second;
1477 bool FirstEcalGsf =
true;
1478 for (
unsigned int ielegsf=0;ielegsf<assogsf_index.size();ielegsf++) {
1489 if(!isPrim)
continue;
1491 kf_index = assogsf_index[ielegsf];
1496 unsigned int keyecalgsf = assogsf_index[ielegsf];
1497 vector<unsigned int> assoecalgsf_index = associatedToEcal_.find(keyecalgsf)->second;
1499 vector<double> ps1Ene(0);
1500 vector<double> ps2Ene(0);
1501 for(
unsigned int ips =0; ips<assoecalgsf_index.size();ips++) {
1504 PFClusterRef psref = elements[(assoecalgsf_index[ips])].clusterRef();
1505 ps1Ene.push_back(psref->energy());
1508 PFClusterRef psref = elements[(assoecalgsf_index[ips])].clusterRef();
1509 ps2Ene.push_back(psref->energy());
1518 FirstEcalGsf =
false;
1519 ecalGsf_index = assogsf_index[ielegsf];
1526 posX += Ene_ecalgsf * clusterRef->position().X();
1527 posY += Ene_ecalgsf * clusterRef->position().Y();
1528 posZ += Ene_ecalgsf * clusterRef->position().Z();
1531 cout <<
" setIdOutput! GSF ECAL Cluster E " << Ene_ecalgsf
1532 <<
" eta,phi " << clusterRef->position().eta()
1533 <<
", " << clusterRef->position().phi() << endl;
1535 deta_gsfecal = clusterRef->position().eta() - Etaout_gsf;
1537 vector< const reco::PFCluster * > pfClust_vec(0);
1538 pfClust_vec.clear();
1539 pfClust_vec.push_back(&(*clusterRef));
1549 Ene_extraecalgsf += TempClus_energy;
1550 posX += TempClus_energy * clusterRef->position().X();
1551 posY += TempClus_energy * clusterRef->position().Y();
1552 posZ += TempClus_energy * clusterRef->position().Z();
1555 cout <<
" setIdOutput! Extra ECAL Cluster E "
1556 << TempClus_energy <<
" Tot " << Ene_extraecalgsf << endl;
1562 unsigned int brem_index = assogsf_index[ielegsf];
1567 if (TrajPos < FirstBrem) FirstBrem = TrajPos;
1569 vector<unsigned int> assobrem_index = associatedToBrems_.find(brem_index)->second;
1570 for (
unsigned int ibrem = 0; ibrem < assobrem_index.size(); ibrem++){
1572 unsigned int keyecalbrem = assobrem_index[ibrem];
1573 vector<unsigned int> assoelebrem_index = associatedToEcal_.find(keyecalbrem)->second;
1574 vector<double> ps1EneFromBrem(0);
1575 vector<double> ps2EneFromBrem(0);
1576 for (
unsigned int ielebrem=0; ielebrem<assoelebrem_index.size();ielebrem++) {
1578 PFClusterRef psref = elements[(assoelebrem_index[ielebrem])].clusterRef();
1579 ps1EneFromBrem.push_back(psref->energy());
1582 PFClusterRef psref = elements[(assoelebrem_index[ielebrem])].clusterRef();
1583 ps2EneFromBrem.push_back(psref->energy());
1587 if( assobrem_index[ibrem] != ecalGsf_index) {
1589 elements[(assobrem_index[ibrem])].clusterRef();
1591 Ene_ecalbrem += BremClus_energy;
1592 posX += BremClus_energy * clusterRef->position().X();
1593 posY += BremClus_energy * clusterRef->position().Y();
1594 posZ += BremClus_energy * clusterRef->position().Z();
1597 if (DebugIDOutputs)
cout <<
" setIdOutput::BREM Cluster "
1598 << BremClus_energy <<
" eta,phi "
1599 << clusterRef->position().eta() <<
", "
1600 << clusterRef->position().phi() << endl;
1609 if (Ene_ecalgsf > 0.) {
1617 float Pt_gsf = RefGSF->ptMode();
1622 if(RefGSF->ptModeError() > 0.)
1625 nhit_gsf= RefGSF->hitPattern().trackerLayersWithMeasurement();
1626 chi2_gsf = RefGSF->normalizedChi2();
1635 nhit_kf= RefKF->hitPattern().trackerLayersWithMeasurement();
1636 chi2_kf = RefKF->normalizedChi2();
1645 EtotPinMode = (Ene_ecalgsf + Ene_ecalbrem + Ene_extraecalgsf) / Ein_gsf;
1664 HOverHE = Ene_hcalgsf/(Ene_hcalgsf + Ene_ecalgsf);
1699 double mvaValue =
tmvaReader_->EvaluateMVA(
"BDT");
1703 myExtra.
setMVA(mvaValue);
1722 unsigned int iextratrack = 0;
1723 unsigned int itrackHcalLinked = 0;
1724 float SumExtraKfP = 0.;
1727 double Etotal = Ene_ecalgsf + Ene_ecalbrem + Ene_extraecalgsf;
1732 double ETtotal = Etotal*
sin(sc_pflow.Theta());
1733 double phiTrack = RefGSF->phiMode();
1734 double dphi_normalsc = sc_pflow.Phi() - phiTrack;
1735 if ( dphi_normalsc < -
M_PI )
1736 dphi_normalsc = dphi_normalsc + 2.*
M_PI;
1737 else if ( dphi_normalsc >
M_PI )
1738 dphi_normalsc = dphi_normalsc - 2.*
M_PI;
1739 dphi_normalsc = fabs(dphi_normalsc);
1742 if(ecalGsf_index < 100000) {
1743 vector<unsigned int> assoecalgsf_index = associatedToEcal_.find(ecalGsf_index)->second;
1744 for(
unsigned int itrk =0; itrk<assoecalgsf_index.size();itrk++) {
1759 int nexhits = trackref->trackerExpectedHitsInner().numberOfLostHits();
1761 bool trackIsFromPrimaryVertex =
false;
1763 if ( (*trackIt).castTo<
TrackRef>() == trackref ) {
1764 trackIsFromPrimaryVertex =
true;
1770 if(Algo < 3 && nexhits == 0 && trackIsFromPrimaryVertex) {
1773 cout <<
" The ecalGsf cluster is not isolated: >0 KF extra with algo < 3" << endl;
1775 float p_trk = trackref->p();
1780 cout <<
" p_trk " << p_trk
1781 <<
" nexhits " << nexhits << endl;
1783 SumExtraKfP += p_trk;
1786 std::multimap<double, unsigned int> hcalKfElems;
1791 if(hcalKfElems.size() > 0) {
1798 if( iextratrack > 0) {
1800 if(iextratrack > 3 || Ene_hcalgsf > 10 || (SumExtraKfP/Ene_ecalgsf) > 1.
1801 || (ETtotal > 50. && iextratrack > 1 && (Ene_hcalgsf/Ene_ecalgsf) > 0.1) ) {
1803 cout <<
" *****This electron candidate is discarded: Non isolated # tracks "
1804 << iextratrack <<
" HOverHE " <<
HOverHE
1805 <<
" SumExtraKfP/Ene_ecalgsf " << SumExtraKfP/Ene_ecalgsf
1806 <<
" SumExtraKfP " << SumExtraKfP
1807 <<
" Ene_ecalgsf " << Ene_ecalgsf
1808 <<
" ETtotal " << ETtotal
1809 <<
" Ene_hcalgsf/Ene_ecalgsf " << Ene_hcalgsf/Ene_ecalgsf
1818 ((EtotPinMode < 1.1 && EtotPinMode > 0.6) && (fabs(
Eta_gsf) >= 1.0 && fabs(
Eta_gsf) <= 2.0))) {
1820 (itrackHcalLinked == iextratrack) &&
1821 kf_index < 100000 ) {
1826 cout <<
" *****This electron is reactivated # tracks "
1827 << iextratrack <<
" #tracks hcal linked " << itrackHcalLinked
1828 <<
" SumExtraKfP/Ene_ecalgsf " << SumExtraKfP/Ene_ecalgsf
1830 <<
" eta gsf " << fabs(
Eta_gsf) <<
" kf index " << kf_index <<endl;
1837 cout <<
" *****This electron candidate is discarded HCAL ENERGY "
1848 cout <<
" *****This electron candidate is discarded Low ETOTPIN "
1854 if(ETtotal > 50. && dphi_normalsc > 0.1 ) {
1856 cout <<
" *****This electron candidate is discarded Large ANGLE "
1857 <<
" ETtotal " << ETtotal <<
" EGsfPoutMode " << dphi_normalsc << endl;
1863 if (DebugIDOutputs) {
1864 cout <<
" **** BDT observables ****" << endl;
1865 cout <<
" < Normalization > " << endl;
1866 cout <<
" Pt_gsf " << Pt_gsf <<
" Pin " << Ein_gsf <<
" Pout " << Eout_gsf
1867 <<
" Eta_gsf " <<
Eta_gsf << endl;
1868 cout <<
" < PureTracking > " << endl;
1875 <<
" nhit_kf " <<
nhit_kf << endl;
1876 cout <<
" < track-ecal-hcal-ps " << endl;
1882 <<
" HOverHE " <<
HOverHE <<
" Hcal energy " << Ene_hcalgsf
1886 cout <<
" !!!!!!!!!!!!!!!! the BDT output !!!!!!!!!!!!!!!!!: direct " << mvaValue
1887 <<
" corrected " <<
BDToutput_[cgsf] << endl;
1893 cout <<
" Gsf Ref isNULL " << endl;
1898 cout <<
" No clusters associated to the gsf " << endl;
1901 DebugIDOutputs =
false;
1909 AssMap& associatedToGsf_,
1910 AssMap& associatedToBrems_,
1911 AssMap& associatedToEcal_){
1919 bool DebugIDCandidates =
false;
1923 unsigned int cgsf=0;
1924 for (
map<
unsigned int,vector<unsigned int> >::iterator igsf = associatedToGsf_.begin();
1925 igsf != associatedToGsf_.end(); igsf++,cgsf++) {
1926 unsigned int gsf_index = igsf->first;
1936 float dpt=0;
float dpt_gsf=0;
1937 float Eene=0;
float dene=0;
float Hene=0.;
1942 std::vector<float> bremEnergyVec;
1944 std::vector<const PFCluster*> pfSC_Clust_vec;
1946 float de_gs = 0., de_me = 0., de_kf = 0.;
1952 float ps1TotEne = 0;
1953 float ps2TotEne = 0;
1954 vector<unsigned int> elementsToAdd(0);
1959 elementsToAdd.push_back(gsf_index);
1968 charge= RefGSF->chargeMode();
1969 nhit_gsf= RefGSF->hitPattern().trackerLayersWithMeasurement();
1971 momentum_gsf.SetPx(RefGSF->pxMode());
1972 momentum_gsf.SetPy(RefGSF->pyMode());
1973 momentum_gsf.SetPz(RefGSF->pzMode());
1974 float ENE=
sqrt(RefGSF->pMode()*
1975 RefGSF->pMode()+m_el*m_el);
1977 if( DebugIDCandidates )
1978 cout <<
"SetCandidates:: GsfTrackRef: Ene " << ENE
1979 <<
" charge " << charge <<
" nhits " << nhit_gsf <<endl;
1981 momentum_gsf.SetE(ENE);
1982 dpt_gsf=RefGSF->ptModeError()*
1983 (RefGSF->pMode()/RefGSF->ptMode());
1985 momentum_mean.SetPx(RefGSF->px());
1986 momentum_mean.SetPy(RefGSF->py());
1987 momentum_mean.SetPz(RefGSF->pz());
1988 float ENEm=
sqrt(RefGSF->p()*
1989 RefGSF->p()+m_el*m_el);
1990 momentum_mean.SetE(ENEm);
1995 if( DebugIDCandidates )
1996 cout <<
"SetCandidates:: !!!! NULL GSF Track Ref " << endl;
2000 vector<unsigned int> assogsf_index = igsf->second;
2001 unsigned int ecalGsf_index = 100000;
2002 bool FirstEcalGsf =
true;
2003 for (
unsigned int ielegsf=0;ielegsf<assogsf_index.size();ielegsf++) {
2006 elementsToAdd.push_back((assogsf_index[ielegsf]));
2011 if(!isPrim)
continue;
2017 nhit_kf=RefKF->hitPattern().trackerLayersWithMeasurement();
2018 momentum_kf.SetPx(RefKF->px());
2019 momentum_kf.SetPy(RefKF->py());
2020 momentum_kf.SetPz(RefKF->pz());
2021 float ENE=
sqrt(RefKF->p()*RefKF->p()+m_el*m_el);
2022 if( DebugIDCandidates )
2023 cout <<
"SetCandidates:: KFTrackRef: Ene " << ENE <<
" nhits " << nhit_kf << endl;
2025 momentum_kf.SetE(ENE);
2028 if( DebugIDCandidates )
2029 cout <<
"SetCandidates:: !!!! NULL KF Track Ref " << endl;
2034 unsigned int keyecalgsf = assogsf_index[ielegsf];
2035 vector<unsigned int> assoecalgsf_index = associatedToEcal_.find(keyecalgsf)->second;
2036 vector<double> ps1Ene(0);
2037 vector<double> ps2Ene(0);
2041 for(
unsigned int ips =0; ips<assoecalgsf_index.size();ips++) {
2044 PFClusterRef psref = elements[(assoecalgsf_index[ips])].clusterRef();
2045 ps1Ene.push_back(psref->energy());
2046 elementsToAdd.push_back((assoecalgsf_index[ips]));
2049 PFClusterRef psref = elements[(assoecalgsf_index[ips])].clusterRef();
2050 ps2Ene.push_back(psref->energy());
2051 elementsToAdd.push_back((assoecalgsf_index[ips]));
2056 elementsToAdd.push_back((assoecalgsf_index[ips]));
2061 elementsToAdd.push_back((assogsf_index[ielegsf]));
2079 float ceta=
cl.position().eta();
2080 float cphi=
cl.position().phi();
2093 if( DebugIDCandidates )
2094 cout <<
"SetCandidates:: EcalCluster: EneNoCalib " << clust->
clusterRef()->energy()
2095 <<
" eta,phi " << ceta <<
"," << cphi <<
" Calib " << EE <<
" dE " << dE <<endl;
2097 bool elecCluster=
false;
2099 FirstEcalGsf =
false;
2101 ecalGsf_index = assogsf_index[ielegsf];
2109 clusterMomentum.SetPxPyPzE(EE*direction.x(),
2126 std::map<unsigned int,std::vector<reco::PFCandidate> >::iterator itcheck=
2131 std::vector<reco::PFCandidate> tmpVec;
2132 tmpVec.push_back(cluster_Candidate);
2138 itcheck->second.push_back(cluster_Candidate);
2142 posX += EE *
cl.position().X();
2143 posY += EE *
cl.position().Y();
2144 posZ += EE *
cl.position().Z();
2150 pfSC_Clust_vec.push_back( &
cl );
2158 unsigned int brem_index = assogsf_index[ielegsf];
2159 vector<unsigned int> assobrem_index = associatedToBrems_.find(brem_index)->second;
2160 elementsToAdd.push_back(brem_index);
2161 for (
unsigned int ibrem = 0; ibrem < assobrem_index.size(); ibrem++){
2164 if( assobrem_index[ibrem] != ecalGsf_index) {
2165 unsigned int keyecalbrem = assobrem_index[ibrem];
2166 const vector<unsigned int>& assoelebrem_index = associatedToEcal_.find(keyecalbrem)->second;
2167 vector<double> ps1EneFromBrem(0);
2168 vector<double> ps2EneFromBrem(0);
2169 for (
unsigned int ielebrem=0; ielebrem<assoelebrem_index.size();ielebrem++) {
2171 PFClusterRef psref = elements[(assoelebrem_index[ielebrem])].clusterRef();
2172 ps1EneFromBrem.push_back(psref->energy());
2173 elementsToAdd.push_back(assoelebrem_index[ielebrem]);
2176 PFClusterRef psref = elements[(assoelebrem_index[ielebrem])].clusterRef();
2177 ps2EneFromBrem.push_back(psref->energy());
2178 elementsToAdd.push_back(assoelebrem_index[ielebrem]);
2181 elementsToAdd.push_back(assobrem_index[ibrem]);
2188 bremEnergyVec.push_back(EE);
2190 float ceta = clusterRef->position().eta();
2193 if( DebugIDCandidates )
2194 cout <<
"SetCandidates:: BremCluster: Ene " << EE <<
" dE " << dE <<endl;
2197 posX += EE * clusterRef->position().X();
2198 posY += EE * clusterRef->position().Y();
2199 posZ += EE * clusterRef->position().Z();
2207 pfSC_Clust_vec.push_back( clusterRef.
get() );
2212 math::XYZPoint direction=clusterRef->position()/clusterRef->position().R();
2214 photonMomentum.SetPxPyPzE(EE*direction.x(),
2230 std::map<unsigned int,std::vector<reco::PFCandidate> >::iterator itcheck=
2235 std::vector<reco::PFCandidate> tmpVec;
2236 tmpVec.push_back(photon_Candidate);
2242 itcheck->second.push_back(photon_Candidate);
2252 double unCorrEene = Eene;
2253 double absEta = fabs(momentum_gsf.Eta());
2254 double emTheta = momentum_gsf.Theta();
2257 pfSC_Clust_vec.clear();
2259 if( DebugIDCandidates )
2260 cout <<
"PFEelectronAlgo:: absEta " << absEta <<
" theta " << emTheta
2261 <<
" EneRaw " << Eene <<
" Err " << dene;
2267 double Etene = Eene*
sin(emTheta);
2269 double emBR_et = emBR_e*
sin(emTheta);
2271 Eene = emCorrFull_et/
sin(emTheta);
2276 double emBR_et = emBR_e*
sin(emTheta);
2278 Eene = emCorrFull_et/
sin(emTheta);
2280 dene =
sqrt(dene)*(Eene/unCorrEene);
2284 if( DebugIDCandidates )
2285 cout <<
" EneCorrected " << Eene <<
" Err " << dene << endl;
2290 if(has_kf && unCorrEene > 0.) {
2296 std::multimap<double, unsigned int> bremElems;
2302 double phiTrack = RefGSF->phiMode();
2303 if(bremElems.size()>0) {
2304 unsigned int brem_index = bremElems.begin()->second;
2310 double dphi_normalsc = sc_pflow.Phi() - phiTrack;
2311 if ( dphi_normalsc < -
M_PI )
2312 dphi_normalsc = dphi_normalsc + 2.*
M_PI;
2313 else if ( dphi_normalsc >
M_PI )
2314 dphi_normalsc = dphi_normalsc - 2.*
M_PI;
2316 int chargeGsf = RefGSF->chargeMode();
2317 int chargeKf = RefKF->charge();
2320 if(dphi_normalsc < 0.)
2325 if(chargeKf == chargeGsf)
2327 else if(chargeGsf == chargeSC)
2332 if( DebugIDCandidates )
2333 cout <<
"PFElectronAlgo:: charge determination "
2334 <<
" charge GSF " << chargeGsf
2335 <<
" charge KF " << chargeKf
2336 <<
" charge SC " << chargeSC
2337 <<
" Final Charge " << charge << endl;
2342 if ((nhit_gsf<8) && (has_kf)){
2346 momentum=momentum_kf;
2348 float scale= Fe/momentum.E();
2351 if (Eene < 0.0001) {
2357 newmomentum.SetPxPyPzE(scale*momentum.Px(),
2358 scale*momentum.Py(),
2359 scale*momentum.Pz(),Fe);
2360 if( DebugIDCandidates )
2361 cout <<
"SetCandidates:: (nhit_gsf<8) && (has_kf):: pt " << newmomentum.pt() <<
" Ene " << Fe <<endl;
2365 if ((nhit_gsf>7) || (has_kf==
false)){
2367 de_gs=1-momentum_gsf.E()/Eene;
2368 de_me=1-momentum_mean.E()/Eene;
2369 de_kf=1-momentum_kf.E()/Eene;
2372 momentum=momentum_gsf;
2373 dpt=1/(dpt_gsf*dpt_gsf);
2380 Fe =((dene*Eene) +(dpt*momentum.E()))/(dene+dpt);
2386 if ((de_gs>0.05)&&(de_kf>0.05)){
2389 if ((de_gs<-0.1)&&(de_me<-0.1) &&(de_kf<0.) &&
2390 (momentum.E()/dpt_gsf) > 5. && momentum_gsf.pt() < 30.){
2393 float scale= Fe/momentum.E();
2395 newmomentum.SetPxPyPzE(scale*momentum.Px(),
2396 scale*momentum.Py(),
2397 scale*momentum.Pz(),Fe);
2398 if( DebugIDCandidates )
2399 cout <<
"SetCandidates::(nhit_gsf>7) || (has_kf==false) " << newmomentum.pt() <<
" Ene " << Fe <<endl;
2403 if (newmomentum.pt()>0.5){
2408 if( DebugIDCandidates )
2409 cout <<
"SetCandidates:: I am before doing candidate " <<endl;
2412 std::vector<float> clusterEnergyVec;
2413 clusterEnergyVec.push_back(RawEene);
2414 clusterEnergyVec.insert(clusterEnergyVec.end(),bremEnergyVec.begin(),bremEnergyVec.end());
2417 std::vector<reco::PFCandidateElectronExtra>::iterator itextra;
2421 itextra->setClusterEnergies(clusterEnergyVec);
2425 std::cout <<
" There is a big problem with the electron extra, PFElectronAlgo should crash soon " << RawEene << std::endl;
2431 temp_Candidate =
PFCandidate(charge,newmomentum,particleType);
2448 if(seedRef.
isAvailable() && seedRef->isEcalDriven()) {
2455 if( DebugIDCandidates )
2456 cout <<
"SetCandidates:: I am after doing candidate " <<endl;
2458 for (
unsigned int elad=0; elad<elementsToAdd.size();elad++){
2463 std::map<unsigned int, std::vector<reco::PFCandidate> >::const_iterator itcluster=
2467 const std::vector<reco::PFCandidate> & theClusters=itcluster->second;
2468 unsigned nclus=theClusters.size();
2470 for(
unsigned iclus=0;iclus<nclus;++iclus)
2477 bool bypassmva=
false;
2486 if( DebugIDCandidates ) {
2488 float esceg = itcheck->caloEnergy();
2490 <<
" SuperClusterEnergy " << esceg
2491 <<
" PF Energy " << Eene << endl;
2493 cout <<
" hoe " << itcheck->hcalOverEcal()
2494 <<
" tkiso04 " << itcheck->dr04TkSumPt()
2495 <<
" ecaliso04 " << itcheck->dr04EcalRecHitSumEt()
2496 <<
" hcaliso04 " << itcheck->dr04HcalTowerSumEt()
2497 <<
" tkiso03 " << itcheck->dr03TkSumPt()
2498 <<
" ecaliso03 " << itcheck->dr03EcalRecHitSumEt()
2499 <<
" hcaliso03 " << itcheck->dr03HcalTowerSumEt() << endl;
2507 if( mvaSelected || bypassmva ) {
2510 itextra->setStatus(PFCandidateElectronExtra::Selected,
true);
2514 itextra->setStatus(PFCandidateElectronExtra::Rejected,
true);
2520 itextra->setStatus(PFCandidateElectronExtra::ECALDrivenPreselected,bypassmva);
2521 itextra->setStatus(PFCandidateElectronExtra::MVASelected,mvaSelected);
2529 if( DebugIDCandidates )
2530 cout <<
"SetCandidates:: No Candidate Produced because of Pt cut: 0.5 " <<endl;
2535 if( DebugIDCandidates )
2536 cout <<
"SetCandidates:: No Candidate Produced because of No GSF Track Ref " <<endl;
2545 AssMap& associatedToGsf_,
2546 AssMap& associatedToBrems_,
2547 AssMap& associatedToEcal_,
2548 std::vector<bool>& active){
2554 unsigned int cgsf=0;
2555 for (
map<
unsigned int,vector<unsigned int> >::iterator igsf = associatedToGsf_.begin();
2556 igsf != associatedToGsf_.end(); igsf++,cgsf++) {
2558 unsigned int gsf_index = igsf->first;
2564 bool bypassmva=
false;
2577 active[gsf_index] =
false;
2578 vector<unsigned int> assogsf_index = igsf->second;
2579 for (
unsigned int ielegsf=0;ielegsf<assogsf_index.size();ielegsf++) {
2582 active[(assogsf_index[ielegsf])] =
false;
2584 unsigned int keyecalgsf = assogsf_index[ielegsf];
2597 for(
unsigned int iconv = 0; iconv <
convGsfTrack_.size(); iconv++) {
2602 std::multimap<double, unsigned> convKf;
2608 if(convKf.size() > 0) {
2609 active[convKf.begin()->second] =
false;
2616 vector<unsigned int> assoecalgsf_index = associatedToEcal_.find(keyecalgsf)->second;
2617 for(
unsigned int ips =0; ips<assoecalgsf_index.size();ips++) {
2620 active[(assoecalgsf_index[ips])] =
false;
2622 active[(assoecalgsf_index[ips])] =
false;
2625 active[(assoecalgsf_index[ips])] =
false;
2631 unsigned int brem_index = assogsf_index[ielegsf];
2632 vector<unsigned int> assobrem_index = associatedToBrems_.find(brem_index)->second;
2633 for (
unsigned int ibrem = 0; ibrem < assobrem_index.size(); ibrem++){
2635 unsigned int keyecalbrem = assobrem_index[ibrem];
2637 active[(assobrem_index[ibrem])] =
false;
2648 vector<unsigned int> assoelebrem_index = associatedToEcal_.find(keyecalbrem)->second;
2650 for (
unsigned int ielebrem=0; ielebrem<assoelebrem_index.size();ielebrem++) {
2652 active[(assoelebrem_index[ielebrem])] =
false;
2654 active[(assoelebrem_index[ielebrem])] =
false;
2667 unsigned int Algo = 0;
2668 switch (trackRef->algo()) {
2669 case TrackBase::ctf:
2670 case TrackBase::iter0:
2671 case TrackBase::iter1:
2672 case TrackBase::iter2:
2675 case TrackBase::iter3:
2678 case TrackBase::iter4:
2681 case TrackBase::iter5:
2684 case TrackBase::iter6:
2695 bool isPrimary =
false;
2701 PFRecTrackRef kfPfRef_fromGsf = (*gsfPfRef).kfPFRecTrackRef();
2706 if(kfref == kfref_fromGsf)
std::vector< std::pair< unsigned int, unsigned int > > fifthStepKfTrack_
const math::XYZTLorentzVector & Pout() const
void setPs2Energy(float e2)
set corrected PS2 energy
const math::XYZPointF & positionAtECALEntrance() const
const reco::TrackRef & trackRef() 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
static std::vector< std::string > checklist log
ParticleType
particle types
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
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
double pflowPhiWidth() const
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 PFClusterRef & clusterRef() const
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
double pflowEtaWidth() 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 setVertexSource(PFVertexType vt)
double getEnergyResolutionEm(double CorrectedEnergy, double eta) const
double pflowSigmaEtaEta() const
void addElementInBlock(const reco::PFBlockRef &blockref, unsigned elementIndex)
add an element to the current PFCandidate
double sumEtEcalIsoForEgammaSC_barrel_
std::vector< bool > lockExtraKf_
std::vector< double > BDToutput_
void setDeltaEta(float val)
set the delta eta
double sumEtEcalIsoForEgammaSC_endcap_
void SetIDOutputs(const reco::PFBlockRef &blockRef, AssMap &associatedToGsf_, AssMap &associatedToBrems_, AssMap &associatedToEcal_, const reco::Vertex &primaryVertex)
virtual bool trackType(TrackType trType) const
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_
unsigned int whichTrackAlgo(const reco::TrackRef &trackRef)
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
boost::shared_ptr< PFSCEnergyCalibration > thePFSCEnergyCalibration_
Particle reconstructed by the particle flow algorithm.
const PFRecTrackRef & trackRefPF() const
std::vector< TrackBaseRef >::const_iterator trackRef_iterator
The iteratator for the vector<TrackRef>
int numberOfValidPixelHits() const
PFElectronAlgo(const double mvaEleCut, std::string mvaWeightFileEleID, const boost::shared_ptr< PFSCEnergyCalibration > &thePFSCEnergyCalibration, const boost::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)
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_
T const * get() const
Returns C++ pointer to the item.
void setTrackRef(const reco::TrackRef &ref)
set track reference
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
boost::shared_ptr< PFEnergyCalibration > thePFEnergyCalibration_
std::vector< reco::PFCandidate > elCandidate_
bool applyCrackCorrections_
void setEGElectronCollection(const reco::GsfElectronCollection &egelectrons)
bool useEGammaSupercluster_
std::vector< reco::PFCandidate > allElCandidate_