Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:25:52

0001 #ifndef RecoLocalCalo_HGCalRecAlgos_HGCal3DClustering
0002 #define RecoLocalCalo_HGCalRecAlgos_HGCal3DClustering
0003 
0004 #include "DataFormats/Math/interface/Point3D.h"
0005 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
0006 #include "DataFormats/ParticleFlowReco/interface/HGCalMultiCluster.h"
0007 
0008 #include <vector>
0009 #include <array>
0010 
0011 #include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h"
0012 #include "RecoLocalCalo/HGCalRecAlgos/interface/ClusterTools.h"
0013 
0014 #include "CommonTools/RecoAlgos/interface/KDTreeLinkerAlgo.h"
0015 
0016 class HGCal3DClustering {
0017 public:
0018   HGCal3DClustering() : radii({0., 0., 0.}), minClusters(0), clusterTools(nullptr) {}
0019 
0020   HGCal3DClustering(const edm::ParameterSet& conf,
0021                     edm::ConsumesCollector& sumes,
0022                     const std::vector<double>& radii_in,
0023                     uint32_t min_clusters)
0024       : radii(radii_in),
0025         minClusters(min_clusters),
0026         es(0),
0027         clusterTools(std::make_unique<hgcal::ClusterTools>(conf, sumes)),
0028         caloGeomToken_(sumes.esConsumes<CaloGeometry, CaloGeometryRecord>()) {}
0029 
0030   HGCal3DClustering(const edm::ParameterSet& conf, edm::ConsumesCollector& sumes)
0031       : HGCal3DClustering(conf,
0032                           sumes,
0033                           conf.getParameter<std::vector<double>>("multiclusterRadii"),
0034                           conf.getParameter<unsigned>("minClusters")) {}
0035 
0036   void getEvent(const edm::Event& ev) { clusterTools->getEvent(ev); }
0037   void getEventSetup(const edm::EventSetup& es) {
0038     clusterTools->getEventSetup(es);
0039     const CaloGeometry& geom = es.getData(caloGeomToken_);
0040     rhtools_.setGeometry(geom);
0041     maxlayer = rhtools_.lastLayerBH();
0042     points.clear();
0043     minpos.clear();
0044     maxpos.clear();
0045     zees.clear();
0046     points.resize(2 * (maxlayer + 1));
0047     minpos.resize(2 * (maxlayer + 1), {{0.0f, 0.0f}});
0048     maxpos.resize(2 * (maxlayer + 1), {{0.0f, 0.0f}});
0049     zees.resize(2 * (maxlayer + 1), 0.);
0050   }
0051 
0052   typedef std::vector<reco::BasicCluster> ClusterCollection;
0053 
0054   std::vector<reco::HGCalMultiCluster> makeClusters(const reco::HGCalMultiCluster::ClusterCollection&);
0055 
0056 private:
0057   void organizeByLayer(const reco::HGCalMultiCluster::ClusterCollection&);
0058   void reset() {
0059     for (auto& it : points) {
0060       it.clear();
0061       std::vector<KDNode>().swap(it);
0062     }
0063     std::fill(zees.begin(), zees.end(), 0.);
0064     for (unsigned int i = 0; i < minpos.size(); i++) {
0065       minpos[i][0] = 0.;
0066       minpos[i][1] = 0.;
0067       maxpos[i][0] = 0.;
0068       maxpos[i][1] = 0.;
0069     }
0070   }
0071   void layerIntersection(std::array<double, 3>& to, const std::array<double, 3>& from) const;
0072 
0073   //max number of layers
0074   unsigned int maxlayer;
0075 
0076   std::vector<double> radii;
0077   uint32_t minClusters;
0078   struct ClusterRef {
0079     int ind;
0080     float z;
0081     ClusterRef(int ind_i, float z_i) : ind(ind_i), z(z_i) {}
0082     ClusterRef() : ind(-1), z(0.) {}
0083   };
0084 
0085   typedef KDTreeLinkerAlgo<ClusterRef> KDTree;
0086   typedef KDTreeNodeInfo<ClusterRef> KDNode;
0087   std::vector<std::vector<KDNode>> points;
0088   std::vector<std::array<float, 2>> minpos;
0089   std::vector<std::array<float, 2>> maxpos;
0090   std::vector<size_t> es;                            /*!< vector to contain sorted indices of all clusters. */
0091   std::vector<float> zees;                           /*!< vector to contain z position of each layer. */
0092   std::unique_ptr<hgcal::ClusterTools> clusterTools; /*!< instance of tools to simplify cluster access. */
0093   hgcal::RecHitTools rhtools_;                       /*!< instance of tools to access RecHit information. */
0094   edm::ESGetToken<CaloGeometry, CaloGeometryRecord> caloGeomToken_;
0095 };
0096 
0097 #endif