111 std::vector<bool>::const_iterator actIter = active.begin();
113 bool isActive =
true;
116 if(elements.
size() != active.size()) {
124 std::vector<unsigned int> elemsToLock;
125 elemsToLock.resize(0);
127 for( ; ele != elements.
end(); ++ele, ++actIter ) {
133 float photonEnergy_ = 0.;
137 float RawEcalEne = 0.;
140 float ps1TotEne = 0.;
141 float ps2TotEne = 0.;
143 bool hasConvTrack=
false;
144 bool hasSingleleg=
false;
145 std::vector<unsigned int> AddClusters(0);
147 std::multimap<unsigned int, unsigned int>ClusterAddPS1;
148 std::multimap<unsigned int, unsigned int>ClusterAddPS2;
149 std::vector<reco::TrackRef>singleLegRef;
150 std::vector<float>MVA_values(0);
151 std::vector<float>MVALCorr;
154 isActive = *(actIter);
167 elemsToLock.push_back(ele-elements.
begin());
169 std::multimap<double, unsigned int> ecalAssoPFClusters;
170 blockRef->associatedElements( ele-elements.
begin(),
179 if( ecalAssoPFClusters.empty() ) {
187 for(std::multimap<double, unsigned int>::iterator itecal = ecalAssoPFClusters.begin();
188 itecal != ecalAssoPFClusters.end(); ++itecal) {
199 vector<double> ps1Ene(0);
200 vector<double> ps2Ene(0);
215 if( !( active[itecal->second] ) ) {
227 bool isClosest=
false;
228 std::multimap<double, unsigned int> Trackscheck;
229 blockRef->associatedElements( itecal->second,
234 for(std::multimap<double, unsigned int>::iterator
track = Trackscheck.begin();
238 if( ! (active[
track->second]) )
continue;
241 std::multimap<double, unsigned int> closecheck;
242 blockRef->associatedElements(
track->second,
245 reco::PFBlockElement::ECAL,
247 if(closecheck.begin()->second ==itecal->second)isClosest=
true;
248 if(!hasSingleleg)mva_reject++;
251 if(mva_reject>0 && isClosest)useIt=
false;
253 if( !useIt )
continue;
258 elemsToLock.push_back(itecal->second);
261 std::multimap<double, unsigned int> PS1Elems;
262 std::multimap<double, unsigned int> PS2Elems;
264 blockRef->associatedElements( itecal->second,
270 blockRef->associatedElements( itecal->second,
277 for(std::multimap<double, unsigned int>::iterator iteps = PS1Elems.begin();
278 iteps != PS1Elems.end(); ++iteps) {
281 if( !(active[iteps->second]) )
continue;
284 std::multimap<double, unsigned int> ECALPS1check;
285 blockRef->associatedElements( iteps->second,
288 reco::PFBlockElement::ECAL,
290 if(itecal->second==ECALPS1check.begin()->second)
293 ps1Ene.
push_back( ps1ClusterRef->energy() );
294 ps1=ps1+ps1ClusterRef->energy();
296 elemsToLock.push_back(iteps->second);
299 for(std::multimap<double, unsigned int>::iterator iteps = PS2Elems.begin();
300 iteps != PS2Elems.end(); ++iteps) {
303 if( !(active[iteps->second]) )
continue;
306 std::multimap<double, unsigned int> ECALPS2check;
307 blockRef->associatedElements( iteps->second,
310 reco::PFBlockElement::ECAL,
312 if(itecal->second==ECALPS2check.begin()->second)
315 ps2Ene.
push_back( ps2ClusterRef->energy() );
316 ps2=ps2ClusterRef->energy()+ps2;
318 elemsToLock.push_back(iteps->second);
323 std::multimap<double, unsigned int> hcalElems;
324 blockRef->associatedElements( itecal->second,linkData,
329 for(std::multimap<double, unsigned int>::iterator ithcal = hcalElems.begin();
330 ithcal != hcalElems.end(); ++ithcal) {
332 if ( ! (active[ithcal->second] ) )
continue;
339 if ( !useHcal )
continue;
347 std::multimap<double, unsigned int> convTracks;
348 blockRef->associatedElements( itecal->second,
353 for(std::multimap<double, unsigned int>::iterator
track = convTracks.begin();
357 if( ! (active[
track->second]) )
continue;
383 elemsToLock.push_back(
track->second);
387 for(
unsigned int ic=0; ic<singleLegRef.size(); ic++)
388 if(singleLegRef[ic]==t_ref)matched=
true;
391 singleLegRef.push_back(t_ref);
395 std::multimap<double, unsigned int> moreClusters;
396 blockRef->associatedElements(
track->second,
399 reco::PFBlockElement::ECAL,
402 float p_in=
sqrt(elements[
track->second].trackRef()->innerMomentum().x() * elements[
track->second].trackRef()->innerMomentum().x() +
403 elements[
track->second].trackRef()->innerMomentum().y()*elements[
track->second].trackRef()->innerMomentum().y()+
404 elements[
track->second].trackRef()->innerMomentum().z()*elements[
track->second].trackRef()->innerMomentum().z());
406 for(std::multimap<double, unsigned int>::iterator clust = moreClusters.begin();
407 clust != moreClusters.end(); ++clust)
409 if(!active[clust->second])
continue;
411 linked_E=linked_E+elements[clust->second].clusterRef()->energy();
413 if(linked_E/p_in>1.5)
break;
416 for(std::multimap<double, unsigned int>::iterator cluscheck = ecalAssoPFClusters.begin();
417 cluscheck != ecalAssoPFClusters.end(); ++cluscheck)
419 if(cluscheck->second==clust->second)included=
true;
421 if(!included)AddClusters.
push_back(clust->second);
429 elemsToLock.push_back(
track->second);
435 std::multimap<double, unsigned int> moreClusters;
436 blockRef->associatedElements(
track->second,
439 reco::PFBlockElement::ECAL,
442 float p_in=
sqrt(elements[
track->second].trackRef()->innerMomentum().x() * elements[
track->second].trackRef()->innerMomentum().x() +
443 elements[
track->second].trackRef()->innerMomentum().y()*elements[
track->second].trackRef()->innerMomentum().y()+
444 elements[
track->second].trackRef()->innerMomentum().z()*elements[
track->second].trackRef()->innerMomentum().z());
446 for(std::multimap<double, unsigned int>::iterator clust = moreClusters.begin();
447 clust != moreClusters.end(); ++clust)
449 if(!active[clust->second])
continue;
450 linked_E=linked_E+elements[clust->second].clusterRef()->energy();
451 if(linked_E/p_in>1.5)
break;
453 for(std::multimap<double, unsigned int>::iterator cluscheck = ecalAssoPFClusters.begin();
454 cluscheck != ecalAssoPFClusters.end(); ++cluscheck)
456 if(cluscheck->second==clust->second)included=
true;
458 if(!included)AddClusters.
push_back(clust->second);
464 std::multimap<double, unsigned int> moreTracks;
465 blockRef->associatedElements(
track->second,
471 for(std::multimap<double, unsigned int>::iterator track2 = moreTracks.begin();
472 track2 != moreTracks.end(); ++track2) {
475 if( ! (active[track2->second]) )
continue;
477 if(
track->second==track2->second)
continue;
481 elemsToLock.push_back(track2->second);
484 std::multimap<double, unsigned int> convEcal;
485 blockRef->associatedElements( track2->second,
488 reco::PFBlockElement::ECAL,
490 float p_in=
sqrt(elements[
track->second].trackRef()->innerMomentum().x()*elements[
track->second].trackRef()->innerMomentum().x()+
491 elements[
track->second].trackRef()->innerMomentum().y()*elements[
track->second].trackRef()->innerMomentum().y()+
492 elements[
track->second].trackRef()->innerMomentum().z()*elements[
track->second].trackRef()->innerMomentum().z());
496 for(std::multimap<double, unsigned int>::iterator itConvEcal = convEcal.begin();
497 itConvEcal != convEcal.end(); ++itConvEcal) {
499 if( ! (active[itConvEcal->second]) )
continue;
501 for(std::multimap<double, unsigned int>::iterator cluscheck = ecalAssoPFClusters.begin();
502 cluscheck != ecalAssoPFClusters.end(); ++cluscheck)
504 if(cluscheck->second==itConvEcal->second)included=
true;
506 linked_E=linked_E+elements[itConvEcal->second].clusterRef()->energy();
507 if(linked_E/p_in>1.5)
break;
508 if(!included){AddClusters.
push_back(itConvEcal->second);
515 std::multimap<double, unsigned int> hcalElems_conv;
516 blockRef->associatedElements( itecal->second,linkData,
521 for(std::multimap<double, unsigned int>::iterator ithcal2 = hcalElems_conv.begin();
522 ithcal2 != hcalElems_conv.end(); ++ithcal2) {
524 if ( ! (active[ithcal2->second] ) )
continue;
531 if ( !useHcal )
continue;
547 float addedCalibEne=0;
549 std::vector<double>AddedPS1(0);
550 std::vector<double>AddedPS2(0);
553 for(
unsigned int i=0;
i<AddClusters.size();
i++)
555 std::multimap<double, unsigned int> PS1Elems_conv;
556 std::multimap<double, unsigned int> PS2Elems_conv;
557 blockRef->associatedElements(AddClusters[
i],
562 blockRef->associatedElements( AddClusters[i],
568 for(std::multimap<double, unsigned int>::iterator iteps = PS1Elems_conv.begin();
569 iteps != PS1Elems_conv.end(); ++iteps)
571 if(!active[iteps->second])
continue;
572 std::multimap<double, unsigned int> PS1Elems_check;
573 blockRef->associatedElements(iteps->second,
576 reco::PFBlockElement::ECAL,
578 if(PS1Elems_check.begin()->second==AddClusters[
i])
582 AddedPS1.
push_back(ps1ClusterRef->energy());
583 addedps1=addedps1+ps1ClusterRef->energy();
584 elemsToLock.push_back(iteps->second);
588 for(std::multimap<double, unsigned int>::iterator iteps = PS2Elems_conv.begin();
589 iteps != PS2Elems_conv.end(); ++iteps) {
590 if(!active[iteps->second])
continue;
591 std::multimap<double, unsigned int> PS2Elems_check;
592 blockRef->associatedElements(iteps->second,
595 reco::PFBlockElement::ECAL,
598 if(PS2Elems_check.begin()->second==AddClusters[
i])
601 AddedPS2.
push_back(ps2ClusterRef->energy());
602 addedps2=addedps2+ps2ClusterRef->energy();
603 elemsToLock.push_back(iteps->second);
607 addedRawEne = AddclusterRef->energy()+addedRawEne;
611 elemsToLock.push_back(AddClusters[i]);
615 PFClusters.push_back(*clusterRef);
618 EE=LocCorr*clusterRef->energy()+addedCalibEne;
622 MVALCorr.push_back(LocCorr*clusterRef->energy());
628 RawEcalEne += clusterRef->energy()+addedRawEne;
629 photonX_ += EE * clusterRef->position().X();
630 photonY_ += EE * clusterRef->position().Y();
631 photonZ_ += EE * clusterRef->position().Z();
632 ps1TotEne += ps1+addedps1;
633 ps2TotEne += ps2+addedps2;
637 float Elec_rawEcal=0;
643 std::vector<double>AddedPS1(0);
644 std::vector<double>AddedPS2(0);
647 tempElectronCandidates,
655 for(std::vector<unsigned int>::const_iterator it =
665 unsigned int index=*it;
667 elements[
index].clusterRef();
669 Elec_rawEcal=Elec_rawEcal+
670 elements[
index].clusterRef()->energy();
671 std::multimap<double, unsigned int> PS1Elems;
672 std::multimap<double, unsigned int> PS2Elems;
674 blockRef->associatedElements(index,
678 blockRef->associatedElements( index,
685 for(std::multimap<double, unsigned int>::iterator iteps =
687 iteps != PS1Elems.end(); ++iteps)
689 std::multimap<double, unsigned int> Clustcheck; blockRef->associatedElements( iteps->second, linkData,
691 reco::PFBlockElement::ECAL,
693 if(Clustcheck.begin()->second==
index)
695 AddedPS1.push_back(elements[iteps->second].clusterRef()->energy());
696 Elec_totPs1=Elec_totPs1+elements[iteps->second].clusterRef()->energy();
700 for(std::multimap<double, unsigned int>::iterator iteps =
702 iteps != PS2Elems.end(); ++iteps)
704 std::multimap<double, unsigned int> Clustcheck; blockRef->associatedElements( iteps->second, linkData,
706 reco::PFBlockElement::ECAL,
708 if(Clustcheck.begin()->second==
index)
710 AddedPS2.push_back(elements[iteps->second].clusterRef()->energy());
711 Elec_totPs2=Elec_totPs2+elements[iteps->second].clusterRef()->energy();
717 energyEm(*clusterRef,AddedPS1,AddedPS2,
false);
718 PFClusters.push_back(*clusterRef);
721 EE=LocCorr*clusterRef->energy();
722 MVALCorr.push_back(LocCorr*clusterRef->energy());
727 MVALCorr.push_back(LocCorr*clusterRef->energy());
731 ElectronX += EE * clusterRef->position().X();
732 ElectronY += EE * clusterRef->position().Y();
733 ElectronZ += EE * clusterRef->position().Z();
747 photonEnergy_ += Elec_energy;
748 RawEcalEne += Elec_rawEcal;
749 photonX_ += ElectronX;
750 photonY_ += ElectronY;
751 photonZ_ += ElectronZ;
752 ps1TotEne += Elec_totPs1;
753 ps2TotEne += Elec_totPs2;
756 if( ! (photonEnergy_ > 0.) )
continue;
757 float sum_track_pt=0;
759 for(
unsigned int i=0; i<
IsoTracks.size(); i++)sum_track_pt=sum_track_pt+elements[
IsoTracks[i]].trackRef()->pt();
774 photonEnergy_* photonDirection.Y(),
775 photonEnergy_* photonDirection.Z(),
780 elemsToLock.resize(0);
799 photonCand.setPs1Energy(ps1TotEne);
800 photonCand.setPs2Energy(ps2TotEne);
801 photonCand.setEcalEnergy(RawEcalEne,photonEnergy_);
802 photonCand.setHcalEnergy(0.,0.);
803 photonCand.set_mva_nothing_gamma(1.);
806 photonCand.setVertex(
v );
810 for ( std::vector<reco::PFCandidate>::const_iterator
ec=tempElectronCandidates.begin();
ec != tempElectronCandidates.end(); ++
ec ){
813 if(count==
match_ind[i])photonCand.addDaughter(*
ec);
821 for(std::vector<unsigned int>::const_iterator it =
823 it !=
AddFromElectron_.end(); ++it)photonCand.addElementInBlock(blockRef,*it);
826 for(std::vector<unsigned int>::const_iterator it = elemsToLock.begin();
827 it != elemsToLock.end(); ++it)
831 photonCand.addElementInBlock(blockRef,*it);
834 for(
const auto& convref : elements[*it].convRefs() ) {
835 if(convref.isNonnull())
839 for(
unsigned int ic = 0; ic < ConversionsRef_.
size(); ic++)
841 if(ConversionsRef_[ic]==convref)matched=
true;
843 if(!matched)ConversionsRef_.
push_back(convref);
854 for(
unsigned int l=0;
l<MVALCorr.size(); ++
l)
867 GCorr * photonEnergy_ );
868 photonCand.setP4(photonCorrMomentum);
871 std::multimap<float, unsigned int>OrderedClust;
872 for(
unsigned int i=0; i<PFClusters.size(); ++
i){
874 OrderedClust.insert(make_pair(et, i));
876 std::multimap<float, unsigned int>::reverse_iterator rit;
877 rit=OrderedClust.rbegin();
878 unsigned int highEindex=(*rit).second;
887 myExtra.setMustache_Et(MustacheEt);
888 myExtra.setExcludedClust(excluded);
889 if(fabs(photonCand.eta()<1.4446))
892 myExtra.setMVAGlobalCorrE(GCorr * PFPhoECorr_);
893 else myExtra.setMVAGlobalCorrE(GCorr * photonEnergy_);
895 myExtra.SetPFPhotonRes(Res);
899 for(
unsigned int ic = 0; ic < MVA_values.size(); ic++)
901 myExtra.addSingleLegConvMva(MVA_values[ic]);
902 myExtra.addSingleLegConvTrackRef(singleLegRef[ic]);
905 for(
unsigned int ic = 0; ic < ConversionsRef_.
size(); ic++)
907 myExtra.addConversionRef(ConversionsRef_[ic]);
910 pfPhotonExtraCandidates.push_back(myExtra);
913 elemsToLock.resize(0);
const SuperClusterRef & superClusterRef() const
void EarlyConversion( std::vector< reco::PFCandidate > &tempElectronCandidates, const reco::PFBlockElementSuperCluster *sc)
double y() const
y coordinate
Sin< T >::type sin(const T &t)
std::map< unsigned int, Link > LinkData
Geom::Theta< T > theta() const
bool trackType(TrackType trType) const override
verbosityLevel verbosityLevel_
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float > > XYZPointF
point in space with cartesian internal representation
std::vector< unsigned int > AddFromElectron_
void addLCorrClusEnergy(float LCorrE)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
float EvaluateResMVA(const reco::PFCandidate &, const std::vector< reco::CaloCluster > &PFClusters)
double z() const
z coordinate
float EvaluateGCorrMVA(const reco::PFCandidate &, const std::vector< reco::CaloCluster > &PFClusters)
float EvaluateLCorrMVA(reco::PFClusterRef clusterRef)
const reco::Vertex * primaryVertex_
double sumPtTrackIsoSlopeForPhoton_
boost::shared_ptr< PFEnergyCalibration > thePFEnergyCalibration_
double x() const
x coordinate
XYZVectorD XYZVector
spatial vector with cartesian internal representation
XYZPointD XYZPoint
point in space with cartesian internal representation
et
define resolution functions of each parameter
bool EvaluateSingleLegMVA(const reco::PFBlockRef &blockref, const reco::Vertex &primaryvtx, unsigned int track_index)
Particle reconstructed by the particle flow algorithm.
static int position[264][3]
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
size_type size() const
Size of the RefVector.
double sumPtTrackIsoForPhoton_
void FillMustacheVar(const std::vector< CaloCluster > &clusters)
const PhotonRef & photonRef() const
std::vector< int > match_ind