ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Trigger
TrigAnalysis
TrigInDetAnalysisUtils
TrigInDetAnalysisUtils
BestMatcher.h
Go to the documentation of this file.
1
/* emacs: this is -*- c++ -*- */
14
15
16
#ifndef BESTMATCHER_H
17
#define BESTMATCHER_H
18
19
#include <iostream>
20
#include <set>
21
22
23
#include "
TrigInDetAnalysis/TIDAAssociator.h
"
24
25
26
27
28
template
<
typename
T,
typename
S=T>
29
class
BestMatcher
:
public
TIDA::Associator
<T,S> {
30
31
protected
:
32
35
36
class
matched_
{
37
38
public
:
39
40
matched_
(
double
d
,
int
i,
int
j) :
m_d
(
d
),
m_match
(
std
::
pair
<int,int>(i,j)) { }
41
42
double
d
()
const
{
return
m_d
; }
43
44
std::pair<int, int>
pair
()
const
{
return
m_match
; }
45
46
int
first
()
const
{
return
m_match
.first; }
47
int
second
()
const
{
return
m_match
.second; }
48
49
bool
operator<
(
const
matched_
&
a
)
const
{
return
d
()<
a
.d(); }
50
bool
operator>
(
const
matched_
&
a
)
const
{
return
d
()>
a
.d(); }
51
bool
operator==
(
const
matched_
&
a
)
const
{
return
d
()==
a
.d(); }
52
bool
operator!=
(
const
matched_
&
a
)
const
{
return
d
()!=
a
.d(); }
53
54
private
:
55
double
m_d
;
56
std::pair<int, int>
m_match
;
57
};
58
59
public
:
60
61
BestMatcher
(
const
std::string& name,
double
d) :
62
TIDA
::
Associator
<T,S>(name),
m_d
(d)
63
{ }
64
65
virtual
~BestMatcher
() { }
66
67
68
virtual
void
match
(
const
std::vector<T*>&
ref
,
const
std::vector<S*>& test )
69
{
70
this->
clear
();
71
72
std::map<int,int>
matched
=
matcher
(
ref
, test);
73
74
std::map<int,int>::iterator mitr =
matched
.begin();
75
while
( mitr!=
matched
.end() ) {
76
this->
mmatched
.insert(
typename
TIDA::Associator<T,S>::map_type::value_type
(
ref
[mitr->first], test[mitr->second]) );
77
this->
mrevmatched
.insert(
typename
TIDA::Associator<S,T>::map_type::value_type
( test[mitr->second],
ref
[mitr->first] ) );
78
++mitr;
79
}
80
81
}
82
83
84
virtual
double
distance
(
const
T*
t0
,
const
S* t1 )
const
= 0;
85
86
87
protected
:
88
89
90
template
<
typename
Tp,
typename
Tq>
91
std::map<int, int>
matcher
(
const
std::vector<Tp*>&
ref
,
const
std::vector<Tq*>& test) {
92
98
99
std::multiset<matched_> m;
100
101
for
(
unsigned
int
i=0 ; i<
ref
.size() ; i++ ) {
102
103
for
(
unsigned
int
j=0 ; j<test.size() ; j++ ) {
104
double
d =
distance
(
ref
[i], test[j]);
105
if
( d<
m_d
){
106
m.insert( matched_(d, i, j) );
107
}
108
}
109
}
110
114
115
std::vector<bool> refused(
ref
.size(),
false
);
116
std::vector<bool> testused( test.size(),
false
);
117
122
std::multiset<matched_> unique;
123
124
typename
std::multiset<matched_>::iterator mitr = m.begin();
125
126
for
( ; mitr!=m.end() ; ++mitr ) {
127
128
int
rind = mitr->first();
129
int
tind = mitr->second();
130
131
if
( refused[rind] )
continue
;
132
if
( testused[tind] )
continue
;
133
134
refused[rind] =
true
;
135
testused[tind] =
true
;
136
137
unique.insert( *mitr );
138
}
139
140
141
// std::cout << "chi2 of matches " << chi2 << std::endl;
142
146
147
// std::cout << "\nmatched" << std::endl;
148
149
std::map<int, int> matches;
150
151
152
mitr = unique.begin();
153
while
( mitr!=unique.end() ) {
154
matches.insert( std::map<int, int>::value_type( mitr->first(), mitr->second() ) );
155
// std::cout << "\tbest match " << *mitr << "\t" << ref[mitr->first()] << "\t" << test[mitr->second()] << std::endl;
156
++mitr;
157
}
158
159
return
matches;
160
161
}
162
163
164
protected
:
165
166
double
m_d
;
167
168
};
169
170
171
172
#endif
// MATCH_H
173
174
175
176
177
178
179
180
181
182
ref
const std::regex ref(r_ef)
a
static Double_t a
Definition
LArPhysWaveHECTool.cxx:38
t0
static Double_t t0
Definition
LArPhysWaveHECTool.cxx:38
TIDAAssociator.h
BestMatcher::matched_::operator!=
bool operator!=(const matched_ &a) const
Definition
BestMatcher.h:52
BestMatcher::matched_::first
int first() const
Definition
BestMatcher.h:46
BestMatcher::matched_::d
double d() const
Definition
BestMatcher.h:42
BestMatcher::matched_::operator>
bool operator>(const matched_ &a) const
Definition
BestMatcher.h:50
BestMatcher::matched_::m_match
std::pair< int, int > m_match
Definition
BestMatcher.h:56
BestMatcher::matched_::operator<
bool operator<(const matched_ &a) const
Definition
BestMatcher.h:49
BestMatcher::matched_::matched_
matched_(double d, int i, int j)
Definition
BestMatcher.h:40
BestMatcher::matched_::m_d
double m_d
Definition
BestMatcher.h:55
BestMatcher::matched_::operator==
bool operator==(const matched_ &a) const
Definition
BestMatcher.h:51
BestMatcher::matched_::second
int second() const
Definition
BestMatcher.h:47
BestMatcher::matched_::pair
std::pair< int, int > pair() const
Definition
BestMatcher.h:44
BestMatcher::match
virtual void match(const std::vector< T * > &ref, const std::vector< S * > &test)
Definition
BestMatcher.h:68
BestMatcher::distance
virtual double distance(const T *t0, const S *t1) const =0
BestMatcher::matcher
std::map< int, int > matcher(const std::vector< Tp * > &ref, const std::vector< Tq * > &test)
Definition
BestMatcher.h:91
BestMatcher::BestMatcher
BestMatcher(const std::string &name, double d)
Definition
BestMatcher.h:61
BestMatcher< TIDA::Track >::m_d
double m_d
Definition
BestMatcher.h:166
BestMatcher::~BestMatcher
virtual ~BestMatcher()
Definition
BestMatcher.h:65
TIDA::Associator
Definition
TIDAAssociator.h:26
BestMatcher< TIDA::Track >::mmatched
map_type mmatched
Definition
TIDAAssociator.h:75
TIDA::Associator< T, T >::clear
void clear()
Definition
TIDAAssociator.h:65
BestMatcher< TIDA::Track >::matched
virtual const TIDA::Track * matched(TIDA::Track *t) const
Definition
TIDAAssociator.h:47
BestMatcher< TIDA::Track >::mrevmatched
rmap_type mrevmatched
Definition
TIDAAssociator.h:76
TIDA::Associator::Associator
Associator(const std::string &name)
Definition
TIDAAssociator.h:35
TIDA
Test for xAOD.
Definition
Filter_AcceptAll.h:22
std
STL namespace.
Generated on
for ATLAS Offline Software by
1.17.0