CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes
HGCal3DClustering Class Reference

#include <HGCal3DClustering.h>

Classes

struct  ClusterRef
 

Public Types

typedef std::vector< reco::BasicClusterClusterCollection
 

Public Member Functions

void getEvent (const edm::Event &ev)
 
void getEventSetup (const edm::EventSetup &es)
 
 HGCal3DClustering ()
 
 HGCal3DClustering (const edm::ParameterSet &conf, edm::ConsumesCollector &sumes, const std::vector< double > &radii_in, uint32_t min_clusters)
 
std::vector< reco::HGCalMultiClustermakeClusters (const reco::HGCalMultiCluster::ClusterCollection &)
 

Private Types

typedef KDTreeNodeInfoT< ClusterRef, 2 > KDNode
 
typedef KDTreeLinkerAlgo< ClusterRef, 2 > KDTree
 

Private Member Functions

void layerIntersection (std::array< double, 3 > &to, const std::array< double, 3 > &from) const
 
void organizeByLayer (const reco::HGCalMultiCluster::ClusterCollection &)
 
void reset ()
 

Private Attributes

std::unique_ptr< hgcal::ClusterToolsclusterTools
 
std::vector< size_t > es
 
std::vector< std::array< float, 2 > > maxpos
 
uint32_t minClusters
 
std::vector< std::array< float, 2 > > minpos
 
std::vector< std::vector< KDNode > > points
 
std::vector< double > radii
 
hgcal::RecHitTools rhtools_
 
std::vector< float > zees
 

Static Private Attributes

static const unsigned int lastLayerBH = 52
 
static const unsigned int lastLayerEE = 28
 
static const unsigned int lastLayerFH = 40
 
static const unsigned int maxlayer = HGCalImagingAlgo::maxlayer
 

Detailed Description

Definition at line 18 of file HGCal3DClustering.h.

Member Typedef Documentation

Definition at line 45 of file HGCal3DClustering.h.

Definition at line 80 of file HGCal3DClustering.h.

Definition at line 79 of file HGCal3DClustering.h.

Constructor & Destructor Documentation

HGCal3DClustering::HGCal3DClustering ( )
inline

Definition at line 22 of file HGCal3DClustering.h.

22  : radii({0.,0.,0.}), minClusters(0), clusterTools(nullptr)
23  {
24  }
std::vector< double > radii
std::unique_ptr< hgcal::ClusterTools > clusterTools
HGCal3DClustering::HGCal3DClustering ( const edm::ParameterSet conf,
edm::ConsumesCollector sumes,
const std::vector< double > &  radii_in,
uint32_t  min_clusters 
)
inline

Definition at line 26 of file HGCal3DClustering.h.

References clusterTools, es, maxlayer, maxpos, and zees.

26  :
27  radii(radii_in),
28  minClusters(min_clusters),
29  points(2*(maxlayer+1)),
30  minpos(2*(maxlayer+1),{ {0.0f,0.0f} }),
31  maxpos(2*(maxlayer+1),{ {0.0f,0.0f} }),
32  es(0),
33  zees(2*(maxlayer+1),0.),
34  clusterTools(std::make_unique<hgcal::ClusterTools>(conf,sumes))
35  {
36  }
std::vector< std::array< float, 2 > > maxpos
std::vector< double > radii
std::vector< float > zees
std::unique_ptr< hgcal::ClusterTools > clusterTools
std::vector< std::vector< KDNode > > points
std::vector< size_t > es
std::vector< std::array< float, 2 > > minpos
static const unsigned int maxlayer

Member Function Documentation

void HGCal3DClustering::getEvent ( const edm::Event ev)
inline

Definition at line 38 of file HGCal3DClustering.h.

References clusterTools.

38 { clusterTools->getEvent(ev); }
std::unique_ptr< hgcal::ClusterTools > clusterTools
void HGCal3DClustering::getEventSetup ( const edm::EventSetup es)
inline

Definition at line 39 of file HGCal3DClustering.h.

References clusterTools, hgcal::RecHitTools::getEventSetup(), and rhtools_.

40  {
41  clusterTools->getEventSetup(es);
43  }
void getEventSetup(const edm::EventSetup &)
Definition: RecHitTools.cc:79
std::unique_ptr< hgcal::ClusterTools > clusterTools
hgcal::RecHitTools rhtools_
void HGCal3DClustering::layerIntersection ( std::array< double, 3 > &  to,
const std::array< double, 3 > &  from 
) const
private

Definition at line 123 of file HGCal3DClustering.cc.

Referenced by makeClusters(), and reset().

126 {
127  if (from[2] != 0) {
128  to[0]=from[0]/from[2]*to[2];
129  to[1]=from[1]/from[2]*to[2];
130  }
131  else {
132  to[0] = 0;
133  to[1] = 0;
134  }
135 }
std::vector< reco::HGCalMultiCluster > HGCal3DClustering::makeClusters ( const reco::HGCalMultiCluster::ClusterCollection thecls)

Definition at line 50 of file HGCal3DClustering.cc.

References funct::abs(), clusterTools, data, es, runEdmFileComparison::found, mps_fire::i, createfilelist::int, gen::k, lastLayerBH, lastLayerEE, lastLayerFH, layerIntersection(), maxlayer, maxpos, minClusters, minpos, organizeByLayer(), points, position, reco::HGCalMultiCluster::push_back(), radii, TCMET_cfi::radius, reset(), reco::HGCalMultiCluster::size(), groupFilesInBlocks::temp, z, and zees.

50  {
51  reset();
52  organizeByLayer(thecls);
53  std::vector<reco::HGCalMultiCluster> thePreClusters;
54 
55  std::vector<KDTree> hit_kdtree(2*(maxlayer+1));
56  for (unsigned int i = 0; i <= 2*maxlayer+1; ++i) {
57  KDTreeBox bounds(minpos[i][0],maxpos[i][0],
58  minpos[i][1],maxpos[i][1]);
59  hit_kdtree[i].build(points[i],bounds);
60  }
61  std::vector<int> vused(es.size(),0);
62  unsigned int used = 0;
63 
64  unsigned int es_size = es.size();
65  for(unsigned int i = 0; i < es_size; ++i) {
66  if(vused[i]==0) {
68  temp.push_back(thecls[es[i]]);
69  vused[i]=(thecls[es[i]]->z()>0)? 1 : -1;
70  ++used;
71  // Starting from cluster es[i] at from[0] - from[1] - from[2]
72  std::array<double,3> from{ {thecls[es[i]]->x(),thecls[es[i]]->y(),thecls[es[i]]->z()} };
73  unsigned int firstlayer = int(thecls[es[i]]->z()>0)*(maxlayer+1);
74  unsigned int lastlayer = firstlayer+maxlayer+1;
75  for(unsigned int j = firstlayer; j < lastlayer; ++j) {
76  if(zees[j]==0.){
77  // layer j not yet ever reached?
78  continue;
79  }
80  std::array<double,3> to{ {0.,0.,zees[j]} };
81  layerIntersection(to,from);
82  unsigned int layer = j > maxlayer ? (j-(maxlayer+1)) : j; //maps back from index used for KD trees to actual layer
83  float radius = 9999.;
84  if(layer <= lastLayerEE) radius = radii[0];
85  else if(layer <= lastLayerFH) radius = radii[1];
86  else if(layer <= lastLayerBH) radius = radii[2];
87  else assert(radius<100. && "nonsense layer value - cannot assign multicluster radius");
88  float radius2 = radius*radius;
89  KDTreeBox search_box(float(to[0])-radius,float(to[0])+radius,
90  float(to[1])-radius,float(to[1])+radius);
91  std::vector<KDNode> found;
92  // at layer j in box float(to[0])+/-radius - float(to[1])+/-radius
93  hit_kdtree[j].search(search_box,found);
94  // found found.size() clusters within box
95  for(unsigned int k = 0; k < found.size(); k++){
96  if(vused[found[k].data.ind]==0 && distReal2(thecls[es[found[k].data.ind]],to)<radius2){
97  temp.push_back(thecls[es[found[k].data.ind]]);
98  vused[found[k].data.ind]=vused[i];
99  ++used;
100  }
101  }
102 
103  }
104  if( temp.size() > minClusters ) {
105  math::XYZPoint position = clusterTools->getMultiClusterPosition(temp);
106  if (std::abs(position.z()) <= 0.) continue;
107  // only store multiclusters that pass the energy threshold in getMultiClusterPosition
108  // giving them a position inside the HGCal
109  thePreClusters.push_back(temp);
110  auto& back = thePreClusters.back();
111  back.setPosition(position);
112  back.setEnergy(clusterTools->getMultiClusterEnergy(back));
113  }
114 
115  }
116 
117  }
118 
119  return thePreClusters;
120 
121 }
std::vector< std::array< float, 2 > > maxpos
std::vector< double > radii
void organizeByLayer(const reco::HGCalMultiCluster::ClusterCollection &)
std::vector< float > zees
unsigned int size() const
void layerIntersection(std::array< double, 3 > &to, const std::array< double, 3 > &from) const
void push_back(const edm::Ptr< reco::BasicCluster > &b)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int k[5][pyjets_maxn]
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
static const unsigned int lastLayerFH
std::unique_ptr< hgcal::ClusterTools > clusterTools
std::vector< std::vector< KDNode > > points
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
static int position[264][3]
Definition: ReadPGInfo.cc:509
std::vector< size_t > es
static const unsigned int lastLayerEE
std::vector< std::array< float, 2 > > minpos
static const unsigned int maxlayer
static const unsigned int lastLayerBH
void HGCal3DClustering::organizeByLayer ( const reco::HGCalMultiCluster::ClusterCollection thecls)
private

Definition at line 25 of file HGCal3DClustering.cc.

References relativeConstraints::empty, es, plotBeamSpotDB::first, hgcal::RecHitTools::getLayerWithOffset(), mps_fire::i, createfilelist::int, SiStripPI::max, maxlayer, maxpos, min(), minpos, points, rhtools_, sorted_indices(), x, y, z, and zees.

Referenced by makeClusters().

25  {
26  es = sorted_indices(thecls);
27  unsigned int es_size = es.size();
28  for(unsigned int i = 0; i < es_size; ++i) {
29  int layer = rhtools_.getLayerWithOffset(thecls[es[i]]->hitsAndFractions()[0].first);
30  layer += int(thecls[es[i]]->z()>0)*(maxlayer+1);
31  float x = thecls[es[i]]->x();
32  float y = thecls[es[i]]->y();
33  float z = thecls[es[i]]->z();
34  points[layer].emplace_back(ClusterRef(i,z),x,y);
35  if(zees[layer]==0.) {
36  // At least one cluster for layer at z
37  zees[layer] = z;
38  }
39  if(points[layer].empty()){
40  minpos[layer][0] = x; minpos[layer][1] = y;
41  maxpos[layer][0] = x; maxpos[layer][1] = y;
42  }else{
43  minpos[layer][0] = std::min(x,minpos[layer][0]);
44  minpos[layer][1] = std::min(y,minpos[layer][1]);
45  maxpos[layer][0] = std::max(x,maxpos[layer][0]);
46  maxpos[layer][1] = std::max(y,maxpos[layer][1]);
47  }
48  }
49 }
std::vector< std::array< float, 2 > > maxpos
std::vector< float > zees
T min(T a, T b)
Definition: MathUtil.h:58
std::vector< size_t > sorted_indices(const std::vector< T > &v)
unsigned int getLayerWithOffset(const DetId &) const
Definition: RecHitTools.cc:294
std::vector< std::vector< KDNode > > points
hgcal::RecHitTools rhtools_
std::vector< size_t > es
std::vector< std::array< float, 2 > > minpos
static const unsigned int maxlayer
void HGCal3DClustering::reset ( void  )
inlineprivate

Definition at line 52 of file HGCal3DClustering.h.

References lumiContext::fill, mps_fire::i, layerIntersection(), maxpos, minpos, points, edm::swap(), and zees.

Referenced by makeClusters().

52  {
53  for( auto& it: points)
54  {
55  it.clear();
56  std::vector<KDNode>().swap(it);
57  }
58  std::fill(zees.begin(), zees.end(), 0.);
59  for(unsigned int i = 0; i < minpos.size(); i++)
60  {
61  minpos[i][0]=0.;minpos[i][1]=0.;
62  maxpos[i][0]=0.;maxpos[i][1]=0.;
63  }
64  }
std::vector< std::array< float, 2 > > maxpos
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:116
std::vector< float > zees
std::vector< std::vector< KDNode > > points
std::vector< std::array< float, 2 > > minpos

Member Data Documentation

std::unique_ptr<hgcal::ClusterTools> HGCal3DClustering::clusterTools
private

instance of tools to simplify cluster access.

Definition at line 86 of file HGCal3DClustering.h.

Referenced by getEvent(), getEventSetup(), HGCal3DClustering(), and makeClusters().

std::vector<size_t> HGCal3DClustering::es
private

vector to contain sorted indices of all clusters.

Definition at line 84 of file HGCal3DClustering.h.

Referenced by HGCal3DClustering(), makeClusters(), and organizeByLayer().

const unsigned int HGCal3DClustering::lastLayerBH = 52
staticprivate

Definition at line 90 of file HGCal3DClustering.h.

Referenced by makeClusters().

const unsigned int HGCal3DClustering::lastLayerEE = 28
staticprivate

Definition at line 88 of file HGCal3DClustering.h.

Referenced by makeClusters().

const unsigned int HGCal3DClustering::lastLayerFH = 40
staticprivate

Definition at line 89 of file HGCal3DClustering.h.

Referenced by makeClusters().

const unsigned int HGCal3DClustering::maxlayer = HGCalImagingAlgo::maxlayer
staticprivate

Definition at line 68 of file HGCal3DClustering.h.

Referenced by HGCal3DClustering(), makeClusters(), and organizeByLayer().

std::vector<std::array<float,2> > HGCal3DClustering::maxpos
private

Definition at line 83 of file HGCal3DClustering.h.

Referenced by HGCal3DClustering(), makeClusters(), organizeByLayer(), and reset().

uint32_t HGCal3DClustering::minClusters
private

Definition at line 71 of file HGCal3DClustering.h.

Referenced by makeClusters().

std::vector<std::array<float,2> > HGCal3DClustering::minpos
private

Definition at line 82 of file HGCal3DClustering.h.

Referenced by makeClusters(), organizeByLayer(), and reset().

std::vector< std::vector<KDNode> > HGCal3DClustering::points
private

Definition at line 81 of file HGCal3DClustering.h.

Referenced by makeClusters(), organizeByLayer(), and reset().

std::vector<double> HGCal3DClustering::radii
private

Definition at line 70 of file HGCal3DClustering.h.

Referenced by makeClusters().

hgcal::RecHitTools HGCal3DClustering::rhtools_
private

instance of tools to access RecHit information.

Definition at line 87 of file HGCal3DClustering.h.

Referenced by getEventSetup(), and organizeByLayer().

std::vector<float> HGCal3DClustering::zees
private

vector to contain z position of each layer.

Definition at line 85 of file HGCal3DClustering.h.

Referenced by HGCal3DClustering(), makeClusters(), organizeByLayer(), and reset().