Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-07-09 05:00:26

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/ParticleFlowReco/interface/PFRecHitFwd.h"
0009 #include "DataFormats/Math/interface/Point3D.h"
0010 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
0011 
0012 #include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h"
0013 
0014 #include "CondFormats/DataRecord/interface/EcalPFRecHitThresholdsRcd.h"
0015 #include "CondFormats/EcalObjects/interface/EcalPFRecHitThresholds.h"
0016 #include "CondFormats/DataRecord/interface/HcalPFCutsRcd.h"
0017 #include "CondFormats/HcalObjects/interface/HcalPFCuts.h"
0018 
0019 // C/C++ headers
0020 #include <vector>
0021 #include <numeric>
0022 
0023 namespace hgcal_clustering {
0024   template <typename T>
0025   std::vector<size_t> sorted_indices(const std::vector<T> &v) {
0026     // initialize original index locations
0027     std::vector<size_t> idx(v.size());
0028     std::iota(std::begin(idx), std::end(idx), 0);
0029 
0030     // sort indices based on comparing values in v
0031     std::sort(idx.begin(), idx.end(), [&v](size_t i1, size_t i2) { return v[i1] > v[i2]; });
0032 
0033     return idx;
0034   }
0035 
0036   template <typename T>
0037   size_t max_index(const std::vector<T> &v) {
0038     // initialize original index locations
0039     std::vector<size_t> idx(v.size(), 0);
0040     std::iota(std::begin(idx), std::end(idx), 0);
0041 
0042     // take the max index based on comparing values in v
0043     auto maxidx = std::max_element(
0044         idx.begin(), idx.end(), [&v](size_t i1, size_t i2) { return v[i1].data.rho < v[i2].data.rho; });
0045 
0046     return (*maxidx);
0047   }
0048 
0049   //Density collection
0050   typedef std::map<DetId, float> Density;
0051 
0052 };  // namespace hgcal_clustering
0053 
0054 class HGCalClusteringAlgoBase {
0055 public:
0056   enum VerbosityLevel { pDEBUG = 0, pWARNING = 1, pINFO = 2, pERROR = 3 };
0057 
0058   HGCalClusteringAlgoBase(VerbosityLevel v, reco::CaloCluster::AlgoId algo) : verbosity_(v), algoId_(algo) {}
0059   virtual ~HGCalClusteringAlgoBase() {}
0060 
0061   virtual void populate(const HGCRecHitCollection &hits) = 0;
0062   virtual void populate(const reco::PFRecHitCollection &hits) = 0;
0063   virtual void makeClusters() = 0;
0064   virtual std::vector<reco::BasicCluster> getClusters(bool) = 0;
0065   virtual void reset() = 0;
0066   virtual hgcal_clustering::Density getDensity() { return {}; };        //implementation is in some child class
0067   virtual void getEventSetupPerAlgorithm(const edm::EventSetup &es) {}  //implementation is in some child class
0068 
0069   inline void getEventSetup(const edm::EventSetup &es, hgcal::RecHitTools rhtools) {
0070     rhtools_ = rhtools;
0071     maxlayer_ = rhtools_.lastLayer(isNose_);
0072     lastLayerEE_ = rhtools_.lastLayerEE(isNose_);
0073     lastLayerFH_ = rhtools_.lastLayerFH();
0074     firstLayerBH_ = rhtools_.firstLayerBH();
0075     scintMaxIphi_ = rhtools_.getScintMaxIphi();
0076     getEventSetupPerAlgorithm(es);
0077   }
0078   inline void setVerbosity(VerbosityLevel the_verbosity) { verbosity_ = the_verbosity; }
0079   inline void setAlgoId(reco::CaloCluster::AlgoId algo, bool isNose = false) {
0080     algoId_ = algo;
0081     isNose_ = isNose;
0082   }
0083   virtual void setThresholds(edm::ESGetToken<EcalPFRecHitThresholds, EcalPFRecHitThresholdsRcd>,
0084                              edm::ESGetToken<HcalPFCuts, HcalPFCutsRcd>){};
0085 
0086   //max number of layers
0087   unsigned int maxlayer_;
0088   // last layer per subdetector
0089   unsigned int lastLayerEE_;
0090   unsigned int lastLayerFH_;
0091   unsigned int firstLayerBH_;
0092   int scintMaxIphi_;
0093   bool isNose_;
0094 
0095 protected:
0096   // The verbosity level
0097   VerbosityLevel verbosity_;
0098 
0099   // The vector of clusters
0100   std::vector<reco::BasicCluster> clusters_v_;
0101 
0102   hgcal::RecHitTools rhtools_;
0103 
0104   // The algo id
0105   reco::CaloCluster::AlgoId algoId_;
0106 
0107   edm::ESGetToken<CaloGeometry, CaloGeometryRecord> caloGeomToken_;
0108 };
0109 
0110 #endif