13 #include "Math/GenVector/VectorUtil.h"
27 namespace MK = reco::MustacheKernel;
35 typedef std::pair<reco::CaloClusterPtr::key_type,reco::CaloClusterPtr> EEPSPair;
36 typedef std::binary_function<
const CalibClusterPtr&,
37 const CalibClusterPtr&,
38 bool> ClusBinaryFunction;
40 typedef std::unary_function<
const CalibClusterPtr&,
41 bool> ClusUnaryFunction;
43 bool sortByKey(
const EEPSPair&
a,
const EEPSPair&
b) {
44 return a.first < b.first;
47 inline double getPFClusterEnergy(
const PFClusterPtr&
p) {
54 const auto v = position - origin;
58 struct SumPSEnergy :
public std::binary_function<double,
63 double operator()(
double a,
64 const PFClusterPtr&
b) {
65 return a + (_thelayer == b->layer())*b->energy();
69 struct GreaterByE :
public ClusBinaryFunction {
70 bool operator()(
const CalibClusterPtr& x,
71 const CalibClusterPtr& y) {
72 return x->energy() > y->energy() ;
76 struct GreaterByEt :
public ClusBinaryFunction {
77 bool operator()(
const CalibClusterPtr& x,
78 const CalibClusterPtr& y) {
80 const double xpt =
ptFast(x->energy(),x->the_ptr()->position(),zero);
81 const double ypt =
ptFast(y->energy(),y->the_ptr()->position(),zero);
86 struct IsASeed :
public ClusUnaryFunction {
89 IsASeed(
double thresh,
bool useETcut =
false) :
91 bool operator()(
const CalibClusterPtr& x) {
93 double e_or_et = x->energy();
94 if( cutET ) e_or_et =
ptFast(e_or_et,x->the_ptr()->position(),zero);
99 struct IsLinkedByRecHit :
public ClusUnaryFunction {
100 const CalibClusterPtr the_seed;
101 const double _threshold, _majority;
102 const double _maxSatelliteDEta, _maxSatelliteDPhi;
103 double x_rechits_tot=0;
104 double x_rechits_match=0;
105 IsLinkedByRecHit(
const CalibClusterPtr&
s,
const double threshold,
106 const double majority,
const double maxDEta,
107 const double maxDPhi) :
108 the_seed(s),_threshold(threshold),_majority(majority),
109 _maxSatelliteDEta(maxDEta), _maxSatelliteDPhi(maxDPhi) {}
110 bool operator()(
const CalibClusterPtr& x) {
111 if( the_seed->energy_nocalib() < _threshold )
return false;
112 const double dEta =
std::abs(the_seed->eta()-x->eta());
115 if( _maxSatelliteDEta < dEta || _maxSatelliteDPhi < dPhi)
return false;
117 const auto& seedHitsAndFractions =
118 the_seed->the_ptr()->hitsAndFractions();
119 const auto& xHitsAndFractions =
120 x->the_ptr()->hitsAndFractions();
121 x_rechits_tot = xHitsAndFractions.size();
122 x_rechits_match = 0.0;
123 for(
const std::pair<DetId, float>& seedHit : seedHitsAndFractions ) {
124 for(
const std::pair<DetId, float>& xHit : xHitsAndFractions ) {
125 if( seedHit.first == xHit.first ) {
126 x_rechits_match += 1.0;
130 return x_rechits_match/x_rechits_tot > _majority;
134 struct IsClustered :
public ClusUnaryFunction {
135 const CalibClusterPtr the_seed;
138 double etawidthSuperCluster_ = .0 , phiwidthSuperCluster_ = .0;
139 IsClustered(
const CalibClusterPtr
s,
141 const bool dyn_dphi) :
142 the_seed(s), _type(ct), dynamic_dphi(dyn_dphi) {}
143 bool operator()(
const CalibClusterPtr& x) {
146 const bool passes_dphi =
147 ( (!dynamic_dphi && dphi < phiwidthSuperCluster_ ) ||
156 return (
std::abs(the_seed->eta()-x->eta())<etawidthSuperCluster_ &&
160 return ( passes_dphi &&
195 regr_->setTokens(regconf, cc);
203 regr_->setEventSetup(setup);
239 regr_->setEvent(iEvent);
250 for (
size_t i = 0;
i < clusters.size(); ++
i ){
251 auto cluster = clusters.ptrAt(
i);
253 <<
"Loading PFCluster i="<<cluster.key()
254 <<
" energy="<<cluster->energy()<<std::endl;
257 switch( cluster->layer() ) {
292 std::stable_partition(clusters.begin(),clusters.end(),seedable);
297 while( std::any_of(clusters.cbegin(), clusters.cend(), seedable) ) {
310 switch( seed->the_ptr()->layer() ) {
316 <<
" in the ECAL barrel!";
323 <<
" in the ECAL endcap!" << std::endl;
335 auto not_clustered = std::stable_partition(clusters.begin(),clusters.end(),
336 IsClusteredWithSeed);
340 not_clustered = std::stable_partition(not_clustered,clusters.end(),
341 MatchesSeedByRecHit);
345 edm::LogInfo(
"PFClustering") <<
"Dumping cluster detail";
347 <<
"\tPassed seed: e = " << seed->energy_nocalib()
348 <<
" eta = " << seed->eta() <<
" phi = " << seed->phi()
350 for(
auto clus = clusters.cbegin(); clus != not_clustered; ++clus ) {
352 <<
"\t\tClustered cluster: e = " << (*clus)->energy_nocalib()
353 <<
" eta = " << (*clus)->eta() <<
" phi = " << (*clus)->phi()
356 for(
auto clus = not_clustered; clus != clusters.end(); ++clus ) {
358 <<
"\tNon-Clustered cluster: e = " << (*clus)->energy_nocalib()
359 <<
" eta = " << (*clus)->eta() <<
" phi = " << (*clus)->phi()
366 clusters.erase(clusters.begin(),not_clustered);
368 std::vector<const reco::PFCluster*> bare_ptrs;
370 double posX(0), posY(0), posZ(0),
371 corrSCEnergy(0), corrPS1Energy(0), corrPS2Energy(0),
372 ePS1(0), ePS2(0), energyweight(0), energyweighttot(0);
373 std::vector<double> ps1_energies, ps2_energies;
374 int condP1(1), condP2(1);
375 for(
auto& clus : clustered ) {
377 energyweight = clus->energy_nocalib();
378 bare_ptrs.push_back(clus->the_ptr().get());
383 ps1_energies.clear();
384 ps2_energies.clear();
387 const auto clustops = std::equal_range(
EEtoPS_->begin(),
391 for(
auto i_ps = clustops.first; i_ps != clustops.second; ++i_ps) {
394 auto const& recH_Frac = psclus->recHitFractions();
396 switch( psclus->layer() ) {
398 ps1_energies.push_back(psclus->energy());
399 for (
auto const& recH : recH_Frac){
400 ESDetId strip1 = recH.recHitRef()->detId();
405 if(status_p1->getStatusCode() == 0) condP1 = 0;
410 ps2_energies.push_back(psclus->energy());
411 for (
auto const& recH : recH_Frac){
412 ESDetId strip2 = recH.recHitRef()->detId();
415 if(status_p2->getStatusCode() == 0) condP2 = 0;
423 if(condP1 == 1) ePS1 = -1.;
424 if(condP2 == 1) ePS2 = -1.;
426 ps1_energies,ps2_energies,
431 if(ePS1 == -1.) ePS1 = 0;
432 if(ePS2 == -1.) ePS2 = 0;
438 energyweight = clus->energy() - ePS1 - ePS2;
441 energyweight = clus->energy();
447 posX += energyweight * cluspos.X();
448 posY += energyweight * cluspos.Y();
449 posZ += energyweight * cluspos.Z();
451 energyweighttot += energyweight;
452 corrSCEnergy += clus->energy();
453 corrPS1Energy += ePS1;
454 corrPS2Energy += ePS2;
456 posX /= energyweighttot;
457 posY /= energyweighttot;
458 posZ /= energyweighttot;
463 new_sc.
setSeed(clustered.front()->the_ptr());
467 for(
const auto& clus : clustered ) {
470 auto& hits_and_fractions = clus->the_ptr()->hitsAndFractions();
471 for(
auto& hit_and_fraction : hits_and_fractions ) {
477 const auto clustops = std::equal_range(
EEtoPS_->begin(),
484 for(
auto i_ps = clustops.first; i_ps != clustops.second; ++i_ps) {
496 <<
"Found a PS cluster matched to more than one EE cluster!"
497 << std::endl << std::hex << psclus.
get() <<
" == "
498 << found_pscluster->get() <<
std::dec << std::endl;
515 regr_->modifyObject(new_sc);
527 switch( seed->the_ptr()->layer() ) {
T getParameter(std::string const &) const
const math::XYZPoint & position() const
cluster centroid position
CaloCluster_iterator preshowerClustersBegin() const
fist iterator over PreshowerCluster constituents
std::auto_ptr< reco::SuperClusterCollection > superClustersEB_
double etawidthSuperClusterBarrel_
PFECALSuperClusterAlgo()
constructor
const ESChannelStatus * channelStatus_
double phiwidthSuperClusterEndcap_
void addHitAndFraction(DetId id, float fraction)
edm::EDGetTokenT< edm::View< reco::PFCluster > > inputTagPFClusters_
std::unique_ptr< SCEnergyCorrectorSemiParm > regr_
bool inDynamicDPhiWindow(const float seedEta, const float seedPhi, const float ClustE, const float ClusEta, const float clusPhi)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
void setPreshowerEnergyPlane2(double preshowerEnergy2)
const self & getMap() const
T const * get() const
Returns C++ pointer to the item.
double threshPFClusterSeedBarrel_
bool applyCrackCorrections_
double pflowPhiWidth() const
const reco::BeamSpot * beamSpot_
const reco::PFCluster::EEtoPSAssociation * EEtoPS_
double Phi_mpi_pi(double x)
void setSeed(const CaloClusterPtr &r)
list of used xtals by DetId // now inherited by CaloCluster
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
void setPhiWidth(double pw)
double etawidthSuperClusterEndcap_
double threshPFClusterSeedEndcap_
double pflowEtaWidth() const
double ptFast(const double energy, const math::XYZPoint &position, const math::XYZPoint &origin)
void loadAndSortPFClusters(const edm::Event &evt)
void update(const edm::EventSetup &)
void setEtaWidth(double ew)
std::vector< CalibratedClusterPtr > CalibratedClusterPtrVector
std::shared_ptr< CalibratedPFCluster > CalibratedClusterPtr
MVATrainerComputer * calib
void buildAllSuperClusters(CalibratedClusterPtrVector &, double seedthresh)
std::shared_ptr< PFEnergyCalibration > _pfEnergyCalibration
void setTokens(const edm::ParameterSet &, edm::ConsumesCollector &&)
double dPhi(double phi1, double phi2)
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
bool doSatelliteClusterMerge_
void setCorrectedEnergy(double cenergy)
const_iterator find(uint32_t rawId) const
std::vector< std::pair< CaloClusterPtr::key_type, edm::Ptr< PFCluster > > > EEtoPSAssociation
Abs< T >::type abs(const T &t)
CalibratedClusterPtrVector _clustersEE
double threshSuperClusterEt_
double energy() const
cluster energy
double satelliteThreshold_
double fractionForMajority_
double threshPFClusterBarrel_
double phiwidthSuperClusterBarrel_
double rawEnergy() const
raw uncorrected energy (sum of energies of component BasicClusters)
edm::EDGetTokenT< reco::PFCluster::EEtoPSAssociation > inputTagPFClustersES_
T const * product() const
edm::EDGetTokenT< reco::BeamSpot > inputTagBeamSpot_
XYZPointD XYZPoint
point in space with cartesian internal representation
void addPreshowerCluster(const CaloClusterPtr &r)
add reference to constituent BasicCluster
std::auto_ptr< reco::SuperClusterCollection > superClustersEE_
T const * product() const
clustering_type _clustype
double threshPFClusterEndcap_
void buildSuperCluster(CalibratedClusterPtr &, CalibratedClusterPtrVector &)
std::vector< Item >::const_iterator const_iterator
bool GreaterByE(const T &a1, const T &a2)
void addCluster(const CaloClusterPtr &r)
add reference to constituent BasicCluster
static int position[264][3]
const Point & position() const
position
void setPreshowerEnergyPlane1(double preshowerEnergy1)
void setPFClusterCalibration(const std::shared_ptr< PFEnergyCalibration > &)
CalibratedClusterPtrVector _clustersEB
bool inMustache(const float maxEta, const float maxPhi, const float ClustE, const float ClusEta, const float ClusPhi)
CaloCluster_iterator preshowerClustersEnd() const
last iterator over PreshowerCluster constituents
void setPreshowerEnergy(double preshowerEnergy)