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,
226 double ph_sietaieta_eb,
227 double ph_sietaieta_ee,
235 FILE * fileEGamma_ele_iso_ID = fopen(ele_iso_path_mvaWeightFile.c_str(),
"r");
236 if (fileEGamma_ele_iso_ID) {
237 fclose(fileEGamma_ele_iso_ID);
240 string err =
"PFAlgo: cannot open weight file '";
241 err += ele_iso_path_mvaWeightFile;
243 throw invalid_argument( err );
254 ph_protectionsForJetMET,
258 ele_iso_combIso_barrel,
259 ele_iso_combIso_endcap,
262 ele_iso_path_mvaWeightFile,
263 ele_protectionsForJetMET);
298 GCorrForestBarrel, GCorrForestEndcapHr9,
299 GCorrForestEndcapLr9, PFEcalResolution);
321 assert (
muonHCAL_.size() == 2 && muonECAL_.size() == 2 && muonHO_.size() == 2);
325 assert ( factors45_.size() == 2 );
381 bool primaryVertexFound =
false;
382 nVtx_ = primaryVertices->size();
386 for (
unsigned short i=0 ;
i<primaryVertices->size();++
i)
388 if(primaryVertices->at(
i).isValid()&&(!primaryVertices->at(
i).isFake()))
391 primaryVertexFound =
true;
403 e(0, 0) = 0.0015 * 0.0015;
404 e(1, 1) = 0.0015 * 0.0015;
452 cout<<
"*********************************************************"<<endl;
453 cout<<
"***** Particle flow algorithm *****"<<endl;
454 cout<<
"*********************************************************"<<endl;
458 std::list< reco::PFBlockRef > hcalBlockRefs;
459 std::list< reco::PFBlockRef > ecalBlockRefs;
460 std::list< reco::PFBlockRef > hoBlockRefs;
461 std::list< reco::PFBlockRef > otherBlockRefs;
463 for(
unsigned i=0;
i<blocks.size(); ++
i ) {
471 bool singleEcalOrHcal =
false;
472 if( elements.
size() == 1 ){
474 ecalBlockRefs.push_back( blockref );
475 singleEcalOrHcal =
true;
478 hcalBlockRefs.push_back( blockref );
479 singleEcalOrHcal =
true;
483 hoBlockRefs.push_back( blockref );
484 singleEcalOrHcal =
true;
488 if(!singleEcalOrHcal) {
489 otherBlockRefs.push_back( blockref );
494 cout<<
"# Ecal blocks: "<<ecalBlockRefs.size()
495 <<
", # Hcal blocks: "<<hcalBlockRefs.size()
496 <<
", # HO blocks: "<<hoBlockRefs.size()
497 <<
", # Other blocks: "<<otherBlockRefs.size()<<endl;
505 for(
IBR io = otherBlockRefs.begin(); io!=otherBlockRefs.end(); ++io) {
510 std::list< reco::PFBlockRef >
empty;
514 for(
IBR ih = hcalBlockRefs.begin(); ih!=hcalBlockRefs.end(); ++ih) {
515 if (
debug_ )
std::cout <<
"HCAL block number " << hblcks++ << std::endl;
521 for(
IBR ie = ecalBlockRefs.begin(); ie!=ecalBlockRefs.end(); ++ie) {
522 if (
debug_ )
std::cout <<
"ECAL block number " << eblcks++ << std::endl;
539 std::list<reco::PFBlockRef>& hcalBlockRefs,
540 std::list<reco::PFBlockRef>& ecalBlockRefs ) {
543 assert(!blockref.
isNull() );
546 typedef std::multimap<double, unsigned>::iterator IE;
547 typedef std::multimap<double, std::pair<unsigned,::math::XYZVector> >::iterator IS;
548 typedef std::multimap<double, std::pair<unsigned,bool> >::iterator
IT;
549 typedef std::multimap< unsigned, std::pair<double, unsigned> >::iterator II;
552 cout<<
"#########################################################"<<endl;
553 cout<<
"##### Process Block: #####"<<endl;
554 cout<<
"#########################################################"<<endl;
564 vector<bool> active( elements.
size(),
true );
569 std::vector<reco::PFCandidate> tempElectronCandidates;
570 tempElectronCandidates.clear();
575 for ( std::vector<reco::PFCandidate>::const_iterator
ec=PFElectCandidates_.begin();
ec != PFElectCandidates_.end(); ++
ec )tempElectronCandidates.push_back(*
ec);
595 cout<<endl<<
"--------------- entering PFPhotonAlgo ----------------"<<endl;
596 vector<PFCandidatePhotonExtra> pfPhotonExtraCand;
601 tempElectronCandidates
611 unsigned int extracand =0;
619 pfPhotonExtraCand.clear();
624 for ( std::vector<reco::PFCandidate>::const_iterator
ec=tempElectronCandidates.begin();
ec != tempElectronCandidates.end(); ++
ec ){
627 tempElectronCandidates.clear();
635 bool egmLocalDebug =
false;
636 bool egmLocalBlockDebug =
false;
639 for(
unsigned int ieg=0 ; ieg < negmcandidates; ++ieg) {
644 PFCandidate::ElementsInBlocks::const_iterator iegfirst = theElements.begin();
645 bool sameBlock =
false;
646 bool isGoodElectron =
false;
647 bool isGoodPhoton =
false;
648 bool isPrimaryElectron =
false;
649 if(iegfirst->first == blockref)
654 cout <<
" I am in looping on EGamma Candidates: pt " << (*pfEgmRef).pt()
655 <<
" eta,phi " << (*pfEgmRef).eta() <<
", " << (*pfEgmRef).phi()
656 <<
" charge " << (*pfEgmRef).charge() << endl;
658 if((*pfEgmRef).gsfTrackRef().isNonnull()) {
666 cout <<
"** Good Electron, pt " << gedEleRef->pt()
667 <<
" eta, phi " << gedEleRef->eta() <<
", " << gedEleRef->phi()
668 <<
" charge " << gedEleRef->charge()
669 <<
" isPrimary " << isPrimaryElectron << endl;
675 if((*pfEgmRef).superClusterRef().isNonnull()) {
682 cout <<
"** Good Photon, pt " << gedPhoRef->pt()
683 <<
" eta, phi " << gedPhoRef->eta() <<
", " << gedPhoRef->phi() << endl;
689 if(isGoodElectron && isGoodPhoton) {
690 if(isPrimaryElectron)
691 isGoodPhoton =
false;
693 isGoodElectron =
false;
701 bool lockTracks =
false;
711 myPFElectron.
setCharge(gedEleRef->charge());
712 myPFElectron.
setP4(gedEleRef->p4());
717 cout <<
" PFAlgo: found an electron with NEW EGamma code " << endl;
718 cout <<
" myPFElectron: pt " << myPFElectron.
pt()
719 <<
" eta,phi " << myPFElectron.
eta() <<
", " <<myPFElectron.
phi()
720 <<
" mva " << myPFElectron.
mva_e_pi()
721 <<
" charge " << myPFElectron.
charge() << endl;
726 if(egmLocalBlockDebug)
727 cout <<
" THE BLOCK " << *blockref << endl;
728 for (PFCandidate::ElementsInBlocks::const_iterator ieb = theElements.begin();
729 ieb<theElements.end(); ++ieb) {
730 active[ieb->second] =
false;
731 if(egmLocalBlockDebug)
732 cout <<
" Elements used " << ieb->second << endl;
738 for (PFCandidate::ElementsInBlocks::const_iterator itrk = extraTracks.begin();
739 itrk<extraTracks.end(); ++itrk) {
740 active[itrk->second] =
false;
749 cout <<
"PFAlgo: Electron DISCARDED, NOT SAFE FOR JETMET " << endl;
769 myPFPhoton.
setP4(gedPhoRef->p4());
771 cout <<
" PFAlgo: found a photon with NEW EGamma code " << endl;
772 cout <<
" myPFPhoton: pt " << myPFPhoton.
pt()
773 <<
" eta,phi " << myPFPhoton.
eta() <<
", " <<myPFPhoton.
phi()
774 <<
" charge " << myPFPhoton.
charge() << endl;
778 if(egmLocalBlockDebug)
779 cout <<
" THE BLOCK " << *blockref << endl;
780 for (PFCandidate::ElementsInBlocks::const_iterator ieb = theElements.begin();
781 ieb<theElements.end(); ++ieb) {
782 active[ieb->second] =
false;
783 if(egmLocalBlockDebug)
784 cout <<
" Elements used " << ieb->second << endl;
798 for(
unsigned iEle=0; iEle<elements.
size(); iEle++) {
800 if(type==PFBlockElement::TRACK)
807 if(!elements[iEle].convRefs().
empty())active[iEle]=
false;
817 cout<<endl<<
"--------------- loop 1 ------------------"<<endl;
844 vector<unsigned> hcalIs;
845 vector<unsigned> hoIs;
846 vector<unsigned> ecalIs;
847 vector<unsigned> trackIs;
848 vector<unsigned> ps1Is;
849 vector<unsigned> ps2Is;
851 vector<unsigned> hfEmIs;
852 vector<unsigned> hfHadIs;
855 for(
unsigned iEle=0; iEle<elements.
size(); iEle++) {
858 if(
debug_ && type != PFBlockElement::BREM )
cout<<endl<<elements[iEle];
861 case PFBlockElement::TRACK:
862 if ( active[iEle] ) {
864 if(
debug_)
cout<<
"TRACK, stored index, continue"<<endl;
868 if ( active[iEle] ) {
869 ecalIs.push_back( iEle );
870 if(
debug_)
cout<<
"ECAL, stored index, continue"<<endl;
874 if ( active[iEle] ) {
875 hcalIs.push_back( iEle );
876 if(
debug_)
cout<<
"HCAL, stored index, continue"<<endl;
881 if ( active[iEle] ) {
882 hoIs.push_back( iEle );
883 if(
debug_)
cout<<
"HO, stored index, continue"<<endl;
887 case PFBlockElement::HFEM:
888 if ( active[iEle] ) {
889 hfEmIs.push_back( iEle );
890 if(
debug_)
cout<<
"HFEM, stored index, continue"<<endl;
893 case PFBlockElement::HFHAD:
894 if ( active[iEle] ) {
895 hfHadIs.push_back( iEle );
896 if(
debug_)
cout<<
"HFHAD, stored index, continue"<<endl;
904 unsigned iTrack = iEle;
910 if (active[iTrack] &&
isFromSecInt(elements[iEle],
"primary")){
911 bool isPrimaryTrack = elements[iEle].displacedVertexRef(PFBlockElement::T_TO_DISP)->displacedVertexRef()->isTherePrimaryTracks();
912 if (isPrimaryTrack) {
913 if (
debug_)
cout <<
"Primary Track reconstructed alone" << endl;
916 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEle );
917 active[iTrack] =
false;
923 if ( !active[iTrack] )
924 cout <<
"Already used by electrons, muons, conversions" << endl;
929 if ( ! active[iTrack] )
continue;
932 assert( !trackRef.
isNull() );
935 cout <<
"PFAlgo:processBlock "<<
" "<<trackIs.size()<<
" "<<ecalIs.size()<<
" "<<hcalIs.size()<<
" "<<hoIs.size()<<endl;
942 std::multimap<double, unsigned> ecalElems;
943 block.associatedElements( iTrack, linkData,
948 std::multimap<double, unsigned> hcalElems;
949 block.associatedElements( iTrack, linkData,
957 if ( hcalElems.empty() && !ecalElems.empty() ) {
960 unsigned index = ecalElems.begin()->second;
961 std::multimap<double, unsigned> sortedTracks;
962 block.associatedElements( index, linkData,
969 for(IE ie = sortedTracks.begin(); ie != sortedTracks.end(); ++ie ) {
970 unsigned jTrack = ie->second;
973 if ( !active[jTrack] )
continue;
977 if ( jTrack == iTrack )
continue;
982 std::multimap<double, unsigned> sortedECAL;
983 block.associatedElements( jTrack, linkData,
987 if ( sortedECAL.begin()->second !=
index )
continue;
992 std::multimap<double, unsigned> sortedHCAL;
993 block.associatedElements( jTrack, linkData,
997 if ( sortedHCAL.empty() )
continue;
1002 block.setLink( iTrack,
1003 sortedHCAL.begin()->second,
1004 sortedECAL.begin()->first,
1006 PFBlock::LINKTEST_RECHIT );
1011 block.associatedElements( iTrack, linkData,
1016 if (
debug_ && !hcalElems.empty() )
1017 std::cout <<
"Track linked back to HCAL due to ECAL sharing with other tracks" << std::endl;
1027 std::multimap<double,unsigned> gsfElems;
1029 block.associatedElements( iTrack, linkData,
1035 if(hcalElems.empty() &&
debug_) {
1036 cout<<
"no hcal element connected to track "<<iTrack<<endl;
1042 bool hcalFound =
false;
1045 cout<<
"now looping on elements associated to the track"<<endl;
1049 for(IE ie = ecalElems.begin(); ie != ecalElems.end(); ++ie ) {
1051 unsigned index = ie->second;
1055 double dist = ie->first;
1056 cout<<
"\telement "<<elements[
index]<<
" linked with distance = "<< dist <<endl;
1057 if ( ! active[index] )
cout <<
"This ECAL is already used - skip it" << endl;
1062 if ( ! active[index] )
continue;
1068 if( !hcalElems.empty() &&
debug_)
1069 cout<<
"\t\tat least one hcal element connected to the track." 1070 <<
" Sparing Ecal cluster for the hcal loop"<<endl;
1078 if( hcalElems.empty() ) {
1081 std::cout <<
"Now deals with tracks linked to no HCAL clusters" << std::endl;
1088 std::cout << elements[iTrack] << std::endl;
1094 if ( thisIsAMuon ) trackMomentum = 0.;
1098 bool rejectFake =
false;
1099 if ( !thisIsAMuon && elements[iTrack].trackRef()->ptError() >
ptError_ ) {
1103 elements[iTrack].trackRef()->
eta());
1106 if ( !ecalElems.empty() ) {
1107 unsigned thisEcal = ecalElems.begin()->second;
1109 deficit -= clusterRef->energy();
1111 clusterRef->positionREP().Eta());
1115 bool isPrimary =
isFromSecInt(elements[iTrack],
"primary");
1119 active[iTrack] =
false;
1121 std::cout << elements[iTrack] << std::endl
1122 <<
"is probably a fake (1) --> lock the track" 1127 if ( rejectFake )
continue;
1132 std::vector<unsigned> tmpi;
1133 std::vector<unsigned> kTrack;
1136 double Dpt = trackRef->ptError();
1139 trackMomentum > 30. && Dpt > 0.5 &&
1142 double dptRel = Dpt/trackRef->pt()*100;
1143 bool isPrimaryOrSecondary =
isFromSecInt(elements[iTrack],
"all");
1146 unsigned nHits = elements[iTrack].trackRef()->hitPattern().trackerLayersWithMeasurement();
1147 unsigned int NLostHit = trackRef->hitPattern().trackerLayersWithoutMeasurement(HitPattern::TRACK_HITS);
1150 std::cout <<
"A track (algo = " << trackRef->algo() <<
") with momentum " << trackMomentum
1151 <<
" / " << elements[iTrack].trackRef()->pt() <<
" +/- " << Dpt
1152 <<
" / " << elements[iTrack].trackRef()->eta()
1153 <<
" without any link to ECAL/HCAL and with " << nHits <<
" (" << NLostHit
1154 <<
") hits (lost hits) has been cleaned" << std::endl;
1155 active[iTrack] =
false;
1162 kTrack.push_back(iTrack);
1163 active[iTrack] =
false;
1166 if ( ecalElems.empty() ) {
1167 (*pfCandidates_)[tmpi[0]].setEcalEnergy( 0., 0. );
1168 (*pfCandidates_)[tmpi[0]].setHcalEnergy( 0., 0. );
1169 (*pfCandidates_)[tmpi[0]].setHoEnergy( 0., 0. );
1170 (*pfCandidates_)[tmpi[0]].setPs1Energy( 0 );
1171 (*pfCandidates_)[tmpi[0]].setPs2Energy( 0 );
1172 (*pfCandidates_)[tmpi[0]].addElementInBlock( blockref, kTrack[0] );
1177 unsigned thisEcal = ecalElems.begin()->second;
1179 if (
debug_ )
std::cout <<
" is associated to " << elements[thisEcal] << std::endl;
1183 if ( thisIsAMuon ) {
1184 (*pfCandidates_)[tmpi[0]].setEcalEnergy( clusterRef->energy(),
1186 (*pfCandidates_)[tmpi[0]].setHcalEnergy( 0., 0. );
1187 (*pfCandidates_)[tmpi[0]].setHoEnergy( 0., 0. );
1188 (*pfCandidates_)[tmpi[0]].setPs1Energy( 0 );
1189 (*pfCandidates_)[tmpi[0]].setPs2Energy( 0 );
1190 (*pfCandidates_)[tmpi[0]].addElementInBlock( blockref, kTrack[0] );
1193 double slopeEcal = 1.;
1194 bool connectedToEcal =
false;
1195 unsigned iEcal = 99999;
1196 double calibEcal = 0.;
1197 double calibHcal = 0.;
1198 double totalEcal = thisIsAMuon ? -
muonECAL_[0] : 0.;
1201 std::multimap<double, unsigned> sortedTracks;
1202 block.associatedElements( thisEcal, linkData,
1207 for(IE ie = sortedTracks.begin(); ie != sortedTracks.end(); ++ie ) {
1208 unsigned jTrack = ie->second;
1211 if ( !active[jTrack] )
continue;
1214 if ( jTrack == iTrack )
continue;
1219 std::multimap<double, unsigned> sortedECAL;
1220 block.associatedElements( jTrack, linkData,
1224 if ( sortedECAL.begin()->second != thisEcal )
continue;
1231 bool rejectFake =
false;
1233 if ( !thatIsAMuon && trackRef->ptError() >
ptError_) {
1234 double deficit = trackMomentum + trackRef->p() - clusterRef->energy();
1236 clusterRef->positionREP().Eta());
1237 resol *= (trackMomentum+trackRef->p());
1240 kTrack.push_back(jTrack);
1241 active[jTrack] =
false;
1243 std::cout << elements[jTrack] << std::endl
1244 <<
"is probably a fake (2) --> lock the track" 1248 if ( rejectFake )
continue;
1254 if ( !thatIsAMuon ) {
1256 std::cout <<
"Track momentum increased from " << trackMomentum <<
" GeV ";
1257 trackMomentum += trackRef->p();
1259 std::cout <<
"to " << trackMomentum <<
" GeV." << std::endl;
1260 std::cout <<
"with " << elements[jTrack] << std::endl;
1264 totalEcal =
std::max(totalEcal, 0.);
1272 kTrack.push_back(jTrack);
1273 active[jTrack] =
false;
1275 if ( thatIsAMuon ) {
1276 (*pfCandidates_)[tmpi.back()].setEcalEnergy(clusterRef->energy(),
1278 (*pfCandidates_)[tmpi.back()].setHcalEnergy( 0., 0. );
1279 (*pfCandidates_)[tmpi.back()].setHoEnergy( 0., 0. );
1280 (*pfCandidates_)[tmpi.back()].setPs1Energy( 0 );
1281 (*pfCandidates_)[tmpi.back()].setPs2Energy( 0 );
1282 (*pfCandidates_)[tmpi.back()].addElementInBlock( blockref, kTrack.back() );
1287 if (
debug_ )
std::cout <<
"Loop over all associated ECAL clusters" << std::endl;
1289 for(IE ie = ecalElems.begin(); ie != ecalElems.end(); ++ie ) {
1291 unsigned index = ie->second;
1297 if (
debug_ && ! active[index] )
std::cout <<
"is not active - ignore " << std::endl;
1298 if ( ! active[index] )
continue;
1302 block.associatedElements( index, linkData,
1307 for (
unsigned ic=0; ic<kTrack.size();++ic) {
1308 if ( sortedTracks.begin()->second == kTrack[ic] ) {
1313 if (
debug_ && skip )
std::cout <<
"is closer to another track - ignore " << std::endl;
1314 if ( skip )
continue;
1319 assert( !clusterRef.
isNull() );
1322 double dist = ie->first;
1323 std::cout <<
"Ecal cluster with raw energy = " << clusterRef->energy()
1324 <<
" linked with distance = " << dist << std::endl;
1339 vector<double> ps1Ene(1,static_cast<double>(0.));
1341 vector<double> ps2Ene(1,static_cast<double>(0.));
1344 double ecalEnergy = clusterRef->correctedEnergy();
1346 std::cout <<
"Corrected ECAL(+PS) energy = " << ecalEnergy << std::endl;
1350 totalEcal += ecalEnergy;
1351 double previousCalibEcal = calibEcal;
1352 double previousSlopeEcal = slopeEcal;
1353 calibEcal =
std::max(totalEcal,0.);
1355 calibration_->energyEmHad(trackMomentum,calibEcal,calibHcal,
1356 clusterRef->positionREP().Eta(),
1357 clusterRef->positionREP().Phi());
1358 if ( totalEcal > 0.) slopeEcal = calibEcal/totalEcal;
1361 std::cout <<
"The total calibrated energy so far amounts to = " << calibEcal << std::endl;
1365 if ( connectedToEcal && calibEcal - trackMomentum >= 0. ) {
1368 calibEcal = previousCalibEcal;
1369 slopeEcal = previousSlopeEcal;
1370 totalEcal = calibEcal/slopeEcal;
1374 active[
index] =
false;
1377 std::multimap<double, unsigned> assTracks;
1378 block.associatedElements( index, linkData,
1385 (*pfCandidates_)[tmpe].setEcalEnergy( clusterRef->energy(), ecalEnergy );
1386 (*pfCandidates_)[tmpe].setHcalEnergy( 0., 0. );
1387 (*pfCandidates_)[tmpe].setHoEnergy( 0., 0. );
1388 (*pfCandidates_)[tmpe].setPs1Energy( ps1Ene[0] );
1389 (*pfCandidates_)[tmpe].setPs2Energy( ps2Ene[0] );
1390 (*pfCandidates_)[tmpe].addElementInBlock( blockref, index );
1392 if(!assTracks.empty()) {
1393 (*pfCandidates_)[tmpe].addElementInBlock( blockref, assTracks.begin()->second );
1404 connectedToEcal =
true;
1406 active[
index] =
false;
1407 for (
unsigned ic=0; ic<tmpi.size();++ic)
1408 (*
pfCandidates_)[tmpi[ic]].addElementInBlock( blockref, iEcal );
1413 bool bNeutralProduced =
false;
1416 if( connectedToEcal ) {
1458 neutralEnergy /= slopeEcal;
1460 (*pfCandidates_)[tmpj].setEcalEnergy( pivotalRef->energy(), neutralEnergy );
1461 (*pfCandidates_)[tmpj].setHcalEnergy( 0., 0. );
1462 (*pfCandidates_)[tmpj].setHoEnergy( 0., 0. );
1463 (*pfCandidates_)[tmpj].setPs1Energy( 0. );
1464 (*pfCandidates_)[tmpj].setPs2Energy( 0. );
1465 (*pfCandidates_)[tmpj].addElementInBlock(blockref, iEcal);
1466 bNeutralProduced =
true;
1467 for (
unsigned ic=0; ic<kTrack.size();++ic)
1468 (*
pfCandidates_)[tmpj].addElementInBlock( blockref, kTrack[ic] );
1472 for (
unsigned ic=0; ic<tmpi.size();++ic) {
1477 double fraction = trackMomentum > 0 ? (*pfCandidates_)[tmpi[ic]].trackRef()->p()/trackMomentum : 0;
1478 double ecalCal = bNeutralProduced ?
1479 (calibEcal-neutralEnergy*slopeEcal)*fraction : calibEcal*fraction;
1480 double ecalRaw = totalEcal*
fraction;
1482 if (
debug_)
cout <<
"The fraction after photon supression is " << fraction <<
" calibrated ecal = " << ecalCal << endl;
1484 (*pfCandidates_)[tmpi[ic]].setEcalEnergy( ecalRaw, ecalCal );
1485 (*pfCandidates_)[tmpi[ic]].setHcalEnergy( 0., 0. );
1486 (*pfCandidates_)[tmpi[ic]].setHoEnergy( 0., 0. );
1487 (*pfCandidates_)[tmpi[ic]].setPs1Energy( 0 );
1488 (*pfCandidates_)[tmpi[ic]].setPs2Energy( 0 );
1489 (*pfCandidates_)[tmpi[ic]].addElementInBlock( blockref, kTrack[ic] );
1495 for (
unsigned ic=0; ic<tmpi.size();++ic) {
1496 const PFCandidate& pfc = (*pfCandidates_)[tmpi[ic]];
1498 if ( eleInBlocks.empty() ) {
1499 if (
debug_ )
std::cout <<
"Single track / Fill element in block! " << std::endl;
1500 (*pfCandidates_)[tmpi[ic]].addElementInBlock( blockref, kTrack[ic] );
1509 for(IE ie = hcalElems.begin(); ie != hcalElems.end(); ++ie ) {
1511 unsigned index = ie->second;
1517 cout<<
"\telement "<<elements[
index]<<
" linked with distance "<< dist <<endl;
1526 cout<<
"\t\tclosest hcal cluster, doing nothing"<<endl;
1536 cout<<
"\t\tsecondary hcal cluster. unlinking"<<endl;
1537 block.setLink( iTrack, index, -1., linkData,
1538 PFBlock::LINKTEST_RECHIT );
1546 if( !(hfEmIs.empty() && hfHadIs.empty() ) ) {
1549 assert( hfEmIs.size() + hfHadIs.size() == elements.
size() );
1551 if( elements.
size() == 1 ) {
1554 double energyHF = 0.;
1555 double uncalibratedenergyHF = 0.;
1557 switch( clusterRef->layer() ) {
1560 energyHF = clusterRef->energy();
1561 uncalibratedenergyHF = energyHF;
1564 clusterRef->positionREP().Eta(),
1565 clusterRef->positionREP().Phi());
1568 (*pfCandidates_)[tmpi].setEcalEnergy( uncalibratedenergyHF, energyHF );
1569 (*pfCandidates_)[tmpi].setHcalEnergy( 0., 0.);
1570 (*pfCandidates_)[tmpi].setHoEnergy( 0., 0.);
1571 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
1572 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
1573 (*pfCandidates_)[tmpi].addElementInBlock( blockref, hfEmIs[0] );
1578 energyHF = clusterRef->energy();
1579 uncalibratedenergyHF = energyHF;
1582 clusterRef->positionREP().Eta(),
1583 clusterRef->positionREP().Phi());
1586 (*pfCandidates_)[tmpi].setHcalEnergy( uncalibratedenergyHF, energyHF );
1587 (*pfCandidates_)[tmpi].setEcalEnergy( 0., 0.);
1588 (*pfCandidates_)[tmpi].setHoEnergy( 0., 0.);
1589 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
1590 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
1591 (*pfCandidates_)[tmpi].addElementInBlock( blockref, hfHadIs[0] );
1598 else if( elements.
size() == 2 ) {
1607 cerr<<
"Error: 2 elements, but not 1 HFEM and 1 HFHAD"<<endl;
1614 double energyHfEm = cem->energy();
1615 double energyHfHad = chad->energy();
1616 double uncalibratedenergyHFEm = energyHfEm;
1617 double uncalibratedenergyHFHad = energyHfHad;
1622 c0->positionREP().Eta(),
1623 c0->positionREP().Phi());
1625 uncalibratedenergyHFHad,
1626 c1->positionREP().Eta(),
1627 c1->positionREP().Phi());
1630 (*pfCandidates_)[tmpi].setEcalEnergy( uncalibratedenergyHFEm, energyHfEm );
1631 (*pfCandidates_)[tmpi].setHcalEnergy( uncalibratedenergyHFHad, energyHfHad);
1632 (*pfCandidates_)[tmpi].setHoEnergy( 0., 0.);
1633 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
1634 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
1635 (*pfCandidates_)[tmpi].addElementInBlock( blockref, hfEmIs[0] );
1636 (*pfCandidates_)[tmpi].addElementInBlock( blockref, hfHadIs[0] );
1642 cerr<<
"Warning: HF, but n elem different from 1 or 2"<<endl;
1653 cout<<endl<<
"--------------- loop hcal ---------------------"<<endl;
1662 for(
unsigned i=0;
i<hcalIs.size();
i++) {
1664 unsigned iHcal= hcalIs[
i];
1669 if(
debug_)
cout<<endl<<elements[iHcal]<<endl;
1675 std::multimap<double, unsigned> sortedTracks;
1676 block.associatedElements( iHcal, linkData,
1681 std::multimap< unsigned, std::pair<double, unsigned> > associatedEcals;
1683 std::map< unsigned, std::pair<double, double> > associatedPSs;
1685 std::multimap<double, std::pair<unsigned,bool> > associatedTracks;
1688 std::multimap<double,std::pair<unsigned,::math::XYZVector> > ecalSatellites;
1689 std::pair<unsigned,::math::XYZVector> fakeSatellite = make_pair(iHcal,::
math::XYZVector(0.,0.,0.));
1690 ecalSatellites.insert( make_pair(-1., fakeSatellite) );
1692 std::multimap< unsigned, std::pair<double, unsigned> > associatedHOs;
1694 PFClusterRef hclusterref = elements[iHcal].clusterRef();
1695 assert(!hclusterref.
isNull() );
1705 if( sortedTracks.empty() ) {
1707 cout<<
"\tno associated tracks, keep for later"<<endl;
1712 active[iHcal] =
false;
1720 if(
debug_)
cout<<
"\t"<<sortedTracks.size()<<
" associated tracks:"<<endl;
1722 double totalChargedMomentum = 0;
1723 double sumpError2 = 0.;
1724 double totalHO = 0.;
1725 double totalEcal = 0.;
1726 double totalHcal = hclusterref->energy();
1727 vector<double> hcalP;
1728 vector<double> hcalDP;
1729 vector<unsigned> tkIs;
1730 double maxDPovP = -9999.;
1733 vector< unsigned > chargedHadronsIndices;
1734 vector< unsigned > chargedHadronsInBlock;
1735 double mergedNeutralHadronEnergy = 0;
1736 double mergedPhotonEnergy = 0;
1737 double muonHCALEnergy = 0.;
1738 double muonECALEnergy = 0.;
1739 double muonHCALError = 0.;
1740 double muonECALError = 0.;
1745 std::vector<std::pair<unsigned,::math::XYZVector> >
ecalClusters;
1746 double sumEcalClusters=0;
1748 hclusterref->position().Y(),
1749 hclusterref->position().Z());
1750 hadronDirection = hadronDirection.Unit();
1754 for(IE ie = sortedTracks.begin(); ie != sortedTracks.end(); ++ie ) {
1756 unsigned iTrack = ie->second;
1759 if ( !active[iTrack] )
continue;
1765 assert( !trackRef.
isNull() );
1770 ::math::XYZVector chargedDirection(chargedPosition.X(),chargedPosition.Y(),chargedPosition.Z());
1771 chargedDirection = chargedDirection.Unit();
1774 std::multimap<double, unsigned> sortedEcals;
1775 block.associatedElements( iTrack, linkData,
1780 if(
debug_)
cout<<
"\t\t\tnumber of Ecal elements linked to this track: " 1781 <<sortedEcals.size()<<endl;
1784 std::multimap<double, unsigned> sortedHOs;
1786 block.associatedElements( iTrack, linkData,
1793 cout<<
"PFAlgo : number of HO elements linked to this track: " 1794 <<sortedHOs.size()<<endl;
1802 bool thisIsALooseMuon =
false;
1810 if ( thisIsAMuon ) {
1812 std::cout <<
"\t\tThis track is identified as a muon - remove it from the stack" << std::endl;
1813 std::cout <<
"\t\t" << elements[iTrack] << std::endl;
1821 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iTrack );
1822 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
1828 bool letMuonEatCaloEnergy =
false;
1830 if(thisIsAnIsolatedMuon){
1832 double totalCaloEnergy = totalHcal / 1.30;
1834 if( !sortedEcals.empty() ) {
1835 iEcal = sortedEcals.begin()->second;
1836 PFClusterRef eclusterref = elements[iEcal].clusterRef();
1837 totalCaloEnergy += eclusterref->energy();
1843 if( !sortedHOs.empty() ) {
1844 iHO = sortedHOs.begin()->second;
1846 totalCaloEnergy += eclusterref->energy() / 1.30;
1852 if( (
pfCandidates_->back()).
p() > totalCaloEnergy ) letMuonEatCaloEnergy =
true;
1855 if(letMuonEatCaloEnergy) muonHcal = totalHcal;
1856 double muonEcal =0.;
1858 if( !sortedEcals.empty() ) {
1859 iEcal = sortedEcals.begin()->second;
1860 PFClusterRef eclusterref = elements[iEcal].clusterRef();
1861 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal);
1863 if(letMuonEatCaloEnergy) muonEcal = eclusterref->energy();
1865 if ( eclusterref->energy() - muonEcal < 0.2 ) active[iEcal] =
false;
1866 (*pfCandidates_)[tmpi].setEcalEnergy(eclusterref->energy(), muonEcal);
1871 if( !sortedHOs.empty() ) {
1872 iHO = sortedHOs.begin()->second;
1873 PFClusterRef hoclusterref = elements[iHO].clusterRef();
1874 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHO);
1876 if(letMuonEatCaloEnergy) muonHO = hoclusterref->energy();
1878 if ( hoclusterref->energy() - muonHO < 0.2 ) active[iHO] =
false;
1879 (*pfCandidates_)[tmpi].setHcalEnergy(totalHcal, muonHcal);
1880 (*pfCandidates_)[tmpi].setHoEnergy(hoclusterref->energy(), muonHO);
1883 (*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();
1938 bool isPrimaryOrSecondary =
isFromSecInt(elements[iTrack],
"all");
1940 if ( isPrimaryOrSecondary ) blowError = 1.;
1942 std::pair<unsigned,bool> tkmuon = make_pair(iTrack,thisIsALooseMuon);
1943 associatedTracks.insert( make_pair(-Dpt*blowError, tkmuon) );
1946 double Dp = trackRef->qoverpError()*trackMomentum*
trackMomentum;
1947 sumpError2 += Dp*Dp;
1949 bool connectedToEcal =
false;
1950 if( !sortedEcals.empty() )
1954 for ( IE iec=sortedEcals.begin();
1955 iec!=sortedEcals.end(); ++iec ) {
1957 unsigned iEcal = iec->second;
1958 double dist = iec->first;
1961 if( !active[iEcal] ) {
1969 PFClusterRef eclusterref = elements[iEcal].clusterRef();
1970 assert(!eclusterref.
isNull() );
1973 std::multimap<double, unsigned> sortedTracksEcal;
1974 block.associatedElements( iEcal, linkData,
1978 unsigned jTrack = sortedTracksEcal.
begin()->second;
1979 if ( jTrack != iTrack )
continue;
1983 double distEcal = block.dist(jTrack,iEcal,linkData,
1990 float ecalEnergyCalibrated = eclusterref->correctedEnergy();
1992 eclusterref->position().Y(),
1993 eclusterref->position().Z());
1994 photonDirection = photonDirection.Unit();
1996 if ( !connectedToEcal ) {
1999 <<elements[iEcal]<<endl;
2001 connectedToEcal =
true;
2005 std::pair<unsigned,::math::XYZVector> satellite =
2006 make_pair(iEcal,ecalEnergyCalibrated*photonDirection);
2007 ecalSatellites.insert( make_pair(-1., satellite) );
2011 std::pair<unsigned,::math::XYZVector> satellite =
2012 make_pair(iEcal,ecalEnergyCalibrated*photonDirection);
2013 ecalSatellites.insert( make_pair(dist, satellite) );
2017 std::pair<double, unsigned> associatedEcal
2018 = make_pair( distEcal, iEcal );
2019 associatedEcals.insert( make_pair(iTrack, associatedEcal) );
2024 if(
useHO_ && !sortedHOs.empty() )
2028 for ( IE ieho=sortedHOs.begin(); ieho!=sortedHOs.end(); ++ieho ) {
2030 unsigned iHO = ieho->second;
2031 double distHO = ieho->first;
2034 if( !active[iHO] ) {
2042 PFClusterRef hoclusterref = elements[iHO].clusterRef();
2043 assert(!hoclusterref.
isNull() );
2046 std::multimap<double, unsigned> sortedTracksHO;
2047 block.associatedElements( iHO, linkData,
2051 unsigned jTrack = sortedTracksHO.
begin()->second;
2052 if ( jTrack != iTrack )
continue;
2060 totalHO += hoclusterref->energy();
2061 active[iHO] =
false;
2063 std::pair<double, unsigned> associatedHO
2064 = make_pair( distHO, iHO );
2065 associatedHOs.insert( make_pair(iTrack, associatedHO) );
2074 totalHcal += totalHO;
2078 double caloEnergy = 0.;
2079 double slopeEcal = 1.0;
2080 double calibEcal = 0.;
2081 double calibHcal = 0.;
2082 hadronDirection = hadronAtECAL.Unit();
2086 Caloresolution *= totalChargedMomentum;
2088 Caloresolution =
std::sqrt(Caloresolution*Caloresolution + muonHCALError + muonECALError);
2089 totalEcal -=
std::min(totalEcal,muonECALEnergy);
2090 totalHcal -=
std::min(totalHcal,muonHCALEnergy);
2098 for ( IS is = ecalSatellites.begin(); is != ecalSatellites.end(); ++is ) {
2101 double previousCalibEcal = calibEcal;
2102 double previousCalibHcal = calibHcal;
2103 double previousCaloEnergy = caloEnergy;
2104 double previousSlopeEcal = slopeEcal;
2107 totalEcal +=
sqrt(is->second.second.Mag2());
2108 photonAtECAL += is->second.second;
2109 calibEcal =
std::max(0.,totalEcal);
2110 calibHcal =
std::max(0.,totalHcal);
2111 hadronAtECAL = calibHcal * hadronDirection;
2113 calibration_->energyEmHad(totalChargedMomentum,calibEcal,calibHcal,
2114 hclusterref->positionREP().Eta(),
2115 hclusterref->positionREP().Phi());
2116 caloEnergy = calibEcal+calibHcal;
2117 if ( totalEcal > 0.) slopeEcal = calibEcal/totalEcal;
2119 hadronAtECAL = calibHcal * hadronDirection;
2123 if ( is->first < 0. || caloEnergy - totalChargedMomentum <= 0. ) {
2124 if(
debug_)
cout<<
"\t\t\tactive, adding "<<is->second.second
2125 <<
" to ECAL energy, and locking"<<endl;
2126 active[is->second.first] =
false;
2127 double clusterEnergy=
sqrt(is->second.second.Mag2());
2128 if(clusterEnergy>50) {
2129 ecalClusters.push_back(is->second);
2130 sumEcalClusters+=clusterEnergy;
2137 totalEcal -=
sqrt(is->second.second.Mag2());
2138 photonAtECAL -= is->second.second;
2139 calibEcal = previousCalibEcal;
2140 calibHcal = previousCalibHcal;
2141 hadronAtECAL = previousHadronAtECAL;
2142 slopeEcal = previousSlopeEcal;
2143 caloEnergy = previousCaloEnergy;
2150 assert(caloEnergy>=0);
2166 if ( totalChargedMomentum - caloEnergy >
nSigmaTRACK_*Caloresolution ) {
2181 for ( IT it = associatedTracks.begin(); it != associatedTracks.end(); ++it ) {
2182 unsigned iTrack = it->second.first;
2184 if ( !active[iTrack] )
continue;
2186 if ( !it->second.second )
continue;
2188 double trackMomentum = elements[it->second.first].trackRef()->p();
2191 std::multimap<double, unsigned> sortedEcals;
2192 block.associatedElements( iTrack, linkData,
2196 std::multimap<double, unsigned> sortedHOs;
2197 block.associatedElements( iTrack, linkData,
2205 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iTrack );
2206 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
2209 (*pfCandidates_)[tmpi].setHcalEnergy(totalHcal,muonHcal);
2210 if( !sortedEcals.empty() ) {
2211 unsigned iEcal = sortedEcals.begin()->second;
2212 PFClusterRef eclusterref = elements[iEcal].clusterRef();
2213 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal);
2215 (*pfCandidates_)[tmpi].setEcalEnergy(eclusterref->energy(),muonEcal);
2217 if(
useHO_ && !sortedHOs.empty() ) {
2218 unsigned iHO = sortedHOs.begin()->second;
2219 PFClusterRef hoclusterref = elements[iHO].clusterRef();
2220 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHO);
2222 (*pfCandidates_)[tmpi].setHcalEnergy(
max(totalHcal-totalHO,0.0),muonHcal);
2223 (*pfCandidates_)[tmpi].setHoEnergy(hoclusterref->energy(),muonHO);
2229 ::math::XYZVector chargedDirection(chargedPosition.X(), chargedPosition.Y(), chargedPosition.Z());
2230 chargedDirection = chargedDirection.Unit();
2233 if ( totalEcal > 0. )
2235 if ( totalHcal > 0. )
2240 if ( totalHcal >
muonHCAL_[0] ) hadronAtECAL -=
muonHCAL_[0]*calibHcal/totalHcal * chargedDirection;
2241 caloEnergy = calibEcal+calibHcal;
2244 if ( muonHO > 0. ) {
2247 if ( totalHcal > 0. ) {
2248 calibHcal -=
std::min(calibHcal,muonHO_[0]*calibHcal/totalHcal);
2249 totalHcal -=
std::min(totalHcal,muonHO_[0]);
2254 active[iTrack] =
false;
2261 Caloresolution *= totalChargedMomentum;
2262 Caloresolution =
std::sqrt(Caloresolution*Caloresolution + muonHCALError + muonECALError);
2280 unsigned corrTrack = 10000000;
2281 double corrFact = 1.;
2284 totalChargedMomentum - caloEnergy >
nSigmaTRACK_*Caloresolution) {
2286 for ( IT it = associatedTracks.begin(); it != associatedTracks.end(); ++it ) {
2287 unsigned iTrack = it->second.first;
2289 if ( !active[iTrack] )
continue;
2290 const reco::TrackRef& trackref = elements[it->second.first].trackRef();
2292 double dptRel = fabs(it->first)/trackref->pt()*100;
2293 bool isSecondary =
isFromSecInt(elements[iTrack],
"secondary");
2294 bool isPrimary =
isFromSecInt(elements[iTrack],
"primary");
2298 if ( fabs(it->first) <
ptError_ )
break;
2300 double wouldBeTotalChargedMomentum =
2301 totalChargedMomentum - trackref->p();
2305 if ( wouldBeTotalChargedMomentum > caloEnergy ) {
2307 if (
debug_ && isSecondary) {
2308 cout <<
"In bad track rejection step dptRel = " << dptRel <<
" dptRel_DispVtx_ = " <<
dptRel_DispVtx_ << endl;
2309 cout <<
"The calo energy would be still smaller even without this track but it is attached to a NI"<< endl;
2314 active[iTrack] =
false;
2315 totalChargedMomentum = wouldBeTotalChargedMomentum;
2317 std::cout <<
"\tElement " << elements[iTrack]
2318 <<
" rejected (Dpt = " << -it->first
2319 <<
" GeV/c, algo = " << trackref->algo() <<
")" << std::endl;
2322 if(isPrimary)
break;
2324 corrFact = (caloEnergy - wouldBeTotalChargedMomentum)/elements[it->second.first].trackRef()->p();
2325 if ( trackref->p()*corrFact < 0.05 ) {
2327 active[iTrack] =
false;
2329 totalChargedMomentum -= trackref->p()*(1.-corrFact);
2331 std::cout <<
"\tElement " << elements[iTrack]
2332 <<
" (Dpt = " << -it->first
2333 <<
" GeV/c, algo = " << trackref->algo()
2334 <<
") rescaled by " << corrFact
2335 <<
" Now the total charged momentum is " << totalChargedMomentum << endl;
2343 Caloresolution *= totalChargedMomentum;
2344 Caloresolution =
std::sqrt(Caloresolution*Caloresolution + muonHCALError + muonECALError);
2350 sortedTracks.size() > 1 &&
2351 totalChargedMomentum - caloEnergy >
nSigmaTRACK_*Caloresolution ) {
2352 for ( IT it = associatedTracks.begin(); it != associatedTracks.end(); ++it ) {
2353 unsigned iTrack = it->second.first;
2355 if ( !active[iTrack] )
continue;
2357 double dptRel = fabs(it->first)/trackref->pt()*100;
2358 bool isPrimaryOrSecondary =
isFromSecInt(elements[iTrack],
"all");
2366 active[iTrack] =
false;
2367 totalChargedMomentum -= trackref->p();
2370 std::cout <<
"\tElement " << elements[iTrack]
2371 <<
" rejected (Dpt = " << -it->first
2372 <<
" GeV/c, algo = " << trackref->algo() <<
")" << std::endl;
2381 Caloresolution *= totalChargedMomentum;
2382 Caloresolution =
std::sqrt(Caloresolution*Caloresolution + muonHCALError + muonECALError);
2386 for ( IT it = associatedTracks.begin(); it != associatedTracks.end(); ++it ) {
2387 unsigned iTrack = it->second.first;
2388 if ( !active[iTrack] )
continue;
2391 double Dp = trackRef->qoverpError()*trackMomentum*
trackMomentum;
2395 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iTrack );
2396 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
2398 std::pair<II,II> myEcals = associatedEcals.equal_range(iTrack);
2399 for (II
ii=myEcals.first;
ii!=myEcals.second; ++
ii ) {
2400 unsigned iEcal =
ii->second.second;
2401 if ( active[iEcal] )
continue;
2402 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal );
2406 std::pair<II,II> myHOs = associatedHOs.equal_range(iTrack);
2407 for (II
ii=myHOs.first;
ii!=myHOs.second; ++
ii ) {
2408 unsigned iHO =
ii->second.second;
2409 if ( active[iHO] )
continue;
2410 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHO );
2414 if ( iTrack == corrTrack ) {
2415 (*pfCandidates_)[tmpi].rescaleMomentum(corrFact);
2416 trackMomentum *= corrFact;
2418 chargedHadronsIndices.push_back( tmpi );
2419 chargedHadronsInBlock.push_back( iTrack );
2420 active[iTrack] =
false;
2421 hcalP.push_back(trackMomentum);
2422 hcalDP.push_back(Dp);
2423 if (Dp/trackMomentum > maxDPovP) maxDPovP = Dp/
trackMomentum;
2424 sumpError2 += Dp*Dp;
2428 double TotalError =
sqrt(sumpError2 + Caloresolution*Caloresolution);
2431 cout<<
"\tCompare Calo Energy to total charged momentum "<<endl;
2432 cout<<
"\t\tsum p = "<<totalChargedMomentum<<
" +- "<<
sqrt(sumpError2)<<endl;
2433 cout<<
"\t\tsum ecal = "<<totalEcal<<endl;
2434 cout<<
"\t\tsum hcal = "<<totalHcal<<endl;
2435 cout<<
"\t\t => Calo Energy = "<<caloEnergy<<
" +- "<<Caloresolution<<endl;
2436 cout<<
"\t\t => Calo Energy- total charged momentum = " 2437 <<caloEnergy-totalChargedMomentum<<
" +- "<<TotalError<<endl;
2444 double nsigma =
nSigmaHCAL(totalChargedMomentum,hclusterref->positionREP().Eta());
2446 if (
abs(totalChargedMomentum-caloEnergy)<nsigma*TotalError ) {
2452 cout<<
"\t\tcase 1: COMPATIBLE " 2453 <<
"|Calo Energy- total charged momentum| = " 2454 <<
abs(caloEnergy-totalChargedMomentum)
2455 <<
" < "<<nsigma<<
" x "<<TotalError<<endl;
2456 if (maxDPovP < 0.1 )
2457 cout<<
"\t\t\tmax DP/P = "<< maxDPovP
2458 <<
" less than 0.1: do nothing "<<endl;
2460 cout<<
"\t\t\tmax DP/P = "<< maxDPovP
2461 <<
" > 0.1: take weighted averages "<<endl;
2465 if (maxDPovP > 0.1) {
2469 int nrows = chargedHadronsIndices.size();
2470 TMatrixTSym<double>
a (nrows);
2472 TVectorD
check(nrows);
2473 double sigma2E = Caloresolution*Caloresolution;
2474 for(
int i=0;
i<nrows;
i++) {
2475 double sigma2i = hcalDP[
i]*hcalDP[
i];
2477 cout<<
"\t\t\ttrack associated to hcal "<<
i 2478 <<
" P = "<<hcalP[
i]<<
" +- " 2481 a(
i,
i) = 1./sigma2i + 1./sigma2E;
2482 b(
i) = hcalP[
i]/sigma2i + caloEnergy/sigma2E;
2483 for(
int j=0; j<nrows; j++) {
2485 a(
i,j) = 1./sigma2E;
2496 TDecompChol decomp(a);
2498 TVectorD
x = decomp.Solve(b, ok);
2502 for (
int i=0;
i<nrows;
i++){
2504 unsigned ich = chargedHadronsIndices[
i];
2505 double rescaleFactor =
x(
i)/hcalP[
i];
2506 (*pfCandidates_)[ich].rescaleMomentum( rescaleFactor );
2509 cout<<
"\t\t\told p "<<hcalP[
i]
2511 <<
" rescale "<<rescaleFactor<<endl;
2516 cerr<<
"not ok!"<<endl;
2523 else if( caloEnergy > totalChargedMomentum ) {
2542 double eNeutralHadron = caloEnergy - totalChargedMomentum;
2543 double ePhoton = (caloEnergy - totalChargedMomentum) / slopeEcal;
2546 if(!sortedTracks.empty() ){
2547 cout<<
"\t\tcase 2: NEUTRAL DETECTION " 2548 <<caloEnergy<<
" > "<<nsigma<<
"x"<<TotalError
2549 <<
" + "<<totalChargedMomentum<<endl;
2550 cout<<
"\t\tneutral activity detected: "<<endl
2551 <<
"\t\t\t photon = "<<ePhoton<<endl
2552 <<
"\t\t\tor neutral hadron = "<<eNeutralHadron<<endl;
2554 cout<<
"\t\tphoton or hadron ?"<<endl;}
2556 if(sortedTracks.empty() )
2557 cout<<
"\t\tno track -> hadron "<<endl;
2559 cout<<
"\t\t"<<sortedTracks.size()
2560 <<
"tracks -> check if the excess is photonic or hadronic"<<endl;
2564 double ratioMax = 0.;
2566 unsigned maxiEcal= 9999;
2570 for(IE ie = sortedTracks.begin(); ie != sortedTracks.end(); ++ie ) {
2572 unsigned iTrack = ie->second;
2578 assert( !trackRef.
isNull() );
2580 II iae = associatedEcals.find(iTrack);
2582 if( iae == associatedEcals.end() )
continue;
2585 unsigned iEcal = iae->second.second;
2591 assert( !clusterRef.
isNull() );
2593 double pTrack = trackRef->p();
2594 double eECAL = clusterRef->energy();
2595 double eECALOverpTrack = eECAL / pTrack;
2597 if ( eECALOverpTrack > ratioMax ) {
2598 ratioMax = eECALOverpTrack;
2599 maxEcalRef = clusterRef;
2605 std::vector<reco::PFClusterRef> pivotalClusterRef;
2606 std::vector<unsigned> iPivotal;
2607 std::vector<double> particleEnergy, ecalEnergy, hcalEnergy, rawecalEnergy, rawhcalEnergy;
2608 std::vector<::math::XYZVector> particleDirection;
2612 if ( ePhoton < totalEcal || eNeutralHadron-calibEcal < 1E-10 ) {
2613 if ( !maxEcalRef.
isNull() ) {
2615 mergedPhotonEnergy = ePhoton;
2619 if ( !maxEcalRef.
isNull() ) {
2621 mergedPhotonEnergy = totalEcal;
2624 mergedNeutralHadronEnergy = eNeutralHadron-calibEcal;
2627 if ( mergedPhotonEnergy > 0 ) {
2630 if ( ecalClusters.size()<=1 ) {
2631 ecalClusters.clear();
2632 ecalClusters.push_back(make_pair(maxiEcal, photonAtECAL));
2633 sumEcalClusters=
sqrt(photonAtECAL.Mag2());
2635 for(std::vector<std::pair<unsigned,::math::XYZVector> >::const_iterator pae = ecalClusters.begin(); pae != ecalClusters.end(); ++pae ) {
2636 double clusterEnergy=
sqrt(pae->second.Mag2());
2637 particleEnergy.push_back(mergedPhotonEnergy*clusterEnergy/sumEcalClusters);
2638 particleDirection.push_back(pae->second);
2639 ecalEnergy.push_back(mergedPhotonEnergy*clusterEnergy/sumEcalClusters);
2640 hcalEnergy.push_back(0.);
2641 rawecalEnergy.push_back(totalEcal);
2642 rawhcalEnergy.push_back(totalHcal);
2643 pivotalClusterRef.push_back(elements[pae->first].clusterRef());
2644 iPivotal.push_back(pae->first);
2648 if ( mergedNeutralHadronEnergy > 1.0 ) {
2651 if ( ecalClusters.size()<=1 ) {
2652 ecalClusters.clear();
2653 ecalClusters.push_back(make_pair(iHcal, hadronAtECAL));
2654 sumEcalClusters=
sqrt(hadronAtECAL.Mag2());
2656 for(std::vector<std::pair<unsigned,::math::XYZVector> >::const_iterator pae = ecalClusters.begin(); pae != ecalClusters.end(); ++pae ) {
2657 double clusterEnergy=
sqrt(pae->second.Mag2());
2658 particleEnergy.push_back(mergedNeutralHadronEnergy*clusterEnergy/sumEcalClusters);
2659 particleDirection.push_back(pae->second);
2660 ecalEnergy.push_back(0.);
2661 hcalEnergy.push_back(mergedNeutralHadronEnergy*clusterEnergy/sumEcalClusters);
2662 rawecalEnergy.push_back(totalEcal);
2663 rawhcalEnergy.push_back(totalHcal);
2664 pivotalClusterRef.push_back(hclusterref);
2665 iPivotal.push_back(iHcal);
2673 for (
unsigned iPivot=0; iPivot<iPivotal.size(); ++iPivot ) {
2675 if ( particleEnergy[iPivot] < 0. )
2676 std::cout <<
"ALARM = Negative energy ! " 2677 << particleEnergy[iPivot] << std::endl;
2679 bool useDirection =
true;
2681 particleEnergy[iPivot],
2683 particleDirection[iPivot].
X(),
2684 particleDirection[iPivot].
Y(),
2685 particleDirection[iPivot].
Z());
2688 (*pfCandidates_)[tmpi].setEcalEnergy( rawecalEnergy[iPivot],ecalEnergy[iPivot] );
2690 (*pfCandidates_)[tmpi].setHcalEnergy( rawhcalEnergy[iPivot],hcalEnergy[iPivot] );
2691 (*pfCandidates_)[tmpi].setHoEnergy(0., 0.);
2693 (*pfCandidates_)[tmpi].setHcalEnergy(
max(rawhcalEnergy[iPivot]-totalHO,0.0),hcalEnergy[iPivot]*(1.-totalHO/rawhcalEnergy[iPivot]));
2694 (*pfCandidates_)[tmpi].setHoEnergy(totalHO, totalHO * hcalEnergy[iPivot]/rawhcalEnergy[iPivot]);
2696 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
2697 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
2698 (*pfCandidates_)[tmpi].set_mva_nothing_gamma( -1. );
2701 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
2702 for (
unsigned ich=0; ich<chargedHadronsInBlock.size(); ++ich) {
2703 unsigned iTrack = chargedHadronsInBlock[ich];
2704 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iTrack );
2710 std::pair<II,II> myEcals = associatedEcals.equal_range(iTrack);
2711 for (II
ii=myEcals.first;
ii!=myEcals.second; ++
ii ) {
2712 unsigned iEcal =
ii->second.second;
2713 if ( active[iEcal] )
continue;
2714 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal );
2726 double totalHcalEnergyCalibrated = calibHcal;
2727 double totalEcalEnergyCalibrated = calibEcal;
2742 totalHcalEnergyCalibrated -= mergedNeutralHadronEnergy;
2744 totalEcalEnergyCalibrated -= mergedPhotonEnergy;
2749 double chargedHadronsTotalEnergy = 0;
2750 for(
unsigned ich=0; ich<chargedHadronsIndices.size(); ++ich ) {
2751 unsigned index = chargedHadronsIndices[ich];
2753 chargedHadronsTotalEnergy += chargedHadron.
energy();
2756 for(
unsigned ich=0; ich<chargedHadronsIndices.size(); ++ich ) {
2757 unsigned index = chargedHadronsIndices[ich];
2759 float fraction = chargedHadron.
energy()/chargedHadronsTotalEnergy;
2762 chargedHadron.
setHcalEnergy( fraction * totalHcal, fraction * totalHcalEnergyCalibrated );
2765 chargedHadron.
setHcalEnergy( fraction *
max(totalHcal-totalHO,0.0), fraction * totalHcalEnergyCalibrated * (1.-totalHO/totalHcal) );
2766 chargedHadron.
setHoEnergy( fraction * totalHO, fraction * totalHO * totalHcalEnergyCalibrated / totalHcal );
2769 chargedHadron.
setEcalEnergy( fraction * totalEcal, fraction * totalEcalEnergyCalibrated );
2773 for ( IS is = ecalSatellites.begin(); is != ecalSatellites.end(); ++is ) {
2776 unsigned iEcal = is->second.first;
2777 if ( !active[iEcal] )
continue;
2782 PFClusterRef eclusterref = elements[iEcal].clusterRef();
2783 assert(!eclusterref.
isNull() );
2786 active[iEcal] =
false;
2789 std::multimap<double, unsigned> assTracks;
2790 block.associatedElements( iEcal, linkData,
2797 (*pfCandidates_)[tmpi].setEcalEnergy( eclusterref->energy(),
sqrt(is->second.second.Mag2()) );
2798 (*pfCandidates_)[tmpi].setHcalEnergy( 0., 0. );
2799 (*pfCandidates_)[tmpi].setHoEnergy( 0., 0. );
2800 (*pfCandidates_)[tmpi].setPs1Energy( associatedPSs[iEcal].
first );
2801 (*pfCandidates_)[tmpi].setPs2Energy( associatedPSs[iEcal].
second );
2802 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal );
2803 (*pfCandidates_)[tmpi].addElementInBlock( blockref, sortedTracks.begin()->second) ;
2817 <<
"---- loop remaining hcal ------- "<<endl;
2823 for(
unsigned ihcluster=0; ihcluster<hcalIs.size(); ihcluster++) {
2824 unsigned iHcal = hcalIs[ihcluster];
2827 std::vector<unsigned> ecalRefs;
2828 std::vector<unsigned> hoRefs;
2831 cout<<endl<<elements[iHcal]<<
" ";
2834 if( !active[iHcal] ) {
2836 cout<<
"not active"<<endl;
2841 std::multimap<double, unsigned> ecalElems;
2842 block.associatedElements( iHcal, linkData,
2848 float totalEcal = 0.;
2851 for(IE ie = ecalElems.begin(); ie != ecalElems.end(); ++ie ) {
2853 unsigned iEcal = ie->second;
2854 double dist = ie->first;
2859 if( !active[iEcal] )
continue;
2880 std::multimap<double, unsigned> hcalElems;
2881 block.associatedElements( iEcal, linkData,
2886 bool isClosest =
true;
2887 for(IE ih = hcalElems.begin(); ih != hcalElems.end(); ++ih ) {
2889 unsigned jHcal = ih->second;
2890 double distH = ih->first;
2892 if ( !active[jHcal] )
continue;
2894 if ( distH < dist ) {
2901 if (!isClosest)
continue;
2905 cout<<
"\telement "<<elements[iEcal]<<
" linked with dist "<< dist<<endl;
2906 cout<<
"Added to HCAL cluster to form a neutral hadron"<<endl;
2910 assert( !eclusterRef.
isNull() );
2912 double ecalEnergy = eclusterRef->correctedEnergy();
2916 totalEcal += ecalEnergy;
2917 if ( ecalEnergy > ecalMax ) {
2918 ecalMax = ecalEnergy;
2919 eClusterRef = eclusterRef;
2922 ecalRefs.push_back(iEcal);
2923 active[iEcal] =
false;
2929 double totalHO = 0.;
2933 std::multimap<double, unsigned> hoElems;
2934 block.associatedElements( iHcal, linkData,
2944 for(IE ie = hoElems.begin(); ie != hoElems.end(); ++ie ) {
2946 unsigned iHO = ie->second;
2947 double dist = ie->first;
2952 if( !active[iHO] )
continue;
2958 std::multimap<double, unsigned> hcalElems;
2959 block.associatedElements( iHO, linkData,
2964 bool isClosest =
true;
2965 for(IE ih = hcalElems.begin(); ih != hcalElems.end(); ++ih ) {
2967 unsigned jHcal = ih->second;
2968 double distH = ih->first;
2970 if ( !active[jHcal] )
continue;
2972 if ( distH < dist ) {
2979 if (!isClosest)
continue;
2982 cout<<
"\telement "<<elements[iHO]<<
" linked with dist "<< dist<<endl;
2983 cout<<
"Added to HCAL cluster to form a neutral hadron"<<endl;
2987 assert( !hoclusterRef.
isNull() );
2989 double hoEnergy = hoclusterRef->energy();
2991 totalHO += hoEnergy;
2992 if ( hoEnergy > hoMax ) {
2994 hoClusterRef = hoclusterRef;
2998 hoRefs.push_back(iHO);
2999 active[iHO] =
false;
3005 = elements[iHcal].clusterRef();
3006 assert( !hclusterRef.
isNull() );
3009 double totalHcal = hclusterRef->energy();
3011 if (
useHO_ ) totalHcal += totalHO;
3019 double calibEcal = totalEcal > 0. ? totalEcal : 0.;
3020 double calibHcal =
std::max(0.,totalHcal);
3024 calibEcal = totalEcal;
3027 hclusterRef->positionREP().Eta(),
3028 hclusterRef->positionREP().Phi());
3041 calibEcal+calibHcal );
3044 (*pfCandidates_)[tmpi].setEcalEnergy( totalEcal, calibEcal );
3046 (*pfCandidates_)[tmpi].setHcalEnergy( totalHcal, calibHcal );
3047 (*pfCandidates_)[tmpi].setHoEnergy(0.,0.);
3049 (*pfCandidates_)[tmpi].setHcalEnergy(
max(totalHcal-totalHO,0.0), calibHcal*(1.-totalHO/totalHcal));
3050 (*pfCandidates_)[tmpi].setHoEnergy(totalHO,totalHO*calibHcal/totalHcal);
3052 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
3053 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
3054 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
3055 for (
unsigned iec=0; iec<ecalRefs.size(); ++iec)
3056 (*
pfCandidates_)[tmpi].addElementInBlock( blockref, ecalRefs[iec] );
3057 for (
unsigned iho=0; iho<hoRefs.size(); ++iho)
3058 (*
pfCandidates_)[tmpi].addElementInBlock( blockref, hoRefs[iho] );
3067 if(
debug_)
cout<<endl<<
"---- loop ecal------- "<<endl;
3072 for(
unsigned i=0;
i<ecalIs.size();
i++) {
3073 unsigned iEcal = ecalIs[
i];
3076 cout<<endl<<elements[iEcal]<<
" ";
3078 if( ! active[iEcal] ) {
3080 cout<<
"not active"<<endl;
3087 PFClusterRef clusterref = elements[iEcal].clusterRef();
3088 assert(!clusterref.
isNull() );
3090 active[iEcal] =
false;
3092 float ecalEnergy = clusterref->correctedEnergy();
3094 double particleEnergy = ecalEnergy;
3099 (*pfCandidates_)[tmpi].setEcalEnergy( clusterref->energy(),ecalEnergy );
3100 (*pfCandidates_)[tmpi].setHcalEnergy( 0., 0. );
3101 (*pfCandidates_)[tmpi].setHoEnergy( 0., 0. );
3102 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
3103 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
3104 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal );
3123 double px = track.
px();
3124 double py = track.
py();
3125 double pz = track.
pz();
3126 double energy =
sqrt(track.
p()*track.
p() + 0.13957*0.13957);
3138 pfCandidates_->back().setVertexSource( PFCandidate::kTrkVertex );
3153 if ((!isMuon) && isFromDisp) {
3154 double Dpt = trackRef->ptError();
3155 double dptRel = Dpt/trackRef->pt()*100;
3161 cout <<
"Not refitted px = " << px <<
" py = " << py <<
" pz = " << pz <<
" energy = " << energy << endl;
3164 reco::Track trackRefit = vRef->refittedTrack(trackRef);
3169 sqrt(trackRefit.
p()*trackRefit.
p() + 0.13957*0.13957));
3171 cout <<
"Refitted px = " << px <<
" py = " << py <<
" pz = " << pz <<
" energy = " << energy << endl;
3190 double particleEnergy,
3203 if ( useDirection ) {
3204 switch( cluster.
layer() ) {
3207 factor =
std::sqrt(cluster.
position().Perp2()/(particleX*particleX+particleY*particleY));
3213 factor = cluster.
position().Z()/particleZ;
3228 cluster.
position().Y()-vertexPos.Y(),
3229 cluster.
position().Z()-vertexPos.Z());
3231 particleY*factor-vertexPos.Y(),
3232 particleZ*factor-vertexPos.Z() );
3237 clusterPos = useDirection ? particleDirection.Unit() : clusterPos.Unit();
3238 clusterPos *= particleEnergy;
3244 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzM4D<double> >
3245 momentum( clusterPos.X(), clusterPos.Y(), clusterPos.Z(),
mass);
3255 switch( cluster.
layer() ) {
3262 particleType = PFCandidate::h0;
3265 particleType = PFCandidate::h_HF;
3268 particleType = PFCandidate::egamma_HF;
3304 std::array<double,7> energyPerDepth;
3305 std::fill(energyPerDepth.begin(), energyPerDepth.end(), 0.0);
3307 const auto &
hit = *hitRefAndFrac.recHitRef();
3309 if (
hit.depth() == 0) {
3313 if (
hit.depth() < 1 ||
hit.depth() > 7) {
3314 throw cms::Exception(
"CorruptData") <<
"Bogus depth " <<
hit.depth() <<
" at detid " <<
hit.detId() <<
"\n";
3316 energyPerDepth[
hit.depth()-1] += hitRefAndFrac.fraction()*
hit.energy();
3319 double sum = std::accumulate(energyPerDepth.begin(), energyPerDepth.end(), 0.);
3320 std::array<float,7> depthFractions;
3322 for (
unsigned int i = 0;
i < depthFractions.size(); ++
i) {
3323 depthFractions[
i] = energyPerDepth[
i]/sum;
3326 std::fill(depthFractions.begin(), depthFractions.end(), 0.f);
3337 if ( clusterEnergyHCAL < 1. ) clusterEnergyHCAL = 1.;
3339 double resol = fabs(eta) < 1.48 ?
3340 sqrt (1.02*1.02/clusterEnergyHCAL + 0.065*0.065)
3342 sqrt (1.20*1.20/clusterEnergyHCAL + 0.028*0.028);
3350 double nS = fabs(eta) < 1.48 ?
3360 if(!out )
return out;
3362 out<<
"====== Particle Flow Algorithm ======= ";
3369 out<<
"reconstructed particles: "<<endl;
3373 if(!candidates.get() ) {
3374 out<<
"candidates already transfered"<<endl;
3403 std::vector<bool>& active,
3404 std::vector<double>& psEne) {
3412 std::multimap<double, unsigned> sortedPS;
3413 typedef std::multimap<double, unsigned>::iterator IE;
3415 sortedPS, psElementType,
3419 double totalPS = 0.;
3420 for ( IE ips=sortedPS.begin(); ips!=sortedPS.end(); ++ips ) {
3423 unsigned iPS = ips->second;
3427 if (!active[iPS])
continue;
3430 std::multimap<double, unsigned> sortedECAL;
3435 unsigned jEcal = sortedECAL.begin()->second;
3436 if ( jEcal != iEcal )
continue;
3440 assert( pstype == psElementType );
3441 PFClusterRef psclusterref = elements[iPS].clusterRef();
3442 assert(!psclusterref.
isNull() );
3443 totalPS += psclusterref->energy();
3444 psEne[0] += psclusterref->energy();
3445 active[iPS] =
false;
3460 bool bPrimary = (order.find(
"primary") != string::npos);
3461 bool bSecondary = (order.find(
"secondary") != string::npos);
3462 bool bAll = (order.find(
"all") != string::npos);
3467 if (bPrimary && isToDisp)
return true;
3468 if (bSecondary && isFromDisp )
return true;
3469 if (bAll && ( isToDisp || isFromDisp ) )
return true;
3498 std::vector<unsigned int> pfCandidatesToBeRemoved;
3505 double met2 = metX*metX+metY*metY;
3511 double metXCor = metX;
3512 double metYCor = metY;
3513 double sumetCor = sumet;
3514 double met2Cor = met2;
3516 double deltaPhiPt = 100.;
3518 unsigned iCor = 1E9;
3523 double metReduc = -1.;
3537 for(
unsigned j=0; j<pfCandidatesToBeRemoved.size(); ++j) {
3538 if (
i == pfCandidatesToBeRemoved[j] ) skip =
true;
3541 if ( skip )
continue;
3544 deltaPhi = std::acos((metX*pfc.
px()+metY*pfc.
py())/(pfc.
pt()*
std::sqrt(met2)));
3545 deltaPhiPt = deltaPhi*pfc.
pt();
3549 double metXInt = metX - pfc.
px();
3550 double metYInt = metY - pfc.
py();
3551 double sumetInt = sumet - pfc.
pt();
3552 double met2Int = metXInt*metXInt+metYInt*metYInt;
3553 if ( met2Int < met2Cor ) {
3556 metReduc = (met2-met2Int)/met2Int;
3558 sumetCor = sumetInt;
3559 significanceCor =
std::sqrt(met2Cor/sumetCor);
3566 pfCandidatesToBeRemoved.push_back(iCor);
3580 std::cout <<
"Significance reduction = " << significance <<
" -> " 3581 << significanceCor <<
" = " << significanceCor - significance
3583 for(
unsigned j=0; j<pfCandidatesToBeRemoved.size(); ++j) {
3584 std::cout <<
"Removed : " << (*pfCandidates_)[pfCandidatesToBeRemoved[j]] << std::endl;
3586 (*pfCandidates_)[pfCandidatesToBeRemoved[j]].rescaleMomentum(1E-6);
3600 if ( cleanedHits.empty() )
return;
3606 std::vector<unsigned int> hitsToBeAdded;
3613 double met2 = metX*metX+metY*metY;
3614 double met2_Original = met2;
3618 double metXCor = metX;
3619 double metYCor = metY;
3620 double sumetCor = sumet;
3621 double met2Cor = met2;
3623 unsigned iCor = 1E9;
3628 double metReduc = -1.;
3630 for(
unsigned i=0;
i<cleanedHits.size(); ++
i) {
3639 for(
unsigned j=0; j<hitsToBeAdded.size(); ++j) {
3640 if (
i == hitsToBeAdded[j] ) skip =
true;
3643 if ( skip )
continue;
3646 double metXInt = metX + px;
3647 double metYInt = metY + py;
3648 double sumetInt = sumet +
pt;
3649 double met2Int = metXInt*metXInt+metYInt*metYInt;
3652 if ( met2Int < met2Cor ) {
3655 metReduc = (met2-met2Int)/met2Int;
3657 sumetCor = sumetInt;
3666 hitsToBeAdded.push_back(iCor);
3680 std::cout << hitsToBeAdded.size() <<
" hits were re-added " << std::endl;
3684 std::cout <<
"Added after cleaning check : " << std::endl;
3686 for(
unsigned j=0; j<hitsToBeAdded.size(); ++j) {
3687 const PFRecHit&
hit = cleanedHits[hitsToBeAdded[j]];
3706 for(
unsigned ic=0;ic<
size;++ic) {
3715 (*pfCandidates_)[ic].setPFElectronExtraRef(theRef);
3727 (*pfCandidates_)[ic].set_mva_e_pi(it->mvaVariable(PFCandidateElectronExtra::MVA_MVA));
3729 (*pfCandidates_)[ic].setPFElectronExtraRef(theRef);
3730 (*pfCandidates_)[ic].setGsfTrackRef(it->gsfTrackRef());
3738 for(
unsigned ic=0;ic<
size;++ic) {
3746 (*pfElectronCandidates_)[ic].setPFElectronExtraRef(theRef);
3757 for(
unsigned ic=0;ic<
size;++ic) {
3762 for(
unsigned pcextra=0;pcextra<sizePhExtra;++pcextra) {
3765 (*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
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 &)
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
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)
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
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_
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)
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 &)
const std::vector< reco::PFCandidateElectronExtra > & getElectronExtra()
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.
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()
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)
std::vector< double > muonHO_
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_
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
sumPtTrackIsoSlopeForPhoton
double sumPtTrackIsoForEgammaSC_endcap_
std::unique_ptr< reco::PFCandidateCollection > pfElectronCandidates_
the unfiltered electron collection
void setPhotonPrimaryVtx(const reco::Vertex &primary)
const reco::MuonRef & muonRef() const override
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
double sumPtTrackIsoForEgammaSC_barrel_
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
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_
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