Jpp  19.1.0-rc.1
the software that should make you happy
Public Member Functions | Private Member Functions | Private Attributes | List of all members
JTRIGGER::clusterizeWeight Struct Reference

Anonymous struct for weighed clustering of hits. More...

#include <JAlgorithm.hh>

Public Member Functions

template<class JHitIterator_t , class JMatch_t >
JHitIterator_t operator() (JHitIterator_t __begin, JHitIterator_t __end, const JMatch_t &match) const
 Partition data according given binary match operator. More...
 

Private Member Functions

template<class JHitIterator_t , class JMatch_t >
JHitIterator_t operator() (JHitIterator_t buffer, const int N, const JMatch_t &match, std::random_access_iterator_tag tag) const
 Implementation of method clusterizeWeight for random access iterators. More...
 

Private Attributes

std::vector< double > weight
 

Detailed Description

Anonymous struct for weighed clustering of hits.

Definition at line 300 of file JAlgorithm.hh.

Member Function Documentation

◆ operator()() [1/2]

template<class JHitIterator_t , class JMatch_t >
JHitIterator_t JTRIGGER::clusterizeWeight::operator() ( JHitIterator_t  __begin,
JHitIterator_t  __end,
const JMatch_t &  match 
) const
inline

Partition data according given binary match operator.

The underlying algorithm is known in literature as reverse 'clique'. The result is (likely to be) the maximal sub-set with all elements matched to each other. The complexity is quadratic, i.e. at most (number of elements x number of elements) operations. The algorithm will sort the data such that all clusterized hits are at the front. The return value points the first non clusterized hit. Note that the weight is assumed to be positive definite and the larger the weight the better.

The hit iterator refers to a data structure which should conform with the match operator. In addition, it should have the following member method:

  • double getW(); // [a.u.]
Parameters
__beginbegin of data
__endend of data
matchbinary match operator
Returns
end of data

Definition at line 322 of file JAlgorithm.hh.

325  {
326  return (*this)(__begin, std::distance(__begin,__end), match, typename std::iterator_traits<JHitIterator_t>::iterator_category());
327  }
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.

◆ operator()() [2/2]

template<class JHitIterator_t , class JMatch_t >
JHitIterator_t JTRIGGER::clusterizeWeight::operator() ( JHitIterator_t  buffer,
const int  N,
const JMatch_t &  match,
std::random_access_iterator_tag  tag 
) const
inlineprivate

Implementation of method clusterizeWeight for random access iterators.

Parameters
bufferpointer to data
Nnumber of hits
matchbinary match operator
tagiterator tag
Returns
pointer to end of data

Definition at line 340 of file JAlgorithm.hh.

344  {
345  using namespace std;
346 
347  if (N != 0) {
348 
349  int i, j;
350 
351  // Determine weight of each hit.
352 
353  weight.resize(N);
354 
355  for (i = 0; i != N; ++i) {
356  weight[i] = buffer[i].getW(); // Assume always a match with itself.
357  }
358 
359  for (i = 0; i != N; ++i) {
360  for (j = i; ++j != N; ) {
361  if (match(buffer[i], buffer[j])) {
362  weight[i] += buffer[j].getW();
363  weight[j] += buffer[i].getW();
364  }
365  }
366  }
367 
368  // Remove hit with the smallest weight of associated hits.
369  // This procedure stops when the weight of associated hits
370  // is equal to the maximal weight of (remaining) hits.
371 
372  int n = N;
373  double W;
374 
375  for ( ; ; ) {
376 
377  j = 0;
378  W = weight[j];
379 
380  for (i = 1; i != n; ++i) {
381  if (weight[i] < weight[j])
382  j = i;
383  else if (weight[i] > W)
384  W = weight[i];
385  }
386 
387  // Ready?
388 
389  if (weight[j] == W) {
390  return buffer + n;
391  }
392 
393  // Reduce effective size.
394 
395  --n;
396 
397  // Swap the selected hit to end.
398 
399  swap(buffer[j], buffer[n]);
400  swap(weight[j], weight[n]);
401 
402  // Decrease weight of associated hits for each associated hit.
403 
404  for (i = 0; i != n && weight[n] > buffer[n].getW(); ++i) {
405  if (match(buffer[i], buffer[n])) {
406  weight[i] -= buffer[n].getW();
407  weight[n] -= buffer[i].getW();
408  }
409  }
410  }
411  }
412 
413  return buffer;
414  }
const int n
Definition: JPolint.hh:786
int j
Definition: JPolint.hh:792
Definition: JSTDTypes.hh:14
std::vector< double > weight
Definition: JAlgorithm.hh:417

Member Data Documentation

◆ weight

std::vector<double> JTRIGGER::clusterizeWeight::weight
mutableprivate

Definition at line 417 of file JAlgorithm.hh.


The documentation for this struct was generated from the following file: