14 #include "Math/GenVector/VectorUtil.h" 34 typedef std::pair<reco::CaloClusterPtr::key_type,reco::CaloClusterPtr>
EEPSPair;
36 bool sortByKey(
const EEPSPair&
a,
const EEPSPair&
b) {
37 return a.first < b.first;
40 inline double getPFClusterEnergy(
const PFClusterPtr&
p) {
44 inline double ptFast(
const double energy,
47 const auto v = position - origin;
51 bool greaterByEt(
const CalibClusterPtr& x,
const CalibClusterPtr& y)
54 const double xpt =
ptFast(x->energy(),x->the_ptr()->position(),zero);
55 const double ypt =
ptFast(y->energy(),y->the_ptr()->position(),zero);
59 bool isSeed(
const CalibClusterPtr& x,
double threshold,
bool useETcut)
62 double e_or_et = x->energy();
63 if( useETcut ) e_or_et =
ptFast(e_or_et,x->the_ptr()->position(),zero);
67 bool isLinkedByRecHit(
const CalibClusterPtr& x,
68 const CalibClusterPtr&
seed,
const double threshold,
69 const double majority,
const double maxDEta,
72 if( seed->energy_nocalib() <
threshold ) {
76 const double dPhi =
std::abs(TVector2::Phi_mpi_pi(seed->phi() - x->phi()));
77 if( maxDEta < dEta || maxDPhi < dPhi) {
81 const auto& seedHitsAndFractions = seed->the_ptr()->hitsAndFractions();
82 const auto& xHitsAndFractions = x->the_ptr()->hitsAndFractions();
83 double x_rechits_tot = xHitsAndFractions.size();
84 double x_rechits_match = 0.0;
85 for(
const std::pair<DetId, float>& seedHit : seedHitsAndFractions ) {
86 for(
const std::pair<DetId, float>& xHit : xHitsAndFractions ) {
87 if( seedHit.first == xHit.first ) {
88 x_rechits_match += 1.0;
92 return x_rechits_match/x_rechits_tot > majority;
95 bool isClustered(
const CalibClusterPtr& x,
96 const CalibClusterPtr seed,
99 const double etawidthSuperCluster,
100 const double phiwidthSuperCluster)
102 const double dphi =
std::abs(TVector2::Phi_mpi_pi(seed->phi() - x->phi()));
103 const bool passes_dphi =
104 ( (!dyn_dphi && dphi < phiwidthSuperCluster ) ||
112 return (
std::abs(seed->eta()-x->eta()) < etawidthSuperCluster && passes_dphi);
146 regr_->setTokens(regconf, cc);
160 regr_->setEventSetup(setup);
196 regr_->setEvent(iEvent);
207 for (
size_t i = 0;
i < clusters.size(); ++
i ){
208 auto cluster = clusters.ptrAt(
i);
210 <<
"Loading PFCluster i="<<cluster.key()
211 <<
" energy="<<cluster->energy()<<std::endl;
214 if( cluster->caloID().detectors() == 0 &&
215 cluster->hitsAndFractions().empty() )
continue;
218 switch( cluster->layer() ) {
244 if (!barrelRecHitsHandle.
isValid()) {
246 <<
"If you use OOT photons, need to specify proper barrel rec hit collection";
252 if (!endcapRecHitsHandle.
isValid()) {
254 <<
"If you use OOT photons, need to specify proper endcap rec hit collection";
270 auto seedable = std::bind(isSeed, _1, seedthresh,
threshIsET_);
272 std::stable_partition(clusters.begin(),clusters.end(),seedable);
277 while( std::any_of(clusters.cbegin(), clusters.cend(), seedable) ) {
284 double etawidthSuperCluster = 0.0;
285 double phiwidthSuperCluster = 0.0;
287 switch( seed->the_ptr()->layer() )
294 <<
" in the ECAL barrel!";
303 <<
" in the ECAL endcap!" << std::endl;
309 auto isClusteredWithSeed = std::bind(isClustered, _1, seed,
_clustype,
useDynamicDPhi_, etawidthSuperCluster, phiwidthSuperCluster);
317 auto not_clustered = std::stable_partition(clusters.begin(),clusters.end(),
318 isClusteredWithSeed);
322 not_clustered = std::stable_partition(not_clustered,clusters.end(),
323 matchesSeedByRecHit);
327 edm::LogInfo(
"PFClustering") <<
"Dumping cluster detail";
329 <<
"\tPassed seed: e = " << seed->energy_nocalib()
330 <<
" eta = " << seed->eta() <<
" phi = " << seed->phi()
332 for(
auto clus = clusters.cbegin(); clus != not_clustered; ++clus ) {
334 <<
"\t\tClustered cluster: e = " << (*clus)->energy_nocalib()
335 <<
" eta = " << (*clus)->eta() <<
" phi = " << (*clus)->phi()
338 for(
auto clus = not_clustered; clus != clusters.end(); ++clus ) {
340 <<
"\tNon-Clustered cluster: e = " << (*clus)->energy_nocalib()
341 <<
" eta = " << (*clus)->eta() <<
" phi = " << (*clus)->phi()
346 if (not_clustered == clusters.begin()) {
348 clusters.erase(clusters.begin());
353 <<
"Cluster is not seedable!" << std::endl
354 <<
"\tNon-Clustered cluster: e = " << (*not_clustered)->energy_nocalib()
355 <<
" eta = " << (*not_clustered)->eta() <<
" phi = " << (*not_clustered)->phi()
363 clusters.erase(clusters.begin(),not_clustered);
365 std::vector<const reco::PFCluster*> bare_ptrs;
368 corrSCEnergy(0), corrPS1Energy(0), corrPS2Energy(0),
369 ePS1(0), ePS2(0), energyweight(0), energyweighttot(0);
370 std::vector<double> ps1_energies, ps2_energies;
371 int condP1(1), condP2(1);
372 for(
auto& clus : clustered ) {
374 energyweight = clus->energy_nocalib();
375 bare_ptrs.push_back(clus->the_ptr().get());
380 ps1_energies.clear();
381 ps2_energies.clear();
384 const auto clustops = std::equal_range(
EEtoPS_->begin(),
388 for(
auto i_ps = clustops.first; i_ps != clustops.second; ++i_ps) {
393 switch( psclus->
layer() ) {
395 ps1_energies.push_back(psclus->
energy());
396 for (
auto const& recH : recH_Frac){
397 ESDetId strip1 = recH.recHitRef()->detId();
402 if(status_p1->getStatusCode() == 0) condP1 = 0;
407 ps2_energies.push_back(psclus->
energy());
408 for (
auto const& recH : recH_Frac){
409 ESDetId strip2 = recH.recHitRef()->detId();
412 if(status_p2->getStatusCode() == 0) condP2 = 0;
420 if(condP1 == 1) ePS1 = -1.;
421 if(condP2 == 1) ePS2 = -1.;
423 ps1_energies,ps2_energies,
428 if(ePS1 == -1.) ePS1 = 0;
429 if(ePS2 == -1.) ePS2 = 0;
435 energyweight = clus->energy() - ePS1 - ePS2;
438 energyweight = clus->energy();
444 posX += energyweight * cluspos.X();
445 posY += energyweight * cluspos.Y();
446 posZ += energyweight * cluspos.Z();
448 energyweighttot += energyweight;
449 corrSCEnergy += clus->energy();
450 corrPS1Energy += ePS1;
451 corrPS2Energy += ePS2;
453 posX /= energyweighttot;
454 posY /= energyweighttot;
455 posZ /= energyweighttot;
460 new_sc.
setSeed(clustered.front()->the_ptr());
464 for(
const auto& clus : clustered ) {
467 auto& hits_and_fractions = clus->the_ptr()->hitsAndFractions();
468 for(
auto& hit_and_fraction : hits_and_fractions ) {
474 const auto clustops = std::equal_range(
EEtoPS_->begin(),
481 for(
auto i_ps = clustops.first; i_ps != clustops.second; ++i_ps) {
486 [&i_ps](
const auto&
i) {
return i.key() == i_ps->first;});
493 <<
"Found a PS cluster matched to more than one EE cluster!" 494 << std::endl << std::hex << psclus.
get() <<
" == " 495 << found_pscluster->get() <<
std::dec << std::endl;
512 regr_->modifyObject(new_sc);
524 switch( seed->the_ptr()->layer() ) {
PFLayer::Layer layer() const
cluster layer, see PFLayer.h in this directory
T getParameter(std::string const &) const
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 inDynamicDPhiWindow(const float seedEta, const float seedPhi, const float ClustE, const float ClusEta, const float clusPhi)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
std::unique_ptr< reco::SuperClusterCollection > superClustersEB_
void setPreshowerEnergyPlane2(double preshowerEnergy2)
edm::EDGetTokenT< EcalRecHitCollection > inputTagBarrelRecHits_
const self & getMap() const
T const * get() const
Returns C++ pointer to the item.
double threshPFClusterSeedBarrel_
bool applyCrackCorrections_
double pflowPhiWidth() const
std::vector< EcalRecHit >::const_iterator const_iterator
def setup(process, global_tag, zero_tesla=False)
const reco::BeamSpot * beamSpot_
const reco::PFCluster::EEtoPSAssociation * EEtoPS_
void setSeed(const CaloClusterPtr &r)
list of used xtals by DetId // now inherited by CaloCluster
void setPhiWidth(double pw)
double etawidthSuperClusterEndcap_
double threshPFClusterSeedEndcap_
double pflowEtaWidth() const
double ptFast(const double energy, const math::XYZPoint &position, const math::XYZPoint &origin)
std::unique_ptr< reco::SuperClusterCollection > superClustersEE_
edm::EDGetTokenT< EcalRecHitCollection > inputTagEndcapRecHits_
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 &&)
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 energy() const
cluster energy
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
reco::PFCluster::EEtoPSAssociation::value_type EEPSPair
void addPreshowerCluster(const CaloClusterPtr &r)
add reference to constituent BasicCluster
bool sortByKey(const EEPSPair &a, const EEPSPair &b)
clustering_type _clustype
double threshPFClusterEndcap_
void buildSuperCluster(CalibratedClusterPtr &, CalibratedClusterPtrVector &)
std::vector< Item >::const_iterator const_iterator
void addCluster(const CaloClusterPtr &r)
add reference to constituent BasicCluster
iterator find(key_type k)
static int position[264][3]
const std::vector< reco::PFRecHitFraction > & recHitFractions() const
vector of rechit fractions
const Point & position() const
position
const CaloClusterPtr & seed() const
seed BasicCluster
const EcalRecHitCollection * barrelRecHits_
T const * product() const
void setPreshowerEnergyPlane1(double preshowerEnergy1)
void setPFClusterCalibration(const std::shared_ptr< PFEnergyCalibration > &)
CalibratedClusterPtrVector _clustersEB
const EcalRecHitCollection * endcapRecHits_
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)