12 #include "Math/GenVector/VectorUtil.h" 32 typedef std::pair<reco::CaloClusterPtr::key_type, reco::CaloClusterPtr>
EEPSPair;
43 const double xpt =
ptFast(
x->energy(),
x->ptr()->position(),
zero);
44 const double ypt =
ptFast(
y->energy(),
y->ptr()->position(),
zero);
50 double e_or_et =
x->energy();
52 e_or_et =
ptFast(e_or_et,
x->ptr()->position(),
zero);
59 const double majority,
71 const auto& seedHitsAndFractions =
seed->ptr()->hitsAndFractions();
72 const auto& xHitsAndFractions =
x->ptr()->hitsAndFractions();
73 double x_rechits_tot = xHitsAndFractions.size();
74 double x_rechits_match = 0.0;
75 for (
const std::pair<DetId, float>& seedHit : seedHitsAndFractions) {
76 for (
const std::pair<DetId, float>& xHit : xHitsAndFractions) {
77 if (seedHit.first == xHit.first) {
78 x_rechits_match += 1.0;
82 return x_rechits_match / x_rechits_tot > majority;
91 const double etawidthSuperCluster,
92 const double phiwidthSuperCluster) {
93 const double dphi =
std::abs(TVector2::Phi_mpi_pi(
seed->phi() -
x->phi()));
94 const bool passes_dphi =
95 ((!dyn_dphi && dphi < phiwidthSuperCluster) ||
97 dynamic_dphi_params,
seed->eta(),
seed->phi(),
x->energy_nocalib(),
x->eta(),
x->phi())));
100 return (
std::abs(
seed->eta() -
x->eta()) < etawidthSuperCluster && passes_dphi);
104 mustache_params,
seed->eta(),
seed->phi(),
x->energy_nocalib(),
x->eta(),
x->phi()));
112 : beamSpot_(nullptr), SCProducerCache_(
cache) {}
138 regr_ = std::make_unique<SCEnergyCorrectorSemiParm>();
139 regr_->setTokens(regconf, cc);
216 LogDebug(
"PFClustering") <<
"Loading PFCluster i=" << cluster.key() <<
" energy=" << cluster->energy();
219 if (cluster->caloID().detectors() == 0 && cluster->hitsAndFractions().empty())
223 switch (cluster->layer()) {
248 if (!barrelRecHitsHandle.
isValid()) {
250 <<
"If you use OOT photons or DeepSC, need to specify proper barrel rec hit collection";
256 if (!endcapRecHitsHandle.
isValid()) {
258 <<
"If you use OOT photons or DeepSC, need to specify proper endcap rec hit collection";
280 auto seedable = std::bind(isSeed, _1, seedthresh,
threshIsET_);
295 auto seedable = std::bind(isSeed, _1, seedthresh,
threshIsET_);
298 auto last_seed = std::stable_partition(
clusters.begin(),
clusters.end(), seedable);
309 ecalClusterGraph_.initWindows();
311 ecalClusterGraph_.fillVariables();
313 ecalClusterGraph_.evaluateScores();
315 ecalClusterGraph_.setThresholds();
316 ecalClusterGraph_.selectClusters();
319 for (
auto& [
seed, clustered] : windows) {
331 double etawidthSuperCluster = 0.0;
332 double phiwidthSuperCluster = 0.0;
334 switch (
seed->ptr()->layer()) {
353 auto isClusteredWithSeed = std::bind(isClustered,
360 etawidthSuperCluster,
361 phiwidthSuperCluster);
370 auto not_clustered = std::stable_partition(
clusters.begin(),
clusters.end(), isClusteredWithSeed);
374 not_clustered = std::stable_partition(not_clustered,
clusters.end(), matchesSeedByRecHit);
378 edm::LogInfo(
"PFClustering") <<
"Dumping cluster detail";
380 <<
" phi = " <<
seed->phi() << std::endl;
381 for (
auto clus =
clusters.cbegin(); clus != not_clustered; ++clus) {
382 edm::LogVerbatim(
"PFClustering") <<
"\t\tClustered cluster: e = " << (*clus)->energy_nocalib()
383 <<
" eta = " << (*clus)->eta() <<
" phi = " << (*clus)->phi() << std::endl;
385 for (
auto clus = not_clustered; clus !=
clusters.end(); ++clus) {
386 edm::LogVerbatim(
"PFClustering") <<
"\tNon-Clustered cluster: e = " << (*clus)->energy_nocalib()
387 <<
" eta = " << (*clus)->eta() <<
" phi = " << (*clus)->phi() << std::endl;
391 if (not_clustered ==
clusters.begin()) {
397 <<
"Cluster is not seedable!" << std::endl
398 <<
"\tNon-Clustered cluster: e = " << (*not_clustered)->energy_nocalib()
399 <<
" eta = " << (*not_clustered)->eta() <<
" phi = " << (*not_clustered)->phi() << std::endl;
406 clustered = clustered_tmp;
417 std::vector<const reco::PFCluster*> bare_ptrs;
419 double posX(0),
posY(0), posZ(0), corrSCEnergy(0), corrPS1Energy(0), corrPS2Energy(0), energyweight(0),
421 for (
const auto& clus : clustered) {
424 energyweight = clus->energy_nocalib();
425 bare_ptrs.push_back(clus->ptr().get());
430 std::vector<reco::PFCluster const*> psClusterPointers;
431 for (
auto i_ps = clustops.first; i_ps != clustops.second; ++i_ps) {
432 psClusterPointers.push_back(i_ps->second.get());
436 ePS1 = calibratedEnergies.ps1Energy;
437 ePS2 = calibratedEnergies.ps2Energy;
449 energyweight = clus->energy() - ePS1 - ePS2;
452 energyweight = clus->energy();
458 posX += energyweight * cluspos.X();
459 posY += energyweight * cluspos.Y();
460 posZ += energyweight * cluspos.Z();
462 energyweighttot += energyweight;
463 corrSCEnergy += clus->energy();
464 corrPS1Energy += ePS1;
465 corrPS2Energy += ePS2;
467 posX /= energyweighttot;
468 posY /= energyweighttot;
469 posZ /= energyweighttot;
474 new_sc.
setSeed(clustered.front()->ptr());
478 for (
const auto& clus : clustered) {
481 auto& hits_and_fractions = clus->ptr()->hitsAndFractions();
482 for (
auto& hit_and_fraction : hits_and_fractions) {
491 for (
auto i_ps = clustops.first; i_ps != clustops.second; ++i_ps) {
495 auto found_pscluster =
504 <<
"Found a PS cluster matched to more than one EE cluster!" << std::endl
505 << std::hex << psclus.
get() <<
" == " << found_pscluster->get() <<
std::dec << std::endl;
522 regr_->modifyObject(new_sc);
533 switch (
seed->ptr()->layer()) {
const math::XYZPoint & position() const
cluster centroid position
std::vector< CalibratedClusterPtr > CalibratedClusterPtrVector
Log< level::Info, true > LogVerbatim
double etawidthSuperClusterBarrel_
const ESChannelStatus * channelStatus_
T getParameter(std::string const &) const
double phiwidthSuperClusterEndcap_
void addHitAndFraction(DetId id, float fraction)
edm::EDGetTokenT< edm::View< reco::PFCluster > > inputTagPFClusters_
const Point & position() const
position
std::unique_ptr< SCEnergyCorrectorSemiParm > regr_
double pflowPhiWidth() const
std::unique_ptr< reco::SuperClusterCollection > superClustersEB_
void setPreshowerEnergyPlane2(double preshowerEnergy2)
edm::EDGetTokenT< EcalRecHitCollection > inputTagBarrelRecHits_
double threshPFClusterSeedBarrel_
double rawEnergy() const
raw uncorrected energy (sum of energies of component BasicClusters)
T const * product() const
bool applyCrackCorrections_
std::vector< EcalRecHit >::const_iterator const_iterator
double pflowEtaWidth() const
const reco::BeamSpot * beamSpot_
const EcalMustacheSCParameters * mustacheSCParams_
const reco::PFCluster::EEtoPSAssociation * EEtoPS_
CaloCluster_iterator preshowerClustersBegin() const
fist iterator over PreshowerCluster constituents
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
edm::Ptr< CaloCluster > CaloClusterPtr
const reco::SCProducerCache * SCProducerCache_
void buildSuperClusterMustacheOrBox(CalibratedClusterPtr &, CalibratedClusterPtrVector &)
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_
edm::ESGetToken< ESEEIntercalibConstants, ESEEIntercalibConstantsRcd > esEEInterCalibToken_
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
void buildAllSuperClustersDeepSC(CalibratedClusterPtrVector &, double seedthresh)
void loadAndSortPFClusters(const edm::Event &evt)
void update(const edm::EventSetup &)
void setEtaWidth(double ew)
T const * product() const
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
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeometryToken_
double threshSuperClusterEt_
edm::ESGetToken< ESChannelStatus, ESChannelStatusRcd > esChannelStatusToken_
double satelliteThreshold_
CaloCluster_iterator preshowerClustersEnd() const
last iterator over PreshowerCluster constituents
double fractionForMajority_
edm::ESGetToken< EcalSCDynamicDPhiParameters, EcalSCDynamicDPhiParametersRcd > ecalSCDynamicDPhiParametersToken_
double threshPFClusterBarrel_
T const * get() const
Returns C++ pointer to the item.
void buildAllSuperClustersMustacheOrBox(CalibratedClusterPtrVector &, double seedthresh)
double phiwidthSuperClusterBarrel_
const CaloSubdetectorGeometry * eeGeom_
double energy() const
cluster energy
Log< level::Info, false > LogInfo
const CaloSubdetectorGeometry * esGeom_
edm::ESGetToken< CaloTopology, CaloTopologyRecord > caloTopologyToken_
edm::EDGetTokenT< reco::PFCluster::EEtoPSAssociation > inputTagPFClustersES_
std::vector< std::pair< CalibratedClusterPtr, CalibratedClusterPtrVector > > EcalGraphOutput
std::vector< std::pair< CaloClusterPtr::key_type, edm::Ptr< PFCluster > > > EEtoPSAssociation
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
bool sortByKey(const EEPSPair &a, const EEPSPair &b)
edm::ESGetToken< EcalMustacheSCParameters, EcalMustacheSCParametersRcd > ecalMustacheSCParametersToken_
clustering_type _clustype
double threshPFClusterEndcap_
const CaloTopology * topology_
const CaloGeometry * geometry_
void finalizeSuperCluster(CalibratedClusterPtr &seed, CalibratedClusterPtrVector &clustered, bool isEE)
PFECALSuperClusterAlgo(const reco::SCProducerCache *cache)
constructor
void addCluster(const CaloClusterPtr &r)
add reference to constituent BasicCluster
const CaloClusterPtr & seed() const
seed 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 EcalRecHitCollection * barrelRecHits_
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
void setPreshowerEnergyPlane1(double preshowerEnergy1)
std::shared_ptr< CalibratedPFCluster > CalibratedClusterPtr
\ Algorithm for box particle flow super clustering in the ECAL
void setPFClusterCalibration(const std::shared_ptr< PFEnergyCalibration > &)
CalibratedClusterPtrVector _clustersEB
const CaloSubdetectorGeometry * ebGeom_
const EcalRecHitCollection * endcapRecHits_
void setPreshowerEnergy(double preshowerEnergy)