39 #include "Math/PxPyPzM4D.h"
40 #include "Math/LorentzVector.h"
41 #include "Math/DisplacementVector3D.h"
42 #include "Math/SMatrix.h"
43 #include "TDecompChol.h"
45 #include "boost/graph/adjacency_matrix.hpp"
46 #include "boost/graph/graph_utility.hpp"
52 using namespace boost;
54 typedef std::list< reco::PFBlockRef >::iterator
IBR;
80 const boost::shared_ptr<PFEnergyCalibration>& calibration,
81 const boost::shared_ptr<PFEnergyCalibrationHF>& thepfEnergyCalibrationHF) {
99 string mvaWeightFileEleID,
101 const boost::shared_ptr<PFSCEnergyCalibration>& thePFSCEnergyCalibration,
102 const boost::shared_ptr<PFEnergyCalibration>& thePFEnergyCalibration,
138 string err =
"PFAlgo: cannot open weight file '";
139 err += mvaWeightFileEleID;
141 throw invalid_argument( err );
145 thePFEnergyCalibration,
165 const boost::shared_ptr<PFEnergyCalibration>& thePFEnergyCalibration,
180 e(0, 0) = 0.0015 * 0.0015;
181 e(1, 1) = 0.0015 * 0.0015;
188 FILE * filePhotonConvID = fopen(mvaWeightFileConvID.c_str(),
"r");
189 if (filePhotonConvID) {
190 fclose(filePhotonConvID);
193 string err =
"PFAlgo: cannot open weight file '";
194 err += mvaWeightFileConvID;
196 throw invalid_argument( err );
204 thePFEnergyCalibration,
205 sumPtTrackIsoForPhoton,
206 sumPtTrackIsoSlopeForPhoton
214 double ele_iso_mva_barrel,
215 double ele_iso_mva_endcap,
216 double ele_iso_combIso_barrel,
217 double ele_iso_combIso_endcap,
218 double ele_noniso_mva,
219 unsigned int ele_missinghits,
225 double ph_sietaieta_eb,
226 double ph_sietaieta_ee,
234 FILE * fileEGamma_ele_iso_ID = fopen(ele_iso_path_mvaWeightFile.c_str(),
"r");
235 if (fileEGamma_ele_iso_ID) {
236 fclose(fileEGamma_ele_iso_ID);
239 string err =
"PFAlgo: cannot open weight file '";
240 err += ele_iso_path_mvaWeightFile;
242 throw invalid_argument( err );
253 ph_protectionsForJetMET,
257 ele_iso_combIso_barrel,
258 ele_iso_combIso_endcap,
261 ele_iso_path_mvaWeightFile,
262 ele_protectionsForJetMET);
297 GCorrForestBarrel, GCorrForestEndcapHr9,
298 GCorrForestEndcapLr9, PFEcalResolution);
320 assert (
muonHCAL_.size() == 2 && muonECAL_.size() == 2 && muonHO_.size() == 2);
324 assert ( factors45_.size() == 2 );
380 bool primaryVertexFound =
false;
381 nVtx_ = primaryVertices->size();
385 for (
unsigned short i=0 ;
i<primaryVertices->size();++
i)
387 if(primaryVertices->at(
i).isValid()&&(!primaryVertices->at(
i).isFake()))
390 primaryVertexFound =
true;
402 e(0, 0) = 0.0015 * 0.0015;
403 e(1, 1) = 0.0015 * 0.0015;
451 cout<<
"*********************************************************"<<endl;
452 cout<<
"***** Particle flow algorithm *****"<<endl;
453 cout<<
"*********************************************************"<<endl;
457 std::list< reco::PFBlockRef > hcalBlockRefs;
458 std::list< reco::PFBlockRef > ecalBlockRefs;
459 std::list< reco::PFBlockRef > hoBlockRefs;
460 std::list< reco::PFBlockRef > otherBlockRefs;
462 for(
unsigned i=0;
i<blocks.size(); ++
i ) {
470 bool singleEcalOrHcal =
false;
471 if( elements.
size() == 1 ){
473 ecalBlockRefs.push_back( blockref );
474 singleEcalOrHcal =
true;
477 hcalBlockRefs.push_back( blockref );
478 singleEcalOrHcal =
true;
482 hoBlockRefs.push_back( blockref );
483 singleEcalOrHcal =
true;
487 if(!singleEcalOrHcal) {
488 otherBlockRefs.push_back( blockref );
493 cout<<
"# Ecal blocks: "<<ecalBlockRefs.size()
494 <<
", # Hcal blocks: "<<hcalBlockRefs.size()
495 <<
", # HO blocks: "<<hoBlockRefs.size()
496 <<
", # Other blocks: "<<otherBlockRefs.size()<<endl;
504 for(
IBR io = otherBlockRefs.begin(); io!=otherBlockRefs.end(); ++io) {
509 std::list< reco::PFBlockRef >
empty;
513 for(
IBR ih = hcalBlockRefs.begin(); ih!=hcalBlockRefs.end(); ++ih) {
514 if (
debug_ )
std::cout <<
"HCAL block number " << hblcks++ << std::endl;
520 for(
IBR ie = ecalBlockRefs.begin(); ie!=ecalBlockRefs.end(); ++ie) {
521 if (
debug_ )
std::cout <<
"ECAL block number " << eblcks++ << std::endl;
538 std::list<reco::PFBlockRef>& hcalBlockRefs,
539 std::list<reco::PFBlockRef>& ecalBlockRefs ) {
545 typedef std::multimap<double, unsigned>::iterator IE;
546 typedef std::multimap<double, std::pair<unsigned,::math::XYZVector> >::iterator IS;
547 typedef std::multimap<double, std::pair<unsigned,bool> >::iterator
IT;
548 typedef std::multimap< unsigned, std::pair<double, unsigned> >::iterator II;
551 cout<<
"#########################################################"<<endl;
552 cout<<
"##### Process Block: #####"<<endl;
553 cout<<
"#########################################################"<<endl;
563 vector<bool> active( elements.
size(),
true );
568 std::vector<reco::PFCandidate> tempElectronCandidates;
569 tempElectronCandidates.clear();
574 for ( std::vector<reco::PFCandidate>::const_iterator ec=PFElectCandidates_.begin(); ec != PFElectCandidates_.end(); ++ec )tempElectronCandidates.push_back(*ec);
594 cout<<endl<<
"--------------- entering PFPhotonAlgo ----------------"<<endl;
595 vector<PFCandidatePhotonExtra> pfPhotonExtraCand;
600 tempElectronCandidates
610 unsigned int extracand =0;
618 pfPhotonExtraCand.clear();
623 for ( std::vector<reco::PFCandidate>::const_iterator ec=tempElectronCandidates.begin(); ec != tempElectronCandidates.end(); ++ec ){
626 tempElectronCandidates.clear();
634 bool egmLocalDebug =
false;
635 bool egmLocalBlockDebug =
false;
638 for(
unsigned int ieg=0 ; ieg < negmcandidates; ++ieg) {
643 PFCandidate::ElementsInBlocks::const_iterator iegfirst = theElements.begin();
644 bool sameBlock =
false;
645 bool isGoodElectron =
false;
646 bool isGoodPhoton =
false;
647 bool isPrimaryElectron =
false;
648 if(iegfirst->first == blockref)
653 cout <<
" I am in looping on EGamma Candidates: pt " << (*pfEgmRef).pt()
654 <<
" eta,phi " << (*pfEgmRef).eta() <<
", " << (*pfEgmRef).phi()
655 <<
" charge " << (*pfEgmRef).charge() << endl;
657 if((*pfEgmRef).gsfTrackRef().isNonnull()) {
665 cout <<
"** Good Electron, pt " << gedEleRef->pt()
666 <<
" eta, phi " << gedEleRef->eta() <<
", " << gedEleRef->phi()
667 <<
" charge " << gedEleRef->charge()
668 <<
" isPrimary " << isPrimaryElectron << endl;
674 if((*pfEgmRef).superClusterRef().isNonnull()) {
681 cout <<
"** Good Photon, pt " << gedPhoRef->pt()
682 <<
" eta, phi " << gedPhoRef->eta() <<
", " << gedPhoRef->phi() << endl;
688 if(isGoodElectron && isGoodPhoton) {
689 if(isPrimaryElectron)
690 isGoodPhoton =
false;
692 isGoodElectron =
false;
700 bool lockTracks =
false;
710 myPFElectron.
setCharge(gedEleRef->charge());
711 myPFElectron.
setP4(gedEleRef->p4());
716 cout <<
" PFAlgo: found an electron with NEW EGamma code " << endl;
717 cout <<
" myPFElectron: pt " << myPFElectron.
pt()
718 <<
" eta,phi " << myPFElectron.
eta() <<
", " <<myPFElectron.
phi()
719 <<
" mva " << myPFElectron.
mva_e_pi()
720 <<
" charge " << myPFElectron.
charge() << endl;
725 if(egmLocalBlockDebug)
726 cout <<
" THE BLOCK " << *blockref << endl;
727 for (PFCandidate::ElementsInBlocks::const_iterator ieb = theElements.begin();
728 ieb<theElements.end(); ++ieb) {
729 active[ieb->second] =
false;
730 if(egmLocalBlockDebug)
731 cout <<
" Elements used " << ieb->second << endl;
737 for (PFCandidate::ElementsInBlocks::const_iterator itrk = extraTracks.begin();
738 itrk<extraTracks.end(); ++itrk) {
739 active[itrk->second] =
false;
748 cout <<
"PFAlgo: Electron DISCARDED, NOT SAFE FOR JETMET " << endl;
768 myPFPhoton.
setP4(gedPhoRef->p4());
770 cout <<
" PFAlgo: found a photon with NEW EGamma code " << endl;
771 cout <<
" myPFPhoton: pt " << myPFPhoton.
pt()
772 <<
" eta,phi " << myPFPhoton.
eta() <<
", " <<myPFPhoton.
phi()
773 <<
" charge " << myPFPhoton.
charge() << endl;
777 if(egmLocalBlockDebug)
778 cout <<
" THE BLOCK " << *blockref << endl;
779 for (PFCandidate::ElementsInBlocks::const_iterator ieb = theElements.begin();
780 ieb<theElements.end(); ++ieb) {
781 active[ieb->second] =
false;
782 if(egmLocalBlockDebug)
783 cout <<
" Elements used " << ieb->second << endl;
797 for(
unsigned iEle=0; iEle<elements.
size(); iEle++) {
799 if(type==PFBlockElement::TRACK)
801 if(elements[iEle].trackRef()->
algo() == 12)
806 if(elements[iEle].convRefs().
size())active[iEle]=
false;
816 cout<<endl<<
"--------------- loop 1 ------------------"<<endl;
843 vector<unsigned> hcalIs;
844 vector<unsigned> hoIs;
845 vector<unsigned> ecalIs;
846 vector<unsigned> trackIs;
847 vector<unsigned> ps1Is;
848 vector<unsigned> ps2Is;
850 vector<unsigned> hfEmIs;
851 vector<unsigned> hfHadIs;
854 for(
unsigned iEle=0; iEle<elements.
size(); iEle++) {
857 if(
debug_ && type != PFBlockElement::BREM )
cout<<endl<<elements[iEle];
860 case PFBlockElement::TRACK:
861 if ( active[iEle] ) {
863 if(
debug_)
cout<<
"TRACK, stored index, continue"<<endl;
867 if ( active[iEle] ) {
868 ecalIs.push_back( iEle );
869 if(
debug_)
cout<<
"ECAL, stored index, continue"<<endl;
873 if ( active[iEle] ) {
874 hcalIs.push_back( iEle );
875 if(
debug_)
cout<<
"HCAL, stored index, continue"<<endl;
878 case PFBlockElement::HO:
880 if ( active[iEle] ) {
881 hoIs.push_back( iEle );
882 if(
debug_)
cout<<
"HO, stored index, continue"<<endl;
886 case PFBlockElement::HFEM:
887 if ( active[iEle] ) {
888 hfEmIs.push_back( iEle );
889 if(
debug_)
cout<<
"HFEM, stored index, continue"<<endl;
892 case PFBlockElement::HFHAD:
893 if ( active[iEle] ) {
894 hfHadIs.push_back( iEle );
895 if(
debug_)
cout<<
"HFHAD, stored index, continue"<<endl;
903 unsigned iTrack = iEle;
909 if (active[iTrack] &&
isFromSecInt(elements[iEle],
"primary")){
910 bool isPrimaryTrack = elements[iEle].displacedVertexRef(PFBlockElement::T_TO_DISP)->displacedVertexRef()->isTherePrimaryTracks();
911 if (isPrimaryTrack) {
912 if (
debug_)
cout <<
"Primary Track reconstructed alone" << endl;
915 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEle );
916 active[iTrack] =
false;
922 if ( !active[iTrack] )
923 cout <<
"Already used by electrons, muons, conversions" << endl;
928 if ( ! active[iTrack] )
continue;
934 cout <<
"PFAlgo:processBlock "<<
" "<<trackIs.size()<<
" "<<ecalIs.size()<<
" "<<hcalIs.size()<<
" "<<hoIs.size()<<endl;
941 std::multimap<double, unsigned> ecalElems;
942 block.associatedElements( iTrack, linkData,
947 std::multimap<double, unsigned> hcalElems;
948 block.associatedElements( iTrack, linkData,
956 if ( hcalElems.empty() && !ecalElems.empty() ) {
959 unsigned index = ecalElems.begin()->second;
960 std::multimap<double, unsigned> sortedTracks;
961 block.associatedElements( index, linkData,
968 for(IE ie = sortedTracks.begin(); ie != sortedTracks.end(); ++ie ) {
969 unsigned jTrack = ie->second;
972 if ( !active[jTrack] )
continue;
976 if ( jTrack == iTrack )
continue;
981 std::multimap<double, unsigned> sortedECAL;
982 block.associatedElements( jTrack, linkData,
986 if ( sortedECAL.begin()->second !=
index )
continue;
991 std::multimap<double, unsigned> sortedHCAL;
992 block.associatedElements( jTrack, linkData,
996 if ( !sortedHCAL.size() )
continue;
1001 block.setLink( iTrack,
1002 sortedHCAL.begin()->second,
1003 sortedECAL.begin()->first,
1005 PFBlock::LINKTEST_RECHIT );
1010 block.associatedElements( iTrack, linkData,
1015 if (
debug_ && hcalElems.size() )
1016 std::cout <<
"Track linked back to HCAL due to ECAL sharing with other tracks" << std::endl;
1026 std::multimap<double,unsigned> gsfElems;
1028 block.associatedElements( iTrack, linkData,
1034 if(hcalElems.empty() &&
debug_) {
1035 cout<<
"no hcal element connected to track "<<iTrack<<endl;
1041 bool hcalFound =
false;
1044 cout<<
"now looping on elements associated to the track"<<endl;
1048 for(IE ie = ecalElems.begin(); ie != ecalElems.end(); ++ie ) {
1050 unsigned index = ie->second;
1054 double dist = ie->first;
1055 cout<<
"\telement "<<elements[
index]<<
" linked with distance = "<< dist <<endl;
1056 if ( ! active[index] )
cout <<
"This ECAL is already used - skip it" << endl;
1061 if ( ! active[index] )
continue;
1067 if( !hcalElems.empty() &&
debug_)
1068 cout<<
"\t\tat least one hcal element connected to the track."
1069 <<
" Sparing Ecal cluster for the hcal loop"<<endl;
1077 if( hcalElems.empty() ) {
1080 std::cout <<
"Now deals with tracks linked to no HCAL clusters" << std::endl;
1087 std::cout << elements[iTrack] << std::endl;
1093 if ( thisIsAMuon ) trackMomentum = 0.;
1097 bool rejectFake =
false;
1098 if ( !thisIsAMuon && elements[iTrack].trackRef()->ptError() >
ptError_ ) {
1102 elements[iTrack].trackRef()->
eta());
1105 if ( !ecalElems.empty() ) {
1106 unsigned thisEcal = ecalElems.begin()->second;
1108 deficit -= clusterRef->energy();
1110 clusterRef->positionREP().Eta());
1114 bool isPrimary =
isFromSecInt(elements[iTrack],
"primary");
1118 active[iTrack] =
false;
1120 std::cout << elements[iTrack] << std::endl
1121 <<
"is probably a fake (1) --> lock the track"
1126 if ( rejectFake )
continue;
1131 std::vector<unsigned> tmpi;
1132 std::vector<unsigned> kTrack;
1135 double Dpt = trackRef->ptError();
1138 trackMomentum > 30. && Dpt > 0.5 &&
1141 trackRef->algo() == TrackBase::tobTecStep ) ) {
1143 double dptRel = Dpt/trackRef->pt()*100;
1144 bool isPrimaryOrSecondary =
isFromSecInt(elements[iTrack],
"all");
1147 unsigned nHits = elements[iTrack].trackRef()->hitPattern().trackerLayersWithMeasurement();
1148 unsigned int NLostHit = trackRef->hitPattern().trackerLayersWithoutMeasurement(HitPattern::TRACK_HITS);
1151 std::cout <<
"A track (algo = " << trackRef->algo() <<
") with momentum " << trackMomentum
1152 <<
" / " << elements[iTrack].trackRef()->pt() <<
" +/- " << Dpt
1153 <<
" / " << elements[iTrack].trackRef()->eta()
1154 <<
" without any link to ECAL/HCAL and with " << nHits <<
" (" << NLostHit
1155 <<
") hits (lost hits) has been cleaned" << std::endl;
1156 active[iTrack] =
false;
1163 kTrack.push_back(iTrack);
1164 active[iTrack] =
false;
1167 if ( ecalElems.empty() ) {
1168 (*pfCandidates_)[tmpi[0]].setEcalEnergy( 0., 0. );
1169 (*pfCandidates_)[tmpi[0]].setHcalEnergy( 0., 0. );
1170 (*pfCandidates_)[tmpi[0]].setHoEnergy( 0., 0. );
1171 (*pfCandidates_)[tmpi[0]].setPs1Energy( 0 );
1172 (*pfCandidates_)[tmpi[0]].setPs2Energy( 0 );
1173 (*pfCandidates_)[tmpi[0]].addElementInBlock( blockref, kTrack[0] );
1178 unsigned thisEcal = ecalElems.begin()->second;
1180 if (
debug_ )
std::cout <<
" is associated to " << elements[thisEcal] << std::endl;
1184 if ( thisIsAMuon ) {
1185 (*pfCandidates_)[tmpi[0]].setEcalEnergy( clusterRef->energy(),
1187 (*pfCandidates_)[tmpi[0]].setHcalEnergy( 0., 0. );
1188 (*pfCandidates_)[tmpi[0]].setHoEnergy( 0., 0. );
1189 (*pfCandidates_)[tmpi[0]].setPs1Energy( 0 );
1190 (*pfCandidates_)[tmpi[0]].setPs2Energy( 0 );
1191 (*pfCandidates_)[tmpi[0]].addElementInBlock( blockref, kTrack[0] );
1194 double slopeEcal = 1.;
1195 bool connectedToEcal =
false;
1196 unsigned iEcal = 99999;
1197 double calibEcal = 0.;
1198 double calibHcal = 0.;
1199 double totalEcal = thisIsAMuon ? -
muonECAL_[0] : 0.;
1202 std::multimap<double, unsigned> sortedTracks;
1203 block.associatedElements( thisEcal, linkData,
1208 for(IE ie = sortedTracks.begin(); ie != sortedTracks.end(); ++ie ) {
1209 unsigned jTrack = ie->second;
1212 if ( !active[jTrack] )
continue;
1215 if ( jTrack == iTrack )
continue;
1220 std::multimap<double, unsigned> sortedECAL;
1221 block.associatedElements( jTrack, linkData,
1225 if ( sortedECAL.begin()->second != thisEcal )
continue;
1232 bool rejectFake =
false;
1234 if ( !thatIsAMuon && trackRef->ptError() >
ptError_) {
1235 double deficit = trackMomentum + trackRef->p() - clusterRef->energy();
1237 clusterRef->positionREP().Eta());
1238 resol *= (trackMomentum+trackRef->p());
1241 kTrack.push_back(jTrack);
1242 active[jTrack] =
false;
1244 std::cout << elements[jTrack] << std::endl
1245 <<
"is probably a fake (2) --> lock the track"
1249 if ( rejectFake )
continue;
1255 if ( !thatIsAMuon ) {
1257 std::cout <<
"Track momentum increased from " << trackMomentum <<
" GeV ";
1258 trackMomentum += trackRef->p();
1260 std::cout <<
"to " << trackMomentum <<
" GeV." << std::endl;
1261 std::cout <<
"with " << elements[jTrack] << std::endl;
1265 totalEcal =
std::max(totalEcal, 0.);
1273 kTrack.push_back(jTrack);
1274 active[jTrack] =
false;
1276 if ( thatIsAMuon ) {
1277 (*pfCandidates_)[tmpi.back()].setEcalEnergy(clusterRef->energy(),
1279 (*pfCandidates_)[tmpi.back()].setHcalEnergy( 0., 0. );
1280 (*pfCandidates_)[tmpi.back()].setHoEnergy( 0., 0. );
1281 (*pfCandidates_)[tmpi.back()].setPs1Energy( 0 );
1282 (*pfCandidates_)[tmpi.back()].setPs2Energy( 0 );
1283 (*pfCandidates_)[tmpi.back()].addElementInBlock( blockref, kTrack.back() );
1288 if (
debug_ )
std::cout <<
"Loop over all associated ECAL clusters" << std::endl;
1290 for(IE ie = ecalElems.begin(); ie != ecalElems.end(); ++ie ) {
1292 unsigned index = ie->second;
1298 if (
debug_ && ! active[index] )
std::cout <<
"is not active - ignore " << std::endl;
1299 if ( ! active[index] )
continue;
1303 block.associatedElements( index, linkData,
1308 for (
unsigned ic=0; ic<kTrack.size();++ic) {
1309 if ( sortedTracks.begin()->second == kTrack[ic] ) {
1314 if (
debug_ && skip )
std::cout <<
"is closer to another track - ignore " << std::endl;
1315 if ( skip )
continue;
1323 double dist = ie->first;
1324 std::cout <<
"Ecal cluster with raw energy = " << clusterRef->energy()
1325 <<
" linked with distance = " << dist << std::endl;
1340 vector<double> ps1Ene(1,static_cast<double>(0.));
1342 vector<double> ps2Ene(1,static_cast<double>(0.));
1345 double ecalEnergy = clusterRef->correctedEnergy();
1347 std::cout <<
"Corrected ECAL(+PS) energy = " << ecalEnergy << std::endl;
1351 totalEcal += ecalEnergy;
1352 double previousCalibEcal = calibEcal;
1353 double previousSlopeEcal = slopeEcal;
1354 calibEcal =
std::max(totalEcal,0.);
1356 calibration_->energyEmHad(trackMomentum,calibEcal,calibHcal,
1357 clusterRef->positionREP().Eta(),
1358 clusterRef->positionREP().Phi());
1359 if ( totalEcal > 0.) slopeEcal = calibEcal/totalEcal;
1362 std::cout <<
"The total calibrated energy so far amounts to = " << calibEcal << std::endl;
1366 if ( connectedToEcal && calibEcal - trackMomentum >= 0. ) {
1369 calibEcal = previousCalibEcal;
1370 slopeEcal = previousSlopeEcal;
1371 totalEcal = calibEcal/slopeEcal;
1375 active[
index] =
false;
1378 std::multimap<double, unsigned> assTracks;
1379 block.associatedElements( index, linkData,
1386 (*pfCandidates_)[tmpe].setEcalEnergy( clusterRef->energy(), ecalEnergy );
1387 (*pfCandidates_)[tmpe].setHcalEnergy( 0., 0. );
1388 (*pfCandidates_)[tmpe].setHoEnergy( 0., 0. );
1389 (*pfCandidates_)[tmpe].setPs1Energy( ps1Ene[0] );
1390 (*pfCandidates_)[tmpe].setPs2Energy( ps2Ene[0] );
1391 (*pfCandidates_)[tmpe].addElementInBlock( blockref, index );
1393 if(assTracks.size()) {
1394 (*pfCandidates_)[tmpe].addElementInBlock( blockref, assTracks.begin()->second );
1405 connectedToEcal =
true;
1407 active[
index] =
false;
1408 for (
unsigned ic=0; ic<tmpi.size();++ic)
1409 (*
pfCandidates_)[tmpi[ic]].addElementInBlock( blockref, iEcal );
1414 bool bNeutralProduced =
false;
1417 if( connectedToEcal ) {
1459 neutralEnergy /= slopeEcal;
1461 (*pfCandidates_)[tmpj].setEcalEnergy( pivotalRef->energy(), neutralEnergy );
1462 (*pfCandidates_)[tmpj].setHcalEnergy( 0., 0. );
1463 (*pfCandidates_)[tmpj].setHoEnergy( 0., 0. );
1464 (*pfCandidates_)[tmpj].setPs1Energy( 0. );
1465 (*pfCandidates_)[tmpj].setPs2Energy( 0. );
1466 (*pfCandidates_)[tmpj].addElementInBlock(blockref, iEcal);
1467 bNeutralProduced =
true;
1468 for (
unsigned ic=0; ic<kTrack.size();++ic)
1469 (*
pfCandidates_)[tmpj].addElementInBlock( blockref, kTrack[ic] );
1473 for (
unsigned ic=0; ic<tmpi.size();++ic) {
1479 double ecalCal = bNeutralProduced ?
1480 (calibEcal-neutralEnergy*slopeEcal)*fraction : calibEcal*fraction;
1481 double ecalRaw = totalEcal*
fraction;
1483 if (
debug_)
cout <<
"The fraction after photon supression is " << fraction <<
" calibrated ecal = " << ecalCal << endl;
1485 (*pfCandidates_)[tmpi[ic]].setEcalEnergy( ecalRaw, ecalCal );
1486 (*pfCandidates_)[tmpi[ic]].setHcalEnergy( 0., 0. );
1487 (*pfCandidates_)[tmpi[ic]].setHoEnergy( 0., 0. );
1488 (*pfCandidates_)[tmpi[ic]].setPs1Energy( 0 );
1489 (*pfCandidates_)[tmpi[ic]].setPs2Energy( 0 );
1490 (*pfCandidates_)[tmpi[ic]].addElementInBlock( blockref, kTrack[ic] );
1496 for (
unsigned ic=0; ic<tmpi.size();++ic) {
1497 const PFCandidate& pfc = (*pfCandidates_)[tmpi[ic]];
1499 if ( eleInBlocks.size() == 0 ) {
1500 if (
debug_ )
std::cout <<
"Single track / Fill element in block! " << std::endl;
1501 (*pfCandidates_)[tmpi[ic]].addElementInBlock( blockref, kTrack[ic] );
1510 for(IE ie = hcalElems.begin(); ie != hcalElems.end(); ++ie ) {
1512 unsigned index = ie->second;
1518 cout<<
"\telement "<<elements[
index]<<
" linked with distance "<< dist <<endl;
1527 cout<<
"\t\tclosest hcal cluster, doing nothing"<<endl;
1537 cout<<
"\t\tsecondary hcal cluster. unlinking"<<endl;
1538 block.setLink( iTrack, index, -1., linkData,
1539 PFBlock::LINKTEST_RECHIT );
1547 if( !(hfEmIs.empty() && hfHadIs.empty() ) ) {
1550 assert( hfEmIs.size() + hfHadIs.size() == elements.
size() );
1552 if( elements.
size() == 1 ) {
1555 double energyHF = 0.;
1556 double uncalibratedenergyHF = 0.;
1558 switch( clusterRef->layer() ) {
1561 energyHF = clusterRef->energy();
1562 uncalibratedenergyHF = energyHF;
1565 clusterRef->positionREP().Eta(),
1566 clusterRef->positionREP().Phi());
1569 (*pfCandidates_)[tmpi].setEcalEnergy( uncalibratedenergyHF, energyHF );
1570 (*pfCandidates_)[tmpi].setHcalEnergy( 0., 0.);
1571 (*pfCandidates_)[tmpi].setHoEnergy( 0., 0.);
1572 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
1573 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
1574 (*pfCandidates_)[tmpi].addElementInBlock( blockref, hfEmIs[0] );
1579 energyHF = clusterRef->energy();
1580 uncalibratedenergyHF = energyHF;
1583 clusterRef->positionREP().Eta(),
1584 clusterRef->positionREP().Phi());
1587 (*pfCandidates_)[tmpi].setHcalEnergy( uncalibratedenergyHF, energyHF );
1588 (*pfCandidates_)[tmpi].setEcalEnergy( 0., 0.);
1589 (*pfCandidates_)[tmpi].setHoEnergy( 0., 0.);
1590 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
1591 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
1592 (*pfCandidates_)[tmpi].addElementInBlock( blockref, hfHadIs[0] );
1599 else if( elements.
size() == 2 ) {
1608 cerr<<
"Error: 2 elements, but not 1 HFEM and 1 HFHAD"<<endl;
1615 double energyHfEm = cem->energy();
1616 double energyHfHad = chad->energy();
1617 double uncalibratedenergyHFEm = energyHfEm;
1618 double uncalibratedenergyHFHad = energyHfHad;
1623 c0->positionREP().Eta(),
1624 c0->positionREP().Phi());
1626 uncalibratedenergyHFHad,
1627 c1->positionREP().Eta(),
1628 c1->positionREP().Phi());
1631 (*pfCandidates_)[tmpi].setEcalEnergy( uncalibratedenergyHFEm, energyHfEm );
1632 (*pfCandidates_)[tmpi].setHcalEnergy( uncalibratedenergyHFHad, energyHfHad);
1633 (*pfCandidates_)[tmpi].setHoEnergy( 0., 0.);
1634 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
1635 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
1636 (*pfCandidates_)[tmpi].addElementInBlock( blockref, hfEmIs[0] );
1637 (*pfCandidates_)[tmpi].addElementInBlock( blockref, hfHadIs[0] );
1643 cerr<<
"Warning: HF, but n elem different from 1 or 2"<<endl;
1654 cout<<endl<<
"--------------- loop hcal ---------------------"<<endl;
1663 for(
unsigned i=0;
i<hcalIs.size();
i++) {
1665 unsigned iHcal= hcalIs[
i];
1670 if(
debug_)
cout<<endl<<elements[iHcal]<<endl;
1676 std::multimap<double, unsigned> sortedTracks;
1677 block.associatedElements( iHcal, linkData,
1682 std::multimap< unsigned, std::pair<double, unsigned> > associatedEcals;
1684 std::map< unsigned, std::pair<double, double> > associatedPSs;
1686 std::multimap<double, std::pair<unsigned,bool> > associatedTracks;
1689 std::multimap<double,std::pair<unsigned,::math::XYZVector> > ecalSatellites;
1690 std::pair<unsigned,::math::XYZVector> fakeSatellite = make_pair(iHcal,::
math::XYZVector(0.,0.,0.));
1691 ecalSatellites.insert( make_pair(-1., fakeSatellite) );
1693 std::multimap< unsigned, std::pair<double, unsigned> > associatedHOs;
1695 PFClusterRef hclusterref = elements[iHcal].clusterRef();
1706 if( sortedTracks.empty() ) {
1708 cout<<
"\tno associated tracks, keep for later"<<endl;
1713 active[iHcal] =
false;
1721 if(
debug_)
cout<<
"\t"<<sortedTracks.size()<<
" associated tracks:"<<endl;
1723 double totalChargedMomentum = 0;
1724 double sumpError2 = 0.;
1725 double totalHO = 0.;
1726 double totalEcal = 0.;
1727 double totalHcal = hclusterref->energy();
1728 vector<double> hcalP;
1729 vector<double> hcalDP;
1730 vector<unsigned> tkIs;
1731 double maxDPovP = -9999.;
1734 vector< unsigned > chargedHadronsIndices;
1735 vector< unsigned > chargedHadronsInBlock;
1736 double mergedNeutralHadronEnergy = 0;
1737 double mergedPhotonEnergy = 0;
1738 double muonHCALEnergy = 0.;
1739 double muonECALEnergy = 0.;
1740 double muonHCALError = 0.;
1741 double muonECALError = 0.;
1742 unsigned nMuons = 0;
1746 std::vector<std::pair<unsigned,::math::XYZVector> >
ecalClusters;
1747 double sumEcalClusters=0;
1749 hclusterref->position().Y(),
1750 hclusterref->position().Z());
1751 hadronDirection = hadronDirection.Unit();
1755 for(IE ie = sortedTracks.begin(); ie != sortedTracks.end(); ++ie ) {
1757 unsigned iTrack = ie->second;
1760 if ( !active[iTrack] )
continue;
1771 ::math::XYZVector chargedDirection(chargedPosition.X(),chargedPosition.Y(),chargedPosition.Z());
1772 chargedDirection = chargedDirection.Unit();
1775 std::multimap<double, unsigned> sortedEcals;
1776 block.associatedElements( iTrack, linkData,
1781 if(
debug_)
cout<<
"\t\t\tnumber of Ecal elements linked to this track: "
1782 <<sortedEcals.size()<<endl;
1785 std::multimap<double, unsigned> sortedHOs;
1787 block.associatedElements( iTrack, linkData,
1794 cout<<
"PFAlgo : number of HO elements linked to this track: "
1795 <<sortedHOs.size()<<endl;
1803 bool thisIsALooseMuon =
false;
1811 if ( thisIsAMuon ) {
1813 std::cout <<
"\t\tThis track is identified as a muon - remove it from the stack" << std::endl;
1814 std::cout <<
"\t\t" << elements[iTrack] << std::endl;
1822 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iTrack );
1823 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
1829 bool letMuonEatCaloEnergy =
false;
1831 if(thisIsAnIsolatedMuon){
1833 double totalCaloEnergy = totalHcal / 1.30;
1835 if( !sortedEcals.empty() ) {
1836 iEcal = sortedEcals.begin()->second;
1837 PFClusterRef eclusterref = elements[iEcal].clusterRef();
1838 totalCaloEnergy += eclusterref->energy();
1844 if( !sortedHOs.empty() ) {
1845 iHO = sortedHOs.begin()->second;
1847 totalCaloEnergy += eclusterref->energy() / 1.30;
1853 if( (
pfCandidates_->back()).
p() > totalCaloEnergy ) letMuonEatCaloEnergy =
true;
1856 if(letMuonEatCaloEnergy) muonHcal = totalHcal;
1857 double muonEcal =0.;
1859 if( !sortedEcals.empty() ) {
1860 iEcal = sortedEcals.begin()->second;
1861 PFClusterRef eclusterref = elements[iEcal].clusterRef();
1862 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal);
1864 if(letMuonEatCaloEnergy) muonEcal = eclusterref->energy();
1866 if ( eclusterref->energy() - muonEcal < 0.2 ) active[iEcal] =
false;
1867 (*pfCandidates_)[tmpi].setEcalEnergy(eclusterref->energy(), muonEcal);
1872 if( !sortedHOs.empty() ) {
1873 iHO = sortedHOs.begin()->second;
1874 PFClusterRef hoclusterref = elements[iHO].clusterRef();
1875 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHO);
1877 if(letMuonEatCaloEnergy) muonHO = hoclusterref->energy();
1879 if ( hoclusterref->energy() - muonHO < 0.2 ) active[iHO] =
false;
1880 (*pfCandidates_)[tmpi].setHcalEnergy(totalHcal, muonHcal);
1881 (*pfCandidates_)[tmpi].setHoEnergy(hoclusterref->energy(), muonHO);
1884 (*pfCandidates_)[tmpi].setHcalEnergy(totalHcal, muonHcal);
1887 if(letMuonEatCaloEnergy){
1888 muonHCALEnergy += totalHcal;
1889 if (
useHO_) muonHCALEnergy +=muonHO;
1890 muonHCALError += 0.;
1891 muonECALEnergy += muonEcal;
1892 muonECALError += 0.;
1893 photonAtECAL -= muonEcal*chargedDirection;
1894 hadronAtECAL -= totalHcal*chargedDirection;
1895 if ( !sortedEcals.empty() ) active[iEcal] =
false;
1896 active[iHcal] =
false;
1897 if (
useHO_ && !sortedHOs.empty() ) active[iHO] =
false;
1903 if ( muonHO > 0. ) {
1910 photonAtECAL -= muonECAL_[0]*chargedDirection;
1911 hadronAtECAL -= muonHCAL_[0]*chargedDirection;
1915 active[iTrack] =
false;
1922 if(
debug_)
cout<<
"\t\t"<<elements[iTrack]<<endl;
1930 if ( thisIsALooseMuon && !thisIsAMuon ) nMuons += 1;
1935 double Dpt = trackRef->ptError();
1936 double blowError = 1.;
1937 switch (trackRef->algo()) {
1938 case TrackBase::ctf:
1940 case TrackBase::lowPtTripletStep:
1941 case TrackBase::pixelPairStep:
1944 case TrackBase::jetCoreRegionalStep:
1945 case TrackBase::muonSeededStepInOut:
1946 case TrackBase::muonSeededStepOutIn:
1952 case TrackBase::tobTecStep:
1972 bool isPrimaryOrSecondary =
isFromSecInt(elements[iTrack],
"all");
1974 if ( isPrimaryOrSecondary ) blowError = 1.;
1976 std::pair<unsigned,bool> tkmuon = make_pair(iTrack,thisIsALooseMuon);
1977 associatedTracks.insert( make_pair(-Dpt*blowError, tkmuon) );
1980 double Dp = trackRef->qoverpError()*trackMomentum*
trackMomentum;
1981 sumpError2 += Dp*Dp;
1983 bool connectedToEcal =
false;
1984 if( !sortedEcals.empty() )
1988 for ( IE iec=sortedEcals.begin();
1989 iec!=sortedEcals.end(); ++iec ) {
1991 unsigned iEcal = iec->second;
1992 double dist = iec->first;
1995 if( !active[iEcal] ) {
2003 PFClusterRef eclusterref = elements[iEcal].clusterRef();
2007 std::multimap<double, unsigned> sortedTracksEcal;
2008 block.associatedElements( iEcal, linkData,
2012 unsigned jTrack = sortedTracksEcal.begin()->second;
2013 if ( jTrack != iTrack )
continue;
2017 double distEcal = block.dist(jTrack,iEcal,linkData,
2024 float ecalEnergyCalibrated = eclusterref->correctedEnergy();
2026 eclusterref->position().Y(),
2027 eclusterref->position().Z());
2028 photonDirection = photonDirection.Unit();
2030 if ( !connectedToEcal ) {
2033 <<elements[iEcal]<<endl;
2035 connectedToEcal =
true;
2039 std::pair<unsigned,::math::XYZVector> satellite =
2040 make_pair(iEcal,ecalEnergyCalibrated*photonDirection);
2041 ecalSatellites.insert( make_pair(-1., satellite) );
2045 std::pair<unsigned,::math::XYZVector> satellite =
2046 make_pair(iEcal,ecalEnergyCalibrated*photonDirection);
2047 ecalSatellites.insert( make_pair(dist, satellite) );
2051 std::pair<double, unsigned> associatedEcal
2052 = make_pair( distEcal, iEcal );
2053 associatedEcals.insert( make_pair(iTrack, associatedEcal) );
2058 if(
useHO_ && !sortedHOs.empty() )
2062 for ( IE ieho=sortedHOs.begin(); ieho!=sortedHOs.end(); ++ieho ) {
2064 unsigned iHO = ieho->second;
2065 double distHO = ieho->first;
2068 if( !active[iHO] ) {
2075 assert( type == PFBlockElement::HO );
2076 PFClusterRef hoclusterref = elements[iHO].clusterRef();
2080 std::multimap<double, unsigned> sortedTracksHO;
2081 block.associatedElements( iHO, linkData,
2085 unsigned jTrack = sortedTracksHO.begin()->second;
2086 if ( jTrack != iTrack )
continue;
2094 totalHO += hoclusterref->energy();
2095 active[iHO] =
false;
2097 std::pair<double, unsigned> associatedHO
2098 = make_pair( distHO, iHO );
2099 associatedHOs.insert( make_pair(iTrack, associatedHO) );
2108 totalHcal += totalHO;
2112 double caloEnergy = 0.;
2113 double slopeEcal = 1.0;
2114 double calibEcal = 0.;
2115 double calibHcal = 0.;
2116 hadronDirection = hadronAtECAL.Unit();
2120 Caloresolution *= totalChargedMomentum;
2122 Caloresolution =
std::sqrt(Caloresolution*Caloresolution + muonHCALError + muonECALError);
2123 totalEcal -=
std::min(totalEcal,muonECALEnergy);
2124 totalHcal -=
std::min(totalHcal,muonHCALEnergy);
2132 for ( IS is = ecalSatellites.begin(); is != ecalSatellites.end(); ++is ) {
2135 double previousCalibEcal = calibEcal;
2136 double previousCalibHcal = calibHcal;
2137 double previousCaloEnergy = caloEnergy;
2138 double previousSlopeEcal = slopeEcal;
2141 totalEcal +=
sqrt(is->second.second.Mag2());
2142 photonAtECAL += is->second.second;
2143 calibEcal =
std::max(0.,totalEcal);
2144 calibHcal =
std::max(0.,totalHcal);
2145 hadronAtECAL = calibHcal * hadronDirection;
2147 calibration_->energyEmHad(totalChargedMomentum,calibEcal,calibHcal,
2148 hclusterref->positionREP().Eta(),
2149 hclusterref->positionREP().Phi());
2150 caloEnergy = calibEcal+calibHcal;
2151 if ( totalEcal > 0.) slopeEcal = calibEcal/totalEcal;
2153 hadronAtECAL = calibHcal * hadronDirection;
2157 if ( is->first < 0. || caloEnergy - totalChargedMomentum <= 0. ) {
2158 if(
debug_)
cout<<
"\t\t\tactive, adding "<<is->second.second
2159 <<
" to ECAL energy, and locking"<<endl;
2160 active[is->second.first] =
false;
2161 double clusterEnergy=
sqrt(is->second.second.Mag2());
2162 if(clusterEnergy>50) {
2163 ecalClusters.push_back(is->second);
2164 sumEcalClusters+=clusterEnergy;
2171 totalEcal -=
sqrt(is->second.second.Mag2());
2172 photonAtECAL -= is->second.second;
2173 calibEcal = previousCalibEcal;
2174 calibHcal = previousCalibHcal;
2175 hadronAtECAL = previousHadronAtECAL;
2176 slopeEcal = previousSlopeEcal;
2177 caloEnergy = previousCaloEnergy;
2200 if ( totalChargedMomentum - caloEnergy >
nSigmaTRACK_*Caloresolution ) {
2215 for ( IT it = associatedTracks.begin(); it != associatedTracks.end(); ++it ) {
2216 unsigned iTrack = it->second.first;
2218 if ( !active[iTrack] )
continue;
2220 if ( !it->second.second )
continue;
2222 double trackMomentum = elements[it->second.first].trackRef()->p();
2225 std::multimap<double, unsigned> sortedEcals;
2226 block.associatedElements( iTrack, linkData,
2230 std::multimap<double, unsigned> sortedHOs;
2231 block.associatedElements( iTrack, linkData,
2239 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iTrack );
2240 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
2243 (*pfCandidates_)[tmpi].setHcalEnergy(totalHcal,muonHcal);
2244 if( !sortedEcals.empty() ) {
2245 unsigned iEcal = sortedEcals.begin()->second;
2246 PFClusterRef eclusterref = elements[iEcal].clusterRef();
2247 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal);
2249 (*pfCandidates_)[tmpi].setEcalEnergy(eclusterref->energy(),muonEcal);
2251 if(
useHO_ && !sortedHOs.empty() ) {
2252 unsigned iHO = sortedHOs.begin()->second;
2253 PFClusterRef hoclusterref = elements[iHO].clusterRef();
2254 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHO);
2256 (*pfCandidates_)[tmpi].setHcalEnergy(
max(totalHcal-totalHO,0.0),muonHcal);
2257 (*pfCandidates_)[tmpi].setHoEnergy(hoclusterref->energy(),muonHO);
2262 ::math::XYZVector chargedDirection(chargedPosition.X(), chargedPosition.Y(), chargedPosition.Z());
2263 chargedDirection = chargedDirection.Unit();
2266 if ( totalEcal > 0. )
2268 if ( totalHcal > 0. )
2273 if ( totalHcal >
muonHCAL_[0] ) hadronAtECAL -=
muonHCAL_[0]*calibHcal/totalHcal * chargedDirection;
2274 caloEnergy = calibEcal+calibHcal;
2277 if ( muonHO > 0. ) {
2280 if ( totalHcal > 0. ) {
2281 calibHcal -=
std::min(calibHcal,muonHO_[0]*calibHcal/totalHcal);
2282 totalHcal -=
std::min(totalHcal,muonHO_[0]);
2287 active[iTrack] =
false;
2294 Caloresolution *= totalChargedMomentum;
2295 Caloresolution =
std::sqrt(Caloresolution*Caloresolution + muonHCALError + muonECALError);
2313 unsigned corrTrack = 10000000;
2314 double corrFact = 1.;
2317 totalChargedMomentum - caloEnergy >
nSigmaTRACK_*Caloresolution) {
2319 for ( IT it = associatedTracks.begin(); it != associatedTracks.end(); ++it ) {
2320 unsigned iTrack = it->second.first;
2322 if ( !active[iTrack] )
continue;
2323 const reco::TrackRef& trackref = elements[it->second.first].trackRef();
2325 double dptRel = fabs(it->first)/trackref->pt()*100;
2326 bool isSecondary =
isFromSecInt(elements[iTrack],
"secondary");
2327 bool isPrimary =
isFromSecInt(elements[iTrack],
"primary");
2331 if ( fabs(it->first) <
ptError_ )
break;
2333 double wouldBeTotalChargedMomentum =
2334 totalChargedMomentum - trackref->p();
2338 if ( wouldBeTotalChargedMomentum > caloEnergy ) {
2340 if (
debug_ && isSecondary) {
2341 cout <<
"In bad track rejection step dptRel = " << dptRel <<
" dptRel_DispVtx_ = " <<
dptRel_DispVtx_ << endl;
2342 cout <<
"The calo energy would be still smaller even without this track but it is attached to a NI"<< endl;
2347 active[iTrack] =
false;
2348 totalChargedMomentum = wouldBeTotalChargedMomentum;
2350 std::cout <<
"\tElement " << elements[iTrack]
2351 <<
" rejected (Dpt = " << -it->first
2352 <<
" GeV/c, algo = " << trackref->algo() <<
")" << std::endl;
2355 if(isPrimary)
break;
2357 corrFact = (caloEnergy - wouldBeTotalChargedMomentum)/elements[it->second.first].trackRef()->p();
2358 if ( trackref->p()*corrFact < 0.05 ) {
2360 active[iTrack] =
false;
2362 totalChargedMomentum -= trackref->p()*(1.-corrFact);
2364 std::cout <<
"\tElement " << elements[iTrack]
2365 <<
" (Dpt = " << -it->first
2366 <<
" GeV/c, algo = " << trackref->algo()
2367 <<
") rescaled by " << corrFact
2368 <<
" Now the total charged momentum is " << totalChargedMomentum << endl;
2376 Caloresolution *= totalChargedMomentum;
2377 Caloresolution =
std::sqrt(Caloresolution*Caloresolution + muonHCALError + muonECALError);
2383 sortedTracks.size() > 1 &&
2384 totalChargedMomentum - caloEnergy >
nSigmaTRACK_*Caloresolution ) {
2385 for ( IT it = associatedTracks.begin(); it != associatedTracks.end(); ++it ) {
2386 unsigned iTrack = it->second.first;
2388 if ( !active[iTrack] )
continue;
2390 double dptRel = fabs(it->first)/trackref->pt()*100;
2391 bool isPrimaryOrSecondary =
isFromSecInt(elements[iTrack],
"all");
2398 switch (trackref->algo()) {
2399 case TrackBase::ctf:
2401 case TrackBase::lowPtTripletStep:
2402 case TrackBase::pixelPairStep:
2405 case TrackBase::jetCoreRegionalStep:
2406 case TrackBase::muonSeededStepInOut:
2407 case TrackBase::muonSeededStepOutIn:
2410 case TrackBase::tobTecStep:
2411 active[iTrack] =
false;
2412 totalChargedMomentum -= trackref->p();
2415 std::cout <<
"\tElement " << elements[iTrack]
2416 <<
" rejected (Dpt = " << -it->first
2417 <<
" GeV/c, algo = " << trackref->algo() <<
")" << std::endl;
2434 Caloresolution *= totalChargedMomentum;
2435 Caloresolution =
std::sqrt(Caloresolution*Caloresolution + muonHCALError + muonECALError);
2439 for ( IT it = associatedTracks.begin(); it != associatedTracks.end(); ++it ) {
2440 unsigned iTrack = it->second.first;
2441 if ( !active[iTrack] )
continue;
2444 double Dp = trackRef->qoverpError()*trackMomentum*
trackMomentum;
2448 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iTrack );
2449 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
2450 std::pair<II,II> myEcals = associatedEcals.equal_range(iTrack);
2451 for (II
ii=myEcals.first;
ii!=myEcals.second; ++
ii ) {
2452 unsigned iEcal =
ii->second.second;
2453 if ( active[iEcal] )
continue;
2454 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal );
2458 std::pair<II,II> myHOs = associatedHOs.equal_range(iTrack);
2459 for (II
ii=myHOs.first;
ii!=myHOs.second; ++
ii ) {
2460 unsigned iHO =
ii->second.second;
2461 if ( active[iHO] )
continue;
2462 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHO );
2466 if ( iTrack == corrTrack ) {
2467 (*pfCandidates_)[tmpi].rescaleMomentum(corrFact);
2468 trackMomentum *= corrFact;
2470 chargedHadronsIndices.push_back( tmpi );
2471 chargedHadronsInBlock.push_back( iTrack );
2472 active[iTrack] =
false;
2473 hcalP.push_back(trackMomentum);
2474 hcalDP.push_back(Dp);
2475 if (Dp/trackMomentum > maxDPovP) maxDPovP = Dp/
trackMomentum;
2476 sumpError2 += Dp*Dp;
2480 double TotalError =
sqrt(sumpError2 + Caloresolution*Caloresolution);
2483 cout<<
"\tCompare Calo Energy to total charged momentum "<<endl;
2484 cout<<
"\t\tsum p = "<<totalChargedMomentum<<
" +- "<<
sqrt(sumpError2)<<endl;
2485 cout<<
"\t\tsum ecal = "<<totalEcal<<endl;
2486 cout<<
"\t\tsum hcal = "<<totalHcal<<endl;
2487 cout<<
"\t\t => Calo Energy = "<<caloEnergy<<
" +- "<<Caloresolution<<endl;
2488 cout<<
"\t\t => Calo Energy- total charged momentum = "
2489 <<caloEnergy-totalChargedMomentum<<
" +- "<<TotalError<<endl;
2496 double nsigma =
nSigmaHCAL(totalChargedMomentum,hclusterref->positionREP().Eta());
2498 if (
abs(totalChargedMomentum-caloEnergy)<nsigma*TotalError ) {
2504 cout<<
"\t\tcase 1: COMPATIBLE "
2505 <<
"|Calo Energy- total charged momentum| = "
2506 <<
abs(caloEnergy-totalChargedMomentum)
2507 <<
" < "<<nsigma<<
" x "<<TotalError<<endl;
2508 if (maxDPovP < 0.1 )
2509 cout<<
"\t\t\tmax DP/P = "<< maxDPovP
2510 <<
" less than 0.1: do nothing "<<endl;
2512 cout<<
"\t\t\tmax DP/P = "<< maxDPovP
2513 <<
" > 0.1: take weighted averages "<<endl;
2517 if (maxDPovP > 0.1) {
2521 int nrows = chargedHadronsIndices.size();
2522 TMatrixTSym<double>
a (nrows);
2524 TVectorD
check(nrows);
2525 double sigma2E = Caloresolution*Caloresolution;
2526 for(
int i=0;
i<nrows;
i++) {
2527 double sigma2i = hcalDP[
i]*hcalDP[
i];
2529 cout<<
"\t\t\ttrack associated to hcal "<<
i
2530 <<
" P = "<<hcalP[
i]<<
" +- "
2533 a(
i,
i) = 1./sigma2i + 1./sigma2E;
2534 b(
i) = hcalP[
i]/sigma2i + caloEnergy/sigma2E;
2535 for(
int j=0;
j<nrows;
j++) {
2537 a(
i,
j) = 1./sigma2E;
2548 TDecompChol decomp(a);
2550 TVectorD
x = decomp.Solve(b, ok);
2554 for (
int i=0;
i<nrows;
i++){
2556 unsigned ich = chargedHadronsIndices[
i];
2557 double rescaleFactor =
x(
i)/hcalP[
i];
2558 (*pfCandidates_)[ich].rescaleMomentum( rescaleFactor );
2561 cout<<
"\t\t\told p "<<hcalP[
i]
2563 <<
" rescale "<<rescaleFactor<<endl;
2568 cerr<<
"not ok!"<<endl;
2575 else if( caloEnergy > totalChargedMomentum ) {
2594 double eNeutralHadron = caloEnergy - totalChargedMomentum;
2595 double ePhoton = (caloEnergy - totalChargedMomentum) / slopeEcal;
2598 if(!sortedTracks.empty() ){
2599 cout<<
"\t\tcase 2: NEUTRAL DETECTION "
2600 <<caloEnergy<<
" > "<<nsigma<<
"x"<<TotalError
2601 <<
" + "<<totalChargedMomentum<<endl;
2602 cout<<
"\t\tneutral activity detected: "<<endl
2603 <<
"\t\t\t photon = "<<ePhoton<<endl
2604 <<
"\t\t\tor neutral hadron = "<<eNeutralHadron<<endl;
2606 cout<<
"\t\tphoton or hadron ?"<<endl;}
2608 if(sortedTracks.empty() )
2609 cout<<
"\t\tno track -> hadron "<<endl;
2611 cout<<
"\t\t"<<sortedTracks.size()
2612 <<
"tracks -> check if the excess is photonic or hadronic"<<endl;
2616 double ratioMax = 0.;
2618 unsigned maxiEcal= 9999;
2622 for(IE ie = sortedTracks.begin(); ie != sortedTracks.end(); ++ie ) {
2624 unsigned iTrack = ie->second;
2632 II iae = associatedEcals.find(iTrack);
2634 if( iae == associatedEcals.end() )
continue;
2637 unsigned iEcal = iae->second.second;
2645 double pTrack = trackRef->p();
2646 double eECAL = clusterRef->energy();
2647 double eECALOverpTrack = eECAL / pTrack;
2649 if ( eECALOverpTrack > ratioMax ) {
2650 ratioMax = eECALOverpTrack;
2651 maxEcalRef = clusterRef;
2657 std::vector<reco::PFClusterRef> pivotalClusterRef;
2658 std::vector<unsigned> iPivotal;
2659 std::vector<double> particleEnergy, ecalEnergy, hcalEnergy, rawecalEnergy, rawhcalEnergy;
2660 std::vector<::math::XYZVector> particleDirection;
2664 if ( ePhoton < totalEcal || eNeutralHadron-calibEcal < 1E-10 ) {
2665 if ( !maxEcalRef.
isNull() ) {
2667 mergedPhotonEnergy = ePhoton;
2671 if ( !maxEcalRef.
isNull() ) {
2673 mergedPhotonEnergy = totalEcal;
2676 mergedNeutralHadronEnergy = eNeutralHadron-calibEcal;
2679 if ( mergedPhotonEnergy > 0 ) {
2682 if ( ecalClusters.size()<=1 ) {
2683 ecalClusters.clear();
2684 ecalClusters.push_back(make_pair(maxiEcal, photonAtECAL));
2685 sumEcalClusters=
sqrt(photonAtECAL.Mag2());
2687 for(std::vector<std::pair<unsigned,::math::XYZVector> >::const_iterator pae = ecalClusters.begin(); pae != ecalClusters.end(); ++pae ) {
2688 double clusterEnergy=
sqrt(pae->second.Mag2());
2689 particleEnergy.push_back(mergedPhotonEnergy*clusterEnergy/sumEcalClusters);
2690 particleDirection.push_back(pae->second);
2691 ecalEnergy.push_back(mergedPhotonEnergy*clusterEnergy/sumEcalClusters);
2692 hcalEnergy.push_back(0.);
2693 rawecalEnergy.push_back(totalEcal);
2694 rawhcalEnergy.push_back(totalHcal);
2695 pivotalClusterRef.push_back(elements[pae->first].clusterRef());
2696 iPivotal.push_back(pae->first);
2700 if ( mergedNeutralHadronEnergy > 1.0 ) {
2703 if ( ecalClusters.size()<=1 ) {
2704 ecalClusters.clear();
2705 ecalClusters.push_back(make_pair(iHcal, hadronAtECAL));
2706 sumEcalClusters=
sqrt(hadronAtECAL.Mag2());
2708 for(std::vector<std::pair<unsigned,::math::XYZVector> >::const_iterator pae = ecalClusters.begin(); pae != ecalClusters.end(); ++pae ) {
2709 double clusterEnergy=
sqrt(pae->second.Mag2());
2710 particleEnergy.push_back(mergedNeutralHadronEnergy*clusterEnergy/sumEcalClusters);
2711 particleDirection.push_back(pae->second);
2712 ecalEnergy.push_back(0.);
2713 hcalEnergy.push_back(mergedNeutralHadronEnergy*clusterEnergy/sumEcalClusters);
2714 rawecalEnergy.push_back(totalEcal);
2715 rawhcalEnergy.push_back(totalHcal);
2716 pivotalClusterRef.push_back(hclusterref);
2717 iPivotal.push_back(iHcal);
2725 for (
unsigned iPivot=0; iPivot<iPivotal.size(); ++iPivot ) {
2727 if ( particleEnergy[iPivot] < 0. )
2728 std::cout <<
"ALARM = Negative energy ! "
2729 << particleEnergy[iPivot] << std::endl;
2731 bool useDirection =
true;
2733 particleEnergy[iPivot],
2735 particleDirection[iPivot].
X(),
2736 particleDirection[iPivot].Y(),
2737 particleDirection[iPivot].
Z());
2740 (*pfCandidates_)[tmpi].setEcalEnergy( rawecalEnergy[iPivot],ecalEnergy[iPivot] );
2742 (*pfCandidates_)[tmpi].setHcalEnergy( rawhcalEnergy[iPivot],hcalEnergy[iPivot] );
2743 (*pfCandidates_)[tmpi].setHoEnergy(0., 0.);
2745 (*pfCandidates_)[tmpi].setHcalEnergy(
max(rawhcalEnergy[iPivot]-totalHO,0.0),hcalEnergy[iPivot]*(1.-totalHO/rawhcalEnergy[iPivot]));
2746 (*pfCandidates_)[tmpi].setHoEnergy(totalHO, totalHO * hcalEnergy[iPivot]/rawhcalEnergy[iPivot]);
2748 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
2749 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
2750 (*pfCandidates_)[tmpi].set_mva_nothing_gamma( -1. );
2753 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
2754 for (
unsigned ich=0; ich<chargedHadronsInBlock.size(); ++ich) {
2755 unsigned iTrack = chargedHadronsInBlock[ich];
2756 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iTrack );
2762 std::pair<II,II> myEcals = associatedEcals.equal_range(iTrack);
2763 for (II
ii=myEcals.first;
ii!=myEcals.second; ++
ii ) {
2764 unsigned iEcal =
ii->second.second;
2765 if ( active[iEcal] )
continue;
2766 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal );
2778 double totalHcalEnergyCalibrated = calibHcal;
2779 double totalEcalEnergyCalibrated = calibEcal;
2794 totalHcalEnergyCalibrated -= mergedNeutralHadronEnergy;
2796 totalEcalEnergyCalibrated -= mergedPhotonEnergy;
2801 double chargedHadronsTotalEnergy = 0;
2802 for(
unsigned ich=0; ich<chargedHadronsIndices.size(); ++ich ) {
2803 unsigned index = chargedHadronsIndices[ich];
2805 chargedHadronsTotalEnergy += chargedHadron.
energy();
2808 for(
unsigned ich=0; ich<chargedHadronsIndices.size(); ++ich ) {
2809 unsigned index = chargedHadronsIndices[ich];
2811 float fraction = chargedHadron.
energy()/chargedHadronsTotalEnergy;
2814 chargedHadron.
setHcalEnergy( fraction * totalHcal, fraction * totalHcalEnergyCalibrated );
2817 chargedHadron.
setHcalEnergy( fraction *
max(totalHcal-totalHO,0.0), fraction * totalHcalEnergyCalibrated * (1.-totalHO/totalHcal) );
2818 chargedHadron.
setHoEnergy( fraction * totalHO, fraction * totalHO * totalHcalEnergyCalibrated / totalHcal );
2821 chargedHadron.
setEcalEnergy( fraction * totalEcal, fraction * totalEcalEnergyCalibrated );
2825 for ( IS is = ecalSatellites.begin(); is != ecalSatellites.end(); ++is ) {
2828 unsigned iEcal = is->second.first;
2829 if ( !active[iEcal] )
continue;
2834 PFClusterRef eclusterref = elements[iEcal].clusterRef();
2838 active[iEcal] =
false;
2841 std::multimap<double, unsigned> assTracks;
2842 block.associatedElements( iEcal, linkData,
2849 (*pfCandidates_)[tmpi].setEcalEnergy( eclusterref->energy(),
sqrt(is->second.second.Mag2()) );
2850 (*pfCandidates_)[tmpi].setHcalEnergy( 0., 0. );
2851 (*pfCandidates_)[tmpi].setHoEnergy( 0., 0. );
2852 (*pfCandidates_)[tmpi].setPs1Energy( associatedPSs[iEcal].
first );
2853 (*pfCandidates_)[tmpi].setPs2Energy( associatedPSs[iEcal].
second );
2854 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal );
2855 (*pfCandidates_)[tmpi].addElementInBlock( blockref, sortedTracks.begin()->second) ;
2869 <<
"---- loop remaining hcal ------- "<<endl;
2875 for(
unsigned ihcluster=0; ihcluster<hcalIs.size(); ihcluster++) {
2876 unsigned iHcal = hcalIs[ihcluster];
2879 std::vector<unsigned> ecalRefs;
2880 std::vector<unsigned> hoRefs;
2883 cout<<endl<<elements[iHcal]<<
" ";
2886 if( !active[iHcal] ) {
2888 cout<<
"not active"<<endl;
2893 std::multimap<double, unsigned> ecalElems;
2894 block.associatedElements( iHcal, linkData,
2900 float totalEcal = 0.;
2903 for(IE ie = ecalElems.begin(); ie != ecalElems.end(); ++ie ) {
2905 unsigned iEcal = ie->second;
2906 double dist = ie->first;
2911 if( !active[iEcal] )
continue;
2932 std::multimap<double, unsigned> hcalElems;
2933 block.associatedElements( iEcal, linkData,
2938 bool isClosest =
true;
2939 for(IE ih = hcalElems.begin(); ih != hcalElems.end(); ++ih ) {
2941 unsigned jHcal = ih->second;
2942 double distH = ih->first;
2944 if ( !active[jHcal] )
continue;
2946 if ( distH < dist ) {
2953 if (!isClosest)
continue;
2957 cout<<
"\telement "<<elements[iEcal]<<
" linked with dist "<< dist<<endl;
2958 cout<<
"Added to HCAL cluster to form a neutral hadron"<<endl;
2964 double ecalEnergy = eclusterRef->correctedEnergy();
2968 totalEcal += ecalEnergy;
2969 if ( ecalEnergy > ecalMax ) {
2970 ecalMax = ecalEnergy;
2971 eClusterRef = eclusterRef;
2974 ecalRefs.push_back(iEcal);
2975 active[iEcal] =
false;
2981 double totalHO = 0.;
2985 std::multimap<double, unsigned> hoElems;
2986 block.associatedElements( iHcal, linkData,
2996 for(IE ie = hoElems.begin(); ie != hoElems.end(); ++ie ) {
2998 unsigned iHO = ie->second;
2999 double dist = ie->first;
3001 assert( type == PFBlockElement::HO );
3004 if( !active[iHO] )
continue;
3010 std::multimap<double, unsigned> hcalElems;
3011 block.associatedElements( iHO, linkData,
3016 bool isClosest =
true;
3017 for(IE ih = hcalElems.begin(); ih != hcalElems.end(); ++ih ) {
3019 unsigned jHcal = ih->second;
3020 double distH = ih->first;
3022 if ( !active[jHcal] )
continue;
3024 if ( distH < dist ) {
3031 if (!isClosest)
continue;
3034 cout<<
"\telement "<<elements[iHO]<<
" linked with dist "<< dist<<endl;
3035 cout<<
"Added to HCAL cluster to form a neutral hadron"<<endl;
3041 double hoEnergy = hoclusterRef->energy();
3043 totalHO += hoEnergy;
3044 if ( hoEnergy > hoMax ) {
3046 hoClusterRef = hoclusterRef;
3050 hoRefs.push_back(iHO);
3051 active[iHO] =
false;
3057 = elements[iHcal].clusterRef();
3061 double totalHcal = hclusterRef->energy();
3063 if (
useHO_ ) totalHcal += totalHO;
3071 double calibEcal = totalEcal > 0. ? totalEcal : 0.;
3072 double calibHcal =
std::max(0.,totalHcal);
3076 calibEcal = totalEcal;
3079 hclusterRef->positionREP().Eta(),
3080 hclusterRef->positionREP().Phi());
3093 calibEcal+calibHcal );
3096 (*pfCandidates_)[tmpi].setEcalEnergy( totalEcal, calibEcal );
3098 (*pfCandidates_)[tmpi].setHcalEnergy( totalHcal, calibHcal );
3099 (*pfCandidates_)[tmpi].setHoEnergy(0.,0.);
3101 (*pfCandidates_)[tmpi].setHcalEnergy(
max(totalHcal-totalHO,0.0), calibHcal*(1.-totalHO/totalHcal));
3102 (*pfCandidates_)[tmpi].setHoEnergy(totalHO,totalHO*calibHcal/totalHcal);
3104 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
3105 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
3106 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
3107 for (
unsigned iec=0; iec<ecalRefs.size(); ++iec)
3108 (*
pfCandidates_)[tmpi].addElementInBlock( blockref, ecalRefs[iec] );
3109 for (
unsigned iho=0; iho<hoRefs.size(); ++iho)
3110 (*
pfCandidates_)[tmpi].addElementInBlock( blockref, hoRefs[iho] );
3119 if(
debug_)
cout<<endl<<
"---- loop ecal------- "<<endl;
3124 for(
unsigned i=0;
i<ecalIs.size();
i++) {
3125 unsigned iEcal = ecalIs[
i];
3128 cout<<endl<<elements[iEcal]<<
" ";
3130 if( ! active[iEcal] ) {
3132 cout<<
"not active"<<endl;
3139 PFClusterRef clusterref = elements[iEcal].clusterRef();
3142 active[iEcal] =
false;
3144 float ecalEnergy = clusterref->correctedEnergy();
3146 double particleEnergy = ecalEnergy;
3151 (*pfCandidates_)[tmpi].setEcalEnergy( clusterref->energy(),ecalEnergy );
3152 (*pfCandidates_)[tmpi].setHcalEnergy( 0., 0. );
3153 (*pfCandidates_)[tmpi].setHoEnergy( 0., 0. );
3154 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
3155 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
3156 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal );
3175 double px = track.
px();
3176 double py = track.
py();
3177 double pz = track.
pz();
3178 double energy =
sqrt(track.
p()*track.
p() + 0.13957*0.13957);
3190 pfCandidates_->back().setVertexSource( PFCandidate::kTrkVertex );
3203 if ((!isMuon) && isFromDisp) {
3204 double Dpt = trackRef->ptError();
3205 double dptRel = Dpt/trackRef->pt()*100;
3211 cout <<
"Not refitted px = " << px <<
" py = " << py <<
" pz = " << pz <<
" energy = " << energy << endl;
3214 reco::Track trackRefit = vRef->refittedTrack(trackRef);
3219 sqrt(trackRefit.
p()*trackRefit.
p() + 0.13957*0.13957));
3221 cout <<
"Refitted px = " << px <<
" py = " << py <<
" pz = " << pz <<
" energy = " << energy << endl;
3239 double particleEnergy,
3252 if ( useDirection ) {
3253 switch( cluster.
layer() ) {
3256 factor =
std::sqrt(cluster.
position().Perp2()/(particleX*particleX+particleY*particleY));
3262 factor = cluster.
position().Z()/particleZ;
3277 cluster.
position().Y()-vertexPos.Y(),
3278 cluster.
position().Z()-vertexPos.Z());
3280 particleY*factor-vertexPos.Y(),
3281 particleZ*factor-vertexPos.Z() );
3286 clusterPos = useDirection ? particleDirection.Unit() : clusterPos.Unit();
3287 clusterPos *= particleEnergy;
3293 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzM4D<double> >
3294 momentum( clusterPos.X(), clusterPos.Y(), clusterPos.Z(), mass);
3304 switch( cluster.
layer() ) {
3307 particleType = PFCandidate::gamma;
3311 particleType = PFCandidate::h0;
3314 particleType = PFCandidate::h_HF;
3317 particleType = PFCandidate::egamma_HF;
3353 if ( clusterEnergyHCAL < 1. ) clusterEnergyHCAL = 1.;
3355 double resol = fabs(eta) < 1.48 ?
3356 sqrt (1.02*1.02/clusterEnergyHCAL + 0.065*0.065)
3358 sqrt (1.20*1.20/clusterEnergyHCAL + 0.028*0.028);
3366 double nS = fabs(eta) < 1.48 ?
3376 if(!out )
return out;
3378 out<<
"====== Particle Flow Algorithm ======= ";
3385 out<<
"reconstructed particles: "<<endl;
3387 const std::auto_ptr< reco::PFCandidateCollection >&
3390 if(!candidates.get() ) {
3391 out<<
"candidates already transfered"<<endl;
3420 std::vector<bool>& active,
3421 std::vector<double>& psEne) {
3429 std::multimap<double, unsigned> sortedPS;
3430 typedef std::multimap<double, unsigned>::iterator IE;
3432 sortedPS, psElementType,
3436 double totalPS = 0.;
3437 for ( IE ips=sortedPS.begin(); ips!=sortedPS.end(); ++ips ) {
3440 unsigned iPS = ips->second;
3444 if (!active[iPS])
continue;
3447 std::multimap<double, unsigned> sortedECAL;
3452 unsigned jEcal = sortedECAL.begin()->second;
3453 if ( jEcal != iEcal )
continue;
3457 assert( pstype == psElementType );
3458 PFClusterRef psclusterref = elements[iPS].clusterRef();
3460 totalPS += psclusterref->energy();
3461 psEne[0] += psclusterref->energy();
3462 active[iPS] =
false;
3477 bool bPrimary = (order.find(
"primary") != string::npos);
3478 bool bSecondary = (order.find(
"secondary") != string::npos);
3479 bool bAll = (order.find(
"all") != string::npos);
3484 if (bPrimary && isToDisp)
return true;
3485 if (bSecondary && isFromDisp )
return true;
3486 if (bAll && ( isToDisp || isFromDisp ) )
return true;
3515 std::vector<unsigned int> pfCandidatesToBeRemoved;
3522 double met2 = metX*metX+metY*metY;
3524 double significance =
std::sqrt(met2/sumet);
3525 double significanceCor = significance;
3528 double metXCor = metX;
3529 double metYCor = metY;
3530 double sumetCor = sumet;
3531 double met2Cor = met2;
3533 double deltaPhiPt = 100.;
3535 unsigned iCor = 1E9;
3540 double metReduc = -1.;
3554 for(
unsigned j=0;
j<pfCandidatesToBeRemoved.size(); ++
j) {
3555 if (
i == pfCandidatesToBeRemoved[
j] ) skip =
true;
3558 if ( skip )
continue;
3561 deltaPhi = std::acos((metX*pfc.
px()+metY*pfc.
py())/(pfc.
pt()*
std::sqrt(met2)));
3562 deltaPhiPt = deltaPhi*pfc.
pt();
3566 double metXInt = metX - pfc.
px();
3567 double metYInt = metY - pfc.
py();
3568 double sumetInt = sumet - pfc.
pt();
3569 double met2Int = metXInt*metXInt+metYInt*metYInt;
3570 if ( met2Int < met2Cor ) {
3573 metReduc = (met2-met2Int)/met2Int;
3575 sumetCor = sumetInt;
3576 significanceCor =
std::sqrt(met2Cor/sumetCor);
3583 pfCandidatesToBeRemoved.push_back(iCor);
3597 std::cout <<
"Significance reduction = " << significance <<
" -> "
3598 << significanceCor <<
" = " << significanceCor - significance
3600 for(
unsigned j=0;
j<pfCandidatesToBeRemoved.size(); ++
j) {
3601 std::cout <<
"Removed : " << (*pfCandidates_)[pfCandidatesToBeRemoved[
j]] << std::endl;
3603 (*pfCandidates_)[pfCandidatesToBeRemoved[
j]].rescaleMomentum(1E-6);
3617 if ( !cleanedHits.size() )
return;
3623 std::vector<unsigned int> hitsToBeAdded;
3630 double met2 = metX*metX+metY*metY;
3631 double met2_Original = met2;
3635 double metXCor = metX;
3636 double metYCor = metY;
3637 double sumetCor = sumet;
3638 double met2Cor = met2;
3640 unsigned iCor = 1E9;
3645 double metReduc = -1.;
3647 for(
unsigned i=0;
i<cleanedHits.size(); ++
i) {
3656 for(
unsigned j=0;
j<hitsToBeAdded.size(); ++
j) {
3657 if (
i == hitsToBeAdded[
j] ) skip =
true;
3660 if ( skip )
continue;
3663 double metXInt = metX + px;
3664 double metYInt = metY + py;
3665 double sumetInt = sumet +
pt;
3666 double met2Int = metXInt*metXInt+metYInt*metYInt;
3669 if ( met2Int < met2Cor ) {
3672 metReduc = (met2-met2Int)/met2Int;
3674 sumetCor = sumetInt;
3683 hitsToBeAdded.push_back(iCor);
3697 std::cout << hitsToBeAdded.size() <<
" hits were re-added " << std::endl;
3701 std::cout <<
"Added after cleaning check : " << std::endl;
3703 for(
unsigned j=0;
j<hitsToBeAdded.size(); ++
j) {
3723 for(
unsigned ic=0;ic<
size;++ic) {
3732 (*pfCandidates_)[ic].setPFElectronExtraRef(theRef);
3744 (*pfCandidates_)[ic].set_mva_e_pi(it->mvaVariable(PFCandidateElectronExtra::MVA_MVA));
3746 (*pfCandidates_)[ic].setPFElectronExtraRef(theRef);
3747 (*pfCandidates_)[ic].setGsfTrackRef(it->gsfTrackRef());
3755 for(
unsigned ic=0;ic<
size;++ic) {
3763 (*pfElectronCandidates_)[ic].setPFElectronExtraRef(theRef);
3774 for(
unsigned ic=0;ic<
size;++ic) {
3779 for(
unsigned pcextra=0;pcextra<sizePhExtra;++pcextra) {
3782 (*pfCandidates_)[ic].setPFPhotonExtraRef(theRef);
PFLayer::Layer layer() const
cluster layer, see PFLayer.h in this directory
const double Z[kNumberCalorimeter]
tuple sumPtTrackIsoSlopeForPhoton
tuple useEGammaSupercluster
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
const reco::TrackRef & trackRef() const
std::vector< double > muonHCAL_
Variables for muons and fakes.
algo_(conf.existsAs< bool >("Correct")?conf.getParameter< bool >("Correct"):true, conf.getParameter< double >("e9e25Cut"), conf.getParameter< double >("intercept2DCut"), conf.existsAs< bool >("intercept2DSlope")?conf.getParameter< double >("intercept2DSlope"):defaultSlope2D_, conf.getParameter< std::vector< double > >("e1e9Cut"), conf.getParameter< std::vector< double > >("eCOREe9Cut"), conf.getParameter< std::vector< double > >("eSeLCut"), hfvars_)
ParticleType
particle types
bool isNonnull() const
Checks for non-null.
void setPFMuonAndFakeParameters(const edm::ParameterSet &pset)
void addMissingMuons(edm::Handle< reco::MuonCollection >, reco::PFCandidateCollection *cands)
double sumEtEcalIsoForEgammaSC_endcap_
std::auto_ptr< reco::PFCandidateCollection > pfPhotonCandidates_
the unfiltered photon collection
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.
edm::Ref< PFCandidatePhotonExtraCollection > PFCandidatePhotonExtraRef
persistent reference to a PFCandidatePhotonExtra
double coneEcalIsoForEgammaSC_
static bool isMuon(const reco::PFBlockElement &elt)
const std::vector< reco::PFCandidate > & getAllElectronCandidates()
virtual void setCharge(Charge q)
set electric charge
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)
double y() const
y coordinate
bool useProtectionsForJetMET_
double coneTrackIsoForEgammaSC_
void setParameters(const edm::ParameterSet &)
double nSigmaHCAL_
number of sigma to judge energy excess in HCAL
std::map< unsigned int, Link > LinkData
bool isElectronSafeForJetMET(const reco::GsfElectron &, const reco::PFCandidate &, const reco::Vertex &, bool lockTracks)
virtual void processBlock(const reco::PFBlockRef &blockref, std::list< reco::PFBlockRef > &hcalBlockRefs, std::list< reco::PFBlockRef > &ecalBlockRefs)
void setMuonHandle(const edm::Handle< reco::MuonCollection > &)
math::Error< dimension >::type Error
covariance error matrix (3x3)
virtual void setP4(const LorentzVector &p4)
set 4-momentum
std::vector< Vertex > VertexCollection
collection of Vertex objects
tuple minSignificanceReduction
const edm::OwnVector< reco::PFBlockElement > & elements() const
std::vector< PFRecHit > PFRecHitCollection
collection of PFRecHit objects
const edm::ValueMap< reco::PhotonRef > * valueMapGedPhotons_
void checkCleaning(const reco::PFRecHitCollection &cleanedHF)
Check HF Cleaning.
edm::Ref< PFCandidateElectronExtraCollection > PFCandidateElectronExtraRef
persistent reference to a PFCandidateElectronExtra
virtual void setVertex(const math::XYZPoint &p)
set vertex
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)
std::ostream & operator<<(std::ostream &out, const ALILine &li)
PFCandidateCollection::const_iterator PFCandidateConstIterator
iterator
double sumEtEcalIsoForEgammaSC_barrel_
std::auto_ptr< reco::PFCandidateCollection > pfCleanedCandidates_
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)
void setPFVertexParameters(bool useVertex, const reco::VertexCollection *primaryVertices)
void setEGElectronCollection(const reco::GsfElectronCollection &egelectrons)
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
bool rejectTracks_Step45_
const math::XYZPointF & positionAtECALEntrance() const
virtual double eta() const
momentum pseudorapidity
virtual double pt() const
transverse momentum
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)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
bool isElectron(const reco::GsfElectron &)
void set_mva_e_pi(float mvaNI)
bool usePFNuclearInteractions_
virtual double energy() const
energy
tuple usePFNuclearInteractions
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 set_mva_Isolated(float mvaI)
void setParameters(double nSigmaECAL, double nSigmaHCAL, const boost::shared_ptr< PFEnergyCalibration > &calibration, const boost::shared_ptr< PFEnergyCalibrationHF > &thepfEnergyCalibrationHF)
bool check(const std::string &)
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.
tuple rejectTracks_Step45
std::string mvaWeightFileEleID_
Variables for PFElectrons.
void setParticleType(ParticleType type)
set Particle Type
bool passPhotonSelection(const reco::Photon &)
const std::vector< reco::PFCandidateElectronExtra > & getElectronExtra()
virtual int charge() const
electric charge
void setPFPhotonRegWeights(const GBRForest *LCorrForestEB, const GBRForest *LCorrForestEE, const GBRForest *GCorrForestBarrel, const GBRForest *GCorrForestEndcapHr9, const GBRForest *GCorrForestEndcapLr9, const GBRForest *PFEcalResolution)
tuple sumPtTrackIsoForPhoton
Abs< T >::type abs(const T &t)
double z() const
y 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
std::vector< LinkConnSpec >::const_iterator IT
void setPostHFCleaningParameters(bool postHFCleaning, double minHFCleaningPt, double minSignificance, double maxSignificance, double minSignificanceReduction, double maxDeltaPhiPt, double minDeltaMet)
tuple coneEcalIsoForEgammaSC
std::vector< PFBlock > PFBlockCollection
collection of PFBlock objects
PFEGammaFilters * pfegamma_
bool isNull() const
Checks for null.
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
tuple applyCrackCorrections
const std::vector< reco::PFCandidate > & getElectronCandidates()
const math::XYZPoint & position() const
rechit cell centre x, y, z
tuple detachedTripletStep
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
double x() const
x coordinate
virtual bool trackType(TrackType trType) const
std::list< reco::PFBlockRef >::iterator IBR
unsigned reconstructTrack(const reco::PFBlockElement &elt, bool allowLoose=false)
tuple nTrackIsoForEgammaSC
std::vector< double > muonHO_
virtual double px() const
x coordinate of momentum vector
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)
tuple sumPtTrackIsoForEgammaSC_barrel
virtual bool trackType(TrackType trType) const
boost::shared_ptr< PFSCEnergyCalibration > thePFSCEnergyCalibration_
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.
double energy() const
rechit energy
tuple sumEtEcalIsoForEgammaSC_barrel
boost::shared_ptr< PFEnergyCalibrationHF > thepfEnergyCalibrationHF_
reco::PFCandidateEGammaExtraRef egammaExtraRef() const
return a reference to the EGamma extra
std::auto_ptr< reco::PFCandidateCollection > pfCandidates_
const PFDisplacedTrackerVertexRef & displacedVertexRef(TrackType trType) const
PFMuonAlgo * getPFMuonAlgo()
bool useEGammaFilters_
Variables for NEW EGAMMA selection.
tuple useProtectionsForJetMET
void setPhotonExtraRef(const edm::OrphanHandle< reco::PFCandidatePhotonExtraCollection > &pf_extrah)
bool applyCrackCorrectionsElectrons_
int charge() const
track electric charge
double sumPtTrackIsoForEgammaSC_endcap_
void setPhotonPrimaryVtx(const reco::Vertex &primary)
tuple sumEtEcalIsoForEgammaSC_endcap
volatile std::atomic< bool > shutdown_flag false
const reco::MuonRef & muonRef() const
virtual ParticleType particleId() const
std::auto_ptr< reco::PFCandidateCollection > pfElectronCandidates_
the unfiltered electron collection
double time() const
timing for cleaned hits
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
bool isPhotonValidCandidate(const reco::PFBlockRef &blockRef, std::vector< bool > &active, std::auto_ptr< reco::PFCandidateCollection > &pfPhotonCandidates, std::vector< reco::PFCandidatePhotonExtra > &pfPhotonExtraCandidates, std::vector< reco::PFCandidate > &tempElectronCandidates)
void setInputsForCleaning(const reco::VertexCollection *)
tuple coneTrackIsoForEgammaSC
virtual double phi() const
momentum azimuthal angle
bool isPhotonSafeForJetMET(const reco::Photon &, const reco::PFCandidate &)
tuple size
Write out results.
double sumPtTrackIsoForEgammaSC_barrel_
virtual double py() const
y coordinate of momentum vector
const std::auto_ptr< reco::PFCandidateCollection > & pfCandidates() const
void setHcalEnergy(float ehRaw, float ehCorr)
set corrected Hcal energy
tuple sumPtTrackIsoForEgammaSC_endcap
double py() const
y coordinate of momentum vector
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, double ph_MinEt, double ph_combIso, double ph_HoE, double ph_sietaieta_eb, double ph_sietaieta_ee, const edm::ParameterSet &ph_protectionsForJetMET)
const edm::ValueMap< reco::GsfElectronRef > * valueMapGedElectrons_
void setElectronExtraRef(const edm::OrphanHandle< reco::PFCandidateElectronExtraCollection > &extrah)
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