Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-04-27 00:16:56

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 // C/C++ headers
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     // initialize original index locations
0021     std::vector<size_t> idx(v.size());
0022     std::iota(std::begin(idx), std::end(idx), 0);
0023 
0024     // sort indices based on comparing values in v
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     // initialize original index locations
0033     std::vector<size_t> idx(v.size(), 0);
0034     std::iota(std::begin(idx), std::end(idx), 0);
0035 
0036     // take the max index based on comparing values in v
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   //Density collection
0044   typedef std::map<DetId, float> Density;
0045 
0046 };  // namespace hgcal_clustering
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, edm::ConsumesCollector iC)
0053       : verbosity_(v), algoId_(algo), caloGeomToken_(iC.esConsumes<CaloGeometry, CaloGeometryRecord>()) {}
0054   virtual ~HGCalClusteringAlgoBase() {}
0055 
0056   virtual void populate(const HGCRecHitCollection &hits) = 0;
0057   virtual void makeClusters() = 0;
0058   virtual std::vector<reco::BasicCluster> getClusters(bool) = 0;
0059   virtual void reset() = 0;
0060   virtual hgcal_clustering::Density getDensity() = 0;
0061   virtual void getEventSetupPerAlgorithm(const edm::EventSetup &es) {}
0062 
0063   inline void getEventSetup(const edm::EventSetup &es) {
0064     edm::ESHandle<CaloGeometry> geom = es.getHandle(caloGeomToken_);
0065     rhtools_.setGeometry(*geom);
0066     maxlayer_ = rhtools_.lastLayer(isNose_);
0067     lastLayerEE_ = rhtools_.lastLayerEE(isNose_);
0068     lastLayerFH_ = rhtools_.lastLayerFH();
0069     firstLayerBH_ = rhtools_.firstLayerBH();
0070     scintMaxIphi_ = rhtools_.getScintMaxIphi();
0071     getEventSetupPerAlgorithm(es);
0072   }
0073   inline void setVerbosity(VerbosityLevel the_verbosity) { verbosity_ = the_verbosity; }
0074   inline void setAlgoId(reco::CaloCluster::AlgoId algo, bool isNose = false) {
0075     algoId_ = algo;
0076     isNose_ = isNose;
0077   }
0078 
0079   //max number of layers
0080   unsigned int maxlayer_;
0081   // last layer per subdetector
0082   unsigned int lastLayerEE_;
0083   unsigned int lastLayerFH_;
0084   unsigned int firstLayerBH_;
0085   int scintMaxIphi_;
0086   bool isNose_;
0087 
0088 protected:
0089   // The verbosity level
0090   VerbosityLevel verbosity_;
0091 
0092   // The vector of clusters
0093   std::vector<reco::BasicCluster> clusters_v_;
0094 
0095   hgcal::RecHitTools rhtools_;
0096 
0097   // The algo id
0098   reco::CaloCluster::AlgoId algoId_;
0099 
0100   edm::ESGetToken<CaloGeometry, CaloGeometryRecord> caloGeomToken_;
0101 };
0102 
0103 #endif