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