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

# User Rev Content
1 loizides 1.1 //--------------------------------------------------------------------------------------------------
2 loizides 1.4 // $Id: MatchingTools.h,v 1.3 2009/06/18 16:51:04 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.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 loizides 1.4 // Return closest geometrical neighbor in eta-phi within maximum DeltaR 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.4 const V2 *MatchingTools::Closest(const V1 *v1, const Collection<V2> &col, Double_t maxR,
68     Double_t maxPtDiff, Bool_t self)
69 loizides 1.1 {
70 loizides 1.4 // 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 loizides 1.2 // If self is kFALSE make sure that identical pointers are excluded.
73 loizides 1.1
74 loizides 1.2 if (!v1)
75     return 0;
76    
77 loizides 1.1 const V2 *res = 0;
78     const UInt_t ents = col.GetEntries();
79     if (ents>0) {
80 loizides 1.4 Double_t dR = 1e30;
81 loizides 1.1 for (UInt_t i = 0; i<ents; ++i) {
82     const V2 *v2 = col.At(i);
83 loizides 1.2 if (!v2)
84     continue;
85     if (!self && (void*)v1==(void*)v2)
86     continue;
87 loizides 1.4 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 loizides 1.1 res = v2;
93 loizides 1.4 dR = diff;
94 loizides 1.1 }
95     }
96     }
97     return res;
98     }
99 loizides 1.2
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 loizides 1.4 // Return closest geometrical neighbors in eta-phi within maximum DeltaR of maxR.
106 loizides 1.2 // 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 loizides 1.1 }
127     #endif