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 &&
1139 ( trackRef->algo() == TrackBase::iter4 ||
1140 trackRef->algo() == TrackBase::iter5 ||
1141 trackRef->algo() == TrackBase::iter6 ) ) {
1144 double dptRel = Dpt/trackRef->pt()*100;
1145 bool isPrimaryOrSecondary =
isFromSecInt(elements[iTrack],
"all");
1148 unsigned nHits = elements[iTrack].trackRef()->hitPattern().trackerLayersWithMeasurement();
1149 unsigned int NLostHit = trackRef->hitPattern().trackerLayersWithoutMeasurement(HitPattern::TRACK_HITS);
1152 std::cout <<
"A track (algo = " << trackRef->algo() <<
") with momentum " << trackMomentum
1153 <<
" / " << elements[iTrack].trackRef()->pt() <<
" +/- " << Dpt
1154 <<
" / " << elements[iTrack].trackRef()->eta()
1155 <<
" without any link to ECAL/HCAL and with " << nHits <<
" (" << NLostHit
1156 <<
") hits (lost hits) has been cleaned" << std::endl;
1157 active[iTrack] =
false;
1164 kTrack.push_back(iTrack);
1165 active[iTrack] =
false;
1168 if ( ecalElems.empty() ) {
1169 (*pfCandidates_)[tmpi[0]].setEcalEnergy( 0., 0. );
1170 (*pfCandidates_)[tmpi[0]].setHcalEnergy( 0., 0. );
1171 (*pfCandidates_)[tmpi[0]].setHoEnergy( 0., 0. );
1172 (*pfCandidates_)[tmpi[0]].setPs1Energy( 0 );
1173 (*pfCandidates_)[tmpi[0]].setPs2Energy( 0 );
1174 (*pfCandidates_)[tmpi[0]].addElementInBlock( blockref, kTrack[0] );
1179 unsigned thisEcal = ecalElems.begin()->second;
1181 if (
debug_ )
std::cout <<
" is associated to " << elements[thisEcal] << std::endl;
1185 if ( thisIsAMuon ) {
1186 (*pfCandidates_)[tmpi[0]].setEcalEnergy( clusterRef->energy(),
1188 (*pfCandidates_)[tmpi[0]].setHcalEnergy( 0., 0. );
1189 (*pfCandidates_)[tmpi[0]].setHoEnergy( 0., 0. );
1190 (*pfCandidates_)[tmpi[0]].setPs1Energy( 0 );
1191 (*pfCandidates_)[tmpi[0]].setPs2Energy( 0 );
1192 (*pfCandidates_)[tmpi[0]].addElementInBlock( blockref, kTrack[0] );
1195 double slopeEcal = 1.;
1196 bool connectedToEcal =
false;
1197 unsigned iEcal = 99999;
1198 double calibEcal = 0.;
1199 double calibHcal = 0.;
1200 double totalEcal = thisIsAMuon ? -
muonECAL_[0] : 0.;
1203 std::multimap<double, unsigned> sortedTracks;
1204 block.associatedElements( thisEcal, linkData,
1209 for(IE ie = sortedTracks.begin(); ie != sortedTracks.end(); ++ie ) {
1210 unsigned jTrack = ie->second;
1213 if ( !active[jTrack] )
continue;
1216 if ( jTrack == iTrack )
continue;
1221 std::multimap<double, unsigned> sortedECAL;
1222 block.associatedElements( jTrack, linkData,
1226 if ( sortedECAL.begin()->second != thisEcal )
continue;
1233 bool rejectFake =
false;
1235 if ( !thatIsAMuon && trackRef->ptError() >
ptError_) {
1236 double deficit = trackMomentum + trackRef->p() - clusterRef->energy();
1238 clusterRef->positionREP().Eta());
1239 resol *= (trackMomentum+trackRef->p());
1242 kTrack.push_back(jTrack);
1243 active[jTrack] =
false;
1245 std::cout << elements[jTrack] << std::endl
1246 <<
"is probably a fake (2) --> lock the track"
1250 if ( rejectFake )
continue;
1256 if ( !thatIsAMuon ) {
1258 std::cout <<
"Track momentum increased from " << trackMomentum <<
" GeV ";
1259 trackMomentum += trackRef->p();
1261 std::cout <<
"to " << trackMomentum <<
" GeV." << std::endl;
1262 std::cout <<
"with " << elements[jTrack] << std::endl;
1266 totalEcal =
std::max(totalEcal, 0.);
1274 kTrack.push_back(jTrack);
1275 active[jTrack] =
false;
1277 if ( thatIsAMuon ) {
1278 (*pfCandidates_)[tmpi.back()].setEcalEnergy(clusterRef->energy(),
1280 (*pfCandidates_)[tmpi.back()].setHcalEnergy( 0., 0. );
1281 (*pfCandidates_)[tmpi.back()].setHoEnergy( 0., 0. );
1282 (*pfCandidates_)[tmpi.back()].setPs1Energy( 0 );
1283 (*pfCandidates_)[tmpi.back()].setPs2Energy( 0 );
1284 (*pfCandidates_)[tmpi.back()].addElementInBlock( blockref, kTrack.back() );
1289 if (
debug_ )
std::cout <<
"Loop over all associated ECAL clusters" << std::endl;
1291 for(IE ie = ecalElems.begin(); ie != ecalElems.end(); ++ie ) {
1293 unsigned index = ie->second;
1299 if (
debug_ && ! active[index] )
std::cout <<
"is not active - ignore " << std::endl;
1300 if ( ! active[index] )
continue;
1304 block.associatedElements( index, linkData,
1309 for (
unsigned ic=0; ic<kTrack.size();++ic) {
1310 if ( sortedTracks.begin()->second == kTrack[ic] ) {
1315 if (
debug_ && skip )
std::cout <<
"is closer to another track - ignore " << std::endl;
1316 if ( skip )
continue;
1321 assert( !clusterRef.
isNull() );
1324 double dist = ie->first;
1325 std::cout <<
"Ecal cluster with raw energy = " << clusterRef->energy()
1326 <<
" linked with distance = " << dist << std::endl;
1339 vector<double> ps1Ene(1,static_cast<double>(0.));
1341 vector<double> ps2Ene(1,static_cast<double>(0.));
1345 bool crackCorrection =
false;
1346 double ecalEnergy =
calibration_->energyEm(*clusterRef,ps1Ene,ps2Ene,crackCorrection);
1348 std::cout <<
"Corrected ECAL(+PS) energy = " << ecalEnergy << std::endl;
1352 totalEcal += ecalEnergy;
1353 double previousCalibEcal = calibEcal;
1354 double previousSlopeEcal = slopeEcal;
1355 calibEcal =
std::max(totalEcal,0.);
1357 calibration_->energyEmHad(trackMomentum,calibEcal,calibHcal,
1358 clusterRef->positionREP().Eta(),
1359 clusterRef->positionREP().Phi());
1360 if ( totalEcal > 0.) slopeEcal = calibEcal/totalEcal;
1363 std::cout <<
"The total calibrated energy so far amounts to = " << calibEcal << std::endl;
1367 if ( connectedToEcal && calibEcal - trackMomentum >= 0. ) {
1370 calibEcal = previousCalibEcal;
1371 slopeEcal = previousSlopeEcal;
1372 totalEcal = calibEcal/slopeEcal;
1376 active[
index] =
false;
1379 std::multimap<double, unsigned> assTracks;
1380 block.associatedElements( index, linkData,
1387 (*pfCandidates_)[tmpe].setEcalEnergy( clusterRef->energy(), ecalEnergy );
1388 (*pfCandidates_)[tmpe].setHcalEnergy( 0., 0. );
1389 (*pfCandidates_)[tmpe].setHoEnergy( 0., 0. );
1390 (*pfCandidates_)[tmpe].setPs1Energy( ps1Ene[0] );
1391 (*pfCandidates_)[tmpe].setPs2Energy( ps2Ene[0] );
1392 (*pfCandidates_)[tmpe].addElementInBlock( blockref, index );
1394 if(assTracks.size()) {
1395 (*pfCandidates_)[tmpe].addElementInBlock( blockref, assTracks.begin()->second );
1406 connectedToEcal =
true;
1408 active[
index] =
false;
1409 for (
unsigned ic=0; ic<tmpi.size();++ic)
1410 (*
pfCandidates_)[tmpi[ic]].addElementInBlock( blockref, iEcal );
1415 bool bNeutralProduced =
false;
1418 if( connectedToEcal ) {
1460 neutralEnergy /= slopeEcal;
1462 (*pfCandidates_)[tmpj].setEcalEnergy( pivotalRef->energy(), neutralEnergy );
1463 (*pfCandidates_)[tmpj].setHcalEnergy( 0., 0. );
1464 (*pfCandidates_)[tmpj].setHoEnergy( 0., 0. );
1465 (*pfCandidates_)[tmpj].setPs1Energy( 0. );
1466 (*pfCandidates_)[tmpj].setPs2Energy( 0. );
1467 (*pfCandidates_)[tmpj].addElementInBlock(blockref, iEcal);
1468 bNeutralProduced =
true;
1469 for (
unsigned ic=0; ic<kTrack.size();++ic)
1470 (*
pfCandidates_)[tmpj].addElementInBlock( blockref, kTrack[ic] );
1474 for (
unsigned ic=0; ic<tmpi.size();++ic) {
1479 double fraction = (*pfCandidates_)[tmpi[ic]].trackRef()->p()/
trackMomentum;
1480 double ecalCal = bNeutralProduced ?
1481 (calibEcal-neutralEnergy*slopeEcal)*fraction : calibEcal*fraction;
1482 double ecalRaw = totalEcal*fraction;
1484 if (
debug_)
cout <<
"The fraction after photon supression is " << fraction <<
" calibrated ecal = " << ecalCal << endl;
1486 (*pfCandidates_)[tmpi[ic]].setEcalEnergy( ecalRaw, ecalCal );
1487 (*pfCandidates_)[tmpi[ic]].setHcalEnergy( 0., 0. );
1488 (*pfCandidates_)[tmpi[ic]].setHoEnergy( 0., 0. );
1489 (*pfCandidates_)[tmpi[ic]].setPs1Energy( 0 );
1490 (*pfCandidates_)[tmpi[ic]].setPs2Energy( 0 );
1491 (*pfCandidates_)[tmpi[ic]].addElementInBlock( blockref, kTrack[ic] );
1497 for (
unsigned ic=0; ic<tmpi.size();++ic) {
1498 const PFCandidate& pfc = (*pfCandidates_)[tmpi[ic]];
1500 if ( eleInBlocks.size() == 0 ) {
1501 if (
debug_ )
std::cout <<
"Single track / Fill element in block! " << std::endl;
1502 (*pfCandidates_)[tmpi[ic]].addElementInBlock( blockref, kTrack[ic] );
1511 for(IE ie = hcalElems.begin(); ie != hcalElems.end(); ++ie ) {
1513 unsigned index = ie->second;
1519 cout<<
"\telement "<<elements[
index]<<
" linked with distance "<< dist <<endl;
1528 cout<<
"\t\tclosest hcal cluster, doing nothing"<<endl;
1538 cout<<
"\t\tsecondary hcal cluster. unlinking"<<endl;
1539 block.setLink( iTrack, index, -1., linkData,
1540 PFBlock::LINKTEST_RECHIT );
1548 if( !(hfEmIs.empty() && hfHadIs.empty() ) ) {
1551 assert( hfEmIs.size() + hfHadIs.size() == elements.
size() );
1553 if( elements.
size() == 1 ) {
1556 double energyHF = 0.;
1557 double uncalibratedenergyHF = 0.;
1559 switch( clusterRef->layer() ) {
1562 energyHF = clusterRef->energy();
1563 uncalibratedenergyHF = energyHF;
1566 clusterRef->positionREP().Eta(),
1567 clusterRef->positionREP().Phi());
1570 (*pfCandidates_)[tmpi].setEcalEnergy( uncalibratedenergyHF, energyHF );
1571 (*pfCandidates_)[tmpi].setHcalEnergy( 0., 0.);
1572 (*pfCandidates_)[tmpi].setHoEnergy( 0., 0.);
1573 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
1574 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
1575 (*pfCandidates_)[tmpi].addElementInBlock( blockref, hfEmIs[0] );
1580 energyHF = clusterRef->energy();
1581 uncalibratedenergyHF = energyHF;
1584 clusterRef->positionREP().Eta(),
1585 clusterRef->positionREP().Phi());
1588 (*pfCandidates_)[tmpi].setHcalEnergy( uncalibratedenergyHF, energyHF );
1589 (*pfCandidates_)[tmpi].setEcalEnergy( 0., 0.);
1590 (*pfCandidates_)[tmpi].setHoEnergy( 0., 0.);
1591 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
1592 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
1593 (*pfCandidates_)[tmpi].addElementInBlock( blockref, hfHadIs[0] );
1600 else if( elements.
size() == 2 ) {
1609 cerr<<
"Error: 2 elements, but not 1 HFEM and 1 HFHAD"<<endl;
1616 double energyHfEm = cem->energy();
1617 double energyHfHad = chad->energy();
1618 double uncalibratedenergyHFEm = energyHfEm;
1619 double uncalibratedenergyHFHad = energyHfHad;
1624 c0->positionREP().Eta(),
1625 c0->positionREP().Phi());
1627 uncalibratedenergyHFHad,
1628 c1->positionREP().Eta(),
1629 c1->positionREP().Phi());
1632 (*pfCandidates_)[tmpi].setEcalEnergy( uncalibratedenergyHFEm, energyHfEm );
1633 (*pfCandidates_)[tmpi].setHcalEnergy( uncalibratedenergyHFHad, energyHfHad);
1634 (*pfCandidates_)[tmpi].setHoEnergy( 0., 0.);
1635 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
1636 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
1637 (*pfCandidates_)[tmpi].addElementInBlock( blockref, hfEmIs[0] );
1638 (*pfCandidates_)[tmpi].addElementInBlock( blockref, hfHadIs[0] );
1644 cerr<<
"Warning: HF, but n elem different from 1 or 2"<<endl;
1655 cout<<endl<<
"--------------- loop hcal ---------------------"<<endl;
1664 for(
unsigned i=0;
i<hcalIs.size();
i++) {
1666 unsigned iHcal= hcalIs[
i];
1671 if(
debug_)
cout<<endl<<elements[iHcal]<<endl;
1677 std::multimap<double, unsigned> sortedTracks;
1678 block.associatedElements( iHcal, linkData,
1683 std::multimap< unsigned, std::pair<double, unsigned> > associatedEcals;
1685 std::map< unsigned, std::pair<double, double> > associatedPSs;
1687 std::multimap<double, std::pair<unsigned,bool> > associatedTracks;
1690 std::multimap<double,std::pair<unsigned,::math::XYZVector> > ecalSatellites;
1691 std::pair<unsigned,::math::XYZVector> fakeSatellite = make_pair(iHcal,::
math::XYZVector(0.,0.,0.));
1692 ecalSatellites.insert( make_pair(-1., fakeSatellite) );
1694 std::multimap< unsigned, std::pair<double, unsigned> > associatedHOs;
1696 PFClusterRef hclusterref = elements[iHcal].clusterRef();
1697 assert(!hclusterref.
isNull() );
1707 if( sortedTracks.empty() ) {
1709 cout<<
"\tno associated tracks, keep for later"<<endl;
1714 active[iHcal] =
false;
1722 if(
debug_)
cout<<
"\t"<<sortedTracks.size()<<
" associated tracks:"<<endl;
1724 double totalChargedMomentum = 0;
1725 double sumpError2 = 0.;
1726 double totalHO = 0.;
1727 double totalEcal = 0.;
1728 double totalHcal = hclusterref->energy();
1729 vector<double> hcalP;
1730 vector<double> hcalDP;
1731 vector<unsigned> tkIs;
1732 double maxDPovP = -9999.;
1735 vector< unsigned > chargedHadronsIndices;
1736 vector< unsigned > chargedHadronsInBlock;
1737 double mergedNeutralHadronEnergy = 0;
1738 double mergedPhotonEnergy = 0;
1739 double muonHCALEnergy = 0.;
1740 double muonECALEnergy = 0.;
1741 double muonHCALError = 0.;
1742 double muonECALError = 0.;
1743 unsigned nMuons = 0;
1747 std::vector<std::pair<unsigned,::math::XYZVector> >
ecalClusters;
1748 double sumEcalClusters=0;
1750 hclusterref->position().Y(),
1751 hclusterref->position().Z());
1752 hadronDirection = hadronDirection.Unit();
1756 for(IE ie = sortedTracks.begin(); ie != sortedTracks.end(); ++ie ) {
1758 unsigned iTrack = ie->second;
1761 if ( !active[iTrack] )
continue;
1767 assert( !trackRef.
isNull() );
1772 ::math::XYZVector chargedDirection(chargedPosition.X(),chargedPosition.Y(),chargedPosition.Z());
1773 chargedDirection = chargedDirection.Unit();
1776 std::multimap<double, unsigned> sortedEcals;
1777 block.associatedElements( iTrack, linkData,
1782 if(
debug_)
cout<<
"\t\t\tnumber of Ecal elements linked to this track: "
1783 <<sortedEcals.size()<<endl;
1786 std::multimap<double, unsigned> sortedHOs;
1788 block.associatedElements( iTrack, linkData,
1795 cout<<
"PFAlgo : number of HO elements linked to this track: "
1796 <<sortedHOs.size()<<endl;
1804 bool thisIsALooseMuon =
false;
1812 if ( thisIsAMuon ) {
1814 std::cout <<
"\t\tThis track is identified as a muon - remove it from the stack" << std::endl;
1815 std::cout <<
"\t\t" << elements[iTrack] << std::endl;
1823 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iTrack );
1824 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
1830 bool letMuonEatCaloEnergy =
false;
1832 if(thisIsAnIsolatedMuon){
1834 double totalCaloEnergy = totalHcal / 1.30;
1836 if( !sortedEcals.empty() ) {
1837 iEcal = sortedEcals.begin()->second;
1838 PFClusterRef eclusterref = elements[iEcal].clusterRef();
1839 totalCaloEnergy += eclusterref->energy();
1845 if( !sortedHOs.empty() ) {
1846 iHO = sortedHOs.begin()->second;
1848 totalCaloEnergy += eclusterref->energy() / 1.30;
1854 if( (
pfCandidates_->back()).
p() > totalCaloEnergy ) letMuonEatCaloEnergy =
true;
1857 if(letMuonEatCaloEnergy) muonHcal = totalHcal;
1858 double muonEcal =0.;
1860 if( !sortedEcals.empty() ) {
1861 iEcal = sortedEcals.begin()->second;
1862 PFClusterRef eclusterref = elements[iEcal].clusterRef();
1863 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal);
1865 if(letMuonEatCaloEnergy) muonEcal = eclusterref->energy();
1867 if ( eclusterref->energy() - muonEcal < 0.2 ) active[iEcal] =
false;
1868 (*pfCandidates_)[tmpi].setEcalEnergy(eclusterref->energy(), muonEcal);
1873 if( !sortedHOs.empty() ) {
1874 iHO = sortedHOs.begin()->second;
1875 PFClusterRef hoclusterref = elements[iHO].clusterRef();
1876 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHO);
1878 if(letMuonEatCaloEnergy) muonHO = hoclusterref->energy();
1880 if ( hoclusterref->energy() - muonHO < 0.2 ) active[iHO] =
false;
1881 (*pfCandidates_)[tmpi].setHcalEnergy(totalHcal, muonHcal);
1882 (*pfCandidates_)[tmpi].setHoEnergy(hoclusterref->energy(), muonHO);
1885 (*pfCandidates_)[tmpi].setHcalEnergy(totalHcal, muonHcal);
1888 if(letMuonEatCaloEnergy){
1889 muonHCALEnergy += totalHcal;
1890 if (
useHO_) muonHCALEnergy +=muonHO;
1891 muonHCALError += 0.;
1892 muonECALEnergy += muonEcal;
1893 muonECALError += 0.;
1894 photonAtECAL -= muonEcal*chargedDirection;
1895 hadronAtECAL -= totalHcal*chargedDirection;
1896 if ( !sortedEcals.empty() ) active[iEcal] =
false;
1897 active[iHcal] =
false;
1898 if (
useHO_ && !sortedHOs.empty() ) active[iHO] =
false;
1904 if ( muonHO > 0. ) {
1911 photonAtECAL -= muonECAL_[0]*chargedDirection;
1912 hadronAtECAL -= muonHCAL_[0]*chargedDirection;
1916 active[iTrack] =
false;
1923 if(
debug_)
cout<<
"\t\t"<<elements[iTrack]<<endl;
1931 if ( thisIsALooseMuon && !thisIsAMuon ) nMuons += 1;
1936 double Dpt = trackRef->ptError();
1937 double blowError = 1.;
1938 switch (trackRef->algo()) {
1939 case TrackBase::ctf:
1940 case TrackBase::iter0:
1941 case TrackBase::iter1:
1942 case TrackBase::iter2:
1943 case TrackBase::iter3:
1944 case TrackBase::iter4:
1945 case TrackBase::iter7:
1946 case TrackBase::iter9:
1947 case TrackBase::iter10:
1950 case TrackBase::iter5:
1953 case TrackBase::iter6:
1961 bool isPrimaryOrSecondary =
isFromSecInt(elements[iTrack],
"all");
1963 if ( isPrimaryOrSecondary ) blowError = 1.;
1965 std::pair<unsigned,bool> tkmuon = make_pair(iTrack,thisIsALooseMuon);
1966 associatedTracks.insert( make_pair(-Dpt*blowError, tkmuon) );
1969 double Dp = trackRef->qoverpError()*trackMomentum*
trackMomentum;
1970 sumpError2 += Dp*Dp;
1972 bool connectedToEcal =
false;
1973 if( !sortedEcals.empty() )
1977 for ( IE iec=sortedEcals.begin();
1978 iec!=sortedEcals.end(); ++iec ) {
1980 unsigned iEcal = iec->second;
1981 double dist = iec->first;
1984 if( !active[iEcal] ) {
1992 PFClusterRef eclusterref = elements[iEcal].clusterRef();
1993 assert(!eclusterref.
isNull() );
1996 std::multimap<double, unsigned> sortedTracksEcal;
1997 block.associatedElements( iEcal, linkData,
2001 unsigned jTrack = sortedTracksEcal.
begin()->second;
2002 if ( jTrack != iTrack )
continue;
2006 double distEcal = block.dist(jTrack,iEcal,linkData,
2014 vector<double> ps1Ene(1,static_cast<double>(0.));
2016 block, elements, linkData, active,
2018 vector<double> ps2Ene(1,static_cast<double>(0.));
2020 block, elements, linkData, active,
2022 std::pair<double,double> psEnes = make_pair(ps1Ene[0],
2024 associatedPSs.insert(make_pair(iEcal,psEnes));
2027 bool crackCorrection =
false;
2028 float ecalEnergyCalibrated =
calibration_->energyEm(*eclusterref,ps1Ene,ps2Ene,crackCorrection);
2030 eclusterref->position().Y(),
2031 eclusterref->position().Z());
2032 photonDirection = photonDirection.Unit();
2034 if ( !connectedToEcal ) {
2037 <<elements[iEcal]<<endl;
2039 connectedToEcal =
true;
2043 std::pair<unsigned,::math::XYZVector> satellite =
2044 make_pair(iEcal,ecalEnergyCalibrated*photonDirection);
2045 ecalSatellites.insert( make_pair(-1., satellite) );
2049 std::pair<unsigned,::math::XYZVector> satellite =
2050 make_pair(iEcal,ecalEnergyCalibrated*photonDirection);
2051 ecalSatellites.insert( make_pair(dist, satellite) );
2055 std::pair<double, unsigned> associatedEcal
2056 = make_pair( distEcal, iEcal );
2057 associatedEcals.insert( make_pair(iTrack, associatedEcal) );
2062 if(
useHO_ && !sortedHOs.empty() )
2066 for ( IE ieho=sortedHOs.begin(); ieho!=sortedHOs.end(); ++ieho ) {
2068 unsigned iHO = ieho->second;
2069 double distHO = ieho->first;
2072 if( !active[iHO] ) {
2079 assert( type == PFBlockElement::HO );
2080 PFClusterRef hoclusterref = elements[iHO].clusterRef();
2081 assert(!hoclusterref.
isNull() );
2084 std::multimap<double, unsigned> sortedTracksHO;
2085 block.associatedElements( iHO, linkData,
2089 unsigned jTrack = sortedTracksHO.
begin()->second;
2090 if ( jTrack != iTrack )
continue;
2098 totalHO += hoclusterref->energy();
2099 active[iHO] =
false;
2101 std::pair<double, unsigned> associatedHO
2102 = make_pair( distHO, iHO );
2103 associatedHOs.insert( make_pair(iTrack, associatedHO) );
2112 totalHcal += totalHO;
2116 double caloEnergy = 0.;
2117 double slopeEcal = 1.0;
2118 double calibEcal = 0.;
2119 double calibHcal = 0.;
2120 hadronDirection = hadronAtECAL.Unit();
2124 Caloresolution *= totalChargedMomentum;
2126 Caloresolution =
std::sqrt(Caloresolution*Caloresolution + muonHCALError + muonECALError);
2127 totalEcal -=
std::min(totalEcal,muonECALEnergy);
2128 totalHcal -=
std::min(totalHcal,muonHCALEnergy);
2136 for ( IS is = ecalSatellites.begin(); is != ecalSatellites.end(); ++is ) {
2139 double previousCalibEcal = calibEcal;
2140 double previousCalibHcal = calibHcal;
2141 double previousCaloEnergy = caloEnergy;
2142 double previousSlopeEcal = slopeEcal;
2145 totalEcal +=
sqrt(is->second.second.Mag2());
2146 photonAtECAL += is->second.second;
2147 calibEcal =
std::max(0.,totalEcal);
2148 calibHcal =
std::max(0.,totalHcal);
2149 hadronAtECAL = calibHcal * hadronDirection;
2151 calibration_->energyEmHad(totalChargedMomentum,calibEcal,calibHcal,
2152 hclusterref->positionREP().Eta(),
2153 hclusterref->positionREP().Phi());
2154 caloEnergy = calibEcal+calibHcal;
2155 if ( totalEcal > 0.) slopeEcal = calibEcal/totalEcal;
2157 hadronAtECAL = calibHcal * hadronDirection;
2161 if ( is->first < 0. || caloEnergy - totalChargedMomentum <= 0. ) {
2162 if(
debug_)
cout<<
"\t\t\tactive, adding "<<is->second.second
2163 <<
" to ECAL energy, and locking"<<endl;
2164 active[is->second.first] =
false;
2165 double clusterEnergy=
sqrt(is->second.second.Mag2());
2166 if(clusterEnergy>50) {
2167 ecalClusters.push_back(is->second);
2168 sumEcalClusters+=clusterEnergy;
2175 totalEcal -=
sqrt(is->second.second.Mag2());
2176 photonAtECAL -= is->second.second;
2177 calibEcal = previousCalibEcal;
2178 calibHcal = previousCalibHcal;
2179 hadronAtECAL = previousHadronAtECAL;
2180 slopeEcal = previousSlopeEcal;
2181 caloEnergy = previousCaloEnergy;
2188 assert(caloEnergy>=0);
2201 double TotalError =
sqrt(sumpError2 + Caloresolution*Caloresolution);
2205 if ( totalChargedMomentum - caloEnergy >
nSigmaTRACK_*Caloresolution ) {
2220 for ( IT it = associatedTracks.begin(); it != associatedTracks.end(); ++it ) {
2221 unsigned iTrack = it->second.first;
2223 if ( !active[iTrack] )
continue;
2225 if ( !it->second.second )
continue;
2227 double trackMomentum = elements[it->second.first].trackRef()->p();
2230 std::multimap<double, unsigned> sortedEcals;
2231 block.associatedElements( iTrack, linkData,
2235 std::multimap<double, unsigned> sortedHOs;
2236 block.associatedElements( iTrack, linkData,
2244 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iTrack );
2245 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
2248 (*pfCandidates_)[tmpi].setHcalEnergy(totalHcal,muonHcal);
2249 if( !sortedEcals.empty() ) {
2250 unsigned iEcal = sortedEcals.begin()->second;
2251 PFClusterRef eclusterref = elements[iEcal].clusterRef();
2252 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal);
2254 (*pfCandidates_)[tmpi].setEcalEnergy(eclusterref->energy(),muonEcal);
2256 if(
useHO_ && !sortedHOs.empty() ) {
2257 unsigned iHO = sortedHOs.begin()->second;
2258 PFClusterRef hoclusterref = elements[iHO].clusterRef();
2259 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHO);
2261 (*pfCandidates_)[tmpi].setHcalEnergy(totalHcal-totalHO,muonHcal);
2262 (*pfCandidates_)[tmpi].setHoEnergy(hoclusterref->energy(),muonHO);
2267 ::math::XYZVector chargedDirection(chargedPosition.X(), chargedPosition.Y(), chargedPosition.Z());
2268 chargedDirection = chargedDirection.Unit();
2271 if ( totalEcal > 0. )
2273 if ( totalHcal > 0. )
2278 if ( totalHcal >
muonHCAL_[0] ) hadronAtECAL -=
muonHCAL_[0]*calibHcal/totalHcal * chargedDirection;
2279 caloEnergy = calibEcal+calibHcal;
2282 if ( muonHO > 0. ) {
2285 if ( totalHcal > 0. ) {
2286 calibHcal -=
std::min(calibHcal,muonHO_[0]*calibHcal/totalHcal);
2287 totalHcal -=
std::min(totalHcal,muonHO_[0]);
2292 active[iTrack] =
false;
2299 Caloresolution *= totalChargedMomentum;
2300 Caloresolution =
std::sqrt(Caloresolution*Caloresolution + muonHCALError + muonECALError);
2318 unsigned corrTrack = 10000000;
2319 double corrFact = 1.;
2322 totalChargedMomentum - caloEnergy >
nSigmaTRACK_*Caloresolution) {
2324 for ( IT it = associatedTracks.begin(); it != associatedTracks.end(); ++it ) {
2325 unsigned iTrack = it->second.first;
2327 if ( !active[iTrack] )
continue;
2328 const reco::TrackRef& trackref = elements[it->second.first].trackRef();
2330 double dptRel = fabs(it->first)/trackref->pt()*100;
2331 bool isSecondary =
isFromSecInt(elements[iTrack],
"secondary");
2332 bool isPrimary =
isFromSecInt(elements[iTrack],
"primary");
2336 if ( fabs(it->first) <
ptError_ )
break;
2338 double wouldBeTotalChargedMomentum =
2339 totalChargedMomentum - trackref->p();
2343 if ( wouldBeTotalChargedMomentum > caloEnergy ) {
2345 if (
debug_ && isSecondary) {
2346 cout <<
"In bad track rejection step dptRel = " << dptRel <<
" dptRel_DispVtx_ = " <<
dptRel_DispVtx_ << endl;
2347 cout <<
"The calo energy would be still smaller even without this track but it is attached to a NI"<< endl;
2352 active[iTrack] =
false;
2353 totalChargedMomentum = wouldBeTotalChargedMomentum;
2355 std::cout <<
"\tElement " << elements[iTrack]
2356 <<
" rejected (Dpt = " << -it->first
2357 <<
" GeV/c, algo = " << trackref->algo() <<
")" << std::endl;
2360 if(isPrimary)
break;
2362 corrFact = (caloEnergy - wouldBeTotalChargedMomentum)/elements[it->second.first].trackRef()->p();
2363 if ( trackref->p()*corrFact < 0.05 ) {
2365 active[iTrack] =
false;
2367 totalChargedMomentum -= trackref->p()*(1.-corrFact);
2369 std::cout <<
"\tElement " << elements[iTrack]
2370 <<
" (Dpt = " << -it->first
2371 <<
" GeV/c, algo = " << trackref->algo()
2372 <<
") rescaled by " << corrFact
2373 <<
" Now the total charged momentum is " << totalChargedMomentum << endl;
2381 Caloresolution *= totalChargedMomentum;
2382 Caloresolution =
std::sqrt(Caloresolution*Caloresolution + muonHCALError + muonECALError);
2388 sortedTracks.size() > 1 &&
2389 totalChargedMomentum - caloEnergy >
nSigmaTRACK_*Caloresolution ) {
2390 for ( IT it = associatedTracks.begin(); it != associatedTracks.end(); ++it ) {
2391 unsigned iTrack = it->second.first;
2393 if ( !active[iTrack] )
continue;
2395 double dptRel = fabs(it->first)/trackref->pt()*100;
2396 bool isPrimaryOrSecondary =
isFromSecInt(elements[iTrack],
"all");
2403 switch (trackref->algo()) {
2404 case TrackBase::ctf:
2405 case TrackBase::iter0:
2406 case TrackBase::iter1:
2407 case TrackBase::iter2:
2408 case TrackBase::iter3:
2409 case TrackBase::iter4:
2410 case TrackBase::iter7:
2411 case TrackBase::iter9:
2412 case TrackBase::iter10:
2414 case TrackBase::iter5:
2415 case TrackBase::iter6:
2416 active[iTrack] =
false;
2417 totalChargedMomentum -= trackref->p();
2420 std::cout <<
"\tElement " << elements[iTrack]
2421 <<
" rejected (Dpt = " << -it->first
2422 <<
" GeV/c, algo = " << trackref->algo() <<
")" << std::endl;
2432 Caloresolution *= totalChargedMomentum;
2433 Caloresolution =
std::sqrt(Caloresolution*Caloresolution + muonHCALError + muonECALError);
2437 for ( IT it = associatedTracks.begin(); it != associatedTracks.end(); ++it ) {
2438 unsigned iTrack = it->second.first;
2439 if ( !active[iTrack] )
continue;
2442 double Dp = trackRef->qoverpError()*trackMomentum*
trackMomentum;
2446 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iTrack );
2447 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
2448 std::pair<II,II> myEcals = associatedEcals.equal_range(iTrack);
2449 for (II
ii=myEcals.first;
ii!=myEcals.second; ++
ii ) {
2450 unsigned iEcal =
ii->second.second;
2451 if ( active[iEcal] )
continue;
2452 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal );
2456 std::pair<II,II> myHOs = associatedHOs.equal_range(iTrack);
2457 for (II
ii=myHOs.first;
ii!=myHOs.second; ++
ii ) {
2458 unsigned iHO =
ii->second.second;
2459 if ( active[iHO] )
continue;
2460 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHO );
2464 if ( iTrack == corrTrack ) {
2465 (*pfCandidates_)[tmpi].rescaleMomentum(corrFact);
2466 trackMomentum *= corrFact;
2468 chargedHadronsIndices.push_back( tmpi );
2469 chargedHadronsInBlock.push_back( iTrack );
2470 active[iTrack] =
false;
2471 hcalP.push_back(trackMomentum);
2472 hcalDP.push_back(Dp);
2473 if (Dp/trackMomentum > maxDPovP) maxDPovP = Dp/
trackMomentum;
2474 sumpError2 += Dp*Dp;
2478 TotalError =
sqrt(sumpError2 + Caloresolution*Caloresolution);
2481 cout<<
"\tCompare Calo Energy to total charged momentum "<<endl;
2482 cout<<
"\t\tsum p = "<<totalChargedMomentum<<
" +- "<<
sqrt(sumpError2)<<endl;
2483 cout<<
"\t\tsum ecal = "<<totalEcal<<endl;
2484 cout<<
"\t\tsum hcal = "<<totalHcal<<endl;
2485 cout<<
"\t\t => Calo Energy = "<<caloEnergy<<
" +- "<<Caloresolution<<endl;
2486 cout<<
"\t\t => Calo Energy- total charged momentum = "
2487 <<caloEnergy-totalChargedMomentum<<
" +- "<<TotalError<<endl;
2494 double nsigma =
nSigmaHCAL(totalChargedMomentum,hclusterref->positionREP().Eta());
2496 if (
abs(totalChargedMomentum-caloEnergy)<nsigma*TotalError ) {
2502 cout<<
"\t\tcase 1: COMPATIBLE "
2503 <<
"|Calo Energy- total charged momentum| = "
2504 <<
abs(caloEnergy-totalChargedMomentum)
2505 <<
" < "<<nsigma<<
" x "<<TotalError<<endl;
2506 if (maxDPovP < 0.1 )
2507 cout<<
"\t\t\tmax DP/P = "<< maxDPovP
2508 <<
" less than 0.1: do nothing "<<endl;
2510 cout<<
"\t\t\tmax DP/P = "<< maxDPovP
2511 <<
" > 0.1: take weighted averages "<<endl;
2515 if (maxDPovP > 0.1) {
2519 int nrows = chargedHadronsIndices.size();
2520 TMatrixTSym<double>
a (nrows);
2522 TVectorD
check(nrows);
2523 double sigma2E = Caloresolution*Caloresolution;
2524 for(
int i=0;
i<nrows;
i++) {
2525 double sigma2i = hcalDP[
i]*hcalDP[
i];
2527 cout<<
"\t\t\ttrack associated to hcal "<<
i
2528 <<
" P = "<<hcalP[
i]<<
" +- "
2531 a(
i,
i) = 1./sigma2i + 1./sigma2E;
2532 b(
i) = hcalP[
i]/sigma2i + caloEnergy/sigma2E;
2533 for(
int j=0;
j<nrows;
j++) {
2535 a(
i,
j) = 1./sigma2E;
2546 TDecompChol decomp(a);
2548 TVectorD
x = decomp.Solve(b, ok);
2552 for (
int i=0;
i<nrows;
i++){
2554 unsigned ich = chargedHadronsIndices[
i];
2555 double rescaleFactor =
x(
i)/hcalP[
i];
2556 (*pfCandidates_)[ich].rescaleMomentum( rescaleFactor );
2559 cout<<
"\t\t\told p "<<hcalP[
i]
2561 <<
" rescale "<<rescaleFactor<<endl;
2566 cerr<<
"not ok!"<<endl;
2573 else if( caloEnergy > totalChargedMomentum ) {
2592 double eNeutralHadron = caloEnergy - totalChargedMomentum;
2593 double ePhoton = (caloEnergy - totalChargedMomentum) / slopeEcal;
2596 if(!sortedTracks.empty() ){
2597 cout<<
"\t\tcase 2: NEUTRAL DETECTION "
2598 <<caloEnergy<<
" > "<<nsigma<<
"x"<<TotalError
2599 <<
" + "<<totalChargedMomentum<<endl;
2600 cout<<
"\t\tneutral activity detected: "<<endl
2601 <<
"\t\t\t photon = "<<ePhoton<<endl
2602 <<
"\t\t\tor neutral hadron = "<<eNeutralHadron<<endl;
2604 cout<<
"\t\tphoton or hadron ?"<<endl;}
2606 if(sortedTracks.empty() )
2607 cout<<
"\t\tno track -> hadron "<<endl;
2609 cout<<
"\t\t"<<sortedTracks.size()
2610 <<
"tracks -> check if the excess is photonic or hadronic"<<endl;
2614 double ratioMax = 0.;
2616 unsigned maxiEcal= 9999;
2620 for(IE ie = sortedTracks.begin(); ie != sortedTracks.end(); ++ie ) {
2622 unsigned iTrack = ie->second;
2628 assert( !trackRef.
isNull() );
2630 II iae = associatedEcals.find(iTrack);
2632 if( iae == associatedEcals.end() )
continue;
2635 unsigned iEcal = iae->second.second;
2641 assert( !clusterRef.
isNull() );
2643 double pTrack = trackRef->p();
2644 double eECAL = clusterRef->energy();
2645 double eECALOverpTrack = eECAL / pTrack;
2647 if ( eECALOverpTrack > ratioMax ) {
2648 ratioMax = eECALOverpTrack;
2649 maxEcalRef = clusterRef;
2655 std::vector<reco::PFClusterRef> pivotalClusterRef;
2656 std::vector<unsigned> iPivotal;
2657 std::vector<double> particleEnergy, ecalEnergy, hcalEnergy, rawecalEnergy, rawhcalEnergy;
2658 std::vector<::math::XYZVector> particleDirection;
2662 if ( ePhoton < totalEcal || eNeutralHadron-calibEcal < 1E-10 ) {
2663 if ( !maxEcalRef.
isNull() ) {
2665 mergedPhotonEnergy = ePhoton;
2669 if ( !maxEcalRef.
isNull() ) {
2671 mergedPhotonEnergy = totalEcal;
2674 mergedNeutralHadronEnergy = eNeutralHadron-calibEcal;
2677 if ( mergedPhotonEnergy > 0 ) {
2680 if ( ecalClusters.size()<=1 ) {
2681 ecalClusters.clear();
2682 ecalClusters.push_back(make_pair(maxiEcal, photonAtECAL));
2683 sumEcalClusters=
sqrt(photonAtECAL.Mag2());
2685 for(std::vector<std::pair<unsigned,::math::XYZVector> >::const_iterator pae = ecalClusters.begin(); pae != ecalClusters.end(); ++pae ) {
2686 double clusterEnergy=
sqrt(pae->second.Mag2());
2687 particleEnergy.push_back(mergedPhotonEnergy*clusterEnergy/sumEcalClusters);
2688 particleDirection.push_back(pae->second);
2689 ecalEnergy.push_back(mergedPhotonEnergy*clusterEnergy/sumEcalClusters);
2690 hcalEnergy.push_back(0.);
2691 rawecalEnergy.push_back(totalEcal);
2692 rawhcalEnergy.push_back(totalHcal);
2693 pivotalClusterRef.push_back(elements[pae->first].clusterRef());
2694 iPivotal.push_back(pae->first);
2698 if ( mergedNeutralHadronEnergy > 1.0 ) {
2701 if ( ecalClusters.size()<=1 ) {
2702 ecalClusters.clear();
2703 ecalClusters.push_back(make_pair(iHcal, hadronAtECAL));
2704 sumEcalClusters=
sqrt(hadronAtECAL.Mag2());
2706 for(std::vector<std::pair<unsigned,::math::XYZVector> >::const_iterator pae = ecalClusters.begin(); pae != ecalClusters.end(); ++pae ) {
2707 double clusterEnergy=
sqrt(pae->second.Mag2());
2708 particleEnergy.push_back(mergedNeutralHadronEnergy*clusterEnergy/sumEcalClusters);
2709 particleDirection.push_back(pae->second);
2710 ecalEnergy.push_back(0.);
2711 hcalEnergy.push_back(mergedNeutralHadronEnergy*clusterEnergy/sumEcalClusters);
2712 rawecalEnergy.push_back(totalEcal);
2713 rawhcalEnergy.push_back(totalHcal);
2714 pivotalClusterRef.push_back(hclusterref);
2715 iPivotal.push_back(iHcal);
2723 for (
unsigned iPivot=0; iPivot<iPivotal.size(); ++iPivot ) {
2725 if ( particleEnergy[iPivot] < 0. )
2726 std::cout <<
"ALARM = Negative energy ! "
2727 << particleEnergy[iPivot] << std::endl;
2729 bool useDirection =
true;
2731 particleEnergy[iPivot],
2733 particleDirection[iPivot].
X(),
2734 particleDirection[iPivot].Y(),
2735 particleDirection[iPivot].
Z());
2738 (*pfCandidates_)[tmpi].setEcalEnergy( rawecalEnergy[iPivot],ecalEnergy[iPivot] );
2740 (*pfCandidates_)[tmpi].setHcalEnergy( rawhcalEnergy[iPivot],hcalEnergy[iPivot] );
2741 (*pfCandidates_)[tmpi].setHoEnergy(0., 0.);
2743 (*pfCandidates_)[tmpi].setHcalEnergy( rawhcalEnergy[iPivot]-totalHO,hcalEnergy[iPivot]*(1.-totalHO/rawhcalEnergy[iPivot]));
2744 (*pfCandidates_)[tmpi].setHoEnergy(totalHO, totalHO * hcalEnergy[iPivot]/rawhcalEnergy[iPivot]);
2746 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
2747 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
2748 (*pfCandidates_)[tmpi].set_mva_nothing_gamma( -1. );
2751 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
2752 for (
unsigned ich=0; ich<chargedHadronsInBlock.size(); ++ich) {
2753 unsigned iTrack = chargedHadronsInBlock[ich];
2754 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iTrack );
2760 std::pair<II,II> myEcals = associatedEcals.equal_range(iTrack);
2761 for (II
ii=myEcals.first;
ii!=myEcals.second; ++
ii ) {
2762 unsigned iEcal =
ii->second.second;
2763 if ( active[iEcal] )
continue;
2764 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal );
2776 double totalHcalEnergyCalibrated = calibHcal;
2777 double totalEcalEnergyCalibrated = calibEcal;
2792 totalHcalEnergyCalibrated -= mergedNeutralHadronEnergy;
2794 totalEcalEnergyCalibrated -= mergedPhotonEnergy;
2799 double chargedHadronsTotalEnergy = 0;
2800 for(
unsigned ich=0; ich<chargedHadronsIndices.size(); ++ich ) {
2801 unsigned index = chargedHadronsIndices[ich];
2803 chargedHadronsTotalEnergy += chargedHadron.
energy();
2806 for(
unsigned ich=0; ich<chargedHadronsIndices.size(); ++ich ) {
2807 unsigned index = chargedHadronsIndices[ich];
2809 float fraction = chargedHadron.
energy()/chargedHadronsTotalEnergy;
2812 chargedHadron.
setHcalEnergy( fraction * totalHcal, fraction * totalHcalEnergyCalibrated );
2815 chargedHadron.
setHcalEnergy( fraction * (totalHcal-totalHO), fraction * totalHcalEnergyCalibrated * (1.-totalHO/totalHcal) );
2816 chargedHadron.
setHoEnergy( fraction * totalHO, fraction * totalHO * totalHcalEnergyCalibrated / totalHcal );
2819 chargedHadron.
setEcalEnergy( fraction * totalEcal, fraction * totalEcalEnergyCalibrated );
2823 for ( IS is = ecalSatellites.begin(); is != ecalSatellites.end(); ++is ) {
2826 unsigned iEcal = is->second.first;
2827 if ( !active[iEcal] )
continue;
2832 PFClusterRef eclusterref = elements[iEcal].clusterRef();
2833 assert(!eclusterref.
isNull() );
2836 active[iEcal] =
false;
2839 std::multimap<double, unsigned> assTracks;
2840 block.associatedElements( iEcal, linkData,
2847 (*pfCandidates_)[tmpi].setEcalEnergy( eclusterref->energy(),
sqrt(is->second.second.Mag2()) );
2848 (*pfCandidates_)[tmpi].setHcalEnergy( 0., 0. );
2849 (*pfCandidates_)[tmpi].setHoEnergy( 0., 0. );
2850 (*pfCandidates_)[tmpi].setPs1Energy( associatedPSs[iEcal].
first );
2851 (*pfCandidates_)[tmpi].setPs2Energy( associatedPSs[iEcal].
second );
2852 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal );
2853 (*pfCandidates_)[tmpi].addElementInBlock( blockref, sortedTracks.begin()->second) ;
2867 <<
"---- loop remaining hcal ------- "<<endl;
2873 for(
unsigned ihcluster=0; ihcluster<hcalIs.size(); ihcluster++) {
2874 unsigned iHcal = hcalIs[ihcluster];
2877 std::vector<unsigned> ecalRefs;
2878 std::vector<unsigned> hoRefs;
2881 cout<<endl<<elements[iHcal]<<
" ";
2884 if( !active[iHcal] ) {
2886 cout<<
"not active"<<endl;
2891 std::multimap<double, unsigned> ecalElems;
2892 block.associatedElements( iHcal, linkData,
2898 float totalEcal = 0.;
2901 for(IE ie = ecalElems.begin(); ie != ecalElems.end(); ++ie ) {
2903 unsigned iEcal = ie->second;
2904 double dist = ie->first;
2909 if( !active[iEcal] )
continue;
2930 std::multimap<double, unsigned> hcalElems;
2931 block.associatedElements( iEcal, linkData,
2936 bool isClosest =
true;
2937 for(IE ih = hcalElems.begin(); ih != hcalElems.end(); ++ih ) {
2939 unsigned jHcal = ih->second;
2940 double distH = ih->first;
2942 if ( !active[jHcal] )
continue;
2944 if ( distH < dist ) {
2951 if (!isClosest)
continue;
2955 cout<<
"\telement "<<elements[iEcal]<<
" linked with dist "<< dist<<endl;
2956 cout<<
"Added to HCAL cluster to form a neutral hadron"<<endl;
2960 assert( !eclusterRef.
isNull() );
2963 vector<double> ps1Ene(1,static_cast<double>(0.));
2965 vector<double> ps2Ene(1,static_cast<double>(0.));
2967 bool crackCorrection =
false;
2968 double ecalEnergy =
calibration_->energyEm(*eclusterRef,ps1Ene,ps2Ene,crackCorrection);
2972 totalEcal += ecalEnergy;
2973 if ( ecalEnergy > ecalMax ) {
2974 ecalMax = ecalEnergy;
2975 eClusterRef = eclusterRef;
2978 ecalRefs.push_back(iEcal);
2979 active[iEcal] =
false;
2985 double totalHO = 0.;
2989 std::multimap<double, unsigned> hoElems;
2990 block.associatedElements( iHcal, linkData,
3000 for(IE ie = hoElems.begin(); ie != hoElems.end(); ++ie ) {
3002 unsigned iHO = ie->second;
3003 double dist = ie->first;
3005 assert( type == PFBlockElement::HO );
3008 if( !active[iHO] )
continue;
3014 std::multimap<double, unsigned> hcalElems;
3015 block.associatedElements( iHO, linkData,
3020 bool isClosest =
true;
3021 for(IE ih = hcalElems.begin(); ih != hcalElems.end(); ++ih ) {
3023 unsigned jHcal = ih->second;
3024 double distH = ih->first;
3026 if ( !active[jHcal] )
continue;
3028 if ( distH < dist ) {
3035 if (!isClosest)
continue;
3038 cout<<
"\telement "<<elements[iHO]<<
" linked with dist "<< dist<<endl;
3039 cout<<
"Added to HCAL cluster to form a neutral hadron"<<endl;
3043 assert( !hoclusterRef.
isNull() );
3045 double hoEnergy = hoclusterRef->energy();
3047 totalHO += hoEnergy;
3048 if ( hoEnergy > hoMax ) {
3050 hoClusterRef = hoclusterRef;
3054 hoRefs.push_back(iHO);
3055 active[iHO] =
false;
3061 = elements[iHcal].clusterRef();
3062 assert( !hclusterRef.
isNull() );
3065 double totalHcal = hclusterRef->energy();
3067 if (
useHO_ ) totalHcal += totalHO;
3075 double calibEcal = totalEcal > 0. ? totalEcal : 0.;
3076 double calibHcal =
std::max(0.,totalHcal);
3080 calibEcal = totalEcal;
3083 hclusterRef->positionREP().Eta(),
3084 hclusterRef->positionREP().Phi());
3097 calibEcal+calibHcal );
3100 (*pfCandidates_)[tmpi].setEcalEnergy( totalEcal, calibEcal );
3102 (*pfCandidates_)[tmpi].setHcalEnergy( totalHcal, calibHcal );
3103 (*pfCandidates_)[tmpi].setHoEnergy(0.,0.);
3105 (*pfCandidates_)[tmpi].setHcalEnergy( totalHcal-totalHO, calibHcal*(1.-totalHO/totalHcal));
3106 (*pfCandidates_)[tmpi].setHoEnergy(totalHO,totalHO*calibHcal/totalHcal);
3108 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
3109 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
3110 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iHcal );
3111 for (
unsigned iec=0; iec<ecalRefs.size(); ++iec)
3112 (*
pfCandidates_)[tmpi].addElementInBlock( blockref, ecalRefs[iec] );
3113 for (
unsigned iho=0; iho<hoRefs.size(); ++iho)
3114 (*
pfCandidates_)[tmpi].addElementInBlock( blockref, hoRefs[iho] );
3123 if(
debug_)
cout<<endl<<
"---- loop ecal------- "<<endl;
3128 for(
unsigned i=0;
i<ecalIs.size();
i++) {
3129 unsigned iEcal = ecalIs[
i];
3132 cout<<endl<<elements[iEcal]<<
" ";
3134 if( ! active[iEcal] ) {
3136 cout<<
"not active"<<endl;
3143 PFClusterRef clusterref = elements[iEcal].clusterRef();
3144 assert(!clusterref.
isNull() );
3146 active[iEcal] =
false;
3149 vector<double> ps1Ene(1,static_cast<double>(0.));
3151 vector<double> ps2Ene(1,static_cast<double>(0.));
3153 bool crackCorrection =
false;
3154 float ecalEnergy =
calibration_->energyEm(*clusterref,ps1Ene,ps2Ene,crackCorrection);
3156 double particleEnergy = ecalEnergy;
3161 (*pfCandidates_)[tmpi].setEcalEnergy( clusterref->energy(),ecalEnergy );
3162 (*pfCandidates_)[tmpi].setHcalEnergy( 0., 0. );
3163 (*pfCandidates_)[tmpi].setHoEnergy( 0., 0. );
3164 (*pfCandidates_)[tmpi].setPs1Energy( 0. );
3165 (*pfCandidates_)[tmpi].setPs2Energy( 0. );
3166 (*pfCandidates_)[tmpi].addElementInBlock( blockref, iEcal );
3182 int charge = track.
charge()>0 ? 1 : -1;
3185 double px = track.
px();
3186 double py = track.
py();
3187 double pz = track.
pz();
3188 double energy =
sqrt(track.
p()*track.
p() + 0.13957*0.13957);
3200 pfCandidates_->back().setVertexSource( PFCandidate::kTrkVertex );
3213 if ((!isMuon) && isFromDisp) {
3214 double Dpt = trackRef->ptError();
3215 double dptRel = Dpt/trackRef->pt()*100;
3221 cout <<
"Not refitted px = " << px <<
" py = " << py <<
" pz = " << pz <<
" energy = " << energy << endl;
3224 reco::Track trackRefit = vRef->refittedTrack(trackRef);
3229 sqrt(trackRefit.
p()*trackRefit.
p() + 0.13957*0.13957));
3231 cout <<
"Refitted px = " << px <<
" py = " << py <<
" pz = " << pz <<
" energy = " << energy << endl;
3249 double particleEnergy,
3262 if ( useDirection ) {
3263 switch( cluster.
layer() ) {
3266 factor =
std::sqrt(cluster.
position().Perp2()/(particleX*particleX+particleY*particleY));
3272 factor = cluster.
position().Z()/particleZ;
3287 cluster.
position().Y()-vertexPos.Y(),
3288 cluster.
position().Z()-vertexPos.Z());
3290 particleY*factor-vertexPos.Y(),
3291 particleZ*factor-vertexPos.Z() );
3296 clusterPos = useDirection ? particleDirection.Unit() : clusterPos.Unit();
3297 clusterPos *= particleEnergy;
3303 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzM4D<double> >
3304 momentum( clusterPos.X(), clusterPos.Y(), clusterPos.Z(), mass);
3314 switch( cluster.
layer() ) {
3317 particleType = PFCandidate::gamma;
3321 particleType = PFCandidate::h0;
3324 particleType = PFCandidate::h_HF;
3327 particleType = PFCandidate::egamma_HF;
3363 if ( clusterEnergyHCAL < 1. ) clusterEnergyHCAL = 1.;
3365 double resol = fabs(eta) < 1.48 ?
3366 sqrt (1.02*1.02/clusterEnergyHCAL + 0.065*0.065)
3368 sqrt (1.20*1.20/clusterEnergyHCAL + 0.028*0.028);
3376 double nS = fabs(eta) < 1.48 ?
3386 if(!out )
return out;
3388 out<<
"====== Particle Flow Algorithm ======= ";
3395 out<<
"reconstructed particles: "<<endl;
3397 const std::auto_ptr< reco::PFCandidateCollection >&
3400 if(!candidates.get() ) {
3401 out<<
"candidates already transfered"<<endl;
3430 std::vector<bool>& active,
3431 std::vector<double>& psEne) {
3439 std::multimap<double, unsigned> sortedPS;
3440 typedef std::multimap<double, unsigned>::iterator IE;
3442 sortedPS, psElementType,
3446 double totalPS = 0.;
3447 for ( IE ips=sortedPS.begin(); ips!=sortedPS.end(); ++ips ) {
3450 unsigned iPS = ips->second;
3454 if (!active[iPS])
continue;
3457 std::multimap<double, unsigned> sortedECAL;
3462 unsigned jEcal = sortedECAL.begin()->second;
3463 if ( jEcal != iEcal )
continue;
3467 assert( pstype == psElementType );
3468 PFClusterRef psclusterref = elements[iPS].clusterRef();
3469 assert(!psclusterref.
isNull() );
3470 totalPS += psclusterref->energy();
3471 psEne[0] += psclusterref->energy();
3472 active[iPS] =
false;
3487 bool bPrimary = (order.find(
"primary") != string::npos);
3488 bool bSecondary = (order.find(
"secondary") != string::npos);
3489 bool bAll = (order.find(
"all") != string::npos);
3494 if (bPrimary && isToDisp)
return true;
3495 if (bSecondary && isFromDisp )
return true;
3496 if (bAll && ( isToDisp || isFromDisp ) )
return true;
3525 std::vector<unsigned int> pfCandidatesToBeRemoved;
3532 double met2 = metX*metX+metY*metY;
3534 double significance =
std::sqrt(met2/sumet);
3535 double significanceCor = significance;
3538 double metXCor = metX;
3539 double metYCor = metY;
3540 double sumetCor = sumet;
3541 double met2Cor = met2;
3543 double deltaPhiPt = 100.;
3545 unsigned iCor = 1E9;
3550 double metReduc = -1.;
3564 for(
unsigned j=0;
j<pfCandidatesToBeRemoved.size(); ++
j) {
3565 if (
i == pfCandidatesToBeRemoved[
j] ) skip =
true;
3568 if ( skip )
continue;
3571 deltaPhi = std::acos((metX*pfc.
px()+metY*pfc.
py())/(pfc.
pt()*
std::sqrt(met2)));
3572 deltaPhiPt = deltaPhi*pfc.
pt();
3576 double metXInt = metX - pfc.
px();
3577 double metYInt = metY - pfc.
py();
3578 double sumetInt = sumet - pfc.
pt();
3579 double met2Int = metXInt*metXInt+metYInt*metYInt;
3580 if ( met2Int < met2Cor ) {
3583 metReduc = (met2-met2Int)/met2Int;
3585 sumetCor = sumetInt;
3586 significanceCor =
std::sqrt(met2Cor/sumetCor);
3593 pfCandidatesToBeRemoved.push_back(iCor);
3607 std::cout <<
"Significance reduction = " << significance <<
" -> "
3608 << significanceCor <<
" = " << significanceCor - significance
3610 for(
unsigned j=0;
j<pfCandidatesToBeRemoved.size(); ++
j) {
3611 std::cout <<
"Removed : " << (*pfCandidates_)[pfCandidatesToBeRemoved[
j]] << std::endl;
3613 (*pfCandidates_)[pfCandidatesToBeRemoved[
j]].rescaleMomentum(1E-6);
3627 if ( !cleanedHits.size() )
return;
3633 std::vector<unsigned int> hitsToBeAdded;
3640 double met2 = metX*metX+metY*metY;
3641 double met2_Original = met2;
3645 double metXCor = metX;
3646 double metYCor = metY;
3647 double sumetCor = sumet;
3648 double met2Cor = met2;
3650 unsigned iCor = 1E9;
3655 double metReduc = -1.;
3657 for(
unsigned i=0;
i<cleanedHits.size(); ++
i) {
3666 for(
unsigned j=0;
j<hitsToBeAdded.size(); ++
j) {
3667 if (
i == hitsToBeAdded[
j] ) skip =
true;
3670 if ( skip )
continue;
3673 double metXInt = metX + px;
3674 double metYInt = metY + py;
3675 double sumetInt = sumet +
pt;
3676 double met2Int = metXInt*metXInt+metYInt*metYInt;
3679 if ( met2Int < met2Cor ) {
3682 metReduc = (met2-met2Int)/met2Int;
3684 sumetCor = sumetInt;
3693 hitsToBeAdded.push_back(iCor);
3707 std::cout << hitsToBeAdded.size() <<
" hits were re-added " << std::endl;
3711 std::cout <<
"Added after cleaning check : " << std::endl;
3713 for(
unsigned j=0;
j<hitsToBeAdded.size(); ++
j) {
3733 for(
unsigned ic=0;ic<
size;++ic) {
3742 (*pfCandidates_)[ic].setPFElectronExtraRef(theRef);
3754 (*pfCandidates_)[ic].set_mva_e_pi(it->mvaVariable(PFCandidateElectronExtra::MVA_MVA));
3756 (*pfCandidates_)[ic].setPFElectronExtraRef(theRef);
3757 (*pfCandidates_)[ic].setGsfTrackRef(it->gsfTrackRef());
3765 for(
unsigned ic=0;ic<
size;++ic) {
3773 (*pfElectronCandidates_)[ic].setPFElectronExtraRef(theRef);
3784 for(
unsigned ic=0;ic<
size;++ic) {
3789 for(
unsigned pcextra=0;pcextra<sizePhExtra;++pcextra) {
3792 (*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
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)
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.
virtual float eta() const
momentum pseudorapidity
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()
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