ATLAS Offline Software
TrigMuonEFInfoCnvTestAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
12 #include "xAODMuon/MuonContainer.h"
14 
15 #include "FourMomUtils/P4Helpers.h"
16 
17 #include <vector>
18 #include <iomanip>
19 
20 static const double ptcheckthres=0.001;
21 static const double etaphicheckthres=0.0001;
22 
23 TrigMuonEFInfoCnvTestAlg::TrigMuonEFInfoCnvTestAlg( const std::string& name, ISvcLocator* svcLoc ) :
24  AthAlgorithm(name, svcLoc)
25 {
26  declareProperty( "AODContainerName", m_aodContainerName = "HLT_MuonEFInfo" );
27  declareProperty( "xAODMuonContainerName", m_xaodMuonContainerName = "HLT_Muons" );
28 }
29 
31 
32  ATH_MSG_INFO( "AODContainerName = " << m_aodContainerName << ", xAODMuonContainerName = " << m_xaodMuonContainerName );
33 
34  // Return gracefully:
35  return StatusCode::SUCCESS;
36 }
37 
39 
40  // Retrieve the TrigMuonEFInfoContainer
41  const TrigMuonEFInfoContainer* infocont = evtStore()->tryConstRetrieve<TrigMuonEFInfoContainer>(m_aodContainerName);
42  if (!infocont) {
43  ATH_MSG_ERROR("No TrigMuonEFInfoContainer with key " << m_aodContainerName << " found.");
44  return StatusCode::RECOVERABLE;
45  }
46  ATH_MSG_DEBUG("Retrieved " << m_aodContainerName);
47 
48  // Retrieve the xAOD::MuonContainer
49  const xAOD::MuonContainer* muoncont = evtStore()->tryConstRetrieve<xAOD::MuonContainer>(m_xaodMuonContainerName);
50  if(!muoncont) {
51  ATH_MSG_ERROR("No xAOD::MuonContainer with key " << m_xaodMuonContainerName << " found.");
52  return StatusCode::RECOVERABLE;
53  }
54  ATH_MSG_DEBUG("Retrieved " << m_xaodMuonContainerName);
55 
56  // put all TrigMuonEF tracks into a single vector
57  std::vector<const TrigMuonEFInfoTrack*> efinfotracks;
58  for(const auto *infoit : *infocont) {
59  const TrigMuonEFInfoTrackContainer* trkcont = infoit->TrackContainer();
60  for(const auto *trk : *trkcont) {
61 
62  if(trk->hasCombinedTrack() || trk->hasExtrapolatedTrack()) {
63  // for now ignore MS only tracks
64  efinfotracks.push_back(trk);
65  }
66 
67  }//loop on Info track objects
68  }//loop on TrigMuonEFInfo objects
69 
70  ATH_MSG_DEBUG("N(TrigMuonEFInfoTrack) = " << efinfotracks.size());
71  ATH_MSG_DEBUG("N(muons) = " << muoncont->size());
72 
73  if(efinfotracks.size() != muoncont->size()) {
74  ATH_MSG_ERROR("Inconsistency in number of muons from " << m_xaodMuonContainerName << " and " << m_aodContainerName);
75  ATH_MSG_ERROR("Converter code is likely faulty");
76  return StatusCode::RECOVERABLE;
77  }
78  ATH_MSG_DEBUG("Size of old & new vectors matches ok");
79 
80  // same number of muons, now loop over them
81  for( unsigned int i=0; i<muoncont->size(); ++i) {
82 
83  const TrigMuonEFInfoTrack* infotrk = efinfotracks[i];
84  const xAOD::Muon* muon = (*muoncont)[i];
85 
86  if(!infotrk) {
87  ATH_MSG_ERROR("Zero pointer for TrigMuonEFInfoTrack");
88  return StatusCode::RECOVERABLE;
89  }
90  if(!muon) {
91  ATH_MSG_ERROR("Zero pointer for xAOD::Muon");
92  return StatusCode::RECOVERABLE;
93  }
94 
95  ATH_MSG_DEBUG("Check muon " << i);
96 
100 
101  }//loop on muons
102 
103  return StatusCode::SUCCESS;
104 }//execute
105 
111 
112  if( !infotrk->hasExtrapolatedTrack() ) {
113  ATH_MSG_DEBUG("TrigMuonEFInfo track has no extrapolated track");
114  if(muon->muonSpectrometerTrackParticleLink().isValid() ) {
115  ATH_MSG_ERROR("Mismatch: TrigMuonEFInfoTrack has no ME track, xAOD::Muon does");
116  return StatusCode::RECOVERABLE;
117  }
118 
119  return StatusCode::SUCCESS; // ok both new and old don't have the track
120  }
121 
122  if( infotrk->hasExtrapolatedTrack() ) {
123  ATH_MSG_DEBUG("TrigMuonEFInfo track has extrapolated track");
124  if( !(muon->muonSpectrometerTrackParticleLink().isValid()) ) {
125  ATH_MSG_ERROR("Mismatch: TrigMuonEFInfoTrack has ME track, xAOD::Muon does not");
126  return StatusCode::RECOVERABLE;
127  }
128  }
129 
130  // now compare the actual tracks
131  StatusCode sc = compareTracks( infotrk->ExtrapolatedTrack(), *(muon->muonSpectrometerTrackParticleLink()) );
132  if(sc.isFailure()) return sc;
133  else ATH_MSG_DEBUG("Passed check on extrapolated track");
134 
135  return StatusCode::SUCCESS;
136 }
137 
142 
143  if( !infotrk->hasCombinedTrack() ) {
144  ATH_MSG_DEBUG("TrigMuonEFInfo track has no combined track");
145  if(muon->combinedTrackParticleLink().isValid() ) {
146  ATH_MSG_ERROR("Mismatch: TrigMuonEFInfoTrack has no combined track, xAOD::Muon does");
147  return StatusCode::RECOVERABLE;
148  }
149 
150  return StatusCode::SUCCESS; // ok both new and old don't have the track
151  }
152 
153  if( infotrk->hasCombinedTrack() ) {
154  ATH_MSG_DEBUG("TrigMuonEFInfo track has combined track");
155  if( !(muon->combinedTrackParticleLink().isValid()) ) {
156  ATH_MSG_ERROR("Mismatch: TrigMuonEFInfoTrack has combined track, xAOD::Muon does not");
157  return StatusCode::RECOVERABLE;
158  }
159  }
160 
161  // now compare the actual tracks
162  StatusCode sc = compareTracks( infotrk->CombinedTrack(), *(muon->combinedTrackParticleLink()) );
163  if(sc.isFailure()) return sc;
164  else ATH_MSG_DEBUG("Passed check on combined track");
165 
166  return StatusCode::SUCCESS;
167 }
168 
173 
174  const TrigMuonEFTrack* primtrk=nullptr;
175  if( infotrk->hasExtrapolatedTrack() ) {
176  primtrk = infotrk->ExtrapolatedTrack();
177  }
178  if( infotrk->hasCombinedTrack() ) {
179  primtrk = infotrk->CombinedTrack();
180  }
181  if(primtrk!=nullptr && muon->primaryTrackParticleLink().isValid()) {
182  StatusCode sc = compareTracks(primtrk, *(muon->primaryTrackParticleLink()));
183  if(sc.isFailure()) return sc;
184  } else {
185  if(primtrk!=nullptr || muon->primaryTrackParticleLink().isValid()) {
186  ATH_MSG_ERROR("One of the primary tracks is not good, old = " << (primtrk!=nullptr) << ", new = " << muon->primaryTrackParticleLink().isValid() );
187  return StatusCode::RECOVERABLE;
188  } else return StatusCode::SUCCESS; // this means both are 0, which is ok
189  }
190 
191  ATH_MSG_DEBUG("Passed check on primary track");
192 
193  return StatusCode::SUCCESS;
194 
195 }//comparePrimaryTracks
196 
198 
199  if(msgLvl(MSG::VERBOSE)) {
200  msg() << MSG::VERBOSE << "Compare Track:" << endmsg;
201  msg() << MSG::VERBOSE << "old track pt = " << eftrack->pt() << ", new track pt = " << xaodtrack->pt() << endmsg;
202  msg() << MSG::VERBOSE << "old track eta = " << eftrack->eta() << ", new track eta = " << xaodtrack->eta() << endmsg;
203  msg() << MSG::VERBOSE << "old track phi = " << eftrack->phi() << ", new track phi = " << xaodtrack->phi() << endmsg;
204  }
205  const double dpt = std::abs(eftrack->pt() - xaodtrack->pt());
206  if( dpt > ptcheckthres*eftrack->pt() ) { // pT check is relative - we accept 0.1% changes
207 
208  ATH_MSG_ERROR("pT of two tracks is different, old = " << std::fixed << std::setprecision(8) << eftrack->pt() << ", new = " << xaodtrack->pt() << ", dpt = " << dpt);
209  return StatusCode::RECOVERABLE;
210 
211  }
212  if( std::abs(eftrack->eta() - xaodtrack->eta()) > etaphicheckthres ) {
213  ATH_MSG_ERROR("eta of two tracks is different, old = " << eftrack->eta() << ", new = " << xaodtrack->eta());
214  return StatusCode::RECOVERABLE;
215  }
216  const double dphi = P4Helpers::deltaPhi( eftrack->phi(), xaodtrack->phi() );
217  if( std::abs(dphi) > etaphicheckthres) {
218  ATH_MSG_ERROR("phi of two tracks is different, old = " << eftrack->phi() << ", new = " << xaodtrack->phi());
219  return StatusCode::RECOVERABLE;
220  }
221 
222  return StatusCode::SUCCESS;
223 }
xAOD::TrackParticle_v1::pt
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition: TrackParticle_v1.cxx:73
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
TrigMuonEFInfoCnvTestAlg::m_aodContainerName
std::string m_aodContainerName
The key of the TrigMuonEFInfoContainer.
Definition: TrigMuonEFInfoCnvTestAlg.h:61
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TrigMuonEFTrack
Definition: TrigMuonEFTrack.h:27
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
xAOD::TrackParticle_v1::eta
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
Definition: TrackParticle_v1.cxx:77
TrigMuonEFInfoContainer.h
TrigMuonEFInfoTrack::hasExtrapolatedTrack
bool hasExtrapolatedTrack() const
Definition: TrigMuonEFInfoTrack.cxx:121
TrigMuonEFCbTrack.h
AthCommonMsg< Algorithm >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
TrigMuonEFInfoCnvTestAlg::compareCombinedTracks
StatusCode compareCombinedTracks(const TrigMuonEFInfoTrack *infotrk, const xAOD::Muon *muon)
compare combined tracks
Definition: TrigMuonEFInfoCnvTestAlg.cxx:141
TrigMuonEFInfoCnvTestAlg::m_xaodMuonContainerName
std::string m_xaodMuonContainerName
The key for the xAOD::MuonContainer.
Definition: TrigMuonEFInfoCnvTestAlg.h:63
TrigMuonEFTrack.h
TrigMuonEFInfoContainer
Definition: TrigMuonEFInfoContainer.h:27
TrigMuonEFInfoTrack.h
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
P4Helpers::deltaPhi
double deltaPhi(double phiA, double phiB)
delta Phi in range [-pi,pi[
Definition: P4Helpers.h:34
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TrigMuonEFInfoCnvTestAlg::compareExtrapolatedTracks
StatusCode compareExtrapolatedTracks(const TrigMuonEFInfoTrack *infotrk, const xAOD::Muon *muon)
compare extrapolated tracks
Definition: TrigMuonEFInfoCnvTestAlg.cxx:110
TrigMuonEFInfoTrack::CombinedTrack
TrigMuonEFCbTrack * CombinedTrack()
Definition: TrigMuonEFInfoTrack.h:52
lumiFormat.i
int i
Definition: lumiFormat.py:85
P4IPtCotThPhiMBase::eta
virtual double eta() const
pseudo rapidity
Definition: P4IPtCotThPhiMBase.cxx:76
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TrigMuonEFInfoTrackContainer
Definition: TrigMuonEFInfoTrackContainer.h:27
TrigMuonEFInfoCnvTestAlg::execute
virtual StatusCode execute()
Function executing the algorithm.
Definition: TrigMuonEFInfoCnvTestAlg.cxx:38
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
P4IPtCotThPhiM::phi
virtual double phi() const
get phi data member
Definition: P4IPtCotThPhiM.h:106
AthAlgorithm
Definition: AthAlgorithm.h:47
P4Helpers.h
TrigMuonEFInfoTrack::ExtrapolatedTrack
TrigMuonEFTrack * ExtrapolatedTrack()
Definition: TrigMuonEFInfoTrack.h:51
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
TrigMuonEFInfoTrack::hasCombinedTrack
bool hasCombinedTrack() const
Definition: TrigMuonEFInfoTrack.cxx:111
TrigMuonEFInfoCnvTestAlg::compareTracks
StatusCode compareTracks(const TrigMuonEFTrack *eftrack, const xAOD::TrackParticle *xaodtrack)
compare tracks
Definition: TrigMuonEFInfoCnvTestAlg.cxx:197
MuonContainer.h
TrigMuonEFInfoCnvTestAlg::TrigMuonEFInfoCnvTestAlg
TrigMuonEFInfoCnvTestAlg(const std::string &name, ISvcLocator *svcLoc)
Regular algorithm constructor.
Definition: TrigMuonEFInfoCnvTestAlg.cxx:23
TrigMuonEFInfoTrack
Definition: TrigMuonEFInfoTrack.h:22
TrackParticle.h
TrigMuonEFInfoCnvTestAlg::initialize
virtual StatusCode initialize()
Function initialising the algorithm.
Definition: TrigMuonEFInfoCnvTestAlg.cxx:30
TrigMuonEFInfoTrackContainer.h
TrigMuonEFInfoCnvTestAlg::comparePrimaryTracks
StatusCode comparePrimaryTracks(const TrigMuonEFInfoTrack *infotrk, const xAOD::Muon *muon)
compare primary tracks
Definition: TrigMuonEFInfoCnvTestAlg.cxx:172
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
TrigMuonEFInfoCnvTestAlg.h
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
P4IPtCotThPhiMBase::pt
virtual double pt() const
transverse momentum
Definition: P4IPtCotThPhiMBase.cxx:12
xAOD::TrackParticle_v1::phi
virtual double phi() const override final
The azimuthal angle ( ) of the particle (has range to .)