9 #include "Math/GenVector/VectorUtil.h"
23 using namespace std::placeholders;
31 typedef std::pair<reco::CaloClusterPtr::key_type, reco::CaloClusterPtr>
EEPSPair;
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,
58 const double majority,
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>();
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_);
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";
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()) {
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;
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()) {