File indexing completed on 2024-04-06 12:24:45
0001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0002 #include "RecoEcal/EgammaCoreTools/interface/EcalClusterPUCleaningTools.h"
0003
0004 #include "Geometry/CaloTopology/interface/CaloTopology.h"
0005 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
0006
0007 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
0008
0009 #include "RecoEcal/EgammaCoreTools/interface/EcalClusterTools.h"
0010
0011 #include "RecoEcal/EgammaCoreTools/interface/SuperClusterShapeAlgo.h"
0012
0013 EcalClusterPUCleaningTools::EcalClusterPUCleaningTools(edm::ConsumesCollector &cc,
0014 const edm::InputTag &redEBRecHits,
0015 const edm::InputTag &redEERecHits)
0016 : pEBRecHitsToken_(cc.consumes<EcalRecHitCollection>(redEBRecHits)),
0017 pEERecHitsToken_(cc.consumes<EcalRecHitCollection>(redEERecHits)),
0018 geometryToken_(cc.esConsumes()) {}
0019
0020 EcalClusterPUCleaningTools::~EcalClusterPUCleaningTools() {}
0021
0022 void EcalClusterPUCleaningTools::getEBRecHits(const edm::Event &ev) {
0023 edm::Handle<EcalRecHitCollection> pEBRecHits;
0024 ev.getByToken(pEBRecHitsToken_, pEBRecHits);
0025 ebRecHits_ = pEBRecHits.product();
0026 }
0027
0028 void EcalClusterPUCleaningTools::getEERecHits(const edm::Event &ev) {
0029 edm::Handle<EcalRecHitCollection> pEERecHits;
0030 ev.getByToken(pEERecHitsToken_, pEERecHits);
0031 eeRecHits_ = pEERecHits.product();
0032 }
0033
0034 reco::SuperCluster EcalClusterPUCleaningTools::CleanedSuperCluster(float xi,
0035 const reco::SuperCluster &scluster,
0036 const edm::Event &ev,
0037 const edm::EventSetup &es) {
0038
0039 const auto &geometry = es.getData(geometryToken_);
0040
0041
0042 getEBRecHits(ev);
0043 getEERecHits(ev);
0044
0045
0046 const reco::CaloClusterPtr &seed = scluster.seed();
0047
0048
0049 float seedBCEnergy = (scluster.seed())->energy();
0050 float eSeed = 0.35;
0051
0052 double ClusterE = 0;
0053
0054 double posX = 0;
0055 double posY = 0;
0056 double posZ = 0;
0057
0058 reco::CaloClusterPtrVector thissc;
0059
0060
0061 for (reco::CaloCluster_iterator bcIt = scluster.clustersBegin(); bcIt != scluster.clustersEnd(); bcIt++) {
0062
0063
0064 if ((*bcIt)->energy() >
0065 sqrt(eSeed * eSeed + xi * xi * seedBCEnergy * seedBCEnergy / cosh((*bcIt)->eta()) / cosh((*bcIt)->eta()))) {
0066 ;
0067 }
0068
0069
0070 thissc.push_back((*bcIt));
0071
0072 ClusterE += (*bcIt)->energy();
0073 posX += (*bcIt)->energy() * (*bcIt)->position().X();
0074 posY += (*bcIt)->energy() * (*bcIt)->position().Y();
0075 posZ += (*bcIt)->energy() * (*bcIt)->position().Z();
0076
0077 }
0078
0079 posX /= ClusterE;
0080 posY /= ClusterE;
0081 posZ /= ClusterE;
0082
0083
0084 double Epreshower = scluster.preshowerEnergy();
0085 double phiWidth = 0.;
0086 double etaWidth = 0.;
0087 reco::SuperCluster suCltmp(ClusterE, math::XYZPoint(posX, posY, posZ), seed, thissc, Epreshower, phiWidth, etaWidth);
0088
0089
0090 const CaloSubdetectorGeometry *geometry_p = nullptr;
0091 if (seed->seed().det() == DetId::Ecal && seed->seed().subdetId() == EcalBarrel) {
0092 geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
0093 SuperClusterShapeAlgo SCShape(ebRecHits_, geometry_p);
0094 SCShape.Calculate_Covariances(suCltmp);
0095 phiWidth = SCShape.phiWidth();
0096 etaWidth = SCShape.etaWidth();
0097 } else if (seed->seed().det() == DetId::Ecal && seed->seed().subdetId() == EcalEndcap) {
0098 geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
0099 SuperClusterShapeAlgo SCShape(eeRecHits_, geometry_p);
0100 SCShape.Calculate_Covariances(suCltmp);
0101 phiWidth = SCShape.phiWidth();
0102 etaWidth = SCShape.etaWidth();
0103 } else {
0104 edm::LogError("SeedError")
0105 << "The seed crystal of this SC is neither in EB nor in EE. This is a problem. Bailing out";
0106 assert(-1);
0107 }
0108
0109
0110 return reco::SuperCluster(ClusterE, math::XYZPoint(posX, posY, posZ), seed, thissc, Epreshower, phiWidth, etaWidth);
0111 }