21 std::vector<bool> firstHit(2*(
maxlayer+1),
true);
22 for (
unsigned int i=0;
i<hits.
size();++
i) {
29 float sigmaNoise = 1.;
36 if(hgrh.
energy() < storedThreshold)
49 points[layer].emplace_back(
Hexel(hgrh,detid,isHalf,sigmaNoise,thickness,&
rhtools_),position.
x(),position.
y());
55 firstHit[layer] =
false;
60 maxpos[layer][1] =
std::max((
float)position.
y(),maxpos[layer][1]);
73 std::vector<KDTree> hit_kdtree(2*(
maxlayer+1));
80 hit_kdtree[
i].build(
points[i],bounds);
95 std::vector< std::pair<DetId, float> > thisCluster;
105 std::vector<std::vector<double> > fractions;
113 for(
unsigned isub = 0; isub < fractions.size(); ++isub ) {
114 double effective_hits = 0.0;
118 for(
unsigned ihit = 0; ihit < fractions[isub].size(); ++ihit ) {
119 const double fraction = fractions[isub][ihit];
120 if( fraction > 1
e-7 ) {
122 thisCluster.emplace_back(
current_v[i][ihit].
data.detid,fraction);
128 std::cout <<
"\t******** NEW CLUSTER (SHARING) ********" << std::endl;
129 std::cout <<
"\tEff. No. of cells = " << effective_hits << std::endl;
130 std::cout <<
"\t Energy = " << energy << std::endl;
131 std::cout <<
"\t Phi = " << position.phi() << std::endl;
132 std::cout <<
"\t Eta = " << position.eta() << std::endl;
133 std::cout <<
"\t*****************************" << std::endl;
144 energy += it.data.isHalo ? 0. : it.data.weight;
146 thisCluster.emplace_back(std::pair<DetId, float>(it.data.detid,(it.data.isHalo?0.:1.)));
150 std::cout <<
"******** NEW CLUSTER (HGCIA) ********" << std::endl;
153 std::cout <<
" Energy = " << energy << std::endl;
154 std::cout <<
" Phi = " << position.phi() << std::endl;
155 std::cout <<
" Eta = " << position.eta() << std::endl;
156 std::cout <<
"*****************************" << std::endl;
167 float total_weight = 0.;
171 unsigned int v_size = v.size();
172 unsigned int maxEnergyIndex = 0;
173 float maxEnergyValue = 0;
174 bool haloOnlyCluster =
true;
179 for (
unsigned int i = 0;
i < v_size;
i++){
180 if(!v[
i].
data.isHalo){
181 haloOnlyCluster =
false;
182 total_weight += v[
i].data.weight;
183 x += v[
i].data.x*v[
i].data.weight;
184 y += v[
i].data.y*v[
i].data.weight;
185 z += v[
i].data.z*v[
i].data.weight;
188 if (v[i].
data.weight > maxEnergyValue) {
189 maxEnergyValue = v[
i].data.weight;
195 if (!haloOnlyCluster) {
196 if (total_weight != 0) {
202 else if (v_size > 0) {
204 return math::XYZPoint(v[maxEnergyIndex].
data.x, v[maxEnergyIndex].data.y, v[maxEnergyIndex].data.z);
211 double maxdensity = 0.;
218 for(
unsigned int i = 0;
i < nd.size(); ++
i){
220 KDTreeBox search_box(nd[
i].dims[0]-delta_c,nd[
i].dims[0]+delta_c,
221 nd[
i].dims[1]-delta_c,nd[
i].dims[1]+delta_c);
222 std::vector<KDNode>
found;
223 lp.
search(search_box,found);
224 const unsigned int found_size = found.size();
225 for(
unsigned int j = 0; j < found_size; j++){
227 nd[
i].data.rho += found[j].data.weight;
228 if(nd[
i].data.rho > maxdensity) maxdensity = nd[
i].data.rho;
241 double maxdensity = 0.0;
242 int nearestHigher = -1;
246 maxdensity = nd[rs[0]].
data.rho;
259 nd[rs[0]].data.nearestHigher = nearestHigher;
262 const double max_dist2 = dist2;
263 const unsigned int nd_size = nd.size();
265 for(
unsigned int oi = 1; oi < nd_size; ++oi){
267 unsigned int i = rs[oi];
272 for(
unsigned int oj = 0; oj < oi; ++oj){
273 unsigned int j = rs[oj];
281 nd[
i].data.nearestHigher = nearestHigher;
292 unsigned int clusterIndex = 0;
301 const unsigned int nd_size = nd.size();
302 for(
unsigned int i=0;
i < nd_size; ++
i){
304 if(nd[ds[
i]].
data.delta < delta_c)
break;
307 float rho_c =
kappa*nd[ds[
i]].data.sigmaNoise;
308 if(nd[ds[
i]].
data.rho < rho_c )
continue;
311 else if(nd[ds[
i]].
data.rho*
kappa < maxdensity)
315 nd[ds[
i]].data.clusterIndex = clusterIndex;
319 std::cout <<
"Cluster center is hit " << ds[
i] << std::endl;
326 if(clusterIndex==0)
return clusterIndex;
330 for(
unsigned int oi =1; oi < nd_size; ++oi){
331 unsigned int i = rs[oi];
332 int ci = nd[
i].data.clusterIndex;
334 nd[
i].data.clusterIndex = nd[nd[
i].data.nearestHigher].data.clusterIndex;
342 std::cout <<
"resizing cluster vector by "<< clusterIndex << std::endl;
348 std::vector<double> rho_b(clusterIndex,0.);
352 for(
unsigned int i = 0;
i < nd_size; ++
i){
353 int ci = nd[
i].data.clusterIndex;
354 bool flag_isolated =
true;
356 KDTreeBox search_box(nd[
i].dims[0]-delta_c,nd[
i].dims[0]+delta_c,
357 nd[
i].dims[1]-delta_c,nd[
i].dims[1]+delta_c);
358 std::vector<KDNode>
found;
359 lp.
search(search_box,found);
361 const unsigned int found_size = found.size();
362 for(
unsigned int j = 0; j < found_size; j++){
364 if(found[j].
data.clusterIndex!=-1){
366 if(dist < delta_c && found[j].data.clusterIndex!=ci){
368 nd[
i].data.isBorder =
true;
373 if(dist < delta_c && dist != 0. && found[j].data.clusterIndex==ci){
376 flag_isolated =
false;
380 if(flag_isolated) nd[
i].data.isBorder =
true;
383 if(nd[
i].
data.isBorder && rho_b[ci] < nd[
i].data.rho)
384 rho_b[ci] = nd[
i].data.rho;
388 for(
unsigned int i = 0;
i < nd_size; ++
i){
389 int ci = nd[
i].data.clusterIndex;
391 if (nd[
i].
data.rho <= rho_b[ci]) nd[
i].data.isHalo =
true;
404 std::cout <<
"moving cluster offset by " << clusterIndex << std::endl;
412 std::vector<unsigned>
result;
413 std::vector<bool>
seed(cluster.size(),
true);
416 for(
unsigned i = 0;
i < cluster.size(); ++
i ) {
417 for(
unsigned j = 0; j < cluster.size(); ++j ) {
418 if(
distance(cluster[
i].
data,cluster[j].data) < delta_c &&
i != j) {
419 if( cluster[
i].data.weight < cluster[j].data.weight ) {
427 for(
unsigned i = 0 ;
i < cluster.size(); ++
i ) {
440 const std::vector<double>& fractions) {
441 double norm(0.0),
x(0.0),
y(0.0),
z(0.0);
442 for(
unsigned i = 0;
i < hits.size(); ++
i ) {
443 const double weight = fractions[
i]*hits[
i].data.weight;
445 x += weight*hits[
i].data.x;
446 y += weight*hits[
i].data.y;
447 z += weight*hits[
i].data.z;
450 double norm_inv = 1.0/norm;
456 const std::vector<double>& fractions) {
458 for(
unsigned i = 0 ;
i < hits.size(); ++
i ) {
459 result += fractions[
i]*hits[
i].data.weight;
465 const std::vector<unsigned>& seeds,
466 std::vector<std::vector<double> >& outclusters) {
467 std::vector<bool> isaseed(incluster.size(),
false);
469 outclusters.resize(seeds.size());
470 std::vector<Point> centroids(seeds.size());
471 std::vector<double> energies(seeds.size());
473 if( seeds.size() == 1 ) {
474 outclusters[0].clear();
475 outclusters[0].resize(incluster.size(),1.0);
482 for(
unsigned i = 0;
i < seeds.size(); ++
i ) {
483 isaseed[seeds[
i]] =
true;
490 for(
unsigned i = 0;
i < seeds.size(); ++
i ) {
491 outclusters[
i].resize(incluster.size(),0.0);
492 for(
unsigned j = 0; j < incluster.size(); ++j ) {
493 if( j == seeds[
i] ) {
494 outclusters[
i][j] = 1.0;
495 centroids[
i] =
math::XYZPoint(incluster[j].
data.x,incluster[j].data.y,incluster[j].data.z);
496 energies[
i] = incluster[j].data.weight;
504 const unsigned iterMax = 50;
507 const double toleranceScaling =
std::pow(
std::max(1.0,seeds.size()-1.0),2.0);
508 std::vector<Point> prevCentroids;
509 std::vector<double>
frac(seeds.size()), dist2(seeds.size());
510 while( iter++ < iterMax && diff > stoppingTolerance*toleranceScaling ) {
511 for(
unsigned i = 0;
i < incluster.size(); ++
i ) {
512 const Hexel& ihit = incluster[
i].data;
514 for(
unsigned j = 0; j < seeds.size(); ++j ) {
516 double d2 = (
std::pow(ihit.
x - centroids[j].x(),2.0) +
517 std::pow(ihit.
y - centroids[j].y(),2.0) +
521 if(
i == seeds[j] ) {
523 }
else if( isaseed[
i] ) {
526 fraction = energies[j]*
std::exp( -0.5*d2 );
533 for(
unsigned j = 0; j < seeds.size(); ++j ) {
534 if( fracTot > minFracTot ||
535 (
i == seeds[j] && fracTot > 0.0 ) ) {
536 outclusters[j][
i] =
frac[j]/fracTot;
538 outclusters[j][
i] = 0.0;
546 centroids.resize(seeds.size());
548 for(
unsigned i = 0;
i < seeds.size(); ++
i ) {
552 const double delta2 = (prevCentroids[
i]-centroids[
i]).
perp2();
553 if( delta2 > diff2 ) diff2 = delta2;
566 std::vector<double>
dummy;
570 int previouswafer=-999;
572 for(
unsigned icalo=0;icalo<2;++icalo)
574 const std::vector<DetId>& listDetId( icalo==0 ? listee : listfh);
576 for(
auto& detid: listDetId)
579 if(wafer==previouswafer)
continue;
580 previouswafer = wafer;
586 if( thickness>99. && thickness<101.) thickIndex=0;
587 else if( thickness>199. && thickness<201. ) thickIndex=1;
588 else if( thickness>299. && thickness<301. ) thickIndex=2;
589 else assert( thickIndex>0 &&
"ERROR - silicon thickness has a nonsensical value" );
600 std::vector<double> bhDummy_thresholds;
601 std::vector<double> bhDummy_sigmaNoise;
602 bhDummy_thresholds.push_back(sigmaNoise*
ecut);
603 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