ATLAS Offline Software
Loading...
Searching...
No Matches
Associator_DeltaR.h
Go to the documentation of this file.
1/* emacs: this is -*- c++ -*- */
10
11
13
14
15#if 0
16
17#ifndef TrigInDetAnalysisUtils_Associator_DeltaR_H
18#define TrigInDetAnalysisUtils_Associator_DeltaR_H
19
20
21#include <iostream>
22#include <string>
23#include <cmath>
24#include <map>
25
28
29
30
31
32
33class Associator_DeltaR : public TrackAssociator {
34
35public:
36
37 Associator_DeltaR(const std::string& name, double deltaR) : TrackAssociator(name), m_deltaR2(deltaR*deltaR) {}
38
39 ~Associator_DeltaR() { }
40
41 virtual TrackAssociator* clone() override { return new Associator_DeltaR(*this); }
42
43 virtual void match(const std::vector<TIDA::Track*>& referenceTracks,
44 const std::vector<TIDA::Track*>& testTracks) {
45
46 // Clear previously filled association map
47 clear();
48
49 // Loop over reference tracks
50 std::vector<TIDA::Track*>::const_iterator reference, referenceEnd=referenceTracks.end();
51 for(reference=referenceTracks.begin(); reference!=referenceEnd; reference++) {
52
53 // Loop over test tracks and find the closest
54 TIDA::Track* bestMatch = NULL;
55 double bestDeltaR=1000;
56
57 std::vector<TIDA::Track*>::const_iterator test, testEnd=testTracks.end();
58 for(test=testTracks.begin(); test!=testEnd; test++) {
59
60 // Evaluate distance between reference and test tracks
61 double deta = (*reference)->eta() - (*test)->eta();
62 double dphi = (*reference)->phi() - (*test)->phi();
63 if(dphi>M_PI) dphi-=2*M_PI;
64 if(dphi<-M_PI) dphi+=2*M_PI;
65 double deltaR = deta*deta+dphi*dphi;
66
67 // Check if this is the best match so far
68 if(bestMatch==NULL || deltaR<bestDeltaR) {
69 bestDeltaR = deltaR;
70 bestMatch = (*test);
71 }
72 }
73
74 // Check if the best match is within delta R specifications
75 if(bestMatch && bestDeltaR<m_deltaR2) {
76 // Create reference->test and test->reference associations
77 mmatched.insert(map_type::value_type(*reference, bestMatch));
78 mrevmatched.insert(map_type::value_type(bestMatch, *reference));
79 }
80 }
81 }
82
83private:
84
85 double m_deltaR2;
86
87};
88
89#endif // TrigInDetAnalysisUtils_Associator_DeltaR_H
90
91#endif
#define M_PI
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