5 #include "PtPartitioningIndex.h"
9 unsigned PtPartitioningIndex::max_element(
const unsigned * clu,
unsigned size )
const
12 for (
unsigned i=0; i != size; i++ ) {
13 const unsigned tmp = clu[i];
14 if ( tmp > max && tmp < UINT_MAX ) {
24 const unsigned* clustering1,
25 const unsigned* clustering2,
26 const unsigned len)
const
28 assert(inputParticles);
35 unsigned n1 = this->max_element(clustering1,len)+1U;
36 unsigned n2 = this->max_element(clustering2,len)+1U;
40 std::swap(clustering1, clustering2);
44 const unsigned matlen = n1*n2;
47 if (storage_.size() < matlen)
48 storage_.resize(matlen);
49 double* data = &storage_[0];
51 for (
unsigned i=0; i<matlen; ++i)
54 long double ptsum = 0.0L;
55 long double ptsumsq = 0.0L;
56 for (
unsigned i=0; i<len; ++i)
58 if ( clustering1[i] == UINT_MAX || clustering2[i] == UINT_MAX )
continue;
59 const double pt = inputParticles[i].pt();
62 data[clustering1[i]*n2 + clustering2[i]] += pt;
66 return processInterClusterMatrix(data, n1, n2, ptsum, ptsumsq);
69 double BestPtMatchIndex::processInterClusterMatrix(
70 const double* mat,
const unsigned nrows,
71 const unsigned ncols,
const double etSum,
74 const unsigned matlen = nrows*ncols;
75 if (storage_.size() < matlen)
76 storage_.resize(matlen);
77 ElementSort* data = &storage_[0];
79 const unsigned nflags = nrows + ncols;
80 if (intstorage_.size() < nflags)
81 intstorage_.resize(nflags);
82 int *rowTaken = &intstorage_[0];
83 int *colTaken = rowTaken + nrows;
84 for (
unsigned i=0; i<nflags; ++i)
87 ElementSort* d = data;
88 for (
unsigned i=0; i<nrows; ++i)
89 for (
unsigned j=0; j<ncols; ++j, ++d)
96 std::sort(data, data+matlen);
97 long double usedsum = 0.0L;
98 ElementSort*
const dmax = data + matlen;
100 const unsigned kmax = nrows < ncols ? nrows : ncols;
101 for (d = data; d!=dmax && k<kmax; ++d)
102 if (!rowTaken[d->row] && !colTaken[d->col])
104 rowTaken[d->row] = 1;
105 colTaken[d->col] = 1;
110 return static_cast<double>(usedsum)/etSum;
113 double TransverseRandIndex2::processInterClusterMatrix(
114 const double* mat,
const unsigned nrows,
115 const unsigned ncols,
const double etSum,
116 const double etSumsq)
const
118 const unsigned nsums = nrows + ncols;
119 if (storage_.size() < nsums)
120 storage_.resize(nsums);
121 long double* rowSums = &storage_[0];
122 long double* colSums = rowSums + nrows;
123 for (
unsigned i=0; i<ncols; ++i)
126 long double sumsq = 0.0L;
127 for (
unsigned i=0; i<nrows; ++i)
129 long double rsum = 0.0L;
130 const double* m = mat + i*ncols;
131 for (
unsigned j=0; j<ncols; ++j)
140 long double crsq = 0.0L;
141 for (
unsigned i=0; i<nsums; ++i)
142 crsq += rowSums[i]*rowSums[i];
144 const double norm = 0.5*(etSum*etSum - etSumsq);
147 return 1.0 - (0.5*crsq - sumsq)/norm;
double index(const PseudoJet *inputParticles, const unsigned *clustering1, const unsigned *clustering2, unsigned size) const
Calculate the stability index.