File indexing completed on 2024-04-06 12:24:43
0001 #ifndef RecoEcal_EgammaCoreTools_EcalClusterLazyTools_h
0002 #define RecoEcal_EgammaCoreTools_EcalClusterLazyTools_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include "FWCore/Framework/interface/Event.h"
0015 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
0016 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
0017 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
0018
0019 #include "FWCore/Framework/interface/ESHandle.h"
0020
0021 #include "CondFormats/EcalObjects/interface/EcalIntercalibConstants.h"
0022 #include "CondFormats/EcalObjects/interface/EcalADCToGeVConstant.h"
0023 #include "CalibCalorimetry/EcalLaserCorrection/interface/EcalLaserDbService.h"
0024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0025 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgoRcd.h"
0026 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgo.h"
0027 #include "RecoEcal/EgammaCoreTools/interface/EcalClusterTools.h"
0028
0029 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0030 #include "Geometry/Records/interface/CaloTopologyRecord.h"
0031 #include "CondFormats/DataRecord/interface/EcalIntercalibConstantsRcd.h"
0032 #include "CondFormats/DataRecord/interface/EcalADCToGeVConstantRcd.h"
0033 #include "CalibCalorimetry/EcalLaserCorrection/interface/EcalLaserDbRecord.h"
0034 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgoRcd.h"
0035 #include "FWCore/Framework/interface/ConsumesCollector.h"
0036 #include "CondFormats/EcalObjects/interface/EcalPFRecHitThresholds.h"
0037 #include "CondFormats/DataRecord/interface/EcalPFRecHitThresholdsRcd.h"
0038 #include "RecoEcal/EgammaCoreTools/interface/EgammaLocalCovParamDefaults.h"
0039 #include <optional>
0040
0041 class CaloTopology;
0042 class CaloGeometry;
0043 class CaloSubdetectorTopology;
0044
0045 class EcalClusterLazyToolsBase {
0046 public:
0047 struct ESData {
0048 CaloGeometry const &caloGeometry;
0049 CaloTopology const &caloTopology;
0050 EcalIntercalibConstants const &ecalIntercalibConstants;
0051 EcalADCToGeVConstant const &ecalADCToGeV;
0052 EcalLaserDbService const &ecalLaserDbService;
0053 };
0054
0055 class ESGetTokens {
0056 public:
0057 ESGetTokens(edm::ConsumesCollector cc)
0058 : caloGeometryToken_{cc.esConsumes()},
0059 caloTopologyToken_{cc.esConsumes()},
0060 ecalIntercalibConstantsToken_{cc.esConsumes()},
0061 ecalADCToGeVConstantToken_{cc.esConsumes()},
0062 ecalLaserDbServiceToken_{cc.esConsumes()} {}
0063
0064 ESData get(edm::EventSetup const &eventSetup) const {
0065 return {.caloGeometry = eventSetup.getData(caloGeometryToken_),
0066 .caloTopology = eventSetup.getData(caloTopologyToken_),
0067 .ecalIntercalibConstants = eventSetup.getData(ecalIntercalibConstantsToken_),
0068 .ecalADCToGeV = eventSetup.getData(ecalADCToGeVConstantToken_),
0069 .ecalLaserDbService = eventSetup.getData(ecalLaserDbServiceToken_)};
0070 }
0071
0072 private:
0073 edm::ESGetToken<CaloGeometry, CaloGeometryRecord> caloGeometryToken_;
0074 edm::ESGetToken<CaloTopology, CaloTopologyRecord> caloTopologyToken_;
0075 edm::ESGetToken<EcalIntercalibConstants, EcalIntercalibConstantsRcd> ecalIntercalibConstantsToken_;
0076 edm::ESGetToken<EcalADCToGeVConstant, EcalADCToGeVConstantRcd> ecalADCToGeVConstantToken_;
0077 edm::ESGetToken<EcalLaserDbService, EcalLaserDbRecord> ecalLaserDbServiceToken_;
0078 };
0079
0080 EcalClusterLazyToolsBase(const edm::Event &ev,
0081 ESData const &esData,
0082 edm::EDGetTokenT<EcalRecHitCollection> token1,
0083 edm::EDGetTokenT<EcalRecHitCollection> token2,
0084 std::optional<edm::EDGetTokenT<EcalRecHitCollection>> token3);
0085
0086
0087 float BasicClusterSeedTime(const reco::BasicCluster &cluster);
0088
0089 float BasicClusterTime(const reco::BasicCluster &cluster, const edm::Event &ev);
0090
0091 float SuperClusterSeedTime(const reco::SuperCluster &cluster);
0092
0093 inline float SuperClusterTime(const reco::SuperCluster &cluster, const edm::Event &ev) {
0094 return BasicClusterTime((*cluster.seed()), ev);
0095 }
0096
0097
0098 std::map<DetId, EcalRecHit> rechits_map_;
0099
0100 std::vector<float> getESHits(double X,
0101 double Y,
0102 double Z,
0103 const std::map<DetId, EcalRecHit> &rechits_map,
0104 const CaloGeometry *geometry,
0105 CaloSubdetectorTopology const *topology_p,
0106 int row = 0,
0107 int plane = 1);
0108
0109 float getESShape(const std::vector<float> &ESHits0);
0110
0111 float eseffsirir(const reco::SuperCluster &cluster);
0112 float eseffsixix(const reco::SuperCluster &cluster);
0113 float eseffsiyiy(const reco::SuperCluster &cluster);
0114
0115 protected:
0116 EcalRecHitCollection const *getEcalRecHitCollection(const reco::BasicCluster &cluster) const;
0117
0118 const CaloGeometry *geometry_;
0119 const CaloTopology *topology_;
0120 const EcalRecHitCollection *ebRecHits_;
0121 const EcalRecHitCollection *eeRecHits_;
0122 const EcalRecHitCollection *esRecHits_;
0123
0124 std::unique_ptr<CaloSubdetectorTopology const> ecalPS_topology_ = nullptr;
0125
0126 EcalIntercalibConstants const *ical = nullptr;
0127 EcalIntercalibConstantMap const *icalMap = nullptr;
0128 EcalADCToGeVConstant const *agc = nullptr;
0129 EcalLaserDbService const *laser = nullptr;
0130
0131 private:
0132 void getESRecHits(const edm::Event &ev, edm::EDGetTokenT<EcalRecHitCollection> const &esRecHitsToken);
0133
0134 };
0135
0136 template <class ClusterTools>
0137 class EcalClusterLazyToolsT : public EcalClusterLazyToolsBase {
0138 public:
0139 EcalClusterLazyToolsT(const edm::Event &ev,
0140 ESData const &esData,
0141 edm::EDGetTokenT<EcalRecHitCollection> token1,
0142 edm::EDGetTokenT<EcalRecHitCollection> token2)
0143 : EcalClusterLazyToolsBase(ev, esData, token1, token2, std::nullopt) {}
0144
0145 EcalClusterLazyToolsT(const edm::Event &ev,
0146 ESData const &esData,
0147 edm::EDGetTokenT<EcalRecHitCollection> token1,
0148 edm::EDGetTokenT<EcalRecHitCollection> token2,
0149 edm::EDGetTokenT<EcalRecHitCollection> token3)
0150 : EcalClusterLazyToolsBase(ev, esData, token1, token2, token3) {}
0151
0152
0153 std::vector<float> energyMatrix(reco::BasicCluster const &cluster, int size) const {
0154 auto recHits = getEcalRecHitCollection(cluster);
0155 DetId maxId = ClusterTools::getMaximum(cluster, recHits).first;
0156
0157 std::vector<float> energies;
0158 for (auto const &detId : CaloRectangleRange(size, maxId, *topology_)) {
0159 energies.push_back(ClusterTools::recHitEnergy(detId, recHits));
0160 }
0161
0162 return energies;
0163 }
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177 float e1x3(const reco::BasicCluster &cluster) const {
0178 return ClusterTools::e1x3(cluster, getEcalRecHitCollection(cluster), topology_);
0179 }
0180 float e3x1(const reco::BasicCluster &cluster) const {
0181 return ClusterTools::e3x1(cluster, getEcalRecHitCollection(cluster), topology_);
0182 }
0183 float e1x5(const reco::BasicCluster &cluster) const {
0184 return ClusterTools::e1x5(cluster, getEcalRecHitCollection(cluster), topology_);
0185 }
0186 float e5x1(const reco::BasicCluster &cluster) const {
0187 return ClusterTools::e5x1(cluster, getEcalRecHitCollection(cluster), topology_);
0188 }
0189 float e2x2(const reco::BasicCluster &cluster) const {
0190 return ClusterTools::e2x2(cluster, getEcalRecHitCollection(cluster), topology_);
0191 }
0192 float e3x2(const reco::BasicCluster &cluster) const {
0193 return ClusterTools::e3x2(cluster, getEcalRecHitCollection(cluster), topology_);
0194 }
0195 float e3x3(const reco::BasicCluster &cluster) const {
0196 return ClusterTools::e3x3(cluster, getEcalRecHitCollection(cluster), topology_);
0197 }
0198 float e4x4(const reco::BasicCluster &cluster) const {
0199 return ClusterTools::e4x4(cluster, getEcalRecHitCollection(cluster), topology_);
0200 }
0201 float e5x5(const reco::BasicCluster &cluster) const {
0202 return ClusterTools::e5x5(cluster, getEcalRecHitCollection(cluster), topology_);
0203 }
0204 int n5x5(const reco::BasicCluster &cluster) const {
0205 return ClusterTools::n5x5(cluster, getEcalRecHitCollection(cluster), topology_);
0206 }
0207
0208
0209 float e2x5Right(const reco::BasicCluster &cluster) const {
0210 return ClusterTools::e2x5Right(cluster, getEcalRecHitCollection(cluster), topology_);
0211 }
0212
0213 float e2x5Left(const reco::BasicCluster &cluster) const {
0214 return ClusterTools::e2x5Left(cluster, getEcalRecHitCollection(cluster), topology_);
0215 }
0216
0217
0218 float e2x5Top(const reco::BasicCluster &cluster) const {
0219 return ClusterTools::e2x5Top(cluster, getEcalRecHitCollection(cluster), topology_);
0220 }
0221
0222
0223 float e2x5Bottom(const reco::BasicCluster &cluster) const {
0224 return ClusterTools::e2x5Bottom(cluster, getEcalRecHitCollection(cluster), topology_);
0225 }
0226
0227
0228
0229 float e2x5Max(const reco::BasicCluster &cluster) const {
0230 return ClusterTools::e2x5Max(cluster, getEcalRecHitCollection(cluster), topology_);
0231 }
0232
0233 float eLeft(const reco::BasicCluster &cluster) const {
0234 return ClusterTools::eLeft(cluster, getEcalRecHitCollection(cluster), topology_);
0235 }
0236 float eRight(const reco::BasicCluster &cluster) const {
0237 return ClusterTools::eRight(cluster, getEcalRecHitCollection(cluster), topology_);
0238 }
0239 float eTop(const reco::BasicCluster &cluster) const {
0240 return ClusterTools::eTop(cluster, getEcalRecHitCollection(cluster), topology_);
0241 }
0242 float eBottom(const reco::BasicCluster &cluster) const {
0243 return ClusterTools::eBottom(cluster, getEcalRecHitCollection(cluster), topology_);
0244 }
0245
0246 float eMax(const reco::BasicCluster &cluster) const {
0247 return ClusterTools::eMax(cluster, getEcalRecHitCollection(cluster));
0248 }
0249
0250 float e2nd(const reco::BasicCluster &cluster) const {
0251 return ClusterTools::e2nd(cluster, getEcalRecHitCollection(cluster));
0252 }
0253
0254
0255 std::pair<DetId, float> getMaximum(const reco::BasicCluster &cluster) const {
0256 return ClusterTools::getMaximum(cluster, getEcalRecHitCollection(cluster));
0257 }
0258 std::vector<float> energyBasketFractionEta(const reco::BasicCluster &cluster) const {
0259 return ClusterTools::energyBasketFractionEta(cluster, getEcalRecHitCollection(cluster));
0260 }
0261 std::vector<float> energyBasketFractionPhi(const reco::BasicCluster &cluster) const {
0262 return ClusterTools::energyBasketFractionPhi(cluster, getEcalRecHitCollection(cluster));
0263 }
0264
0265
0266 std::vector<float> lat(const reco::BasicCluster &cluster, bool logW = true, float w0 = 4.7) const {
0267 return ClusterTools::lat(cluster, getEcalRecHitCollection(cluster), geometry_, logW, w0);
0268 }
0269
0270
0271 std::array<float, 3> covariances(const reco::BasicCluster &cluster, float w0 = 4.7) const {
0272 return ClusterTools::covariances(cluster, getEcalRecHitCollection(cluster), topology_, geometry_, w0);
0273 }
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284 std::array<float, 3> localCovariances(const reco::BasicCluster &cluster,
0285 float w0 = EgammaLocalCovParamDefaults::kRelEnCut,
0286 const EcalPFRecHitThresholds *rhthresholds = nullptr,
0287 float multEB = 0.0,
0288 float multEE = 0.0) const {
0289 return ClusterTools::localCovariances(
0290 cluster, getEcalRecHitCollection(cluster), topology_, w0, rhthresholds, multEB, multEE);
0291 }
0292 std::array<float, 3> scLocalCovariances(const reco::SuperCluster &cluster, float w0 = 4.7) const {
0293 return ClusterTools::scLocalCovariances(cluster, getEcalRecHitCollection(cluster), topology_, w0);
0294 }
0295 double zernike20(const reco::BasicCluster &cluster, double R0 = 6.6, bool logW = true, float w0 = 4.7) const {
0296 return ClusterTools::zernike20(cluster, getEcalRecHitCollection(cluster), geometry_, R0, logW, w0);
0297 }
0298 double zernike42(const reco::BasicCluster &cluster, double R0 = 6.6, bool logW = true, float w0 = 4.7) const {
0299 return ClusterTools::zernike42(cluster, getEcalRecHitCollection(cluster), geometry_, R0, logW, w0);
0300 }
0301
0302 };
0303
0304 namespace noZS {
0305 typedef EcalClusterLazyToolsT<noZS::EcalClusterTools> EcalClusterLazyTools;
0306 }
0307 typedef EcalClusterLazyToolsT<::EcalClusterTools> EcalClusterLazyTools;
0308
0309 #endif