39 #include "Math/PxPyPzM4D.h"
40 #include "Math/LorentzVector.h"
41 #include "Math/DisplacementVector3D.h"
42 #include "Math/SMatrix.h"
43 #include "TDecompChol.h"
45 #include "boost/graph/adjacency_matrix.hpp"
46 #include "boost/graph/graph_utility.hpp"
52 using namespace boost;
54 typedef std::list< reco::PFBlockRef >::iterator
IBR;
80 const boost::shared_ptr<PFEnergyCalibration>& calibration,
81 const boost::shared_ptr<PFEnergyCalibrationHF>& thepfEnergyCalibrationHF) {
99 string mvaWeightFileEleID,
101 const boost::shared_ptr<PFSCEnergyCalibration>& thePFSCEnergyCalibration,
102 const boost::shared_ptr<PFEnergyCalibration>& thePFEnergyCalibration,
103 double sumEtEcalIsoForEgammaSC_barrel,
104 double sumEtEcalIsoForEgammaSC_endcap,
105 double coneEcalIsoForEgammaSC,
106 double sumPtTrackIsoForEgammaSC_barrel,
107 double sumPtTrackIsoForEgammaSC_endcap,
108 unsigned int nTrackIsoForEgammaSC,
109 double coneTrackIsoForEgammaSC,
110 bool applyCrackCorrections,
111 bool usePFSCEleCalib,
113 bool useEGammaSupercluster) {
138 string err =
"PFAlgo: cannot open weight file '";
139 err += mvaWeightFileEleID;
141 throw invalid_argument( err );
145 thePFEnergyCalibration,
165 const boost::shared_ptr<PFEnergyCalibration>& thePFEnergyCalibration,
166 double sumPtTrackIsoForPhoton,
167 double sumPtTrackIsoSlopeForPhoton)
180 e(0, 0) = 0.0015 * 0.0015;
181 e(1, 1) = 0.0015 * 0.0015;
188 FILE * filePhotonConvID = fopen(mvaWeightFileConvID.c_str(),
"r");
189 if (filePhotonConvID) {
190 fclose(filePhotonConvID);
193 string err =
"PFAlgo: cannot open weight file '";
194 err += mvaWeightFileConvID;
196 throw invalid_argument( err );
204 thePFEnergyCalibration,
205 sumPtTrackIsoForPhoton,
206 sumPtTrackIsoSlopeForPhoton
214 double ele_iso_mva_barrel,
215 double ele_iso_mva_endcap,
216 double ele_iso_combIso_barrel,
217 double ele_iso_combIso_endcap,
218 double ele_noniso_mva,
219 unsigned int ele_missinghits,
220 bool useProtectionsForJetMET,
225 double ph_sietaieta_eb,
226 double ph_sietaieta_ee,
234 FILE * fileEGamma_ele_iso_ID = fopen(ele_iso_path_mvaWeightFile.c_str(),
"r");
235 if (fileEGamma_ele_iso_ID) {
236 fclose(fileEGamma_ele_iso_ID);
239 string err =
"PFAlgo: cannot open weight file '";
240 err += ele_iso_path_mvaWeightFile;
242 throw invalid_argument( err );
253 ph_protectionsForJetMET,
257 ele_iso_combIso_barrel,
258 ele_iso_combIso_endcap,
261 ele_iso_path_mvaWeightFile,
262 ele_protectionsForJetMET);
297 GCorrForestBarrel, GCorrForestEndcapHr9,
298 GCorrForestEndcapLr9, PFEcalResolution);
320 assert (
muonHCAL_.size() == 2 && muonECAL_.size() == 2 && muonHO_.size() == 2);
324 assert ( factors45_.size() == 2 );
337 double minHFCleaningPt,
338 double minSignificance,
339 double maxSignificance,
340 double minSignificanceReduction,
341 double maxDeltaPhiPt,
342 double minDeltaMet) {
354 bool rejectTracks_Step45,
355 bool usePFNuclearInteractions,
356 bool usePFConversions,
358 double dptRel_DispVtx){
380 bool primaryVertexFound =
false;
381 nVtx_ = primaryVertices->size();
385 for (
unsigned short i=0 ;
i<primaryVertices->size();++
i)
387 if(primaryVertices->at(
i).isValid()&&(!primaryVertices->at(
i).isFake()))
390 primaryVertexFound =
true;
402 e(0, 0) = 0.0015 * 0.0015;
403 e(1, 1) = 0.0015 * 0.0015;
451 cout<<
"*********************************************************"<<endl;
452 cout<<
"***** Particle flow algorithm *****"<<endl;
453 cout<<
"*********************************************************"<<endl;
457 std::list< reco::PFBlockRef > hcalBlockRefs;
458 std::list< reco::PFBlockRef > ecalBlockRefs;
459 std::list< reco::PFBlockRef > hoBlockRefs;
460 std::list< reco::PFBlockRef > otherBlockRefs;
462 for(
unsigned i=0;
i<blocks.size(); ++
i ) {
470 bool singleEcalOrHcal =
false;
471 if( elements.
size() == 1 ){
473 ecalBlockRefs.push_back( blockref );
474 singleEcalOrHcal =
true;
477 hcalBlockRefs.push_back( blockref );
478 singleEcalOrHcal =
true;
482 hoBlockRefs.push_back( blockref );
483 singleEcalOrHcal =
true;
487 if(!singleEcalOrHcal) {
488 otherBlockRefs.push_back( blockref );
493 cout<<
"# Ecal blocks: "<<ecalBlockRefs.size()
494 <<
", # Hcal blocks: "<<hcalBlockRefs.size()
495 <<
", # HO blocks: "<<hoBlockRefs.size()
496 <<
", # Other blocks: "<<otherBlockRefs.size()<<endl;
504 for(
IBR io = otherBlockRefs.begin(); io!=otherBlockRefs.end(); ++io) {
509 std::list< reco::PFBlockRef >
empty;
513 for(
IBR ih = hcalBlockRefs.begin(); ih!=hcalBlockRefs.end(); ++ih) {
514 if (
debug_ )
std::cout <<
"HCAL block number " << hblcks++ << std::endl;
520 for(
IBR ie = ecalBlockRefs.begin(); ie!=ecalBlockRefs.end(); ++ie) {
521 if (
debug_ )
std::cout <<
"ECAL block number " << eblcks++ << std::endl;
538 std::list<reco::PFBlockRef>& hcalBlockRefs,
539 std::list<reco::PFBlockRef>& ecalBlockRefs ) {
542 assert(!blockref.
isNull() );
545 typedef std::multimap<double, unsigned>::iterator IE;
546 typedef std::multimap<double, std::pair<unsigned,math::XYZVector> >::iterator IS;
547 typedef std::multimap<double, std::pair<unsigned,bool> >::iterator
IT;
548 typedef std::multimap< unsigned, std::pair<double, unsigned> >::iterator II;
551 cout<<
"#########################################################"<<endl;
552 cout<<
"##### Process Block: #####"<<endl;
553 cout<<
"#########################################################"<<endl;
563 vector<bool> active( elements.
size(),
true );
568 std::vector<reco::PFCandidate> tempElectronCandidates;
569 tempElectronCandidates.clear();
574 for ( std::vector<reco::PFCandidate>::const_iterator ec=PFElectCandidates_.begin(); ec != PFElectCandidates_.end(); ++ec )tempElectronCandidates.push_back(*ec);
594 cout<<endl<<
"--------------- entering PFPhotonAlgo ----------------"<<endl;
595 vector<PFCandidatePhotonExtra> pfPhotonExtraCand;
600 tempElectronCandidates
610 unsigned int extracand =0;
618 pfPhotonExtraCand.clear();
623 for ( std::vector<reco::PFCandidate>::const_iterator ec=tempElectronCandidates.begin(); ec != tempElectronCandidates.end(); ++ec ){
626 tempElectronCandidates.clear();
634 bool egmLocalDebug =
false;
635 bool egmLocalBlockDebug =
false;
638 for(
unsigned int ieg=0 ; ieg < negmcandidates; ++ieg) {
643 PFCandidate::ElementsInBlocks::const_iterator iegfirst = theElements.begin();
644 bool sameBlock =
false;
645 bool isGoodElectron =
false;
646 bool isGoodPhoton =
false;
647 bool isPrimaryElectron =
false;
648 if(iegfirst->first == blockref)
653 cout <<
" I am in looping on EGamma Candidates: pt " << (*pfEgmRef).pt()
654 <<
" eta,phi " << (*pfEgmRef).eta() <<
", " << (*pfEgmRef).phi()
655 <<
" charge " << (*pfEgmRef).charge() << endl;
657 if((*pfEgmRef).gsfTrackRef().isNonnull()) {
665 cout <<
"** Good Electron, pt " << gedEleRef->pt()
666 <<
" eta, phi " << gedEleRef->eta() <<
", " << gedEleRef->phi()
667 <<
" charge " << gedEleRef->charge()
668 <<
" isPrimary " << isPrimaryElectron << endl;
674 if((*pfEgmRef).superClusterRef().isNonnull()) {
681 cout <<
"** Good Photon, pt " << gedPhoRef->pt()
682 <<
" eta, phi " << gedPhoRef->eta() <<
", " << gedPhoRef->phi() << endl;
688 if(isGoodElectron && isGoodPhoton) {
689 if(isPrimaryElectron)
690 isGoodPhoton =
false;
692 isGoodElectron =
false;
700 bool lockTracks =
false;
710 myPFElectron.
setCharge(gedEleRef->charge());
711 myPFElectron.
setP4(gedEleRef->p4());
715 cout <<
" PFAlgo: found an electron with NEW EGamma code " << endl;
716 cout <<
" myPFElectron: pt " << myPFElectron.
pt()
717 <<
" eta,phi " << myPFElectron.
eta() <<
", " <<myPFElectron.
phi()
718 <<
" mva " << myPFElectron.
mva_e_pi()
719 <<
" charge " << myPFElectron.
charge() << endl;
724 if(egmLocalBlockDebug)
725 cout <<
" THE BLOCK " << *blockref << endl;
726 for (PFCandidate::ElementsInBlocks::const_iterator ieb = theElements.begin();
727 ieb<theElements.end(); ++ieb) {
728 active[ieb->second] =
false;
729 if(egmLocalBlockDebug)
730 cout <<
" Elements used " << ieb->second << endl;
736 for (PFCandidate::ElementsInBlocks::const_iterator itrk = extraTracks.begin();
737 itrk<extraTracks.end(); ++itrk) {
738 active[itrk->second] =
false;
747 cout <<
"PFAlgo: Electron DISCARDED, NOT SAFE FOR JETMET " << endl;
767 myPFPhoton.
setP4(gedPhoRef->p4());
769 cout <<
" PFAlgo: found a photon with NEW EGamma code " << endl;
770 cout <<
" myPFPhoton: pt " << myPFPhoton.
pt()
771 <<
" eta,phi " << myPFPhoton.
eta() <<
", " <<myPFPhoton.
phi()
772 <<
" charge " << myPFPhoton.
charge() << endl;
776 if(egmLocalBlockDebug)
777 cout <<
" THE BLOCK " << *blockref << endl;
778 for (PFCandidate::ElementsInBlocks::const_iterator ieb = theElements.begin();
779 ieb<theElements.end(); ++ieb) {
780 active[ieb->second] =
false;
781 if(egmLocalBlockDebug)
782 cout <<
" Elements used " << ieb->second << endl;
796 for(
unsigned iEle=0; iEle<elements.
size(); iEle++) {
798 if(type==PFBlockElement::TRACK)
800 if(elements[iEle].trackRef()->algo() == 12)
805 if(elements[iEle].convRef().isNonnull())active[iEle]=
false;
815 cout<<endl<<
"--------------- loop 1 ------------------"<<endl;
842 vector<unsigned> hcalIs;
843 vector<unsigned> hoIs;
844 vector<unsigned> ecalIs;
845 vector<unsigned> trackIs;
846 vector<unsigned> ps1Is;
847 vector<unsigned> ps2Is;
849 vector<unsigned> hfEmIs;
850 vector<unsigned> hfHadIs;
853 for(
unsigned iEle=0; iEle<elements.
size(); iEle++) {
856 if(
debug_ && type != PFBlockElement::BREM )
cout<<endl<<elements[iEle];
859 case PFBlockElement::TRACK:
860 if ( active[iEle] ) {
862 if(
debug_)
cout<<
"TRACK, stored index, continue"<<endl;
866 if ( active[iEle] ) {
867 ecalIs.push_back( iEle );
868 if(
debug_)
cout<<
"ECAL, stored index, continue"<<endl;
872 if ( active[iEle] ) {
873 hcalIs.push_back( iEle );
874 if(
debug_)
cout<<
"HCAL, stored index, continue"<<endl;
877 case PFBlockElement::HO:
879 if ( active[iEle] ) {
880 hoIs.push_back( iEle );
881 if(
debug_)
cout<<
"HO, stored index, continue"<<endl;
885 case PFBlockElement::HFEM:
886 if ( active[iEle] ) {
887 hfEmIs.push_back( iEle );
888 if(
debug_)
cout<<
"HFEM, stored index, continue"<<endl;
891 case PFBlockElement::HFHAD:
892 if ( active[iEle] ) {
893 hfHadIs.push_back( iEle );
894 if(
debug_)
cout<<
"HFHAD, stored index, continue"<<endl;
902 unsigned iTrack = iEle;
908 if (active[iTrack] &&
isFromSecInt(elements[iEle],
"primary")){
909 bool isPrimaryTrack = elements[iEle].displacedVertexRef(PFBlockElement::T_TO_DISP)->displacedVertexRef()->isTherePrimaryTracks();
910 if (isPrimaryTrack) {
911 if (
debug_)
cout <<
"Primary Track reconstructed alone" << endl;
914 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEle );
915 active[iTrack] =
false;
921 if ( !active[iTrack] )
922 cout <<
"Already used by electrons, muons, conversions" << endl;
927 if ( ! active[iTrack] )
continue;
930 assert( !trackRef.
isNull() );
933 cout <<
"PFAlgo:processBlock "<<
" "<<trackIs.size()<<
" "<<ecalIs.size()<<
" "<<hcalIs.size()<<
" "<<hoIs.size()<<endl;
940 std::multimap<double, unsigned> ecalElems;
941 block.associatedElements( iTrack, linkData,
946 std::multimap<double, unsigned> hcalElems;
947 block.associatedElements( iTrack, linkData,
955 if ( hcalElems.empty() && !ecalElems.empty() ) {
958 unsigned index = ecalElems.begin()->second;
959 std::multimap<double, unsigned> sortedTracks;
960 block.associatedElements( index, linkData,
967 for(IE ie = sortedTracks.begin(); ie != sortedTracks.end(); ++ie ) {
968 unsigned jTrack = ie->second;
971 if ( !active[jTrack] )
continue;
975 if ( jTrack == iTrack )
continue;
980 std::multimap<double, unsigned> sortedECAL;
981 block.associatedElements( jTrack, linkData,
985 if ( sortedECAL.begin()->second !=
index )
continue;
990 std::multimap<double, unsigned> sortedHCAL;
991 block.associatedElements( jTrack, linkData,
995 if ( !sortedHCAL.size() )
continue;
1000 block.setLink( iTrack,
1001 sortedHCAL.begin()->second,
1002 sortedECAL.begin()->first,
1004 PFBlock::LINKTEST_RECHIT );
1009 block.associatedElements( iTrack, linkData,
1014 if (
debug_ && hcalElems.size() )
1015 std::cout <<
"Track linked back to HCAL due to ECAL sharing with other tracks" << std::endl;
1025 std::multimap<double,unsigned> gsfElems;
1027 block.associatedElements( iTrack, linkData,
1033 if(hcalElems.empty() &&
debug_) {
1034 cout<<
"no hcal element connected to track "<<iTrack<<endl;
1040 bool hcalFound =
false;
1043 cout<<
"now looping on elements associated to the track"<<endl;
1047 for(IE ie = ecalElems.begin(); ie != ecalElems.end(); ++ie ) {
1049 unsigned index = ie->second;
1053 double dist = ie->first;
1054 cout<<
"\telement "<<elements[
index]<<
" linked with distance = "<< dist <<endl;
1055 if ( ! active[index] )
cout <<
"This ECAL is already used - skip it" << endl;
1060 if ( ! active[index] )
continue;
1066 if( !hcalElems.empty() &&
debug_)
1067 cout<<
"\t\tat least one hcal element connected to the track."
1068 <<
" Sparing Ecal cluster for the hcal loop"<<endl;
1076 if( hcalElems.empty() ) {
1079 std::cout <<
"Now deals with tracks linked to no HCAL clusters" << std::endl;
1086 std::cout << elements[iTrack] << std::endl;
1092 if ( thisIsAMuon ) trackMomentum = 0.;
1096 bool rejectFake =
false;
1097 if ( !thisIsAMuon && elements[iTrack].trackRef()->ptError() >
ptError_ ) {
1101 elements[iTrack].trackRef()->
eta());
1104 if ( !ecalElems.empty() ) {
1105 unsigned thisEcal = ecalElems.begin()->second;
1107 deficit -= clusterRef->energy();
1109 clusterRef->positionREP().Eta());
1113 bool isPrimary =
isFromSecInt(elements[iTrack],
"primary");
1117 active[iTrack] =
false;
1119 std::cout << elements[iTrack] << std::endl
1120 <<
"is probably a fake (1) --> lock the track"
1125 if ( rejectFake )
continue;
1130 std::vector<unsigned> tmpi;
1131 std::vector<unsigned> kTrack;
1134 double Dpt = trackRef->ptError();
1137 trackMomentum > 30. && Dpt > 0.5 &&
1138 ( trackRef->algo() == TrackBase::iter4 ||
1139 trackRef->algo() == TrackBase::iter5 ||
1140 trackRef->algo() == TrackBase::iter6 ) ) {
1143 double dptRel = Dpt/trackRef->pt()*100;
1144 bool isPrimaryOrSecondary =
isFromSecInt(elements[iTrack],
"all");
1147 unsigned nHits = elements[iTrack].trackRef()->hitPattern().trackerLayersWithMeasurement();
1148 unsigned int NLostHit = trackRef->hitPattern().trackerLayersWithoutMeasurement();
1151 std::cout <<
"A track (algo = " << trackRef->algo() <<
") with momentum " << trackMomentum
1152 <<
" / " << elements[iTrack].trackRef()->pt() <<
" +/- " << Dpt
1153 <<
" / " << elements[iTrack].trackRef()->eta()
1154 <<
" without any link to ECAL/HCAL and with " << nHits <<
" (" << NLostHit
1155 <<
") hits (lost hits) has been cleaned" << std::endl;
1156 active[iTrack] =
false;
1163 kTrack.push_back(iTrack);
1164 active[iTrack] =
false;
1167 if ( ecalElems.empty() ) {
1168 (*pfCandidates_)[tmpi[0]].setEcalEnergy( 0., 0. );
1169 (*pfCandidates_)[tmpi[0]].setHcalEnergy( 0., 0. );
1170 (*pfCandidates_)[tmpi[0]].setHoEnergy( 0., 0. );
1171 (*pfCandidates_)[tmpi[0]].setPs1Energy( 0 );
1172 (*pfCandidates_)[tmpi[0]].setPs2Energy( 0 );
1173 (*pfCandidates_)[tmpi[0]].addElementInBlock( blockref, kTrack[0] );
1178 unsigned thisEcal = ecalElems.begin()->second;
1180 if (
debug_ )
std::cout <<
" is associated to " << elements[thisEcal] << std::endl;
1184 if ( thisIsAMuon ) {
1185 (*pfCandidates_)[tmpi[0]].setEcalEnergy( clusterRef->energy(),
1187 (*pfCandidates_)[tmpi[0]].setHcalEnergy( 0., 0. );
1188 (*pfCandidates_)[tmpi[0]].setHoEnergy( 0., 0. );
1189 (*pfCandidates_)[tmpi[0]].setPs1Energy( 0 );
1190 (*pfCandidates_)[tmpi[0]].setPs2Energy( 0 );
1191 (*pfCandidates_)[tmpi[0]].addElementInBlock( blockref, kTrack[0] );
1194 double slopeEcal = 1.;
1195 bool connectedToEcal =
false;
1196 unsigned iEcal = 99999;
1197 double calibEcal = 0.;
1198 double calibHcal = 0.;
1199 double totalEcal = thisIsAMuon ? -
muonECAL_[0] : 0.;
1202 std::multimap<double, unsigned> sortedTracks;
1203 block.associatedElements( thisEcal, linkData,
1208 for(IE ie = sortedTracks.begin(); ie != sortedTracks.end(); ++ie ) {
1209 unsigned jTrack = ie->second;
1212 if ( !active[jTrack] )
continue;
1215 if ( jTrack == iTrack )
continue;
1220 std::multimap<double, unsigned> sortedECAL;
1221 block.associatedElements( jTrack, linkData,
1225 if ( sortedECAL.begin()->second != thisEcal )
continue;
1232 bool rejectFake =
false;
1234 if ( !thatIsAMuon && trackRef->ptError() >
ptError_) {
1235 double deficit = trackMomentum + trackRef->p() - clusterRef->energy();
1237 clusterRef->positionREP().Eta());
1238 resol *= (trackMomentum+trackRef->p());
1241 kTrack.push_back(jTrack);
1242 active[jTrack] =
false;
1244 std::cout << elements[jTrack] << std::endl
1245 <<
"is probably a fake (2) --> lock the track"
1249 if ( rejectFake )
continue;
1255 if ( !thatIsAMuon ) {
1257 std::cout <<
"Track momentum increased from " << trackMomentum <<
" GeV ";
1258 trackMomentum += trackRef->p();
1260 std::cout <<
"to " << trackMomentum <<
" GeV." << std::endl;
1261 std::cout <<
"with " << elements[jTrack] << std::endl;
1265 totalEcal =
std::max(totalEcal, 0.);
1273 kTrack.push_back(jTrack);
1274 active[jTrack] =
false;
1276 if ( thatIsAMuon ) {
1277 (*pfCandidates_)[tmpi.back()].setEcalEnergy(clusterRef->energy(),
1279 (*pfCandidates_)[tmpi.back()].setHcalEnergy( 0., 0. );
1280 (*pfCandidates_)[tmpi.back()].setHoEnergy( 0., 0. );
1281 (*pfCandidates_)[tmpi.back()].setPs1Energy( 0 );
1282 (*pfCandidates_)[tmpi.back()].setPs2Energy( 0 );
1283 (*pfCandidates_)[tmpi.back()].addElementInBlock( blockref, kTrack.back() );
1288 if (
debug_ )
std::cout <<
"Loop over all associated ECAL clusters" << std::endl;
1290 for(IE ie = ecalElems.begin(); ie != ecalElems.end(); ++ie ) {
1292 unsigned index = ie->second;
1298 if (
debug_ && ! active[index] )
std::cout <<
"is not active - ignore " << std::endl;
1299 if ( ! active[index] )
continue;
1303 block.associatedElements( index, linkData,
1308 for (
unsigned ic=0; ic<kTrack.size();++ic) {
1309 if ( sortedTracks.begin()->second == kTrack[ic] ) {
1314 if (
debug_ && skip )
std::cout <<
"is closer to another track - ignore " << std::endl;
1315 if ( skip )
continue;
1320 assert( !clusterRef.
isNull() );
1323 double dist = ie->first;
1324 std::cout <<
"Ecal cluster with raw energy = " << clusterRef->energy()
1325 <<
" linked with distance = " << dist << std::endl;
1338 vector<double> ps1Ene(1,static_cast<double>(0.));
1340 vector<double> ps2Ene(1,static_cast<double>(0.));
1344 bool crackCorrection =
false;
1345 double ecalEnergy =
calibration_->energyEm(*clusterRef,ps1Ene,ps2Ene,crackCorrection);
1347 std::cout <<
"Corrected ECAL(+PS) energy = " << ecalEnergy << std::endl;
1351 totalEcal += ecalEnergy;
1352 double previousCalibEcal = calibEcal;
1353 double previousSlopeEcal = slopeEcal;
1354 calibEcal =
std::max(totalEcal,0.);
1356 calibration_->energyEmHad(trackMomentum,calibEcal,calibHcal,
1357 clusterRef->positionREP().Eta(),
1358 clusterRef->positionREP().Phi());
1359 if ( totalEcal > 0.) slopeEcal = calibEcal/totalEcal;
1362 std::cout <<
"The total calibrated energy so far amounts to = " << calibEcal << std::endl;
1366 if ( connectedToEcal && calibEcal - trackMomentum >= 0. ) {
1369 calibEcal = previousCalibEcal;
1370 slopeEcal = previousSlopeEcal;
1371 totalEcal = calibEcal/slopeEcal;
1375 active[
index] =
false;
1378 std::multimap<double, unsigned> assTracks;
1379 block.associatedElements( index, linkData,
1386 (*pfCandidates_)[tmpe].setEcalEnergy( clusterRef->energy(), ecalEnergy );
1387 (*pfCandidates_)[tmpe].setHcalEnergy( 0., 0. );
1388 (*pfCandidates_)[tmpe].setHoEnergy( 0., 0. );
1389 (*pfCandidates_)[tmpe].setPs1Energy( ps1Ene[0] );
1390 (*pfCandidates_)[tmpe].setPs2Energy( ps2Ene[0] );
1391 (*pfCandidates_)[tmpe].addElementInBlock( blockref, index );
1393 if(assTracks.size()) {
1394 (*pfCandidates_)[tmpe].addElementInBlock( blockref, assTracks.begin()->second );
1405 connectedToEcal =
true;
1407 active[
index] =
false;
1408 for (
unsigned ic=0; ic<tmpi.size();++ic)
1409 (*
pfCandidates_)[tmpi[ic]].addElementInBlock( blockref, iEcal );
1414 bool bNeutralProduced =
false;
1417 if( connectedToEcal ) {
1459 neutralEnergy /= slopeEcal;
1461 (*pfCandidates_)[tmpj].setEcalEnergy( pivotalRef->energy(),
neutralEnergy );
1462 (*pfCandidates_)[tmpj].setHcalEnergy( 0., 0. );
1463 (*pfCandidates_)[tmpj].setHoEnergy( 0., 0. );
1464 (*pfCandidates_)[tmpj].setPs1Energy( 0. );
1465 (*pfCandidates_)[tmpj].setPs2Energy( 0. );
1466 (*pfCandidates_)[tmpj].addElementInBlock(blockref, iEcal);
1467 bNeutralProduced =
true;
1468 for (
unsigned ic=0; ic<kTrack.size();++ic)
1469 (*
pfCandidates_)[tmpj].addElementInBlock( blockref, kTrack[ic] );
1473 for (
unsigned ic=0; ic<tmpi.size();++ic) {
1478 double fraction = (*pfCandidates_)[tmpi[ic]].trackRef()->p()/
trackMomentum;
1479 double ecalCal = bNeutralProduced ?
1480 (calibEcal-neutralEnergy*slopeEcal)*fraction : calibEcal*fraction;
1481 double ecalRaw = totalEcal*fraction;
1483 if (
debug_)
cout <<
"The fraction after photon supression is " << fraction <<
" calibrated ecal = " << ecalCal << endl;
1485 (*pfCandidates_)[tmpi[ic]].setEcalEnergy( ecalRaw, ecalCal );
1486 (*pfCandidates_)[tmpi[ic]].setHcalEnergy( 0., 0. );
1487 (*pfCandidates_)[tmpi[ic]].setHoEnergy( 0., 0. );
1488 (*pfCandidates_)[tmpi[ic]].setPs1Energy( 0 );
1489 (*pfCandidates_)[tmpi[ic]].setPs2Energy( 0 );
1490 (*pfCandidates_)[tmpi[ic]].addElementInBlock( blockref, kTrack[ic] );
1496 for (
unsigned ic=0; ic<tmpi.size();++ic) {
1497 const PFCandidate& pfc = (*pfCandidates_)[tmpi[ic]];
1499 if ( eleInBlocks.size() == 0 ) {
1500 if (
debug_ )
std::cout <<
"Single track / Fill element in block! " << std::endl;
1501 (*pfCandidates_)[tmpi[ic]].addElementInBlock( blockref, kTrack[ic] );
1510 for(IE ie = hcalElems.begin(); ie != hcalElems.end(); ++ie ) {
1512 unsigned index = ie->second;
1518 cout<<
"\telement "<<elements[
index]<<
" linked with distance "<< dist <<endl;
1527 cout<<
"\t\tclosest hcal cluster, doing nothing"<<endl;
1537 cout<<
"\t\tsecondary hcal cluster. unlinking"<<endl;
1538 block.setLink( iTrack, index, -1., linkData,
1539 PFBlock::LINKTEST_RECHIT );
1547 if( !(hfEmIs.empty() && hfHadIs.empty() ) ) {
1550 assert( hfEmIs.size() + hfHadIs.size() == elements.
size() );
1552 if( elements.
size() == 1 ) {
1555 double energyHF = 0.;
1556 double uncalibratedenergyHF = 0.;
1558 switch( clusterRef->layer() ) {
1561 energyHF = clusterRef->energy();
1562 uncalibratedenergyHF = energyHF;
1565 clusterRef->positionREP().Eta(),
1566 clusterRef->positionREP().Phi());
1569 (*pfCandidates_)[tmpi].setEcalEnergy( uncalibratedenergyHF, energyHF );
1570 (*pfCandidates_)[tmpi].setHcalEnergy( 0., 0.);
1571 (*pfCandidates_)[tmpi].setHoEnergy( 0., 0.);
1572 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
1573 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
1574 (*pfCandidates_)[tmpi].addElementInBlock( blockref, hfEmIs[0] );
1579 energyHF = clusterRef->energy();
1580 uncalibratedenergyHF = energyHF;
1583 clusterRef->positionREP().Eta(),
1584 clusterRef->positionREP().Phi());
1587 (*pfCandidates_)[tmpi].setHcalEnergy( uncalibratedenergyHF, energyHF );
1588 (*pfCandidates_)[tmpi].setEcalEnergy( 0., 0.);
1589 (*pfCandidates_)[tmpi].setHoEnergy( 0., 0.);
1590 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
1591 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
1592 (*pfCandidates_)[tmpi].addElementInBlock( blockref, hfHadIs[0] );
1599 else if( elements.
size() == 2 ) {
1609 cem = c0; chad =
c1;
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] );
1641 cerr<<
"Warning: 2 elements, but not 1 HFEM and 1 HFHAD"<<endl;
1650 cerr<<
"Warning: HF, but n elem different from 1 or 2"<<endl;
1661 cout<<endl<<
"--------------- loop hcal ---------------------"<<endl;
1670 for(
unsigned i=0;
i<hcalIs.size();
i++) {
1672 unsigned iHcal= hcalIs[
i];
1677 if(
debug_)
cout<<endl<<elements[iHcal]<<endl;
1683 std::multimap<double, unsigned> sortedTracks;
1684 block.associatedElements( iHcal, linkData,
1689 std::multimap< unsigned, std::pair<double, unsigned> > associatedEcals;
1691 std::map< unsigned, std::pair<double, double> > associatedPSs;
1693 std::multimap<double, std::pair<unsigned,bool> > associatedTracks;
1696 std::multimap<double,std::pair<unsigned,math::XYZVector> > ecalSatellites;
1697 std::pair<unsigned,math::XYZVector> fakeSatellite = make_pair(iHcal,
math::XYZVector(0.,0.,0.));
1698 ecalSatellites.insert( make_pair(-1., fakeSatellite) );
1700 std::multimap< unsigned, std::pair<double, unsigned> > associatedHOs;
1702 PFClusterRef hclusterref = elements[iHcal].clusterRef();
1703 assert(!hclusterref.
isNull() );
1713 if( sortedTracks.empty() ) {
1715 cout<<
"\tno associated tracks, keep for later"<<endl;
1720 active[iHcal] =
false;
1728 if(
debug_)
cout<<
"\t"<<sortedTracks.size()<<
" associated tracks:"<<endl;
1730 double totalChargedMomentum = 0;
1731 double sumpError2 = 0.;
1732 double totalHO = 0.;
1733 double totalEcal = 0.;
1734 double totalHcal = hclusterref->energy();
1735 vector<double> hcalP;
1736 vector<double> hcalDP;
1737 vector<unsigned> tkIs;
1738 double maxDPovP = -9999.;
1741 vector< unsigned > chargedHadronsIndices;
1742 vector< unsigned > chargedHadronsInBlock;
1743 double mergedNeutralHadronEnergy = 0;
1744 double mergedPhotonEnergy = 0;
1745 double muonHCALEnergy = 0.;
1746 double muonECALEnergy = 0.;
1747 double muonHCALError = 0.;
1748 double muonECALError = 0.;
1749 unsigned nMuons = 0;
1754 hclusterref->position().Y(),
1755 hclusterref->position().Z());
1756 hadronDirection = hadronDirection.Unit();
1760 for(IE ie = sortedTracks.begin(); ie != sortedTracks.end(); ++ie ) {
1762 unsigned iTrack = ie->second;
1765 if ( !active[iTrack] )
continue;
1771 assert( !trackRef.
isNull() );
1776 math::XYZVector chargedDirection(chargedPosition.X(),chargedPosition.Y(),chargedPosition.Z());
1777 chargedDirection = chargedDirection.Unit();
1780 std::multimap<double, unsigned> sortedEcals;
1781 block.associatedElements( iTrack, linkData,
1786 if(
debug_)
cout<<
"\t\t\tnumber of Ecal elements linked to this track: "
1787 <<sortedEcals.size()<<endl;
1790 std::multimap<double, unsigned> sortedHOs;
1792 block.associatedElements( iTrack, linkData,
1799 cout<<
"PFAlgo : number of HO elements linked to this track: "
1800 <<sortedHOs.size()<<endl;
1808 bool thisIsALooseMuon =
false;
1816 if ( thisIsAMuon ) {
1818 std::cout <<
"\t\tThis track is identified as a muon - remove it from the stack" << std::endl;
1819 std::cout <<
"\t\t" << elements[iTrack] << std::endl;
1827 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iTrack );
1828 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
1834 bool letMuonEatCaloEnergy =
false;
1836 if(thisIsAnIsolatedMuon){
1838 double totalCaloEnergy = totalHcal / 1.30;
1840 if( !sortedEcals.empty() ) {
1841 iEcal = sortedEcals.begin()->second;
1842 PFClusterRef eclusterref = elements[iEcal].clusterRef();
1843 totalCaloEnergy += eclusterref->energy();
1849 if( !sortedHOs.empty() ) {
1850 iHO = sortedHOs.begin()->second;
1852 totalCaloEnergy += eclusterref->energy() / 1.30;
1858 if( (
pfCandidates_->back()).
p() > totalCaloEnergy ) letMuonEatCaloEnergy =
true;
1861 if(letMuonEatCaloEnergy) muonHcal = totalHcal;
1862 double muonEcal =0.;
1864 if( !sortedEcals.empty() ) {
1865 iEcal = sortedEcals.begin()->second;
1866 PFClusterRef eclusterref = elements[iEcal].clusterRef();
1867 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal);
1869 if(letMuonEatCaloEnergy) muonEcal = eclusterref->energy();
1871 if ( eclusterref->energy() - muonEcal < 0.2 ) active[iEcal] =
false;
1872 (*pfCandidates_)[tmpi].setEcalEnergy(eclusterref->energy(), muonEcal);
1877 if( !sortedHOs.empty() ) {
1878 iHO = sortedHOs.begin()->second;
1879 PFClusterRef hoclusterref = elements[iHO].clusterRef();
1880 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHO);
1882 if(letMuonEatCaloEnergy) muonHO = hoclusterref->energy();
1884 if ( hoclusterref->energy() - muonHO < 0.2 ) active[iHO] =
false;
1885 (*pfCandidates_)[tmpi].setHcalEnergy(totalHcal, muonHcal);
1886 (*pfCandidates_)[tmpi].setHoEnergy(hoclusterref->energy(), muonHO);
1889 (*pfCandidates_)[tmpi].setHcalEnergy(totalHcal, muonHcal);
1892 if(letMuonEatCaloEnergy){
1893 muonHCALEnergy += totalHcal;
1894 if (
useHO_) muonHCALEnergy +=muonHO;
1895 muonHCALError += 0.;
1896 muonECALEnergy += muonEcal;
1897 muonECALError += 0.;
1898 photonAtECAL -= muonEcal*chargedDirection;
1899 hadronAtECAL -= totalHcal*chargedDirection;
1900 if ( !sortedEcals.empty() ) active[iEcal] =
false;
1901 active[iHcal] =
false;
1902 if (
useHO_ && !sortedHOs.empty() ) active[iHO] =
false;
1908 if ( muonHO > 0. ) {
1915 photonAtECAL -= muonECAL_[0]*chargedDirection;
1916 hadronAtECAL -= muonHCAL_[0]*chargedDirection;
1920 active[iTrack] =
false;
1927 if(
debug_)
cout<<
"\t\t"<<elements[iTrack]<<endl;
1935 if ( thisIsALooseMuon && !thisIsAMuon ) nMuons += 1;
1940 double Dpt = trackRef->ptError();
1941 double blowError = 1.;
1942 switch (trackRef->algo()) {
1943 case TrackBase::ctf:
1944 case TrackBase::iter0:
1945 case TrackBase::iter1:
1946 case TrackBase::iter2:
1947 case TrackBase::iter3:
1948 case TrackBase::iter4:
1951 case TrackBase::iter5:
1954 case TrackBase::iter6:
1962 bool isPrimaryOrSecondary =
isFromSecInt(elements[iTrack],
"all");
1964 if ( isPrimaryOrSecondary ) blowError = 1.;
1966 std::pair<unsigned,bool> tkmuon = make_pair(iTrack,thisIsALooseMuon);
1967 associatedTracks.insert( make_pair(-Dpt*blowError, tkmuon) );
1970 double Dp = trackRef->qoverpError()*trackMomentum*
trackMomentum;
1971 sumpError2 += Dp*Dp;
1973 bool connectedToEcal =
false;
1974 if( !sortedEcals.empty() )
1978 for ( IE iec=sortedEcals.begin();
1979 iec!=sortedEcals.end(); ++iec ) {
1981 unsigned iEcal = iec->second;
1982 double dist = iec->first;
1985 if( !active[iEcal] ) {
1993 PFClusterRef eclusterref = elements[iEcal].clusterRef();
1994 assert(!eclusterref.
isNull() );
1997 std::multimap<double, unsigned> sortedTracksEcal;
1998 block.associatedElements( iEcal, linkData,
2002 unsigned jTrack = sortedTracksEcal.
begin()->second;
2003 if ( jTrack != iTrack )
continue;
2007 double distEcal = block.dist(jTrack,iEcal,linkData,
2015 vector<double> ps1Ene(1,static_cast<double>(0.));
2017 block, elements, linkData, active,
2019 vector<double> ps2Ene(1,static_cast<double>(0.));
2021 block, elements, linkData, active,
2023 std::pair<double,double> psEnes = make_pair(ps1Ene[0],
2025 associatedPSs.insert(make_pair(iEcal,psEnes));
2028 bool crackCorrection =
false;
2029 float ecalEnergyCalibrated =
calibration_->energyEm(*eclusterref,ps1Ene,ps2Ene,crackCorrection);
2031 eclusterref->position().Y(),
2032 eclusterref->position().Z());
2033 photonDirection = photonDirection.Unit();
2035 if ( !connectedToEcal ) {
2038 <<elements[iEcal]<<endl;
2040 connectedToEcal =
true;
2044 std::pair<unsigned,math::XYZVector> satellite =
2045 make_pair(iEcal,ecalEnergyCalibrated*photonDirection);
2046 ecalSatellites.insert( make_pair(-1., satellite) );
2050 std::pair<unsigned,math::XYZVector> satellite =
2051 make_pair(iEcal,ecalEnergyCalibrated*photonDirection);
2052 ecalSatellites.insert( make_pair(dist, satellite) );
2056 std::pair<double, unsigned> associatedEcal
2057 = make_pair( distEcal, iEcal );
2058 associatedEcals.insert( make_pair(iTrack, associatedEcal) );
2063 if(
useHO_ && !sortedHOs.empty() )
2067 for ( IE ieho=sortedHOs.begin(); ieho!=sortedHOs.end(); ++ieho ) {
2069 unsigned iHO = ieho->second;
2070 double distHO = ieho->first;
2073 if( !active[iHO] ) {
2080 assert( type == PFBlockElement::HO );
2081 PFClusterRef hoclusterref = elements[iHO].clusterRef();
2082 assert(!hoclusterref.
isNull() );
2085 std::multimap<double, unsigned> sortedTracksHO;
2086 block.associatedElements( iHO, linkData,
2090 unsigned jTrack = sortedTracksHO.
begin()->second;
2091 if ( jTrack != iTrack )
continue;
2099 totalHO += hoclusterref->energy();
2100 active[iHO] =
false;
2102 std::pair<double, unsigned> associatedHO
2103 = make_pair( distHO, iHO );
2104 associatedHOs.insert( make_pair(iTrack, associatedHO) );
2113 totalHcal += totalHO;
2117 double caloEnergy = 0.;
2118 double slopeEcal = 1.0;
2119 double calibEcal = 0.;
2120 double calibHcal = 0.;
2121 hadronDirection = hadronAtECAL.Unit();
2125 Caloresolution *= totalChargedMomentum;
2127 Caloresolution =
std::sqrt(Caloresolution*Caloresolution + muonHCALError + muonECALError);
2128 totalEcal -=
std::min(totalEcal,muonECALEnergy);
2129 totalHcal -=
std::min(totalHcal,muonHCALEnergy);
2137 for ( IS is = ecalSatellites.begin(); is != ecalSatellites.end(); ++is ) {
2140 double previousCalibEcal = calibEcal;
2141 double previousCalibHcal = calibHcal;
2142 double previousCaloEnergy = caloEnergy;
2143 double previousSlopeEcal = slopeEcal;
2146 totalEcal +=
sqrt(is->second.second.Mag2());
2147 photonAtECAL += is->second.second;
2148 calibEcal =
std::max(0.,totalEcal);
2149 calibHcal =
std::max(0.,totalHcal);
2150 hadronAtECAL = calibHcal * hadronDirection;
2152 calibration_->energyEmHad(totalChargedMomentum,calibEcal,calibHcal,
2153 hclusterref->positionREP().Eta(),
2154 hclusterref->positionREP().Phi());
2155 caloEnergy = calibEcal+calibHcal;
2156 if ( totalEcal > 0.) slopeEcal = calibEcal/totalEcal;
2158 hadronAtECAL = calibHcal * hadronDirection;
2162 if ( is->first < 0. || caloEnergy - totalChargedMomentum <= 0. ) {
2163 if(
debug_)
cout<<
"\t\t\tactive, adding "<<is->second.second
2164 <<
" to ECAL energy, and locking"<<endl;
2165 active[is->second.first] =
false;
2171 totalEcal -=
sqrt(is->second.second.Mag2());
2172 photonAtECAL -= is->second.second;
2173 calibEcal = previousCalibEcal;
2174 calibHcal = previousCalibHcal;
2175 hadronAtECAL = previousHadronAtECAL;
2176 slopeEcal = previousSlopeEcal;
2177 caloEnergy = previousCaloEnergy;
2184 assert(caloEnergy>=0);
2197 double TotalError =
sqrt(sumpError2 + Caloresolution*Caloresolution);
2201 if ( totalChargedMomentum - caloEnergy >
nSigmaTRACK_*Caloresolution ) {
2216 for ( IT it = associatedTracks.begin(); it != associatedTracks.end(); ++it ) {
2217 unsigned iTrack = it->second.first;
2219 if ( !active[iTrack] )
continue;
2221 if ( !it->second.second )
continue;
2223 double trackMomentum = elements[it->second.first].trackRef()->p();
2226 std::multimap<double, unsigned> sortedEcals;
2227 block.associatedElements( iTrack, linkData,
2231 std::multimap<double, unsigned> sortedHOs;
2232 block.associatedElements( iTrack, linkData,
2240 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iTrack );
2241 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
2244 (*pfCandidates_)[tmpi].setHcalEnergy(totalHcal,muonHcal);
2245 if( !sortedEcals.empty() ) {
2246 unsigned iEcal = sortedEcals.begin()->second;
2247 PFClusterRef eclusterref = elements[iEcal].clusterRef();
2248 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal);
2250 (*pfCandidates_)[tmpi].setEcalEnergy(eclusterref->energy(),muonEcal);
2252 if(
useHO_ && !sortedHOs.empty() ) {
2253 unsigned iHO = sortedHOs.begin()->second;
2254 PFClusterRef hoclusterref = elements[iHO].clusterRef();
2255 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHO);
2257 (*pfCandidates_)[tmpi].setHcalEnergy(totalHcal-totalHO,muonHcal);
2258 (*pfCandidates_)[tmpi].setHoEnergy(hoclusterref->energy(),muonHO);
2263 math::XYZVector chargedDirection(chargedPosition.X(), chargedPosition.Y(), chargedPosition.Z());
2264 chargedDirection = chargedDirection.Unit();
2267 if ( totalEcal > 0. )
2269 if ( totalHcal > 0. )
2274 if ( totalHcal >
muonHCAL_[0] ) hadronAtECAL -=
muonHCAL_[0]*calibHcal/totalHcal * chargedDirection;
2275 caloEnergy = calibEcal+calibHcal;
2278 if ( muonHO > 0. ) {
2281 if ( totalHcal > 0. ) {
2282 calibHcal -=
std::min(calibHcal,muonHO_[0]*calibHcal/totalHcal);
2283 totalHcal -=
std::min(totalHcal,muonHO_[0]);
2288 active[iTrack] =
false;
2295 Caloresolution *= totalChargedMomentum;
2296 Caloresolution =
std::sqrt(Caloresolution*Caloresolution + muonHCALError + muonECALError);
2314 unsigned corrTrack = 10000000;
2315 double corrFact = 1.;
2318 totalChargedMomentum - caloEnergy >
nSigmaTRACK_*Caloresolution) {
2320 for ( IT it = associatedTracks.begin(); it != associatedTracks.end(); ++it ) {
2321 unsigned iTrack = it->second.first;
2323 if ( !active[iTrack] )
continue;
2324 const reco::TrackRef& trackref = elements[it->second.first].trackRef();
2326 double dptRel = fabs(it->first)/trackref->pt()*100;
2327 bool isSecondary =
isFromSecInt(elements[iTrack],
"secondary");
2328 bool isPrimary =
isFromSecInt(elements[iTrack],
"primary");
2332 if ( fabs(it->first) <
ptError_ )
break;
2334 double wouldBeTotalChargedMomentum =
2335 totalChargedMomentum - trackref->p();
2339 if ( wouldBeTotalChargedMomentum > caloEnergy ) {
2341 if (
debug_ && isSecondary) {
2342 cout <<
"In bad track rejection step dptRel = " << dptRel <<
" dptRel_DispVtx_ = " <<
dptRel_DispVtx_ << endl;
2343 cout <<
"The calo energy would be still smaller even without this track but it is attached to a NI"<< endl;
2348 active[iTrack] =
false;
2349 totalChargedMomentum = wouldBeTotalChargedMomentum;
2351 std::cout <<
"\tElement " << elements[iTrack]
2352 <<
" rejected (Dpt = " << -it->first
2353 <<
" GeV/c, algo = " << trackref->algo() <<
")" << std::endl;
2356 if(isPrimary)
break;
2358 corrFact = (caloEnergy - wouldBeTotalChargedMomentum)/elements[it->second.first].trackRef()->p();
2359 if ( trackref->p()*corrFact < 0.05 ) {
2361 active[iTrack] =
false;
2363 totalChargedMomentum -= trackref->p()*(1.-corrFact);
2365 std::cout <<
"\tElement " << elements[iTrack]
2366 <<
" (Dpt = " << -it->first
2367 <<
" GeV/c, algo = " << trackref->algo()
2368 <<
") rescaled by " << corrFact
2369 <<
" Now the total charged momentum is " << totalChargedMomentum << endl;
2377 Caloresolution *= totalChargedMomentum;
2378 Caloresolution =
std::sqrt(Caloresolution*Caloresolution + muonHCALError + muonECALError);
2384 sortedTracks.size() > 1 &&
2385 totalChargedMomentum - caloEnergy >
nSigmaTRACK_*Caloresolution ) {
2386 for ( IT it = associatedTracks.begin(); it != associatedTracks.end(); ++it ) {
2387 unsigned iTrack = it->second.first;
2389 if ( !active[iTrack] )
continue;
2391 double dptRel = fabs(it->first)/trackref->pt()*100;
2392 bool isPrimaryOrSecondary =
isFromSecInt(elements[iTrack],
"all");
2399 switch (trackref->algo()) {
2400 case TrackBase::ctf:
2401 case TrackBase::iter0:
2402 case TrackBase::iter1:
2403 case TrackBase::iter2:
2404 case TrackBase::iter3:
2405 case TrackBase::iter4:
2407 case TrackBase::iter5:
2408 case TrackBase::iter6:
2409 active[iTrack] =
false;
2410 totalChargedMomentum -= trackref->p();
2413 std::cout <<
"\tElement " << elements[iTrack]
2414 <<
" rejected (Dpt = " << -it->first
2415 <<
" GeV/c, algo = " << trackref->algo() <<
")" << std::endl;
2425 Caloresolution *= totalChargedMomentum;
2426 Caloresolution =
std::sqrt(Caloresolution*Caloresolution + muonHCALError + muonECALError);
2430 for ( IT it = associatedTracks.begin(); it != associatedTracks.end(); ++it ) {
2431 unsigned iTrack = it->second.first;
2432 if ( !active[iTrack] )
continue;
2435 double Dp = trackRef->qoverpError()*trackMomentum*
trackMomentum;
2439 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iTrack );
2440 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
2441 std::pair<II,II> myEcals = associatedEcals.equal_range(iTrack);
2442 for (II
ii=myEcals.first;
ii!=myEcals.second; ++
ii ) {
2443 unsigned iEcal =
ii->second.second;
2444 if ( active[iEcal] )
continue;
2445 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal );
2449 std::pair<II,II> myHOs = associatedHOs.equal_range(iTrack);
2450 for (II
ii=myHOs.first;
ii!=myHOs.second; ++
ii ) {
2451 unsigned iHO =
ii->second.second;
2452 if ( active[iHO] )
continue;
2453 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHO );
2457 if ( iTrack == corrTrack ) {
2458 (*pfCandidates_)[tmpi].rescaleMomentum(corrFact);
2459 trackMomentum *= corrFact;
2461 chargedHadronsIndices.push_back( tmpi );
2462 chargedHadronsInBlock.push_back( iTrack );
2463 active[iTrack] =
false;
2464 hcalP.push_back(trackMomentum);
2465 hcalDP.push_back(Dp);
2466 if (Dp/trackMomentum > maxDPovP) maxDPovP = Dp/
trackMomentum;
2467 sumpError2 += Dp*Dp;
2471 TotalError =
sqrt(sumpError2 + Caloresolution*Caloresolution);
2474 cout<<
"\tCompare Calo Energy to total charged momentum "<<endl;
2475 cout<<
"\t\tsum p = "<<totalChargedMomentum<<
" +- "<<
sqrt(sumpError2)<<endl;
2476 cout<<
"\t\tsum ecal = "<<totalEcal<<endl;
2477 cout<<
"\t\tsum hcal = "<<totalHcal<<endl;
2478 cout<<
"\t\t => Calo Energy = "<<caloEnergy<<
" +- "<<Caloresolution<<endl;
2479 cout<<
"\t\t => Calo Energy- total charged momentum = "
2480 <<caloEnergy-totalChargedMomentum<<
" +- "<<TotalError<<endl;
2487 double nsigma =
nSigmaHCAL(totalChargedMomentum,hclusterref->positionREP().Eta());
2489 if (
abs(totalChargedMomentum-caloEnergy)<nsigma*TotalError ) {
2495 cout<<
"\t\tcase 1: COMPATIBLE "
2496 <<
"|Calo Energy- total charged momentum| = "
2497 <<
abs(caloEnergy-totalChargedMomentum)
2498 <<
" < "<<nsigma<<
" x "<<TotalError<<endl;
2499 if (maxDPovP < 0.1 )
2500 cout<<
"\t\t\tmax DP/P = "<< maxDPovP
2501 <<
" less than 0.1: do nothing "<<endl;
2503 cout<<
"\t\t\tmax DP/P = "<< maxDPovP
2504 <<
" > 0.1: take weighted averages "<<endl;
2508 if (maxDPovP > 0.1) {
2512 int nrows = chargedHadronsIndices.size();
2513 TMatrixTSym<double>
a (nrows);
2515 TVectorD
check(nrows);
2516 double sigma2E = Caloresolution*Caloresolution;
2517 for(
int i=0;
i<nrows;
i++) {
2518 double sigma2i = hcalDP[
i]*hcalDP[
i];
2520 cout<<
"\t\t\ttrack associated to hcal "<<
i
2521 <<
" P = "<<hcalP[
i]<<
" +- "
2524 a(
i,
i) = 1./sigma2i + 1./sigma2E;
2525 b(
i) = hcalP[
i]/sigma2i + caloEnergy/sigma2E;
2526 for(
int j=0;
j<nrows;
j++) {
2528 a(
i,
j) = 1./sigma2E;
2539 TDecompChol decomp(a);
2541 TVectorD
x = decomp.Solve(b, ok);
2545 for (
int i=0;
i<nrows;
i++){
2547 unsigned ich = chargedHadronsIndices[
i];
2548 double rescaleFactor =
x(
i)/hcalP[
i];
2549 (*pfCandidates_)[ich].rescaleMomentum( rescaleFactor );
2552 cout<<
"\t\t\told p "<<hcalP[
i]
2554 <<
" rescale "<<rescaleFactor<<endl;
2559 cerr<<
"not ok!"<<endl;
2566 else if( caloEnergy > totalChargedMomentum ) {
2585 double eNeutralHadron = caloEnergy - totalChargedMomentum;
2586 double ePhoton = (caloEnergy - totalChargedMomentum) / slopeEcal;
2589 if(!sortedTracks.empty() ){
2590 cout<<
"\t\tcase 2: NEUTRAL DETECTION "
2591 <<caloEnergy<<
" > "<<nsigma<<
"x"<<TotalError
2592 <<
" + "<<totalChargedMomentum<<endl;
2593 cout<<
"\t\tneutral activity detected: "<<endl
2594 <<
"\t\t\t photon = "<<ePhoton<<endl
2595 <<
"\t\t\tor neutral hadron = "<<eNeutralHadron<<endl;
2597 cout<<
"\t\tphoton or hadron ?"<<endl;}
2599 if(sortedTracks.empty() )
2600 cout<<
"\t\tno track -> hadron "<<endl;
2602 cout<<
"\t\t"<<sortedTracks.size()
2603 <<
"tracks -> check if the excess is photonic or hadronic"<<endl;
2607 double ratioMax = 0.;
2609 unsigned maxiEcal= 9999;
2613 for(IE ie = sortedTracks.begin(); ie != sortedTracks.end(); ++ie ) {
2615 unsigned iTrack = ie->second;
2621 assert( !trackRef.
isNull() );
2623 II iae = associatedEcals.find(iTrack);
2625 if( iae == associatedEcals.end() )
continue;
2628 unsigned iEcal = iae->second.second;
2634 assert( !clusterRef.
isNull() );
2636 double pTrack = trackRef->p();
2637 double eECAL = clusterRef->energy();
2638 double eECALOverpTrack = eECAL / pTrack;
2640 if ( eECALOverpTrack > ratioMax ) {
2641 ratioMax = eECALOverpTrack;
2642 maxEcalRef = clusterRef;
2648 std::vector<reco::PFClusterRef> pivotalClusterRef;
2649 std::vector<unsigned> iPivotal;
2650 std::vector<double> particleEnergy, ecalEnergy, hcalEnergy, rawecalEnergy, rawhcalEnergy;
2651 std::vector<math::XYZVector> particleDirection;
2655 if ( ePhoton < totalEcal || eNeutralHadron-calibEcal < 1E-10 ) {
2657 if ( !maxEcalRef.
isNull() ) {
2658 particleEnergy.push_back(ePhoton);
2659 particleDirection.push_back(photonAtECAL);
2660 ecalEnergy.push_back(ePhoton);
2661 hcalEnergy.push_back(0.);
2662 rawecalEnergy.push_back(totalEcal);
2663 rawhcalEnergy.push_back(totalHcal);
2664 pivotalClusterRef.push_back(maxEcalRef);
2665 iPivotal.push_back(maxiEcal);
2667 mergedPhotonEnergy = ePhoton;
2673 if ( !maxEcalRef.
isNull() ) {
2674 pivotalClusterRef.push_back(maxEcalRef);
2675 particleEnergy.push_back(totalEcal);
2676 particleDirection.push_back(photonAtECAL);
2677 ecalEnergy.push_back(totalEcal);
2678 hcalEnergy.push_back(0.);
2679 rawecalEnergy.push_back(totalEcal);
2680 rawhcalEnergy.push_back(totalHcal);
2681 iPivotal.push_back(maxiEcal);
2683 mergedPhotonEnergy = totalEcal;
2687 mergedNeutralHadronEnergy = eNeutralHadron-calibEcal;
2688 if ( mergedNeutralHadronEnergy > 1.0 ) {
2689 pivotalClusterRef.push_back(hclusterref);
2690 particleEnergy.push_back(mergedNeutralHadronEnergy);
2691 particleDirection.push_back(hadronAtECAL);
2692 ecalEnergy.push_back(0.);
2693 hcalEnergy.push_back(mergedNeutralHadronEnergy);
2694 rawecalEnergy.push_back(totalEcal);
2695 rawhcalEnergy.push_back(totalHcal);
2696 iPivotal.push_back(iHcal);
2706 for (
unsigned iPivot=0; iPivot<iPivotal.size(); ++iPivot ) {
2708 if ( particleEnergy[iPivot] < 0. )
2709 std::cout <<
"ALARM = Negative energy ! "
2710 << particleEnergy[iPivot] << std::endl;
2712 bool useDirection =
true;
2714 particleEnergy[iPivot],
2716 particleDirection[iPivot].
X(),
2717 particleDirection[iPivot].Y(),
2718 particleDirection[iPivot].
Z());
2721 (*pfCandidates_)[tmpi].setEcalEnergy( rawecalEnergy[iPivot],ecalEnergy[iPivot] );
2723 (*pfCandidates_)[tmpi].setHcalEnergy( rawhcalEnergy[iPivot],hcalEnergy[iPivot] );
2724 (*pfCandidates_)[tmpi].setHoEnergy(0., 0.);
2726 (*pfCandidates_)[tmpi].setHcalEnergy( rawhcalEnergy[iPivot]-totalHO,hcalEnergy[iPivot]*(1.-totalHO/rawhcalEnergy[iPivot]));
2727 (*pfCandidates_)[tmpi].setHoEnergy(totalHO, totalHO * hcalEnergy[iPivot]/rawhcalEnergy[iPivot]);
2729 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
2730 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
2731 (*pfCandidates_)[tmpi].set_mva_nothing_gamma( -1. );
2734 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
2735 for (
unsigned ich=0; ich<chargedHadronsInBlock.size(); ++ich) {
2736 unsigned iTrack = chargedHadronsInBlock[ich];
2737 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iTrack );
2743 std::pair<II,II> myEcals = associatedEcals.equal_range(iTrack);
2744 for (II
ii=myEcals.first;
ii!=myEcals.second; ++
ii ) {
2745 unsigned iEcal =
ii->second.second;
2746 if ( active[iEcal] )
continue;
2747 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal );
2759 double totalHcalEnergyCalibrated = calibHcal;
2760 double totalEcalEnergyCalibrated = calibEcal;
2775 totalHcalEnergyCalibrated -= mergedNeutralHadronEnergy;
2777 totalEcalEnergyCalibrated -= mergedPhotonEnergy;
2782 double chargedHadronsTotalEnergy = 0;
2783 for(
unsigned ich=0; ich<chargedHadronsIndices.size(); ++ich ) {
2784 unsigned index = chargedHadronsIndices[ich];
2786 chargedHadronsTotalEnergy += chargedHadron.
energy();
2789 for(
unsigned ich=0; ich<chargedHadronsIndices.size(); ++ich ) {
2790 unsigned index = chargedHadronsIndices[ich];
2792 float fraction = chargedHadron.
energy()/chargedHadronsTotalEnergy;
2795 chargedHadron.
setHcalEnergy( fraction * totalHcal, fraction * totalHcalEnergyCalibrated );
2798 chargedHadron.
setHcalEnergy( fraction * (totalHcal-totalHO), fraction * totalHcalEnergyCalibrated * (1.-totalHO/totalHcal) );
2799 chargedHadron.
setHoEnergy( fraction * totalHO, fraction * totalHO * totalHcalEnergyCalibrated / totalHcal );
2802 chargedHadron.
setEcalEnergy( fraction * totalEcal, fraction * totalEcalEnergyCalibrated );
2806 for ( IS is = ecalSatellites.begin(); is != ecalSatellites.end(); ++is ) {
2809 unsigned iEcal = is->second.first;
2810 if ( !active[iEcal] )
continue;
2815 PFClusterRef eclusterref = elements[iEcal].clusterRef();
2816 assert(!eclusterref.
isNull() );
2819 active[iEcal] =
false;
2822 std::multimap<double, unsigned> assTracks;
2823 block.associatedElements( iEcal, linkData,
2830 (*pfCandidates_)[tmpi].setEcalEnergy( eclusterref->energy(),
sqrt(is->second.second.Mag2()) );
2831 (*pfCandidates_)[tmpi].setHcalEnergy( 0., 0. );
2832 (*pfCandidates_)[tmpi].setHoEnergy( 0., 0. );
2833 (*pfCandidates_)[tmpi].setPs1Energy( associatedPSs[iEcal].
first );
2834 (*pfCandidates_)[tmpi].setPs2Energy( associatedPSs[iEcal].
second );
2835 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal );
2836 (*pfCandidates_)[tmpi].addElementInBlock( blockref, sortedTracks.begin()->second) ;
2850 <<
"---- loop remaining hcal ------- "<<endl;
2856 for(
unsigned ihcluster=0; ihcluster<hcalIs.size(); ihcluster++) {
2857 unsigned iHcal = hcalIs[ihcluster];
2860 std::vector<unsigned> ecalRefs;
2861 std::vector<unsigned> hoRefs;
2864 cout<<endl<<elements[iHcal]<<
" ";
2867 if( !active[iHcal] ) {
2869 cout<<
"not active"<<endl;
2874 std::multimap<double, unsigned> ecalElems;
2875 block.associatedElements( iHcal, linkData,
2881 float totalEcal = 0.;
2884 for(IE ie = ecalElems.begin(); ie != ecalElems.end(); ++ie ) {
2886 unsigned iEcal = ie->second;
2887 double dist = ie->first;
2892 if( !active[iEcal] )
continue;
2913 std::multimap<double, unsigned> hcalElems;
2914 block.associatedElements( iEcal, linkData,
2919 bool isClosest =
true;
2920 for(IE ih = hcalElems.begin(); ih != hcalElems.end(); ++ih ) {
2922 unsigned jHcal = ih->second;
2923 double distH = ih->first;
2925 if ( !active[jHcal] )
continue;
2927 if ( distH < dist ) {
2934 if (!isClosest)
continue;
2938 cout<<
"\telement "<<elements[iEcal]<<
" linked with dist "<< dist<<endl;
2939 cout<<
"Added to HCAL cluster to form a neutral hadron"<<endl;
2943 assert( !eclusterRef.
isNull() );
2946 vector<double> ps1Ene(1,static_cast<double>(0.));
2948 vector<double> ps2Ene(1,static_cast<double>(0.));
2950 bool crackCorrection =
false;
2951 double ecalEnergy =
calibration_->energyEm(*eclusterRef,ps1Ene,ps2Ene,crackCorrection);
2955 totalEcal += ecalEnergy;
2956 if ( ecalEnergy > ecalMax ) {
2957 ecalMax = ecalEnergy;
2958 eClusterRef = eclusterRef;
2961 ecalRefs.push_back(iEcal);
2962 active[iEcal] =
false;
2968 double totalHO = 0.;
2972 std::multimap<double, unsigned> hoElems;
2973 block.associatedElements( iHcal, linkData,
2983 for(IE ie = hoElems.begin(); ie != hoElems.end(); ++ie ) {
2985 unsigned iHO = ie->second;
2986 double dist = ie->first;
2988 assert( type == PFBlockElement::HO );
2991 if( !active[iHO] )
continue;
2997 std::multimap<double, unsigned> hcalElems;
2998 block.associatedElements( iHO, linkData,
3003 bool isClosest =
true;
3004 for(IE ih = hcalElems.begin(); ih != hcalElems.end(); ++ih ) {
3006 unsigned jHcal = ih->second;
3007 double distH = ih->first;
3009 if ( !active[jHcal] )
continue;
3011 if ( distH < dist ) {
3018 if (!isClosest)
continue;
3021 cout<<
"\telement "<<elements[iHO]<<
" linked with dist "<< dist<<endl;
3022 cout<<
"Added to HCAL cluster to form a neutral hadron"<<endl;
3026 assert( !hoclusterRef.
isNull() );
3028 double hoEnergy = hoclusterRef->energy();
3030 totalHO += hoEnergy;
3031 if ( hoEnergy > hoMax ) {
3033 hoClusterRef = hoclusterRef;
3037 hoRefs.push_back(iHO);
3038 active[iHO] =
false;
3044 = elements[iHcal].clusterRef();
3045 assert( !hclusterRef.
isNull() );
3048 double totalHcal = hclusterRef->energy();
3050 if (
useHO_ ) totalHcal += totalHO;
3058 double calibEcal = totalEcal > 0. ? totalEcal : 0.;
3059 double calibHcal =
std::max(0.,totalHcal);
3063 calibEcal = totalEcal;
3066 hclusterRef->positionREP().Eta(),
3067 hclusterRef->positionREP().Phi());
3080 calibEcal+calibHcal );
3083 (*pfCandidates_)[tmpi].setEcalEnergy( totalEcal, calibEcal );
3085 (*pfCandidates_)[tmpi].setHcalEnergy( totalHcal, calibHcal );
3086 (*pfCandidates_)[tmpi].setHoEnergy(0.,0.);
3088 (*pfCandidates_)[tmpi].setHcalEnergy( totalHcal-totalHO, calibHcal*(1.-totalHO/totalHcal));
3089 (*pfCandidates_)[tmpi].setHoEnergy(totalHO,totalHO*calibHcal/totalHcal);
3091 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
3092 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
3093 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
3094 for (
unsigned iec=0; iec<ecalRefs.size(); ++iec)
3095 (*
pfCandidates_)[tmpi].addElementInBlock( blockref, ecalRefs[iec] );
3096 for (
unsigned iho=0; iho<hoRefs.size(); ++iho)
3097 (*
pfCandidates_)[tmpi].addElementInBlock( blockref, hoRefs[iho] );
3106 if(
debug_)
cout<<endl<<
"---- loop ecal------- "<<endl;
3111 for(
unsigned i=0;
i<ecalIs.size();
i++) {
3112 unsigned iEcal = ecalIs[
i];
3115 cout<<endl<<elements[iEcal]<<
" ";
3117 if( ! active[iEcal] ) {
3119 cout<<
"not active"<<endl;
3126 PFClusterRef clusterref = elements[iEcal].clusterRef();
3127 assert(!clusterref.
isNull() );
3129 active[iEcal] =
false;
3132 vector<double> ps1Ene(1,static_cast<double>(0.));
3134 vector<double> ps2Ene(1,static_cast<double>(0.));
3136 bool crackCorrection =
false;
3137 float ecalEnergy =
calibration_->energyEm(*clusterref,ps1Ene,ps2Ene,crackCorrection);
3139 double particleEnergy = ecalEnergy;
3144 (*pfCandidates_)[tmpi].setEcalEnergy( clusterref->energy(),ecalEnergy );
3145 (*pfCandidates_)[tmpi].setHcalEnergy( 0., 0. );
3146 (*pfCandidates_)[tmpi].setHoEnergy( 0., 0. );
3147 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
3148 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
3149 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal );
3168 double px = track.
px();
3169 double py = track.
py();
3170 double pz = track.
pz();
3171 double energy =
sqrt(track.
p()*track.
p() + 0.13957*0.13957);
3183 pfCandidates_->back().setVertexSource( PFCandidate::kTrkVertex );
3196 if ((!isMuon) && isFromDisp) {
3197 double Dpt = trackRef->ptError();
3198 double dptRel = Dpt/trackRef->pt()*100;
3204 cout <<
"Not refitted px = " << px <<
" py = " << py <<
" pz = " << pz <<
" energy = " << energy << endl;
3207 reco::Track trackRefit = vRef->refittedTrack(trackRef);
3212 sqrt(trackRefit.
p()*trackRefit.
p() + 0.13957*0.13957));
3214 cout <<
"Refitted px = " << px <<
" py = " << py <<
" pz = " << pz <<
" energy = " << energy << endl;
3232 double particleEnergy,
3245 if ( useDirection ) {
3246 switch( cluster.
layer() ) {
3249 factor =
std::sqrt(cluster.
position().Perp2()/(particleX*particleX+particleY*particleY));
3255 factor = cluster.
position().Z()/particleZ;
3270 cluster.
position().Y()-vertexPos.Y(),
3271 cluster.
position().Z()-vertexPos.Z());
3273 particleY*factor-vertexPos.Y(),
3274 particleZ*factor-vertexPos.Z() );
3279 clusterPos = useDirection ? particleDirection.Unit() : clusterPos.Unit();
3280 clusterPos *= particleEnergy;
3286 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzM4D<double> >
3287 momentum( clusterPos.X(), clusterPos.Y(), clusterPos.Z(), mass);
3297 switch( cluster.
layer() ) {
3300 particleType = PFCandidate::gamma;
3304 particleType = PFCandidate::h0;
3307 particleType = PFCandidate::h_HF;
3310 particleType = PFCandidate::egamma_HF;
3346 if ( clusterEnergyHCAL < 1. ) clusterEnergyHCAL = 1.;
3348 double resol = fabs(eta) < 1.48 ?
3349 sqrt (1.02*1.02/clusterEnergyHCAL + 0.065*0.065)
3351 sqrt (1.20*1.20/clusterEnergyHCAL + 0.028*0.028);
3359 double nS = fabs(eta) < 1.48 ?
3369 if(!out )
return out;
3371 out<<
"====== Particle Flow Algorithm ======= ";
3378 out<<
"reconstructed particles: "<<endl;
3380 const std::auto_ptr< reco::PFCandidateCollection >&
3383 if(!candidates.get() ) {
3384 out<<
"candidates already transfered"<<endl;
3413 std::vector<bool>& active,
3414 std::vector<double>& psEne) {
3422 std::multimap<double, unsigned> sortedPS;
3423 typedef std::multimap<double, unsigned>::iterator IE;
3425 sortedPS, psElementType,
3429 double totalPS = 0.;
3430 for ( IE ips=sortedPS.begin(); ips!=sortedPS.end(); ++ips ) {
3433 unsigned iPS = ips->second;
3437 if (!active[iPS])
continue;
3440 std::multimap<double, unsigned> sortedECAL;
3445 unsigned jEcal = sortedECAL.begin()->second;
3446 if ( jEcal != iEcal )
continue;
3450 assert( pstype == psElementType );
3451 PFClusterRef psclusterref = elements[iPS].clusterRef();
3452 assert(!psclusterref.
isNull() );
3453 totalPS += psclusterref->energy();
3454 psEne[0] += psclusterref->energy();
3455 active[iPS] =
false;
3470 bool bPrimary = (order.find(
"primary") != string::npos);
3471 bool bSecondary = (order.find(
"secondary") != string::npos);
3472 bool bAll = (order.find(
"all") != string::npos);
3477 if (bPrimary && isToDisp)
return true;
3478 if (bSecondary && isFromDisp )
return true;
3479 if (bAll && ( isToDisp || isFromDisp ) )
return true;
3508 std::vector<unsigned int> pfCandidatesToBeRemoved;
3515 double met2 = metX*metX+metY*metY;
3517 double significance =
std::sqrt(met2/sumet);
3518 double significanceCor = significance;
3521 double metXCor = metX;
3522 double metYCor = metY;
3523 double sumetCor = sumet;
3524 double met2Cor = met2;
3526 double deltaPhiPt = 100.;
3528 unsigned iCor = 1E9;
3533 double metReduc = -1.;
3547 for(
unsigned j=0;
j<pfCandidatesToBeRemoved.size(); ++
j) {
3548 if (
i == pfCandidatesToBeRemoved[
j] ) skip =
true;
3551 if ( skip )
continue;
3554 deltaPhi = std::acos((metX*pfc.
px()+metY*pfc.
py())/(pfc.
pt()*
std::sqrt(met2)));
3555 deltaPhiPt = deltaPhi*pfc.
pt();
3559 double metXInt = metX - pfc.
px();
3560 double metYInt = metY - pfc.
py();
3561 double sumetInt = sumet - pfc.
pt();
3562 double met2Int = metXInt*metXInt+metYInt*metYInt;
3563 if ( met2Int < met2Cor ) {
3566 metReduc = (met2-met2Int)/met2Int;
3568 sumetCor = sumetInt;
3569 significanceCor =
std::sqrt(met2Cor/sumetCor);
3576 pfCandidatesToBeRemoved.push_back(iCor);
3590 std::cout <<
"Significance reduction = " << significance <<
" -> "
3591 << significanceCor <<
" = " << significanceCor - significance
3593 for(
unsigned j=0;
j<pfCandidatesToBeRemoved.size(); ++
j) {
3594 std::cout <<
"Removed : " << (*pfCandidates_)[pfCandidatesToBeRemoved[
j]] << std::endl;
3596 (*pfCandidates_)[pfCandidatesToBeRemoved[
j]].rescaleMomentum(1E-6);
3610 if ( !cleanedHits.size() )
return;
3616 std::vector<unsigned int> hitsToBeAdded;
3623 double met2 = metX*metX+metY*metY;
3624 double met2_Original = met2;
3628 double metXCor = metX;
3629 double metYCor = metY;
3630 double sumetCor = sumet;
3631 double met2Cor = met2;
3633 unsigned iCor = 1E9;
3638 double metReduc = -1.;
3640 for(
unsigned i=0;
i<cleanedHits.size(); ++
i) {
3649 for(
unsigned j=0;
j<hitsToBeAdded.size(); ++
j) {
3650 if (
i == hitsToBeAdded[
j] ) skip =
true;
3653 if ( skip )
continue;
3656 double metXInt = metX + px;
3657 double metYInt = metY + py;
3658 double sumetInt = sumet +
pt;
3659 double met2Int = metXInt*metXInt+metYInt*metYInt;
3662 if ( met2Int < met2Cor ) {
3665 metReduc = (met2-met2Int)/met2Int;
3667 sumetCor = sumetInt;
3676 hitsToBeAdded.push_back(iCor);
3690 std::cout << hitsToBeAdded.size() <<
" hits were re-added " << std::endl;
3694 std::cout <<
"Added after cleaning check : " << std::endl;
3696 for(
unsigned j=0;
j<hitsToBeAdded.size(); ++
j) {
3716 for(
unsigned ic=0;ic<
size;++ic) {
3725 (*pfCandidates_)[ic].setPFElectronExtraRef(theRef);
3737 (*pfCandidates_)[ic].set_mva_e_pi(it->mvaVariable(PFCandidateElectronExtra::MVA_MVA));
3739 (*pfCandidates_)[ic].setPFElectronExtraRef(theRef);
3740 (*pfCandidates_)[ic].setGsfTrackRef(it->gsfTrackRef());
3748 for(
unsigned ic=0;ic<
size;++ic) {
3756 (*pfElectronCandidates_)[ic].setPFElectronExtraRef(theRef);
3767 for(
unsigned ic=0;ic<
size;++ic) {
3772 for(
unsigned pcextra=0;pcextra<sizePhExtra;++pcextra) {
3775 (*pfCandidates_)[ic].setPFPhotonExtraRef(theRef);
PFLayer::Layer layer() const
cluster layer, see PFLayer.h in this directory
const double Z[kNumberCalorimeter]
double p() const
momentum vector magnitude
virtual double energy() const GCC11_FINAL
energy
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.
virtual void setCharge(Charge q) GCC11_FINAL
set electric charge
ParticleType
particle types
void setPFMuonAndFakeParameters(const edm::ParameterSet &pset)
void addMissingMuons(edm::Handle< reco::MuonCollection >, reco::PFCandidateCollection *cands)
double sumEtEcalIsoForEgammaSC_endcap_
std::auto_ptr< reco::PFCandidateCollection > pfPhotonCandidates_
the unfiltered photon collection
void set_mva_nothing_gamma(float mva)
set mva for gamma detection
bool isMuon(const Candidate &part)
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
edm::Ref< PFCandidatePhotonExtraCollection > PFCandidatePhotonExtraRef
persistent reference to a PFCandidatePhotonExtra
double coneEcalIsoForEgammaSC_
static bool isMuon(const reco::PFBlockElement &elt)
const std::vector< reco::PFCandidate > & getAllElectronCandidates()
unsigned reconstructCluster(const reco::PFCluster &cluster, double particleEnergy, bool useDirection=false, double particleX=0., double particleY=0., double particleZ=0.)
void reconstructParticles(const reco::PFBlockHandle &blockHandle)
double y() const
y coordinate
bool useProtectionsForJetMET_
double coneTrackIsoForEgammaSC_
void setParameters(const edm::ParameterSet &)
double nSigmaHCAL_
number of sigma to judge energy excess in HCAL
std::map< unsigned int, Link > LinkData
bool isElectronSafeForJetMET(const reco::GsfElectron &, const reco::PFCandidate &, const reco::Vertex &, bool lockTracks)
virtual void processBlock(const reco::PFBlockRef &blockref, std::list< reco::PFBlockRef > &hcalBlockRefs, std::list< reco::PFBlockRef > &ecalBlockRefs)
void setMuonHandle(const edm::Handle< reco::MuonCollection > &)
math::Error< dimension >::type Error
covariance error matrix (3x3)
std::vector< Vertex > VertexCollection
collection of Vertex objects
const edm::OwnVector< reco::PFBlockElement > & elements() const
std::vector< PFRecHit > PFRecHitCollection
collection of PFRecHit objects
const edm::ValueMap< reco::PhotonRef > * valueMapGedPhotons_
RefToBase< value_type > refAt(size_type i) const
void checkCleaning(const reco::PFRecHitCollection &cleanedHF)
Check HF Cleaning.
edm::Ref< PFCandidateElectronExtraCollection > PFCandidateElectronExtraRef
persistent reference to a PFCandidateElectronExtra
virtual void setVertex(const math::XYZPoint &p)
set vertex
bool passElectronSelection(const reco::GsfElectron &, const reco::PFCandidate &, const int &)
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float > > XYZPointF
point in space with cartesian internal representation
double px() const
x coordinate of momentum vector
void setDisplacedVerticesParameters(bool rejectTracks_Bad, bool rejectTracks_Step45, bool usePFNuclearInteractions, bool usePFConversions, bool usePFDecays, double dptRel_DispVtx)
std::ostream & operator<<(std::ostream &out, const ALILine &li)
PFCandidateCollection::const_iterator PFCandidateConstIterator
iterator
double sumEtEcalIsoForEgammaSC_barrel_
std::auto_ptr< reco::PFCandidateCollection > pfCleanedCandidates_
void setPFEleParameters(double mvaEleCut, std::string mvaWeightFileEleID, bool usePFElectrons, const boost::shared_ptr< PFSCEnergyCalibration > &thePFSCEnergyCalibration, const boost::shared_ptr< PFEnergyCalibration > &thePFEnergyCalibration, double sumEtEcalIsoForEgammaSC_barrel, double sumEtEcalIsoForEgammaSC_endcap, double coneEcalIsoForEgammaSC, double sumPtTrackIsoForEgammaSC_barrel, double sumPtTrackIsoForEgammaSC_endcap, unsigned int nTrackIsoForEgammaSC, double coneTrackIsoForEgammaSC, bool applyCrackCorrections=false, bool usePFSCEleCalib=true, bool useEGElectrons=false, bool useEGammaSupercluster=true)
void setPFVertexParameters(bool useVertex, const reco::VertexCollection *primaryVertices)
void setEGElectronCollection(const reco::GsfElectronCollection &egelectrons)
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
virtual double py() const GCC11_FINAL
y coordinate of momentum vector
bool rejectTracks_Step45_
const math::XYZPointF & positionAtECALEntrance() const
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_
void set_mva_e_pi(float mva)
PFLayer::Layer layer() const
rechit layer
bool useEGammaSupercluster_
U second(std::pair< T, U > const &p)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
bool isNonnull() const
Checks for non-null.
bool isElectron(const reco::GsfElectron &)
reco::MuonRef muonRef() const
virtual float phi() const GCC11_FINAL
momentum azimuthal angle
bool usePFNuclearInteractions_
bool isNull() const
Checks for null.
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 setParameters(double nSigmaECAL, double nSigmaHCAL, const boost::shared_ptr< PFEnergyCalibration > &calibration, const boost::shared_ptr< PFEnergyCalibrationHF > &thepfEnergyCalibrationHF)
const T & max(const T &a, const T &b)
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 &)
bool check(const DataFrame &df, bool capcheck, bool dvercheck)
const std::vector< reco::PFCandidateElectronExtra > & getElectronExtra()
void setPFPhotonRegWeights(const GBRForest *LCorrForestEB, const GBRForest *LCorrForestEE, const GBRForest *GCorrForestBarrel, const GBRForest *GCorrForestEndcapHr9, const GBRForest *GCorrForestEndcapLr9, const GBRForest *PFEcalResolution)
virtual double px() const GCC11_FINAL
x coordinate of momentum vector
Abs< T >::type abs(const T &t)
double z() const
y coordinate
reco::Vertex primaryVertex_
double nSigmaHCAL(double clusterEnergy, double clusterEta) const
edm::Handle< reco::MuonCollection > muonHandle_
std::vector< double > muonECAL_
void setPositionAtECALEntrance(float x, float y, float z)
set position at ECAL entrance
math::XYZPoint Point
point in the space
std::vector< LinkConnSpec >::const_iterator IT
void setPostHFCleaningParameters(bool postHFCleaning, double minHFCleaningPt, double minSignificance, double maxSignificance, double minSignificanceReduction, double maxDeltaPhiPt, double minDeltaMet)
std::vector< PFBlock > PFBlockCollection
collection of PFBlock objects
PFEGammaFilters * pfegamma_
reco::PFBlockRef createBlockRef(const reco::PFBlockCollection &blocks, unsigned bi)
reco::PFCandidatePhotonExtraCollection pfPhotonExtra_
the extra photon collection
double pz() const
z coordinate of momentum vector
virtual float eta() const GCC11_FINAL
momentum pseudorapidity
void setEcalEnergy(float eeRaw, float eeCorr)
set corrected Ecal energy
float mva_e_pi() const
mva for electron-pion discrimination
const std::vector< reco::PFCandidate > & getElectronCandidates()
const math::XYZPoint & position() const
is seed ?
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)
virtual int charge() const GCC11_FINAL
electric charge
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 bool trackType(TrackType trType) const
boost::shared_ptr< PFSCEnergyCalibration > thePFSCEnergyCalibration_
reco::TrackRef trackRef() const
virtual ~PFAlgo()
destructor
void setHoEnergy(float eoRaw, float eoCorr)
set corrected Hcal energy
std::vector< std::vector< double > > tmp
bool isElectronValidCandidate(const reco::PFBlockRef &blockRef, std::vector< bool > &active, const reco::Vertex &primaryVertex)
Particle reconstructed by the particle flow algorithm.
double energy() const
rechit energy
boost::shared_ptr< PFEnergyCalibrationHF > thepfEnergyCalibrationHF_
virtual void setP4(const LorentzVector &p4) GCC11_FINAL
set 4-momentum
reco::PFCandidateEGammaExtraRef egammaExtraRef() const
return a reference to the EGamma extra
std::auto_ptr< reco::PFCandidateCollection > pfCandidates_
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
double sumPtTrackIsoForEgammaSC_endcap_
void setPhotonPrimaryVtx(const reco::Vertex &primary)
volatile std::atomic< bool > shutdown_flag false
virtual ParticleType particleId() const
std::auto_ptr< reco::PFCandidateCollection > pfElectronCandidates_
the unfiltered electron collection
double time() const
timing for cleaned hits
double neutralHadronEnergyResolution(double clusterEnergy, double clusterEta) const
todo: use PFClusterTools for this
void postClean(reco::PFCandidateCollection *)
virtual float pt() const GCC11_FINAL
transverse momentum
reco::PFCandidateElectronExtraCollection pfElectronExtra_
the unfiltered electron collection
const ElementsInBlocks & elementsInBlocks() const
bool isPhotonValidCandidate(const reco::PFBlockRef &blockRef, std::vector< bool > &active, std::auto_ptr< reco::PFCandidateCollection > &pfPhotonCandidates, std::vector< reco::PFCandidatePhotonExtra > &pfPhotonExtraCandidates, std::vector< reco::PFCandidate > &tempElectronCandidates)
void setInputsForCleaning(const reco::VertexCollection *)
bool isPhotonSafeForJetMET(const reco::Photon &, const reco::PFCandidate &)
tuple size
Write out results.
double sumPtTrackIsoForEgammaSC_barrel_
const std::auto_ptr< reco::PFCandidateCollection > & pfCandidates() const
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_
void setElectronExtraRef(const edm::OrphanHandle< reco::PFCandidateElectronExtraCollection > &extrah)
void setEGElectronCollection(const reco::GsfElectronCollection &egelectrons)
bool reconstructMuon(reco::PFCandidate &, const reco::MuonRef &, bool allowLoose=false)
PFDisplacedTrackerVertexRef displacedVertexRef(TrackType trType) const
double nSigmaECAL_
number of sigma to judge energy excess in ECAL