40 #include "Math/PxPyPzM4D.h" 41 #include "Math/LorentzVector.h" 42 #include "Math/DisplacementVector3D.h" 43 #include "Math/SMatrix.h" 44 #include "TDecompChol.h" 46 #include "boost/graph/adjacency_matrix.hpp" 47 #include "boost/graph/graph_utility.hpp" 53 using namespace boost;
55 typedef std::list< reco::PFBlockRef >::iterator
IBR;
81 const boost::shared_ptr<PFEnergyCalibration>& calibration,
82 const boost::shared_ptr<PFEnergyCalibrationHF>& thepfEnergyCalibrationHF) {
100 string mvaWeightFileEleID,
102 const boost::shared_ptr<PFSCEnergyCalibration>& thePFSCEnergyCalibration,
139 string err =
"PFAlgo: cannot open weight file '";
140 err += mvaWeightFileEleID;
142 throw invalid_argument( err );
146 thePFEnergyCalibration,
181 e(0, 0) = 0.0015 * 0.0015;
182 e(1, 1) = 0.0015 * 0.0015;
189 FILE * filePhotonConvID = fopen(mvaWeightFileConvID.c_str(),
"r");
190 if (filePhotonConvID) {
191 fclose(filePhotonConvID);
194 string err =
"PFAlgo: cannot open weight file '";
195 err += mvaWeightFileConvID;
197 throw invalid_argument( err );
205 thePFEnergyCalibration,
206 sumPtTrackIsoForPhoton,
207 sumPtTrackIsoSlopeForPhoton
215 double ele_iso_mva_barrel,
216 double ele_iso_mva_endcap,
217 double ele_iso_combIso_barrel,
218 double ele_iso_combIso_endcap,
219 double ele_noniso_mva,
220 unsigned int ele_missinghits,
227 double ph_sietaieta_eb,
228 double ph_sietaieta_ee,
237 FILE * fileEGamma_ele_iso_ID = fopen(ele_iso_path_mvaWeightFile.c_str(),
"r");
238 if (fileEGamma_ele_iso_ID) {
239 fclose(fileEGamma_ele_iso_ID);
242 string err =
"PFAlgo: cannot open weight file '";
243 err += ele_iso_path_mvaWeightFile;
245 throw invalid_argument( err );
256 ph_protectionsForJetMET,
257 ph_protectionsForBadHcal,
261 ele_iso_combIso_barrel,
262 ele_iso_combIso_endcap,
265 ele_iso_path_mvaWeightFile,
266 ele_protectionsForJetMET,
267 ele_protectionsForBadHcal);
302 GCorrForestBarrel, GCorrForestEndcapHr9,
303 GCorrForestEndcapLr9, PFEcalResolution);
325 assert (
muonHCAL_.size() == 2 && muonECAL_.size() == 2 && muonHO_.size() == 2);
329 assert ( factors45_.size() == 2 );
403 bool primaryVertexFound =
false;
404 nVtx_ = primaryVertices->size();
408 for (
unsigned short i=0 ;
i<primaryVertices->size();++
i)
410 if(primaryVertices->at(
i).isValid()&&(!primaryVertices->at(
i).isFake()))
413 primaryVertexFound =
true;
425 e(0, 0) = 0.0015 * 0.0015;
426 e(1, 1) = 0.0015 * 0.0015;
474 cout<<
"*********************************************************"<<endl;
475 cout<<
"***** Particle flow algorithm *****"<<endl;
476 cout<<
"*********************************************************"<<endl;
480 std::list< reco::PFBlockRef > hcalBlockRefs;
481 std::list< reco::PFBlockRef > ecalBlockRefs;
482 std::list< reco::PFBlockRef > hoBlockRefs;
483 std::list< reco::PFBlockRef > otherBlockRefs;
485 for(
unsigned i=0;
i<blocks.size(); ++
i ) {
493 bool singleEcalOrHcal =
false;
494 if( elements.
size() == 1 ){
496 ecalBlockRefs.push_back( blockref );
497 singleEcalOrHcal =
true;
500 hcalBlockRefs.push_back( blockref );
501 singleEcalOrHcal =
true;
505 hoBlockRefs.push_back( blockref );
506 singleEcalOrHcal =
true;
510 if(!singleEcalOrHcal) {
511 otherBlockRefs.push_back( blockref );
516 cout<<
"# Ecal blocks: "<<ecalBlockRefs.size()
517 <<
", # Hcal blocks: "<<hcalBlockRefs.size()
518 <<
", # HO blocks: "<<hoBlockRefs.size()
519 <<
", # Other blocks: "<<otherBlockRefs.size()<<endl;
527 for(
IBR io = otherBlockRefs.begin(); io!=otherBlockRefs.end(); ++io) {
532 std::list< reco::PFBlockRef >
empty;
536 for(
IBR ih = hcalBlockRefs.begin(); ih!=hcalBlockRefs.end(); ++ih) {
537 if (
debug_ )
std::cout <<
"HCAL block number " << hblcks++ << std::endl;
543 for(
IBR ie = ecalBlockRefs.begin(); ie!=ecalBlockRefs.end(); ++ie) {
544 if (
debug_ )
std::cout <<
"ECAL block number " << eblcks++ << std::endl;
561 std::list<reco::PFBlockRef>& hcalBlockRefs,
562 std::list<reco::PFBlockRef>& ecalBlockRefs ) {
565 assert(!blockref.
isNull() );
568 typedef std::multimap<double, unsigned>::iterator IE;
569 typedef std::multimap<double, std::pair<unsigned,::math::XYZVector> >::iterator IS;
570 typedef std::multimap<double, std::pair<unsigned,bool> >::iterator
IT;
571 typedef std::multimap< unsigned, std::pair<double, unsigned> >::iterator II;
574 cout<<
"#########################################################"<<endl;
575 cout<<
"##### Process Block: #####"<<endl;
576 cout<<
"#########################################################"<<endl;
586 vector<bool> active( elements.
size(),
true );
591 std::vector<reco::PFCandidate> tempElectronCandidates;
592 tempElectronCandidates.clear();
597 for ( std::vector<reco::PFCandidate>::const_iterator
ec=PFElectCandidates_.begin();
ec != PFElectCandidates_.end(); ++
ec )tempElectronCandidates.push_back(*
ec);
617 cout<<endl<<
"--------------- entering PFPhotonAlgo ----------------"<<endl;
618 vector<PFCandidatePhotonExtra> pfPhotonExtraCand;
623 tempElectronCandidates
633 unsigned int extracand =0;
641 pfPhotonExtraCand.clear();
646 for ( std::vector<reco::PFCandidate>::const_iterator
ec=tempElectronCandidates.begin();
ec != tempElectronCandidates.end(); ++
ec ){
649 tempElectronCandidates.clear();
657 bool egmLocalDebug =
debug_;
658 bool egmLocalBlockDebug =
false;
661 for(
unsigned int ieg=0 ; ieg < negmcandidates; ++ieg) {
666 PFCandidate::ElementsInBlocks::const_iterator iegfirst = theElements.begin();
667 bool sameBlock =
false;
668 bool isGoodElectron =
false;
669 bool isGoodPhoton =
false;
670 bool isPrimaryElectron =
false;
671 if(iegfirst->first == blockref)
676 cout <<
" I am in looping on EGamma Candidates: pt " << (*pfEgmRef).pt()
677 <<
" eta,phi " << (*pfEgmRef).eta() <<
", " << (*pfEgmRef).phi()
678 <<
" charge " << (*pfEgmRef).charge() << endl;
680 if((*pfEgmRef).gsfTrackRef().isNonnull()) {
688 cout <<
"** Good Electron, pt " << gedEleRef->pt()
689 <<
" eta, phi " << gedEleRef->eta() <<
", " << gedEleRef->phi()
690 <<
" charge " << gedEleRef->charge()
691 <<
" isPrimary " << isPrimaryElectron
692 <<
" isoDr03 " << (gedEleRef->dr03TkSumPt() + gedEleRef->dr03EcalRecHitSumEt() + gedEleRef->dr03HcalTowerSumEt())
693 <<
" mva_isolated " << gedEleRef->mva_Isolated()
694 <<
" mva_e_pi " << gedEleRef->mva_e_pi()
701 if((*pfEgmRef).superClusterRef().isNonnull()) {
708 cout <<
"** Good Photon, pt " << gedPhoRef->pt()
709 <<
" eta, phi " << gedPhoRef->eta() <<
", " << gedPhoRef->phi() << endl;
715 if(isGoodElectron && isGoodPhoton) {
716 if(isPrimaryElectron)
717 isGoodPhoton =
false;
719 isGoodElectron =
false;
727 bool lockTracks =
false;
737 myPFElectron.
setCharge(gedEleRef->charge());
738 myPFElectron.
setP4(gedEleRef->p4());
743 cout <<
" PFAlgo: found an electron with NEW EGamma code " << endl;
744 cout <<
" myPFElectron: pt " << myPFElectron.
pt()
745 <<
" eta,phi " << myPFElectron.
eta() <<
", " <<myPFElectron.
phi()
746 <<
" mva " << myPFElectron.
mva_e_pi()
747 <<
" charge " << myPFElectron.
charge() << endl;
752 if(egmLocalBlockDebug)
753 cout <<
" THE BLOCK " << *blockref << endl;
754 for (PFCandidate::ElementsInBlocks::const_iterator ieb = theElements.begin();
755 ieb<theElements.end(); ++ieb) {
756 active[ieb->second] =
false;
757 if(egmLocalBlockDebug||(
debug_&&egmLocalDebug))
758 cout <<
" Elements used " << ieb->second << endl;
764 for (PFCandidate::ElementsInBlocks::const_iterator itrk = extraTracks.begin();
765 itrk<extraTracks.end(); ++itrk) {
766 if(egmLocalBlockDebug||(
debug_&&egmLocalDebug))
767 cout <<
" Extra locked track " << itrk->second << endl;
768 active[itrk->second] =
false;
777 cout <<
"PFAlgo: Electron DISCARDED, NOT SAFE FOR JETMET " << endl;
797 myPFPhoton.
setP4(gedPhoRef->p4());
799 cout <<
" PFAlgo: found a photon with NEW EGamma code " << endl;
800 cout <<
" myPFPhoton: pt " << myPFPhoton.
pt()
801 <<
" eta,phi " << myPFPhoton.
eta() <<
", " <<myPFPhoton.
phi()
802 <<
" charge " << myPFPhoton.
charge() << endl;
806 if(egmLocalBlockDebug)
807 cout <<
" THE BLOCK " << *blockref << endl;
808 for (PFCandidate::ElementsInBlocks::const_iterator ieb = theElements.begin();
809 ieb<theElements.end(); ++ieb) {
810 active[ieb->second] =
false;
811 if(egmLocalBlockDebug||(
debug_&&egmLocalDebug))
812 cout <<
" Elements used " << ieb->second << endl;
826 for(
unsigned iEle=0; iEle<elements.
size(); iEle++) {
828 if(type==PFBlockElement::TRACK)
835 if(!elements[iEle].convRefs().
empty())active[iEle]=
false;
845 cout<<endl<<
"--------------- loop 1 ------------------"<<endl;
872 vector<unsigned> hcalIs;
873 vector<unsigned> hoIs;
874 vector<unsigned> ecalIs;
875 vector<unsigned> trackIs;
876 vector<unsigned> ps1Is;
877 vector<unsigned> ps2Is;
879 vector<unsigned> hfEmIs;
880 vector<unsigned> hfHadIs;
882 vector<bool> deadArea(elements.
size(),
false);
884 for(
unsigned iEle=0; iEle<elements.
size(); iEle++) {
887 if(
debug_ && type != PFBlockElement::BREM )
cout<<endl<<elements[iEle];
890 case PFBlockElement::TRACK:
891 if ( active[iEle] ) {
893 if(
debug_)
cout<<
"TRACK, stored index, continue"<<endl;
897 if ( active[iEle] ) {
898 ecalIs.push_back( iEle );
899 if(
debug_)
cout<<
"ECAL, stored index, continue"<<endl;
903 if ( active[iEle] ) {
905 if(
debug_)
cout<<
"HCAL DEAD AREA: remember and skip."<<endl;
906 active[iEle] =
false;
907 deadArea[iEle] =
true;
910 hcalIs.push_back( iEle );
911 if(
debug_)
cout<<
"HCAL, stored index, continue"<<endl;
916 if ( active[iEle] ) {
917 hoIs.push_back( iEle );
918 if(
debug_)
cout<<
"HO, stored index, continue"<<endl;
922 case PFBlockElement::HFEM:
923 if ( active[iEle] ) {
924 hfEmIs.push_back( iEle );
925 if(
debug_)
cout<<
"HFEM, stored index, continue"<<endl;
928 case PFBlockElement::HFHAD:
929 if ( active[iEle] ) {
930 hfHadIs.push_back( iEle );
931 if(
debug_)
cout<<
"HFHAD, stored index, continue"<<endl;
939 unsigned iTrack = iEle;
942 cout <<
"track " << iTrack <<
" has a valid muon reference. " << std::endl;
952 if (active[iTrack] &&
isFromSecInt(elements[iEle],
"primary")){
953 bool isPrimaryTrack = elements[iEle].displacedVertexRef(PFBlockElement::T_TO_DISP)->displacedVertexRef()->isTherePrimaryTracks();
954 if (isPrimaryTrack) {
955 if (
debug_)
cout <<
"Primary Track reconstructed alone" << endl;
958 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEle );
959 active[iTrack] =
false;
965 if ( !active[iTrack] )
966 cout <<
"Already used by electrons, muons, conversions" << endl;
971 if ( ! active[iTrack] )
continue;
974 assert( !trackRef.
isNull() );
977 cout <<
"PFAlgo:processBlock "<<
" "<<trackIs.size()<<
" "<<ecalIs.size()<<
" "<<hcalIs.size()<<
" "<<hoIs.size()<<endl;
984 std::multimap<double, unsigned> ecalElems;
985 block.associatedElements( iTrack, linkData,
990 std::multimap<double, unsigned> hcalElems;
991 block.associatedElements( iTrack, linkData,
997 std::cout <<
"\tTrack " << iTrack <<
" is linked to " << ecalElems.size() <<
" ecal and " << hcalElems.size() <<
" hcal elements" << std::endl;
998 for (
const auto & pair : ecalElems) {
999 std::cout <<
"ecal: dist " << pair.first <<
"\t elem " << pair.second << std::endl;
1001 for (
const auto & pair : hcalElems) {
1002 std::cout <<
"hcal: dist " << pair.first <<
"\t elem " << pair.second << (deadArea[pair.second] ?
" DEAD AREA MARKER" :
"") << std::endl;
1017 bool hasDeadHcal =
false;
1018 if (!hcalElems.empty() && deadArea[hcalElems.begin()->second]) {
1030 bool goodTrackDeadHcal =
false;
1038 if (!goodTrackDeadHcal &&
1040 trackRef->hitPattern().pixelLayersWithMeasurement() >= 3 &&
1041 trackRef->hitPattern().trackerLayersWithoutMeasurement(HitPattern::TRACK_HITS) == 0 &&
1042 trackRef->hitPattern().trackerLayersWithoutMeasurement(HitPattern::MISSING_INNER_HITS) == 0 &&
1043 trackRef->hitPattern().trackerLayersWithoutMeasurement(HitPattern::MISSING_OUTER_HITS) <= (
1044 trackRef->hitPattern().pixelLayersWithMeasurement() > 3 ?
1051 goodTrackDeadHcal =
true;
1055 if (
debug_)
cout <<
" track pt " << trackRef->pt() <<
" +- " << trackRef->ptError()
1056 <<
" layers valid " << trackRef->hitPattern().trackerLayersWithMeasurement()
1057 <<
", lost " << trackRef->hitPattern().trackerLayersWithoutMeasurement(HitPattern::TRACK_HITS)
1058 <<
", lost outer " << trackRef->hitPattern().trackerLayersWithoutMeasurement(HitPattern::MISSING_OUTER_HITS)
1059 <<
", lost inner " << trackRef->hitPattern().trackerLayersWithoutMeasurement(HitPattern::MISSING_INNER_HITS)
1060 <<
"(valid fraction " << trackRef->validFraction() <<
")" 1061 <<
" chi2/ndf " << trackRef->normalizedChi2()
1064 << (goodTrackDeadHcal ?
" passes " :
" fails ") <<
"quality cuts" << std::endl;
1070 if ( hcalElems.empty() && !ecalElems.empty() && !hasDeadHcal) {
1073 unsigned index = ecalElems.begin()->second;
1074 std::multimap<double, unsigned> sortedTracks;
1075 block.associatedElements( index, linkData,
1079 if (
debug_ )
std::cout <<
"The closest ECAL cluster is linked to " << sortedTracks.size() <<
" tracks, with distance = " << ecalElems.begin()->first << std::endl;
1082 for(IE ie = sortedTracks.begin(); ie != sortedTracks.end(); ++ie ) {
1083 unsigned jTrack = ie->second;
1086 if ( !active[jTrack] )
continue;
1090 if ( jTrack == iTrack )
continue;
1095 std::multimap<double, unsigned> sortedECAL;
1096 block.associatedElements( jTrack, linkData,
1100 if ( sortedECAL.begin()->second !=
index )
continue;
1101 if (
debug_ )
std::cout <<
" track " << jTrack <<
" with closest ECAL identical " << std::endl;
1105 std::multimap<double, unsigned> sortedHCAL;
1106 block.associatedElements( jTrack, linkData,
1110 if ( sortedHCAL.empty() )
continue;
1111 if (
debug_ )
std::cout <<
" and with an HCAL cluster " << sortedHCAL.begin()->second << std::endl;
1115 block.setLink( iTrack,
1116 sortedHCAL.begin()->second,
1117 sortedECAL.begin()->first,
1119 PFBlock::LINKTEST_RECHIT );
1124 block.associatedElements( iTrack, linkData,
1129 if (
debug_ && !hcalElems.empty() )
1130 std::cout <<
"Track linked back to HCAL due to ECAL sharing with other tracks" << std::endl;
1140 std::multimap<double,unsigned> gsfElems;
1142 block.associatedElements( iTrack, linkData,
1148 if(hcalElems.empty() &&
debug_) {
1149 cout<<
"no hcal element connected to track "<<iTrack<<endl;
1155 bool hcalFound =
false;
1158 cout<<
"now looping on elements associated to the track"<<endl;
1162 for(IE ie = ecalElems.begin(); ie != ecalElems.end(); ++ie ) {
1164 unsigned index = ie->second;
1168 double dist = ie->first;
1169 cout<<
"\telement "<<elements[
index]<<
" linked with distance = "<< dist <<endl;
1170 if ( ! active[index] )
cout <<
"This ECAL is already used - skip it" << endl;
1175 if ( ! active[index] )
continue;
1181 if( !hcalElems.empty() &&
debug_)
1182 cout<<
"\t\tat least one hcal element connected to the track." 1183 <<
" Sparing Ecal cluster for the hcal loop"<<endl;
1191 if( hcalElems.empty() ) {
1194 std::cout <<
"Now deals with tracks linked to no HCAL clusters. Was HCal active? " << (!hasDeadHcal) << std::endl;
1201 std::cout << elements[iTrack] << std::endl;
1207 if ( thisIsAMuon ) trackMomentum = 0.;
1211 bool rejectFake =
false;
1212 if ( !thisIsAMuon && elements[iTrack].trackRef()->ptError() >
ptError_ ) {
1216 elements[iTrack].trackRef()->
eta());
1219 if ( !ecalElems.empty() ) {
1220 unsigned thisEcal = ecalElems.begin()->second;
1222 bool useCluster =
true;
1224 std::multimap<double, unsigned> sortedTracks;
1225 block.associatedElements( thisEcal, linkData,
1229 useCluster = (sortedTracks.begin()->second == iTrack);
1232 deficit -= clusterRef->energy();
1234 clusterRef->positionREP().Eta());
1239 bool isPrimary =
isFromSecInt(elements[iTrack],
"primary");
1241 if ( deficit >
nSigmaTRACK_*resol && !isPrimary && !goodTrackDeadHcal) {
1243 active[iTrack] =
false;
1245 std::cout << elements[iTrack] << std::endl
1246 <<
" deficit " << deficit <<
" > " <<
nSigmaTRACK_ <<
" x " << resol
1247 <<
" track pt " << trackRef->pt() <<
" +- " << trackRef->ptError()
1248 <<
" layers valid " << trackRef->hitPattern().trackerLayersWithMeasurement()
1249 <<
", lost " << trackRef->hitPattern().trackerLayersWithoutMeasurement(HitPattern::TRACK_HITS)
1250 <<
", lost outer " << trackRef->hitPattern().trackerLayersWithoutMeasurement(HitPattern::MISSING_OUTER_HITS)
1251 <<
", lost inner " << trackRef->hitPattern().trackerLayersWithoutMeasurement(HitPattern::MISSING_INNER_HITS)
1252 <<
"(valid fraction " << trackRef->validFraction() <<
")" 1253 <<
" chi2/ndf " << trackRef->normalizedChi2()
1256 <<
"is probably a fake (1) --> lock the track" 1261 if ( rejectFake )
continue;
1266 std::vector<unsigned> tmpi;
1267 std::vector<unsigned> kTrack;
1270 double Dpt = trackRef->ptError();
1273 trackMomentum > 30. && Dpt > 0.5 &&
1275 && !goodTrackDeadHcal) ) {
1277 double dptRel = Dpt/trackRef->pt()*100;
1278 bool isPrimaryOrSecondary =
isFromSecInt(elements[iTrack],
"all");
1281 unsigned nHits = elements[iTrack].trackRef()->hitPattern().trackerLayersWithMeasurement();
1282 unsigned int NLostHit = trackRef->hitPattern().trackerLayersWithoutMeasurement(HitPattern::TRACK_HITS);
1285 std::cout <<
"A track (algo = " << trackRef->algo() <<
") with momentum " << trackMomentum
1286 <<
" / " << elements[iTrack].trackRef()->pt() <<
" +/- " << Dpt
1287 <<
" / " << elements[iTrack].trackRef()->eta()
1288 <<
" without any link to ECAL/HCAL and with " << nHits <<
" (" << NLostHit
1289 <<
") hits (lost hits) has been cleaned" << std::endl;
1290 active[iTrack] =
false;
1297 kTrack.push_back(iTrack);
1298 active[iTrack] =
false;
1301 if ( ecalElems.empty() ) {
1302 (*pfCandidates_)[tmpi[0]].setEcalEnergy( 0., 0. );
1303 (*pfCandidates_)[tmpi[0]].setHcalEnergy( 0., 0. );
1304 (*pfCandidates_)[tmpi[0]].setHoEnergy( 0., 0. );
1305 (*pfCandidates_)[tmpi[0]].setPs1Energy( 0 );
1306 (*pfCandidates_)[tmpi[0]].setPs2Energy( 0 );
1307 (*pfCandidates_)[tmpi[0]].addElementInBlock( blockref, kTrack[0] );
1312 unsigned thisEcal = ecalElems.begin()->second;
1314 if (
debug_ )
std::cout <<
" is associated to " << elements[thisEcal] << std::endl;
1318 if ( thisIsAMuon ) {
1319 (*pfCandidates_)[tmpi[0]].setEcalEnergy( clusterRef->energy(),
1321 (*pfCandidates_)[tmpi[0]].setHcalEnergy( 0., 0. );
1322 (*pfCandidates_)[tmpi[0]].setHoEnergy( 0., 0. );
1323 (*pfCandidates_)[tmpi[0]].setPs1Energy( 0 );
1324 (*pfCandidates_)[tmpi[0]].setPs2Energy( 0 );
1325 (*pfCandidates_)[tmpi[0]].addElementInBlock( blockref, kTrack[0] );
1328 double slopeEcal = 1.;
1329 bool connectedToEcal =
false;
1330 unsigned iEcal = 99999;
1331 double calibEcal = 0.;
1332 double calibHcal = 0.;
1333 double totalEcal = thisIsAMuon ? -
muonECAL_[0] : 0.;
1336 std::multimap<double, unsigned> sortedTracks;
1337 block.associatedElements( thisEcal, linkData,
1341 if (
debug_)
cout <<
"the closest ECAL cluster, id " << thisEcal <<
", has " << sortedTracks.size() <<
" associated tracks, now processing them. " << endl;
1343 if (hasDeadHcal && !sortedTracks.empty()) {
1345 if (
debug_)
cout <<
" the closest track to ECAL " << thisEcal <<
" is " << sortedTracks.begin()->second <<
" (distance " << sortedTracks.begin()->first <<
")" << endl;
1346 if (sortedTracks.begin()->second != iTrack) {
1347 if (
debug_)
cout <<
" the closest track to ECAL " << thisEcal <<
" is " << sortedTracks.begin()->second <<
" which is not the one being processed. Will skip ECAL linking for this track" << endl;
1348 (*pfCandidates_)[tmpi[0]].setEcalEnergy( 0., 0. );
1349 (*pfCandidates_)[tmpi[0]].setHcalEnergy( 0., 0. );
1350 (*pfCandidates_)[tmpi[0]].setHoEnergy( 0., 0. );
1351 (*pfCandidates_)[tmpi[0]].setPs1Energy( 0 );
1352 (*pfCandidates_)[tmpi[0]].setPs2Energy( 0 );
1353 (*pfCandidates_)[tmpi[0]].addElementInBlock( blockref, kTrack[0] );
1356 if (
debug_)
cout <<
" the closest track to ECAL " << thisEcal <<
" is " << sortedTracks.begin()->second <<
" which is the one being processed. Will skip ECAL linking for all other track" << endl;
1357 sortedTracks.clear();
1361 for(IE ie = sortedTracks.begin(); ie != sortedTracks.end(); ++ie ) {
1362 unsigned jTrack = ie->second;
1365 if ( !active[jTrack] )
continue;
1368 if ( jTrack == iTrack )
continue;
1376 std::multimap<double, unsigned> sortedECAL;
1377 block.associatedElements( jTrack, linkData,
1381 if ( sortedECAL.begin()->second != thisEcal )
continue;
1386 cout <<
" found track " << jTrack << (thatIsAMuon ?
" (muon) " :
" (non-muon)") <<
", with distance = " << sortedECAL.begin()->first << std::endl;
1391 bool rejectFake =
false;
1393 if ( !thatIsAMuon && trackRef->ptError() >
ptError_) {
1396 double deficit = trackMomentum + trackRef->p() - clusterRef->energy();
1398 clusterRef->positionREP().Eta());
1399 resol *= (trackMomentum+trackRef->p());
1400 if ( deficit >
nSigmaTRACK_*resol && !goodTrackDeadHcal) {
1402 kTrack.push_back(jTrack);
1403 active[jTrack] =
false;
1405 std::cout << elements[jTrack] << std::endl
1406 <<
"is probably a fake (2) --> lock the track" 1407 <<
"(trackMomentum = " << trackMomentum <<
", clusterEnergy = " << clusterRef->energy() <<
1408 ", deficit = " << deficit <<
" > " <<
nSigmaTRACK_ <<
" x " << resol <<
1409 " assuming neutralHadronEnergyResolution " <<
neutralHadronEnergyResolution(trackMomentum+trackRef->p(), clusterRef->positionREP().Eta()) <<
") " 1413 if ( rejectFake )
continue;
1419 if ( !thatIsAMuon ) {
1421 std::cout <<
"Track momentum increased from " << trackMomentum <<
" GeV ";
1422 trackMomentum += trackRef->p();
1424 std::cout <<
"to " << trackMomentum <<
" GeV." << std::endl;
1425 std::cout <<
"with " << elements[jTrack] << std::endl;
1429 totalEcal =
std::max(totalEcal, 0.);
1437 kTrack.push_back(jTrack);
1438 active[jTrack] =
false;
1440 if ( thatIsAMuon ) {
1441 (*pfCandidates_)[tmpi.back()].setEcalEnergy(clusterRef->energy(),
1443 (*pfCandidates_)[tmpi.back()].setHcalEnergy( 0., 0. );
1444 (*pfCandidates_)[tmpi.back()].setHoEnergy( 0., 0. );
1445 (*pfCandidates_)[tmpi.back()].setPs1Energy( 0 );
1446 (*pfCandidates_)[tmpi.back()].setPs2Energy( 0 );
1447 (*pfCandidates_)[tmpi.back()].addElementInBlock( blockref, kTrack.back() );
1452 if (
debug_ )
std::cout <<
"Loop over all associated ECAL clusters" << std::endl;
1454 for(IE ie = ecalElems.begin(); ie != ecalElems.end(); ++ie ) {
1456 unsigned index = ie->second;
1462 if (
debug_ && ! active[index] )
std::cout <<
"is not active - ignore " << std::endl;
1463 if ( ! active[index] )
continue;
1467 block.associatedElements( index, linkData,
1472 for (
unsigned ic=0; ic<kTrack.size();++ic) {
1473 if ( sortedTracks.begin()->second == kTrack[ic] ) {
1478 if (
debug_ && skip )
std::cout <<
"is closer to another track - ignore " << std::endl;
1479 if ( skip )
continue;
1484 assert( !clusterRef.
isNull() );
1487 double dist = ie->first;
1488 std::cout <<
"Ecal cluster with raw energy = " << clusterRef->energy()
1489 <<
" linked with distance = " << dist << std::endl;
1504 vector<double> ps1Ene(1,static_cast<double>(0.));
1506 vector<double> ps2Ene(1,static_cast<double>(0.));
1509 double ecalEnergy = clusterRef->correctedEnergy();
1511 std::cout <<
"Corrected ECAL(+PS) energy = " << ecalEnergy << std::endl;
1515 totalEcal += ecalEnergy;
1516 double previousCalibEcal = calibEcal;
1517 double previousSlopeEcal = slopeEcal;
1518 calibEcal =
std::max(totalEcal,0.);
1520 calibration_->energyEmHad(trackMomentum,calibEcal,calibHcal,
1521 clusterRef->positionREP().Eta(),
1522 clusterRef->positionREP().Phi());
1523 if ( totalEcal > 0.) slopeEcal = calibEcal/totalEcal;
1526 std::cout <<
"The total calibrated energy so far amounts to = " << calibEcal <<
" (slope = " << slopeEcal <<
")" << std::endl;
1530 if ( connectedToEcal && calibEcal - trackMomentum >= 0. ) {
1533 calibEcal = previousCalibEcal;
1534 slopeEcal = previousSlopeEcal;
1535 totalEcal = calibEcal/slopeEcal;
1539 active[
index] =
false;
1542 std::multimap<double, unsigned> assTracks;
1543 block.associatedElements( index, linkData,
1550 (*pfCandidates_)[tmpe].setEcalEnergy( clusterRef->energy(), ecalEnergy );
1551 (*pfCandidates_)[tmpe].setHcalEnergy( 0., 0. );
1552 (*pfCandidates_)[tmpe].setHoEnergy( 0., 0. );
1553 (*pfCandidates_)[tmpe].setPs1Energy( ps1Ene[0] );
1554 (*pfCandidates_)[tmpe].setPs2Energy( ps2Ene[0] );
1555 (*pfCandidates_)[tmpe].addElementInBlock( blockref, index );
1557 if(!assTracks.empty()) {
1558 (*pfCandidates_)[tmpe].addElementInBlock( blockref, assTracks.begin()->second );
1569 connectedToEcal =
true;
1571 active[
index] =
false;
1572 for (
unsigned ic=0; ic<tmpi.size();++ic)
1573 (*
pfCandidates_)[tmpi[ic]].addElementInBlock( blockref, iEcal );
1578 bool bNeutralProduced =
false;
1581 if( connectedToEcal ) {
1623 neutralEnergy /= slopeEcal;
1625 (*pfCandidates_)[tmpj].setEcalEnergy( pivotalRef->energy(), neutralEnergy );
1626 (*pfCandidates_)[tmpj].setHcalEnergy( 0., 0. );
1627 (*pfCandidates_)[tmpj].setHoEnergy( 0., 0. );
1628 (*pfCandidates_)[tmpj].setPs1Energy( 0. );
1629 (*pfCandidates_)[tmpj].setPs2Energy( 0. );
1630 (*pfCandidates_)[tmpj].addElementInBlock(blockref, iEcal);
1631 bNeutralProduced =
true;
1632 for (
unsigned ic=0; ic<kTrack.size();++ic)
1633 (*
pfCandidates_)[tmpj].addElementInBlock( blockref, kTrack[ic] );
1637 for (
unsigned ic=0; ic<tmpi.size();++ic) {
1642 double fraction = trackMomentum > 0 ? (*pfCandidates_)[tmpi[ic]].trackRef()->p()/trackMomentum : 0;
1643 double ecalCal = bNeutralProduced ?
1644 (calibEcal-neutralEnergy*slopeEcal)*fraction : calibEcal*fraction;
1645 double ecalRaw = totalEcal*
fraction;
1647 if (
debug_)
cout <<
"The fraction after photon supression is " << fraction <<
" calibrated ecal = " << ecalCal << endl;
1649 (*pfCandidates_)[tmpi[ic]].setEcalEnergy( ecalRaw, ecalCal );
1650 (*pfCandidates_)[tmpi[ic]].setHcalEnergy( 0., 0. );
1651 (*pfCandidates_)[tmpi[ic]].setHoEnergy( 0., 0. );
1652 (*pfCandidates_)[tmpi[ic]].setPs1Energy( 0 );
1653 (*pfCandidates_)[tmpi[ic]].setPs2Energy( 0 );
1654 (*pfCandidates_)[tmpi[ic]].addElementInBlock( blockref, kTrack[ic] );
1660 for (
unsigned ic=0; ic<tmpi.size();++ic) {
1661 const PFCandidate& pfc = (*pfCandidates_)[tmpi[ic]];
1663 if ( eleInBlocks.empty() ) {
1664 if (
debug_ )
std::cout <<
"Single track / Fill element in block! " << std::endl;
1665 (*pfCandidates_)[tmpi[ic]].addElementInBlock( blockref, kTrack[ic] );
1674 for(IE ie = hcalElems.begin(); ie != hcalElems.end(); ++ie ) {
1676 unsigned index = ie->second;
1682 cout<<
"\telement "<<elements[
index]<<
" linked with distance "<< dist <<endl;
1691 cout<<
"\t\tclosest hcal cluster, doing nothing"<<endl;
1701 cout<<
"\t\tsecondary hcal cluster. unlinking"<<endl;
1702 block.setLink( iTrack, index, -1., linkData,
1703 PFBlock::LINKTEST_RECHIT );
1711 if( !(hfEmIs.empty() && hfHadIs.empty() ) ) {
1714 assert( hfEmIs.size() + hfHadIs.size() == elements.
size() );
1716 if( elements.
size() == 1 ) {
1719 double energyHF = 0.;
1720 double uncalibratedenergyHF = 0.;
1722 switch( clusterRef->layer() ) {
1725 energyHF = clusterRef->energy();
1726 uncalibratedenergyHF = energyHF;
1729 clusterRef->positionREP().Eta(),
1730 clusterRef->positionREP().Phi());
1733 (*pfCandidates_)[tmpi].setEcalEnergy( uncalibratedenergyHF, energyHF );
1734 (*pfCandidates_)[tmpi].setHcalEnergy( 0., 0.);
1735 (*pfCandidates_)[tmpi].setHoEnergy( 0., 0.);
1736 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
1737 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
1738 (*pfCandidates_)[tmpi].addElementInBlock( blockref, hfEmIs[0] );
1743 energyHF = clusterRef->energy();
1744 uncalibratedenergyHF = energyHF;
1747 clusterRef->positionREP().Eta(),
1748 clusterRef->positionREP().Phi());
1751 (*pfCandidates_)[tmpi].setHcalEnergy( uncalibratedenergyHF, energyHF );
1752 (*pfCandidates_)[tmpi].setEcalEnergy( 0., 0.);
1753 (*pfCandidates_)[tmpi].setHoEnergy( 0., 0.);
1754 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
1755 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
1756 (*pfCandidates_)[tmpi].addElementInBlock( blockref, hfHadIs[0] );
1763 else if( elements.
size() == 2 ) {
1772 cerr<<
"Error: 2 elements, but not 1 HFEM and 1 HFHAD"<<endl;
1779 double energyHfEm = cem->energy();
1780 double energyHfHad = chad->energy();
1781 double uncalibratedenergyHFEm = energyHfEm;
1782 double uncalibratedenergyHFHad = energyHfHad;
1787 c0->positionREP().Eta(),
1788 c0->positionREP().Phi());
1790 uncalibratedenergyHFHad,
1791 c1->positionREP().Eta(),
1792 c1->positionREP().Phi());
1795 (*pfCandidates_)[tmpi].setEcalEnergy( uncalibratedenergyHFEm, energyHfEm );
1796 (*pfCandidates_)[tmpi].setHcalEnergy( uncalibratedenergyHFHad, energyHfHad);
1797 (*pfCandidates_)[tmpi].setHoEnergy( 0., 0.);
1798 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
1799 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
1800 (*pfCandidates_)[tmpi].addElementInBlock( blockref, hfEmIs[0] );
1801 (*pfCandidates_)[tmpi].addElementInBlock( blockref, hfHadIs[0] );
1807 cerr<<
"Warning: HF, but n elem different from 1 or 2"<<endl;
1818 cout<<endl<<
"--------------- loop hcal ---------------------"<<endl;
1827 for(
unsigned i=0;
i<hcalIs.size();
i++) {
1829 unsigned iHcal= hcalIs[
i];
1834 if(
debug_)
cout<<endl<<elements[iHcal]<<endl;
1840 std::multimap<double, unsigned> sortedTracks;
1841 block.associatedElements( iHcal, linkData,
1846 std::multimap< unsigned, std::pair<double, unsigned> > associatedEcals;
1848 std::map< unsigned, std::pair<double, double> > associatedPSs;
1850 std::multimap<double, std::pair<unsigned,bool> > associatedTracks;
1853 std::multimap<double,std::pair<unsigned,::math::XYZVector> > ecalSatellites;
1854 std::pair<unsigned,::math::XYZVector> fakeSatellite = make_pair(iHcal,::
math::XYZVector(0.,0.,0.));
1855 ecalSatellites.insert( make_pair(-1., fakeSatellite) );
1857 std::multimap< unsigned, std::pair<double, unsigned> > associatedHOs;
1859 PFClusterRef hclusterref = elements[iHcal].clusterRef();
1860 assert(!hclusterref.
isNull() );
1870 if( sortedTracks.empty() ) {
1872 cout<<
"\tno associated tracks, keep for later"<<endl;
1877 active[iHcal] =
false;
1885 if(
debug_)
cout<<
"\t"<<sortedTracks.size()<<
" associated tracks:"<<endl;
1887 double totalChargedMomentum = 0;
1888 double sumpError2 = 0.;
1889 double totalHO = 0.;
1890 double totalEcal = 0.;
1891 double totalHcal = hclusterref->energy();
1892 vector<double> hcalP;
1893 vector<double> hcalDP;
1894 vector<unsigned> tkIs;
1895 double maxDPovP = -9999.;
1898 vector< unsigned > chargedHadronsIndices;
1899 vector< unsigned > chargedHadronsInBlock;
1900 double mergedNeutralHadronEnergy = 0;
1901 double mergedPhotonEnergy = 0;
1902 double muonHCALEnergy = 0.;
1903 double muonECALEnergy = 0.;
1904 double muonHCALError = 0.;
1905 double muonECALError = 0.;
1910 std::vector<std::pair<unsigned,::math::XYZVector> >
ecalClusters;
1911 double sumEcalClusters=0;
1913 hclusterref->position().Y(),
1914 hclusterref->position().Z());
1915 hadronDirection = hadronDirection.Unit();
1919 for(IE ie = sortedTracks.begin(); ie != sortedTracks.end(); ++ie ) {
1921 unsigned iTrack = ie->second;
1924 if ( !active[iTrack] )
continue;
1930 assert( !trackRef.
isNull() );
1935 ::math::XYZVector chargedDirection(chargedPosition.X(),chargedPosition.Y(),chargedPosition.Z());
1936 chargedDirection = chargedDirection.Unit();
1939 std::multimap<double, unsigned> sortedEcals;
1940 block.associatedElements( iTrack, linkData,
1945 if(
debug_)
cout<<
"\t\t\tnumber of Ecal elements linked to this track: " 1946 <<sortedEcals.size()<<endl;
1949 std::multimap<double, unsigned> sortedHOs;
1951 block.associatedElements( iTrack, linkData,
1958 cout<<
"PFAlgo : number of HO elements linked to this track: " 1959 <<sortedHOs.size()<<endl;
1967 bool thisIsALooseMuon =
false;
1975 if ( thisIsAMuon ) {
1977 std::cout <<
"\t\tThis track is identified as a muon - remove it from the stack" << std::endl;
1978 std::cout <<
"\t\t" << elements[iTrack] << std::endl;
1986 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iTrack );
1987 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
1993 bool letMuonEatCaloEnergy =
false;
1995 if(thisIsAnIsolatedMuon){
1997 double totalCaloEnergy = totalHcal / 1.30;
1999 if( !sortedEcals.empty() ) {
2000 iEcal = sortedEcals.begin()->second;
2001 PFClusterRef eclusterref = elements[iEcal].clusterRef();
2002 totalCaloEnergy += eclusterref->energy();
2008 if( !sortedHOs.empty() ) {
2009 iHO = sortedHOs.begin()->second;
2011 totalCaloEnergy += eclusterref->energy() / 1.30;
2017 if( (
pfCandidates_->back()).
p() > totalCaloEnergy ) letMuonEatCaloEnergy =
true;
2020 if(letMuonEatCaloEnergy) muonHcal = totalHcal;
2021 double muonEcal =0.;
2023 if( !sortedEcals.empty() ) {
2024 iEcal = sortedEcals.begin()->second;
2025 PFClusterRef eclusterref = elements[iEcal].clusterRef();
2026 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal);
2028 if(letMuonEatCaloEnergy) muonEcal = eclusterref->energy();
2030 if ( eclusterref->energy() - muonEcal < 0.2 ) active[iEcal] =
false;
2031 (*pfCandidates_)[tmpi].setEcalEnergy(eclusterref->energy(), muonEcal);
2036 if( !sortedHOs.empty() ) {
2037 iHO = sortedHOs.begin()->second;
2038 PFClusterRef hoclusterref = elements[iHO].clusterRef();
2039 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHO);
2041 if(letMuonEatCaloEnergy) muonHO = hoclusterref->energy();
2043 if ( hoclusterref->energy() - muonHO < 0.2 ) active[iHO] =
false;
2044 (*pfCandidates_)[tmpi].setHcalEnergy(totalHcal, muonHcal);
2045 (*pfCandidates_)[tmpi].setHoEnergy(hoclusterref->energy(), muonHO);
2048 (*pfCandidates_)[tmpi].setHcalEnergy(totalHcal, muonHcal);
2052 if(letMuonEatCaloEnergy){
2053 muonHCALEnergy += totalHcal;
2054 if (
useHO_) muonHCALEnergy +=muonHO;
2055 muonHCALError += 0.;
2056 muonECALEnergy += muonEcal;
2057 muonECALError += 0.;
2058 photonAtECAL -= muonEcal*chargedDirection;
2059 hadronAtECAL -= totalHcal*chargedDirection;
2060 if ( !sortedEcals.empty() ) active[iEcal] =
false;
2061 active[iHcal] =
false;
2062 if (
useHO_ && !sortedHOs.empty() ) active[iHO] =
false;
2068 if ( muonHO > 0. ) {
2075 photonAtECAL -= muonECAL_[0]*chargedDirection;
2076 hadronAtECAL -= muonHCAL_[0]*chargedDirection;
2080 active[iTrack] =
false;
2087 if(
debug_)
cout<<
"\t\t"<<elements[iTrack]<<endl;
2095 if ( thisIsALooseMuon && !thisIsAMuon ) nMuons += 1;
2100 double Dpt = trackRef->ptError();
2103 bool isPrimaryOrSecondary =
isFromSecInt(elements[iTrack],
"all");
2105 if ( isPrimaryOrSecondary ) blowError = 1.;
2107 std::pair<unsigned,bool> tkmuon = make_pair(iTrack,thisIsALooseMuon);
2108 associatedTracks.insert( make_pair(-Dpt*blowError, tkmuon) );
2111 double Dp = trackRef->qoverpError()*trackMomentum*
trackMomentum;
2112 sumpError2 += Dp*Dp;
2114 bool connectedToEcal =
false;
2115 if( !sortedEcals.empty() )
2119 for ( IE iec=sortedEcals.begin();
2120 iec!=sortedEcals.end(); ++iec ) {
2122 unsigned iEcal = iec->second;
2123 double dist = iec->first;
2126 if( !active[iEcal] ) {
2134 PFClusterRef eclusterref = elements[iEcal].clusterRef();
2135 assert(!eclusterref.
isNull() );
2138 std::multimap<double, unsigned> sortedTracksEcal;
2139 block.associatedElements( iEcal, linkData,
2143 unsigned jTrack = sortedTracksEcal.
begin()->second;
2144 if ( jTrack != iTrack )
continue;
2148 double distEcal = block.dist(jTrack,iEcal,linkData,
2155 float ecalEnergyCalibrated = eclusterref->correctedEnergy();
2157 eclusterref->position().Y(),
2158 eclusterref->position().Z());
2159 photonDirection = photonDirection.Unit();
2161 if ( !connectedToEcal ) {
2164 <<elements[iEcal]<<endl;
2166 connectedToEcal =
true;
2170 std::pair<unsigned,::math::XYZVector> satellite =
2171 make_pair(iEcal,ecalEnergyCalibrated*photonDirection);
2172 ecalSatellites.insert( make_pair(-1., satellite) );
2176 std::pair<unsigned,::math::XYZVector> satellite =
2177 make_pair(iEcal,ecalEnergyCalibrated*photonDirection);
2178 ecalSatellites.insert( make_pair(dist, satellite) );
2182 std::pair<double, unsigned> associatedEcal
2183 = make_pair( distEcal, iEcal );
2184 associatedEcals.insert( make_pair(iTrack, associatedEcal) );
2189 if(
useHO_ && !sortedHOs.empty() )
2193 for ( IE ieho=sortedHOs.begin(); ieho!=sortedHOs.end(); ++ieho ) {
2195 unsigned iHO = ieho->second;
2196 double distHO = ieho->first;
2199 if( !active[iHO] ) {
2207 PFClusterRef hoclusterref = elements[iHO].clusterRef();
2208 assert(!hoclusterref.
isNull() );
2211 std::multimap<double, unsigned> sortedTracksHO;
2212 block.associatedElements( iHO, linkData,
2216 unsigned jTrack = sortedTracksHO.
begin()->second;
2217 if ( jTrack != iTrack )
continue;
2225 totalHO += hoclusterref->energy();
2226 active[iHO] =
false;
2228 std::pair<double, unsigned> associatedHO
2229 = make_pair( distHO, iHO );
2230 associatedHOs.insert( make_pair(iTrack, associatedHO) );
2239 totalHcal += totalHO;
2243 double caloEnergy = 0.;
2244 double slopeEcal = 1.0;
2245 double calibEcal = 0.;
2246 double calibHcal = 0.;
2247 hadronDirection = hadronAtECAL.Unit();
2251 Caloresolution *= totalChargedMomentum;
2253 Caloresolution =
std::sqrt(Caloresolution*Caloresolution + muonHCALError + muonECALError);
2254 totalEcal -=
std::min(totalEcal,muonECALEnergy);
2255 totalHcal -=
std::min(totalHcal,muonHCALEnergy);
2263 for ( IS is = ecalSatellites.begin(); is != ecalSatellites.end(); ++is ) {
2266 double previousCalibEcal = calibEcal;
2267 double previousCalibHcal = calibHcal;
2268 double previousCaloEnergy = caloEnergy;
2269 double previousSlopeEcal = slopeEcal;
2272 totalEcal +=
sqrt(is->second.second.Mag2());
2273 photonAtECAL += is->second.second;
2274 calibEcal =
std::max(0.,totalEcal);
2275 calibHcal =
std::max(0.,totalHcal);
2276 hadronAtECAL = calibHcal * hadronDirection;
2278 calibration_->energyEmHad(totalChargedMomentum,calibEcal,calibHcal,
2279 hclusterref->positionREP().Eta(),
2280 hclusterref->positionREP().Phi());
2281 caloEnergy = calibEcal+calibHcal;
2282 if ( totalEcal > 0.) slopeEcal = calibEcal/totalEcal;
2284 hadronAtECAL = calibHcal * hadronDirection;
2288 if ( is->first < 0. || caloEnergy - totalChargedMomentum <= 0. ) {
2289 if(
debug_)
cout<<
"\t\t\tactive, adding "<<is->second.second
2290 <<
" to ECAL energy, and locking"<<endl;
2291 active[is->second.first] =
false;
2292 double clusterEnergy=
sqrt(is->second.second.Mag2());
2293 if(clusterEnergy>50) {
2294 ecalClusters.push_back(is->second);
2295 sumEcalClusters+=clusterEnergy;
2302 totalEcal -=
sqrt(is->second.second.Mag2());
2303 photonAtECAL -= is->second.second;
2304 calibEcal = previousCalibEcal;
2305 calibHcal = previousCalibHcal;
2306 hadronAtECAL = previousHadronAtECAL;
2307 slopeEcal = previousSlopeEcal;
2308 caloEnergy = previousCaloEnergy;
2315 assert(caloEnergy>=0);
2331 if ( totalChargedMomentum - caloEnergy >
nSigmaTRACK_*Caloresolution ) {
2346 for ( IT it = associatedTracks.begin(); it != associatedTracks.end(); ++it ) {
2347 unsigned iTrack = it->second.first;
2349 if ( !active[iTrack] )
continue;
2351 if ( !it->second.second )
continue;
2353 double trackMomentum = elements[it->second.first].trackRef()->p();
2356 std::multimap<double, unsigned> sortedEcals;
2357 block.associatedElements( iTrack, linkData,
2361 std::multimap<double, unsigned> sortedHOs;
2362 block.associatedElements( iTrack, linkData,
2370 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iTrack );
2371 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
2374 (*pfCandidates_)[tmpi].setHcalEnergy(totalHcal,muonHcal);
2375 if( !sortedEcals.empty() ) {
2376 unsigned iEcal = sortedEcals.begin()->second;
2377 PFClusterRef eclusterref = elements[iEcal].clusterRef();
2378 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal);
2380 (*pfCandidates_)[tmpi].setEcalEnergy(eclusterref->energy(),muonEcal);
2382 if(
useHO_ && !sortedHOs.empty() ) {
2383 unsigned iHO = sortedHOs.begin()->second;
2384 PFClusterRef hoclusterref = elements[iHO].clusterRef();
2385 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHO);
2387 (*pfCandidates_)[tmpi].setHcalEnergy(
max(totalHcal-totalHO,0.0),muonHcal);
2388 (*pfCandidates_)[tmpi].setHoEnergy(hoclusterref->energy(),muonHO);
2394 ::math::XYZVector chargedDirection(chargedPosition.X(), chargedPosition.Y(), chargedPosition.Z());
2395 chargedDirection = chargedDirection.Unit();
2398 if ( totalEcal > 0. )
2400 if ( totalHcal > 0. )
2405 if ( totalHcal >
muonHCAL_[0] ) hadronAtECAL -=
muonHCAL_[0]*calibHcal/totalHcal * chargedDirection;
2406 caloEnergy = calibEcal+calibHcal;
2409 if ( muonHO > 0. ) {
2412 if ( totalHcal > 0. ) {
2413 calibHcal -=
std::min(calibHcal,muonHO_[0]*calibHcal/totalHcal);
2414 totalHcal -=
std::min(totalHcal,muonHO_[0]);
2419 active[iTrack] =
false;
2426 Caloresolution *= totalChargedMomentum;
2427 Caloresolution =
std::sqrt(Caloresolution*Caloresolution + muonHCALError + muonECALError);
2432 cout<<
"\tBefore Cleaning "<<endl;
2433 cout<<
"\tCompare Calo Energy to total charged momentum "<<endl;
2434 cout<<
"\t\tsum p = "<<totalChargedMomentum<<
" +- "<<
sqrt(sumpError2)<<endl;
2435 cout<<
"\t\tsum ecal = "<<totalEcal<<endl;
2436 cout<<
"\t\tsum hcal = "<<totalHcal<<endl;
2437 cout<<
"\t\t => Calo Energy = "<<caloEnergy<<
" +- "<<Caloresolution<<endl;
2438 cout<<
"\t\t => Calo Energy- total charged momentum = " 2439 <<caloEnergy-totalChargedMomentum<<
" +- "<<
sqrt(sumpError2 + Caloresolution*Caloresolution)<<endl;
2445 unsigned corrTrack = 10000000;
2446 double corrFact = 1.;
2449 totalChargedMomentum - caloEnergy >
nSigmaTRACK_*Caloresolution) {
2451 for ( IT it = associatedTracks.begin(); it != associatedTracks.end(); ++it ) {
2452 unsigned iTrack = it->second.first;
2454 if ( !active[iTrack] )
continue;
2455 const reco::TrackRef& trackref = elements[it->second.first].trackRef();
2457 double dptRel = fabs(it->first)/trackref->pt()*100;
2458 bool isSecondary =
isFromSecInt(elements[iTrack],
"secondary");
2459 bool isPrimary =
isFromSecInt(elements[iTrack],
"primary");
2463 if ( fabs(it->first) <
ptError_ )
break;
2465 double wouldBeTotalChargedMomentum =
2466 totalChargedMomentum - trackref->p();
2470 if ( wouldBeTotalChargedMomentum > caloEnergy ) {
2472 if (
debug_ && isSecondary) {
2473 cout <<
"In bad track rejection step dptRel = " << dptRel <<
" dptRel_DispVtx_ = " <<
dptRel_DispVtx_ << endl;
2474 cout <<
"The calo energy would be still smaller even without this track but it is attached to a NI"<< endl;
2479 active[iTrack] =
false;
2480 totalChargedMomentum = wouldBeTotalChargedMomentum;
2482 std::cout <<
"\tElement " << elements[iTrack]
2483 <<
" rejected (Dpt = " << -it->first
2484 <<
" GeV/c, algo = " << trackref->algo() <<
")" << std::endl;
2487 if(isPrimary)
break;
2489 corrFact = (caloEnergy - wouldBeTotalChargedMomentum)/elements[it->second.first].trackRef()->p();
2490 if ( trackref->p()*corrFact < 0.05 ) {
2492 active[iTrack] =
false;
2494 totalChargedMomentum -= trackref->p()*(1.-corrFact);
2496 std::cout <<
"\tElement " << elements[iTrack]
2497 <<
" (Dpt = " << -it->first
2498 <<
" GeV/c, algo = " << trackref->algo()
2499 <<
") rescaled by " << corrFact
2500 <<
" Now the total charged momentum is " << totalChargedMomentum << endl;
2508 Caloresolution *= totalChargedMomentum;
2509 Caloresolution =
std::sqrt(Caloresolution*Caloresolution + muonHCALError + muonECALError);
2515 sortedTracks.size() > 1 &&
2516 totalChargedMomentum - caloEnergy >
nSigmaTRACK_*Caloresolution ) {
2517 for ( IT it = associatedTracks.begin(); it != associatedTracks.end(); ++it ) {
2518 unsigned iTrack = it->second.first;
2520 if ( !active[iTrack] )
continue;
2522 double dptRel = fabs(it->first)/trackref->pt()*100;
2523 bool isPrimaryOrSecondary =
isFromSecInt(elements[iTrack],
"all");
2531 active[iTrack] =
false;
2532 totalChargedMomentum -= trackref->p();
2535 std::cout <<
"\tElement " << elements[iTrack]
2536 <<
" rejected (Dpt = " << -it->first
2537 <<
" GeV/c, algo = " << trackref->algo() <<
")" << std::endl;
2546 Caloresolution *= totalChargedMomentum;
2547 Caloresolution =
std::sqrt(Caloresolution*Caloresolution + muonHCALError + muonECALError);
2551 for ( IT it = associatedTracks.begin(); it != associatedTracks.end(); ++it ) {
2552 unsigned iTrack = it->second.first;
2553 if ( !active[iTrack] )
continue;
2556 double Dp = trackRef->qoverpError()*trackMomentum*
trackMomentum;
2560 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iTrack );
2561 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
2563 std::pair<II,II> myEcals = associatedEcals.equal_range(iTrack);
2564 for (II
ii=myEcals.first;
ii!=myEcals.second; ++
ii ) {
2565 unsigned iEcal =
ii->second.second;
2566 if ( active[iEcal] )
continue;
2567 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal );
2571 std::pair<II,II> myHOs = associatedHOs.equal_range(iTrack);
2572 for (II
ii=myHOs.first;
ii!=myHOs.second; ++
ii ) {
2573 unsigned iHO =
ii->second.second;
2574 if ( active[iHO] )
continue;
2575 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHO );
2579 if ( iTrack == corrTrack ) {
2580 (*pfCandidates_)[tmpi].rescaleMomentum(corrFact);
2581 trackMomentum *= corrFact;
2583 chargedHadronsIndices.push_back( tmpi );
2584 chargedHadronsInBlock.push_back( iTrack );
2585 active[iTrack] =
false;
2586 hcalP.push_back(trackMomentum);
2587 hcalDP.push_back(Dp);
2588 if (Dp/trackMomentum > maxDPovP) maxDPovP = Dp/
trackMomentum;
2589 sumpError2 += Dp*Dp;
2593 double TotalError =
sqrt(sumpError2 + Caloresolution*Caloresolution);
2596 cout<<
"\tCompare Calo Energy to total charged momentum "<<endl;
2597 cout<<
"\t\tsum p = "<<totalChargedMomentum<<
" +- "<<
sqrt(sumpError2)<<endl;
2598 cout<<
"\t\tsum ecal = "<<totalEcal<<endl;
2599 cout<<
"\t\tsum hcal = "<<totalHcal<<endl;
2600 cout<<
"\t\t => Calo Energy = "<<caloEnergy<<
" +- "<<Caloresolution<<endl;
2601 cout<<
"\t\t => Calo Energy- total charged momentum = " 2602 <<caloEnergy-totalChargedMomentum<<
" +- "<<TotalError<<endl;
2609 double nsigma =
nSigmaHCAL(totalChargedMomentum,hclusterref->positionREP().Eta());
2611 if (
abs(totalChargedMomentum-caloEnergy)<nsigma*TotalError ) {
2617 cout<<
"\t\tcase 1: COMPATIBLE " 2618 <<
"|Calo Energy- total charged momentum| = " 2619 <<
abs(caloEnergy-totalChargedMomentum)
2620 <<
" < "<<nsigma<<
" x "<<TotalError<<endl;
2621 if (maxDPovP < 0.1 )
2622 cout<<
"\t\t\tmax DP/P = "<< maxDPovP
2623 <<
" less than 0.1: do nothing "<<endl;
2625 cout<<
"\t\t\tmax DP/P = "<< maxDPovP
2626 <<
" > 0.1: take weighted averages "<<endl;
2630 if (maxDPovP > 0.1) {
2634 int nrows = chargedHadronsIndices.size();
2635 TMatrixTSym<double>
a (nrows);
2637 TVectorD
check(nrows);
2638 double sigma2E = Caloresolution*Caloresolution;
2639 for(
int i=0;
i<nrows;
i++) {
2640 double sigma2i = hcalDP[
i]*hcalDP[
i];
2642 cout<<
"\t\t\ttrack associated to hcal "<<
i 2643 <<
" P = "<<hcalP[
i]<<
" +- " 2646 a(
i,
i) = 1./sigma2i + 1./sigma2E;
2647 b(
i) = hcalP[
i]/sigma2i + caloEnergy/sigma2E;
2648 for(
int j=0; j<nrows; j++) {
2650 a(
i,j) = 1./sigma2E;
2661 TDecompChol decomp(a);
2663 TVectorD
x = decomp.Solve(b, ok);
2667 for (
int i=0;
i<nrows;
i++){
2669 unsigned ich = chargedHadronsIndices[
i];
2670 double rescaleFactor =
x(
i)/hcalP[
i];
2671 (*pfCandidates_)[ich].rescaleMomentum( rescaleFactor );
2674 cout<<
"\t\t\told p "<<hcalP[
i]
2676 <<
" rescale "<<rescaleFactor<<endl;
2681 cerr<<
"not ok!"<<endl;
2688 else if( caloEnergy > totalChargedMomentum ) {
2707 double eNeutralHadron = caloEnergy - totalChargedMomentum;
2708 double ePhoton = (caloEnergy - totalChargedMomentum) / slopeEcal;
2711 if(!sortedTracks.empty() ){
2712 cout<<
"\t\tcase 2: NEUTRAL DETECTION " 2713 <<caloEnergy<<
" > "<<nsigma<<
"x"<<TotalError
2714 <<
" + "<<totalChargedMomentum<<endl;
2715 cout<<
"\t\tneutral activity detected: "<<endl
2716 <<
"\t\t\t photon = "<<ePhoton<<endl
2717 <<
"\t\t\tor neutral hadron = "<<eNeutralHadron<<endl;
2719 cout<<
"\t\tphoton or hadron ?"<<endl;}
2721 if(sortedTracks.empty() )
2722 cout<<
"\t\tno track -> hadron "<<endl;
2724 cout<<
"\t\t"<<sortedTracks.size()
2725 <<
" tracks -> check if the excess is photonic or hadronic"<<endl;
2729 double ratioMax = 0.;
2731 unsigned maxiEcal= 9999;
2735 for(IE ie = sortedTracks.begin(); ie != sortedTracks.end(); ++ie ) {
2737 unsigned iTrack = ie->second;
2743 assert( !trackRef.
isNull() );
2745 II iae = associatedEcals.find(iTrack);
2747 if( iae == associatedEcals.end() )
continue;
2750 unsigned iEcal = iae->second.second;
2756 assert( !clusterRef.
isNull() );
2758 double pTrack = trackRef->p();
2759 double eECAL = clusterRef->energy();
2760 double eECALOverpTrack = eECAL / pTrack;
2762 if ( eECALOverpTrack > ratioMax ) {
2763 ratioMax = eECALOverpTrack;
2764 maxEcalRef = clusterRef;
2770 std::vector<reco::PFClusterRef> pivotalClusterRef;
2771 std::vector<unsigned> iPivotal;
2772 std::vector<double> particleEnergy, ecalEnergy, hcalEnergy, rawecalEnergy, rawhcalEnergy;
2773 std::vector<::math::XYZVector> particleDirection;
2777 if ( ePhoton < totalEcal || eNeutralHadron-calibEcal < 1E-10 ) {
2778 if ( !maxEcalRef.
isNull() ) {
2780 mergedPhotonEnergy = ePhoton;
2784 if ( !maxEcalRef.
isNull() ) {
2786 mergedPhotonEnergy = totalEcal;
2789 mergedNeutralHadronEnergy = eNeutralHadron-calibEcal;
2792 if ( mergedPhotonEnergy > 0 ) {
2795 if ( ecalClusters.size()<=1 ) {
2796 ecalClusters.clear();
2797 ecalClusters.push_back(make_pair(maxiEcal, photonAtECAL));
2798 sumEcalClusters=
sqrt(photonAtECAL.Mag2());
2800 for(std::vector<std::pair<unsigned,::math::XYZVector> >::const_iterator pae = ecalClusters.begin(); pae != ecalClusters.end(); ++pae ) {
2801 double clusterEnergy=
sqrt(pae->second.Mag2());
2802 particleEnergy.push_back(mergedPhotonEnergy*clusterEnergy/sumEcalClusters);
2803 particleDirection.push_back(pae->second);
2804 ecalEnergy.push_back(mergedPhotonEnergy*clusterEnergy/sumEcalClusters);
2805 hcalEnergy.push_back(0.);
2806 rawecalEnergy.push_back(totalEcal);
2807 rawhcalEnergy.push_back(totalHcal);
2808 pivotalClusterRef.push_back(elements[pae->first].clusterRef());
2809 iPivotal.push_back(pae->first);
2813 if ( mergedNeutralHadronEnergy > 1.0 ) {
2816 if ( ecalClusters.size()<=1 ) {
2817 ecalClusters.clear();
2818 ecalClusters.push_back(make_pair(iHcal, hadronAtECAL));
2819 sumEcalClusters=
sqrt(hadronAtECAL.Mag2());
2821 for(std::vector<std::pair<unsigned,::math::XYZVector> >::const_iterator pae = ecalClusters.begin(); pae != ecalClusters.end(); ++pae ) {
2822 double clusterEnergy=
sqrt(pae->second.Mag2());
2823 particleEnergy.push_back(mergedNeutralHadronEnergy*clusterEnergy/sumEcalClusters);
2824 particleDirection.push_back(pae->second);
2825 ecalEnergy.push_back(0.);
2826 hcalEnergy.push_back(mergedNeutralHadronEnergy*clusterEnergy/sumEcalClusters);
2827 rawecalEnergy.push_back(totalEcal);
2828 rawhcalEnergy.push_back(totalHcal);
2829 pivotalClusterRef.push_back(hclusterref);
2830 iPivotal.push_back(iHcal);
2838 for (
unsigned iPivot=0; iPivot<iPivotal.size(); ++iPivot ) {
2840 if ( particleEnergy[iPivot] < 0. )
2841 std::cout <<
"ALARM = Negative energy ! " 2842 << particleEnergy[iPivot] << std::endl;
2844 bool useDirection =
true;
2846 particleEnergy[iPivot],
2848 particleDirection[iPivot].
X(),
2849 particleDirection[iPivot].
Y(),
2850 particleDirection[iPivot].
Z());
2853 (*pfCandidates_)[tmpi].setEcalEnergy( rawecalEnergy[iPivot],ecalEnergy[iPivot] );
2855 (*pfCandidates_)[tmpi].setHcalEnergy( rawhcalEnergy[iPivot],hcalEnergy[iPivot] );
2856 (*pfCandidates_)[tmpi].setHoEnergy(0., 0.);
2858 (*pfCandidates_)[tmpi].setHcalEnergy(
max(rawhcalEnergy[iPivot]-totalHO,0.0),hcalEnergy[iPivot]*(1.-totalHO/rawhcalEnergy[iPivot]));
2859 (*pfCandidates_)[tmpi].setHoEnergy(totalHO, totalHO * hcalEnergy[iPivot]/rawhcalEnergy[iPivot]);
2861 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
2862 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
2863 (*pfCandidates_)[tmpi].set_mva_nothing_gamma( -1. );
2866 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
2867 for (
unsigned ich=0; ich<chargedHadronsInBlock.size(); ++ich) {
2868 unsigned iTrack = chargedHadronsInBlock[ich];
2869 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iTrack );
2875 std::pair<II,II> myEcals = associatedEcals.equal_range(iTrack);
2876 for (II
ii=myEcals.first;
ii!=myEcals.second; ++
ii ) {
2877 unsigned iEcal =
ii->second.second;
2878 if ( active[iEcal] )
continue;
2879 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal );
2891 double totalHcalEnergyCalibrated = calibHcal;
2892 double totalEcalEnergyCalibrated = calibEcal;
2907 totalHcalEnergyCalibrated -= mergedNeutralHadronEnergy;
2909 totalEcalEnergyCalibrated -= mergedPhotonEnergy;
2914 double chargedHadronsTotalEnergy = 0;
2915 for(
unsigned ich=0; ich<chargedHadronsIndices.size(); ++ich ) {
2916 unsigned index = chargedHadronsIndices[ich];
2918 chargedHadronsTotalEnergy += chargedHadron.
energy();
2921 for(
unsigned ich=0; ich<chargedHadronsIndices.size(); ++ich ) {
2922 unsigned index = chargedHadronsIndices[ich];
2924 float fraction = chargedHadron.
energy()/chargedHadronsTotalEnergy;
2927 chargedHadron.
setHcalEnergy( fraction * totalHcal, fraction * totalHcalEnergyCalibrated );
2930 chargedHadron.
setHcalEnergy( fraction *
max(totalHcal-totalHO,0.0), fraction * totalHcalEnergyCalibrated * (1.-totalHO/totalHcal) );
2931 chargedHadron.
setHoEnergy( fraction * totalHO, fraction * totalHO * totalHcalEnergyCalibrated / totalHcal );
2934 chargedHadron.
setEcalEnergy( fraction * totalEcal, fraction * totalEcalEnergyCalibrated );
2938 for ( IS is = ecalSatellites.begin(); is != ecalSatellites.end(); ++is ) {
2941 unsigned iEcal = is->second.first;
2942 if ( !active[iEcal] )
continue;
2947 PFClusterRef eclusterref = elements[iEcal].clusterRef();
2948 assert(!eclusterref.
isNull() );
2951 active[iEcal] =
false;
2954 std::multimap<double, unsigned> assTracks;
2955 block.associatedElements( iEcal, linkData,
2962 (*pfCandidates_)[tmpi].setEcalEnergy( eclusterref->energy(),
sqrt(is->second.second.Mag2()) );
2963 (*pfCandidates_)[tmpi].setHcalEnergy( 0., 0. );
2964 (*pfCandidates_)[tmpi].setHoEnergy( 0., 0. );
2965 (*pfCandidates_)[tmpi].setPs1Energy( associatedPSs[iEcal].
first );
2966 (*pfCandidates_)[tmpi].setPs2Energy( associatedPSs[iEcal].
second );
2967 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal );
2968 (*pfCandidates_)[tmpi].addElementInBlock( blockref, sortedTracks.begin()->second) ;
2982 <<
"---- loop remaining hcal ------- "<<endl;
2988 for(
unsigned ihcluster=0; ihcluster<hcalIs.size(); ihcluster++) {
2989 unsigned iHcal = hcalIs[ihcluster];
2992 std::vector<unsigned> ecalRefs;
2993 std::vector<unsigned> hoRefs;
2996 cout<<endl<<elements[iHcal]<<
" ";
2999 if( !active[iHcal] ) {
3001 cout<<
"not active"<<endl;
3006 std::multimap<double, unsigned> ecalElems;
3007 block.associatedElements( iHcal, linkData,
3013 float totalEcal = 0.;
3016 for(IE ie = ecalElems.begin(); ie != ecalElems.end(); ++ie ) {
3018 unsigned iEcal = ie->second;
3019 double dist = ie->first;
3024 if( !active[iEcal] )
continue;
3045 std::multimap<double, unsigned> hcalElems;
3046 block.associatedElements( iEcal, linkData,
3051 bool isClosest =
true;
3052 for(IE ih = hcalElems.begin(); ih != hcalElems.end(); ++ih ) {
3054 unsigned jHcal = ih->second;
3055 double distH = ih->first;
3057 if ( !active[jHcal] )
continue;
3059 if ( distH < dist ) {
3066 if (!isClosest)
continue;
3070 cout<<
"\telement "<<elements[iEcal]<<
" linked with dist "<< dist<<endl;
3071 cout<<
"Added to HCAL cluster to form a neutral hadron"<<endl;
3075 assert( !eclusterRef.
isNull() );
3077 double ecalEnergy = eclusterRef->correctedEnergy();
3081 totalEcal += ecalEnergy;
3082 if ( ecalEnergy > ecalMax ) {
3083 ecalMax = ecalEnergy;
3084 eClusterRef = eclusterRef;
3087 ecalRefs.push_back(iEcal);
3088 active[iEcal] =
false;
3094 double totalHO = 0.;
3098 std::multimap<double, unsigned> hoElems;
3099 block.associatedElements( iHcal, linkData,
3109 for(IE ie = hoElems.begin(); ie != hoElems.end(); ++ie ) {
3111 unsigned iHO = ie->second;
3112 double dist = ie->first;
3117 if( !active[iHO] )
continue;
3123 std::multimap<double, unsigned> hcalElems;
3124 block.associatedElements( iHO, linkData,
3129 bool isClosest =
true;
3130 for(IE ih = hcalElems.begin(); ih != hcalElems.end(); ++ih ) {
3132 unsigned jHcal = ih->second;
3133 double distH = ih->first;
3135 if ( !active[jHcal] )
continue;
3137 if ( distH < dist ) {
3144 if (!isClosest)
continue;
3147 cout<<
"\telement "<<elements[iHO]<<
" linked with dist "<< dist<<endl;
3148 cout<<
"Added to HCAL cluster to form a neutral hadron"<<endl;
3152 assert( !hoclusterRef.
isNull() );
3154 double hoEnergy = hoclusterRef->energy();
3156 totalHO += hoEnergy;
3157 if ( hoEnergy > hoMax ) {
3159 hoClusterRef = hoclusterRef;
3163 hoRefs.push_back(iHO);
3164 active[iHO] =
false;
3170 = elements[iHcal].clusterRef();
3171 assert( !hclusterRef.
isNull() );
3174 double totalHcal = hclusterRef->energy();
3176 if (
useHO_ ) totalHcal += totalHO;
3184 double calibEcal = totalEcal > 0. ? totalEcal : 0.;
3185 double calibHcal =
std::max(0.,totalHcal);
3189 calibEcal = totalEcal;
3192 hclusterRef->positionREP().Eta(),
3193 hclusterRef->positionREP().Phi());
3206 calibEcal+calibHcal );
3209 (*pfCandidates_)[tmpi].setEcalEnergy( totalEcal, calibEcal );
3211 (*pfCandidates_)[tmpi].setHcalEnergy( totalHcal, calibHcal );
3212 (*pfCandidates_)[tmpi].setHoEnergy(0.,0.);
3214 (*pfCandidates_)[tmpi].setHcalEnergy(
max(totalHcal-totalHO,0.0), calibHcal*(1.-totalHO/totalHcal));
3215 (*pfCandidates_)[tmpi].setHoEnergy(totalHO,totalHO*calibHcal/totalHcal);
3217 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
3218 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
3219 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
3220 for (
unsigned iec=0; iec<ecalRefs.size(); ++iec)
3221 (*
pfCandidates_)[tmpi].addElementInBlock( blockref, ecalRefs[iec] );
3222 for (
unsigned iho=0; iho<hoRefs.size(); ++iho)
3223 (*
pfCandidates_)[tmpi].addElementInBlock( blockref, hoRefs[iho] );
3232 if(
debug_)
cout<<endl<<
"---- loop ecal------- "<<endl;
3237 for(
unsigned i=0;
i<ecalIs.size();
i++) {
3238 unsigned iEcal = ecalIs[
i];
3241 cout<<endl<<elements[iEcal]<<
" ";
3243 if( ! active[iEcal] ) {
3245 cout<<
"not active"<<endl;
3252 PFClusterRef clusterref = elements[iEcal].clusterRef();
3253 assert(!clusterref.
isNull() );
3255 active[iEcal] =
false;
3257 float ecalEnergy = clusterref->correctedEnergy();
3259 double particleEnergy = ecalEnergy;
3264 (*pfCandidates_)[tmpi].setEcalEnergy( clusterref->energy(),ecalEnergy );
3265 (*pfCandidates_)[tmpi].setHcalEnergy( 0., 0. );
3266 (*pfCandidates_)[tmpi].setHoEnergy( 0., 0. );
3267 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
3268 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
3269 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal );
3288 double px = track.
px();
3289 double py = track.
py();
3290 double pz = track.
pz();
3291 double energy =
sqrt(track.
p()*track.
p() + 0.13957*0.13957);
3293 if (
debug_)
cout <<
"Reconstructing PF candidate from track of pT = " << track.
pt() <<
" eta = " << track.
eta() <<
" phi = " << track.
phi() <<
" px = " << px <<
" py = " << py <<
" pz = " << pz <<
" energy = " << energy << endl;
3306 pfCandidates_->back().setVertexSource( PFCandidate::kTrkVertex );
3321 if ((!isMuon) && isFromDisp) {
3322 double Dpt = trackRef->ptError();
3323 double dptRel = Dpt/trackRef->pt()*100;
3329 cout <<
"Not refitted px = " << px <<
" py = " << py <<
" pz = " << pz <<
" energy = " << energy << endl;
3332 reco::Track trackRefit = vRef->refittedTrack(trackRef);
3337 sqrt(trackRefit.
p()*trackRefit.
p() + 0.13957*0.13957));
3339 cout <<
"Refitted px = " << px <<
" py = " << py <<
" pz = " << pz <<
" energy = " << energy << endl;
3358 double particleEnergy,
3371 if ( useDirection ) {
3372 switch( cluster.
layer() ) {
3375 factor =
std::sqrt(cluster.
position().Perp2()/(particleX*particleX+particleY*particleY));
3381 factor = cluster.
position().Z()/particleZ;
3396 cluster.
position().Y()-vertexPos.Y(),
3397 cluster.
position().Z()-vertexPos.Z());
3399 particleY*factor-vertexPos.Y(),
3400 particleZ*factor-vertexPos.Z() );
3405 clusterPos = useDirection ? particleDirection.Unit() : clusterPos.Unit();
3406 clusterPos *= particleEnergy;
3412 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzM4D<double> >
3413 momentum( clusterPos.X(), clusterPos.Y(), clusterPos.Z(),
mass);
3423 switch( cluster.
layer() ) {
3430 particleType = PFCandidate::h0;
3433 particleType = PFCandidate::h_HF;
3436 particleType = PFCandidate::egamma_HF;
3472 std::array<double,7> energyPerDepth;
3473 std::fill(energyPerDepth.begin(), energyPerDepth.end(), 0.0);
3475 const auto &
hit = *hitRefAndFrac.recHitRef();
3477 if (
hit.depth() == 0) {
3481 if (
hit.depth() < 1 ||
hit.depth() > 7) {
3482 throw cms::Exception(
"CorruptData") <<
"Bogus depth " <<
hit.depth() <<
" at detid " <<
hit.detId() <<
"\n";
3484 energyPerDepth[
hit.depth()-1] += hitRefAndFrac.fraction()*
hit.energy();
3487 double sum = std::accumulate(energyPerDepth.begin(), energyPerDepth.end(), 0.);
3488 std::array<float,7> depthFractions;
3490 for (
unsigned int i = 0;
i < depthFractions.size(); ++
i) {
3491 depthFractions[
i] = energyPerDepth[
i]/sum;
3494 std::fill(depthFractions.begin(), depthFractions.end(), 0.f);
3505 if ( clusterEnergyHCAL < 1. ) clusterEnergyHCAL = 1.;
3507 double resol = fabs(eta) < 1.48 ?
3508 sqrt (1.02*1.02/clusterEnergyHCAL + 0.065*0.065)
3510 sqrt (1.20*1.20/clusterEnergyHCAL + 0.028*0.028);
3518 double nS = fabs(eta) < 1.48 ?
3528 if(!out )
return out;
3530 out<<
"====== Particle Flow Algorithm ======= ";
3537 out<<
"reconstructed particles: "<<endl;
3541 if(!candidates.get() ) {
3542 out<<
"candidates already transfered"<<endl;
3571 std::vector<bool>& active,
3572 std::vector<double>& psEne) {
3580 std::multimap<double, unsigned> sortedPS;
3581 typedef std::multimap<double, unsigned>::iterator IE;
3583 sortedPS, psElementType,
3587 double totalPS = 0.;
3588 for ( IE ips=sortedPS.begin(); ips!=sortedPS.end(); ++ips ) {
3591 unsigned iPS = ips->second;
3595 if (!active[iPS])
continue;
3598 std::multimap<double, unsigned> sortedECAL;
3603 unsigned jEcal = sortedECAL.begin()->second;
3604 if ( jEcal != iEcal )
continue;
3608 assert( pstype == psElementType );
3609 PFClusterRef psclusterref = elements[iPS].clusterRef();
3610 assert(!psclusterref.
isNull() );
3611 totalPS += psclusterref->energy();
3612 psEne[0] += psclusterref->energy();
3613 active[iPS] =
false;
3628 bool bPrimary = (order.find(
"primary") != string::npos);
3629 bool bSecondary = (order.find(
"secondary") != string::npos);
3630 bool bAll = (order.find(
"all") != string::npos);
3635 if (bPrimary && isToDisp)
return true;
3636 if (bSecondary && isFromDisp )
return true;
3637 if (bAll && ( isToDisp || isFromDisp ) )
return true;
3666 std::vector<unsigned int> pfCandidatesToBeRemoved;
3673 double met2 = metX*metX+metY*metY;
3679 double metXCor = metX;
3680 double metYCor = metY;
3681 double sumetCor = sumet;
3682 double met2Cor = met2;
3684 double deltaPhiPt = 100.;
3686 unsigned iCor = 1E9;
3691 double metReduc = -1.;
3705 for(
unsigned j=0; j<pfCandidatesToBeRemoved.size(); ++j) {
3706 if (
i == pfCandidatesToBeRemoved[j] ) skip =
true;
3709 if ( skip )
continue;
3712 deltaPhi = std::acos((metX*pfc.
px()+metY*pfc.
py())/(pfc.
pt()*
std::sqrt(met2)));
3713 deltaPhiPt = deltaPhi*pfc.
pt();
3717 double metXInt = metX - pfc.
px();
3718 double metYInt = metY - pfc.
py();
3719 double sumetInt = sumet - pfc.
pt();
3720 double met2Int = metXInt*metXInt+metYInt*metYInt;
3721 if ( met2Int < met2Cor ) {
3724 metReduc = (met2-met2Int)/met2Int;
3726 sumetCor = sumetInt;
3727 significanceCor =
std::sqrt(met2Cor/sumetCor);
3734 pfCandidatesToBeRemoved.push_back(iCor);
3748 std::cout <<
"Significance reduction = " << significance <<
" -> " 3749 << significanceCor <<
" = " << significanceCor - significance
3751 for(
unsigned j=0; j<pfCandidatesToBeRemoved.size(); ++j) {
3752 std::cout <<
"Removed : " << (*pfCandidates_)[pfCandidatesToBeRemoved[j]] << std::endl;
3754 (*pfCandidates_)[pfCandidatesToBeRemoved[j]].rescaleMomentum(1E-6);
3768 if ( cleanedHits.empty() )
return;
3774 std::vector<unsigned int> hitsToBeAdded;
3781 double met2 = metX*metX+metY*metY;
3782 double met2_Original = met2;
3786 double metXCor = metX;
3787 double metYCor = metY;
3788 double sumetCor = sumet;
3789 double met2Cor = met2;
3791 unsigned iCor = 1E9;
3796 double metReduc = -1.;
3798 for(
unsigned i=0;
i<cleanedHits.size(); ++
i) {
3807 for(
unsigned j=0; j<hitsToBeAdded.size(); ++j) {
3808 if (
i == hitsToBeAdded[j] ) skip =
true;
3811 if ( skip )
continue;
3814 double metXInt = metX + px;
3815 double metYInt = metY + py;
3816 double sumetInt = sumet +
pt;
3817 double met2Int = metXInt*metXInt+metYInt*metYInt;
3820 if ( met2Int < met2Cor ) {
3823 metReduc = (met2-met2Int)/met2Int;
3825 sumetCor = sumetInt;
3834 hitsToBeAdded.push_back(iCor);
3848 std::cout << hitsToBeAdded.size() <<
" hits were re-added " << std::endl;
3852 std::cout <<
"Added after cleaning check : " << std::endl;
3854 for(
unsigned j=0; j<hitsToBeAdded.size(); ++j) {
3855 const PFRecHit&
hit = cleanedHits[hitsToBeAdded[j]];
3874 for(
unsigned ic=0;ic<
size;++ic) {
3883 (*pfCandidates_)[ic].setPFElectronExtraRef(theRef);
3895 (*pfCandidates_)[ic].set_mva_e_pi(it->mvaVariable(PFCandidateElectronExtra::MVA_MVA));
3897 (*pfCandidates_)[ic].setPFElectronExtraRef(theRef);
3898 (*pfCandidates_)[ic].setGsfTrackRef(it->gsfTrackRef());
3906 for(
unsigned ic=0;ic<
size;++ic) {
3914 (*pfElectronCandidates_)[ic].setPFElectronExtraRef(theRef);
3925 for(
unsigned ic=0;ic<
size;++ic) {
3930 for(
unsigned pcextra=0;pcextra<sizePhExtra;++pcextra) {
3933 (*pfCandidates_)[ic].setPFPhotonExtraRef(theRef);
PFLayer::Layer layer() const
cluster layer, see PFLayer.h in this directory
sumPtTrackIsoForEgammaSC_barrel
double p() const
momentum vector magnitude
T getParameter(std::string const &) const
unsigned int nTrackIsoForEgammaSC_
edm::Ref< PFBlockCollection > PFBlockRef
persistent reference to PFCluster objects
Abstract base class for a PFBlock element (track, cluster...)
static bool isIsolatedMuon(const reco::PFBlockElement &elt)
const math::XYZPoint & position() const
cluster centroid position
bool isFromSecInt(const reco::PFBlockElement &eTrack, std::string order) const
float goodTrackDeadHcal_dxy_
std::vector< double > muonHCAL_
Variables for muons and fakes.
ParticleType
particle types
bool isNonnull() const
Checks for non-null.
T y() const
Cartesian y coordinate.
double eta() const final
momentum pseudorapidity
sumPtTrackIsoForEgammaSC_endcap
void setPFMuonAndFakeParameters(const edm::ParameterSet &pset)
T x() const
Cartesian x coordinate.
void addMissingMuons(edm::Handle< reco::MuonCollection >, reco::PFCandidateCollection *cands)
double sumEtEcalIsoForEgammaSC_endcap_
bool isElectronSafeForJetMET(const reco::GsfElectron &, const reco::PFCandidate &, const reco::Vertex &, bool &lockTracks)
void set_mva_nothing_gamma(float mva)
set mva for gamma detection
bool isMuon(const Candidate &part)
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
bool isPhotonValidCandidate(const reco::PFBlockRef &blockRef, std::vector< bool > &active, std::unique_ptr< reco::PFCandidateCollection > &pfPhotonCandidates, std::vector< reco::PFCandidatePhotonExtra > &pfPhotonExtraCandidates, std::vector< reco::PFCandidate > &tempElectronCandidates)
edm::Ref< PFCandidatePhotonExtraCollection > PFCandidatePhotonExtraRef
persistent reference to a PFCandidatePhotonExtra
double coneEcalIsoForEgammaSC_
static bool isMuon(const reco::PFBlockElement &elt)
const std::vector< reco::PFCandidate > & getAllElectronCandidates()
float time() const
timing for cleaned hits
std::unique_ptr< reco::PFCandidateCollection > pfCandidates_
unsigned reconstructCluster(const reco::PFCluster &cluster, double particleEnergy, bool useDirection=false, double particleX=0., double particleY=0., double particleZ=0.)
void reconstructParticles(const reco::PFBlockHandle &blockHandle)
const std::unique_ptr< reco::PFCandidateCollection > & pfCandidates() const
double y() const
y coordinate
bool useProtectionsForJetMET_
double coneTrackIsoForEgammaSC_
void setParameters(const edm::ParameterSet &)
float goodPixelTrackDeadHcal_minEta_
const reco::TrackRef & trackRef() const override
double px() const final
x coordinate of momentum vector
double nSigmaHCAL_
number of sigma to judge energy excess in HCAL
std::map< unsigned int, Link > LinkData
virtual void processBlock(const reco::PFBlockRef &blockref, std::list< reco::PFBlockRef > &hcalBlockRefs, std::list< reco::PFBlockRef > &ecalBlockRefs)
void setMuonHandle(const edm::Handle< reco::MuonCollection > &)
bool trackType(TrackType trType) const override
math::Error< dimension >::type Error
covariance error matrix (3x3)
void setVertex(const math::XYZPoint &p) override
set vertex
std::vector< Variable::Flags > flags
double phi() const
azimuthal angle of momentum vector
double pt() const final
transverse momentum
std::vector< Vertex > VertexCollection
collection of Vertex objects
const edm::OwnVector< reco::PFBlockElement > & elements() const
int charge() const final
electric charge
std::vector< PFRecHit > PFRecHitCollection
collection of PFRecHit objects
sumEtEcalIsoForEgammaSC_endcap
const edm::ValueMap< reco::PhotonRef > * valueMapGedPhotons_
void checkCleaning(const reco::PFRecHitCollection &cleanedHF)
Check HF Cleaning.
edm::Ref< PFCandidateElectronExtraCollection > PFCandidateElectronExtraRef
persistent reference to a PFCandidateElectronExtra
bool passElectronSelection(const reco::GsfElectron &, const reco::PFCandidate &, const int &)
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float > > XYZPointF
point in space with cartesian internal representation
double px() const
x coordinate of momentum vector
void setDisplacedVerticesParameters(bool rejectTracks_Bad, bool rejectTracks_Step45, bool usePFNuclearInteractions, bool usePFConversions, bool usePFDecays, double dptRel_DispVtx)
PFCandidateCollection::const_iterator PFCandidateConstIterator
iterator
double sumEtEcalIsoForEgammaSC_barrel_
void setPFEleParameters(double mvaEleCut, std::string mvaWeightFileEleID, bool usePFElectrons, const boost::shared_ptr< PFSCEnergyCalibration > &thePFSCEnergyCalibration, const boost::shared_ptr< PFEnergyCalibration > &thePFEnergyCalibration, double sumEtEcalIsoForEgammaSC_barrel, double sumEtEcalIsoForEgammaSC_endcap, double coneEcalIsoForEgammaSC, double sumPtTrackIsoForEgammaSC_barrel, double sumPtTrackIsoForEgammaSC_endcap, unsigned int nTrackIsoForEgammaSC, double coneTrackIsoForEgammaSC, bool applyCrackCorrections=false, bool usePFSCEleCalib=true, bool useEGElectrons=false, bool useEGammaSupercluster=true)
float goodPixelTrackDeadHcal_dxy_
void setPFVertexParameters(bool useVertex, const reco::VertexCollection *primaryVertices)
void setEGElectronCollection(const reco::GsfElectronCollection &egelectrons)
const Point & position() const
position
static bool isGlobalTightMuon(const reco::PFBlockElement &elt)
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
bool rejectTracks_Step45_
const math::XYZPointF & positionAtECALEntrance() const
PositionType const & position() const
rechit cell centre x, y, z
std::vector< ElementInBlock > ElementsInBlocks
double minSignificanceReduction_
void setPFPhotonParameters(bool usePFPhoton, std::string mvaWeightFileConvID, double mvaConvCut, bool useReg, std::string X0_Map, const boost::shared_ptr< PFEnergyCalibration > &thePFEnergyCalibration, double sumPtTrackIsoForPhoton, double sumPtTrackIsoSlopeForPhoton)
std::vector< double > factors45_
PFLayer::Layer layer() const
rechit layer
RefToBase< value_type > refAt(size_type i) const
bool useEGammaSupercluster_
U second(std::pair< T, U > const &p)
void setCharge(Charge q) final
set electric charge
std::unique_ptr< reco::PFCandidateCollection > pfCleanedCandidates_
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
bool isElectron(const reco::GsfElectron &)
void set_mva_e_pi(float mvaNI)
bool isTimeValid() const
do we have a valid time information
bool usePFNuclearInteractions_
double eta() const
pseudorapidity of momentum vector
void setEGammaCollections(const edm::View< reco::PFCandidate > &pfEgammaCandidates, const edm::ValueMap< reco::GsfElectronRef > &valueMapGedElectrons, const edm::ValueMap< reco::PhotonRef > &valueMapGedPhotons)
Particle flow rechit (rechit + geometry and topology information). See clustering algorithm in PFClus...
void setBadHcalTrackParams(const edm::ParameterSet &pset)
void set_mva_Isolated(float mvaI)
boost::shared_ptr< PFEnergyCalibration > thePFEnergyCalibration()
return the pointer to the calibration function
void setParameters(double nSigmaECAL, double nSigmaHCAL, const boost::shared_ptr< PFEnergyCalibration > &calibration, const boost::shared_ptr< PFEnergyCalibrationHF > &thepfEnergyCalibrationHF)
T z() const
Cartesian z coordinate.
const edm::View< reco::PFCandidate > * pfEgammaCandidates_
void associatePSClusters(unsigned iEcal, reco::PFBlockElement::Type psElementType, const reco::PFBlock &block, const edm::OwnVector< reco::PFBlockElement > &elements, const reco::PFBlock::LinkData &linkData, std::vector< bool > &active, std::vector< double > &psEne)
Associate PS clusters to a given ECAL cluster, and return their energy.
std::string mvaWeightFileEleID_
Variables for PFElectrons.
void setParticleType(ParticleType type)
set Particle Type
bool passPhotonSelection(const reco::Photon &)
double pt() const
track transverse momentum
const std::vector< reco::PFCandidateElectronExtra > & getElectronExtra()
float goodTrackDeadHcal_validFr_
double energy() const final
energy
void setPFPhotonRegWeights(const GBRForest *LCorrForestEB, const GBRForest *LCorrForestEE, const GBRForest *GCorrForestBarrel, const GBRForest *GCorrForestEndcapHr9, const GBRForest *GCorrForestEndcapLr9, const GBRForest *PFEcalResolution)
Abs< T >::type abs(const T &t)
double z() const
z coordinate
reco::Vertex primaryVertex_
double nSigmaHCAL(double clusterEnergy, double clusterEta) const
edm::Handle< reco::MuonCollection > muonHandle_
std::vector< double > muonECAL_
void setPositionAtECALEntrance(float x, float y, float z)
set position at ECAL entrance
math::XYZPoint Point
point in the space
float energy() const
rechit energy
std::vector< LinkConnSpec >::const_iterator IT
sumEtEcalIsoForEgammaSC_barrel
void setPostHFCleaningParameters(bool postHFCleaning, double minHFCleaningPt, double minSignificance, double maxSignificance, double minSignificanceReduction, double maxDeltaPhiPt, double minDeltaMet)
std::vector< PFBlock > PFBlockCollection
collection of PFBlock objects
PFEGammaFilters * pfegamma_
bool isNull() const
Checks for null.
int goodPixelTrackDeadHcal_maxLost3Hit_
reco::PFBlockRef createBlockRef(const reco::PFBlockCollection &blocks, unsigned bi)
reco::PFCandidatePhotonExtraCollection pfPhotonExtra_
the extra photon collection
double pz() const
z coordinate of momentum vector
void setEcalEnergy(float eeRaw, float eeCorr)
set corrected Ecal energy
float mva_e_pi() const
mva for electron-pion discrimination
void setHcalDepthEnergyFractions(const std::array< float, 7 > &fracs)
set the fraction of hcal energy as function of depth (index 0..6 for depth 1..7)
std::unique_ptr< reco::PFCandidateCollection > pfPhotonCandidates_
the unfiltered photon collection
const PFDisplacedTrackerVertexRef & displacedVertexRef(TrackType trType) const override
const std::vector< reco::PFCandidate > & getElectronCandidates()
float goodPixelTrackDeadHcal_maxPt_
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
double x() const
x coordinate
std::list< reco::PFBlockRef >::iterator IBR
unsigned reconstructTrack(const reco::PFBlockElement &elt, bool allowLoose=false)
int goodTrackDeadHcal_layers_
std::vector< double > muonHO_
float goodPixelTrackDeadHcal_ptErrRel_
XYZVectorD XYZVector
spatial vector with cartesian internal representation
void setGBRForest(const GBRForest *LCorrForest, const GBRForest *GCorrForest, const GBRForest *ResForest)
void associatedElements(unsigned i, const LinkData &linkData, std::multimap< double, unsigned > &sortedAssociates, reco::PFBlockElement::Type type=PFBlockElement::NONE, LinkTest test=LINKTEST_RECHIT) const
static bool isLooseMuon(const reco::PFBlockElement &elt)
XYZPointD XYZPoint
point in space with cartesian internal representation
boost::shared_ptr< PFEnergyCalibration > calibration_
reco::PFBlockHandle blockHandle_
input block handle (full framework case)
double py() const final
y coordinate of momentum vector
virtual bool trackType(TrackType trType) const
boost::shared_ptr< PFSCEnergyCalibration > thePFSCEnergyCalibration_
void setEGammaParameters(bool use_EGammaFilters, std::string ele_iso_path_mvaWeightFile, double ele_iso_pt, double ele_iso_mva_barrel, double ele_iso_mva_endcap, double ele_iso_combIso_barrel, double ele_iso_combIso_endcap, double ele_noniso_mva, unsigned int ele_missinghits, bool useProtectionsForJetMET, const edm::ParameterSet &ele_protectionsForJetMET, const edm::ParameterSet &ele_protectionsForBadHcal, double ph_MinEt, double ph_combIso, double ph_HoE, double ph_sietaieta_eb, double ph_sietaieta_ee, const edm::ParameterSet &ph_protectionsForJetMET, const edm::ParameterSet &ph_protectionsForBadHcal)
virtual ~PFAlgo()
destructor
void setHoEnergy(float eoRaw, float eoCorr)
set corrected Hcal energy
std::vector< std::vector< double > > tmp
bool isElectronValidCandidate(const reco::PFBlockRef &blockRef, std::vector< bool > &active, const reco::Vertex &primaryVertex)
Particle reconstructed by the particle flow algorithm.
boost::shared_ptr< PFEnergyCalibrationHF > thepfEnergyCalibrationHF_
reco::PFCandidateEGammaExtraRef egammaExtraRef() const
return a reference to the EGamma extra
PFMuonAlgo * getPFMuonAlgo()
bool useEGammaFilters_
Variables for NEW EGAMMA selection.
const std::vector< reco::PFRecHitFraction > & recHitFractions() const
vector of rechit fractions
void setPhotonExtraRef(const edm::OrphanHandle< reco::PFCandidatePhotonExtraCollection > &pf_extrah)
bool applyCrackCorrectionsElectrons_
int charge() const
track electric charge
float goodTrackDeadHcal_ptErrRel_
Variables for track cleaning in bad HCal areas.
sumPtTrackIsoSlopeForPhoton
double sumPtTrackIsoForEgammaSC_endcap_
std::unique_ptr< reco::PFCandidateCollection > pfElectronCandidates_
the unfiltered electron collection
void setPhotonPrimaryVtx(const reco::Vertex &primary)
int goodPixelTrackDeadHcal_maxLost4Hit_
const reco::MuonRef & muonRef() const override
float goodPixelTrackDeadHcal_chi2n_
virtual ParticleType particleId() const
double neutralHadronEnergyResolution(double clusterEnergy, double clusterEta) const
todo: use PFClusterTools for this
void postClean(reco::PFCandidateCollection *)
reco::PFCandidateElectronExtraCollection pfElectronExtra_
the unfiltered electron collection
const ElementsInBlocks & elementsInBlocks() const
void setInputsForCleaning(const reco::VertexCollection *)
double phi() const final
momentum azimuthal angle
bool isPhotonSafeForJetMET(const reco::Photon &, const reco::PFCandidate &)
void setP4(const LorentzVector &p4) final
set 4-momentum
float goodTrackDeadHcal_chi2n_
double sumPtTrackIsoForEgammaSC_barrel_
float goodPixelTrackDeadHcal_dz_
void setHcalEnergy(float ehRaw, float ehCorr)
set corrected Hcal energy
void setHcalDepthInfo(reco::PFCandidate &cand, const reco::PFCluster &cluster) const
double py() const
y coordinate of momentum vector
static bool isTrackerTightMuon(const reco::PFBlockElement &elt)
const edm::ValueMap< reco::GsfElectronRef > * valueMapGedElectrons_
friend std::ostream & operator<<(std::ostream &out, const PFAlgo &algo)
void setElectronExtraRef(const edm::OrphanHandle< reco::PFCandidateElectronExtraCollection > &extrah)
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
void setEGElectronCollection(const reco::GsfElectronCollection &egelectrons)
bool reconstructMuon(reco::PFCandidate &, const reco::MuonRef &, bool allowLoose=false)
double nSigmaECAL_
number of sigma to judge energy excess in ECAL