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());
716 cout <<
" PFAlgo: found an electron with NEW EGamma code " << endl;
717 cout <<
" myPFElectron: pt " << myPFElectron.
pt()
718 <<
" eta,phi " << myPFElectron.
eta() <<
", " <<myPFElectron.
phi()
719 <<
" mva " << myPFElectron.
mva_e_pi()
720 <<
" charge " << myPFElectron.
charge() << endl;
725 if(egmLocalBlockDebug)
726 cout <<
" THE BLOCK " << *blockref << endl;
727 for (PFCandidate::ElementsInBlocks::const_iterator ieb = theElements.begin();
728 ieb<theElements.end(); ++ieb) {
729 active[ieb->second] =
false;
730 if(egmLocalBlockDebug)
731 cout <<
" Elements used " << ieb->second << endl;
737 for (PFCandidate::ElementsInBlocks::const_iterator itrk = extraTracks.begin();
738 itrk<extraTracks.end(); ++itrk) {
739 active[itrk->second] =
false;
748 cout <<
"PFAlgo: Electron DISCARDED, NOT SAFE FOR JETMET " << endl;
768 myPFPhoton.
setP4(gedPhoRef->p4());
770 cout <<
" PFAlgo: found a photon with NEW EGamma code " << endl;
771 cout <<
" myPFPhoton: pt " << myPFPhoton.
pt()
772 <<
" eta,phi " << myPFPhoton.
eta() <<
", " <<myPFPhoton.
phi()
773 <<
" charge " << myPFPhoton.
charge() << endl;
777 if(egmLocalBlockDebug)
778 cout <<
" THE BLOCK " << *blockref << endl;
779 for (PFCandidate::ElementsInBlocks::const_iterator ieb = theElements.begin();
780 ieb<theElements.end(); ++ieb) {
781 active[ieb->second] =
false;
782 if(egmLocalBlockDebug)
783 cout <<
" Elements used " << ieb->second << endl;
797 for(
unsigned iEle=0; iEle<elements.
size(); iEle++) {
799 if(type==PFBlockElement::TRACK)
801 if(elements[iEle].trackRef()->algo() == 12)
806 if(elements[iEle].convRefs().
size())active[iEle]=
false;
816 cout<<endl<<
"--------------- loop 1 ------------------"<<endl;
843 vector<unsigned> hcalIs;
844 vector<unsigned> hoIs;
845 vector<unsigned> ecalIs;
846 vector<unsigned> trackIs;
847 vector<unsigned> ps1Is;
848 vector<unsigned> ps2Is;
850 vector<unsigned> hfEmIs;
851 vector<unsigned> hfHadIs;
854 for(
unsigned iEle=0; iEle<elements.
size(); iEle++) {
857 if(
debug_ && type != PFBlockElement::BREM )
cout<<endl<<elements[iEle];
860 case PFBlockElement::TRACK:
861 if ( active[iEle] ) {
863 if(
debug_)
cout<<
"TRACK, stored index, continue"<<endl;
867 if ( active[iEle] ) {
868 ecalIs.push_back( iEle );
869 if(
debug_)
cout<<
"ECAL, stored index, continue"<<endl;
873 if ( active[iEle] ) {
874 hcalIs.push_back( iEle );
875 if(
debug_)
cout<<
"HCAL, stored index, continue"<<endl;
878 case PFBlockElement::HO:
880 if ( active[iEle] ) {
881 hoIs.push_back( iEle );
882 if(
debug_)
cout<<
"HO, stored index, continue"<<endl;
886 case PFBlockElement::HFEM:
887 if ( active[iEle] ) {
888 hfEmIs.push_back( iEle );
889 if(
debug_)
cout<<
"HFEM, stored index, continue"<<endl;
892 case PFBlockElement::HFHAD:
893 if ( active[iEle] ) {
894 hfHadIs.push_back( iEle );
895 if(
debug_)
cout<<
"HFHAD, stored index, continue"<<endl;
903 unsigned iTrack = iEle;
909 if (active[iTrack] &&
isFromSecInt(elements[iEle],
"primary")){
910 bool isPrimaryTrack = elements[iEle].displacedVertexRef(PFBlockElement::T_TO_DISP)->displacedVertexRef()->isTherePrimaryTracks();
911 if (isPrimaryTrack) {
912 if (
debug_)
cout <<
"Primary Track reconstructed alone" << endl;
915 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEle );
916 active[iTrack] =
false;
922 if ( !active[iTrack] )
923 cout <<
"Already used by electrons, muons, conversions" << endl;
928 if ( ! active[iTrack] )
continue;
931 assert( !trackRef.
isNull() );
934 cout <<
"PFAlgo:processBlock "<<
" "<<trackIs.size()<<
" "<<ecalIs.size()<<
" "<<hcalIs.size()<<
" "<<hoIs.size()<<endl;
941 std::multimap<double, unsigned> ecalElems;
942 block.associatedElements( iTrack, linkData,
947 std::multimap<double, unsigned> hcalElems;
948 block.associatedElements( iTrack, linkData,
956 if ( hcalElems.empty() && !ecalElems.empty() ) {
959 unsigned index = ecalElems.begin()->second;
960 std::multimap<double, unsigned> sortedTracks;
961 block.associatedElements( index, linkData,
968 for(IE ie = sortedTracks.begin(); ie != sortedTracks.end(); ++ie ) {
969 unsigned jTrack = ie->second;
972 if ( !active[jTrack] )
continue;
976 if ( jTrack == iTrack )
continue;
981 std::multimap<double, unsigned> sortedECAL;
982 block.associatedElements( jTrack, linkData,
986 if ( sortedECAL.begin()->second !=
index )
continue;
991 std::multimap<double, unsigned> sortedHCAL;
992 block.associatedElements( jTrack, linkData,
996 if ( !sortedHCAL.size() )
continue;
1001 block.setLink( iTrack,
1002 sortedHCAL.begin()->second,
1003 sortedECAL.begin()->first,
1005 PFBlock::LINKTEST_RECHIT );
1010 block.associatedElements( iTrack, linkData,
1015 if (
debug_ && hcalElems.size() )
1016 std::cout <<
"Track linked back to HCAL due to ECAL sharing with other tracks" << std::endl;
1026 std::multimap<double,unsigned> gsfElems;
1028 block.associatedElements( iTrack, linkData,
1034 if(hcalElems.empty() &&
debug_) {
1035 cout<<
"no hcal element connected to track "<<iTrack<<endl;
1041 bool hcalFound =
false;
1044 cout<<
"now looping on elements associated to the track"<<endl;
1048 for(IE ie = ecalElems.begin(); ie != ecalElems.end(); ++ie ) {
1050 unsigned index = ie->second;
1054 double dist = ie->first;
1055 cout<<
"\telement "<<elements[
index]<<
" linked with distance = "<< dist <<endl;
1056 if ( ! active[index] )
cout <<
"This ECAL is already used - skip it" << endl;
1061 if ( ! active[index] )
continue;
1067 if( !hcalElems.empty() &&
debug_)
1068 cout<<
"\t\tat least one hcal element connected to the track."
1069 <<
" Sparing Ecal cluster for the hcal loop"<<endl;
1077 if( hcalElems.empty() ) {
1080 std::cout <<
"Now deals with tracks linked to no HCAL clusters" << std::endl;
1087 std::cout << elements[iTrack] << std::endl;
1093 if ( thisIsAMuon ) trackMomentum = 0.;
1097 bool rejectFake =
false;
1098 if ( !thisIsAMuon && elements[iTrack].trackRef()->ptError() >
ptError_ ) {
1102 elements[iTrack].trackRef()->
eta());
1105 if ( !ecalElems.empty() ) {
1106 unsigned thisEcal = ecalElems.begin()->second;
1108 deficit -= clusterRef->energy();
1110 clusterRef->positionREP().Eta());
1114 bool isPrimary =
isFromSecInt(elements[iTrack],
"primary");
1118 active[iTrack] =
false;
1120 std::cout << elements[iTrack] << std::endl
1121 <<
"is probably a fake (1) --> lock the track"
1126 if ( rejectFake )
continue;
1131 std::vector<unsigned> tmpi;
1132 std::vector<unsigned> kTrack;
1135 double Dpt = trackRef->ptError();
1138 trackMomentum > 30. && Dpt > 0.5 &&
1141 trackRef->algo() == TrackBase::tobTecStep ) ) {
1143 double dptRel = Dpt/trackRef->pt()*100;
1144 bool isPrimaryOrSecondary =
isFromSecInt(elements[iTrack],
"all");
1147 unsigned nHits = elements[iTrack].trackRef()->hitPattern().trackerLayersWithMeasurement();
1148 unsigned int NLostHit = trackRef->hitPattern().trackerLayersWithoutMeasurement(HitPattern::TRACK_HITS);
1151 std::cout <<
"A track (algo = " << trackRef->algo() <<
") with momentum " << trackMomentum
1152 <<
" / " << elements[iTrack].trackRef()->pt() <<
" +/- " << Dpt
1153 <<
" / " << elements[iTrack].trackRef()->eta()
1154 <<
" without any link to ECAL/HCAL and with " << nHits <<
" (" << NLostHit
1155 <<
") hits (lost hits) has been cleaned" << std::endl;
1156 active[iTrack] =
false;
1163 kTrack.push_back(iTrack);
1164 active[iTrack] =
false;
1167 if ( ecalElems.empty() ) {
1168 (*pfCandidates_)[tmpi[0]].setEcalEnergy( 0., 0. );
1169 (*pfCandidates_)[tmpi[0]].setHcalEnergy( 0., 0. );
1170 (*pfCandidates_)[tmpi[0]].setHoEnergy( 0., 0. );
1171 (*pfCandidates_)[tmpi[0]].setPs1Energy( 0 );
1172 (*pfCandidates_)[tmpi[0]].setPs2Energy( 0 );
1173 (*pfCandidates_)[tmpi[0]].addElementInBlock( blockref, kTrack[0] );
1178 unsigned thisEcal = ecalElems.begin()->second;
1180 if (
debug_ )
std::cout <<
" is associated to " << elements[thisEcal] << std::endl;
1184 if ( thisIsAMuon ) {
1185 (*pfCandidates_)[tmpi[0]].setEcalEnergy( clusterRef->energy(),
1187 (*pfCandidates_)[tmpi[0]].setHcalEnergy( 0., 0. );
1188 (*pfCandidates_)[tmpi[0]].setHoEnergy( 0., 0. );
1189 (*pfCandidates_)[tmpi[0]].setPs1Energy( 0 );
1190 (*pfCandidates_)[tmpi[0]].setPs2Energy( 0 );
1191 (*pfCandidates_)[tmpi[0]].addElementInBlock( blockref, kTrack[0] );
1194 double slopeEcal = 1.;
1195 bool connectedToEcal =
false;
1196 unsigned iEcal = 99999;
1197 double calibEcal = 0.;
1198 double calibHcal = 0.;
1199 double totalEcal = thisIsAMuon ? -
muonECAL_[0] : 0.;
1202 std::multimap<double, unsigned> sortedTracks;
1203 block.associatedElements( thisEcal, linkData,
1208 for(IE ie = sortedTracks.begin(); ie != sortedTracks.end(); ++ie ) {
1209 unsigned jTrack = ie->second;
1212 if ( !active[jTrack] )
continue;
1215 if ( jTrack == iTrack )
continue;
1220 std::multimap<double, unsigned> sortedECAL;
1221 block.associatedElements( jTrack, linkData,
1225 if ( sortedECAL.begin()->second != thisEcal )
continue;
1232 bool rejectFake =
false;
1234 if ( !thatIsAMuon && trackRef->ptError() >
ptError_) {
1235 double deficit = trackMomentum + trackRef->p() - clusterRef->energy();
1237 clusterRef->positionREP().Eta());
1238 resol *= (trackMomentum+trackRef->p());
1241 kTrack.push_back(jTrack);
1242 active[jTrack] =
false;
1244 std::cout << elements[jTrack] << std::endl
1245 <<
"is probably a fake (2) --> lock the track"
1249 if ( rejectFake )
continue;
1255 if ( !thatIsAMuon ) {
1257 std::cout <<
"Track momentum increased from " << trackMomentum <<
" GeV ";
1258 trackMomentum += trackRef->p();
1260 std::cout <<
"to " << trackMomentum <<
" GeV." << std::endl;
1261 std::cout <<
"with " << elements[jTrack] << std::endl;
1265 totalEcal =
std::max(totalEcal, 0.);
1273 kTrack.push_back(jTrack);
1274 active[jTrack] =
false;
1276 if ( thatIsAMuon ) {
1277 (*pfCandidates_)[tmpi.back()].setEcalEnergy(clusterRef->energy(),
1279 (*pfCandidates_)[tmpi.back()].setHcalEnergy( 0., 0. );
1280 (*pfCandidates_)[tmpi.back()].setHoEnergy( 0., 0. );
1281 (*pfCandidates_)[tmpi.back()].setPs1Energy( 0 );
1282 (*pfCandidates_)[tmpi.back()].setPs2Energy( 0 );
1283 (*pfCandidates_)[tmpi.back()].addElementInBlock( blockref, kTrack.back() );
1288 if (
debug_ )
std::cout <<
"Loop over all associated ECAL clusters" << std::endl;
1290 for(IE ie = ecalElems.begin(); ie != ecalElems.end(); ++ie ) {
1292 unsigned index = ie->second;
1298 if (
debug_ && ! active[index] )
std::cout <<
"is not active - ignore " << std::endl;
1299 if ( ! active[index] )
continue;
1303 block.associatedElements( index, linkData,
1308 for (
unsigned ic=0; ic<kTrack.size();++ic) {
1309 if ( sortedTracks.begin()->second == kTrack[ic] ) {
1314 if (
debug_ && skip )
std::cout <<
"is closer to another track - ignore " << std::endl;
1315 if ( skip )
continue;
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 ) {
1608 cerr<<
"Error: 2 elements, but not 1 HFEM and 1 HFHAD"<<endl;
1615 double energyHfEm = cem->energy();
1616 double energyHfHad = chad->energy();
1617 double uncalibratedenergyHFEm = energyHfEm;
1618 double uncalibratedenergyHFHad = energyHfHad;
1623 c0->positionREP().Eta(),
1624 c0->positionREP().Phi());
1626 uncalibratedenergyHFHad,
1627 c1->positionREP().Eta(),
1628 c1->positionREP().Phi());
1631 (*pfCandidates_)[tmpi].setEcalEnergy( uncalibratedenergyHFEm, energyHfEm );
1632 (*pfCandidates_)[tmpi].setHcalEnergy( uncalibratedenergyHFHad, energyHfHad);
1633 (*pfCandidates_)[tmpi].setHoEnergy( 0., 0.);
1634 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
1635 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
1636 (*pfCandidates_)[tmpi].addElementInBlock( blockref, hfEmIs[0] );
1637 (*pfCandidates_)[tmpi].addElementInBlock( blockref, hfHadIs[0] );
1643 cerr<<
"Warning: HF, but n elem different from 1 or 2"<<endl;
1654 cout<<endl<<
"--------------- loop hcal ---------------------"<<endl;
1663 for(
unsigned i=0;
i<hcalIs.size();
i++) {
1665 unsigned iHcal= hcalIs[
i];
1670 if(
debug_)
cout<<endl<<elements[iHcal]<<endl;
1676 std::multimap<double, unsigned> sortedTracks;
1677 block.associatedElements( iHcal, linkData,
1682 std::multimap< unsigned, std::pair<double, unsigned> > associatedEcals;
1684 std::map< unsigned, std::pair<double, double> > associatedPSs;
1686 std::multimap<double, std::pair<unsigned,bool> > associatedTracks;
1689 std::multimap<double,std::pair<unsigned,::math::XYZVector> > ecalSatellites;
1690 std::pair<unsigned,::math::XYZVector> fakeSatellite = make_pair(iHcal,::
math::XYZVector(0.,0.,0.));
1691 ecalSatellites.insert( make_pair(-1., fakeSatellite) );
1693 std::multimap< unsigned, std::pair<double, unsigned> > associatedHOs;
1695 PFClusterRef hclusterref = elements[iHcal].clusterRef();
1696 assert(!hclusterref.
isNull() );
1706 if( sortedTracks.empty() ) {
1708 cout<<
"\tno associated tracks, keep for later"<<endl;
1713 active[iHcal] =
false;
1721 if(
debug_)
cout<<
"\t"<<sortedTracks.size()<<
" associated tracks:"<<endl;
1723 double totalChargedMomentum = 0;
1724 double sumpError2 = 0.;
1725 double totalHO = 0.;
1726 double totalEcal = 0.;
1727 double totalHcal = hclusterref->energy();
1728 vector<double> hcalP;
1729 vector<double> hcalDP;
1730 vector<unsigned> tkIs;
1731 double maxDPovP = -9999.;
1734 vector< unsigned > chargedHadronsIndices;
1735 vector< unsigned > chargedHadronsInBlock;
1736 double mergedNeutralHadronEnergy = 0;
1737 double mergedPhotonEnergy = 0;
1738 double muonHCALEnergy = 0.;
1739 double muonECALEnergy = 0.;
1740 double muonHCALError = 0.;
1741 double muonECALError = 0.;
1742 unsigned nMuons = 0;
1746 std::vector<std::pair<unsigned,::math::XYZVector> >
ecalClusters;
1747 double sumEcalClusters=0;
1749 hclusterref->position().Y(),
1750 hclusterref->position().Z());
1751 hadronDirection = hadronDirection.Unit();
1755 for(IE ie = sortedTracks.begin(); ie != sortedTracks.end(); ++ie ) {
1757 unsigned iTrack = ie->second;
1760 if ( !active[iTrack] )
continue;
1766 assert( !trackRef.
isNull() );
1771 ::math::XYZVector chargedDirection(chargedPosition.X(),chargedPosition.Y(),chargedPosition.Z());
1772 chargedDirection = chargedDirection.Unit();
1775 std::multimap<double, unsigned> sortedEcals;
1776 block.associatedElements( iTrack, linkData,
1781 if(
debug_)
cout<<
"\t\t\tnumber of Ecal elements linked to this track: "
1782 <<sortedEcals.size()<<endl;
1785 std::multimap<double, unsigned> sortedHOs;
1787 block.associatedElements( iTrack, linkData,
1794 cout<<
"PFAlgo : number of HO elements linked to this track: "
1795 <<sortedHOs.size()<<endl;
1803 bool thisIsALooseMuon =
false;
1811 if ( thisIsAMuon ) {
1813 std::cout <<
"\t\tThis track is identified as a muon - remove it from the stack" << std::endl;
1814 std::cout <<
"\t\t" << elements[iTrack] << std::endl;
1822 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iTrack );
1823 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
1829 bool letMuonEatCaloEnergy =
false;
1831 if(thisIsAnIsolatedMuon){
1833 double totalCaloEnergy = totalHcal / 1.30;
1835 if( !sortedEcals.empty() ) {
1836 iEcal = sortedEcals.begin()->second;
1837 PFClusterRef eclusterref = elements[iEcal].clusterRef();
1838 totalCaloEnergy += eclusterref->energy();
1844 if( !sortedHOs.empty() ) {
1845 iHO = sortedHOs.begin()->second;
1847 totalCaloEnergy += eclusterref->energy() / 1.30;
1853 if( (
pfCandidates_->back()).
p() > totalCaloEnergy ) letMuonEatCaloEnergy =
true;
1856 if(letMuonEatCaloEnergy) muonHcal = totalHcal;
1857 double muonEcal =0.;
1859 if( !sortedEcals.empty() ) {
1860 iEcal = sortedEcals.begin()->second;
1861 PFClusterRef eclusterref = elements[iEcal].clusterRef();
1862 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal);
1864 if(letMuonEatCaloEnergy) muonEcal = eclusterref->energy();
1866 if ( eclusterref->energy() - muonEcal < 0.2 ) active[iEcal] =
false;
1867 (*pfCandidates_)[tmpi].setEcalEnergy(eclusterref->energy(), muonEcal);
1872 if( !sortedHOs.empty() ) {
1873 iHO = sortedHOs.begin()->second;
1874 PFClusterRef hoclusterref = elements[iHO].clusterRef();
1875 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHO);
1877 if(letMuonEatCaloEnergy) muonHO = hoclusterref->energy();
1879 if ( hoclusterref->energy() - muonHO < 0.2 ) active[iHO] =
false;
1880 (*pfCandidates_)[tmpi].setHcalEnergy(totalHcal, muonHcal);
1881 (*pfCandidates_)[tmpi].setHoEnergy(hoclusterref->energy(), muonHO);
1884 (*pfCandidates_)[tmpi].setHcalEnergy(totalHcal, muonHcal);
1887 if(letMuonEatCaloEnergy){
1888 muonHCALEnergy += totalHcal;
1889 if (
useHO_) muonHCALEnergy +=muonHO;
1890 muonHCALError += 0.;
1891 muonECALEnergy += muonEcal;
1892 muonECALError += 0.;
1893 photonAtECAL -= muonEcal*chargedDirection;
1894 hadronAtECAL -= totalHcal*chargedDirection;
1895 if ( !sortedEcals.empty() ) active[iEcal] =
false;
1896 active[iHcal] =
false;
1897 if (
useHO_ && !sortedHOs.empty() ) active[iHO] =
false;
1903 if ( muonHO > 0. ) {
1910 photonAtECAL -= muonECAL_[0]*chargedDirection;
1911 hadronAtECAL -= muonHCAL_[0]*chargedDirection;
1915 active[iTrack] =
false;
1922 if(
debug_)
cout<<
"\t\t"<<elements[iTrack]<<endl;
1930 if ( thisIsALooseMuon && !thisIsAMuon ) nMuons += 1;
1935 double Dpt = trackRef->ptError();
1936 double blowError = 1.;
1937 switch (trackRef->algo()) {
1938 case TrackBase::ctf:
1940 case TrackBase::lowPtTripletStep:
1941 case TrackBase::pixelPairStep:
1944 case TrackBase::jetCoreRegionalStep:
1945 case TrackBase::muonSeededStepInOut:
1946 case TrackBase::muonSeededStepOutIn:
1952 case TrackBase::tobTecStep:
1972 bool isPrimaryOrSecondary =
isFromSecInt(elements[iTrack],
"all");
1974 if ( isPrimaryOrSecondary ) blowError = 1.;
1976 std::pair<unsigned,bool> tkmuon = make_pair(iTrack,thisIsALooseMuon);
1977 associatedTracks.insert( make_pair(-Dpt*blowError, tkmuon) );
1980 double Dp = trackRef->qoverpError()*trackMomentum*
trackMomentum;
1981 sumpError2 += Dp*Dp;
1983 bool connectedToEcal =
false;
1984 if( !sortedEcals.empty() )
1988 for ( IE iec=sortedEcals.begin();
1989 iec!=sortedEcals.end(); ++iec ) {
1991 unsigned iEcal = iec->second;
1992 double dist = iec->first;
1995 if( !active[iEcal] ) {
2003 PFClusterRef eclusterref = elements[iEcal].clusterRef();
2004 assert(!eclusterref.
isNull() );
2007 std::multimap<double, unsigned> sortedTracksEcal;
2008 block.associatedElements( iEcal, linkData,
2012 unsigned jTrack = sortedTracksEcal.
begin()->second;
2013 if ( jTrack != iTrack )
continue;
2017 double distEcal = block.dist(jTrack,iEcal,linkData,
2025 vector<double> ps1Ene(1,static_cast<double>(0.));
2027 block, elements, linkData, active,
2029 vector<double> ps2Ene(1,static_cast<double>(0.));
2031 block, elements, linkData, active,
2033 std::pair<double,double> psEnes = make_pair(ps1Ene[0],
2035 associatedPSs.insert(make_pair(iEcal,psEnes));
2038 bool crackCorrection =
false;
2039 float ecalEnergyCalibrated =
calibration_->energyEm(*eclusterref,ps1Ene,ps2Ene,crackCorrection);
2041 eclusterref->position().Y(),
2042 eclusterref->position().Z());
2043 photonDirection = photonDirection.Unit();
2045 if ( !connectedToEcal ) {
2048 <<elements[iEcal]<<endl;
2050 connectedToEcal =
true;
2054 std::pair<unsigned,::math::XYZVector> satellite =
2055 make_pair(iEcal,ecalEnergyCalibrated*photonDirection);
2056 ecalSatellites.insert( make_pair(-1., satellite) );
2060 std::pair<unsigned,::math::XYZVector> satellite =
2061 make_pair(iEcal,ecalEnergyCalibrated*photonDirection);
2062 ecalSatellites.insert( make_pair(dist, satellite) );
2066 std::pair<double, unsigned> associatedEcal
2067 = make_pair( distEcal, iEcal );
2068 associatedEcals.insert( make_pair(iTrack, associatedEcal) );
2073 if(
useHO_ && !sortedHOs.empty() )
2077 for ( IE ieho=sortedHOs.begin(); ieho!=sortedHOs.end(); ++ieho ) {
2079 unsigned iHO = ieho->second;
2080 double distHO = ieho->first;
2083 if( !active[iHO] ) {
2090 assert( type == PFBlockElement::HO );
2091 PFClusterRef hoclusterref = elements[iHO].clusterRef();
2092 assert(!hoclusterref.
isNull() );
2095 std::multimap<double, unsigned> sortedTracksHO;
2096 block.associatedElements( iHO, linkData,
2100 unsigned jTrack = sortedTracksHO.
begin()->second;
2101 if ( jTrack != iTrack )
continue;
2109 totalHO += hoclusterref->energy();
2110 active[iHO] =
false;
2112 std::pair<double, unsigned> associatedHO
2113 = make_pair( distHO, iHO );
2114 associatedHOs.insert( make_pair(iTrack, associatedHO) );
2123 totalHcal += totalHO;
2127 double caloEnergy = 0.;
2128 double slopeEcal = 1.0;
2129 double calibEcal = 0.;
2130 double calibHcal = 0.;
2131 hadronDirection = hadronAtECAL.Unit();
2135 Caloresolution *= totalChargedMomentum;
2137 Caloresolution =
std::sqrt(Caloresolution*Caloresolution + muonHCALError + muonECALError);
2138 totalEcal -=
std::min(totalEcal,muonECALEnergy);
2139 totalHcal -=
std::min(totalHcal,muonHCALEnergy);
2147 for ( IS is = ecalSatellites.begin(); is != ecalSatellites.end(); ++is ) {
2150 double previousCalibEcal = calibEcal;
2151 double previousCalibHcal = calibHcal;
2152 double previousCaloEnergy = caloEnergy;
2153 double previousSlopeEcal = slopeEcal;
2156 totalEcal +=
sqrt(is->second.second.Mag2());
2157 photonAtECAL += is->second.second;
2158 calibEcal =
std::max(0.,totalEcal);
2159 calibHcal =
std::max(0.,totalHcal);
2160 hadronAtECAL = calibHcal * hadronDirection;
2162 calibration_->energyEmHad(totalChargedMomentum,calibEcal,calibHcal,
2163 hclusterref->positionREP().Eta(),
2164 hclusterref->positionREP().Phi());
2165 caloEnergy = calibEcal+calibHcal;
2166 if ( totalEcal > 0.) slopeEcal = calibEcal/totalEcal;
2168 hadronAtECAL = calibHcal * hadronDirection;
2172 if ( is->first < 0. || caloEnergy - totalChargedMomentum <= 0. ) {
2173 if(
debug_)
cout<<
"\t\t\tactive, adding "<<is->second.second
2174 <<
" to ECAL energy, and locking"<<endl;
2175 active[is->second.first] =
false;
2176 double clusterEnergy=
sqrt(is->second.second.Mag2());
2177 if(clusterEnergy>50) {
2178 ecalClusters.push_back(is->second);
2179 sumEcalClusters+=clusterEnergy;
2186 totalEcal -=
sqrt(is->second.second.Mag2());
2187 photonAtECAL -= is->second.second;
2188 calibEcal = previousCalibEcal;
2189 calibHcal = previousCalibHcal;
2190 hadronAtECAL = previousHadronAtECAL;
2191 slopeEcal = previousSlopeEcal;
2192 caloEnergy = previousCaloEnergy;
2199 assert(caloEnergy>=0);
2212 double TotalError =
sqrt(sumpError2 + Caloresolution*Caloresolution);
2216 if ( totalChargedMomentum - caloEnergy >
nSigmaTRACK_*Caloresolution ) {
2231 for ( IT it = associatedTracks.begin(); it != associatedTracks.end(); ++it ) {
2232 unsigned iTrack = it->second.first;
2234 if ( !active[iTrack] )
continue;
2236 if ( !it->second.second )
continue;
2238 double trackMomentum = elements[it->second.first].trackRef()->p();
2241 std::multimap<double, unsigned> sortedEcals;
2242 block.associatedElements( iTrack, linkData,
2246 std::multimap<double, unsigned> sortedHOs;
2247 block.associatedElements( iTrack, linkData,
2255 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iTrack );
2256 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
2259 (*pfCandidates_)[tmpi].setHcalEnergy(totalHcal,muonHcal);
2260 if( !sortedEcals.empty() ) {
2261 unsigned iEcal = sortedEcals.begin()->second;
2262 PFClusterRef eclusterref = elements[iEcal].clusterRef();
2263 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal);
2265 (*pfCandidates_)[tmpi].setEcalEnergy(eclusterref->energy(),muonEcal);
2267 if(
useHO_ && !sortedHOs.empty() ) {
2268 unsigned iHO = sortedHOs.begin()->second;
2269 PFClusterRef hoclusterref = elements[iHO].clusterRef();
2270 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHO);
2272 (*pfCandidates_)[tmpi].setHcalEnergy(totalHcal-totalHO,muonHcal);
2273 (*pfCandidates_)[tmpi].setHoEnergy(hoclusterref->energy(),muonHO);
2278 ::math::XYZVector chargedDirection(chargedPosition.X(), chargedPosition.Y(), chargedPosition.Z());
2279 chargedDirection = chargedDirection.Unit();
2282 if ( totalEcal > 0. )
2284 if ( totalHcal > 0. )
2289 if ( totalHcal >
muonHCAL_[0] ) hadronAtECAL -=
muonHCAL_[0]*calibHcal/totalHcal * chargedDirection;
2290 caloEnergy = calibEcal+calibHcal;
2293 if ( muonHO > 0. ) {
2296 if ( totalHcal > 0. ) {
2297 calibHcal -=
std::min(calibHcal,muonHO_[0]*calibHcal/totalHcal);
2298 totalHcal -=
std::min(totalHcal,muonHO_[0]);
2303 active[iTrack] =
false;
2310 Caloresolution *= totalChargedMomentum;
2311 Caloresolution =
std::sqrt(Caloresolution*Caloresolution + muonHCALError + muonECALError);
2329 unsigned corrTrack = 10000000;
2330 double corrFact = 1.;
2333 totalChargedMomentum - caloEnergy >
nSigmaTRACK_*Caloresolution) {
2335 for ( IT it = associatedTracks.begin(); it != associatedTracks.end(); ++it ) {
2336 unsigned iTrack = it->second.first;
2338 if ( !active[iTrack] )
continue;
2339 const reco::TrackRef& trackref = elements[it->second.first].trackRef();
2341 double dptRel = fabs(it->first)/trackref->pt()*100;
2342 bool isSecondary =
isFromSecInt(elements[iTrack],
"secondary");
2343 bool isPrimary =
isFromSecInt(elements[iTrack],
"primary");
2347 if ( fabs(it->first) <
ptError_ )
break;
2349 double wouldBeTotalChargedMomentum =
2350 totalChargedMomentum - trackref->p();
2354 if ( wouldBeTotalChargedMomentum > caloEnergy ) {
2356 if (
debug_ && isSecondary) {
2357 cout <<
"In bad track rejection step dptRel = " << dptRel <<
" dptRel_DispVtx_ = " <<
dptRel_DispVtx_ << endl;
2358 cout <<
"The calo energy would be still smaller even without this track but it is attached to a NI"<< endl;
2363 active[iTrack] =
false;
2364 totalChargedMomentum = wouldBeTotalChargedMomentum;
2366 std::cout <<
"\tElement " << elements[iTrack]
2367 <<
" rejected (Dpt = " << -it->first
2368 <<
" GeV/c, algo = " << trackref->algo() <<
")" << std::endl;
2371 if(isPrimary)
break;
2373 corrFact = (caloEnergy - wouldBeTotalChargedMomentum)/elements[it->second.first].trackRef()->p();
2374 if ( trackref->p()*corrFact < 0.05 ) {
2376 active[iTrack] =
false;
2378 totalChargedMomentum -= trackref->p()*(1.-corrFact);
2380 std::cout <<
"\tElement " << elements[iTrack]
2381 <<
" (Dpt = " << -it->first
2382 <<
" GeV/c, algo = " << trackref->algo()
2383 <<
") rescaled by " << corrFact
2384 <<
" Now the total charged momentum is " << totalChargedMomentum << endl;
2392 Caloresolution *= totalChargedMomentum;
2393 Caloresolution =
std::sqrt(Caloresolution*Caloresolution + muonHCALError + muonECALError);
2399 sortedTracks.size() > 1 &&
2400 totalChargedMomentum - caloEnergy >
nSigmaTRACK_*Caloresolution ) {
2401 for ( IT it = associatedTracks.begin(); it != associatedTracks.end(); ++it ) {
2402 unsigned iTrack = it->second.first;
2404 if ( !active[iTrack] )
continue;
2406 double dptRel = fabs(it->first)/trackref->pt()*100;
2407 bool isPrimaryOrSecondary =
isFromSecInt(elements[iTrack],
"all");
2414 switch (trackref->algo()) {
2415 case TrackBase::ctf:
2417 case TrackBase::lowPtTripletStep:
2418 case TrackBase::pixelPairStep:
2421 case TrackBase::jetCoreRegionalStep:
2422 case TrackBase::muonSeededStepInOut:
2423 case TrackBase::muonSeededStepOutIn:
2426 case TrackBase::tobTecStep:
2427 active[iTrack] =
false;
2428 totalChargedMomentum -= trackref->p();
2431 std::cout <<
"\tElement " << elements[iTrack]
2432 <<
" rejected (Dpt = " << -it->first
2433 <<
" GeV/c, algo = " << trackref->algo() <<
")" << std::endl;
2450 Caloresolution *= totalChargedMomentum;
2451 Caloresolution =
std::sqrt(Caloresolution*Caloresolution + muonHCALError + muonECALError);
2455 for ( IT it = associatedTracks.begin(); it != associatedTracks.end(); ++it ) {
2456 unsigned iTrack = it->second.first;
2457 if ( !active[iTrack] )
continue;
2460 double Dp = trackRef->qoverpError()*trackMomentum*
trackMomentum;
2464 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iTrack );
2465 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
2466 std::pair<II,II> myEcals = associatedEcals.equal_range(iTrack);
2467 for (II
ii=myEcals.first;
ii!=myEcals.second; ++
ii ) {
2468 unsigned iEcal =
ii->second.second;
2469 if ( active[iEcal] )
continue;
2470 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal );
2474 std::pair<II,II> myHOs = associatedHOs.equal_range(iTrack);
2475 for (II
ii=myHOs.first;
ii!=myHOs.second; ++
ii ) {
2476 unsigned iHO =
ii->second.second;
2477 if ( active[iHO] )
continue;
2478 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHO );
2482 if ( iTrack == corrTrack ) {
2483 (*pfCandidates_)[tmpi].rescaleMomentum(corrFact);
2484 trackMomentum *= corrFact;
2486 chargedHadronsIndices.push_back( tmpi );
2487 chargedHadronsInBlock.push_back( iTrack );
2488 active[iTrack] =
false;
2489 hcalP.push_back(trackMomentum);
2490 hcalDP.push_back(Dp);
2491 if (Dp/trackMomentum > maxDPovP) maxDPovP = Dp/
trackMomentum;
2492 sumpError2 += Dp*Dp;
2496 TotalError =
sqrt(sumpError2 + Caloresolution*Caloresolution);
2499 cout<<
"\tCompare Calo Energy to total charged momentum "<<endl;
2500 cout<<
"\t\tsum p = "<<totalChargedMomentum<<
" +- "<<
sqrt(sumpError2)<<endl;
2501 cout<<
"\t\tsum ecal = "<<totalEcal<<endl;
2502 cout<<
"\t\tsum hcal = "<<totalHcal<<endl;
2503 cout<<
"\t\t => Calo Energy = "<<caloEnergy<<
" +- "<<Caloresolution<<endl;
2504 cout<<
"\t\t => Calo Energy- total charged momentum = "
2505 <<caloEnergy-totalChargedMomentum<<
" +- "<<TotalError<<endl;
2512 double nsigma =
nSigmaHCAL(totalChargedMomentum,hclusterref->positionREP().Eta());
2514 if (
abs(totalChargedMomentum-caloEnergy)<nsigma*TotalError ) {
2520 cout<<
"\t\tcase 1: COMPATIBLE "
2521 <<
"|Calo Energy- total charged momentum| = "
2522 <<
abs(caloEnergy-totalChargedMomentum)
2523 <<
" < "<<nsigma<<
" x "<<TotalError<<endl;
2524 if (maxDPovP < 0.1 )
2525 cout<<
"\t\t\tmax DP/P = "<< maxDPovP
2526 <<
" less than 0.1: do nothing "<<endl;
2528 cout<<
"\t\t\tmax DP/P = "<< maxDPovP
2529 <<
" > 0.1: take weighted averages "<<endl;
2533 if (maxDPovP > 0.1) {
2537 int nrows = chargedHadronsIndices.size();
2538 TMatrixTSym<double>
a (nrows);
2540 TVectorD
check(nrows);
2541 double sigma2E = Caloresolution*Caloresolution;
2542 for(
int i=0;
i<nrows;
i++) {
2543 double sigma2i = hcalDP[
i]*hcalDP[
i];
2545 cout<<
"\t\t\ttrack associated to hcal "<<
i
2546 <<
" P = "<<hcalP[
i]<<
" +- "
2549 a(
i,
i) = 1./sigma2i + 1./sigma2E;
2550 b(
i) = hcalP[
i]/sigma2i + caloEnergy/sigma2E;
2551 for(
int j=0;
j<nrows;
j++) {
2553 a(
i,
j) = 1./sigma2E;
2564 TDecompChol decomp(a);
2566 TVectorD
x = decomp.Solve(b, ok);
2570 for (
int i=0;
i<nrows;
i++){
2572 unsigned ich = chargedHadronsIndices[
i];
2573 double rescaleFactor =
x(
i)/hcalP[
i];
2574 (*pfCandidates_)[ich].rescaleMomentum( rescaleFactor );
2577 cout<<
"\t\t\told p "<<hcalP[
i]
2579 <<
" rescale "<<rescaleFactor<<endl;
2584 cerr<<
"not ok!"<<endl;
2591 else if( caloEnergy > totalChargedMomentum ) {
2610 double eNeutralHadron = caloEnergy - totalChargedMomentum;
2611 double ePhoton = (caloEnergy - totalChargedMomentum) / slopeEcal;
2614 if(!sortedTracks.empty() ){
2615 cout<<
"\t\tcase 2: NEUTRAL DETECTION "
2616 <<caloEnergy<<
" > "<<nsigma<<
"x"<<TotalError
2617 <<
" + "<<totalChargedMomentum<<endl;
2618 cout<<
"\t\tneutral activity detected: "<<endl
2619 <<
"\t\t\t photon = "<<ePhoton<<endl
2620 <<
"\t\t\tor neutral hadron = "<<eNeutralHadron<<endl;
2622 cout<<
"\t\tphoton or hadron ?"<<endl;}
2624 if(sortedTracks.empty() )
2625 cout<<
"\t\tno track -> hadron "<<endl;
2627 cout<<
"\t\t"<<sortedTracks.size()
2628 <<
"tracks -> check if the excess is photonic or hadronic"<<endl;
2632 double ratioMax = 0.;
2634 unsigned maxiEcal= 9999;
2638 for(IE ie = sortedTracks.begin(); ie != sortedTracks.end(); ++ie ) {
2640 unsigned iTrack = ie->second;
2646 assert( !trackRef.
isNull() );
2648 II iae = associatedEcals.find(iTrack);
2650 if( iae == associatedEcals.end() )
continue;
2653 unsigned iEcal = iae->second.second;
2659 assert( !clusterRef.
isNull() );
2661 double pTrack = trackRef->p();
2662 double eECAL = clusterRef->energy();
2663 double eECALOverpTrack = eECAL / pTrack;
2665 if ( eECALOverpTrack > ratioMax ) {
2666 ratioMax = eECALOverpTrack;
2667 maxEcalRef = clusterRef;
2673 std::vector<reco::PFClusterRef> pivotalClusterRef;
2674 std::vector<unsigned> iPivotal;
2675 std::vector<double> particleEnergy, ecalEnergy, hcalEnergy, rawecalEnergy, rawhcalEnergy;
2676 std::vector<::math::XYZVector> particleDirection;
2680 if ( ePhoton < totalEcal || eNeutralHadron-calibEcal < 1E-10 ) {
2681 if ( !maxEcalRef.
isNull() ) {
2683 mergedPhotonEnergy = ePhoton;
2687 if ( !maxEcalRef.
isNull() ) {
2689 mergedPhotonEnergy = totalEcal;
2692 mergedNeutralHadronEnergy = eNeutralHadron-calibEcal;
2695 if ( mergedPhotonEnergy > 0 ) {
2698 if ( ecalClusters.size()<=1 ) {
2699 ecalClusters.clear();
2700 ecalClusters.push_back(make_pair(maxiEcal, photonAtECAL));
2701 sumEcalClusters=
sqrt(photonAtECAL.Mag2());
2703 for(std::vector<std::pair<unsigned,::math::XYZVector> >::const_iterator pae = ecalClusters.begin(); pae != ecalClusters.end(); ++pae ) {
2704 double clusterEnergy=
sqrt(pae->second.Mag2());
2705 particleEnergy.push_back(mergedPhotonEnergy*clusterEnergy/sumEcalClusters);
2706 particleDirection.push_back(pae->second);
2707 ecalEnergy.push_back(mergedPhotonEnergy*clusterEnergy/sumEcalClusters);
2708 hcalEnergy.push_back(0.);
2709 rawecalEnergy.push_back(totalEcal);
2710 rawhcalEnergy.push_back(totalHcal);
2711 pivotalClusterRef.push_back(elements[pae->first].clusterRef());
2712 iPivotal.push_back(pae->first);
2716 if ( mergedNeutralHadronEnergy > 1.0 ) {
2719 if ( ecalClusters.size()<=1 ) {
2720 ecalClusters.clear();
2721 ecalClusters.push_back(make_pair(iHcal, hadronAtECAL));
2722 sumEcalClusters=
sqrt(hadronAtECAL.Mag2());
2724 for(std::vector<std::pair<unsigned,::math::XYZVector> >::const_iterator pae = ecalClusters.begin(); pae != ecalClusters.end(); ++pae ) {
2725 double clusterEnergy=
sqrt(pae->second.Mag2());
2726 particleEnergy.push_back(mergedNeutralHadronEnergy*clusterEnergy/sumEcalClusters);
2727 particleDirection.push_back(pae->second);
2728 ecalEnergy.push_back(0.);
2729 hcalEnergy.push_back(mergedNeutralHadronEnergy*clusterEnergy/sumEcalClusters);
2730 rawecalEnergy.push_back(totalEcal);
2731 rawhcalEnergy.push_back(totalHcal);
2732 pivotalClusterRef.push_back(hclusterref);
2733 iPivotal.push_back(iHcal);
2741 for (
unsigned iPivot=0; iPivot<iPivotal.size(); ++iPivot ) {
2743 if ( particleEnergy[iPivot] < 0. )
2744 std::cout <<
"ALARM = Negative energy ! "
2745 << particleEnergy[iPivot] << std::endl;
2747 bool useDirection =
true;
2749 particleEnergy[iPivot],
2751 particleDirection[iPivot].
X(),
2752 particleDirection[iPivot].Y(),
2753 particleDirection[iPivot].
Z());
2756 (*pfCandidates_)[tmpi].setEcalEnergy( rawecalEnergy[iPivot],ecalEnergy[iPivot] );
2758 (*pfCandidates_)[tmpi].setHcalEnergy( rawhcalEnergy[iPivot],hcalEnergy[iPivot] );
2759 (*pfCandidates_)[tmpi].setHoEnergy(0., 0.);
2761 (*pfCandidates_)[tmpi].setHcalEnergy( rawhcalEnergy[iPivot]-totalHO,hcalEnergy[iPivot]*(1.-totalHO/rawhcalEnergy[iPivot]));
2762 (*pfCandidates_)[tmpi].setHoEnergy(totalHO, totalHO * hcalEnergy[iPivot]/rawhcalEnergy[iPivot]);
2764 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
2765 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
2766 (*pfCandidates_)[tmpi].set_mva_nothing_gamma( -1. );
2769 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
2770 for (
unsigned ich=0; ich<chargedHadronsInBlock.size(); ++ich) {
2771 unsigned iTrack = chargedHadronsInBlock[ich];
2772 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iTrack );
2778 std::pair<II,II> myEcals = associatedEcals.equal_range(iTrack);
2779 for (II
ii=myEcals.first;
ii!=myEcals.second; ++
ii ) {
2780 unsigned iEcal =
ii->second.second;
2781 if ( active[iEcal] )
continue;
2782 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal );
2794 double totalHcalEnergyCalibrated = calibHcal;
2795 double totalEcalEnergyCalibrated = calibEcal;
2810 totalHcalEnergyCalibrated -= mergedNeutralHadronEnergy;
2812 totalEcalEnergyCalibrated -= mergedPhotonEnergy;
2817 double chargedHadronsTotalEnergy = 0;
2818 for(
unsigned ich=0; ich<chargedHadronsIndices.size(); ++ich ) {
2819 unsigned index = chargedHadronsIndices[ich];
2821 chargedHadronsTotalEnergy += chargedHadron.
energy();
2824 for(
unsigned ich=0; ich<chargedHadronsIndices.size(); ++ich ) {
2825 unsigned index = chargedHadronsIndices[ich];
2827 float fraction = chargedHadron.
energy()/chargedHadronsTotalEnergy;
2830 chargedHadron.
setHcalEnergy( fraction * totalHcal, fraction * totalHcalEnergyCalibrated );
2833 chargedHadron.
setHcalEnergy( fraction * (totalHcal-totalHO), fraction * totalHcalEnergyCalibrated * (1.-totalHO/totalHcal) );
2834 chargedHadron.
setHoEnergy( fraction * totalHO, fraction * totalHO * totalHcalEnergyCalibrated / totalHcal );
2837 chargedHadron.
setEcalEnergy( fraction * totalEcal, fraction * totalEcalEnergyCalibrated );
2841 for ( IS is = ecalSatellites.begin(); is != ecalSatellites.end(); ++is ) {
2844 unsigned iEcal = is->second.first;
2845 if ( !active[iEcal] )
continue;
2850 PFClusterRef eclusterref = elements[iEcal].clusterRef();
2851 assert(!eclusterref.
isNull() );
2854 active[iEcal] =
false;
2857 std::multimap<double, unsigned> assTracks;
2858 block.associatedElements( iEcal, linkData,
2865 (*pfCandidates_)[tmpi].setEcalEnergy( eclusterref->energy(),
sqrt(is->second.second.Mag2()) );
2866 (*pfCandidates_)[tmpi].setHcalEnergy( 0., 0. );
2867 (*pfCandidates_)[tmpi].setHoEnergy( 0., 0. );
2868 (*pfCandidates_)[tmpi].setPs1Energy( associatedPSs[iEcal].
first );
2869 (*pfCandidates_)[tmpi].setPs2Energy( associatedPSs[iEcal].
second );
2870 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal );
2871 (*pfCandidates_)[tmpi].addElementInBlock( blockref, sortedTracks.begin()->second) ;
2885 <<
"---- loop remaining hcal ------- "<<endl;
2891 for(
unsigned ihcluster=0; ihcluster<hcalIs.size(); ihcluster++) {
2892 unsigned iHcal = hcalIs[ihcluster];
2895 std::vector<unsigned> ecalRefs;
2896 std::vector<unsigned> hoRefs;
2899 cout<<endl<<elements[iHcal]<<
" ";
2902 if( !active[iHcal] ) {
2904 cout<<
"not active"<<endl;
2909 std::multimap<double, unsigned> ecalElems;
2910 block.associatedElements( iHcal, linkData,
2916 float totalEcal = 0.;
2919 for(IE ie = ecalElems.begin(); ie != ecalElems.end(); ++ie ) {
2921 unsigned iEcal = ie->second;
2922 double dist = ie->first;
2927 if( !active[iEcal] )
continue;
2948 std::multimap<double, unsigned> hcalElems;
2949 block.associatedElements( iEcal, linkData,
2954 bool isClosest =
true;
2955 for(IE ih = hcalElems.begin(); ih != hcalElems.end(); ++ih ) {
2957 unsigned jHcal = ih->second;
2958 double distH = ih->first;
2960 if ( !active[jHcal] )
continue;
2962 if ( distH < dist ) {
2969 if (!isClosest)
continue;
2973 cout<<
"\telement "<<elements[iEcal]<<
" linked with dist "<< dist<<endl;
2974 cout<<
"Added to HCAL cluster to form a neutral hadron"<<endl;
2978 assert( !eclusterRef.
isNull() );
2981 vector<double> ps1Ene(1,static_cast<double>(0.));
2983 vector<double> ps2Ene(1,static_cast<double>(0.));
2985 bool crackCorrection =
false;
2986 double ecalEnergy =
calibration_->energyEm(*eclusterRef,ps1Ene,ps2Ene,crackCorrection);
2990 totalEcal += ecalEnergy;
2991 if ( ecalEnergy > ecalMax ) {
2992 ecalMax = ecalEnergy;
2993 eClusterRef = eclusterRef;
2996 ecalRefs.push_back(iEcal);
2997 active[iEcal] =
false;
3003 double totalHO = 0.;
3007 std::multimap<double, unsigned> hoElems;
3008 block.associatedElements( iHcal, linkData,
3018 for(IE ie = hoElems.begin(); ie != hoElems.end(); ++ie ) {
3020 unsigned iHO = ie->second;
3021 double dist = ie->first;
3023 assert( type == PFBlockElement::HO );
3026 if( !active[iHO] )
continue;
3032 std::multimap<double, unsigned> hcalElems;
3033 block.associatedElements( iHO, linkData,
3038 bool isClosest =
true;
3039 for(IE ih = hcalElems.begin(); ih != hcalElems.end(); ++ih ) {
3041 unsigned jHcal = ih->second;
3042 double distH = ih->first;
3044 if ( !active[jHcal] )
continue;
3046 if ( distH < dist ) {
3053 if (!isClosest)
continue;
3056 cout<<
"\telement "<<elements[iHO]<<
" linked with dist "<< dist<<endl;
3057 cout<<
"Added to HCAL cluster to form a neutral hadron"<<endl;
3061 assert( !hoclusterRef.
isNull() );
3063 double hoEnergy = hoclusterRef->energy();
3065 totalHO += hoEnergy;
3066 if ( hoEnergy > hoMax ) {
3068 hoClusterRef = hoclusterRef;
3072 hoRefs.push_back(iHO);
3073 active[iHO] =
false;
3079 = elements[iHcal].clusterRef();
3080 assert( !hclusterRef.
isNull() );
3083 double totalHcal = hclusterRef->energy();
3085 if (
useHO_ ) totalHcal += totalHO;
3093 double calibEcal = totalEcal > 0. ? totalEcal : 0.;
3094 double calibHcal =
std::max(0.,totalHcal);
3098 calibEcal = totalEcal;
3101 hclusterRef->positionREP().Eta(),
3102 hclusterRef->positionREP().Phi());
3115 calibEcal+calibHcal );
3118 (*pfCandidates_)[tmpi].setEcalEnergy( totalEcal, calibEcal );
3120 (*pfCandidates_)[tmpi].setHcalEnergy( totalHcal, calibHcal );
3121 (*pfCandidates_)[tmpi].setHoEnergy(0.,0.);
3123 (*pfCandidates_)[tmpi].setHcalEnergy( totalHcal-totalHO, calibHcal*(1.-totalHO/totalHcal));
3124 (*pfCandidates_)[tmpi].setHoEnergy(totalHO,totalHO*calibHcal/totalHcal);
3126 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
3127 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
3128 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
3129 for (
unsigned iec=0; iec<ecalRefs.size(); ++iec)
3130 (*
pfCandidates_)[tmpi].addElementInBlock( blockref, ecalRefs[iec] );
3131 for (
unsigned iho=0; iho<hoRefs.size(); ++iho)
3132 (*
pfCandidates_)[tmpi].addElementInBlock( blockref, hoRefs[iho] );
3141 if(
debug_)
cout<<endl<<
"---- loop ecal------- "<<endl;
3146 for(
unsigned i=0;
i<ecalIs.size();
i++) {
3147 unsigned iEcal = ecalIs[
i];
3150 cout<<endl<<elements[iEcal]<<
" ";
3152 if( ! active[iEcal] ) {
3154 cout<<
"not active"<<endl;
3161 PFClusterRef clusterref = elements[iEcal].clusterRef();
3162 assert(!clusterref.
isNull() );
3164 active[iEcal] =
false;
3167 vector<double> ps1Ene(1,static_cast<double>(0.));
3169 vector<double> ps2Ene(1,static_cast<double>(0.));
3171 bool crackCorrection =
false;
3172 float ecalEnergy =
calibration_->energyEm(*clusterref,ps1Ene,ps2Ene,crackCorrection);
3174 double particleEnergy = ecalEnergy;
3179 (*pfCandidates_)[tmpi].setEcalEnergy( clusterref->energy(),ecalEnergy );
3180 (*pfCandidates_)[tmpi].setHcalEnergy( 0., 0. );
3181 (*pfCandidates_)[tmpi].setHoEnergy( 0., 0. );
3182 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
3183 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
3184 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal );
3200 int charge = track.
charge()>0 ? 1 : -1;
3203 double px = track.
px();
3204 double py = track.
py();
3205 double pz = track.
pz();
3206 double energy =
sqrt(track.
p()*track.
p() + 0.13957*0.13957);
3218 pfCandidates_->back().setVertexSource( PFCandidate::kTrkVertex );
3231 if ((!isMuon) && isFromDisp) {
3232 double Dpt = trackRef->ptError();
3233 double dptRel = Dpt/trackRef->pt()*100;
3239 cout <<
"Not refitted px = " << px <<
" py = " << py <<
" pz = " << pz <<
" energy = " << energy << endl;
3242 reco::Track trackRefit = vRef->refittedTrack(trackRef);
3247 sqrt(trackRefit.
p()*trackRefit.
p() + 0.13957*0.13957));
3249 cout <<
"Refitted px = " << px <<
" py = " << py <<
" pz = " << pz <<
" energy = " << energy << endl;
3267 double particleEnergy,
3280 if ( useDirection ) {
3281 switch( cluster.
layer() ) {
3284 factor =
std::sqrt(cluster.
position().Perp2()/(particleX*particleX+particleY*particleY));
3290 factor = cluster.
position().Z()/particleZ;
3305 cluster.
position().Y()-vertexPos.Y(),
3306 cluster.
position().Z()-vertexPos.Z());
3308 particleY*factor-vertexPos.Y(),
3309 particleZ*factor-vertexPos.Z() );
3314 clusterPos = useDirection ? particleDirection.Unit() : clusterPos.Unit();
3315 clusterPos *= particleEnergy;
3321 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzM4D<double> >
3322 momentum( clusterPos.X(), clusterPos.Y(), clusterPos.Z(), mass);
3332 switch( cluster.
layer() ) {
3335 particleType = PFCandidate::gamma;
3339 particleType = PFCandidate::h0;
3342 particleType = PFCandidate::h_HF;
3345 particleType = PFCandidate::egamma_HF;
3381 if ( clusterEnergyHCAL < 1. ) clusterEnergyHCAL = 1.;
3383 double resol = fabs(eta) < 1.48 ?
3384 sqrt (1.02*1.02/clusterEnergyHCAL + 0.065*0.065)
3386 sqrt (1.20*1.20/clusterEnergyHCAL + 0.028*0.028);
3394 double nS = fabs(eta) < 1.48 ?
3404 if(!out )
return out;
3406 out<<
"====== Particle Flow Algorithm ======= ";
3413 out<<
"reconstructed particles: "<<endl;
3415 const std::auto_ptr< reco::PFCandidateCollection >&
3418 if(!candidates.get() ) {
3419 out<<
"candidates already transfered"<<endl;
3448 std::vector<bool>& active,
3449 std::vector<double>& psEne) {
3457 std::multimap<double, unsigned> sortedPS;
3458 typedef std::multimap<double, unsigned>::iterator IE;
3460 sortedPS, psElementType,
3464 double totalPS = 0.;
3465 for ( IE ips=sortedPS.begin(); ips!=sortedPS.end(); ++ips ) {
3468 unsigned iPS = ips->second;
3472 if (!active[iPS])
continue;
3475 std::multimap<double, unsigned> sortedECAL;
3480 unsigned jEcal = sortedECAL.begin()->second;
3481 if ( jEcal != iEcal )
continue;
3485 assert( pstype == psElementType );
3486 PFClusterRef psclusterref = elements[iPS].clusterRef();
3487 assert(!psclusterref.
isNull() );
3488 totalPS += psclusterref->energy();
3489 psEne[0] += psclusterref->energy();
3490 active[iPS] =
false;
3505 bool bPrimary = (order.find(
"primary") != string::npos);
3506 bool bSecondary = (order.find(
"secondary") != string::npos);
3507 bool bAll = (order.find(
"all") != string::npos);
3512 if (bPrimary && isToDisp)
return true;
3513 if (bSecondary && isFromDisp )
return true;
3514 if (bAll && ( isToDisp || isFromDisp ) )
return true;
3543 std::vector<unsigned int> pfCandidatesToBeRemoved;
3550 double met2 = metX*metX+metY*metY;
3552 double significance =
std::sqrt(met2/sumet);
3553 double significanceCor = significance;
3556 double metXCor = metX;
3557 double metYCor = metY;
3558 double sumetCor = sumet;
3559 double met2Cor = met2;
3561 double deltaPhiPt = 100.;
3563 unsigned iCor = 1E9;
3568 double metReduc = -1.;
3582 for(
unsigned j=0;
j<pfCandidatesToBeRemoved.size(); ++
j) {
3583 if (
i == pfCandidatesToBeRemoved[
j] ) skip =
true;
3586 if ( skip )
continue;
3589 deltaPhi = std::acos((metX*pfc.
px()+metY*pfc.
py())/(pfc.
pt()*
std::sqrt(met2)));
3590 deltaPhiPt = deltaPhi*pfc.
pt();
3594 double metXInt = metX - pfc.
px();
3595 double metYInt = metY - pfc.
py();
3596 double sumetInt = sumet - pfc.
pt();
3597 double met2Int = metXInt*metXInt+metYInt*metYInt;
3598 if ( met2Int < met2Cor ) {
3601 metReduc = (met2-met2Int)/met2Int;
3603 sumetCor = sumetInt;
3604 significanceCor =
std::sqrt(met2Cor/sumetCor);
3611 pfCandidatesToBeRemoved.push_back(iCor);
3625 std::cout <<
"Significance reduction = " << significance <<
" -> "
3626 << significanceCor <<
" = " << significanceCor - significance
3628 for(
unsigned j=0;
j<pfCandidatesToBeRemoved.size(); ++
j) {
3629 std::cout <<
"Removed : " << (*pfCandidates_)[pfCandidatesToBeRemoved[
j]] << std::endl;
3631 (*pfCandidates_)[pfCandidatesToBeRemoved[
j]].rescaleMomentum(1E-6);
3645 if ( !cleanedHits.size() )
return;
3651 std::vector<unsigned int> hitsToBeAdded;
3658 double met2 = metX*metX+metY*metY;
3659 double met2_Original = met2;
3663 double metXCor = metX;
3664 double metYCor = metY;
3665 double sumetCor = sumet;
3666 double met2Cor = met2;
3668 unsigned iCor = 1E9;
3673 double metReduc = -1.;
3675 for(
unsigned i=0;
i<cleanedHits.size(); ++
i) {
3684 for(
unsigned j=0;
j<hitsToBeAdded.size(); ++
j) {
3685 if (
i == hitsToBeAdded[
j] ) skip =
true;
3688 if ( skip )
continue;
3691 double metXInt = metX + px;
3692 double metYInt = metY + py;
3693 double sumetInt = sumet +
pt;
3694 double met2Int = metXInt*metXInt+metYInt*metYInt;
3697 if ( met2Int < met2Cor ) {
3700 metReduc = (met2-met2Int)/met2Int;
3702 sumetCor = sumetInt;
3711 hitsToBeAdded.push_back(iCor);
3725 std::cout << hitsToBeAdded.size() <<
" hits were re-added " << std::endl;
3729 std::cout <<
"Added after cleaning check : " << std::endl;
3731 for(
unsigned j=0;
j<hitsToBeAdded.size(); ++
j) {
3751 for(
unsigned ic=0;ic<
size;++ic) {
3760 (*pfCandidates_)[ic].setPFElectronExtraRef(theRef);
3772 (*pfCandidates_)[ic].set_mva_e_pi(it->mvaVariable(PFCandidateElectronExtra::MVA_MVA));
3774 (*pfCandidates_)[ic].setPFElectronExtraRef(theRef);
3775 (*pfCandidates_)[ic].setGsfTrackRef(it->gsfTrackRef());
3783 for(
unsigned ic=0;ic<
size;++ic) {
3791 (*pfElectronCandidates_)[ic].setPFElectronExtraRef(theRef);
3802 for(
unsigned ic=0;ic<
size;++ic) {
3807 for(
unsigned pcextra=0;pcextra<sizePhExtra;++pcextra) {
3810 (*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
tuple detachedTripletStep
T getParameter(std::string const &) const
unsigned int nTrackIsoForEgammaSC_
edm::Ref< PFBlockCollection > PFBlockRef
persistent reference to PFCluster objects
Abstract base class for a PFBlock element (track, cluster...)
static bool isIsolatedMuon(const reco::PFBlockElement &elt)
const math::XYZPoint & position() const
cluster centroid position
bool isFromSecInt(const reco::PFBlockElement &eTrack, std::string order) const
const reco::TrackRef & trackRef() const
std::vector< double > muonHCAL_
Variables for muons and fakes.
algo_(conf.existsAs< bool >("Correct")?conf.getParameter< bool >("Correct"):true, conf.getParameter< double >("e9e25Cut"), conf.getParameter< double >("intercept2DCut"), conf.existsAs< bool >("intercept2DSlope")?conf.getParameter< double >("intercept2DSlope"):defaultSlope2D_, conf.getParameter< std::vector< double > >("e1e9Cut"), conf.getParameter< std::vector< double > >("eCOREe9Cut"), conf.getParameter< std::vector< double > >("eSeLCut"), hfvars_)
ParticleType
particle types
bool isNonnull() const
Checks for non-null.
void setPFMuonAndFakeParameters(const edm::ParameterSet &pset)
void addMissingMuons(edm::Handle< reco::MuonCollection >, reco::PFCandidateCollection *cands)
double sumEtEcalIsoForEgammaSC_endcap_
virtual float pt() const
transverse momentum
std::auto_ptr< reco::PFCandidateCollection > pfPhotonCandidates_
the unfiltered photon collection
void set_mva_nothing_gamma(float mva)
set mva for gamma detection
bool isMuon(const Candidate &part)
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
edm::Ref< PFCandidatePhotonExtraCollection > PFCandidatePhotonExtraRef
persistent reference to a PFCandidatePhotonExtra
double coneEcalIsoForEgammaSC_
static bool isMuon(const reco::PFBlockElement &elt)
const std::vector< reco::PFCandidate > & getAllElectronCandidates()
virtual void setCharge(Charge q)
set electric charge
unsigned reconstructCluster(const reco::PFCluster &cluster, double particleEnergy, bool useDirection=false, double particleX=0., double particleY=0., double particleZ=0.)
void reconstructParticles(const reco::PFBlockHandle &blockHandle)
virtual float phi() const
momentum azimuthal angle
double y() const
y coordinate
bool useProtectionsForJetMET_
double coneTrackIsoForEgammaSC_
void setParameters(const edm::ParameterSet &)
double nSigmaHCAL_
number of sigma to judge energy excess in HCAL
std::map< unsigned int, Link > LinkData
bool isElectronSafeForJetMET(const reco::GsfElectron &, const reco::PFCandidate &, const reco::Vertex &, bool lockTracks)
virtual void processBlock(const reco::PFBlockRef &blockref, std::list< reco::PFBlockRef > &hcalBlockRefs, std::list< reco::PFBlockRef > &ecalBlockRefs)
void setMuonHandle(const edm::Handle< reco::MuonCollection > &)
math::Error< dimension >::type Error
covariance error matrix (3x3)
virtual void setP4(const LorentzVector &p4)
set 4-momentum
std::vector< Vertex > VertexCollection
collection of Vertex objects
const edm::OwnVector< reco::PFBlockElement > & elements() const
std::vector< PFRecHit > PFRecHitCollection
collection of PFRecHit objects
const edm::ValueMap< reco::PhotonRef > * valueMapGedPhotons_
void checkCleaning(const reco::PFRecHitCollection &cleanedHF)
Check HF Cleaning.
edm::Ref< PFCandidateElectronExtraCollection > PFCandidateElectronExtraRef
persistent reference to a PFCandidateElectronExtra
virtual void setVertex(const math::XYZPoint &p)
set vertex
bool passElectronSelection(const reco::GsfElectron &, const reco::PFCandidate &, const int &)
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float > > XYZPointF
point in space with cartesian internal representation
double px() const
x coordinate of momentum vector
void setDisplacedVerticesParameters(bool rejectTracks_Bad, bool rejectTracks_Step45, bool usePFNuclearInteractions, bool usePFConversions, bool usePFDecays, double dptRel_DispVtx)
std::ostream & operator<<(std::ostream &out, const ALILine &li)
PFCandidateCollection::const_iterator PFCandidateConstIterator
iterator
double sumEtEcalIsoForEgammaSC_barrel_
std::auto_ptr< reco::PFCandidateCollection > pfCleanedCandidates_
void setPFEleParameters(double mvaEleCut, std::string mvaWeightFileEleID, bool usePFElectrons, const boost::shared_ptr< PFSCEnergyCalibration > &thePFSCEnergyCalibration, const boost::shared_ptr< PFEnergyCalibration > &thePFEnergyCalibration, double sumEtEcalIsoForEgammaSC_barrel, double sumEtEcalIsoForEgammaSC_endcap, double coneEcalIsoForEgammaSC, double sumPtTrackIsoForEgammaSC_barrel, double sumPtTrackIsoForEgammaSC_endcap, unsigned int nTrackIsoForEgammaSC, double coneTrackIsoForEgammaSC, bool applyCrackCorrections=false, bool usePFSCEleCalib=true, bool useEGElectrons=false, bool useEGammaSupercluster=true)
void setPFVertexParameters(bool useVertex, const reco::VertexCollection *primaryVertices)
void setEGElectronCollection(const reco::GsfElectronCollection &egelectrons)
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
bool rejectTracks_Step45_
const math::XYZPointF & positionAtECALEntrance() const
std::vector< ElementInBlock > ElementsInBlocks
double minSignificanceReduction_
void setPFPhotonParameters(bool usePFPhoton, std::string mvaWeightFileConvID, double mvaConvCut, bool useReg, std::string X0_Map, const boost::shared_ptr< PFEnergyCalibration > &thePFEnergyCalibration, double sumPtTrackIsoForPhoton, double sumPtTrackIsoSlopeForPhoton)
std::vector< double > factors45_
PFLayer::Layer layer() const
rechit layer
RefToBase< value_type > refAt(size_type i) const
bool useEGammaSupercluster_
U second(std::pair< T, U > const &p)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
bool isElectron(const reco::GsfElectron &)
void set_mva_e_pi(float mvaNI)
bool usePFNuclearInteractions_
virtual double energy() const
energy
void setEGammaCollections(const edm::View< reco::PFCandidate > &pfEgammaCandidates, const edm::ValueMap< reco::GsfElectronRef > &valueMapGedElectrons, const edm::ValueMap< reco::PhotonRef > &valueMapGedPhotons)
Particle flow rechit (rechit + geometry and topology information). See clustering algorithm in PFClus...
void set_mva_Isolated(float mvaI)
void setParameters(double nSigmaECAL, double nSigmaHCAL, const boost::shared_ptr< PFEnergyCalibration > &calibration, const boost::shared_ptr< PFEnergyCalibrationHF > &thepfEnergyCalibrationHF)
bool check(const std::string &)
const edm::View< reco::PFCandidate > * pfEgammaCandidates_
void associatePSClusters(unsigned iEcal, reco::PFBlockElement::Type psElementType, const reco::PFBlock &block, const edm::OwnVector< reco::PFBlockElement > &elements, const reco::PFBlock::LinkData &linkData, std::vector< bool > &active, std::vector< double > &psEne)
Associate PS clusters to a given ECAL cluster, and return their energy.
std::string mvaWeightFileEleID_
Variables for PFElectrons.
virtual float eta() const
momentum pseudorapidity
void setParticleType(ParticleType type)
set Particle Type
bool passPhotonSelection(const reco::Photon &)
const std::vector< reco::PFCandidateElectronExtra > & getElectronExtra()
virtual int charge() const
electric charge
void setPFPhotonRegWeights(const GBRForest *LCorrForestEB, const GBRForest *LCorrForestEE, const GBRForest *GCorrForestBarrel, const GBRForest *GCorrForestEndcapHr9, const GBRForest *GCorrForestEndcapLr9, const GBRForest *PFEcalResolution)
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_
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
const std::vector< reco::PFCandidate > & getElectronCandidates()
const math::XYZPoint & position() const
rechit cell centre x, y, z
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_
virtual double px() const
x coordinate of momentum vector
XYZVectorD XYZVector
spatial vector with cartesian internal representation
void setGBRForest(const GBRForest *LCorrForest, const GBRForest *GCorrForest, const GBRForest *ResForest)
void associatedElements(unsigned i, const LinkData &linkData, std::multimap< double, unsigned > &sortedAssociates, reco::PFBlockElement::Type type=PFBlockElement::NONE, LinkTest test=LINKTEST_RECHIT) const
static bool isLooseMuon(const reco::PFBlockElement &elt)
XYZPointD XYZPoint
point in space with cartesian internal representation
boost::shared_ptr< PFEnergyCalibration > calibration_
reco::PFBlockHandle blockHandle_
input block handle (full framework case)
virtual bool trackType(TrackType trType) const
boost::shared_ptr< PFSCEnergyCalibration > thePFSCEnergyCalibration_
virtual ~PFAlgo()
destructor
void setHoEnergy(float eoRaw, float eoCorr)
set corrected Hcal energy
std::vector< std::vector< double > > tmp
bool isElectronValidCandidate(const reco::PFBlockRef &blockRef, std::vector< bool > &active, const reco::Vertex &primaryVertex)
Particle reconstructed by the particle flow algorithm.
double energy() const
rechit energy
boost::shared_ptr< PFEnergyCalibrationHF > thepfEnergyCalibrationHF_
reco::PFCandidateEGammaExtraRef egammaExtraRef() const
return a reference to the EGamma extra
std::auto_ptr< reco::PFCandidateCollection > pfCandidates_
const PFDisplacedTrackerVertexRef & displacedVertexRef(TrackType trType) const
PFMuonAlgo * getPFMuonAlgo()
bool useEGammaFilters_
Variables for NEW EGAMMA selection.
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
const reco::MuonRef & muonRef() const
virtual ParticleType particleId() const
std::auto_ptr< reco::PFCandidateCollection > pfElectronCandidates_
the unfiltered electron collection
double time() const
timing for cleaned hits
double neutralHadronEnergyResolution(double clusterEnergy, double clusterEta) const
todo: use PFClusterTools for this
void postClean(reco::PFCandidateCollection *)
reco::PFCandidateElectronExtraCollection pfElectronExtra_
the unfiltered electron collection
const ElementsInBlocks & elementsInBlocks() const
bool isPhotonValidCandidate(const reco::PFBlockRef &blockRef, std::vector< bool > &active, std::auto_ptr< reco::PFCandidateCollection > &pfPhotonCandidates, std::vector< reco::PFCandidatePhotonExtra > &pfPhotonExtraCandidates, std::vector< reco::PFCandidate > &tempElectronCandidates)
void setInputsForCleaning(const reco::VertexCollection *)
bool isPhotonSafeForJetMET(const reco::Photon &, const reco::PFCandidate &)
tuple size
Write out results.
double sumPtTrackIsoForEgammaSC_barrel_
virtual double py() const
y coordinate of momentum vector
const std::auto_ptr< reco::PFCandidateCollection > & pfCandidates() const
void setHcalEnergy(float ehRaw, float ehCorr)
set corrected Hcal energy
double py() const
y coordinate of momentum vector
void setEGammaParameters(bool use_EGammaFilters, std::string ele_iso_path_mvaWeightFile, double ele_iso_pt, double ele_iso_mva_barrel, double ele_iso_mva_endcap, double ele_iso_combIso_barrel, double ele_iso_combIso_endcap, double ele_noniso_mva, unsigned int ele_missinghits, bool useProtectionsForJetMET, const edm::ParameterSet &ele_protectionsForJetMET, double ph_MinEt, double ph_combIso, double ph_HoE, double ph_sietaieta_eb, double ph_sietaieta_ee, const edm::ParameterSet &ph_protectionsForJetMET)
const edm::ValueMap< reco::GsfElectronRef > * valueMapGedElectrons_
void setElectronExtraRef(const edm::OrphanHandle< reco::PFCandidateElectronExtraCollection > &extrah)
void setEGElectronCollection(const reco::GsfElectronCollection &egelectrons)
bool reconstructMuon(reco::PFCandidate &, const reco::MuonRef &, bool allowLoose=false)
double nSigmaECAL_
number of sigma to judge energy excess in ECAL