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().
size())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.size() )
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.size() )
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.size()) {
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.size() == 0 ) {
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.;
1741 unsigned nMuons = 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);
1886 if(letMuonEatCaloEnergy){
1887 muonHCALEnergy += totalHcal;
1888 if (
useHO_) muonHCALEnergy +=muonHO;
1889 muonHCALError += 0.;
1890 muonECALEnergy += muonEcal;
1891 muonECALError += 0.;
1892 photonAtECAL -= muonEcal*chargedDirection;
1893 hadronAtECAL -= totalHcal*chargedDirection;
1894 if ( !sortedEcals.empty() ) active[iEcal] =
false;
1895 active[iHcal] =
false;
1896 if (
useHO_ && !sortedHOs.empty() ) active[iHO] =
false;
1902 if ( muonHO > 0. ) {
1909 photonAtECAL -= muonECAL_[0]*chargedDirection;
1910 hadronAtECAL -= muonHCAL_[0]*chargedDirection;
1914 active[iTrack] =
false;
1921 if(
debug_)
cout<<
"\t\t"<<elements[iTrack]<<endl;
1929 if ( thisIsALooseMuon && !thisIsAMuon ) nMuons += 1;
1934 double Dpt = trackRef->ptError();
1937 bool isPrimaryOrSecondary =
isFromSecInt(elements[iTrack],
"all");
1939 if ( isPrimaryOrSecondary ) blowError = 1.;
1941 std::pair<unsigned,bool> tkmuon = make_pair(iTrack,thisIsALooseMuon);
1942 associatedTracks.insert( make_pair(-Dpt*blowError, tkmuon) );
1945 double Dp = trackRef->qoverpError()*trackMomentum*
trackMomentum;
1946 sumpError2 += Dp*Dp;
1948 bool connectedToEcal =
false;
1949 if( !sortedEcals.empty() )
1953 for ( IE iec=sortedEcals.begin();
1954 iec!=sortedEcals.end(); ++iec ) {
1956 unsigned iEcal = iec->second;
1957 double dist = iec->first;
1960 if( !active[iEcal] ) {
1968 PFClusterRef eclusterref = elements[iEcal].clusterRef();
1969 assert(!eclusterref.
isNull() );
1972 std::multimap<double, unsigned> sortedTracksEcal;
1973 block.associatedElements( iEcal, linkData,
1977 unsigned jTrack = sortedTracksEcal.
begin()->second;
1978 if ( jTrack != iTrack )
continue;
1982 double distEcal = block.dist(jTrack,iEcal,linkData,
1989 float ecalEnergyCalibrated = eclusterref->correctedEnergy();
1991 eclusterref->position().Y(),
1992 eclusterref->position().Z());
1993 photonDirection = photonDirection.Unit();
1995 if ( !connectedToEcal ) {
1998 <<elements[iEcal]<<endl;
2000 connectedToEcal =
true;
2004 std::pair<unsigned,::math::XYZVector> satellite =
2005 make_pair(iEcal,ecalEnergyCalibrated*photonDirection);
2006 ecalSatellites.insert( make_pair(-1., satellite) );
2010 std::pair<unsigned,::math::XYZVector> satellite =
2011 make_pair(iEcal,ecalEnergyCalibrated*photonDirection);
2012 ecalSatellites.insert( make_pair(dist, satellite) );
2016 std::pair<double, unsigned> associatedEcal
2017 = make_pair( distEcal, iEcal );
2018 associatedEcals.insert( make_pair(iTrack, associatedEcal) );
2023 if(
useHO_ && !sortedHOs.empty() )
2027 for ( IE ieho=sortedHOs.begin(); ieho!=sortedHOs.end(); ++ieho ) {
2029 unsigned iHO = ieho->second;
2030 double distHO = ieho->first;
2033 if( !active[iHO] ) {
2041 PFClusterRef hoclusterref = elements[iHO].clusterRef();
2042 assert(!hoclusterref.
isNull() );
2045 std::multimap<double, unsigned> sortedTracksHO;
2046 block.associatedElements( iHO, linkData,
2050 unsigned jTrack = sortedTracksHO.
begin()->second;
2051 if ( jTrack != iTrack )
continue;
2059 totalHO += hoclusterref->energy();
2060 active[iHO] =
false;
2062 std::pair<double, unsigned> associatedHO
2063 = make_pair( distHO, iHO );
2064 associatedHOs.insert( make_pair(iTrack, associatedHO) );
2073 totalHcal += totalHO;
2077 double caloEnergy = 0.;
2078 double slopeEcal = 1.0;
2079 double calibEcal = 0.;
2080 double calibHcal = 0.;
2081 hadronDirection = hadronAtECAL.Unit();
2085 Caloresolution *= totalChargedMomentum;
2087 Caloresolution =
std::sqrt(Caloresolution*Caloresolution + muonHCALError + muonECALError);
2088 totalEcal -=
std::min(totalEcal,muonECALEnergy);
2089 totalHcal -=
std::min(totalHcal,muonHCALEnergy);
2097 for ( IS is = ecalSatellites.begin(); is != ecalSatellites.end(); ++is ) {
2100 double previousCalibEcal = calibEcal;
2101 double previousCalibHcal = calibHcal;
2102 double previousCaloEnergy = caloEnergy;
2103 double previousSlopeEcal = slopeEcal;
2106 totalEcal +=
sqrt(is->second.second.Mag2());
2107 photonAtECAL += is->second.second;
2108 calibEcal =
std::max(0.,totalEcal);
2109 calibHcal =
std::max(0.,totalHcal);
2110 hadronAtECAL = calibHcal * hadronDirection;
2112 calibration_->energyEmHad(totalChargedMomentum,calibEcal,calibHcal,
2113 hclusterref->positionREP().Eta(),
2114 hclusterref->positionREP().Phi());
2115 caloEnergy = calibEcal+calibHcal;
2116 if ( totalEcal > 0.) slopeEcal = calibEcal/totalEcal;
2118 hadronAtECAL = calibHcal * hadronDirection;
2122 if ( is->first < 0. || caloEnergy - totalChargedMomentum <= 0. ) {
2123 if(
debug_)
cout<<
"\t\t\tactive, adding "<<is->second.second
2124 <<
" to ECAL energy, and locking"<<endl;
2125 active[is->second.first] =
false;
2126 double clusterEnergy=
sqrt(is->second.second.Mag2());
2127 if(clusterEnergy>50) {
2128 ecalClusters.push_back(is->second);
2129 sumEcalClusters+=clusterEnergy;
2136 totalEcal -=
sqrt(is->second.second.Mag2());
2137 photonAtECAL -= is->second.second;
2138 calibEcal = previousCalibEcal;
2139 calibHcal = previousCalibHcal;
2140 hadronAtECAL = previousHadronAtECAL;
2141 slopeEcal = previousSlopeEcal;
2142 caloEnergy = previousCaloEnergy;
2149 assert(caloEnergy>=0);
2165 if ( totalChargedMomentum - caloEnergy >
nSigmaTRACK_*Caloresolution ) {
2180 for ( IT it = associatedTracks.begin(); it != associatedTracks.end(); ++it ) {
2181 unsigned iTrack = it->second.first;
2183 if ( !active[iTrack] )
continue;
2185 if ( !it->second.second )
continue;
2187 double trackMomentum = elements[it->second.first].trackRef()->p();
2190 std::multimap<double, unsigned> sortedEcals;
2191 block.associatedElements( iTrack, linkData,
2195 std::multimap<double, unsigned> sortedHOs;
2196 block.associatedElements( iTrack, linkData,
2204 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iTrack );
2205 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
2208 (*pfCandidates_)[tmpi].setHcalEnergy(totalHcal,muonHcal);
2209 if( !sortedEcals.empty() ) {
2210 unsigned iEcal = sortedEcals.begin()->second;
2211 PFClusterRef eclusterref = elements[iEcal].clusterRef();
2212 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal);
2214 (*pfCandidates_)[tmpi].setEcalEnergy(eclusterref->energy(),muonEcal);
2216 if(
useHO_ && !sortedHOs.empty() ) {
2217 unsigned iHO = sortedHOs.begin()->second;
2218 PFClusterRef hoclusterref = elements[iHO].clusterRef();
2219 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHO);
2221 (*pfCandidates_)[tmpi].setHcalEnergy(
max(totalHcal-totalHO,0.0),muonHcal);
2222 (*pfCandidates_)[tmpi].setHoEnergy(hoclusterref->energy(),muonHO);
2227 ::math::XYZVector chargedDirection(chargedPosition.X(), chargedPosition.Y(), chargedPosition.Z());
2228 chargedDirection = chargedDirection.Unit();
2231 if ( totalEcal > 0. )
2233 if ( totalHcal > 0. )
2238 if ( totalHcal >
muonHCAL_[0] ) hadronAtECAL -=
muonHCAL_[0]*calibHcal/totalHcal * chargedDirection;
2239 caloEnergy = calibEcal+calibHcal;
2242 if ( muonHO > 0. ) {
2245 if ( totalHcal > 0. ) {
2246 calibHcal -=
std::min(calibHcal,muonHO_[0]*calibHcal/totalHcal);
2247 totalHcal -=
std::min(totalHcal,muonHO_[0]);
2252 active[iTrack] =
false;
2259 Caloresolution *= totalChargedMomentum;
2260 Caloresolution =
std::sqrt(Caloresolution*Caloresolution + muonHCALError + muonECALError);
2278 unsigned corrTrack = 10000000;
2279 double corrFact = 1.;
2282 totalChargedMomentum - caloEnergy >
nSigmaTRACK_*Caloresolution) {
2284 for ( IT it = associatedTracks.begin(); it != associatedTracks.end(); ++it ) {
2285 unsigned iTrack = it->second.first;
2287 if ( !active[iTrack] )
continue;
2288 const reco::TrackRef& trackref = elements[it->second.first].trackRef();
2290 double dptRel = fabs(it->first)/trackref->pt()*100;
2291 bool isSecondary =
isFromSecInt(elements[iTrack],
"secondary");
2292 bool isPrimary =
isFromSecInt(elements[iTrack],
"primary");
2296 if ( fabs(it->first) <
ptError_ )
break;
2298 double wouldBeTotalChargedMomentum =
2299 totalChargedMomentum - trackref->p();
2303 if ( wouldBeTotalChargedMomentum > caloEnergy ) {
2305 if (
debug_ && isSecondary) {
2306 cout <<
"In bad track rejection step dptRel = " << dptRel <<
" dptRel_DispVtx_ = " <<
dptRel_DispVtx_ << endl;
2307 cout <<
"The calo energy would be still smaller even without this track but it is attached to a NI"<< endl;
2312 active[iTrack] =
false;
2313 totalChargedMomentum = wouldBeTotalChargedMomentum;
2315 std::cout <<
"\tElement " << elements[iTrack]
2316 <<
" rejected (Dpt = " << -it->first
2317 <<
" GeV/c, algo = " << trackref->algo() <<
")" << std::endl;
2320 if(isPrimary)
break;
2322 corrFact = (caloEnergy - wouldBeTotalChargedMomentum)/elements[it->second.first].trackRef()->p();
2323 if ( trackref->p()*corrFact < 0.05 ) {
2325 active[iTrack] =
false;
2327 totalChargedMomentum -= trackref->p()*(1.-corrFact);
2329 std::cout <<
"\tElement " << elements[iTrack]
2330 <<
" (Dpt = " << -it->first
2331 <<
" GeV/c, algo = " << trackref->algo()
2332 <<
") rescaled by " << corrFact
2333 <<
" Now the total charged momentum is " << totalChargedMomentum << endl;
2341 Caloresolution *= totalChargedMomentum;
2342 Caloresolution =
std::sqrt(Caloresolution*Caloresolution + muonHCALError + muonECALError);
2348 sortedTracks.size() > 1 &&
2349 totalChargedMomentum - caloEnergy >
nSigmaTRACK_*Caloresolution ) {
2350 for ( IT it = associatedTracks.begin(); it != associatedTracks.end(); ++it ) {
2351 unsigned iTrack = it->second.first;
2353 if ( !active[iTrack] )
continue;
2355 double dptRel = fabs(it->first)/trackref->pt()*100;
2356 bool isPrimaryOrSecondary =
isFromSecInt(elements[iTrack],
"all");
2364 active[iTrack] =
false;
2365 totalChargedMomentum -= trackref->p();
2368 std::cout <<
"\tElement " << elements[iTrack]
2369 <<
" rejected (Dpt = " << -it->first
2370 <<
" GeV/c, algo = " << trackref->algo() <<
")" << std::endl;
2379 Caloresolution *= totalChargedMomentum;
2380 Caloresolution =
std::sqrt(Caloresolution*Caloresolution + muonHCALError + muonECALError);
2384 for ( IT it = associatedTracks.begin(); it != associatedTracks.end(); ++it ) {
2385 unsigned iTrack = it->second.first;
2386 if ( !active[iTrack] )
continue;
2389 double Dp = trackRef->qoverpError()*trackMomentum*
trackMomentum;
2393 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iTrack );
2394 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
2395 std::pair<II,II> myEcals = associatedEcals.equal_range(iTrack);
2396 for (II
ii=myEcals.first;
ii!=myEcals.second; ++
ii ) {
2397 unsigned iEcal =
ii->second.second;
2398 if ( active[iEcal] )
continue;
2399 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal );
2403 std::pair<II,II> myHOs = associatedHOs.equal_range(iTrack);
2404 for (II
ii=myHOs.first;
ii!=myHOs.second; ++
ii ) {
2405 unsigned iHO =
ii->second.second;
2406 if ( active[iHO] )
continue;
2407 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHO );
2411 if ( iTrack == corrTrack ) {
2412 (*pfCandidates_)[tmpi].rescaleMomentum(corrFact);
2413 trackMomentum *= corrFact;
2415 chargedHadronsIndices.push_back( tmpi );
2416 chargedHadronsInBlock.push_back( iTrack );
2417 active[iTrack] =
false;
2418 hcalP.push_back(trackMomentum);
2419 hcalDP.push_back(Dp);
2420 if (Dp/trackMomentum > maxDPovP) maxDPovP = Dp/
trackMomentum;
2421 sumpError2 += Dp*Dp;
2425 double TotalError =
sqrt(sumpError2 + Caloresolution*Caloresolution);
2428 cout<<
"\tCompare Calo Energy to total charged momentum "<<endl;
2429 cout<<
"\t\tsum p = "<<totalChargedMomentum<<
" +- "<<
sqrt(sumpError2)<<endl;
2430 cout<<
"\t\tsum ecal = "<<totalEcal<<endl;
2431 cout<<
"\t\tsum hcal = "<<totalHcal<<endl;
2432 cout<<
"\t\t => Calo Energy = "<<caloEnergy<<
" +- "<<Caloresolution<<endl;
2433 cout<<
"\t\t => Calo Energy- total charged momentum = " 2434 <<caloEnergy-totalChargedMomentum<<
" +- "<<TotalError<<endl;
2441 double nsigma =
nSigmaHCAL(totalChargedMomentum,hclusterref->positionREP().Eta());
2443 if (
abs(totalChargedMomentum-caloEnergy)<nsigma*TotalError ) {
2449 cout<<
"\t\tcase 1: COMPATIBLE " 2450 <<
"|Calo Energy- total charged momentum| = " 2451 <<
abs(caloEnergy-totalChargedMomentum)
2452 <<
" < "<<nsigma<<
" x "<<TotalError<<endl;
2453 if (maxDPovP < 0.1 )
2454 cout<<
"\t\t\tmax DP/P = "<< maxDPovP
2455 <<
" less than 0.1: do nothing "<<endl;
2457 cout<<
"\t\t\tmax DP/P = "<< maxDPovP
2458 <<
" > 0.1: take weighted averages "<<endl;
2462 if (maxDPovP > 0.1) {
2466 int nrows = chargedHadronsIndices.size();
2467 TMatrixTSym<double>
a (nrows);
2469 TVectorD
check(nrows);
2470 double sigma2E = Caloresolution*Caloresolution;
2471 for(
int i=0;
i<nrows;
i++) {
2472 double sigma2i = hcalDP[
i]*hcalDP[
i];
2474 cout<<
"\t\t\ttrack associated to hcal "<<
i 2475 <<
" P = "<<hcalP[
i]<<
" +- " 2478 a(
i,
i) = 1./sigma2i + 1./sigma2E;
2479 b(
i) = hcalP[
i]/sigma2i + caloEnergy/sigma2E;
2480 for(
int j=0; j<nrows; j++) {
2482 a(
i,j) = 1./sigma2E;
2493 TDecompChol decomp(a);
2495 TVectorD
x = decomp.Solve(b, ok);
2499 for (
int i=0;
i<nrows;
i++){
2501 unsigned ich = chargedHadronsIndices[
i];
2502 double rescaleFactor =
x(
i)/hcalP[
i];
2503 (*pfCandidates_)[ich].rescaleMomentum( rescaleFactor );
2506 cout<<
"\t\t\told p "<<hcalP[
i]
2508 <<
" rescale "<<rescaleFactor<<endl;
2513 cerr<<
"not ok!"<<endl;
2520 else if( caloEnergy > totalChargedMomentum ) {
2539 double eNeutralHadron = caloEnergy - totalChargedMomentum;
2540 double ePhoton = (caloEnergy - totalChargedMomentum) / slopeEcal;
2543 if(!sortedTracks.empty() ){
2544 cout<<
"\t\tcase 2: NEUTRAL DETECTION " 2545 <<caloEnergy<<
" > "<<nsigma<<
"x"<<TotalError
2546 <<
" + "<<totalChargedMomentum<<endl;
2547 cout<<
"\t\tneutral activity detected: "<<endl
2548 <<
"\t\t\t photon = "<<ePhoton<<endl
2549 <<
"\t\t\tor neutral hadron = "<<eNeutralHadron<<endl;
2551 cout<<
"\t\tphoton or hadron ?"<<endl;}
2553 if(sortedTracks.empty() )
2554 cout<<
"\t\tno track -> hadron "<<endl;
2556 cout<<
"\t\t"<<sortedTracks.size()
2557 <<
"tracks -> check if the excess is photonic or hadronic"<<endl;
2561 double ratioMax = 0.;
2563 unsigned maxiEcal= 9999;
2567 for(IE ie = sortedTracks.begin(); ie != sortedTracks.end(); ++ie ) {
2569 unsigned iTrack = ie->second;
2575 assert( !trackRef.
isNull() );
2577 II iae = associatedEcals.find(iTrack);
2579 if( iae == associatedEcals.end() )
continue;
2582 unsigned iEcal = iae->second.second;
2588 assert( !clusterRef.
isNull() );
2590 double pTrack = trackRef->p();
2591 double eECAL = clusterRef->energy();
2592 double eECALOverpTrack = eECAL / pTrack;
2594 if ( eECALOverpTrack > ratioMax ) {
2595 ratioMax = eECALOverpTrack;
2596 maxEcalRef = clusterRef;
2602 std::vector<reco::PFClusterRef> pivotalClusterRef;
2603 std::vector<unsigned> iPivotal;
2604 std::vector<double> particleEnergy, ecalEnergy, hcalEnergy, rawecalEnergy, rawhcalEnergy;
2605 std::vector<::math::XYZVector> particleDirection;
2609 if ( ePhoton < totalEcal || eNeutralHadron-calibEcal < 1E-10 ) {
2610 if ( !maxEcalRef.
isNull() ) {
2612 mergedPhotonEnergy = ePhoton;
2616 if ( !maxEcalRef.
isNull() ) {
2618 mergedPhotonEnergy = totalEcal;
2621 mergedNeutralHadronEnergy = eNeutralHadron-calibEcal;
2624 if ( mergedPhotonEnergy > 0 ) {
2627 if ( ecalClusters.size()<=1 ) {
2628 ecalClusters.clear();
2629 ecalClusters.push_back(make_pair(maxiEcal, photonAtECAL));
2630 sumEcalClusters=
sqrt(photonAtECAL.Mag2());
2632 for(std::vector<std::pair<unsigned,::math::XYZVector> >::const_iterator pae = ecalClusters.begin(); pae != ecalClusters.end(); ++pae ) {
2633 double clusterEnergy=
sqrt(pae->second.Mag2());
2634 particleEnergy.push_back(mergedPhotonEnergy*clusterEnergy/sumEcalClusters);
2635 particleDirection.push_back(pae->second);
2636 ecalEnergy.push_back(mergedPhotonEnergy*clusterEnergy/sumEcalClusters);
2637 hcalEnergy.push_back(0.);
2638 rawecalEnergy.push_back(totalEcal);
2639 rawhcalEnergy.push_back(totalHcal);
2640 pivotalClusterRef.push_back(elements[pae->first].clusterRef());
2641 iPivotal.push_back(pae->first);
2645 if ( mergedNeutralHadronEnergy > 1.0 ) {
2648 if ( ecalClusters.size()<=1 ) {
2649 ecalClusters.clear();
2650 ecalClusters.push_back(make_pair(iHcal, hadronAtECAL));
2651 sumEcalClusters=
sqrt(hadronAtECAL.Mag2());
2653 for(std::vector<std::pair<unsigned,::math::XYZVector> >::const_iterator pae = ecalClusters.begin(); pae != ecalClusters.end(); ++pae ) {
2654 double clusterEnergy=
sqrt(pae->second.Mag2());
2655 particleEnergy.push_back(mergedNeutralHadronEnergy*clusterEnergy/sumEcalClusters);
2656 particleDirection.push_back(pae->second);
2657 ecalEnergy.push_back(0.);
2658 hcalEnergy.push_back(mergedNeutralHadronEnergy*clusterEnergy/sumEcalClusters);
2659 rawecalEnergy.push_back(totalEcal);
2660 rawhcalEnergy.push_back(totalHcal);
2661 pivotalClusterRef.push_back(hclusterref);
2662 iPivotal.push_back(iHcal);
2670 for (
unsigned iPivot=0; iPivot<iPivotal.size(); ++iPivot ) {
2672 if ( particleEnergy[iPivot] < 0. )
2673 std::cout <<
"ALARM = Negative energy ! " 2674 << particleEnergy[iPivot] << std::endl;
2676 bool useDirection =
true;
2678 particleEnergy[iPivot],
2680 particleDirection[iPivot].
X(),
2681 particleDirection[iPivot].
Y(),
2682 particleDirection[iPivot].
Z());
2685 (*pfCandidates_)[tmpi].setEcalEnergy( rawecalEnergy[iPivot],ecalEnergy[iPivot] );
2687 (*pfCandidates_)[tmpi].setHcalEnergy( rawhcalEnergy[iPivot],hcalEnergy[iPivot] );
2688 (*pfCandidates_)[tmpi].setHoEnergy(0., 0.);
2690 (*pfCandidates_)[tmpi].setHcalEnergy(
max(rawhcalEnergy[iPivot]-totalHO,0.0),hcalEnergy[iPivot]*(1.-totalHO/rawhcalEnergy[iPivot]));
2691 (*pfCandidates_)[tmpi].setHoEnergy(totalHO, totalHO * hcalEnergy[iPivot]/rawhcalEnergy[iPivot]);
2693 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
2694 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
2695 (*pfCandidates_)[tmpi].set_mva_nothing_gamma( -1. );
2698 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
2699 for (
unsigned ich=0; ich<chargedHadronsInBlock.size(); ++ich) {
2700 unsigned iTrack = chargedHadronsInBlock[ich];
2701 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iTrack );
2707 std::pair<II,II> myEcals = associatedEcals.equal_range(iTrack);
2708 for (II
ii=myEcals.first;
ii!=myEcals.second; ++
ii ) {
2709 unsigned iEcal =
ii->second.second;
2710 if ( active[iEcal] )
continue;
2711 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal );
2723 double totalHcalEnergyCalibrated = calibHcal;
2724 double totalEcalEnergyCalibrated = calibEcal;
2739 totalHcalEnergyCalibrated -= mergedNeutralHadronEnergy;
2741 totalEcalEnergyCalibrated -= mergedPhotonEnergy;
2746 double chargedHadronsTotalEnergy = 0;
2747 for(
unsigned ich=0; ich<chargedHadronsIndices.size(); ++ich ) {
2748 unsigned index = chargedHadronsIndices[ich];
2750 chargedHadronsTotalEnergy += chargedHadron.
energy();
2753 for(
unsigned ich=0; ich<chargedHadronsIndices.size(); ++ich ) {
2754 unsigned index = chargedHadronsIndices[ich];
2756 float fraction = chargedHadron.
energy()/chargedHadronsTotalEnergy;
2759 chargedHadron.
setHcalEnergy( fraction * totalHcal, fraction * totalHcalEnergyCalibrated );
2762 chargedHadron.
setHcalEnergy( fraction *
max(totalHcal-totalHO,0.0), fraction * totalHcalEnergyCalibrated * (1.-totalHO/totalHcal) );
2763 chargedHadron.
setHoEnergy( fraction * totalHO, fraction * totalHO * totalHcalEnergyCalibrated / totalHcal );
2766 chargedHadron.
setEcalEnergy( fraction * totalEcal, fraction * totalEcalEnergyCalibrated );
2770 for ( IS is = ecalSatellites.begin(); is != ecalSatellites.end(); ++is ) {
2773 unsigned iEcal = is->second.first;
2774 if ( !active[iEcal] )
continue;
2779 PFClusterRef eclusterref = elements[iEcal].clusterRef();
2780 assert(!eclusterref.
isNull() );
2783 active[iEcal] =
false;
2786 std::multimap<double, unsigned> assTracks;
2787 block.associatedElements( iEcal, linkData,
2794 (*pfCandidates_)[tmpi].setEcalEnergy( eclusterref->energy(),
sqrt(is->second.second.Mag2()) );
2795 (*pfCandidates_)[tmpi].setHcalEnergy( 0., 0. );
2796 (*pfCandidates_)[tmpi].setHoEnergy( 0., 0. );
2797 (*pfCandidates_)[tmpi].setPs1Energy( associatedPSs[iEcal].
first );
2798 (*pfCandidates_)[tmpi].setPs2Energy( associatedPSs[iEcal].
second );
2799 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal );
2800 (*pfCandidates_)[tmpi].addElementInBlock( blockref, sortedTracks.begin()->second) ;
2814 <<
"---- loop remaining hcal ------- "<<endl;
2820 for(
unsigned ihcluster=0; ihcluster<hcalIs.size(); ihcluster++) {
2821 unsigned iHcal = hcalIs[ihcluster];
2824 std::vector<unsigned> ecalRefs;
2825 std::vector<unsigned> hoRefs;
2828 cout<<endl<<elements[iHcal]<<
" ";
2831 if( !active[iHcal] ) {
2833 cout<<
"not active"<<endl;
2838 std::multimap<double, unsigned> ecalElems;
2839 block.associatedElements( iHcal, linkData,
2845 float totalEcal = 0.;
2848 for(IE ie = ecalElems.begin(); ie != ecalElems.end(); ++ie ) {
2850 unsigned iEcal = ie->second;
2851 double dist = ie->first;
2856 if( !active[iEcal] )
continue;
2877 std::multimap<double, unsigned> hcalElems;
2878 block.associatedElements( iEcal, linkData,
2883 bool isClosest =
true;
2884 for(IE ih = hcalElems.begin(); ih != hcalElems.end(); ++ih ) {
2886 unsigned jHcal = ih->second;
2887 double distH = ih->first;
2889 if ( !active[jHcal] )
continue;
2891 if ( distH < dist ) {
2898 if (!isClosest)
continue;
2902 cout<<
"\telement "<<elements[iEcal]<<
" linked with dist "<< dist<<endl;
2903 cout<<
"Added to HCAL cluster to form a neutral hadron"<<endl;
2907 assert( !eclusterRef.
isNull() );
2909 double ecalEnergy = eclusterRef->correctedEnergy();
2913 totalEcal += ecalEnergy;
2914 if ( ecalEnergy > ecalMax ) {
2915 ecalMax = ecalEnergy;
2916 eClusterRef = eclusterRef;
2919 ecalRefs.push_back(iEcal);
2920 active[iEcal] =
false;
2926 double totalHO = 0.;
2930 std::multimap<double, unsigned> hoElems;
2931 block.associatedElements( iHcal, linkData,
2941 for(IE ie = hoElems.begin(); ie != hoElems.end(); ++ie ) {
2943 unsigned iHO = ie->second;
2944 double dist = ie->first;
2949 if( !active[iHO] )
continue;
2955 std::multimap<double, unsigned> hcalElems;
2956 block.associatedElements( iHO, linkData,
2961 bool isClosest =
true;
2962 for(IE ih = hcalElems.begin(); ih != hcalElems.end(); ++ih ) {
2964 unsigned jHcal = ih->second;
2965 double distH = ih->first;
2967 if ( !active[jHcal] )
continue;
2969 if ( distH < dist ) {
2976 if (!isClosest)
continue;
2979 cout<<
"\telement "<<elements[iHO]<<
" linked with dist "<< dist<<endl;
2980 cout<<
"Added to HCAL cluster to form a neutral hadron"<<endl;
2984 assert( !hoclusterRef.
isNull() );
2986 double hoEnergy = hoclusterRef->energy();
2988 totalHO += hoEnergy;
2989 if ( hoEnergy > hoMax ) {
2991 hoClusterRef = hoclusterRef;
2995 hoRefs.push_back(iHO);
2996 active[iHO] =
false;
3002 = elements[iHcal].clusterRef();
3003 assert( !hclusterRef.
isNull() );
3006 double totalHcal = hclusterRef->energy();
3008 if (
useHO_ ) totalHcal += totalHO;
3016 double calibEcal = totalEcal > 0. ? totalEcal : 0.;
3017 double calibHcal =
std::max(0.,totalHcal);
3021 calibEcal = totalEcal;
3024 hclusterRef->positionREP().Eta(),
3025 hclusterRef->positionREP().Phi());
3038 calibEcal+calibHcal );
3041 (*pfCandidates_)[tmpi].setEcalEnergy( totalEcal, calibEcal );
3043 (*pfCandidates_)[tmpi].setHcalEnergy( totalHcal, calibHcal );
3044 (*pfCandidates_)[tmpi].setHoEnergy(0.,0.);
3046 (*pfCandidates_)[tmpi].setHcalEnergy(
max(totalHcal-totalHO,0.0), calibHcal*(1.-totalHO/totalHcal));
3047 (*pfCandidates_)[tmpi].setHoEnergy(totalHO,totalHO*calibHcal/totalHcal);
3049 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
3050 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
3051 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
3052 for (
unsigned iec=0; iec<ecalRefs.size(); ++iec)
3053 (*
pfCandidates_)[tmpi].addElementInBlock( blockref, ecalRefs[iec] );
3054 for (
unsigned iho=0; iho<hoRefs.size(); ++iho)
3055 (*
pfCandidates_)[tmpi].addElementInBlock( blockref, hoRefs[iho] );
3064 if(
debug_)
cout<<endl<<
"---- loop ecal------- "<<endl;
3069 for(
unsigned i=0;
i<ecalIs.size();
i++) {
3070 unsigned iEcal = ecalIs[
i];
3073 cout<<endl<<elements[iEcal]<<
" ";
3075 if( ! active[iEcal] ) {
3077 cout<<
"not active"<<endl;
3084 PFClusterRef clusterref = elements[iEcal].clusterRef();
3085 assert(!clusterref.
isNull() );
3087 active[iEcal] =
false;
3089 float ecalEnergy = clusterref->correctedEnergy();
3091 double particleEnergy = ecalEnergy;
3096 (*pfCandidates_)[tmpi].setEcalEnergy( clusterref->energy(),ecalEnergy );
3097 (*pfCandidates_)[tmpi].setHcalEnergy( 0., 0. );
3098 (*pfCandidates_)[tmpi].setHoEnergy( 0., 0. );
3099 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
3100 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
3101 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal );
3120 double px = track.
px();
3121 double py = track.
py();
3122 double pz = track.
pz();
3123 double energy =
sqrt(track.
p()*track.
p() + 0.13957*0.13957);
3135 pfCandidates_->back().setVertexSource( PFCandidate::kTrkVertex );
3150 if ((!isMuon) && isFromDisp) {
3151 double Dpt = trackRef->ptError();
3152 double dptRel = Dpt/trackRef->pt()*100;
3158 cout <<
"Not refitted px = " << px <<
" py = " << py <<
" pz = " << pz <<
" energy = " << energy << endl;
3161 reco::Track trackRefit = vRef->refittedTrack(trackRef);
3166 sqrt(trackRefit.
p()*trackRefit.
p() + 0.13957*0.13957));
3168 cout <<
"Refitted px = " << px <<
" py = " << py <<
" pz = " << pz <<
" energy = " << energy << endl;
3187 double particleEnergy,
3200 if ( useDirection ) {
3201 switch( cluster.
layer() ) {
3204 factor =
std::sqrt(cluster.
position().Perp2()/(particleX*particleX+particleY*particleY));
3210 factor = cluster.
position().Z()/particleZ;
3225 cluster.
position().Y()-vertexPos.Y(),
3226 cluster.
position().Z()-vertexPos.Z());
3228 particleY*factor-vertexPos.Y(),
3229 particleZ*factor-vertexPos.Z() );
3234 clusterPos = useDirection ? particleDirection.Unit() : clusterPos.Unit();
3235 clusterPos *= particleEnergy;
3241 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzM4D<double> >
3242 momentum( clusterPos.X(), clusterPos.Y(), clusterPos.Z(),
mass);
3252 switch( cluster.
layer() ) {
3259 particleType = PFCandidate::h0;
3262 particleType = PFCandidate::h_HF;
3265 particleType = PFCandidate::egamma_HF;
3304 if ( clusterEnergyHCAL < 1. ) clusterEnergyHCAL = 1.;
3306 double resol = fabs(eta) < 1.48 ?
3307 sqrt (1.02*1.02/clusterEnergyHCAL + 0.065*0.065)
3309 sqrt (1.20*1.20/clusterEnergyHCAL + 0.028*0.028);
3317 double nS = fabs(eta) < 1.48 ?
3327 if(!out )
return out;
3329 out<<
"====== Particle Flow Algorithm ======= ";
3336 out<<
"reconstructed particles: "<<endl;
3340 if(!candidates.get() ) {
3341 out<<
"candidates already transfered"<<endl;
3370 std::vector<bool>& active,
3371 std::vector<double>& psEne) {
3379 std::multimap<double, unsigned> sortedPS;
3380 typedef std::multimap<double, unsigned>::iterator IE;
3382 sortedPS, psElementType,
3386 double totalPS = 0.;
3387 for ( IE ips=sortedPS.begin(); ips!=sortedPS.end(); ++ips ) {
3390 unsigned iPS = ips->second;
3394 if (!active[iPS])
continue;
3397 std::multimap<double, unsigned> sortedECAL;
3402 unsigned jEcal = sortedECAL.begin()->second;
3403 if ( jEcal != iEcal )
continue;
3407 assert( pstype == psElementType );
3408 PFClusterRef psclusterref = elements[iPS].clusterRef();
3409 assert(!psclusterref.
isNull() );
3410 totalPS += psclusterref->energy();
3411 psEne[0] += psclusterref->energy();
3412 active[iPS] =
false;
3427 bool bPrimary = (order.find(
"primary") != string::npos);
3428 bool bSecondary = (order.find(
"secondary") != string::npos);
3429 bool bAll = (order.find(
"all") != string::npos);
3434 if (bPrimary && isToDisp)
return true;
3435 if (bSecondary && isFromDisp )
return true;
3436 if (bAll && ( isToDisp || isFromDisp ) )
return true;
3465 std::vector<unsigned int> pfCandidatesToBeRemoved;
3472 double met2 = metX*metX+metY*metY;
3474 double significance =
std::sqrt(met2/sumet);
3475 double significanceCor = significance;
3478 double metXCor = metX;
3479 double metYCor = metY;
3480 double sumetCor = sumet;
3481 double met2Cor = met2;
3483 double deltaPhiPt = 100.;
3485 unsigned iCor = 1E9;
3490 double metReduc = -1.;
3504 for(
unsigned j=0; j<pfCandidatesToBeRemoved.size(); ++j) {
3505 if (
i == pfCandidatesToBeRemoved[j] ) skip =
true;
3508 if ( skip )
continue;
3511 deltaPhi = std::acos((metX*pfc.
px()+metY*pfc.
py())/(pfc.
pt()*
std::sqrt(met2)));
3512 deltaPhiPt = deltaPhi*pfc.
pt();
3516 double metXInt = metX - pfc.
px();
3517 double metYInt = metY - pfc.
py();
3518 double sumetInt = sumet - pfc.
pt();
3519 double met2Int = metXInt*metXInt+metYInt*metYInt;
3520 if ( met2Int < met2Cor ) {
3523 metReduc = (met2-met2Int)/met2Int;
3525 sumetCor = sumetInt;
3526 significanceCor =
std::sqrt(met2Cor/sumetCor);
3533 pfCandidatesToBeRemoved.push_back(iCor);
3547 std::cout <<
"Significance reduction = " << significance <<
" -> " 3548 << significanceCor <<
" = " << significanceCor - significance
3550 for(
unsigned j=0; j<pfCandidatesToBeRemoved.size(); ++j) {
3551 std::cout <<
"Removed : " << (*pfCandidates_)[pfCandidatesToBeRemoved[j]] << std::endl;
3553 (*pfCandidates_)[pfCandidatesToBeRemoved[j]].rescaleMomentum(1E-6);
3567 if ( !cleanedHits.size() )
return;
3573 std::vector<unsigned int> hitsToBeAdded;
3580 double met2 = metX*metX+metY*metY;
3581 double met2_Original = met2;
3585 double metXCor = metX;
3586 double metYCor = metY;
3587 double sumetCor = sumet;
3588 double met2Cor = met2;
3590 unsigned iCor = 1E9;
3595 double metReduc = -1.;
3597 for(
unsigned i=0;
i<cleanedHits.size(); ++
i) {
3606 for(
unsigned j=0; j<hitsToBeAdded.size(); ++j) {
3607 if (
i == hitsToBeAdded[j] ) skip =
true;
3610 if ( skip )
continue;
3613 double metXInt = metX + px;
3614 double metYInt = metY + py;
3615 double sumetInt = sumet +
pt;
3616 double met2Int = metXInt*metXInt+metYInt*metYInt;
3619 if ( met2Int < met2Cor ) {
3622 metReduc = (met2-met2Int)/met2Int;
3624 sumetCor = sumetInt;
3633 hitsToBeAdded.push_back(iCor);
3647 std::cout << hitsToBeAdded.size() <<
" hits were re-added " << std::endl;
3651 std::cout <<
"Added after cleaning check : " << std::endl;
3653 for(
unsigned j=0; j<hitsToBeAdded.size(); ++j) {
3654 const PFRecHit&
hit = cleanedHits[hitsToBeAdded[j]];
3673 for(
unsigned ic=0;ic<
size;++ic) {
3682 (*pfCandidates_)[ic].setPFElectronExtraRef(theRef);
3694 (*pfCandidates_)[ic].set_mva_e_pi(it->mvaVariable(PFCandidateElectronExtra::MVA_MVA));
3696 (*pfCandidates_)[ic].setPFElectronExtraRef(theRef);
3697 (*pfCandidates_)[ic].setGsfTrackRef(it->gsfTrackRef());
3705 for(
unsigned ic=0;ic<
size;++ic) {
3713 (*pfElectronCandidates_)[ic].setPFElectronExtraRef(theRef);
3724 for(
unsigned ic=0;ic<
size;++ic) {
3729 for(
unsigned pcextra=0;pcextra<sizePhExtra;++pcextra) {
3732 (*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
virtual double pt() const final
transverse momentum
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.
ParticleType
particle types
bool isNonnull() const
Checks for non-null.
T y() const
Cartesian y coordinate.
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
virtual double eta() const final
momentum pseudorapidity
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 &)
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 > &)
math::Error< dimension >::type Error
covariance error matrix (3x3)
std::vector< Vertex > VertexCollection
collection of Vertex objects
const edm::OwnVector< reco::PFBlockElement > & elements() const
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
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)
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
virtual double phi() const final
momentum azimuthal angle
bool useEGammaSupercluster_
U second(std::pair< T, U > const &p)
std::unique_ptr< reco::PFCandidateCollection > pfCleanedCandidates_
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
virtual int charge() const final
electric charge
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.
virtual double px() const final
x coordinate of momentum vector
void setParticleType(ParticleType type)
set Particle Type
bool passPhotonSelection(const reco::Photon &)
const std::vector< reco::PFCandidateElectronExtra > & getElectronExtra()
virtual double energy() const final
energy
virtual void setCharge(Charge q) final
set electric charge
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
std::unique_ptr< reco::PFCandidateCollection > pfPhotonCandidates_
the unfiltered photon collection
const std::vector< reco::PFCandidate > & getElectronCandidates()
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)
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)
virtual void setP4(const LorentzVector &p4) final
set 4-momentum
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
const PFDisplacedTrackerVertexRef & displacedVertexRef(TrackType trType) const
PFMuonAlgo * getPFMuonAlgo()
bool useEGammaFilters_
Variables for NEW EGAMMA selection.
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
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 *)
bool isPhotonSafeForJetMET(const reco::Photon &, const reco::PFCandidate &)
virtual double py() const final
y coordinate of momentum vector
double sumPtTrackIsoForEgammaSC_barrel_
void setHcalEnergy(float ehRaw, float ehCorr)
set corrected Hcal energy
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