9 #include "Math/GenVector/VectorUtil.h"
23 using namespace std::placeholders;
31 typedef std::pair<reco::CaloClusterPtr::key_type, reco::CaloClusterPtr>
EEPSPair;
33 bool sortByKey(
const EEPSPair&
a,
const EEPSPair&
b) {
return a.first < b.first; }
36 const auto v = position - origin;
40 bool greaterByEt(
const CalibClusterPtr& x,
const CalibClusterPtr& y) {
42 const double xpt =
ptFast(x->energy(), x->the_ptr()->position(),
zero);
43 const double ypt =
ptFast(y->energy(), y->the_ptr()->position(),
zero);
47 bool isSeed(
const CalibClusterPtr& x,
double threshold,
bool useETcut) {
49 double e_or_et = x->energy();
51 e_or_et =
ptFast(e_or_et, x->the_ptr()->position(),
zero);
55 bool isLinkedByRecHit(
const CalibClusterPtr& x,
56 const CalibClusterPtr&
seed,
57 const double threshold,
58 const double majority,
60 const double maxDPhi) {
64 const double dEta =
std::abs(seed->eta() - x->eta());
65 const double dPhi =
std::abs(TVector2::Phi_mpi_pi(seed->phi() - x->phi()));
66 if (maxDEta < dEta || maxDPhi < dPhi) {
70 const auto& seedHitsAndFractions = seed->the_ptr()->hitsAndFractions();
71 const auto& xHitsAndFractions = x->the_ptr()->hitsAndFractions();
72 double x_rechits_tot = xHitsAndFractions.size();
73 double x_rechits_match = 0.0;
74 for (
const std::pair<DetId, float>& seedHit : seedHitsAndFractions) {
75 for (
const std::pair<DetId, float>& xHit : xHitsAndFractions) {
76 if (seedHit.first == xHit.first) {
77 x_rechits_match += 1.0;
81 return x_rechits_match / x_rechits_tot > majority;
84 bool isClustered(
const CalibClusterPtr& x,
85 const CalibClusterPtr seed,
90 const double etawidthSuperCluster,
91 const double phiwidthSuperCluster) {
92 const double dphi =
std::abs(TVector2::Phi_mpi_pi(seed->phi() - x->phi()));
93 const bool passes_dphi =
94 ((!dyn_dphi && dphi < phiwidthSuperCluster) ||
96 dynamic_dphi_params, seed->eta(), seed->phi(), x->energy_nocalib(), x->eta(), x->phi())));
99 return (
std::abs(seed->eta() - x->eta()) < etawidthSuperCluster && passes_dphi);
103 mustache_params, seed->eta(), seed->phi(), x->energy_nocalib(), x->eta(), x->phi()));
136 regr_ = std::make_unique<SCEnergyCorrectorSemiParm>();
137 regr_->setTokens(regconf, cc);
148 regr_->setEventSetup(setup);
186 regr_->setEvent(iEvent);
197 for (
size_t i = 0;
i < clusters.size(); ++
i) {
198 auto cluster = clusters.ptrAt(
i);
199 LogDebug(
"PFClustering") <<
"Loading PFCluster i=" << cluster.key() <<
" energy=" << cluster->energy() << std::endl;
202 if (cluster->caloID().detectors() == 0 && cluster->hitsAndFractions().empty())
206 switch (cluster->layer()) {
231 if (!barrelRecHitsHandle.
isValid()) {
233 <<
"If you use OOT photons, need to specify proper barrel rec hit collection";
239 if (!endcapRecHitsHandle.
isValid()) {
241 <<
"If you use OOT photons, need to specify proper endcap rec hit collection";
255 auto seedable = std::bind(isSeed, _1, seedthresh,
threshIsET_);
257 std::stable_partition(clusters.begin(), clusters.end(), seedable);
262 while (std::any_of(clusters.cbegin(), clusters.cend(), seedable)) {
268 double etawidthSuperCluster = 0.0;
269 double phiwidthSuperCluster = 0.0;
271 switch (seed->the_ptr()->layer()) {
289 auto isClusteredWithSeed = std::bind(isClustered,
296 etawidthSuperCluster,
297 phiwidthSuperCluster);
305 auto not_clustered = std::stable_partition(clusters.begin(), clusters.end(), isClusteredWithSeed);
309 not_clustered = std::stable_partition(not_clustered, clusters.end(), matchesSeedByRecHit);
313 edm::LogInfo(
"PFClustering") <<
"Dumping cluster detail";
314 edm::LogVerbatim(
"PFClustering") <<
"\tPassed seed: e = " << seed->energy_nocalib() <<
" eta = " << seed->eta()
315 <<
" phi = " << seed->phi() << std::endl;
316 for (
auto clus = clusters.cbegin(); clus != not_clustered; ++clus) {
317 edm::LogVerbatim(
"PFClustering") <<
"\t\tClustered cluster: e = " << (*clus)->energy_nocalib()
318 <<
" eta = " << (*clus)->eta() <<
" phi = " << (*clus)->phi() << std::endl;
320 for (
auto clus = not_clustered; clus != clusters.end(); ++clus) {
321 edm::LogVerbatim(
"PFClustering") <<
"\tNon-Clustered cluster: e = " << (*clus)->energy_nocalib()
322 <<
" eta = " << (*clus)->eta() <<
" phi = " << (*clus)->phi() << std::endl;
326 if (not_clustered == clusters.begin()) {
328 clusters.erase(clusters.begin());
332 <<
"Cluster is not seedable!" << std::endl
333 <<
"\tNon-Clustered cluster: e = " << (*not_clustered)->energy_nocalib()
334 <<
" eta = " << (*not_clustered)->eta() <<
" phi = " << (*not_clustered)->phi() << std::endl;
341 clusters.erase(clusters.begin(), not_clustered);
343 std::vector<const reco::PFCluster*> bare_ptrs;
345 double posX(0), posY(0), posZ(0), corrSCEnergy(0), corrPS1Energy(0), corrPS2Energy(0), energyweight(0),
347 for (
auto& clus : clustered) {
350 energyweight = clus->energy_nocalib();
351 bare_ptrs.push_back(clus->the_ptr().get());
356 std::vector<reco::PFCluster const*> psClusterPointers;
357 for (
auto i_ps = clustops.first; i_ps != clustops.second; ++i_ps) {
358 psClusterPointers.push_back(i_ps->second.get());
362 ePS1 = calibratedEnergies.ps1Energy;
363 ePS2 = calibratedEnergies.ps2Energy;
375 energyweight = clus->energy() - ePS1 - ePS2;
378 energyweight = clus->energy();
384 posX += energyweight * cluspos.X();
385 posY += energyweight * cluspos.Y();
386 posZ += energyweight * cluspos.Z();
388 energyweighttot += energyweight;
389 corrSCEnergy += clus->energy();
390 corrPS1Energy += ePS1;
391 corrPS2Energy += ePS2;
393 posX /= energyweighttot;
394 posY /= energyweighttot;
395 posZ /= energyweighttot;
400 new_sc.
setSeed(clustered.front()->the_ptr());
404 for (
const auto& clus : clustered) {
407 auto& hits_and_fractions = clus->the_ptr()->hitsAndFractions();
408 for (
auto& hit_and_fraction : hits_and_fractions) {
417 for (
auto i_ps = clustops.first; i_ps != clustops.second; ++i_ps) {
422 [&i_ps](
const auto&
i) {
return i.key() == i_ps->first; });
429 <<
"Found a PS cluster matched to more than one EE cluster!" << std::endl
430 << std::hex << psclus.
get() <<
" == " << found_pscluster->get() <<
std::dec << std::endl;
447 regr_->modifyObject(new_sc);
458 switch (seed->the_ptr()->layer()) {
Log< level::Info, true > LogVerbatim
const math::XYZPoint & position() const
cluster centroid position
CaloCluster_iterator preshowerClustersBegin() const
fist iterator over PreshowerCluster constituents
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 getByToken(EDGetToken token, Handle< PROD > &result) const
std::unique_ptr< reco::SuperClusterCollection > superClustersEB_
void setPreshowerEnergyPlane2(double preshowerEnergy2)
edm::EDGetTokenT< EcalRecHitCollection > inputTagBarrelRecHits_
T const * get() const
Returns C++ pointer to the item.
double threshPFClusterSeedBarrel_
bool applyCrackCorrections_
double pflowPhiWidth() const
std::vector< EcalRecHit >::const_iterator const_iterator
const reco::BeamSpot * beamSpot_
const EcalMustacheSCParameters * mustacheSCParams_
const reco::PFCluster::EEtoPSAssociation * EEtoPS_
bool inMustache(const EcalMustacheSCParameters *params, const float maxEta, const float maxPhi, const float ClustE, const float ClusEta, const float ClusPhi)
void setSeed(const CaloClusterPtr &r)
list of used xtals by DetId // now inherited by CaloCluster
void setPhiWidth(double pw)
double etawidthSuperClusterEndcap_
double threshPFClusterSeedEndcap_
edm::ESGetToken< ESEEIntercalibConstants, ESEEIntercalibConstantsRcd > esEEInterCalibToken_
double pflowEtaWidth() const
double ptFast(const double energy, const math::XYZPoint &position, const math::XYZPoint &origin)
std::unique_ptr< reco::SuperClusterCollection > superClustersEE_
const EcalSCDynamicDPhiParameters * scDynamicDPhiParams_
edm::EDGetTokenT< EcalRecHitCollection > inputTagEndcapRecHits_
ESChannelStatusMap ESChannelStatus
bool getData(T &iHolder) const
void loadAndSortPFClusters(const edm::Event &evt)
void update(const edm::EventSetup &)
void setEtaWidth(double ew)
std::vector< CalibratedClusterPtr > CalibratedClusterPtrVector
std::shared_ptr< CalibratedPFCluster > CalibratedClusterPtr
void buildAllSuperClusters(CalibratedClusterPtrVector &, double seedthresh)
std::shared_ptr< PFEnergyCalibration > _pfEnergyCalibration
void setTokens(const edm::ParameterSet &, edm::ConsumesCollector &&)
bool doSatelliteClusterMerge_
void setCorrectedEnergy(double cenergy)
Abs< T >::type abs(const T &t)
CalibratedClusterPtrVector _clustersEE
double threshSuperClusterEt_
edm::ESGetToken< ESChannelStatus, ESChannelStatusRcd > esChannelStatusToken_
double energy() const
cluster energy
double satelliteThreshold_
double fractionForMajority_
edm::ESGetToken< EcalSCDynamicDPhiParameters, EcalSCDynamicDPhiParametersRcd > ecalSCDynamicDPhiParametersToken_
double threshPFClusterBarrel_
double phiwidthSuperClusterBarrel_
Log< level::Info, false > LogInfo
double rawEnergy() const
raw uncorrected energy (sum of energies of component BasicClusters)
edm::EDGetTokenT< reco::PFCluster::EEtoPSAssociation > inputTagPFClustersES_
std::vector< std::pair< CaloClusterPtr::key_type, edm::Ptr< PFCluster > > > EEtoPSAssociation
T const * product() const
edm::EDGetTokenT< reco::BeamSpot > inputTagBeamSpot_
XYZPointD XYZPoint
point in space with cartesian internal representation
reco::PFCluster::EEtoPSAssociation::value_type EEPSPair
void addPreshowerCluster(const CaloClusterPtr &r)
add reference to constituent BasicCluster
T const * product() const
T getParameter(std::string const &) const
bool sortByKey(const EEPSPair &a, const EEPSPair &b)
edm::ESGetToken< EcalMustacheSCParameters, EcalMustacheSCParametersRcd > ecalMustacheSCParametersToken_
clustering_type _clustype
double threshPFClusterEndcap_
void buildSuperCluster(CalibratedClusterPtr &, CalibratedClusterPtrVector &)
void addCluster(const CaloClusterPtr &r)
add reference to constituent BasicCluster
iterator find(key_type k)
bool inDynamicDPhiWindow(const EcalSCDynamicDPhiParameters *params, const float seedEta, const float seedPhi, const float ClustE, const float ClusEta, const float clusPhi)
static int position[264][3]
void updateSCParams(const edm::EventSetup &)
const Point & position() const
position
const CaloClusterPtr & seed() const
seed BasicCluster
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
const EcalRecHitCollection * barrelRecHits_
void setPreshowerEnergyPlane1(double preshowerEnergy1)
void setPFClusterCalibration(const std::shared_ptr< PFEnergyCalibration > &)
CalibratedClusterPtrVector _clustersEB
const EcalRecHitCollection * endcapRecHits_
CaloCluster_iterator preshowerClustersEnd() const
last iterator over PreshowerCluster constituents
void setPreshowerEnergy(double preshowerEnergy)