ATLAS Offline Software
MuonMatchingTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <utility>
6 
7 
8 
9 #include "MuonMatchingTool.h"
11 
12 const static double ZERO_LIMIT = 1.e-5;
13 
14 MuonMatchingTool :: MuonMatchingTool(const std::string& type, const std::string& name, const IInterface* parent)
16 {}
17 
18 
20 
21  ATH_CHECK( m_trigDec.retrieve() );
23  ATH_CHECK( m_extrapolator.retrieve() );
24  }
25  ATH_CHECK( m_MuonContainerKey.initialize() );
26  ATH_CHECK( m_MuonRoIContainerKey.initialize() );
27  ATH_CHECK( m_L2MuonSAContainerKey.initialize() );
28  ATH_CHECK( m_L2muCombContainerKey.initialize() );
29  ATH_CHECK( m_EFSAMuonContainerKey.initialize() );
30  ATH_CHECK( m_EFCBMuonContainerKey.initialize() );
31  ATH_CHECK( m_EFSAFSMuonContainerKey.initialize() );
32  ATH_CHECK( m_EFCBFSMuonContainerKey.initialize() );
35 
36  return StatusCode::SUCCESS;
37 }
38 
39 
41  const xAOD::TrackParticle* track = mu->primaryTrackParticle();
42  std::unique_ptr<const Trk::TrackParameters> extPars(extTrackToPivot(track));
43  return extPars ? extPars->position() : Amg::Vector3D(0.,0.,0.);
44 }
45 
46 
47 template<>
48 std::tuple<bool, double,double> MuonMatchingTool :: trigPosForMatch<xAOD::L2StandAloneMuon>(const xAOD::L2StandAloneMuon *trig){
49  return std::forward_as_tuple(true, trig->roiEta(), trig->roiPhi());
50 }
51 
52 
53 std::tuple<bool, double,double> MuonMatchingTool :: trigPosForMatchSATrack(const xAOD::Muon *mu){
54  return mu->muonType() == xAOD::Muon::MuonType::MuonStandAlone ? std::forward_as_tuple(true, mu->eta(), mu->phi()) : std::forward_as_tuple(false, 0., 0.);
55 }
56 
57 std::tuple<bool, double,double> MuonMatchingTool :: trigPosForMatchCBTrack(const xAOD::Muon *mu){
58  return mu->muonType() == xAOD::Muon::MuonType::Combined ? std::forward_as_tuple(true, mu->eta(), mu->phi()) : std::forward_as_tuple(false, 0., 0.);
59 }
60 
61 std::tuple<bool, double,double> MuonMatchingTool :: PosForMatchSATrack(const xAOD::Muon *mu){
62  const xAOD::TrackParticle* MuonTrack = mu->trackParticle(xAOD::Muon::TrackParticleType::ExtrapolatedMuonSpectrometerTrackParticle);
63  return MuonTrack ? std::forward_as_tuple(true, MuonTrack->eta(), MuonTrack->phi()) : std::forward_as_tuple(false, 0., 0.);
64 }
65 
66 std::tuple<bool, double,double> MuonMatchingTool :: PosForMatchCBTrack(const xAOD::Muon *mu){
67  const xAOD::TrackParticle* MuonTrack = mu->trackParticle(xAOD::Muon::TrackParticleType::CombinedTrackParticle);
68  return MuonTrack ? std::forward_as_tuple(true, MuonTrack->eta(), MuonTrack->phi()) : std::forward_as_tuple(false, 0., 0.);
69 }
70 
71 
72 const xAOD::Muon* MuonMatchingTool :: matchEFSA(const xAOD::Muon *mu, std::string trig, bool &pass) const {
73  ATH_MSG_DEBUG("MuonMonitoring::matchEFSA()");
74  const xAOD::TrackParticle* MuonTrack = nullptr;
75  using Type = xAOD::Muon::TrackParticleType;
76  std::vector<Type> types { Type::ExtrapolatedMuonSpectrometerTrackParticle,
77  Type::MSOnlyExtrapolatedMuonSpectrometerTrackParticle,
78  Type::MuonSpectrometerTrackParticle};
79  for (Type type : types){
80  MuonTrack = mu->trackParticle(type);
81  ATH_MSG_DEBUG("HLT_Muons_RoI SA Muon");
82  if (MuonTrack) break;
83  }
84  return MuonTrack ? match<xAOD::Muon>(MuonTrack, std::move(trig), m_EFreqdR, pass, "HLT_Muons_RoI.*", &MuonMatchingTool::trigPosForMatchSATrack) : nullptr;
85 }
86 
87 const xAOD::Muon* MuonMatchingTool :: matchEFSA(const xAOD::TruthParticle *mu, std::string trig, bool &pass) const {
88  ATH_MSG_DEBUG("MuonMonitoring::matchEFSA() for truth particle");
89  return mu ? match<xAOD::Muon>(mu, std::move(trig), m_EFreqdR, pass, "HLT_Muons_RoI.*", &MuonMatchingTool::trigPosForMatchSATrack) : nullptr;
90 }
91 
93  ATH_MSG_DEBUG("MuonMonitoring::matchEFSALinkInfo()");
94  bool pass = false;
96  const xAOD::TrackParticle* MuonTrack = nullptr;
97  using Type = xAOD::Muon::TrackParticleType;
98  std::vector<Type> types { Type::ExtrapolatedMuonSpectrometerTrackParticle,
99  Type::MSOnlyExtrapolatedMuonSpectrometerTrackParticle,
100  Type::MuonSpectrometerTrackParticle};
101  for (Type type : types){
102  MuonTrack = mu->trackParticle(type);
103  if (MuonTrack) break;
104  }
105  return MuonTrack ? matchLinkInfo<xAOD::Muon>(MuonTrack, std::move(trig), m_EFreqdR, pass, "HLT_Muons_RoI.*", &MuonMatchingTool::trigPosForMatchSATrack) : muonLinkInfo;
106 }
107 
108 const xAOD::Muon* MuonMatchingTool :: matchEFSAReadHandle( const EventContext& ctx, const xAOD::Muon *mu) const {
109  ATH_MSG_DEBUG("MuonMonitoring::matchEFSAReadHandle()");
110  const xAOD::TrackParticle* MuonTrack = nullptr;
111  using Type = xAOD::Muon::TrackParticleType;
112  std::vector<Type> types { Type::ExtrapolatedMuonSpectrometerTrackParticle,
113  Type::MSOnlyExtrapolatedMuonSpectrometerTrackParticle,
114  Type::MuonSpectrometerTrackParticle};
115  for (Type type : types){
116  MuonTrack = mu->trackParticle(type);
117  if (MuonTrack) break;
118  }
119  return MuonTrack ? matchReadHandle<xAOD::Muon>( MuonTrack, m_EFreqdR, m_EFSAMuonContainerKey, ctx, &MuonMatchingTool::trigPosForMatchSATrack) : nullptr;
120 }
121 
122 const xAOD::Muon* MuonMatchingTool :: matchEFCB( const xAOD::TruthParticle *mu, std::string trig, bool &pass) const {
123  ATH_MSG_DEBUG("MuonMonitoring::matchEFCB() for TruthParticle");
124  return mu ? match<xAOD::Muon>( mu, std::move(trig), m_EFreqdR, pass, "HLT_MuonsCB_RoI.*", &MuonMatchingTool::trigPosForMatchCBTrack) : nullptr;
125 }
126 
127 const xAOD::Muon* MuonMatchingTool :: matchEFCB( const xAOD::Muon *mu, std::string trig, bool &pass) const {
128  ATH_MSG_DEBUG("MuonMonitoring::matchEFCB()");
129  const xAOD::TrackParticle* MuonTrack = mu->trackParticle(xAOD::Muon::TrackParticleType::Primary);
130  ATH_MSG_DEBUG("HLT_Muons_RoI CB Muon");
131  return MuonTrack ? match<xAOD::Muon>( MuonTrack, std::move(trig), m_EFreqdR, pass, "HLT_MuonsCB_RoI.*", &MuonMatchingTool::trigPosForMatchCBTrack) : nullptr;
132 }
133 
135  ATH_MSG_DEBUG("MuonMonitoring::matchEFCBLinkInfo()");
136  bool pass = false;
138  const xAOD::TrackParticle* MuonTrack = mu->trackParticle(xAOD::Muon::TrackParticleType::Primary);
139  return MuonTrack ? matchLinkInfo<xAOD::Muon>(MuonTrack, std::move(trig), m_EFreqdR, pass, "HLT_MuonsCB_RoI.*", &MuonMatchingTool::trigPosForMatchCBTrack) : muonLinkInfo;
140 }
141 
142 const xAOD::Muon* MuonMatchingTool :: matchEFCBReadHandle( const EventContext& ctx, const xAOD::Muon *mu) const {
143  ATH_MSG_DEBUG("MuonMonitoring::matchEFCBReadHandle()");
144  const xAOD::TrackParticle* MuonTrack = mu->trackParticle(xAOD::Muon::TrackParticleType::Primary);
145  return MuonTrack ? matchReadHandle<xAOD::Muon>( MuonTrack, m_EFreqdR, m_EFCBMuonContainerKey, ctx, &MuonMatchingTool::trigPosForMatchCBTrack) : nullptr;
146 }
147 
148 const xAOD::Muon* MuonMatchingTool :: matchEFSAFS(const xAOD::Muon *mu, std::string trig, bool &pass) const {
149  ATH_MSG_DEBUG("MuonMonitoring::matchEFSAFS()");
150  const xAOD::TrackParticle* MuonTrack = nullptr;
151  using Type = xAOD::Muon::TrackParticleType;
152  std::vector<Type> types { Type::ExtrapolatedMuonSpectrometerTrackParticle,
153  Type::MSOnlyExtrapolatedMuonSpectrometerTrackParticle,
154  Type::MuonSpectrometerTrackParticle};
155  for (Type type : types){
156  MuonTrack = mu->trackParticle(type);
157  ATH_MSG_DEBUG("HLT_Muons_FS SA Muon");
158  if (MuonTrack) break;
159  }
160  return MuonTrack ? match<xAOD::Muon>(MuonTrack, std::move(trig), m_EFreqdR, pass, "HLT_Muons_FS.*", &MuonMatchingTool::trigPosForMatchSATrack) : nullptr;
161 }
162 
163 const xAOD::Muon* MuonMatchingTool :: matchEFSAFS(const xAOD::TruthParticle *mu, std::string trig, bool &pass) const {
164  ATH_MSG_DEBUG("MuonMonitoring::matchEFSAFS() for truth particle");
165  return mu ? match<xAOD::Muon>(mu, std::move(trig), m_EFreqdR, pass, "HLT_Muons_FS.*", &MuonMatchingTool::trigPosForMatchSATrack) : nullptr;
166 }
167 
169  ATH_MSG_DEBUG("MuonMonitoring::matchEFSAFSLinkInfo()");
170  bool pass = false;
172  const xAOD::TrackParticle* MuonTrack = nullptr;
173  using Type = xAOD::Muon::TrackParticleType;
174  std::vector<Type> types { Type::ExtrapolatedMuonSpectrometerTrackParticle,
175  Type::MSOnlyExtrapolatedMuonSpectrometerTrackParticle,
176  Type::MuonSpectrometerTrackParticle};
177  for (Type type : types){
178  MuonTrack = mu->trackParticle(type);
179  if (MuonTrack) break;
180  }
181  return MuonTrack ? matchLinkInfo<xAOD::Muon>(MuonTrack, std::move(trig), m_EFreqdR, pass, "HLT_Muons_FS.*", &MuonMatchingTool::trigPosForMatchSATrack) : muonLinkInfo;
182 }
183 
184 const xAOD::Muon* MuonMatchingTool :: matchEFSAFSReadHandle( const EventContext& ctx, const xAOD::Muon *mu) const {
185  ATH_MSG_DEBUG("MuonMonitoring::matchEFSAFSReadHandle()");
186  const xAOD::TrackParticle* MuonTrack = nullptr;
187  using Type = xAOD::Muon::TrackParticleType;
188  std::vector<Type> types { Type::ExtrapolatedMuonSpectrometerTrackParticle,
189  Type::MSOnlyExtrapolatedMuonSpectrometerTrackParticle,
190  Type::MuonSpectrometerTrackParticle};
191  for (Type type : types){
192  MuonTrack = mu->trackParticle(type);
193  if (MuonTrack) break;
194  }
195  return MuonTrack ? matchReadHandle<xAOD::Muon>( MuonTrack, m_EFreqdR, m_EFSAFSMuonContainerKey, ctx, &MuonMatchingTool::trigPosForMatchSATrack) : nullptr;
196 }
197 
198 const xAOD::Muon* MuonMatchingTool :: matchEFCBFS( const xAOD::TruthParticle *mu, std::string trig, bool &pass) const {
199  ATH_MSG_DEBUG("MuonMonitoring::matchEFCBFS() for TruthParticle");
200  return mu ? match<xAOD::Muon>( mu, std::move(trig), m_EFreqdR, pass, "HLT_MuonsCB_FS.*", &MuonMatchingTool::trigPosForMatchCBTrack) : nullptr;
201 }
202 
203 const xAOD::Muon* MuonMatchingTool :: matchEFCBFS( const xAOD::Muon *mu, std::string trig, bool &pass) const {
204  ATH_MSG_DEBUG("MuonMonitoring::matchEFCBFS()");
205  const xAOD::TrackParticle* MuonTrack = mu->trackParticle(xAOD::Muon::TrackParticleType::Primary);
206  ATH_MSG_DEBUG("HLT_Muons_FS CB Muon");
207  return MuonTrack ? match<xAOD::Muon>( MuonTrack, std::move(trig), m_EFreqdR, pass, "HLT_MuonsCB_FS.*", &MuonMatchingTool::trigPosForMatchCBTrack) : nullptr;
208 }
209 
211  ATH_MSG_DEBUG("MuonMonitoring::matchEFCBFSLinkInfo()");
212  bool pass = false;
214  const xAOD::TrackParticle* MuonTrack = mu->trackParticle(xAOD::Muon::TrackParticleType::Primary);
215  return MuonTrack ? matchLinkInfo<xAOD::Muon>(MuonTrack, std::move(trig), m_EFreqdR, pass, "HLT_MuonsCB_FS.*", &MuonMatchingTool::trigPosForMatchCBTrack) : muonLinkInfo;
216 }
217 
218 const xAOD::Muon* MuonMatchingTool :: matchEFCBFSReadHandle( const EventContext& ctx, const xAOD::Muon *mu) const {
219  ATH_MSG_DEBUG("MuonMonitoring::matchEFCBFSReadHandle()");
220  const xAOD::TrackParticle* MuonTrack = mu->trackParticle(xAOD::Muon::TrackParticleType::Primary);
221  return MuonTrack ? matchReadHandle<xAOD::Muon>( MuonTrack, m_EFreqdR, m_EFCBFSMuonContainerKey, ctx, &MuonMatchingTool::trigPosForMatchCBTrack) : nullptr;
222 }
223 
224 const xAOD::Muon* MuonMatchingTool :: matchEFIso( const xAOD::Muon *mu, std::string trig, bool &pass) const {
225  ATH_MSG_DEBUG("MuonMonitoring::matchEFIso()");
226  const xAOD::TrackParticle* MuonTrack = mu->trackParticle(xAOD::Muon::TrackParticleType::Primary);
227  return MuonTrack ? match<xAOD::Muon>( MuonTrack, std::move(trig), m_EFreqdR, pass, "HLT_MuonsIso", &MuonMatchingTool::trigPosForMatchCBTrack) : nullptr;
228 }
229 
230 const xAOD::Muon* MuonMatchingTool :: matchEFIso( const xAOD::TruthParticle *mu, std::string trig, bool &pass) const {
231  ATH_MSG_DEBUG("MuonMonitoring::matchEFIso() for truth particle");
232  return mu ? match<xAOD::Muon>( mu, std::move(trig), m_EFreqdR, pass, "HLT_MuonsIso", &MuonMatchingTool::trigPosForMatchCBTrack) : nullptr;
233 }
234 
235 
237  const xAOD::TrackParticle* MatchedTrack = nullptr;
238  const ElementLink<xAOD::MuonContainer> muEL = muLinkInfo.link;
239  float EFEta = (*muEL)->eta();
240  float EFPhi = (*muEL)->phi();
241  float mindR = 999.;
242 
243  SG::ReadHandle<xAOD::TrackParticleContainer> trackHandle(ReadHandleKey, ctx);
244  if ( !trackHandle.isValid() ) return MatchedTrack;
245 
246  const auto track = m_trigDec->associateToEventView<xAOD::TrackParticleContainer>(trackHandle, muLinkInfo);
249 
251 
252  float deta = EFEta - (*it)->eta();
253  float dphi = xAOD::P4Helpers::deltaPhi(EFPhi, (*it)->phi() );
254  float dR = std::sqrt(deta*deta + dphi*dphi);
255 
256  if( dR< mindR ){
257  mindR = dR;
258  MatchedTrack = (*it);
259  }
260  }
261 
262  return MatchedTrack;
263 
264 }
265 
267  ATH_MSG_DEBUG("MuonMonitoring::matchEFCBLinkInfo()");
268  bool pass = false;
270  const xAOD::TrackParticle* MuonTrack = mu->trackParticle(xAOD::Muon::TrackParticleType::Primary);
271  return MuonTrack ? matchLinkInfo<xAOD::Muon>(MuonTrack, std::move(trig), m_EFreqdR, pass, "HLT_MuonsIso", &MuonMatchingTool::trigPosForMatchCBTrack) : muonLinkInfo;
272 }
273 
274 
275 const xAOD::L2StandAloneMuon* MuonMatchingTool :: matchL2SA( const xAOD::Muon *mu, const std::string& trig, bool &pass) const {
276  ATH_MSG_DEBUG("MuonMonitoring::matchL2SA()");
277  float reqdR = m_L2SAreqdR;
278  if(m_use_extrapolator){
279  reqdR = reqdRL1byPt(mu->pt());
280  const Amg::Vector3D extPos = offlineMuonAtPivot(mu);
281  if(extPos.norm()>ZERO_LIMIT){
282  return match<xAOD::L2StandAloneMuon>( &extPos, trig, reqdR, pass);
283  }
284  }
285  return match<xAOD::L2StandAloneMuon>( mu, trig, reqdR, pass, "HLT_MuonL2SAInfo");
286 }
287 
289  ATH_MSG_DEBUG("MuonMonitoring::searchL2SALinkInfo()");
290  bool pass = false;
291  return matchLinkInfo<xAOD::L2StandAloneMuon>( mu, std::move(trig), 1000., pass, "HLT_MuonL2SAInfo");
292 }
293 
294 const xAOD::L2StandAloneMuon* MuonMatchingTool :: matchL2SAReadHandle( const EventContext& ctx, const xAOD::Muon *mu) const {
295  ATH_MSG_DEBUG("MuonMonitoring::matchL2SAReadHandle()");
296  float reqdR = m_L2SAreqdR;
297  if(m_use_extrapolator){
298  reqdR = reqdRL1byPt(mu->pt());
299  const Amg::Vector3D extPos = offlineMuonAtPivot(mu);
300  if(extPos.norm()>ZERO_LIMIT){
301  return matchReadHandle<xAOD::L2StandAloneMuon>( &extPos, reqdR, m_L2MuonSAContainerKey, ctx);
302  }
303  }
304  const xAOD::TrackParticle* MuonTrack = nullptr;
305  using Type = xAOD::Muon::TrackParticleType;
306  std::vector<Type> types { Type::ExtrapolatedMuonSpectrometerTrackParticle,
307  Type::MSOnlyExtrapolatedMuonSpectrometerTrackParticle,
308  Type::MuonSpectrometerTrackParticle};
309  for (Type type : types){
310  MuonTrack = mu->trackParticle(type);
311  if (MuonTrack) break;
312  }
313  return MuonTrack ? matchReadHandle<xAOD::L2StandAloneMuon>( MuonTrack, reqdR, m_L2MuonSAContainerKey, ctx) : nullptr;
314 }
315 
316 
317 const xAOD::L2CombinedMuon* MuonMatchingTool :: matchL2CB( const xAOD::Muon *mu, std::string trig, bool &pass) const {
318  ATH_MSG_DEBUG("MuonMonitoring::matchL2CB()");
319  return match<xAOD::L2CombinedMuon>( mu, std::move(trig), m_L2CBreqdR, pass, "HLT_MuonL2CBInfo");
320 }
321 
323  ATH_MSG_DEBUG("MuonMonitoring::searchL2CBLinkInfo()");
324  bool pass = false;
325  return matchLinkInfo<xAOD::L2CombinedMuon>( mu, std::move(trig), 1000., pass, "HLT_MuonL2CBInfo");
326 }
327 
328 const xAOD::L2CombinedMuon* MuonMatchingTool :: matchL2CBReadHandle( const EventContext& ctx, const xAOD::Muon *mu) const {
329  ATH_MSG_DEBUG("MuonMonitoring::matchL2CBReadHandle()");
330  const xAOD::TrackParticle* MuonTrack = mu->trackParticle(xAOD::Muon::TrackParticleType::Primary);
331  return MuonTrack ? matchReadHandle<xAOD::L2CombinedMuon>( MuonTrack, m_L2CBreqdR, m_L2muCombContainerKey, ctx) : nullptr;
332 }
333 
334 const xAOD::MuonRoI* MuonMatchingTool :: matchL1( double refEta, double refPhi, double reqdR, const std::string& trig, bool &pass) const {
335  ATH_MSG_DEBUG("Chain: " << trig);
336  pass = false;
337  const xAOD::MuonRoI *closest = nullptr;
338  Trig::FeatureRequestDescriptor featureRequestDescriptor(trig,TrigDefs::includeFailedDecisions);
339  auto l2muonFeatures = m_trigDec->features<xAOD::L2StandAloneMuonContainer>(featureRequestDescriptor);
340  for( const auto& linkInfo : l2muonFeatures){ // loop on L2 muon features
341  // get L1 muon associated with this L2 muon
342  auto l1muonLinkInfo = TrigCompositeUtils::findLink<xAOD::MuonRoIContainer>(linkInfo.source, "initialRecRoI");
343  auto l1muonLink = l1muonLinkInfo.link;
344  if(!l1muonLink.isValid()){
345  ATH_MSG_ERROR("Invalid link to L1 muon");
346  continue;
347  }
348  const xAOD::MuonRoI* l1muon = *l1muonLink;
349  double l1muonEta = l1muon->eta();
350  double l1muonPhi = l1muon->phi();
351 
352  double deta = refEta - l1muonEta;
353  double dphi = xAOD::P4Helpers::deltaPhi(refPhi, l1muonPhi);
354  double dR = std::sqrt(deta*deta + dphi*dphi);
355  ATH_MSG_DEBUG("L1 muon candidate eta=" << l1muonEta << " phi=" << l1muonPhi << " dR=" << dR);
356  if( dR<reqdR ){
357  reqdR = dR;
358  pass = true;
359  closest = l1muon;
360  ATH_MSG_DEBUG("*** L1 muon eta=" << l1muonEta << " phi=" << l1muonPhi << " dR=" << dR << " isPassed=true" );
361  }
362  else{
363  ATH_MSG_DEBUG("*** L1 muon eta=" << l1muonEta << " phi=" << l1muonPhi << " dR=" << dR << " isPassed=false" );
364  }
365  }
366  return closest;
367 }
368 
369 const xAOD::MuonRoI* MuonMatchingTool :: matchL1( const xAOD::Muon *mu, const std::string& trig, bool &pass) const {
370  double refEta = mu->eta();
371  double refPhi = mu->phi();
372  double reqdR = 0.25;
373 
374  if(m_use_extrapolator){
375  reqdR = reqdRL1byPt(mu->pt());
376  const Amg::Vector3D extPos = offlineMuonAtPivot(mu);
377  if(extPos.norm()>ZERO_LIMIT){
378  refEta = extPos.eta();
379  refPhi = extPos.phi();
380  }
381  }
382  return matchL1(refEta, refPhi, reqdR, trig, pass);
383 }
384 
385 const xAOD::MuonRoI* MuonMatchingTool :: matchL1( const xAOD::TruthParticle *mu, const std::string& trig, bool &pass) const {
386  double refEta = mu->eta();
387  double refPhi = mu->phi();
388  double reqdR = 0.25;
389  return matchL1(refEta, refPhi, reqdR, trig, pass);
390 }
391 
392 
393 const xAOD::Muon* MuonMatchingTool :: matchL2SAtoOff( const EventContext& ctx, const xAOD::L2StandAloneMuon* samu) const {
395 }
396 
397 const xAOD::Muon* MuonMatchingTool :: matchL2CBtoOff( const EventContext& ctx, const xAOD::L2CombinedMuon* cbmu) const {
399 }
400 
401 
403  float offlEta = mu->eta();
404  float offlPhi = mu->phi();
405  float trigEta = samu->roiEta();
406  float trigPhi = samu->roiPhi();
407 
408  float deta = offlEta - trigEta;
409  float dphi = xAOD::P4Helpers::deltaPhi(offlPhi, trigPhi);
410  float dR = sqrt(deta*deta + dphi*dphi);
411  return dR < m_L2SAreqdR;
412 }
413 
415  float dR = xAOD::P4Helpers::deltaR(cbmu, mu, false);
416  return dR < m_L2CBreqdR;
417 }
418 
420  float dR = xAOD::P4Helpers::deltaR(cbiomu, mu, false);
421  return dR < m_L2InsideOutreqdR;
422 }
423 
424 double MuonMatchingTool :: FermiFunction(double x, double x0, double w) {
425  return 1/(1+TMath::Exp(-10*(x-x0)/w));
426 }
427 
428 
429 
431 
432  const Trk::TrackParameters *extRPC = nullptr;
433  const Trk::TrackParameters *extTGC = nullptr;
434 
435  if(!track) return extTGC;
436  double trkEta = track->eta();
437  double extEta =0.;
438  bool isBarrel = true;
439 
440  if( fabs(trkEta)<1.05){
441  extRPC = extTrackToRPC(track);
442  if(!extRPC){
443  isBarrel = false;
444  extTGC = extTrackToTGC(track);
445  }
446  else{
447  isBarrel = true;
448  extEta = extRPC->position().eta();
449  if(fabs(extEta)>=1.05){
450  extTGC = extTrackToTGC(track);
451  isBarrel = (extTGC) == nullptr;
452  }
453  }
454  }
455  else if( fabs(trkEta)>=1.05 ){
456  extTGC = extTrackToTGC(track);
457  if(!extTGC){
458  isBarrel = true;
459  extRPC = extTrackToRPC(track);
460  }
461  else{
462  isBarrel = false;
463  extEta = extTGC->position().eta();
464  if(fabs(extEta)<1.05){
465  extRPC = extTrackToRPC(track);
466  isBarrel = (extRPC) != nullptr;
467  }
468  }
469  }
470 
471  ATH_MSG_DEBUG("extTGC=" << extTGC << " extRPC=" << extRPC << " isBarrel=" << isBarrel);
472  if( isBarrel) delete extTGC;
473  else if(!isBarrel) delete extRPC;
474  return (isBarrel) ? extRPC : extTGC;
475 }
476 
477 
478 
480  ATH_MSG_DEBUG("extTrackToTGC");
481  if(!trk) return nullptr;
482  double TGC_Z = ( trk->eta()>0 )? 15153.0:-15153.0;
484  //object pointed by matrix will be deleted in destructer of DiscSurface, therefore release it
485  std::unique_ptr<Trk::DiscSurface> disc(new Trk::DiscSurface( matrix, 0., 15000.));
486  const bool boundaryCheck = true;
487 
488  const Trk::TrackParameters* param = m_extrapolator->extrapolate(Gaudi::Hive::currentContext(),
489  trk->perigeeParameters(),
490  *disc,
492  boundaryCheck,
493  Trk::muon).release();
494 
495  ATH_MSG_DEBUG("param=" << param
496  << " eta=" << ((param) ? param->position().eta() : 0)
497  << " phi=" << ((param) ? param->position().phi() : 0));;
498  return param;
499 }
500 
501 
502 
504  ATH_MSG_DEBUG("extTrackToRPC");
505  if(!trk) return nullptr;
506  std::unique_ptr<Trk::CylinderSurface> barrel(new Trk::CylinderSurface( 7478., 15000. ));
507  const bool boundaryCheck = true;
508 
509  const Trk::TrackParameters* param = m_extrapolator->extrapolate(Gaudi::Hive::currentContext(),
510  trk->perigeeParameters(),
511  *barrel,
513  boundaryCheck,
514  Trk::muon).release();
515  return param;
516 }
517 
518 
519 
520 double MuonMatchingTool :: reqdRL1byPt( double mupt){
521  double dR = 0.08;
522  if( mupt < 10000. ) {
523  dR = -0.00001*mupt + 0.18;
524  }
525  return dR;
526 }
MuonMatchingTool::matchEFIso
const xAOD::Muon * matchEFIso(const xAOD::Muon *mu, std::string trigger, bool &pass) const
Function that searches for an EF isolation muon (EFIso) candidate and judges if it is matched to a gi...
Definition: MuonMatchingTool.cxx:224
Trk::anyDirection
@ anyDirection
Definition: PropDirection.h:22
Trig::FeatureRequestDescriptor
Definition: FeatureRequestDescriptor.h:37
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
TrigCompositeUtils::LinkInfo::link
ElementLink< T > link
Link to the feature.
Definition: LinkInfo.h:61
MuonMatchingTool::searchL2SALinkInfo
const TrigCompositeUtils::LinkInfo< xAOD::L2StandAloneMuonContainer > searchL2SALinkInfo(const xAOD::Muon *mu, std::string trigger) const
Function that searches for the L2 standalone muon (L2MuonSA) candidate closest to a given offline muo...
Definition: MuonMatchingTool.cxx:288
MuonMatchingTool::m_L2CBreqdR
const float m_L2CBreqdR
Definition: MuonMatchingTool.h:362
xAOD::L2StandAloneMuon_v2
Class describing standalone muons reconstructed in the LVL2 trigger.
Definition: L2StandAloneMuon_v2.h:36
Trk::ParametersBase::position
const Amg::Vector3D & position() const
Access method for the position.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
MuonRoIContainer.h
xAOD::TrackParticle_v1::eta
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
Definition: TrackParticle_v1.cxx:77
MuonMatchingTool::m_EFreqdR
const float m_EFreqdR
Definition: MuonMatchingTool.h:364
MuonMatchingTool::m_extrapolator
PublicToolHandle< Trk::IExtrapolator > m_extrapolator
Definition: MuonMatchingTool.h:455
MuonMatchingTool::m_MStrackContainerKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_MStrackContainerKey
Definition: MuonMatchingTool.h:447
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
skel.it
it
Definition: skel.GENtoEVGEN.py:423
MuonMatchingTool::searchL2CBLinkInfo
const TrigCompositeUtils::LinkInfo< xAOD::L2CombinedMuonContainer > searchL2CBLinkInfo(const xAOD::Muon *mu, std::string trigger) const
Function that searches for the L2 combined muon (L2muComb) candidate closest to a given offline muon.
Definition: MuonMatchingTool.cxx:322
xAOD::MuonRoI_v1::eta
float eta() const
The pseudorapidity ( ) of the muon candidate.
MuonMatchingTool::matchEFCBReadHandle
const xAOD::Muon * matchEFCBReadHandle(const EventContext &ctx, const xAOD::Muon *mu) const
Function that searches for an EF combined muon (EFCB) candidate by ReadHandle and judges if it is mat...
Definition: MuonMatchingTool.cxx:142
xAOD::P4Helpers::deltaPhi
double deltaPhi(double phiA, double phiB)
delta Phi in range [-pi,pi[
Definition: xAODP4Helpers.h:69
MuonMatchingTool::trigPosForMatchSATrack
static std::tuple< bool, double, double > trigPosForMatchSATrack(const xAOD::Muon *mu)
Definition: MuonMatchingTool.cxx:53
MuonMatchingTool::m_EFCBFSMuonContainerKey
SG::ReadHandleKey< xAOD::MuonContainer > m_EFCBFSMuonContainerKey
Definition: MuonMatchingTool.h:446
Trk::DiscSurface
Definition: DiscSurface.h:54
MuonMatchingTool::isMatchedL2SA
bool isMatchedL2SA(const xAOD::L2StandAloneMuon *, const xAOD::Muon *) const
Definition: MuonMatchingTool.cxx:402
MuonMatchingTool::extTrackToRPC
const Trk::TrackParameters * extTrackToRPC(const xAOD::TrackParticle *track) const
Definition: MuonMatchingTool.cxx:503
SG::ReadHandleKey< xAOD::TrackParticleContainer >
MuonMatchingTool::matchL2SAReadHandle
const xAOD::L2StandAloneMuon * matchL2SAReadHandle(const EventContext &ctx, const xAOD::Muon *mu) const
Function that searches for an L2 standalone muon (L2MuonSA) candidate by ReadHandle and judges if it ...
Definition: MuonMatchingTool.cxx:294
x
#define x
MuonMatchingTool::matchEFSAFSLinkInfo
const TrigCompositeUtils::LinkInfo< xAOD::MuonContainer > matchEFSAFSLinkInfo(const xAOD::Muon *mu, std::string trig) const
Function that searches for an EF standalone muon (EFSAFS) candidate and judges if it is matched to a ...
Definition: MuonMatchingTool.cxx:168
MuonMatchingTool::matchL2CB
const xAOD::L2CombinedMuon * matchL2CB(const xAOD::Muon *mu, std::string trigger, bool &pass) const
Function that searches for an L2 combined muon (L2muComb) candidate and judges if it is matched to a ...
Definition: MuonMatchingTool.cxx:317
MuonMatchingTool::matchL2SAtoOff
const xAOD::Muon * matchL2SAtoOff(const EventContext &ctx, const xAOD::L2StandAloneMuon *samu) const
Function that searches for an offline muon matched to L2SA muon.
Definition: MuonMatchingTool.cxx:393
MuonMatchingTool::PosForMatchSATrack
static std::tuple< bool, double, double > PosForMatchSATrack(const xAOD::Muon *mu)
Definition: MuonMatchingTool.cxx:61
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
MuonMatchingTool::extTrackToPivot
const Trk::TrackParameters * extTrackToPivot(const xAOD::TrackParticle *track) const
Function to extrapolate a Inner Detector track to the pivot plane i.e.
Definition: MuonMatchingTool.cxx:430
MuonMatchingTool::m_CBtrackContainerKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_CBtrackContainerKey
Definition: MuonMatchingTool.h:448
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
xAOD::L2CombinedMuon_v1
Class describing combined muon reconstructed in the LVL2 trigger.
Definition: L2CombinedMuon_v1.h:41
InDet::ExclusiveOrigin::Primary
@ Primary
Definition: InDetTrackTruthOriginDefs.h:163
MuonMatchingTool::FermiFunction
static double FermiFunction(double x, double x0, double w)
Definition: MuonMatchingTool.cxx:424
MuonMatchingTool::matchL2CBReadHandle
const xAOD::L2CombinedMuon * matchL2CBReadHandle(const EventContext &ctx, const xAOD::Muon *mu) const
Function that searches for an L2 combined muon (L2muComb) candidate by ReadHandle and judges if it is...
Definition: MuonMatchingTool.cxx:328
MuonMatchingTool::m_L2MuonSAContainerKey
SG::ReadHandleKey< xAOD::L2StandAloneMuonContainer > m_L2MuonSAContainerKey
Definition: MuonMatchingTool.h:441
xAOD::TrackParticle_v1::perigeeParameters
const Trk::Perigee & perigeeParameters() const
Returns the Trk::MeasuredPerigee track parameters.
Definition: TrackParticle_v1.cxx:485
MuonMatchingTool::m_EFSAFSMuonContainerKey
SG::ReadHandleKey< xAOD::MuonContainer > m_EFSAFSMuonContainerKey
Definition: MuonMatchingTool.h:445
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
xAOD::L2StandAloneMuon_v2::roiPhi
float roiPhi() const
Get and set RoI phi.
MuonMatchingTool.h
xAOD::P4Helpers::deltaR
double deltaR(double rapidity1, double phi1, double rapidity2, double phi2)
from bare bare rapidity,phi
Definition: xAODP4Helpers.h:150
MuonMatchingTool::matchL2CBtoOff
const xAOD::Muon * matchL2CBtoOff(const EventContext &ctx, const xAOD::L2CombinedMuon *cbmu) const
Function that searches for an offline muon matched to L2CB muon.
Definition: MuonMatchingTool.cxx:397
MuonMatchingTool::isMatchedL2CB
bool isMatchedL2CB(const xAOD::L2CombinedMuon *, const xAOD::Muon *) const
Definition: MuonMatchingTool.cxx:414
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Trk::CylinderSurface
Definition: CylinderSurface.h:55
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:41
MuonMatchingTool::m_L2InsideOutreqdR
const float m_L2InsideOutreqdR
Definition: MuonMatchingTool.h:363
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
MuonMatchingTool::m_L2muCombContainerKey
SG::ReadHandleKey< xAOD::L2CombinedMuonContainer > m_L2muCombContainerKey
Definition: MuonMatchingTool.h:442
MuonMatchingTool::m_trigDec
PublicToolHandle< Trig::TrigDecisionTool > m_trigDec
Definition: MuonMatchingTool.h:454
MuonMatchingTool::initialize
virtual StatusCode initialize() override
Definition: MuonMatchingTool.cxx:19
xAOD::MuonRoI_v1
Class describing a LVL1 muon region of interest.
Definition: MuonRoI_v1.h:33
test_pyathena.parent
parent
Definition: test_pyathena.py:15
MuonMatchingTool::matchL1
const xAOD::MuonRoI * matchL1(const xAOD::Muon *mu, const std::string &trigger, bool &pass) const
Function that searches for a Level 1 muon candidate and judges if it is matched to a given offline mu...
Definition: MuonMatchingTool.cxx:369
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Trk::ParametersBase
Definition: ParametersBase.h:55
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
Trk::muon
@ muon
Definition: ParticleHypothesis.h:28
xAODType
Definition: ObjectType.h:13
DataVector< xAOD::TrackParticle_v1 >
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
ZERO_LIMIT
const float ZERO_LIMIT
Definition: VP1TriggerHandleL2.cxx:37
Trk::Combined
@ Combined
Definition: TrackSummaryTool.h:32
MuonMatchingTool::matchEFCBFSReadHandle
const xAOD::Muon * matchEFCBFSReadHandle(const EventContext &ctx, const xAOD::Muon *mu) const
Function that searches for an EF combined muon (EFCBFS) candidate by ReadHandle and judges if it is m...
Definition: MuonMatchingTool.cxx:218
MuonMatchingTool::matchEFCBFS
const xAOD::Muon * matchEFCBFS(const xAOD::Muon *mu, std::string trigger, bool &pass) const
Function that searches for an EF combined muon (EFCBFS) candidate and judges if it is matched to a gi...
Definition: MuonMatchingTool.cxx:203
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
MuonMatchingTool::offlineMuonAtPivot
const Amg::Vector3D offlineMuonAtPivot(const xAOD::Muon *mu) const
Definition: MuonMatchingTool.cxx:40
MuonMatchingTool::MuonMatchingTool
MuonMatchingTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: MuonMatchingTool.cxx:14
MuonMatchingTool::m_use_extrapolator
Gaudi::Property< bool > m_use_extrapolator
Definition: MuonMatchingTool.h:451
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
MuonMatchingTool::matchEFSA
const xAOD::Muon * matchEFSA(const xAOD::Muon *mu, std::string trigger, bool &pass) const
Function that searches for an EF standalone muon (EFSA) candidate and judges if it is matched to a gi...
Definition: MuonMatchingTool.cxx:72
MuonMatchingTool::m_MuonContainerKey
SG::ReadHandleKey< xAOD::MuonContainer > m_MuonContainerKey
Definition: MuonMatchingTool.h:440
MuonMatchingTool::PosForMatchCBTrack
static std::tuple< bool, double, double > PosForMatchCBTrack(const xAOD::Muon *mu)
Definition: MuonMatchingTool.cxx:66
python.testIfMatch.matrix
matrix
Definition: testIfMatch.py:66
TrigCompositeUtils::LinkInfo
Helper to keep a Decision object, ElementLink and ActiveState (with respect to some requested ChainGr...
Definition: LinkInfo.h:28
MuonMatchingTool::trigPosForMatchCBTrack
static std::tuple< bool, double, double > trigPosForMatchCBTrack(const xAOD::Muon *mu)
Definition: MuonMatchingTool.cxx:57
MuonMatchingTool::matchEFSAReadHandle
const xAOD::Muon * matchEFSAReadHandle(const EventContext &ctx, const xAOD::Muon *mu) const
Function that searches for an EF standalone muon (EFSA) candidate by ReadHandle and judges if it is m...
Definition: MuonMatchingTool.cxx:108
MuonMatchingTool::m_EFCBMuonContainerKey
SG::ReadHandleKey< xAOD::MuonContainer > m_EFCBMuonContainerKey
Definition: MuonMatchingTool.h:444
MuonMatchingTool::matchEFCB
const xAOD::Muon * matchEFCB(const xAOD::Muon *mu, std::string trigger, bool &pass) const
Function that searches for an EF combined muon (EFCB) candidate and judges if it is matched to a give...
Definition: MuonMatchingTool.cxx:127
xAOD::L2StandAloneMuon_v2::roiEta
float roiEta() const
Get and set RoI eta.
MuonMatchingTool::matchL2SA
const xAOD::L2StandAloneMuon * matchL2SA(const xAOD::Muon *mu, const std::string &trigger, bool &pass) const
Function that searches for an L2 standalone muon (L2MuonSA) candidate and judges if it is matched to ...
Definition: MuonMatchingTool.cxx:275
MuonMatchingTool::SearchEFTrack
const xAOD::TrackParticle * SearchEFTrack(const EventContext &ctx, const TrigCompositeUtils::LinkInfo< xAOD::MuonContainer > &muLinkInfo, const SG::ReadHandleKey< xAOD::TrackParticleContainer > &ReadHandleKey) const
Function that searches for an EF muon track (e.g.
Definition: MuonMatchingTool.cxx:236
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
MuonMatchingTool::isMatchedL2InsideOut
bool isMatchedL2InsideOut(const xAOD::L2CombinedMuon *, const xAOD::Muon *) const
Definition: MuonMatchingTool.cxx:419
DetectorZone::barrel
@ barrel
python.LArCondContChannels.isBarrel
isBarrel
Definition: LArCondContChannels.py:659
MuonMatchingTool::matchEFCBLinkInfo
const TrigCompositeUtils::LinkInfo< xAOD::MuonContainer > matchEFCBLinkInfo(const xAOD::Muon *mu, std::string trig) const
Function that searches for an EF combined muon (EFCB) candidate and judges if it is matched to a give...
Definition: MuonMatchingTool.cxx:134
MuonMatchingTool::extTrackToTGC
const Trk::TrackParameters * extTrackToTGC(const xAOD::TrackParticle *track) const
Definition: MuonMatchingTool.cxx:479
MuonMatchingTool::matchEFCBFSLinkInfo
const TrigCompositeUtils::LinkInfo< xAOD::MuonContainer > matchEFCBFSLinkInfo(const xAOD::Muon *mu, std::string trig) const
Function that searches for an EF combined muon (EFCBFS) candidate and judges if it is matched to a gi...
Definition: MuonMatchingTool.cxx:210
MuonMatchingTool::m_EFSAMuonContainerKey
SG::ReadHandleKey< xAOD::MuonContainer > m_EFSAMuonContainerKey
Definition: MuonMatchingTool.h:443
MuonMatchingTool::matchEFSALinkInfo
const TrigCompositeUtils::LinkInfo< xAOD::MuonContainer > matchEFSALinkInfo(const xAOD::Muon *mu, std::string trig) const
Function that searches for an EF standalone muon (EFSA) candidate and judges if it is matched to a gi...
Definition: MuonMatchingTool.cxx:92
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
MuonMatchingTool::matchEFIsoLinkInfo
const TrigCompositeUtils::LinkInfo< xAOD::MuonContainer > matchEFIsoLinkInfo(const xAOD::Muon *mu, std::string trig) const
Function that searches for an EF isolation muon (EFIso) candidate and judges if it is matched to a gi...
Definition: MuonMatchingTool.cxx:266
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
MuonMatchingTool::m_L2SAreqdR
const float m_L2SAreqdR
Definition: MuonMatchingTool.h:361
AthAlgTool
Definition: AthAlgTool.h:26
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
MuonMatchingTool::matchOff
const xAOD::Muon * matchOff(const EventContext &ctx, const T *trig, float reqdR, std::tuple< bool, double, double >(*offlinePosForMatchFunc)(const xAOD::Muon *), std::tuple< bool, double, double >(*trigPosForMatchFunc)(const T *)=&MuonMatchingTool::trigPosForMatch< T >) const
Function that searches for an offline muon candidate matched to online muon of type T.
MuonMatchingTool::matchEFSAFSReadHandle
const xAOD::Muon * matchEFSAFSReadHandle(const EventContext &ctx, const xAOD::Muon *mu) const
Function that searches for an EF standalone muon (EFSAFS) candidate by ReadHandle and judges if it is...
Definition: MuonMatchingTool.cxx:184
MuonMatchingTool::m_MuonRoIContainerKey
SG::ReadHandleKey< xAOD::MuonRoIContainer > m_MuonRoIContainerKey
Definition: MuonMatchingTool.h:439
xAOD::TrackParticle_v1::phi
virtual double phi() const override final
The azimuthal angle ( ) of the particle (has range to .)
MuonMatchingTool::reqdRL1byPt
static double reqdRL1byPt(double mupt)
Function compute dR used for matching offline muons and level 1 RoIs at the pivot plane.
Definition: MuonMatchingTool.cxx:520
xAOD::MuonRoI_v1::phi
float phi() const
The azimuthal angle ( ) of the muon candidate.
MuonMatchingTool::matchEFSAFS
const xAOD::Muon * matchEFSAFS(const xAOD::Muon *mu, std::string trigger, bool &pass) const
Function that searches for an EF FS standalone muon (EFSAFS) candidate and judges if it is matched to...
Definition: MuonMatchingTool.cxx:148