9 #include "Math/GenVector/VectorUtil.h" 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>();
137 regr_->setTokens(regconf, cc);
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) {
421 auto found_pscluster =
430 <<
"Found a PS cluster matched to more than one EE cluster!" << std::endl
431 << std::hex << psclus.
get() <<
" == " << found_pscluster->get() <<
std::dec << std::endl;
448 regr_->modifyObject(new_sc);
459 switch (
seed->the_ptr()->layer()) {
const math::XYZPoint & position() const
cluster centroid position
Log< level::Info, true > LogVerbatim
double etawidthSuperClusterBarrel_
PFECALSuperClusterAlgo()
constructor
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
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 loadAndSortPFClusters(const edm::Event &evt)
void update(const edm::EventSetup &)
void setEtaWidth(double ew)
std::vector< CalibratedClusterPtr > CalibratedClusterPtrVector
std::shared_ptr< CalibratedPFCluster > CalibratedClusterPtr
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
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.
double phiwidthSuperClusterBarrel_
double energy() const
cluster energy
Log< level::Info, false > LogInfo
edm::EDGetTokenT< reco::PFCluster::EEtoPSAssociation > inputTagPFClustersES_
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_
void buildSuperCluster(CalibratedClusterPtr &, CalibratedClusterPtrVector &)
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_
void setPreshowerEnergyPlane1(double preshowerEnergy1)
void setPFClusterCalibration(const std::shared_ptr< PFEnergyCalibration > &)
CalibratedClusterPtrVector _clustersEB
const EcalRecHitCollection * endcapRecHits_
void setPreshowerEnergy(double preshowerEnergy)