ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Utils/interface/MatchingTools.h
Revision: 1.1
Committed: Mon May 11 08:01:51 2009 UTC (15 years, 11 months ago) by loizides
Content type: text/plain
Branch: MAIN
Log Message:
Added matching tools

File Contents

# Content
1 //--------------------------------------------------------------------------------------------------
2 // $Id: MatchingTools.h,v 1.3 2009/02/17 06:49:01 phedex Exp $
3 //
4 // MatchingTools
5 //
6 //
7 //
8 // Authors: C.Loizides
9 //--------------------------------------------------------------------------------------------------
10
11 #ifndef MITPHYSICS_UTILS_MATCHINGTOOLS_H
12 #define MITPHYSICS_UTILS_MATCHINGTOOLS_H
13
14 #include <TMath.h>
15 #include "MitCommon/MathTools/interface/MathUtils.h"
16 #include "MitAna/DataCont/interface/Collection.h"
17
18 namespace mithep
19 {
20 class MatchingTools {
21 public:
22 template<class V1, class V2>
23 static const V2 *Closest(const V1 *v1, const Collection<V2> &col, Double_t maxR);
24 template<class V1, class V2>
25 static const V2 *ClosestEtaPhiPt(const V1 *v1, const Collection<V2> &col, Double_t max);
26 };
27
28 //------------------------------------------------------------------------------------------------
29 template<class V1, class V2>
30 const V2 *MatchingTools::Closest(const V1 *v1, const Collection<V2> &col, Double_t maxR)
31 {
32 // Return closest geometrical neighbor in eta-phi within maximum delta R of maxR.
33
34 const V2 *res = 0;
35
36 const UInt_t ents = col.GetEntries();
37 if (ents>0) {
38 Double_t dR = 1e30;
39 for (UInt_t i = 0; i<ents; ++i) {
40 const V2 *v2 = col.At(i);
41 Double_t diff = MathUtils::DeltaR(*v1,*v2);
42 if ((diff<maxR) && (diff<dR)) {
43 res = v2;
44 dR = diff;
45 }
46 }
47 }
48 return res;
49 }
50
51 //------------------------------------------------------------------------------------------------
52 template<class V1, class V2>
53 const V2 *MatchingTools::ClosestEtaPhiPt(const V1 *v1, const Collection<V2> &col, Double_t max)
54 {
55 // Return closest geometrical neighbor in eta-phi-pt within maximum delta of max.
56
57 const V2 *res = 0;
58
59 const UInt_t ents = col.GetEntries();
60 if (ents>0) {
61 Double_t d = 1e30;
62 for (UInt_t i = 0; i<ents; ++i) {
63 const V2 *v2 = col.At(i);
64 Double_t diff = MathUtils::DeltaR2(*v1,*v2);
65 Double_t ptd = 1-v1->Pt()/v2->Pt();
66 diff += ptd*ptd;
67 diff = TMath::Sqrt(diff);
68 if ((diff<max) && (diff<d)) {
69 res = v2;
70 d = diff;
71 }
72 }
73 }
74 return res;
75 }
76 }
77 #endif