13 #include "Math/GenVector/VectorUtil.h" 35 typedef std::pair<reco::CaloClusterPtr::key_type,reco::CaloClusterPtr> EEPSPair;
36 typedef std::binary_function<
const CalibClusterPtr&,
37 const CalibClusterPtr&,
38 bool> ClusBinaryFunction;
40 typedef std::unary_function<
const CalibClusterPtr&,
41 bool> ClusUnaryFunction;
43 bool sortByKey(
const EEPSPair&
a,
const EEPSPair&
b) {
44 return a.first < b.first;
47 inline double getPFClusterEnergy(
const PFClusterPtr&
p) {
51 inline double ptFast(
const double energy,
54 const auto v = position - origin;
58 struct SumPSEnergy :
public std::binary_function<double,
63 double operator()(
double a,
64 const PFClusterPtr&
b) {
65 return a + (_thelayer == b->layer())*b->energy();
69 struct GreaterByE :
public ClusBinaryFunction {
70 bool operator()(
const CalibClusterPtr& x,
71 const CalibClusterPtr& y) {
72 return x->energy() > y->energy() ;
76 struct GreaterByEt :
public ClusBinaryFunction {
77 bool operator()(
const CalibClusterPtr& x,
78 const CalibClusterPtr& y) {
80 const double xpt =
ptFast(x->energy(),x->the_ptr()->position(),zero);
81 const double ypt =
ptFast(y->energy(),y->the_ptr()->position(),zero);
86 struct IsASeed :
public ClusUnaryFunction {
89 IsASeed(
double thresh,
bool useETcut =
false) :
90 threshold(thresh), cutET(useETcut) {}
91 bool operator()(
const CalibClusterPtr& x) {
93 double e_or_et = x->energy();
94 if( cutET ) e_or_et =
ptFast(e_or_et,x->the_ptr()->position(),zero);
99 struct IsLinkedByRecHit :
public ClusUnaryFunction {
100 const CalibClusterPtr the_seed;
101 const double _threshold, _majority;
102 const double _maxSatelliteDEta, _maxSatelliteDPhi;
103 double x_rechits_tot=0;
104 double x_rechits_match=0;
105 IsLinkedByRecHit(
const CalibClusterPtr&
s,
const double threshold,
106 const double majority,
const double maxDEta,
108 the_seed(s),_threshold(threshold),_majority(majority),
109 _maxSatelliteDEta(maxDEta), _maxSatelliteDPhi(maxDPhi) {}
110 bool operator()(
const CalibClusterPtr& x) {
111 if( the_seed->energy_nocalib() < _threshold )
return false;
112 const double dEta =
std::abs(the_seed->eta()-x->eta());
115 if( _maxSatelliteDEta < dEta || _maxSatelliteDPhi < dPhi)
return false;
117 const auto& seedHitsAndFractions =
118 the_seed->the_ptr()->hitsAndFractions();
119 const auto& xHitsAndFractions =
120 x->the_ptr()->hitsAndFractions();
121 x_rechits_tot = xHitsAndFractions.size();
122 x_rechits_match = 0.0;
123 for(
const std::pair<DetId, float>& seedHit : seedHitsAndFractions ) {
124 for(
const std::pair<DetId, float>& xHit : xHitsAndFractions ) {
125 if( seedHit.first == xHit.first ) {
126 x_rechits_match += 1.0;
130 return x_rechits_match/x_rechits_tot > _majority;
134 struct IsClustered :
public ClusUnaryFunction {
135 const CalibClusterPtr the_seed;
138 double etawidthSuperCluster_ = .0 , phiwidthSuperCluster_ = .0;
139 IsClustered(
const CalibClusterPtr
s,
141 const bool dyn_dphi) :
142 the_seed(s), _type(ct), dynamic_dphi(dyn_dphi) {}
143 bool operator()(
const CalibClusterPtr& x) {
146 const bool passes_dphi =
147 ( (!dynamic_dphi && dphi < phiwidthSuperCluster_ ) ||
156 return (
std::abs(the_seed->eta()-x->eta())<etawidthSuperCluster_ &&
160 return ( passes_dphi &&
195 regr_->setTokens(regconf, cc);
203 regr_->setEventSetup(setup);
239 regr_->setEvent(iEvent);
250 for (
size_t i = 0;
i < clusters.size(); ++
i ){
251 auto cluster = clusters.ptrAt(
i);
253 <<
"Loading PFCluster i="<<cluster.key()
254 <<
" energy="<<cluster->energy()<<std::endl;
257 if( cluster->caloID().detectors() == 0 &&
258 cluster->hitsAndFractions().size() == 0 )
continue;
261 switch( cluster->layer() ) {
296 std::stable_partition(clusters.begin(),clusters.end(),seedable);
301 while( std::any_of(clusters.cbegin(), clusters.cend(), seedable) ) {
314 switch( seed->the_ptr()->layer() ) {
320 <<
" in the ECAL barrel!";
329 <<
" in the ECAL endcap!" << std::endl;
341 auto not_clustered = std::stable_partition(clusters.begin(),clusters.end(),
342 IsClusteredWithSeed);
346 not_clustered = std::stable_partition(not_clustered,clusters.end(),
347 MatchesSeedByRecHit);
351 edm::LogInfo(
"PFClustering") <<
"Dumping cluster detail";
353 <<
"\tPassed seed: e = " << seed->energy_nocalib()
354 <<
" eta = " << seed->eta() <<
" phi = " << seed->phi()
356 for(
auto clus = clusters.cbegin(); clus != not_clustered; ++clus ) {
358 <<
"\t\tClustered cluster: e = " << (*clus)->energy_nocalib()
359 <<
" eta = " << (*clus)->eta() <<
" phi = " << (*clus)->phi()
362 for(
auto clus = not_clustered; clus != clusters.end(); ++clus ) {
364 <<
"\tNon-Clustered cluster: e = " << (*clus)->energy_nocalib()
365 <<
" eta = " << (*clus)->eta() <<
" phi = " << (*clus)->phi()
372 clusters.erase(clusters.begin(),not_clustered);
374 std::vector<const reco::PFCluster*> bare_ptrs;
377 corrSCEnergy(0), corrPS1Energy(0), corrPS2Energy(0),
378 ePS1(0), ePS2(0), energyweight(0), energyweighttot(0);
379 std::vector<double> ps1_energies, ps2_energies;
380 int condP1(1), condP2(1);
381 for(
auto& clus : clustered ) {
383 energyweight = clus->energy_nocalib();
384 bare_ptrs.push_back(clus->the_ptr().get());
389 ps1_energies.clear();
390 ps2_energies.clear();
393 const auto clustops = std::equal_range(
EEtoPS_->begin(),
397 for(
auto i_ps = clustops.first; i_ps != clustops.second; ++i_ps) {
402 switch( psclus->
layer() ) {
404 ps1_energies.push_back(psclus->
energy());
405 for (
auto const& recH : recH_Frac){
406 ESDetId strip1 = recH.recHitRef()->detId();
411 if(status_p1->getStatusCode() == 0) condP1 = 0;
416 ps2_energies.push_back(psclus->
energy());
417 for (
auto const& recH : recH_Frac){
418 ESDetId strip2 = recH.recHitRef()->detId();
421 if(status_p2->getStatusCode() == 0) condP2 = 0;
429 if(condP1 == 1) ePS1 = -1.;
430 if(condP2 == 1) ePS2 = -1.;
432 ps1_energies,ps2_energies,
437 if(ePS1 == -1.) ePS1 = 0;
438 if(ePS2 == -1.) ePS2 = 0;
444 energyweight = clus->energy() - ePS1 - ePS2;
447 energyweight = clus->energy();
453 posX += energyweight * cluspos.X();
454 posY += energyweight * cluspos.Y();
455 posZ += energyweight * cluspos.Z();
457 energyweighttot += energyweight;
458 corrSCEnergy += clus->energy();
459 corrPS1Energy += ePS1;
460 corrPS2Energy += ePS2;
462 posX /= energyweighttot;
463 posY /= energyweighttot;
464 posZ /= energyweighttot;
469 new_sc.
setSeed(clustered.front()->the_ptr());
473 for(
const auto& clus : clustered ) {
476 auto& hits_and_fractions = clus->the_ptr()->hitsAndFractions();
477 for(
auto& hit_and_fraction : hits_and_fractions ) {
483 const auto clustops = std::equal_range(
EEtoPS_->begin(),
490 for(
auto i_ps = clustops.first; i_ps != clustops.second; ++i_ps) {
502 <<
"Found a PS cluster matched to more than one EE cluster!" 503 << std::endl << std::hex << psclus.
get() <<
" == " 504 << found_pscluster->get() <<
std::dec << std::endl;
521 regr_->modifyObject(new_sc);
533 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)
const self & getMap() const
T const * get() const
Returns C++ pointer to the item.
double threshPFClusterSeedBarrel_
bool applyCrackCorrections_
double pflowPhiWidth() const
def setup(process, global_tag, zero_tesla=False)
const reco::BeamSpot * beamSpot_
const reco::PFCluster::EEtoPSAssociation * EEtoPS_
double Phi_mpi_pi(double x)
void setSeed(const CaloClusterPtr &r)
list of used xtals by DetId // now inherited by CaloCluster
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_
double pflowEtaWidth() const
double ptFast(const double energy, const math::XYZPoint &position, const math::XYZPoint &origin)
std::unique_ptr< reco::SuperClusterCollection > superClustersEE_
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 &&)
double dPhi(double phi1, double phi2)
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
void addPreshowerCluster(const CaloClusterPtr &r)
add reference to constituent BasicCluster
clustering_type _clustype
double threshPFClusterEndcap_
void buildSuperCluster(CalibratedClusterPtr &, CalibratedClusterPtrVector &)
std::vector< Item >::const_iterator const_iterator
bool GreaterByE(const T &a1, const T &a2)
void addCluster(const CaloClusterPtr &r)
add reference to constituent BasicCluster
static int position[264][3]
const std::vector< reco::PFRecHitFraction > & recHitFractions() const
vector of rechit fractions
const Point & position() const
position
T const * product() const
void setPreshowerEnergyPlane1(double preshowerEnergy1)
void setPFClusterCalibration(const std::shared_ptr< PFEnergyCalibration > &)
CalibratedClusterPtrVector _clustersEB
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)