ATLAS Offline Software
Loading...
Searching...
No Matches
DistanceFunctor.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef DISTANCE_FUNCTOR_H
6#define DISTANCE_FUNCTOR_H
7
8#include <math.h>
9
10template <typename T, typename U>
12
13 public:
14 float operator()(const T *t, const U *u) const {
15 return calculateDistance(t, u);
16 }
17
18 float distance(const T *t, const U *u) const {
19 return (*this)(t, u);
20 }
21
22 virtual ~DistanceFunctor() {;}
23
24 private:
25 virtual float calculateDistance(const T *t, const U *u) const = 0;
26
27}; // end class DistanceFunctor
28
29template <typename T, typename U>
30class DeltaRDistanceFunctor : virtual public DistanceFunctor<T, U> {
31
32 public:
33
35
36 static float deltaR(const T *t, const U *u) {
37
38 if(!t || !u)
39 return -1.;
40
41 float phiDiff = t->phi() - u->phi();
42 while(phiDiff < -M_PI) phiDiff += 2. * M_PI;
43 while(phiDiff >= M_PI) phiDiff -= 2. * M_PI;
44 float etaDiff = t->eta() - u->eta();
45 return sqrt(phiDiff * phiDiff + etaDiff * etaDiff);
46
47 }
48
49 private:
50
51 virtual float calculateDistance(const T *t, const U *u) const {
53 }
54
55}; // end class DeltaRDistanceFunctor
56
57#endif
#define M_PI
static float deltaR(const T *t, const U *u)
virtual float calculateDistance(const T *t, const U *u) const
virtual ~DistanceFunctor()
virtual float calculateDistance(const T *t, const U *u) const =0
float distance(const T *t, const U *u) const
float operator()(const T *t, const U *u) const