ATLAS Offline Software
MatchingImplementation.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 #include <utility>
9 
10 namespace Trig {
11 
12 MatchingImplementation::MatchingImplementation(MatchingTool& mt, double threshold) : asg::AsgMessaging("MatchingImplementation"), m_tool(mt), m_threshold(threshold) {
13  m_strategies[Trig::MatchingStrategy::MinimalSum] = std::unique_ptr<IAssociationStrategy>(new MinimalSumAssociation());
14 }
15 
17  return std::as_const(m_tool).m_trigDecTool.operator->();
18 }
19 
20  bool MatchingImplementation::assocIsMatched(const IAssociationStrategy::index_assignment_t& association, const std::vector<std::vector<double> >& matrix, double threshold) const {
21  int ndim = matrix.size();
22  if(!ndim) return false;
23 
24  bool result = true;
25  for(auto trig_reco : association){
26  double distance = matrix[trig_reco.first][trig_reco.second];
27  bool single_assoc = distance < threshold;
28  result = result && single_assoc;
29  ATH_MSG_DEBUG("reco: " << trig_reco.first << " associated to trig: " << trig_reco.second <<
30  " with distance: " << distance << " ok: " << single_assoc << " overall: " << result);
31  }
32  return result;
33 }
34 
35  bool MatchingImplementation::matchDistanceMatrix(const std::vector<std::vector<double> >& matrix, const Trig::MatchingStrategy::Strategy strategy, double threshold) const {
36  int nrows = matrix.size();
37  int ncols = matrix.at(0).size();
38 
39  ATH_MSG_DEBUG("matching a " << nrows << "x" << ncols << "matrix now");
40 
41 
42  auto MSG_MATRIX = MSG::DEBUG;
43  if(msgLvl(MSG_MATRIX)){
44  msg() << MSG_MATRIX << "===========" << endmsg;
45  for(auto& row : matrix){
46  msg() << MSG_MATRIX << "|";
47  for(auto distance : row){
48  msg() << MSG_MATRIX << distance << " , ";
49  }
50  msg() << MSG_MATRIX << "|" << endmsg;
51  }
52  msg() << MSG_MATRIX << "===========" << endmsg;
53  }
54 
55 
56  //require that every row contains an entry that is smaller than threshold, otherwise matching will obviously fail
57  for(auto& row : matrix) {
58  bool rowOk=false;
59  for(auto distance : row) {
60  if( distance < threshold ) { rowOk = true; break; }
61  }
62  if(!rowOk) {
63  ATH_MSG_DEBUG("row of matrix does not contain any distance below threshold. Return false"); return false;
64  }
65  }
66 
67  auto association_map = m_strategies.at(strategy)->associate(matrix);
68  return assocIsMatched(association_map,matrix,threshold);
69 }
70 
71 }
xAOD::strategy
strategy
Definition: L2CombinedMuon_v1.cxx:107
query_example.row
row
Definition: query_example.py:24
get_generator_info.result
result
Definition: get_generator_info.py:21
asg::AsgMessaging::msgLvl
bool msgLvl(const MSG::Level lvl) const
Test the output level of the object.
Definition: AsgMessaging.cxx:41
Trig
The common trigger namespace for trigger analysis tools.
Definition: CaloTowerVecMon.h:44
Trig::MatchingStrategy::Strategy
Strategy
Definition: MatchingImplementation.h:26
Trig::MatchingImplementation::m_tool
MatchingTool & m_tool
Definition: MatchingImplementation.h:41
asg
Definition: DataHandleTestTool.h:28
Trig::MatchingTool
Definition: MatchingTool.h:23
Trig::distance
int distance(const BunchCrossing bc1, const BunchCrossing bc2)
I need this function only for technical reasons.
Definition: BunchCrossing.cxx:402
Trig::MatchingImplementation::matchDistanceMatrix
bool matchDistanceMatrix(const std::vector< std::vector< double > > &matrix, const Trig::MatchingStrategy::Strategy strategy=Trig::MatchingStrategy::MinimalSum, double threshold=0.0) const
Definition: MatchingImplementation.cxx:35
Trig::TrigDecisionTool
Definition: TrigDecisionTool.h:65
IAssociationStrategy::index_assignment_t
std::map< unsigned int, unsigned int > index_assignment_t
Definition: IAssociationStrategy.h:16
Trig::MatchingStrategy::MinimalSum
@ MinimalSum
Definition: MatchingImplementation.h:27
Trig::MatchingImplementation::MatchingImplementation
MatchingImplementation(MatchingTool &mt, double threshold=0.4)
Definition: MatchingImplementation.cxx:12
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
MinimalSumAssociation
Definition: MinimalSumAssociation.h:14
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Trk::association
@ association
Definition: TrackingGeometry.h:46
asg::AsgMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AsgMessaging.cxx:49
Trig::MatchingImplementation::assocIsMatched
bool assocIsMatched(const IAssociationStrategy::index_assignment_t &association, const std::vector< std::vector< double > > &matrix, double threshold) const
Definition: MatchingImplementation.cxx:20
MatchingImplementation.h
Trig::MatchingImplementation::m_strategies
std::map< Trig::MatchingStrategy::Strategy, std::unique_ptr< IAssociationStrategy > > m_strategies
Definition: MatchingImplementation.h:42
MatchingTool.h
threshold
Definition: chainparser.cxx:74
Trig::MatchingImplementation::tdt
const Trig::TrigDecisionTool * tdt() const
Definition: MatchingImplementation.cxx:16
python.testIfMatch.matrix
matrix
Definition: testIfMatch.py:66
DEBUG
#define DEBUG
Definition: page_access.h:11
MinimalSumAssociation.h
dumpTgcDigiThreshold.threshold
list threshold
Definition: dumpTgcDigiThreshold.py:34