File indexing completed on 2023-06-02 00:50:53
0001 #ifndef RecoLocalCalo_HGCalRecProducers_HGCalClusteringAlgoBase_h
0002 #define RecoLocalCalo_HGCalRecProducers_HGCalClusteringAlgoBase_h
0003
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005 #include "FWCore/Framework/interface/ConsumesCollector.h"
0006
0007 #include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h"
0008 #include "DataFormats/Math/interface/Point3D.h"
0009 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
0010
0011 #include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h"
0012
0013
0014 #include <vector>
0015 #include <numeric>
0016
0017 namespace hgcal_clustering {
0018 template <typename T>
0019 std::vector<size_t> sorted_indices(const std::vector<T> &v) {
0020
0021 std::vector<size_t> idx(v.size());
0022 std::iota(std::begin(idx), std::end(idx), 0);
0023
0024
0025 std::sort(idx.begin(), idx.end(), [&v](size_t i1, size_t i2) { return v[i1] > v[i2]; });
0026
0027 return idx;
0028 }
0029
0030 template <typename T>
0031 size_t max_index(const std::vector<T> &v) {
0032
0033 std::vector<size_t> idx(v.size(), 0);
0034 std::iota(std::begin(idx), std::end(idx), 0);
0035
0036
0037 auto maxidx = std::max_element(
0038 idx.begin(), idx.end(), [&v](size_t i1, size_t i2) { return v[i1].data.rho < v[i2].data.rho; });
0039
0040 return (*maxidx);
0041 }
0042
0043
0044 typedef std::map<DetId, float> Density;
0045
0046 };
0047
0048 class HGCalClusteringAlgoBase {
0049 public:
0050 enum VerbosityLevel { pDEBUG = 0, pWARNING = 1, pINFO = 2, pERROR = 3 };
0051
0052 HGCalClusteringAlgoBase(VerbosityLevel v, reco::CaloCluster::AlgoId algo) : verbosity_(v), algoId_(algo) {}
0053 virtual ~HGCalClusteringAlgoBase() {}
0054
0055 virtual void populate(const HGCRecHitCollection &hits) = 0;
0056 virtual void makeClusters() = 0;
0057 virtual std::vector<reco::BasicCluster> getClusters(bool) = 0;
0058 virtual void reset() = 0;
0059 virtual hgcal_clustering::Density getDensity() { return {}; };
0060 virtual void getEventSetupPerAlgorithm(const edm::EventSetup &es) {}
0061
0062 inline void getEventSetup(const edm::EventSetup &es, hgcal::RecHitTools rhtools) {
0063 rhtools_ = rhtools;
0064 maxlayer_ = rhtools_.lastLayer(isNose_);
0065 lastLayerEE_ = rhtools_.lastLayerEE(isNose_);
0066 lastLayerFH_ = rhtools_.lastLayerFH();
0067 firstLayerBH_ = rhtools_.firstLayerBH();
0068 scintMaxIphi_ = rhtools_.getScintMaxIphi();
0069 getEventSetupPerAlgorithm(es);
0070 }
0071 inline void setVerbosity(VerbosityLevel the_verbosity) { verbosity_ = the_verbosity; }
0072 inline void setAlgoId(reco::CaloCluster::AlgoId algo, bool isNose = false) {
0073 algoId_ = algo;
0074 isNose_ = isNose;
0075 }
0076
0077
0078 unsigned int maxlayer_;
0079
0080 unsigned int lastLayerEE_;
0081 unsigned int lastLayerFH_;
0082 unsigned int firstLayerBH_;
0083 int scintMaxIphi_;
0084 bool isNose_;
0085
0086 protected:
0087
0088 VerbosityLevel verbosity_;
0089
0090
0091 std::vector<reco::BasicCluster> clusters_v_;
0092
0093 hgcal::RecHitTools rhtools_;
0094
0095
0096 reco::CaloCluster::AlgoId algoId_;
0097
0098 edm::ESGetToken<CaloGeometry, CaloGeometryRecord> caloGeomToken_;
0099 };
0100
0101 #endif