CMS 3D CMS Logo

HGCalDepthPreClusterer.cc
Go to the documentation of this file.
3 
4 #include <list>
5 
6 namespace {
8 
9  // initialize original index locations
10  std::vector<size_t> idx(v.size());
11  for (size_t i = 0; i != idx.size(); ++i) idx[i] = i;
12 
13  // sort indices based on comparing values in v
14  std::sort(idx.begin(), idx.end(),
15  [&v](size_t i1, size_t i2) {return (*v[i1]) > (*v[i2]);});
16 
17  return idx;
18  }
19 
20  float dist2(const edm::Ptr<reco::BasicCluster> &a,
22  return reco::deltaR2(*a,*b);
23  }
24 
25  //get distance between cluster and multicluster axis (defined by remaning cluster with highest energy)
26  // N.B. the order of the clusters matters
27  float distAxisCluster2(const edm::Ptr<reco::BasicCluster> &a,
29  float tanTheta = tan(2*atan(exp(-1*a->eta())));
30  float ax = b->z()*tanTheta*cos(a->phi());
31  float ay = b->z()*tanTheta*sin(a->phi());
32  return (ax-b->x())*(ax-b->x()) + (ay-b->y())*(ay-b->y());
33  }
34 }
35 
36 std::vector<reco::HGCalMultiCluster> HGCalDepthPreClusterer::makePreClusters(const reco::HGCalMultiCluster::ClusterCollection &thecls) const {
37 
38  std::vector<reco::HGCalMultiCluster> thePreClusters;
39  std::vector<size_t> es = sorted_indices(thecls);
40  std::vector<int> vused(es.size(),0);
41  unsigned int used = 0;
42 
43  for(unsigned int i = 0; i < es.size(); ++i) {
44  if(vused[i]==0) {
46  temp.push_back(thecls[es[i]]);
47  vused[i]=(thecls[es[i]]->z()>0)? 1 : -1;
48  ++used;
49  for(unsigned int j = i+1; j < es.size(); ++j) {
50  if(vused[j]==0) {
51  float distanceCheck = 9999.;
52  if( realSpaceCone ) distanceCheck = distAxisCluster2(thecls[es[i]],thecls[es[j]]);
53  else distanceCheck = dist2(thecls[es[i]],thecls[es[j]]);
54  DetId detid = thecls[es[j]]->hitsAndFractions()[0].first();
55  unsigned int layer = clusterTools->getLayer(detid);
56  float radius2 = 9999.;
57  if(layer <= lastLayerEE) radius2 = radii[0]*radii[0];
58  else if(layer <= lastLayerFH) radius2 = radii[1]*radii[1];
59  else if(layer <= lastLayerBH) radius2 = radii[2]*radii[2];
60  else assert(radius2<100. && "nonsense layer value - cannot assign multicluster radius");
61  if( distanceCheck<radius2 && int(thecls[es[j]]->z()*vused[i])>0 ) {
62  temp.push_back(thecls[es[j]]);
63  vused[j]=vused[i];
64  ++used;
65  }
66  }
67  }
68  if( temp.size() > minClusters ) {
69  thePreClusters.push_back(temp);
70  auto& back = thePreClusters.back();
71  back.setPosition(clusterTools->getMultiClusterPosition(back));
72  back.setEnergy(clusterTools->getMultiClusterEnergy(back));
73  }
74  }
75  }
76 
77 
78 
79  return thePreClusters;
80 }
size_type size() const
Size of the RefVector.
Definition: PtrVectorBase.h:74
static const unsigned int lastLayerBH
std::vector< reco::HGCalMultiCluster > makePreClusters(const reco::HGCalMultiCluster::ClusterCollection &) const
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
std::unique_ptr< hgcal::ClusterTools > clusterTools
unsigned int size() const
void push_back(const edm::Ptr< reco::BasicCluster > &b)
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
std::vector< size_t > sorted_indices(const std::vector< T > &v)
Definition: DetId.h:18
std::vector< float > radii
static const unsigned int lastLayerEE
static const unsigned int lastLayerFH
double b
Definition: hdecay.h:120
T1 deltaR2(T1 eta1, T2 phi1, T3 eta2, T4 phi2)
Definition: deltaR.h:36
double a
Definition: hdecay.h:121