1 |
loizides |
1.1 |
//--------------------------------------------------------------------------------------------------
|
2 |
loizides |
1.5 |
// $Id: MatchingTools.h,v 1.4 2009/06/28 08:03:09 loizides Exp $
|
3 |
loizides |
1.1 |
//
|
4 |
|
|
// MatchingTools
|
5 |
|
|
//
|
6 |
loizides |
1.2 |
// This class implements a couple of simple geometrical matching functions.
|
7 |
loizides |
1.1 |
//
|
8 |
|
|
// Authors: C.Loizides
|
9 |
|
|
//--------------------------------------------------------------------------------------------------
|
10 |
|
|
|
11 |
|
|
#ifndef MITPHYSICS_UTILS_MATCHINGTOOLS_H
|
12 |
|
|
#define MITPHYSICS_UTILS_MATCHINGTOOLS_H
|
13 |
|
|
|
14 |
loizides |
1.2 |
#include <TObjArray.h>
|
15 |
loizides |
1.1 |
#include <TMath.h>
|
16 |
|
|
#include "MitCommon/MathTools/interface/MathUtils.h"
|
17 |
|
|
#include "MitAna/DataCont/interface/Collection.h"
|
18 |
|
|
|
19 |
|
|
namespace mithep
|
20 |
|
|
{
|
21 |
|
|
class MatchingTools {
|
22 |
|
|
public:
|
23 |
|
|
template<class V1, class V2>
|
24 |
loizides |
1.2 |
static const V2 *Closest(const V1 *v1, const Collection<V2> &col, Double_t maxR,
|
25 |
loizides |
1.3 |
Bool_t self=kFALSE);
|
26 |
loizides |
1.2 |
template<class V1, class V2>
|
27 |
loizides |
1.4 |
static const V2 *Closest(const V1 *v1, const Collection<V2> &col, Double_t maxR,
|
28 |
|
|
Double_t maxPtDiff, Bool_t self=kFALSE);
|
29 |
loizides |
1.1 |
template<class V1, class V2>
|
30 |
loizides |
1.2 |
static TObjArray *Closests(const V1 *v1, const Collection<V2> &col, Double_t maxR,
|
31 |
loizides |
1.3 |
Bool_t self=kFALSE);
|
32 |
loizides |
1.5 |
|
33 |
|
|
ClassDef(MatchingTools, 0) // Geometric matching tools in eta-phi
|
34 |
loizides |
1.1 |
};
|
35 |
|
|
|
36 |
|
|
//------------------------------------------------------------------------------------------------
|
37 |
|
|
template<class V1, class V2>
|
38 |
loizides |
1.2 |
const V2 *MatchingTools::Closest(const V1 *v1, const Collection<V2> &col, Double_t maxR,
|
39 |
|
|
Bool_t self)
|
40 |
loizides |
1.1 |
{
|
41 |
loizides |
1.4 |
// Return closest geometrical neighbor in eta-phi within maximum DeltaR of maxR.
|
42 |
loizides |
1.2 |
// If self is kFALSE make sure that identical pointers are excluded.
|
43 |
loizides |
1.1 |
|
44 |
loizides |
1.2 |
if (!v1)
|
45 |
|
|
return 0;
|
46 |
|
|
|
47 |
loizides |
1.1 |
const V2 *res = 0;
|
48 |
|
|
const UInt_t ents = col.GetEntries();
|
49 |
|
|
if (ents>0) {
|
50 |
|
|
Double_t dR = 1e30;
|
51 |
|
|
for (UInt_t i = 0; i<ents; ++i) {
|
52 |
|
|
const V2 *v2 = col.At(i);
|
53 |
loizides |
1.2 |
if (!v2)
|
54 |
|
|
continue;
|
55 |
|
|
if (!self && (void*)v1==(void*)v2)
|
56 |
|
|
continue;
|
57 |
loizides |
1.1 |
Double_t diff = MathUtils::DeltaR(*v1,*v2);
|
58 |
|
|
if ((diff<maxR) && (diff<dR)) {
|
59 |
|
|
res = v2;
|
60 |
|
|
dR = diff;
|
61 |
|
|
}
|
62 |
|
|
}
|
63 |
|
|
}
|
64 |
|
|
return res;
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
//------------------------------------------------------------------------------------------------
|
68 |
|
|
template<class V1, class V2>
|
69 |
loizides |
1.4 |
const V2 *MatchingTools::Closest(const V1 *v1, const Collection<V2> &col, Double_t maxR,
|
70 |
|
|
Double_t maxPtDiff, Bool_t self)
|
71 |
loizides |
1.1 |
{
|
72 |
loizides |
1.4 |
// Return closest geometrical neighbor in eta-phi within maximum DeltaR of maxR.
|
73 |
|
|
// Exclude particles where the relative pt differs by more than maxPtDiff.
|
74 |
loizides |
1.2 |
// If self is kFALSE make sure that identical pointers are excluded.
|
75 |
loizides |
1.1 |
|
76 |
loizides |
1.2 |
if (!v1)
|
77 |
|
|
return 0;
|
78 |
|
|
|
79 |
loizides |
1.1 |
const V2 *res = 0;
|
80 |
|
|
const UInt_t ents = col.GetEntries();
|
81 |
|
|
if (ents>0) {
|
82 |
loizides |
1.4 |
Double_t dR = 1e30;
|
83 |
loizides |
1.1 |
for (UInt_t i = 0; i<ents; ++i) {
|
84 |
|
|
const V2 *v2 = col.At(i);
|
85 |
loizides |
1.2 |
if (!v2)
|
86 |
|
|
continue;
|
87 |
|
|
if (!self && (void*)v1==(void*)v2)
|
88 |
|
|
continue;
|
89 |
loizides |
1.4 |
Double_t ptd = TMath::Abs(1-v2->Pt()/v1->Pt());
|
90 |
|
|
if (ptd>maxPtDiff)
|
91 |
|
|
continue;
|
92 |
|
|
Double_t diff = MathUtils::DeltaR(*v1,*v2);
|
93 |
|
|
if ((diff<maxR) && (diff<dR)) {
|
94 |
loizides |
1.1 |
res = v2;
|
95 |
loizides |
1.4 |
dR = diff;
|
96 |
loizides |
1.1 |
}
|
97 |
|
|
}
|
98 |
|
|
}
|
99 |
|
|
return res;
|
100 |
|
|
}
|
101 |
loizides |
1.2 |
|
102 |
|
|
//------------------------------------------------------------------------------------------------
|
103 |
|
|
template<class V1, class V2>
|
104 |
|
|
TObjArray *MatchingTools::Closests(const V1 *v1, const Collection<V2> &col, Double_t maxR,
|
105 |
|
|
Bool_t self)
|
106 |
|
|
{
|
107 |
loizides |
1.4 |
// Return closest geometrical neighbors in eta-phi within maximum DeltaR of maxR.
|
108 |
loizides |
1.2 |
// If self is kFALSE make sure that identical pointers are excluded.
|
109 |
|
|
|
110 |
|
|
if (!v1)
|
111 |
|
|
return 0;
|
112 |
|
|
|
113 |
|
|
TObjArray *res = new TObjArray;
|
114 |
|
|
res->SetOwner(kFALSE);
|
115 |
|
|
const UInt_t ents = col.GetEntries();
|
116 |
|
|
for (UInt_t i = 0; i<ents; ++i) {
|
117 |
|
|
const V2 *v2 = col.At(i);
|
118 |
|
|
if (!v2)
|
119 |
|
|
continue;
|
120 |
|
|
if (!self && (void*)v1==(void*)v2)
|
121 |
|
|
continue;
|
122 |
|
|
Double_t diff = MathUtils::DeltaR(*v1,*v2);
|
123 |
|
|
if (diff<maxR)
|
124 |
|
|
res->Add(const_cast<V2*>(v2));
|
125 |
|
|
}
|
126 |
|
|
return res;
|
127 |
|
|
}
|
128 |
loizides |
1.1 |
}
|
129 |
|
|
#endif
|