33 string mvaWeightFileEleID,
34 const boost::shared_ptr<PFSCEnergyCalibration>& thePFSCEnergyCalibration,
35 const boost::shared_ptr<PFEnergyCalibration>& thePFEnergyCalibration,
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->hitPattern().numberOfLostHits(HitPattern::MISSING_INNER_HITS);
274 Algo = refKf->algo();
276 bool trackIsFromPrimaryVertex =
false;
278 if ( (*trackIt).castTo<
TrackRef>() == refKf ) {
279 trackIsFromPrimaryVertex =
true;
293 && nexhits == 0 && trackIsFromPrimaryVertex) {
294 localactive[ecalKf_index] =
false;
306 for(
unsigned int iEle=0; iEle<gsfIs.size(); iEle++) {
308 if (!localactive[(gsfIs[iEle])])
continue;
310 localactive[gsfIs[iEle]] =
false;
311 bool ClosestEcalWithKf =
false;
313 if (DebugSetLinksDetailed)
cout <<
" Gsf Index " << gsfIs[iEle] << endl;
320 IsThereAGoodGSFTrack =
true;
322 float etaOut_gsf = GsfEl->
Pout().eta();
323 float diffOutEcalEta = fabs(eta_gsf-etaOut_gsf);
325 float Pin_gsf = 0.01;
327 Pin_gsf = RefGSF->pMode();
331 unsigned int KfGsf_index = CutIndex;
332 unsigned int KfGsf_secondIndex = CutIndex;
333 std::multimap<double, unsigned int> kfElems;
338 std::multimap<double, unsigned int> ecalKfElems;
339 if (kfElems.size() > 0) {
343 for(std::multimap<double, unsigned int>::iterator itkf = kfElems.begin();
344 itkf != kfElems.end(); ++itkf) {
352 if(localactive[itkf->second] ==
true) {
354 KfGsf_index = itkf->second;
355 localactive[KfGsf_index] =
false;
363 KfGsf_secondIndex = itkf->second;
369 std::multimap<double, unsigned int> ecalGsfElems;
374 double ecalGsf_dist = CutGSFECAL;
375 unsigned int ClosestEcalGsf_index = CutIndex;
376 if (ecalGsfElems.size() > 0) {
377 if(localactive[(ecalGsfElems.begin()->second)] ==
true) {
379 bool compatibleEPout =
true;
380 if(diffOutEcalEta > 0.3) {
381 reco::PFClusterRef clusterRef = elements[(ecalGsfElems.begin()->second)].clusterRef();
382 float EoPout = (clusterRef->energy())/(GsfEl->
Pout().t());
384 compatibleEPout =
false;
386 if(compatibleEPout) {
387 ClosestEcalGsf_index = ecalGsfElems.begin()->second;
388 ecalGsf_dist = block.
dist(gsfIs[iEle],ClosestEcalGsf_index,
393 std::multimap<double, unsigned int> ecalOtherGsfElems;
399 if(ecalOtherGsfElems.size()>0) {
404 if(ecalOtherGsfElems.begin()->second != gsfIs[iEle]&&
406 ecalGsf_dist = CutGSFECAL;
407 ClosestEcalGsf_index = CutIndex;
415 else if(ecalKfElems.size() > 0) {
416 if(localactive[(ecalKfElems.begin()->second)] ==
true) {
417 ClosestEcalGsf_index = ecalKfElems.begin()->second;
418 ecalGsf_dist = block.
dist(gsfIs[iEle],ClosestEcalGsf_index,
420 ClosestEcalWithKf =
true;
423 std::multimap<double, unsigned int> ecalOtherGsfElems;
428 if(ecalOtherGsfElems.size() > 0) {
432 if(ecalOtherGsfElems.begin()->second != gsfIs[iEle] &&
434 ecalGsf_dist = CutGSFECAL;
435 ClosestEcalGsf_index = CutIndex;
436 ClosestEcalWithKf =
false;
442 if (DebugSetLinksDetailed)
443 cout <<
" Closest Ecal to the Gsf/Kf: index " << ClosestEcalGsf_index
444 <<
" dist " << ecalGsf_dist << endl;
449 std::multimap<double, unsigned int> bremElems;
456 multimap<unsigned int,unsigned int> cleanedEcalBremElems;
457 vector<unsigned int> keyBremIndex(0);
458 unsigned int latestBrem_trajP = 0;
459 unsigned int latestBrem_index = CutIndex;
460 for(std::multimap<double, unsigned int>::iterator ieb = bremElems.begin();
461 ieb != bremElems.end(); ++ieb ) {
462 unsigned int brem_index = ieb->second;
463 if(localactive[brem_index] ==
false)
continue;
467 std::multimap<double, unsigned int> ecalBremsElems;
474 for (std::multimap<double, unsigned int>::iterator ie = ecalBremsElems.begin();
475 ie != ecalBremsElems.end();ie++) {
476 unsigned int ecalBrem_index = ie->second;
477 if(localactive[ecalBrem_index] ==
false)
continue;
480 float ecalBrem_dist = block.
dist(brem_index,ecalBrem_index,
484 if (ecalBrem_index == ClosestEcalGsf_index && (ecalBrem_dist + 0.0012) > ecalGsf_dist)
continue;
487 std::multimap<double, unsigned int> sortedBremElems;
493 bool isGoodBrem =
false;
494 unsigned int sortedBrem_index = CutIndex;
495 for (std::multimap<double, unsigned int>::iterator ibs = sortedBremElems.begin();
496 ibs != sortedBremElems.end();ibs++) {
497 unsigned int temp_sortedBrem_index = ibs->second;
498 std::multimap<double, unsigned int> sortedGsfElems;
503 bool enteredInPrimaryGsf =
false;
504 for (std::multimap<double, unsigned int>::iterator igs = sortedGsfElems.begin();
505 igs != sortedGsfElems.end();igs++) {
510 if(igs->second == gsfIs[iEle]) {
512 sortedBrem_index = temp_sortedBrem_index;
514 enteredInPrimaryGsf =
true;
518 if(enteredInPrimaryGsf)
526 std::multimap<double, unsigned int> ecalOtherGsfElems;
531 if (ecalOtherGsfElems.size() > 0) {
534 if(ecalOtherGsfElems.begin()->second != gsfIs[iEle] &&
544 elements[ecalBrem_index].clusterRef();
550 if(sortedBremEcal_deta < 0.015) {
552 cleanedEcalBremElems.insert(pair<unsigned int,unsigned int>(sortedBrem_index,ecalBrem_index));
555 if (BremTrajP > latestBrem_trajP) {
556 latestBrem_trajP = BremTrajP;
557 latestBrem_index = sortedBrem_index;
559 if (DebugSetLinksDetailed)
560 cout <<
" brem Index " << sortedBrem_index
561 <<
" associated cluster " << ecalBrem_index <<
" BremTrajP " << BremTrajP <<endl;
566 localactive[ecalBrem_index] =
false;
567 bool alreadyfound =
false;
568 for(
unsigned int ii=0;
ii<keyBremIndex.size();
ii++) {
569 if (sortedBrem_index == keyBremIndex[
ii]) alreadyfound =
true;
571 if (alreadyfound ==
false) {
572 keyBremIndex.push_back(sortedBrem_index);
573 localactive[sortedBrem_index] =
false;
582 vector<unsigned int> GsfElemIndex(0);
583 vector<unsigned int> EcalIndex(0);
586 if (ClosestEcalGsf_index < CutIndex) {
587 GsfElemIndex.push_back(ClosestEcalGsf_index);
588 localactive[ClosestEcalGsf_index] =
false;
589 for (std::multimap<double, unsigned int>::iterator
ii = ecalGsfElems.begin();
590 ii != ecalGsfElems.end();
ii++) {
591 if(localactive[
ii->second]) {
593 std::multimap<double, unsigned int> ecalOtherGsfElems;
598 if(ecalOtherGsfElems.size()) {
599 if(ecalOtherGsfElems.begin()->second != gsfIs[iEle])
continue;
604 float etacl = clusterRef->eta();
605 if( fabs(eta_gsf-etacl) < 0.05) {
606 GsfElemIndex.push_back(
ii->second);
607 localactive[
ii->second] =
false;
608 if (DebugSetLinksDetailed)
609 cout <<
" ExtraCluster From Gsf " <<
ii->second << endl;
646 if(GsfElemIndex.size() == 0){
647 if(latestBrem_index < CutIndex) {
648 unsigned int ckey = cleanedEcalBremElems.count(latestBrem_index);
650 unsigned int temp_cal =
651 cleanedEcalBremElems.find(latestBrem_index)->second;
652 GsfElemIndex.push_back(temp_cal);
653 if (DebugSetLinksDetailed)
654 cout <<
"******************** Gsf Cluster From Brem " << temp_cal
655 <<
" Latest Brem index " << latestBrem_index
656 <<
" ************************* " << endl;
659 pair<multimap<unsigned int,unsigned int>::iterator,multimap<unsigned int,unsigned int>::iterator>
ret;
660 ret = cleanedEcalBremElems.equal_range(latestBrem_index);
661 multimap<unsigned int,unsigned int>::iterator it;
662 for(it=ret.first; it!=ret.second; ++it) {
663 GsfElemIndex.push_back((*it).second);
664 if (DebugSetLinksDetailed)
665 cout <<
"******************** Gsf Cluster From Brem " << (*it).second
666 <<
" Latest Brem index " << latestBrem_index
667 <<
" ************************* " << endl;
671 unsigned int elToErase = 0;
672 for(
unsigned int i = 0;
i<keyBremIndex.size();
i++) {
673 if(latestBrem_index == keyBremIndex[
i]) {
677 keyBremIndex.erase(keyBremIndex.begin()+elToErase);
685 for(
unsigned int iConv=0; iConv<gsfIs.size(); iConv++) {
693 if (DebugSetLinksDetailed)
694 cout <<
" PFElectronAlgo:: I'm running on convGsfBrem " << endl;
696 float conv_dist = block.
dist(gsfIs[iConv],gsfIs[iEle],
701 std::multimap<double, unsigned int> ecalConvElems;
706 if(ecalConvElems.size() > 0) {
708 if(localactive[(ecalConvElems.begin()->second)] ==
true) {
709 if (DebugSetLinksDetailed)
710 cout <<
" PFElectronAlgo:: convGsfBrem has a ECAL cluster linked and free" << endl;
712 std::multimap<double, unsigned int> ecalOtherGsfPrimElems;
714 ecalOtherGsfPrimElems,
717 if(ecalOtherGsfPrimElems.size()>0) {
718 unsigned int gsfprimcheck_index = ecalOtherGsfPrimElems.begin()->second;
724 if (DebugSetLinksDetailed)
725 cout <<
" PFElectronAlgo: !!!!!!! convGsfBrem ECAL cluster has been stored !!!!!!! "
726 <<
" Energy " << clusterRef->energy() <<
" eta,phi " << clusterRef->position().eta()
727 <<
", " << clusterRef->position().phi() << endl;
729 GsfElemIndex.push_back(ecalConvElems.begin()->second);
730 convGsfTrack_.push_back(make_pair(ecalConvElems.begin()->second,gsfIs[iConv]));
731 localactive[ecalConvElems.begin()->second] =
false;
743 EcalIndex.insert(EcalIndex.end(),GsfElemIndex.begin(),GsfElemIndex.end());
748 for(
unsigned int i =0;
i<keyBremIndex.size();
i++) {
749 unsigned int ikey = keyBremIndex[
i];
750 unsigned int ckey = cleanedEcalBremElems.count(ikey);
751 vector<unsigned int> BremElemIndex(0);
753 unsigned int temp_cal =
754 cleanedEcalBremElems.find(ikey)->second;
755 BremElemIndex.push_back(temp_cal);
758 pair<multimap<unsigned int,unsigned int>::iterator,multimap<unsigned int,unsigned int>::iterator>
ret;
759 ret = cleanedEcalBremElems.equal_range(ikey);
760 multimap<unsigned int,unsigned int>::iterator it;
761 for(it=ret.first; it!=ret.second; ++it) {
762 BremElemIndex.push_back((*it).second);
765 EcalIndex.insert(EcalIndex.end(),BremElemIndex.begin(),BremElemIndex.end());
766 associatedToBrems_.insert(pair<
unsigned int,vector<unsigned int> >(ikey,BremElemIndex));
771 vector<unsigned int> convBremKFTrack;
772 convBremKFTrack.clear();
773 if (kfElems.size() > 0) {
774 for(std::multimap<double, unsigned int>::iterator itkf = kfElems.begin();
775 itkf != kfElems.end(); ++itkf) {
783 std::multimap<double, unsigned int> ecalConvElems;
788 if(ecalConvElems.size() > 0) {
794 float secpin = trkRef->p();
798 float eneclust =clust->
clusterRef()->energy();
804 std::multimap<double, unsigned int> hcalConvElems;
814 float enehcalclust = -1;
815 if(hcalConvElems.size() > 0) {
818 enehcalclust =clusthcal->
clusterRef()->energy();
820 if( (enehcalclust / (enehcalclust+eneclust) ) > 0.1 && Algo < 3) {
822 if(enehcalclust > eneclust)
824 if(secpin > (enehcalclust+eneclust) )
830 if(localactive[(ecalConvElems.begin()->second)] ==
false) {
832 if(isHoE || isPoHE) {
833 if (DebugSetLinksDetailed)
834 cout <<
"PFElectronAlgo:: LOCKED ECAL REJECTED TRACK FOR H/E or P/(H+E) "
835 <<
" H/H+E " << enehcalclust/(enehcalclust+eneclust)
836 <<
" H/E " << enehcalclust/eneclust
837 <<
" P/(H+E) " << secpin/(enehcalclust+eneclust)
838 <<
" HCAL ENE " << enehcalclust
839 <<
" ECAL ENE " << eneclust
840 <<
" secPIN " << secpin
841 <<
" Algo Track " << Algo << endl;
846 for(
unsigned int iecal =0; iecal < EcalIndex.size(); iecal++) {
849 if(EcalIndex[iecal] == ecalConvElems.begin()->second) {
850 if (DebugSetLinksDetailed)
851 cout <<
" PFElectronAlgo:: Conv Brem Recovery locked cluster and I will lock also the KF track " << endl;
852 convBremKFTrack.push_back(itkf->second);
861 if (DebugSetLinksDetailed)
862 cout <<
"PFElectronAlgo:: FREE ECAL REJECTED TRACK FOR H/H+E "
863 <<
" H/H+E " << (enehcalclust / (enehcalclust+eneclust) )
864 <<
" H/E " << enehcalclust/eneclust
865 <<
" P/(H+E) " << secpin/(enehcalclust+eneclust)
866 <<
" HCAL ENE " << enehcalclust
867 <<
" ECAL ENE " << eneclust
868 <<
" secPIN " << secpin
869 <<
" Algo Track " << Algo << endl;
874 std::multimap<double, unsigned int> ecalOtherKFPrimElems;
876 ecalOtherKFPrimElems,
879 if(ecalOtherKFPrimElems.size() > 0) {
883 bool isFromGSF =
false;
884 for(std::multimap<double, unsigned int>::iterator itclos = kfElems.begin();
885 itclos != kfElems.end(); ++itclos) {
886 if(ecalOtherKFPrimElems.begin()->second == itclos->second) {
896 float Epin = eneclust/secpin;
899 float totenergy = 0.;
900 for(
unsigned int ikeyecal = 0;
901 ikeyecal<EcalIndex.size(); ikeyecal++){
903 bool foundcluster =
false;
905 for(
unsigned int i2 = 0; i2<ikeyecal-1; i2++) {
906 if(EcalIndex[ikeyecal] == EcalIndex[i2])
910 if(foundcluster)
continue;
913 totenergy += clusasso->
clusterRef()->energy();
918 if(totenergy == 0.) {
919 if (DebugSetLinksDetailed)
920 cout <<
"PFElectronAlgo:: REJECTED_NULLTOT totenergy " << totenergy << endl;
926 double res_before = fabs((totenergy-Pin_gsf)/Pin_gsf);
927 double res_after = fabs(((totenergy+eneclust)-Pin_gsf)/Pin_gsf);
929 if(res_before < res_after) {
930 if (DebugSetLinksDetailed)
931 cout <<
"PFElectronAlgo::REJECTED_RES totenergy " << totenergy <<
" Pin_gsf " << Pin_gsf <<
" cluster to secondary " << eneclust
932 <<
" Res before " << res_before <<
" res_after " << res_after << endl;
937 if (DebugSetLinksDetailed)
938 cout <<
"PFElectronAlgo:: conv brem found asso to ECAL linked to a secondary KF " << endl;
939 convBremKFTrack.push_back(itkf->second);
940 GsfElemIndex.push_back(ecalConvElems.begin()->second);
941 EcalIndex.push_back(ecalConvElems.begin()->second);
942 localactive[(ecalConvElems.begin()->second)] =
false;
943 localactive[(itkf->second)] =
false;
954 double sumEtEcalInTheCone = 0.;
959 double PhiFC = clust->
clusterRef()->position().Phi();
960 double EtaFC = clust->
clusterRef()->position().Eta();
963 for(
unsigned int iEcal=0; iEcal<ecalIs.size(); iEcal++) {
964 bool foundcluster =
false;
965 for(
unsigned int ikeyecal = 0;
966 ikeyecal<EcalIndex.size(); ikeyecal++){
967 if(ecalIs[iEcal] == EcalIndex[ikeyecal])
972 if(foundcluster ==
false) {
975 double eta_clust = clustExt->
clusterRef()->position().Eta();
976 double phi_clust = clustExt->
clusterRef()->position().Phi();
977 double theta_clust = clustExt->
clusterRef()->position().Theta();
978 double deta_clust = eta_clust - EtaFC;
979 double dphi_clust = phi_clust - PhiFC;
980 if ( dphi_clust < -
M_PI )
981 dphi_clust = dphi_clust + 2.*
M_PI;
982 else if ( dphi_clust >
M_PI )
983 dphi_clust = dphi_clust - 2.*
M_PI;
984 double DR =
sqrt(deta_clust*deta_clust+
985 dphi_clust*dphi_clust);
989 vector<double> ps1Ene(0);
990 vector<double> ps2Ene(0);
994 double ET_calib = EE_calib*
sin(theta_clust);
995 sumEtEcalInTheCone += ET_calib;
1001 unsigned int sumNTracksInTheCone = 0;
1002 double sumPtTracksInTheCone = 0.;
1003 for(
unsigned int iTrack=0; iTrack<trackIs.size(); iTrack++) {
1005 if(localactive[(trackIs[iTrack])]==
true) {
1010 double deta_trk = trkref->eta() - RefGSF->etaMode();
1011 double dphi_trk = trkref->phi() - RefGSF->phiMode();
1012 if ( dphi_trk < -
M_PI )
1013 dphi_trk = dphi_trk + 2.*
M_PI;
1014 else if ( dphi_trk >
M_PI )
1015 dphi_trk = dphi_trk - 2.*
M_PI;
1016 double DR =
sqrt(deta_trk*deta_trk+
1019 int NValPixelHit = trkref->hitPattern().numberOfValidPixelHits();
1021 if(DR < coneTrackIsoForEgammaSC_ && NValPixelHit >=3) {
1022 sumNTracksInTheCone++;
1023 sumPtTracksInTheCone+=trkref->pt();
1030 bool isBarrelIsolated =
false;
1031 if( fabs(EtaFC < 1.478) &&
1034 isBarrelIsolated =
true;
1037 bool isEndcapIsolated =
false;
1038 if( fabs(EtaFC >= 1.478) &&
1041 isEndcapIsolated =
true;
1045 if(DebugSetLinksDetailed) {
1046 if(fabs(EtaFC < 1.478) && isBarrelIsolated ==
false) {
1047 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND BUT FAILS ISOLATION:BARREL *** "
1048 <<
" sumEtEcalInTheCone " <<sumEtEcalInTheCone
1049 <<
" sumNTracksInTheCone " << sumNTracksInTheCone
1050 <<
" sumPtTracksInTheCone " << sumPtTracksInTheCone << endl;
1052 if(fabs(EtaFC >= 1.478) && isEndcapIsolated ==
false) {
1053 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND BUT FAILS ISOLATION:ENDCAP *** "
1054 <<
" sumEtEcalInTheCone " <<sumEtEcalInTheCone
1055 <<
" sumNTracksInTheCone " << sumNTracksInTheCone
1056 <<
" sumPtTracksInTheCone " << sumPtTracksInTheCone << endl;
1063 if(isBarrelIsolated || isEndcapIsolated ) {
1067 double totenergy = 0.;
1068 for(
unsigned int ikeyecal = 0;
1069 ikeyecal<EcalIndex.size(); ikeyecal++){
1071 bool foundcluster =
false;
1073 for(
unsigned int i2 = 0; i2<ikeyecal-1; i2++) {
1074 if(EcalIndex[ikeyecal] == EcalIndex[i2])
1075 foundcluster =
true;;
1078 if(foundcluster)
continue;
1081 totenergy += clusasso->
clusterRef()->energy();
1087 for(
unsigned int ikeyecal = 0;
1088 ikeyecal<EcalIndex.size(); ikeyecal++){
1090 bool foundcluster =
false;
1092 for(
unsigned int i2 = 0; i2<ikeyecal-1; i2++) {
1093 if(EcalIndex[ikeyecal] == EcalIndex[i2])
1094 foundcluster =
true;
1097 if(foundcluster)
continue;
1100 std::multimap<double, unsigned int> ecalFromSuperClusterElems;
1102 ecalFromSuperClusterElems,
1105 if(ecalFromSuperClusterElems.size() > 0) {
1106 for(std::multimap<double, unsigned int>::iterator itsc = ecalFromSuperClusterElems.begin();
1107 itsc != ecalFromSuperClusterElems.end(); ++itsc) {
1108 if(localactive[itsc->second] ==
false) {
1112 std::multimap<double, unsigned int> ecalOtherKFPrimElems;
1114 ecalOtherKFPrimElems,
1117 if(ecalOtherKFPrimElems.size() > 0) {
1118 if(localactive[ecalOtherKFPrimElems.begin()->second] ==
true) {
1119 if (DebugSetLinksDetailed)
1120 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND BUT FAILS KF VETO *** " << endl;
1124 bool isInTheEtaRange =
false;
1127 double deta_clustToAdd = clustToAdd->
clusterRef()->position().Eta() - EtaFC;
1128 double ene_clustToAdd = clustToAdd->
clusterRef()->energy();
1130 if(fabs(deta_clustToAdd) < 0.05)
1131 isInTheEtaRange =
true;
1134 bool isBetterEpin =
false;
1135 if(isInTheEtaRange ==
false ) {
1136 if (DebugSetLinksDetailed)
1137 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND BUT FAILS GAMMA DETA RANGE *** "
1138 << fabs(deta_clustToAdd) << endl;
1140 if(KfGsf_index < CutIndex) {
1142 double res_before_gsf = fabs((totenergy-Pin_gsf)/Pin_gsf);
1143 double res_after_gsf = fabs(((totenergy+ene_clustToAdd)-Pin_gsf)/Pin_gsf);
1148 double Pin_kf = trackEl->
trackRef()->p();
1149 double res_before_kf = fabs((totenergy-Pin_kf)/Pin_kf);
1150 double res_after_kf = fabs(((totenergy+ene_clustToAdd)-Pin_kf)/Pin_kf);
1153 if(res_after_gsf < res_before_gsf && res_after_kf < res_before_kf ) {
1154 isBetterEpin =
true;
1157 if (DebugSetLinksDetailed)
1158 cout <<
"**** PFElectronAlgo:: SUPERCLUSTER FOUND AND FAILS ALSO RES_EPIN"
1159 <<
" tot energy " << totenergy
1160 <<
" Pin_gsf " << Pin_gsf
1161 <<
" Pin_kf " << Pin_kf
1162 <<
" cluster from SC to ADD " << ene_clustToAdd
1163 <<
" Res before GSF " << res_before_gsf <<
" res_after_gsf " << res_after_gsf
1164 <<
" Res before KF " << res_before_kf <<
" res_after_kf " << res_after_kf << endl;
1169 if(isInTheEtaRange || isBetterEpin) {
1170 if (DebugSetLinksDetailed)
1171 cout <<
"!!!! PFElectronAlgo:: ECAL from SUPERCLUSTER FOUND !!!!! " << endl;
1172 GsfElemIndex.push_back(itsc->second);
1173 EcalIndex.push_back(itsc->second);
1174 localactive[(itsc->second)] =
false;
1183 if(KfGsf_index < CutIndex)
1184 GsfElemIndex.push_back(KfGsf_index);
1185 else if(KfGsf_secondIndex < CutIndex)
1186 GsfElemIndex.push_back(KfGsf_secondIndex);
1189 GsfElemIndex.insert(GsfElemIndex.end(),convBremKFTrack.begin(),convBremKFTrack.end());
1190 GsfElemIndex.insert(GsfElemIndex.end(),keyBremIndex.begin(),keyBremIndex.end());
1191 associatedToGsf_.insert(pair<
unsigned int, vector<unsigned int> >(gsfIs[iEle],GsfElemIndex));
1194 for(
unsigned int ikeyecal = 0;
1195 ikeyecal<EcalIndex.size(); ikeyecal++){
1198 vector<unsigned int> EcalElemsIndex(0);
1200 std::multimap<double, unsigned int> PS1Elems;
1205 for( std::multimap<double, unsigned int>::iterator it = PS1Elems.begin();
1206 it != PS1Elems.end();it++) {
1207 unsigned int index = it->second;
1208 if(localactive[index] ==
true) {
1211 std::multimap<double, unsigned> sortedECAL;
1216 unsigned jEcal = sortedECAL.begin()->second;
1217 if ( jEcal != EcalIndex[ikeyecal])
continue;
1220 EcalElemsIndex.push_back(index);
1221 localactive[
index] =
false;
1225 std::multimap<double, unsigned int> PS2Elems;
1230 for( std::multimap<double, unsigned int>::iterator it = PS2Elems.begin();
1231 it != PS2Elems.end();it++) {
1232 unsigned int index = it->second;
1233 if(localactive[index] ==
true) {
1235 std::multimap<double, unsigned> sortedECAL;
1240 unsigned jEcal = sortedECAL.begin()->second;
1241 if ( jEcal != EcalIndex[ikeyecal])
continue;
1243 EcalElemsIndex.push_back(index);
1244 localactive[
index] =
false;
1251 std::multimap<double, unsigned int> hcalGsfElems;
1256 for( std::multimap<double, unsigned int>::iterator it = hcalGsfElems.begin();
1257 it != hcalGsfElems.end();it++) {
1258 unsigned int index = it->second;
1271 EcalElemsIndex.push_back(index);
1272 localactive[
index] =
false;
1277 if(hcalGsfElems.size() == 0 && ClosestEcalWithKf ==
true) {
1278 std::multimap<double, unsigned int> hcalKfElems;
1283 for( std::multimap<double, unsigned int>::iterator it = hcalKfElems.begin();
1284 it != hcalKfElems.end();it++) {
1285 unsigned int index = it->second;
1286 if(localactive[index] ==
true) {
1289 std::multimap<double, unsigned> sortedKf;
1294 unsigned jKf = sortedKf.begin()->second;
1295 if ( jKf != KfGsf_index)
continue;
1296 EcalElemsIndex.push_back(index);
1297 localactive[
index] =
false;
1302 std::multimap<double, unsigned int> kfEtraElems;
1307 if(kfEtraElems.size() > 0) {
1308 for( std::multimap<double, unsigned int>::iterator it = kfEtraElems.begin();
1309 it != kfEtraElems.end();it++) {
1310 unsigned int index = it->second;
1318 bool thisIsAMuon =
false;
1320 if (DebugSetLinksDetailed && thisIsAMuon)
1321 cout <<
" This is a Muon: index " << index << endl;
1322 if(localactive[index] ==
true && !thisIsAMuon) {
1323 if(index != KfGsf_index) {
1326 std::multimap<double, unsigned> sortedECAL;
1331 unsigned jEcal = sortedECAL.begin()->second;
1332 if ( jEcal != EcalIndex[ikeyecal])
continue;
1333 EcalElemsIndex.push_back(index);
1334 localactive[
index] =
false;
1341 associatedToEcal_.insert(pair<
unsigned int,vector<unsigned int> >(EcalIndex[ikeyecal],EcalElemsIndex));
1350 if (DebugSetLinksSummary) {
1351 if(IsThereAGoodGSFTrack) {
1352 if (DebugSetLinksSummary)
cout <<
" -- The Link Summary --" << endl;
1353 for(
map<
unsigned int,vector<unsigned int> >::iterator it = associatedToGsf_.begin();
1354 it != associatedToGsf_.end(); it++) {
1356 if (DebugSetLinksSummary)
cout <<
" AssoGsf " << it->first << endl;
1357 vector<unsigned int> eleasso = it->second;
1358 for(
unsigned int i=0;
i<eleasso.size();
i++) {
1361 if (DebugSetLinksSummary)
1362 cout <<
" AssoGsfElements BREM " << eleasso[
i] << endl;
1365 if (DebugSetLinksSummary)
1366 cout <<
" AssoGsfElements ECAL " << eleasso[
i] << endl;
1369 if (DebugSetLinksSummary)
1370 cout <<
" AssoGsfElements KF " << eleasso[
i] << endl;
1373 if (DebugSetLinksSummary)
1374 cout <<
" AssoGsfElements ????? " << eleasso[
i] << endl;
1379 for(
map<
unsigned int,vector<unsigned int> >::iterator it = associatedToBrems_.begin();
1380 it != associatedToBrems_.end(); it++) {
1381 if (DebugSetLinksSummary)
cout <<
" AssoBrem " << it->first << endl;
1382 vector<unsigned int> eleasso = it->second;
1383 for(
unsigned int i=0;
i<eleasso.size();
i++) {
1386 if (DebugSetLinksSummary)
1387 cout <<
" AssoBremElements ECAL " << eleasso[
i] << endl;
1390 if (DebugSetLinksSummary)
1391 cout <<
" AssoBremElements ????? " << eleasso[
i] << endl;
1396 for(
map<
unsigned int,vector<unsigned int> >::iterator it = associatedToEcal_.begin();
1397 it != associatedToEcal_.end(); it++) {
1398 if (DebugSetLinksSummary)
cout <<
" AssoECAL " << it->first << endl;
1399 vector<unsigned int> eleasso = it->second;
1400 for(
unsigned int i=0;
i<eleasso.size();
i++) {
1403 if (DebugSetLinksSummary)
1404 cout <<
" AssoECALElements PS1 " << eleasso[
i] << endl;
1407 if (DebugSetLinksSummary)
1408 cout <<
" AssoECALElements PS2 " << eleasso[
i] << endl;
1411 if (DebugSetLinksSummary)
1412 cout <<
" AssoECALElements HCAL " << eleasso[
i] << endl;
1415 if (DebugSetLinksSummary)
1416 cout <<
" AssoHCALElements ????? " << eleasso[
i] << endl;
1420 if (DebugSetLinksSummary)
1421 cout <<
"-- End Summary --" << endl;
1426 return IsThereAGoodGSFTrack;
1430 AssMap& associatedToGsf_,
1431 AssMap& associatedToBrems_,
1432 AssMap& associatedToEcal_,
1438 bool DebugIDOutputs =
false;
1439 if(DebugIDOutputs)
cout <<
" ######## Enter in SetIDOutputs #########" << endl;
1441 unsigned int cgsf=0;
1442 for (
map<
unsigned int,vector<unsigned int> >::iterator igsf = associatedToGsf_.begin();
1443 igsf != associatedToGsf_.end(); igsf++,cgsf++) {
1445 float Ene_ecalgsf = 0.;
1446 float Ene_hcalgsf = 0.;
1447 double sigmaEtaEta = 0.;
1448 float deta_gsfecal = 0.;
1449 float Ene_ecalbrem = 0.;
1450 float Ene_extraecalgsf = 0.;
1451 bool LateBrem =
false;
1453 int FirstBrem = 1000;
1454 unsigned int ecalGsf_index = 100000;
1455 unsigned int kf_index = 100000;
1463 unsigned int gsf_index = igsf->first;
1470 Ein_gsf =
sqrt(RefGSF->pMode()*
1471 RefGSF->pMode()+m_el*m_el);
1474 float Eout_gsf = GsfEl->
Pout().t();
1479 cout <<
" setIdOutput! GSF Track: Ein " << Ein_gsf
1480 <<
" eta,phi " << Etaout_gsf
1484 vector<unsigned int> assogsf_index = igsf->second;
1485 bool FirstEcalGsf =
true;
1486 for (
unsigned int ielegsf=0;ielegsf<assogsf_index.size();ielegsf++) {
1497 if(!isPrim)
continue;
1499 kf_index = assogsf_index[ielegsf];
1504 unsigned int keyecalgsf = assogsf_index[ielegsf];
1505 vector<unsigned int> assoecalgsf_index = associatedToEcal_.find(keyecalgsf)->second;
1507 vector<double> ps1Ene(0);
1508 vector<double> ps2Ene(0);
1509 for(
unsigned int ips =0; ips<assoecalgsf_index.size();ips++) {
1512 PFClusterRef psref = elements[(assoecalgsf_index[ips])].clusterRef();
1513 ps1Ene.push_back(psref->energy());
1516 PFClusterRef psref = elements[(assoecalgsf_index[ips])].clusterRef();
1517 ps2Ene.push_back(psref->energy());
1526 FirstEcalGsf =
false;
1527 ecalGsf_index = assogsf_index[ielegsf];
1534 posX += Ene_ecalgsf * clusterRef->position().X();
1535 posY += Ene_ecalgsf * clusterRef->position().Y();
1536 posZ += Ene_ecalgsf * clusterRef->position().Z();
1539 cout <<
" setIdOutput! GSF ECAL Cluster E " << Ene_ecalgsf
1540 <<
" eta,phi " << clusterRef->position().eta()
1541 <<
", " << clusterRef->position().phi() << endl;
1543 deta_gsfecal = clusterRef->position().eta() - Etaout_gsf;
1545 vector< const reco::PFCluster * > pfClust_vec(0);
1546 pfClust_vec.clear();
1547 pfClust_vec.push_back(&(*clusterRef));
1557 Ene_extraecalgsf += TempClus_energy;
1558 posX += TempClus_energy * clusterRef->position().X();
1559 posY += TempClus_energy * clusterRef->position().Y();
1560 posZ += TempClus_energy * clusterRef->position().Z();
1563 cout <<
" setIdOutput! Extra ECAL Cluster E "
1564 << TempClus_energy <<
" Tot " << Ene_extraecalgsf << endl;
1570 unsigned int brem_index = assogsf_index[ielegsf];
1575 if (TrajPos < FirstBrem) FirstBrem = TrajPos;
1577 vector<unsigned int> assobrem_index = associatedToBrems_.find(brem_index)->second;
1578 for (
unsigned int ibrem = 0; ibrem < assobrem_index.size(); ibrem++){
1580 unsigned int keyecalbrem = assobrem_index[ibrem];
1581 vector<unsigned int> assoelebrem_index = associatedToEcal_.find(keyecalbrem)->second;
1582 vector<double> ps1EneFromBrem(0);
1583 vector<double> ps2EneFromBrem(0);
1584 for (
unsigned int ielebrem=0; ielebrem<assoelebrem_index.size();ielebrem++) {
1586 PFClusterRef psref = elements[(assoelebrem_index[ielebrem])].clusterRef();
1587 ps1EneFromBrem.push_back(psref->energy());
1590 PFClusterRef psref = elements[(assoelebrem_index[ielebrem])].clusterRef();
1591 ps2EneFromBrem.push_back(psref->energy());
1595 if( assobrem_index[ibrem] != ecalGsf_index) {
1597 elements[(assobrem_index[ibrem])].clusterRef();
1599 Ene_ecalbrem += BremClus_energy;
1600 posX += BremClus_energy * clusterRef->position().X();
1601 posY += BremClus_energy * clusterRef->position().Y();
1602 posZ += BremClus_energy * clusterRef->position().Z();
1605 if (DebugIDOutputs)
cout <<
" setIdOutput::BREM Cluster "
1606 << BremClus_energy <<
" eta,phi "
1607 << clusterRef->position().eta() <<
", "
1608 << clusterRef->position().phi() << endl;
1617 if (Ene_ecalgsf > 0.) {
1625 float Pt_gsf = RefGSF->ptMode();
1630 if(RefGSF->ptModeError() > 0.)
1633 nhit_gsf= RefGSF->hitPattern().trackerLayersWithMeasurement();
1634 chi2_gsf = RefGSF->normalizedChi2();
1643 nhit_kf= RefKF->hitPattern().trackerLayersWithMeasurement();
1644 chi2_kf = RefKF->normalizedChi2();
1653 EtotPinMode = (Ene_ecalgsf + Ene_ecalbrem + Ene_extraecalgsf) / Ein_gsf;
1672 HOverHE = Ene_hcalgsf/(Ene_hcalgsf + Ene_ecalgsf);
1707 double mvaValue =
tmvaReader_->EvaluateMVA(
"BDT");
1711 myExtra.
setMVA(mvaValue);
1730 unsigned int iextratrack = 0;
1731 unsigned int itrackHcalLinked = 0;
1732 float SumExtraKfP = 0.;
1735 double Etotal = Ene_ecalgsf + Ene_ecalbrem + Ene_extraecalgsf;
1740 double ETtotal = Etotal*
sin(sc_pflow.Theta());
1741 double phiTrack = RefGSF->phiMode();
1742 double dphi_normalsc = sc_pflow.Phi() - phiTrack;
1743 if ( dphi_normalsc < -
M_PI )
1744 dphi_normalsc = dphi_normalsc + 2.*
M_PI;
1745 else if ( dphi_normalsc >
M_PI )
1746 dphi_normalsc = dphi_normalsc - 2.*
M_PI;
1747 dphi_normalsc = fabs(dphi_normalsc);
1750 if(ecalGsf_index < 100000) {
1751 vector<unsigned int> assoecalgsf_index = associatedToEcal_.find(ecalGsf_index)->second;
1752 for(
unsigned int itrk =0; itrk<assoecalgsf_index.size();itrk++) {
1767 int nexhits = trackref->hitPattern().numberOfLostHits(HitPattern::MISSING_INNER_HITS);
1769 bool trackIsFromPrimaryVertex =
false;
1771 if ( (*trackIt).castTo<
TrackRef>() == trackref ) {
1772 trackIsFromPrimaryVertex =
true;
1778 if(Algo < 3 && nexhits == 0 && trackIsFromPrimaryVertex) {
1781 cout <<
" The ecalGsf cluster is not isolated: >0 KF extra with algo < 3" << endl;
1783 float p_trk = trackref->p();
1788 cout <<
" p_trk " << p_trk
1789 <<
" nexhits " << nexhits << endl;
1791 SumExtraKfP += p_trk;
1794 std::multimap<double, unsigned int> hcalKfElems;
1799 if(hcalKfElems.size() > 0) {
1806 if( iextratrack > 0) {
1808 if(iextratrack > 3 || Ene_hcalgsf > 10 || (SumExtraKfP/Ene_ecalgsf) > 1.
1809 || (ETtotal > 50. && iextratrack > 1 && (Ene_hcalgsf/Ene_ecalgsf) > 0.1) ) {
1811 cout <<
" *****This electron candidate is discarded: Non isolated # tracks "
1812 << iextratrack <<
" HOverHE " <<
HOverHE
1813 <<
" SumExtraKfP/Ene_ecalgsf " << SumExtraKfP/Ene_ecalgsf
1814 <<
" SumExtraKfP " << SumExtraKfP
1815 <<
" Ene_ecalgsf " << Ene_ecalgsf
1816 <<
" ETtotal " << ETtotal
1817 <<
" Ene_hcalgsf/Ene_ecalgsf " << Ene_hcalgsf/Ene_ecalgsf
1826 ((EtotPinMode < 1.1 && EtotPinMode > 0.6) && (fabs(
Eta_gsf) >= 1.0 && fabs(
Eta_gsf) <= 2.0))) {
1828 (itrackHcalLinked == iextratrack) &&
1829 kf_index < 100000 ) {
1834 cout <<
" *****This electron is reactivated # tracks "
1835 << iextratrack <<
" #tracks hcal linked " << itrackHcalLinked
1836 <<
" SumExtraKfP/Ene_ecalgsf " << SumExtraKfP/Ene_ecalgsf
1838 <<
" eta gsf " << fabs(
Eta_gsf) <<
" kf index " << kf_index <<endl;
1845 cout <<
" *****This electron candidate is discarded HCAL ENERGY "
1856 cout <<
" *****This electron candidate is discarded Low ETOTPIN "
1862 if(ETtotal > 50. && dphi_normalsc > 0.1 ) {
1864 cout <<
" *****This electron candidate is discarded Large ANGLE "
1865 <<
" ETtotal " << ETtotal <<
" EGsfPoutMode " << dphi_normalsc << endl;
1871 if (DebugIDOutputs) {
1872 cout <<
" **** BDT observables ****" << endl;
1873 cout <<
" < Normalization > " << endl;
1874 cout <<
" Pt_gsf " << Pt_gsf <<
" Pin " << Ein_gsf <<
" Pout " << Eout_gsf
1875 <<
" Eta_gsf " <<
Eta_gsf << endl;
1876 cout <<
" < PureTracking > " << endl;
1883 <<
" nhit_kf " <<
nhit_kf << endl;
1884 cout <<
" < track-ecal-hcal-ps " << endl;
1890 <<
" HOverHE " <<
HOverHE <<
" Hcal energy " << Ene_hcalgsf
1894 cout <<
" !!!!!!!!!!!!!!!! the BDT output !!!!!!!!!!!!!!!!!: direct " << mvaValue
1895 <<
" corrected " <<
BDToutput_[cgsf] << endl;
1901 cout <<
" Gsf Ref isNULL " << endl;
1906 cout <<
" No clusters associated to the gsf " << endl;
1909 DebugIDOutputs =
false;
1917 AssMap& associatedToGsf_,
1918 AssMap& associatedToBrems_,
1919 AssMap& associatedToEcal_){
1927 bool DebugIDCandidates =
false;
1931 unsigned int cgsf=0;
1932 for (
map<
unsigned int,vector<unsigned int> >::iterator igsf = associatedToGsf_.begin();
1933 igsf != associatedToGsf_.end(); igsf++,cgsf++) {
1934 unsigned int gsf_index = igsf->first;
1944 float dpt=0;
float dpt_gsf=0;
1945 float Eene=0;
float dene=0;
float Hene=0.;
1950 std::vector<float> bremEnergyVec;
1952 std::vector<const PFCluster*> pfSC_Clust_vec;
1954 float de_gs = 0., de_me = 0., de_kf = 0.;
1960 float ps1TotEne = 0;
1961 float ps2TotEne = 0;
1962 vector<unsigned int> elementsToAdd(0);
1967 elementsToAdd.push_back(gsf_index);
1976 charge= RefGSF->chargeMode();
1977 nhit_gsf= RefGSF->hitPattern().trackerLayersWithMeasurement();
1979 momentum_gsf.SetPx(RefGSF->pxMode());
1980 momentum_gsf.SetPy(RefGSF->pyMode());
1981 momentum_gsf.SetPz(RefGSF->pzMode());
1982 float ENE=
sqrt(RefGSF->pMode()*
1983 RefGSF->pMode()+m_el*m_el);
1985 if( DebugIDCandidates )
1986 cout <<
"SetCandidates:: GsfTrackRef: Ene " << ENE
1987 <<
" charge " << charge <<
" nhits " << nhit_gsf <<endl;
1989 momentum_gsf.SetE(ENE);
1990 dpt_gsf=RefGSF->ptModeError()*
1991 (RefGSF->pMode()/RefGSF->ptMode());
1993 momentum_mean.SetPx(RefGSF->px());
1994 momentum_mean.SetPy(RefGSF->py());
1995 momentum_mean.SetPz(RefGSF->pz());
1996 float ENEm=
sqrt(RefGSF->p()*
1997 RefGSF->p()+m_el*m_el);
1998 momentum_mean.SetE(ENEm);
2003 if( DebugIDCandidates )
2004 cout <<
"SetCandidates:: !!!! NULL GSF Track Ref " << endl;
2008 vector<unsigned int> assogsf_index = igsf->second;
2009 unsigned int ecalGsf_index = 100000;
2010 bool FirstEcalGsf =
true;
2011 for (
unsigned int ielegsf=0;ielegsf<assogsf_index.size();ielegsf++) {
2014 elementsToAdd.push_back((assogsf_index[ielegsf]));
2019 if(!isPrim)
continue;
2025 nhit_kf=RefKF->hitPattern().trackerLayersWithMeasurement();
2026 momentum_kf.SetPx(RefKF->px());
2027 momentum_kf.SetPy(RefKF->py());
2028 momentum_kf.SetPz(RefKF->pz());
2029 float ENE=
sqrt(RefKF->p()*RefKF->p()+m_el*m_el);
2030 if( DebugIDCandidates )
2031 cout <<
"SetCandidates:: KFTrackRef: Ene " << ENE <<
" nhits " << nhit_kf << endl;
2033 momentum_kf.SetE(ENE);
2036 if( DebugIDCandidates )
2037 cout <<
"SetCandidates:: !!!! NULL KF Track Ref " << endl;
2042 unsigned int keyecalgsf = assogsf_index[ielegsf];
2043 vector<unsigned int> assoecalgsf_index = associatedToEcal_.find(keyecalgsf)->second;
2044 vector<double> ps1Ene(0);
2045 vector<double> ps2Ene(0);
2049 for(
unsigned int ips =0; ips<assoecalgsf_index.size();ips++) {
2052 PFClusterRef psref = elements[(assoecalgsf_index[ips])].clusterRef();
2053 ps1Ene.push_back(psref->energy());
2054 elementsToAdd.push_back((assoecalgsf_index[ips]));
2057 PFClusterRef psref = elements[(assoecalgsf_index[ips])].clusterRef();
2058 ps2Ene.push_back(psref->energy());
2059 elementsToAdd.push_back((assoecalgsf_index[ips]));
2064 elementsToAdd.push_back((assoecalgsf_index[ips]));
2069 elementsToAdd.push_back((assogsf_index[ielegsf]));
2087 float ceta=
cl.position().eta();
2088 float cphi=
cl.position().phi();
2101 if( DebugIDCandidates )
2102 cout <<
"SetCandidates:: EcalCluster: EneNoCalib " << clust->
clusterRef()->energy()
2103 <<
" eta,phi " << ceta <<
"," << cphi <<
" Calib " << EE <<
" dE " << dE <<endl;
2105 bool elecCluster=
false;
2107 FirstEcalGsf =
false;
2109 ecalGsf_index = assogsf_index[ielegsf];
2117 clusterMomentum.SetPxPyPzE(EE*direction.x(),
2134 std::map<unsigned int,std::vector<reco::PFCandidate> >::iterator itcheck=
2139 std::vector<reco::PFCandidate> tmpVec;
2140 tmpVec.push_back(cluster_Candidate);
2146 itcheck->second.push_back(cluster_Candidate);
2150 posX += EE *
cl.position().X();
2151 posY += EE *
cl.position().Y();
2152 posZ += EE *
cl.position().Z();
2158 pfSC_Clust_vec.push_back( &
cl );
2166 unsigned int brem_index = assogsf_index[ielegsf];
2167 vector<unsigned int> assobrem_index = associatedToBrems_.find(brem_index)->second;
2168 elementsToAdd.push_back(brem_index);
2169 for (
unsigned int ibrem = 0; ibrem < assobrem_index.size(); ibrem++){
2172 if( assobrem_index[ibrem] != ecalGsf_index) {
2173 unsigned int keyecalbrem = assobrem_index[ibrem];
2174 const vector<unsigned int>& assoelebrem_index = associatedToEcal_.find(keyecalbrem)->second;
2175 vector<double> ps1EneFromBrem(0);
2176 vector<double> ps2EneFromBrem(0);
2177 for (
unsigned int ielebrem=0; ielebrem<assoelebrem_index.size();ielebrem++) {
2179 PFClusterRef psref = elements[(assoelebrem_index[ielebrem])].clusterRef();
2180 ps1EneFromBrem.push_back(psref->energy());
2181 elementsToAdd.push_back(assoelebrem_index[ielebrem]);
2184 PFClusterRef psref = elements[(assoelebrem_index[ielebrem])].clusterRef();
2185 ps2EneFromBrem.push_back(psref->energy());
2186 elementsToAdd.push_back(assoelebrem_index[ielebrem]);
2189 elementsToAdd.push_back(assobrem_index[ibrem]);
2196 bremEnergyVec.push_back(EE);
2198 float ceta = clusterRef->position().eta();
2201 if( DebugIDCandidates )
2202 cout <<
"SetCandidates:: BremCluster: Ene " << EE <<
" dE " << dE <<endl;
2205 posX += EE * clusterRef->position().X();
2206 posY += EE * clusterRef->position().Y();
2207 posZ += EE * clusterRef->position().Z();
2215 pfSC_Clust_vec.push_back( clusterRef.
get() );
2220 math::XYZPoint direction=clusterRef->position()/clusterRef->position().R();
2222 photonMomentum.SetPxPyPzE(EE*direction.x(),
2238 std::map<unsigned int,std::vector<reco::PFCandidate> >::iterator itcheck=
2243 std::vector<reco::PFCandidate> tmpVec;
2244 tmpVec.push_back(photon_Candidate);
2250 itcheck->second.push_back(photon_Candidate);
2260 double unCorrEene = Eene;
2261 double absEta = fabs(momentum_gsf.Eta());
2262 double emTheta = momentum_gsf.Theta();
2265 pfSC_Clust_vec.clear();
2267 if( DebugIDCandidates )
2268 cout <<
"PFEelectronAlgo:: absEta " << absEta <<
" theta " << emTheta
2269 <<
" EneRaw " << Eene <<
" Err " << dene;
2275 double Etene = Eene*
sin(emTheta);
2277 double emBR_et = emBR_e*
sin(emTheta);
2279 Eene = emCorrFull_et/
sin(emTheta);
2284 double emBR_et = emBR_e*
sin(emTheta);
2286 Eene = emCorrFull_et/
sin(emTheta);
2288 dene =
sqrt(dene)*(Eene/unCorrEene);
2292 if( DebugIDCandidates )
2293 cout <<
" EneCorrected " << Eene <<
" Err " << dene << endl;
2298 if(has_kf && unCorrEene > 0.) {
2304 std::multimap<double, unsigned int> bremElems;
2310 double phiTrack = RefGSF->phiMode();
2311 if(bremElems.size()>0) {
2312 unsigned int brem_index = bremElems.begin()->second;
2318 double dphi_normalsc = sc_pflow.Phi() - phiTrack;
2319 if ( dphi_normalsc < -
M_PI )
2320 dphi_normalsc = dphi_normalsc + 2.*
M_PI;
2321 else if ( dphi_normalsc >
M_PI )
2322 dphi_normalsc = dphi_normalsc - 2.*
M_PI;
2324 int chargeGsf = RefGSF->chargeMode();
2325 int chargeKf = RefKF->charge();
2328 if(dphi_normalsc < 0.)
2333 if(chargeKf == chargeGsf)
2335 else if(chargeGsf == chargeSC)
2340 if( DebugIDCandidates )
2341 cout <<
"PFElectronAlgo:: charge determination "
2342 <<
" charge GSF " << chargeGsf
2343 <<
" charge KF " << chargeKf
2344 <<
" charge SC " << chargeSC
2345 <<
" Final Charge " << charge << endl;
2350 if ((nhit_gsf<8) && (has_kf)){
2354 momentum=momentum_kf;
2356 float scale= Fe/momentum.E();
2359 if (Eene < 0.0001) {
2365 newmomentum.SetPxPyPzE(scale*momentum.Px(),
2366 scale*momentum.Py(),
2367 scale*momentum.Pz(),Fe);
2368 if( DebugIDCandidates )
2369 cout <<
"SetCandidates:: (nhit_gsf<8) && (has_kf):: pt " << newmomentum.pt() <<
" Ene " << Fe <<endl;
2373 if ((nhit_gsf>7) || (has_kf==
false)){
2375 de_gs=1-momentum_gsf.E()/Eene;
2376 de_me=1-momentum_mean.E()/Eene;
2377 de_kf=1-momentum_kf.E()/Eene;
2380 momentum=momentum_gsf;
2381 dpt=1/(dpt_gsf*dpt_gsf);
2388 Fe =((dene*Eene) +(dpt*momentum.E()))/(dene+dpt);
2394 if ((de_gs>0.05)&&(de_kf>0.05)){
2397 if ((de_gs<-0.1)&&(de_me<-0.1) &&(de_kf<0.) &&
2398 (momentum.E()/dpt_gsf) > 5. && momentum_gsf.pt() < 30.){
2401 float scale= Fe/momentum.E();
2403 newmomentum.SetPxPyPzE(scale*momentum.Px(),
2404 scale*momentum.Py(),
2405 scale*momentum.Pz(),Fe);
2406 if( DebugIDCandidates )
2407 cout <<
"SetCandidates::(nhit_gsf>7) || (has_kf==false) " << newmomentum.pt() <<
" Ene " << Fe <<endl;
2411 if (newmomentum.pt()>0.5){
2416 if( DebugIDCandidates )
2417 cout <<
"SetCandidates:: I am before doing candidate " <<endl;
2420 std::vector<float> clusterEnergyVec;
2421 clusterEnergyVec.push_back(RawEene);
2422 clusterEnergyVec.insert(clusterEnergyVec.end(),bremEnergyVec.begin(),bremEnergyVec.end());
2425 std::vector<reco::PFCandidateElectronExtra>::iterator itextra;
2429 itextra->setClusterEnergies(clusterEnergyVec);
2433 std::cout <<
" There is a big problem with the electron extra, PFElectronAlgo should crash soon " << RawEene << std::endl;
2439 temp_Candidate =
PFCandidate(charge,newmomentum,particleType);
2456 if(seedRef.
isAvailable() && seedRef->isEcalDriven()) {
2463 if( DebugIDCandidates )
2464 cout <<
"SetCandidates:: I am after doing candidate " <<endl;
2466 for (
unsigned int elad=0; elad<elementsToAdd.size();elad++){
2471 std::map<unsigned int, std::vector<reco::PFCandidate> >::const_iterator itcluster=
2475 const std::vector<reco::PFCandidate> & theClusters=itcluster->second;
2476 unsigned nclus=theClusters.size();
2478 for(
unsigned iclus=0;iclus<nclus;++iclus)
2485 bool bypassmva=
false;
2494 if( DebugIDCandidates ) {
2496 float esceg = itcheck->caloEnergy();
2498 <<
" SuperClusterEnergy " << esceg
2499 <<
" PF Energy " << Eene << endl;
2501 cout <<
" hoe " << itcheck->hcalOverEcal()
2502 <<
" tkiso04 " << itcheck->dr04TkSumPt()
2503 <<
" ecaliso04 " << itcheck->dr04EcalRecHitSumEt()
2504 <<
" hcaliso04 " << itcheck->dr04HcalTowerSumEt()
2505 <<
" tkiso03 " << itcheck->dr03TkSumPt()
2506 <<
" ecaliso03 " << itcheck->dr03EcalRecHitSumEt()
2507 <<
" hcaliso03 " << itcheck->dr03HcalTowerSumEt() << endl;
2515 if( mvaSelected || bypassmva ) {
2518 itextra->setStatus(PFCandidateElectronExtra::Selected,
true);
2522 itextra->setStatus(PFCandidateElectronExtra::Rejected,
true);
2528 itextra->setStatus(PFCandidateElectronExtra::ECALDrivenPreselected,bypassmva);
2529 itextra->setStatus(PFCandidateElectronExtra::MVASelected,mvaSelected);
2537 if( DebugIDCandidates )
2538 cout <<
"SetCandidates:: No Candidate Produced because of Pt cut: 0.5 " <<endl;
2543 if( DebugIDCandidates )
2544 cout <<
"SetCandidates:: No Candidate Produced because of No GSF Track Ref " <<endl;
2553 AssMap& associatedToGsf_,
2554 AssMap& associatedToBrems_,
2555 AssMap& associatedToEcal_,
2556 std::vector<bool>& active){
2562 unsigned int cgsf=0;
2563 for (
map<
unsigned int,vector<unsigned int> >::iterator igsf = associatedToGsf_.begin();
2564 igsf != associatedToGsf_.end(); igsf++,cgsf++) {
2566 unsigned int gsf_index = igsf->first;
2572 bool bypassmva=
false;
2585 active[gsf_index] =
false;
2586 vector<unsigned int> assogsf_index = igsf->second;
2587 for (
unsigned int ielegsf=0;ielegsf<assogsf_index.size();ielegsf++) {
2590 active[(assogsf_index[ielegsf])] =
false;
2592 unsigned int keyecalgsf = assogsf_index[ielegsf];
2605 for(
unsigned int iconv = 0; iconv <
convGsfTrack_.size(); iconv++) {
2610 std::multimap<double, unsigned> convKf;
2616 if(convKf.size() > 0) {
2617 active[convKf.begin()->second] =
false;
2624 vector<unsigned int> assoecalgsf_index = associatedToEcal_.find(keyecalgsf)->second;
2625 for(
unsigned int ips =0; ips<assoecalgsf_index.size();ips++) {
2628 active[(assoecalgsf_index[ips])] =
false;
2630 active[(assoecalgsf_index[ips])] =
false;
2633 active[(assoecalgsf_index[ips])] =
false;
2639 unsigned int brem_index = assogsf_index[ielegsf];
2640 vector<unsigned int> assobrem_index = associatedToBrems_.find(brem_index)->second;
2641 for (
unsigned int ibrem = 0; ibrem < assobrem_index.size(); ibrem++){
2643 unsigned int keyecalbrem = assobrem_index[ibrem];
2645 active[(assobrem_index[ibrem])] =
false;
2656 vector<unsigned int> assoelebrem_index = associatedToEcal_.find(keyecalbrem)->second;
2658 for (
unsigned int ielebrem=0; ielebrem<assoelebrem_index.size();ielebrem++) {
2660 active[(assoelebrem_index[ielebrem])] =
false;
2662 active[(assoelebrem_index[ielebrem])] =
false;
2675 unsigned int Algo = 0;
2676 switch (trackRef->algo()) {
2677 case TrackBase::ctf:
2679 case TrackBase::lowPtTripletStep:
2680 case TrackBase::pixelPairStep:
2681 case TrackBase::jetCoreRegionalStep:
2682 case TrackBase::muonSeededStepInOut:
2683 case TrackBase::muonSeededStepOutIn:
2695 case TrackBase::tobTecStep:
2706 bool isPrimary =
false;
2712 PFRecTrackRef kfPfRef_fromGsf = (*gsfPfRef).kfPFRecTrackRef();
2717 if(kfref == kfref_fromGsf)
std::vector< std::pair< unsigned int, unsigned int > > fifthStepKfTrack_
tuple useEGammaSupercluster
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
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_
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_
TrackAlgorithm
track algorithm
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 detachedTripletStep
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_
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 coneEcalIsoForEgammaSC
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
tuple applyCrackCorrections
double sumPtTrackIsoForEgammaSC_endcap_
tuple nTrackIsoForEgammaSC
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_
tuple sumPtTrackIsoForEgammaSC_barrel
Particle reconstructed by the particle flow algorithm.
tuple sumEtEcalIsoForEgammaSC_barrel
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)
double dist(unsigned ie1, unsigned ie2, const LinkData &linkData, LinkTest test) const
tuple sumEtEcalIsoForEgammaSC_endcap
trackRef_iterator tracks_begin() const
first iterator over tracks
unsigned int nTrackIsoForEgammaSC_
void setTrackRef(const reco::TrackRef &ref)
set track reference
tuple coneTrackIsoForEgammaSC
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_
tuple sumPtTrackIsoForEgammaSC_endcap
bool applyCrackCorrections_
void setEGElectronCollection(const reco::GsfElectronCollection &egelectrons)
bool useEGammaSupercluster_
std::vector< reco::PFCandidate > allElCandidate_