3 |
|
// |
4 |
|
// MatchingTools |
5 |
|
// |
6 |
< |
// |
6 |
> |
// This class implements a couple of simple geometrical matching functions. |
7 |
|
// |
8 |
|
// Authors: C.Loizides |
9 |
|
//-------------------------------------------------------------------------------------------------- |
11 |
|
#ifndef MITPHYSICS_UTILS_MATCHINGTOOLS_H |
12 |
|
#define MITPHYSICS_UTILS_MATCHINGTOOLS_H |
13 |
|
|
14 |
+ |
#include <TObjArray.h> |
15 |
|
#include <TMath.h> |
16 |
|
#include "MitCommon/MathTools/interface/MathUtils.h" |
17 |
|
#include "MitAna/DataCont/interface/Collection.h" |
21 |
|
class MatchingTools { |
22 |
|
public: |
23 |
|
template<class V1, class V2> |
24 |
< |
static const V2 *Closest(const V1 *v1, const Collection<V2> &col, Double_t maxR); |
24 |
> |
static const V2 *Closest(const V1 *v1, const Collection<V2> &col, Double_t maxR, |
25 |
> |
Bool_t self=kTRUE); |
26 |
> |
template<class V1, class V2> |
27 |
> |
static const V2 *ClosestRPt(const V1 *v1, const Collection<V2> &col, Double_t max, |
28 |
> |
Bool_t self=kTRUE); |
29 |
|
template<class V1, class V2> |
30 |
< |
static const V2 *ClosestEtaPhiPt(const V1 *v1, const Collection<V2> &col, Double_t max); |
30 |
> |
static TObjArray *Closests(const V1 *v1, const Collection<V2> &col, Double_t maxR, |
31 |
> |
Bool_t self=kTRUE); |
32 |
|
}; |
33 |
|
|
34 |
|
//------------------------------------------------------------------------------------------------ |
35 |
|
template<class V1, class V2> |
36 |
< |
const V2 *MatchingTools::Closest(const V1 *v1, const Collection<V2> &col, Double_t maxR) |
36 |
> |
const V2 *MatchingTools::Closest(const V1 *v1, const Collection<V2> &col, Double_t maxR, |
37 |
> |
Bool_t self) |
38 |
|
{ |
39 |
|
// Return closest geometrical neighbor in eta-phi within maximum delta R of maxR. |
40 |
+ |
// If self is kFALSE make sure that identical pointers are excluded. |
41 |
|
|
42 |
< |
const V2 *res = 0; |
42 |
> |
if (!v1) |
43 |
> |
return 0; |
44 |
|
|
45 |
+ |
const V2 *res = 0; |
46 |
|
const UInt_t ents = col.GetEntries(); |
47 |
|
if (ents>0) { |
48 |
|
Double_t dR = 1e30; |
49 |
|
for (UInt_t i = 0; i<ents; ++i) { |
50 |
|
const V2 *v2 = col.At(i); |
51 |
+ |
if (!v2) |
52 |
+ |
continue; |
53 |
+ |
if (!self && (void*)v1==(void*)v2) |
54 |
+ |
continue; |
55 |
|
Double_t diff = MathUtils::DeltaR(*v1,*v2); |
56 |
|
if ((diff<maxR) && (diff<dR)) { |
57 |
|
res = v2; |
64 |
|
|
65 |
|
//------------------------------------------------------------------------------------------------ |
66 |
|
template<class V1, class V2> |
67 |
< |
const V2 *MatchingTools::ClosestEtaPhiPt(const V1 *v1, const Collection<V2> &col, Double_t max) |
67 |
> |
const V2 *MatchingTools::ClosestRPt(const V1 *v1, const Collection<V2> &col, Double_t max, |
68 |
> |
Bool_t self) |
69 |
|
{ |
70 |
|
// Return closest geometrical neighbor in eta-phi-pt within maximum delta of max. |
71 |
+ |
// If self is kFALSE make sure that identical pointers are excluded. |
72 |
|
|
73 |
< |
const V2 *res = 0; |
73 |
> |
if (!v1) |
74 |
> |
return 0; |
75 |
|
|
76 |
+ |
const V2 *res = 0; |
77 |
|
const UInt_t ents = col.GetEntries(); |
78 |
|
if (ents>0) { |
79 |
|
Double_t d = 1e30; |
80 |
|
for (UInt_t i = 0; i<ents; ++i) { |
81 |
|
const V2 *v2 = col.At(i); |
82 |
+ |
if (!v2) |
83 |
+ |
continue; |
84 |
+ |
if (!self && (void*)v1==(void*)v2) |
85 |
+ |
continue; |
86 |
|
Double_t diff = MathUtils::DeltaR2(*v1,*v2); |
87 |
|
Double_t ptd = 1-v1->Pt()/v2->Pt(); |
88 |
|
diff += ptd*ptd; |
95 |
|
} |
96 |
|
return res; |
97 |
|
} |
98 |
+ |
|
99 |
+ |
//------------------------------------------------------------------------------------------------ |
100 |
+ |
template<class V1, class V2> |
101 |
+ |
TObjArray *MatchingTools::Closests(const V1 *v1, const Collection<V2> &col, Double_t maxR, |
102 |
+ |
Bool_t self) |
103 |
+ |
{ |
104 |
+ |
// Return closest geometrical neighbors in eta-phi within maximum delta R of maxR. |
105 |
+ |
// If self is kFALSE make sure that identical pointers are excluded. |
106 |
+ |
|
107 |
+ |
if (!v1) |
108 |
+ |
return 0; |
109 |
+ |
|
110 |
+ |
TObjArray *res = new TObjArray; |
111 |
+ |
res->SetOwner(kFALSE); |
112 |
+ |
const UInt_t ents = col.GetEntries(); |
113 |
+ |
for (UInt_t i = 0; i<ents; ++i) { |
114 |
+ |
const V2 *v2 = col.At(i); |
115 |
+ |
if (!v2) |
116 |
+ |
continue; |
117 |
+ |
if (!self && (void*)v1==(void*)v2) |
118 |
+ |
continue; |
119 |
+ |
Double_t diff = MathUtils::DeltaR(*v1,*v2); |
120 |
+ |
if (diff<maxR) |
121 |
+ |
res->Add(const_cast<V2*>(v2)); |
122 |
+ |
} |
123 |
+ |
return res; |
124 |
+ |
} |
125 |
|
} |
126 |
|
#endif |