310 std::vector<SiPixelCluster>
output;
312 unsigned int meanExp = nSplitted;
314 output.push_back(aCluster);
318 std::vector<float> clx(meanExp);
319 std::vector<float> cly(meanExp);
320 std::vector<float> cls(meanExp);
321 std::vector<float> oldclx(meanExp);
322 std::vector<float> oldcly(meanExp);
323 std::vector<SiPixelCluster::Pixel> originalpixels = aCluster.
pixels();
324 std::vector<std::pair<int, SiPixelCluster::Pixel>>
pixels;
325 for (
unsigned int j = 0;
j < originalpixels.size();
j++) {
329 int perDiv = originalpixels[
j].adc / sub;
332 <<
" ], expected numb of clusters: " << meanExp <<
" original pixel (x,y) " << originalpixels[
j].x
333 <<
" " << originalpixels[
j].y <<
" sub " << sub << std::endl;
334 for (
int k = 0;
k < sub;
k++) {
336 perDiv = originalpixels[
j].adc - perDiv *
k;
340 std::vector<int> clusterForPixel(
pixels.size());
342 for (
unsigned int j = 0;
j < meanExp;
j++) {
345 clx[
j] = originalpixels[0].x +
j;
346 cly[
j] = originalpixels[0].y +
j;
350 int remainingSteps = 100;
351 while (!
stop && remainingSteps > 0) {
354 std::vector<std::vector<float>> distanceMapX(originalpixels.size(), std::vector<float>(meanExp));
355 std::vector<std::vector<float>> distanceMapY(originalpixels.size(), std::vector<float>(meanExp));
356 std::vector<std::vector<float>> distanceMap(originalpixels.size(), std::vector<float>(meanExp));
357 for (
unsigned int j = 0;
j < originalpixels.size();
j++) {
360 for (
unsigned int i = 0;
i < meanExp;
i++) {
361 distanceMapX[
j][
i] = 1.f * originalpixels[
j].x - clx[
i];
362 distanceMapY[
j][
i] = 1.f * originalpixels[
j].y - cly[
i];
369 dist += (2.f * distanceMapX[
j][
i] /
sizeX) * (2.
f * distanceMapX[
j][
i] /
sizeX);
376 dist += 1.f * (2.f * distanceMapY[
j][
i] /
sizeY) * (2.
f * distanceMapY[
j][
i] /
sizeY);
378 distanceMap[
j][
i] =
sqrt(dist);
380 std::cout <<
"Cluster " <<
i <<
" Original Pixel " <<
j <<
" distances: " << distanceMapX[
j][
i] <<
" " 381 << distanceMapY[
j][
i] <<
" " << distanceMap[
j][
i] << std::endl;
387 std::multimap<float, int> scores;
394 std::vector<float> weightOfPixel(
pixels.size());
395 for (std::multimap<float, int>::iterator
it = scores.begin();
it != scores.end();
it++) {
396 int pixel_index =
it->second;
398 std::cout <<
"Original Pixel " << pixel_index <<
" with score " <<
it->first << std::endl;
400 int subpixel_counter = 0;
401 for (
auto subpixel =
pixels.begin(); subpixel !=
pixels.end(); ++subpixel, ++subpixel_counter) {
402 if (subpixel->first > pixel_index) {
404 }
else if (subpixel->first != pixel_index) {
409 for (
unsigned int subcluster_index = 0; subcluster_index < meanExp; subcluster_index++) {
410 float nsig = (cls[subcluster_index] - expectedADC) /
412 float clQest = 1.f / (1.f +
std::exp(nsig)) + 1
e-6
f;
413 float clDest = 1.f / (distanceMap[pixel_index][subcluster_index] + 0.05f);
416 std::cout <<
" Q: " << clQest <<
" D: " << clDest <<
" " << distanceMap[pixel_index][subcluster_index]
418 float est = clQest * clDest;
420 cl = subcluster_index;
424 cls[
cl] += subpixel->second.adc;
425 clusterForPixel[subpixel_counter] =
cl;
426 weightOfPixel[subpixel_counter] = maxEst;
428 std::cout <<
"Pixel weight j cl " << weightOfPixel[subpixel_counter] <<
" " << subpixel_counter <<
" " <<
cl 435 for (
unsigned int subcluster_index = 0; subcluster_index < meanExp; subcluster_index++) {
436 if (
std::abs(clx[subcluster_index] - oldclx[subcluster_index]) > 0.01f)
438 if (
std::abs(cly[subcluster_index] - oldcly[subcluster_index]) > 0.01f)
440 oldclx[subcluster_index] = clx[subcluster_index];
441 oldcly[subcluster_index] = cly[subcluster_index];
442 clx[subcluster_index] = 0;
443 cly[subcluster_index] = 0;
444 cls[subcluster_index] = 1
e-99;
446 for (
unsigned int pixel_index = 0; pixel_index <
pixels.size(); pixel_index++) {
447 if (clusterForPixel[pixel_index] < 0)
450 std::cout <<
"j " << pixel_index <<
" x " <<
pixels[pixel_index].second.x <<
" * y " 451 <<
pixels[pixel_index].second.y <<
" * ADC " <<
pixels[pixel_index].second.adc <<
" * W " 452 << weightOfPixel[pixel_index] << std::endl;
453 clx[clusterForPixel[pixel_index]] +=
pixels[pixel_index].second.x *
pixels[pixel_index].second.adc;
454 cly[clusterForPixel[pixel_index]] +=
pixels[pixel_index].second.y *
pixels[pixel_index].second.adc;
455 cls[clusterForPixel[pixel_index]] +=
pixels[pixel_index].second.adc;
457 for (
unsigned int subcluster_index = 0; subcluster_index < meanExp; subcluster_index++) {
458 if (cls[subcluster_index] != 0) {
459 clx[subcluster_index] /= cls[subcluster_index];
460 cly[subcluster_index] /= cls[subcluster_index];
463 std::cout <<
"Center for cluster " << subcluster_index <<
" x,y " << clx[subcluster_index] <<
" " 464 << cly[subcluster_index] << std::endl;
465 cls[subcluster_index] = 0;
469 std::cout <<
"maxstep " << remainingSteps << std::endl;
471 std::vector<std::vector<SiPixelCluster::Pixel>> pixelsForCl(meanExp);
472 for (
int cl = 0;
cl < (
int)meanExp;
cl++) {
473 for (
unsigned int j = 0;
j <
pixels.size();
j++) {
478 for (
unsigned int k =
j + 1;
k <
pixels.size();
k++) {
483 <<
" at index " <<
k <<
" associated to cl " << clusterForPixel[
k] << std::endl;
488 for (
unsigned int p = 0;
p <
pixels.size(); ++
p)
491 <<
pixels[
p].second.adc <<
" associated to cl " << clusterForPixel[
p] << std::endl
492 <<
"Adding pixel " <<
pixels[
j].second.x <<
", " <<
pixels[
j].second.y <<
" to cluster " <<
cl 503 for (
int cl = 0;
cl < (
int)meanExp;
cl++) {
506 for (
unsigned int j = 0;
j < pixelsForCl[
cl].size();
j++) {
509 std::cout << pixelsForCl[
cl][
j].x <<
"," << pixelsForCl[
cl][
j].y <<
"|";
518 if (!pixelsForCl[
cl].
empty()) {
std::multimap< float, int > secondDistScore(const std::vector< std::vector< float >> &distanceMap)
U second(std::pair< T, U > const &p)
const std::vector< Pixel > pixels() const
Abs< T >::type abs(const T &t)
uint16_t *__restrict__ uint16_t const *__restrict__ adc