34 string mvaWeightFileEleID,
35 const boost::shared_ptr<PFSCEnergyCalibration>& thePFSCEnergyCalibration,
36 const boost::shared_ptr<PFEnergyCalibration>& thePFEnergyCalibration,
48 mvaEleCut_(mvaEleCut),
49 thePFSCEnergyCalibration_(thePFSCEnergyCalibration),
50 thePFEnergyCalibration_(thePFEnergyCalibration),
51 applyCrackCorrections_(applyCrackCorrections),
52 usePFSCEleCalib_(usePFSCEleCalib),
53 useEGElectrons_(useEGElectrons),
54 useEGammaSupercluster_(useEGammaSupercluster),
55 sumEtEcalIsoForEgammaSC_barrel_(sumEtEcalIsoForEgammaSC_barrel),
56 sumEtEcalIsoForEgammaSC_endcap_(sumEtEcalIsoForEgammaSC_endcap),
57 coneEcalIsoForEgammaSC_(coneEcalIsoForEgammaSC),
58 sumPtTrackIsoForEgammaSC_barrel_(sumPtTrackIsoForEgammaSC_barrel),
59 sumPtTrackIsoForEgammaSC_endcap_(sumPtTrackIsoForEgammaSC_endcap),
60 nTrackIsoForEgammaSC_(nTrackIsoForEgammaSC),
61 coneTrackIsoForEgammaSC_(coneTrackIsoForEgammaSC)
83 tmvaReader_->BookMVA(
"BDT",mvaWeightFileEleID.c_str());
86 std::vector<bool>& active,
103 bool blockHasGSF =
SetLinks(blockRef,associatedToGsf,
104 associatedToBrems,associatedToEcal,
105 active, primaryVertex);
114 BDToutput_.assign(associatedToGsf.size(),-1.);
118 SetIDOutputs(blockRef,associatedToGsf,associatedToBrems,associatedToEcal,primaryVertex);
123 SetCandidates(blockRef,associatedToGsf,associatedToBrems,associatedToEcal);
128 SetActive(blockRef,associatedToGsf,associatedToBrems,associatedToEcal,active);
134 AssMap& associatedToBrems_,
135 AssMap& associatedToEcal_,
136 std::vector<bool>& active,
138 unsigned int CutIndex = 100000;
139 double CutGSFECAL = 10000. ;
142 bool DebugSetLinksSummary =
false;
143 bool DebugSetLinksDetailed =
false;
149 bool IsThereAGSFTrack =
false;
150 bool IsThereAGoodGSFTrack =
false;
152 vector<unsigned int> trackIs(0);
153 vector<unsigned int> gsfIs(0);
154 vector<unsigned int> ecalIs(0);
156 std::vector<bool> localactive(elements.
size(),
true);
160 std::multimap<double, unsigned int> kfElems;
161 for(
unsigned int iEle=0; iEle<elements.
size(); iEle++) {
162 localactive[iEle] = active[iEle];
163 bool thisIsAMuon =
false;
166 case PFBlockElement::TRACK:
170 if ( !thisIsAMuon && active[iEle] ) {
171 trackIs.push_back( iEle );
172 if (DebugSetLinksDetailed)
173 cout<<
"TRACK, stored index, continue "<< iEle << endl;
176 case PFBlockElement::GSF:
182 thisIsAMuon = kfElems.size() ?
185 if ( !thisIsAMuon && active[iEle] ) {
186 IsThereAGSFTrack =
true;
187 gsfIs.push_back( iEle );
188 if (DebugSetLinksDetailed)
189 cout<<
"GSF, stored index, continue "<< iEle << endl;
193 if ( active[iEle] ) {
194 ecalIs.push_back( iEle );
195 if (DebugSetLinksDetailed)
196 cout<<
"ECAL, stored index, continue "<< iEle << endl;
205 if(IsThereAGSFTrack) {
216 if (DebugSetLinksDetailed) {
217 cout<<
"#########################################################"<<endl;
218 cout<<
"##### Process Block: #####"<<endl;
219 cout<<
"#########################################################"<<endl;
224 for(
unsigned int iEle=0; iEle<trackIs.size(); iEle++) {
225 std::multimap<double, unsigned int> gsfElems;
230 if(gsfElems.size() == 0){
233 std::multimap<double, unsigned int> ecalKfElems;
238 if(ecalKfElems.size() > 0) {
239 unsigned int ecalKf_index = ecalKfElems.begin()->second;
240 if(localactive[ecalKf_index]==
true) {
244 bool isGsfLinked =
false;
245 for(
unsigned int iGsf=0; iGsf<gsfIs.size(); iGsf++) {
253 std::multimap<double, unsigned int> ecalGsfElems;
258 if(ecalGsfElems.size() > 0) {
259 if (ecalGsfElems.begin()->second == ecalKf_index) {
264 if(isGsfLinked ==
false) {
271 int nexhits = refKf->hitPattern().numberOfLostHits(HitPattern::MISSING_INNER_HITS);
273 bool isGoodTrack=
false;
278 bool trackIsFromPrimaryVertex =
false;
280 if ( (*trackIt).castTo<
TrackRef>() == refKf ) {
281 trackIsFromPrimaryVertex =
true;
287 && nexhits == 0 && trackIsFromPrimaryVertex) {
288 localactive[ecalKf_index] =
false;
300 for(
unsigned int iEle=0; iEle<gsfIs.size(); iEle++) {
302 if (!localactive[(gsfIs[iEle])])
continue;
304 localactive[gsfIs[iEle]] =
false;
305 bool ClosestEcalWithKf =
false;
307 if (DebugSetLinksDetailed)
cout <<
" Gsf Index " << gsfIs[iEle] << endl;
314 IsThereAGoodGSFTrack =
true;
316 float etaOut_gsf = GsfEl->
Pout().eta();
317 float diffOutEcalEta = fabs(eta_gsf-etaOut_gsf);
319 float Pin_gsf = 0.01;
321 Pin_gsf = RefGSF->pMode();
325 unsigned int KfGsf_index = CutIndex;
326 unsigned int KfGsf_secondIndex = CutIndex;
327 std::multimap<double, unsigned int> kfElems;
332 std::multimap<double, unsigned int> ecalKfElems;
333 if (kfElems.size() > 0) {
337 for(std::multimap<double, unsigned int>::iterator itkf = kfElems.begin();
338 itkf != kfElems.end(); ++itkf) {
346 if(localactive[itkf->second] ==
true) {
348 KfGsf_index = itkf->second;
349 localactive[KfGsf_index] =
false;
357 KfGsf_secondIndex = itkf->second;
363 std::multimap<double, unsigned int> ecalGsfElems;
368 double ecalGsf_dist = CutGSFECAL;
369 unsigned int ClosestEcalGsf_index = CutIndex;
370 if (ecalGsfElems.size() > 0) {
371 if(localactive[(ecalGsfElems.begin()->second)] ==
true) {
373 bool compatibleEPout =
true;
374 if(diffOutEcalEta > 0.3) {
375 reco::PFClusterRef clusterRef = elements[(ecalGsfElems.begin()->second)].clusterRef();
376 float EoPout = (clusterRef->energy())/(GsfEl->
Pout().t());
378 compatibleEPout =
false;
380 if(compatibleEPout) {
381 ClosestEcalGsf_index = ecalGsfElems.begin()->second;
382 ecalGsf_dist = block.
dist(gsfIs[iEle],ClosestEcalGsf_index,
387 std::multimap<double, unsigned int> ecalOtherGsfElems;
393 if(ecalOtherGsfElems.size()>0) {
398 if(ecalOtherGsfElems.begin()->second != gsfIs[iEle]&&
400 ecalGsf_dist = CutGSFECAL;
401 ClosestEcalGsf_index = CutIndex;
409 else if(ecalKfElems.size() > 0) {
410 if(localactive[(ecalKfElems.begin()->second)] ==
true) {
411 ClosestEcalGsf_index = ecalKfElems.begin()->second;
412 ecalGsf_dist = block.
dist(gsfIs[iEle],ClosestEcalGsf_index,
414 ClosestEcalWithKf =
true;
417 std::multimap<double, unsigned int> ecalOtherGsfElems;
422 if(ecalOtherGsfElems.size() > 0) {
426 if(ecalOtherGsfElems.begin()->second != gsfIs[iEle] &&
428 ecalGsf_dist = CutGSFECAL;
429 ClosestEcalGsf_index = CutIndex;
430 ClosestEcalWithKf =
false;
436 if (DebugSetLinksDetailed)
437 cout <<
" Closest Ecal to the Gsf/Kf: index " << ClosestEcalGsf_index
438 <<
" dist " << ecalGsf_dist << endl;
443 std::multimap<double, unsigned int> bremElems;
450 multimap<unsigned int,unsigned int> cleanedEcalBremElems;
451 vector<unsigned int> keyBremIndex(0);
452 unsigned int latestBrem_trajP = 0;
453 unsigned int latestBrem_index = CutIndex;
454 for(std::multimap<double, unsigned int>::iterator ieb = bremElems.begin();
455 ieb != bremElems.end(); ++ieb ) {
456 unsigned int brem_index = ieb->second;
457 if(localactive[brem_index] ==
false)
continue;
461 std::multimap<double, unsigned int> ecalBremsElems;
468 for (std::multimap<double, unsigned int>::iterator ie = ecalBremsElems.begin();
469 ie != ecalBremsElems.end();ie++) {
470 unsigned int ecalBrem_index = ie->second;
471 if(localactive[ecalBrem_index] ==
false)
continue;
474 float ecalBrem_dist = block.
dist(brem_index,ecalBrem_index,
478 if (ecalBrem_index == ClosestEcalGsf_index && (ecalBrem_dist + 0.0012) > ecalGsf_dist)
continue;
481 std::multimap<double, unsigned int> sortedBremElems;
487 bool isGoodBrem =
false;
488 unsigned int sortedBrem_index = CutIndex;
489 for (std::multimap<double, unsigned int>::iterator ibs = sortedBremElems.begin();
490 ibs != sortedBremElems.end();ibs++) {
491 unsigned int temp_sortedBrem_index = ibs->second;
492 std::multimap<double, unsigned int> sortedGsfElems;
497 bool enteredInPrimaryGsf =
false;
498 for (std::multimap<double, unsigned int>::iterator igs = sortedGsfElems.begin();
499 igs != sortedGsfElems.end();igs++) {
504 if(igs->second == gsfIs[iEle]) {
506 sortedBrem_index = temp_sortedBrem_index;
508 enteredInPrimaryGsf =
true;
512 if(enteredInPrimaryGsf)
520 std::multimap<double, unsigned int> ecalOtherGsfElems;
525 if (ecalOtherGsfElems.size() > 0) {
528 if(ecalOtherGsfElems.begin()->second != gsfIs[iEle] &&
538 elements[ecalBrem_index].clusterRef();
544 if(sortedBremEcal_deta < 0.015) {
546 cleanedEcalBremElems.
insert(pair<unsigned int,unsigned int>(sortedBrem_index,ecalBrem_index));
549 if (BremTrajP > latestBrem_trajP) {
550 latestBrem_trajP = BremTrajP;
551 latestBrem_index = sortedBrem_index;
553 if (DebugSetLinksDetailed)
554 cout <<
" brem Index " << sortedBrem_index
555 <<
" associated cluster " << ecalBrem_index <<
" BremTrajP " << BremTrajP <<endl;
560 localactive[ecalBrem_index] =
false;
561 bool alreadyfound =
false;
562 for(
unsigned int ii=0;
ii<keyBremIndex.size();
ii++) {
563 if (sortedBrem_index == keyBremIndex[
ii]) alreadyfound =
true;
565 if (alreadyfound ==
false) {
566 keyBremIndex.push_back(sortedBrem_index);
567 localactive[sortedBrem_index] =
false;
576 vector<unsigned int> GsfElemIndex(0);
577 vector<unsigned int> EcalIndex(0);
580 if (ClosestEcalGsf_index < CutIndex) {
581 GsfElemIndex.push_back(ClosestEcalGsf_index);
582 localactive[ClosestEcalGsf_index] =
false;
583 for (std::multimap<double, unsigned int>::iterator
ii = ecalGsfElems.begin();
584 ii != ecalGsfElems.end();
ii++) {
585 if(localactive[
ii->second]) {
587 std::multimap<double, unsigned int> ecalOtherGsfElems;
592 if(ecalOtherGsfElems.size()) {
593 if(ecalOtherGsfElems.begin()->second != gsfIs[iEle])
continue;
598 float etacl = clusterRef->eta();
599 if( fabs(eta_gsf-etacl) < 0.05) {
600 GsfElemIndex.push_back(
ii->second);
601 localactive[
ii->second] =
false;
602 if (DebugSetLinksDetailed)
603 cout <<
" ExtraCluster From Gsf " <<
ii->second << endl;
640 if(GsfElemIndex.size() == 0){
641 if(latestBrem_index < CutIndex) {
642 unsigned int ckey = cleanedEcalBremElems.count(latestBrem_index);
644 unsigned int temp_cal =
645 cleanedEcalBremElems.find(latestBrem_index)->second;
646 GsfElemIndex.push_back(temp_cal);
647 if (DebugSetLinksDetailed)
648 cout <<
"******************** Gsf Cluster From Brem " << temp_cal
649 <<
" Latest Brem index " << latestBrem_index
650 <<
" ************************* " << endl;
653 pair<multimap<unsigned int,unsigned int>::iterator,multimap<unsigned int,unsigned int>::iterator>
ret;
654 ret = cleanedEcalBremElems.equal_range(latestBrem_index);
655 multimap<unsigned int,unsigned int>::iterator it;
656 for(it=ret.first; it!=ret.second; ++it) {
657 GsfElemIndex.push_back((*it).second);
658 if (DebugSetLinksDetailed)
659 cout <<
"******************** Gsf Cluster From Brem " << (*it).second
660 <<
" Latest Brem index " << latestBrem_index
661 <<
" ************************* " << endl;
665 unsigned int elToErase = 0;
666 for(
unsigned int i = 0;
i<keyBremIndex.size();
i++) {
667 if(latestBrem_index == keyBremIndex[
i]) {
671 keyBremIndex.erase(keyBremIndex.begin()+elToErase);
679 for(
unsigned int iConv=0; iConv<gsfIs.size(); iConv++) {
687 if (DebugSetLinksDetailed)
688 cout <<
" PFElectronAlgo:: I'm running on convGsfBrem " << endl;
690 float conv_dist = block.
dist(gsfIs[iConv],gsfIs[iEle],
695 std::multimap<double, unsigned int> ecalConvElems;
700 if(ecalConvElems.size() > 0) {
702 if(localactive[(ecalConvElems.begin()->second)] ==
true) {
703 if (DebugSetLinksDetailed)
704 cout <<
" PFElectronAlgo:: convGsfBrem has a ECAL cluster linked and free" << endl;
706 std::multimap<double, unsigned int> ecalOtherGsfPrimElems;
708 ecalOtherGsfPrimElems,
711 if(ecalOtherGsfPrimElems.size()>0) {
712 unsigned int gsfprimcheck_index = ecalOtherGsfPrimElems.begin()->second;
718 if (DebugSetLinksDetailed)
719 cout <<
" PFElectronAlgo: !!!!!!! convGsfBrem ECAL cluster has been stored !!!!!!! "
720 <<
" Energy " << clusterRef->energy() <<
" eta,phi " << clusterRef->position().eta()
721 <<
", " << clusterRef->position().phi() << endl;
723 GsfElemIndex.push_back(ecalConvElems.begin()->second);
724 convGsfTrack_.push_back(make_pair(ecalConvElems.begin()->second,gsfIs[iConv]));
725 localactive[ecalConvElems.begin()->second] =
false;
737 EcalIndex.insert(EcalIndex.end(),GsfElemIndex.begin(),GsfElemIndex.end());
742 for(
unsigned int i =0;
i<keyBremIndex.size();
i++) {
743 unsigned int ikey = keyBremIndex[
i];
744 unsigned int ckey = cleanedEcalBremElems.count(ikey);
745 vector<unsigned int> BremElemIndex(0);
747 unsigned int temp_cal =
748 cleanedEcalBremElems.find(ikey)->second;
749 BremElemIndex.push_back(temp_cal);
752 pair<multimap<unsigned int,unsigned int>::iterator,multimap<unsigned int,unsigned int>::iterator>
ret;
753 ret = cleanedEcalBremElems.equal_range(ikey);
754 multimap<unsigned int,unsigned int>::iterator it;
755 for(it=ret.first; it!=ret.second; ++it) {
756 BremElemIndex.push_back((*it).second);
759 EcalIndex.insert(EcalIndex.end(),BremElemIndex.begin(),BremElemIndex.end());
760 associatedToBrems_.insert(pair<
unsigned int,vector<unsigned int> >(ikey,BremElemIndex));
765 vector<unsigned int> convBremKFTrack;
766 convBremKFTrack.clear();
767 if (kfElems.size() > 0) {
768 for(std::multimap<double, unsigned int>::iterator itkf = kfElems.begin();
769 itkf != kfElems.end(); ++itkf) {
777 std::multimap<double, unsigned int> ecalConvElems;
782 if(ecalConvElems.size() > 0) {
787 float secpin = trkRef->p();
791 float eneclust =clust->
clusterRef()->energy();
797 std::multimap<double, unsigned int> hcalConvElems;
807 float enehcalclust = -1;
808 if(hcalConvElems.size() > 0) {
811 enehcalclust =clusthcal->
clusterRef()->energy();
813 if( (enehcalclust / (enehcalclust+eneclust) ) > 0.1 && isGoodTrack) {
815 if(enehcalclust > eneclust)
817 if(secpin > (enehcalclust+eneclust) )
823 if(localactive[(ecalConvElems.begin()->second)] ==
false) {
825 if(isHoE || isPoHE) {
826 if (DebugSetLinksDetailed)
827 cout <<
"PFElectronAlgo:: LOCKED ECAL REJECTED TRACK FOR H/E or P/(H+E) "
828 <<
" H/H+E " << enehcalclust/(enehcalclust+eneclust)
829 <<
" H/E " << enehcalclust/eneclust
830 <<
" P/(H+E) " << secpin/(enehcalclust+eneclust)
831 <<
" HCAL ENE " << enehcalclust
832 <<
" ECAL ENE " << eneclust
833 <<
" secPIN " << secpin
834 <<
" Algo Track " << trkRef->algo() << endl;
839 for(
unsigned int iecal =0; iecal < EcalIndex.size(); iecal++) {
842 if(EcalIndex[iecal] == ecalConvElems.begin()->second) {
843 if (DebugSetLinksDetailed)
844 cout <<
" PFElectronAlgo:: Conv Brem Recovery locked cluster and I will lock also the KF track " << endl;
845 convBremKFTrack.push_back(itkf->second);
854 if (DebugSetLinksDetailed)
855 cout <<
"PFElectronAlgo:: FREE ECAL REJECTED TRACK FOR H/H+E "
856 <<
" H/H+E " << (enehcalclust / (enehcalclust+eneclust) )
857 <<
" H/E " << enehcalclust/eneclust
858 <<
" P/(H+E) " << secpin/(enehcalclust+eneclust)
859 <<
" HCAL ENE " << enehcalclust
860 <<
" ECAL ENE " << eneclust
861 <<
" secPIN " << secpin
862 <<
" Algo Track " << trkRef->algo() << endl;
867 std::multimap<double, unsigned int> ecalOtherKFPrimElems;
869 ecalOtherKFPrimElems,
872 if(ecalOtherKFPrimElems.size() > 0) {
876 bool isFromGSF =
false;
877 for(std::multimap<double, unsigned int>::iterator itclos = kfElems.begin();
878 itclos != kfElems.end(); ++itclos) {
879 if(ecalOtherKFPrimElems.begin()->second == itclos->second) {
889 float Epin = eneclust/secpin;
892 float totenergy = 0.;
893 for(
unsigned int ikeyecal = 0;
894 ikeyecal<EcalIndex.size(); ikeyecal++){
896 bool foundcluster =
false;
898 for(
unsigned int i2 = 0; i2<ikeyecal-1; i2++) {
899 if(EcalIndex[ikeyecal] == EcalIndex[i2])
903 if(foundcluster)
continue;
906 totenergy += clusasso->
clusterRef()->energy();
911 if(totenergy == 0.) {
912 if (DebugSetLinksDetailed)
913 cout <<
"PFElectronAlgo:: REJECTED_NULLTOT totenergy " << totenergy << endl;
919 double res_before = fabs((totenergy-Pin_gsf)/Pin_gsf);
920 double res_after = fabs(((totenergy+eneclust)-Pin_gsf)/Pin_gsf);
922 if(res_before < res_after) {
923 if (DebugSetLinksDetailed)
924 cout <<
"PFElectronAlgo::REJECTED_RES totenergy " << totenergy <<
" Pin_gsf " << Pin_gsf <<
" cluster to secondary " << eneclust
925 <<
" Res before " << res_before <<
" res_after " << res_after << endl;
930 if (DebugSetLinksDetailed)
931 cout <<
"PFElectronAlgo:: conv brem found asso to ECAL linked to a secondary KF " << endl;
932 convBremKFTrack.push_back(itkf->second);
933 GsfElemIndex.push_back(ecalConvElems.begin()->second);
934 EcalIndex.push_back(ecalConvElems.begin()->second);
935 localactive[(ecalConvElems.begin()->second)] =
false;
936 localactive[(itkf->second)] =
false;
947 double sumEtEcalInTheCone = 0.;
952 double PhiFC = clust->
clusterRef()->position().Phi();
953 double EtaFC = clust->
clusterRef()->position().Eta();
956 for(
unsigned int iEcal=0; iEcal<ecalIs.size(); iEcal++) {
957 bool foundcluster =
false;
958 for(
unsigned int ikeyecal = 0;
959 ikeyecal<EcalIndex.size(); ikeyecal++){
960 if(ecalIs[iEcal] == EcalIndex[ikeyecal])
965 if(foundcluster ==
false) {
968 double eta_clust = clustExt->
clusterRef()->position().Eta();
969 double phi_clust = clustExt->
clusterRef()->position().Phi();
970 double theta_clust = clustExt->
clusterRef()->position().Theta();
971 double deta_clust = eta_clust - EtaFC;
972 double dphi_clust = phi_clust - PhiFC;
973 if ( dphi_clust < -
M_PI )
974 dphi_clust = dphi_clust + 2.*
M_PI;
975 else if ( dphi_clust >
M_PI )
976 dphi_clust = dphi_clust - 2.*
M_PI;
977 double DR =
sqrt(deta_clust*deta_clust+
978 dphi_clust*dphi_clust);
982 vector<double> ps1Ene(0);
983 vector<double> ps2Ene(0);
987 double ET_calib = EE_calib*
sin(theta_clust);
988 sumEtEcalInTheCone += ET_calib;
994 unsigned int sumNTracksInTheCone = 0;
995 double sumPtTracksInTheCone = 0.;
996 for(
unsigned int iTrack=0; iTrack<trackIs.size(); iTrack++) {
998 if(localactive[(trackIs[iTrack])]==
true) {
1003 double deta_trk = trkref->eta() - RefGSF->etaMode();
1004 double dphi_trk = trkref->phi() - RefGSF->phiMode();
1005 if ( dphi_trk < -
M_PI )
1006 dphi_trk = dphi_trk + 2.*
M_PI;
1007 else if ( dphi_trk >
M_PI )
1008 dphi_trk = dphi_trk - 2.*
M_PI;
1009 double DR =
sqrt(deta_trk*deta_trk+
1012 int NValPixelHit = trkref->hitPattern().numberOfValidPixelHits();
1014 if(DR < coneTrackIsoForEgammaSC_ && NValPixelHit >=3) {
1015 sumNTracksInTheCone++;
1016 sumPtTracksInTheCone+=trkref->pt();
1023 bool isBarrelIsolated =
false;
1024 if( fabs(EtaFC < 1.478) &&
1027 isBarrelIsolated =
true;
1030 bool isEndcapIsolated =
false;
1031 if( fabs(EtaFC >= 1.478) &&
1034 isEndcapIsolated =
true;
1038 if(DebugSetLinksDetailed) {
1039 if(fabs(EtaFC < 1.478) && isBarrelIsolated ==
false) {
1040 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND BUT FAILS ISOLATION:BARREL *** "
1041 <<
" sumEtEcalInTheCone " <<sumEtEcalInTheCone
1042 <<
" sumNTracksInTheCone " << sumNTracksInTheCone
1043 <<
" sumPtTracksInTheCone " << sumPtTracksInTheCone << endl;
1045 if(fabs(EtaFC >= 1.478) && isEndcapIsolated ==
false) {
1046 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND BUT FAILS ISOLATION:ENDCAP *** "
1047 <<
" sumEtEcalInTheCone " <<sumEtEcalInTheCone
1048 <<
" sumNTracksInTheCone " << sumNTracksInTheCone
1049 <<
" sumPtTracksInTheCone " << sumPtTracksInTheCone << endl;
1056 if(isBarrelIsolated || isEndcapIsolated ) {
1060 double totenergy = 0.;
1061 for(
unsigned int ikeyecal = 0;
1062 ikeyecal<EcalIndex.size(); ikeyecal++){
1064 bool foundcluster =
false;
1066 for(
unsigned int i2 = 0; i2<ikeyecal-1; i2++) {
1067 if(EcalIndex[ikeyecal] == EcalIndex[i2])
1068 foundcluster =
true;;
1071 if(foundcluster)
continue;
1074 totenergy += clusasso->
clusterRef()->energy();
1080 for(
unsigned int ikeyecal = 0;
1081 ikeyecal<EcalIndex.size(); ikeyecal++){
1083 bool foundcluster =
false;
1085 for(
unsigned int i2 = 0; i2<ikeyecal-1; i2++) {
1086 if(EcalIndex[ikeyecal] == EcalIndex[i2])
1087 foundcluster =
true;
1090 if(foundcluster)
continue;
1093 std::multimap<double, unsigned int> ecalFromSuperClusterElems;
1095 ecalFromSuperClusterElems,
1098 if(ecalFromSuperClusterElems.size() > 0) {
1099 for(std::multimap<double, unsigned int>::iterator itsc = ecalFromSuperClusterElems.begin();
1100 itsc != ecalFromSuperClusterElems.end(); ++itsc) {
1101 if(localactive[itsc->second] ==
false) {
1105 std::multimap<double, unsigned int> ecalOtherKFPrimElems;
1107 ecalOtherKFPrimElems,
1110 if(ecalOtherKFPrimElems.size() > 0) {
1111 if(localactive[ecalOtherKFPrimElems.begin()->second] ==
true) {
1112 if (DebugSetLinksDetailed)
1113 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND BUT FAILS KF VETO *** " << endl;
1117 bool isInTheEtaRange =
false;
1120 double deta_clustToAdd = clustToAdd->
clusterRef()->position().Eta() - EtaFC;
1121 double ene_clustToAdd = clustToAdd->
clusterRef()->energy();
1123 if(fabs(deta_clustToAdd) < 0.05)
1124 isInTheEtaRange =
true;
1127 bool isBetterEpin =
false;
1128 if(isInTheEtaRange ==
false ) {
1129 if (DebugSetLinksDetailed)
1130 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND BUT FAILS GAMMA DETA RANGE *** "
1131 << fabs(deta_clustToAdd) << endl;
1133 if(KfGsf_index < CutIndex) {
1135 double res_before_gsf = fabs((totenergy-Pin_gsf)/Pin_gsf);
1136 double res_after_gsf = fabs(((totenergy+ene_clustToAdd)-Pin_gsf)/Pin_gsf);
1141 double Pin_kf = trackEl->
trackRef()->p();
1142 double res_before_kf = fabs((totenergy-Pin_kf)/Pin_kf);
1143 double res_after_kf = fabs(((totenergy+ene_clustToAdd)-Pin_kf)/Pin_kf);
1146 if(res_after_gsf < res_before_gsf && res_after_kf < res_before_kf ) {
1147 isBetterEpin =
true;
1150 if (DebugSetLinksDetailed)
1151 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND AND FAILS ALSO RES_EPIN"
1152 <<
" tot energy " << totenergy
1153 <<
" Pin_gsf " << Pin_gsf
1154 <<
" Pin_kf " << Pin_kf
1155 <<
" cluster from SC to ADD " << ene_clustToAdd
1156 <<
" Res before GSF " << res_before_gsf <<
" res_after_gsf " << res_after_gsf
1157 <<
" Res before KF " << res_before_kf <<
" res_after_kf " << res_after_kf << endl;
1162 if(isInTheEtaRange || isBetterEpin) {
1163 if (DebugSetLinksDetailed)
1164 cout <<
"!!!! PFElectronAlgo:: ECAL from SUPERCLUSTER FOUND !!!!! " << endl;
1165 GsfElemIndex.push_back(itsc->second);
1166 EcalIndex.push_back(itsc->second);
1167 localactive[(itsc->second)] =
false;
1176 if(KfGsf_index < CutIndex)
1177 GsfElemIndex.push_back(KfGsf_index);
1178 else if(KfGsf_secondIndex < CutIndex)
1179 GsfElemIndex.push_back(KfGsf_secondIndex);
1182 GsfElemIndex.insert(GsfElemIndex.end(),convBremKFTrack.begin(),convBremKFTrack.end());
1183 GsfElemIndex.insert(GsfElemIndex.end(),keyBremIndex.begin(),keyBremIndex.end());
1184 associatedToGsf_.insert(pair<
unsigned int, vector<unsigned int> >(gsfIs[iEle],GsfElemIndex));
1187 for(
unsigned int ikeyecal = 0;
1188 ikeyecal<EcalIndex.size(); ikeyecal++){
1191 vector<unsigned int> EcalElemsIndex(0);
1193 std::multimap<double, unsigned int> PS1Elems;
1198 for( std::multimap<double, unsigned int>::iterator it = PS1Elems.begin();
1199 it != PS1Elems.end();it++) {
1200 unsigned int index = it->second;
1201 if(localactive[index] ==
true) {
1204 std::multimap<double, unsigned> sortedECAL;
1209 unsigned jEcal = sortedECAL.begin()->second;
1210 if ( jEcal != EcalIndex[ikeyecal])
continue;
1213 EcalElemsIndex.push_back(index);
1214 localactive[
index] =
false;
1218 std::multimap<double, unsigned int> PS2Elems;
1223 for( std::multimap<double, unsigned int>::iterator it = PS2Elems.begin();
1224 it != PS2Elems.end();it++) {
1225 unsigned int index = it->second;
1226 if(localactive[index] ==
true) {
1228 std::multimap<double, unsigned> sortedECAL;
1233 unsigned jEcal = sortedECAL.begin()->second;
1234 if ( jEcal != EcalIndex[ikeyecal])
continue;
1236 EcalElemsIndex.push_back(index);
1237 localactive[
index] =
false;
1244 std::multimap<double, unsigned int> hcalGsfElems;
1249 for( std::multimap<double, unsigned int>::iterator it = hcalGsfElems.begin();
1250 it != hcalGsfElems.end();it++) {
1251 unsigned int index = it->second;
1264 EcalElemsIndex.push_back(index);
1265 localactive[
index] =
false;
1270 if(hcalGsfElems.size() == 0 && ClosestEcalWithKf ==
true) {
1271 std::multimap<double, unsigned int> hcalKfElems;
1276 for( std::multimap<double, unsigned int>::iterator it = hcalKfElems.begin();
1277 it != hcalKfElems.end();it++) {
1278 unsigned int index = it->second;
1279 if(localactive[index] ==
true) {
1282 std::multimap<double, unsigned> sortedKf;
1287 unsigned jKf = sortedKf.begin()->second;
1288 if ( jKf != KfGsf_index)
continue;
1289 EcalElemsIndex.push_back(index);
1290 localactive[
index] =
false;
1295 std::multimap<double, unsigned int> kfEtraElems;
1300 if(kfEtraElems.size() > 0) {
1301 for( std::multimap<double, unsigned int>::iterator it = kfEtraElems.begin();
1302 it != kfEtraElems.end();it++) {
1303 unsigned int index = it->second;
1311 bool thisIsAMuon =
false;
1313 if (DebugSetLinksDetailed && thisIsAMuon)
1314 cout <<
" This is a Muon: index " << index << endl;
1315 if(localactive[index] ==
true && !thisIsAMuon) {
1316 if(index != KfGsf_index) {
1319 std::multimap<double, unsigned> sortedECAL;
1324 unsigned jEcal = sortedECAL.begin()->second;
1325 if ( jEcal != EcalIndex[ikeyecal])
continue;
1326 EcalElemsIndex.push_back(index);
1327 localactive[
index] =
false;
1334 associatedToEcal_.insert(pair<
unsigned int,vector<unsigned int> >(EcalIndex[ikeyecal],EcalElemsIndex));
1343 if (DebugSetLinksSummary) {
1344 if(IsThereAGoodGSFTrack) {
1345 if (DebugSetLinksSummary)
cout <<
" -- The Link Summary --" << endl;
1346 for(map<
unsigned int,vector<unsigned int> >::iterator it = associatedToGsf_.begin();
1347 it != associatedToGsf_.end(); it++) {
1349 if (DebugSetLinksSummary)
cout <<
" AssoGsf " << it->first << endl;
1350 vector<unsigned int> eleasso = it->second;
1351 for(
unsigned int i=0;
i<eleasso.size();
i++) {
1354 if (DebugSetLinksSummary)
1355 cout <<
" AssoGsfElements BREM " << eleasso[
i] << endl;
1358 if (DebugSetLinksSummary)
1359 cout <<
" AssoGsfElements ECAL " << eleasso[
i] << endl;
1362 if (DebugSetLinksSummary)
1363 cout <<
" AssoGsfElements KF " << eleasso[
i] << endl;
1366 if (DebugSetLinksSummary)
1367 cout <<
" AssoGsfElements ????? " << eleasso[
i] << endl;
1372 for(map<
unsigned int,vector<unsigned int> >::iterator it = associatedToBrems_.begin();
1373 it != associatedToBrems_.end(); it++) {
1374 if (DebugSetLinksSummary)
cout <<
" AssoBrem " << it->first << endl;
1375 vector<unsigned int> eleasso = it->second;
1376 for(
unsigned int i=0;
i<eleasso.size();
i++) {
1379 if (DebugSetLinksSummary)
1380 cout <<
" AssoBremElements ECAL " << eleasso[
i] << endl;
1383 if (DebugSetLinksSummary)
1384 cout <<
" AssoBremElements ????? " << eleasso[
i] << endl;
1389 for(map<
unsigned int,vector<unsigned int> >::iterator it = associatedToEcal_.begin();
1390 it != associatedToEcal_.end(); it++) {
1391 if (DebugSetLinksSummary)
cout <<
" AssoECAL " << it->first << endl;
1392 vector<unsigned int> eleasso = it->second;
1393 for(
unsigned int i=0;
i<eleasso.size();
i++) {
1396 if (DebugSetLinksSummary)
1397 cout <<
" AssoECALElements PS1 " << eleasso[
i] << endl;
1400 if (DebugSetLinksSummary)
1401 cout <<
" AssoECALElements PS2 " << eleasso[
i] << endl;
1404 if (DebugSetLinksSummary)
1405 cout <<
" AssoECALElements HCAL " << eleasso[
i] << endl;
1408 if (DebugSetLinksSummary)
1409 cout <<
" AssoHCALElements ????? " << eleasso[
i] << endl;
1413 if (DebugSetLinksSummary)
1414 cout <<
"-- End Summary --" << endl;
1419 return IsThereAGoodGSFTrack;
1423 AssMap& associatedToGsf_,
1424 AssMap& associatedToBrems_,
1425 AssMap& associatedToEcal_,
1431 bool DebugIDOutputs =
false;
1432 if(DebugIDOutputs)
cout <<
" ######## Enter in SetIDOutputs #########" << endl;
1434 unsigned int cgsf=0;
1435 for (map<
unsigned int,vector<unsigned int> >::iterator igsf = associatedToGsf_.begin();
1436 igsf != associatedToGsf_.end(); igsf++,cgsf++) {
1438 float Ene_ecalgsf = 0.;
1439 float Ene_hcalgsf = 0.;
1440 double sigmaEtaEta = 0.;
1441 float deta_gsfecal = 0.;
1442 float Ene_ecalbrem = 0.;
1443 float Ene_extraecalgsf = 0.;
1444 bool LateBrem =
false;
1446 int FirstBrem = 1000;
1447 unsigned int ecalGsf_index = 100000;
1448 unsigned int kf_index = 100000;
1456 unsigned int gsf_index = igsf->first;
1463 Ein_gsf =
sqrt(RefGSF->pMode()*
1464 RefGSF->pMode()+m_el*m_el);
1467 float Eout_gsf = GsfEl->
Pout().t();
1472 cout <<
" setIdOutput! GSF Track: Ein " << Ein_gsf
1473 <<
" eta,phi " << Etaout_gsf
1477 vector<unsigned int> assogsf_index = igsf->second;
1478 bool FirstEcalGsf =
true;
1479 for (
unsigned int ielegsf=0;ielegsf<assogsf_index.size();ielegsf++) {
1490 if(!isPrim)
continue;
1492 kf_index = assogsf_index[ielegsf];
1497 unsigned int keyecalgsf = assogsf_index[ielegsf];
1498 vector<unsigned int> assoecalgsf_index = associatedToEcal_.find(keyecalgsf)->second;
1500 vector<double> ps1Ene(0);
1501 vector<double> ps2Ene(0);
1502 for(
unsigned int ips =0; ips<assoecalgsf_index.size();ips++) {
1505 PFClusterRef psref = elements[(assoecalgsf_index[ips])].clusterRef();
1506 ps1Ene.push_back(psref->energy());
1509 PFClusterRef psref = elements[(assoecalgsf_index[ips])].clusterRef();
1510 ps2Ene.push_back(psref->energy());
1519 FirstEcalGsf =
false;
1520 ecalGsf_index = assogsf_index[ielegsf];
1527 posX += Ene_ecalgsf * clusterRef->position().X();
1528 posY += Ene_ecalgsf * clusterRef->position().Y();
1529 posZ += Ene_ecalgsf * clusterRef->position().Z();
1532 cout <<
" setIdOutput! GSF ECAL Cluster E " << Ene_ecalgsf
1533 <<
" eta,phi " << clusterRef->position().eta()
1534 <<
", " << clusterRef->position().phi() << endl;
1536 deta_gsfecal = clusterRef->position().eta() - Etaout_gsf;
1538 vector< const reco::PFCluster * > pfClust_vec(0);
1539 pfClust_vec.clear();
1540 pfClust_vec.push_back(&(*clusterRef));
1550 Ene_extraecalgsf += TempClus_energy;
1551 posX += TempClus_energy * clusterRef->position().X();
1552 posY += TempClus_energy * clusterRef->position().Y();
1553 posZ += TempClus_energy * clusterRef->position().Z();
1556 cout <<
" setIdOutput! Extra ECAL Cluster E "
1557 << TempClus_energy <<
" Tot " << Ene_extraecalgsf << endl;
1563 unsigned int brem_index = assogsf_index[ielegsf];
1568 if (TrajPos < FirstBrem) FirstBrem = TrajPos;
1570 vector<unsigned int> assobrem_index = associatedToBrems_.find(brem_index)->second;
1571 for (
unsigned int ibrem = 0; ibrem < assobrem_index.size(); ibrem++){
1573 unsigned int keyecalbrem = assobrem_index[ibrem];
1574 vector<unsigned int> assoelebrem_index = associatedToEcal_.find(keyecalbrem)->second;
1575 vector<double> ps1EneFromBrem(0);
1576 vector<double> ps2EneFromBrem(0);
1577 for (
unsigned int ielebrem=0; ielebrem<assoelebrem_index.size();ielebrem++) {
1579 PFClusterRef psref = elements[(assoelebrem_index[ielebrem])].clusterRef();
1580 ps1EneFromBrem.push_back(psref->energy());
1583 PFClusterRef psref = elements[(assoelebrem_index[ielebrem])].clusterRef();
1584 ps2EneFromBrem.push_back(psref->energy());
1588 if( assobrem_index[ibrem] != ecalGsf_index) {
1590 elements[(assobrem_index[ibrem])].clusterRef();
1592 Ene_ecalbrem += BremClus_energy;
1593 posX += BremClus_energy * clusterRef->position().X();
1594 posY += BremClus_energy * clusterRef->position().Y();
1595 posZ += BremClus_energy * clusterRef->position().Z();
1598 if (DebugIDOutputs)
cout <<
" setIdOutput::BREM Cluster "
1599 << BremClus_energy <<
" eta,phi "
1600 << clusterRef->position().eta() <<
", "
1601 << clusterRef->position().phi() << endl;
1610 if (Ene_ecalgsf > 0.) {
1618 float Pt_gsf = RefGSF->ptMode();
1623 if(RefGSF->ptModeError() > 0.)
1626 nhit_gsf= RefGSF->hitPattern().trackerLayersWithMeasurement();
1627 chi2_gsf = RefGSF->normalizedChi2();
1636 nhit_kf= RefKF->hitPattern().trackerLayersWithMeasurement();
1637 chi2_kf = RefKF->normalizedChi2();
1646 EtotPinMode = (Ene_ecalgsf + Ene_ecalbrem + Ene_extraecalgsf) / Ein_gsf;
1665 HOverHE = Ene_hcalgsf/(Ene_hcalgsf + Ene_ecalgsf);
1700 double mvaValue =
tmvaReader_->EvaluateMVA(
"BDT");
1704 myExtra.
setMVA(mvaValue);
1723 unsigned int iextratrack = 0;
1724 unsigned int itrackHcalLinked = 0;
1725 float SumExtraKfP = 0.;
1728 double Etotal = Ene_ecalgsf + Ene_ecalbrem + Ene_extraecalgsf;
1733 double ETtotal = Etotal*
sin(sc_pflow.Theta());
1734 double phiTrack = RefGSF->phiMode();
1735 double dphi_normalsc = sc_pflow.Phi() - phiTrack;
1736 if ( dphi_normalsc < -
M_PI )
1737 dphi_normalsc = dphi_normalsc + 2.*
M_PI;
1738 else if ( dphi_normalsc >
M_PI )
1739 dphi_normalsc = dphi_normalsc - 2.*
M_PI;
1740 dphi_normalsc = fabs(dphi_normalsc);
1743 if(ecalGsf_index < 100000) {
1744 vector<unsigned int> assoecalgsf_index = associatedToEcal_.find(ecalGsf_index)->second;
1745 for(
unsigned int itrk =0; itrk<assoecalgsf_index.size();itrk++) {
1760 int nexhits = trackref->hitPattern().numberOfLostHits(HitPattern::MISSING_INNER_HITS);
1762 bool trackIsFromPrimaryVertex =
false;
1764 if ( (*trackIt).castTo<
TrackRef>() == trackref ) {
1765 trackIsFromPrimaryVertex =
true;
1771 if(goodTrack && nexhits == 0 && trackIsFromPrimaryVertex) {
1774 cout <<
" The ecalGsf cluster is not isolated: >0 KF extra with algo < 3" << endl;
1776 float p_trk = trackref->p();
1781 cout <<
" p_trk " << p_trk
1782 <<
" nexhits " << nexhits << endl;
1784 SumExtraKfP += p_trk;
1787 std::multimap<double, unsigned int> hcalKfElems;
1792 if(hcalKfElems.size() > 0) {
1799 if( iextratrack > 0) {
1801 if(iextratrack > 3 || Ene_hcalgsf > 10 || (SumExtraKfP/Ene_ecalgsf) > 1.
1802 || (ETtotal > 50. && iextratrack > 1 && (Ene_hcalgsf/Ene_ecalgsf) > 0.1) ) {
1804 cout <<
" *****This electron candidate is discarded: Non isolated # tracks "
1805 << iextratrack <<
" HOverHE " <<
HOverHE
1806 <<
" SumExtraKfP/Ene_ecalgsf " << SumExtraKfP/Ene_ecalgsf
1807 <<
" SumExtraKfP " << SumExtraKfP
1808 <<
" Ene_ecalgsf " << Ene_ecalgsf
1809 <<
" ETtotal " << ETtotal
1810 <<
" Ene_hcalgsf/Ene_ecalgsf " << Ene_hcalgsf/Ene_ecalgsf
1819 ((EtotPinMode < 1.1 && EtotPinMode > 0.6) && (fabs(
Eta_gsf) >= 1.0 && fabs(
Eta_gsf) <= 2.0))) {
1821 (itrackHcalLinked == iextratrack) &&
1822 kf_index < 100000 ) {
1827 cout <<
" *****This electron is reactivated # tracks "
1828 << iextratrack <<
" #tracks hcal linked " << itrackHcalLinked
1829 <<
" SumExtraKfP/Ene_ecalgsf " << SumExtraKfP/Ene_ecalgsf
1831 <<
" eta gsf " << fabs(
Eta_gsf) <<
" kf index " << kf_index <<endl;
1838 cout <<
" *****This electron candidate is discarded HCAL ENERGY "
1849 cout <<
" *****This electron candidate is discarded Low ETOTPIN "
1855 if(ETtotal > 50. && dphi_normalsc > 0.1 ) {
1857 cout <<
" *****This electron candidate is discarded Large ANGLE "
1858 <<
" ETtotal " << ETtotal <<
" EGsfPoutMode " << dphi_normalsc << endl;
1864 if (DebugIDOutputs) {
1865 cout <<
" **** BDT observables ****" << endl;
1866 cout <<
" < Normalization > " << endl;
1867 cout <<
" Pt_gsf " << Pt_gsf <<
" Pin " << Ein_gsf <<
" Pout " << Eout_gsf
1868 <<
" Eta_gsf " <<
Eta_gsf << endl;
1869 cout <<
" < PureTracking > " << endl;
1876 <<
" nhit_kf " <<
nhit_kf << endl;
1877 cout <<
" < track-ecal-hcal-ps " << endl;
1883 <<
" HOverHE " <<
HOverHE <<
" Hcal energy " << Ene_hcalgsf
1887 cout <<
" !!!!!!!!!!!!!!!! the BDT output !!!!!!!!!!!!!!!!!: direct " << mvaValue
1888 <<
" corrected " <<
BDToutput_[cgsf] << endl;
1894 cout <<
" Gsf Ref isNULL " << endl;
1899 cout <<
" No clusters associated to the gsf " << endl;
1902 DebugIDOutputs =
false;
1910 AssMap& associatedToGsf_,
1911 AssMap& associatedToBrems_,
1912 AssMap& associatedToEcal_){
1920 bool DebugIDCandidates =
false;
1924 unsigned int cgsf=0;
1925 for (map<
unsigned int,vector<unsigned int> >::iterator igsf = associatedToGsf_.begin();
1926 igsf != associatedToGsf_.end(); igsf++,cgsf++) {
1927 unsigned int gsf_index = igsf->first;
1937 float dpt=0;
float dpt_gsf=0;
1938 float Eene=0;
float dene=0;
float Hene=0.;
1943 std::vector<float> bremEnergyVec;
1945 std::vector<const PFCluster*> pfSC_Clust_vec;
1947 float de_gs = 0., de_me = 0., de_kf = 0.;
1953 float ps1TotEne = 0;
1954 float ps2TotEne = 0;
1955 vector<unsigned int> elementsToAdd(0);
1960 elementsToAdd.push_back(gsf_index);
1969 charge= RefGSF->chargeMode();
1970 nhit_gsf= RefGSF->hitPattern().trackerLayersWithMeasurement();
1972 momentum_gsf.SetPx(RefGSF->pxMode());
1973 momentum_gsf.SetPy(RefGSF->pyMode());
1974 momentum_gsf.SetPz(RefGSF->pzMode());
1975 float ENE=
sqrt(RefGSF->pMode()*
1976 RefGSF->pMode()+m_el*m_el);
1978 if( DebugIDCandidates )
1979 cout <<
"SetCandidates:: GsfTrackRef: Ene " << ENE
1980 <<
" charge " << charge <<
" nhits " << nhit_gsf <<endl;
1982 momentum_gsf.SetE(ENE);
1983 dpt_gsf=RefGSF->ptModeError()*
1984 (RefGSF->pMode()/RefGSF->ptMode());
1986 momentum_mean.SetPx(RefGSF->px());
1987 momentum_mean.SetPy(RefGSF->py());
1988 momentum_mean.SetPz(RefGSF->pz());
1989 float ENEm=
sqrt(RefGSF->p()*
1990 RefGSF->p()+m_el*m_el);
1991 momentum_mean.SetE(ENEm);
1996 if( DebugIDCandidates )
1997 cout <<
"SetCandidates:: !!!! NULL GSF Track Ref " << endl;
2001 vector<unsigned int> assogsf_index = igsf->second;
2002 unsigned int ecalGsf_index = 100000;
2003 bool FirstEcalGsf =
true;
2004 for (
unsigned int ielegsf=0;ielegsf<assogsf_index.size();ielegsf++) {
2007 elementsToAdd.push_back((assogsf_index[ielegsf]));
2012 if(!isPrim)
continue;
2018 nhit_kf=RefKF->hitPattern().trackerLayersWithMeasurement();
2019 momentum_kf.SetPx(RefKF->px());
2020 momentum_kf.SetPy(RefKF->py());
2021 momentum_kf.SetPz(RefKF->pz());
2022 float ENE=
sqrt(RefKF->p()*RefKF->p()+m_el*m_el);
2023 if( DebugIDCandidates )
2024 cout <<
"SetCandidates:: KFTrackRef: Ene " << ENE <<
" nhits " << nhit_kf << endl;
2026 momentum_kf.SetE(ENE);
2029 if( DebugIDCandidates )
2030 cout <<
"SetCandidates:: !!!! NULL KF Track Ref " << endl;
2035 unsigned int keyecalgsf = assogsf_index[ielegsf];
2036 vector<unsigned int> assoecalgsf_index = associatedToEcal_.find(keyecalgsf)->second;
2037 vector<double> ps1Ene(0);
2038 vector<double> ps2Ene(0);
2042 for(
unsigned int ips =0; ips<assoecalgsf_index.size();ips++) {
2045 PFClusterRef psref = elements[(assoecalgsf_index[ips])].clusterRef();
2046 ps1Ene.push_back(psref->energy());
2047 elementsToAdd.push_back((assoecalgsf_index[ips]));
2050 PFClusterRef psref = elements[(assoecalgsf_index[ips])].clusterRef();
2051 ps2Ene.push_back(psref->energy());
2052 elementsToAdd.push_back((assoecalgsf_index[ips]));
2057 elementsToAdd.push_back((assoecalgsf_index[ips]));
2062 elementsToAdd.push_back((assogsf_index[ielegsf]));
2080 float ceta=
cl.position().eta();
2081 float cphi=
cl.position().phi();
2094 if( DebugIDCandidates )
2095 cout <<
"SetCandidates:: EcalCluster: EneNoCalib " << clust->
clusterRef()->energy()
2096 <<
" eta,phi " << ceta <<
"," << cphi <<
" Calib " << EE <<
" dE " << dE <<endl;
2098 bool elecCluster=
false;
2100 FirstEcalGsf =
false;
2102 ecalGsf_index = assogsf_index[ielegsf];
2110 clusterMomentum.SetPxPyPzE(EE*direction.x(),
2127 std::map<unsigned int,std::vector<reco::PFCandidate> >::iterator itcheck=
2132 std::vector<reco::PFCandidate> tmpVec;
2133 tmpVec.push_back(cluster_Candidate);
2139 itcheck->second.push_back(cluster_Candidate);
2143 posX += EE *
cl.position().X();
2144 posY += EE *
cl.position().Y();
2145 posZ += EE *
cl.position().Z();
2151 pfSC_Clust_vec.push_back( &
cl );
2159 unsigned int brem_index = assogsf_index[ielegsf];
2160 vector<unsigned int> assobrem_index = associatedToBrems_.find(brem_index)->second;
2161 elementsToAdd.push_back(brem_index);
2162 for (
unsigned int ibrem = 0; ibrem < assobrem_index.size(); ibrem++){
2165 if( assobrem_index[ibrem] != ecalGsf_index) {
2166 unsigned int keyecalbrem = assobrem_index[ibrem];
2167 const vector<unsigned int>& assoelebrem_index = associatedToEcal_.find(keyecalbrem)->second;
2168 vector<double> ps1EneFromBrem(0);
2169 vector<double> ps2EneFromBrem(0);
2170 for (
unsigned int ielebrem=0; ielebrem<assoelebrem_index.size();ielebrem++) {
2172 PFClusterRef psref = elements[(assoelebrem_index[ielebrem])].clusterRef();
2173 ps1EneFromBrem.push_back(psref->energy());
2174 elementsToAdd.push_back(assoelebrem_index[ielebrem]);
2177 PFClusterRef psref = elements[(assoelebrem_index[ielebrem])].clusterRef();
2178 ps2EneFromBrem.push_back(psref->energy());
2179 elementsToAdd.push_back(assoelebrem_index[ielebrem]);
2182 elementsToAdd.push_back(assobrem_index[ibrem]);
2189 bremEnergyVec.push_back(EE);
2191 float ceta = clusterRef->position().eta();
2194 if( DebugIDCandidates )
2195 cout <<
"SetCandidates:: BremCluster: Ene " << EE <<
" dE " << dE <<endl;
2198 posX += EE * clusterRef->position().X();
2199 posY += EE * clusterRef->position().Y();
2200 posZ += EE * clusterRef->position().Z();
2208 pfSC_Clust_vec.push_back( clusterRef.
get() );
2213 math::XYZPoint direction=clusterRef->position()/clusterRef->position().R();
2215 photonMomentum.SetPxPyPzE(EE*direction.x(),
2231 std::map<unsigned int,std::vector<reco::PFCandidate> >::iterator itcheck=
2236 std::vector<reco::PFCandidate> tmpVec;
2237 tmpVec.push_back(photon_Candidate);
2243 itcheck->second.push_back(photon_Candidate);
2253 double unCorrEene = Eene;
2254 double absEta = fabs(momentum_gsf.Eta());
2255 double emTheta = momentum_gsf.Theta();
2258 pfSC_Clust_vec.clear();
2260 if( DebugIDCandidates )
2261 cout <<
"PFEelectronAlgo:: absEta " << absEta <<
" theta " << emTheta
2262 <<
" EneRaw " << Eene <<
" Err " << dene;
2268 double Etene = Eene*
sin(emTheta);
2270 double emBR_et = emBR_e*
sin(emTheta);
2272 Eene = emCorrFull_et/
sin(emTheta);
2277 double emBR_et = emBR_e*
sin(emTheta);
2279 Eene = emCorrFull_et/
sin(emTheta);
2281 dene =
sqrt(dene)*(Eene/unCorrEene);
2285 if( DebugIDCandidates )
2286 cout <<
" EneCorrected " << Eene <<
" Err " << dene << endl;
2291 if(has_kf && unCorrEene > 0.) {
2297 std::multimap<double, unsigned int> bremElems;
2303 double phiTrack = RefGSF->phiMode();
2304 if(bremElems.size()>0) {
2305 unsigned int brem_index = bremElems.begin()->second;
2311 double dphi_normalsc = sc_pflow.Phi() - phiTrack;
2312 if ( dphi_normalsc < -
M_PI )
2313 dphi_normalsc = dphi_normalsc + 2.*
M_PI;
2314 else if ( dphi_normalsc >
M_PI )
2315 dphi_normalsc = dphi_normalsc - 2.*
M_PI;
2317 int chargeGsf = RefGSF->chargeMode();
2318 int chargeKf = RefKF->charge();
2321 if(dphi_normalsc < 0.)
2326 if(chargeKf == chargeGsf)
2328 else if(chargeGsf == chargeSC)
2333 if( DebugIDCandidates )
2334 cout <<
"PFElectronAlgo:: charge determination "
2335 <<
" charge GSF " << chargeGsf
2336 <<
" charge KF " << chargeKf
2337 <<
" charge SC " << chargeSC
2338 <<
" Final Charge " << charge << endl;
2343 if ((nhit_gsf<8) && (has_kf)){
2347 momentum=momentum_kf;
2349 float scale= Fe/momentum.E();
2352 if (Eene < 0.0001) {
2358 newmomentum.SetPxPyPzE(scale*momentum.Px(),
2359 scale*momentum.Py(),
2360 scale*momentum.Pz(),Fe);
2361 if( DebugIDCandidates )
2362 cout <<
"SetCandidates:: (nhit_gsf<8) && (has_kf):: pt " << newmomentum.pt() <<
" Ene " << Fe <<endl;
2366 if ((nhit_gsf>7) || (has_kf==
false)){
2368 de_gs=1-momentum_gsf.E()/Eene;
2369 de_me=1-momentum_mean.E()/Eene;
2370 de_kf=1-momentum_kf.E()/Eene;
2373 momentum=momentum_gsf;
2374 dpt=1/(dpt_gsf*dpt_gsf);
2381 Fe =((dene*Eene) +(dpt*momentum.E()))/(dene+dpt);
2387 if ((de_gs>0.05)&&(de_kf>0.05)){
2390 if ((de_gs<-0.1)&&(de_me<-0.1) &&(de_kf<0.) &&
2391 (momentum.E()/dpt_gsf) > 5. && momentum_gsf.pt() < 30.){
2394 float scale= Fe/momentum.E();
2396 newmomentum.SetPxPyPzE(scale*momentum.Px(),
2397 scale*momentum.Py(),
2398 scale*momentum.Pz(),Fe);
2399 if( DebugIDCandidates )
2400 cout <<
"SetCandidates::(nhit_gsf>7) || (has_kf==false) " << newmomentum.pt() <<
" Ene " << Fe <<endl;
2404 if (newmomentum.pt()>0.5){
2409 if( DebugIDCandidates )
2410 cout <<
"SetCandidates:: I am before doing candidate " <<endl;
2413 std::vector<float> clusterEnergyVec;
2414 clusterEnergyVec.push_back(RawEene);
2415 clusterEnergyVec.insert(clusterEnergyVec.end(),bremEnergyVec.begin(),bremEnergyVec.end());
2418 std::vector<reco::PFCandidateElectronExtra>::iterator itextra;
2422 itextra->setClusterEnergies(clusterEnergyVec);
2426 std::cout <<
" There is a big problem with the electron extra, PFElectronAlgo should crash soon " << RawEene << std::endl;
2432 temp_Candidate =
PFCandidate(charge,newmomentum,particleType);
2449 if(seedRef.
isAvailable() && seedRef->isEcalDriven()) {
2456 if( DebugIDCandidates )
2457 cout <<
"SetCandidates:: I am after doing candidate " <<endl;
2459 for (
unsigned int elad=0; elad<elementsToAdd.size();elad++){
2464 std::map<unsigned int, std::vector<reco::PFCandidate> >::const_iterator itcluster=
2468 const std::vector<reco::PFCandidate> & theClusters=itcluster->second;
2469 unsigned nclus=theClusters.size();
2471 for(
unsigned iclus=0;iclus<nclus;++iclus)
2478 bool bypassmva=
false;
2487 if( DebugIDCandidates ) {
2489 float esceg = itcheck->caloEnergy();
2491 <<
" SuperClusterEnergy " << esceg
2492 <<
" PF Energy " << Eene << endl;
2494 cout <<
" hoe " << itcheck->hcalOverEcal()
2495 <<
" tkiso04 " << itcheck->dr04TkSumPt()
2496 <<
" ecaliso04 " << itcheck->dr04EcalRecHitSumEt()
2497 <<
" hcaliso04 " << itcheck->dr04HcalTowerSumEt()
2498 <<
" tkiso03 " << itcheck->dr03TkSumPt()
2499 <<
" ecaliso03 " << itcheck->dr03EcalRecHitSumEt()
2500 <<
" hcaliso03 " << itcheck->dr03HcalTowerSumEt() << endl;
2508 if( mvaSelected || bypassmva ) {
2511 itextra->setStatus(PFCandidateElectronExtra::Selected,
true);
2515 itextra->setStatus(PFCandidateElectronExtra::Rejected,
true);
2521 itextra->setStatus(PFCandidateElectronExtra::ECALDrivenPreselected,bypassmva);
2522 itextra->setStatus(PFCandidateElectronExtra::MVASelected,mvaSelected);
2530 if( DebugIDCandidates )
2531 cout <<
"SetCandidates:: No Candidate Produced because of Pt cut: 0.5 " <<endl;
2536 if( DebugIDCandidates )
2537 cout <<
"SetCandidates:: No Candidate Produced because of No GSF Track Ref " <<endl;
2546 AssMap& associatedToGsf_,
2547 AssMap& associatedToBrems_,
2548 AssMap& associatedToEcal_,
2549 std::vector<bool>& active){
2555 unsigned int cgsf=0;
2556 for (map<
unsigned int,vector<unsigned int> >::iterator igsf = associatedToGsf_.begin();
2557 igsf != associatedToGsf_.end(); igsf++,cgsf++) {
2559 unsigned int gsf_index = igsf->first;
2565 bool bypassmva=
false;
2578 active[gsf_index] =
false;
2579 vector<unsigned int> assogsf_index = igsf->second;
2580 for (
unsigned int ielegsf=0;ielegsf<assogsf_index.size();ielegsf++) {
2583 active[(assogsf_index[ielegsf])] =
false;
2585 unsigned int keyecalgsf = assogsf_index[ielegsf];
2598 for(
unsigned int iconv = 0; iconv <
convGsfTrack_.size(); iconv++) {
2603 std::multimap<double, unsigned> convKf;
2609 if(convKf.size() > 0) {
2610 active[convKf.begin()->second] =
false;
2617 vector<unsigned int> assoecalgsf_index = associatedToEcal_.find(keyecalgsf)->second;
2618 for(
unsigned int ips =0; ips<assoecalgsf_index.size();ips++) {
2621 active[(assoecalgsf_index[ips])] =
false;
2623 active[(assoecalgsf_index[ips])] =
false;
2626 active[(assoecalgsf_index[ips])] =
false;
2632 unsigned int brem_index = assogsf_index[ielegsf];
2633 vector<unsigned int> assobrem_index = associatedToBrems_.find(brem_index)->second;
2634 for (
unsigned int ibrem = 0; ibrem < assobrem_index.size(); ibrem++){
2636 unsigned int keyecalbrem = assobrem_index[ibrem];
2638 active[(assobrem_index[ibrem])] =
false;
2649 vector<unsigned int> assoelebrem_index = associatedToEcal_.find(keyecalbrem)->second;
2651 for (
unsigned int ielebrem=0; ielebrem<assoelebrem_index.size();ielebrem++) {
2653 active[(assoelebrem_index[ielebrem])] =
false;
2655 active[(assoelebrem_index[ielebrem])] =
false;
2670 bool isPrimary =
false;
2676 PFRecTrackRef kfPfRef_fromGsf = (*gsfPfRef).kfPFRecTrackRef();
2681 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
tuple ret
prodAgent to be discontinued
bool SetLinks(const reco::PFBlockRef &blockRef, AssMap &associatedToGsf_, AssMap &associatedToBrems_, AssMap &associatedToEcal_, std::vector< bool > &active, const reco::Vertex &primaryVertex)
std::map< unsigned int, std::vector< unsigned int > > AssMap
const reco::GsfTrackRef & GsftrackRef() const
void setPs1Energy(float e1)
set corrected PS1 energy
ParticleType
particle types
bool isNonnull() const
Checks for non-null.
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_
tuple coneTrackIsoForEgammaSC
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_
tuple sumPtTrackIsoForEgammaSC_endcap
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_
U second(std::pair< T, U > const &p)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
void set_mva_e_pi(float mvaNI)
tuple coneEcalIsoForEgammaSC
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
tuple sumPtTrackIsoForEgammaSC_barrel
bool goodTrack(const reco::Track *pTrack, math::XYZPoint leadPV, trackSelectionParameters parameters, bool debug=false)
double pflowSigmaEtaEta() const
void addElementInBlock(const reco::PFBlockRef &blockref, unsigned elementIndex)
add an element to the current PFCandidate
double sumEtEcalIsoForEgammaSC_barrel_
std::vector< bool > lockExtraKf_
tuple sumEtEcalIsoForEgammaSC_barrel
std::vector< double > BDToutput_
void setDeltaEta(float val)
set the delta eta
double sumEtEcalIsoForEgammaSC_endcap_
T const * get() const
Returns C++ pointer to the item.
void SetIDOutputs(const reco::PFBlockRef &blockRef, AssMap &associatedToGsf_, AssMap &associatedToBrems_, AssMap &associatedToEcal_, const reco::Vertex &primaryVertex)
tuple sumEtEcalIsoForEgammaSC_endcap
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_
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
tuple useEGammaSupercluster
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>
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)
tuple applyCrackCorrections
double dist(unsigned ie1, unsigned ie2, const LinkData &linkData, LinkTest test) const
trackRef_iterator tracks_begin() const
first iterator over tracks
unsigned int nTrackIsoForEgammaSC_
void setTrackRef(const reco::TrackRef &ref)
set track reference
void insert(const_iterator i, D *&d)
tuple nTrackIsoForEgammaSC
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_