1 |
loizides |
1.1 |
//--------------------------------------------------------------------------------------------------
|
2 |
loizides |
1.3 |
// $Id: MatchingTools.h,v 1.2 2009/05/18 06:31:23 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 |
|
|
static const V2 *ClosestRPt(const V1 *v1, const Collection<V2> &col, Double_t max,
|
28 |
loizides |
1.3 |
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.1 |
};
|
33 |
|
|
|
34 |
|
|
//------------------------------------------------------------------------------------------------
|
35 |
|
|
template<class V1, class V2>
|
36 |
loizides |
1.2 |
const V2 *MatchingTools::Closest(const V1 *v1, const Collection<V2> &col, Double_t maxR,
|
37 |
|
|
Bool_t self)
|
38 |
loizides |
1.1 |
{
|
39 |
|
|
// Return closest geometrical neighbor in eta-phi within maximum delta R of maxR.
|
40 |
loizides |
1.2 |
// If self is kFALSE make sure that identical pointers are excluded.
|
41 |
loizides |
1.1 |
|
42 |
loizides |
1.2 |
if (!v1)
|
43 |
|
|
return 0;
|
44 |
|
|
|
45 |
loizides |
1.1 |
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 |
loizides |
1.2 |
if (!v2)
|
52 |
|
|
continue;
|
53 |
|
|
if (!self && (void*)v1==(void*)v2)
|
54 |
|
|
continue;
|
55 |
loizides |
1.1 |
Double_t diff = MathUtils::DeltaR(*v1,*v2);
|
56 |
|
|
if ((diff<maxR) && (diff<dR)) {
|
57 |
|
|
res = v2;
|
58 |
|
|
dR = diff;
|
59 |
|
|
}
|
60 |
|
|
}
|
61 |
|
|
}
|
62 |
|
|
return res;
|
63 |
|
|
}
|
64 |
|
|
|
65 |
|
|
//------------------------------------------------------------------------------------------------
|
66 |
|
|
template<class V1, class V2>
|
67 |
loizides |
1.2 |
const V2 *MatchingTools::ClosestRPt(const V1 *v1, const Collection<V2> &col, Double_t max,
|
68 |
|
|
Bool_t self)
|
69 |
loizides |
1.1 |
{
|
70 |
|
|
// Return closest geometrical neighbor in eta-phi-pt within maximum delta of max.
|
71 |
loizides |
1.2 |
// If self is kFALSE make sure that identical pointers are excluded.
|
72 |
loizides |
1.1 |
|
73 |
loizides |
1.2 |
if (!v1)
|
74 |
|
|
return 0;
|
75 |
|
|
|
76 |
loizides |
1.1 |
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 |
loizides |
1.2 |
if (!v2)
|
83 |
|
|
continue;
|
84 |
|
|
if (!self && (void*)v1==(void*)v2)
|
85 |
|
|
continue;
|
86 |
loizides |
1.1 |
Double_t diff = MathUtils::DeltaR2(*v1,*v2);
|
87 |
|
|
Double_t ptd = 1-v1->Pt()/v2->Pt();
|
88 |
|
|
diff += ptd*ptd;
|
89 |
|
|
diff = TMath::Sqrt(diff);
|
90 |
|
|
if ((diff<max) && (diff<d)) {
|
91 |
|
|
res = v2;
|
92 |
|
|
d = diff;
|
93 |
|
|
}
|
94 |
|
|
}
|
95 |
|
|
}
|
96 |
|
|
return res;
|
97 |
|
|
}
|
98 |
loizides |
1.2 |
|
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 |
loizides |
1.1 |
}
|
126 |
|
|
#endif
|