ATLAS Offline Software
Loading...
Searching...
No Matches
Associator_DeltaEtaPhi.h
Go to the documentation of this file.
1/* emacs: this is -*- c++ -*- */
10
11#if 0
12
15
16
18
19
20
21
22#ifndef TrigInDetAnalysisUtils_Associator_DeltaEtaPhi_H
23#define TrigInDetAnalysisUtils_Associator_DeltaEtaPhi_H
24
25
26#include <iostream>
27#include <string>
28#include <cmath>
29#include <map>
30
33
34
35class Associator_DeltaEtaPhi : public TrackAssociator {
36
37public:
38
39 Associator_DeltaEtaPhi(const std::string& name, double deltaEta, double deltaPhi) : TrackAssociator(name), m_deltaEta(deltaEta), m_deltaPhi(deltaPhi) {}
40
41 ~Associator_DeltaEtaPhi() { }
42
43 virtual TrackAssociator* clone() override { return new Associator_DeltaEtaPhi(*this); }
44
45 virtual void match(const std::vector<TIDA::Track*>& referenceTracks,
46 const std::vector<TIDA::Track*>& testTracks) {
47
48 // Clear previously filled association map
49 clear();
50
51
52 // Loop over reference tracks
53 std::vector<TIDA::Track*>::const_iterator reference, referenceEnd=referenceTracks.end();
54 for(reference=referenceTracks.begin(); reference!=referenceEnd; reference++) {
55
56 // std::cout << "Offline = " << (*reference)->eta() << " " << (*reference)->phi() << " " << (*reference)->pT() << std::endl;
57
58 // Loop over test tracks and find the closest
59 TIDA::Track* bestMatch = NULL;
60 double bestDeltaR=1000;
61
62 std::vector<TIDA::Track*>::const_iterator test, testEnd=testTracks.end();
63 for(test=testTracks.begin(); test!=testEnd; test++) {
64
65 // Evaluate distance between reference and test tracks
66 double deta = (*reference)->eta() - (*test)->eta();
67 double dphi = (*reference)->phi() - (*test)->phi();
68 if(dphi>M_PI) dphi-=2*M_PI;
69 if(dphi<-M_PI) dphi+=2*M_PI;
70
71 if (fabs(deta)>m_deltaEta || fabs(dphi)>m_deltaPhi) continue;
72
73 double deltaR = (deta*deta)/(m_deltaEta*m_deltaEta)+(dphi*dphi)/(m_deltaPhi*m_deltaPhi);
74
75 // Check if this is the best match so far
76 if(bestMatch==NULL || deltaR<bestDeltaR) {
77 bestDeltaR = deltaR;
78 bestMatch = (*test);
79 }
80 }
81
82 // Check if the best match is within delta R specifications
83 if(bestMatch) {
84 // Create reference->test and test->reference associations
85 mmatched.insert(map_type::value_type(*reference, bestMatch));
86 mrevmatched.insert(map_type::value_type(bestMatch, *reference));
87 //std::cout << "Matched = " << bestMatch->eta() << " "<< bestMatch->phi() << " " << bestMatch->pT() << std::endl;
88 }
89 }
90 }
91
92private:
93
94 double m_deltaEta;
95 double m_deltaPhi;
96
97};
98
99
100#endif // TrigInDetAnalysisUtils_Associator_DeltaEtaPhi_H
101
102#endif
#define M_PI
Scalar deltaPhi(const MatrixBase< Derived > &vec) const
Scalar deltaR(const MatrixBase< Derived > &vec) const
TIDA::Associator< TIDA::Track > TrackAssociator
virtual Associator * clone()=0
virtual void match(const std::vector< TIDA::Track * > &s1, const std::vector< TIDA::Track * > &s2)=0
double deltaEta(const I4Momentum &p1, const I4Momentum &p2)
Computes efficiently .
Definition P4Helpers.h:66