1#ifndef __JTRIGGER__JALGORITHM__
2#define __JTRIGGER__JALGORITHM__
37 template<
class JHitIterator_t,
class JMatch_t>
40 const JMatch_t& match,
45 const int N =
distance(__begin,__end);
47 JHitIterator_t buffer = __begin;
58 for (i = 0; i != N; ++i) {
59 for (j = i; ++j != N; ) {
60 if (match(buffer[i], buffer[j])) {
74 int M = (count[0] >= Nmin ? 1 : 0);
78 for (i = 1; i != n; ++i) {
79 if (count[i] < count[j]) {
82 if (count[i] >= Nmin) {
103 swap(buffer[j], buffer[n]);
104 swap(count [j], count [n]);
108 for (i = 0; i != n && count[n] != 1; ++i) {
109 if (match(buffer[i], buffer[n])) {
133 template<
class JHitIterator_t,
class JComparator_t,
class JMatch_t>
135 JHitIterator_t __end,
136 const JComparator_t& comparator,
137 const JMatch_t& match)
139 if (__begin != __end) {
141 std::sort(__begin, __end, comparator);
143 JHitIterator_t
root = __begin;
145 return std::partition(++__begin, __end,
JBind2nd(match, *
root));
170 template<
class JHitIterator_t,
class JMatch_t>
172 JHitIterator_t __end,
173 const JMatch_t& match)
177 const int N =
distance(__begin,__end);
179 JHitIterator_t buffer = __begin;
189 for (i = 0; i != N; ++i) {
190 for (j = 0; j != i; ++j) {
191 if (match(buffer[i], buffer[j])) {
201 for (
int n = 0; ; ++n) {
205 for (i = j; ++i != N; ) {
206 if (count[i] > count[j]) {
219 swap(buffer[j], buffer[n]);
220 swap(count [j], count [n]);
224 for (i = n; ++i != N; ) {
225 if (match(buffer[i], buffer[n])) {
256 template<
class JHitIterator_t,
class JMatch_t>
258 JHitIterator_t __end,
259 const JMatch_t& match)
263 const int N =
distance(__begin,__end);
265 JHitIterator_t buffer = __begin;
275 for (i = 0; i != N; ++i) {
276 weight[i] = buffer[i].getW();
279 for (i = 0; i != N; ++i) {
280 for (j = i; ++j != N; ) {
281 if (match(buffer[i], buffer[j])) {
282 weight[i] += buffer[j].getW();
283 weight[j] += buffer[i].getW();
300 for (i = 1; i != n; ++i) {
301 if (weight[i] < weight[j])
303 else if (weight[i] > W)
309 if (weight[j] == W) {
319 swap(buffer[j], buffer[n]);
320 swap(weight[j], weight[n]);
324 for (i = 0; i != n && weight[n] > buffer[n].getW(); ++i) {
325 if (match(buffer[i], buffer[n])) {
326 weight[i] -= buffer[n].getW();
327 weight[n] -= buffer[i].getW();
347 template<
class JHit_t>
350 return first.getW() > second.getW();
364 template<
class JHit_t>
365 inline bool timeSorter(
const JHit_t& first,
const JHit_t& second)
367 return first.getT() < second.getT();
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for triggering.
JBinder2nd< JHit_t > JBind2nd(const JMatch< JHit_t > &match, const JHit_t &second)
Auxiliary method to create JBinder2nd object.
JHitIterator_t clusterize(JHitIterator_t __begin, JHitIterator_t __end, const JMatch_t &match, const int Nmin=1)
Partition data according given binary match operator.
JHitIterator_t reverse_clusterize(JHitIterator_t __begin, JHitIterator_t __end, const JMatch_t &match)
Partition data according given binary match operator.
JHitIterator_t clusterizeWeight(JHitIterator_t __begin, JHitIterator_t __end, const JMatch_t &match)
Partition data according given binary match operator.
bool weightSorter(const JHit_t &first, const JHit_t &second)
Compare two hits by weight.
bool timeSorter(const JHit_t &first, const JHit_t &second)
Compare two hits by weight.