ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Utils/interface/MatchingTools.h
Revision: 1.4
Committed: Sun Jun 28 08:03:09 2009 UTC (15 years, 10 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.3: +16 -15 lines
Log Message:
Introduce relpt diff cut in Closest function.

File Contents

# Content
1 //--------------------------------------------------------------------------------------------------
2 // $Id: MatchingTools.h,v 1.3 2009/06/18 16:51:04 loizides Exp $
3 //
4 // MatchingTools
5 //
6 // This class implements a couple of simple geometrical matching functions.
7 //
8 // Authors: C.Loizides
9 //--------------------------------------------------------------------------------------------------
10
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"
18
19 namespace mithep
20 {
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,
25 Bool_t self=kFALSE);
26 template<class V1, class V2>
27 static const V2 *Closest(const V1 *v1, const Collection<V2> &col, Double_t maxR,
28 Double_t maxPtDiff, Bool_t self=kFALSE);
29 template<class V1, class V2>
30 static TObjArray *Closests(const V1 *v1, const Collection<V2> &col, Double_t maxR,
31 Bool_t self=kFALSE);
32 };
33
34 //------------------------------------------------------------------------------------------------
35 template<class V1, class V2>
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 DeltaR of maxR.
40 // If self is kFALSE make sure that identical pointers are excluded.
41
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;
58 dR = diff;
59 }
60 }
61 }
62 return res;
63 }
64
65 //------------------------------------------------------------------------------------------------
66 template<class V1, class V2>
67 const V2 *MatchingTools::Closest(const V1 *v1, const Collection<V2> &col, Double_t maxR,
68 Double_t maxPtDiff, Bool_t self)
69 {
70 // Return closest geometrical neighbor in eta-phi within maximum DeltaR of maxR.
71 // Exclude particles where the relative pt differs by more than maxPtDiff.
72 // If self is kFALSE make sure that identical pointers are excluded.
73
74 if (!v1)
75 return 0;
76
77 const V2 *res = 0;
78 const UInt_t ents = col.GetEntries();
79 if (ents>0) {
80 Double_t dR = 1e30;
81 for (UInt_t i = 0; i<ents; ++i) {
82 const V2 *v2 = col.At(i);
83 if (!v2)
84 continue;
85 if (!self && (void*)v1==(void*)v2)
86 continue;
87 Double_t ptd = TMath::Abs(1-v2->Pt()/v1->Pt());
88 if (ptd>maxPtDiff)
89 continue;
90 Double_t diff = MathUtils::DeltaR(*v1,*v2);
91 if ((diff<maxR) && (diff<dR)) {
92 res = v2;
93 dR = diff;
94 }
95 }
96 }
97 return res;
98 }
99
100 //------------------------------------------------------------------------------------------------
101 template<class V1, class V2>
102 TObjArray *MatchingTools::Closests(const V1 *v1, const Collection<V2> &col, Double_t maxR,
103 Bool_t self)
104 {
105 // Return closest geometrical neighbors in eta-phi within maximum DeltaR of maxR.
106 // If self is kFALSE make sure that identical pointers are excluded.
107
108 if (!v1)
109 return 0;
110
111 TObjArray *res = new TObjArray;
112 res->SetOwner(kFALSE);
113 const UInt_t ents = col.GetEntries();
114 for (UInt_t i = 0; i<ents; ++i) {
115 const V2 *v2 = col.At(i);
116 if (!v2)
117 continue;
118 if (!self && (void*)v1==(void*)v2)
119 continue;
120 Double_t diff = MathUtils::DeltaR(*v1,*v2);
121 if (diff<maxR)
122 res->Add(const_cast<V2*>(v2));
123 }
124 return res;
125 }
126 }
127 #endif