21 for (
unsigned int i=0;
i<hits.
size();++
i) {
28 float sigmaNoise = 1.;
35 if(hgrh.
energy() < storedThreshold)
48 points[layer].emplace_back(
Hexel(hgrh,detid,isHalf,sigmaNoise,thickness,&
rhtools_),position.
x(),position.
y());
58 maxpos[layer][1] =
std::max((
float)position.
y(),maxpos[layer][1]);
71 std::vector<KDTree> hit_kdtree(2*(
maxlayer+1));
78 hit_kdtree[
i].build(
points[i],bounds);
93 std::vector< std::pair<DetId, float> > thisCluster;
103 std::vector<std::vector<double> > fractions;
111 for(
unsigned isub = 0; isub < fractions.size(); ++isub ) {
112 double effective_hits = 0.0;
116 for(
unsigned ihit = 0; ihit < fractions[isub].size(); ++ihit ) {
117 const double fraction = fractions[isub][ihit];
118 if( fraction > 1
e-7 ) {
120 thisCluster.emplace_back(
current_v[i][ihit].
data.detid,fraction);
126 std::cout <<
"\t******** NEW CLUSTER (SHARING) ********" << std::endl;
127 std::cout <<
"\tEff. No. of cells = " << effective_hits << std::endl;
128 std::cout <<
"\t Energy = " << energy << std::endl;
129 std::cout <<
"\t Phi = " << position.phi() << std::endl;
130 std::cout <<
"\t Eta = " << position.eta() << std::endl;
131 std::cout <<
"\t*****************************" << std::endl;
142 energy += it.data.isHalo ? 0. : it.data.weight;
144 thisCluster.emplace_back(std::pair<DetId, float>(it.data.detid,(it.data.isHalo?0.:1.)));
148 std::cout <<
"******** NEW CLUSTER (HGCIA) ********" << std::endl;
151 std::cout <<
" Energy = " << energy << std::endl;
152 std::cout <<
" Phi = " << position.phi() << std::endl;
153 std::cout <<
" Eta = " << position.eta() << std::endl;
154 std::cout <<
"*****************************" << std::endl;
165 float total_weight = 0.;
169 unsigned int v_size = v.size();
171 for (
unsigned int i = 0;
i < v_size;
i++){
172 if(!v[
i].
data.isHalo){
173 total_weight += v[
i].data.weight;
174 x += v[
i].data.x*v[
i].data.weight;
175 y += v[
i].data.y*v[
i].data.weight;
176 z += v[
i].data.z*v[
i].data.weight;
180 if (total_weight != 0) {
190 double maxdensity = 0.;
197 for(
unsigned int i = 0;
i < nd.size(); ++
i){
199 KDTreeBox search_box(nd[
i].dims[0]-delta_c,nd[
i].dims[0]+delta_c,
200 nd[
i].dims[1]-delta_c,nd[
i].dims[1]+delta_c);
201 std::vector<KDNode>
found;
202 lp.
search(search_box,found);
203 const unsigned int found_size = found.size();
204 for(
unsigned int j = 0; j < found_size; j++){
206 nd[
i].data.rho += found[j].data.weight;
207 if(nd[
i].data.rho > maxdensity) maxdensity = nd[
i].data.rho;
220 double maxdensity = 0.0;
221 int nearestHigher = -1;
225 maxdensity = nd[rs[0]].
data.rho;
238 nd[rs[0]].data.nearestHigher = nearestHigher;
241 const double max_dist2 = dist2;
242 const unsigned int nd_size = nd.size();
244 for(
unsigned int oi = 1; oi < nd_size; ++oi){
246 unsigned int i = rs[oi];
251 for(
unsigned int oj = 0; oj < oi; ++oj){
252 unsigned int j = rs[oj];
260 nd[
i].data.nearestHigher = nearestHigher;
271 unsigned int clusterIndex = 0;
280 const unsigned int nd_size = nd.size();
281 for(
unsigned int i=0;
i < nd_size; ++
i){
283 if(nd[ds[
i]].
data.delta < delta_c)
break;
286 float rho_c =
kappa*nd[ds[
i]].data.sigmaNoise;
287 if(nd[ds[
i]].
data.rho < rho_c )
continue;
290 else if(nd[ds[
i]].
data.rho*
kappa < maxdensity)
294 nd[ds[
i]].data.clusterIndex = clusterIndex;
298 std::cout <<
"Cluster center is hit " << ds[
i] << std::endl;
305 if(clusterIndex==0)
return clusterIndex;
309 for(
unsigned int oi =1; oi < nd_size; ++oi){
310 unsigned int i = rs[oi];
311 int ci = nd[
i].data.clusterIndex;
313 nd[
i].data.clusterIndex = nd[nd[
i].data.nearestHigher].data.clusterIndex;
321 std::cout <<
"resizing cluster vector by "<< clusterIndex << std::endl;
327 std::vector<double> rho_b(clusterIndex,0.);
331 for(
unsigned int i = 0;
i < nd_size; ++
i){
332 int ci = nd[
i].data.clusterIndex;
333 bool flag_isolated =
true;
335 KDTreeBox search_box(nd[
i].dims[0]-delta_c,nd[
i].dims[0]+delta_c,
336 nd[
i].dims[1]-delta_c,nd[
i].dims[1]+delta_c);
337 std::vector<KDNode>
found;
338 lp.
search(search_box,found);
340 const unsigned int found_size = found.size();
341 for(
unsigned int j = 0; j < found_size; j++){
343 if(found[j].
data.clusterIndex!=-1){
345 if(dist < delta_c && found[j].data.clusterIndex!=ci){
347 nd[
i].data.isBorder =
true;
352 if(dist < delta_c && dist != 0. && found[j].data.clusterIndex==ci){
355 flag_isolated =
false;
359 if(flag_isolated) nd[
i].data.isBorder =
true;
362 if(nd[
i].
data.isBorder && rho_b[ci] < nd[
i].data.rho)
363 rho_b[ci] = nd[
i].data.rho;
367 for(
unsigned int i = 0;
i < nd_size; ++
i){
368 int ci = nd[
i].data.clusterIndex;
369 if(ci!=-1 && nd[
i].
data.rho < rho_b[ci])
370 nd[
i].data.isHalo =
true;
371 if(nd[
i].
data.clusterIndex!=-1){
384 std::cout <<
"moving cluster offset by " << clusterIndex << std::endl;
392 std::vector<unsigned>
result;
393 std::vector<bool>
seed(cluster.size(),
true);
396 for(
unsigned i = 0;
i < cluster.size(); ++
i ) {
397 for(
unsigned j = 0; j < cluster.size(); ++j ) {
398 if(
distance(cluster[
i].
data,cluster[j].data) < delta_c &&
i != j) {
399 if( cluster[
i].data.weight < cluster[j].data.weight ) {
407 for(
unsigned i = 0 ;
i < cluster.size(); ++
i ) {
420 const std::vector<double>& fractions) {
421 double norm(0.0),
x(0.0),
y(0.0),
z(0.0);
422 for(
unsigned i = 0;
i < hits.size(); ++
i ) {
423 const double weight = fractions[
i]*hits[
i].data.weight;
425 x += weight*hits[
i].data.x;
426 y += weight*hits[
i].data.y;
427 z += weight*hits[
i].data.z;
430 double norm_inv = 1.0/norm;
436 const std::vector<double>& fractions) {
438 for(
unsigned i = 0 ;
i < hits.size(); ++
i ) {
439 result += fractions[
i]*hits[
i].data.weight;
445 const std::vector<unsigned>& seeds,
446 std::vector<std::vector<double> >& outclusters) {
447 std::vector<bool> isaseed(incluster.size(),
false);
449 outclusters.resize(seeds.size());
450 std::vector<Point> centroids(seeds.size());
451 std::vector<double> energies(seeds.size());
453 if( seeds.size() == 1 ) {
454 outclusters[0].clear();
455 outclusters[0].resize(incluster.size(),1.0);
462 for(
unsigned i = 0;
i < seeds.size(); ++
i ) {
463 isaseed[seeds[
i]] =
true;
470 for(
unsigned i = 0;
i < seeds.size(); ++
i ) {
471 outclusters[
i].resize(incluster.size(),0.0);
472 for(
unsigned j = 0; j < incluster.size(); ++j ) {
473 if( j == seeds[
i] ) {
474 outclusters[
i][j] = 1.0;
475 centroids[
i] =
math::XYZPoint(incluster[j].
data.x,incluster[j].data.y,incluster[j].data.z);
476 energies[
i] = incluster[j].data.weight;
484 const unsigned iterMax = 50;
487 const double toleranceScaling =
std::pow(
std::max(1.0,seeds.size()-1.0),2.0);
488 std::vector<Point> prevCentroids;
489 std::vector<double>
frac(seeds.size()), dist2(seeds.size());
490 while( iter++ < iterMax && diff > stoppingTolerance*toleranceScaling ) {
491 for(
unsigned i = 0;
i < incluster.size(); ++
i ) {
492 const Hexel& ihit = incluster[
i].data;
494 for(
unsigned j = 0; j < seeds.size(); ++j ) {
496 double d2 = (
std::pow(ihit.
x - centroids[j].x(),2.0) +
497 std::pow(ihit.
y - centroids[j].y(),2.0) +
501 if(
i == seeds[j] ) {
503 }
else if( isaseed[
i] ) {
506 fraction = energies[j]*
std::exp( -0.5*d2 );
513 for(
unsigned j = 0; j < seeds.size(); ++j ) {
514 if( fracTot > minFracTot ||
515 (
i == seeds[j] && fracTot > 0.0 ) ) {
516 outclusters[j][
i] =
frac[j]/fracTot;
518 outclusters[j][
i] = 0.0;
526 centroids.resize(seeds.size());
528 for(
unsigned i = 0;
i < seeds.size(); ++
i ) {
532 const double delta2 = (prevCentroids[
i]-centroids[
i]).
perp2();
533 if( delta2 > diff2 ) diff2 = delta2;
546 std::vector<double>
dummy;
550 int previouswafer=-999;
552 for(
unsigned icalo=0;icalo<2;++icalo)
554 const std::vector<DetId>& listDetId( icalo==0 ? listee : listfh);
556 for(
auto& detid: listDetId)
559 if(wafer==previouswafer)
continue;
560 previouswafer = wafer;
566 if( thickness>99. && thickness<101.) thickIndex=0;
567 else if( thickness>199. && thickness<201. ) thickIndex=1;
568 else if( thickness>299. && thickness<301. ) thickIndex=2;
569 else assert( thickIndex>0 &&
"ERROR - silicon thickness has a nonsensical value" );
580 std::vector<double> bhDummy_thresholds;
581 std::vector<double> bhDummy_sigmaNoise;
582 bhDummy_thresholds.push_back(sigmaNoise*
ecut);
583 bhDummy_sigmaNoise.push_back(sigmaNoise);
double calculateEnergyWithFraction(const std::vector< KDNode > &, const std::vector< double > &)
hgcal::RecHitTools rhtools_
std::vector< std::vector< KDNode > > current_v
math::XYZPoint calculatePositionWithFraction(const std::vector< KDNode > &, const std::vector< double > &)
double distance(const Hexel &pt1, const Hexel &pt2)
std::vector< double > dEdXweights
reco::CaloCluster::AlgoId algoId
double calculateDistanceToHigher(std::vector< KDNode > &)
static const unsigned int maxlayer
std::vector< std::array< float, 2 > > minpos
static const unsigned int maxNumberOfWafersPerLayer
std::vector< double > vecDeltas
std::vector< std::vector< double > > thresholds
const DetId & detid() const
std::vector< std::array< float, 2 > > maxpos
void build(std::vector< KDTreeNodeInfoT< DATA, DIM > > &eltList, const KDTreeBoxT< DIM > ®ion)
math::XYZPoint Point
point in the space
std::vector< double > thicknessCorrection
std::vector< double > nonAgedNoises
void search(const KDTreeBoxT< DIM > &searchBox, std::vector< KDTreeNodeInfoT< DATA, DIM > > &resRecHitList)
std::vector< size_t > sort_by_delta(const std::vector< KDNode > &v)
void shareEnergy(const std::vector< KDNode > &, const std::vector< unsigned > &, std::vector< std::vector< double > > &)
static const unsigned int lastLayerEE
static const unsigned int lastLayerFH
unsigned int cluster_offset
std::vector< size_t > sorted_indices(const std::vector< T > &v)
std::vector< reco::BasicCluster > getClusters(bool)
std::vector< unsigned > findLocalMaximaInCluster(const std::vector< KDNode > &)
double calculateLocalDensity(std::vector< KDNode > &, KDTree &, const unsigned int)
int findAndAssignClusters(std::vector< KDNode > &, KDTree &, double, KDTreeBox &, const unsigned int)
std::vector< std::vector< KDNode > > points
XYZPointD XYZPoint
point in space with cartesian internal representation
T perp2() const
Squared magnitude of transverse component.
math::XYZPoint calculatePosition(std::vector< KDNode > &)
std::vector< std::vector< double > > v_sigmaNoise
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
std::vector< std::vector< double > > tmp
char data[epos_bytes_allocation]
double distance2(const Hexel &pt1, const Hexel &pt2)
static int position[264][3]
std::vector< double > fcPerMip
void populate(const HGCRecHitCollection &hits)
Power< A, B >::type pow(const A &a, const B &b)
std::vector< reco::BasicCluster > clusters_v