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;
43 const auto v = position - origin;
47 bool greaterByEt(
const CalibClusterPtr& x,
const CalibClusterPtr& y)
50 const double xpt =
ptFast(x->energy(),x->the_ptr()->position(),zero);
51 const double ypt =
ptFast(y->energy(),y->the_ptr()->position(),zero);
55 bool isSeed(
const CalibClusterPtr& x,
double threshold,
bool useETcut)
58 double e_or_et = x->energy();
59 if( useETcut ) e_or_et =
ptFast(e_or_et,x->the_ptr()->position(),zero);
63 bool isLinkedByRecHit(
const CalibClusterPtr& x,
64 const CalibClusterPtr&
seed,
const double threshold,
65 const double majority,
const double maxDEta,
68 if( seed->energy_nocalib() <
threshold ) {
72 const double dPhi =
std::abs(TVector2::Phi_mpi_pi(seed->phi() - x->phi()));
73 if( maxDEta < dEta || maxDPhi < dPhi) {
77 const auto& seedHitsAndFractions = seed->the_ptr()->hitsAndFractions();
78 const auto& xHitsAndFractions = x->the_ptr()->hitsAndFractions();
79 double x_rechits_tot = xHitsAndFractions.size();
80 double x_rechits_match = 0.0;
81 for(
const std::pair<DetId, float>& seedHit : seedHitsAndFractions ) {
82 for(
const std::pair<DetId, float>& xHit : xHitsAndFractions ) {
83 if( seedHit.first == xHit.first ) {
84 x_rechits_match += 1.0;
88 return x_rechits_match/x_rechits_tot > majority;
91 bool isClustered(
const CalibClusterPtr& x,
92 const CalibClusterPtr seed,
95 const double etawidthSuperCluster,
96 const double phiwidthSuperCluster)
98 const double dphi =
std::abs(TVector2::Phi_mpi_pi(seed->phi() - x->phi()));
99 const bool passes_dphi =
100 ( (!dyn_dphi && dphi < phiwidthSuperCluster ) ||
108 return (
std::abs(seed->eta()-x->eta()) < etawidthSuperCluster && passes_dphi);
142 regr_->setTokens(regconf, cc);
156 regr_->setEventSetup(setup);
192 regr_->setEvent(iEvent);
203 for (
size_t i = 0;
i < clusters.size(); ++
i ){
204 auto cluster = clusters.ptrAt(
i);
206 <<
"Loading PFCluster i="<<cluster.key()
207 <<
" energy="<<cluster->energy()<<std::endl;
210 if( cluster->caloID().detectors() == 0 &&
211 cluster->hitsAndFractions().empty() )
continue;
214 switch( cluster->layer() ) {
240 if (!barrelRecHitsHandle.
isValid()) {
242 <<
"If you use OOT photons, need to specify proper barrel rec hit collection";
248 if (!endcapRecHitsHandle.
isValid()) {
250 <<
"If you use OOT photons, need to specify proper endcap rec hit collection";
266 auto seedable = std::bind(isSeed, _1, seedthresh,
threshIsET_);
268 std::stable_partition(clusters.begin(),clusters.end(),seedable);
273 while( std::any_of(clusters.cbegin(), clusters.cend(), seedable) ) {
280 double etawidthSuperCluster = 0.0;
281 double phiwidthSuperCluster = 0.0;
283 switch( seed->the_ptr()->layer() )
290 <<
" in the ECAL barrel!";
299 <<
" in the ECAL endcap!" << std::endl;
305 auto isClusteredWithSeed = std::bind(isClustered, _1, seed,
_clustype,
useDynamicDPhi_, etawidthSuperCluster, phiwidthSuperCluster);
313 auto not_clustered = std::stable_partition(clusters.begin(),clusters.end(),
314 isClusteredWithSeed);
318 not_clustered = std::stable_partition(not_clustered,clusters.end(),
319 matchesSeedByRecHit);
323 edm::LogInfo(
"PFClustering") <<
"Dumping cluster detail";
325 <<
"\tPassed seed: e = " << seed->energy_nocalib()
326 <<
" eta = " << seed->eta() <<
" phi = " << seed->phi()
328 for(
auto clus = clusters.cbegin(); clus != not_clustered; ++clus ) {
330 <<
"\t\tClustered cluster: e = " << (*clus)->energy_nocalib()
331 <<
" eta = " << (*clus)->eta() <<
" phi = " << (*clus)->phi()
334 for(
auto clus = not_clustered; clus != clusters.end(); ++clus ) {
336 <<
"\tNon-Clustered cluster: e = " << (*clus)->energy_nocalib()
337 <<
" eta = " << (*clus)->eta() <<
" phi = " << (*clus)->phi()
342 if (not_clustered == clusters.begin()) {
344 clusters.erase(clusters.begin());
349 <<
"Cluster is not seedable!" << std::endl
350 <<
"\tNon-Clustered cluster: e = " << (*not_clustered)->energy_nocalib()
351 <<
" eta = " << (*not_clustered)->eta() <<
" phi = " << (*not_clustered)->phi()
359 clusters.erase(clusters.begin(),not_clustered);
361 std::vector<const reco::PFCluster*> bare_ptrs;
364 corrSCEnergy(0), corrPS1Energy(0), corrPS2Energy(0),
365 ePS1(0), ePS2(0), energyweight(0), energyweighttot(0);
366 std::vector<double> ps1_energies, ps2_energies;
367 int condP1(1), condP2(1);
368 for(
auto& clus : clustered ) {
370 energyweight = clus->energy_nocalib();
371 bare_ptrs.push_back(clus->the_ptr().get());
376 ps1_energies.clear();
377 ps2_energies.clear();
380 const auto clustops = std::equal_range(
EEtoPS_->begin(),
384 for(
auto i_ps = clustops.first; i_ps != clustops.second; ++i_ps) {
389 switch( psclus->
layer() ) {
391 ps1_energies.push_back(psclus->
energy());
392 for (
auto const& recH : recH_Frac){
393 ESDetId strip1 = recH.recHitRef()->detId();
398 if(status_p1->getStatusCode() == 0) condP1 = 0;
403 ps2_energies.push_back(psclus->
energy());
404 for (
auto const& recH : recH_Frac){
405 ESDetId strip2 = recH.recHitRef()->detId();
408 if(status_p2->getStatusCode() == 0) condP2 = 0;
416 if(condP1 == 1) ePS1 = -1.;
417 if(condP2 == 1) ePS2 = -1.;
419 ps1_energies,ps2_energies,
424 if(ePS1 == -1.) ePS1 = 0;
425 if(ePS2 == -1.) ePS2 = 0;
431 energyweight = clus->energy() - ePS1 - ePS2;
434 energyweight = clus->energy();
440 posX += energyweight * cluspos.X();
441 posY += energyweight * cluspos.Y();
442 posZ += energyweight * cluspos.Z();
444 energyweighttot += energyweight;
445 corrSCEnergy += clus->energy();
446 corrPS1Energy += ePS1;
447 corrPS2Energy += ePS2;
449 posX /= energyweighttot;
450 posY /= energyweighttot;
451 posZ /= energyweighttot;
456 new_sc.
setSeed(clustered.front()->the_ptr());
460 for(
const auto& clus : clustered ) {
463 auto& hits_and_fractions = clus->the_ptr()->hitsAndFractions();
464 for(
auto& hit_and_fraction : hits_and_fractions ) {
470 const auto clustops = std::equal_range(
EEtoPS_->begin(),
477 for(
auto i_ps = clustops.first; i_ps != clustops.second; ++i_ps) {
482 [&i_ps](
const auto&
i) {
return i.key() == i_ps->first;});
489 <<
"Found a PS cluster matched to more than one EE cluster!" 490 << std::endl << std::hex << psclus.
get() <<
" == " 491 << found_pscluster->get() <<
std::dec << std::endl;
508 regr_->modifyObject(new_sc);
520 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)