ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Utils/interface/MatchingTools.h
Revision: 1.5
Committed: Mon Jul 20 04:55:33 2009 UTC (15 years, 9 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_029c, Mit_029b, Mit_029a, Mit_028a, Mit_028, Mit_027, Mit_027a, Mit_025e, Mit_025d, Mit_025c, Mit_025b, Mit_025a, Mit_025, Mit_025pre2, Mit_024b, Mit_025pre1, Mit_024a, Mit_024, Mit_023, Mit_022a, Mit_022, Mit_020d, TMit_020d, Mit_020c, Mit_021, Mit_021pre2, Mit_021pre1, Mit_020b, Mit_020a, Mit_020, Mit_020pre1, Mit_018, Mit_017, Mit_017pre3, Mit_017pre2, Mit_017pre1, Mit_016, Mit_015b, Mit_015a, Mit_015, Mit_014e, Mit_014d, Mit_014c, Mit_014b, Mit_014a, Mit_014, Mit_014pre3, Mit_014pre2, Mit_014pre1, Mit_013d, Mit_013c, Mit_013b, Mit_013a, Mit_013, Mit_013pre1, Mit_012i, Mit_012g, Mit_012f, Mit_012e, Mit_012d, Mit_012c, Mit_012b, Mit_012a, Mit_012, Mit_011a, Mit_011, Mit_010a, Mit_010, HEAD
Changes since 1.4: +3 -1 lines
Log Message:
Changes for docu

File Contents

# User Rev Content
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